Example #1
0
 def saveData(self, ship, trim, drafts):
     """ Write data file.
     @param ship Selected ship instance
     @param trim Trim in degrees.
     @param drafts List of drafts to be performed.
     @return True if error happens.
     """
     # Open the file
     filename = self.path + 'hydrostatics.dat'
     try:
         Output = open(filename, "w")
     except IOError:
         msg = Translator.translate("Can't write '" + filename + "' file.\n")
         FreeCAD.Console.PrintError(msg)
         return True
     # Print header
     Output.write(header)
     Output.write(" #\n")
     Output.write(" # File automatically exported by FreeCAD-Ship\n")
     Output.write(" # This file contains transversal areas data, filled with following columns:\n")
     Output.write(" #  1: Ship displacement [ton]\n")
     Output.write(" #  2: Draft [m]\n")
     Output.write(" #  3: Wetted surface [m2]\n")
     Output.write(" #  4: 1cm triming ship moment [ton m]\n")
     Output.write(" #  5: Bouyance center x coordinate\n")
     Output.write(" #  6: Floating area\n")
     Output.write(" #  7: KBt\n")
     Output.write(" #  8: BMt\n")
     Output.write(" #  9: Cb (block coefficient)\n")
     Output.write(" # 10: Cf (Floating coefficient)\n")
     Output.write(" # 11: Cm (Main frame coefficient)\n")
     Output.write(" #\n")
     Output.write(" #################################################################\n")
     # Get external faces
     faces = self.externalFaces(ship.Shape)
     if len(faces) == 0:
         msg = Translator.translate("Can't detect external faces from ship object.\n")
         FreeCAD.Console.PrintError(msg)
     else:
         faces = Part.makeShell(faces)
     # Print data
     FreeCAD.Console.PrintMessage("Computing hydrostatics...\n")
     for i in range(0,len(drafts)):
         FreeCAD.Console.PrintMessage("\t%d / %d\n" % (i+1, len(drafts)))
         draft = drafts[i]
         point = Tools.Point(ship,faces,draft,trim)
         string = "%f %f %f %f %f %f %f %f %f %f %f\n" % (point.disp, point.draft, point.wet, point.mom, point.xcb, point.farea, point.KBt, point.BMt, point.Cb, point.Cf, point.Cm)
         Output.write(string)
     # Close file
     Output.close()
     self.dataFile = filename
     msg = Translator.translate("Data saved at '" + self.dataFile + "'.\n")
     FreeCAD.Console.PrintMessage(msg)
     return False
Example #2
0
 def __init__(self, obj, faces):
     """ Creates a new ship on active document.
     @param faces Ship faces (Part::Shape entities).
     """
     # Add uniqueness property to identify Ship instances
     obj.addProperty("App::PropertyBool","IsShip","Ship", str(Translator.translate("True if is a valid ship instance"))).IsShip=True
     # Add main dimensions
     obj.addProperty("App::PropertyLength","Length","Ship", str(Translator.translate("Ship length (Lpp) [m]"))).Length=0.0
     obj.addProperty("App::PropertyLength","Beam","Ship", str(Translator.translate("Ship beam (B) [m]"))).Beam=0.0
     obj.addProperty("App::PropertyLength","Draft","Ship", str(Translator.translate("Ship draft (T) [m]"))).Draft=0.0
     # Add shapes
     obj.Shape = Part.makeShell(faces)
     obj.Proxy = self
     self.obj = obj
