Browse Source

fixed rasterization issues, and added possibility to render Draft objects (dimensions, lines, etc.)

master
Youen 2 years ago
parent
commit
a8e10a2b99
  1. 21
      ahb_raster_view.py
  2. 55
      ahb_techdraw_extensions.py

21
ahb_raster_view.py

@ -89,7 +89,7 @@ class RasterView:
result.extend(self._flatten_objects_tree([obj.LinkedObject]))
elif obj.TypeId in ['App::Part', 'App::DocumentObjectGroup']:
result.extend(self._flatten_objects_tree(obj.Group))
elif obj.TypeId in ['Part::Feature', 'Part::FeaturePython', 'PartDesign::Body', 'PartDesign::CoordinateSystem', 'PartDesign::Line', 'Part::Mirroring', 'Part::Cut', 'Part::Part2DObjectPython']:
elif self._should_render(obj) or self._should_render_as_is(obj) or obj.TypeId in ['PartDesign::CoordinateSystem', 'PartDesign::Line']:
result.append(obj)
if hasattr(obj, 'Group'):
result.extend(self._flatten_objects_tree(obj.Group))
@ -97,7 +97,10 @@ class RasterView:
return result
def _should_render(self, obj):
return obj.TypeId in ['Part::Feature', 'Part::FeaturePython', 'PartDesign::Body', 'Part::Mirroring', 'Part::Cut', 'Part::Part2DObjectPython']
return obj.TypeId in ['Part::Feature', 'Part::FeaturePython', 'PartDesign::Body', 'Part::Mirroring', 'Part::Cut', 'Part::Part2DObjectPython', 'Part::MultiFuse', 'Part::Loft', 'Part::Torus', 'Part::Cylinder']
def _should_render_as_is(self, obj):
return obj.TypeId in ['App::FeaturePython']
def render(self, fast_render = True):
from pivy import coin
@ -128,7 +131,8 @@ class RasterView:
sceneGroup = tmp_doc.addObject('App::DocumentObjectGroup', 'Scene')
prev_parts = []
new_parts = []
for part in view.XSource:
all_parts = view.XSource + view.Source
for part in all_parts:
link = tmp_doc.addObject('App::Link', part.Name)
link.Label = part.Label
if part.TypeId == 'App::Link':
@ -139,10 +143,14 @@ class RasterView:
link.Placement = part.Placement
else:
link.LinkedObject = part
if part.TypeId in ['Part::Part2DObjectPython']:
link.Placement = part.Placement
is_new_part = workbench.techDrawExtensions.isNewPartInView(view, part)
if not fast_render:
# check if another part with different render settings will conflict with ours
# a conflict occurs when two parts link to the same object (directly or indirectly), because render settings (such as color) are set at the object level
is_conflicting = False
if link.LinkedObject in duplicated_parts.keys():
link.LinkedObject = duplicated_parts[link.LinkedObject]
@ -189,6 +197,12 @@ class RasterView:
obj.ViewObject.LineWidth,
obj.ViewObject.DisplayMode
)
if not obj.ViewObject.Visibility:
obj.ViewObject.ShapeMaterial.AmbientColor = (0, 0, 0)
obj.ViewObject.ShapeMaterial.DiffuseColor = (0, 0, 0)
obj.ViewObject.ShapeMaterial.SpecularColor = (0, 0, 0)
obj.ViewObject.ShapeMaterial.EmissiveColor = (0, 0, 0)
else:
objects_to_reset[obj] = (
obj.ViewObject.Visibility,
@ -267,6 +281,7 @@ class RasterView:
composite_img = composite_img.quantize(colors=num_colors, dither=Image.Dither.NONE)
finally:
#raise Exception("test")
# restore properties on objects we have modified
for obj, props in objects_to_reset.items():
obj.ViewObject.Visibility = props[0]

55
ahb_techdraw_extensions.py

@ -94,6 +94,7 @@ class TechDrawExtensions:
def _do_repaint(self):
from ahb_raster_view import RasterView
import Draft
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench") #: :type workbench: AssemblyHandbookWorkbench
@ -133,44 +134,28 @@ class TechDrawExtensions:
overlay_frame_name = view.Label + "_frame"
overlay_frame = doc.getObject(overlay_frame_name)
if overlay_frame is None:
import Draft
'''
points = [App.Vector(0.0, 0.0, 0.0), App.Vector(1.01, 0, 0)]
obj1 = Draft.makeWire(points, closed=False, face=False, support=None)
points = [App.Vector(200.0, 0.0, 0.0), App.Vector(201.01, 0, 0)]
obj2 = Draft.makeWire(points, closed=False, face=False, support=None)
#overlay_frame = Draft.upgrade([], delete=True)
#overlay_frame.Label = overlay_frame_name
overlay_frame = App.ActiveDocument.addObject("Part::Part2DObjectPython", overlay_frame_name)
Draft.Block(overlay_frame)
overlay_frame.Components = [obj1, obj2]
Draft.ViewProviderDraftPart(overlay_frame.ViewObject)
doc.removeObject(obj1.Name)
doc.removeObject(obj2.Name)'''
#overlay_frame = Draft.makeWire(points, closed=False, face=False, support=None)
overlay_frame = App.ActiveDocument.addObject("Part::Part2DObjectPython", overlay_frame_name)
Draft.Wire(overlay_frame)
pos = raster_view.projectImageViewPointTo3D(App.Vector(0,0,0))
pos2 = raster_view.projectImageViewPointTo3D(App.Vector(0.001,0.001,1))
overlay_frame.Points = [pos, pos2]
Draft.ViewProviderWire(overlay_frame.ViewObject)
overlay_frame.recompute()
if overlay_frame is not None:
doc.removeObject(overlay_frame.Name)
#overlay_frame = Draft.makeWire(points, closed=False, face=False, support=None)
overlay_frame = doc.addObject("Part::Part2DObjectPython", overlay_frame_name)
Draft.Wire(overlay_frame)
pos = raster_view.projectImageViewPointTo3D(App.Vector(0,0,0))
pos2 = raster_view.projectImageViewPointTo3D(App.Vector(0.001,0.001,1))
overlay_frame.Points = [pos, pos2]
Draft.ViewProviderWire(overlay_frame.ViewObject)
overlay_frame.recompute()
overlay_frame2_name = view.Label + "_frame2"
overlay_frame2 = doc.getObject(overlay_frame2_name)
if overlay_frame2 is None:
overlay_frame2 = App.ActiveDocument.addObject("Part::Part2DObjectPython", overlay_frame2_name)
Draft.Wire(overlay_frame2)
pos = raster_view.projectImageViewPointTo3D(App.Vector(1,1,0))
pos2 = raster_view.projectImageViewPointTo3D(App.Vector(1.001,1.001,1))
overlay_frame2.Points = [pos, pos2]
Draft.ViewProviderWire(overlay_frame2.ViewObject)
overlay_frame2.recompute()
if overlay_frame2 is not None:
doc.removeObject(overlay_frame2.Name)
overlay_frame2 = doc.addObject("Part::Part2DObjectPython", overlay_frame2_name)
Draft.Wire(overlay_frame2)
pos = raster_view.projectImageViewPointTo3D(App.Vector(1,1,0))
pos2 = raster_view.projectImageViewPointTo3D(App.Vector(1.001,1.001,1))
overlay_frame2.Points = [pos, pos2]
Draft.ViewProviderWire(overlay_frame2.ViewObject)
overlay_frame2.recompute()
overlay.Source = [overlay_frame, overlay_frame2]

Loading…
Cancel
Save