Esempio n. 1
0
    def onData(self, value):
        """ Method called when the tool input data is touched.
        @param value Changed value.
        """
        if not self.ship:
            return

        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")

        # Get the values (or fix them in bad setting case)
        try:
            draft = Units.parseQuantity(Locale.fromString(form.draft.text()))
        except:
            draft = self.ship.Draft
            form.draft.setText(draft.UserString)
        try:
            trim = Units.parseQuantity(Locale.fromString(form.trim.text()))
        except:
            trim = Units.parseQuantity("0 deg")
            form.trim.setText(trim.UserString)

        bbox = self.ship.Shape.BoundBox
        draft_min = Units.Quantity(bbox.ZMin, Units.Length)
        draft_max = Units.Quantity(bbox.ZMax, Units.Length)
        draft = self.clampValue(form.draft, draft_min, draft_max, draft)

        trim_min = Units.parseQuantity("-180 deg")
        trim_max = Units.parseQuantity("180 deg")
        trim = self.clampValue(form.trim, trim_min, trim_max, trim)

        self.onUpdate()
        self.preview.update(draft, trim, self.ship)
Esempio n. 2
0
    def onData(self, value):
        """Updates the 3D preview on data changes.

        Keyword arguments:
        value -- Edited value. This parameter is required in order to use this
        method as a callback function, but it is unuseful.
        """
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.length = self.widget(QtGui.QLineEdit, "Length")
        form.breadth = self.widget(QtGui.QLineEdit, "Breadth")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")

        qty = Units.Quantity(Locale.fromString(form.length.text()))
        val_min = 0.001
        val_max = self.bounds[0] / Units.Metre.Value
        val = qty.getValueAs('m').Value
        self.L = self.clampVal(form.length, val_min, val_max, val)
        qty = Units.Quantity(Locale.fromString(form.breadth.text()))
        val_min = 0.001
        val_max = self.bounds[1] / Units.Metre.Value
        val = qty.getValueAs('m').Value
        self.B = self.clampVal(form.breadth, val_min, val_max, val)
        qty = Units.Quantity(Locale.fromString(form.draft.text()))
        val_min = 0.001
        val_max = self.bounds[2] / Units.Metre.Value
        val = qty.getValueAs('m').Value
        self.T = self.clampVal(form.draft, val_min, val_max, val)
        self.preview.update(self.L, self.B, self.T)
Esempio n. 3
0
    def onData(self, value):
        """Updates the 3D preview on data changes.

        Keyword arguments:
        value -- Edited value. This parameter is required in order to use this
        method as a callback function, but it is unuseful.
        """
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.length = self.widget(QtGui.QLineEdit, "Length")
        form.breadth = self.widget(QtGui.QLineEdit, "Breadth")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")

        qty = Units.Quantity(Locale.fromString(form.length.text()))
        val_min = 0.001
        val_max = self.bounds[0] / Units.Metre.Value
        val = qty.getValueAs('m').Value
        self.L = self.clampVal(form.length, val_min, val_max, val)
        qty = Units.Quantity(Locale.fromString(form.breadth.text()))
        val_min = 0.001
        val_max = self.bounds[1] / Units.Metre.Value
        val = qty.getValueAs('m').Value
        self.B = self.clampVal(form.breadth, val_min, val_max, val)
        qty = Units.Quantity(Locale.fromString(form.draft.text()))
        val_min = 0.001
        val_max = self.bounds[2] / Units.Metre.Value
        val = qty.getValueAs('m').Value
        self.T = self.clampVal(form.draft, val_min, val_max, val)
        self.preview.update(self.L, self.B, self.T)
Esempio n. 4
0
    def accept(self):
        if not self.ship:
            return False
        self.save()
        # Plot data
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.num = self.widget(QtGui.QSpinBox, "Num")
        draft = Units.parseQuantity(Locale.fromString(form.draft.text()))
        trim = Units.parseQuantity(Locale.fromString(form.trim.text()))
        num = form.num.value()

        disp, B, _ = Hydrostatics.displacement(self.ship, draft,
                                               Units.parseQuantity("0 deg"),
                                               trim)
        xcb = Units.Quantity(B.x, Units.Length)
        data = Hydrostatics.areas(self.ship, num, draft=draft, trim=trim)
        x = []
        y = []
        for i in range(0, len(data)):
            x.append(data[i][0].getValueAs("m").Value)
            y.append(data[i][1].getValueAs("m^2").Value)
        PlotAux.Plot(x, y, disp, xcb, self.ship)
        self.preview.clean()
        return True
Esempio n. 5
0
    def onData(self, value):
        """ Method called when the tool input data is touched.
        @param value Changed value.
        """
        if not self.ship:
            return

        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")

        # Get the values (or fix them in bad setting case)
        try:
            draft = Units.parseQuantity(Locale.fromString(form.draft.text()))
        except:
            draft = self.ship.Draft
            form.draft.setText(draft.UserString)
        try:
            trim = Units.parseQuantity(Locale.fromString(form.trim.text()))
        except:
            trim = Units.parseQuantity("0 deg")
            form.trim.setText(trim.UserString)

        bbox = self.ship.Shape.BoundBox
        draft_min = Units.Quantity(bbox.ZMin, Units.Length)
        draft_max = Units.Quantity(bbox.ZMax, Units.Length)
        draft = self.clampValue(form.draft, draft_min, draft_max, draft)

        trim_min = Units.parseQuantity("-180 deg")
        trim_max = Units.parseQuantity("180 deg")
        trim = self.clampValue(form.trim, trim_min, trim_max, trim)

        self.onUpdate()
        self.preview.update(draft, trim, self.ship)
Esempio n. 6
0
    def accept(self):
        if not self.ship:
            return False
        self.save()
        # Plot data
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.num = self.widget(QtGui.QSpinBox, "Num")
        draft = Units.parseQuantity(Locale.fromString(form.draft.text()))
        trim = Units.parseQuantity(Locale.fromString(form.trim.text()))
        num = form.num.value()

        disp, B, _ = Hydrostatics.displacement(self.ship,
                                               draft,
                                               Units.parseQuantity("0 deg"),
                                               trim)
        xcb = Units.Quantity(B.x, Units.Length)
        data = Hydrostatics.areas(self.ship,
                                  num,
                                  draft=draft,
                                  trim=trim)
        x = []
        y = []
        for i in range(0, len(data)):
            x.append(data[i][0].getValueAs("m").Value)
            y.append(data[i][1].getValueAs("m^2").Value)
        PlotAux.Plot(x, y, disp, xcb, self.ship)
        self.preview.clean()
        return True
