Browse Source

Added button to insert a new step

pull/1/head
Youen 2 years ago
parent
commit
339ebba88e
  1. 3
      InitGui.py
  2. 99
      ahb_cmd_new_step.py
  3. 2
      ahb_parts_cache.py
  4. 2
      ahb_techdraw_extensions.py

3
InitGui.py

@ -88,6 +88,9 @@ class AssemblyHandbookWorkbench(Gui.Workbench):
#self.importModule('ahb_cmd_animate')
#toolbox.append("AHB_animate")
self.importModule('ahb_cmd_new_step')
toolbox.append("AHB_new_step")
self.importModule('ahb_cmd_view_annotate')
toolbox.append("AHB_view_annotate")

99
ahb_cmd_new_step.py

@ -0,0 +1,99 @@
import FreeCADGui as Gui
import FreeCAD as App
class AHB_New_Step:
def GetResources(self):
return {"MenuText": "New Step",
"ToolTip": "Creates a page for the next step (first, select the view of the preceding step, if any)",
"Pixmap": ""
}
def IsActive(self):
return True
def Activated(self):
import re
import os
import sys
from PySide.QtCore import QTimer
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench") #: :type workbench: AssemblyHandbookWorkbench
if len(Gui.Selection.getSelection()) > 1:
raise Exception("Please either select exactly one TechDraw view, or nothing at all")
prev_view = None if len(Gui.Selection.getSelection()) == 0 else Gui.Selection.getSelection()[0]
if prev_view is not None and prev_view.TypeId != 'TechDraw::DrawViewPart':
raise Exception("Selected object is not a TechDraw view")
doc = App.ActiveDocument if prev_view is None else prev_view.Document
freecad_path = os.path.normpath(os.path.dirname(sys.executable) + '/..') # 'usr' absolute path
if prev_view is None:
step_number = 1
keep_updated = False
template_file_name = freecad_path + '/share/Mod/TechDraw/Templates/A4_Landscape_blank.svg'
parent_group = None
else:
prev_page = workbench.techDrawExtensions.getViewPage(prev_view)
prev_page_group = prev_page.getParentGroup()
if prev_page_group is not None:
parent_group = prev_page_group.getParentGroup()
keep_updated = prev_page.KeepUpdated
template_file_name = prev_page.Template.Template
numbers = re.findall(r'\d+', prev_page.Label)
if len(numbers) == 0: prev_number = 0
else: prev_number = max(1, int(numbers[-1]))
step_number = prev_number + 1
step_num_str = str(step_number).zfill(3)
group = doc.addObject('App::DocumentObjectGroup', 'Etape' + step_num_str)
if parent_group is not None:
parent_group.addObject(group)
page_name = 'Etape' + step_num_str + '_Page'
page = doc.addObject('TechDraw::DrawPage', page_name)
group.addObject(page)
if page.KeepUpdated != keep_updated: page.KeepUpdated = keep_updated
template = doc.addObject('TechDraw::DrawSVGTemplate', 'Template')
template.Template = template_file_name
page.Template = template
view = doc.addObject('TechDraw::DrawViewPart', 'View')
view.Perspective = False
view.addProperty("App::PropertyString", "AssemblyHandbook_PreviousStepView", "AssemblyHandbook")
if prev_view is not None:
view.AssemblyHandbook_PreviousStepView = prev_view.Name
view.X = prev_view.X
view.Y = prev_view.Y
view.Direction = prev_view.Direction
view.XDirection = prev_view.XDirection
view.ScaleType = prev_view.ScaleType
view.Scale = prev_view.Scale
view.XSource = prev_view.XSource
page.addView(view)
view.recompute()
# search for views after the prev view to relink them after the new view (i.e. we insert the new view as an intermediate step)
# TODO: re-number next steps if needed
if prev_view is not None:
for obj in doc.Objects:
if obj != view and obj.TypeId == 'TechDraw::DrawViewPart' and 'AssemblyHandbook_PreviousStepView' in obj.PropertiesList and obj.AssemblyHandbook_PreviousStepView == prev_view.Name:
obj.AssemblyHandbook_PreviousStepView = view.Name
print(obj.Label + ' has been moved after the new step')
if not page.KeepUpdated and len(view.XSource) > 0:
page.KeepUpdated = True
def restoreKeepUpdated():
page.KeepUpdated = False
QTimer.singleShot(100, restoreKeepUpdated)
Gui.Selection.clearSelection()
Gui.Selection.addSelection(page)
from ahb_command import AHB_CommandWrapper
AHB_CommandWrapper.addGuiCommand('AHB_new_step', AHB_New_Step())

2
ahb_parts_cache.py

@ -51,7 +51,7 @@ class PartCachedView:
self.cached_lines = np.empty([numLines, 4])
lineIdx = 0
for edge in tmpEdges:
if not hasattr(edge.Curve, 'Degree') or edge.Curve.Degree == 1:
if (not hasattr(edge.Curve, 'Degree') or edge.Curve.Degree == 1) and len(edge.Vertexes) == 2:
sx = 1.0
sy = -1.0
self.cached_lines[lineIdx] = [

2
ahb_techdraw_extensions.py

@ -115,7 +115,7 @@ class TechDrawExtensions:
if is_first_part:
view.formatGeometricEdge(edgeIdx,1,0.25,0,True)
if balloon is not None and (not hasattr(edge.Curve, 'Degree') or edge.Curve.Degree == 1):
if balloon 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,

Loading…
Cancel
Save