Browse Source

Added fast rendering mode (when CoarseView is set to true)

master
Youen 2 years ago
parent
commit
05e7da16a5
  1. 172
      ahb_techdraw_extensions.py

172
ahb_techdraw_extensions.py

@ -99,95 +99,107 @@ class TechDrawExtensions:
doc = view.Document doc = view.Document
fast_rendering = False
#try:
# fast_rendering = view.Assembly_handbook_FastRendering
#except:
# pass
if view.CoarseView:
fast_rendering = True
selected_balloons = [] selected_balloons = []
for obj in Gui.Selection.getSelection(): for obj in Gui.Selection.getSelection():
if obj.TypeId == 'TechDraw::DrawViewBalloon' and obj.SourceView == view and 'Assembly_handbook_Source' in obj.PropertiesList: if obj.TypeId == 'TechDraw::DrawViewBalloon' and obj.SourceView == view and 'Assembly_handbook_Source' in obj.PropertiesList:
selected_balloons.append(obj) selected_balloons.append(obj)
is_first_part = True #view.clearGeomFormats() # for an unknown reason, this will crash freecad
parts_to_paint = [] if not fast_rendering:
is_first_part = True
# repaint parts that are highlighted by selection parts_to_paint = []
if self.enable_selected_part_highlight:
for balloon in selected_balloons: # repaint parts that are highlighted by selection
part = self.getBalloonSourcePart(balloon) if self.enable_selected_part_highlight:
if part in view.XSource: for balloon in selected_balloons:
part = self.getBalloonSourcePart(balloon)
if part in view.XSource:
parts_to_paint.append(part)
# repaint parts that are new in this step (thick line)
prev_view = None
if 'Assembly_handbook_PreviousStepView' in view.PropertiesList:
prev_view = doc.getObject(view.Assembly_handbook_PreviousStepView)
for part in view.XSource:
if (prev_view is None or part not in prev_view.XSource) and part not in parts_to_paint:
parts_to_paint.append(part) parts_to_paint.append(part)
# repaint parts that are new in this step (thick line) # make sure the list is not empty, so that we reset all lines
prev_view = None if len(parts_to_paint) == 0:
if 'Assembly_handbook_PreviousStepView' in view.PropertiesList: parts_to_paint.append(None)
prev_view = doc.getObject(view.Assembly_handbook_PreviousStepView)
for part in view.XSource: for part in parts_to_paint:
if (prev_view is None or part not in prev_view.XSource) and part not in parts_to_paint: default_line_thickness = 0.05
parts_to_paint.append(part) line_thickness = default_line_thickness
# make sure the list is not empty, so that we reset all lines default_color = (0.0, 0.0, 0.0) if fast_rendering else (0.5, 0.5, 0.5)
if len(parts_to_paint) == 0: color = default_color
parts_to_paint.append(None)
if part is not None:
for part in parts_to_paint: part_view = workbench.partsCache.getPart2DView(view, part)
default_line_thickness = 0.05
line_thickness = default_line_thickness center = self.computePartCenter(view, part)
default_color = (0.5, 0.5, 0.5) if self.isNewPartInView(view, part):
color = default_color line_thickness = 0.2
color = (0, 0, 0)
if part is not None:
part_view = workbench.partsCache.getPart2DView(view, part) if self.enable_selected_part_highlight:
for balloon in selected_balloons:
center = self.computePartCenter(view, part) if part == self.getBalloonSourcePart(balloon):
color = (0.0, 0.85, 0.0) # selection highlighting
if self.isNewPartInView(view, part):
line_thickness = 0.2 # iterate edges of actual view and highlight matching edges
color = (0, 0, 0) for edgeIdx in range(10000):
hasEdge = False
if self.enable_selected_part_highlight: try:
for balloon in selected_balloons: edge = view.getEdgeByIndex(edgeIdx)
if part == self.getBalloonSourcePart(balloon): hasEdge = True
color = (0.0, 0.85, 0.0) # selection highlighting except:
pass
# iterate edges of actual view and highlight matching edges if not hasEdge:
for edgeIdx in range(10000): break
hasEdge = False
try: is_edge_of_part = False
edge = view.getEdgeByIndex(edgeIdx) if part is not None and (not hasattr(edge.Curve, 'Degree') or edge.Curve.Degree == 1) and len(edge.Vertexes) == 2:
hasEdge = True edgeData = [
except: edge.Vertexes[0].X - center.x,
pass edge.Vertexes[0].Y - center.y,
if not hasEdge: edge.Vertexes[1].X - center.x,
break edge.Vertexes[1].Y - center.y
]
is_edge_of_part = False v0 = App.Vector(edgeData[0], edgeData[1])
if part is not None and (not hasattr(edge.Curve, 'Degree') or edge.Curve.Degree == 1) and len(edge.Vertexes) == 2: v1 = App.Vector(edgeData[2], edgeData[3])
edgeData = [
edge.Vertexes[0].X - center.x, for line in part_view.cached_lines:
edge.Vertexes[0].Y - center.y, l0 = App.Vector(line[0], line[1])
edge.Vertexes[1].X - center.x, l1 = App.Vector(line[2], line[3])
edge.Vertexes[1].Y - center.y #d = abs(edgeData[0] - line[0]) + abs(edgeData[1] - line[1]) + abs(edgeData[2] - line[2]) + abs(edgeData[3] - line[3])
] d = v0.distanceToLineSegment(l0, l1).Length + v1.distanceToLineSegment(l0, l1).Length
v0 = App.Vector(edgeData[0], edgeData[1]) if d < 0.01:
v1 = App.Vector(edgeData[2], edgeData[3]) is_edge_of_part = True
break
for line in part_view.cached_lines:
l0 = App.Vector(line[0], line[1]) if is_edge_of_part:
l1 = App.Vector(line[2], line[3]) view.formatGeometricEdge(edgeIdx,1,line_thickness,color,True)
#d = abs(edgeData[0] - line[0]) + abs(edgeData[1] - line[1]) + abs(edgeData[2] - line[2]) + abs(edgeData[3] - line[3]) elif is_first_part:
d = v0.distanceToLineSegment(l0, l1).Length + v1.distanceToLineSegment(l0, l1).Length # reset edge format
if d < 0.01: view.formatGeometricEdge(edgeIdx,1,default_line_thickness,default_color,True)
is_edge_of_part = True
break is_first_part = False
if is_edge_of_part: view.requestPaint()
view.formatGeometricEdge(edgeIdx,1,line_thickness,color,True)
elif is_first_part:
# reset edge format
view.formatGeometricEdge(edgeIdx,1,default_line_thickness,default_color,True)
is_first_part = False
view.requestPaint()
def updateBalloonCursor(self, view): def updateBalloonCursor(self, view):
selected_balloons = [] selected_balloons = []

Loading…
Cancel
Save