Salome HOME
Dump names of features copied in Multi-Translation, Multi-Rotation and Mirror macro...
authorazv <azv@opencascade.com>
Fri, 2 Sep 2016 13:24:00 +0000 (16:24 +0300)
committerazv <azv@opencascade.com>
Fri, 2 Sep 2016 13:24:22 +0000 (16:24 +0300)
12 files changed:
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.h
src/PythonAPI/model/dump/DumpAssistant.py
src/SketchAPI/SketchAPI.i
src/SketchAPI/SketchAPI_Mirror.cpp
src/SketchAPI/SketchAPI_Mirror.h
src/SketchAPI/SketchAPI_Rotation.cpp
src/SketchAPI/SketchAPI_Rotation.h
src/SketchAPI/SketchAPI_SketchEntity.cpp
src/SketchAPI/SketchAPI_SketchEntity.h
src/SketchAPI/SketchAPI_Translation.cpp
src/SketchAPI/SketchAPI_Translation.h

index 5086d766232c27161606df30747f0890372a7e81..c2ae64971f3a46d898f999a93937f4de45c5a959 100644 (file)
@@ -225,7 +225,7 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_CompositeFeatur
   ++gCompositeStackDepth;
   // dump composite itself
   if (!isDumped(theComposite) || isForce)
-    dumpFeature(theComposite, isForce);
+    dumpFeature(FeaturePtr(theComposite), isForce);
 
   // sub-part is processed independently, because it provides separate document
   if (theComposite->getKind() == 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;
 }
 
index 026f955c0ca1df1648ac07fd670054f7b97be9c5..cdd2fdde6bb8d737432e3319e98ba74814140761 100644 (file)
@@ -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);
index b4a27add1a8050dc10a825b2f209a7497cd840de..d32cb19baa56eab81cea2f4bddf32c8dbe1d562d 100644 (file)
@@ -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
index c9638a205a48b7f4d9dd17020a96d8717b1f0013..5244181562c374d5b90ec09cffb339718c3a123c 100644 (file)
@@ -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
 %shared_ptr(SketchAPI_Rotation)
 %shared_ptr(SketchAPI_Translation)
 
+// std::list -> []
+%template(InterfaceList) std::list<std::shared_ptr<ModelHighAPI_Interface> >;
+
+%typecheck(SWIG_TYPECHECK_POINTER) std::shared_ptr<ModelAPI_Feature>, const std::shared_ptr<ModelAPI_Feature> & {
+  std::shared_ptr<ModelAPI_Feature> * temp_feature;
+  std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
+  int newmem = 0;
+  if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_feature, $descriptor(std::shared_ptr<ModelAPI_Feature> *), 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<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+    if (temp_interface) {
+      $1 = 1;
+    } else {
+      $1 = 0;
+    }
+  } else
+    $1 = 0;
+}
+
+%typemap(in) const std::shared_ptr<ModelAPI_Feature> & (std::shared_ptr<ModelAPI_Feature> temp) {
+  std::shared_ptr<ModelAPI_Feature> * temp_feature;
+  std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
+  int newmem = 0;
+  if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_feature, $descriptor(std::shared_ptr<ModelAPI_Feature> *), 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<ModelHighAPI_Interface> *), 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<ModelAPI_Attribute> * temp_attribute;
   std::shared_ptr<ModelAPI_Object> * temp_object;
index 32abfc90bf3ddebb0f6ff9a1e36acc88dfcebab0..0039dffb8ba78e9c37286ae2d3fcb916ea9ebb55 100644 (file)
@@ -6,6 +6,7 @@
 
 //--------------------------------------------------------------------------------------
 #include "SketchAPI_Mirror.h"
+#include <SketchAPI_SketchEntity.h>
 //--------------------------------------------------------------------------------------
 #include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Selection.h>
@@ -37,6 +38,18 @@ SketchAPI_Mirror::~SketchAPI_Mirror()
 
 }
 
