#include <GeomAPI_Shape.h>
#include <Config_Common.h>
-#include <Events_Error.h>
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
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;
}
//
#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;
}
#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
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
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeBoolean.h>
-#include <Events_Error.h>
#include <GeomAlgoAPI_Extrusion.h>
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()
{
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;
}
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
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();
#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()
{
}
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);
}
}
-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)
{
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
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;
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();
+}
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
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)
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 =
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());
if (updateObject(*aRefObj)) {
aMustbeUpdated = true;
}
+ aState = stateByReference(*aRefObj, aState);
}
}
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();
#define Model_Update_H_
#include "Model.h"
+#include <ModelAPI_Data.h>
#include "Events_Listener.h"
#include <memory>
#include <set>
/// 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
}
}
+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);
/// 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);
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
{
}
- /// 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;
/// 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
/// \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
/// 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;
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");