Merge branch 'freecad-ship' of ssh://free-cad.git.sourceforge.net/gitroot/free-cad/free-cad into freecad-ship

This commit is contained in:
Jose Luis Cercós Pita 2012-01-30 14:25:21 +01:00
commit 822beda220
15 changed files with 2538 additions and 15 deletions

View File

@ -21,6 +21,9 @@ SET(ShipIcons_SRCS
Icons/Ico.png
Icons/Ico.xcf
Icons/Ico.xpm
Icons/LoadIco.png
Icons/LoadIco.xcf
Icons/LoadIco.xpm
Icons/OutlineDrawIco.png
Icons/OutlineDrawIco.xcf
Icons/OutlineDrawIco.xpm
@ -32,6 +35,19 @@ SET(ShipIcons_SRCS
)
SOURCE_GROUP("shipicons" FILES ${ShipIcons_SRCS})
SET(ShipExamples_SRCS
Examples/s60.fcstd
Examples/barehull5415.fcstd
)
SOURCE_GROUP("shipexamples" FILES ${ShipExamples_SRCS})
SET(ShipLoadExample_SRCS
shipLoadExample/__init__.py
shipLoadExample/TaskPanel.py
shipLoadExample/TaskPanel.ui
)
SOURCE_GROUP("shiploadexample" FILES ${ShipLoadExample_SRCS})
SET(ShipCreateShip_SRCS
shipCreateShip/__init__.py
shipCreateShip/Preview.py
@ -51,6 +67,7 @@ SOURCE_GROUP("shipoutlinedraw" FILES ${ShipOutlineDraw_SRCS})
SET(ShipAreasCurve_SRCS
shipAreasCurve/__init__.py
shipAreasCurve/Plot.py
shipAreasCurve/Preview.py
shipAreasCurve/TaskPanel.py
shipAreasCurve/TaskPanel.ui
@ -71,7 +88,7 @@ SET(ShipUtils_SRCS
)
SOURCE_GROUP("shiputils" FILES ${ShipUtils_SRCS})
SET(all_files ${ShipMain_SRCS} ${ShipIcons_SRCS} ${ShipCreateShip_SRCS} ${ShipOutlineDraw_SRCS} ${ShipAreasCurve_SRCS} ${ShipHydrostatics_SRCS} ${ShipUtils_SRCS})
SET(all_files ${ShipMain_SRCS} ${ShipIcons_SRCS} ${ShipExamples_SRCS} ${ShipLoadExample_SRCS} ${ShipCreateShip_SRCS} ${ShipOutlineDraw_SRCS} ${ShipAreasCurve_SRCS} ${ShipHydrostatics_SRCS} ${ShipUtils_SRCS})
ADD_CUSTOM_TARGET(Ship ALL
SOURCES ${all_files}
@ -85,6 +102,18 @@ INSTALL(
DESTINATION
Mod/Ship/Icons
)
INSTALL(
FILES
${ShipExamples_SRCS}
DESTINATION
Mod/Ship/Examples
)
INSTALL(
FILES
${ShipLoadExample_SRCS}
DESTINATION
Mod/Ship/shipLoadExample
)
INSTALL(
FILES
${ShipCreateShip_SRCS}

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -32,11 +32,11 @@ class ShipWorkbench ( Workbench ):
def Initialize(self):
# ToolBar
list = ["Ship_CreateShip", "Ship_OutlineDraw", "Ship_AreasCurve"]
list = ["Ship_LoadExample", "Ship_CreateShip", "Ship_OutlineDraw", "Ship_AreasCurve"]
self.appendToolbar("Ship design",list)
# Menu
list = ["Ship_CreateShip", "Ship_OutlineDraw", "Ship_AreasCurve"]
list = ["Ship_LoadExample", "Ship_CreateShip", "Ship_OutlineDraw", "Ship_AreasCurve"]
self.appendMenu("Ship design",list)
Gui.addWorkbench(ShipWorkbench())

View File

@ -22,6 +22,9 @@ nobase_data_DATA = \
Icons/Ico.png \
Icons/Ico.xcf \
Icons/Ico.xpm \
Icons/LoadIco.png \
Icons/LoadIco.xcf \
Icons/LoadIco.xpm \
Icons/OutlineDrawIco.png \
Icons/OutlineDrawIco.xcf \
Icons/OutlineDrawIco.xpm \
@ -30,6 +33,11 @@ nobase_data_DATA = \
Icons/ReparametrizeIco.xpm \
Icons/Ship.xcf \
Icons/Ship.xpm \
Examples/s60.fcstd \
Examples/barehull5415.fcstd \
shipLoadExample/__init__.py \
shipLoadExample/TaskPanel.py \
shipLoadExample/TaskPanel.ui \
shipCreateShip/__init__.py \
shipCreateShip/Preview.py \
shipCreateShip/TaskPanel.py \
@ -40,6 +48,7 @@ nobase_data_DATA = \
shipOutlineDraw/TaskPanel.py \
shipOutlineDraw/TaskPanel.ui \
shipAreasCurve/__init__.py \
shipAreasCurve/Plot.py \
shipAreasCurve/Preview.py \
shipAreasCurve/TaskPanel.py \
shipAreasCurve/TaskPanel.ui \

View File

@ -24,6 +24,18 @@
from PyQt4 import QtCore, QtGui
import FreeCAD, FreeCADGui, os
class LoadExample:
def Activated(self):
import shipLoadExample
shipLoadExample.load()
def GetResources(self):
from shipUtils import Paths, Translator
IconPath = Paths.iconsPath() + "/LoadIco.png"
MenuText = str(Translator.translate('Load an example ship geometry'))
ToolTip = str(Translator.translate('Load an example ship geometry able to be converted into a ship.'))
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
class CreateShip:
def Activated(self):
import shipCreateShip
@ -60,6 +72,7 @@ class AreasCurve:
ToolTip = str(Translator.translate('Plot transversal areas curve'))
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())

View File

@ -0,0 +1,211 @@
#***************************************************************************
#* *
#* 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 os
# FreeCAD modules
import FreeCAD,FreeCADGui
from FreeCAD import Part, Base
from FreeCAD import Image, ImageGui
# FreeCADShip modules
from shipUtils import Paths, Translator
header = """ #################################################################
##### #### ### #### ##### # # ### ####
# # # # # # # # # # # #
# ## #### #### # # # # # # # # # # #
#### # # # # # # # ##### # # ## ## ##### # ####
# # #### #### # # # # # # # # # #
# # # # # # # # # # # # # #
# # #### #### ### # # #### ##### # # ### #
#################################################################
"""
class Plot(object):
def __init__(self, x, y, disp, xcb, ship):
""" Constructor. performs plot and show it (Using pyxplot).
@param x X coordinates.
@param y Transversal areas.
@param disp Ship displacement.
@param xcb Bouyancy center length.
@param ship Active ship instance.
"""
if self.createDirectory():
return
if self.saveData(x,y,ship):
return
if self.saveLayout(x,y,disp,xcb,ship):
return
if self.execute():
return
ImageGui.open(self.path + 'areas.png')
def createDirectory(self):
""" Create needed folder to write data and scripts.
@return True if error happens.
"""
self.path = FreeCAD.ConfigGet("UserAppData") + "ShipOutput/"
if not os.path.exists(self.path):
os.makedirs(self.path)
if not os.path.exists(self.path):
msg = Translator.translate("Can't create '" + self.path + "' folder.\n")
FreeCAD.Console.PrintError(msg)
return False
def saveData(self,x,y,ship):
""" Write data file.
@param x X coordinates.
@param y Transversal areas.
@param ship Active ship instance.
@return True if error happens.
"""
# Open the file
filename = self.path + 'areas.dat'
try:
Output = open(filename, "w")
except IOError:
msg = Translator.translate("Can't write '" + filename + "' file.\n")
FreeCAD.Console.PrintError(msg)
return True
# Print header
Output.write(header)
Output.write(" #\n")
Output.write(" # File automatically exported by FreeCAD-Ship\n")
Output.write(" # This file contains transversal areas data, filled with following columns:\n")
Output.write(" # 1: X coordiante [m]\n")
Output.write(" # 2: Transversal area [m2]\n")
Output.write(" # 3: X FP coordinate [m]\n")
Output.write(" # 4: Y FP coordinate (bounds in order to draw it)\n")
Output.write(" # 3: X AP coordinate [m]\n")
Output.write(" # 4: Y AP coordinate (bounds in order to draw it)\n")
Output.write(" #\n")
Output.write(" #################################################################\n")
# Get perpendiculars data
Lpp = ship.Length
FPx = 0.5*Lpp
APx = -0.5*Lpp
maxArea = max(y)
# Print data
if len(x) < 2:
msg = Translator.translate("Not enough data to plot.\n")
FreeCAD.Console.PrintError(msg)
string = "%f %f %f %f %f %f\n" % (x[0], y[0], FPx, 0.0, APx, 0.0)
Output.write(string)
for i in range(1, len(x)):
string = "%f %f %f %f %f %f\n" % (x[i], y[i], FPx, maxArea, APx, maxArea)
Output.write(string)
# Close file
Output.close()
self.dataFile = filename
msg = Translator.translate("Data saved at '" + self.dataFile + "'.\n")
FreeCAD.Console.PrintMessage(msg)
return False
def saveLayout(self, x, y, disp, xcb, ship):
""" Prints the data output.
@param x X coordinates.
@param y Transversal areas.
@param disp Ship displacement.
@param xcb Bouyancy center length.
@param ship Active ship instance.
@return True if error happens.
"""
filename = self.path + 'areas.pyxplot'
# Open the file
try:
Output = open(filename, "w")
except IOError:
msg = Translator.translate("Can't write '" + filename + "' file.\n")
FreeCAD.Console.PrintError(msg)
return True
# Write header
Output.write(header)
Output.write(" #\n")
Output.write(" # File automatically exported by FreeCAD-Ship\n")
Output.write(" # This file contains a script to plot transversal areas curve.\n")
Output.write(" # To use it execute:\n")
Output.write(" #\n")
Output.write(" # pyxplot %s\n" % (filename))
Output.write(" #\n")
Output.write(" #################################################################\n")
# Write general options for hydrostatics
Output.write("set numeric display latex\n")
Output.write("set output '%s'\n" % (self.path + 'areas.eps'))
Output.write("set nokey\n")
Output.write("set grid\n")
Output.write("# X axis\n")
Output.write("set xlabel 'x / $m$'\n")
Output.write("set xtic\n")
Output.write("# Y axis\n")
Output.write("set ylabel 'Area / $m^2$'\n")
Output.write("set ytic\n")
Output.write("# Line styles\n")
Output.write("set style 1 line linetype 1 linewidth 1 colour rgb (0):(0):(0)\n")
Output.write("set style 2 line linetype 1 linewidth 2 colour rgb (0):(0):(0)\n")
# Get perpendiculars data
Lpp = ship.Length
FPx = 0.5*Lpp
APx = -0.5*Lpp
maxArea = max(y)
# Perpendicular labels
Output.write("# Perpendiculars labels\n")
Output.write("set label (1) AP %f,%f\n" % (APx+0.01*Lpp, 0.01*maxArea))
Output.write("set label (2) AP %f,%f\n" % (APx+0.01*Lpp, 0.95*maxArea))
Output.write("set label (3) FP %f,%f\n" % (FPx+0.01*Lpp, 0.01*maxArea))
Output.write("set label (4) FP %f,%f\n" % (FPx+0.01*Lpp, 0.95*maxArea))
# Additional data
Output.write("# Additional data\n")
Output.write("set label (5) 'XCB = %g m' %f,%f\n" % (xcb, -0.25*Lpp, 0.25*maxArea))
Output.write("set label (6) 'Maximum area = %g m2' %f,%f\n" % (maxArea, -0.25*Lpp, 0.15*maxArea))
Output.write("set label (7) 'Displacement = %g tons' %f,%f\n" % (disp, -0.25*Lpp, 0.05*maxArea))
# Write plot call
Output.write("# Plot\n")
Output.write("plot '%s' using 1:2 title 'Transversal areas' axes x1y1 with lines style 1, \\\n" % (self.dataFile))
Output.write(" '%s' using 3:4 title 'FP' axes x1y1 with lines style 2, \\\n" % (self.dataFile))
Output.write(" '%s' using 5:6 title 'AP' axes x1y1 with lines style 2\n" % (self.dataFile))
# Close file
self.layoutFile = filename
Output.close()
return False
def execute(self):
""" Calls pyxplot in order to plot an save an image.
@return True if error happens.
"""
filename = self.path + 'areas'
comm = "pyxplot %s" % (self.layoutFile)
if os.system(comm):
msg = Translator.translate("Can't execute pyxplot. Maybe is not installed?\n")
FreeCAD.Console.PrintError(msg)
msg = Translator.translate("Plot will not generated\n")
FreeCAD.Console.PrintError(msg)
return True
comm = "gs -r300 -dEPSCrop -dTextAlphaBits=4 -sDEVICE=png16m -sOutputFile=%s.png -dBATCH -dNOPAUSE %s.eps" % (filename,filename)
if os.system(comm):
msg = Translator.translate("Can't execute ghostscript. Maybe is not installed?\n")
FreeCAD.Console.PrintError(msg)
msg = Translator.translate("Generated image will not converted to png\n")
FreeCAD.Console.PrintError(msg)
return True
return False

View File

@ -28,7 +28,7 @@ import FreeCADGui as Gui
# Qt library
from PyQt4 import QtGui,QtCore
# Module
import Preview
import Preview, Plot
import Instance
from shipUtils import Paths, Translator
from surfUtils import Geometry
@ -44,6 +44,13 @@ class TaskPanel:
if not self.ship:
return False
self.save()
# Plot data
data = Hydrostatics.Displacement(self.ship,self.form.draft.value(),self.form.trim.value())
x = self.ship.xSection[:]
y = data[0]
disp = data[1]
xcb = data[2]
Plot.Plot(x,y,disp,xcb, self.ship)
self.preview.clean()
return True

View File

@ -119,7 +119,9 @@ class TaskPanel:
self.faces = None
selObjs = Geometry.getSelectedObjs()
if not selObjs:
msg = Translator.translate("All ship surfaces must be selected (Any object has been selected)\n")
msg = Translator.translate("Ship objects can only be created on top of hull geometry (any object selected).\n")
App.Console.PrintError(msg)
msg = Translator.translate("Please create or download a ship hull geometry before using this tool\n")
App.Console.PrintError(msg)
return True
self.faces = []
@ -128,23 +130,37 @@ class TaskPanel:
for j in range(0, len(faces)):
self.faces.append(faces[j])
if not self.faces:
msg = Translator.translate("All ship surfaces must be selected (Any face found into selected objects)\n")
msg = Translator.translate("Ship objects can only be created on top of hull geometry (any face object selected).\n")
App.Console.PrintError(msg)
msg = Translator.translate("Please create or download a ship hull geometry before using this tool\n")
App.Console.PrintError(msg)
return True
# Get bounds
bounds = [0.0, 0.0, 0.0]
bbox = self.faces[0].BoundBox
bounds[0] = bbox.XLength
bounds[1] = bbox.YLength
bounds[2] = bbox.ZLength
minX = bbox.XMin
maxX = bbox.XMax
minY = bbox.YMin
maxY = bbox.YMax
minZ = bbox.ZMin
maxZ = bbox.ZMax
for i in range(1,len(self.faces)):
bbox = self.faces[i].BoundBox
if bounds[0] < bbox.XLength:
bounds[0] = bbox.XLength
if bounds[1] < bbox.YLength:
bounds[1] = bbox.YLength
if bounds[2] < bbox.ZLength:
bounds[2] = bbox.ZLength
if minX > bbox.XMin:
minX = bbox.XMin
if maxX < bbox.XMax:
maxX = bbox.XMax
if minY > bbox.YMin:
minY = bbox.YMin
if maxY < bbox.YMax:
maxY = bbox.YMax
if minZ > bbox.ZMin:
minZ = bbox.ZMin
if maxZ < bbox.ZMax:
maxZ = bbox.ZMax
bounds[0] = maxX - minX
bounds[1] = maxY - minY
bounds[2] = maxZ - minZ
# Set UI fields
self.form.length.setMaximum(bounds[0])
self.form.length.setValue(bounds[0])

View File

@ -0,0 +1,102 @@
#***************************************************************************
#* *
#* 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 shipUtils import Paths, Translator
from surfUtils import Geometry
class TaskPanel:
def __init__(self):
self.ui = Paths.modulePath() + "/shipLoadExample/TaskPanel.ui"
def accept(self):
path = Paths.modulePath() + "/Examples/"
if(self.form.ship.currentIndex() == 0): # s60 from Iowa University
App.open(path + "s60.fcstd")
elif(self.form.ship.currentIndex() == 1): # Barehull 5415
App.open(path + "barehull5415.fcstd")
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.ship = form.findChild(QtGui.QComboBox, "Ship")
form.mainLogo = form.findChild(QtGui.QLabel, "MainLogo")
iconPath = Paths.iconsPath() + "/Ico.xpm"
form.mainLogo.setPixmap(QtGui.QPixmap(iconPath))
self.form = form
self.retranslateUi()
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 retranslateUi(self):
""" Set user interface locale strings.
"""
self.form.setWindowTitle(Translator.translate("Load example ship"))
self.form.findChild(QtGui.QGroupBox, "ShipSelectionBox").setTitle(Translator.translate("Select ship example geometry"))
def createTask():
panel = TaskPanel()
Gui.Control.showDialog(panel)
if panel.setupUi():
Gui.Control.closeDialog(panel)
return None
return panel

View File

@ -0,0 +1,115 @@
<?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>397</height>
</rect>
</property>
<property name="windowTitle">
<string>Load example ship</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="MainLogo">
<property name="minimumSize">
<size>
<width>128</width>
<height>128</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>128</width>
<height>128</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap>../Icons/Ico.xpm</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="ShipSelectionBox">
<property name="minimumSize">
<size>
<width>240</width>
<height>80</height>
</size>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="title">
<string>Select ship example geometry</string>
</property>
<widget class="QWidget" name="verticalLayoutWidget_3">
<property name="geometry">
<rect>
<x>0</x>
<y>20</y>
<width>241</width>
<height>101</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QComboBox" name="Ship">
<item>
<property name="text">
<string>Serie 60 from Iowa University</string>
</property>
</item>
<item>
<property name="text">
<string>Barehull 5145</string>
</property>
</item>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</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()