static const int TAG_OBJECTS = 2; // tag of the objects sub-tree (features, results)
static const int TAG_HISTORY = 3; // tag of the history sub-tree (python dump)
+// general sub-labels
+static const int TAG_CURRENT_FEATURE = 1; ///< where the reference to the current feature label is located (or no attribute if null feature)
+
// feature sub-labels
static const int TAG_FEATURE_ARGUMENTS = 1; ///< where the arguments are located
static const int TAG_FEATURE_RESULTS = 2; ///< where the results are located
// event: feature is added
static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
+ setCurrentFeature(aFeature); // after all this feature stays in the document, so make it current
} else { // feature must be executed
// no creation event => updater not working, problem with remove part
aFeature->execute();
aComposite->removeFeature(theFeature);
}
}
+ // if this feature is current, make the current the previous feature
+ if (theFeature == currentFeature()) {
+ int aCurrentIndex = index(theFeature);
+ if (aCurrentIndex != -1) {
+ setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(
+ object(ModelAPI_Feature::group(), aCurrentIndex - 1)));
+ }
+ }
// erase fields
theFeature->erase();
return aResult;
}
+std::shared_ptr<ModelAPI_Feature> Model_Document::currentFeature()
+{
+ static TDF_Label aRefLab = generalLabel().FindChild(TAG_CURRENT_FEATURE);
+ Handle(TDF_Reference) aRef;
+ if (aRefLab.FindAttribute(TDF_Reference::GetID(), aRef)) {
+ return feature(aRef->Get());
+ }
+ return std::shared_ptr<ModelAPI_Feature>(); // null feature means the higher than first
+}
+
+void Model_Document::setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent)
+{
+ static TDF_Label aRefLab = generalLabel().FindChild(TAG_CURRENT_FEATURE);
+ if (theCurrent.get()) {
+ std::shared_ptr<Model_Data> aData = std::static_pointer_cast<Model_Data>(theCurrent->data());
+ if (aData.get()) {
+ TDF_Label aFeatureLabel = aData->label().Father();
+ Handle(TDF_Reference) aRef;
+ if (aRefLab.FindAttribute(TDF_Reference::GetID(), aRef)) {
+ aRef->Set(aFeatureLabel);
+ } else {
+ aRef = TDF_Reference::Set(aRefLab, aFeatureLabel);
+ }
+ }
+ } else { // remove reference for the null feature
+ aRefLab.ForgetAttribute(TDF_Reference::GetID());
+ }
+ // make all features after this feature disabled in reversed order (to remove results without deps)
+ bool aPassed = false; // flag that the current object is already passed in cycle
+ int aSize = size(ModelAPI_Feature::group(), true);
+ for(int a = aSize - 1; a >= 0; a--) {
+ FeaturePtr aFeature =
+ std::dynamic_pointer_cast<ModelAPI_Feature>(object(ModelAPI_Feature::group(), a, true));
+ if (aFeature->setDisabled(!aPassed)) {
+ // state of feature is changed => so feature become updated
+ static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+ ModelAPI_EventCreator::get()->sendUpdated(aFeature, anUpdateEvent);
+
+ }
+ // check this only after passed become enabled: the current feature is enabled!
+ if (aFeature == theCurrent) aPassed = true;
+ }
+}
+
TDF_Label Model_Document::featuresLabel() const
{
return myDoc->Main().FindChild(TAG_OBJECTS);
}
+TDF_Label Model_Document::generalLabel() const
+{
+ return myDoc->Main().FindChild(TAG_GENERAL);
+}
+
void Model_Document::setUniqueName(FeaturePtr theFeature)
{
if (!theFeature->data()->name().empty())
//! If theHidden is true, it counts also the features that are not in tree
MODEL_EXPORT virtual int size(const std::string& theGroupID, const bool theHidden = false);
+ //! Returns the feature that is currently edited in this document, normally
+ //! this is the latest created feature
+ //! \returns null if next created feature must be the first
+ MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature> currentFeature();
+
+ //! Sets the current feature: all features below will be disabled, new features
+ //! will be appended after this one.
+ MODEL_EXPORT virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent);
+
/// Creates a construction cresults
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
//! Returns (creates if needed) the features label
TDF_Label featuresLabel() const;
+ //! Returns (creates if needed) the general label
+ TDF_Label generalLabel() const;
//! Initializes feature with a unique name in this group (unique name is generated as
//! feature type + "_" + index
//! If theHidden is true, it counts also the features that are not in tree
virtual int size(const std::string& theGroupID, const bool theHidden = false) = 0;
+ //! Returns the feature that is currently edited in this document, normally
+ //! this is the latest created feature
+ //! \returns null if next created feature must be the first
+ virtual std::shared_ptr<ModelAPI_Feature> currentFeature() = 0;
+
+ //! Sets the current feature: all features below will be disabled, new features
+ //! will be appended after this one.
+ virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent) = 0;
+
/// To virtually destroy the fields of successors
MODELAPI_EXPORT virtual ~ModelAPI_Document();
{
///< list of current results of this feature
std::list<std::shared_ptr<ModelAPI_Result> > myResults;
+ ///< is feature disabled or not
+ bool myIsDisabled;
public:
/// Returns the unique kind of a feature (like "Point")
virtual const std::string& getKind() = 0;
/// By default it is empty: it is added to the document this method is called to
MODELAPI_EXPORT virtual const std::string& documentToAdd();
+ /// Enables/disables the feature. The disabled feature has no results and does not participate in
+ /// any calculation.
+ /// \returns true if state is really changed
+ MODELAPI_EXPORT virtual bool setDisabled(const bool theFlag);
+
+ /// Returns the feature is disabled or not.
+ MODELAPI_EXPORT virtual bool isDisabled() const;
+
/// To virtually destroy the fields of successors
MODELAPI_EXPORT virtual ~ModelAPI_Feature();