Browse Source

Added button to assign the current 3D view direction to a TechDraw view

pull/1/head
Youen 2 years ago
parent
commit
1338f7d989
  1. 3
      InitGui.py
  2. 2
      ahb_cmd_render.py
  3. 30
      ahb_cmd_view_set_direction.py
  4. 20
      ahb_techdraw_extensions.py

3
InitGui.py

@ -83,6 +83,9 @@ class AssemblyHandbookWorkbench(Gui.Workbench):
self.importModule('ahb_cmd_new_step') self.importModule('ahb_cmd_new_step')
toolbox.append("AHB_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') self.importModule('ahb_cmd_view_annotate')
toolbox.append("AHB_view_annotate") toolbox.append("AHB_view_annotate")

2
ahb_cmd_render.py

@ -8,7 +8,7 @@ import FreeCAD as App
class AHB_Render: class AHB_Render:
def GetResources(self): def GetResources(self):
return {"MenuText": "Render", return {"MenuText": "Render",
"ToolTip": "Render to images", "ToolTip": "Render current 3D view to a PNG image",
"Pixmap": "" "Pixmap": ""
} }

30
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())

20
ahb_techdraw_extensions.py

@ -119,7 +119,7 @@ class TechDrawExtensions:
parts_to_paint.append(None) parts_to_paint.append(None)
for part in parts_to_paint: for part in parts_to_paint:
default_line_thickness = 0.1 default_line_thickness = 0.05
line_thickness = default_line_thickness line_thickness = default_line_thickness
default_color = (0, 0, 0) default_color = (0, 0, 0)
@ -134,7 +134,7 @@ class TechDrawExtensions:
prev_view = doc.getObject(view.Assembly_handbook_PreviousStepView) prev_view = doc.getObject(view.Assembly_handbook_PreviousStepView)
if prev_view is not None: if prev_view is not None:
if not part in prev_view.XSource: if not part in prev_view.XSource:
line_thickness *= 2.5 line_thickness = 0.3
for balloon in selected_balloons: for balloon in selected_balloons:
if part.Name == balloon.Assembly_handbook_PartName: 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.setViewPos(App.Vector(selected_balloons[0].OriginX, selected_balloons[0].OriginY))
cursor.setVisible(True) 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)) != "<class 'View3DInventorPy'>":
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): def refreshView(self, view):
doc = view.Document doc = view.Document

Loading…
Cancel
Save