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 #include "ModuleBase_OperationDescription.h"
9 #include <Events_Loop.h>
11 #include <ModelAPI_Events.h>
12 #include <ModelAPI_CompositeFeature.h>
14 #include <Config_PointerMessage.h>
15 #include <Config_WidgetReader.h>
16 #include <Config_ModuleReader.h>
20 ModuleBase_IModule::ModuleBase_IModule(ModuleBase_IWorkshop* theParent)
21 : QObject(theParent), myWorkshop(theParent)
23 connect(myWorkshop, SIGNAL(operationStarted(ModuleBase_Operation*)),
24 SLOT(onOperationStarted(ModuleBase_Operation*)));
26 connect(myWorkshop, SIGNAL(operationStopped(ModuleBase_Operation*)),
27 SLOT(onOperationStopped(ModuleBase_Operation*)));
29 connect(myWorkshop, SIGNAL(operationResumed(ModuleBase_Operation*)),
30 SLOT(onOperationResumed(ModuleBase_Operation*)));
32 connect(myWorkshop, SIGNAL(operationComitted(ModuleBase_Operation*)),
33 SLOT(onOperationComitted(ModuleBase_Operation*)));
35 connect(myWorkshop, SIGNAL(operationAborted(ModuleBase_Operation*)),
36 SLOT(onOperationAborted(ModuleBase_Operation*)));
38 connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
41 //connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this,
42 // SLOT(onMousePressed(QMouseEvent*)));
43 //connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), this,
44 // SLOT(onMouseReleased(QMouseEvent*)));
45 //connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), this,
46 // SLOT(onMouseMoved(QMouseEvent*)));
47 //connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)), this,
48 // SLOT(onKeyRelease(QKeyEvent*)));
49 //connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
50 // SLOT(onMouseDoubleClick(QMouseEvent*)));
54 void ModuleBase_IModule::launchOperation(const QString& theCmdId)
56 if (!myWorkshop->canStartOperation(theCmdId))
59 ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
60 ModuleBase_ISelection* aSelection = myWorkshop->selection();
61 // Initialise operation with preliminary selection
62 anOperation->initSelection(aSelection, myWorkshop->viewer());
63 sendOperation(anOperation);
67 void ModuleBase_IModule::sendOperation(ModuleBase_Operation* theOperation)
69 static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
70 std::shared_ptr<Config_PointerMessage> aMessage =
71 std::shared_ptr<Config_PointerMessage>(new Config_PointerMessage(aModuleEvent, this));
72 aMessage->setPointer(theOperation);
73 Events_Loop::loop()->send(aMessage);
76 ModuleBase_Operation* ModuleBase_IModule::getNewOperation(const std::string& theFeatureId)
78 return new ModuleBase_Operation(theFeatureId.c_str(), this);
81 ModuleBase_Operation* ModuleBase_IModule::createOperation(const std::string& theFeatureId)
83 ModuleBase_Operation* anOperation = getNewOperation(theFeatureId);
85 // If the operation is launched as sub-operation of another then we have to initialise
87 ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
89 FeaturePtr aFeature = aCurOperation->feature();
90 CompositeFeaturePtr aCompFea = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
92 anOperation->setParentFeature(aCompFea);
95 std::string aPluginFileName = myFeaturesInFiles[theFeatureId];
96 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
98 std::string aXmlCfg = aWdgReader.featureWidgetCfg(theFeatureId);
99 std::string aDescription = aWdgReader.featureDescription(theFeatureId);
101 anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
102 anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
107 void ModuleBase_IModule::createFeatures()
109 registerValidators();
111 Config_ModuleReader aXMLReader = Config_ModuleReader();
112 aXMLReader.readAll();
113 myFeaturesInFiles = aXMLReader.featuresInFiles();
117 void ModuleBase_IModule::actionCreated(QAction* theFeature)
119 connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
123 void ModuleBase_IModule::onFeatureTriggered()
125 QAction* aCmd = dynamic_cast<QAction*>(sender());
126 //Do nothing on uncheck
127 if (aCmd->isCheckable() && !aCmd->isChecked())
129 launchOperation(aCmd->data().toString());
133 void ModuleBase_IModule::editFeature(FeaturePtr theFeature)
135 std::string aFeatureId = theFeature->getKind();
136 if (!myWorkshop->canStartOperation(aFeatureId.c_str()))
139 ModuleBase_Operation* anOperation = createOperation(aFeatureId);
140 anOperation->setFeature(theFeature);
141 sendOperation(anOperation);