1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 #include "ModuleBase_IModule.h"
5 #include "ModuleBase_IViewer.h"
6 #include "ModuleBase_ViewerPrs.h"
7 #include "ModuleBase_Operation.h"
8 #include "ModuleBase_ISelection.h"
9 #include "ModuleBase_OperationDescription.h"
11 #include <Events_Loop.h>
13 #include <ModelAPI_Events.h>
14 #include <ModelAPI_CompositeFeature.h>
16 #include <Config_PointerMessage.h>
17 #include <Config_WidgetReader.h>
18 #include <Config_ModuleReader.h>
22 ModuleBase_IModule::ModuleBase_IModule(ModuleBase_IWorkshop* theParent)
23 : QObject(theParent), myWorkshop(theParent)
25 connect(myWorkshop, SIGNAL(operationStarted(ModuleBase_Operation*)),
26 SLOT(onOperationStarted(ModuleBase_Operation*)));
28 connect(myWorkshop, SIGNAL(operationStopped(ModuleBase_Operation*)),
29 SLOT(onOperationStopped(ModuleBase_Operation*)));
31 connect(myWorkshop, SIGNAL(operationResumed(ModuleBase_Operation*)),
32 SLOT(onOperationResumed(ModuleBase_Operation*)));
34 connect(myWorkshop, SIGNAL(operationComitted(ModuleBase_Operation*)),
35 SLOT(onOperationComitted(ModuleBase_Operation*)));
37 connect(myWorkshop, SIGNAL(operationAborted(ModuleBase_Operation*)),
38 SLOT(onOperationAborted(ModuleBase_Operation*)));
40 connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
43 //connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this,
44 // SLOT(onMousePressed(QMouseEvent*)));
45 //connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), this,
46 // SLOT(onMouseReleased(QMouseEvent*)));
47 //connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), this,
48 // SLOT(onMouseMoved(QMouseEvent*)));
49 //connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)), this,
50 // SLOT(onKeyRelease(QKeyEvent*)));
51 //connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
52 // SLOT(onMouseDoubleClick(QMouseEvent*)));
56 void ModuleBase_IModule::launchOperation(const QString& theCmdId)
58 if (!myWorkshop->canStartOperation(theCmdId))
61 ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
62 ModuleBase_ISelection* aSelection = myWorkshop->selection();
63 // Initialise operation with preliminary selection
64 anOperation->initSelection(aSelection, myWorkshop->viewer());
65 sendOperation(anOperation);
69 void ModuleBase_IModule::sendOperation(ModuleBase_Operation* theOperation)
71 static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
72 std::shared_ptr<Config_PointerMessage> aMessage =
73 std::shared_ptr<Config_PointerMessage>(new Config_PointerMessage(aModuleEvent, this));
74 aMessage->setPointer(theOperation);
75 Events_Loop::loop()->send(aMessage);
78 ModuleBase_Operation* ModuleBase_IModule::getNewOperation(const std::string& theFeatureId)
80 return new ModuleBase_Operation(theFeatureId.c_str(), this);
83 ModuleBase_Operation* ModuleBase_IModule::createOperation(const std::string& theFeatureId)
85 ModuleBase_Operation* anOperation = getNewOperation(theFeatureId);
87 // If the operation is launched as sub-operation of another then we have to initialise
89 ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
91 FeaturePtr aFeature = aCurOperation->feature();
92 CompositeFeaturePtr aCompFea = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
94 anOperation->setParentFeature(aCompFea);
97 std::string aPluginFileName = myFeaturesInFiles[theFeatureId];
98 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
100 std::string aXmlCfg = aWdgReader.featureWidgetCfg(theFeatureId);
101 std::string aDescription = aWdgReader.featureDescription(theFeatureId);
103 anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
104 anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
109 void ModuleBase_IModule::createFeatures()
111 registerValidators();
114 Config_ModuleReader aXMLReader = Config_ModuleReader();
115 aXMLReader.readAll();
116 myFeaturesInFiles = aXMLReader.featuresInFiles();
120 void ModuleBase_IModule::actionCreated(QAction* theFeature)
122 connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
126 void ModuleBase_IModule::onFeatureTriggered()
128 QAction* aCmd = dynamic_cast<QAction*>(sender());
129 //Do nothing on uncheck
130 if (aCmd->isCheckable() && !aCmd->isChecked())
132 launchOperation(aCmd->data().toString());
136 void ModuleBase_IModule::editFeature(FeaturePtr theFeature)
138 std::string aFeatureId = theFeature->getKind();
139 if (!myWorkshop->canStartOperation(aFeatureId.c_str()))
142 ModuleBase_Operation* anOperation = createOperation(aFeatureId);
143 anOperation->setFeature(theFeature);
144 sendOperation(anOperation);