FreeCAD-macros

Форк
0
/
AirfoilImportAndScale.FCMacro 
119 строк · 4.5 Кб
1
# This Macro, when run, will first provide the user with a file browser to
2
# locate and select a .dat airfoil text file. Once selected, a chord length is
3
# entered and upon pressing the OK button, a properly scaled airfoil is
4
# produced. There are two versions provided here. Version 1.5 should work on
5
# FreeCAD versions, 0.13 stable as well as all 0.14 versions. Version 2 should
6
# only be used with FreeCAD versions equal to or greater than 0.14 3077 and
7
# will work best with versions built with OCE/OCC versions 6.7 or greater (See
8
# the Wiki page for all available version).
9
#
10
# (c) quick61
11

12
__Name__ = 'Airfoil Import and Scale'
13
__Comment__ = 'Imports and scales an Airfoil in the form of a Draft Wire (DWire) or Basic Spline (BSpline)'
14
__Author__ = "quick61"
15
__Version__ = '2.1.2'
16
__Date__ = '2024-01-14'
17
__License__ = ''
18
__Web__ = 'http://forum.freecadweb.org/viewtopic.php?f=22&t=5554'
19
__Wiki__ = 'http://www.freecadweb.org/wiki/Macro_Airfoil_Import_%26_Scale'
20
__Icon__ = ''
21
__Help__ = ''
22
__Status__ = 'stable'
23
__Requires__ = 'freecad >= 0.14.3706'
24
__Communication__ = ''
25
__Files__ = ''
26

27

28
import FreeCAD as app
29
import FreeCADGui as gui
30
from PySide import QtCore, QtGui  # FreeCAD's PySide!
31
import Draft  # FreeCAD.
32
import importAirfoilDAT  # From the Draft module.
33

34
# Select .dat airfoil data file to be imported
35

36
# PySide returns a tuple (filename, filter) instead of just a string like in PyQt
37
filename, filefilter = QtGui.QFileDialog.getOpenFileName(
38
    gui.getMainWindow(), 'Open An Airfoil File', '*.dat')
39

40

41
class AirfoilImporterAndScaler():
42

43
    def __init__(self):
44
        self.dialog = None
45

46
        # Make dialog box and get the scale size
47
        self.dialog = QtGui.QDialog(gui.getMainWindow())
48
        self.dialog.resize(350, 100)
49
        self.dialog.setWindowTitle('Airfoil Import & Scale')
50
        layout = QtGui.QVBoxLayout(self.dialog)
51
        label = QtGui.QLabel('Chord Length')
52
        layout.addWidget(label)
53
        self.line_edit_scale = QtGui.QLineEdit()
54
        layout.addWidget(self.line_edit_scale)
55

56
        # Add radio buttons to select between DWire and BSpline
57
        self.radio_dwire = QtGui.QRadioButton('Make DWire')
58
        self.radio_bspline = QtGui.QRadioButton('Make BSpline')
59

60
        # set default to DWire & make radio buttons - Change self.radio1.setChecked(True) to
61
        # self.radio2.setChecked(True) to set BSpline as default
62

63
        self.radio_dwire.setChecked(True)
64
        layout.addWidget(self.radio_dwire)
65
        layout.addWidget(self.radio_bspline)
66

67
        # Add OK / Cancel buttons
68
        button_box = QtGui.QDialogButtonBox(self.dialog)
69
        button_box.setOrientation(QtCore.Qt.Horizontal)
70
        button_box.setStandardButtons(
71
                QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Ok)
72
        layout.addWidget(button_box)
73
        button_box.accepted.connect(self.proceed)
74
        button_box.rejected.connect(self.close)
75
        QtCore.QMetaObject.connectSlotsByName(self.dialog)
76
        self.dialog.show()
77
        self.dialog.exec_()
78

79
    def proceed(self):
80
        global filename
81
        if self.radio_dwire.isChecked():
82
            try:
83
                # This produces a scaled Airfoil with a DWire
84
                scalefactor = float(self.line_edit_scale.text())
85
                f1 = str(filename)
86
                importAirfoilDAT.insert(f1, 'Unnamed')
87
                Draft.scale(
88
                        app.ActiveDocument.ActiveObject,
89
                        delta=app.Vector(scalefactor, scalefactor, scalefactor),
90
                        center=app.Vector(0, 0, 0),
91
                        legacy=True)
92
            except Exception as e:
93
                app.Console.PrintError('Error, not a valid .dat file\n')
94

95
            self.close()
96

97
        if self.radio_bspline.isChecked():
98
            try:
99
                # This produces a scaled Airfoil with a BSpline
100
                scalefactor = float(self.line_edit_scale.text())
101
                f1 = str(filename)
102
                importAirfoilDAT.insert(f1, 'Unnamed')
103
                points = app.ActiveDocument.ActiveObject.Points
104
                Draft.makeBSpline(points, closed=True)
105
                Draft.scale(app.ActiveDocument.ActiveObject,
106
                            delta=app.Vector(scalefactor, scalefactor, scalefactor),
107
                            center=app.Vector(0, 0, 0),
108
                            legacy=True)
109
                app.getDocument('Unnamed').removeObject('DWire')
110
            except:
111
                app.Console.PrintError('Error, not a valid .dat file\n')
112

113
            self.close()
114

115
    def close(self):
116
        self.dialog.hide()
117

118

119
AirfoilImporterAndScaler()
120

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

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

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

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