Esempio n. 7
0
 def accept(self):
     if not self.ship:
         return False
     self.save()
     # Plot data
     mw = self.getMainWindow()
     form = mw.findChild(QtGui.QWidget, "TaskPanel")
     form.draft = self.widget(QtGui.QLineEdit, "Draft")
     form.trim = self.widget(QtGui.QLineEdit, "Trim")
     draft = Units.Quantity(Locale.fromString(
         form.draft.text())).getValueAs('m').Value
     trim = Units.Quantity(Locale.fromString(
         form.trim.text())).getValueAs('deg').Value
     data = Hydrostatics.displacement(self.ship,
                                      draft,
                                      0.0,
                                      trim)
     disp = data[0]
     xcb = data[1].x
     data = Hydrostatics.areas(self.ship,
                               draft,
                               0.0,
                               trim)
     x = []
     y = []
     for i in range(0, len(data)):
         x.append(data[i][0])
         y.append(data[i][1])
     PlotAux.Plot(x, y, disp, xcb, self.ship)
     self.preview.clean()
     return True
Esempio n. 8
0
 def accept(self):
     if not self.ship:
         return False
     self.save()
     # Plot data
     mw = self.getMainWindow()
     form = mw.findChild(QtGui.QWidget, "TaskPanel")
     form.draft = self.widget(QtGui.QLineEdit, "Draft")
     form.trim = self.widget(QtGui.QLineEdit, "Trim")
     draft = Units.Quantity(Locale.fromString(
         form.draft.text())).getValueAs('m').Value
     trim = Units.Quantity(Locale.fromString(
         form.trim.text())).getValueAs('deg').Value
     data = Hydrostatics.displacement(self.ship, draft, 0.0, trim)
     disp = data[0]
     xcb = data[1].x
     data = Hydrostatics.areas(self.ship, draft, 0.0, trim)
     x = []
     y = []
     for i in range(0, len(data)):
         x.append(data[i][0])
         y.append(data[i][1])
     PlotAux.Plot(x, y, disp, xcb, self.ship)
     self.preview.clean()
     return True
Esempio n. 9
0
    def save(self):
        """ Saves the data into ship instance. """
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.num = self.widget(QtGui.QSpinBox, "Num")

        draft = Units.parseQuantity(Locale.fromString(form.draft.text()))
        trim = Units.parseQuantity(Locale.fromString(form.trim.text()))
        num = form.num.value()

        props = self.ship.PropertiesList
        try:
            props.index("AreaCurveDraft")
        except ValueError:
            try:
                tooltip = str(QtGui.QApplication.translate(
                    "ship_areas",
                    "Areas curve tool draft selected [m]",
                    None))
            except:
                tooltip = "Areas curve tool draft selected [m]"
            self.ship.addProperty("App::PropertyLength",
                                  "AreaCurveDraft",
                                  "Ship",
                                  tooltip)
        self.ship.AreaCurveDraft = draft
        try:
            props.index("AreaCurveTrim")
        except ValueError:
            try:
                tooltip = str(QtGui.QApplication.translate(
                    "ship_areas",
                    "Areas curve tool trim selected [deg]",
                    None))
            except:
                tooltip = "Areas curve tool trim selected [deg]"
            self.ship.addProperty("App::PropertyAngle",
                                  "AreaCurveTrim",
                                  "Ship",
                                  tooltip)
        self.ship.AreaCurveTrim = trim
        try:
            props.index("AreaCurveNum")
        except ValueError:
            try:
                tooltip = str(QtGui.QApplication.translate(
                    "ship_areas",
                    "Areas curve tool number of points",
                    None))
            except:
                tooltip = "Areas curve tool number of points"
            self.ship.addProperty("App::PropertyInteger",
                                  "AreaCurveNum",
                                  "Ship",
                                  tooltip)
        self.ship.AreaCurveNum = num
Esempio n. 10
0
    def save(self):
        """ Saves the data into ship instance. """
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.num = self.widget(QtGui.QSpinBox, "Num")

        draft = Units.parseQuantity(Locale.fromString(form.draft.text()))
        trim = Units.parseQuantity(Locale.fromString(form.trim.text()))
        num = form.num.value()

        props = self.ship.PropertiesList
        try:
            props.index("AreaCurveDraft")
        except ValueError:
            try:
                tooltip = str(
                    QtGui.QApplication.translate(
                        "ship_areas", "Areas curve tool draft selected [m]",
                        None))
            except:
                tooltip = "Areas curve tool draft selected [m]"
            self.ship.addProperty("App::PropertyLength", "AreaCurveDraft",
                                  "Ship", tooltip)
        self.ship.AreaCurveDraft = draft
        try:
            props.index("AreaCurveTrim")
        except ValueError:
            try:
                tooltip = str(
                    QtGui.QApplication.translate(
                        "ship_areas", "Areas curve tool trim selected [deg]",
                        None))
            except:
                tooltip = "Areas curve tool trim selected [deg]"
            self.ship.addProperty("App::PropertyAngle", "AreaCurveTrim",
                                  "Ship", tooltip)
        self.ship.AreaCurveTrim = trim
        try:
            props.index("AreaCurveNum")
        except ValueError:
            try:
                tooltip = str(
                    QtGui.QApplication.translate(
                        "ship_areas", "Areas curve tool number of points",
                        None))
            except:
                tooltip = "Areas curve tool number of points"
            self.ship.addProperty("App::PropertyInteger", "AreaCurveNum",
                                  "Ship", tooltip)
        self.ship.AreaCurveNum = num
Esempio n. 11
0
    def accept(self):
        """Create the ship instance"""
        self.preview.clean()
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.length = self.widget(QtGui.QLineEdit, "Length")
        form.breadth = self.widget(QtGui.QLineEdit, "Breadth")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")

        Tools.createShip(self.solids, Locale.fromString(form.length.text()),
                         Locale.fromString(form.breadth.text()),
                         Locale.fromString(form.draft.text()))
        return True
