FreeCAD-macros
177 строк · 5.9 Кб
1# Hyperbola Creator - Version 0.7
2'''
3***************************************************************************
4* Copyright (c) 2015 <quick61> *
5* *
6* This file is a supplement to the FreeCAD CAx development system. *
7* *
8* This program is free software; you can redistribute it and/or modify *
9* it under the terms of the GNU General Public License (GPL) *
10* as published by the Free Software Foundation; either version 3 of *
11* the License, or (at your option) any later version. *
12* for detail see the LICENCE text file. *
13* *
14* This software is distributed in the hope that it will be useful, *
15* but WITHOUT ANY WARRANTY; without even the implied warranty of *
16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17* GNU Library General Public License for more details. *
18* *
19* You should have received a copy of the GNU General Public License *
20* License along with this macro; if not, write to the Free Software *
21* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
22* USA *
23***************************************************************************
24'''
25
26
27_Title__="Hyperbola Creator"
28__Author__ = "Quick61"
29__Version__ = "00.11"
30__Date__ = "16/06/2015"
31
32
33__Comment__ = "This macro creates ..."
34
35
36__Web__ = "http://forum.freecadweb.org/viewtopic.php?f=22&t=11328"
37__Wiki__ = "http://www.freecadweb.org"
38__Icon__ = "/usr/lib/freecad/Mod/plugins/FreeCAD-macros/icons/HyperbolaIcon.png"
39__IconW__ = "C:/Documents and Settings/YourUserName/Application Data/FreeCAD"
40__Help__ = "start the macro and follow the instructions"
41__Status__ = ""
42__Requires__ = ""
43__License__ = "GPL-3.0-or-later"
44__Communication__ = "https://forum.freecadweb.org/memberlist.php?mode=viewprofile&u=2030"
45
46
47import FreeCAD, FreeCADGui, Part, PySide
48from FreeCAD import Base
49from PySide import QtCore, QtGui
50from PySide.QtGui import QLineEdit, QRadioButton
51App=FreeCAD
52
53#+ hack
54import sys,traceback
55def sayexc(mess=''):
56exc_type, exc_value, exc_traceback = sys.exc_info()
57ttt=repr(traceback.format_exception(exc_type, exc_value,exc_traceback))
58lls=eval(ttt)
59l=len(lls)
60l2=lls[(l-3):]
61FreeCAD.Console.PrintError(mess + "\n" +"--> ".join(l2))
62
63class p():
64
65def makeHyp(self):
66
67if self.radio1.isChecked():
68try:
69
70Mi = float(self.r1.text())
71Ma = float(self.r2.text())
72tS1 = float(self.s1.text())
73tS2 = float(self.s2.text())
74
75hyp=Part.Hyperbola()
76hyp.MinorRadius=Mi
77hyp.MajorRadius=Ma
78
79shape=hyp.toShape(tS1,tS2)
80Part.show(shape)
81
82except:
83sayexc()
84FreeCAD.Console.PrintError("Unable to complete task")
85
86self.close()
87
88
89if self.radio2.isChecked():
90try:
91
92Mi = float(self.r1.text())
93Ma = float(self.r2.text())
94tS1 = float(self.s1.text())
95tS2 = float(self.s2.text())
96Dg = float(self.Dg.text())
97
98hyp=Part.Hyperbola()
99hyp.MinorRadius=Mi
100hyp.MajorRadius=Ma
101
102shape=hyp.toShape(tS1,tS2)
103rev=shape.revolve(App.Vector(0,0,0),App.Vector(0,1,0),Dg) # revolve around Y axis by number of degrees
104Part.show(rev)
105except:
106sayexc()
107FreeCAD.Console.PrintError("Unable to complete task")
108
109self.close()
110
111def close(self):
112self.dialog.hide()
113
114
115
116def __init__(self):
117self.dialog = None
118
119self.dialog = QtGui.QDialog()
120self.dialog.resize(280,110)
121
122self.dialog.setWindowTitle("Hyperbola Creator")
123la = QtGui.QVBoxLayout(self.dialog)
124
125self.radio1 = QRadioButton("Make 2D Shape")
126self.radio2 = QRadioButton("Make 3D Revolution")
127
128# # # #
129# set default to "Make 2D Shape" & make radio buttons - Change self.radio1.setChecked(True) to
130# self.radio2.setChecked(True) to set "Make 3D Revolution" as default
131# # # #
132
133self.radio1.setChecked(True)
134la.addWidget(self.radio1)
135la.addWidget(self.radio2)
136
137iN1 = QtGui.QLabel("Minor Radius")
138la.addWidget(iN1)
139self.r1 = QtGui.QLineEdit()
140la.addWidget(self.r1)
141self.r1.setText('2')
142
143iN2 = QtGui.QLabel("Major Radius")
144la.addWidget(iN2)
145self.r2 = QtGui.QLineEdit()
146la.addWidget(self.r2)
147self.r2.setText('3')
148
149iN3 = QtGui.QLabel("Range Of Curve - Minimum")
150la.addWidget(iN3)
151self.s1 = QtGui.QLineEdit()
152la.addWidget(self.s1)
153self.s1.setText('-2')
154
155iN4 = QtGui.QLabel("Range Of Curve - Maximum")
156la.addWidget(iN4)
157self.s2 = QtGui.QLineEdit()
158la.addWidget(self.s2)
159self.s2.setText('2')
160
161iN5 = QtGui.QLabel("Degrees of Revolve (Only valid for 3D Revolution)")
162la.addWidget(iN5)
163self.Dg = QtGui.QLineEdit()
164self.Dg.insert("360")
165la.addWidget(self.Dg)
166
167okbox = QtGui.QDialogButtonBox(self.dialog)
168okbox.setOrientation(QtCore.Qt.Horizontal)
169okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
170la.addWidget(okbox)
171QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), self.makeHyp)
172QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), self.close)
173QtCore.QMetaObject.connectSlotsByName(self.dialog)
174self.dialog.show()
175self.dialog.exec_()
176
177p()
178