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();
49 aXMLReader.setAutoImport(true);
53 void PartSet_Module::featureCreated(XGUI_Command* theFeature)
55 theFeature->connectTo(this, SLOT(onFeatureTriggered()));
58 std::string PartSet_Module::modulePlugin()
60 Config_ModuleReader aModuleReader = Config_ModuleReader();
61 aModuleReader.readAll();
62 std::map < std::string, std::string > aPluginMap = aModuleReader.plugins();
63 std::string aPluginName = aPluginMap["PartSetPlugin"];
70 void PartSet_Module::onFeatureTriggered()
72 std::string aPluginName = modulePlugin();
73 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginName);
75 XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
76 QString aCmdId = aCmd->id();
77 std::string aXmlCfg = aWdgReader.featureWidgetCfg(aCmdId.toStdString());
78 std::string aDescription = aWdgReader.featureDescription(aCmdId.toStdString());
79 ModuleBase_PropPanelOperation* aPartSetOp;
80 if (aCmdId == "Sketch" ) {
81 aPartSetOp = new PartSet_OperationSketch(aCmdId, this);
83 aPartSetOp = new ModuleBase_PropPanelOperation(aCmdId, this);
85 aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
86 aPartSetOp->setDescription(QString::fromStdString(aDescription));
88 //TODO(sbh): Implement static method to extract event id [SEID]
89 static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent");
90 Config_PointerMessage aMessage(aModuleEvent, this);
91 aMessage.setPointer(aPartSetOp);
92 Events_Loop::loop()->send(aMessage);
95 void PartSet_Module::onOperationStarted()
97 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
99 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
101 connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
102 aPreviewOp, SLOT(onViewSelectionChanged()));
103 visualizePreview(true);
107 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
109 ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(theOperation);
113 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
115 disconnect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
116 aPreviewOp, SLOT(onViewSelectionChanged()));
117 visualizePreview(false);
121 void PartSet_Module::visualizePreview(bool isDisplay)
123 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
127 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
132 myWorkshop->displayer()->LocalSelection(anOperation->feature(), aPreviewOp->preview(),
133 aPreviewOp->getSelectionMode());
136 myWorkshop->displayer()->GlobalSelection(false);
137 myWorkshop->displayer()->Erase(anOperation->feature(), aPreviewOp->preview());