Esempio n. 12
0
    def accept(self):
        """Create the ship instance"""
        self.preview.clean()
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.length = self.widget(QtGui.QLineEdit, "Length")
        form.breadth = self.widget(QtGui.QLineEdit, "Breadth")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")

        Tools.createShip(self.solids,
                         Locale.fromString(form.length.text()),
                         Locale.fromString(form.breadth.text()),
                         Locale.fromString(form.draft.text()))
        return True
Esempio n. 13
0
    def accept(self):
        if self.lc is None:
            return False
        self.save()

        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.angle = self.widget(QtGui.QLineEdit, "Angle")
        form.n_points = self.widget(QtGui.QSpinBox, "NumPoints")
        form.var_trim = self.widget(QtGui.QCheckBox, "VariableTrim")

        roll = Units.Quantity(Locale.fromString(form.angle.text()))
        n_points = form.n_points.value()
        var_trim = form.var_trim.isChecked()

        rolls = []
        for i in range(n_points):
            rolls.append(roll * i / float(n_points - 1))

        points = Tools.gz(self.lc, rolls, var_trim)
        gzs = []
        drafts = []
        trims = []
        for p in points:
            gzs.append(p[0].getValueAs("m").Value)
            drafts.append(p[1].getValueAs("m").Value)
            trims.append(p[2].getValueAs("deg").Value)

        PlotAux.Plot(rolls, gzs, drafts, trims)

        return True
Esempio n. 14
0
    def accept(self):
        if self.lc is None:
            return False
        self.save()

        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.angle = self.widget(QtGui.QLineEdit, "Angle")
        form.n_points = self.widget(QtGui.QSpinBox, "NumPoints")
        form.var_trim = self.widget(QtGui.QCheckBox, "VariableTrim")

        roll = Units.Quantity(Locale.fromString(form.angle.text()))
        n_points = form.n_points.value()
        var_trim = form.var_trim.isChecked()

        rolls = []
        for i in range(n_points):
            rolls.append(roll * i / float(n_points - 1))

        points = Tools.gz(self.lc, rolls, var_trim)
        gzs = []
        drafts = []
        trims = []
        for p in points:
            gzs.append(p[0].getValueAs('m').Value)
            drafts.append(p[1].getValueAs('m').Value)
            trims.append(p[2].getValueAs('deg').Value)

        PlotAux.Plot(rolls, gzs, drafts, trims)

        return True
Esempio n. 15
0
    def onData(self, value):
        """ Method called when the tool input data is touched.
        @param value Changed value.
        """
        if not self.ship:
            return

        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")

        # Get the values (or fix them in bad setting case)
        try:
            draft = Units.Quantity(Locale.fromString(
                form.draft.text())).getValueAs('m').Value
        except:
            draft = self.ship.Draft.getValueAs(USys.getLengthUnits()).Value
            input_format = USys.getLengthFormat()
            qty = Units.Quantity('{} m'.format(draft))
            widget.setText(
                Locale.toString(
                    input_format.format(
                        qty.getValueAs(USys.getLengthUnits()).Value)))
        try:
            trim = Units.Quantity(Locale.fromString(
                form.trim.text())).getValueAs('deg').Value
        except:
            trim = 0.0
            input_format = USys.getAngleFormat()
            qty = Units.Quantity('{} deg'.format(trim))
            widget.setText(
                Locale.toString(
                    input_format.format(
                        qty.getValueAs(USys.getLengthUnits()).Value)))

        bbox = self.ship.Shape.BoundBox
        draft_min = bbox.ZMin / Units.Metre.Value
        draft_max = bbox.ZMax / Units.Metre.Value
        draft = self.clampLength(form.draft, draft_min, draft_max, draft)

        trim_min = -180.0
        trim_max = 180.0
        trim = self.clampAngle(form.trim, trim_min, trim_max, trim)

        self.onUpdate()
        self.preview.update(draft, trim, self.ship)
Esempio n. 16
0
    def save(self):
        """ Saves the data into ship instance. """
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.angle = self.widget(QtGui.QLineEdit, "Angle")
        form.n_points = self.widget(QtGui.QSpinBox, "NumPoints")
        form.var_trim = self.widget(QtGui.QCheckBox, "VariableTrim")

        angle = Units.Quantity(Locale.fromString(
            form.angle.text())).getValueAs('deg').Value
        n_points = form.n_points.value()
        var_trim = form.var_trim.isChecked()

        props = self.ship.PropertiesList
        try:
            props.index("GZAngle")
        except ValueError:
            try:
                tooltip = str(QtGui.QApplication.translate(
                    "ship_gz",
                    "GZ curve tool angle selected [deg]",
                    None))
            except:
                tooltip = "GZ curve tool angle selected [deg]"
            self.ship.addProperty("App::PropertyAngle",
                                  "GZAngle",
                                  "Ship",
                                  tooltip)
        self.ship.GZAngle = '{} deg'.format(angle)
        try:
            props.index("GZNumPoints")
        except ValueError:
            try:
                tooltip = str(QtGui.QApplication.translate(
                    "ship_gz",
                    "GZ curve tool number of points selected",
                    None))
            except:
                tooltip = "GZ curve tool number of points selected"
            self.ship.addProperty("App::PropertyInteger",
                                  "GZNumPoints",
                                  "Ship",
                                  tooltip)
        self.ship.GZNumPoints = n_points
        try:
            props.index("GZVariableTrim")
        except ValueError:
            try:
                tooltip = str(QtGui.QApplication.translate(
                    "ship_gz",
                    "GZ curve tool variable trim angle selection",
                    None))
            except:
                tooltip = "GZ curve tool variable trim angle selection"
            self.ship.addProperty("App::PropertyBool",
                                  "GZVariableTrim",
                                  "Ship",
                                  tooltip)
        self.ship.GZVariableTrim = var_trim
Esempio n. 17
0
    def accept(self):
        """Create the ship instance"""
        self.preview.clean()
        obj = App.ActiveDocument.addObject("Part::FeaturePython", "Ship")
        ship = Instance.Ship(obj, self.solids)
        Instance.ViewProviderShip(obj.ViewObject)
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.length = self.widget(QtGui.QLineEdit, "Length")
        form.breadth = self.widget(QtGui.QLineEdit, "Breadth")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")

        obj.Length = Locale.fromString(form.length.text())
        obj.Breadth = Locale.fromString(form.breadth.text())
        obj.Draft = Locale.fromString(form.draft.text())
        App.ActiveDocument.recompute()
        return True
