Changed (and accelerated) simulation creation process.
This commit is contained in:
parent
cc59edda71
commit
779f148b44
File diff suppressed because it is too large
Load Diff
|
@ -1,174 +1,177 @@
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
#* *
|
#* *
|
||||||
#* Copyright (c) 2011, 2012 *
|
#* Copyright (c) 2011, 2012 *
|
||||||
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
||||||
#* *
|
#* *
|
||||||
#* This program is free software; you can redistribute it and/or modify *
|
#* This program is free software; you can redistribute it and/or modify *
|
||||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||||
#* as published by the Free Software Foundation; either version 2 of *
|
#* as published by the Free Software Foundation; either version 2 of *
|
||||||
#* the License, or (at your option) any later version. *
|
#* the License, or (at your option) any later version. *
|
||||||
#* for detail see the LICENCE text file. *
|
#* for detail see the LICENCE text file. *
|
||||||
#* *
|
#* *
|
||||||
#* This program is distributed in the hope that it will be useful, *
|
#* This program is distributed in the hope that it will be useful, *
|
||||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||||
#* GNU Library General Public License for more details. *
|
#* GNU Library General Public License for more details. *
|
||||||
#* *
|
#* *
|
||||||
#* You should have received a copy of the GNU Library General Public *
|
#* You should have received a copy of the GNU Library General Public *
|
||||||
#* License along with this program; if not, write to the Free Software *
|
#* License along with this program; if not, write to the Free Software *
|
||||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||||
#* USA *
|
#* USA *
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
# FreeCAD modules
|
# FreeCAD modules
|
||||||
import FreeCAD as App
|
import FreeCAD as App
|
||||||
import FreeCADGui as Gui
|
import FreeCADGui as Gui
|
||||||
# Qt library
|
# Qt library
|
||||||
from PyQt4 import QtGui,QtCore
|
from PyQt4 import QtGui,QtCore
|
||||||
# Module
|
# Module
|
||||||
import SimInstance
|
import SimInstance
|
||||||
from shipUtils import Paths, Translator
|
from shipUtils import Paths, Translator
|
||||||
|
|
||||||
class TaskPanel:
|
class TaskPanel:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ui = Paths.modulePath() + "/simCreate/TaskPanel.ui"
|
self.ui = Paths.modulePath() + "/simCreate/TaskPanel.ui"
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
form = self.form
|
form = self.form
|
||||||
# Read waves data
|
# Read waves data
|
||||||
w = []
|
w = []
|
||||||
for i in range(0,form.waves.rowCount() - 1):
|
for i in range(0,form.waves.rowCount() - 1):
|
||||||
item = form.waves.item(i,0)
|
item = form.waves.item(i,0)
|
||||||
A = item.text().toFloat()[0]
|
A = item.text().toFloat()[0]
|
||||||
item = form.waves.item(i,1)
|
item = form.waves.item(i,1)
|
||||||
T = item.text().toFloat()[0]
|
T = item.text().toFloat()[0]
|
||||||
item = form.waves.item(i,2)
|
item = form.waves.item(i,2)
|
||||||
phi = item.text().toFloat()[0]
|
phi = item.text().toFloat()[0]
|
||||||
item = form.waves.item(i,3)
|
item = form.waves.item(i,3)
|
||||||
head = item.text().toFloat()[0]
|
head = item.text().toFloat()[0]
|
||||||
w.append([A,T,phi,head])
|
w.append([A,T,phi,head])
|
||||||
obj = App.ActiveDocument.addObject("Part::FeaturePython","ShipSimulation")
|
obj = App.ActiveDocument.addObject("Part::FeaturePython","ShipSimulation")
|
||||||
sim = SimInstance.ShipSimulation(obj,
|
sim = SimInstance.ShipSimulation(obj,
|
||||||
[form.length.value(), form.beam.value(), form.n.value()],
|
[form.length.value(), form.beam.value(), form.n.value()],
|
||||||
w)
|
w)
|
||||||
SimInstance.ViewProviderShipSimulation(obj.ViewObject)
|
SimInstance.ViewProviderShipSimulation(obj.ViewObject)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def reject(self):
|
def reject(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def clicked(self, index):
|
def clicked(self, index):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def needsFullSpace(self):
|
def needsFullSpace(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def isAllowedAlterSelection(self):
|
def isAllowedAlterSelection(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def isAllowedAlterView(self):
|
def isAllowedAlterView(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def isAllowedAlterDocument(self):
|
def isAllowedAlterDocument(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def helpRequested(self):
|
def helpRequested(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def setupUi(self):
|
def setupUi(self):
|
||||||
mw = self.getMainWindow()
|
mw = self.getMainWindow()
|
||||||
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||||
form.length = form.findChild(QtGui.QDoubleSpinBox, "Length")
|
form.length = form.findChild(QtGui.QDoubleSpinBox, "Length")
|
||||||
form.beam = form.findChild(QtGui.QDoubleSpinBox, "Beam")
|
form.beam = form.findChild(QtGui.QDoubleSpinBox, "Beam")
|
||||||
form.n = form.findChild(QtGui.QSpinBox, "N")
|
form.n = form.findChild(QtGui.QSpinBox, "N")
|
||||||
form.waves = form.findChild(QtGui.QTableWidget, "Waves")
|
form.waves = form.findChild(QtGui.QTableWidget, "Waves")
|
||||||
self.form = form
|
self.form = form
|
||||||
# Initial values
|
# Initial values
|
||||||
if self.initValues():
|
if self.initValues():
|
||||||
return True
|
return True
|
||||||
self.retranslateUi()
|
self.retranslateUi()
|
||||||
# Connect Signals and Slots
|
# Connect Signals and Slots
|
||||||
QtCore.QObject.connect(form.length, QtCore.SIGNAL("valueChanged(double)"), self.onFS)
|
QtCore.QObject.connect(form.length, QtCore.SIGNAL("valueChanged(double)"), self.onFS)
|
||||||
QtCore.QObject.connect(form.beam, QtCore.SIGNAL("valueChanged(double)"), self.onFS)
|
QtCore.QObject.connect(form.beam, QtCore.SIGNAL("valueChanged(double)"), self.onFS)
|
||||||
QtCore.QObject.connect(form.n, QtCore.SIGNAL("valueChanged(int)"), self.onFS)
|
QtCore.QObject.connect(form.n, QtCore.SIGNAL("valueChanged(int)"), self.onFS)
|
||||||
QtCore.QObject.connect(form.waves,QtCore.SIGNAL("cellChanged(int,int)"),self.onWaves);
|
QtCore.QObject.connect(form.waves,QtCore.SIGNAL("cellChanged(int,int)"),self.onWaves);
|
||||||
|
|
||||||
def getMainWindow(self):
|
def getMainWindow(self):
|
||||||
"returns the main window"
|
"returns the main window"
|
||||||
# using QtGui.qApp.activeWindow() isn't very reliable because if another
|
# 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
|
# widget than the mainwindow is active (e.g. a dialog) the wrong widget is
|
||||||
# returned
|
# returned
|
||||||
toplevel = QtGui.qApp.topLevelWidgets()
|
toplevel = QtGui.qApp.topLevelWidgets()
|
||||||
for i in toplevel:
|
for i in toplevel:
|
||||||
if i.metaObject().className() == "Gui::MainWindow":
|
if i.metaObject().className() == "Gui::MainWindow":
|
||||||
return i
|
return i
|
||||||
raise Exception("No main window found")
|
raise Exception("No main window found")
|
||||||
|
|
||||||
def initValues(self):
|
def initValues(self):
|
||||||
""" Set initial values for fields
|
""" Set initial values for fields
|
||||||
"""
|
"""
|
||||||
msg = Translator.translate("Ready to work\n")
|
msg = Translator.translate("Ready to work\n")
|
||||||
App.Console.PrintMessage(msg)
|
App.Console.PrintMessage(msg)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def retranslateUi(self):
|
def retranslateUi(self):
|
||||||
""" Set user interface locale strings.
|
""" Set user interface locale strings.
|
||||||
"""
|
"""
|
||||||
self.form.setWindowTitle(Translator.translate("Create a new ship simulation"))
|
self.form.setWindowTitle(Translator.translate("Create a new ship simulation"))
|
||||||
self.form.findChild(QtGui.QGroupBox, "FSDataBox").setTitle(Translator.translate("Free surface"))
|
self.form.findChild(QtGui.QGroupBox, "FSDataBox").setTitle(Translator.translate("Free surface"))
|
||||||
self.form.findChild(QtGui.QLabel, "LengthLabel").setText(Translator.translate("Length"))
|
self.form.findChild(QtGui.QLabel, "LengthLabel").setText(Translator.translate("Length"))
|
||||||
self.form.findChild(QtGui.QLabel, "BeamLabel").setText(Translator.translate("Beam"))
|
self.form.findChild(QtGui.QLabel, "BeamLabel").setText(Translator.translate("Beam"))
|
||||||
self.form.findChild(QtGui.QLabel, "NLabel").setText(Translator.translate("Number of points"))
|
self.form.findChild(QtGui.QLabel, "NLabel").setText(Translator.translate("Number of points"))
|
||||||
self.form.findChild(QtGui.QGroupBox, "WavesDataBox").setTitle(Translator.translate("Waves"))
|
self.form.findChild(QtGui.QGroupBox, "WavesDataBox").setTitle(Translator.translate("Waves"))
|
||||||
labels = []
|
labels = []
|
||||||
labels.append(Translator.translate("Amplitude") + " [m]")
|
labels.append(Translator.translate("Amplitude") + " [m]")
|
||||||
labels.append(Translator.translate("Period") + " [s]")
|
labels.append(Translator.translate("Period") + " [s]")
|
||||||
labels.append(Translator.translate("Phase") + " [rad]")
|
labels.append(Translator.translate("Phase") + " [rad]")
|
||||||
labels.append(Translator.translate("Heading") + " [deg]")
|
labels.append(Translator.translate("Heading") + " [deg]")
|
||||||
self.form.waves.setHorizontalHeaderLabels(labels)
|
self.form.waves.setHorizontalHeaderLabels(labels)
|
||||||
|
|
||||||
def onFS(self, value):
|
def onFS(self, value):
|
||||||
""" Method called when free surface data is changed.
|
""" Method called when free surface data is changed.
|
||||||
@param value Changed value.
|
@param value Changed value.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def onWaves(self, row, column):
|
def onWaves(self, row, column):
|
||||||
""" Method called when waves data is changed.
|
""" Method called when waves data is changed.
|
||||||
@param row Affected row.
|
@param row Affected row.
|
||||||
@param col Affected column.
|
@param col Affected column.
|
||||||
"""
|
"""
|
||||||
item = self.form.waves.item(row,column)
|
item = self.form.waves.item(row,column)
|
||||||
# Row deletion
|
# Row deletion
|
||||||
if column == 0:
|
if column == 0:
|
||||||
if not item.text():
|
if not item.text():
|
||||||
self.form.waves.removeRow(row)
|
self.form.waves.removeRow(row)
|
||||||
# Ensure that exist one empty item at the end
|
# Ensure that exist one empty item at the end
|
||||||
nRow = self.form.waves.rowCount()
|
nRow = self.form.waves.rowCount()
|
||||||
last = self.form.waves.item(nRow-1,0)
|
if not nRow:
|
||||||
if last:
|
self.form.waves.setRowCount(1)
|
||||||
if(last.text() != ''):
|
else:
|
||||||
self.form.waves.setRowCount(nRow+1)
|
last = self.form.waves.item(nRow-1,0)
|
||||||
# Fields must be numbers
|
if last:
|
||||||
for i in range(0,self.form.waves.rowCount()-1): # Avoid last row
|
if(last.text() != ''):
|
||||||
for j in range(0,self.form.waves.columnCount()): # Avoid name column
|
self.form.waves.setRowCount(nRow+1)
|
||||||
item = self.form.waves.item(i,j)
|
# Fields must be numbers
|
||||||
if not item:
|
for i in range(0,self.form.waves.rowCount()-1): # Avoid last row
|
||||||
item = QtGui.QTableWidgetItem('0.0')
|
for j in range(0,self.form.waves.columnCount()): # Avoid name column
|
||||||
self.form.waves.setItem(i,j,item)
|
item = self.form.waves.item(i,j)
|
||||||
continue
|
if not item:
|
||||||
(number,flag) = item.text().toFloat()
|
item = QtGui.QTableWidgetItem('0.0')
|
||||||
if not flag:
|
self.form.waves.setItem(i,j,item)
|
||||||
item.setText('0.0')
|
continue
|
||||||
|
(number,flag) = item.text().toFloat()
|
||||||
def createTask():
|
if not flag:
|
||||||
panel = TaskPanel()
|
item.setText('0.0')
|
||||||
Gui.Control.showDialog(panel)
|
|
||||||
if panel.setupUi():
|
def createTask():
|
||||||
Gui.Control.closeDialog(panel)
|
panel = TaskPanel()
|
||||||
return None
|
Gui.Control.showDialog(panel)
|
||||||
return panel
|
if panel.setupUi():
|
||||||
|
Gui.Control.closeDialog(panel)
|
||||||
|
return None
|
||||||
|
return panel
|
||||||
|
|
Loading…
Reference in New Issue
Block a user