+std::list<std::shared_ptr<ModelHighAPI_Interface> > SketchAPI_Mirror::mirrored() const
+{
+  std::list<ObjectPtr> aList = mirroredObjects()->list();
+  std::list<FeaturePtr> anIntermediate;
+  std::list<ObjectPtr>::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<std::shared_ptr<ModelHighAPI_Interface> > aList = mirrored();
+  std::list<std::shared_ptr<ModelHighAPI_Interface> >::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;
 }
index ab77061ea8671ad68ffb505cd9b2061d58201e15..4de2f172f6dc6932c2f72f6b229fabd59de37db4 100644 (file)
@@ -46,6 +46,10 @@ public:
               mirroredObjects, SketchPlugin_ConstraintMirror::ENTITY_C(), ModelAPI_AttributeRefList, /** Mirrored objects */
   )
 
+  /// List of mirrored objects
+  SKETCHAPI_EXPORT
+  std::list<std::shared_ptr<ModelHighAPI_Interface> > mirrored() const;
+
   /// Dump wrapped feature
   virtual void dump(ModelHighAPI_Dumper& theDumper) const;
 };
index 87f7e805b366a896c91dcd5d52ce0811ed030fb1..57fd4bf15867b8c32ad15ad7f067ce71d4c9a97f 100644 (file)
@@ -6,9 +6,12 @@
 
 //--------------------------------------------------------------------------------------
 #include "SketchAPI_Rotation.h"
+#include <SketchAPI_SketchEntity.h>
 //--------------------------------------------------------------------------------------
 #include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Tools.h>
+
+#include <SketchPlugin_SketchEntity.h>
 //--------------------------------------------------------------------------------------
 SketchAPI_Rotation::SketchAPI_Rotation(
     const std::shared_ptr<ModelAPI_Feature> & theFeature)
@@ -42,6 +45,21 @@ SketchAPI_Rotation::~SketchAPI_Rotation()
 
 }
 
+std::list<std::shared_ptr<ModelHighAPI_Interface> > SketchAPI_Rotation::rotated() const
+{
+  std::list<ObjectPtr> aList = rotatedObjects()->list();
+  // remove all initial features
+  std::list<FeaturePtr> anIntermediate;
+  std::list<ObjectPtr>::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<std::shared_ptr<ModelHighAPI_Interface> > aList = rotated();
+  std::list<std::shared_ptr<ModelHighAPI_Interface> >::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;
 }
index 800c4c521ba25065dd1f600eefb3a7fe0fa5f593..2f58d77605df198fe59749f686f14b7f3065ca45 100644 (file)
@@ -54,6 +54,10 @@ public:
               rotatedObjects, SketchPlugin_MultiRotation::ENTITY_B(), ModelAPI_AttributeRefList, /** Rotated objects */
   )
 
+  /// List of rotated objects
+  SKETCHAPI_EXPORT
+  std::list<std::shared_ptr<ModelHighAPI_Interface> > rotated() const;
+
   /// Dump wrapped feature
   virtual void dump(ModelHighAPI_Dumper& theDumper) const;
 };
index f6cfdc17a50c1c7b4bca3dbd783ef4c99c8f8278..24758c6803b8f70bd7422ec95e202a613b8d493a 100644 (file)
@@ -6,9 +6,20 @@
 
 //--------------------------------------------------------------------------------------
 #include "SketchAPI_SketchEntity.h"
+#include <SketchAPI_Arc.h>
+#include <SketchAPI_Circle.h>
+#include <SketchAPI_IntersectionPoint.h>
+#include <SketchAPI_Line.h>
+#include <SketchAPI_Point.h>
 //--------------------------------------------------------------------------------------
 #include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Tools.h>
