1 #include <PartSet_Module.h>
2 #include <PartSet_OperationSketch.h>
3 #include <PartSet_OperationSketchLine.h>
4 #include <PartSet_Listener.h>
5 #include <PartSet_Tools.h>
7 #include <ModuleBase_Operation.h>
9 #include <XGUI_MainWindow.h>
10 #include <XGUI_Displayer.h>
11 #include <XGUI_Viewer.h>
12 #include <XGUI_Workshop.h>
13 #include <XGUI_OperationMgr.h>
14 #include <XGUI_ViewWindow.h>
15 #include <XGUI_ViewPort.h>
17 #include <Config_PointerMessage.h>
18 #include <Config_ModuleReader.h>
19 #include <Config_WidgetReader.h>
20 #include <Events_Loop.h>
21 #include <Events_Message.h>
22 #include <Events_Error.h>
24 #include <GeomAPI_Shape.h>
26 #include <AIS_ListOfInteractive.hxx>
36 /*!Create and return new instance of XGUI_Module*/
37 extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop)
39 return new PartSet_Module(theWshop);
42 PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
44 myWorkshop = theWshop;
45 myListener = new PartSet_Listener(this);
47 XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
49 connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
50 connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
51 this, SLOT(onOperationStopped(ModuleBase_Operation*)));
52 if (!myWorkshop->isSalomeMode()) {
53 connect(myWorkshop->mainWindow()->viewer(), SIGNAL(mouseReleased(QPoint)),
54 this, SLOT(onMouseReleased(QPoint)));
55 connect(myWorkshop->mainWindow()->viewer(), SIGNAL(mouseMoved(QPoint)),
56 this, SLOT(onMouseMoved(QPoint)));
60 PartSet_Module::~PartSet_Module()
64 void PartSet_Module::createFeatures()
66 Config_ModuleReader aXMLReader = Config_ModuleReader();
68 myFeaturesInFiles = aXMLReader.featuresInFiles();
71 void PartSet_Module::featureCreated(XGUI_Command* theFeature)
73 theFeature->connectTo(this, SLOT(onFeatureTriggered()));
76 QStringList PartSet_Module::nestedFeatures(QString)
81 std::string PartSet_Module::featureFile(const std::string& theFeatureId)
83 return myFeaturesInFiles[theFeatureId];
89 void PartSet_Module::onFeatureTriggered()
91 XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
92 //Do nothing on uncheck
93 if(aCmd->isCheckable() && !aCmd->isChecked())
95 launchOperation(aCmd->id());
98 void PartSet_Module::launchOperation(const QString& theCmdId)
100 std::string aStdCmdId = theCmdId.toStdString();
101 std::string aPluginFileName = featureFile(aStdCmdId);
102 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
103 aWdgReader.readAll();
104 std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId);
105 std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
106 ModuleBase_PropPanelOperation* aPartSetOp;
107 if (theCmdId == "Sketch" ) {
108 aPartSetOp = new PartSet_OperationSketch(theCmdId, this);
110 else if(theCmdId == "SketchLine") {
111 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
112 boost::shared_ptr<ModelAPI_Feature> aSketchFeature;
114 aSketchFeature = anOperation->feature();
115 aPartSetOp = new PartSet_OperationSketchLine(theCmdId, this, aSketchFeature);
118 aPartSetOp = new ModuleBase_PropPanelOperation(theCmdId, this);
120 aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
121 aPartSetOp->setDescription(QString::fromStdString(aDescription));
123 //TODO(sbh): Implement static method to extract event id [SEID]
124 static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent");
125 Config_PointerMessage aMessage(aModuleEvent, this);
126 aMessage.setPointer(aPartSetOp);
127 Events_Loop::loop()->send(aMessage);
130 void PartSet_Module::onOperationStarted()
132 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
134 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
136 visualizePreview(true);
137 connect(aPreviewOp, SIGNAL(viewerProjectionChange(double, double, double)),
138 this, SLOT(onViewerProjectionChange(double, double, double)));
142 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
144 ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(theOperation);
147 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
149 visualizePreview(false);
152 void PartSet_Module::onMouseReleased(QPoint thePoint)
154 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
155 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
157 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
159 NCollection_List<TopoDS_Shape> aList;
160 aViewer->getSelectedShapes(aList);
161 XGUI_ViewWindow* aWindow = aViewer->activeViewWindow();
163 Handle(V3d_View) aView3d = aWindow->viewPort()->getView();
164 if ( !aView3d.IsNull() ) {
165 gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(thePoint, aView3d);
166 aPreviewOp->setSelectedShapes(aList, aPoint);
173 void PartSet_Module::onMouseMoved(QPoint thePoint)
175 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
176 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
178 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
180 XGUI_ViewWindow* aWindow = aViewer->activeViewWindow();
182 Handle(V3d_View) aView3d = aWindow->viewPort()->getView();
183 if ( !aView3d.IsNull() ) {
184 gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(thePoint, aView3d);
185 aPreviewOp->setMouseMovePoint(aPoint);
192 void PartSet_Module::onViewerProjectionChange(double theX, double theY, double theZ)
194 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
196 aViewer->setViewProjection(theX, theY, theZ);
200 void PartSet_Module::visualizePreview(bool isDisplay)
202 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
206 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
210 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
212 boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview();
214 aDisplayer->LocalSelection(anOperation->feature(),
215 aPreview->impl<TopoDS_Shape>(), aPreviewOp->getSelectionMode());
219 aDisplayer->GlobalSelection(false);
220 aDisplayer->Erase(anOperation->feature());