From: mpv Date: Fri, 4 Sep 2015 07:26:11 +0000 (+0300) Subject: Optimization for big sketched (from unit tests) X-Git-Tag: V_1.4.0_beta4~129 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ece8ec37099dbbef19853878e70394761ec3b977;p=modules%2Fshaper.git Optimization for big sketched (from unit tests) --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp index 147efefd8..04785ca63 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.cpp @@ -50,7 +50,7 @@ int FeaturesPlugin_CompositeBoolean::numberOfSubs(bool forTree) const } //================================================================================================= -std::shared_ptr FeaturesPlugin_CompositeBoolean::subFeature(const int theIndex, bool forTree) const +std::shared_ptr FeaturesPlugin_CompositeBoolean::subFeature(const int theIndex, bool forTree) { if (theIndex == 0) return std::dynamic_pointer_cast(data()->reference(SKETCH_OBJECT_ID())->value()); @@ -60,9 +60,12 @@ std::shared_ptr FeaturesPlugin_CompositeBoolean::subFeature(co //================================================================================================= int FeaturesPlugin_CompositeBoolean::subFeatureId(const int theIndex) const { - std::shared_ptr aFeature = subFeature(theIndex); - if (aFeature.get()) - return aFeature->data()->featureId(); + if (theIndex == 0) { + FeaturePtr aFeature = + std::dynamic_pointer_cast(data()->reference(SKETCH_OBJECT_ID())->value()); + if (aFeature.get()) + return aFeature->data()->featureId(); + } return -1; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h index d5ce37c38..344faafe5 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeBoolean.h @@ -46,7 +46,7 @@ class FeaturesPlugin_CompositeBoolean : public ModelAPI_CompositeFeature FEATURESPLUGIN_EXPORT virtual int numberOfSubs(bool forTree = false) const; /// \return the sub-feature by zero-base index. - FEATURESPLUGIN_EXPORT virtual std::shared_ptr subFeature(const int theIndex, bool forTree = false) const; + FEATURESPLUGIN_EXPORT virtual std::shared_ptr subFeature(const int theIndex, bool forTree = false); /// \return the sub-feature unique identifier in this composite feature by zero-base index. FEATURESPLUGIN_EXPORT virtual int subFeatureId(const int theIndex) const; diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index b900b1819..d85df7d3e 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -300,8 +300,19 @@ TDF_LabelMap& Model_AttributeSelection::scope() DocumentPtr aMyDoc = owner()->document(); std::list > allFeatures = aMyDoc->allFeatures(); std::list >::iterator aFIter = allFeatures.begin(); + bool aMePassed = false; + std::shared_ptr aComposite = + std::dynamic_pointer_cast(owner()); for(; aFIter != allFeatures.end(); aFIter++) { - if (*aFIter == owner()) break; // the left features are created later + if (*aFIter == owner()) { // the left features are created later (except subs of composite) + aMePassed = true; + continue; + } + bool isInScope = !aMePassed; + if (!isInScope && aComposite.get()) { // try to add sub-elements of composite if this is composite + if (aComposite->isSub(*aFIter)) + isInScope = true; + } if (aFIter->get() && (*aFIter)->data()->isValid()) { TDF_Label aFeatureLab = std::dynamic_pointer_cast( (*aFIter)->data())->label().Father(); diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index eed45d304..4b4ac45a2 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -589,7 +589,8 @@ void Model_Update::updateArguments(FeaturePtr theFeature) { // composite feature must be executed after sub-features execution if (aCompos) { // number of subs can be changed in execution: like fillet - for(int a = 0; a < aCompos->numberOfSubs(); a++) { + int aNumSubs = aCompos->numberOfSubs(); + for(int a = 0; a < aNumSubs; a++) { FeaturePtr aSub = aCompos->subFeature(a); if (aSub.get() && aState == ModelAPI_StateDone) { if (isOlder(theFeature, aSub)) { @@ -605,6 +606,8 @@ void Model_Update::updateArguments(FeaturePtr theFeature) { } } } + if (a == aNumSubs - 1) // in case number of subs is changed, just recheck before end + aNumSubs = aCompos->numberOfSubs(); } } diff --git a/src/ModelAPI/ModelAPI_CompositeFeature.h b/src/ModelAPI/ModelAPI_CompositeFeature.h index 0814141b7..4a86409e2 100644 --- a/src/ModelAPI/ModelAPI_CompositeFeature.h +++ b/src/ModelAPI/ModelAPI_CompositeFeature.h @@ -28,7 +28,7 @@ public: virtual int numberOfSubs(bool forTree = false) const = 0; /// Returns the sub-feature by zero-base index - virtual std::shared_ptr subFeature(const int theIndex, bool forTree = false) const = 0; + virtual std::shared_ptr subFeature(const int theIndex, bool forTree = false) = 0; /// Returns the sub-feature unique identifier in this composite feature by zero-base index virtual int subFeatureId(const int theIndex) const = 0; diff --git a/src/PartSetPlugin/PartSetPlugin_Part.cpp b/src/PartSetPlugin/PartSetPlugin_Part.cpp index 73dae50ef..794fcd4fa 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Part.cpp @@ -72,7 +72,7 @@ int PartSetPlugin_Part::numberOfSubs(bool forTree) const return 0; } -std::shared_ptr PartSetPlugin_Part::subFeature(const int theIndex, bool forTree) const +std::shared_ptr PartSetPlugin_Part::subFeature(const int theIndex, bool forTree) { ResultPartPtr aResult = std::dynamic_pointer_cast(firstResult()); if (aResult.get()) { diff --git a/src/PartSetPlugin/PartSetPlugin_Part.h b/src/PartSetPlugin/PartSetPlugin_Part.h index 0610a68ab..242848300 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.h +++ b/src/PartSetPlugin/PartSetPlugin_Part.h @@ -56,7 +56,7 @@ class PartSetPlugin_Part : public ModelAPI_CompositeFeature virtual int numberOfSubs(bool forTree = false) const; /// Returns the sub-feature by zero-base index - virtual std::shared_ptr subFeature(const int theIndex, bool forTree = false) const; + virtual std::shared_ptr subFeature(const int theIndex, bool forTree = false); /// Returns the sub-feature unique identifier in this composite feature by zero-base index virtual int subFeatureId(const int theIndex) const; diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index ceaf6dd09..7b993c216 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -143,42 +143,36 @@ void SketchPlugin_Sketch::removeFeature(std::shared_ptr theFea // 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; - bool aHasEmtpyFeature = false; - for(; aSubIt != aLastIt && !isRemoved; aSubIt++) { - std::shared_ptr aFeature = std::dynamic_pointer_cast(*aSubIt); - if (aFeature.get() != NULL && aFeature == theFeature) { - data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->remove(aFeature); - isRemoved = true; + + std::map >::iterator aSubIter = mySubs.begin(); + for(; aSubIter != mySubs.end(); aSubIter++) { + if (aSubIter->second == theFeature) { + mySubs.erase(aSubIter); + break; } - else if (aFeature.get() == NULL) - aHasEmtpyFeature = true; } - // if the object is not found in the sketch sub-elements, that means that the object is removed already. - // Find the first empty element and remove it - if (!isRemoved && aHasEmtpyFeature) - data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->remove(ObjectPtr()); - */ } int SketchPlugin_Sketch::numberOfSubs(bool forTree) const { if (forTree) return 0; - return data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->size(false); + return data()->reflist(FEATURES_ID())->size(false); } std::shared_ptr SketchPlugin_Sketch::subFeature( - const int theIndex, bool forTree) const + const int theIndex, bool forTree) { if (forTree) return FeaturePtr(); + if (mySubs.find(theIndex) != mySubs.end()) + return mySubs[theIndex]; + ObjectPtr anObj = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->object(theIndex, false); - return std::dynamic_pointer_cast(anObj); + FeaturePtr aRes = std::dynamic_pointer_cast(anObj); + mySubs[theIndex] = aRes; + return aRes; } int SketchPlugin_Sketch::subFeatureId(const int theIndex) const diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index ab0bcd6ad..aadbe9caf 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -30,6 +30,8 @@ */ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_ICustomPrs//, public GeomAPI_IPresentable { + /// Optimization: indexes of sketch sub-elements are persistent, so, no problems in synchronization. + std::map > mySubs; public: /// Sketch feature kind inline static const std::string& ID() @@ -177,7 +179,7 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature, public GeomAPI_ICu /// Returns the sub-feature by zero-base index SKETCHPLUGIN_EXPORT virtual std::shared_ptr - subFeature(const int theIndex, bool forTree = false) const; + subFeature(const int theIndex, bool forTree = false); /// Returns the sub-feature unique identifier in this composite feature by index SKETCHPLUGIN_EXPORT virtual int subFeatureId(const int theIndex) const;