Arch: Added Arch/Utilities/Toggle Subcomponent Display command

This commit is contained in:
Yorik van Havre
2016-09-10 14:44:00 -03:00
parent 1df315160d
commit a932f7a363
6 changed files with 548 additions and 4 deletions

View File

@@ -66,6 +66,9 @@ def getDefaultColor(objectType):
c = p.GetUnsigned("RebarColor",3111475967)
elif objectType == "Panel":
c = p.GetUnsigned("PanelColor",3416289279)
elif objectType == "Construction":
c = Draft.getParam("constructioncolor",746455039)
transparency = 0.80
else:
c = p.GetUnsigned("WindowsColor",810781695)
r = float((c>>24)&0xFF)/255.0
@@ -85,6 +88,7 @@ def addComponents(objectsList,host):
c = host.Group
for o in objectsList:
if not o in c:
setAsSubcomponent(o)
c.append(o)
host.Group = c
elif hostType in ["Wall","Structure","Window","Roof","Stairs","StructuralSystem","Panel"]:
@@ -97,12 +101,15 @@ def addComponents(objectsList,host):
if DraftGeomUtils.isValidPath(o.Shape) and (hostType == "Structure"):
if o.Support == host:
o.Support = None
setAsSubcomponent(o)
host.Tool = o
elif Draft.getType(o) == "Axis":
if not o in x:
setAsSubcomponent(o)
x.append(o)
elif not o in a:
if hasattr(o,"Shape"):
setAsSubcomponent(o)
a.append(o)
host.Additions = a
if hasattr(host,"Axes"):
@@ -111,12 +118,14 @@ def addComponents(objectsList,host):
a = host.Objects
for o in objectsList:
if not o in a:
setAsSubcomponent(o)
a.append(o)
host.Objects = a
elif host.isDerivedFrom("App::DocumentObjectGroup"):
c = host.Group
for o in objectsList:
if not o in c:
setAsSubcomponent(o)
c.append(o)
host.Group = c
@@ -141,6 +150,7 @@ def removeComponents(objectsList,host=None):
s = host.Subtractions
for o in objectsList:
if not o in s:
setAsSubcomponent(o)
s.append(o)
fixDAG(o)
if FreeCAD.GuiUp:
@@ -201,6 +211,17 @@ def makeComponent(baseobj=None,name="Component",delete=False):
obj.Shape = baseobj
return obj
def setAsSubcomponent(obj):
'''Sets the given object properly to become a subcomponent (addition, subtraction)
of an Arch component'''
Draft.ungroup(obj)
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetBool("applyConstructionStyle",True):
if FreeCAD.GuiUp:
color = getDefaultColor("Construction")
obj.ViewObject.LineColor = color
obj.ViewObject.ShapeColor = color
obj.ViewObject.Transparency = int(color[3]*100)
def fixDAG(obj):
'''fixDAG(object): Fixes non-DAG problems in windows and rebars
by removing supports and external geometry from underlying sketches'''
@@ -1275,6 +1296,32 @@ class _CommandIfcSpreadsheet:
FreeCAD.ActiveDocument.commitTransaction()
FreeCAD.ActiveDocument.recompute()
class _ToggleSubcomponentDisplay:
"the Toggle SubcomponentDisplay command definition"
def GetResources(self):
return {'Pixmap' : 'Arch_ToggleSubcomponentDisplay',
'MenuText': QtCore.QT_TRANSLATE_NOOP("Arch_ToggleSubcomponentDisplay","Toggle subcomponents"),
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Arch_ToggleSubcomponentDisplay","Shows or hides the subcomponents of this object")}
def IsActive(self):
return bool(FreeCADGui.Selection.getSelection())
def Activated(self):
mode = None
for obj in FreeCADGui.Selection.getSelection():
if hasattr(obj, "Subtractions"):
for sub in obj.Subtractions:
if not (Draft.getType(sub) in ["Window","Roof"]):
if mode == None:
# take the first sub as base
mode = sub.ViewObject.isVisible()
if mode == True:
sub.ViewObject.hide()
else:
sub.ViewObject.show()
if FreeCAD.GuiUp:
FreeCADGui.addCommand('Arch_Add',_CommandAdd())
FreeCADGui.addCommand('Arch_Remove',_CommandRemove())
@@ -1289,3 +1336,4 @@ if FreeCAD.GuiUp:
FreeCADGui.addCommand('Arch_ToggleIfcBrepFlag',_ToggleIfcBrepFlag())
FreeCADGui.addCommand('Arch_Component',_CommandComponent())
FreeCADGui.addCommand('Arch_IfcSpreadsheet',_CommandIfcSpreadsheet())
FreeCADGui.addCommand('Arch_ToggleSubcomponentDisplay',_ToggleSubcomponentDisplay())

View File

@@ -31,7 +31,7 @@ Roles = ['Undefined','Beam','Chimney','Column','Covering','Curtain Wall',
'Member','Plate','Railing','Ramp','Ramp Flight','Rebar','Pile','Roof','Shading Device','Slab','Space',
'Stair','Stair Flight','Tendon','Wall','Wall Layer','Window']
import FreeCAD,Draft
import FreeCAD,Draft,ArchCommands
from FreeCAD import Vector
if FreeCAD.GuiUp:
import FreeCADGui
@@ -77,6 +77,7 @@ def addToComponent(compobject,addobject,mod=None):
l.append(addobject)
setattr(compobject,mod,l)
if mod != "Objects":
ArchCommands.setAsSubcomponent(addobject)
addobject.ViewObject.hide()
else:
for a in attribs[:3]:
@@ -116,6 +117,7 @@ def removeFromComponent(compobject,subobject):
l.append(subobject)
compobject.Subtractions = l
if (Draft.getType(subobject) != "Window") and (not Draft.isClone(subobject,"Window",True)):
ArchCommands.setAsSubcomponent(subobject)
subobject.ViewObject.hide()

View File

@@ -44,7 +44,7 @@ class ArchWorkbench(Workbench):
"Arch_SelectNonSolidMeshes","Arch_RemoveShape",
"Arch_CloseHoles","Arch_MergeWalls","Arch_Check",
"Arch_IfcExplorer","Arch_ToggleIfcBrepFlag","Arch_3Views",
"Arch_Bimserver","Arch_Git","Arch_IfcSpreadsheet"]
"Arch_Bimserver","Arch_Git","Arch_IfcSpreadsheet","Arch_ToggleSubcomponentDisplay"]
# draft tools
self.drafttools = ["Draft_Line","Draft_Wire","Draft_Circle","Draft_Arc","Draft_Ellipse",

View File

@@ -70,6 +70,7 @@
<file>icons/Arch_Pipe.svg</file>
<file>icons/Arch_Pipe_Tree.svg</file>
<file>icons/Arch_PipeConnector.svg</file>
<file>icons/Arch_ToggleSubcomponentDisplay.svg</file>
<file>ui/ParametersWindowDouble.svg</file>
<file>ui/ParametersWindowSimple.svg</file>
<file>ui/ParametersWindowFixed.svg</file>

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>407</width>
<height>646</height>
<width>396</width>
<height>638</height>
</rect>
</property>
<property name="windowTitle">
@@ -86,6 +86,26 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_7">
<property name="toolTip">
<string>If this is checked, when an object becomes Subtraction or Addition of an Arch object, it will receive the Draft Construction color.</string>
</property>
<property name="text">
<string>Apply Draft construction style to subcomponents</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>applyconstructionStyle</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Arch</cstring>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>