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.) context = None 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 """ if self.context is None: self.initializeContext() 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 initializeContext(self): import ahb_context self.context = ahb_context.AHB_Context() def registerCommands(self): toolbox = [] #self.importModule('ahb_cmd_export_csv') #toolbox.append("AHB_exportCsv") #self.importModule('ahb_cmd_set_active_stage') #toolbox.append("AHB_setActiveStage") #self.importModule('ahb_cmd_set_part_stage') #toolbox.append("AHB_setPartStage") #self.importModule('ahb_cmd_switch_visibility_mode') #toolbox.append("AHB_switchVisibilityMode") #self.importModule('ahb_cmd_render') #toolbox.append("AHB_render") #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") 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") self.context.setAnimationActive(False) import importlib import ahb_context importlib.reload(ahb_context) 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.initializeContext() self.registerCommands() pass def importModule(self, moduleName): import importlib module = importlib.import_module(moduleName) if self.dev: importlib.reload(module) Gui.addWorkbench(AssemblyHandbookWorkbench())