/
PlotAux.py
338 lines (313 loc) · 12.9 KB
/
PlotAux.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#***************************************************************************
#* *
#* Copyright (c) 2011, 2016 *
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) *
#* as published by the Free Software Foundation; either version 2 of *
#* the License, or (at your option) any later version. *
#* for detail see the LICENCE text file. *
#* *
#* This program is distributed in the hope that it will be useful, *
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
#* GNU Library General Public License for more details. *
#* *
#* You should have received a copy of the GNU Library General Public *
#* License along with this program; if not, write to the Free Software *
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
#* USA *
#* *
#***************************************************************************
import os
import math
from PySide import QtGui, QtCore
import FreeCAD
import FreeCADGui
import Spreadsheet
from shipUtils import Paths
class Plot(object):
def __init__(self, ship, trim, points):
""" Constructor. performs plot and show it (Using pyxplot).
@param ship Selected ship instance
@param trim Trim in degrees.
@param points List of computed hydrostatics.
"""
self.points = points[:]
# Try to plot
self.plotVolume()
self.plotStability()
self.plotCoeffs()
# Save data
if self.spreadSheet(ship, trim):
return
def plotVolume(self):
""" Perform volumetric hydrostatics.
@return True if error happens.
"""
try:
import Plot
plt = Plot.figure('Volume')
except ImportError:
msg = QtGui.QApplication.translate(
"ship_console",
"Plot module is disabled, so I cannot perform the plot",
None,
QtGui.QApplication.UnicodeUTF8)
FreeCAD.Console.PrintWarning(msg + '\n')
return True
# Generate the set of axes
Plot.grid(True)
for i in range(0, 3):
ax = Plot.addNewAxes()
# Y axis can be placed at right
ax.yaxis.tick_right()
ax.spines['right'].set_color((0.0, 0.0, 0.0))
ax.spines['left'].set_color('none')
ax.yaxis.set_ticks_position('right')
ax.yaxis.set_label_position('right')
# And X axis can be placed at bottom
for loc, spine in ax.spines.iteritems():
if loc in ['bottom', 'top']:
spine.set_position(('outward', (i + 1) * 35))
Plot.grid(True)
disp = []
draft = []
warea = []
t1cm = []
xcb = []
for i in range(len(self.points)):
disp.append(self.points[i].disp)
draft.append(self.points[i].draft)
warea.append(self.points[i].wet)
t1cm.append(self.points[i].mom)
xcb.append(self.points[i].xcb)
axes = Plot.axesList()
for ax in axes:
ax.set_position([0.1, 0.2, 0.8, 0.75])
plt.axes = axes[0]
serie = Plot.plot(draft, disp, r'$T$')
serie.line.set_linestyle('-')
serie.line.set_linewidth(2.0)
serie.line.set_color((0.0, 0.0, 0.0))
Plot.xlabel(r'$T \; \left[ \mathrm{m} \right]$')
Plot.ylabel(r'$\bigtriangleup \; \left[ \mathrm{tons} \right]$')
plt.axes.xaxis.label.set_fontsize(15)
plt.axes.yaxis.label.set_fontsize(15)
plt.axes = axes[1]
serie = Plot.plot(warea, disp, r'Wetted area')
serie.line.set_linestyle('-')
serie.line.set_linewidth(2.0)
serie.line.set_color((1.0, 0.0, 0.0))
Plot.xlabel(r'$Wetted \; area \; \left[ \mathrm{m}^2 \right]$')
Plot.ylabel(r'$\bigtriangleup \; \left[ \mathrm{tons} \right]$')
plt.axes.xaxis.label.set_fontsize(15)
plt.axes.yaxis.label.set_fontsize(15)
plt.axes = axes[2]
serie = Plot.plot(t1cm, disp, r'Moment to trim 1cm')
serie.line.set_linestyle('-')
serie.line.set_linewidth(2.0)
serie.line.set_color((0.0, 0.0, 1.0))
Plot.xlabel(r'$Moment \; to \; trim \; 1 \mathrm{cm} \; \left['
r' \mathrm{tons} \; \times \; \mathrm{m} \right]$')
plt.axes.xaxis.label.set_fontsize(15)
plt.axes.yaxis.label.set_fontsize(15)
plt.axes = axes[3]
serie = Plot.plot(xcb, disp, r'$XCB$')
serie.line.set_linestyle('-')
serie.line.set_linewidth(2.0)
serie.line.set_color((0.2, 0.8, 0.2))
Plot.xlabel(r'$XCB \; \left[ \mathrm{m} \right]$')
plt.axes.xaxis.label.set_fontsize(15)
plt.axes.yaxis.label.set_fontsize(15)
Plot.legend(True)
plt.update()
return False
def plotStability(self):
""" Perform stability hydrostatics.
@return True if error happens.
"""
try:
import Plot
plt = Plot.figure('Stability')
except ImportError:
return True
# Generate the sets of axes
Plot.grid(True)
for i in range(0, 3):
ax = Plot.addNewAxes()
# Y axis can be placed at right
ax.yaxis.tick_right()
ax.spines['right'].set_color((0.0, 0.0, 0.0))
ax.spines['left'].set_color('none')
ax.yaxis.set_ticks_position('right')
ax.yaxis.set_label_position('right')
# And X axis can be placed at bottom
for loc, spine in ax.spines.iteritems():
if loc in ['bottom', 'top']:
spine.set_position(('outward', (i + 1) * 35))
Plot.grid(True)
disp = []
draft = []
farea = []
kbt = []
bmt = []
for i in range(len(self.points)):
disp.append(self.points[i].disp)
draft.append(self.points[i].draft)
farea.append(self.points[i].farea)
kbt.append(self.points[i].KBt)
bmt.append(self.points[i].BMt)
axes = Plot.axesList()
for ax in axes:
ax.set_position([0.1, 0.2, 0.8, 0.75])
plt.axes = axes[0]
serie = Plot.plot(draft, disp, r'$T$')
serie.line.set_linestyle('-')
serie.line.set_linewidth(2.0)
serie.line.set_color((0.0, 0.0, 0.0))
Plot.xlabel(r'$T \; \left[ \mathrm{m} \right]$')
Plot.ylabel(r'$\bigtriangleup \; \left[ \mathrm{tons} \right]$')
plt.axes.xaxis.label.set_fontsize(15)
plt.axes.yaxis.label.set_fontsize(15)
plt.axes = axes[1]
serie = Plot.plot(farea, disp, r'Floating area')
serie.line.set_linestyle('-')
serie.line.set_linewidth(2.0)
serie.line.set_color((1.0, 0.0, 0.0))
Plot.xlabel(r'$Floating \; area \; \left[ \mathrm{m}^2 \right]$')
Plot.ylabel(r'$\bigtriangleup \; \left[ \mathrm{tons} \right]$')
plt.axes.xaxis.label.set_fontsize(15)
plt.axes.yaxis.label.set_fontsize(15)
plt.axes = axes[2]
serie = Plot.plot(kbt, disp, r'$KB_T$')
serie.line.set_linestyle('-')
serie.line.set_linewidth(2.0)
serie.line.set_color((0.0, 0.0, 1.0))
Plot.xlabel(r'$KB_T \; \left[ \mathrm{m} \right]$')
plt.axes.xaxis.label.set_fontsize(15)
plt.axes.yaxis.label.set_fontsize(15)
plt.axes = axes[3]
serie = Plot.plot(bmt, disp, r'$BM_T$')
serie.line.set_linestyle('-')
serie.line.set_linewidth(2.0)
serie.line.set_color((0.2, 0.8, 0.2))
Plot.xlabel(r'$BM_T \; \left[ \mathrm{m} \right]$')
plt.axes.xaxis.label.set_fontsize(15)
plt.axes.yaxis.label.set_fontsize(15)
Plot.legend(True)
plt.update()
return False
def plotCoeffs(self):
""" Perform stability hydrostatics.
@return True if error happens.
"""
# Create plot
try:
import Plot
plt = Plot.figure('Coefficients')
except ImportError:
return True
# Generate the set of axes
Plot.grid(True)
for i in range(0, 3):
ax = Plot.addNewAxes()
# Y axis can be placed at right
ax.yaxis.tick_right()
ax.spines['right'].set_color((0.0, 0.0, 0.0))
ax.spines['left'].set_color('none')
ax.yaxis.set_ticks_position('right')
ax.yaxis.set_label_position('right')
# And X axis can be placed at bottom
for loc, spine in ax.spines.iteritems():
if loc in ['bottom', 'top']:
spine.set_position(('outward', (i + 1) * 35))
Plot.grid(True)
disp = []
draft = []
cb = []
cf = []
cm = []
for i in range(len(self.points)):
disp.append(self.points[i].disp)
draft.append(self.points[i].draft)
cb.append(self.points[i].Cb)
cf.append(self.points[i].Cf)
cm.append(self.points[i].Cm)
axes = Plot.axesList()
for ax in axes:
ax.set_position([0.1, 0.2, 0.8, 0.75])
plt.axes = axes[0]
serie = Plot.plot(draft, disp, r'$T$')
serie.line.set_linestyle('-')
serie.line.set_linewidth(2.0)
serie.line.set_color((0.0, 0.0, 0.0))
Plot.xlabel(r'$T \; \left[ \mathrm{m} \right]$')
Plot.ylabel(r'$\bigtriangleup \; \left[ \mathrm{tons} \right]$')
plt.axes.xaxis.label.set_fontsize(15)
plt.axes.yaxis.label.set_fontsize(15)
plt.axes = axes[1]
serie = Plot.plot(cb, disp, r'$Cb$')
serie.line.set_linestyle('-')
serie.line.set_linewidth(2.0)
serie.line.set_color((1.0, 0.0, 0.0))
Plot.xlabel(r'$Cb$ (Block coefficient)')
Plot.ylabel(r'$\bigtriangleup \; \left[ \mathrm{tons} \right]$')
plt.axes.xaxis.label.set_fontsize(15)
plt.axes.yaxis.label.set_fontsize(15)
plt.axes = axes[2]
serie = Plot.plot(cf, disp, r'$Cf$')
serie.line.set_linestyle('-')
serie.line.set_linewidth(2.0)
serie.line.set_color((0.0, 0.0, 1.0))
Plot.xlabel(r'$Cf$ (floating area coefficient)')
plt.axes.xaxis.label.set_fontsize(15)
plt.axes.yaxis.label.set_fontsize(15)
plt.axes = axes[3]
serie = Plot.plot(cm, disp, r'$Cm$')
serie.line.set_linestyle('-')
serie.line.set_linewidth(2.0)
serie.line.set_color((0.2, 0.8, 0.2))
Plot.xlabel(r'$Cm$ (Main section coefficient)')
plt.axes.xaxis.label.set_fontsize(15)
plt.axes.yaxis.label.set_fontsize(15)
Plot.legend(True)
plt.update()
return False
def spreadSheet(self, ship, trim):
""" Write data file.
@param ship Selected ship instance
@param trim Trim in degrees.
@return True if error happens.
"""
s = FreeCAD.activeDocument().addObject('Spreadsheet::Sheet',
'Hydrostatics')
# Print the header
s.set("A1", "displacement [ton]")
s.set("B1", "draft [m]")
s.set("C1", "wetted surface [m^2]")
s.set("D1", "1cm triming ship moment [ton*m]")
s.set("E1", "Floating area [m^2]")
s.set("F1", "KBl [m]")
s.set("G1", "KBt [m]")
s.set("H1", "BMt [m]")
s.set("I1", "Cb")
s.set("J1", "Cf")
s.set("K1", "Cm")
# Print the data
for i in range(len(self.points)):
point = self.points[i]
s.set("A{}".format(i + 2), str(point.disp))
s.set("B{}".format(i + 2), str(point.draft))
s.set("C{}".format(i + 2), str(point.wet))
s.set("D{}".format(i + 2), str(point.mom))
s.set("E{}".format(i + 2), str(point.farea))
s.set("F{}".format(i + 2), str(point.xcb))
s.set("G{}".format(i + 2), str(point.KBt))
s.set("H{}".format(i + 2), str(point.BMt))
s.set("I{}".format(i + 2), str(point.Cb))
s.set("J{}".format(i + 2), str(point.Cf))
s.set("K{}".format(i + 2), str(point.Cm))
# Recompute
FreeCAD.activeDocument().recompute()