From: azv Date: Fri, 2 Sep 2016 13:24:00 +0000 (+0300) Subject: Dump names of features copied in Multi-Translation, Multi-Rotation and Mirror macro... X-Git-Tag: V_2.5.0~73 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b0e217e6399717e35fcfe2ada28dd6c5213d3721;p=modules%2Fshaper.git Dump names of features copied in Multi-Translation, Multi-Rotation and Mirror macro. This features may be used in the constraints. --- diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index 5086d7662..c2ae64971 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -225,7 +225,7 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptrgetKind() == PartSetPlugin_Part::ID()) { @@ -610,7 +610,19 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const ObjectPtr& theObject) ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const AttributePtr& theAttr) { FeaturePtr anOwner = ModelAPI_Feature::feature(theAttr->owner()); - myDumpBuffer << name(anOwner) << "." << attributeGetter(anOwner, theAttr->id()) << "()"; + + std::string aWrapperPrefix, aWrapperSuffix; + // Check the attribute belongs to copied (in multi-translation or multi-rotation) feature. + // In this case we need to cast explicitly feature to appropriate type. + AttributeBooleanPtr isCopy = anOwner->boolean("Copy"); + if (isCopy.get() && isCopy->value()) { + aWrapperPrefix = featureWrapper(anOwner) + "("; + aWrapperSuffix = ")"; + importModule("SketchAPI"); + } + + myDumpBuffer << aWrapperPrefix << name(anOwner) << aWrapperSuffix + << "." << attributeGetter(anOwner, theAttr->id()) << "()"; return *this; } diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.h b/src/ModelHighAPI/ModelHighAPI_Dumper.h index 026f955c0..cdd2fdde6 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.h +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.h @@ -110,6 +110,9 @@ public: virtual std::string attributeGetter(const FeaturePtr& theFeature, const std::string& theAttrName) const = 0; + /// Return name of wrapper feature + virtual std::string featureWrapper(const FeaturePtr& theFeature) const = 0; + /// Save all dumps into specified file MODELHIGHAPI_EXPORT bool exportTo(const std::string& theFileName); diff --git a/src/PythonAPI/model/dump/DumpAssistant.py b/src/PythonAPI/model/dump/DumpAssistant.py index b4a27add1..d32cb19ba 100644 --- a/src/PythonAPI/model/dump/DumpAssistant.py +++ b/src/PythonAPI/model/dump/DumpAssistant.py @@ -29,10 +29,12 @@ class DumpAssistant(ModelHighAPI.ModelHighAPI_Dumper): ## Collect feature wrappers, which allow dumping (have method dump) def collectFeatures(self): self.myFeatures = {} + self.myWrapperNames = {} for aModule in sys.modules: for aName, anObj in inspect.getmembers(sys.modules[aModule], inspect.isclass): if issubclass(anObj, ModelHighAPI.ModelHighAPI_Interface) and hasattr(anObj, "ID") and anObj.dump != ModelHighAPI.ModelHighAPI_Interface.dump: self.myFeatures[anObj.ID()] = anObj + self.myWrapperNames[anObj.ID()] = aName ## Create wrapper for a given feature and dump it def dumpFeature(self, theFeature, theForce): @@ -63,5 +65,12 @@ class DumpAssistant(ModelHighAPI.ModelHighAPI_Dumper): return self.myFeatures[aFeatureKind](theFeature).attributeGetter(theAttrName) return std_string() + ## Return name of wrapper feature + def featureWrapper(self, theFeature): + aFeatureKind = theFeature.getKind() + if aFeatureKind in self.myWrapperNames: + return self.myWrapperNames[aFeatureKind] + return std_string() + # Instance of dumper dumper = DumpAssistant \ No newline at end of file diff --git a/src/SketchAPI/SketchAPI.i b/src/SketchAPI/SketchAPI.i index c9638a205..524418156 100644 --- a/src/SketchAPI/SketchAPI.i +++ b/src/SketchAPI/SketchAPI.i @@ -4,11 +4,16 @@ %{ #include "SketchAPI_swig.h" + #include "ModelHighAPI_swig.h" + + // fix for SWIG v2.0.4 + #define SWIGPY_SLICE_ARG(obj) ((PySliceObject*)(obj)) %} %include "doxyhelp.i" // import other modules +%import "ModelAPI.i" %import "ModelHighAPI.i" // to avoid error on this @@ -34,6 +39,63 @@ %shared_ptr(SketchAPI_Rotation) %shared_ptr(SketchAPI_Translation) +// std::list -> [] +%template(InterfaceList) std::list >; + +%typecheck(SWIG_TYPECHECK_POINTER) std::shared_ptr, const std::shared_ptr & { + std::shared_ptr * temp_feature; + std::shared_ptr * temp_interface; + int newmem = 0; + if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_feature, $descriptor(std::shared_ptr *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (temp_feature) { + $1 = 1; + } else { + $1 = 0; + } + } else + if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (temp_interface) { + $1 = 1; + } else { + $1 = 0; + } + } else + $1 = 0; +} + +%typemap(in) const std::shared_ptr & (std::shared_ptr temp) { + std::shared_ptr * temp_feature; + std::shared_ptr * temp_interface; + int newmem = 0; + if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_feature, $descriptor(std::shared_ptr *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (!temp_feature) { + PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Interface."); + return NULL; + } + temp = (*temp_feature); + if (newmem & SWIG_CAST_NEW_MEMORY) { + delete temp_feature; + } + $1 = &temp; + } else + if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (!temp_interface) { + PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Interface."); + return NULL; + } + temp = (*temp_interface)->feature(); + if (newmem & SWIG_CAST_NEW_MEMORY) { + delete temp_interface; + } + $1 = &temp; + } else + if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) { + } else { + PyErr_SetString(PyExc_ValueError, "argument must be ModelHighAPI_Interface."); + return NULL; + } +} + %typemap(in) const ModelHighAPI_RefAttr & (ModelHighAPI_RefAttr temp) { std::shared_ptr * temp_attribute; std::shared_ptr * temp_object; diff --git a/src/SketchAPI/SketchAPI_Mirror.cpp b/src/SketchAPI/SketchAPI_Mirror.cpp index 32abfc90b..0039dffb8 100644 --- a/src/SketchAPI/SketchAPI_Mirror.cpp +++ b/src/SketchAPI/SketchAPI_Mirror.cpp @@ -6,6 +6,7 @@ //-------------------------------------------------------------------------------------- #include "SketchAPI_Mirror.h" +#include //-------------------------------------------------------------------------------------- #include #include @@ -37,6 +38,18 @@ SketchAPI_Mirror::~SketchAPI_Mirror() } +std::list > SketchAPI_Mirror::mirrored() const +{ + std::list aList = mirroredObjects()->list(); + std::list anIntermediate; + std::list::const_iterator anIt = aList.begin(); + for (; anIt != aList.end(); ++anIt) { + FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt); + anIntermediate.push_back(aFeature); + } + return SketchAPI_SketchEntity::wrap(anIntermediate); +} + //-------------------------------------------------------------------------------------- void SketchAPI_Mirror::dump(ModelHighAPI_Dumper& theDumper) const @@ -48,4 +61,15 @@ void SketchAPI_Mirror::dump(ModelHighAPI_Dumper& theDumper) const AttributeRefListPtr aMirrorObjects = mirrorList(); theDumper << aBase << " = " << aSketchName << ".addMirror(" << aMirrorLine << ", " << aMirrorObjects << ")" << std::endl; + + // Dump variables for a list of mirrored features + theDumper << "["; + 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; } diff --git a/src/SketchAPI/SketchAPI_Mirror.h b/src/SketchAPI/SketchAPI_Mirror.h index ab77061ea..4de2f172f 100644 --- a/src/SketchAPI/SketchAPI_Mirror.h +++ b/src/SketchAPI/SketchAPI_Mirror.h @@ -46,6 +46,10 @@ public: mirroredObjects, SketchPlugin_ConstraintMirror::ENTITY_C(), ModelAPI_AttributeRefList, /** Mirrored objects */ ) + /// List of mirrored objects + SKETCHAPI_EXPORT + 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 87f7e805b..57fd4bf15 100644 --- a/src/SketchAPI/SketchAPI_Rotation.cpp +++ b/src/SketchAPI/SketchAPI_Rotation.cpp @@ -6,9 +6,12 @@ //-------------------------------------------------------------------------------------- #include "SketchAPI_Rotation.h" +#include //-------------------------------------------------------------------------------------- #include #include + +#include //-------------------------------------------------------------------------------------- SketchAPI_Rotation::SketchAPI_Rotation( const std::shared_ptr & theFeature) @@ -42,6 +45,21 @@ SketchAPI_Rotation::~SketchAPI_Rotation() } +std::list > SketchAPI_Rotation::rotated() const +{ + std::list aList = rotatedObjects()->list(); + // remove all initial features + std::list anIntermediate; + std::list::const_iterator anIt = aList.begin(); + for (; anIt != aList.end(); ++anIt) { + FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt); + AttributeBooleanPtr isCopy = aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID()); + if (isCopy.get() && isCopy->value()) + anIntermediate.push_back(aFeature); + } + return SketchAPI_SketchEntity::wrap(anIntermediate); +} + //-------------------------------------------------------------------------------------- void SketchAPI_Rotation::dump(ModelHighAPI_Dumper& theDumper) const @@ -60,4 +78,15 @@ void SketchAPI_Rotation::dump(ModelHighAPI_Dumper& theDumper) const if (isFullValue) theDumper << ", " << isFullValue; theDumper << ")" << std::endl; + + // Dump variables for a list of rotated features + theDumper << "["; + 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; } diff --git a/src/SketchAPI/SketchAPI_Rotation.h b/src/SketchAPI/SketchAPI_Rotation.h index 800c4c521..2f58d7760 100644 --- a/src/SketchAPI/SketchAPI_Rotation.h +++ b/src/SketchAPI/SketchAPI_Rotation.h @@ -54,6 +54,10 @@ public: rotatedObjects, SketchPlugin_MultiRotation::ENTITY_B(), ModelAPI_AttributeRefList, /** Rotated objects */ ) + /// List of rotated objects + SKETCHAPI_EXPORT + std::list > rotated() const; + /// Dump wrapped feature virtual void dump(ModelHighAPI_Dumper& theDumper) const; }; diff --git a/src/SketchAPI/SketchAPI_SketchEntity.cpp b/src/SketchAPI/SketchAPI_SketchEntity.cpp index f6cfdc17a..24758c680 100644 --- a/src/SketchAPI/SketchAPI_SketchEntity.cpp +++ b/src/SketchAPI/SketchAPI_SketchEntity.cpp @@ -6,9 +6,20 @@ //-------------------------------------------------------------------------------------- #include "SketchAPI_SketchEntity.h" +#include +#include +#include +#include +#include //-------------------------------------------------------------------------------------- #include #include + +#include +#include +#include +#include +#include //-------------------------------------------------------------------------------------- SketchAPI_SketchEntity::SketchAPI_SketchEntity( const std::shared_ptr & theFeature) @@ -60,3 +71,23 @@ bool SketchAPI_SketchEntity::isCopy() const AttributeBooleanPtr isCopy = feature()->boolean(SketchPlugin_SketchEntity::COPY_ID()); return isCopy.get() && isCopy->value(); } + +std::list > +SketchAPI_SketchEntity::wrap(const std::list >& theFeatures) +{ + 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))); + else if ((*anIt)->getKind() == SketchPlugin_Arc::ID()) + 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))); + else if ((*anIt)->getKind() == SketchPlugin_Point::ID()) + aResult.push_back(std::shared_ptr(new SketchAPI_Point(*anIt))); + else if ((*anIt)->getKind() == SketchPlugin_IntersectionPoint::ID()) + 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 fcc863900..77773910f 100644 --- a/src/SketchAPI/SketchAPI_SketchEntity.h +++ b/src/SketchAPI/SketchAPI_SketchEntity.h @@ -14,6 +14,8 @@ #include #include + +class ModelAPI_Feature; //-------------------------------------------------------------------------------------- /**\class SketchAPI_SketchEntity * \ingroup CPPHighAPI @@ -40,6 +42,11 @@ public: /// Dump wrapped feature virtual void dump(ModelHighAPI_Dumper& theDumper) const; + /// Convert list of features to list of appropriate wrappers + SKETCHAPI_EXPORT + static std::list > + wrap(const std::list >& theFeatures); + protected: std::shared_ptr myAuxiliary; diff --git a/src/SketchAPI/SketchAPI_Translation.cpp b/src/SketchAPI/SketchAPI_Translation.cpp index 4fff83bbe..53c18e971 100644 --- a/src/SketchAPI/SketchAPI_Translation.cpp +++ b/src/SketchAPI/SketchAPI_Translation.cpp @@ -6,9 +6,12 @@ //-------------------------------------------------------------------------------------- #include "SketchAPI_Translation.h" +#include //-------------------------------------------------------------------------------------- #include #include + +#include //-------------------------------------------------------------------------------------- SketchAPI_Translation::SketchAPI_Translation( const std::shared_ptr & theFeature) @@ -42,6 +45,21 @@ SketchAPI_Translation::~SketchAPI_Translation() } +std::list > SketchAPI_Translation::translated() const +{ + std::list aList = translatedObjects()->list(); + // remove all initial features + std::list anIntermediate; + std::list::const_iterator anIt = aList.begin(); + for (; anIt != aList.end(); ++anIt) { + FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt); + AttributeBooleanPtr isCopy = aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID()); + if (isCopy.get() && isCopy->value()) + anIntermediate.push_back(aFeature); + } + return SketchAPI_SketchEntity::wrap(anIntermediate); +} + //-------------------------------------------------------------------------------------- void SketchAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const @@ -60,4 +78,15 @@ void SketchAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const if (isFullValue) theDumper << ", " << isFullValue; theDumper << ")" << std::endl; + + // Dump variables for a list of translated features + theDumper << "["; + 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; } diff --git a/src/SketchAPI/SketchAPI_Translation.h b/src/SketchAPI/SketchAPI_Translation.h index 4e3fd270f..b60938444 100644 --- a/src/SketchAPI/SketchAPI_Translation.h +++ b/src/SketchAPI/SketchAPI_Translation.h @@ -53,6 +53,10 @@ public: translatedObjects, SketchPlugin_MultiTranslation::ENTITY_B(), ModelAPI_AttributeRefList, /** Translationed objects */ ) + /// List of translated objects + SKETCHAPI_EXPORT + std::list > translated() const; + /// Dump wrapped feature virtual void dump(ModelHighAPI_Dumper& theDumper) const; };