Salome HOME
Task #267: initial implementation of errors management
authormpv <mikhail.ponikarov@opencascade.com>
Fri, 21 Nov 2014 11:24:04 +0000 (14:24 +0300)
committersbh <sergey.belash@opencascade.com>
Tue, 25 Nov 2014 08:41:32 +0000 (11:41 +0300)
17 files changed:
src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp
src/FeaturesPlugin/FeaturesPlugin_Boolean.cpp
src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp
src/FeaturesPlugin/FeaturesPlugin_Group.h
src/Model/Model_Data.cpp
src/Model/Model_Data.h
src/Model/Model_FeatureValidator.cpp
src/Model/Model_FeatureValidator.h
src/Model/Model_Update.cpp
src/Model/Model_Update.h
src/Model/Model_Validator.cpp
src/Model/Model_Validator.h
src/ModelAPI/ModelAPI_Data.h
src/ModelAPI/ModelAPI_Feature.h
src/ModelAPI/ModelAPI_FeatureValidator.h
src/ModelAPI/ModelAPI_Validator.h
src/XGUI/XGUI_PartDataModel.cpp

index 6493870df6ea6a6260f552f10576471c83837246..5a31c28f98eb19b82d795910601432a7b576c2e4 100644 (file)
@@ -9,7 +9,6 @@
 
 #include <GeomAPI_Shape.h>
 #include <Config_Common.h>
-#include <Events_Error.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
@@ -100,12 +99,9 @@ bool ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
                             anUnknownLabel);
    // Check if shape is valid
    if ( aShape.IsNull() ) {
-     std::string aShapeError = "An error occurred while importing " + theFileName + ": ";
-     aShapeError = aShapeError + std::string(anError.ToCString());
-     Events_Error::send(aShapeError, this);
- #ifdef _DEBUG
-     std::cerr << aShapeError << std::endl;
- #endif
+     const static std::string aShapeError = 
+       "An error occurred while importing " + theFileName + ": " + anError.ToCString();
+     setError(aShapeError);
      return false;
    }
   //
@@ -154,20 +150,15 @@ LibHandle ExchangePlugin_ImportFeature::loadImportPlugin(const std::string& theF
 #else
     anImportError = anImportError + std::string(dlerror());
 #endif
-    Events_Error::send(anImportError, this);
-#ifdef _DEBUG
-    std::cerr << anImportError << std::endl;
-#endif
+    setError(anImportError);
     return false;
   }
   // Test loaded plugin for existence of valid "Import" function:
   importFunctionPointer fp = (importFunctionPointer) GetProc(anImportLib, "Import");
   if (!fp) {
-    std::string aFunctionError = "No valid \"Import\" function was found in the " + aLibName;
-    Events_Error::send(aFunctionError, this);
-#ifdef _DEBUG
-    std::cerr << aFunctionError << std::endl;
-#endif
+    const static std::string aFunctionError = 
+      "No valid \"Import\" function was found in the " + aLibName;
+    setError(aFunctionError);
     UnLoadLib(anImportLib)
     return NULL;
   }
index d8b8198ed1219c4ec710785d678a2f5722c0c242..025f63babad152cdba50d96665f366cd3ae9d81f 100644 (file)
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_ResultBody.h>
 #include <GeomAlgoAPI_Boolean.h>
-#include <Events_Error.h>
 using namespace std;
-#ifdef _DEBUG
-#include <iostream>
-#include <ostream>
-#endif
 
 #define FACE 4
 #define _MODIFY_TAG 1
@@ -65,29 +60,26 @@ void FeaturesPlugin_Boolean::execute()
 
   GeomAlgoAPI_Boolean* aFeature = new GeomAlgoAPI_Boolean(anObject, aTool, aType);
   if(aFeature && !aFeature->isDone()) {
-    std::string aFeatureError = "Boolean feature: algorithm failed";  
-    Events_Error::send(aFeatureError, this);
+    static const std::string aFeatureError = "Boolean feature: algorithm failed";  
+    setError(aFeatureError);
     return;
   }
    // Check if shape is valid
   if (aFeature->shape()->isNull()) {
-    std::string aShapeError = "Boolean feature: resulting shape is Null";     
-    Events_Error::send(aShapeError, this);
-#ifdef _DEBUG
-    std::cerr << aShapeError << std::endl;
-#endif
+    static const std::string aShapeError = "Boolean feature: resulting shape is Null";     
+    setError(aShapeError);
     return;
   }
   if(!aFeature->isValid()) {
-    std::string aFeatureError = "Boolean feature: resulting shape is not valid";  
-    Events_Error::send(aFeatureError, this);
+    static const std::string aFeatureError = "Boolean feature: resulting shape is not valid";  
+    setError(aFeatureError);
     return;
   }  
   // if result of Boolean operation is same as was before it means that Boolean operation has no sence
   // and naming provides no result, so, generate an error in this case
   if (anObject->isEqual(aFeature->shape())) {
-    std::string aFeatureError = "Boolean feature: operation was not performed";  
-    Events_Error::send(aFeatureError, this);
+    static const std::string aFeatureError = "Boolean feature: operation was not performed";  
+    setError(aFeatureError);
     return;
   }
   //LoadNamingDS
