From c7bffd2ce62d08efb10432d7bf61938772d834ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Luis=20Cerc=C3=B3s=20pita?= Date: Wed, 23 May 2012 19:04:35 +0200 Subject: [PATCH] Added draft computation to GZ tool. --- src/Mod/Ship/tankGZ/TaskPanel.py | 47 ++++++++++++++++++++------------ src/Mod/Ship/tankGZ/TaskPanel.ui | 2 +- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/Mod/Ship/tankGZ/TaskPanel.py b/src/Mod/Ship/tankGZ/TaskPanel.py index 8a47e67ae..9864bfd10 100644 --- a/src/Mod/Ship/tankGZ/TaskPanel.py +++ b/src/Mod/Ship/tankGZ/TaskPanel.py @@ -30,12 +30,14 @@ from PyQt4 import QtGui,QtCore from Instance import * from TankInstance import * from shipUtils import Paths, Translator +from shipHydrostatics import Tools as Hydrostatics class TaskPanel: def __init__(self): self.ui = Paths.modulePath() + "/tankGZ/TaskPanel.ui" self.ship = None self.tanks = {} + self.trim = 0.0 def accept(self): if not self.ship: @@ -163,14 +165,18 @@ class TaskPanel: """ self.form.setWindowTitle(Translator.translate("GZ curve computation")) self.form.findChild(QtGui.QGroupBox, "LoadConditionGroup").setTitle(Translator.translate("Loading condition.")) + self.form.findChild(QtGui.QGroupBox, "AnglesGroup").setTitle(Translator.translate("Roll angles.")) def onTanksSelection(self): """ Called when tanks are selected or deselected. """ # Set displacement label disp = self.computeDisplacement() - self.form.disp.setText(Translator.translate("Displacement") + ' %g [kg]' % (disp[0])) - + self.form.disp.setText(Translator.translate("Displacement") + ' = %g [kg]' % (disp[0])) + # Set draft label + draft = self.computeDraft(disp[0]) + self.form.draft.setText(Translator.translate("Draft") + ' = %g [m]' % (draft)) + def getTanks(self): """ Get the selected tanks objects list. @return Selected tanks list. @@ -192,23 +198,9 @@ class TaskPanel: """ if not self.ship: return None - # Test if is a ship instance - obj = self.ship - props = obj.PropertiesList - try: - props.index("IsShip") - except ValueError: - return None - if not obj.IsShip: - return None - # Test if properties already exist - try: - props.index("WeightNames") - except: - return None # Get ship structure weights W = [0.0, 0.0, 0.0, 0.0] - sWeights = weights(obj) + sWeights = weights(self.ship) for w in sWeights: W[0] = W[0] + w[1] W[1] = W[1] + w[1]*w[2][0] @@ -224,6 +216,27 @@ class TaskPanel: W[3] = W[3] + w[0]*w[3] return [W[0], W[1]/W[0], W[2]/W[0], W[3]/W[0]] + def computeDraft(self, disp): + """ Computes ship draft. + @param disp Ship displacement. + @return Ship draft. None if errors detected. + @note 0 trim will be assumed. + """ + if not self.ship: + return None + # Initial condition + trim = 0.0 + dens = 1025 + bbox = self.ship.Shape.BoundBox + draft = bbox.ZMin + dx = bbox.XMax - bbox.XMin + dy = bbox.YMax - bbox.YMin + w = 0.0 + while(abs(disp - w)/disp > 0.01): + draft = draft + (disp - w) / (dens*dx*dy) + w = 1000.0*Hydrostatics.Displacement(self.ship, draft, trim)[1] + return draft + def createTask(): panel = TaskPanel() Gui.Control.showDialog(panel) diff --git a/src/Mod/Ship/tankGZ/TaskPanel.ui b/src/Mod/Ship/tankGZ/TaskPanel.ui index a1f16c39b..41823bf71 100644 --- a/src/Mod/Ship/tankGZ/TaskPanel.ui +++ b/src/Mod/Ship/tankGZ/TaskPanel.ui @@ -76,7 +76,7 @@ - + 0