]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_Operation.cpp
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.cpp
1 /*
2  * ModuleBase_Operation.cpp
3  *
4  *  Created on: May 5, 2014
5  *      Author: nds
6  */
7
8 #include "ModuleBase_Operation.h"
9
10 #include "ModuleBase_OperationDescription.h"
11 #include "ModuleBase_WidgetCustom.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_PluginManager.h>
18 #include <ModelAPI_Document.h>
19
20 #ifdef _DEBUG
21 #include <QDebug>
22 #endif
23
24 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
25 : ModuleBase_IOperation(theId, theParent)
26 {
27 }
28
29 ModuleBase_Operation::~ModuleBase_Operation()
30 {
31 }
32
33 boost::shared_ptr<ModelAPI_Feature> ModuleBase_Operation::feature() const
34 {
35   return myFeature;
36 }
37
38 void ModuleBase_Operation::storeReal(double theValue)
39 {
40   if(!myFeature){
41     #ifdef _DEBUG
42     qDebug() << "ModuleBase_Operation::storeReal: " <<
43         "trying to store value without opening a transaction.";
44     #endif
45     return;
46   }
47   QString anId = sender()->objectName();
48   boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
49   boost::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(anId.toStdString());
50   aReal->setValue(theValue);
51 }
52
53 void ModuleBase_Operation::storeCustomValue()
54 {
55   if(!myFeature){
56     #ifdef _DEBUG
57     qDebug() << "ModuleBase_Operation::storeCustom: " <<
58         "trying to store value without opening a transaction.";
59     #endif
60     return;
61   }
62
63   ModuleBase_WidgetCustom* aCustom = dynamic_cast<ModuleBase_WidgetCustom*>(sender());
64   if (aCustom)
65     aCustom->store(myFeature);
66 }
67
68 void ModuleBase_Operation::startOperation()
69 {
70   boost::shared_ptr<ModelAPI_Document> aDoc = ModelAPI_PluginManager::get()->rootDocument();
71   myFeature = aDoc->addFeature(getDescription()->operationId().toStdString());
72   if (myFeature) // TODO: generate an error if feature was not created
73     myFeature->execute();
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 }