|
|
@ -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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parts_to_paint = [] |
|
|
|
#view.clearGeomFormats() # for an unknown reason, this will crash freecad |
|
|
|
|
|
|
|
|
|
|
|
# repaint parts that are highlighted by selection |
|
|
|
if not fast_rendering: |
|
|
|
if self.enable_selected_part_highlight: |
|
|
|
is_first_part = True |
|
|
|
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 |
|
|
|
parts_to_paint = [] |
|
|
|
if len(parts_to_paint) == 0: |
|
|
|
|
|
|
|
parts_to_paint.append(None) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for part in parts_to_paint: |
|
|
|
# repaint parts that are highlighted by selection |
|
|
|
default_line_thickness = 0.05 |
|
|
|
if self.enable_selected_part_highlight: |
|
|
|
line_thickness = default_line_thickness |
|
|
|
for balloon in selected_balloons: |
|
|
|
|
|
|
|
part = self.getBalloonSourcePart(balloon) |
|
|
|
default_color = (0.5, 0.5, 0.5) |
|
|
|
if part in view.XSource: |
|
|
|
color = default_color |
|
|
|
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: |
|
|
|
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.0, 0.0, 0.0) if fast_rendering else (0.5, 0.5, 0.5) |
|
|
|
|
|
|
|
color = default_color |
|
|
|
if self.isNewPartInView(view, part): |
|
|
|
|
|
|
|
line_thickness = 0.2 |
|
|
|
|
|
|
|
color = (0, 0, 0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.enable_selected_part_highlight: |
|
|
|
if part is not None: |
|
|
|
for balloon in selected_balloons: |
|
|
|
part_view = workbench.partsCache.getPart2DView(view, part) |
|
|
|
if part == self.getBalloonSourcePart(balloon): |
|
|
|
|
|
|
|
color = (0.0, 0.85, 0.0) # selection highlighting |
|
|
|
center = self.computePartCenter(view, part) |
|
|
|
|
|
|
|
|
|
|
|
# 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 self.isNewPartInView(view, part): |
|
|
|
if part is not None and (not hasattr(edge.Curve, 'Degree') or edge.Curve.Degree == 1) and len(edge.Vertexes) == 2: |
|
|
|
line_thickness = 0.2 |
|
|
|
edgeData = [ |
|
|
|
color = (0, 0, 0) |
|
|
|
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]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for line in part_view.cached_lines: |
|
|
|
if self.enable_selected_part_highlight: |
|
|
|
l0 = App.Vector(line[0], line[1]) |
|
|
|
for balloon in selected_balloons: |
|
|
|
l1 = App.Vector(line[2], line[3]) |
|
|
|
if part == self.getBalloonSourcePart(balloon): |
|
|
|
#d = abs(edgeData[0] - line[0]) + abs(edgeData[1] - line[1]) + abs(edgeData[2] - line[2]) + abs(edgeData[3] - line[3]) |
|
|
|
color = (0.0, 0.85, 0.0) # selection highlighting |
|
|
|
d = v0.distanceToLineSegment(l0, l1).Length + v1.distanceToLineSegment(l0, l1).Length |
|
|
|
|
|
|
|
if d < 0.01: |
|
|
|
# iterate edges of actual view and highlight matching edges |
|
|
|
is_edge_of_part = True |
|
|
|
for edgeIdx in range(10000): |
|
|
|
break |
|
|
|
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: |
|
|
|
for line in part_view.cached_lines: |
|
|
|
view.formatGeometricEdge(edgeIdx,1,line_thickness,color,True) |
|
|
|
l0 = App.Vector(line[0], line[1]) |
|
|
|
elif is_first_part: |
|
|
|
l1 = App.Vector(line[2], line[3]) |
|
|
|
# reset edge format |
|
|
|
#d = abs(edgeData[0] - line[0]) + abs(edgeData[1] - line[1]) + abs(edgeData[2] - line[2]) + abs(edgeData[3] - line[3]) |
|
|
|
view.formatGeometricEdge(edgeIdx,1,default_line_thickness,default_color,True) |
|
|
|
d = v0.distanceToLineSegment(l0, l1).Length + v1.distanceToLineSegment(l0, l1).Length |
|
|
|
|
|
|
|
if d < 0.01: |
|
|
|
is_first_part = False |
|
|
|
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): |
|
|
|
def updateBalloonCursor(self, view): |
|
|
|
selected_balloons = [] |
|
|
|
selected_balloons = [] |
|
|
|