]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Module.cpp
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
[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 = new Config_ModuleReader();
47   aXMLReader->setAutoImport(true);
48   aXMLReader->readAll();
49   delete aXMLReader;
50 }
51
52 void PartSet_Module::featureCreated(XGUI_Command* theFeature)
53 {
54   QString aFtId = theFeature->id();
55   theFeature->connectTo(this, SLOT(onFeatureTriggered()));
56 }
57
58 void PartSet_Module::onFeatureTriggered()
59 {
60   Config_ModuleReader aModuleReader = Config_ModuleReader();
61   aModuleReader.readAll();
62   std::map<std::string, std::string> aPluginMap = aModuleReader.plugins();
63   std::string aPluginName = aPluginMap["PartSetPlugin"];
64   Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginName);
65   aWdgReader.readAll();
66   XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
67   QString aCmdId = aCmd->id();
68   std::string aXmlCfg = aWdgReader.featureWidgetCfg(aCmdId.toStdString());
69   std::string aDescription = aWdgReader.featureDescription(aCmdId.toStdString());
70   //TODO(sbh): Implement static method to extract event id [SEID]
71   static Event_ID aModuleEvent = Event_Loop::eventByName("PartSetModuleEvent");
72   Config_PointerMessage aMessage(aModuleEvent, this);
73   ModuleBase_PropPanelOperation* aPartSetOp;
74   if (aCmdId == "Sketch" )
75     aPartSetOp = new PartSet_OperationSketch(aCmdId, this);
76   else
77     aPartSetOp = new ModuleBase_PropPanelOperation(aCmdId, this);
78
79   aPartSetOp->setXmlRepresentation(QString::fromStdString(aXmlCfg));
80   aPartSetOp->setDescription(QString::fromStdString(aDescription));
81   aMessage.setPointer(aPartSetOp);
82   Event_Loop::loop()->send(aMessage);
83 }
84
85 /**
86  * Slot that is called by the operation requiring of preview display or erase
87  * \param isDisplay the display or erase state
88 */
89 void PartSet_Module::onVisualizePreview(bool isDisplay)
90 {
91   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
92   if (!anOperation)
93     return;
94
95   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
96   if (!aPreviewOp)
97     return;
98
99   if (isDisplay)
100     myWorkshop->displayer()->Display(anOperation->feature(), aPreviewOp->preview());
101   else
102     myWorkshop->displayer()->Erase(anOperation->feature(), aPreviewOp->preview());
103 }
104
105 void PartSet_Module::onBeforeOperationStart()
106 {
107   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
108
109   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
110   if (aPreviewOp) {
111     connect(anOperation, SIGNAL(stopped()), this, SLOT(onOperationStopped()));
112     connect(aPreviewOp, SIGNAL(visualizePreview(bool)), this, SLOT(onVisualizePreview(bool)));
113     connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
114             aPreviewOp, SLOT(onViewSelectionChanged()));
115   }
116 }
117
118 void PartSet_Module::onOperationStopped()
119 {
120   ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(sender());
121   if (!anOperation)
122     return;
123
124   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
125   if (aPreviewOp) {
126     disconnect(aPreviewOp, SIGNAL(visualizePreview(bool)), this, SLOT(onVisualizePreview(bool)));
127     disconnect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
128                aPreviewOp, SLOT(onViewSelectionChanged()));
129   }
130 }