Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / ModuleBase / ModuleBase_IModule.cpp
1
2 #include "ModuleBase_IModule.h"
3 #include "ModuleBase_IViewer.h"
4 #include "ModuleBase_ViewerPrs.h"
5 #include "ModuleBase_Operation.h"
6 #include "ModuleBase_ISelection.h"
7
8 #include <Events_Loop.h>
9
10 #include <ModelAPI_Events.h>
11
12 #include <Config_PointerMessage.h>
13
14
15 ModuleBase_IModule::ModuleBase_IModule(ModuleBase_IWorkshop* theParent)
16   : QObject(theParent), myWorkshop(theParent) 
17 {
18   connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
19   connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this,
20           SLOT(onMousePressed(QMouseEvent*)));
21   connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), this,
22           SLOT(onMouseReleased(QMouseEvent*)));
23   connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), this,
24           SLOT(onMouseMoved(QMouseEvent*)));
25   connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)), this,
26           SLOT(onKeyRelease(QKeyEvent*)));
27   connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
28           SLOT(onMouseDoubleClick(QMouseEvent*)));
29 }
30
31
32 void ModuleBase_IModule::launchOperation(const QString& theCmdId)
33 {
34   ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
35   ModuleBase_ISelection* aSelection = myWorkshop->selection();
36   // Initialise operation with preliminary selection
37   anOperation->initSelection(aSelection, myWorkshop->viewer());
38   sendOperation(anOperation);
39 }
40
41
42 void ModuleBase_IModule::sendOperation(ModuleBase_Operation* theOperation)
43 {
44   static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
45   boost::shared_ptr<Config_PointerMessage> aMessage =
46       boost::shared_ptr<Config_PointerMessage>(new Config_PointerMessage(aModuleEvent, this));
47   aMessage->setPointer(theOperation);
48   Events_Loop::loop()->send(aMessage);
49 }