Added tank creator.

This commit is contained in:
Jose Luis Cercós pita 2012-05-01 17:13:44 +02:00
parent 2a846428fe
commit 87e1dea1ac
12 changed files with 4013 additions and 5 deletions

View File

@ -2,6 +2,7 @@ SET(ShipMain_SRCS
InitGui.py
ShipGui.py
Instance.py
TankInstance.py
)
SOURCE_GROUP("" FILES ${ShipMain_SRCS})
@ -32,6 +33,9 @@ SET(ShipIcons_SRCS
Icons/ReparametrizeIco.xpm
Icons/Ship.xcf
Icons/Ship.xpm
Icons/Tank.png
Icons/Tank.xcf
Icons/Tank.xpm
)
SOURCE_GROUP("shipicons" FILES ${ShipIcons_SRCS})
@ -92,7 +96,14 @@ SET(ShipUtils_SRCS
)
SOURCE_GROUP("shiputils" FILES ${ShipUtils_SRCS})
SET(all_files ${ShipMain_SRCS} ${ShipIcons_SRCS} ${ShipExamples_SRCS} ${ShipLoadExample_SRCS} ${ShipCreateShip_SRCS} ${ShipOutlineDraw_SRCS} ${ShipAreasCurve_SRCS} ${ShipHydrostatics_SRCS} ${ShipUtils_SRCS})
SET(ShipCreateTank_SRCS
tankCreateTank/__init__.py
tankCreateTank/TaskPanel.py
tankCreateTank/TaskPanel.ui
)
SOURCE_GROUP("shipcreatetank" FILES ${ShipCreateTank_SRCS})
SET(all_files ${ShipMain_SRCS} ${ShipIcons_SRCS} ${ShipExamples_SRCS} ${ShipLoadExample_SRCS} ${ShipCreateShip_SRCS} ${ShipOutlineDraw_SRCS} ${ShipAreasCurve_SRCS} ${ShipHydrostatics_SRCS} ${ShipUtils_SRCS} ${ShipCreateTank_SRCS})
ADD_CUSTOM_TARGET(Ship ALL
SOURCES ${all_files}
@ -148,6 +159,12 @@ INSTALL(
DESTINATION
Mod/Ship/shipUtils
)
INSTALL(
FILES
${ShipCreateTank_SRCS}
DESTINATION
Mod/Ship/tankCreateTank
)
INSTALL(
FILES
${ShipMain_SRCS}
@ -155,3 +172,4 @@ INSTALL(
Mod/Ship
)

BIN
src/Mod/Ship/Icons/Tank.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

BIN
src/Mod/Ship/Icons/Tank.xcf Normal file

Binary file not shown.

1736
src/Mod/Ship/Icons/Tank.xpm Normal file

File diff suppressed because it is too large Load Diff

View File

@ -34,9 +34,13 @@ class ShipWorkbench ( Workbench ):
# ToolBar
list = ["Ship_LoadExample", "Ship_CreateShip", "Ship_OutlineDraw", "Ship_AreasCurve", "Ship_Hydrostatics"]
self.appendToolbar("Ship design",list)
list = ["Ship_CreateTank"]
self.appendToolbar("Loading",list)
# Menu
list = ["Ship_LoadExample", "Ship_CreateShip", "Ship_OutlineDraw", "Ship_AreasCurve", "Ship_Hydrostatics"]
self.appendMenu("Ship design",list)
list = ["Ship_CreateTank"]
self.appendToolbar("Loading",list)
Gui.addWorkbench(ShipWorkbench())

View File

@ -4,7 +4,8 @@ datadir = $(prefix)/Mod/Ship
data_DATA = \
InitGui.py \
ShipGui.py \
Instance.py
Instance.py \
TankInstance.py
nobase_data_DATA = \
Icons/AreaCurveIco.png \
@ -33,6 +34,9 @@ nobase_data_DATA = \
Icons/ReparametrizeIco.xpm \
Icons/Ship.xcf \
Icons/Ship.xpm \
Icons/Tank.png \
Icons/Tank.xcf \
Icons/Tank.xpm \
Examples/s60.fcstd \
Examples/barehull5415.fcstd \
Examples/s60_katamaran.fcstd \
@ -61,7 +65,10 @@ nobase_data_DATA = \
shipUtils/__init__.py \
shipUtils/Math.py \
shipUtils/Paths.py \
shipUtils/Translator.py
shipUtils/Translator.py \
tankCreateTank/__init__.py \
tankCreateTank/TaskPanel.py \
tankCreateTank/TaskPanel.ui
CLEANFILES = $(BUILT_SOURCES)

View File

@ -84,8 +84,21 @@ class Hydrostatics:
ToolTip = str(Translator.translate('Plot ship hydrostatics'))
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
class CreateTank:
def Activated(self):
import tankCreateTank
tankCreateTank.load()
def GetResources(self):
from shipUtils import Paths, Translator
IconPath = Paths.iconsPath() + "/Tank.png"
MenuText = str(Translator.translate('Create a new tank'))
ToolTip = str(Translator.translate('Create a new ship tank'))
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
FreeCADGui.addCommand('Ship_LoadExample', LoadExample())
FreeCADGui.addCommand('Ship_CreateShip', CreateShip())
FreeCADGui.addCommand('Ship_OutlineDraw', OutlineDraw())
FreeCADGui.addCommand('Ship_AreasCurve', AreasCurve())
FreeCADGui.addCommand('Ship_Hydrostatics', Hydrostatics())
FreeCADGui.addCommand('Ship_CreateTank', CreateTank())

1886
src/Mod/Ship/TankInstance.py Normal file

File diff suppressed because it is too large Load Diff

View File

@ -76,7 +76,7 @@
<widget class="QComboBox" name="Ship">
<item>
<property name="text">
<string>Serie 60 from Iowa University</string>
<string>Series 60 from Iowa University</string>
</property>
</item>
<item>
@ -86,7 +86,7 @@
</item>
<item>
<property name="text">
<string>Serie 60 (Katamaran)</string>
<string>Series 60 (Katamaran)</string>
</property>
</item>
</widget>

View File

@ -0,0 +1,167 @@
#***************************************************************************
#* *
#* 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 *
#* *
#***************************************************************************
# FreeCAD modules
import FreeCAD as App
import FreeCADGui as Gui
# Qt library
from PyQt4 import QtGui,QtCore
# Module
from TankInstance import *
from shipUtils import Paths, Translator
class TaskPanel:
def __init__(self):
self.ui = Paths.modulePath() + "/tankCreateTank/TaskPanel.ui"
def accept(self):
# Create new ship instance
obj = App.ActiveDocument.addObject("Part::FeaturePython","Tank")
ShipTank(obj, self.solid, self.form.level.value(), self.form.dens.value())
if not obj.IsShipTank:
msg = Translator.translate("Tank has not been created.\n")
App.Console.PrintError(msg)
ViewProviderShipTank(obj.ViewObject)
App.ActiveDocument.recompute()
return True
def reject(self):
return True
def clicked(self, index):
pass
def open(self):
pass
def needsFullSpace(self):
return True
def isAllowedAlterSelection(self):
return False
def isAllowedAlterView(self):
return True
def isAllowedAlterDocument(self):
return False
def helpRequested(self):
pass
def setupUi(self):
mw = self.getMainWindow()
form = mw.findChild(QtGui.QWidget, "TaskPanel")
form.level = form.findChild(QtGui.QDoubleSpinBox, "Level")
form.dens = form.findChild(QtGui.QDoubleSpinBox, "Density")
self.form = form
# Initial values
if self.initValues():
return True
self.retranslateUi()
# Connect Signals and Slots
QtCore.QObject.connect(form.level, QtCore.SIGNAL("valueChanged(double)"), self.onLevel)
QtCore.QObject.connect(form.dens , QtCore.SIGNAL("valueChanged(double)"), self.onDens)
def getMainWindow(self):
"returns the main window"
# using QtGui.qApp.activeWindow() isn't very reliable because if another
# widget than the mainwindow is active (e.g. a dialog) the wrong widget is
# returned
toplevel = QtGui.qApp.topLevelWidgets()
for i in toplevel:
if i.metaObject().className() == "Gui::MainWindow":
return i
raise Exception("No main window found")
def initValues(self):
""" Get selected geometry.
@return False if sucessfully find valid geometry.
"""
self.solid = None
solids = []
selObjs = Gui.Selection.getSelection()
if not selObjs:
msg = Translator.translate("Tank objects can only be created on top of structure geometry (no object selected).\n")
App.Console.PrintError(msg)
msg = Translator.translate("Please create a tank geometry before using this tool.\n")
App.Console.PrintError(msg)
return True
for i in range(0, len(selObjs)):
solid = selObjs[i]
if solid.isDerivedFrom('Part::Feature'):
# Get shape
shape = solid.Shape
if not shape:
continue
solid = shape
if not solid.isDerivedFrom('Part::TopoShape'):
return None
# Get shells
shells = solid.Shells
if not shells:
continue
# Build solids
for s in shells:
solids.append(Part.Solid(s))
if not solids:
msg = Translator.translate("Ship objects can only be created on top of structure geometry (no solids can't be computed).\n")
App.Console.PrintError(msg)
msg = Translator.translate("Please create or download a tank geometry before using this tool\n")
App.Console.PrintError(msg)
return True
self.solid = Part.CompSolid(solids)
msg = Translator.translate("Ready to work\n")
App.Console.PrintMessage(msg)
return False
def retranslateUi(self):
""" Set user interface locale strings.
"""
self.form.setWindowTitle(Translator.translate("Create a new tank"))
name = Translator.translate("Filling level") + " (\%)"
self.form.findChild(QtGui.QLabel, "LevelLabel").setText(name)
name = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">\n<html><body>'
name = name + Translator.translate("Density")
name = name + '(kg/m<span style=" vertical-align:super;">3</span>)</body></html>'
self.form.findChild(QtGui.QLabel, "DensityLabel").setText(name)
def onLevel(self, value):
""" Method called when tank filling level has been modified.
@param value Changed value.
"""
pass
def onDens(self, value):
""" Method called when fluid density has been modified.
@param value Changed value.
"""
pass
def createTask():
panel = TaskPanel()
Gui.Control.showDialog(panel)
if panel.setupUi():
Gui.Control.closeDialog(panel)
return None
return panel

View File

@ -0,0 +1,141 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TaskPanel</class>
<widget class="QWidget" name="TaskPanel">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>260</width>
<height>180</height>
</rect>
</property>
<property name="windowTitle">
<string>Create new ship tank</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="ShipDataBox">
<property name="minimumSize">
<size>
<width>240</width>
<height>160</height>
</size>
</property>
<property name="title">
<string>Fluid</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<widget class="QWidget" name="verticalLayoutWidget_2">
<property name="geometry">
<rect>
<x>0</x>
<y>20</y>
<width>241</width>
<height>141</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0">
<property name="spacing">
<number>6</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="leftMargin">
<number>10</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="LevelLabel">
<property name="text">
<string>Filling level (%)</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="Level">
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>100.000000000000000</double>
</property>
<property name="singleStep">
<double>1.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="leftMargin">
<number>10</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="DensityLabel">
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Density (kg/m&lt;span style=&quot; vertical-align:super;&quot;&gt;3&lt;/span&gt;)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="Density">
<property name="decimals">
<number>1</number>
</property>
<property name="maximum">
<double>1000000.000000000000000</double>
</property>
<property name="singleStep">
<double>10.000000000000000</double>
</property>
<property name="value">
<double>998.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,36 @@
#***************************************************************************
#* *
#* 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 *
#* *
#***************************************************************************
# FreeCAD modules
import FreeCAD
import FreeCADGui
# Qt libraries
from PyQt4 import QtGui,QtCore
# Main object
import TaskPanel
def load():
""" Loads the tool """
TaskPanel.createTask()