Files

94 lines
4.5 KiB
Plaintext

import os
import sys
import traceback
import FreeCAD as App
import FreeCADGui as Gui
from PySide import QtCore
ROOT = os.path.abspath(os.environ.get('QI_ROOT') or os.getcwd())
for path in (os.path.join(ROOT, 'src', 'QInventor'), os.path.join(ROOT, 'tests')):
if path not in sys.path:
sys.path.insert(0, path)
# These preferences reproduce the visible drafting workflow, not proprietary
# Autodesk solver internals. Apply defaults once so user changes persist.
settings = App.ParamGet('User parameter:BaseApp/Preferences/Mod/QInventor')
App.ParamGet('User parameter:BaseApp/Preferences/General').SetString('Language', 'Russian')
dimension_display = App.ParamGet('User parameter:BaseApp/Preferences/Mod/Sketcher')
if not any(item[1] == 'ShowDimensionalName' for item in (dimension_display.GetContents() or [])):
# Keep parameter aliases in the model and constraint list, but show a
# compact value on the canvas by default. Preserve explicit user choices.
dimension_display.SetBool('ShowDimensionalName', False)
App.saveParameter()
if not settings.GetBool('DefaultsV1', False):
App.ParamGet('User parameter:BaseApp/Preferences/General').SetString('AutoloadModule', 'QInventorWorkbench')
App.ParamGet('User parameter:BaseApp/Preferences/Units').SetInt('UserSchema', 0)
view = App.ParamGet('User parameter:BaseApp/Preferences/View')
view.SetString('NavigationStyle', 'Gui::RevitNavigationStyle')
view.SetUnsigned('BackgroundColor', 3908102143)
view.SetUnsigned('BackgroundColor2', 4177066239)
view.SetBool('Simple', False)
sketch = App.ParamGet('User parameter:BaseApp/Preferences/Mod/Sketcher')
for key, value in [('LeaveSketchWithEscape', False), ('ContinuousCreationMode', True),
('ContinuousConstraintMode', True), ('ShowDialogOnDistanceConstraint', True)]:
sketch.SetBool(key, value)
general = App.ParamGet('User parameter:BaseApp/Preferences/Mod/Sketcher/General')
general.SetBool('RestoreCamera', True)
general.SetBool('ForceOrtho', True)
App.ParamGet('User parameter:BaseApp/Preferences/Mod/Sketcher/Tools').SetInt('OnViewParameterVisibility', 2)
App.ParamGet('User parameter:BaseApp/Preferences/Mod/Sketcher/dimensioning').SetBool('SingleDimensioningTool', True)
settings.SetBool('DefaultsV1', True)
App.saveParameter()
# Early development profiles used FreeCAD's historical Open Inventor mouse
# mode. Migrate that one old default, preserving other user navigation choices.
if not settings.GetBool('NavigationV2', False):
view = App.ParamGet('User parameter:BaseApp/Preferences/View')
if view.GetString('NavigationStyle') == 'Gui::InventorNavigationStyle':
view.SetString('NavigationStyle', 'Gui::RevitNavigationStyle')
settings.SetBool('NavigationV2', True)
App.saveParameter()
def start():
try:
# The first launch has already created native menus before this macro.
# Changing the preference alone does not retranslate those QAction labels.
Gui.updateLocale()
import qi_localization
qi_localization.install()
# Native opening names a document after its filename. Keep the saved
# Russian title when a project was passed to the portable launcher.
import qi_io
for document in App.listDocuments().values():
if document.FileName:
qi_io.restore_document_label(document, document.FileName)
Gui.activateWorkbench('QInventorWorkbench')
if os.environ.get('QI_TEST'):
import gui_suite
gui_suite.run(ROOT)
elif not App.ActiveDocument:
import qi_ui
qi_ui.show_welcome()
except Exception:
text = traceback.format_exc()
App.Console.PrintError(text)
os.makedirs(os.path.join(ROOT, 'logs'), exist_ok=True)
with open(os.path.join(ROOT, 'logs', 'startup-error.txt'), 'w', encoding='utf-8') as f:
f.write(text)
if os.environ.get('QI_TEST'):
import json
result_path = os.path.join(ROOT, 'artifacts', 'validation.json')
result = {}
if os.path.exists(result_path):
with open(result_path, encoding='utf-8') as f:
result = json.load(f)
result.update(status='failed', fatal_error=text)
result['failed'] = result.get('failed', 0) + 1
with open(result_path, 'w', encoding='utf-8') as f:
json.dump(result, f, indent=2, ensure_ascii=False)
QtCore.QTimer.singleShot(100, Gui.getMainWindow().close)
QtCore.QTimer.singleShot(800, start)