From 1338f7d989360c6152d4314e5982ed3e19419121 Mon Sep 17 00:00:00 2001 From: Youen Date: Tue, 18 Oct 2022 22:35:35 +0200 Subject: [PATCH] Added button to assign the current 3D view direction to a TechDraw view --- InitGui.py | 3 +++ ahb_cmd_render.py | 2 +- ahb_cmd_view_set_direction.py | 30 ++++++++++++++++++++++++++++++ ahb_techdraw_extensions.py | 20 ++++++++++++++++++-- 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 ahb_cmd_view_set_direction.py diff --git a/InitGui.py b/InitGui.py index 4395d3e..ea0a150 100644 --- a/InitGui.py +++ b/InitGui.py @@ -83,6 +83,9 @@ class AssemblyHandbookWorkbench(Gui.Workbench): self.importModule('ahb_cmd_new_step') toolbox.append("AHB_new_step") + self.importModule('ahb_cmd_view_set_direction') + toolbox.append("AHB_view_set_direction") + self.importModule('ahb_cmd_view_annotate') toolbox.append("AHB_view_annotate") diff --git a/ahb_cmd_render.py b/ahb_cmd_render.py index 792ae8c..63cd48e 100644 --- a/ahb_cmd_render.py +++ b/ahb_cmd_render.py @@ -8,7 +8,7 @@ import FreeCAD as App class AHB_Render: def GetResources(self): return {"MenuText": "Render", - "ToolTip": "Render to images", + "ToolTip": "Render current 3D view to a PNG image", "Pixmap": "" } diff --git a/ahb_cmd_view_set_direction.py b/ahb_cmd_view_set_direction.py new file mode 100644 index 0000000..d657491 --- /dev/null +++ b/ahb_cmd_view_set_direction.py @@ -0,0 +1,30 @@ +import FreeCADGui as Gui +import FreeCAD as App + +class AHB_SetViewDirection: + def GetResources(self): + return {"MenuText": "Set view direction", + "ToolTip": "Applies the current 3D view direction on the selected TechDraw view", + "Pixmap": "" + } + + def IsActive(self): + view = self._get_view() + return view is not None + + def Activated(self): + workbench = Gui.getWorkbench("AssemblyHandbookWorkbench") #: :type workbench: AssemblyHandbookWorkbench + view = self._get_view() + if view is None: + raise Exception("Please select a TechDraw view") + workbench.techDrawExtensions.setCurrentViewDirection(view) + + def _get_view(self): + view = None if len(Gui.Selection.getSelection()) == 0 else Gui.Selection.getSelection()[0] + if view is not None and view.TypeId != 'TechDraw::DrawViewPart': + view = None + return view + + +from ahb_command import AHB_CommandWrapper +AHB_CommandWrapper.addGuiCommand('AHB_view_set_direction', AHB_SetViewDirection()) diff --git a/ahb_techdraw_extensions.py b/ahb_techdraw_extensions.py index 14bdc7f..70259d8 100644 --- a/ahb_techdraw_extensions.py +++ b/ahb_techdraw_extensions.py @@ -119,7 +119,7 @@ class TechDrawExtensions: parts_to_paint.append(None) for part in parts_to_paint: - default_line_thickness = 0.1 + default_line_thickness = 0.05 line_thickness = default_line_thickness default_color = (0, 0, 0) @@ -134,7 +134,7 @@ class TechDrawExtensions: prev_view = doc.getObject(view.Assembly_handbook_PreviousStepView) if prev_view is not None: if not part in prev_view.XSource: - line_thickness *= 2.5 + line_thickness = 0.3 for balloon in selected_balloons: if part.Name == balloon.Assembly_handbook_PartName: @@ -194,6 +194,22 @@ class TechDrawExtensions: cursor.setViewPos(App.Vector(selected_balloons[0].OriginX, selected_balloons[0].OriginY)) cursor.setVisible(True) + def setCurrentViewDirection(self, view): + from pivy import coin + + doc = view.Document + if doc != Gui.ActiveDocument.Document: + raise Exception("Current view is not for the same document as TechDraw view " + view.Name) + activeView = Gui.ActiveDocument.ActiveView + if str(type(activeView)) != "": + raise Exception("Current view is not a 3D view") + + cam = activeView.getCameraNode() + + dir = cam.orientation.getValue().multVec(coin.SbVec3f(0,0,1)).getValue() + xdir = cam.orientation.getValue().multVec(coin.SbVec3f(1,0,0)).getValue() + view.Direction = App.Vector(dir[0], dir[1], dir[2]) + view.XDirection = App.Vector(xdir[0], xdir[1], xdir[2]) def refreshView(self, view): doc = view.Document