index 55bc605c16f4c9f2ecdf67f510bf30268cd022a8..cebc0bb44cd024e123d796b13681fa978eba2570 100644 (file)
@@ -11,7 +11,6 @@
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeBoolean.h>
-#include <Events_Error.h>
 #include <GeomAlgoAPI_Extrusion.h>
 
 using namespace std;
@@ -19,10 +18,6 @@ using namespace std;
 #define _FIRST_TAG 2
 #define _LAST_TAG 3
 #define EDGE 6
-#ifdef _DEBUG
-#include <iostream>
-#include <ostream>
-#endif
 
 FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
 {
@@ -56,8 +51,8 @@ void FeaturesPlugin_Extrusion::execute()
       aContext = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContextRes)->shape();
   }
   if (!aContext) {
-    std::string aContextError = "The selection context is bad";
-    Events_Error::send(aContextError, this);
+    static const std::string aContextError = "The selection context is bad";
+    setError(aContextError);
     return;
   }
 
@@ -68,23 +63,20 @@ void FeaturesPlugin_Extrusion::execute()
   std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
   GeomAlgoAPI_Extrusion aFeature(aFace, aSize);
   if(!aFeature.isDone()) {
-    std::string aFeatureError = "Extrusion algorithm failed";  
-    Events_Error::send(aFeatureError, this);
+    static const std::string aFeatureError = "Extrusion algorithm failed";  
+    setError(aFeatureError);
     return;
   }
 
   // Check if shape is valid
   if (aFeature.shape()->isNull()) {
-    std::string aShapeError = "Resulting shape is Null";     
-    Events_Error::send(aShapeError, this);
-#ifdef _DEBUG
-    std::cerr << aShapeError << std::endl;
-#endif
+    static const std::string aShapeError = "Resulting shape is Null";     
+    setError(aShapeError);
     return;
   }
   if(!aFeature.isValid()) {
     std::string aFeatureError = "Warning: resulting shape is not valid";  
-    Events_Error::send(aFeatureError, this);
+    setError(aFeatureError);
     return;
   }  
   //LoadNamingDS
index 7138c1241ca0a298c6199878f6e2b658a4ea5e4c..e306842a54a46f96dbb6f3105a3ee043aa0985d8 100644 (file)
@@ -45,7 +45,7 @@ class FeaturesPlugin_Group : public ModelAPI_Feature
   FEATURESPLUGIN_EXPORT virtual void initAttributes();
 
   /// Result of groups is created on the fly and don't stored to the document
-  FEATURESPLUGIN_EXPORT virtual bool isPersistentResult() {return false;}
+  FEATURESPLUGIN_EXPORT virtual bool isPersistentResult() {return true;}
 
   /// Use plugin manager for features creation
   FeaturesPlugin_Group();
index 77b834ada84f458a48bf33d6259c9659d57b1a19..5dcc138deeecbf1d46821c83b5e93fe7173cd6ce 100644 (file)
 #include <Events_Error.h>
 
 #include <TDataStd_Name.hxx>
-#include <TDataStd_UAttribute.hxx>
 
 #include <string>
 
+// myLab contains:
+// TDataStd_Name - name of the object
+// TDataStd_Integer - state of the object execution
+
 Model_Data::Model_Data()
 {
 }
@@ -85,7 +88,9 @@ void Model_Data::addAttribute(const std::string& theID, const std::string theAtt
     anAttr = new Model_AttributeRefAttr(anAttrLab);
   } else if (theAttrType == ModelAPI_AttributeRefList::type()) {
     anAttr = new Model_AttributeRefList(anAttrLab);
-  } else if (theAttrType == GeomData_Point::type()) {
+  } 
+  // create also GeomData attributes here because only here the OCAF strucure is known
+  else if (theAttrType == GeomData_Point::type()) {
     anAttr = new GeomData_Point(anAttrLab);
   } else if (theAttrType == GeomData_Dir::type()) {
     anAttr = new GeomData_Dir(anAttrLab);
@@ -100,167 +105,28 @@ void Model_Data::addAttribute(const std::string& theID, const std::string theAtt
   }
 }
 
