def weights(obj): """ Returns Ship weights list. If weights has not been sets, this tool creates it. @param obj Ship object @return Weights list. None if errors """ # Test if is a ship instance 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 ValueError: obj.addProperty( "App::PropertyStringList", "WeightNames", "Ship", str(Translator.translate("Ship Weights names"))).WeightNames = [ Translator.translate("Lightweight").__str__() ] try: props.index("WeightMass") except ValueError: # Compute mass aproximation from shipHydrostatics import Tools disp = Tools.Displacement(obj, obj.Draft, 0.0) obj.addProperty( "App::PropertyFloatList", "WeightMass", "Ship", str(Translator.translate("Ship Weights masses"))).WeightMass = [ 1000.0 * disp[1] ] try: props.index("WeightPos") except ValueError: # Compute mass aproximation from shipHydrostatics import Tools disp = Tools.Displacement(obj, obj.Draft, 0.0) obj.addProperty( "App::PropertyVectorList", "WeightPos", "Ship", str(Translator.translate( "Ship Weights centers of gravity"))).WeightPos = [ Vector(disp[2], 0.0, obj.Draft) ] # Setup list weights = [] for i in range(0, len(obj.WeightNames)): weights.append( [obj.WeightNames[i], obj.WeightMass[i], obj.WeightPos[i]]) return weights
def onUpdate(self): """ Method called when update data request. """ if not self.ship: return # Calculate drafts angle = math.radians(self.form.trim.value()) L = self.ship.Length draftAP = self.form.draft.value() + 0.5 * L * math.tan(angle) if draftAP < 0.0: draftAP = 0.0 draftFP = self.form.draft.value() - 0.5 * L * math.tan(angle) if draftFP < 0.0: draftFP = 0.0 # Calculate hydrostatics involved data = Hydrostatics.Displacement(self.ship, self.form.draft.value(), self.form.trim.value()) # Prepare the string in html format string = 'L = %g [m]<BR>' % (self.ship.Length) string = string + 'B = %g [m]<BR>' % (self.ship.Beam) string = string + 'T = %g [m]<HR>' % (self.form.draft.value()) string = string + 'Trim = %g [degrees]<BR>' % (self.form.trim.value()) string = string + 'T<sub>AP</sub> = %g [m]<BR>' % (draftAP) string = string + 'T<sub>FP</sub> = %g [m]<HR>' % (draftFP) string = string + Translator.translate( 'Displacement') + ' = %g [ton]<BR>' % (data[1]) string = string + 'XCB = %g [m]' % (data[2]) # Set the document self.form.output.setHtml(string)
def accept(self): if not self.ship: return False self.save() # Plot data data = Hydrostatics.Displacement(self.ship, self.form.draft.value(), self.form.trim.value()) x = self.ship.xSection[:] y = data[0] disp = data[1] xcb = data[2] Plot.Plot(x, y, disp, xcb, self.ship) self.preview.clean() return True
def computeDraft(self, disp, trim=0.0): """ Computes ship draft. @param disp Ship displacement. @param trim Trim angle [degrees]. @return Ship draft, and longitudinal bouyance center position. None if errors detected. """ if not self.ship: return None # Initial condition dens = 1025 bbox = self.ship.Shape.BoundBox draft = bbox.ZMin dx = bbox.XMax - bbox.XMin dy = bbox.YMax - bbox.YMin w = 0.0 xcb = 0.0 while(abs(disp - w)/disp > 0.01): draft = draft + (disp - w) / (dens*dx*dy) ww = Hydrostatics.Displacement(self.ship, draft, trim) w = 1000.0*ww[1] xcb = ww[2] return [draft,xcb]