1. Working with current feature (on add of the new feature).
2. Creation of the unique name of the feature.
FeaturePtr anAfterThisSub = theAfterThis;
if (aCompositeAfter.get()) {
FeaturePtr aSub = aCompositeAfter;
+ int anIndex = kUNDEFINED_FEATURE_INDEX;
do {
- FeaturePtr aNext = myObjs->nextFeature(aSub);
+ FeaturePtr aNext = myObjs->nextFeature(aSub, anIndex);
if (!isSub(aCompositeAfter, aNext)) {
anAfterThisSub = aSub;
break;
TDF_Label aLab = aRef->Get();
FeaturePtr aResult = myObjs->feature(aLab);
if (theVisible) { // get nearest visible (in history) going up
+ int anIndex = kUNDEFINED_FEATURE_INDEX;
while(aResult.get() && !aResult->isInHistory()) {
- aResult = myObjs->nextFeature(aResult, true);
+ aResult = myObjs->nextFeature(aResult, anIndex, true);
}
}
return aResult;
if (theVisible && !theCurrent.get()) {
// needed to avoid disabling of PartSet initial constructions
+ int anIndex = kUNDEFINED_FEATURE_INDEX;
FeaturePtr aNext =
- theCurrent.get() ? myObjs->nextFeature(theCurrent) : myObjs->firstFeature();
- for (; aNext.get(); aNext = myObjs->nextFeature(theCurrent)) {
+ theCurrent.get() ? myObjs->nextFeature(theCurrent, anIndex, false) : myObjs->firstFeature();
+ for (; aNext.get(); aNext = myObjs->nextFeature(theCurrent, anIndex, false)) {
if (aNext->isInHistory()) {
break; // next in history is not needed
} else { // next not in history is good for making current
FeaturePtr anIter = myObjs->lastFeature();
bool aWasChanged = false;
bool isCurrentParameter = theCurrent.get() && theCurrent->getKind() == "Parameter";
- for(; anIter.get(); anIter = myObjs->nextFeature(anIter, true)) {
+ int anIndex = kUNDEFINED_FEATURE_INDEX;
+ for(; anIter.get(); anIter = myObjs->nextFeature(anIter, anIndex, true)) {
// check this before passed become enabled: the current feature is enabled!
if (anIter == theCurrent) aPassed = true;
// problems if it is true: here and in "setCurrentFeature"
FeaturePtr aCurrent = currentFeature(false);
if (aCurrent.get()) { // if not, do nothing because null is the upper
- FeaturePtr aPrev = myObjs->nextFeature(aCurrent, true);
+ int anIndex = kUNDEFINED_FEATURE_INDEX;
+ FeaturePtr aPrev = myObjs->nextFeature(aCurrent, anIndex, true);
// make the higher level composite as current (sketch becomes disabled if line is enabled)
if (aPrev.get()) {
FeaturePtr aComp = ModelAPI_Tools::compositeOwner(aPrev);
#include <TDF_LabelMap.hxx>
#include <TDF_ListIteratorOfLabelList.hxx>
+int kUNDEFINED_FEATURE_INDEX = -1;
+
static const std::string& groupNameFoldering(const std::string& theGroupID,
const bool theAllowFolder)
{
} else { // extend array by one more element
Handle(TDataStd_HLabelArray1) aNewArray = new TDataStd_HLabelArray1(aRefs->Lower(),
aRefs->Upper() + 1);
- int aPassedPrev = 0; // prev feature is found and passed
+ int aPassedPrev = 0; // previous feature is found and passed
if (thePrevLab.IsNull()) { // null means that inserted feature must be the first
aNewArray->SetValue(aRefs->Lower(), theReferenced);
aPassedPrev = 1;
Handle(TDataStd_HLabelArray1) aNewArray =
new TDataStd_HLabelArray1(aRefs->Lower(), aRefs->Upper());
- int aPassedMovedFrom = 0; // the prev feature location is found and passed
+ int aPassedMovedFrom = 0; // the previous feature location is found and passed
int aPassedMovedTo = 0; // the feature is added and this location is passed
if (!theAfterThis.get()) { // null means that inserted feature must be the first
aNewArray->SetValue(aRefs->Lower(), aMovedLab);
// first count all features of such kind to start with index = count + 1
int aNumObjects = -1; // this feature is already in this map
NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFIter(myFeatures);
+ std::set<std::string> allNames;
for (; aFIter.More(); aFIter.Next()) {
if (aFIter.Value()->getKind() == theFeature->getKind())
aNumObjects++;
+ allNames.insert(aFIter.Value()->data()->name());
}
// generate candidate name
aName = composeName(theFeature->getKind(), aNumObjects + 1);
// check this is unique, if not, increase index by 1
- for (aFIter.Initialize(myFeatures); aFIter.More();) {
- FeaturePtr aFeature = aFIter.Value();
- bool isSameName = aFeature->data()->name() == aName;
- if (!isSameName) { // check also results to avoid same results names (actual for Parts)
- const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
- std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
- for (; aRIter != aResults.cend(); aRIter++) {
- isSameName = (*aRIter)->data()->name() == aName;
- }
- }
-
- if (isSameName) {
- aNumObjects++;
- aName = composeName(theFeature->getKind(), aNumObjects + 1);
- // reinitialize iterator to make sure a new name is unique
- aFIter.Initialize(myFeatures);
- } else
- aFIter.Next();
+ for(aNumObjects++; allNames.find(aName) != allNames.end(); aNumObjects++) {
+ aName = composeName(theFeature->getKind(), aNumObjects + 1);
}
theFeature->data()->setName(aName);
}
ObjectPtr aFeature = isFolder ? ObjectPtr(new ModelAPI_Folder)
: ObjectPtr(aSession->createFeature(aFeatureID, anOwner));
if (!aFeature.get()) {
- // somethig is wrong, most probably, the opened document has invalid structure
+ // something is wrong, most probably, the opened document has invalid structure
Events_InfoMessage("Model_Objects", "Invalid type of object in the document").send();
aLabIter.Value()->Label().ForgetAllAttributes();
continue;
}
// update results of the features (after features created because
// they may be connected, like sketch and sub elements)
- // After synchronisation of back references because sketch
+ // After synchronization of back references because sketch
// must be set in sub-elements before "execute" by updateResults
std::set<FeaturePtr> aProcessed; // composites must be updated after their subs (issue 360)
TDF_ChildIDIterator aLabIter2(featuresLabel(), TDataStd_Comment::GetID());
anOwner->setExecuteFeatures(true);
}
-/// synchronises back references for the given object basing on the collected data
+/// synchronizes back references for the given object basing on the collected data
void Model_Objects::synchronizeBackRefsForObject(const std::set<AttributePtr>& theNewRefs,
ObjectPtr theObject)
{
if (!theObject.get() || !theObject->data()->isValid())
return; // invalid
std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
- // iterate new list to compare with curent
+ // iterate new list to compare with current
std::set<AttributePtr>::iterator aNewIter = theNewRefs.begin();
for(; aNewIter != theNewRefs.end(); aNewIter++) {
if (aData->refsToMe().find(*aNewIter) == aData->refsToMe().end()) {
void Model_Objects::synchronizeBackRefs()
{
// collect all back references in the separated container: to update everything at once,
- // without additional Concealment switchin on and off: only the final modification
+ // without additional Concealment switching on and off: only the final modification
- // referenced (slave) objects to referencing attirbutes
+ // referenced (slave) objects to referencing attributes
std::map<ObjectPtr, std::set<AttributePtr> > allRefs;
NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFeatures(myFeatures);
for(; aFeatures.More(); aFeatures.Next()) {
FeaturePtr aFeature = aFeatures.Value();
std::list<ResultPtr> aResults;
ModelAPI_Tools::allResults(aFeature, aResults);
- // update the concealment status for disply in isConcealed of ResultBody
+ // update the concealment status for display in isConcealed of ResultBody
std::list<ResultPtr>::iterator aRIter = aResults.begin();
for(; aRIter != aResults.cend(); aRIter++) {
(*aRIter)->isConcealed();
std::shared_ptr<Model_Data> aPrevData =
std::dynamic_pointer_cast<Model_Data>(theBeforeThis->data());
if (aPrevData.get()) {
- aPrevFeatureLab = nextLabel(aPrevData->label().Father(), true);
+ int anIndex = kUNDEFINED_FEATURE_INDEX;
+ aPrevFeatureLab = nextLabel(aPrevData->label().Father(), anIndex, true);
}
} else { // find the label of the last feature
Handle(TDataStd_ReferenceArray) aRefs;
if (!aLastFeatureInFolder.IsNull()) {
if (IsEqual(aCurLabel, aLastFeatureInFolder))
- aLastFeatureInFolder.Nullify(); // the last feature in the folder is achived
+ aLastFeatureInFolder.Nullify(); // the last feature in the folder is achieved
continue;
}
return aResult;
}
-TDF_Label Model_Objects::nextLabel(TDF_Label theCurrent, const bool theReverse)
+TDF_Label Model_Objects::nextLabel(TDF_Label theCurrent, int& theIndex, const bool theReverse)
{
Handle(TDataStd_ReferenceArray) aRefs;
if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
- for(int a = aRefs->Lower(); a <= aRefs->Upper(); a++) { // iterate all existing features
+ int aStart = theIndex == kUNDEFINED_FEATURE_INDEX ? aRefs->Lower() : theIndex;
+ for(int a = aStart; a <= aRefs->Upper(); a++) { // iterate all existing features
TDF_Label aCurLab = aRefs->Value(a);
if (aCurLab.IsEqual(theCurrent)) {
a += theReverse ? -1 : 1;
- if (a >= aRefs->Lower() && a <= aRefs->Upper())
+ if (a >= aRefs->Lower() && a <= aRefs->Upper()) {
+ theIndex = a;
return aRefs->Value(a);
- break; // finish iiteration: it's last feature
+ }
+ break; // finish iteration: it's last feature
}
}
}
return TDF_Label();
}
-FeaturePtr Model_Objects::nextFeature(FeaturePtr theCurrent, const bool theReverse)
+FeaturePtr Model_Objects::nextFeature(FeaturePtr theCurrent, int& theIndex, const bool theReverse)
{
std::shared_ptr<Model_Data> aData = std::static_pointer_cast<Model_Data>(theCurrent->data());
if (aData.get() && aData->isValid()) {
TDF_Label aFeatureLabel = aData->label().Father();
do {
- TDF_Label aNextLabel = nextLabel(aFeatureLabel, theReverse);
+ TDF_Label aNextLabel = nextLabel(aFeatureLabel, theIndex, theReverse);
if (aNextLabel.IsNull())
- break; // last or something is wrong
+ break; // the last or something is wrong
FeaturePtr aFound = feature(aNextLabel);
if (aFound)
return aFound; // the feature is found
static Standard_Integer HashCode(const TDF_Label& theLab, const Standard_Integer theUpper);
static Standard_Boolean IsEqual(const TDF_Label& theLab1, const TDF_Label& theLab2);
+extern int kUNDEFINED_FEATURE_INDEX;
+
/**\class Model_Objects
* \ingroup DataModel
* \brief Manager of objects of the document. Normally one this class corresponds to
class Model_Objects
{
public:
- //! Registers the fieature in the data structure
+ //! Registers the feature in the data structure
//! \param theFeature feature that must be added to the data structure
//! \param theAfterThis the feature will be added after this feature;
//! if it is null, the added feature will be the first
const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
const bool theBelow);
//! Search a folder containing the given feature.
- //! Addtionally calculates a zero-based index of the feature in this folder.
+ //! Additionally calculates a zero-based index of the feature in this folder.
//! \param theFeature feature to search
//! \param theIndexInFolder zero-based index in the folder or -1 if the feature is top-level.
//! \return the folder containing the feature or empty pointer if the feature is top-level.
int& theIndexInFolder);
//! Add a list of features to the folder. The correctness of the adding is not performed
//! (such checks have been done in corresponding find.. method).
- //! \return \c true if the movement is successfull
+ //! \return \c true if the movement is successful
bool moveToFolder(const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
const std::shared_ptr<ModelAPI_Folder>& theFolder);
//! Remove features from the folder
//! Returns the owner of this manager
DocumentPtr owner() {return myDoc;}
- //! Deletes all managed features wit hemmitting of corresponded signal
+ //! Deletes all managed features with emitting of corresponded signal
~Model_Objects();
protected:
//! feature type + "_" + index
void setUniqueName(FeaturePtr theFeature);
- //! Initializes the foldet with an unique name ("Folder_" + index)
+ //! Initializes the folder with an unique name ("Folder_" + index)
void setUniqueName(FolderPtr theFolder);
//! Synchronizes myFeatures list with the updated document
- //! \param theUpdated list of labels that are marked as modified, so featrues must be also
+ //! \param theUpdated list of labels that are marked as modified, so features must be also
//! \param theUpdateReferences causes the update of back-references
//! \param theExecuteFeatures requires re-execute modified persistent features
//! (not needed on undo/redo/abort/open)
- //! \param theOpen - on open nothing must be reexecuted, except not persistent results
+ //! \param theOpen - on open nothing must be re-executed, except not persistent results
//! \param theFlush makes flush all events in the end of all modifications of this method
void synchronizeFeatures(const TDF_LabelList& theUpdated, const bool theUpdateReferences,
const bool theOpen, const bool theExecuteFeatures, const bool theFlush);
/// 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 reverced order (next becomes previous)
- FeaturePtr nextFeature(FeaturePtr theCurrent, const bool theReverse = false);
+ /// \param theReverse if it is true, iterates in reversed order (next becomes previous)
+ /// \param theIndex may be used for optimization: index of theCurrent in references array
+ FeaturePtr nextFeature(FeaturePtr theCurrent, int& theIndex, const bool theReverse = false);
/// Returns to the first (from the history point of view) feature, any: invisible or disabled
FeaturePtr firstFeature();
/// Returns to the last (from the history point of view) feature, any: invisible or disabled
/// Returns the next or previous label
/// \param theCurrent given label
- /// \param theReverse if it is true, iterates in reverced order (next becomes previous)
- TDF_Label nextLabel(TDF_Label theCurrent, const bool theReverse = false);
+ /// \param theReverse if it is true, iterates in reversed order (next becomes previous)
+ TDF_Label nextLabel(TDF_Label theCurrent, int& theIndex, const bool theReverse = false);
/// Returns the result group identifier of the given feature (for this at least one result must
/// be created before)
//! history. Not very fast method, for calling once, not in big cycles.
std::list<std::shared_ptr<ModelAPI_Object> > allObjects();
- //! synchronises back references for the given object basing on the collected data
+ //! synchronizes back references for the given object basing on the collected data
void synchronizeBackRefsForObject(
const std::set<std::shared_ptr<ModelAPI_Attribute>>& theNewRefs, ObjectPtr theObject);
/// Just removes all features without touching the document data (to be able undo)
virtual void eraseAllFeatures();
- // Check whether the pre-image of the result had user-defined name.
+ // Check whether the predefined-image of the result had user-defined name.
// If yes, return this name.
bool hasCustomName(DataPtr theFeatureData,
ResultPtr theResult,
private:
TDF_Label myMain; ///< main label of the data storage
- DocumentPtr myDoc; ///< doc,ument, owner of this objects manager: needed for events creation
+ DocumentPtr myDoc; ///< document, owner of this objects manager: needed for events creation
/// All managed features (not only in history of OB)
/// For optimization mapped by labels
NCollection_DataMap<TDF_Label, ObjectPtr> myFolders;
/// Map from group id to the array that contains all objects located in history.
- /// Each array is updated by demand from scratch, by browing all the features in the history.
+ /// Each array is updated by demand from scratch, by browsing all the features in the history.
std::map<std::string, std::vector<ObjectPtr> > myHistory;
friend class Model_Document;