FreeCAD

Форк
0
/
ArchAxisSystem.py 
325 строк · 9.9 Кб
1
#***************************************************************************
2
#*   Copyright (c) 2011 Yorik van Havre <yorik@uncreated.net>              *
3
#*                                                                         *
4
#*   This program is free software; you can redistribute it and/or modify  *
5
#*   it under the terms of the GNU Lesser General Public License (LGPL)    *
6
#*   as published by the Free Software Foundation; either version 2 of     *
7
#*   the License, or (at your option) any later version.                   *
8
#*   for detail see the LICENCE text file.                                 *
9
#*                                                                         *
10
#*   This program is distributed in the hope that it will be useful,       *
11
#*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12
#*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13
#*   GNU Library General Public License for more details.                  *
14
#*                                                                         *
15
#*   You should have received a copy of the GNU Library General Public     *
16
#*   License along with this program; if not, write to the Free Software   *
17
#*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
18
#*   USA                                                                   *
19
#*                                                                         *
20
#***************************************************************************
21

22
import FreeCAD
23
import DraftGeomUtils
24
if FreeCAD.GuiUp:
25
    import FreeCADGui
26
    import Draft
27
    from PySide import QtCore, QtGui
28
    from draftutils.translate import translate
29
    from pivy import coin
30
    from PySide.QtCore import QT_TRANSLATE_NOOP
31
else:
32
    # \cond
33
    def translate(ctxt,txt):
34
        return txt
35
    def QT_TRANSLATE_NOOP(ctxt,txt):
36
        return txt
37
    # \endcond
38

39
__title__  = "FreeCAD Axis System"
40
__author__ = "Yorik van Havre"
41
__url__    = "https://www.freecad.org"
42

43
## @package ArchAxisSystem
44
#  \ingroup ARCH
45
#  \brief Axis system for the Arch workbench
46
#
47
#  This module provides tools to build axis systems
48
#  An axis system is a collection of multiple axes
49

50

51
class _AxisSystem:
52

53
    "The Axis System object"
54

55
    def __init__(self,obj):
56

57
        obj.Proxy = self
58
        self.setProperties(obj)
59

60
    def setProperties(self,obj):
61

62
        pl = obj.PropertiesList
63
        if not "Axes" in pl:
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"
68

69
    def onDocumentRestored(self,obj):
70

71
        self.setProperties(obj)
72

73
    def execute(self,obj):
74

75
        pass
76

77
    def onBeforeChange(self,obj,prop):
78

79
        if prop == "Placement":
80
            self.Placement = obj.Placement
81

82
    def onChanged(self,obj,prop):
83

84
        if prop == "Placement":
85
            if hasattr(self,"Placement"):
86
                delta = obj.Placement.multiply(self.Placement.inverse())
87
                for o in obj.Axes:
88
                    o.Placement = delta.multiply(o.Placement)
89

90
    def dumps(self):
91

92
        return None
93

94
    def loads(self,state):
95

96
        return None
97

98
    def getPoints(self,obj):
99

100
        "returns the gridpoints of linked axes"
101

102
        pts = []
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 # X
108
            set2 = obj.Axes[1].Shape.Edges # Y
109
            for e1 in set1:
110
                for e2 in set2:
111
                    pts.extend(DraftGeomUtils.findIntersection(e1,e2))
112
        elif len(obj.Axes) == 3:
113
            set1 = obj.Axes[0].Shape.Edges # X
114
            set2 = obj.Axes[1].Shape.Edges # Y
115
            set3 = obj.Axes[2].Shape.Edges # Z
116
            bset = []
117
            cv = None
118
            for e1 in set1:
119
                for e2 in set2:
120
                    bset.extend(DraftGeomUtils.findIntersection(e1,e2))
121
            for e3 in set3:
122
                if not cv:
123
                    cv = e3.Vertexes[0].Point
124
                    pts.extend(bset)
125
                else:
126
                    v = e3.Vertexes[0].Point.sub(cv)
127
                    pts.extend([p.add(v) for p in bset])
128
        return pts
129

130
    def getAxisData(self,obj):
131
        data = []
132
        for axis in obj.Axes:
133
            if hasattr(axis,"Proxy") and hasattr(axis.Proxy,"getAxisData"):
