Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import dataclasses
- import math
- import os
- import subprocess
- import shutil
- from pathlib import Path
- prefile = '''<?xml version='1.0'?>
- <home version='6000' name='Empty.sh3d' camera='topCamera' wallHeight='260.0'>
- <property name='com.eteks.sweethome3d.SweetHome3D.CatalogPaneDividerLocation' value='451'/>
- <property name='com.eteks.sweethome3d.SweetHome3D.Columnwidths' value='189,117,119,117,116'/>
- <property name='com.eteks.sweethome3d.SweetHome3D.FrameHeight' value='1121'/>
- <property name='com.eteks.sweethome3d.SweetHome3D.Framewidth' value='2090'/>
- <property name='com.eteks.sweethome3d.SweetHome3D.FrameX' value='224'/>
- <property name='com.eteks.sweethome3d.SweetHome3D.FrameY' value='224'/>
- <property name='com.eteks.sweethome3d.SweetHome3D.MainPaneDividerLocation' value='663'/>
- <property name='com.eteks.sweethome3d.SweetHome3D.PlanPaneDividerLocation' value='711'/>
- <property name='com.eteks.sweethome3d.SweetHome3D.PlanScale' value='1.3035849'/>
- <property name='com.eteks.sweethome3d.SweetHome3D.PlanViewportX' value='9'/>
- <property name='com.eteks.sweethome3d.SweetHome3D.PlanViewportY' value='0'/>
- <property name='com.eteks.sweethome3d.SweetHome3D.ScreenHeight' value='1402'/>
- <property name='com.eteks.sweethome3d.SweetHome3D.Screenwidth' value='2560'/>
- <furnitureVisibleProperty name='NAME'/>
- <furnitureVisibleProperty name='width'/>
- <furnitureVisibleProperty name='DEPTH'/>
- <furnitureVisibleProperty name='HEIGHT'/>
- <furnitureVisibleProperty name='VISIBLE'/>
- <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'/>
- <compass x='-100.0' y='50.0' diameter='100.0' northDirection='0.0' longitude='0.040724345' latitude='0.8528843' timeZone='Europe/Paris'/>
- <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'/>
- <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'/>
- <!-- Ydermuren 408mm x 2600mm -->
- '''
- postfile = '''</home>
- '''
- @dataclasses.dataclass
- class Point:
- x: int
- y: int
- def distance(self, other: 'Point'):
- return math.sqrt((self.x-other.x)**2 + (self.y-other.y)**2)
- @classmethod
- def from_point(cls, other: 'Point'):
- return cls(other.x, other.y)
- class NW(Point):
- pass
- class SW(Point):
- pass
- class NE(Point):
- pass
- class SE(Point):
- pass
- class Wall:
- Prefix: str = "wall"
- ID: int
- Start: Point
- End: Point
- width: int = 1000
- height: int = 2600
- Pattern: str = "hatchUp"
- WallAtStart: 'Wall' = None
- WallAtEnd: 'Wall' = None
- ne: Point = None
- nw: Point = None
- se: Point = None
- sw: Point = None
- @property
- def name(self):
- return f"{self.Prefix }{self.ID}"
- def __str__(self):
- factor = 10
- tags = []
- tags.append(f"id='{self.name}'")
- if self.WallAtStart is not None:
- tags.append(f"wallAtStart='{self.WallAtStart.name}'")
- if self.WallAtEnd is not None:
- tags.append(f"wallAtEnd='{self.WallAtEnd.name}'")
- tags.append(f"xStart='{self.Start.x/factor}'")
- tags.append(f"yStart='{self.Start.y/factor}'")
- tags.append(f"xEnd='{self.End.x/factor}'")
- tags.append(f"yEnd='{self.End.y/factor}'")
- tags.append(f"height='{self.height/factor}'")
- tags.append(f"thickness='{self.width/factor}'")
- tags.append(f"pattern='{self.Pattern}'")
- return f" <wall {' '.join(tags)}/>"
- def link(self, other: 'Wall'):
- if self.Start.x - self.End.x == 0:
- if self.Start.y > self.End.y:
- self.Start.y = self.Start.y - (self.width / 2)
- else:
- self.Start.y = self.Start.y + (self.width / 2)
- elif self.Start.y - self.End.y == 0:
- if self.Start.x > self.End.x:
- self.Start.x = self.Start.x - (self.width / 2)
- else:
- self.Start.x = self.Start.x + (self.width / 2)
- if other.Start.x - other.End.x == 0:
- if other.End.y > other.Start.y:
- other.End.y = other.End.y - (other.width / 2)
- else:
- other.End.y = other.End.y + (other.width / 2)
- elif other.Start.y - other.End.y == 0:
- if other.End.x > other.Start.x:
- other.End.x = other.End.x - (other.width / 2)
- else:
- other.End.x = other.End.x + (other.width / 2)
- self.WallAtStart = other
- other.WallAtEnd = self
- class OuterWall(Wall):
- Prefix: str = "outer"
- width: int = 408
- def __init__(self, wid, start, end, wallAtStart: Wall = None):
- self.Start = start
- self.End = end
- self.ID = wid
- if wallAtStart is not None:
- self.link(wallAtStart)
- def HOuterWall(wid, start: Point, length: int, wallAtStart: Wall = None):
- wall = Wall()
- wall.Prefix = "Outer"
- wall.width = 408
- wall.ID = wid
- if isinstance(start, NE):
- wall.Start = Point(x=start.x - wall.width/2, y=start.y)
- wall.End = Point(x=start.x - wall.width/2, y=start.y + length)
- ne = NE(x=start.x, y=start.y)
- wall.ne = ne
- wall.se = SE(x=ne.x, y=ne.y + length)
- wall.nw = NW(x=ne.x - wall.width, y=ne.y)
- wall.sw = SW(x=ne.x - wall.width, y=ne.y + length)
- elif isinstance(start, NW):
- wall.Start = Point(x=start.x + wall.width/2, y=start.y)
- wall.End = Point(x=start.x + wall.width/2, y=start.y + length)
- ne = NE(x=start.x + wall.width, y=start.y)
- wall.ne = ne
- wall.se = SE(x=ne.x, y=ne.y + length)
- wall.nw = NW(x=ne.x - wall.width, y=ne.y)
- wall.sw = SW(x=ne.x - wall.width, y=ne.y + length)
- elif isinstance(start, SE):
- wall.Start = Point(x=start.x - wall.width/2, y=start.y)
- wall.End = Point(x=start.x - wall.width/2, y=start.y - length)
- ne = NE(x=start.x, y=start.y-length)
- wall.ne = ne
- wall.se = SE(x=ne.x, y=ne.y + length)
- wall.nw = NW(x=ne.x - wall.width, y=ne.y)
- wall.sw = SW(x=ne.x - wall.width, y=ne.y + length)
- elif isinstance(start, SW):
- wall.Start = Point(x=start.x + wall.width/2, y=start.y)
- wall.End = Point(x=start.x + wall.width/2, y=start.y - length)
- ne = NE(x=start.x + wall.width, y=start.y-length)
- wall.ne = ne
- wall.se = SE(x=ne.x, y=ne.y + length)
- wall.nw = NW(x=ne.x - wall.width, y=ne.y)
- wall.sw = SW(x=ne.x - wall.width, y=ne.y + length)
- else:
- raise ValueError()
- if wallAtStart is not None:
- wall.link(wallAtStart)
- return wall
- def VOuterWall(wid, start: Point, length: int, wallAtStart: Wall = None):
- wall = Wall()
- wall.Prefix = "Outer"
- wall.width = 408
- wall.ID = wid
- if isinstance(start, NE):
- wall.Start = Point(x=start.x, y=start.y + wall.width/2)
- wall.End = Point(x=start.x - length, y=start.y + wall.width/2)
- ne = NE(x=start.x, y=start.y)
- wall.ne = ne
- wall.se = SE(x=ne.x, y=ne.y + wall.width)
- wall.nw = NW(x=ne.x - length, y=ne.y)
- wall.sw = SW(x=ne.x - length, y=ne.y + wall.width)
- elif isinstance(start, NW):
- wall.Start = Point(x=start.x, y=start.y + wall.width/2)
- wall.End = Point(x=start.x + length, y=start.y + wall.width/2)
- ne = NE(x=start.x+length, y=start.y)
- wall.ne = ne
- wall.se = SE(x=ne.x, y=ne.y + wall.width)
- wall.nw = NW(x=ne.x - length, y=ne.y)
- wall.sw = SW(x=ne.x - length, y=ne.y + wall.width)
- elif isinstance(start, SE):
- wall.Start = Point(x=start.x, y=start.y - wall.width/2)
- wall.End = Point(x=start.x - length, y=start.y - wall.width/2)
- ne = NE(x=start.x, y=start.y-wall.width)
- wall.ne = ne
- wall.se = SE(x=ne.x, y=ne.y + wall.width)
- wall.nw = NW(x=ne.x - length, y=ne.y)
- wall.sw = SW(x=ne.x - length, y=ne.y + wall.width)
- elif isinstance(start, SW):
- wall.Start = Point(x=start.x, y=start.y - wall.width/2)
- wall.End = Point(x=start.x + length, y=start.y - wall.width/2)
- ne = NE(x=start.x+length, y=start.y-wall.width)
- wall.ne = ne
- wall.se = SE(x=ne.x, y=ne.y + wall.width)
- wall.nw = NW(x=ne.x - length, y=ne.y)
- wall.sw = SW(x=ne.x - length, y=ne.y + wall.width)
- else:
- raise ValueError()
- if wallAtStart is not None:
- wall.link(wallAtStart)
- return wall
- def dimline(start: Point, end: Point, offset: int=40):
- return f"<dimensionLine xStart='{start.x/10}' yStart='{start.y/10}' xEnd='{end.x/10}' yEnd='{end.y/10}' offset='{-offset}'/>"
- class InnerWall(Wall):
- Prefix: str = "inner"
- width: int = 100
- def __init__(self, wid, start, end, wallAtStart: Wall = None):
- self.Start = start
- self.End = end
- self.ID = wid
- if wallAtStart is not None:
- self.link(wallAtStart)
- @dataclasses.dataclass
- class Room:
- width: int
- length: int
- def main():
- ows = []
- wid = 0
- xml_path = Path('C:/Users/live/Desktop/Empty/Home.xml')
- zip_path = Path('C:/Users/live/Desktop/Empty/Home.sh3x')
- office = Room(width=3010, length=3672)
- kitchen = Room(width=1998+912+200, length=4100)
- livingroom = Room(width=4112, length=3772)
- masterbedroom = Room(width=3910, length=2743+912+100)
- bath1 = Room(width=1200+912+1798, length=1750)
- spare1 = Room(width=3910, length=2502)
- bath2 = Room(width=2102, length=2015)
- spare2 = Room(width=3332, length=2970)
- bryggers = Room(width=2400, length=3203)
- wid = wid + 1
- length = 1500 + OuterWall.width + kitchen.length + InnerWall.width + office.length + OuterWall.width
- # 10.188
- sw = SW(x=0, y=length)
- last = HOuterWall(wid, sw, length)
- ows.append(last)
- ows.append(dimline(last.sw, last.nw))
- wid = wid + 1
- length = OuterWall.width + office.width + InnerWall.width + livingroom.width + InnerWall.width + masterbedroom.width + OuterWall.width
- # 12.048
- last = VOuterWall(wid, last.nw, length, last)
- ows.append(last)
- ows.append(dimline(last.nw, last.ne))
- wid = wid + 1
- length = OuterWall.width + masterbedroom.length + InnerWall.width + bath1.length + InnerWall.width + spare1.length + InnerWall.width + bath2.length + InnerWall.width + spare2.length + OuterWall.width
- # 14.206
- last = HOuterWall(wid, last.ne, length, last)
- ows.append(last)
- ows.append(dimline(last.ne, last.se))
- wid = wid + 1
- length = OuterWall.width + spare2.width + InnerWall.width + bryggers.width + OuterWall.width
- # 6.648
- last = VOuterWall(wid, last.se, length, last)
- ows.append(last)
- ows.append(dimline(last.sw, last.se, -40))
- wid = wid + 1
- length = 5520 + OuterWall.width
- # 5.928
- last = HOuterWall(wid, last.sw, length, last)
- ows.append(last)
- ows.append(dimline(last.sw, NW(last.nw.x, last.nw.y + OuterWall.width)))
- wid = wid + 1
- length = OuterWall.width + 660 + 2772 + 1560
- # 6.648
- last = VOuterWall(wid, last.ne, length, last)
- ows.append(last)
- ows.append(dimline(last.sw, SE(last.se.x-OuterWall.width, last.se.y), -40))
- with xml_path.open('w') as fp:
- fp.write(prefile)
- for ow in ows:
- fp.write(str(ow) + '\n')
- fp.write(postfile)
- subprocess.run([r"C:\Program Files\7-Zip\7z.exe", "a" , zip_path.name, xml_path.name, "-tzip"], cwd=str(xml_path.parent))
- os.startfile(str(zip_path))
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement