Added a console interface to create the ship instance

This commit is contained in:
Jose Luis Cercos Pita 2016-01-21 18:46:08 +01:00
parent 9770cca561
commit 495308905c
4 changed files with 103 additions and 7 deletions

View File

@ -29,6 +29,7 @@ SET(ShipCreateShip_SRCS
shipCreateShip/Preview.py shipCreateShip/Preview.py
shipCreateShip/TaskPanel.py shipCreateShip/TaskPanel.py
shipCreateShip/TaskPanel.ui shipCreateShip/TaskPanel.ui
shipCreateShip/Tools.ui
) )
SOURCE_GROUP("shipcreateship" FILES ${ShipCreateShip_SRCS}) SOURCE_GROUP("shipcreateship" FILES ${ShipCreateShip_SRCS})

32
src/Mod/Ship/Ship.py Normal file
View File

@ -0,0 +1,32 @@
#***************************************************************************
#* *
#* Copyright (c) 2015 *
#* 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 *
#* *
#***************************************************************************
__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

View File

@ -26,6 +26,7 @@ import FreeCADGui as Gui
import Units import Units
from PySide import QtGui, QtCore from PySide import QtGui, QtCore
import Preview import Preview
import Tools
import Instance import Instance
from shipUtils import Paths from shipUtils import Paths
import shipUtils.Units as USys import shipUtils.Units as USys
@ -40,19 +41,16 @@ class TaskPanel:
def accept(self): def accept(self):
"""Create the ship instance""" """Create the ship instance"""
self.preview.clean() self.preview.clean()
obj = App.ActiveDocument.addObject("Part::FeaturePython", "Ship")
ship = Instance.Ship(obj, self.solids)
Instance.ViewProviderShip(obj.ViewObject)
mw = self.getMainWindow() mw = self.getMainWindow()
form = mw.findChild(QtGui.QWidget, "TaskPanel") form = mw.findChild(QtGui.QWidget, "TaskPanel")
form.length = self.widget(QtGui.QLineEdit, "Length") form.length = self.widget(QtGui.QLineEdit, "Length")
form.breadth = self.widget(QtGui.QLineEdit, "Breadth") form.breadth = self.widget(QtGui.QLineEdit, "Breadth")
form.draft = self.widget(QtGui.QLineEdit, "Draft") form.draft = self.widget(QtGui.QLineEdit, "Draft")
obj.Length = Locale.fromString(form.length.text()) Tools.createShip(self.solids,
obj.Breadth = Locale.fromString(form.breadth.text()) Locale.fromString(form.length.text()),
obj.Draft = Locale.fromString(form.draft.text()) Locale.fromString(form.breadth.text()),
App.ActiveDocument.recompute() Locale.fromString(form.draft.text()))
return True return True
def reject(self): def reject(self):

View File

@ -0,0 +1,65 @@
#***************************************************************************
#* *
#* 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 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