Salome HOME
refs #30 - Sketch base GUI: create, draw lines
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.cpp
index 3c052e4753a131cc4167540f49b7daa3c1e8a3af..d5a0ce993ebb9c9e6bd49deeb7a00da8c59ba640 100644 (file)
@@ -7,6 +7,8 @@
 
 #include "ModuleBase_Operation.h"
 
+#include "ModuleBase_WidgetCustom.h"
+
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Feature.h>
@@ -54,7 +56,7 @@ QString ModuleBase_Operation::operationId() const
   return myOperationId;
 }
 
-std::shared_ptr<ModelAPI_Feature> ModuleBase_Operation::feature() const
+boost::shared_ptr<ModelAPI_Feature> ModuleBase_Operation::feature() const
 {
   return myFeature;
 }
@@ -100,7 +102,7 @@ bool ModuleBase_Operation::isValid(ModuleBase_Operation*) const
  * \return Returns TRUE if current operation must not be checked for ActiveOperation->IsValid( this )
  *
  * This method must be redefined in derived operation if operation of derived class
- * must be always can start above any launched one. Default implementation returns FALSE,
+ * must be always can start above any launched one. Default impl returns FALSE,
  * so it is being checked for IsValid, but some operations may overload IsGranted()
  * In this case they will always start, no matter what operation is running.
  */
@@ -112,7 +114,7 @@ bool ModuleBase_Operation::isGranted() const
 /*
  * Returns pointer to the root document.
  */
-std::shared_ptr<ModelAPI_Document> ModuleBase_Operation::document() const
+boost::shared_ptr<ModelAPI_Document> ModuleBase_Operation::document() const
 {
   return ModelAPI_PluginManager::get()->rootDocument();
 }
@@ -194,6 +196,19 @@ void ModuleBase_Operation::start()
   emit started();
 }
 
+/*!
+ * \brief Resumes operation
+ *
+ * Public slot. Verifies whether operation can be started and starts operation.
+ * This slot is not virtual and cannot be redefined. Redefine startOperation method
+ * to change behavior of operation. There is no point in using this method. It would
+ * be better to inherit own operator from base one and redefine startOperation method
+ * instead.
+ */
+void ModuleBase_Operation::resume()
+{
+}
+
 /*!
  * \brief Aborts operation
  *
@@ -259,16 +274,37 @@ void ModuleBase_Operation::storeReal(double theValue)
     return;
   }
   QString anId = sender()->objectName();
-  std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
-  std::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(anId.toStdString());
+  boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(anId.toStdString());
   aReal->setValue(theValue);
 }
 
+/*!
+ * \brief Stores a real value in model.
+ * \param theValue - to store
+ *
+ * Public slot. Passes theValue into the model.
+ */
+void ModuleBase_Operation::storeCustomValue()
+{
+  if(!myFeature){
+    #ifdef _DEBUG
+    qDebug() << "ModuleBase_Operation::storeCustom: " <<
+        "trying to store value without opening a transaction.";
+    #endif
+    return;
+  }
+
+  ModuleBase_WidgetCustom* aCustom = dynamic_cast<ModuleBase_WidgetCustom*>(sender());
+  if (aCustom)
+    aCustom->store(myFeature);
+}
+
 /*!
  * \brief Verifies whether operator is ready to start.
  * \return TRUE if operation is ready to start
  *
- * Default implementation returns TRUE. Redefine this method to add own verifications
+ * Default impl returns TRUE. Redefine this method to add own verifications
  */
 bool ModuleBase_Operation::isReadyToStart() const
 {
@@ -279,11 +315,11 @@ bool ModuleBase_Operation::isReadyToStart() const
  * \brief Virtual method called when operation is started
  *
  * Virtual method called when operation started (see start() method for more description)
- * Default implementation calls corresponding slot and commits immediately.
+ * Default impl calls corresponding slot and commits immediately.
  */
 void ModuleBase_Operation::startOperation()
 {
-  std::shared_ptr<ModelAPI_Document> aDoc = ModelAPI_PluginManager::get()->rootDocument();
+  boost::shared_ptr<ModelAPI_Document> aDoc = ModelAPI_PluginManager::get()->rootDocument();
   myFeature = aDoc->addFeature(myOperationId.toStdString());
   if (myFeature) // TODO: generate an error if feature was not created
     myFeature->execute();