27
from PySide import QtCore, QtGui
28
from draftutils.translate import translate
30
from PySide.QtCore import QT_TRANSLATE_NOOP
33
def translate(ctxt,txt):
35
def QT_TRANSLATE_NOOP(ctxt,txt):
39
__title__ = "FreeCAD Axis System"
40
__author__ = "Yorik van Havre"
41
__url__ = "https://www.freecad.org"
53
"The Axis System object"
55
def __init__(self,obj):
58
self.setProperties(obj)
60
def setProperties(self,obj):
62
pl = obj.PropertiesList
64
obj.addProperty("App::PropertyLinkList","Axes","AxisSystem", QT_TRANSLATE_NOOP("App::Property","The axes this system is made of"))
65
if not "Placement" in pl:
66
obj.addProperty("App::PropertyPlacement","Placement","AxisSystem",QT_TRANSLATE_NOOP("App::Property","The placement of this axis system"))
67
self.Type = "AxisSystem"
69
def onDocumentRestored(self,obj):
71
self.setProperties(obj)
73
def execute(self,obj):
77
def onBeforeChange(self,obj,prop):
79
if prop == "Placement":
80
self.Placement = obj.Placement
82
def onChanged(self,obj,prop):
84
if prop == "Placement":
85
if hasattr(self,"Placement"):
86
delta = obj.Placement.multiply(self.Placement.inverse())
88
o.Placement = delta.multiply(o.Placement)
94
def loads(self,state):
98
def getPoints(self,obj):
100
"returns the gridpoints of linked axes"
103
if len(obj.Axes) == 1:
104
for e in obj.Axes[0].Shape.Edges:
105
pts.append(e.Vertexes[0].Point)
106
elif len(obj.Axes) == 2:
107
set1 = obj.Axes[0].Shape.Edges
108
set2 = obj.Axes[1].Shape.Edges
111
pts.extend(DraftGeomUtils.findIntersection(e1,e2))
112
elif len(obj.Axes) == 3:
113
set1 = obj.Axes[0].Shape.Edges
114
set2 = obj.Axes[1].Shape.Edges
115
set3 = obj.Axes[2].Shape.Edges
120
bset.extend(DraftGeomUtils.findIntersection(e1,e2))
123
cv = e3.Vertexes[0].Point
126
v = e3.Vertexes[0].Point.sub(cv)
127
pts.extend([p.add(v) for p in bset])
130
def getAxisData(self,obj):
132
for axis in obj.Axes:
133
if hasattr(axis,"Proxy") and hasattr(axis.Proxy,"getAxisData"):
134
data.append(axis.Proxy.getAxisData(axis))
138
class _ViewProviderAxisSystem:
140
"A View Provider for the Axis object"
142
def __init__(self,vobj):
149
return ":/icons/Arch_Axis_System_Tree.svg"
151
def claimChildren(self):
153
if hasattr(self,"axes"):
157
def attach(self, vobj):
158
self.Object = vobj.Object
159
self.axes = vobj.Object.Axes
160
vobj.addDisplayMode(coin.SoSeparator(),"Default")
162
def getDisplayModes(self,vobj):
166
def getDefaultDisplayMode(self):
170
def setDisplayMode(self,mode):
174
def updateData(self,obj,prop):
178
def onChanged(self, vobj, prop):
180
if prop == "Visibility":
181
for o in vobj.Object.Axes:
182
o.ViewObject.Visibility = vobj.Visibility
184
def setEdit(self, vobj, mode):
188
taskd = AxisSystemTaskPanel(vobj.Object)
189
FreeCADGui.Control.showDialog(taskd)
192
def unsetEdit(self, vobj, mode):
196
FreeCADGui.Control.closeDialog()
199
def doubleClicked(self, vobj):
202
def setupContextMenu(self, vobj, menu):
203
actionEdit = QtGui.QAction(translate("Arch", "Edit"),
205
QtCore.QObject.connect(actionEdit,
206
QtCore.SIGNAL("triggered()"),
208
menu.addAction(actionEdit)
211
FreeCADGui.ActiveDocument.setEdit(self.Object, 0)
217
def loads(self,state):
222
class AxisSystemTaskPanel:
224
'''A TaskPanel for all the section plane object'''
226
def __init__(self,obj):
229
self.form = QtGui.QWidget()
230
self.form.setObjectName("Axis System")
231
self.grid = QtGui.QGridLayout(self.form)
232
self.grid.setObjectName("grid")
233
self.title = QtGui.QLabel(self.form)
234
self.grid.addWidget(self.title, 0, 0, 1, 2)
237
self.tree = QtGui.QTreeWidget(self.form)
238
self.grid.addWidget(self.tree, 1, 0, 1, 2)
239
self.tree.setColumnCount(1)
240
self.tree.header().hide()
243
self.addButton = QtGui.QPushButton(self.form)
244
self.addButton.setObjectName("addButton")
245
self.addButton.setIcon(QtGui.QIcon(":/icons/Arch_Add.svg"))
246
self.grid.addWidget(self.addButton, 3, 0, 1, 1)
248
self.delButton = QtGui.QPushButton(self.form)
249
self.delButton.setObjectName("delButton")
250
self.delButton.setIcon(QtGui.QIcon(":/icons/Arch_Remove.svg"))
251
self.grid.addWidget(self.delButton, 3, 1, 1, 1)
253
QtCore.QObject.connect(self.addButton, QtCore.SIGNAL("clicked()"), self.addElement)
254
QtCore.QObject.connect(self.delButton, QtCore.SIGNAL("clicked()"), self.removeElement)
257
def isAllowedAlterSelection(self):
261
def isAllowedAlterView(self):
265
def getStandardButtons(self):
267
return QtGui.QDialogButtonBox.Ok
269
def getIcon(self,obj):
271
if hasattr(obj.ViewObject,"Proxy"):
272
return QtGui.QIcon(obj.ViewObject.Proxy.getIcon())
273
elif obj.isDerivedFrom("Sketcher::SketchObject"):
274
return QtGui.QIcon(":/icons/Sketcher_Sketch.svg")
275
elif obj.isDerivedFrom("App::DocumentObjectGroup"):
276
return QtGui.QApplication.style().standardIcon(QtGui.QStyle.SP_DirIcon)
277
elif hasattr(obj.ViewObject, "Icon"):
278
return QtGui.QIcon(obj.ViewObject.Icon)
279
return QtGui.QIcon(":/icons/Part_3D_object.svg")
285
for o in self.obj.Axes:
286
item = QtGui.QTreeWidgetItem(self.tree)
287
item.setText(0,o.Label)
288
item.setToolTip(0,o.Name)
289
item.setIcon(0,self.getIcon(o))
290
self.retranslateUi(self.form)
292
def addElement(self):
295
for o in FreeCADGui.Selection.getSelection():
296
if not(o in self.obj.Axes) and (o != self.obj):
302
def removeElement(self):
305
it = self.tree.currentItem()
307
o = FreeCAD.ActiveDocument.getObject(str(it.toolTip(0)))
308
if o in self.obj.Axes:
316
FreeCAD.ActiveDocument.recompute()
317
FreeCADGui.ActiveDocument.resetEdit()
320
def retranslateUi(self, TaskPanel):
322
TaskPanel.setWindowTitle(QtGui.QApplication.translate("Arch", "Axes", None))
323
self.delButton.setText(QtGui.QApplication.translate("Arch", "Remove", None))
324
self.addButton.setText(QtGui.QApplication.translate("Arch", "Add", None))
325
self.title.setText(QtGui.QApplication.translate("Arch", "Axis system components", None))