Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.93 KB | None | 0 0
  1. import dataclasses
  2. import math
  3. import os
  4. import subprocess
  5. import shutil
  6. from pathlib import Path
  7.  
  8.  
  9. prefile = '''<?xml version='1.0'?>
  10. <home version='6000' name='Empty.sh3d' camera='topCamera' wallHeight='260.0'>
  11. <property name='com.eteks.sweethome3d.SweetHome3D.CatalogPaneDividerLocation' value='451'/>
  12. <property name='com.eteks.sweethome3d.SweetHome3D.Columnwidths' value='189,117,119,117,116'/>
  13. <property name='com.eteks.sweethome3d.SweetHome3D.FrameHeight' value='1121'/>
  14. <property name='com.eteks.sweethome3d.SweetHome3D.Framewidth' value='2090'/>
  15. <property name='com.eteks.sweethome3d.SweetHome3D.FrameX' value='224'/>
  16. <property name='com.eteks.sweethome3d.SweetHome3D.FrameY' value='224'/>
  17. <property name='com.eteks.sweethome3d.SweetHome3D.MainPaneDividerLocation' value='663'/>
  18. <property name='com.eteks.sweethome3d.SweetHome3D.PlanPaneDividerLocation' value='711'/>
  19. <property name='com.eteks.sweethome3d.SweetHome3D.PlanScale' value='1.3035849'/>
  20. <property name='com.eteks.sweethome3d.SweetHome3D.PlanViewportX' value='9'/>
  21. <property name='com.eteks.sweethome3d.SweetHome3D.PlanViewportY' value='0'/>
  22. <property name='com.eteks.sweethome3d.SweetHome3D.ScreenHeight' value='1402'/>
  23. <property name='com.eteks.sweethome3d.SweetHome3D.Screenwidth' value='2560'/>
  24. <furnitureVisibleProperty name='NAME'/>
  25. <furnitureVisibleProperty name='width'/>
  26. <furnitureVisibleProperty name='DEPTH'/>
  27. <furnitureVisibleProperty name='HEIGHT'/>
  28. <furnitureVisibleProperty name='VISIBLE'/>
  29. <environment groundColor='00A8A8A8' skyColor='00CCE4FC' lightColor='00D0D0D0' ceillingLightColor='00D0D0D0' photowidth='400' photoHeight='300' photoAspectRatio='VIEW_3D_RATIO' photoQuality='0' videowidth='320' videoAspectRatio='RATIO_4_3' videoQuality='0' videoFrameRate='25'/>
  30. <compass x='-100.0' y='50.0' diameter='100.0' northDirection='0.0' longitude='0.040724345' latitude='0.8528843' timeZone='Europe/Paris'/>
  31. <observerCamera attribute='observerCamera' lens='PINHOLE' x='50.0' y='50.0' z='170.0' yaw='5.4977875' pitch='0.19634955' fieldOfView='1.0995575' time='1563278400000'/>
  32. <camera attribute='topCamera' lens='PINHOLE' x='254.99991' y='1150.0' z='1130.0' yaw='3.1415927' pitch='0.7853982' fieldOfView='1.0995575' time='1563278400000'/>
  33. <!-- Ydermuren 408mm x 2600mm -->
  34. '''
  35.  
  36. postfile = '''</home>
  37. '''
  38.  
  39. @dataclasses.dataclass
  40. class Point:
  41. x: int
  42. y: int
  43.  
  44. def distance(self, other: 'Point'):
  45. return math.sqrt((self.x-other.x)**2 + (self.y-other.y)**2)
  46.  
  47. @classmethod
  48. def from_point(cls, other: 'Point'):
  49. return cls(other.x, other.y)
  50.  
  51.  
  52. class NW(Point):
  53. pass
  54.  
  55. class SW(Point):
  56. pass
  57.  
  58. class NE(Point):
  59. pass
  60.  
  61. class SE(Point):
  62. pass
  63.  
  64.  
  65. class Wall:
  66. Prefix: str = "wall"
  67. ID: int
  68. Start: Point
  69. End: Point
  70. width: int = 1000
  71. height: int = 2600
  72. Pattern: str = "hatchUp"
  73. WallAtStart: 'Wall' = None
  74. WallAtEnd: 'Wall' = None
  75. ne: Point = None
  76. nw: Point = None
  77. se: Point = None
  78. sw: Point = None
  79.  
  80. @property
  81. def name(self):
  82. return f"{self.Prefix }{self.ID}"
  83.  
  84. def __str__(self):
  85. factor = 10
  86. tags = []
  87. tags.append(f"id='{self.name}'")
  88. if self.WallAtStart is not None:
  89. tags.append(f"wallAtStart='{self.WallAtStart.name}'")
  90. if self.WallAtEnd is not None:
  91. tags.append(f"wallAtEnd='{self.WallAtEnd.name}'")
  92. tags.append(f"xStart='{self.Start.x/factor}'")
  93. tags.append(f"yStart='{self.Start.y/factor}'")
  94. tags.append(f"xEnd='{self.End.x/factor}'")
  95. tags.append(f"yEnd='{self.End.y/factor}'")
  96. tags.append(f"height='{self.height/factor}'")
  97. tags.append(f"thickness='{self.width/factor}'")
  98. tags.append(f"pattern='{self.Pattern}'")
  99. return f" <wall {' '.join(tags)}/>"
  100.  
  101. def link(self, other: 'Wall'):
  102. if self.Start.x - self.End.x == 0:
  103. if self.Start.y > self.End.y:
  104. self.Start.y = self.Start.y - (self.width / 2)
  105. else:
  106. self.Start.y = self.Start.y + (self.width / 2)
  107. elif self.Start.y - self.End.y == 0:
  108. if self.Start.x > self.End.x:
  109. self.Start.x = self.Start.x - (self.width / 2)
  110. else:
  111. self.Start.x = self.Start.x + (self.width / 2)
  112.  
  113. if other.Start.x - other.End.x == 0:
  114. if other.End.y > other.Start.y:
  115. other.End.y = other.End.y - (other.width / 2)
  116. else:
  117. other.End.y = other.End.y + (other.width / 2)
  118. elif other.Start.y - other.End.y == 0:
  119. if other.End.x > other.Start.x:
  120. other.End.x = other.End.x - (other.width / 2)
  121. else:
  122. other.End.x = other.End.x + (other.width / 2)
  123.  
  124. self.WallAtStart = other
  125. other.WallAtEnd = self
  126.  
  127. class OuterWall(Wall):
  128. Prefix: str = "outer"
  129. width: int = 408
  130.  
  131. def __init__(self, wid, start, end, wallAtStart: Wall = None):
  132. self.Start = start
  133. self.End = end
  134. self.ID = wid
  135. if wallAtStart is not None:
  136. self.link(wallAtStart)
  137.  
  138.  
  139. def HOuterWall(wid, start: Point, length: int, wallAtStart: Wall = None):
  140. wall = Wall()
  141. wall.Prefix = "Outer"
  142. wall.width = 408
  143. wall.ID = wid
  144. if isinstance(start, NE):
  145. wall.Start = Point(x=start.x - wall.width/2, y=start.y)
  146. wall.End = Point(x=start.x - wall.width/2, y=start.y + length)
  147. ne = NE(x=start.x, y=start.y)
  148. wall.ne = ne
  149. wall.se = SE(x=ne.x, y=ne.y + length)
  150. wall.nw = NW(x=ne.x - wall.width, y=ne.y)
  151. wall.sw = SW(x=ne.x - wall.width, y=ne.y + length)
  152.  
  153. elif isinstance(start, NW):
  154. wall.Start = Point(x=start.x + wall.width/2, y=start.y)
  155. wall.End = Point(x=start.x + wall.width/2, y=start.y + length)
  156. ne = NE(x=start.x + wall.width, y=start.y)
  157. wall.ne = ne
  158. wall.se = SE(x=ne.x, y=ne.y + length)
  159. wall.nw = NW(x=ne.x - wall.width, y=ne.y)
  160. wall.sw = SW(x=ne.x - wall.width, y=ne.y + length)
  161.  
  162. elif isinstance(start, SE):
  163. wall.Start = Point(x=start.x - wall.width/2, y=start.y)
  164. wall.End = Point(x=start.x - wall.width/2, y=start.y - length)
  165. ne = NE(x=start.x, y=start.y-length)
  166. wall.ne = ne
  167. wall.se = SE(x=ne.x, y=ne.y + length)
  168. wall.nw = NW(x=ne.x - wall.width, y=ne.y)
  169. wall.sw = SW(x=ne.x - wall.width, y=ne.y + length)
  170. elif isinstance(start, SW):
  171. wall.Start = Point(x=start.x + wall.width/2, y=start.y)
  172. wall.End = Point(x=start.x + wall.width/2, y=start.y - length)
  173. ne = NE(x=start.x + wall.width, y=start.y-length)
  174. wall.ne = ne
  175. wall.se = SE(x=ne.x, y=ne.y + length)
  176. wall.nw = NW(x=ne.x - wall.width, y=ne.y)
  177. wall.sw = SW(x=ne.x - wall.width, y=ne.y + length)
  178. else:
  179. raise ValueError()
  180.  
  181. if wallAtStart is not None:
  182. wall.link(wallAtStart)
  183. return wall
  184.  
  185.  
  186. def VOuterWall(wid, start: Point, length: int, wallAtStart: Wall = None):
  187. wall = Wall()
  188. wall.Prefix = "Outer"
  189. wall.width = 408
  190. wall.ID = wid
  191. if isinstance(start, NE):
  192. wall.Start = Point(x=start.x, y=start.y + wall.width/2)
  193. wall.End = Point(x=start.x - length, y=start.y + wall.width/2)
  194. ne = NE(x=start.x, y=start.y)
  195. wall.ne = ne
  196. wall.se = SE(x=ne.x, y=ne.y + wall.width)
  197. wall.nw = NW(x=ne.x - length, y=ne.y)
  198. wall.sw = SW(x=ne.x - length, y=ne.y + wall.width)
  199. elif isinstance(start, NW):
  200. wall.Start = Point(x=start.x, y=start.y + wall.width/2)
  201. wall.End = Point(x=start.x + length, y=start.y + wall.width/2)
  202. ne = NE(x=start.x+length, y=start.y)
  203. wall.ne = ne
  204. wall.se = SE(x=ne.x, y=ne.y + wall.width)
  205. wall.nw = NW(x=ne.x - length, y=ne.y)
  206. wall.sw = SW(x=ne.x - length, y=ne.y + wall.width)
  207. elif isinstance(start, SE):
  208. wall.Start = Point(x=start.x, y=start.y - wall.width/2)
  209. wall.End = Point(x=start.x - length, y=start.y - wall.width/2)
  210. ne = NE(x=start.x, y=start.y-wall.width)
  211. wall.ne = ne
  212. wall.se = SE(x=ne.x, y=ne.y + wall.width)
  213. wall.nw = NW(x=ne.x - length, y=ne.y)
  214. wall.sw = SW(x=ne.x - length, y=ne.y + wall.width)
  215. elif isinstance(start, SW):
  216. wall.Start = Point(x=start.x, y=start.y - wall.width/2)
  217. wall.End = Point(x=start.x + length, y=start.y - wall.width/2)
  218. ne = NE(x=start.x+length, y=start.y-wall.width)
  219. wall.ne = ne
  220. wall.se = SE(x=ne.x, y=ne.y + wall.width)
  221. wall.nw = NW(x=ne.x - length, y=ne.y)
  222. wall.sw = SW(x=ne.x - length, y=ne.y + wall.width)
  223. else:
  224. raise ValueError()
  225. if wallAtStart is not None:
  226. wall.link(wallAtStart)
  227. return wall
  228.  
  229.  
  230. def dimline(start: Point, end: Point, offset: int=40):
  231. return f"<dimensionLine xStart='{start.x/10}' yStart='{start.y/10}' xEnd='{end.x/10}' yEnd='{end.y/10}' offset='{-offset}'/>"
  232.  
  233.  
  234. class InnerWall(Wall):
  235. Prefix: str = "inner"
  236. width: int = 100
  237.  
  238. def __init__(self, wid, start, end, wallAtStart: Wall = None):
  239. self.Start = start
  240. self.End = end
  241. self.ID = wid
  242. if wallAtStart is not None:
  243. self.link(wallAtStart)
  244.  
  245. @dataclasses.dataclass
  246. class Room:
  247. width: int
  248. length: int
  249.  
  250. def main():
  251. ows = []
  252. wid = 0
  253. xml_path = Path('C:/Users/live/Desktop/Empty/Home.xml')
  254. zip_path = Path('C:/Users/live/Desktop/Empty/Home.sh3x')
  255.  
  256. office = Room(width=3010, length=3672)
  257. kitchen = Room(width=1998+912+200, length=4100)
  258. livingroom = Room(width=4112, length=3772)
  259. masterbedroom = Room(width=3910, length=2743+912+100)
  260. bath1 = Room(width=1200+912+1798, length=1750)
  261. spare1 = Room(width=3910, length=2502)
  262. bath2 = Room(width=2102, length=2015)
  263. spare2 = Room(width=3332, length=2970)
  264. bryggers = Room(width=2400, length=3203)
  265.  
  266.  
  267.  
  268. wid = wid + 1
  269. length = 1500 + OuterWall.width + kitchen.length + InnerWall.width + office.length + OuterWall.width
  270. # 10.188
  271. sw = SW(x=0, y=length)
  272. last = HOuterWall(wid, sw, length)
  273. ows.append(last)
  274. ows.append(dimline(last.sw, last.nw))
  275.  
  276. wid = wid + 1
  277. length = OuterWall.width + office.width + InnerWall.width + livingroom.width + InnerWall.width + masterbedroom.width + OuterWall.width
  278. # 12.048
  279. last = VOuterWall(wid, last.nw, length, last)
  280. ows.append(last)
  281. ows.append(dimline(last.nw, last.ne))
  282.  
  283. wid = wid + 1
  284. length = OuterWall.width + masterbedroom.length + InnerWall.width + bath1.length + InnerWall.width + spare1.length + InnerWall.width + bath2.length + InnerWall.width + spare2.length + OuterWall.width
  285. # 14.206
  286. last = HOuterWall(wid, last.ne, length, last)
  287. ows.append(last)
  288. ows.append(dimline(last.ne, last.se))
  289.  
  290. wid = wid + 1
  291. length = OuterWall.width + spare2.width + InnerWall.width + bryggers.width + OuterWall.width
  292. # 6.648
  293. last = VOuterWall(wid, last.se, length, last)
  294. ows.append(last)
  295. ows.append(dimline(last.sw, last.se, -40))
  296.  
  297. wid = wid + 1
  298. length = 5520 + OuterWall.width
  299. # 5.928
  300. last = HOuterWall(wid, last.sw, length, last)
  301. ows.append(last)
  302. ows.append(dimline(last.sw, NW(last.nw.x, last.nw.y + OuterWall.width)))
  303.  
  304. wid = wid + 1
  305. length = OuterWall.width + 660 + 2772 + 1560
  306. # 6.648
  307. last = VOuterWall(wid, last.ne, length, last)
  308. ows.append(last)
  309. ows.append(dimline(last.sw, SE(last.se.x-OuterWall.width, last.se.y), -40))
  310.  
  311.  
  312. with xml_path.open('w') as fp:
  313. fp.write(prefile)
  314. for ow in ows:
  315. fp.write(str(ow) + '\n')
  316. fp.write(postfile)
  317.  
  318. subprocess.run([r"C:\Program Files\7-Zip\7z.exe", "a" , zip_path.name, xml_path.name, "-tzip"], cwd=str(xml_path.parent))
  319.  
  320.  
  321. os.startfile(str(zip_path))
  322.  
  323.  
  324. if __name__ == "__main__":
  325. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement