FreeCAD-macros

Форк
0
/
HyperbolaCreater.FCMacro 
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

47
import FreeCAD, FreeCADGui, Part, PySide
48
from FreeCAD import Base
49
from PySide import QtCore, QtGui
50
from PySide.QtGui import QLineEdit, QRadioButton
51
App=FreeCAD
52

53
#+ hack
54
import sys,traceback
55
def sayexc(mess=''):
56
	exc_type, exc_value, exc_traceback = sys.exc_info()
57
	ttt=repr(traceback.format_exception(exc_type, exc_value,exc_traceback))
58
	lls=eval(ttt)
59
	l=len(lls)
60
	l2=lls[(l-3):]
61
	FreeCAD.Console.PrintError(mess + "\n" +"-->  ".join(l2))
62

63
class p():
64

65
    def makeHyp(self):
66

67
        if self.radio1.isChecked():
68
            try:
69

70
                Mi = float(self.r1.text())
71
                Ma = float(self.r2.text())
72
                tS1 = float(self.s1.text())
73
                tS2 = float(self.s2.text())
74

75
                hyp=Part.Hyperbola()
76
                hyp.MinorRadius=Mi
77
                hyp.MajorRadius=Ma
78

79
                shape=hyp.toShape(tS1,tS2)
80
                Part.show(shape)
81

82
            except:
83
                sayexc()
84
                FreeCAD.Console.PrintError("Unable to complete task")
85

86
            self.close()
87

88

89
        if self.radio2.isChecked():
90
            try:
91

92
                Mi = float(self.r1.text())
93
                Ma = float(self.r2.text())
94
                tS1 = float(self.s1.text())
95
                tS2 = float(self.s2.text())
96
                Dg = float(self.Dg.text())
97

98
                hyp=Part.Hyperbola()
99
                hyp.MinorRadius=Mi
100
                hyp.MajorRadius=Ma
101

102
                shape=hyp.toShape(tS1,tS2)
103
                rev=shape.revolve(App.Vector(0,0,0),App.Vector(0,1,0),Dg) # revolve around Y axis by number of degrees
104
                Part.show(rev)
105
            except:
106
                sayexc()
107
                FreeCAD.Console.PrintError("Unable to complete task")
108

109
            self.close()
110

111
    def close(self):
112
        self.dialog.hide()
113

114

115

116
    def __init__(self):
117
        self.dialog = None
118

119
        self.dialog = QtGui.QDialog()
120
        self.dialog.resize(280,110)
121

122
        self.dialog.setWindowTitle("Hyperbola Creator")
123
        la = QtGui.QVBoxLayout(self.dialog)
124

125
        self.radio1 = QRadioButton("Make 2D Shape")
126
        self.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

133
        self.radio1.setChecked(True)
134
        la.addWidget(self.radio1)
135
        la.addWidget(self.radio2)
136

137
        iN1 = QtGui.QLabel("Minor Radius")
138
        la.addWidget(iN1)
139
        self.r1 = QtGui.QLineEdit()
140
        la.addWidget(self.r1)
141
        self.r1.setText('2')
142

143
        iN2 = QtGui.QLabel("Major Radius")
144
        la.addWidget(iN2)
145
        self.r2 = QtGui.QLineEdit()
146
        la.addWidget(self.r2)
147
        self.r2.setText('3')
148

149
        iN3 = QtGui.QLabel("Range Of Curve - Minimum")
150
        la.addWidget(iN3)
151
        self.s1 = QtGui.QLineEdit()
152
        la.addWidget(self.s1)
153
        self.s1.setText('-2')
154

155
        iN4 = QtGui.QLabel("Range Of Curve - Maximum")
156
        la.addWidget(iN4)
157
        self.s2 = QtGui.QLineEdit()
158
        la.addWidget(self.s2)
159
        self.s2.setText('2')
160

161
        iN5 = QtGui.QLabel("Degrees of Revolve (Only valid for 3D Revolution)")
162
        la.addWidget(iN5)
163
        self.Dg = QtGui.QLineEdit()
164
        self.Dg.insert("360")
165
        la.addWidget(self.Dg)
166

167
        okbox = QtGui.QDialogButtonBox(self.dialog)
168
        okbox.setOrientation(QtCore.Qt.Horizontal)
169
        okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
170
        la.addWidget(okbox)
171
        QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), self.makeHyp)
172
        QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), self.close)
173
        QtCore.QMetaObject.connectSlotsByName(self.dialog)
174
        self.dialog.show()
175
        self.dialog.exec_()
176

177
p()
178

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

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

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

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