Ejemplo 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.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)
Ejemplo n.º 2
0
 def clampAngle(self, widget, val_min, val_max, val):
     if val >= val_min and val <= val_max:
         return val
     input_format = USys.getAngleFormat()
     val = min(val_max, max(val_min, val))
     qty = Units.Quantity('{} deg'.format(val))
     widget.setText(input_format.format(
         qty.getValueAs(USys.getLengthUnits()).Value))
     return val
Ejemplo n.º 3
0
 def clampAngle(self, widget, val_min, val_max, val):
     if val >= val_min and val <= val_max:
         return val
     input_format = USys.getAngleFormat()
     val = min(val_max, max(val_min, val))
     qty = Units.Quantity('{} deg'.format(val))
     widget.setText(input_format.format(
         qty.getValueAs(USys.getLengthUnits()).Value))
     return val
Ejemplo n.º 4
0
 def clampVal(self, widget, val_min, val_max, val):
     if val >= val_min and val <= val_max:
         return val
     input_format = USys.getLengthFormat()
     val = min(val_max, max(val_min, val))
     qty = Units.Quantity('{} m'.format(val))
     widget.setText(Locale.toString(input_format.format(
         qty.getValueAs(USys.getLengthUnits()).Value)))
     return val
Ejemplo n.º 5
0
 def clampVal(self, widget, val_min, val_max, val):
     if val >= val_min and val <= val_max:
         return val
     input_format = USys.getLengthFormat()
     val = min(val_max, max(val_min, val))
     qty = Units.Quantity('{} m'.format(val))
     widget.setText(Locale.toString(input_format.format(
         qty.getValueAs(USys.getLengthUnits()).Value)))
     return val
