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_SelectionMgr.h>
16 #include <XGUI_ViewPort.h>
17 #include <XGUI_ActionsMgr.h>
19 #include <Config_PointerMessage.h>
20 #include <Config_ModuleReader.h>
21 #include <Config_WidgetReader.h>
22 #include <Events_Loop.h>
23 #include <Events_Message.h>
24 #include <Events_Error.h>
26 #include <GeomAPI_Shape.h>
28 #include <AIS_ListOfInteractive.hxx>
31 #include <QMouseEvent>
39 /*!Create and return new instance of XGUI_Module*/
40 extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop)
42 return new PartSet_Module(theWshop);
45 PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
47 myWorkshop = theWshop;
48 myListener = new PartSet_Listener(this);
50 XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
52 connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
53 connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
54 this, SLOT(onOperationStopped(ModuleBase_Operation*)));
55 if (!myWorkshop->isSalomeMode()) {
56 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
57 connect(aViewer, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
58 connect(aViewer, SIGNAL(mouseRelease(XGUI_ViewWindow*, QMouseEvent*)),
59 this, SLOT(onMouseReleased(XGUI_ViewWindow*, QMouseEvent*)));
60 connect(aViewer, SIGNAL(mouseMove(XGUI_ViewWindow*, QMouseEvent*)),
61 this, SLOT(onMouseMoved(XGUI_ViewWindow*, QMouseEvent*)));
62 connect(aViewer, SIGNAL(keyRelease(XGUI_ViewWindow*, QKeyEvent*)),
63 this, SLOT(onKeyRelease(XGUI_ViewWindow*, QKeyEvent*)));
67 PartSet_Module::~PartSet_Module()
71 void PartSet_Module::createFeatures()
73 Config_ModuleReader aXMLReader = Config_ModuleReader();
75 myFeaturesInFiles = aXMLReader.featuresInFiles();
78 void PartSet_Module::featureCreated(XGUI_Command* theFeature)
80 theFeature->connectTo(this, SLOT(onFeatureTriggered()));
83 QStringList PartSet_Module::nestedFeatures(QString)
88 std::string PartSet_Module::featureFile(const std::string& theFeatureId)
90 return myFeaturesInFiles[theFeatureId];
96 void PartSet_Module::onFeatureTriggered()
98 XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
99 //Do nothing on uncheck
100 if(aCmd->isCheckable() && !aCmd->isChecked())
102 launchOperation(aCmd->id());
105 void PartSet_Module::launchOperation(const QString& theCmdId)
107 std::string aStdCmdId = theCmdId.toStdString();
108 std::string aPluginFileName = featureFile(aStdCmdId);
109 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
110 aWdgReader.readAll();
111 std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId);
112 std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
113 ModuleBase_PropPanelOperation* aPartSetOp;
114 if (theCmdId == "Sketch" ) {
115 aPartSetOp = new PartSet_OperationSketch(theCmdId, this);
117 else if(theCmdId == "SketchLine") {
118 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
119 boost::shared_ptr<ModelAPI_Feature> aSketchFeature;
121 aSketchFeature = anOperation->feature();
122 aPartSetOp = new PartSet_OperationSketchLine(theCmdId, this, aSketchFeature);
125 aPartSetOp = new ModuleBase_PropPanelOperation(theCmdId, this);
127 aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
128 aPartSetOp->setDescription(QString::fromStdString(aDescription));
130 //TODO(sbh): Implement static method to extract event id [SEID]
131 static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent");
132 Config_PointerMessage aMessage(aModuleEvent, this);
133 aMessage.setPointer(aPartSetOp);
134 Events_Loop::loop()->send(aMessage);
137 void PartSet_Module::onOperationStarted()
139 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
141 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
143 visualizePreview(aPreviewOp->feature(), true);
145 connect(aPreviewOp, SIGNAL(featureConstructed(boost::shared_ptr<ModelAPI_Feature>)),
146 this, SLOT(onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature>)));
148 PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
150 connect(aSketchOp, SIGNAL(planeSelected(double, double, double)),
151 this, SLOT(onPlaneSelected(double, double, double)));
156 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
158 ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(theOperation);
161 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
163 // visualizePreview(false);
166 void PartSet_Module::onSelectionChanged()
168 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
169 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
171 XGUI_SelectionMgr* aSelector = myWorkshop->selector();
173 NCollection_List<TopoDS_Shape> aList;
174 aSelector->selectedShapes(aList);
175 aPreviewOp->setSelectedShapes(aList);
180 void PartSet_Module::onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
182 QPoint aPoint = theEvent->pos();
183 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
184 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
186 XGUI_SelectionMgr* aSelector = myWorkshop->selector();
188 XGUI_ViewWindow* aWindow = myWorkshop->mainWindow()->viewer()->activeViewWindow();
190 Handle(V3d_View) aView3d = aWindow->viewPort()->getView();
191 if ( !aView3d.IsNull() ) {
192 gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(aPoint, aView3d);
193 aPreviewOp->mouseReleased(aPnt);
200 void PartSet_Module::onMouseMoved(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
202 QPoint aPoint = theEvent->pos();
203 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
204 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
206 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
208 XGUI_ViewWindow* aWindow = aViewer->activeViewWindow();
210 Handle(V3d_View) aView3d = aWindow->viewPort()->getView();
211 if ( !aView3d.IsNull() ) {
212 gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(aPoint, aView3d);
213 aPreviewOp->mouseMoved(aPnt);
220 void PartSet_Module::onKeyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent)
222 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
223 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
225 aPreviewOp->keyReleased(theEvent->key());
229 void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
231 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
233 aViewer->setViewProjection(theX, theY, theZ);
236 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
238 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
240 aPreviewOp->setEditMode(true);
241 visualizePreview(aPreviewOp->feature(), false);
245 myWorkshop->actionsMgr()->setNestedActionsEnabled(true);
248 void PartSet_Module::onFeatureConstructed(boost::shared_ptr<ModelAPI_Feature> theFeature)
250 visualizePreview(theFeature, true);
253 void PartSet_Module::visualizePreview(boost::shared_ptr<ModelAPI_Feature> theFeature, bool isDisplay)
255 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
259 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
263 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
265 boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview(theFeature);
267 aDisplayer->DisplayInLocalContext(theFeature, aPreview->impl<TopoDS_Shape>(),
268 aPreviewOp->getSelectionMode(theFeature));
272 aDisplayer->CloseLocalContexts(false);
273 aDisplayer->Erase(anOperation->feature());