]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_Operation.cpp
Salome HOME
Implementation of mechanism of grouping of messages
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.cpp
1 /*
2  * ModuleBase_Operation.cpp
3  *
4  *  Created on: Apr 2, 2014
5  *      Author: sbh
6  */
7
8 #include "ModuleBase_Operation.h"
9
10 #include "ModuleBase_OperationDescription.h"
11 #include "ModuleBase_ModelWidget.h"
12
13 #include <ModelAPI_AttributeDouble.h>
14 #include <ModelAPI_Document.h>
15 #include <ModelAPI_Feature.h>
16 #include <ModelAPI_Data.h>
17 #include <ModelAPI_Document.h>
18 #include <Model_Events.h>
19
20 #include <Events_Loop.h>
21
22 #ifdef _DEBUG
23 #include <QDebug>
24 #endif
25
26 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
27 : ModuleBase_IOperation(theId, theParent)
28 {
29 }
30
31 ModuleBase_Operation::~ModuleBase_Operation()
32 {
33 }
34
35 boost::shared_ptr<ModelAPI_Feature> ModuleBase_Operation::feature() const
36 {
37   return myFeature;
38 }
39
40 void ModuleBase_Operation::storeReal(double theValue)
41 {
42   if(!myFeature){
43     #ifdef _DEBUG
44     qDebug() << "ModuleBase_Operation::storeReal: " <<
45         "trying to store value without opening a transaction.";
46     #endif
47     return;
48   }
49   QString anId = sender()->objectName();
50   boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
51   boost::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(anId.toStdString());
52   aReal->setValue(theValue);
53   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
54 }
55
56 void ModuleBase_Operation::storeCustomValue()
57 {
58   if(!myFeature){
59     #ifdef _DEBUG
60     qDebug() << "ModuleBase_Operation::storeCustom: " <<
61         "trying to store value without opening a transaction.";
62     #endif
63     return;
64   }
65
66   ModuleBase_ModelWidget* aCustom = dynamic_cast<ModuleBase_ModelWidget*>(sender());
67   if (aCustom)
68     aCustom->storeValue(myFeature);
69 }
70
71 void ModuleBase_Operation::startOperation()
72 {
73   setFeature(createFeature());
74   //emit callSlot();
75   //commit();
76 }
77
78 void ModuleBase_Operation::stopOperation()
79 {
80 }
81
82 void ModuleBase_Operation::abortOperation()
83 {
84 }
85
86 void ModuleBase_Operation::commitOperation()
87 {
88   if (myFeature) myFeature->execute();
89 }
90
91 void ModuleBase_Operation::flushUpdated()
92 {
93   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
94 }
95
96 void ModuleBase_Operation::flushCreated()
97 {
98   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_CREATED));
99 }
100
101 boost::shared_ptr<ModelAPI_Feature> ModuleBase_Operation::createFeature(const bool theFlushMessage)
102 {
103   boost::shared_ptr<ModelAPI_Document> aDoc = document();
104   boost::shared_ptr<ModelAPI_Feature> aFeature = aDoc->addFeature(
105                                            getDescription()->operationId().toStdString());
106   if (aFeature) // TODO: generate an error if feature was not created
107     aFeature->execute();
108
109   if (theFlushMessage)
110     flushCreated();
111   return aFeature;
112 }
113
114 void ModuleBase_Operation::setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature)
115 {
116   myFeature = theFeature;
117 }