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>
18 #include <AIS_ListOfInteractive.hxx>
28 /*!Create and return new instance of XGUI_Module*/
29 extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop)
31 return new PartSet_Module(theWshop);
34 PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
36 myWorkshop = theWshop;
37 XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
39 connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
40 connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
41 this, SLOT(onOperationStopped(ModuleBase_Operation*)));
42 connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
43 this, SLOT(onViewSelectionChanged()));
46 PartSet_Module::~PartSet_Module()
50 void PartSet_Module::createFeatures()
52 Config_ModuleReader aXMLReader = Config_ModuleReader();
54 myFeaturesInFiles = aXMLReader.featuresInFiles();
57 void PartSet_Module::featureCreated(XGUI_Command* theFeature)
59 theFeature->connectTo(this, SLOT(onFeatureTriggered()));
62 std::string PartSet_Module::featureFile(const std::string& theFeatureId)
64 return myFeaturesInFiles[theFeatureId];
70 void PartSet_Module::onFeatureTriggered()
72 XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
73 QString aCmdId = aCmd->id();
74 std::string aStdCmdId = aCmdId.toStdString();
75 std::string aPluginFileName = featureFile(aStdCmdId);
76 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
78 std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId);
79 std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
80 ModuleBase_PropPanelOperation* aPartSetOp;
81 if (aCmdId == "Sketch" ) {
82 aPartSetOp = new PartSet_OperationSketch(aCmdId, this);
84 aPartSetOp = new ModuleBase_PropPanelOperation(aCmdId, this);
86 aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
87 aPartSetOp->setDescription(QString::fromStdString(aDescription));
89 //TODO(sbh): Implement static method to extract event id [SEID]
90 static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent");
91 Config_PointerMessage aMessage(aModuleEvent, this);
92 aMessage.setPointer(aPartSetOp);
93 Events_Loop::loop()->send(aMessage);
96 void PartSet_Module::onOperationStarted()
98 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
100 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
102 visualizePreview(true);
105 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
107 ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(theOperation);
110 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
112 visualizePreview(false);
115 void PartSet_Module::onViewSelectionChanged()
117 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
118 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
120 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
122 AIS_ListOfInteractive aList;
123 aViewer->getSelectedObjects(aList);
124 aPreviewOp->setSelectedObjects(aList);
129 void PartSet_Module::visualizePreview(bool isDisplay)
131 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
135 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
140 myWorkshop->displayer()->LocalSelection(anOperation->feature(), aPreviewOp->preview(),
141 aPreviewOp->getSelectionMode());
144 myWorkshop->displayer()->GlobalSelection(false);
145 myWorkshop->displayer()->Erase(anOperation->feature(), aPreviewOp->preview());