From 13fb0e2ccadc9b08749339e70773a1e5d588cad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Luis=20Cerc=C3=B3s=20pita?= Date: Sun, 29 Jan 2012 19:11:55 +0100 Subject: [PATCH] Added examples loader tool (without functionality yet) --- src/Mod/Ship/CMakeLists.txt | 15 ++- src/Mod/Ship/InitGui.py | 4 +- src/Mod/Ship/Makefile.am | 3 + src/Mod/Ship/ShipGui.py | 13 +++ src/Mod/Ship/shipLoadExample/TaskPanel.py | 97 ++++++++++++++++++ src/Mod/Ship/shipLoadExample/TaskPanel.ui | 115 ++++++++++++++++++++++ src/Mod/Ship/shipLoadExample/__init__.py | 36 +++++++ 7 files changed, 280 insertions(+), 3 deletions(-) create mode 100644 src/Mod/Ship/shipLoadExample/TaskPanel.py create mode 100644 src/Mod/Ship/shipLoadExample/TaskPanel.ui create mode 100644 src/Mod/Ship/shipLoadExample/__init__.py diff --git a/src/Mod/Ship/CMakeLists.txt b/src/Mod/Ship/CMakeLists.txt index 494ce8d0a..8768d92a1 100644 --- a/src/Mod/Ship/CMakeLists.txt +++ b/src/Mod/Ship/CMakeLists.txt @@ -35,6 +35,13 @@ SET(ShipIcons_SRCS ) SOURCE_GROUP("shipicons" FILES ${ShipIcons_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 @@ -75,7 +82,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} ${ShipLoadExample_SRCS} ${ShipCreateShip_SRCS} ${ShipOutlineDraw_SRCS} ${ShipAreasCurve_SRCS} ${ShipHydrostatics_SRCS} ${ShipUtils_SRCS}) ADD_CUSTOM_TARGET(Ship ALL SOURCES ${all_files} @@ -89,6 +96,12 @@ INSTALL( DESTINATION Mod/Ship/Icons ) +INSTALL( + FILES + ${ShipLoadExample_SRCS} + DESTINATION + Mod/Ship/shipLoadExample +) INSTALL( FILES ${ShipCreateShip_SRCS} diff --git a/src/Mod/Ship/InitGui.py b/src/Mod/Ship/InitGui.py index 01d08f55c..5d0a87efe 100644 --- a/src/Mod/Ship/InitGui.py +++ b/src/Mod/Ship/InitGui.py @@ -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()) diff --git a/src/Mod/Ship/Makefile.am b/src/Mod/Ship/Makefile.am index 85137539d..4d61e41f2 100644 --- a/src/Mod/Ship/Makefile.am +++ b/src/Mod/Ship/Makefile.am @@ -33,6 +33,9 @@ nobase_data_DATA = \ Icons/ReparametrizeIco.xpm \ Icons/Ship.xcf \ Icons/Ship.xpm \ + shipLoadExample/__init__.py \ + shipLoadExample/TaskPanel.py \ + shipLoadExample/TaskPanel.ui \ shipCreateShip/__init__.py \ shipCreateShip/Preview.py \ shipCreateShip/TaskPanel.py \ diff --git a/src/Mod/Ship/ShipGui.py b/src/Mod/Ship/ShipGui.py index 2059565bf..c59a43c71 100644 --- a/src/Mod/Ship/ShipGui.py +++ b/src/Mod/Ship/ShipGui.py @@ -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()) diff --git a/src/Mod/Ship/shipLoadExample/TaskPanel.py b/src/Mod/Ship/shipLoadExample/TaskPanel.py new file mode 100644 index 000000000..23f5f85b1 --- /dev/null +++ b/src/Mod/Ship/shipLoadExample/TaskPanel.py @@ -0,0 +1,97 @@ +#*************************************************************************** +#* * +#* 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 * +#* * +#*************************************************************************** + +# 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): + 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 diff --git a/src/Mod/Ship/shipLoadExample/TaskPanel.ui b/src/Mod/Ship/shipLoadExample/TaskPanel.ui new file mode 100644 index 000000000..b9f7aeffe --- /dev/null +++ b/src/Mod/Ship/shipLoadExample/TaskPanel.ui @@ -0,0 +1,115 @@ + + + TaskPanel + + + + 0 + 0 + 260 + 397 + + + + Load example ship + + + + + + + + + + + 128 + 128 + + + + + 128 + 128 + + + + + + + ../Icons/Ico.xpm + + + true + + + Qt::AlignHCenter|Qt::AlignTop + + + + + + + + + + 240 + 80 + + + + Qt::LeftToRight + + + Select ship example geometry + + + + + 0 + 20 + 241 + 101 + + + + + + + + Serie 60 from Iowa University + + + + + Barehull 5145 + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + + + + + + + diff --git a/src/Mod/Ship/shipLoadExample/__init__.py b/src/Mod/Ship/shipLoadExample/__init__.py new file mode 100644 index 000000000..cbfb57d75 --- /dev/null +++ b/src/Mod/Ship/shipLoadExample/__init__.py @@ -0,0 +1,36 @@ +#*************************************************************************** +#* * +#* 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 * +#* * +#*************************************************************************** + +# FreeCAD modules +import FreeCAD +import FreeCADGui + +# Qt libraries +from PyQt4 import QtGui,QtCore + +# Main object +import TaskPanel + +def load(): + """ Loads the tool """ + TaskPanel.createTask()