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
def initValues(self): """ Set initial values for fields """ # Look for selected loading conditions (Spreadsheets) self.lc = None selObjs = Gui.Selection.getSelection() if not selObjs: msg = QtGui.QApplication.translate( "ship_console", "A loading condition 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] try: if obj.TypeId != "Spreadsheet::Sheet": continue except ValueError: continue # Check if it is a Loading condition: # B1 cell must be a ship # B2 cell must be the loading condition itself doc = App.ActiveDocument try: if obj not in doc.getObjectsByLabel(obj.get("B2")): continue ships = doc.getObjectsByLabel(obj.get("B1")) if len(ships) != 1: if len(ships) == 0: msg = QtGui.QApplication.translate( "ship_console", "Wrong Ship label! (no instances labeled as" "'{}' found)", None, QtGui.QApplication.UnicodeUTF8, ) App.Console.PrintError(msg + "\n".format(obj.get("B1"))) else: msg = QtGui.QApplication.translate( "ship_console", "Ambiguous Ship label! ({} instances labeled as" "'{}' found)", None, QtGui.QApplication.UnicodeUTF8, ) App.Console.PrintError(msg + "\n".format(len(ships), obj.get("B1"))) continue ship = ships[0] if ship is None or not ship.PropertiesList.index("IsShip"): continue except ValueError: continue # Let's see if several loading conditions have been selected (and # prompt a warning) if self.lc: msg = QtGui.QApplication.translate( "ship_console", "More than one loading condition have been selected (the" " extra loading conditions will be ignored)", None, QtGui.QApplication.UnicodeUTF8, ) App.Console.PrintWarning(msg + "\n") break self.lc = obj self.ship = ship if not self.lc: msg = QtGui.QApplication.translate( "ship_console", "A loading condition instance must be selected before using" " this tool (no valid loading condition found at the selected" " objects)", None, QtGui.QApplication.UnicodeUTF8, ) App.Console.PrintError(msg + "\n") return True # We have a valid loading condition, let's set the initial field values angle_format = USys.getAngleFormat() 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") form.angle.setText(Locale.toString(angle_format.format(90.0))) # Try to use saved values props = self.ship.PropertiesList try: props.index("GZAngle") form.angle.setText( Locale.toString(angle_format.format(self.ship.GZAngle.getValueAs(USys.getAngleUnits()).Value)) ) except: pass try: props.index("GZNumPoints") form.n_points.setValue(self.ship.GZNumPoints) except ValueError: pass try: props.index("GZVariableTrim") if self.ship.GZVariableTrim: form.var_trim.setCheckState(QtCore.Qt.Checked) else: form.var_trim.setCheckState(QtCore.Qt.Unchecked) except ValueError: pass return False
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
def initValues(self): """ Set initial values for fields """ # Look for selected loading conditions (Spreadsheets) self.lc = None selObjs = Gui.Selection.getSelection() if not selObjs: msg = QtGui.QApplication.translate( "ship_console", "A loading condition instance must be selected before using" " this tool (no objects selected)", None) App.Console.PrintError(msg + '\n') return True for i in range(len(selObjs)): obj = selObjs[i] try: if obj.TypeId != 'Spreadsheet::Sheet': continue except ValueError: continue # Check if it is a Loading condition: # B1 cell must be a ship # B2 cell must be the loading condition itself doc = App.ActiveDocument try: if obj not in doc.getObjectsByLabel(obj.get('B2')): continue ships = doc.getObjectsByLabel(obj.get('B1')) if len(ships) != 1: if len(ships) == 0: msg = QtGui.QApplication.translate( "ship_console", "Wrong Ship label! (no instances labeled as" "'{}' found)", None) App.Console.PrintError(msg + '\n'.format(obj.get('B1'))) else: msg = QtGui.QApplication.translate( "ship_console", "Ambiguous Ship label! ({} instances labeled as" "'{}' found)", None) App.Console.PrintError( msg + '\n'.format(len(ships), obj.get('B1'))) continue ship = ships[0] if ship is None or not ship.PropertiesList.index("IsShip"): continue except ValueError: continue # Let's see if several loading conditions have been selected (and # prompt a warning) if self.lc: msg = QtGui.QApplication.translate( "ship_console", "More than one loading condition have been selected (the" " extra loading conditions will be ignored)", None) App.Console.PrintWarning(msg + '\n') break self.lc = obj self.ship = ship if not self.lc: msg = QtGui.QApplication.translate( "ship_console", "A loading condition instance must be selected before using" " this tool (no valid loading condition found at the selected" " objects)", None) App.Console.PrintError(msg + '\n') return True # We have a valid loading condition, let's set the initial field values angle_format = USys.getAngleFormat() 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") form.angle.setText(Locale.toString(angle_format.format(90.0))) # Try to use saved values props = self.ship.PropertiesList try: props.index("GZAngle") form.angle.setText( Locale.toString( angle_format.format( self.ship.GZAngle.getValueAs( USys.getAngleUnits()).Value))) except: pass try: props.index("GZNumPoints") form.n_points.setValue(self.ship.GZNumPoints) except ValueError: pass try: props.index("GZVariableTrim") if self.ship.GZVariableTrim: form.var_trim.setCheckState(QtCore.Qt.Checked) else: form.var_trim.setCheckState(QtCore.Qt.Unchecked) except ValueError: pass return False