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 QStringList PartSet_Module::nestedFeatures(QString)
71 std::string PartSet_Module::featureFile(const std::string& theFeatureId)
73 return myFeaturesInFiles[theFeatureId];
79 void PartSet_Module::onFeatureTriggered()
81 XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
82 //Do nothing on uncheck
83 if(aCmd->isCheckable() && !aCmd->isChecked())
85 launchOperation(aCmd->id());
88 void PartSet_Module::launchOperation(const QString& theCmdId)
90 std::string aStdCmdId = theCmdId.toStdString();
91 std::string aPluginFileName = featureFile(aStdCmdId);
92 Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
94 std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId);
95 std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
96 ModuleBase_PropPanelOperation* aPartSetOp;
97 if (theCmdId == "Sketch" ) {
98 aPartSetOp = new PartSet_OperationSketch(theCmdId, this);
100 else if(theCmdId == "SketchLine") {
101 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
102 boost::shared_ptr<ModelAPI_Feature> aSketchFeature;
104 aSketchFeature = anOperation->feature();
105 aPartSetOp = new PartSet_OperationSketchLine(theCmdId, this, aSketchFeature);
108 aPartSetOp = new ModuleBase_PropPanelOperation(theCmdId, this);
110 aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
111 aPartSetOp->setDescription(QString::fromStdString(aDescription));
113 //TODO(sbh): Implement static method to extract event id [SEID]
114 static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent");
115 Config_PointerMessage aMessage(aModuleEvent, this);
116 aMessage.setPointer(aPartSetOp);
117 Events_Loop::loop()->send(aMessage);
120 void PartSet_Module::onOperationStarted()
122 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
124 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
126 visualizePreview(true);
127 connect(aPreviewOp, SIGNAL(viewerProjectionChange(double, double, double)),
128 this, SLOT(onViewerProjectionChange(double, double, double)));
132 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
134 ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(theOperation);
137 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
139 visualizePreview(false);
142 void PartSet_Module::onViewSelectionChanged()
144 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
145 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
147 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
149 NCollection_List<TopoDS_Shape> aList;
150 aViewer->getSelectedShapes(aList);
151 aPreviewOp->setSelectedShapes(aList);
156 void PartSet_Module::onViewerProjectionChange(double theX, double theY, double theZ)
158 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
160 aViewer->setViewProjection(theX, theY, theZ);
164 void PartSet_Module::visualizePreview(bool isDisplay)
166 ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
170 PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
175 boost::shared_ptr<GeomAPI_Shape> aPreview = aPreviewOp->preview();
177 myWorkshop->displayer()->LocalSelection(anOperation->feature(),
178 aPreview->impl<TopoDS_Shape>(), aPreviewOp->getSelectionMode());
181 myWorkshop->displayer()->GlobalSelection(false);
182 myWorkshop->displayer()->Erase(anOperation->feature());