134
                data.append(axis.Proxy.getAxisData(axis))
135
        return data
136

137

138
class _ViewProviderAxisSystem:
139

140
    "A View Provider for the Axis object"
141

142
    def __init__(self,vobj):
143

144
        vobj.Proxy = self
145

146
    def getIcon(self):
147

148
        import Arch_rc
149
        return ":/icons/Arch_Axis_System_Tree.svg"
150

151
    def claimChildren(self):
152

153
        if hasattr(self,"axes"):
154
            return self.axes
155
        return []
156

157
    def attach(self, vobj):
158
        self.Object = vobj.Object
159
        self.axes = vobj.Object.Axes
160
        vobj.addDisplayMode(coin.SoSeparator(),"Default")
161

162
    def getDisplayModes(self,vobj):
163

164
        return ["Default"]
165

166
    def getDefaultDisplayMode(self):
167

168
        return "Default"
169

170
    def setDisplayMode(self,mode):
171

172
        return mode
173

174
    def updateData(self,obj,prop):
175

176
        self.axes = obj.Axes
177

178
    def onChanged(self, vobj, prop):
179

180
        if prop == "Visibility":
181
            for o in vobj.Object.Axes:
182
                o.ViewObject.Visibility = vobj.Visibility
183

184
    def setEdit(self, vobj, mode):
185
        if mode != 0:
186
            return None
187

188
        taskd = AxisSystemTaskPanel(vobj.Object)
189
        FreeCADGui.Control.showDialog(taskd)
190
        return True
191

192
    def unsetEdit(self, vobj, mode):
193
        if mode != 0:
194
            return None
195

196
        FreeCADGui.Control.closeDialog()
197
        return True
198

199
    def doubleClicked(self, vobj):
200
        self.edit()
201

202
    def setupContextMenu(self, vobj, menu):
203
        actionEdit = QtGui.QAction(translate("Arch", "Edit"),
204
                                   menu)
205
        QtCore.QObject.connect(actionEdit,
206
                               QtCore.SIGNAL("triggered()"),
207
                               self.edit)
208
        menu.addAction(actionEdit)
209

210
    def edit(self):
211
        FreeCADGui.ActiveDocument.setEdit(self.Object, 0)
212

213
    def dumps(self):
214

215
        return None
216

217
    def loads(self,state):
218

219
        return None
220

221

222
class AxisSystemTaskPanel:
223

224
    '''A TaskPanel for all the section plane object'''
225

226
    def __init__(self,obj):
227

228
        self.obj = 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)
235

236
        # tree
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()
241

242
        # buttons
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)
247

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)
252

253
        QtCore.QObject.connect(self.addButton, QtCore.SIGNAL("clicked()"), self.addElement)
254
        QtCore.QObject.connect(self.delButton, QtCore.SIGNAL("clicked()"), self.removeElement)
255
        self.update()
256

257
    def isAllowedAlterSelection(self):
258

259
        return True
260

261
    def isAllowedAlterView(self):
262

263
        return True
264

265
    def getStandardButtons(self):
266

267
        return QtGui.QDialogButtonBox.Ok
268

269
    def getIcon(self,obj):
270

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")
280

281
    def update(self):
282

283
        self.tree.clear()
284
        if self.obj:
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)
291

292
    def addElement(self):
293

294
        if self.obj:
295
            for o in FreeCADGui.Selection.getSelection():
296
                if not(o in self.obj.Axes) and (o != self.obj):
297
                    g = self.obj.Axes
298
                    g.append(o)
299
                    self.obj.Axes = g
300
            self.update()
301

302
    def removeElement(self):
303

304
        if self.obj:
305
            it = self.tree.currentItem()
306
            if it:
307
                o = FreeCAD.ActiveDocument.getObject(str(it.toolTip(0)))
308
                if o in self.obj.Axes:
309
                    g = self.obj.Axes
310
                    g.remove(o)
311
                    self.obj.Axes = g
312
            self.update()
313

314
    def accept(self):
315

316
        FreeCAD.ActiveDocument.recompute()
317
        FreeCADGui.ActiveDocument.resetEdit()
318
        return True
319

320
    def retranslateUi(self, TaskPanel):
321

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))
326

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.