Esempio n. 18
0
    def accept(self):
        """Create the ship instance"""
        self.preview.clean()
        obj = App.ActiveDocument.addObject("Part::FeaturePython", "Ship")
        ship = Instance.Ship(obj, self.solids)
        Instance.ViewProviderShip(obj.ViewObject)
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.length = self.widget(QtGui.QLineEdit, "Length")
        form.breadth = self.widget(QtGui.QLineEdit, "Breadth")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")

        obj.Length = Locale.fromString(form.length.text())
        obj.Breadth = Locale.fromString(form.breadth.text())
        obj.Draft = Locale.fromString(form.draft.text())
        App.ActiveDocument.recompute()
        return True
Esempio n. 19
0
    def save(self):
        """ Saves the data into ship instance. """
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")

        draft = Units.Quantity(Locale.fromString(
            form.draft.text())).getValueAs('m').Value
        trim = Units.Quantity(Locale.fromString(
            form.trim.text())).getValueAs('deg').Value

        props = self.ship.PropertiesList
        try:
            props.index("AreaCurveDraft")
        except ValueError:
            try:
                tooltip = str(QtGui.QApplication.translate(
                    "ship_areas",
                    "Areas curve tool draft selected [m]",
                    None,
                    QtGui.QApplication.UnicodeUTF8))
            except:
                tooltip = "Areas curve tool draft selected [m]"
            self.ship.addProperty("App::PropertyLength",
                                  "AreaCurveDraft",
                                  "Ship",
                                  tooltip)
        self.ship.AreaCurveDraft = '{} m'.format(draft)
        try:
            props.index("AreaCurveTrim")
        except ValueError:
            try:
                tooltip = str(QtGui.QApplication.translate(
                    "ship_areas",
                    "Areas curve tool trim selected [deg]",
                    None,
                    QtGui.QApplication.UnicodeUTF8))
            except:
                tooltip = "Areas curve tool trim selected [deg]"
            self.ship.addProperty("App::PropertyAngle",
                                  "AreaCurveTrim",
                                  "Ship",
                                  tooltip)
        self.ship.AreaCurveTrim = '{} deg'.format(trim)
Esempio n. 20
0
    def onUpdate(self):
        """ Method called when the data update is requested. """
        if not self.ship:
            return
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.output = self.widget(QtGui.QTextEdit, "OutputData")

        draft = Units.Quantity(Locale.fromString(
            form.draft.text())).getValueAs('m').Value
        trim = Units.Quantity(Locale.fromString(
            form.trim.text())).getValueAs('deg').Value

        # Calculate the drafts at each perpendicular
        angle = math.radians(trim)
        L = self.ship.Length.getValueAs('m').Value
        B = self.ship.Breadth.getValueAs('m').Value
        draftAP = draft + 0.5 * L * math.tan(angle)
        if draftAP < 0.0:
            draftAP = 0.0
        draftFP = draft - 0.5 * L * math.tan(angle)
        if draftFP < 0.0:
            draftFP = 0.0
        # Calculate the involved hydrostatics
        data = Hydrostatics.displacement(self.ship,
                                         draft,
                                         0.0,
                                         trim)
        # Setup the html string
        string = 'L = {0} [m]<BR>'.format(L)
        string = string + 'B = {0} [m]<BR>'.format(B)
        string = string + 'T = {0} [m]<HR>'.format(draft)
        string = string + 'Trim = {0} [degrees]<BR>'.format(trim)
        string = string + 'T<sub>AP</sub> = {0} [m]<BR>'.format(draftAP)
        string = string + 'T<sub>FP</sub> = {0} [m]<HR>'.format(draftFP)
        dispText = QtGui.QApplication.translate(
            "ship_areas",
            'Displacement',
            None,
            QtGui.QApplication.UnicodeUTF8)
        string = string + dispText + ' = {0} [ton]<BR>'.format(data[0])
        string = string + 'XCB = {0} [m]'.format(data[1].x)
        form.output.setHtml(string)
Esempio n. 21
0
    def onUpdate(self):
        """ Method called when the data update is requested. """
        if not self.ship:
            return
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.output = self.widget(QtGui.QTextEdit, "OutputData")

        draft = Units.parseQuantity(Locale.fromString(form.draft.text()))
        trim = Units.parseQuantity(Locale.fromString(form.trim.text()))

        # Calculate the drafts at each perpendicular
        angle = trim.getValueAs("rad").Value
        L = self.ship.Length.getValueAs('m').Value
        B = self.ship.Breadth.getValueAs('m').Value
        draftAP = draft + 0.5 * self.ship.Length * math.tan(angle)
        if draftAP < 0.0:
            draftAP = 0.0
        draftFP = draft - 0.5 * self.ship.Length * math.tan(angle)
        if draftFP < 0.0:
            draftFP = 0.0
        # Calculate the involved hydrostatics
        disp, B, _ = Hydrostatics.displacement(self.ship,
                                               draft,
                                               Units.parseQuantity("0 deg"),
                                               trim)
        xcb = Units.Quantity(B.x, Units.Length)
        # Setup the html string
        string = u'L = {0}<BR>'.format(self.ship.Length.UserString)
        string += u'B = {0}<BR>'.format(self.ship.Breadth.UserString)
        string += u'T = {0}<HR>'.format(draft.UserString)
        string += u'Trim = {0}<BR>'.format(trim.UserString)
        string += u'T<sub>AP</sub> = {0}<BR>'.format(draftAP.UserString)
        string += u'T<sub>FP</sub> = {0}<HR>'.format(draftFP.UserString)
        dispText = QtGui.QApplication.translate(
            "ship_areas",
            'Displacement',
            None,
            QtGui.QApplication.UnicodeUTF8)
        string += dispText + u' = {0}<BR>'.format(disp.UserString)
        string += u'XCB = {0}'.format(xcb.UserString)
        form.output.setHtml(string)
