Moved to InputField widget in ship creation
This commit is contained in:
parent
d7fafdb2b6
commit
978030a678
|
@ -59,6 +59,7 @@ SET(ShipUtils_SRCS
|
|||
shipUtils/__init__.py
|
||||
shipUtils/Math.py
|
||||
shipUtils/Paths.py
|
||||
shipUtils/Units.py
|
||||
)
|
||||
SOURCE_GROUP("shiputils" FILES ${ShipUtils_SRCS})
|
||||
|
||||
|
|
|
@ -35,7 +35,8 @@ nobase_data_DATA = \
|
|||
shipHydrostatics/Tools.py \
|
||||
shipUtils/__init__.py \
|
||||
shipUtils/Math.py \
|
||||
shipUtils/Paths.py
|
||||
shipUtils/Paths.py \
|
||||
shipUtils/Units.py
|
||||
|
||||
CLEANFILES = $(BUILT_SOURCES)
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ from PySide import QtGui, QtCore
|
|||
import Preview
|
||||
import Instance
|
||||
from shipUtils import Paths
|
||||
|
||||
import shipUtils.Units as USys
|
||||
|
||||
class TaskPanel:
|
||||
def __init__(self):
|
||||
|
@ -44,12 +44,13 @@ class TaskPanel:
|
|||
Instance.ViewProviderShip(obj.ViewObject)
|
||||
mw = self.getMainWindow()
|
||||
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||
form.length = self.widget(QtGui.QDoubleSpinBox, "Length")
|
||||
form.breadth = self.widget(QtGui.QDoubleSpinBox, "Breadth")
|
||||
form.draft = self.widget(QtGui.QDoubleSpinBox, "Draft")
|
||||
obj.Length = '{} m'.format(form.length.value())
|
||||
obj.Breadth = '{} m'.format(form.breadth.value())
|
||||
obj.Draft = '{} m'.format(form.draft.value())
|
||||
form.length = self.widget(QtGui.QLineEdit, "Length")
|
||||
form.breadth = self.widget(QtGui.QLineEdit, "Breadth")
|
||||
form.draft = self.widget(QtGui.QLineEdit, "Draft")
|
||||
|
||||
obj.Length = form.length.text()
|
||||
obj.Breadth = form.breadth.text()
|
||||
obj.Draft = form.draft.text()
|
||||
App.ActiveDocument.recompute()
|
||||
return True
|
||||
|
||||
|
@ -83,9 +84,9 @@ class TaskPanel:
|
|||
"""Create and configurate the user interface"""
|
||||
mw = self.getMainWindow()
|
||||
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||
form.length = self.widget(QtGui.QDoubleSpinBox, "Length")
|
||||
form.breadth = self.widget(QtGui.QDoubleSpinBox, "Breadth")
|
||||
form.draft = self.widget(QtGui.QDoubleSpinBox, "Draft")
|
||||
form.length = self.widget(QtGui.QLineEdit, "Length")
|
||||
form.breadth = self.widget(QtGui.QLineEdit, "Breadth")
|
||||
form.draft = self.widget(QtGui.QLineEdit, "Draft")
|
||||
form.mainLogo = self.widget(QtGui.QLabel, "MainLogo")
|
||||
form.mainLogo.setPixmap(QtGui.QPixmap(":/icons/Ship_Logo.svg"))
|
||||
self.form = form
|
||||
|
@ -167,7 +168,7 @@ class TaskPanel:
|
|||
return True
|
||||
# Get the ship bounds. The ship instance can not have dimensions
|
||||
# out of these values.
|
||||
bounds = [0.0, 0.0, 0.0]
|
||||
self.bounds = [0.0, 0.0, 0.0]
|
||||
bbox = self.solids[0].BoundBox
|
||||
minX = bbox.XMin
|
||||
maxX = bbox.XMax
|
||||
|
@ -189,28 +190,30 @@ class TaskPanel:
|
|||
minZ = bbox.ZMin
|
||||
if maxZ < bbox.ZMax:
|
||||
maxZ = bbox.ZMax
|
||||
bounds[0] = maxX - minX
|
||||
bounds[1] = max(maxY - minY, abs(maxY), abs(minY))
|
||||
bounds[2] = maxZ - minZ
|
||||
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.QDoubleSpinBox, "Length")
|
||||
form.breadth = self.widget(QtGui.QDoubleSpinBox, "Breadth")
|
||||
form.draft = self.widget(QtGui.QDoubleSpinBox, "Draft")
|
||||
form.length = self.widget(QtGui.QLineEdit, "Length")
|
||||
form.breadth = self.widget(QtGui.QLineEdit, "Breadth")
|
||||
form.draft = self.widget(QtGui.QLineEdit, "Draft")
|
||||
|
||||
form.length.setMaximum(bounds[0] / Units.Metre.Value)
|
||||
form.length.setMinimum(0.001)
|
||||
form.length.setValue(bounds[0] / Units.Metre.Value)
|
||||
self.L = bounds[0] / Units.Metre.Value
|
||||
form.breadth.setMaximum(bounds[1] / Units.Metre.Value)
|
||||
form.breadth.setMinimum(0.001)
|
||||
form.breadth.setValue(bounds[1] / Units.Metre.Value)
|
||||
self.B = bounds[1] / Units.Metre.Value
|
||||
form.draft.setMaximum(bounds[2] / Units.Metre.Value)
|
||||
form.draft.setMinimum(0.001)
|
||||
form.draft.setValue(0.5 * bounds[2] / Units.Metre.Value)
|
||||
self.T = 0.5 * bounds[2] / Units.Metre.Value
|
||||
qty = Units.Quantity(self.bounds[0], Units.Length)
|
||||
form.length.setText(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(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(input_format.format(
|
||||
0.5 * qty.getValueAs(USys.getLengthUnits()).Value))
|
||||
self.T = 0.5 * self.bounds[2] / Units.Metre.Value
|
||||
return False
|
||||
|
||||
def retranslateUi(self):
|
||||
|
@ -239,6 +242,16 @@ class TaskPanel:
|
|||
None,
|
||||
QtGui.QApplication.UnicodeUTF8))
|
||||
|
||||
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(input_format.format(
|
||||
qty.getValueAs(USys.getLengthUnits()).Value))
|
||||
return val
|
||||
|
||||
def onData(self, value):
|
||||
"""Updates the 3D preview on data changes.
|
||||
|
||||
|
@ -248,13 +261,25 @@ class TaskPanel:
|
|||
"""
|
||||
mw = self.getMainWindow()
|
||||
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||
form.length = self.widget(QtGui.QDoubleSpinBox, "Length")
|
||||
form.breadth = self.widget(QtGui.QDoubleSpinBox, "Breadth")
|
||||
form.draft = self.widget(QtGui.QDoubleSpinBox, "Draft")
|
||||
form.length = self.widget(QtGui.QLineEdit, "Length")
|
||||
form.breadth = self.widget(QtGui.QLineEdit, "Breadth")
|
||||
form.draft = self.widget(QtGui.QLineEdit, "Draft")
|
||||
|
||||
self.L = form.length.value()
|
||||
self.B = form.breadth.value()
|
||||
self.T = form.draft.value()
|
||||
qty = Units.Quantity(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(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(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)
|
||||
|
||||
def getSolids(self, obj):
|
||||
|
|
|
@ -102,26 +102,13 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="Length">
|
||||
<property name="decimals">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.010000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="LengthUnits">
|
||||
<widget class="Gui::InputField" name="Length">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>m</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -148,26 +135,13 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="Breadth">
|
||||
<property name="decimals">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.010000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="BreadthUnits">
|
||||
<widget class="Gui::InputField" name="Breadth">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>m</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -194,26 +168,13 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="Draft">
|
||||
<property name="decimals">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.010000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="DraftUnits">
|
||||
<widget class="Gui::InputField" name="Draft">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>m</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -227,6 +188,13 @@
|
|||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>Gui::InputField</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header location="global">Gui/Inputfield.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
42
src/Mod/Ship/shipUtils/Units.py
Normal file
42
src/Mod/Ship/shipUtils/Units.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2011, 2012 *
|
||||
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
import FreeCAD
|
||||
import Units
|
||||
|
||||
|
||||
# Systems of length units
|
||||
LENGTH_UNITS = ('mm', 'm', 'in', 'in')
|
||||
|
||||
|
||||
def getLengthUnits():
|
||||
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units")
|
||||
units_id = param.GetInt('UserSchema', 0)
|
||||
return LENGTH_UNITS[units_id]
|
||||
|
||||
|
||||
def getLengthFormat():
|
||||
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units")
|
||||
decimals = param.GetInt("Decimals", 2)
|
||||
units_id = param.GetInt('UserSchema', 0)
|
||||
return '{0:.' + str(decimals) + 'f} ' + LENGTH_UNITS[units_id]
|
|
@ -92,6 +92,7 @@
|
|||
<File Id="shipUtils01" Name="__init__.py" />
|
||||
<File Id="shipUtils02" Name="Math.py" />
|
||||
<File Id="shipUtils03" Name="Paths.py" />
|
||||
<File Id="shipUtils04" Name="Units.py" />
|
||||
</Component>
|
||||
</Directory>
|
||||
</Directory>
|
||||
|
|
Loading…
Reference in New Issue
Block a user