if (isFeature) { // here may be also disabled features
if (!isSub && aFeature->isInHistory()) {
aResult.push_back(aFeature);
+ aFeature->setHistoryIndex(aResult.size() - 1);
// the feature is out of the folders
- if (aLastFeatureInFolder.get() == NULL)
+ if (aLastFeatureInFolder.get() == NULL) {
aResultOutOfFolder.push_back(aFeature);
+ aFeature->setHistoryIndex(aResultOutOfFolder.size() - 1, true);
+ }
}
} else if (!aFeature->isDisabled()) { // iterate all results of not-disabled feature
// construction results of sub-features should not be in the tree
if (aRes->groupName() != theGroupID) break; // feature have only same group results
if (!aRes->isDisabled() && aRes->isInHistory() && !aRes->isConcealed()) {
aResult.push_back(*aRIter);
+ (*aRIter)->setHistoryIndex(aResult.size() - 1);
}
}
}
// store folder information for the Features group only
if (isFeature || isFolder) {
aResult.push_back(aFolder);
- if (!isFolder)
+ aFolder->setHistoryIndex(aResult.size() - 1);
+ if (!isFolder) {
aResultOutOfFolder.push_back(aFolder);
+ aFolder->setHistoryIndex(aResultOutOfFolder.size() - 1, true);
+ }
}
// get the last feature in the folder
createHistory(aGroup);
// get the group of features out of folder (if enabled)
- if (theAllowFolder && !groupNameFoldering(aGroup, theAllowFolder).empty())
- aGroup = groupNameFoldering(aGroup, theAllowFolder);
+ bool isGroupNameFoldering = false;
+ const std::string& aGroupNameFoldering = groupNameFoldering(aGroup, theAllowFolder);
+ if (theAllowFolder && !aGroupNameFoldering.empty()) {
+ isGroupNameFoldering = true;
+ aGroup = aGroupNameFoldering;
+ }
std::vector<ObjectPtr>& allObjs = myHistory[aGroup];
- std::vector<ObjectPtr>::iterator anObjIter = allObjs.begin(); // iterate to search object
- for(int anIndex = 0; anObjIter != allObjs.end(); anObjIter++, anIndex++) {
+
+ // try to use saved index (to aviod time consuming iteration)
+ int anIndex = theObject->getHistoryIndex(isGroupNameFoldering);
+ if (0 <= anIndex && anIndex < allObjs.size() &&
+ allObjs[anIndex] == theObject)
+ return anIndex;
+
+ // iterate to search object
+ std::vector<ObjectPtr>::iterator anObjIter = allObjs.begin();
+ for (anIndex = 0; anObjIter != allObjs.end(); anObjIter++, anIndex++) {
if ((*anObjIter) == theObject)
return anIndex;
}
{
std::shared_ptr<ModelAPI_Data> myData; ///< manager of the data model of a feature
std::shared_ptr<ModelAPI_Document> myDoc; ///< document this object belongs to
+
+ int myHistoryIndex; ///< index in Model_Objects history, managed by Model_Objects
+ int myHistoryIndexOOF; ///< index in Model_Objects history, managed by Model_Objects
+
+ /// set object's index in Model_Objects history, called by Model_Objects
+ void setHistoryIndex(int theIndex, bool isOutOfFolder = false)
+ { isOutOfFolder ? myHistoryIndexOOF = theIndex : myHistoryIndex = theIndex; }
+
+ /// get object's index in Model_Objects history, called by Model_Objects
+ int getHistoryIndex(bool isOutOfFolder = false)
+ { if (isOutOfFolder) return myHistoryIndexOOF;
+ return myHistoryIndex; }
+
public:
#ifdef DEBUG_NAMES
std::wstring myName; // name of this object