Esempio n. 22
0
    def onData(self, value):
        """ Method called when the tool input data is touched.
        @param value Changed value.
        """
        if not self.ship:
            return

        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")

        # Get the values (or fix them in bad setting case)
        try:
            draft = Units.Quantity(Locale.fromString(
                form.draft.text())).getValueAs('m').Value
        except:
            draft = self.ship.Draft.getValueAs(USys.getLengthUnits()).Value
            input_format = USys.getLengthFormat()
            qty = Units.Quantity('{} m'.format(draft))
            widget.setText(Locale.toString(input_format.format(
                qty.getValueAs(USys.getLengthUnits()).Value)))
        try:
            trim = Units.Quantity(Locale.fromString(
                form.trim.text())).getValueAs('deg').Value
        except:
            trim = 0.0
            input_format = USys.getAngleFormat()
            qty = Units.Quantity('{} deg'.format(trim))
            widget.setText(Locale.toString(input_format.format(
                qty.getValueAs(USys.getLengthUnits()).Value)))

        bbox = self.ship.Shape.BoundBox
        draft_min = bbox.ZMin / Units.Metre.Value
        draft_max = bbox.ZMax / Units.Metre.Value
        draft = self.clampLength(form.draft, draft_min, draft_max, draft)

        trim_min = -180.0
        trim_max = 180.0
        trim = self.clampAngle(form.trim, trim_min, trim_max, trim)

        self.onUpdate()
        self.preview.update(draft, trim, self.ship)
Esempio n. 23
0
    def onUpdate(self):
        """ Method called when the data update is requested. """
        if not self.ship:
            return
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.output = self.widget(QtGui.QTextEdit, "OutputData")

        draft = Units.parseQuantity(Locale.fromString(form.draft.text()))
        trim = Units.parseQuantity(Locale.fromString(form.trim.text()))

        # Calculate the drafts at each perpendicular
        angle = trim.getValueAs("rad").Value
        L = self.ship.Length.getValueAs('m').Value
        B = self.ship.Breadth.getValueAs('m').Value
        draftAP = draft + 0.5 * self.ship.Length * math.tan(angle)
        if draftAP < 0.0:
            draftAP = 0.0
        draftFP = draft - 0.5 * self.ship.Length * math.tan(angle)
        if draftFP < 0.0:
            draftFP = 0.0
        # Calculate the involved hydrostatics
        disp, B, _ = Hydrostatics.displacement(self.ship, draft,
                                               Units.parseQuantity("0 deg"),
                                               trim)
        xcb = Units.Quantity(B.x, Units.Length)
        # Setup the html string
        string = u'L = {0}<BR>'.format(self.ship.Length.UserString)
        string += u'B = {0}<BR>'.format(self.ship.Breadth.UserString)
        string += u'T = {0}<HR>'.format(draft.UserString)
        string += u'Trim = {0}<BR>'.format(trim.UserString)
        string += u'T<sub>AP</sub> = {0}<BR>'.format(draftAP.UserString)
        string += u'T<sub>FP</sub> = {0}<HR>'.format(draftFP.UserString)
        dispText = QtGui.QApplication.translate("ship_areas", 'Displacement',
                                                None,
                                                QtGui.QApplication.UnicodeUTF8)
        string += dispText + u' = {0}<BR>'.format(disp.UserString)
        string += u'XCB = {0}'.format(xcb.UserString)
        form.output.setHtml(string)
Esempio n. 24
0
    def accept(self):
        """Create the ship instance"""
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.ship = self.widget(QtGui.QComboBox, "Ship")
        form.weight = self.widget(QtGui.QLineEdit, "Weight")

        ship = self.ships[form.ship.currentIndex()]
        density = Units.parseQuantity(Locale.fromString(form.weight.text()))

        Tools.createWeight(self.shapes, ship, density)
        return True
Esempio n. 25
0
    def accept(self):
        """Create the ship instance"""
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.ship = self.widget(QtGui.QComboBox, "Ship")
        form.weight = self.widget(QtGui.QLineEdit, "Weight")

        ship = self.ships[form.ship.currentIndex()]
        density = Units.parseQuantity(Locale.fromString(form.weight.text()))

        Tools.createWeight(self.shapes, ship, density)
        return True
Esempio n. 26
0
    def onUpdate(self):
        """ Method called when the data update is requested. """
        if not self.ship:
            return
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.output = self.widget(QtGui.QTextEdit, "OutputData")

        draft = Units.Quantity(Locale.fromString(
            form.draft.text())).getValueAs('m').Value
        trim = Units.Quantity(Locale.fromString(
            form.trim.text())).getValueAs('deg').Value

        # Calculate the drafts at each perpendicular
        angle = math.radians(trim)
        L = self.ship.Length.getValueAs('m').Value
        B = self.ship.Breadth.getValueAs('m').Value
        draftAP = draft + 0.5 * L * math.tan(angle)
        if draftAP < 0.0:
            draftAP = 0.0
        draftFP = draft - 0.5 * L * math.tan(angle)
        if draftFP < 0.0:
            draftFP = 0.0
        # Calculate the involved hydrostatics
        data = Hydrostatics.displacement(self.ship, draft, 0.0, trim)
        # Setup the html string
        string = 'L = {0} [m]<BR>'.format(L)
        string = string + 'B = {0} [m]<BR>'.format(B)
        string = string + 'T = {0} [m]<HR>'.format(draft)
        string = string + 'Trim = {0} [degrees]<BR>'.format(trim)
        string = string + 'T<sub>AP</sub> = {0} [m]<BR>'.format(draftAP)
        string = string + 'T<sub>FP</sub> = {0} [m]<HR>'.format(draftFP)
        dispText = QtGui.QApplication.translate("ship_areas", 'Displacement',
                                                None,
                                                QtGui.QApplication.UnicodeUTF8)
        string = string + dispText + ' = {0} [ton]<BR>'.format(data[0])
        string = string + 'XCB = {0} [m]'.format(data[1].x)
        form.output.setHtml(string)
