当前位置: 首页>>代码示例>>Python>>正文


Python Units.getLengthUnits方法代码示例

本文整理汇总了Python中shipUtils.Units.getLengthUnits方法的典型用法代码示例。如果您正苦于以下问题:Python Units.getLengthUnits方法的具体用法?Python Units.getLengthUnits怎么用?Python Units.getLengthUnits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shipUtils.Units的用法示例。


在下文中一共展示了Units.getLengthUnits方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: clampVal

# 需要导入模块: from shipUtils import Units [as 别名]
# 或者: from shipUtils.Units import getLengthUnits [as 别名]
 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
开发者ID:3DPrinterGuy,项目名称:FreeCAD,代码行数:11,代码来源:TaskPanel.py

示例2: clampAngle

# 需要导入模块: from shipUtils import Units [as 别名]
# 或者: from shipUtils.Units import getLengthUnits [as 别名]
 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
开发者ID:biki89,项目名称:FreeCAD_sf_master,代码行数:11,代码来源:TaskPanel.py

示例3: onData

# 需要导入模块: from shipUtils import Units [as 别名]
# 或者: from shipUtils.Units import getLengthUnits [as 别名]
    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)
开发者ID:Fabracoder,项目名称:FreeCAD_sf_master,代码行数:45,代码来源:TaskPanel.py

示例4: accept

# 需要导入模块: from shipUtils import Units [as 别名]
# 或者: from shipUtils.Units import getLengthUnits [as 别名]
    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
开发者ID:DanielDTR,项目名称:FreeCAD_sf_master,代码行数:39,代码来源:TaskPanel.py

示例5: initValues

# 需要导入模块: from shipUtils import Units [as 别名]
# 或者: from shipUtils.Units import getLengthUnits [as 别名]
    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
开发者ID:3DPrinterGuy,项目名称:FreeCAD,代码行数:81,代码来源:TaskPanel.py

示例6: initValues

# 需要导入模块: from shipUtils import Units [as 别名]
# 或者: from shipUtils.Units import getLengthUnits [as 别名]
    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
#.........这里部分代码省略.........
开发者ID:DanielDTR,项目名称:FreeCAD_sf_master,代码行数:103,代码来源:TaskPanel.py

示例7: onData

# 需要导入模块: from shipUtils import Units [as 别名]
# 或者: from shipUtils.Units import getLengthUnits [as 别名]
    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)
开发者ID:CobraElDiablo,项目名称:FreeCAD_sf_master,代码行数:68,代码来源:TaskPanel.py

示例8: initValues

# 需要导入模块: from shipUtils import Units [as 别名]
# 或者: from shipUtils.Units import getLengthUnits [as 别名]
    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
开发者ID:CobraElDiablo,项目名称:FreeCAD_sf_master,代码行数:88,代码来源:TaskPanel.py


注:本文中的shipUtils.Units.getLengthUnits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。