-std::shared_ptr<ModelAPI_AttributeDocRef> Model_Data::document(const std::string& theID)
-{
-  std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
-    myAttrs.find(theID);
-  if (aFound == myAttrs.end()) {
-    // TODO: generate error on unknown attribute request and/or add mechanism for customization
-    return std::shared_ptr<ModelAPI_AttributeDocRef>();
-  }
-  std::shared_ptr<ModelAPI_AttributeDocRef> aRes = std::dynamic_pointer_cast<
-      ModelAPI_AttributeDocRef>(aFound->second);
-  if (!aRes) {
-    // TODO: generate error on invalid attribute type request
-  }
-  return aRes;
-}
-
-std::shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const std::string& theID)
-{
-  std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
-    myAttrs.find(theID);
-  if (aFound == myAttrs.end()) {
-    // TODO: generate error on unknown attribute request and/or add mechanism for customization
-    return std::shared_ptr<ModelAPI_AttributeDouble>();
-  }
-  std::shared_ptr<ModelAPI_AttributeDouble> aRes = std::dynamic_pointer_cast<
-      ModelAPI_AttributeDouble>(aFound->second);
-  if (!aRes) {
-    // TODO: generate error on invalid attribute type request
-  }
-  return aRes;
-}
-
-std::shared_ptr<ModelAPI_AttributeInteger> Model_Data::integer(const std::string& theID)
-{
-  std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
-    myAttrs.find(theID);
-  if (aFound == myAttrs.end()) {
-    // TODO: generate error on unknown attribute request and/or add mechanism for customization
-    return std::shared_ptr<ModelAPI_AttributeInteger>();
-  }
-  std::shared_ptr<ModelAPI_AttributeInteger> aRes = std::dynamic_pointer_cast<
-      ModelAPI_AttributeInteger>(aFound->second);
-  if (!aRes) {
-    // TODO: generate error on invalid attribute type request
+// macro for gthe generic returning of the attribute by the ID
+#define GET_ATTRIBUTE_BY_ID(ATTR_TYPE, METHOD_NAME) \
+  std::shared_ptr<ATTR_TYPE> Model_Data::METHOD_NAME(const std::string& theID) { \
+    std::shared_ptr<ATTR_TYPE> aRes; \
+    std::map<std::string, AttributePtr >::iterator aFound = \
+      myAttrs.find(theID); \
+    if (aFound != myAttrs.end()) { \
+      aRes = std::dynamic_pointer_cast<ATTR_TYPE>(aFound->second); \
+    } \
+    return aRes; \
   }
-  return aRes;
-}
-
-std::shared_ptr<ModelAPI_AttributeBoolean> Model_Data::boolean(const std::string& theID)
-{
-  std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
-    myAttrs.find(theID);
-  if (aFound == myAttrs.end()) {
-    // TODO: generate error on unknown attribute request and/or add mechanism for customization
-    return std::shared_ptr<ModelAPI_AttributeBoolean>();
-  }
-  std::shared_ptr<ModelAPI_AttributeBoolean> aRes = std::dynamic_pointer_cast<
-      ModelAPI_AttributeBoolean>(aFound->second);
-  if (!aRes) {
-    // TODO: generate error on invalid attribute type request
-  }
-  return aRes;
-}
-
-std::shared_ptr<ModelAPI_AttributeString> Model_Data::string(const std::string& theID)
-{
-  std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
-    myAttrs.find(theID);
-  if (aFound == myAttrs.end()) {
-    // TODO: generate error on unknown attribute request and/or add mechanism for customization
-    return std::shared_ptr<ModelAPI_AttributeString>();
-  }
-  std::shared_ptr<ModelAPI_AttributeString> aRes =
-      std::dynamic_pointer_cast<ModelAPI_AttributeString>(aFound->second);
-  if (!aRes) {
-    // TODO: generate error on invalid attribute type request
-  }
-  return aRes;
-
-}
-
-std::shared_ptr<ModelAPI_AttributeReference> Model_Data::reference(const std::string& theID)
-{
-  std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
-    myAttrs.find(theID);
-  if (aFound == myAttrs.end()) {
-    // TODO: generate error on unknown attribute request and/or add mechanism for customization
-    return std::shared_ptr<ModelAPI_AttributeReference>();
-  }
-  std::shared_ptr<ModelAPI_AttributeReference> aRes = std::dynamic_pointer_cast<
-      ModelAPI_AttributeReference>(aFound->second);
-  if (!aRes) {
-    // TODO: generate error on invalid attribute type request
-  }
-  return aRes;
-}
-
-std::shared_ptr<ModelAPI_AttributeSelection> Model_Data::selection(const std::string& theID)
-{
-  std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
-    myAttrs.find(theID);
-  if (aFound == myAttrs.end()) {
-    // TODO: generate error on unknown attribute request and/or add mechanism for customization
-    return std::shared_ptr<ModelAPI_AttributeSelection>();
-  }
-  std::shared_ptr<ModelAPI_AttributeSelection> aRes = 
-    std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aFound->second);
-  if (!aRes) {
-    // TODO: generate error on invalid attribute type request
-  }
-  return aRes;
-}
-
-std::shared_ptr<ModelAPI_AttributeSelectionList> 
-  Model_Data::selectionList(const std::string& theID)
-{
-  std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
-    myAttrs.find(theID);
-  if (aFound == myAttrs.end()) {
-    // TODO: generate error on unknown attribute request and/or add mechanism for customization
-    return std::shared_ptr<ModelAPI_AttributeSelectionList>();
-  }
-  std::shared_ptr<ModelAPI_AttributeSelectionList> aRes = 
-    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aFound->second);
-  if (!aRes) {
-    // TODO: generate error on invalid attribute type request
-  }
-  return aRes;
-}
-
-std::shared_ptr<ModelAPI_AttributeRefAttr> Model_Data::refattr(const std::string& theID)
-{
-  std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
-    myAttrs.find(theID);
-  if (aFound == myAttrs.end()) {
-    // TODO: generate error on unknown attribute request and/or add mechanism for customization
-    return std::shared_ptr<ModelAPI_AttributeRefAttr>();
-  }
-  std::shared_ptr<ModelAPI_AttributeRefAttr> aRes = std::dynamic_pointer_cast<
-      ModelAPI_AttributeRefAttr>(aFound->second);
-  if (!aRes) {
-    // TODO: generate error on invalid attribute type request
-  }
-  return aRes;
-}
-
-std::shared_ptr<ModelAPI_AttributeRefList> Model_Data::reflist(const std::string& theID)
-{
-  std::map<std::string, std::shared_ptr<ModelAPI_Attribute> >::iterator aFound = 
-    myAttrs.find(theID);
-  if (aFound == myAttrs.end()) {
-    // TODO: generate error on unknown attribute request and/or add mechanism for customization
-    return std::shared_ptr<ModelAPI_AttributeRefList>();
-  }
-  std::shared_ptr<ModelAPI_AttributeRefList> aRes = std::dynamic_pointer_cast<
-      ModelAPI_AttributeRefList>(aFound->second);
-  if (!aRes) {
-    // TODO: generate error on invalid attribute type request
-  }
-  return aRes;
-}
+// implement nice getting methods for all ModelAPI attributes
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDocRef, document);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeDouble, real);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeInteger, integer);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeBoolean, boolean);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeString, string);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeReference, reference);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelection, selection);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelectionList, selectionList);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttr, refattr);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefList, reflist);
 
 std::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string& theID)
 {
@@ -340,20 +206,25 @@ void Model_Data::erase()
     myLab.ForgetAllAttributes();
 }
 
