diff --git a/src/Mod/Ship/CMakeLists.txt b/src/Mod/Ship/CMakeLists.txt index efbc08b58..c44c5e7e9 100644 --- a/src/Mod/Ship/CMakeLists.txt +++ b/src/Mod/Ship/CMakeLists.txt @@ -29,6 +29,7 @@ SET(ShipCreateShip_SRCS shipCreateShip/Preview.py shipCreateShip/TaskPanel.py shipCreateShip/TaskPanel.ui + shipCreateShip/Tools.ui ) SOURCE_GROUP("shipcreateship" FILES ${ShipCreateShip_SRCS}) diff --git a/src/Mod/Ship/Ship.py b/src/Mod/Ship/Ship.py new file mode 100644 index 000000000..1dbb91a1a --- /dev/null +++ b/src/Mod/Ship/Ship.py @@ -0,0 +1,32 @@ +#*************************************************************************** +#* * +#* Copyright (c) 2015 * +#* Jose Luis Cercos Pita * +#* * +#* 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 * +#* * +#*************************************************************************** + + +__title__="FreeCAD Ship module" +__author__ = "Jose Luis Cercos-Pita" +__url__ = "http://www.freecadweb.org" + +__doc__="The Ships module provide a set of tools to make some specific Naval" \ + " Architecture computations" + +from shipCreateShip.Tools import createShip \ No newline at end of file diff --git a/src/Mod/Ship/shipCreateShip/TaskPanel.py b/src/Mod/Ship/shipCreateShip/TaskPanel.py index f3084507a..38181f313 100644 --- a/src/Mod/Ship/shipCreateShip/TaskPanel.py +++ b/src/Mod/Ship/shipCreateShip/TaskPanel.py @@ -26,6 +26,7 @@ import FreeCADGui as Gui import Units from PySide import QtGui, QtCore import Preview +import Tools import Instance from shipUtils import Paths import shipUtils.Units as USys @@ -40,19 +41,16 @@ class TaskPanel: def accept(self): """Create the ship instance""" self.preview.clean() - obj = App.ActiveDocument.addObject("Part::FeaturePython", "Ship") - ship = Instance.Ship(obj, self.solids) - Instance.ViewProviderShip(obj.ViewObject) 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") - obj.Length = Locale.fromString(form.length.text()) - obj.Breadth = Locale.fromString(form.breadth.text()) - obj.Draft = Locale.fromString(form.draft.text()) - App.ActiveDocument.recompute() + Tools.createShip(self.solids, + Locale.fromString(form.length.text()), + Locale.fromString(form.breadth.text()), + Locale.fromString(form.draft.text())) return True def reject(self): diff --git a/src/Mod/Ship/shipCreateShip/Tools.py b/src/Mod/Ship/shipCreateShip/Tools.py new file mode 100644 index 000000000..eb610fbac --- /dev/null +++ b/src/Mod/Ship/shipCreateShip/Tools.py @@ -0,0 +1,65 @@ +#*************************************************************************** +#* * +#* Copyright (c) 2011, 2012 * +#* Jose Luis Cercos Pita * +#* * +#* 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 as App +import Instance + + +def createShip(solids, L, B, T): + """Create a new ship instance + + Position arguments: + solids -- List of hull solid shapes + L -- Ship length between perpendiculars + B -- Ship Breadth + T -- Ship design draft + + Returned value: + The new ship object + + The solids can be easily extracted from an already existing object. For + instance, to get the solids from the selected object simply type the + following command: + + solids = Gui.ActiveDocument.ActiveObject.Object.Shape.Solids + + Regarding the Lenght, Breadth, and Draft, it is strongly recommended to use + Units.parseQuantity method, e.g. The following obfuscated code snippet build + such variables: + + import Units + L = Units.parseQuantity("25.5 m") + B = Units.parseQuantity("3.9 m") + T = Units.parseQuantity("1.0 m") + """ + obj = App.ActiveDocument.addObject("Part::FeaturePython", "Ship") + ship = Instance.Ship(obj, solids) + Instance.ViewProviderShip(obj.ViewObject) + + obj.Length = L + obj.Breadth = B + obj.Draft = T + + App.ActiveDocument.recompute() + return obj \ No newline at end of file