本文整理汇总了Python中shipUtils.Units.getMassUnits方法的典型用法代码示例。如果您正苦于以下问题:Python Units.getMassUnits方法的具体用法?Python Units.getMassUnits怎么用?Python Units.getMassUnits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shipUtils.Units
的用法示例。
在下文中一共展示了Units.getMassUnits方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: accept
# 需要导入模块: from shipUtils import Units [as 别名]
# 或者: from shipUtils.Units import getMassUnits [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
示例2: initValues
# 需要导入模块: from shipUtils import Units [as 别名]
# 或者: from shipUtils.Units import getMassUnits [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
#.........这里部分代码省略.........