Esempio n. 27
0
    def save(self):
        """ Saves the data into ship instance. """
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")

        draft = Units.Quantity(Locale.fromString(
            form.draft.text())).getValueAs('m').Value
        trim = Units.Quantity(Locale.fromString(
            form.trim.text())).getValueAs('deg').Value

        props = self.ship.PropertiesList
        try:
            props.index("AreaCurveDraft")
        except ValueError:
            try:
                tooltip = str(
                    QtGui.QApplication.translate(
                        "ship_areas", "Areas curve tool draft selected [m]",
                        None, QtGui.QApplication.UnicodeUTF8))
            except:
                tooltip = "Areas curve tool draft selected [m]"
            self.ship.addProperty("App::PropertyLength", "AreaCurveDraft",
                                  "Ship", tooltip)
        self.ship.AreaCurveDraft = '{} m'.format(draft)
        try:
            props.index("AreaCurveTrim")
        except ValueError:
            try:
                tooltip = str(
                    QtGui.QApplication.translate(
                        "ship_areas", "Areas curve tool trim selected [deg]",
                        None, QtGui.QApplication.UnicodeUTF8))
            except:
                tooltip = "Areas curve tool trim selected [deg]"
            self.ship.addProperty("App::PropertyAngle", "AreaCurveTrim",
                                  "Ship", tooltip)
        self.ship.AreaCurveTrim = '{} deg'.format(trim)
Esempio n. 28
0
    def accept(self):
        """Create the ship instance"""
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.ship = self.widget(QtGui.QComboBox, "Ship")
        form.weight = self.widget(QtGui.QLineEdit, "Weight")

        # Create the object
        ship = self.ships[form.ship.currentIndex()]
        obj = App.ActiveDocument.addObject("Part::FeaturePython", "Weight")
        weight = Instance.Weight(obj, self.shapes, ship)
        Instance.ViewProviderWeight(obj.ViewObject)

        # Set the mass/density
        m_unit = USys.getMassUnits()
        l_unit = USys.getLengthUnits()
        qty = Units.parseQuantity(Locale.fromString(form.weight.text()))
        if self.elem_type == 1:
            w_unit = m_unit
            obj.Mass = qty.getValueAs(w_unit).Value
        elif self.elem_type == 2:
            w_unit = m_unit + '/' + l_unit
            obj.LineDens = qty.getValueAs(w_unit).Value
        elif self.elem_type == 3:
            w_unit = m_unit + '/' + l_unit + '^2'
            obj.AreaDens = qty.getValueAs(w_unit).Value
        elif self.elem_type == 4:
            w_unit = m_unit + '/' + l_unit + '^3'
            obj.Dens = qty.getValueAs(w_unit).Value

        # Set it as a child of the ship
        weights = ship.Weights[:]
        weights.append(obj.Name)
        ship.Weights = weights

        App.ActiveDocument.recompute()
        return True
Esempio n. 29
0
    def accept(self):
        """Create the ship instance"""
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.ship = self.widget(QtGui.QComboBox, "Ship")
        form.weight = self.widget(QtGui.QLineEdit, "Weight")

        # Create the object
        ship = self.ships[form.ship.currentIndex()]
        obj = App.ActiveDocument.addObject("Part::FeaturePython", "Weight")
        weight = Instance.Weight(obj, self.shapes, ship)
        Instance.ViewProviderWeight(obj.ViewObject)

        # Set the mass/density
        m_unit = USys.getMassUnits()
        l_unit = USys.getLengthUnits()
        qty = Units.parseQuantity(Locale.fromString(form.weight.text()))
        if self.elem_type == 1:
            w_unit = m_unit
            obj.Mass = qty.getValueAs(w_unit).Value
        elif self.elem_type == 2:
            w_unit = m_unit + '/' + l_unit
            obj.LineDens = qty.getValueAs(w_unit).Value
        elif self.elem_type == 3:
            w_unit = m_unit + '/' + l_unit + '^2'
            obj.AreaDens = qty.getValueAs(w_unit).Value
        elif self.elem_type == 4:
            w_unit = m_unit + '/' + l_unit + '^3'
            obj.Dens = qty.getValueAs(w_unit).Value

        # Set it as a child of the ship
        weights = ship.Weights[:]
        weights.append(obj.Name)
        ship.Weights = weights

        App.ActiveDocument.recompute()
        return True
Esempio n. 30
0
    def accept(self):
        if not self.ship:
            return False
        if self.running:
            return
        self.save()

        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.minDraft = self.widget(QtGui.QLineEdit, "MinDraft")
        form.maxDraft = self.widget(QtGui.QLineEdit, "MaxDraft")
        form.nDraft = self.widget(QtGui.QSpinBox, "NDraft")

        trim = Units.Quantity(Locale.fromString(
            form.trim.text())).getValueAs('deg').Value
        min_draft = Units.Quantity(Locale.fromString(
            form.minDraft.text())).getValueAs('m').Value
        max_draft = Units.Quantity(Locale.fromString(
            form.maxDraft.text())).getValueAs('m').Value
        n_draft = form.nDraft.value()

        draft = min_draft
        drafts = [draft]
        dDraft = (max_draft - min_draft) / (n_draft - 1)
        for i in range(1, n_draft):
            draft = draft + dDraft
            drafts.append(draft)

        # Compute data
        # Get external faces
        self.loop = QtCore.QEventLoop()
        self.timer = QtCore.QTimer()
        self.timer.setSingleShot(True)
        QtCore.QObject.connect(self.timer,
                               QtCore.SIGNAL("timeout()"),
                               self.loop,
                               QtCore.SLOT("quit()"))
        self.running = True
        faces = self.externalFaces(self.ship.Shape)
        if not self.running:
            return False
        if len(faces) == 0:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "Failure detecting external faces from the ship object",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return False
        faces = Part.makeShell(faces)
        # Get the hydrostatics
        msg = QtGui.QApplication.translate(
            "ship_console",
            "Computing hydrostatics",
            None,
            QtGui.QApplication.UnicodeUTF8)
        App.Console.PrintMessage(msg + '...\n')
        points = []
        for i in range(len(drafts)):
            App.Console.PrintMessage("\t{} / {}\n".format(i + 1, len(drafts)))
            draft = drafts[i]
            point = Tools.Point(self.ship,
                                faces,
                                draft,
                                trim)
            points.append(point)
            self.timer.start(0.0)
            self.loop.exec_()
            if(not self.running):
                break
        PlotAux.Plot(self.ship, trim, points)
        return True