-/// identifeir of the "must be updated" flag in the data tree
-Standard_GUID kMustBeUpdatedGUID("baede74c-31a6-4416-9c4d-e48ce65f2005");
+void Model_Data::execState(const ModelAPI_ExecState theState)
+{
+  if (theState != ModelAPI_StateNothing)
+    TDataStd_Integer::Set(myLab, (int)theState);
+}
 
-void Model_Data::mustBeUpdated(const bool theFlag)
+ModelAPI_ExecState Model_Data::execState()
 {
-  if (theFlag)
-    TDataStd_UAttribute::Set(myLab, kMustBeUpdatedGUID);
-  else
-    myLab.ForgetAttribute(kMustBeUpdatedGUID);
+  Handle(TDataStd_Integer) aStateAttr;
+  if (myLab.FindAttribute(TDataStd_Integer::GetID(), aStateAttr)) {
+    return ModelAPI_ExecState(aStateAttr->Get());
+  }
+  return ModelAPI_StateMustBeUpdated; // default value
 }
 
-bool Model_Data::mustBeUpdated()
+void Model_Data::setError(const std::string& theError)
 {
-  return myLab.IsAttribute(kMustBeUpdatedGUID) == Standard_True;
+  execState(ModelAPI_StateExecFailed);
+  Events_Error::send(theError);
 }
 
 int Model_Data::featureId() const
index 1d82ad14be9a89ccb4619adf152f3f955142b01e..05068cd6543c0dd1bbe7fffe578b9244b276066c 100644 (file)
@@ -140,14 +140,17 @@ class Model_Data : public ModelAPI_Data
     myObject = theObject;
   }
 
+  /// Erases all the data from the data model
   MODEL_EXPORT virtual void erase();
 
-  /// Makes feature must be updated later (on rebuild). Normally the Updater must call it
-  /// in case of not-automatic update to true
-  MODEL_EXPORT virtual void mustBeUpdated(const bool theFlag);
+  /// Stores the state of the object to execute it later accordingly
+  MODEL_EXPORT virtual void execState(const ModelAPI_ExecState theState);
 
-  /// Returns true if feature must be updated (re-executed) on rebuild
-  MODEL_EXPORT virtual bool mustBeUpdated();
+  /// Returns the state of the latest execution of the feature
+  MODEL_EXPORT virtual ModelAPI_ExecState execState();
+
+  /// Registers error during the execution, causes the ExecutionFailed state
+  MODEL_EXPORT virtual void setError(const std::string& theError);
 
   /// Returns the identifier of feature-owner, unique in this document
   MODEL_EXPORT virtual int featureId() const;
