}
//=================================================================================================
-std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_CompositeBoolean::subFeature(const int theIndex, bool forTree) const
+std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_CompositeBoolean::subFeature(const int theIndex, bool forTree)
{
if (theIndex == 0)
return std::dynamic_pointer_cast<ModelAPI_Feature>(data()->reference(SKETCH_OBJECT_ID())->value());
//=================================================================================================
int FeaturesPlugin_CompositeBoolean::subFeatureId(const int theIndex) const
{
- std::shared_ptr<ModelAPI_Feature> aFeature = subFeature(theIndex);
- if (aFeature.get())
- return aFeature->data()->featureId();
+ if (theIndex == 0) {
+ FeaturePtr aFeature =
+ std::dynamic_pointer_cast<ModelAPI_Feature>(data()->reference(SKETCH_OBJECT_ID())->value());
+ if (aFeature.get())
+ return aFeature->data()->featureId();
+ }
return -1;
}
FEATURESPLUGIN_EXPORT virtual int numberOfSubs(bool forTree = false) const;
/// \return the sub-feature by zero-base index.
- FEATURESPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex, bool forTree = false) const;
+ FEATURESPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> 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;
DocumentPtr aMyDoc = owner()->document();
std::list<std::shared_ptr<ModelAPI_Feature> > allFeatures = aMyDoc->allFeatures();
std::list<std::shared_ptr<ModelAPI_Feature> >::iterator aFIter = allFeatures.begin();
+ bool aMePassed = false;
+ std::shared_ptr<ModelAPI_CompositeFeature> aComposite =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(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<Model_Data>(
(*aFIter)->data())->label().Father();
// 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)) {
}
}
}
+ if (a == aNumSubs - 1) // in case number of subs is changed, just recheck before end
+ aNumSubs = aCompos->numberOfSubs();
}
}
virtual int numberOfSubs(bool forTree = false) const = 0;
/// Returns the sub-feature by zero-base index
- virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex, bool forTree = false) const = 0;
+ virtual std::shared_ptr<ModelAPI_Feature> 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;
return 0;
}
-std::shared_ptr<ModelAPI_Feature> PartSetPlugin_Part::subFeature(const int theIndex, bool forTree) const
+std::shared_ptr<ModelAPI_Feature> PartSetPlugin_Part::subFeature(const int theIndex, bool forTree)
{
ResultPartPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
if (aResult.get()) {
virtual int numberOfSubs(bool forTree = false) const;
/// Returns the sub-feature by zero-base index
- virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex, bool forTree = false) const;
+ virtual std::shared_ptr<ModelAPI_Feature> 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;
// 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<ObjectPtr> aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
- list<ObjectPtr>::iterator aSubIt = aSubs.begin(), aLastIt = aSubs.end();
- bool isRemoved = false;
- bool aHasEmtpyFeature = false;
- for(; aSubIt != aLastIt && !isRemoved; aSubIt++) {
- std::shared_ptr<ModelAPI_Feature> aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*aSubIt);
- if (aFeature.get() != NULL && aFeature == theFeature) {
- data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->remove(aFeature);
- isRemoved = true;
+
+ std::map<int, std::shared_ptr<ModelAPI_Feature> >::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<ModelAPI_Feature> 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<ModelAPI_Feature>(anObj);
+ FeaturePtr aRes = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
+ mySubs[theIndex] = aRes;
+ return aRes;
}
int SketchPlugin_Sketch::subFeatureId(const int theIndex) const
*/
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<int, std::shared_ptr<ModelAPI_Feature> > mySubs;
public:
/// Sketch feature kind
inline static const std::string& ID()
/// Returns the sub-feature by zero-base index
SKETCHPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature>
- 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;