1 #include <PartSet_Module.h>
2 #include <PartSet_OperationSketch.h>
3 #include <PartSet_OperationSketchLine.h>
5 #include <ModuleBase_Operation.h>
7 #include <XGUI_MainWindow.h>
8 #include <XGUI_Displayer.h>
9 #include <XGUI_Viewer.h>
10 #include <XGUI_Workshop.h>
11 #include <XGUI_OperationMgr.h>
13 #include <Config_PointerMessage.h>
14 #include <Config_ModuleReader.h>
15 #include <Config_WidgetReader.h>
16 #include <Events_Loop.h>
17 #include <Events_Message.h>
19 #include <GeomAPI_Shape.h>
21 #include <AIS_ListOfInteractive.hxx>
31 /*!Create and return new instance of XGUI_Module*/
32 extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop)
34 return new PartSet_Module(theWshop);
37 PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
39 myWorkshop = theWshop;
40 XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
42 connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
43 connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
44 this, SLOT(onOperationStopped(ModuleBase_Operation*)));
45 if (!myWorkshop->isSalomeMode())
46 connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
47 this, SLOT(onViewSelectionChanged()));
50 PartSet_Module::~PartSet_Module()
54 void PartSet_Module::createFeatures()
56 Config_ModuleReader aXMLReader = Config_ModuleReader();
58 myFeaturesInFiles = aXMLReader.featuresInFiles();
61 void PartSet_Module::featureCreated(XGUI_Command* theFeature)
63 theFeature->connectTo(this, SLOT(onFeatureTriggered()));
66 std::string PartSet_Module::featureFile(const std::string& theFeatureId)
68 return myFeaturesInFiles[theFeatureId];
74 void PartSet_Module::onFeatureTriggered()
76 XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
77 launchOperation(aCmd->id());
80 void PartSet_Module::launchOperation(const QString& theCmdId)
82 std::string aStdCmdId = theCmdId.toStdString();
83 std::string aPluginFileName = featureFile(aStdCmdId);
84 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
86 std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId);
87 std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
88 ModuleBase_PropPanelOperation* aPartSetOp;
89 if (theCmdId == "Sketch" ) {
90 aPartSetOp = new PartSet_OperationSketch(theCmdId, this);
92 else if(theCmdId == "SketchLine") {
93 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
94 boost::shared_ptr<ModelAPI_Feature> aSketchFeature;
96 aSketchFeature = anOperation->feature();
97 aPartSetOp = new PartSet_OperationSketchLine(theCmdId, this, aSketchFeature);
100 aPartSetOp = new ModuleBase_PropPanelOperation(theCmdId, this);
102 aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
103 aPartSetOp->setDescription(QString::fromStdString(aDescription));
105 //TODO(sbh): Implement static method to extract event id [SEID]
106 static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent");
107 Config_PointerMessage aMessage(aModuleEvent, this);
108 aMessage.setPointer(aPartSetOp);
109 Events_Loop::loop()->send(aMessage);
112 void PartSet_Module::onOperationStarted()
114 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
116 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
118 visualizePreview(true);
119 connect(aPreviewOp, SIGNAL(viewerProjectionChange(double, double, double)),
120 this, SLOT(onViewerProjectionChange(double, double, double)));
124 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
126 ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(theOperation);
129 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
131 visualizePreview(false);
134 void PartSet_Module::onViewSelectionChanged()
136 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
137 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
139 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
141 NCollection_List<TopoDS_Shape> aList;
142 aViewer->getSelectedShapes(aList);
143 aPreviewOp->setSelectedShapes(aList);
148 void PartSet_Module::onViewerProjectionChange(double theX, double theY, double theZ)
150 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
152 aViewer->setViewProjection(theX, theY, theZ);
156 void PartSet_Module::visualizePreview(bool isDisplay)
158 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
162 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
167 boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview();
169 myWorkshop->displayer()->LocalSelection(anOperation->feature(),
170 aPreview->impl<TopoDS_Shape>(), aPreviewOp->getSelectionMode());
173 myWorkshop->displayer()->GlobalSelection(false);
174 myWorkshop->displayer()->Erase(anOperation->feature());