From cabcd6b2d9916faeaeca319d8f7b9d4443322bf3 Mon Sep 17 00:00:00 2001 From: Roy-043 Date: Wed, 31 Jan 2024 11:03:13 +0100 Subject: [PATCH] Arch: Add "Opening only" preset to Arch_Window As discussed on the forum: https://forum.freecad.org/viewtopic.php?p=734920#p734920 --- src/Mod/Arch/ArchWindow.py | 65 ++++----- src/Mod/Arch/ArchWindowPresets.py | 46 ++++--- .../Arch/Resources/ui/ParametersOpening.svg | 126 ++++++++++++++++++ 3 files changed, 189 insertions(+), 48 deletions(-) create mode 100644 src/Mod/Arch/Resources/ui/ParametersOpening.svg diff --git a/src/Mod/Arch/ArchWindow.py b/src/Mod/Arch/ArchWindow.py index 7a9d8b7212..2afbdfb367 100644 --- a/src/Mod/Arch/ArchWindow.py +++ b/src/Mod/Arch/ArchWindow.py @@ -94,7 +94,7 @@ def makeWindow(baseobj=None,width=None,height=None,parts=None,name=None): if baseobj: obj.Normal = baseobj.Placement.Rotation.multVec(FreeCAD.Vector(0,0,-1)) obj.Base = baseobj - if parts: + if parts is not None: obj.WindowParts = parts else: if baseobj: @@ -512,40 +512,41 @@ class _CommandWindow: self.im.load(":/ui/ParametersWindowFixed.svg") elif i in [1,8]: self.im.load(":/ui/ParametersWindowSimple.svg") - elif i == 6: - self.im.load(":/ui/ParametersDoorGlass.svg") + elif i in [2,4,7]: + self.im.load(":/ui/ParametersWindowDouble.svg") elif i == 3: self.im.load(":/ui/ParametersWindowStash.svg") elif i == 5: self.im.load(":/ui/ParametersDoorSimple.svg") + elif i == 6: + self.im.load(":/ui/ParametersDoorGlass.svg") + elif i == 9: + self.im.load(":/ui/ParametersOpening.svg") else: - if i >= len(WindowPresets): - # From Library - self.im.hide() - path = self.librarypresets[i-len(WindowPresets)][1] - if path.lower().endswith(".fcstd"): - try: - import tempfile - import zipfile - except Exception: - pass - else: - zfile = zipfile.ZipFile(path) - files = zfile.namelist() - # check for meta-file if it's really a FreeCAD document - if files[0] == "Document.xml": - image="thumbnails/Thumbnail.png" - if image in files: - image = zfile.read(image) - thumbfile = tempfile.mkstemp(suffix='.png')[1] - thumb = open(thumbfile,"wb") - thumb.write(image) - thumb.close() - im = QtGui.QPixmap(thumbfile) - self.pic.setPixmap(im) - self.pic.show() - else: - self.im.load(":/ui/ParametersWindowDouble.svg") + # From Library + self.im.hide() + path = self.librarypresets[i-len(WindowPresets)][1] + if path.lower().endswith(".fcstd"): + try: + import tempfile + import zipfile + except Exception: + pass + else: + zfile = zipfile.ZipFile(path) + files = zfile.namelist() + # check for meta-file if it's really a FreeCAD document + if files[0] == "Document.xml": + image="thumbnails/Thumbnail.png" + if image in files: + image = zfile.read(image) + thumbfile = tempfile.mkstemp(suffix='.png')[1] + thumb = open(thumbfile,"wb") + thumb.write(image) + thumb.close() + im = QtGui.QPixmap(thumbfile) + self.pic.setPixmap(im) + self.pic.show() #for param in self.wparams: # getattr(self,"val"+param).setEnabled(True) else: @@ -912,7 +913,7 @@ class _Window(ArchComponent.Component): if shapes: base = Part.makeCompound(shapes) elif not obj.WindowParts: - if not obj.Base.Shape.isNull(): + if obj.Base.Shape.Solids: base = obj.Base.Shape.copy() # obj placement is already added by applyShape() below #if not DraftGeomUtils.isNull(pl): @@ -941,6 +942,8 @@ class _Window(ArchComponent.Component): #base = Part.makeCompound([base]+self.sshapes+self.vshapes) self.applyShape(obj,base,pl,allowinvalid=True,allownosolid=True) obj.Placement = pl + else: + obj.Shape = Part.Shape() if hasattr(obj,"Area"): obj.Area = obj.Width.Value * obj.Height.Value diff --git a/src/Mod/Arch/ArchWindowPresets.py b/src/Mod/Arch/ArchWindowPresets.py index bad21dbdb8..4c0577929c 100644 --- a/src/Mod/Arch/ArchWindowPresets.py +++ b/src/Mod/Arch/ArchWindowPresets.py @@ -25,8 +25,8 @@ from FreeCAD import Vector from draftutils.translate import translate -WindowPresets = ["Fixed", "Open 1-pane", "Open 2-pane", "Sash 2-pane", - "Sliding 2-pane", "Simple door", "Glass door", "Sliding 4-pane", "Awning"] +WindowPresets = ["Fixed", "Open 1-pane", "Open 2-pane", "Sash 2-pane", "Sliding 2-pane", + "Simple door", "Glass door", "Sliding 4-pane", "Awning", "Opening only"] def makeWindowPreset(windowtype,width,height,h1,h2,h3,w1,w2,o1,o2,placement=None): @@ -62,9 +62,9 @@ def makeWindowPreset(windowtype,width,height,h1,h2,h3,w1,w2,o1,o2,placement=None gla = 10 s = FreeCAD.ActiveDocument.addObject('Sketcher::SketchObject','Sketch') - def addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8): + def addRectangle(s,p1,p2,p3,p4): - "adds two rectangles to the given sketch" + "adds a rectangle to the given sketch" idx = s.GeometryCount s.addGeometry(Part.LineSegment(p1,p2)) @@ -79,18 +79,13 @@ def makeWindowPreset(windowtype,width,height,h1,h2,h3,w1,w2,o1,o2,placement=None s.addConstraint(Sketcher.Constraint('Horizontal',idx+2)) s.addConstraint(Sketcher.Constraint('Vertical',idx+1)) s.addConstraint(Sketcher.Constraint('Vertical',idx+3)) - s.addGeometry(Part.LineSegment(p5,p6)) - s.addGeometry(Part.LineSegment(p6,p7)) - s.addGeometry(Part.LineSegment(p7,p8)) - s.addGeometry(Part.LineSegment(p8,p5)) - s.addConstraint(Sketcher.Constraint('Coincident',idx+4,2,idx+5,1)) - s.addConstraint(Sketcher.Constraint('Coincident',idx+5,2,idx+6,1)) - s.addConstraint(Sketcher.Constraint('Coincident',idx+6,2,idx+7,1)) - s.addConstraint(Sketcher.Constraint('Coincident',idx+7,2,idx+4,1)) - s.addConstraint(Sketcher.Constraint('Horizontal',idx+4)) - s.addConstraint(Sketcher.Constraint('Horizontal',idx+6)) - s.addConstraint(Sketcher.Constraint('Vertical',idx+5)) - s.addConstraint(Sketcher.Constraint('Vertical',idx+7)) + + def addFrame(s,p1,p2,p3,p4,p5,p6,p7,p8): + + "adds two rectangles to the given sketch" + + addRectangle(s,p1,p2,p3,p4) + addRectangle(s,p5,p6,p7,p8) def simpleFrame(s,width,height,h1,h2,tol): @@ -489,6 +484,20 @@ def makeWindowPreset(windowtype,width,height,h1,h2,h3,w1,w2,o1,o2,placement=None wp.extend(["InnerFrame","Frame","Wire2,Wire3,Edge8,Mode1",fw,str(o2)+"+V"]) wp.extend(["InnerGlass","Glass panel","Wire3",str(w2/gla),str(o2+w2/2)+"+V"]) + elif windowtype == "Opening only": + + wp = [] + p1 = Vector(0,0,0) + p2 = Vector(width,0,0) + p3 = Vector(width,height,0) + p4 = Vector(0,height,0) + addRectangle(s,p1,p2,p3,p4) + s.addConstraint(Sketcher.Constraint('Coincident',0,1,-1,1)) + s.addConstraint(Sketcher.Constraint('DistanceX',0,width)) + s.addConstraint(Sketcher.Constraint('DistanceY',1,height)) + s.renameConstraint(9,'Width') + s.renameConstraint(10,'Height') + return (s,wp) if windowtype in WindowPresets: @@ -504,9 +513,12 @@ def makeWindowPreset(windowtype,width,height,h1,h2,h3,w1,w2,o1,o2,placement=None obj.Frame = w2 obj.Offset = o1 obj.Placement = FreeCAD.Placement() # unable to find where this bug comes from... - if "door" in windowtype: + if "door" in windowtype.lower(): obj.IfcType = "Door" obj.Label = translate("Arch","Door") + elif "opening" in windowtype.lower(): + obj.IfcType = "Opening Element" + obj.Label = translate("Arch","Opening") FreeCAD.ActiveDocument.recompute() return obj diff --git a/src/Mod/Arch/Resources/ui/ParametersOpening.svg b/src/Mod/Arch/Resources/ui/ParametersOpening.svg new file mode 100644 index 0000000000..45af0a1bb8 --- /dev/null +++ b/src/Mod/Arch/Resources/ui/ParametersOpening.svg @@ -0,0 +1,126 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + WIDTH + HEIGHT + + + + + + +