forked from youen/assembly_handbook
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
4.0 KiB
128 lines
4.0 KiB
sys.path.append('/usr/local/lib/python3.9/dist-packages/') |
|
#import pydevd |
|
#pydevd.settrace() |
|
|
|
import os |
|
|
|
import FreeCADGui as Gui |
|
import FreeCAD as App |
|
|
|
import ahb_locator |
|
|
|
global ahb_icon |
|
ahb_icon = os.path.join(os.path.dirname(ahb_locator.__file__), "resources/assembly-handbook.svg") |
|
|
|
class AssemblyHandbookWorkbench(Gui.Workbench): |
|
""" |
|
class which gets initiated at startup of the gui |
|
""" |
|
|
|
MenuText = "Assembly handbook" |
|
ToolTip = "A workbench for automating creation of an assembly handbook" |
|
Icon = ahb_icon |
|
|
|
dev = True # indicates development mode (enables additional tools, log, debug checks, etc.) |
|
|
|
docObserver = None |
|
docLinkObserver = None |
|
partsCache = None |
|
techDrawExtensions = None |
|
|
|
def GetClassName(self): |
|
return "Gui::PythonWorkbench" |
|
|
|
def Initialize(self): |
|
""" |
|
This function is called at the first activation of the workbench. |
|
""" |
|
self.registerCommands() |
|
|
|
def Activated(self): |
|
""" |
|
code which should be computed when a user switch to this workbench |
|
""" |
|
import ahb_document_observer |
|
if self.docLinkObserver is None: |
|
self.docLinkObserver = ahb_document_observer.DocLinkObserver() |
|
|
|
if self.docObserver is None: |
|
self.docObserver = ahb_document_observer.DocObserver() |
|
App.addDocumentObserver(self.docObserver) |
|
|
|
if self.partsCache is None: |
|
import ahb_parts_cache |
|
self.partsCache = ahb_parts_cache.PartsCache() |
|
|
|
if self.techDrawExtensions is None: |
|
import ahb_techdraw_extensions |
|
self.techDrawExtensions = ahb_techdraw_extensions.TechDrawExtensions() |
|
|
|
def Deactivated(self): |
|
""" |
|
code which should be computed when this workbench is deactivated |
|
""" |
|
pass |
|
|
|
def ContextMenu(self, recipient): |
|
# This is executed whenever the user right-clicks on an object |
|
# "recipient" will be either "view" or "tree" |
|
contextMenu = ['AHB_view_edit_source_parts'] |
|
self.appendContextMenu("", "Separator") |
|
self.appendContextMenu("", contextMenu) |
|
self.appendContextMenu("", "Separator") |
|
|
|
def registerCommands(self): |
|
toolbox = [] |
|
|
|
#self.importModule('ahb_cmd_export_csv') |
|
#toolbox.append("AHB_exportCsv") |
|
|
|
self.importModule('ahb_cmd_render') |
|
toolbox.append("AHB_render") |
|
|
|
self.importModule('ahb_cmd_new_step') |
|
toolbox.append("AHB_new_step") |
|
|
|
self.importModule('ahb_cmd_view_annotate') |
|
toolbox.append("AHB_view_annotate") |
|
|
|
self.importModule('ahb_cmd_view_edit_source_parts') |
|
toolbox.append("AHB_view_edit_source_parts") |
|
toolbox.append("AHB_view_add_source_parts") |
|
toolbox.append("AHB_view_remove_source_parts") |
|
|
|
self.importModule('ahb_cmd_view_refresh') |
|
toolbox.append("AHB_view_refresh") |
|
|
|
if self.dev: |
|
self.importModule('ahb_cmd_reload') |
|
toolbox.append("AHB_reload") |
|
|
|
self.appendToolbar("Assembly Handbook", toolbox) |
|
self.appendMenu("Assembly Handbook", toolbox) |
|
|
|
def reload(self): |
|
# Used for development only |
|
self.removeToolbar("Assembly Handbook") |
|
self.removeMenu("Assembly Handbook") |
|
|
|
import importlib |
|
|
|
import ahb_parts_cache |
|
importlib.reload(ahb_parts_cache) |
|
self.partsCache = ahb_parts_cache.PartsCache() |
|
|
|
import ahb_techdraw_extensions |
|
importlib.reload(ahb_techdraw_extensions) |
|
self.techDrawExtensions = ahb_techdraw_extensions.TechDrawExtensions() |
|
|
|
self.registerCommands() |
|
pass |
|
|
|
def importModule(self, moduleName): |
|
import importlib |
|
module = importlib.import_module(moduleName) |
|
if self.dev: |
|
importlib.reload(module) |
|
|
|
Gui.addWorkbench(AssemblyHandbookWorkbench())
|
|
|