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(selectionChanged()), this, SLOT(onSelectionChanged()));
26 //connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)), this,
27 // SLOT(onMousePressed(QMouseEvent*)));
28 //connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)), this,
29 // SLOT(onMouseReleased(QMouseEvent*)));
30 //connect(myWorkshop->viewer(), SIGNAL(mouseMove(QMouseEvent*)), this,
31 // SLOT(onMouseMoved(QMouseEvent*)));
32 //connect(myWorkshop->viewer(), SIGNAL(keyRelease(QKeyEvent*)), this,
33 // SLOT(onKeyRelease(QKeyEvent*)));
34 //connect(myWorkshop->viewer(), SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
35 // SLOT(onMouseDoubleClick(QMouseEvent*)));
39 void ModuleBase_IModule::launchOperation(const QString& theCmdId)
41 if (!myWorkshop->canStartOperation(theCmdId))
44 ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
45 ModuleBase_ISelection* aSelection = myWorkshop->selection();
46 // Initialise operation with preliminary selection
47 anOperation->initSelection(aSelection, myWorkshop->viewer());
48 sendOperation(anOperation);
52 void ModuleBase_IModule::sendOperation(ModuleBase_Operation* theOperation)
54 static Events_ID aModuleEvent = Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED);
55 std::shared_ptr<Config_PointerMessage> aMessage =
56 std::shared_ptr<Config_PointerMessage>(new Config_PointerMessage(aModuleEvent, this));
57 aMessage->setPointer(theOperation);
58 Events_Loop::loop()->send(aMessage);
61 ModuleBase_Operation* ModuleBase_IModule::getNewOperation(const std::string& theFeatureId)
63 return new ModuleBase_Operation(theFeatureId.c_str(), this);
66 ModuleBase_Operation* ModuleBase_IModule::createOperation(const std::string& theFeatureId)
68 ModuleBase_Operation* anOperation = getNewOperation(theFeatureId);
70 // If the operation is launched as sub-operation of another then we have to initialise
72 ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
74 FeaturePtr aFeature = aCurOperation->feature();
75 CompositeFeaturePtr aCompFea = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
77 anOperation->setParentFeature(aCompFea);
80 std::string aPluginFileName = myFeaturesInFiles[theFeatureId];
81 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
83 std::string aXmlCfg = aWdgReader.featureWidgetCfg(theFeatureId);
84 std::string aDescription = aWdgReader.featureDescription(theFeatureId);
86 anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
87 anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
92 void ModuleBase_IModule::createFeatures()
97 Config_ModuleReader aXMLReader = Config_ModuleReader();
99 myFeaturesInFiles = aXMLReader.featuresInFiles();
103 void ModuleBase_IModule::actionCreated(QAction* theFeature)
105 connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
109 void ModuleBase_IModule::onFeatureTriggered()
111 QAction* aCmd = dynamic_cast<QAction*>(sender());
112 //Do nothing on uncheck
113 if (aCmd->isCheckable() && !aCmd->isChecked())
115 launchOperation(aCmd->data().toString());
119 void ModuleBase_IModule::editFeature(FeaturePtr theFeature)
121 std::string aFeatureId = theFeature->getKind();
122 if (!myWorkshop->canStartOperation(aFeatureId.c_str()))
125 ModuleBase_Operation* anOperation = createOperation(aFeatureId);
126 anOperation->setFeature(theFeature);
127 sendOperation(anOperation);