index 6e609dd5d706cfcb0a6c76729b8a9126f646ae76..2bbad12d176b27e3f24b3067235b69657732e48a 100644 (file)
@@ -41,3 +41,9 @@ void Model_FeatureValidator::registerNotObligatory(std::string theFeature, std::
   std::set<std::string>& anAttrs = myNotObligatory[theFeature];
   anAttrs.insert(theAttribute);
 }
+
+bool Model_FeatureValidator::isNotObligatory(std::string theFeature, std::string theAttribute)
+{
+  std::set<std::string>& anAttrs = myNotObligatory[theFeature];
+  return anAttrs.find(theAttribute) != anAttrs.end();
+}
index b262ff0ea552b0fee6cbb9d1ba2fc063fdbf4af5..dddfb2a318714dd1956b894045956cc707c1259b 100644 (file)
@@ -24,7 +24,10 @@ class Model_FeatureValidator : public ModelAPI_FeatureValidator
     const std::list<std::string>& theArguments) const;
 
   // sets not obligatory attributes, not checked for initialization
-  void registerNotObligatory(std::string theFeature, std::string theAttribute);
+  virtual void registerNotObligatory(std::string theFeature, std::string theAttribute);
+
+  /// Returns true if the attribute in feature is not obligatory for the feature execution
+  virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
 };
 
 #endif
index 8aa00217e8bbc546b2784ef0999a17a69285842d..ca900b86bb4cceac6174e139f23a44a866a314d6 100644 (file)
@@ -160,20 +160,35 @@ void Model_Update::processEvent(const std::shared_ptr<Events_Message>& theMessag
   isExecuted = false;
 }
 
-void Model_Update::redisplayWithResults(FeaturePtr theFeature) {
+void Model_Update::redisplayWithResults(FeaturePtr theFeature, const ModelAPI_ExecState theState) 
+{
   // maske updated and redisplay all results
   static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
   const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = theFeature->results();
   std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
   for (; aRIter != aResults.cend(); aRIter++) {
     std::shared_ptr<ModelAPI_Result> aRes = *aRIter;
-    aRes->data()->mustBeUpdated(false);
+    aRes->data()->execState(theState);
     myUpdated[aRes] = true;
     ModelAPI_EventCreator::get()->sendUpdated(aRes, EVENT_DISP);
   }
   // to redisplay "presentable" feature (for ex. distance constraint)
   ModelAPI_EventCreator::get()->sendUpdated(theFeature, EVENT_DISP);
-  theFeature->data()->mustBeUpdated(false);
+  theFeature->data()->execState(theState);
+}
+
+/// Updates the state by the referenced object: if something bad with it, set state for this one
+ModelAPI_ExecState stateByReference(ObjectPtr theTarget, const ModelAPI_ExecState theCurrent)
+{
+  if (theTarget) {
+    ModelAPI_ExecState aRefState = theTarget->data()->execState();
+    if (aRefState == ModelAPI_StateMustBeUpdated) {
+      return ModelAPI_StateMustBeUpdated;
+    } else if (aRefState != ModelAPI_StateDone) {
+      return ModelAPI_StateInvalidArgument;
+    }
+  }
+  return theCurrent;
 }
 
 bool Model_Update::updateFeature(FeaturePtr theFeature)
@@ -185,7 +200,8 @@ bool Model_Update::updateFeature(FeaturePtr theFeature)
   ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
   bool aMustbeUpdated = myInitial.find(theFeature) != myInitial.end();
   if (theFeature) {  // only real feature contains references to other objects
-    if (theFeature->data()->mustBeUpdated()) aMustbeUpdated = true;
+    if (theFeature->data()->execState() != ModelAPI_StateDone)
+      aMustbeUpdated = true;
 
     // composite feature must be executed after sub-features execution
     CompositeFeaturePtr aComposite = 
@@ -197,7 +213,9 @@ bool Model_Update::updateFeature(FeaturePtr theFeature)
           aMustbeUpdated = true;
       }
     }
+    ModelAPI_ExecState aState = ModelAPI_StateDone;
     // check all references: if referenced objects are updated, this object also must be updated
+    // also check state of referenced objects: if they are not ready, inherit corresponding state
     std::list<std::pair<std::string, std::list<ObjectPtr> > > aRefs;
     std::shared_ptr<Model_Data> aData = 
       std::dynamic_pointer_cast<Model_Data>(theFeature->data());
@@ -209,6 +227,7 @@ bool Model_Update::updateFeature(FeaturePtr theFeature)
         if (updateObject(*aRefObj)) {
           aMustbeUpdated = true;
         }
+        aState = stateByReference(*aRefObj, aState);
       }
     }
 
