|
|
@ -94,11 +94,37 @@ class TechDrawExtensions: |
|
|
|
for view in to_repaint: |
|
|
|
for view in to_repaint: |
|
|
|
#print("Repainting " + view.Name) |
|
|
|
#print("Repainting " + view.Name) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
page = self.getViewPage(view) |
|
|
|
|
|
|
|
|
|
|
|
view_cache = self.getViewCache(view) |
|
|
|
view_cache = self.getViewCache(view) |
|
|
|
view_cache.reset() |
|
|
|
view_cache.reset() |
|
|
|
|
|
|
|
|
|
|
|
doc = view.Document |
|
|
|
doc = view.Document |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not 'Assembly_handbook_RasterView' in view.PropertiesList: |
|
|
|
|
|
|
|
view.addProperty("App::PropertyBool", "Assembly_handbook_RasterView", "Assembly_handbook") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if view.Assembly_handbook_RasterView: |
|
|
|
|
|
|
|
print("Rasterizing view " + view.Label + "...") |
|
|
|
|
|
|
|
imageName = view.Label + "_raster" |
|
|
|
|
|
|
|
image = doc.getObject(imageName) |
|
|
|
|
|
|
|
if image is None: |
|
|
|
|
|
|
|
image = doc.addObject('TechDraw::DrawViewImage', view.Label + "_raster") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not image in page.Views: |
|
|
|
|
|
|
|
page.addView(image) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new_views_list = page.Views |
|
|
|
|
|
|
|
new_views_list.remove(image) |
|
|
|
|
|
|
|
view_idx = new_views_list.index(view) |
|
|
|
|
|
|
|
new_views_list.insert(view_idx, image) |
|
|
|
|
|
|
|
page.Views = new_views_list |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
image_file_name = doc.FileName.replace('.FCStd', '') + '_raster/' + view.Name + '.png' |
|
|
|
|
|
|
|
self.rasterizeView(view, image_file_name) |
|
|
|
|
|
|
|
image.ImageFile = image_file_name # TODO: see if it's possible to set a relative path |
|
|
|
|
|
|
|
image.recompute() |
|
|
|
|
|
|
|
else: |
|
|
|
fast_rendering = False |
|
|
|
fast_rendering = False |
|
|
|
#try: |
|
|
|
#try: |
|
|
|
# fast_rendering = view.Assembly_handbook_FastRendering |
|
|
|
# fast_rendering = view.Assembly_handbook_FastRendering |
|
|
@ -201,6 +227,40 @@ class TechDrawExtensions: |
|
|
|
|
|
|
|
|
|
|
|
view.requestPaint() |
|
|
|
view.requestPaint() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rasterizeView(self, view, image_file_name): |
|
|
|
|
|
|
|
from pivy import coin |
|
|
|
|
|
|
|
import os |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print('Rasterizing ' + view.Label + " to " + image_file_name + "...") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dir = os.path.dirname(image_file_name) |
|
|
|
|
|
|
|
if not os.path.exists(dir): |
|
|
|
|
|
|
|
os.makedirs(dir) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
doc = App.newDocument('tmp_raster', hidden=False, temp=False) |
|
|
|
|
|
|
|
for part in view.XSource: |
|
|
|
|
|
|
|
link = doc.addObject('App::Link', part.Name) |
|
|
|
|
|
|
|
link.Label = part.Label |
|
|
|
|
|
|
|
if part.TypeId == 'App::Link': |
|
|
|
|
|
|
|
link.LinkedObject = part.LinkedObject |
|
|
|
|
|
|
|
link.Placement = part.Placement |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
link.LinkedObject = part |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docView = Gui.getDocument(doc.Name).mdiViewsOfType('Gui::View3DInventor')[0] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cam = docView.getCameraNode() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rot = coin.SbRotation(coin.SbVec3f(1,0,0), coin.SbVec3f(view.XDirection.x,view.XDirection.y,view.XDirection.z)) |
|
|
|
|
|
|
|
rot *= coin.SbRotation(coin.SbVec3f(0,0,1), coin.SbVec3f(view.Direction.x,view.Direction.y,view.Direction.z)) |
|
|
|
|
|
|
|
cam.orientation.setValue(rot) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docView.fitAll() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docView.saveImage(image_file_name, 4096, 4096, "#ffffff") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
App.closeDocument(doc.Name) |
|
|
|
|
|
|
|
|
|
|
|
def updateBalloonCursor(self, view): |
|
|
|
def updateBalloonCursor(self, view): |
|
|
|
selected_balloons = [] |
|
|
|
selected_balloons = [] |
|
|
|
for obj in Gui.Selection.getSelection(): |
|
|
|
for obj in Gui.Selection.getSelection(): |
|
|
@ -227,7 +287,7 @@ class TechDrawExtensions: |
|
|
|
if doc != Gui.ActiveDocument.Document: |
|
|
|
if doc != Gui.ActiveDocument.Document: |
|
|
|
raise Exception("Current view is not for the same document as TechDraw view " + view.Name) |
|
|
|
raise Exception("Current view is not for the same document as TechDraw view " + view.Name) |
|
|
|
activeView = Gui.ActiveDocument.ActiveView |
|
|
|
activeView = Gui.ActiveDocument.ActiveView |
|
|
|
if str(type(activeView)) != "<class 'View3DInventorPy'>": |
|
|
|
if str(type(activeView)) not in ["<class 'View3DInventorPy'>", "<class 'Gui.View3DInventor'>"]: |
|
|
|
raise Exception("Current view is not a 3D view") |
|
|
|
raise Exception("Current view is not a 3D view") |
|
|
|
|
|
|
|
|
|
|
|
cam = activeView.getCameraNode() |
|
|
|
cam = activeView.getCameraNode() |
|
|
@ -408,8 +468,11 @@ class TechDrawExtensions: |
|
|
|
return None |
|
|
|
return None |
|
|
|
|
|
|
|
|
|
|
|
def forceRedrawPage(self, page, callback = None): |
|
|
|
def forceRedrawPage(self, page, callback = None): |
|
|
|
|
|
|
|
needPageUpdate = False |
|
|
|
for view in page.Views: |
|
|
|
for view in page.Views: |
|
|
|
if view.TypeId == 'TechDraw::DrawViewPart' and 'Assembly_handbook_PreviousStepView' in view.PropertiesList: |
|
|
|
if view.TypeId == 'TechDraw::DrawViewPart' and 'Assembly_handbook_PreviousStepView' in view.PropertiesList: |
|
|
|
|
|
|
|
if 'Assembly_handbook_RasterView' not in view.PropertiesList or not view.Assembly_handbook_RasterView: |
|
|
|
|
|
|
|
needPageUpdate = True |
|
|
|
self.refreshView(view) |
|
|
|
self.refreshView(view) |
|
|
|
elif view.TypeId == 'TechDraw::DrawViewBalloon': |
|
|
|
elif view.TypeId == 'TechDraw::DrawViewBalloon': |
|
|
|
if view.ViewObject.Visibility: |
|
|
|
if view.ViewObject.Visibility: |
|
|
@ -425,7 +488,7 @@ class TechDrawExtensions: |
|
|
|
view.ViewObject.Visibility = True |
|
|
|
view.ViewObject.Visibility = True |
|
|
|
view.ViewObject.Visibility = False |
|
|
|
view.ViewObject.Visibility = False |
|
|
|
|
|
|
|
|
|
|
|
if page.KeepUpdated: |
|
|
|
if page.KeepUpdated or not needPageUpdate: |
|
|
|
for view in page.Views: |
|
|
|
for view in page.Views: |
|
|
|
if view.TypeId != 'TechDraw::DrawViewPart': |
|
|
|
if view.TypeId != 'TechDraw::DrawViewPart': |
|
|
|
view.recompute() |
|
|
|
view.recompute() |
|
|
|