1 #include <PartSet_Module.h>
2 #include <PartSet_OperationSketch.h>
4 #include <ModuleBase_Operation.h>
6 #include <XGUI_MainWindow.h>
7 #include <XGUI_Displayer.h>
8 #include <XGUI_Viewer.h>
9 #include <XGUI_Workshop.h>
10 #include <XGUI_OperationMgr.h>
12 #include <Config_PointerMessage.h>
13 #include <Config_ModuleReader.h>
14 #include <Config_WidgetReader.h>
15 #include <Events_Loop.h>
16 #include <Events_Message.h>
26 /*!Create and return new instance of XGUI_Module*/
27 extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop)
29 return new PartSet_Module(theWshop);
32 PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
34 myWorkshop = theWshop;
35 XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
37 connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
38 connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
39 this, SLOT(onOperationStopped(ModuleBase_Operation*)));
42 PartSet_Module::~PartSet_Module()
46 void PartSet_Module::createFeatures()
48 Config_ModuleReader aXMLReader = Config_ModuleReader();
50 myFeaturesInFiles = aXMLReader.featuresInFiles();
53 void PartSet_Module::featureCreated(XGUI_Command* theFeature)
55 theFeature->connectTo(this, SLOT(onFeatureTriggered()));
58 std::string PartSet_Module::featureFile(const std::string& theFeatureId)
60 return myFeaturesInFiles[theFeatureId];
66 void PartSet_Module::onFeatureTriggered()
68 XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
69 QString aCmdId = aCmd->id();
70 std::string aStdCmdId = aCmdId.toStdString();
71 std::string aPluginFileName = featureFile(aStdCmdId);
72 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
74 std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId);
75 std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
76 ModuleBase_PropPanelOperation* aPartSetOp;
77 if (aCmdId == "Sketch" ) {
78 aPartSetOp = new PartSet_OperationSketch(aCmdId, this);
80 aPartSetOp = new ModuleBase_PropPanelOperation(aCmdId, this);
82 aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
83 aPartSetOp->setDescription(QString::fromStdString(aDescription));
85 //TODO(sbh): Implement static method to extract event id [SEID]
86 static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent");
87 Config_PointerMessage aMessage(aModuleEvent, this);
88 aMessage.setPointer(aPartSetOp);
89 Events_Loop::loop()->send(aMessage);
92 void PartSet_Module::onOperationStarted()
94 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
96 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
98 connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
99 aPreviewOp, SLOT(onViewSelectionChanged()));
100 visualizePreview(true);
104 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
106 ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(theOperation);
110 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
112 disconnect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
113 aPreviewOp, SLOT(onViewSelectionChanged()));
114 visualizePreview(false);
118 void PartSet_Module::visualizePreview(bool isDisplay)
120 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
124 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
129 myWorkshop->displayer()->LocalSelection(anOperation->feature(), aPreviewOp->preview(),
130 aPreviewOp->getSelectionMode());
133 myWorkshop->displayer()->GlobalSelection(false);
134 myWorkshop->displayer()->Erase(anOperation->feature(), aPreviewOp->preview());