Merge pull request #53 from wood-galaxy/equipement-fix

Arch : Fix ViewProviderComponent if vobj have not DiffuseColor attribute
This commit is contained in:
Yorik van Havre 2015-09-25 15:23:55 -03:00
commit 6a93d1392d
2 changed files with 48 additions and 47 deletions

View File

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

View File

@ -235,9 +235,9 @@ class _Equipment(ArchComponent.Component):
"The Equipment object" "The Equipment object"
def __init__(self,obj): def __init__(self,obj):
ArchComponent.Component.__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","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","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","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","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")) obj.addProperty("App::PropertyString","Url","Arch",translate("Arch","The url of the product page of this equipment"))
self.Type = "Equipment" self.Type = "Equipment"
@ -248,10 +248,10 @@ class _Equipment(ArchComponent.Component):
self.hideSubobjects(obj,prop) self.hideSubobjects(obj,prop)
def execute(self,obj): def execute(self,obj):
if self.clone(obj): if self.clone(obj):
return return
pl = obj.Placement pl = obj.Placement
if obj.Base: if obj.Base:
if obj.isDerivedFrom("Mesh::Feature"): if obj.isDerivedFrom("Mesh::Feature"):