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 if (!myWorkshop->isSalomeMode())
43 connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
44 this, SLOT(onViewSelectionChanged()));
47 PartSet_Module::~PartSet_Module()
51 void PartSet_Module::createFeatures()
53 Config_ModuleReader aXMLReader = Config_ModuleReader();
55 myFeaturesInFiles = aXMLReader.featuresInFiles();
58 void PartSet_Module::featureCreated(XGUI_Command* theFeature)
60 theFeature->connectTo(this, SLOT(onFeatureTriggered()));
63 std::string PartSet_Module::featureFile(const std::string& theFeatureId)
65 return myFeaturesInFiles[theFeatureId];
71 void PartSet_Module::onFeatureTriggered()
73 XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
74 launchOperation(aCmd->id());
77 void PartSet_Module::launchOperation(const QString& theCmdId)
79 std::string aStdCmdId = theCmdId.toStdString();
80 std::string aPluginFileName = featureFile(aStdCmdId);
81 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
83 std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId);
84 std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
85 ModuleBase_PropPanelOperation* aPartSetOp;
86 if (theCmdId == "Sketch" ) {
87 aPartSetOp = new PartSet_OperationSketch(theCmdId, this);
89 aPartSetOp = new ModuleBase_PropPanelOperation(theCmdId, this);
91 aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
92 aPartSetOp->setDescription(QString::fromStdString(aDescription));
94 //TODO(sbh): Implement static method to extract event id [SEID]
95 static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent");
96 Config_PointerMessage aMessage(aModuleEvent, this);
97 aMessage.setPointer(aPartSetOp);
98 Events_Loop::loop()->send(aMessage);
101 void PartSet_Module::onOperationStarted()
103 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
105 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
107 visualizePreview(true);
108 connect(aPreviewOp, SIGNAL(viewerProjectionChange(double, double, double)),
109 this, SLOT(onViewerProjectionChange(double, double, double)));
113 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
115 ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(theOperation);
118 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
120 visualizePreview(false);
123 void PartSet_Module::onViewSelectionChanged()
125 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
126 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
128 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
130 NCollection_List<TopoDS_Shape> aList;
131 aViewer->getSelectedShapes(aList);
132 aPreviewOp->setSelectedShapes(aList);
137 void PartSet_Module::onViewerProjectionChange(double theX, double theY, double theZ)
139 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
141 aViewer->setViewProjection(theX, theY, theZ);
145 void PartSet_Module::visualizePreview(bool isDisplay)
147 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
151 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
156 myWorkshop->displayer()->LocalSelection(anOperation->feature(), aPreviewOp->preview(),
157 aPreviewOp->getSelectionMode());
160 myWorkshop->displayer()->GlobalSelection(false);
161 myWorkshop->displayer()->Erase(anOperation->feature());