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 <Event_Loop.h>
16 #include <Event_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(beforeOperationStart()), this, SLOT(onBeforeOperationStart()));
40 PartSet_Module::~PartSet_Module()
44 void PartSet_Module::createFeatures()
46 Config_ModuleReader* aXMLReader = new Config_ModuleReader();
47 aXMLReader->setAutoImport(true);
48 aXMLReader->readAll();
52 void PartSet_Module::featureCreated(XGUI_Command* theFeature)
54 QString aFtId = theFeature->id();
55 theFeature->connectTo(this, SLOT(onFeatureTriggered()));
58 void PartSet_Module::onFeatureTriggered()
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"];
64 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginName);
66 XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
67 QString aCmdId = aCmd->id();
68 std::string aXmlCfg = aWdgReader.featureWidgetCfg(aCmdId.toStdString());
69 std::string aDescription = aWdgReader.featureDescription(aCmdId.toStdString());
70 //TODO(sbh): Implement static method to extract event id [SEID]
71 static Event_ID aModuleEvent = Event_Loop::eventByName("PartSetModuleEvent");
72 Config_PointerMessage aMessage(aModuleEvent, this);
73 ModuleBase_PropPanelOperation* aPartSetOp;
74 if (aCmdId == "Sketch" )
75 aPartSetOp = new PartSet_OperationSketch(aCmdId, this);
77 aPartSetOp = new ModuleBase_PropPanelOperation(aCmdId, this);
79 aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
80 aPartSetOp->setDescription(QString::fromStdString(aDescription));
81 aMessage.setPointer(aPartSetOp);
82 Event_Loop::loop()->send(aMessage);
86 * Slot that is called by the operation requiring of preview display or erase
87 * \param isDisplay the display or erase state
89 void PartSet_Module::onVisualizePreview(bool isDisplay)
91 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
95 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
100 myWorkshop->displayer()->Display(anOperation->feature(), aPreviewOp->preview());
102 myWorkshop->displayer()->Erase(anOperation->feature(), aPreviewOp->preview());
105 void PartSet_Module::onBeforeOperationStart()
107 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
109 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
111 connect(anOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
112 connect(aPreviewOp, SIGNAL(visualizePreview(bool)), this, SLOT(onVisualizePreview(bool)));
113 connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
114 aPreviewOp, SLOT(onViewSelectionChanged()));
118 void PartSet_Module::onOperationStopped()
120 ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(sender());
124 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
126 disconnect(aPreviewOp, SIGNAL(visualizePreview(bool)), this, SLOT(onVisualizePreview(bool)));
127 disconnect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
128 aPreviewOp, SLOT(onViewSelectionChanged()));