myObjs->eraseAllFeatures();
}
+std::shared_ptr<ModelAPI_Feature> Model_Document::nextFeature(
+ std::shared_ptr<ModelAPI_Feature> theCurrent, const bool theReverse) const
+{
+ if (theCurrent.get() && myObjs) {
+ int anIndex = kUNDEFINED_FEATURE_INDEX;
+ return myObjs->nextFeature(theCurrent, anIndex, theReverse);
+ }
+ return FeaturePtr(); // nothing by default
+}
+
void Model_Document::setExecuteFeatures(const bool theFlag)
{
myExecuteFeatures = theFlag;
/// Just removes all features without touching the document data (to be able undo)
MODEL_EXPORT virtual void eraseAllFeatures();
+ /// Returns the next (from the history point of view) feature, any: invisible or disabled
+ /// \param theCurrent previous to the resulting feature
+ /// \param theReverse if it is true, iterates in reversed order (next becomes previous)
+ MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature> nextFeature(
+ std::shared_ptr<ModelAPI_Feature> theCurrent, const bool theReverse = false) const;
protected:
//! Returns (creates if needed) the general label
/// Just removes all features without touching the document data (to be able undo)
MODELAPI_EXPORT virtual void eraseAllFeatures() = 0;
+ /// Returns the next (from the history point of view) feature, any: invisible or disabled
+ /// \param theCurrent previous to the resulting feature
+ /// \param theReverse if it is true, iterates in reversed order (next becomes previous)
+ MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Feature> nextFeature(
+ std::shared_ptr<ModelAPI_Feature> theCurrent, const bool theReverse = false) const = 0;
+
protected:
//! Only for SWIG wrapping it is here
MODELAPI_EXPORT ModelAPI_Document();
void ModelAPI_Folder::execute()
{
}
+
+std::shared_ptr<ModelAPI_Feature> ModelAPI_Folder::lastVisibleFeature()
+{
+ FeaturePtr aResult;
+ AttributeReferencePtr aLastFeatAttr = data()->reference(LAST_FEATURE_ID());
+ if (!aLastFeatAttr.get())
+ return aResult;
+ aResult = ModelAPI_Feature::feature(aLastFeatAttr->value());
+ while(aResult.get() && !aResult->isInHistory()) { // searching for previous feature
+ aResult = aResult->document()->nextFeature(aResult, true);
+ }
+ return aResult;
+}
return data()->reference(theID);
}
+ /// Returns the last visible feature in the folder, passing through invisible,
+ /// that may appear as the last ones.
+ MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> lastVisibleFeature();
+
protected:
/// This method is called just after creation of the object: it must initialize
/// all fields, normally initialized in the constructor
if (!aFirstFeatureInFolder.get())
return;
- AttributeReferencePtr aLastFeatAttr =
- aFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID());
- if (!aLastFeatAttr.get())
- return;
- FeaturePtr aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value());
+ FeaturePtr aLastFeatureInFolder = aFolder->lastVisibleFeature();
if (!aLastFeatureInFolder.get())
return;
theFirst = aDoc->index(aFirstFeatureInFolder);
theLast = aDoc->index(aLastFeatureInFolder);
-}
\ No newline at end of file
+}