@@ -218,71 +237,94 @@ bool Model_Update::updateFeature(FeaturePtr theFeature)
       if (std::dynamic_pointer_cast<Model_Document>(theFeature->document())->executeFeatures() ||
           !theFeature->isPersistentResult()) {
         if (aFactory->validate(theFeature)) {
-          if (isAutomatic || (myJustCreatedOrUpdated.find(theFeature) != myJustCreatedOrUpdated.end()) ||
-            !theFeature->isPersistentResult() /* execute quick, not persistent results */) 
+          if (isAutomatic || 
+              (myJustCreatedOrUpdated.find(theFeature) != myJustCreatedOrUpdated.end()) ||
+              !theFeature->isPersistentResult() /* execute quick, not persistent results */) 
           {
-            //std::cout<<"Execute feature "<<theFeature->getKind()<<std::endl;
-            // before execution update the selection attributes if any
-            list<AttributePtr> aRefs = 
-              theFeature->data()->attributes(ModelAPI_AttributeSelection::type());
-            list<AttributePtr>::iterator aRefsIter = aRefs.begin();
-            for (; aRefsIter != aRefs.end(); aRefsIter++) {
-              std::shared_ptr<ModelAPI_AttributeSelection> aSel =
-                std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*aRefsIter);
-              aSel->update(); // this must be done on execution since it may be long operation
-            }
-            aRefs = theFeature->data()->attributes(ModelAPI_AttributeSelectionList::type());
-            for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) {
-              std::shared_ptr<ModelAPI_AttributeSelectionList> aSel =
-                std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(*aRefsIter);
-              for(int a = aSel->size() - 1; a >= 0; a--) {
-                  aSel->value(a)->update();
+            if (aState == ModelAPI_StateDone) {// all referenced objects are ready to be used
+              //std::cout<<"Execute feature "<<theFeature->getKind()<<std::endl;
+              // before execution update the selection attributes if any
+              list<AttributePtr> aRefs = 
+                theFeature->data()->attributes(ModelAPI_AttributeSelection::type());
+              list<AttributePtr>::iterator aRefsIter = aRefs.begin();
+              for (; aRefsIter != aRefs.end(); aRefsIter++) {
+                std::shared_ptr<ModelAPI_AttributeSelection> aSel =
+                  std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(*aRefsIter);
+                if (!aSel->update()) { // this must be done on execution since it may be long operation
+                  if (!aFactory->isNotObligatory(theFeature->getKind(), theFeature->data()->id(aSel)))
+                    aState = ModelAPI_StateInvalidArgument;
+                }
               }
-            }
-            // for sketch after update of plane (by update of selection attribute)
-            // but before execute, all sub-elements also must be updated (due to the plane changes)
-            if (aComposite) {
-              int aSubsNum = aComposite->numberOfSubs();
-              for(int a = 0; a < aSubsNum; a++) {
-                FeaturePtr aSub = aComposite->subFeature(a);
-                bool aWasModified = myUpdated[aSub];
-                myUpdated.erase(myUpdated.find(aSub)); // erase to update for sure (plane may be changed)
-                myInitial.insert(aSub);
-                updateFeature(aSub);
-                myUpdated[aSub] = aWasModified; // restore value
+              aRefs = theFeature->data()->attributes(ModelAPI_AttributeSelectionList::type());
+              for (aRefsIter = aRefs.begin(); aRefsIter != aRefs.end(); aRefsIter++) {
+                std::shared_ptr<ModelAPI_AttributeSelectionList> aSel =
+                  std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(*aRefsIter);
+                for(int a = aSel->size() - 1; a >= 0; a--) {
+                  std::shared_ptr<ModelAPI_AttributeSelection> aSelAttr =
+                    std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aSel->value(a));
+                  if (aSelAttr) {
+                    if (!aSelAttr->update()) {
+                      if (!aFactory->isNotObligatory(
+                          theFeature->getKind(), theFeature->data()->id(aSel)))
+                        aState = ModelAPI_StateInvalidArgument;
+                    }
+                  }
+                }
               }
-              // re-execute after update: solver may update the previous values, so, shapes must be
-              // updated
-              for(int a = 0; a < aSubsNum; a++) {
-                if (aComposite->subFeature(a) && aFactory->validate(aComposite->subFeature(a)))
-                  aComposite->subFeature(a)->execute();
+              // for sketch after update of plane (by update of selection attribute)
+              // but before execute, all sub-elements also must be updated (due to the plane changes)
+              if (aComposite) {
+                int aSubsNum = aComposite->numberOfSubs();
+                for(int a = 0; a < aSubsNum; a++) {
+                  FeaturePtr aSub = aComposite->subFeature(a);
+                  bool aWasModified = myUpdated[aSub];
+                  myUpdated.erase(myUpdated.find(aSub)); // erase to update for sure (plane may be changed)
+                  myInitial.insert(aSub);
+                  updateFeature(aSub);
+                  myUpdated[aSub] = aWasModified; // restore value
+                }
+                // re-execute after update: solver may update the previous values, so, shapes must be
+                // updated
+                for(int a = 0; a < aSubsNum; a++) {
+                  if (aComposite->subFeature(a) && aFactory->validate(aComposite->subFeature(a)))
+                    aComposite->subFeature(a)->execute();
+                }
               }
             }
 
             // execute in try-catch to avoid internal problems of the feature
-            try {
-              theFeature->execute();
-            } catch(...) {
-              Events_Error::send(
-                "Feature " + theFeature->getKind() + " has failed during the execution");
+            if (aState == ModelAPI_StateDone) {
+              theFeature->data()->execState(ModelAPI_StateDone);
+              try {
+                theFeature->execute();
+                if (theFeature->data()->execState() != ModelAPI_StateDone) {
+                  aState = ModelAPI_StateExecFailed;
+                }
+              } catch(...) {
+                aState = ModelAPI_StateExecFailed;
+                Events_Error::send(
+                  "Feature " + theFeature->getKind() + " has failed during the execution");
+              }
+            }
+            if (aState != ModelAPI_StateDone) {
               theFeature->eraseResults();
             }
-            redisplayWithResults(theFeature);
+            redisplayWithResults(theFeature, aState);
           } else { // must be updatet, but not updated yet
-            theFeature->data()->mustBeUpdated(true);
+            theFeature->data()->execState(ModelAPI_StateMustBeUpdated);
             const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = theFeature->results();
             std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
             for (; aRIter != aResults.cend(); aRIter++) {
               std::shared_ptr<ModelAPI_Result> aRes = *aRIter;
-              aRes->data()->mustBeUpdated(true);
+              aRes->data()->execState(ModelAPI_StateMustBeUpdated);
             }
           }
         } else {
           theFeature->eraseResults();
-          redisplayWithResults(theFeature); // result also must be updated
+          redisplayWithResults(theFeature, ModelAPI_StateInvalidArgument); // result also must be updated
         }
       } else { // for automatically updated features (on abort, etc) it is necessary to redisplay anyway
-        redisplayWithResults(theFeature);
+        redisplayWithResults(theFeature, ModelAPI_StateNothing);
       }
     } else {  // returns also true is results were updated: for sketch that refers to sub-features but results of sub-features were changed
       const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = theFeature->results();
index 31d532da516fe38bd0ece5048025097635ed8b4b..bc4c2be68667ad324837e31f3db4d6b4e13430c2 100644 (file)
@@ -6,6 +6,7 @@
 #define Model_Update_H_
 
 #include "Model.h"
+#include <ModelAPI_Data.h>
 #include "Events_Listener.h"
 #include <memory>
 #include <set>
@@ -48,7 +49,8 @@ class Model_Update : public Events_Listener
   /// Returns true if object was updated.
   bool updateObject(std::shared_ptr<ModelAPI_Object> theObject, const bool theCyclic = true);
   /// Sends the redisplay events for feature and results, updates the updated status
-  void redisplayWithResults(std::shared_ptr<ModelAPI_Feature> theFeature);
+  void redisplayWithResults(std::shared_ptr<ModelAPI_Feature> theFeature, 
+    const ModelAPI_ExecState theState);
 };
 
 #endif
index cc3a612a50d19752eae437181a03df9d3122bf75..501b91b2f1072b47e1775a12cb0d331606c8b6c1 100644 (file)
@@ -224,6 +224,19 @@ void Model_ValidatorsFactory::registerNotObligatory(std::string theFeature, std:
   }
 }
 
