|
|
|
@ -2,73 +2,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
from pathlib import Path
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import traceback
|
|
|
|
|
|
|
|
|
|
|
|
import FreeCADGui as Gui
|
|
|
|
import FreeCADGui as Gui
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
from PySide6 import QtCore
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
from PySide2 import QtCore
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
|
|
from PySide import QtCore
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import ExchangeBootstrap
|
|
|
|
|
|
|
|
import ExchangeWriteBack
|
|
|
|
|
|
|
|
import ManualWiring
|
|
|
|
|
|
|
|
import TemplateAuthoring
|
|
|
|
|
|
|
|
import TemplateAuthoringPanel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
COMMANDS = [
|
|
|
|
COMMANDS = [
|
|
|
|
TemplateAuthoringPanel.COMMAND_NAME,
|
|
|
|
"QET_Template_OpenAuthoringPanel",
|
|
|
|
"QET_Template_AddTerminal",
|
|
|
|
"QET_Template_AddTerminal",
|
|
|
|
"QET_Template_ValidateTerminals",
|
|
|
|
"QET_Template_ValidateTerminals",
|
|
|
|
"QET_Template_SaveAsFCStd",
|
|
|
|
"QET_Template_SaveAsFCStd",
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _append_init_log(message):
|
|
|
|
def _append_init_log(message, os_module=os, path_class=Path):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
local_app_data = os.environ.get("LOCALAPPDATA", "").strip()
|
|
|
|
local_app_data = os_module.environ.get("LOCALAPPDATA", "").strip()
|
|
|
|
if local_app_data:
|
|
|
|
if local_app_data:
|
|
|
|
log_path = os.path.join(local_app_data, "QETDeps", "freecad_exchange_bootstrap.log")
|
|
|
|
log_path = os_module.path.join(local_app_data, "QETDeps", "freecad_exchange_bootstrap.log")
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
log_path = os.path.join(str(Path.home()), "AppData", "Local", "QETDeps", "freecad_exchange_bootstrap.log")
|
|
|
|
log_path = os_module.path.join(
|
|
|
|
os.makedirs(os.path.dirname(log_path), exist_ok=True)
|
|
|
|
str(path_class.home()),
|
|
|
|
|
|
|
|
"AppData",
|
|
|
|
|
|
|
|
"Local",
|
|
|
|
|
|
|
|
"QETDeps",
|
|
|
|
|
|
|
|
"freecad_exchange_bootstrap.log",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
os_module.makedirs(os_module.path.dirname(log_path), exist_ok=True)
|
|
|
|
with open(log_path, "a", encoding="utf-8") as handle:
|
|
|
|
with open(log_path, "a", encoding="utf-8") as handle:
|
|
|
|
handle.write(message + "\n")
|
|
|
|
handle.write(message + "\n")
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_append_init_log("InitGui imported")
|
|
|
|
_append_init_log("InitGui start")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _register_exchange_commands():
|
|
|
|
def _safe_import(module_name, append_init_log=_append_init_log, traceback_module=traceback):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
ExchangeWriteBack.ensure_document_observer_installed()
|
|
|
|
module = __import__(module_name)
|
|
|
|
|
|
|
|
append_init_log("InitGui imported {0}".format(module_name))
|
|
|
|
|
|
|
|
return module
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
append_init_log(
|
|
|
|
|
|
|
|
"InitGui failed to import {0}:\n{1}".format(
|
|
|
|
|
|
|
|
module_name,
|
|
|
|
|
|
|
|
traceback_module.format_exc(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _register_exchange_commands(
|
|
|
|
|
|
|
|
safe_import=_safe_import,
|
|
|
|
|
|
|
|
append_init_log=_append_init_log,
|
|
|
|
|
|
|
|
traceback_module=traceback,
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
exchange_write_back = safe_import("ExchangeWriteBack")
|
|
|
|
|
|
|
|
manual_wiring = safe_import("ManualWiring")
|
|
|
|
|
|
|
|
template_authoring = safe_import("TemplateAuthoring")
|
|
|
|
|
|
|
|
template_authoring_panel = safe_import("TemplateAuthoringPanel")
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
ExchangeWriteBack.register_commands()
|
|
|
|
if exchange_write_back is not None:
|
|
|
|
|
|
|
|
exchange_write_back.ensure_document_observer_installed()
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
append_init_log(
|
|
|
|
|
|
|
|
"InitGui failed to install write-back observer:\n{0}".format(
|
|
|
|
|
|
|
|
traceback_module.format_exc()
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
ManualWiring.register_commands()
|
|
|
|
if exchange_write_back is not None:
|
|
|
|
|
|
|
|
exchange_write_back.register_commands()
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
append_init_log(
|
|
|
|
|
|
|
|
"InitGui failed to register write-back commands:\n{0}".format(
|
|
|
|
|
|
|
|
traceback_module.format_exc()
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
TemplateAuthoring.register_commands()
|
|
|
|
if manual_wiring is not None:
|
|
|
|
|
|
|
|
manual_wiring.register_commands()
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
append_init_log(
|
|
|
|
|
|
|
|
"InitGui failed to register wiring commands:\n{0}".format(
|
|
|
|
|
|
|
|
traceback_module.format_exc()
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
TemplateAuthoringPanel.register_commands()
|
|
|
|
if template_authoring is not None:
|
|
|
|
|
|
|
|
template_authoring.register_commands()
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
append_init_log(
|
|
|
|
|
|
|
|
"InitGui failed to register template authoring commands:\n{0}".format(
|
|
|
|
|
|
|
|
traceback_module.format_exc()
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
if template_authoring_panel is not None:
|
|
|
|
|
|
|
|
template_authoring_panel.register_commands()
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
append_init_log(
|
|
|
|
|
|
|
|
"InitGui failed to register template panel command:\n{0}".format(
|
|
|
|
|
|
|
|
traceback_module.format_exc()
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _bootstrap_if_requested(
|
|
|
|
|
|
|
|
safe_import=_safe_import,
|
|
|
|
|
|
|
|
append_init_log=_append_init_log,
|
|
|
|
|
|
|
|
traceback_module=traceback,
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
exchange_bootstrap = safe_import("ExchangeBootstrap")
|
|
|
|
|
|
|
|
if exchange_bootstrap is None:
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
exchange_bootstrap.bootstrap_if_requested()
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
append_init_log(
|
|
|
|
|
|
|
|
"InitGui bootstrap_if_requested failed:\n{0}".format(
|
|
|
|
|
|
|
|
traceback_module.format_exc()
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
globals()["FreeCADExchange_COMMANDS"] = COMMANDS
|
|
|
|
|
|
|
|
globals()["FreeCADExchange_append_init_log"] = _append_init_log
|
|
|
|
|
|
|
|
globals()["FreeCADExchange_register_exchange_commands"] = _register_exchange_commands
|
|
|
|
|
|
|
|
globals()["FreeCADExchange_bootstrap_if_requested"] = _bootstrap_if_requested
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FreeCADExchangeWorkbench(Gui.Workbench):
|
|
|
|
class FreeCADExchangeWorkbench(Gui.Workbench):
|
|
|
|
@ -99,20 +167,47 @@ class FreeCADExchangeWorkbench(Gui.Workbench):
|
|
|
|
"................"};
|
|
|
|
"................"};
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def Initialize(self):
|
|
|
|
def Initialize(
|
|
|
|
_register_exchange_commands()
|
|
|
|
self,
|
|
|
|
self.appendToolbar("QET模板", COMMANDS)
|
|
|
|
register_exchange_commands=FreeCADExchange_register_exchange_commands,
|
|
|
|
self.appendMenu("QET模板", COMMANDS)
|
|
|
|
append_init_log=FreeCADExchange_append_init_log,
|
|
|
|
_append_init_log("FreeCADExchangeWorkbench initialized")
|
|
|
|
commands=FreeCADExchange_COMMANDS,
|
|
|
|
|
|
|
|
):
|
|
|
|
def Activated(self):
|
|
|
|
register_exchange_commands()
|
|
|
|
_register_exchange_commands()
|
|
|
|
self.appendToolbar("QET模板", commands)
|
|
|
|
_append_init_log("FreeCADExchangeWorkbench activated")
|
|
|
|
self.appendMenu("QET模板", commands)
|
|
|
|
|
|
|
|
append_init_log("FreeCADExchangeWorkbench initialized")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def Activated(
|
|
|
|
|
|
|
|
self,
|
|
|
|
|
|
|
|
register_exchange_commands=FreeCADExchange_register_exchange_commands,
|
|
|
|
|
|
|
|
append_init_log=FreeCADExchange_append_init_log,
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
register_exchange_commands()
|
|
|
|
|
|
|
|
append_init_log("FreeCADExchangeWorkbench activated")
|
|
|
|
|
|
|
|
|
|
|
|
def Deactivated(self):
|
|
|
|
def Deactivated(self):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def GetClassName(self):
|
|
|
|
|
|
|
|
return "Gui::PythonWorkbench"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_register_exchange_commands()
|
|
|
|
|
|
|
|
Gui.addWorkbench(FreeCADExchangeWorkbench())
|
|
|
|
Gui.addWorkbench(FreeCADExchangeWorkbench())
|
|
|
|
QtCore.QTimer.singleShot(0, ExchangeBootstrap.bootstrap_if_requested)
|
|
|
|
_append_init_log("InitGui workbench registered")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
from PySide6 import QtCore
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
from PySide2 import QtCore
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
from PySide import QtCore
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
|
|
QtCore = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if QtCore is not None:
|
|
|
|
|
|
|
|
QtCore.QTimer.singleShot(0, FreeCADExchange_bootstrap_if_requested)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
FreeCADExchange_bootstrap_if_requested()
|
|
|
|
|