]> 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 <Event_Loop.h>
16 #include <Event_Message.h>
17
18 #include <QObject>
19 #include <QString>
20
21 #ifdef _DEBUG
22 #include <QDebug>
23 #endif
24
25
26 /*!Create and return new instance of XGUI_Module*/
27 extern "C" PARTSET_EXPORT XGUI_Module* createModule(XGUI_Workshop* theWshop)
28 {
29   return new PartSet_Module(theWshop);
30 }
31
32 PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
33 {
34   myWorkshop = theWshop;
35   XGUI_OperationMgr* anOperationMgr = myWorkshop->operationMgr();
36
37   connect(anOperationMgr, SIGNAL(beforeOperationStart()), this, SLOT(onBeforeOperationStart()));
38 }
39
40 PartSet_Module::~PartSet_Module()
41 {
42 }
43
44 void PartSet_Module::createFeatures()
45 {
46   Config_ModuleReader aXMLReader = Config_ModuleReader();
47   aXMLReader.setAutoImport(true);
48   aXMLReader.readAll();
49 }
50
51 void PartSet_Module::featureCreated(XGUI_Command* theFeature)
52 {
53   theFeature->connectTo(this, SLOT(onFeatureTriggered()));
54 }
55
56 std::string PartSet_Module::modulePlugin()
57 {
58   Config_ModuleReader aModuleReader = Config_ModuleReader();
59   aModuleReader.readAll();
60   std::map < std::string, std::string > aPluginMap = aModuleReader.plugins();
61   std::string aPluginName = aPluginMap["PartSetPlugin"];
62   return aPluginName;
63 }
64
65 /*
66  *
67  */
68 void PartSet_Module::onFeatureTriggered()
69 {
70   std::string aPluginName = modulePlugin();
71   Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginName);
72   aWdgReader.readAll();
73   XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
74   QString aCmdId = aCmd->id();
75   std::string aXmlCfg = aWdgReader.featureWidgetCfg(aCmdId.toStdString());
76   std::string aDescription = aWdgReader.featureDescription(aCmdId.toStdString());
77   ModuleBase_PropPanelOperation* aPartSetOp;
78   if (aCmdId == "Sketch" ) {
79     aPartSetOp = new PartSet_OperationSketch(aCmdId, this);
80   } else {
81     aPartSetOp = new ModuleBase_PropPanelOperation(aCmdId, this);
82   }
83   aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
84   aPartSetOp->setDescription(QString::fromStdString(aDescription));
85
86   //TODO(sbh): Implement static method to extract event id [SEID]
87   static Event_ID aModuleEvent = Event_Loop::eventByName("PartSetModuleEvent");
88   Config_PointerMessage aMessage(aModuleEvent, this);
89   aMessage.setPointer(aPartSetOp);
90   Event_Loop::loop()->send(aMessage);
91 }
92
93 /**
94  * Slot that is called by the operation requiring of preview display or erase
95  * \param isDisplay the display or erase state
96 */
97 void PartSet_Module::onVisualizePreview(bool isDisplay)
98 {
99   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
100   if (!anOperation)
101     return;
102
103   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
104   if (!aPreviewOp)
105     return;
106
107   if (isDisplay)
108     myWorkshop->displayer()->Display(anOperation->feature(), aPreviewOp->preview());
109   else
110     myWorkshop->displayer()->Erase(anOperation->feature(), aPreviewOp->preview());
111 }
112
113 void PartSet_Module::onBeforeOperationStart()
114 {
115   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
116
117   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
118   if (aPreviewOp) {
119     connect(anOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
120     connect(aPreviewOp, SIGNAL(visualizePreview(bool)), this, SLOT(onVisualizePreview(bool)));
121     connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
122             aPreviewOp, SLOT(onViewSelectionChanged()));
123   }
124 }
125
126 void PartSet_Module::onOperationStopped()
127 {
128   ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(sender());
129   if (!anOperation)
130     return;
131
132   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
133   if (aPreviewOp) {
134     disconnect(aPreviewOp, SIGNAL(visualizePreview(bool)), this, SLOT(onVisualizePreview(bool)));
135     disconnect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
136                aPreviewOp, SLOT(onViewSelectionChanged()));
137   }
138 }