Added the capacity curve computation tool to the console interface

This commit is contained in:
Jose Luis Cercos Pita 2016-01-25 08:50:57 +01:00
parent c3ccd0f72c
commit 83d5217795
4 changed files with 80 additions and 34 deletions

View File

@ -80,11 +80,12 @@ SET(ShipCapacityCurve_SRCS
shipCapacityCurve/PlotAux.py
shipCapacityCurve/TaskPanel.py
shipCapacityCurve/TaskPanel.ui
shipCapacityCurve/Tools.py
)
SOURCE_GROUP("shipcapacitycurve" FILES ${ShipCapacityCurve_SRCS})
SET(ShipCreateLoadCondition_SRCS
shipCreateLoadCondition/__init__.py
shipCreateLoadCondition/__init__.py
)
SOURCE_GROUP("shipcreateloadcondition" FILES ${ShipCreateLoadCondition_SRCS})

View File

@ -33,4 +33,5 @@ from shipCreateShip.Tools import createShip
from shipHydrostatics.Tools import areas, displacement, wettedArea, moment,
floatingArea, BMT, mainFrameCoeff
from shipCreateWeight.Tools import createWeight
from shipCreateTank.Tools import createTank
from shipCreateTank.Tools import createTank
from shipCapacityCurve.Tools import tankCapacityCurve

View File

@ -26,6 +26,7 @@ import FreeCAD as App
import FreeCADGui as Gui
import Units
from PySide import QtGui, QtCore
import Tools
import PlotAux
import TankInstance as Instance
from shipUtils import Paths
@ -40,8 +41,21 @@ class TaskPanel:
def accept(self):
if self.tank is None:
return False
# Plot data
l, z, v = self.compute()
mw = self.getMainWindow()
form = mw.findChild(QtGui.QWidget, "TaskPanel")
form.points = self.widget(QtGui.QSpinBox, "Points")
n = form.points.value()
points = Tools.tankCapacityCurve(self.tank, n)
l = []
z = []
v = []
for p in points:
l.append(p[0] * 100)
z.append(p[1].getValueAs("m").Value)
v.append(p[2].getValueAs("m^3").Value)
PlotAux.Plot(l, z, v, self.tank)
return True
@ -154,36 +168,6 @@ class TaskPanel:
None,
QtGui.QApplication.UnicodeUTF8))
def compute(self):
mw = self.getMainWindow()
form = mw.findChild(QtGui.QWidget, "TaskPanel")
form.points = self.widget(QtGui.QSpinBox, "Points")
bbox = self.tank.Shape.BoundBox
dz = Units.Quantity(bbox.ZMax - bbox.ZMin, Units.Length)
n = form.points.value()
dlevel = 1.0 / (n - 1)
l = [0.0]
v = [0.0]
z = [0.0]
msg = QtGui.QApplication.translate(
"ship_console",
"Computing capacity curves",
None,
QtGui.QApplication.UnicodeUTF8)
App.Console.PrintMessage(msg + '...\n')
for i in range(1, n):
App.Console.PrintMessage("\t{} / {}\n".format(i + 1, n))
level = i * dlevel
vol = self.tank.Proxy.getVolume(self.tank, level)
l.append(level * 100.0)
z.append(level * dz.getValueAs("m").Value)
v.append(vol.getValueAs("m^3").Value)
return (l, z, v)
def createTask():
panel = TaskPanel()
Gui.Control.showDialog(panel)

View File

@ -0,0 +1,60 @@
#***************************************************************************
#* *
#* Copyright (c) 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 FreeCAD as App
import Units
import WeightInstance as Instance
import shipUtils.Units as USys
from PySide import QtGui
def tankCapacityCurve(tank, n):
"""Create a tank capacity curve
Position arguments:
tank -- Tank object (see createTank)
ship -- n Number of filling levels to test
Returned value:
List of computed points. Each point contains the filling level percentage
(interval [0, 1]), the the filling level (0 for the bottom of the tank), and
the volume.
"""
bbox = tank.Shape.BoundBox
dz = Units.Quantity(bbox.ZMax - bbox.ZMin, Units.Length)
dlevel = 1.0 / (n - 1)
out = [(0.0, Units.parseQuantity("0 m"), Units.parseQuantity("0 m^3"))]
msg = QtGui.QApplication.translate(
"ship_console",
"Computing capacity curves",
None,
QtGui.QApplication.UnicodeUTF8)
App.Console.PrintMessage(msg + '...\n')
for i in range(1, n):
App.Console.PrintMessage("\t{} / {}\n".format(i + 1, n))
level = i * dlevel
vol = tank.Proxy.getVolume(tank, level)
out.append((level, level * dz, level * vol))
return out