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*)));
65 PartSet_Module::~PartSet_Module()
69 void PartSet_Module::createFeatures()
71 Config_ModuleReader aXMLReader = Config_ModuleReader();
73 myFeaturesInFiles = aXMLReader.featuresInFiles();
76 void PartSet_Module::featureCreated(XGUI_Command* theFeature)
78 theFeature->connectTo(this, SLOT(onFeatureTriggered()));
81 QStringList PartSet_Module::nestedFeatures(QString)
86 std::string PartSet_Module::featureFile(const std::string& theFeatureId)
88 return myFeaturesInFiles[theFeatureId];
94 void PartSet_Module::onFeatureTriggered()
96 XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
97 //Do nothing on uncheck
98 if(aCmd->isCheckable() && !aCmd->isChecked())
100 launchOperation(aCmd->id());
103 void PartSet_Module::launchOperation(const QString& theCmdId)
105 std::string aStdCmdId = theCmdId.toStdString();
106 std::string aPluginFileName = featureFile(aStdCmdId);
107 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
108 aWdgReader.readAll();
109 std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId);
110 std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
111 ModuleBase_PropPanelOperation* aPartSetOp;
112 if (theCmdId == "Sketch" ) {
113 aPartSetOp = new PartSet_OperationSketch(theCmdId, this);
115 else if(theCmdId == "SketchLine") {
116 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
117 boost::shared_ptr<ModelAPI_Feature> aSketchFeature;
119 aSketchFeature = anOperation->feature();
120 aPartSetOp = new PartSet_OperationSketchLine(theCmdId, this, aSketchFeature);
123 aPartSetOp = new ModuleBase_PropPanelOperation(theCmdId, this);
125 aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
126 aPartSetOp->setDescription(QString::fromStdString(aDescription));
128 //TODO(sbh): Implement static method to extract event id [SEID]
129 static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent");
130 Config_PointerMessage aMessage(aModuleEvent, this);
131 aMessage.setPointer(aPartSetOp);
132 Events_Loop::loop()->send(aMessage);
135 void PartSet_Module::onOperationStarted()
137 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
139 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
141 visualizePreview(true);
143 PartSet_OperationSketch* aSketchOp = dynamic_cast<PartSet_OperationSketch*>(aPreviewOp);
145 connect(aSketchOp, SIGNAL(planeSelected(double, double, double)),
146 this, SLOT(onPlaneSelected(double, double, double)));
151 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
153 ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(theOperation);
156 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
158 visualizePreview(false);
161 void PartSet_Module::onSelectionChanged()
163 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
164 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
166 XGUI_SelectionMgr* aSelector = myWorkshop->selector();
168 NCollection_List<TopoDS_Shape> aList;
169 aSelector->selectedShapes(aList);
170 aPreviewOp->setSelectedShapes(aList);
175 void PartSet_Module::onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
177 QPoint aPoint = theEvent->pos();
178 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
179 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
181 XGUI_SelectionMgr* aSelector = myWorkshop->selector();
183 XGUI_ViewWindow* aWindow = myWorkshop->mainWindow()->viewer()->activeViewWindow();
185 Handle(V3d_View) aView3d = aWindow->viewPort()->getView();
186 if ( !aView3d.IsNull() ) {
187 gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(aPoint, aView3d);
188 aPreviewOp->mouseReleased(aPnt);
195 void PartSet_Module::onMouseMoved(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
197 QPoint aPoint = theEvent->pos();
198 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
199 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
201 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
203 XGUI_ViewWindow* aWindow = aViewer->activeViewWindow();
205 Handle(V3d_View) aView3d = aWindow->viewPort()->getView();
206 if ( !aView3d.IsNull() ) {
207 gp_Pnt aPnt = PartSet_Tools::ConvertClickToPoint(aPoint, aView3d);
208 aPreviewOp->mouseMoved(aPnt);
215 void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ)
217 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
219 aViewer->setViewProjection(theX, theY, theZ);
221 myWorkshop->actionsMgr()->setNestedActionsEnabled(true);
224 void PartSet_Module::visualizePreview(bool isDisplay)
226 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
230 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
234 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
236 boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview();
238 aDisplayer->LocalSelection(anOperation->feature(),
239 aPreview->impl<TopoDS_Shape>(), aPreviewOp->getSelectionMode());
243 aDisplayer->GlobalSelection(false);
244 aDisplayer->Erase(anOperation->feature());