First simulator draft version.
This commit is contained in:
committed by
Yorik van Havre
parent
6dabcd3546
commit
3ed62c5bc6
156
src/Mod/Ship/simPost/TaskPanel.py
Normal file
156
src/Mod/Ship/simPost/TaskPanel.py
Normal file
@@ -0,0 +1,156 @@
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* 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
|
||||
# pyOpenCL
|
||||
import pyopencl as cl
|
||||
# Module
|
||||
import SimInstance
|
||||
from shipUtils import Paths, Translator
|
||||
from simRun import Simulation
|
||||
Sim = Simulation.FreeCADShipSimulation
|
||||
# from Simulation import FreeCADShipSimulation as Sim
|
||||
|
||||
class TaskPanel:
|
||||
def __init__(self):
|
||||
self.ui = Paths.modulePath() + "/simPost/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.time = form.findChild(QtGui.QLabel, "TimeLabel")
|
||||
form.first = form.findChild(QtGui.QPushButton, "First")
|
||||
form.prev = form.findChild(QtGui.QPushButton, "Prev")
|
||||
form.now = form.findChild(QtGui.QPushButton, "Now")
|
||||
form.next = form.findChild(QtGui.QPushButton, "Next")
|
||||
form.last = form.findChild(QtGui.QPushButton, "Last")
|
||||
self.form = form
|
||||
# Initial values
|
||||
if self.initValues():
|
||||
return True
|
||||
self.retranslateUi()
|
||||
# Connect Signals and Slots
|
||||
QtCore.QObject.connect(form.first, QtCore.SIGNAL("pressed()"), self.onFirst)
|
||||
QtCore.QObject.connect(form.prev, QtCore.SIGNAL("pressed()"), self.onPrev)
|
||||
QtCore.QObject.connect(form.now, QtCore.SIGNAL("pressed()"), self.onNow)
|
||||
QtCore.QObject.connect(form.next, QtCore.SIGNAL("pressed()"), self.onNext)
|
||||
QtCore.QObject.connect(form.last, QtCore.SIGNAL("pressed()"), self.onLast)
|
||||
|
||||
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):
|
||||
""" Set initial values for fields
|
||||
"""
|
||||
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("Track simulation"))
|
||||
self.form.findChild(QtGui.QPushButton, "Now").setText(Translator.translate("Now"))
|
||||
|
||||
def onFirst(self):
|
||||
""" Called when first frame button is pressed.
|
||||
"""
|
||||
|
||||
def onPrev(self):
|
||||
""" Called when previous frame button is pressed.
|
||||
"""
|
||||
|
||||
def onNow(self):
|
||||
""" Called when actual frame button is pressed.
|
||||
"""
|
||||
sim = Sim()
|
||||
pos = sim.sim.FS_Position[:]
|
||||
nx = sim.FS['Nx']
|
||||
ny = sim.FS['Ny']
|
||||
for i in range(0, nx):
|
||||
for j in range(0, ny):
|
||||
pos[i*ny+j].z = float(sim.FS['pos'][i,j][2])
|
||||
sim.sim.FS_Position = pos[:]
|
||||
App.ActiveDocument.recompute()
|
||||
self.form.time.setText("t = %g s" % (sim.t))
|
||||
|
||||
def onNext(self):
|
||||
""" Called when next frame button is pressed.
|
||||
"""
|
||||
|
||||
def onLast(self):
|
||||
""" Called when last frame button is pressed.
|
||||
"""
|
||||
|
||||
def createTask():
|
||||
try:
|
||||
simulator = Sim()
|
||||
except:
|
||||
msg = Translator.translate("Can't find any active simulation!\n")
|
||||
App.Console.PrintError(msg)
|
||||
return
|
||||
panel = TaskPanel()
|
||||
Gui.Control.showDialog(panel)
|
||||
if panel.setupUi():
|
||||
Gui.Control.closeDialog(panel)
|
||||
return None
|
||||
return panel
|
||||
81
src/Mod/Ship/simPost/TaskPanel.ui
Normal file
81
src/Mod/Ship/simPost/TaskPanel.ui
Normal file
@@ -0,0 +1,81 @@
|
||||
<?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>300</width>
|
||||
<height>102</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>1</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>100</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Track simulation</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="First">
|
||||
<property name="text">
|
||||
<string>|<</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="Prev">
|
||||
<property name="text">
|
||||
<string><</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QPushButton" name="Next">
|
||||
<property name="text">
|
||||
<string>></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<widget class="QPushButton" name="Last">
|
||||
<property name="text">
|
||||
<string>>|</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="Now">
|
||||
<property name="text">
|
||||
<string>Now</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="5">
|
||||
<widget class="QLabel" name="TimeLabel">
|
||||
<property name="text">
|
||||
<string>t = 0 s</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
40
src/Mod/Ship/simPost/__init__.py
Normal file
40
src/Mod/Ship/simPost/__init__.py
Normal file
@@ -0,0 +1,40 @@
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* 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()
|
||||
|
||||
def stop():
|
||||
""" Stops the simulation """
|
||||
TaskPanel.stopSimulation()
|
||||
Reference in New Issue
Block a user