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