Example #3
0
 def __init__(self, obj, faces):
     """ Creates a new ship on active document.
     @param faces Ship faces (Part::Shape entities).
     """
     # Add uniqueness property to identify Ship instances
     obj.addProperty(
         "App::PropertyBool", "IsShip", "Ship",
         str(Translator.translate(
             "True if is a valid ship instance"))).IsShip = True
     # Add main dimensions
     obj.addProperty(
         "App::PropertyLength", "Length", "Ship",
         str(Translator.translate("Ship length (Lpp) [m]"))).Length = 0.0
     obj.addProperty(
         "App::PropertyLength", "Beam", "Ship",
         str(Translator.translate("Ship beam (B) [m]"))).Beam = 0.0
     obj.addProperty(
         "App::PropertyLength", "Draft", "Ship",
         str(Translator.translate("Ship draft (T) [m]"))).Draft = 0.0
     # Add shapes
     obj.Shape = Part.makeShell(faces)
     obj.Proxy = self
     self.obj = obj
Example #4
0
 def execute(self, obj):
     ''' Print a short message when doing a recomputation, this method is mandatory '''
     # FreeCAD.Console.PrintMessage("Recompute Ship\n")
     obj.Shape = Part.makeShell(self.faces)
Example #5
0
 def onChanged(self, fp, prop):
     ''' Print the name of the property that has changed '''
     # FreeCAD.Console.PrintMessage("Change property: " + str(prop) + "\n")
     if prop == "Length" or prop == "Beam" or prop == "Draft":
         fp.Shape = Part.makeShell(self.faces)
Example #6
0
 def execute(self, obj):
     ''' Print a short message when doing a recomputation, this method is mandatory '''
     # FreeCAD.Console.PrintMessage("Recompute Ship\n")
     obj.Shape = Part.makeShell(obj.Shape.Faces)
Example #7
0
 def saveData(self, ship, trim, drafts):
     """ Write data file.
     @param ship Selected ship instance
     @param trim Trim in degrees.
     @param drafts List of drafts to be performed.
     @return True if error happens.
     """
     # Open the file
     filename = self.path + 'hydrostatics.dat'
     try:
         Output = open(filename, "w")
     except IOError:
         msg = Translator.translate("Can't write '" + filename +
                                    "' file.\n")
         FreeCAD.Console.PrintError(msg)
         return True
     # Print header
     Output.write(header)
     Output.write(" #\n")
     Output.write(" # File automatically exported by FreeCAD-Ship\n")
     Output.write(
         " # This file contains transversal areas data, filled with following columns:\n"
     )
     Output.write(" #  1: Ship displacement [ton]\n")
     Output.write(" #  2: Draft [m]\n")
     Output.write(" #  3: Wetted surface [m2]\n")
     Output.write(" #  4: 1cm triming ship moment [ton m]\n")
     Output.write(" #  5: Bouyance center x coordinate\n")
     Output.write(" #  6: Floating area\n")
     Output.write(" #  7: KBt\n")
     Output.write(" #  8: BMt\n")
     Output.write(" #  9: Cb (block coefficient)\n")
     Output.write(" # 10: Cf (Floating coefficient)\n")
     Output.write(" # 11: Cm (Main frame coefficient)\n")
     Output.write(" #\n")
     Output.write(
         " #################################################################\n"
     )
     # Get external faces
     faces = self.externalFaces(ship.Shape)
     if len(faces) == 0:
         msg = Translator.translate(
             "Can't detect external faces from ship object.\n")
         FreeCAD.Console.PrintError(msg)
     else:
         faces = Part.makeShell(faces)
     # Print data
     FreeCAD.Console.PrintMessage("Computing hydrostatics...\n")
     for i in range(0, len(drafts)):
         FreeCAD.Console.PrintMessage("\t%d / %d\n" % (i + 1, len(drafts)))
         draft = drafts[i]
         point = Tools.Point(ship, faces, draft, trim)
         string = "%f %f %f %f %f %f %f %f %f %f %f\n" % (
             point.disp, point.draft, point.wet, point.mom, point.xcb,
             point.farea, point.KBt, point.BMt, point.Cb, point.Cf,
             point.Cm)
         Output.write(string)
     # Close file
     Output.close()
     self.dataFile = filename
     msg = Translator.translate("Data saved at '" + self.dataFile + "'.\n")
     FreeCAD.Console.PrintMessage(msg)
     return False