Simulation thread control developed.
This commit is contained in:
parent
a455cf6fa8
commit
9c4b3cc618
|
@ -43,6 +43,8 @@ SET(ShipIcons_SRCS
|
||||||
Icons/SimCreateIco.xpm
|
Icons/SimCreateIco.xpm
|
||||||
Icons/SimRunIco.png
|
Icons/SimRunIco.png
|
||||||
Icons/SimRunIco.xpm
|
Icons/SimRunIco.xpm
|
||||||
|
Icons/SimStopIco.png
|
||||||
|
Icons/SimStopIco.xpm
|
||||||
Icons/Tank.png
|
Icons/Tank.png
|
||||||
Icons/Tank.xcf
|
Icons/Tank.xcf
|
||||||
Icons/Tank.xpm
|
Icons/Tank.xpm
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 14 KiB |
File diff suppressed because it is too large
Load Diff
BIN
src/Mod/Ship/Icons/SimStopIco.png
Normal file
BIN
src/Mod/Ship/Icons/SimStopIco.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
2217
src/Mod/Ship/Icons/SimStopIco.xpm
Normal file
2217
src/Mod/Ship/Icons/SimStopIco.xpm
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -42,7 +42,7 @@ class ShipWorkbench ( Workbench ):
|
||||||
msg = Translator.translate("pyOpenCL not installed, ship simulations disabled\n")
|
msg = Translator.translate("pyOpenCL not installed, ship simulations disabled\n")
|
||||||
App.Console.PrintWarning(msg)
|
App.Console.PrintWarning(msg)
|
||||||
else:
|
else:
|
||||||
list = ["Ship_CreateSim", "Ship_RunSim"]
|
list = ["Ship_CreateSim", "Ship_RunSim", "Ship_StopSim"]
|
||||||
self.appendToolbar("Simulation",list)
|
self.appendToolbar("Simulation",list)
|
||||||
|
|
||||||
# Menu
|
# Menu
|
||||||
|
@ -55,7 +55,7 @@ class ShipWorkbench ( Workbench ):
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
list = ["Ship_CreateSim", "Ship_RunSim"]
|
list = ["Ship_CreateSim", "Ship_RunSim", "Ship_StopSim"]
|
||||||
self.appendToolbar("Simulation",list)
|
self.appendToolbar("Simulation",list)
|
||||||
|
|
||||||
Gui.addWorkbench(ShipWorkbench())
|
Gui.addWorkbench(ShipWorkbench())
|
||||||
|
|
|
@ -44,6 +44,8 @@ nobase_data_DATA = \
|
||||||
Icons/SimCreateIco.xpm \
|
Icons/SimCreateIco.xpm \
|
||||||
Icons/SimRunIco.png \
|
Icons/SimRunIco.png \
|
||||||
Icons/SimRunIco.xpm \
|
Icons/SimRunIco.xpm \
|
||||||
|
Icons/SimStopIco.png \
|
||||||
|
Icons/SimStopIco.xpm \
|
||||||
Icons/Tank.png \
|
Icons/Tank.png \
|
||||||
Icons/Tank.xcf \
|
Icons/Tank.xcf \
|
||||||
Icons/Tank.xpm \
|
Icons/Tank.xpm \
|
||||||
|
|
|
@ -144,6 +144,18 @@ class RunSim:
|
||||||
ToolTip = str(Translator.translate('Run a simulation'))
|
ToolTip = str(Translator.translate('Run a simulation'))
|
||||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||||
|
|
||||||
|
class StopSim:
|
||||||
|
def Activated(self):
|
||||||
|
import simRun
|
||||||
|
simRun.stop()
|
||||||
|
|
||||||
|
def GetResources(self):
|
||||||
|
from shipUtils import Paths, Translator
|
||||||
|
IconPath = Paths.iconsPath() + "/SimStopIco.png"
|
||||||
|
MenuText = str(Translator.translate('Stop active simulation'))
|
||||||
|
ToolTip = str(Translator.translate('Stop active simulation'))
|
||||||
|
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||||
|
|
||||||
FreeCADGui.addCommand('Ship_LoadExample', LoadExample())
|
FreeCADGui.addCommand('Ship_LoadExample', LoadExample())
|
||||||
FreeCADGui.addCommand('Ship_CreateShip', CreateShip())
|
FreeCADGui.addCommand('Ship_CreateShip', CreateShip())
|
||||||
FreeCADGui.addCommand('Ship_OutlineDraw', OutlineDraw())
|
FreeCADGui.addCommand('Ship_OutlineDraw', OutlineDraw())
|
||||||
|
@ -154,3 +166,4 @@ FreeCADGui.addCommand('Ship_CreateTank', CreateTank())
|
||||||
FreeCADGui.addCommand('Ship_GZ', GZ())
|
FreeCADGui.addCommand('Ship_GZ', GZ())
|
||||||
FreeCADGui.addCommand('Ship_CreateSim', CreateSim())
|
FreeCADGui.addCommand('Ship_CreateSim', CreateSim())
|
||||||
FreeCADGui.addCommand('Ship_RunSim', RunSim())
|
FreeCADGui.addCommand('Ship_RunSim', RunSim())
|
||||||
|
FreeCADGui.addCommand('Ship_StopSim', StopSim())
|
||||||
|
|
|
@ -35,7 +35,18 @@ from FreeCAD import Part, Base, Vector
|
||||||
# Ship design module
|
# Ship design module
|
||||||
from shipUtils import Paths, Translator, Math
|
from shipUtils import Paths, Translator, Math
|
||||||
|
|
||||||
|
class Singleton(type):
|
||||||
|
def __init__(cls, name, bases, dct):
|
||||||
|
cls.__instance = None
|
||||||
|
type.__init__(cls, name, bases, dct)
|
||||||
|
|
||||||
|
def __call__(cls, *args, **kw):
|
||||||
|
if cls.__instance is None:
|
||||||
|
cls.__instance = type.__call__(cls, *args,**kw)
|
||||||
|
return cls.__instance
|
||||||
|
|
||||||
class FreeCADShipSimulation(threading.Thread):
|
class FreeCADShipSimulation(threading.Thread):
|
||||||
|
__metaclass__ = Singleton
|
||||||
def __init__ (self, device, endTime, output, FSmesh, waves):
|
def __init__ (self, device, endTime, output, FSmesh, waves):
|
||||||
""" Thread constructor.
|
""" Thread constructor.
|
||||||
@param device Device to use.
|
@param device Device to use.
|
||||||
|
@ -45,6 +56,8 @@ class FreeCADShipSimulation(threading.Thread):
|
||||||
@param waves Waves parameters (A,T,phi,heading)
|
@param waves Waves parameters (A,T,phi,heading)
|
||||||
"""
|
"""
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
# Setup as stopped
|
||||||
|
self.active = False
|
||||||
# Build OpenCL context and command queue
|
# Build OpenCL context and command queue
|
||||||
self.device = device
|
self.device = device
|
||||||
self.context = cl.Context(devices=[self.device])
|
self.context = cl.Context(devices=[self.device])
|
||||||
|
@ -58,8 +71,25 @@ class FreeCADShipSimulation(threading.Thread):
|
||||||
def run(self):
|
def run(self):
|
||||||
""" Runs the simulation.
|
""" Runs the simulation.
|
||||||
"""
|
"""
|
||||||
|
self.active = True
|
||||||
# Perform work here
|
# Perform work here
|
||||||
|
while self.active:
|
||||||
print("Im thread, Im running...")
|
print("Im thread, Im running...")
|
||||||
time.sleep(2)
|
time.sleep(1)
|
||||||
# ...
|
# ...
|
||||||
print("Im thread, I end!")
|
print("Im thread, step done!")
|
||||||
|
# Set thread as stopped (and prepare it to restarting)
|
||||||
|
self.active = False
|
||||||
|
threading.Event().set()
|
||||||
|
threading.Thread.__init__(self)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
""" Call to stop execution.
|
||||||
|
"""
|
||||||
|
self.active = False
|
||||||
|
|
||||||
|
def isRunning(self):
|
||||||
|
""" Report thread state
|
||||||
|
@return True if thread is running, False otherwise.
|
||||||
|
"""
|
||||||
|
return self.active
|
||||||
|
|
|
@ -33,6 +33,8 @@ import SimInstance
|
||||||
from shipUtils import Paths, Translator
|
from shipUtils import Paths, Translator
|
||||||
from Simulation import FreeCADShipSimulation as Sim
|
from Simulation import FreeCADShipSimulation as Sim
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
class TaskPanel:
|
class TaskPanel:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ui = Paths.modulePath() + "/simRun/TaskPanel.ui"
|
self.ui = Paths.modulePath() + "/simRun/TaskPanel.ui"
|
||||||
|
@ -184,3 +186,18 @@ def createTask():
|
||||||
Gui.Control.closeDialog(panel)
|
Gui.Control.closeDialog(panel)
|
||||||
return None
|
return None
|
||||||
return panel
|
return panel
|
||||||
|
|
||||||
|
def stopSimulation():
|
||||||
|
try:
|
||||||
|
simulator = Sim()
|
||||||
|
if not simulator.isRunning():
|
||||||
|
msg = Translator.translate("Simulation already stopped\n")
|
||||||
|
App.Console.PrintWarning(msg)
|
||||||
|
return
|
||||||
|
except:
|
||||||
|
msg = Translator.translate("Any active simulation to stop!\n")
|
||||||
|
App.Console.PrintError(msg)
|
||||||
|
return
|
||||||
|
simulator.stop()
|
||||||
|
msg = Translator.translate("Simulation will stop at the end of actual iteration\n")
|
||||||
|
App.Console.PrintMessage(msg)
|
||||||
|
|
|
@ -34,3 +34,7 @@ import TaskPanel
|
||||||
def load():
|
def load():
|
||||||
""" Loads the tool """
|
""" Loads the tool """
|
||||||
TaskPanel.createTask()
|
TaskPanel.createTask()
|
||||||
|
|
||||||
|
def stop():
|
||||||
|
""" Stops the simulation """
|
||||||
|
TaskPanel.stopSimulation()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user