From ba4c95a98d9ef1ff40b1c750dbd9666df412ecad Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 2 Dec 2016 17:11:31 +0300 Subject: [PATCH] Set flag "Auxiliary" for copied features during the Python dump (issue #1899) --- src/SketchAPI/SketchAPI.i | 1 + src/SketchAPI/SketchAPI_Mirror.cpp | 23 ++++++++++++++++++--- src/SketchAPI/SketchAPI_Mirror.h | 3 ++- src/SketchAPI/SketchAPI_Rotation.cpp | 26 +++++++++++++++++++++--- src/SketchAPI/SketchAPI_Rotation.h | 3 ++- src/SketchAPI/SketchAPI_Sketch.cpp | 3 ++- src/SketchAPI/SketchAPI_SketchEntity.cpp | 14 ++++++------- src/SketchAPI/SketchAPI_SketchEntity.h | 2 +- src/SketchAPI/SketchAPI_Translation.cpp | 26 +++++++++++++++++++++--- src/SketchAPI/SketchAPI_Translation.h | 3 ++- 10 files changed, 83 insertions(+), 21 deletions(-) diff --git a/src/SketchAPI/SketchAPI.i b/src/SketchAPI/SketchAPI.i index 524418156..6bc6cf6c6 100644 --- a/src/SketchAPI/SketchAPI.i +++ b/src/SketchAPI/SketchAPI.i @@ -41,6 +41,7 @@ // std::list -> [] %template(InterfaceList) std::list >; +%template(EntityList) std::list >; %typecheck(SWIG_TYPECHECK_POINTER) std::shared_ptr, const std::shared_ptr & { std::shared_ptr * temp_feature; diff --git a/src/SketchAPI/SketchAPI_Mirror.cpp b/src/SketchAPI/SketchAPI_Mirror.cpp index 375bb4578..9e6f40ed9 100644 --- a/src/SketchAPI/SketchAPI_Mirror.cpp +++ b/src/SketchAPI/SketchAPI_Mirror.cpp @@ -39,7 +39,7 @@ SketchAPI_Mirror::~SketchAPI_Mirror() } -std::list > SketchAPI_Mirror::mirrored() const +std::list > SketchAPI_Mirror::mirrored() const { std::list aList = mirroredObjects()->list(); std::list anIntermediate; @@ -65,12 +65,29 @@ void SketchAPI_Mirror::dump(ModelHighAPI_Dumper& theDumper) const // Dump variables for a list of mirrored features theDumper << "["; - std::list > aList = mirrored(); - std::list >::const_iterator anIt = aList.begin(); + std::list > aList = mirrored(); + std::list >::const_iterator anIt = aList.begin(); for (; anIt != aList.end(); ++anIt) { if (anIt != aList.begin()) theDumper << ", "; theDumper << theDumper.name((*anIt)->feature(), false); } theDumper << "] = " << theDumper.name(aBase) << ".mirrored()" << std::endl; + + // Set necessary "auxiliary" flag for mirrored features + // (flag is set if it differs to base entity) + std::list aMirList = aMirrorObjects->list(); + std::list::const_iterator aMIt = aMirList.begin(); + for (anIt = aList.begin(); aMIt != aMirList.end(); ++aMIt, ++anIt) { + FeaturePtr aFeature = ModelAPI_Feature::feature(*aMIt); + if (!aFeature) + continue; + bool aBaseAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value(); + + aFeature = (*anIt)->feature(); + bool aFeatAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value(); + if (aFeatAux != aBaseAux) + theDumper << theDumper.name((*anIt)->feature(), false) + << ".setAuxiliary(" << aFeatAux << ")" < @@ -53,7 +54,7 @@ public: /// List of mirrored objects SKETCHAPI_EXPORT - std::list > mirrored() const; + std::list > mirrored() const; /// Dump wrapped feature virtual void dump(ModelHighAPI_Dumper& theDumper) const; diff --git a/src/SketchAPI/SketchAPI_Rotation.cpp b/src/SketchAPI/SketchAPI_Rotation.cpp index c53964912..2dc0e87d9 100644 --- a/src/SketchAPI/SketchAPI_Rotation.cpp +++ b/src/SketchAPI/SketchAPI_Rotation.cpp @@ -46,7 +46,7 @@ SketchAPI_Rotation::~SketchAPI_Rotation() } -std::list > SketchAPI_Rotation::rotated() const +std::list > SketchAPI_Rotation::rotated() const { std::list aList = rotatedObjects()->list(); // remove all initial features @@ -82,12 +82,32 @@ void SketchAPI_Rotation::dump(ModelHighAPI_Dumper& theDumper) const // Dump variables for a list of rotated features theDumper << "["; - std::list > aList = rotated(); - std::list >::const_iterator anIt = aList.begin(); + std::list > aList = rotated(); + std::list >::const_iterator anIt = aList.begin(); for (; anIt != aList.end(); ++anIt) { if (anIt != aList.begin()) theDumper << ", "; theDumper << theDumper.name((*anIt)->feature(), false); } theDumper << "] = " << theDumper.name(aBase) << ".rotated()" << std::endl; + + // Set necessary "auxiliary" flag for rotated features + // (flag is set if it differs to base entity) + std::list aRotList = aRotObjects->list(); + std::list::const_iterator aRIt = aRotList.begin(); + anIt = aList.begin(); + for (; aRIt != aRotList.end(); ++aRIt) { + FeaturePtr aFeature = ModelAPI_Feature::feature(*aRIt); + if (!aFeature) + continue; + bool aBaseAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value(); + + for (int i = 1; i < aNbCopies->value(); ++i, ++anIt) { + aFeature = (*anIt)->feature(); + bool aFeatAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value(); + if (aFeatAux != aBaseAux) + theDumper << theDumper.name((*anIt)->feature(), false) + << ".setAuxiliary(" << aFeatAux << ")" < @@ -64,7 +65,7 @@ public: /// List of rotated objects SKETCHAPI_EXPORT - std::list > rotated() const; + std::list > rotated() const; /// Dump wrapped feature virtual void dump(ModelHighAPI_Dumper& theDumper) const; diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index cd9f9875c..ffbf1bca9 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -491,9 +491,10 @@ std::shared_ptr SketchAPI_Sketch::setAngle( compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID()); fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT, aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID())); + // fill the value before llines to avoid calculation of angle value by the Angle feature + fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE())); fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())); fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B())); - fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE())); aFeature->execute(); return InterfacePtr(new ModelHighAPI_Interface(aFeature)); } diff --git a/src/SketchAPI/SketchAPI_SketchEntity.cpp b/src/SketchAPI/SketchAPI_SketchEntity.cpp index 914c8baa2..fddc34e65 100644 --- a/src/SketchAPI/SketchAPI_SketchEntity.cpp +++ b/src/SketchAPI/SketchAPI_SketchEntity.cpp @@ -73,22 +73,22 @@ bool SketchAPI_SketchEntity::isCopy() const return isCopy.get() && isCopy->value(); } -std::list > +std::list > SketchAPI_SketchEntity::wrap(const std::list >& theFeatures) { - std::list > aResult; + std::list > aResult; std::list >::const_iterator anIt = theFeatures.begin(); for (; anIt != theFeatures.end(); ++anIt) { if ((*anIt)->getKind() == SketchPlugin_Line::ID()) - aResult.push_back(std::shared_ptr(new SketchAPI_Line(*anIt))); + aResult.push_back(std::shared_ptr(new SketchAPI_Line(*anIt))); else if ((*anIt)->getKind() == SketchPlugin_Arc::ID()) - aResult.push_back(std::shared_ptr(new SketchAPI_Arc(*anIt))); + aResult.push_back(std::shared_ptr(new SketchAPI_Arc(*anIt))); else if ((*anIt)->getKind() == SketchPlugin_Circle::ID()) - aResult.push_back(std::shared_ptr(new SketchAPI_Circle(*anIt))); + aResult.push_back(std::shared_ptr(new SketchAPI_Circle(*anIt))); else if ((*anIt)->getKind() == SketchPlugin_Point::ID()) - aResult.push_back(std::shared_ptr(new SketchAPI_Point(*anIt))); + aResult.push_back(std::shared_ptr(new SketchAPI_Point(*anIt))); else if ((*anIt)->getKind() == SketchPlugin_IntersectionPoint::ID()) - aResult.push_back(std::shared_ptr( + aResult.push_back(std::shared_ptr( new SketchAPI_IntersectionPoint(*anIt))); } return aResult; diff --git a/src/SketchAPI/SketchAPI_SketchEntity.h b/src/SketchAPI/SketchAPI_SketchEntity.h index edf8c665e..4322e7b14 100644 --- a/src/SketchAPI/SketchAPI_SketchEntity.h +++ b/src/SketchAPI/SketchAPI_SketchEntity.h @@ -45,7 +45,7 @@ public: /// Convert list of features to list of appropriate wrappers SKETCHAPI_EXPORT - static std::list > + static std::list > wrap(const std::list >& theFeatures); protected: diff --git a/src/SketchAPI/SketchAPI_Translation.cpp b/src/SketchAPI/SketchAPI_Translation.cpp index 2d5eaa38c..2b69f37ea 100644 --- a/src/SketchAPI/SketchAPI_Translation.cpp +++ b/src/SketchAPI/SketchAPI_Translation.cpp @@ -46,7 +46,7 @@ SketchAPI_Translation::~SketchAPI_Translation() } -std::list > SketchAPI_Translation::translated() const +std::list > SketchAPI_Translation::translated() const { std::list aList = translatedObjects()->list(); // remove all initial features @@ -82,12 +82,32 @@ void SketchAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const // Dump variables for a list of translated features theDumper << "["; - std::list > aList = translated(); - std::list >::const_iterator anIt = aList.begin(); + std::list > aList = translated(); + std::list >::const_iterator anIt = aList.begin(); for (; anIt != aList.end(); ++anIt) { if (anIt != aList.begin()) theDumper << ", "; theDumper << theDumper.name((*anIt)->feature(), false); } theDumper << "] = " << theDumper.name(aBase) << ".translated()" << std::endl; + + // Set necessary "auxiliary" flag for translated features + // (flag is set if it differs to base entity) + std::list aTransList = aTransObjects->list(); + std::list::const_iterator aTrIt = aTransList.begin(); + anIt = aList.begin(); + for (; aTrIt != aTransList.end(); ++aTrIt) { + FeaturePtr aFeature = ModelAPI_Feature::feature(*aTrIt); + if (!aFeature) + continue; + bool aBaseAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value(); + + for (int i = 1; i < aNbCopies->value(); ++i, ++anIt) { + aFeature = (*anIt)->feature(); + bool aFeatAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value(); + if (aFeatAux != aBaseAux) + theDumper << theDumper.name((*anIt)->feature(), false) + << ".setAuxiliary(" << aFeatAux << ")" < @@ -63,7 +64,7 @@ public: /// List of translated objects SKETCHAPI_EXPORT - std::list > translated() const; + std::list > translated() const; /// Dump wrapped feature virtual void dump(ModelHighAPI_Dumper& theDumper) const; -- 2.39.2