Repository navigation
Expand file tree
/
Copy pathInitGui.py
More file actions
191 lines (162 loc) · 5.94 KB
/
Copy pathInitGui.py
File metadata and controls
191 lines (162 loc) · 5.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# ***************************************************************************
# * Copyright (C) 2025
# * Structural Analysis Workbench (StEdsFEM)
# * by Kay
# ***************************************************************************
import os
import sys
import inspect
import FreeCAD as App
import FreeCADGui as Gui
from eds_config import module_path
class StEdsFEM(Gui.Workbench):
"""
Structural analysis workbench for FreeCAD.
Provides tools for FEM-based member analysis using CALFEM backend.
"""
def __init__(self):
# Locate module path from config
from eds_config import file_path, module_path
self.__class__.Icon = os.path.join(module_path, "resources", "STedsFEM.svg")
self.__class__.MenuText = "StEdsFEM"
self.__class__.ToolTip = "Structural analysis tools (by Kay)"
# -------------------------------------------------------------------------
def GetClassName(self):
"""Define this as a Python-based workbench."""
return "Gui::PythonWorkbench"
# -------------------------------------------------------------------------
def Initialize(self):
"""Executed on first activation of the workbench."""
import importlib, sys
from eds_config import module_path
# Ensure this directory is on sys.path
#current_dir = module_path
## if module_path not in sys.path:
## sys.path.append(module_path)
# Import command modules dynamically
for mod in [
"load_distributed",
"load_nodal",
"suport",
"section",
"material",
"member",
"calc", "calc_rp",
"diagram",
"displacement",
"reaction",
"import_section",
#"imp_js_section",
"imp_section"
]:
try:
importlib.import_module(mod)
App.Console.PrintMessage(f"✅ Loaded: {mod}\n")
except Exception as e:
App.Console.PrintError(f"❌ Failed to load {mod}: {e}\n")
# Optional: support for Draft/Sketcher toolbars
try:
import DraftTools
import SketcherGui
except ImportError as e:
App.Console.PrintWarning(f"⚠️ Could not import Draft/Sketcher: {e}\n")
# ---------------------------------------------------------------------
# Toolbars setup
# ---------------------------------------------------------------------
self.appendToolbar("DraftDraw", [
"Sketcher_NewSketch",
"Draft_Line",
"Draft_Wire",
"Draft_ArcTools",
"Draft_BSpline",
"Draft_Dimension",
])
self.appendToolbar("DraftEdit", [
"Draft_Move",
"Draft_Rotate",
"Draft_Clone",
"Draft_Offset",
"Draft_Trimex",
"Draft_Join",
"Draft_Split",
"Draft_Stretch",
"Draft_Draft2Sketch",
])
self.appendToolbar("DraftSnap", [
"Draft_Snap_Lock",
"Draft_Snap_Endpoint",
"Draft_Snap_Midpoint",
"Draft_Snap_Center",
"Draft_Snap_Angle",
"Draft_Snap_Intersection",
"Draft_Snap_Perpendicular",
"Draft_Snap_Extension",
"Draft_Snap_Parallel",
"Draft_Snap_Special",
"Draft_Snap_Near",
"Draft_Snap_Ortho",
"Draft_Snap_Grid",
"Draft_Snap_WorkingPlane",
"Draft_Snap_Dimensions",
"Draft_ToggleGrid",
])
self.appendToolbar("DraftTools", [
"Draft_SelectPlane",
"Draft_SetStyle",
])
# ---------------------------------------------------------------------
# Structural-specific toolbars
# ---------------------------------------------------------------------
self.appendToolbar("StructureLoads", [
"load_distributed",
"load_nodal",
])
self.appendToolbar("StructureTools", [
"member",
"Support",
"section",
"material",
])
self.appendToolbar("StructureResults", [
"Calc_2",
"Show_diagram",
])
# ---------------------------------------------------------------------
# Menu setup
# ---------------------------------------------------------------------
self.DefineList = [
"Import_section",
"Select_section",
#"ImportSectionJSON",
"member",
"section",
"material",
]
self.appendMenu("Define", self.DefineList)
self.AssignmentList = [
"load_distributed",
"load_nodal",
#"member",
"Support",
]
self.appendMenu("Assignment", self.AssignmentList)
self.ResultList = [
"Calc_1", "Calc_2",
"ReactionResults",
"Show_diagram",
"View_displacement",
]
self.appendMenu("Analysis", self.ResultList)
App.Console.PrintMessage("🏗️ StEdsFEM workbench initialized.\n")
# -------------------------------------------------------------------------
def Activated(self):
"""Code executed when the workbench is activated."""
App.Console.PrintMessage("🔹 StEdsFEM Workbench activated.\n")
# -------------------------------------------------------------------------
def Deactivated(self):
"""Code executed when the workbench is deactivated."""
App.Console.PrintMessage("🔸 StEdsFEM Workbench deactivated.\n")
# -------------------------------------------------------------------------
# Register workbench with FreeCAD
# -------------------------------------------------------------------------
Gui.addWorkbench(StEdsFEM())