Ejemplo n.º 6
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)
Ejemplo n.º 7
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(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
Ejemplo n.º 8
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(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
Ejemplo n.º 9
0
    def initValues(self):
        """ Set initial values for fields
        """
        selObjs = Gui.Selection.getSelection()
        if not selObjs:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "A ship instance must be selected before using this tool (no"
                " objects selected)", None, QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True
        for i in range(0, len(selObjs)):
            obj = selObjs[i]
            props = obj.PropertiesList
            try:
                props.index("IsShip")
            except ValueError:
                continue
            if obj.IsShip:
                if self.ship:
                    msg = QtGui.QApplication.translate(
                        "ship_console",
                        "More than one ship have been selected (the extra"
                        " ships will be ignored)", None,
                        QtGui.QApplication.UnicodeUTF8)
                    App.Console.PrintWarning(msg + '\n')
                    break
                self.ship = obj
        if not self.ship:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "A ship instance must be selected before using this tool (no"
                " valid ship found at the selected objects)", None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True

        length_format = USys.getLengthFormat()
        angle_format = USys.getAngleFormat()

        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.draft = self.widget(QtGui.QLineEdit, "Draft")
        form.trim = self.widget(QtGui.QLineEdit, "Trim")
        form.draft.setText(
            Locale.toString(
                length_format.format(
                    self.ship.Draft.getValueAs(USys.getLengthUnits()).Value)))
        form.trim.setText(Locale.toString(angle_format.format(0.0)))
        # Try to use saved values
        props = self.ship.PropertiesList
        try:
            props.index("AreaCurveDraft")
            form.draft.setText(
                Locale.toString(
                    length_format.format(
                        self.ship.AreaCurveDraft.getValueAs(
                            USys.getLengthUnits()).Value)))
        except:
            pass
        try:
            props.index("AreaCurveTrim")
            form.trim.setText(
                Locale.toString(
                    angle_format.format(
                        self.ship.AreaCurveTrim.getValueAs(
                            USys.getAngleUnits()).Value)))
        except ValueError:
            pass
        # Update GUI
        draft = Units.Quantity(form.draft.text()).getValueAs('m').Value
        trim = Units.Quantity(form.trim.text()).getValueAs('deg').Value
        self.preview.update(draft, trim, self.ship)
        self.onUpdate()
        return False
Ejemplo n.º 10
0
    def initValues(self):
        """ Set initial values for fields
        """
        selObjs = Gui.Selection.getSelection()
        if not selObjs:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "A ship instance must be selected before using this tool (no"
                " objects selected)",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True
        for i in range(0, len(selObjs)):
            obj = selObjs[i]
            props = obj.PropertiesList
            try:
                props.index("IsShip")
            except ValueError:
                continue
            if obj.IsShip:
                if self.ship:
                    msg = QtGui.QApplication.translate(
                        "ship_console",
                        "More than one ship have been selected (the extra"
                        " ships will be ignored)",
                        None,
                        QtGui.QApplication.UnicodeUTF8)
                    App.Console.PrintWarning(msg + '\n')
                    break
                self.ship = obj
        if not self.ship:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "A ship instance must be selected before using this tool (no"
                " valid ship found at the selected objects)",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True

        length_format = USys.getLengthFormat()
        angle_format = USys.getAngleFormat()

        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")
        form.draft.setText(Locale.toString(length_format.format(
            self.ship.Draft.getValueAs(USys.getLengthUnits()).Value)))
        form.trim.setText(Locale.toString(angle_format.format(0.0)))
        # Try to use saved values
        props = self.ship.PropertiesList
        try:
            props.index("AreaCurveDraft")
            form.draft.setText(Locale.toString(length_format.format(
                self.ship.AreaCurveDraft.getValueAs(
                    USys.getLengthUnits()).Value)))
        except:
            pass
        try:
            props.index("AreaCurveTrim")
            form.trim.setText(Locale.toString(angle_format.format(
                self.ship.AreaCurveTrim.getValueAs(
                    USys.getAngleUnits()).Value)))
        except ValueError:
            pass
        try:
            props.index("AreaCurveNum")
            form.num.setValue(self.ship.AreaCurveNum)
        except ValueError:
            pass
        # Update GUI
        draft = Units.Quantity(form.draft.text()).getValueAs('m').Value
        trim = Units.Quantity(form.trim.text()).getValueAs('deg').Value
        self.preview.update(draft, trim, self.ship)
        self.onUpdate()
        return False
Ejemplo n.º 11
0
    def initValues(self):
        """Setup the initial values"""
        # Ensure that there are at least one valid object to generate the
        # weight
        selObjs = Gui.Selection.getSelection()
        self.shapes = []
        if not selObjs:
            msg = QtGui.QApplication.translate(
                "ship_weight",
                "Weight objects can only be created on top of its geometry"
                " (no objects selected)",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True
        for obj in selObjs:
            try:
                self.shapes.append(obj.Shape)
            except:
                continue
        if not len(self.shapes):
            msg = QtGui.QApplication.translate(
                "ship_weight",
                "No geometrical shapes found in the selected objects",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True

        # Get the element type
        # 0 = unknow, 1 = vertex, 2 = line, 3 = face, 4 = solids
        self.elem_type = 0
        for shape in self.shapes:
            # Doing it in this way we are protected under strange entities,
            # and we are prepared to add higher level type of entities in the
            # future, just in case...
            try:
                if len(shape.Solids):
                    self.elem_type = max(4, self.elem_type)
            except:
                pass
            try:
                if len(shape.Faces):
                    self.elem_type = max(3, self.elem_type)
            except:
                pass
            try:
                if len(shape.Edges):
                    self.elem_type = max(2, self.elem_type)
            except:
                pass
            try:
                if len(shape.Vertexes):
                    self.elem_type = max(1, self.elem_type)
            except:
                pass
        # Could it happens???
        if self.elem_type == 0:
            msg = QtGui.QApplication.translate(
                "ship_weight",
                "Unknow object shapes selected",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True

        # Ensure as well that exist at least one valid ship to create the
        # entity inside it
        self.ships = []
        for obj in App.ActiveDocument.Objects:
            try:
                if obj.IsShip:
                    self.ships.append(obj)
            except:
                continue
        if not len(self.ships):
            msg = QtGui.QApplication.translate(
                "ship_weight",
                "There are not ship objects to create weights into them",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True

        # Fill the ships combo box
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.ship = self.widget(QtGui.QComboBox, "Ship")
        form.weight = self.widget(QtGui.QLineEdit, "Weight")
        icon = QtGui.QIcon(QtGui.QPixmap(":/icons/Ship_Instance.svg"))
        form.ship.clear()
        for ship in self.ships:
            form.ship.addItem(icon, ship.Label)
        form.ship.setCurrentIndex(0)

        # Initialize the 0 mass/density string field
        m_unit = USys.getMassUnits()
        l_unit = USys.getLengthUnits()
        if self.elem_type == 1:
            w_unit = m_unit
        elif self.elem_type == 2:
            w_unit = m_unit + '/' + l_unit
        elif self.elem_type == 3:
            w_unit = m_unit + '/' + l_unit + '^2'
        elif self.elem_type == 4:
            w_unit = m_unit + '/' + l_unit + '^3'
        form.weight.setText('0 ' + w_unit)
        return False
Ejemplo n.º 12
0
    def initValues(self):
        """Setup the initial values"""
        self.solids = None
        selObjs = Gui.Selection.getSelection()
        if not selObjs:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "Ship objects can only be created on top of hull geometry"
                " (no objects selected)",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            msg = QtGui.QApplication.translate(
                "ship_console",
                "Please create or load a ship hull geometry before using"
                " this tool",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True
        self.solids = []
        for i in range(0, len(selObjs)):
            solids = self.getSolids(selObjs[i])
            for j in range(0, len(solids)):
                self.solids.append(solids[j])
        if not self.solids:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "Ship objects can only be created on top of hull geometry"
                " (no solid found at selected objects)",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            msg = QtGui.QApplication.translate(
                "ship_console",
                "Please create or load a ship hull geometry before using"
                " this tool",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True
        # Get the ship bounds. The ship instance can not have dimensions
        # out of these values.
        self.bounds = [0.0, 0.0, 0.0]
        bbox = self.solids[0].BoundBox
        minX = bbox.XMin
        maxX = bbox.XMax
        minY = bbox.YMin
        maxY = bbox.YMax
        minZ = bbox.ZMin
        maxZ = bbox.ZMax
        for i in range(1, len(self.solids)):
            bbox = self.solids[i].BoundBox
            if minX > bbox.XMin:
                minX = bbox.XMin
            if maxX < bbox.XMax:
                maxX = bbox.XMax
            if minY > bbox.YMin:
                minY = bbox.YMin
            if maxY < bbox.YMax:
                maxY = bbox.YMax
            if minZ > bbox.ZMin:
                minZ = bbox.ZMin
            if maxZ < bbox.ZMax:
                maxZ = bbox.ZMax
        self.bounds[0] = maxX - minX
        self.bounds[1] = max(maxY - minY, abs(maxY), abs(minY))
        self.bounds[2] = maxZ - minZ

        input_format = USys.getLengthFormat()

        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(self.bounds[0], Units.Length)
        form.length.setText(Locale.toString(input_format.format(
            qty.getValueAs(USys.getLengthUnits()).Value)))
        self.L = self.bounds[0] / Units.Metre.Value
        qty = Units.Quantity(self.bounds[1], Units.Length)
        form.breadth.setText(Locale.toString(input_format.format(
            qty.getValueAs(USys.getLengthUnits()).Value)))
        self.B = self.bounds[1] / Units.Metre.Value
        qty = Units.Quantity(self.bounds[2], Units.Length)
        form.draft.setText(Locale.toString(input_format.format(
            0.5 * qty.getValueAs(USys.getLengthUnits()).Value)))
        self.T = 0.5 * self.bounds[2] / Units.Metre.Value
        return False
Ejemplo n.º 13
0
    def initValues(self):
        """Setup the initial values"""
        # Ensure that there are at least one valid object to generate the
        # weight
        selObjs = Gui.Selection.getSelection()
        self.shapes = []
        if not selObjs:
            msg = QtGui.QApplication.translate(
                "ship_weight",
                "Weight objects can only be created on top of its geometry"
                " (no objects selected)", None, QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True
        for obj in selObjs:
            try:
                self.shapes.append(obj.Shape)
            except:
                continue
        if not len(self.shapes):
            msg = QtGui.QApplication.translate(
                "ship_weight",
                "No geometrical shapes found in the selected objects", None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True

        # Get the element type
        # 0 = unknow, 1 = vertex, 2 = line, 3 = face, 4 = solids
        self.elem_type = 0
        for shape in self.shapes:
            # Doing it in this way we are protected under strange entities,
            # and we are prepared to add higher level type of entities in the
            # future, just in case...
            try:
                if len(shape.Solids):
                    self.elem_type = max(4, self.elem_type)
            except:
                pass
            try:
                if len(shape.Faces):
                    self.elem_type = max(3, self.elem_type)
            except:
                pass
            try:
                if len(shape.Edges):
                    self.elem_type = max(2, self.elem_type)
            except:
                pass
            try:
                if len(shape.Vertexes):
                    self.elem_type = max(1, self.elem_type)
            except:
                pass
        # Could it happens???
        if self.elem_type == 0:
            msg = QtGui.QApplication.translate(
                "ship_weight", "Unknow object shapes selected", None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True

        # Ensure as well that exist at least one valid ship to create the
        # entity inside it
        self.ships = []
        for obj in App.ActiveDocument.Objects:
            try:
                if obj.IsShip:
                    self.ships.append(obj)
            except:
                continue
        if not len(self.ships):
            msg = QtGui.QApplication.translate(
                "ship_weight",
                "There are not ship objects to create weights into them", None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True

        # Fill the ships combo box
        mw = self.getMainWindow()
        form = mw.findChild(QtGui.QWidget, "TaskPanel")
        form.ship = self.widget(QtGui.QComboBox, "Ship")
        form.weight = self.widget(QtGui.QLineEdit, "Weight")
        icon = QtGui.QIcon(QtGui.QPixmap(":/icons/Ship_Instance.svg"))
        form.ship.clear()
        for ship in self.ships:
            form.ship.addItem(icon, ship.Label)
        form.ship.setCurrentIndex(0)

        # Initialize the 0 mass/density string field
        m_unit = USys.getMassUnits()
        l_unit = USys.getLengthUnits()
        if self.elem_type == 1:
            w_unit = m_unit
        elif self.elem_type == 2:
            w_unit = m_unit + '/' + l_unit
        elif self.elem_type == 3:
            w_unit = m_unit + '/' + l_unit + '^2'
        elif self.elem_type == 4:
            w_unit = m_unit + '/' + l_unit + '^3'
        form.weight.setText('0 ' + w_unit)
        return False
Ejemplo n.º 14
0
    def initValues(self):
        """Setup the initial values"""
        self.solids = None
        selObjs = Gui.Selection.getSelection()
        if not selObjs:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "Ship objects can only be created on top of hull geometry"
                " (no objects selected)",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            msg = QtGui.QApplication.translate(
                "ship_console",
                "Please create or load a ship hull geometry before using"
                " this tool",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True
        self.solids = []
        for i in range(0, len(selObjs)):
            solids = self.getSolids(selObjs[i])
            for j in range(0, len(solids)):
                self.solids.append(solids[j])
        if not self.solids:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "Ship objects can only be created on top of hull geometry"
                " (no solid found at selected objects)",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            msg = QtGui.QApplication.translate(
                "ship_console",
                "Please create or load a ship hull geometry before using"
                " this tool",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True
        # Get the ship bounds. The ship instance can not have dimensions
        # out of these values.
        self.bounds = [0.0, 0.0, 0.0]
        bbox = self.solids[0].BoundBox
        minX = bbox.XMin
        maxX = bbox.XMax
        minY = bbox.YMin
        maxY = bbox.YMax
        minZ = bbox.ZMin
        maxZ = bbox.ZMax
        for i in range(1, len(self.solids)):
            bbox = self.solids[i].BoundBox
            if minX > bbox.XMin:
                minX = bbox.XMin
            if maxX < bbox.XMax:
                maxX = bbox.XMax
            if minY > bbox.YMin:
                minY = bbox.YMin
            if maxY < bbox.YMax:
                maxY = bbox.YMax
            if minZ > bbox.ZMin:
                minZ = bbox.ZMin
            if maxZ < bbox.ZMax:
                maxZ = bbox.ZMax
        self.bounds[0] = maxX - minX
        self.bounds[1] = max(maxY - minY, abs(maxY), abs(minY))
        self.bounds[2] = maxZ - minZ

        input_format = USys.getLengthFormat()

        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(self.bounds[0], Units.Length)
        form.length.setText(Locale.toString(input_format.format(
            qty.getValueAs(USys.getLengthUnits()).Value)))
        self.L = self.bounds[0] / Units.Metre.Value
        qty = Units.Quantity(self.bounds[1], Units.Length)
        form.breadth.setText(Locale.toString(input_format.format(
            qty.getValueAs(USys.getLengthUnits()).Value)))
        self.B = self.bounds[1] / Units.Metre.Value
        qty = Units.Quantity(self.bounds[2], Units.Length)
        form.draft.setText(Locale.toString(input_format.format(
            0.5 * qty.getValueAs(USys.getLengthUnits()).Value)))
        self.T = 0.5 * self.bounds[2] / Units.Metre.Value
        return False
Ejemplo n.º 15
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)
Ejemplo n.º 16
0
    def initValues(self):
        """ Set initial values for fields
        """
        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")

        selObjs = Gui.Selection.getSelection()
        if not selObjs:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "A ship instance must be selected before using this tool (no"
                " objects selected)", None, QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True
        for i in range(len(selObjs)):
            obj = selObjs[i]
            props = obj.PropertiesList
            try:
                props.index("IsShip")
            except ValueError:
                continue
            if obj.IsShip:
                if self.ship:
                    msg = QtGui.QApplication.translate(
                        "ship_console",
                        "More than one ship have been selected (the extra"
                        " ships will be ignored)", None,
                        QtGui.QApplication.UnicodeUTF8)
                    App.Console.PrintWarning(msg + '\n')
                    break
                self.ship = obj

        if not self.ship:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "A ship instance must be selected before using this tool (no"
                " valid ship found at the selected objects)", None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True

        props = self.ship.PropertiesList

        length_format = USys.getLengthFormat()
        angle_format = USys.getAngleFormat()

        try:
            props.index("HydrostaticsTrim")
            form.trim.setText(
                Locale.toString(
                    angle_format.format(
                        self.ship.HydrostaticsTrim.getValueAs(
                            USys.getLengthUnits()).Value)))
        except ValueError:
            form.trim.setText(Locale.toString(angle_format.format(0.0)))

        try:
            props.index("HydrostaticsMinDraft")
            form.minDraft.setText(
                Locale.toString(
                    length_format.format(
                        self.ship.HydrostaticsMinDraft.getValueAs(
                            USys.getLengthUnits()).Value)))
        except ValueError:
            form.minDraft.setText(
                Locale.toString(
                    length_format.format(0.9 * self.ship.Draft.getValueAs(
                        USys.getLengthUnits()).Value)))
        try:
            props.index("HydrostaticsMaxDraft")
            form.maxDraft.setText(
                Locale.toString(
                    length_format.format(
                        self.ship.HydrostaticsMaxDraft.getValueAs(
                            USys.getLengthUnits()).Value)))
        except ValueError:
            form.maxDraft.setText(
                Locale.toString(
                    length_format.format(1.1 * self.ship.Draft.getValueAs(
                        USys.getLengthUnits()).Value)))

        try:
            props.index("HydrostaticsNDraft")
            form.nDraft.setValue(self.ship.HydrostaticsNDraft)
        except ValueError:
            pass

        return False
Ejemplo n.º 17
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(form.trim.text()).getValueAs('deg').Value
        except:
            trim = 0.0
            input_format = USys.getAngleFormat()
            qty = Units.Quantity('{} deg'.format(trim))
            form.trim.setText(input_format.format(
                qty.getValueAs(USys.getLengthUnits()).Value))
        try:
            min_draft = Units.Quantity(
                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(input_format.format(
                qty.getValueAs(USys.getLengthUnits()).Value))
        try:
            max_draft = Units.Quantity(
                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(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)
Ejemplo n.º 18
0
    def initValues(self):
        """ Set initial values for fields
        """
        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")

        selObjs = Gui.Selection.getSelection()
        if not selObjs:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "A ship instance must be selected before using this tool (no"
                " objects selected)",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True
        for i in range(len(selObjs)):
            obj = selObjs[i]
            props = obj.PropertiesList
            try:
                props.index("IsShip")
            except ValueError:
                continue
            if obj.IsShip:
                if self.ship:
                    msg = QtGui.QApplication.translate(
                        "ship_console",
                        "More than one ship have been selected (the extra"
                        " ships will be ignored)",
                        None,
                        QtGui.QApplication.UnicodeUTF8)
                    App.Console.PrintWarning(msg + '\n')
                    break
                self.ship = obj

        if not self.ship:
            msg = QtGui.QApplication.translate(
                "ship_console",
                "A ship instance must be selected before using this tool (no"
                " valid ship found at the selected objects)",
                None,
                QtGui.QApplication.UnicodeUTF8)
            App.Console.PrintError(msg + '\n')
            return True

        props = self.ship.PropertiesList

        length_format = USys.getLengthFormat()
        angle_format = USys.getAngleFormat()

        try:
            props.index("HydrostaticsTrim")
            form.trim.setText(angle_format.format(
                self.ship.HydrostaticsTrim.getValueAs(
                    USys.getLengthUnits()).Value))
        except ValueError:
            form.trim.setText(angle_format.format(0.0))

        try:
            props.index("HydrostaticsMinDraft")
            form.minDraft.setText(length_format.format(
                self.ship.HydrostaticsMinDraft.getValueAs(
                    USys.getLengthUnits()).Value))
        except ValueError:
            form.minDraft.setText(length_format.format(
                0.9 * self.ship.Draft.getValueAs('m').Value))
        try:
            props.index("HydrostaticsMaxDraft")
            form.maxDraft.setText(length_format.format(
                self.ship.HydrostaticsMaxDraft.getValueAs(
                    USys.getLengthUnits()).Value))
        except ValueError:
            form.maxDraft.setText(length_format.format(
                1.1 * self.ship.Draft.getValueAs('m').Value))

        try:
            props.index("HydrostaticsNDraft")
            form.nDraft.setValue(self.ship.HydrostaticsNDraft)
        except ValueError:
            pass

        return False