+bool Model_ValidatorsFactory::isNotObligatory(std::string theFeature, std::string theAttribute)
+{
+  const static std::string kDefaultId = "Model_FeatureValidator";
+  std::map<std::string, ModelAPI_Validator*>::const_iterator it = myIDs.find(kDefaultId);
+  if (it != myIDs.end()) {
+    Model_FeatureValidator* aValidator = dynamic_cast<Model_FeatureValidator*>(it->second);
+    if (aValidator) {
+      return aValidator->isNotObligatory(theFeature, theAttribute);
+    }
+  }
+  return false; // default
+}
+
 void Model_ValidatorsFactory::registerConcealment(std::string theFeature, std::string theAttribute)
 {
   std::map<std::string, std::set<std::string> >::iterator aFind = myConcealed.find(theFeature);
index a6d36996360610ee46f5b983752d6eda01ce79f2..a739a79781b45193302f35ccad389ab2cdcc585f 100644 (file)
@@ -76,6 +76,9 @@ class Model_ValidatorsFactory : public ModelAPI_ValidatorsFactory
   /// so, it is not needed for the standard validation mechanism
   virtual void registerNotObligatory(std::string theFeature, std::string theAttribute);
 
+  /// Returns true if the attribute in feature is not obligatory for the feature execution
+  virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
+
   /// register that this attribute conceals in the object browser
   /// all referenced features after execution
   virtual void registerConcealment(std::string theFeature, std::string theAttribute);
index 8cc137477029665743eee48b877600859cb118bc..8e33c85ff13435074a65e7344e130754ac742dab 100644 (file)
@@ -26,6 +26,15 @@ class ModelAPI_AttributeSelection;
 class ModelAPI_AttributeSelectionList;
 class GeomAPI_Shape;
 
+/// Enumeration that contains the execution status of the Object
+enum ModelAPI_ExecState {
+  ModelAPI_StateDone, ///< execution was performed and result is up to date
+  ModelAPI_StateMustBeUpdated, ///< execution must be performed to obtain the up to date result
+  ModelAPI_StateExecFailed, ///< execution was failed (results are deleted in this case)
+  ModelAPI_StateInvalidArgument, ///< execution was not performed (results are deleted in this case)
+  ModelAPI_StateNothing ///< internal state that actually means that nothing must be changed
+};
+
 /**\class ModelAPI_Data
  * \ingroup DataModel
  * \brief General object of the application that allows
@@ -100,12 +109,14 @@ class MODELAPI_EXPORT ModelAPI_Data
   {
   }
 
-  /// Makes feature must be updated later (on rebuild). Normally the Updater must call it
-  /// in case of not-automatic update to true
-  virtual void mustBeUpdated(const bool theFlag) = 0;
+  /// Stores the state of the object to execute it later accordingly
+  virtual void execState(const ModelAPI_ExecState theState) = 0;
+
+  /// Returns the state of the latest execution of the feature
+  virtual ModelAPI_ExecState execState() = 0;
 
-  /// Returns true if feature must be updated (re-executed) on rebuild
-  virtual bool mustBeUpdated() = 0;
+  /// Registers error during the execution, causes the ExecutionFailed state
+  virtual void setError(const std::string& theError) = 0;
 
   /// Returns the identifier of feature-owner, unique in this document
   virtual int featureId() const = 0;
index 431b065b77f2d76d26d696ba16bbd75b6f9191da..6ea57af293a8d43874d5a198030f372c105923e4 100644 (file)
@@ -53,6 +53,11 @@ class ModelAPI_Feature : public ModelAPI_Object
   /// Computes or recomputes the results
   virtual void execute() = 0;
 
+  /// Registers error during the execution, causes the ExecutionFailed state
+  virtual void setError(const std::string& theError) {
+    data()->setError(theError);
+  }
+
   /// returns the current results of the feature
   MODELAPI_EXPORT const std::list<std::shared_ptr<ModelAPI_Result> >& results();
   /// returns the first result in the list or NULL reference
index 6d44a735a14f1dceb09c2223c76079a1f642322c..b29fda7995e3f241009a53e4c5b8f46f9ff55dea 100644 (file)
@@ -17,6 +17,9 @@ class ModelAPI_FeatureValidator : public ModelAPI_Validator
   /// \param theArguments list of string, feature attribute names: dependent attributes
   virtual bool isValid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
     const std::list<std::string>& theArguments) const = 0;
+
+  /// Returns true if the attribute in feature is not obligatory for the feature execution
+  virtual bool isNotObligatory(std::string theFeature, std::string theAttribute) = 0;
 };
 
 #endif
index a4eb79416c7f802910eb6f49b9232af7a75502bf..3dfb14f10cc9f4816c77bf7f00f4f9eafe36664e 100644 (file)
@@ -83,6 +83,9 @@ class MODELAPI_EXPORT ModelAPI_ValidatorsFactory
   /// so, it is not needed for the standard validation mechanism
   virtual void registerNotObligatory(std::string theFeature, std::string theAttribute) = 0;
 
+  /// Returns true if the attribute in feature is not obligatory for the feature execution
+  virtual bool isNotObligatory(std::string theFeature, std::string theAttribute) = 0;
+
   /// register that this attribute conceals in the object browser
   /// all referenced features after execution
   virtual void registerConcealment(std::string theFeature, std::string theAttribute) = 0;
index c7f1b81a2e26fc70fc5a2a001ef5b915295b6e98..f80e5ae9f77161656ce82100fb5f848b1354db27 100644 (file)
@@ -319,7 +319,8 @@ QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) cons
           std::string aGroup = theIndex.internalId() == ConstructObject ?
             ModelAPI_ResultConstruction::group() : ModelAPI_ResultBody::group();
           ObjectPtr anObject = partDocument()->object(aGroup, theIndex.row());
-          if (anObject && anObject->data() && anObject->data()->mustBeUpdated()) {
+          if (anObject && anObject->data() && 
+              anObject->data()->execState() == ModelAPI_StateMustBeUpdated) {
             return QIcon(":pictures/constr_object_modified.png");
           }
           return QIcon(":pictures/constr_object.png");