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(selectionChanged()), this, SLOT(onSelectionChanged()));
28 //connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this,
29 // SLOT(onMousePressed(QMouseEvent*)));
30 //connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), this,
31 // SLOT(onMouseReleased(QMouseEvent*)));
32 //connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), this,
33 // SLOT(onMouseMoved(QMouseEvent*)));
34 //connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)), this,
35 // SLOT(onKeyRelease(QKeyEvent*)));
36 //connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
37 // SLOT(onMouseDoubleClick(QMouseEvent*)));
41 void ModuleBase_IModule::launchOperation(const QString& theCmdId)
43 if (!myWorkshop->canStartOperation(theCmdId))
46 ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
47 ModuleBase_ISelection* aSelection = myWorkshop->selection();
48 // Initialise operation with preliminary selection
49 anOperation->initSelection(aSelection, myWorkshop->viewer());
50 sendOperation(anOperation);
54 void ModuleBase_IModule::sendOperation(ModuleBase_Operation* theOperation)
56 static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
57 std::shared_ptr<Config_PointerMessage> aMessage =
58 std::shared_ptr<Config_PointerMessage>(new Config_PointerMessage(aModuleEvent, this));
59 aMessage->setPointer(theOperation);
60 Events_Loop::loop()->send(aMessage);
63 ModuleBase_Operation* ModuleBase_IModule::getNewOperation(const std::string& theFeatureId)
65 return new ModuleBase_Operation(theFeatureId.c_str(), this);
68 ModuleBase_Operation* ModuleBase_IModule::createOperation(const std::string& theFeatureId)
70 ModuleBase_Operation* anOperation = getNewOperation(theFeatureId);
72 // If the operation is launched as sub-operation of another then we have to initialise
74 ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
76 FeaturePtr aFeature = aCurOperation->feature();
77 CompositeFeaturePtr aCompFeature =
78 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
80 anOperation->setParentFeature(aCompFeature);
84 std::string aPluginFileName = myFeaturesInFiles[theFeatureId];
85 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
87 std::string aXmlCfg = aWdgReader.featureWidgetCfg(theFeatureId);
88 std::string aDescription = aWdgReader.featureDescription(theFeatureId);
90 anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
91 anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
96 void ModuleBase_IModule::createFeatures()
101 Config_ModuleReader aXMLReader = Config_ModuleReader();
102 aXMLReader.readAll();
103 myFeaturesInFiles = aXMLReader.featuresInFiles();
107 void ModuleBase_IModule::actionCreated(QAction* theFeature)
109 connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
113 void ModuleBase_IModule::onFeatureTriggered()
115 QAction* aCmd = dynamic_cast<QAction*>(sender());
116 //Do nothing on uncheck
117 if (aCmd->isCheckable() && !aCmd->isChecked())
119 launchOperation(aCmd->data().toString());
123 void ModuleBase_IModule::editFeature(FeaturePtr theFeature)
125 std::string aFeatureId = theFeature->getKind();
126 if (!myWorkshop->canStartOperation(aFeatureId.c_str()))
129 ModuleBase_Operation* anOperation = createOperation(aFeatureId);
130 anOperation->setFeature(theFeature);
131 sendOperation(anOperation);