Salome HOME
refs #30 - Sketch base GUI: create, draw lines
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.cpp
index 9def6b185607c528fcff46672bad7f21df07ecef..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,6 +56,11 @@ QString ModuleBase_Operation::operationId() const
   return myOperationId;
 }
 
+boost::shared_ptr<ModelAPI_Feature> ModuleBase_Operation::feature() const
+{
+  return myFeature;
+}
+
 /*!
  * \brief Gets state of operation
  * \return Value from OperationState enumeration
@@ -95,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.
  */
@@ -107,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();
 }
@@ -171,28 +178,6 @@ int ModuleBase_Operation::execStatus() const
   return myExecStatus;
 }
 
-/*!
- *  \brief Returns XML representation of the operation's widget.
- *  \return XML QString
- *
- *  Returns XML representation of the operation's widget.
- */
-const QString& ModuleBase_Operation::xmlRepresentation() const
-{
-  return myXmlRepr;
-}
-
-/*!
- *  \brief Sets XML representation of the operation's widget.
- *  \param xmlRepr - XML QString
- *
- *  Sets XML representation of the operation's widget.
- */
-void ModuleBase_Operation::setXmlRepresentation(const QString& xmlRepr)
-{
-  myXmlRepr = xmlRepr;
-}
-
 /*!
  * \brief Starts operation
  *
@@ -211,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
  *
@@ -224,9 +222,9 @@ void ModuleBase_Operation::abort()
   emit aborted();
 
   stopOperation();
-  emit stopped();
 
   document()->abortOperation();
+  emit stopped();
 }
 
 /*!
@@ -242,9 +240,22 @@ void ModuleBase_Operation::commit()
   emit committed();
 
   stopOperation();
-  emit stopped();
 
   document()->finishOperation();
+  emit stopped();
+}
+
+/*
+ * \brief Alias for start/abort slots
+ *
+ * Public slot. Aborts operation if false, else does nothing.
+ * Provided for S/S compatibility with QAction's toggle(bool)
+ */
+void ModuleBase_Operation::setRunning(bool on)
+{
+  if (!on) {
+    abort();
+  }
 }
 
 /*!
@@ -263,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
 {
@@ -283,13 +315,14 @@ 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());
-  myFeature->execute();
+  if (myFeature) // TODO: generate an error if feature was not created
+    myFeature->execute();
   //emit callSlot();
   //commit();
 }
@@ -319,7 +352,7 @@ void ModuleBase_Operation::abortOperation()
  */
 void ModuleBase_Operation::commitOperation()
 {
-  myFeature->execute();
+  if (myFeature) myFeature->execute();
 }
 
 /*!