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(operationStopped(ModuleBase_Operation*)),
26 SLOT(onOperationStopped(ModuleBase_Operation*)));
28 connect(myWorkshop, SIGNAL(operationComitted(ModuleBase_Operation*)),
29 SLOT(onOperationComitted(ModuleBase_Operation*)));
31 connect(myWorkshop, SIGNAL(operationAborted(ModuleBase_Operation*)),
32 SLOT(onOperationAborted(ModuleBase_Operation*)));
34 connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
37 //connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this,
38 // SLOT(onMousePressed(QMouseEvent*)));
39 //connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), this,
40 // SLOT(onMouseReleased(QMouseEvent*)));
41 //connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), this,
42 // SLOT(onMouseMoved(QMouseEvent*)));
43 //connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)), this,
44 // SLOT(onKeyRelease(QKeyEvent*)));
45 //connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
46 // SLOT(onMouseDoubleClick(QMouseEvent*)));
50 void ModuleBase_IModule::launchOperation(const QString& theCmdId)
52 if (!myWorkshop->canStartOperation(theCmdId))
55 ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
56 ModuleBase_ISelection* aSelection = myWorkshop->selection();
57 // Initialise operation with preliminary selection
58 anOperation->initSelection(aSelection, myWorkshop->viewer());
59 sendOperation(anOperation);
63 void ModuleBase_IModule::sendOperation(ModuleBase_Operation* theOperation)
65 static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
66 std::shared_ptr<Config_PointerMessage> aMessage =
67 std::shared_ptr<Config_PointerMessage>(new Config_PointerMessage(aModuleEvent, this));
68 aMessage->setPointer(theOperation);
69 Events_Loop::loop()->send(aMessage);
72 ModuleBase_Operation* ModuleBase_IModule::getNewOperation(const std::string& theFeatureId)
74 return new ModuleBase_Operation(theFeatureId.c_str(), this);
77 ModuleBase_Operation* ModuleBase_IModule::createOperation(const std::string& theFeatureId)
79 ModuleBase_Operation* anOperation = getNewOperation(theFeatureId);
81 // If the operation is launched as sub-operation of another then we have to initialise
83 ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
85 FeaturePtr aFeature = aCurOperation->feature();
86 CompositeFeaturePtr aCompFea = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
88 anOperation->setParentFeature(aCompFea);
91 std::string aPluginFileName = myFeaturesInFiles[theFeatureId];
92 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
94 std::string aXmlCfg = aWdgReader.featureWidgetCfg(theFeatureId);
95 std::string aDescription = aWdgReader.featureDescription(theFeatureId);
97 anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
98 anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
103 void ModuleBase_IModule::createFeatures()
105 registerValidators();
108 Config_ModuleReader aXMLReader = Config_ModuleReader();
109 aXMLReader.readAll();
110 myFeaturesInFiles = aXMLReader.featuresInFiles();
114 void ModuleBase_IModule::actionCreated(QAction* theFeature)
116 connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
120 void ModuleBase_IModule::onFeatureTriggered()
122 QAction* aCmd = dynamic_cast<QAction*>(sender());
123 //Do nothing on uncheck
124 if (aCmd->isCheckable() && !aCmd->isChecked())
126 launchOperation(aCmd->data().toString());
130 void ModuleBase_IModule::editFeature(FeaturePtr theFeature)
132 std::string aFeatureId = theFeature->getKind();
133 if (!myWorkshop->canStartOperation(aFeatureId.c_str()))
136 ModuleBase_Operation* anOperation = createOperation(aFeatureId);
137 anOperation->setFeature(theFeature);
138 sendOperation(anOperation);