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>
18 #include <Config_PointerMessage.h>
19 #include <Config_ModuleReader.h>
20 #include <Config_WidgetReader.h>
21 #include <Events_Loop.h>
22 #include <Events_Message.h>
23 #include <Events_Error.h>
25 #include <GeomAPI_Shape.h>
27 #include <AIS_ListOfInteractive.hxx>
37 /*!Create and return new instance of XGUI_Module*/
38 extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop)
40 return new PartSet_Module(theWshop);
43 PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
45 myWorkshop = theWshop;
46 myListener = new PartSet_Listener(this);
48 XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
50 connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
51 connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
52 this, SLOT(onOperationStopped(ModuleBase_Operation*)));
53 if (!myWorkshop->isSalomeMode()) {
54 connect(myWorkshop->mainWindow()->viewer(), SIGNAL(mouseReleased(QPoint)),
55 this, SLOT(onMouseReleased(QPoint)));
56 connect(myWorkshop->mainWindow()->viewer(), SIGNAL(mouseMoved(QPoint)),
57 this, SLOT(onMouseMoved(QPoint)));
61 PartSet_Module::~PartSet_Module()
65 void PartSet_Module::createFeatures()
67 Config_ModuleReader aXMLReader = Config_ModuleReader();
69 myFeaturesInFiles = aXMLReader.featuresInFiles();
72 void PartSet_Module::featureCreated(XGUI_Command* theFeature)
74 theFeature->connectTo(this, SLOT(onFeatureTriggered()));
77 QStringList PartSet_Module::nestedFeatures(QString)
82 std::string PartSet_Module::featureFile(const std::string& theFeatureId)
84 return myFeaturesInFiles[theFeatureId];
90 void PartSet_Module::onFeatureTriggered()
92 XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
93 //Do nothing on uncheck
94 if(aCmd->isCheckable() && !aCmd->isChecked())
96 launchOperation(aCmd->id());
99 void PartSet_Module::launchOperation(const QString& theCmdId)
101 std::string aStdCmdId = theCmdId.toStdString();
102 std::string aPluginFileName = featureFile(aStdCmdId);
103 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
104 aWdgReader.readAll();
105 std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId);
106 std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
107 ModuleBase_PropPanelOperation* aPartSetOp;
108 if (theCmdId == "Sketch" ) {
109 aPartSetOp = new PartSet_OperationSketch(theCmdId, this);
111 else if(theCmdId == "SketchLine") {
112 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
113 boost::shared_ptr<ModelAPI_Feature> aSketchFeature;
115 aSketchFeature = anOperation->feature();
116 aPartSetOp = new PartSet_OperationSketchLine(theCmdId, this, aSketchFeature);
119 aPartSetOp = new ModuleBase_PropPanelOperation(theCmdId, this);
121 aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
122 aPartSetOp->setDescription(QString::fromStdString(aDescription));
124 //TODO(sbh): Implement static method to extract event id [SEID]
125 static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent");
126 Config_PointerMessage aMessage(aModuleEvent, this);
127 aMessage.setPointer(aPartSetOp);
128 Events_Loop::loop()->send(aMessage);
131 void PartSet_Module::onOperationStarted()
133 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
135 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
137 visualizePreview(true);
138 connect(aPreviewOp, SIGNAL(viewerProjectionChange(double, double, double)),
139 this, SLOT(onViewerProjectionChange(double, double, double)));
143 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
145 ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(theOperation);
148 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
150 visualizePreview(false);
153 void PartSet_Module::onMouseReleased(QPoint thePoint)
155 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
156 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
158 XGUI_SelectionMgr* aSelector = myWorkshop->selector();
160 NCollection_List<TopoDS_Shape> aList;
161 aSelector->selectedShapes(aList);
162 XGUI_ViewWindow* aWindow = myWorkshop->mainWindow()->viewer()->activeViewWindow();
164 Handle(V3d_View) aView3d = aWindow->viewPort()->getView();
165 if ( !aView3d.IsNull() ) {
166 gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(thePoint, aView3d);
167 aPreviewOp->setSelectedShapes(aList, aPoint);
174 void PartSet_Module::onMouseMoved(QPoint thePoint)
176 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
177 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
179 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
181 XGUI_ViewWindow* aWindow = aViewer->activeViewWindow();
183 Handle(V3d_View) aView3d = aWindow->viewPort()->getView();
184 if ( !aView3d.IsNull() ) {
185 gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(thePoint, aView3d);
186 aPreviewOp->setMouseMovePoint(aPoint);
193 void PartSet_Module::onViewerProjectionChange(double theX, double theY, double theZ)
195 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
197 aViewer->setViewProjection(theX, theY, theZ);
201 void PartSet_Module::visualizePreview(bool isDisplay)
203 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
207 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
211 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
213 boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview();
215 aDisplayer->LocalSelection(anOperation->feature(),
216 aPreview->impl<TopoDS_Shape>(), aPreviewOp->getSelectionMode());
220 aDisplayer->GlobalSelection(false);
221 aDisplayer->Erase(anOperation->feature());