Esempio n. 31
0
    def save(self):
        """ Saves data into ship instance.
        """
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.minDraft = self.widget(QtGui.QLineEdit, "MinDraft")
        form.maxDraft = self.widget(QtGui.QLineEdit, "MaxDraft")
        form.nDraft = self.widget(QtGui.QSpinBox, "NDraft")

        trim = Units.Quantity(Locale.fromString(
            form.trim.text())).getValueAs('deg').Value
        min_draft = Units.Quantity(Locale.fromString(
            form.minDraft.text())).getValueAs('m').Value
        max_draft = Units.Quantity(Locale.fromString(
            form.maxDraft.text())).getValueAs('m').Value
        n_draft = form.nDraft.value()

        props = self.ship.PropertiesList
        try:
            props.index("HydrostaticsTrim")
        except ValueError:
            tooltip = str(QtGui.QApplication.translate(
                "ship_hydrostatic",
                "Hydrostatics tool trim selected",
                None,
                QtGui.QApplication.UnicodeUTF8))
            self.ship.addProperty("App::PropertyAngle",
                                  "HydrostaticsTrim",
                                  "Ship",
                                  tooltip)
        self.ship.HydrostaticsTrim = '{} deg'.format(trim)

        try:
            props.index("HydrostaticsMinDraft")
        except ValueError:
            tooltip = str(QtGui.QApplication.translate(
                "ship_hydrostatic",
                "Hydrostatics tool minimum draft selected [m]",
                None,
                QtGui.QApplication.UnicodeUTF8))
            self.ship.addProperty("App::PropertyLength",
                                  "HydrostaticsMinDraft",
                                  "Ship",
                                  tooltip)
        self.ship.HydrostaticsMinDraft = '{} m'.format(min_draft)

        try:
            props.index("HydrostaticsMaxDraft")
        except ValueError:
            tooltip = str(QtGui.QApplication.translate(
                "ship_hydrostatic",
                "Hydrostatics tool maximum draft selected [m]",
                None,
                QtGui.QApplication.UnicodeUTF8))
            self.ship.addProperty("App::PropertyLength",
                                  "HydrostaticsMaxDraft",
                                  "Ship",
                                  tooltip)
        self.ship.HydrostaticsMaxDraft = '{} m'.format(max_draft)

        try:
            props.index("HydrostaticsNDraft")
        except ValueError:
            tooltip = str(QtGui.QApplication.translate(
                "ship_hydrostatic",
                "Hydrostatics tool number of points selected",
                None,
                QtGui.QApplication.UnicodeUTF8))
            self.ship.addProperty("App::PropertyInteger",
                                  "HydrostaticsNDraft",
                                  "Ship",
                                  tooltip)
        self.ship.HydrostaticsNDraft = form.nDraft.value()
Esempio n. 32
0
    def onData(self, value):
        """ Method called when input data is changed.
         @param value Changed value.
        """
        if not self.ship:
            return
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.minDraft = self.widget(QtGui.QLineEdit, "MinDraft")
        form.maxDraft = self.widget(QtGui.QLineEdit, "MaxDraft")

        # Get the values (or fix them in bad setting case)
        try:
            trim = Units.Quantity(Locale.fromString(
                form.trim.text())).getValueAs('deg').Value
        except:
            trim = 0.0
            input_format = USys.getAngleFormat()
            qty = Units.Quantity('{} deg'.format(trim))
            form.trim.setText(Locale.toString(input_format.format(
                qty.getValueAs(USys.getLengthUnits()).Value)))
        try:
            min_draft = Units.Quantity(Locale.fromString(
                form.minDraft.text())).getValueAs('m').Value
        except:
            min_draft = 0.9 * self.ship.Draft.getValueAs('m').Value
            input_format = USys.getLengthFormat()
            qty = Units.Quantity('{} m'.format(min_draft))
            form.minDraft.setText(Locale.toString(input_format.format(
                qty.getValueAs(USys.getLengthUnits()).Value)))
        try:
            max_draft = Units.Quantity(Locale.fromString(
                form.minDraft.text())).getValueAs('m').Value
        except:
            max_draft = 0.9 * self.ship.Draft.getValueAs('m').Value
            input_format = USys.getLengthFormat()
            qty = Units.Quantity('{} m'.format(max_draft))
            form.maxDraft.setText(Locale.toString(input_format.format(
                qty.getValueAs(USys.getLengthUnits()).Value)))

        # Clamp the values to the bounds
        bbox = self.ship.Shape.BoundBox
        draft_min = bbox.ZMin / Units.Metre.Value
        draft_max = bbox.ZMax / Units.Metre.Value
        min_draft = self.clampLength(form.minDraft,
                                     draft_min,
                                     draft_max,
                                     min_draft)
        max_draft = self.clampLength(form.maxDraft,
                                     draft_min,
                                     draft_max,
                                     max_draft)
        trim_min = -180.0
        trim_max = 180.0
        trim = self.clampAngle(form.trim, trim_min, trim_max, trim)

        # Clamp draft values to assert that the minimum value is lower than
        # the maximum one
        min_draft = self.clampLength(form.minDraft,
                                     draft_min,
                                     max_draft,
                                     min_draft)
        max_draft = self.clampLength(form.maxDraft,
                                     min_draft,
                                     draft_max,
                                     max_draft)
