X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_Sketch.cpp;h=ceaf6dd0939570316aa2e6bb1a47cedfe7c62150;hb=74e9ba33303efc2282db1261706e904efa36b255;hp=362e7f56f66956f60fccba2c0f3200e047cf4a20;hpb=705438fb7ab16ba1608b6b1aeddd546d6311cb77;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 362e7f56f..ceaf6dd09 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -139,6 +140,10 @@ void SketchPlugin_Sketch::removeFeature(std::shared_ptr theFea { if (!data()->isValid()) // sketch is already removed (case on undo of sketch), sync is not needed return; + // to keep the persistent sub-elements indexing, do not remove elements from list, + // but substitute by nulls + reflist(SketchPlugin_Sketch::FEATURES_ID())->substitute(theFeature, ObjectPtr()); + /* list aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list(); list::iterator aSubIt = aSubs.begin(), aLastIt = aSubs.end(); bool isRemoved = false; @@ -156,22 +161,42 @@ void SketchPlugin_Sketch::removeFeature(std::shared_ptr theFea // Find the first empty element and remove it if (!isRemoved && aHasEmtpyFeature) data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->remove(ObjectPtr()); + */ } -int SketchPlugin_Sketch::numberOfSubs() const +int SketchPlugin_Sketch::numberOfSubs(bool forTree) const { - return data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->size(); + if (forTree) + return 0; + return data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->size(false); } -std::shared_ptr SketchPlugin_Sketch::subFeature(const int theIndex) const +std::shared_ptr SketchPlugin_Sketch::subFeature( + const int theIndex, bool forTree) const { - ObjectPtr anObj = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->object(theIndex); + if (forTree) + return FeaturePtr(); + + ObjectPtr anObj = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->object(theIndex, false); return std::dynamic_pointer_cast(anObj); } int SketchPlugin_Sketch::subFeatureId(const int theIndex) const { - return subFeature(theIndex)->data()->featureId(); + std::shared_ptr aRefList = std::dynamic_pointer_cast< + ModelAPI_AttributeRefList>(data()->attribute(SketchPlugin_Sketch::FEATURES_ID())); + std::list aFeatures = aRefList->list(); + std::list::const_iterator anIt = aFeatures.begin(); + int aResultIndex = 1; // number of the counted (created) features, started from 1 + int aFeatureIndex = -1; // number of the not-empty features in the list + for (; anIt != aFeatures.end(); anIt++) { + if (anIt->get()) + aFeatureIndex++; + if (aFeatureIndex == theIndex) + break; + aResultIndex++; + } + return aResultIndex; } bool SketchPlugin_Sketch::isSub(ObjectPtr theObject) const @@ -250,7 +275,8 @@ void SketchPlugin_Sketch::attributeChanged(const std::string& theID) { std::list aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list(); std::list::iterator aSub = aSubs.begin(); for(; aSub != aSubs.end(); aSub++) { - ModelAPI_EventCreator::get()->sendUpdated(*aSub, anUpdateEvent); + if (aSub->get()) + ModelAPI_EventCreator::get()->sendUpdated(*aSub, anUpdateEvent); } } } @@ -287,6 +313,8 @@ FeaturePtr SketchPlugin_Sketch::addUniqueNamedCopiedFeature(FeaturePtr theFeatur theFeature->data()->copyTo(aNewFeature->data()); // as a name for the feature, the generated unique name is set aNewFeature->data()->setName(aUniqueFeatureName); + // text expressions could block setValue of some attributes + clearExpressions(aNewFeature); return aNewFeature; }