Merge pull request #53 from wood-galaxy/equipement-fix
Arch : Fix ViewProviderComponent if vobj have not DiffuseColor attribute
This commit is contained in:
commit
6a93d1392d
|
@ -1,7 +1,7 @@
|
|||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2011 *
|
||||
#* Yorik van Havre <yorik@uncreated.net> *
|
||||
#* Copyright (c) 2011 *
|
||||
#* Yorik van Havre <yorik@uncreated.net> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
|
@ -27,7 +27,7 @@ __url__ = "http://www.freecadweb.org"
|
|||
|
||||
# Possible roles for IFC objects
|
||||
Roles = ['Undefined','Beam','Chimney','Column','Covering','Curtain Wall',
|
||||
'Door','Foundation','Furniture','Hydro Equipment','Electric Equipment',
|
||||
'Door','Foundation','Furniture','Hydro Equipment','Electric Equipment',
|
||||
'Member','Plate','Railing','Ramp','Ramp Flight','Rebar','Pile','Roof','Shading Device','Slab','Space',
|
||||
'Stair','Stair Flight','Tendon','Wall','Wall Layer','Window']
|
||||
|
||||
|
@ -40,7 +40,7 @@ if FreeCAD.GuiUp:
|
|||
else:
|
||||
def translate(ctxt,txt):
|
||||
return txt
|
||||
|
||||
|
||||
|
||||
def addToComponent(compobject,addobject,mod=None):
|
||||
'''addToComponent(compobject,addobject,mod): adds addobject
|
||||
|
@ -117,31 +117,31 @@ def removeFromComponent(compobject,subobject):
|
|||
compobject.Subtractions = l
|
||||
if (Draft.getType(subobject) != "Window") and (not Draft.isClone(subobject,"Window",True)):
|
||||
subobject.ViewObject.hide()
|
||||
|
||||
|
||||
|
||||
|
||||
class SelectionTaskPanel:
|
||||
"""A temp taks panel to wait for a selection"""
|
||||
def __init__(self):
|
||||
self.form = QtGui.QLabel()
|
||||
self.form.setText(QtGui.QApplication.translate("Arch", "Please select a base object", None, QtGui.QApplication.UnicodeUTF8))
|
||||
|
||||
|
||||
def getStandardButtons(self):
|
||||
return int(QtGui.QDialogButtonBox.Cancel)
|
||||
|
||||
|
||||
def reject(self):
|
||||
if hasattr(FreeCAD,"ArchObserver"):
|
||||
FreeCADGui.Selection.removeObserver(FreeCAD.ArchObserver)
|
||||
del FreeCAD.ArchObserver
|
||||
return True
|
||||
|
||||
|
||||
|
||||
|
||||
class ComponentTaskPanel:
|
||||
'''The default TaskPanel for all Arch components'''
|
||||
def __init__(self):
|
||||
# the panel has a tree widget that contains categories
|
||||
# for the subcomponents, such as additions, subtractions.
|
||||
# the categories are shown only if they are not empty.
|
||||
|
||||
|
||||
self.obj = None
|
||||
self.attribs = ["Base","Additions","Subtractions","Objects","Components","Axes","Fixtures","Armatures"]
|
||||
self.form = QtGui.QWidget()
|
||||
|
@ -156,8 +156,8 @@ class ComponentTaskPanel:
|
|||
self.grid.addWidget(self.tree, 1, 0, 1, 2)
|
||||
self.tree.setColumnCount(1)
|
||||
self.tree.header().hide()
|
||||
|
||||
# buttons
|
||||
|
||||
# buttons
|
||||
self.addButton = QtGui.QPushButton(self.form)
|
||||
self.addButton.setObjectName("addButton")
|
||||
self.addButton.setIcon(QtGui.QIcon(":/icons/Arch_Add.svg"))
|
||||
|
@ -184,7 +184,7 @@ class ComponentTaskPanel:
|
|||
|
||||
def getStandardButtons(self):
|
||||
return int(QtGui.QDialogButtonBox.Ok)
|
||||
|
||||
|
||||
def check(self,wid,col):
|
||||
if not wid.parent():
|
||||
self.delButton.setEnabled(False)
|
||||
|
@ -282,10 +282,10 @@ class ComponentTaskPanel:
|
|||
self.treeSubtractions.setText(0,QtGui.QApplication.translate("Arch", "Subtractions", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.treeObjects.setText(0,QtGui.QApplication.translate("Arch", "Objects", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.treeAxes.setText(0,QtGui.QApplication.translate("Arch", "Axes", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.treeComponents.setText(0,QtGui.QApplication.translate("Arch", "Components", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.treeComponents.setText(0,QtGui.QApplication.translate("Arch", "Components", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.treeFixtures.setText(0,QtGui.QApplication.translate("Arch", "Fixtures", None, QtGui.QApplication.UnicodeUTF8))
|
||||
self.treeArmatures.setText(0,QtGui.QApplication.translate("Arch", "Armatures", None, QtGui.QApplication.UnicodeUTF8))
|
||||
|
||||
|
||||
class Component:
|
||||
"The default Arch Component object"
|
||||
def __init__(self,obj):
|
||||
|
@ -315,10 +315,10 @@ class Component:
|
|||
def __setstate__(self,state):
|
||||
if state:
|
||||
self.Type = state
|
||||
|
||||
|
||||
def onChanged(self,obj,prop):
|
||||
pass
|
||||
|
||||
|
||||
def clone(self,obj):
|
||||
"if this object is a clone, sets the shape. Returns True if this is the case"
|
||||
if hasattr(obj,"CloneOf"):
|
||||
|
@ -332,7 +332,7 @@ class Component:
|
|||
obj.BaseMaterial = obj.CloneOf.BaseMaterial
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def getSiblings(self,obj):
|
||||
"returns a list of objects with the same type and same base as this object"
|
||||
if not hasattr(obj,"Base"):
|
||||
|
@ -396,7 +396,7 @@ class Component:
|
|||
if not DraftGeomUtils.isCoplanar(base.Faces):
|
||||
return []
|
||||
return [base]
|
||||
|
||||
|
||||
basewires = []
|
||||
if not base.Wires:
|
||||
if len(base.Edges) == 1:
|
||||
|
@ -519,7 +519,7 @@ class Component:
|
|||
else:
|
||||
normal = default
|
||||
return normal,length,width,height
|
||||
|
||||
|
||||
def getPlacement(self,obj):
|
||||
"returns a total placement for the profile of this component"
|
||||
p = FreeCAD.Placement()
|
||||
|
@ -548,7 +548,7 @@ class Component:
|
|||
"Adds additions and subtractions to a base shape"
|
||||
import Draft,Part
|
||||
#print "Processing subshapes of ",obj.Label, " : ",obj.Additions
|
||||
|
||||
|
||||
if placement:
|
||||
if placement.isNull():
|
||||
placement = None
|
||||
|
@ -558,15 +558,15 @@ class Component:
|
|||
|
||||
# treat additions
|
||||
for o in obj.Additions:
|
||||
|
||||
|
||||
if not base:
|
||||
if o.isDerivedFrom("Part::Feature"):
|
||||
base = o.Shape
|
||||
else:
|
||||
else:
|
||||
if base.isNull():
|
||||
if o.isDerivedFrom("Part::Feature"):
|
||||
base = o.Shape
|
||||
else:
|
||||
else:
|
||||
# special case, both walls with coinciding endpoints
|
||||
import ArchWall
|
||||
js = ArchWall.mergeShapes(o,obj)
|
||||
|
@ -583,7 +583,7 @@ class Component:
|
|||
if placement:
|
||||
f.Placement = f.Placement.multiply(placement)
|
||||
base = base.cut(f)
|
||||
|
||||
|
||||
elif o.isDerivedFrom("Part::Feature"):
|
||||
if o.Shape:
|
||||
if not o.Shape.isNull():
|
||||
|
@ -599,14 +599,14 @@ class Component:
|
|||
print "Arch: unable to fuse object ",obj.Name, " with ", o.Name
|
||||
else:
|
||||
base = s
|
||||
|
||||
|
||||
# treat subtractions
|
||||
for o in obj.Subtractions:
|
||||
|
||||
|
||||
if base:
|
||||
if base.isNull():
|
||||
base = None
|
||||
|
||||
|
||||
if base:
|
||||
if (Draft.getType(o) == "Window") or (Draft.isClone(o,"Window",True)):
|
||||
# windows can be additions or subtractions, treated the same way
|
||||
|
@ -623,7 +623,7 @@ class Component:
|
|||
if f:
|
||||
if base.Solids and f.Solids:
|
||||
base = base.cut(f)
|
||||
|
||||
|
||||
elif o.isDerivedFrom("Part::Feature"):
|
||||
if o.Shape:
|
||||
if not o.Shape.isNull():
|
||||
|
@ -636,7 +636,7 @@ class Component:
|
|||
except Part.OCCError:
|
||||
print "Arch: unable to cut object ",o.Name, " from ", obj.Name
|
||||
return base
|
||||
|
||||
|
||||
def applyShape(self,obj,shape,placement):
|
||||
"checks and cleans the given shape, and apply it to the object"
|
||||
if shape:
|
||||
|
@ -665,7 +665,7 @@ class ViewProviderComponent:
|
|||
def __init__(self,vobj):
|
||||
vobj.Proxy = self
|
||||
self.Object = vobj.Object
|
||||
|
||||
|
||||
def updateData(self,obj,prop):
|
||||
#print obj.Name," : updating ",prop
|
||||
if prop == "BaseMaterial":
|
||||
|
@ -689,7 +689,7 @@ class ViewProviderComponent:
|
|||
obj.ViewObject.update()
|
||||
self.onChanged(obj.ViewObject,"ShapeColor")
|
||||
return
|
||||
|
||||
|
||||
def getIcon(self):
|
||||
import Arch_rc
|
||||
return ":/icons/Arch_Component.svg"
|
||||
|
@ -709,9 +709,10 @@ class ViewProviderComponent:
|
|||
vobj.update()
|
||||
elif prop == "ShapeColor":
|
||||
# restore DiffuseColor after overridden by ShapeColor
|
||||
if len(vobj.DiffuseColor) > 1:
|
||||
d = vobj.DiffuseColor
|
||||
vobj.DiffuseColor = d
|
||||
if hasattr(vobj,"DiffuseColor"):
|
||||
if len(vobj.DiffuseColor) > 1:
|
||||
d = vobj.DiffuseColor
|
||||
vobj.DiffuseColor = d
|
||||
return
|
||||
|
||||
def attach(self,vobj):
|
||||
|
@ -767,26 +768,26 @@ class ViewProviderComponent:
|
|||
taskd.update()
|
||||
FreeCADGui.Control.showDialog(taskd)
|
||||
return True
|
||||
|
||||
|
||||
def unsetEdit(self,vobj,mode):
|
||||
FreeCADGui.Control.closeDialog()
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
||||
class ArchSelectionObserver:
|
||||
"""ArchSelectionObserver([origin,watched,hide,nextCommand]): The ArchSelectionObserver
|
||||
"""ArchSelectionObserver([origin,watched,hide,nextCommand]): The ArchSelectionObserver
|
||||
object can be added as a selection observer to the FreeCAD Gui. If watched is given (a
|
||||
document object), the observer will be triggered only when that object is selected/unselected.
|
||||
If hide is True, the watched object will be hidden. If origin is given (a document
|
||||
object), that object will have its visibility/selectability restored. If nextCommand
|
||||
is given (a FreeCAD command), it will be executed on leave."""
|
||||
|
||||
|
||||
def __init__(self,origin=None,watched=None,hide=True,nextCommand=None):
|
||||
self.origin = origin
|
||||
self.watched = watched
|
||||
self.hide = hide
|
||||
self.nextCommand = nextCommand
|
||||
|
||||
|
||||
def addSelection(self,document, object, element, position):
|
||||
if not self.watched:
|
||||
FreeCADGui.Selection.removeObserver(FreeCAD.ArchObserver)
|
||||
|
|
|
@ -235,9 +235,9 @@ class _Equipment(ArchComponent.Component):
|
|||
"The Equipment object"
|
||||
def __init__(self,obj):
|
||||
ArchComponent.Component.__init__(self,obj)
|
||||
obj.addProperty("Part::PropertyPartShape","TopView","Arch",translate("Arch","an optional 2D shape representing a top view of this equipment"))
|
||||
obj.addProperty("Part::PropertyPartShape","FrontView","Arch",translate("Arch","an optional 2D shape representing a front view of this equipment"))
|
||||
obj.addProperty("Part::PropertyPartShape","SideView","Arch",translate("Arch","an optional 2D shape representing a side view of this equipment"))
|
||||
#obj.addProperty("Part::PropertyPartShape","TopView","Arch",translate("Arch","an optional 2D shape representing a top view of this equipment"))
|
||||
#obj.addProperty("Part::PropertyPartShape","FrontView","Arch",translate("Arch","an optional 2D shape representing a front view of this equipment"))
|
||||
#obj.addProperty("Part::PropertyPartShape","SideView","Arch",translate("Arch","an optional 2D shape representing a side view of this equipment"))
|
||||
obj.addProperty("App::PropertyString","Model","Arch",translate("Arch","The model description of this equipment"))
|
||||
obj.addProperty("App::PropertyString","Url","Arch",translate("Arch","The url of the product page of this equipment"))
|
||||
self.Type = "Equipment"
|
||||
|
@ -248,10 +248,10 @@ class _Equipment(ArchComponent.Component):
|
|||
self.hideSubobjects(obj,prop)
|
||||
|
||||
def execute(self,obj):
|
||||
|
||||
|
||||
if self.clone(obj):
|
||||
return
|
||||
|
||||
|
||||
pl = obj.Placement
|
||||
if obj.Base:
|
||||
if obj.isDerivedFrom("Mesh::Feature"):
|
||||
|
|
Loading…
Reference in New Issue
Block a user