]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Module.cpp
Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / PartSet / PartSet_Module.cpp
1 #include <PartSet_Module.h>
2 #include <PartSet_OperationSketch.h>
3
4 #include <ModuleBase_Operation.h>
5
6 #include <XGUI_MainWindow.h>
7 #include <XGUI_Displayer.h>
8 #include <XGUI_Viewer.h>
9 #include <XGUI_Workshop.h>
10 #include <XGUI_OperationMgr.h>
11
12 #include <Config_PointerMessage.h>
13 #include <Config_ModuleReader.h>
14 #include <Config_WidgetReader.h>
15 #include <Events_Loop.h>
16 #include <Events_Message.h>
17
18 #include <AIS_ListOfInteractive.hxx>
19
20 #include <QObject>
21 #include <QString>
22
23 #ifdef _DEBUG
24 #include <QDebug>
25 #endif
26
27
28 /*!Create and return new instance of XGUI_Module*/
29 extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop)
30 {
31   return new PartSet_Module(theWshop);
32 }
33
34 PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
35 {
36   myWorkshop = theWshop;
37   XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
38
39   connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
40   connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
41           this, SLOT(onOperationStopped(ModuleBase_Operation*)));
42   connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
43           this, SLOT(onViewSelectionChanged()));
44 }
45
46 PartSet_Module::~PartSet_Module()
47 {
48 }
49
50 void PartSet_Module::createFeatures()
51 {
52   Config_ModuleReader aXMLReader = Config_ModuleReader();
53   aXMLReader.readAll();
54   myFeaturesInFiles = aXMLReader.featuresInFiles();
55 }
56
57 void PartSet_Module::featureCreated(XGUI_Command* theFeature)
58 {
59   theFeature->connectTo(this, SLOT(onFeatureTriggered()));
60 }
61
62 std::string PartSet_Module::featureFile(const std::string& theFeatureId)
63 {
64   return myFeaturesInFiles[theFeatureId];
65 }
66
67 /*
68  *
69  */
70 void PartSet_Module::onFeatureTriggered()
71 {
72   XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
73   QString aCmdId = aCmd->id();
74   std::string aStdCmdId = aCmdId.toStdString();
75   std::string aPluginFileName = featureFile(aStdCmdId);
76   Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName);
77   aWdgReader.readAll();
78   std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId);
79   std::string aDescription = aWdgReader.featureDescription(aStdCmdId);
80   ModuleBase_PropPanelOperation* aPartSetOp;
81   if (aCmdId == "Sketch" ) {
82     aPartSetOp = new PartSet_OperationSketch(aCmdId, this);
83   } else {
84     aPartSetOp = new ModuleBase_PropPanelOperation(aCmdId, this);
85   }
86   aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
87   aPartSetOp->setDescription(QString::fromStdString(aDescription));
88
89   //TODO(sbh): Implement static method to extract event id [SEID]
90   static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent");
91   Config_PointerMessage aMessage(aModuleEvent, this);
92   aMessage.setPointer(aPartSetOp);
93   Events_Loop::loop()->send(aMessage);
94 }
95
96 void PartSet_Module::onOperationStarted()
97 {
98   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
99
100   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
101   if (aPreviewOp)
102     visualizePreview(true);
103 }
104
105 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
106 {
107   ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(theOperation);
108   if (!anOperation)
109     return;
110   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
111   if (aPreviewOp)
112     visualizePreview(false);
113 }
114
115 void PartSet_Module::onViewSelectionChanged()
116 {
117   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
118   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
119   if (aPreviewOp) {
120     XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
121     if (aViewer) {
122       AIS_ListOfInteractive aList;
123       aViewer->getSelectedObjects(aList);
124       aPreviewOp->setSelectedObjects(aList);
125     }
126   }
127 }
128
129 void PartSet_Module::visualizePreview(bool isDisplay)
130 {
131   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
132   if (!anOperation)
133     return;
134
135   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
136   if (!aPreviewOp)
137     return;
138
139   if (isDisplay) {
140     myWorkshop->displayer()->LocalSelection(anOperation->feature(), aPreviewOp->preview(),
141                                             aPreviewOp->getSelectionMode());
142   }
143   else {
144     myWorkshop->displayer()->GlobalSelection(false);
145     myWorkshop->displayer()->Erase(anOperation->feature(), aPreviewOp->preview());
146   }
147 }