Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[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
19 #ifdef _DEBUG
20 #include <QDebug>
21 #endif
22
23 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
24 : ModuleBase_IOperation(theId, theParent)
25 {
26 }
27
28 ModuleBase_Operation::~ModuleBase_Operation()
29 {
30 }
31
32 boost::shared_ptr<ModelAPI_Feature> ModuleBase_Operation::feature() const
33 {
34   return myFeature;
35 }
36
37 void ModuleBase_Operation::storeReal(double theValue)
38 {
39   if(!myFeature){
40     #ifdef _DEBUG
41     qDebug() << "ModuleBase_Operation::storeReal: " <<
42         "trying to store value without opening a transaction.";
43     #endif
44     return;
45   }
46   QString anId = sender()->objectName();
47   boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
48   boost::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(anId.toStdString());
49   aReal->setValue(theValue);
50 }
51
52 void ModuleBase_Operation::storeCustomValue()
53 {
54   if(!myFeature){
55     #ifdef _DEBUG
56     qDebug() << "ModuleBase_Operation::storeCustom: " <<
57         "trying to store value without opening a transaction.";
58     #endif
59     return;
60   }
61
62   ModuleBase_ModelWidget* aCustom = dynamic_cast<ModuleBase_ModelWidget*>(sender());
63   if (aCustom)
64     aCustom->storeValue(myFeature);
65 }
66
67 void ModuleBase_Operation::startOperation()
68 {
69   setFeature(createFeature());
70   //emit callSlot();
71   //commit();
72 }
73
74 void ModuleBase_Operation::stopOperation()
75 {
76 }
77
78 void ModuleBase_Operation::abortOperation()
79 {
80 }
81
82 void ModuleBase_Operation::commitOperation()
83 {
84   if (myFeature) myFeature->execute();
85 }
86
87 boost::shared_ptr<ModelAPI_Feature> ModuleBase_Operation::createFeature()
88 {
89   boost::shared_ptr<ModelAPI_Document> aDoc = document();
90   boost::shared_ptr<ModelAPI_Feature> aFeature = aDoc->addFeature(
91                                            getDescription()->operationId().toStdString());
92   if (aFeature) // TODO: generate an error if feature was not created
93     aFeature->execute();
94   return aFeature;
95 }
96
97 void ModuleBase_Operation::setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature)
98 {
99   myFeature = theFeature;
100 }