Arch: BuildingParts autogrouping

Arch BuildingParts now gained a new set of View properties that allows
to define a "capture box". Subsequent Draft and Arch objects, or anything
else that uses Draft.autogroup(), will be automatically added to that
BuildingPart if they are inside the capture box.
This commit is contained in:
Yorik van Havre
2021-10-14 14:42:46 +02:00
parent d95f085760
commit 0e7314068c
2 changed files with 79 additions and 1 deletions

View File

@@ -411,12 +411,13 @@ class BuildingPart(ArchIFC.IfcProduct):
print("angle after rotation:",shape.Placement.Rotation.Angle)
child.Placement = shape.Placement
if deltap:
print("moving child")
print("moving child",child.Label)
child.Placement.move(deltap)
def execute(self,obj):
# gather all the child shapes into a compound
pl = obj.Placement
shapes,materialstable = self.getShapes(obj)
if shapes:
import Part
@@ -430,8 +431,12 @@ class BuildingPart(ArchIFC.IfcProduct):
#print("recomputing ",obj.Label)
else:
obj.Shape = Part.makeCompound(shapes)
obj.Placement = pl
obj.Area = self.getArea(obj)
obj.MaterialsTable = materialstable
if obj.ViewObject:
# update the autogroup box if needed
obj.ViewObject.Proxy.onChanged(obj.ViewObject,"AutoGroupBox")
def getArea(self,obj):
@@ -498,6 +503,28 @@ class BuildingPart(ArchIFC.IfcProduct):
g.append(child)
obj.Group = g
def autogroup(self,obj,child):
"Adds an object to the group of this BuildingPart automatically"
if obj.ViewObject:
if hasattr(obj.ViewObject.Proxy,"autobbox") and obj.ViewObject.Proxy.autobbox:
if hasattr(child,"Shape") and child.Shape:
abb = obj.ViewObject.Proxy.autobbox
cbb = child.Shape.BoundBox
if abb.isValid():
if not cbb.isValid():
FreeCAD.ActiveDocument.recompute()
if not cbb.isValid():
cbb = FreeCAD.BoundBox()
for v in child.Shape.Vertexes:
print(v.Point)
cbb.add(v.Point)
if cbb.isValid() and abb.isInside(cbb):
self.addObject(obj,child)
return True
return False
class ViewProviderBuildingPart:
@@ -589,6 +616,16 @@ class ViewProviderBuildingPart:
if not "AutoCutView" in pl:
vobj.addProperty("App::PropertyBool","AutoCutView","Clip",QT_TRANSLATE_NOOP("App::Property","Turn cutting on when activating this level"))
# autogroup properties
if not "AutogroupSize" in pl:
vobj.addProperty("App::PropertyIntegerList","AutogroupSize","AutoGroup",QT_TRANSLATE_NOOP("App::Property","The capture box for newly created objects expressed as [XMin,YMin,ZMin,XMax,YMax,ZMax]"))
if not "AutogroupBox" in pl:
vobj.addProperty("App::PropertyBool","AutogroupBox","AutoGroup",QT_TRANSLATE_NOOP("App::Property","Turns auto group box on/off"))
if not "AutogroupAutosize" in pl:
vobj.addProperty("App::PropertyBool","AutogroupAutosize","AutoGroup",QT_TRANSLATE_NOOP("App::Property","Automatically set size from contents"))
if not "AutogroupMargin" in pl:
vobj.addProperty("App::PropertyLength","AutogroupMargin","AutoGroup",QT_TRANSLATE_NOOP("App::Property","A margin to use when autosize is turned on"))
def onDocumentRestored(self,vobj):
self.setProperties(vobj)
@@ -618,6 +655,21 @@ class ViewProviderBuildingPart:
lin = coin.SoType.fromName("SoBrepEdgeSet").createInstance()
lin.coordIndex.setValues([0,1,-1,2,3,-1,4,5,-1])
self.sep.addChild(lin)
self.bbox = coin.SoSwitch()
self.bbox.whichChild = -1
bboxsep = coin.SoSeparator()
self.bbox.addChild(bboxsep)
drawstyle = coin.SoDrawStyle()
drawstyle.style = coin.SoDrawStyle.LINES
drawstyle.lineWidth = 3
drawstyle.linePattern = 0x0f0f # 0xaa
bboxsep.addChild(drawstyle)
self.bbco = coin.SoCoordinate3()
bboxsep.addChild(self.bbco)
lin = coin.SoIndexedLineSet()
lin.coordIndex.setValues([0,1,2,3,0,-1,4,5,6,7,4,-1,0,4,-1,1,5,-1,2,6,-1,3,7,-1])
bboxsep.addChild(lin)
self.sep.addChild(self.bbox)
self.tra = coin.SoTransform()
self.tra.rotation.setValue(FreeCAD.Rotation(0,0,90).Q)
self.sep.addChild(self.tra)
@@ -632,6 +684,8 @@ class ViewProviderBuildingPart:
self.onChanged(vobj,"FontName")
self.onChanged(vobj,"ShowLevel")
self.onChanged(vobj,"FontSize")
self.onChanged(vobj,"AutogroupBox")
self.setProperties(vobj)
return
def getDisplayModes(self,vobj):
@@ -793,6 +847,23 @@ class ViewProviderBuildingPart:
vobj.CutView = False
elif prop == "SaveInventor":
self.writeInventor(vobj.Object)
elif prop in ["AutogroupBox","AutogroupSize"]:
if hasattr(vobj,"AutogroupBox") and hasattr(vobj,"AutogroupSize"):
if vobj.AutogroupBox:
if len(vobj.AutogroupSize) >= 6:
self.autobbox = FreeCAD.BoundBox(*vobj.AutogroupSize[0:6])
self.autobbox.move(vobj.Object.Placement.Base)
pts = [list(self.autobbox.getPoint(i)) for i in range(8)]
self.bbco.point.setValues(pts)
self.bbox.whichChild = 0
else:
self.autobbox = None
self.bbox.whichChild = -1
elif prop in ["AutogroupAutosize","AutogroupMargin"]:
if hasattr(vobj,"AutogroupAutosize") and vobj.AutogroupAutosize:
bbox = vobj.Object.Shape.BoundBox
bbox.enlarge(vobj.AutogroupMargin.Value)
vobj.AutogroupSize = [int(i) for i in [bbox.XMin,bbox.YMin,bbox.ZMin,bbox.XMax,bbox.YMax,bbox.ZMax]]
def onDelete(self,vobj,subelements):

View File

@@ -115,6 +115,13 @@ def autogroup(obj):
if Gui.draftToolBar.isConstructionMode():
return
# check first for objects that do autogroup themselves
# at the moment only Arch_BuildingPart, which is an App::GeometryPython
for par in App.ActiveDocument.findObjects(Type="App::GeometryPython"):
if hasattr(par.Proxy,"autogroup"):
if par.Proxy.autogroup(par,obj):
return
# autogroup code
if Gui.draftToolBar.autogroup is not None:
active_group = App.ActiveDocument.getObject(Gui.draftToolBar.autogroup)