+
+#include <SketchPlugin_Arc.h>
+#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_IntersectionPoint.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Point.h>
 //--------------------------------------------------------------------------------------
 SketchAPI_SketchEntity::SketchAPI_SketchEntity(
     const std::shared_ptr<ModelAPI_Feature> & 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<std::shared_ptr<ModelHighAPI_Interface> >
+SketchAPI_SketchEntity::wrap(const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures)
+{
+  std::list<std::shared_ptr<ModelHighAPI_Interface> > aResult;
+  std::list<std::shared_ptr<ModelAPI_Feature> >::const_iterator anIt = theFeatures.begin();
+  for (; anIt != theFeatures.end(); ++anIt) {
+    if ((*anIt)->getKind() == SketchPlugin_Line::ID())
+      aResult.push_back(std::shared_ptr<ModelHighAPI_Interface>(new SketchAPI_Line(*anIt)));
+    else if ((*anIt)->getKind() == SketchPlugin_Arc::ID())
+      aResult.push_back(std::shared_ptr<ModelHighAPI_Interface>(new SketchAPI_Arc(*anIt)));
+    else if ((*anIt)->getKind() == SketchPlugin_Circle::ID())
+      aResult.push_back(std::shared_ptr<ModelHighAPI_Interface>(new SketchAPI_Circle(*anIt)));
+    else if ((*anIt)->getKind() == SketchPlugin_Point::ID())
+      aResult.push_back(std::shared_ptr<ModelHighAPI_Interface>(new SketchAPI_Point(*anIt)));
+    else if ((*anIt)->getKind() == SketchPlugin_IntersectionPoint::ID())
+      aResult.push_back(std::shared_ptr<ModelHighAPI_Interface>(new SketchAPI_IntersectionPoint(*anIt)));
+  }
+  return aResult;
+}
index fcc8639008b85b916dccf3e3249039ee7581297d..77773910f8f5f6518119960061261a629f27c5e7 100644 (file)
@@ -14,6 +14,8 @@
 
 #include <ModelHighAPI_Interface.h>
 #include <ModelHighAPI_Macro.h>
+
+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<std::shared_ptr<ModelHighAPI_Interface> >
+  wrap(const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures);
+
 protected:
   std::shared_ptr<ModelAPI_AttributeBoolean> myAuxiliary;
 
index 4fff83bbeb4f2b5b281d5fd4e7bc6b12f25b68f3..53c18e97100a8971271801c699d48934ddb18494 100644 (file)
@@ -6,9 +6,12 @@
 
 //--------------------------------------------------------------------------------------
 #include "SketchAPI_Translation.h"
+#include <SketchAPI_SketchEntity.h>
 //--------------------------------------------------------------------------------------
 #include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Tools.h>
+
+#include <SketchPlugin_SketchEntity.h>
 //--------------------------------------------------------------------------------------
 SketchAPI_Translation::SketchAPI_Translation(
     const std::shared_ptr<ModelAPI_Feature> & theFeature)
@@ -42,6 +45,21 @@ SketchAPI_Translation::~SketchAPI_Translation()
 
 }
 
+std::list<std::shared_ptr<ModelHighAPI_Interface> > SketchAPI_Translation::translated() const
+{
+  std::list<ObjectPtr> aList = translatedObjects()->list();
+  // remove all initial features
+  std::list<FeaturePtr> anIntermediate;
+  std::list<ObjectPtr>::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<std::shared_ptr<ModelHighAPI_Interface> > aList = translated();
+  std::list<std::shared_ptr<ModelHighAPI_Interface> >::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;
 }
index 4e3fd270f9391d825b8faca65584b2189b88c272..b6093844494600a6b8ce88d014992534bc381c36 100644 (file)
@@ -53,6 +53,10 @@ public:
               translatedObjects, SketchPlugin_MultiTranslation::ENTITY_B(), ModelAPI_AttributeRefList, /** Translationed objects */
   )
 
+  /// List of translated objects
+  SKETCHAPI_EXPORT
+  std::list<std::shared_ptr<ModelHighAPI_Interface> > translated() const;
+
   /// Dump wrapped feature
   virtual void dump(ModelHighAPI_Dumper& theDumper) const;
 };