Draft and BIM: Layer manager minor code improvements
The code should not add the LinePrintColor property. That should be done elsewhere.
This commit is contained in:
@@ -211,11 +211,7 @@ class BIM_Layers:
|
||||
)
|
||||
|
||||
# visibility
|
||||
checked = (
|
||||
True
|
||||
if self.model.item(row, 0).checkState() == QtCore.Qt.Checked
|
||||
else False
|
||||
)
|
||||
checked = self.model.item(row, 0).checkState() == QtCore.Qt.Checked
|
||||
if checked != obj.ViewObject.Visibility:
|
||||
if not changed:
|
||||
FreeCAD.ActiveDocument.openTransaction("Layers change")
|
||||
@@ -224,48 +220,45 @@ class BIM_Layers:
|
||||
|
||||
# label
|
||||
label = self.model.item(row, 1).text()
|
||||
if label:
|
||||
if obj.Label != label:
|
||||
if not changed:
|
||||
FreeCAD.ActiveDocument.openTransaction("Layers change")
|
||||
changed = True
|
||||
obj.Label = label
|
||||
# Setting Label="" is possible in the Property editor but we avoid it here:
|
||||
if label and obj.Label != label:
|
||||
if not changed:
|
||||
FreeCAD.ActiveDocument.openTransaction("Layers change")
|
||||
changed = True
|
||||
obj.Label = label
|
||||
|
||||
# line width
|
||||
width = self.model.item(row, 2).data(QtCore.Qt.DisplayRole)
|
||||
if width:
|
||||
if obj.ViewObject.LineWidth != width:
|
||||
if not changed:
|
||||
FreeCAD.ActiveDocument.openTransaction("Layers change")
|
||||
changed = True
|
||||
obj.ViewObject.LineWidth = width
|
||||
# Setting LineWidth=0 is possible in the Property editor but we avoid it here:
|
||||
if width and obj.ViewObject.LineWidth != width:
|
||||
if not changed:
|
||||
FreeCAD.ActiveDocument.openTransaction("Layers change")
|
||||
changed = True
|
||||
obj.ViewObject.LineWidth = width
|
||||
|
||||
# draw style
|
||||
style = self.model.item(row, 3).text()
|
||||
if style:
|
||||
if obj.ViewObject.DrawStyle != style:
|
||||
if not changed:
|
||||
FreeCAD.ActiveDocument.openTransaction("Layers change")
|
||||
changed = True
|
||||
obj.ViewObject.DrawStyle = style
|
||||
if obj.ViewObject.DrawStyle != style:
|
||||
if not changed:
|
||||
FreeCAD.ActiveDocument.openTransaction("Layers change")
|
||||
changed = True
|
||||
obj.ViewObject.DrawStyle = style
|
||||
|
||||
# line color
|
||||
color = self.model.item(row, 4).data(QtCore.Qt.UserRole)
|
||||
if color:
|
||||
if obj.ViewObject.LineColor[3:] != color:
|
||||
if not changed:
|
||||
FreeCAD.ActiveDocument.openTransaction("Layers change")
|
||||
changed = True
|
||||
obj.ViewObject.LineColor = color
|
||||
if obj.ViewObject.LineColor[3:] != color:
|
||||
if not changed:
|
||||
FreeCAD.ActiveDocument.openTransaction("Layers change")
|
||||
changed = True
|
||||
obj.ViewObject.LineColor = color
|
||||
|
||||
# shape color
|
||||
color = self.model.item(row, 5).data(QtCore.Qt.UserRole)
|
||||
if color:
|
||||
if obj.ViewObject.ShapeColor[3:] != color:
|
||||
if not changed:
|
||||
FreeCAD.ActiveDocument.openTransaction("Layers change")
|
||||
changed = True
|
||||
obj.ViewObject.ShapeColor = color
|
||||
if obj.ViewObject.ShapeColor[3:] != color:
|
||||
if not changed:
|
||||
FreeCAD.ActiveDocument.openTransaction("Layers change")
|
||||
changed = True
|
||||
obj.ViewObject.ShapeColor = color
|
||||
|
||||
# transparency
|
||||
transparency = self.model.item(row, 6).data(QtCore.Qt.DisplayRole)
|
||||
@@ -277,16 +270,11 @@ class BIM_Layers:
|
||||
|
||||
# line print color
|
||||
color = self.model.item(row, 7).data(QtCore.Qt.UserRole)
|
||||
if color:
|
||||
if not "LinePrintColor" in obj.ViewObject.PropertiesList:
|
||||
if hasattr(obj.ViewObject.Proxy, "set_properties"):
|
||||
obj.ViewObject.Proxy.set_properties(obj.ViewObject)
|
||||
if "LinePrintColor" in obj.ViewObject.PropertiesList:
|
||||
if obj.ViewObject.LinePrintColor[3:] != color:
|
||||
if not changed:
|
||||
FreeCAD.ActiveDocument.openTransaction("Layers change")
|
||||
changed = True
|
||||
obj.ViewObject.LinePrintColor = color
|
||||
if obj.ViewObject.LinePrintColor[3:] != color:
|
||||
if not changed:
|
||||
FreeCAD.ActiveDocument.openTransaction("Layers change")
|
||||
changed = True
|
||||
obj.ViewObject.LinePrintColor = color
|
||||
|
||||
# recompute
|
||||
if changed:
|
||||
|
||||
@@ -168,7 +168,7 @@ class LayerManager:
|
||||
for row in range(self.model.rowCount()):
|
||||
|
||||
# get or create layer
|
||||
name = self.model.item(row,1).toolTip()
|
||||
name = self.model.item(row, 1).toolTip()
|
||||
obj = None
|
||||
if name:
|
||||
obj = doc.getObject(name)
|
||||
@@ -181,7 +181,7 @@ class LayerManager:
|
||||
vobj = obj.ViewObject
|
||||
|
||||
# visibility
|
||||
checked = True if self.model.item(row,0).checkState() == QtCore.Qt.Checked else False
|
||||
checked = self.model.item(row, 0).checkState() == QtCore.Qt.Checked
|
||||
if checked != vobj.Visibility:
|
||||
if not changed:
|
||||
doc.openTransaction("Layers change")
|
||||
@@ -189,52 +189,49 @@ class LayerManager:
|
||||
vobj.Visibility = checked
|
||||
|
||||
# label
|
||||
label = self.model.item(row,1).text()
|
||||
if label:
|
||||
if obj.Label != label:
|
||||
if not changed:
|
||||
doc.openTransaction("Layers change")
|
||||
changed = True
|
||||
obj.Label = label
|
||||
label = self.model.item(row, 1).text()
|
||||
# Setting Label="" is possible in the Property editor but we avoid it here:
|
||||
if label and obj.Label != label:
|
||||
if not changed:
|
||||
doc.openTransaction("Layers change")
|
||||
changed = True
|
||||
obj.Label = label
|
||||
|
||||
# line width
|
||||
width = self.model.item(row,2).data(QtCore.Qt.DisplayRole)
|
||||
if width:
|
||||
if vobj.LineWidth != width:
|
||||
if not changed:
|
||||
doc.openTransaction("Layers change")
|
||||
changed = True
|
||||
vobj.LineWidth = width
|
||||
width = self.model.item(row, 2).data(QtCore.Qt.DisplayRole)
|
||||
# Setting LineWidth=0 is possible in the Property editor but we avoid it here:
|
||||
if width and vobj.LineWidth != width:
|
||||
if not changed:
|
||||
doc.openTransaction("Layers change")
|
||||
changed = True
|
||||
vobj.LineWidth = width
|
||||
|
||||
# draw style
|
||||
style = self.model.item(row,3).text()
|
||||
if style:
|
||||
if vobj.DrawStyle != style:
|
||||
if not changed:
|
||||
doc.openTransaction("Layers change")
|
||||
changed = True
|
||||
vobj.DrawStyle = style
|
||||
style = self.model.item(row, 3).text()
|
||||
if vobj.DrawStyle != style:
|
||||
if not changed:
|
||||
doc.openTransaction("Layers change")
|
||||
changed = True
|
||||
vobj.DrawStyle = style
|
||||
|
||||
# line color
|
||||
color = self.model.item(row,4).data(QtCore.Qt.UserRole)
|
||||
if color:
|
||||
if vobj.LineColor[:3] != color:
|
||||
if not changed:
|
||||
doc.openTransaction("Layers change")
|
||||
changed = True
|
||||
vobj.LineColor = color
|
||||
color = self.model.item(row, 4).data(QtCore.Qt.UserRole)
|
||||
if vobj.LineColor[:3] != color:
|
||||
if not changed:
|
||||
doc.openTransaction("Layers change")
|
||||
changed = True
|
||||
vobj.LineColor = color
|
||||
|
||||
# shape color
|
||||
color = self.model.item(row,5).data(QtCore.Qt.UserRole)
|
||||
if color:
|
||||
if vobj.ShapeColor[:3] != color:
|
||||
if not changed:
|
||||
doc.openTransaction("Layers change")
|
||||
changed = True
|
||||
vobj.ShapeColor = color
|
||||
color = self.model.item(row, 5).data(QtCore.Qt.UserRole)
|
||||
if vobj.ShapeColor[:3] != color:
|
||||
if not changed:
|
||||
doc.openTransaction("Layers change")
|
||||
changed = True
|
||||
vobj.ShapeColor = color
|
||||
|
||||
# transparency
|
||||
transparency = self.model.item(row,6).data(QtCore.Qt.DisplayRole)
|
||||
transparency = self.model.item(row, 6).data(QtCore.Qt.DisplayRole)
|
||||
if vobj.Transparency != transparency:
|
||||
if not changed:
|
||||
doc.openTransaction("Layers change")
|
||||
@@ -242,17 +239,12 @@ class LayerManager:
|
||||
vobj.Transparency = transparency
|
||||
|
||||
# line print color
|
||||
color = self.model.item(row,7).data(QtCore.Qt.UserRole)
|
||||
if color:
|
||||
if not "LinePrintColor" in vobj.PropertiesList:
|
||||
if hasattr(vobj.Proxy,"set_properties"):
|
||||
vobj.Proxy.set_properties(vobj)
|
||||
if "LinePrintColor" in vobj.PropertiesList:
|
||||
if vobj.LinePrintColor[:3] != color:
|
||||
if not changed:
|
||||
doc.openTransaction("Layers change")
|
||||
changed = True
|
||||
vobj.LinePrintColor = color
|
||||
color = self.model.item(row, 7).data(QtCore.Qt.UserRole)
|
||||
if vobj.LinePrintColor[:3] != color:
|
||||
if not changed:
|
||||
doc.openTransaction("Layers change")
|
||||
changed = True
|
||||
vobj.LinePrintColor = color
|
||||
|
||||
# recompute
|
||||
if changed:
|
||||
@@ -410,7 +402,7 @@ class LayerManager:
|
||||
onrows.append(index.row())
|
||||
for row in range(self.model.rowCount()):
|
||||
if not row in onrows:
|
||||
self.model.item(row,0).setCheckState(QtCore.Qt.Unchecked)
|
||||
self.model.item(row, 0).setCheckState(QtCore.Qt.Unchecked)
|
||||
|
||||
|
||||
if App.GuiUp:
|
||||
|
||||
Reference in New Issue
Block a user