Esempio n. 33
0
    def onData(self, value):
        """ Method called when input data is changed.
         @param value Changed value.
        """
        if not self.ship:
            return
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.minDraft = self.widget(QtGui.QLineEdit, "MinDraft")
        form.maxDraft = self.widget(QtGui.QLineEdit, "MaxDraft")

        # Get the values (or fix them in bad setting case)
        try:
            trim = Units.Quantity(Locale.fromString(
                form.trim.text())).getValueAs('deg').Value
        except:
            trim = 0.0
            input_format = USys.getAngleFormat()
            qty = Units.Quantity('{} deg'.format(trim))
            form.trim.setText(
                Locale.toString(
                    input_format.format(
                        qty.getValueAs(USys.getLengthUnits()).Value)))
        try:
            min_draft = Units.Quantity(Locale.fromString(
                form.minDraft.text())).getValueAs('m').Value
        except:
            min_draft = 0.9 * self.ship.Draft.getValueAs('m').Value
            input_format = USys.getLengthFormat()
            qty = Units.Quantity('{} m'.format(min_draft))
            form.minDraft.setText(
                Locale.toString(
                    input_format.format(
                        qty.getValueAs(USys.getLengthUnits()).Value)))
        try:
            max_draft = Units.Quantity(Locale.fromString(
                form.minDraft.text())).getValueAs('m').Value
        except:
            max_draft = 0.9 * self.ship.Draft.getValueAs('m').Value
            input_format = USys.getLengthFormat()
            qty = Units.Quantity('{} m'.format(max_draft))
            form.maxDraft.setText(
                Locale.toString(
                    input_format.format(
                        qty.getValueAs(USys.getLengthUnits()).Value)))

        # Clamp the values to the bounds
        bbox = self.ship.Shape.BoundBox
        draft_min = bbox.ZMin / Units.Metre.Value
        draft_max = bbox.ZMax / Units.Metre.Value
        min_draft = self.clampLength(form.minDraft, draft_min, draft_max,
                                     min_draft)
        max_draft = self.clampLength(form.maxDraft, draft_min, draft_max,
                                     max_draft)
        trim_min = -180.0
        trim_max = 180.0
        trim = self.clampAngle(form.trim, trim_min, trim_max, trim)

        # Clamp draft values to assert that the minimum value is lower than
        # the maximum one
        min_draft = self.clampLength(form.minDraft, draft_min, max_draft,
                                     min_draft)
        max_draft = self.clampLength(form.maxDraft, min_draft, draft_max,
                                     max_draft)
Esempio n. 34
0
    def save(self):
        """ Saves data into ship instance.
        """
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.minDraft = self.widget(QtGui.QLineEdit, "MinDraft")
        form.maxDraft = self.widget(QtGui.QLineEdit, "MaxDraft")
        form.nDraft = self.widget(QtGui.QSpinBox, "NDraft")

        trim = Units.Quantity(Locale.fromString(
            form.trim.text())).getValueAs('deg').Value
        min_draft = Units.Quantity(Locale.fromString(
            form.minDraft.text())).getValueAs('m').Value
        max_draft = Units.Quantity(Locale.fromString(
            form.maxDraft.text())).getValueAs('m').Value
        n_draft = form.nDraft.value()

        props = self.ship.PropertiesList
        try:
            props.index("HydrostaticsTrim")
        except ValueError:
            tooltip = str(
                QtGui.QApplication.translate(
                    "ship_hydrostatic", "Hydrostatics tool trim selected",
                    None, QtGui.QApplication.UnicodeUTF8))
            self.ship.addProperty("App::PropertyAngle", "HydrostaticsTrim",
                                  "Ship", tooltip)
        self.ship.HydrostaticsTrim = '{} deg'.format(trim)

        try:
            props.index("HydrostaticsMinDraft")
        except ValueError:
            tooltip = str(
                QtGui.QApplication.translate(
                    "ship_hydrostatic",
                    "Hydrostatics tool minimum draft selected [m]", None,
                    QtGui.QApplication.UnicodeUTF8))
            self.ship.addProperty("App::PropertyLength",
                                  "HydrostaticsMinDraft", "Ship", tooltip)
        self.ship.HydrostaticsMinDraft = '{} m'.format(min_draft)

        try:
            props.index("HydrostaticsMaxDraft")
        except ValueError:
            tooltip = str(
                QtGui.QApplication.translate(
                    "ship_hydrostatic",
                    "Hydrostatics tool maximum draft selected [m]", None,
                    QtGui.QApplication.UnicodeUTF8))
            self.ship.addProperty("App::PropertyLength",
                                  "HydrostaticsMaxDraft", "Ship", tooltip)
        self.ship.HydrostaticsMaxDraft = '{} m'.format(max_draft)

        try:
            props.index("HydrostaticsNDraft")
        except ValueError:
            tooltip = str(
                QtGui.QApplication.translate(
                    "ship_hydrostatic",
                    "Hydrostatics tool number of points selected", None,
                    QtGui.QApplication.UnicodeUTF8))
            self.ship.addProperty("App::PropertyInteger", "HydrostaticsNDraft",
                                  "Ship", tooltip)
        self.ship.HydrostaticsNDraft = form.nDraft.value()
Esempio n. 35
0
    def accept(self):
        if not self.ship:
            return False
        if self.running:
            return
        self.save()

        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.minDraft = self.widget(QtGui.QLineEdit, "MinDraft")
        form.maxDraft = self.widget(QtGui.QLineEdit, "MaxDraft")
        form.nDraft = self.widget(QtGui.QSpinBox, "NDraft")

        trim = Units.Quantity(Locale.fromString(
            form.trim.text())).getValueAs('deg').Value
        min_draft = Units.Quantity(Locale.fromString(
            form.minDraft.text())).getValueAs('m').Value
        max_draft = Units.Quantity(Locale.fromString(
            form.maxDraft.text())).getValueAs('m').Value
        n_draft = form.nDraft.value()

        draft = min_draft
        drafts = [draft]
        dDraft = (max_draft - min_draft) / (n_draft - 1)
        for i in range(1, n_draft):
            draft = draft + dDraft
            drafts.append(draft)

        # Compute data
        # Get external faces
        self.loop = QtCore.QEventLoop()
        self.timer = QtCore.QTimer()
        self.timer.setSingleShot(True)
        QtCore.QObject.connect(self.timer, QtCore.SIGNAL("timeout()"),
                               self.loop, QtCore.SLOT("quit()"))
        self.running = True
        faces = self.externalFaces(self.ship.Shape)
        if not self.running:
            return False
        if len(faces) == 0:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "Failure detecting external faces from the ship object", None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return False
        faces = Part.makeShell(faces)
        # Get the hydrostatics
        msg = QtGui.QApplication.translate("ship_console",
                                           "Computing hydrostatics", None,
                                           QtGui.QApplication.UnicodeUTF8)
        App.Console.PrintMessage(msg + '...\n')
        points = []
        for i in range(len(drafts)):
            App.Console.PrintMessage("\t{} / {}\n".format(i + 1, len(drafts)))
            draft = drafts[i]
            point = Tools.Point(self.ship, faces, draft, trim)
            points.append(point)
            self.timer.start(0.0)
            self.loop.exec_()
            if (not self.running):
                break
        PlotAux.Plot(self.ship, trim, points)
        return True