]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Dump Python in the High Level Parameterized Geometry API (issue #1648)
authorazv <azv@opencascade.com>
Thu, 11 Aug 2016 08:53:33 +0000 (11:53 +0300)
committerazv <azv@opencascade.com>
Thu, 11 Aug 2016 08:53:33 +0000 (11:53 +0300)
* Dump sketch's MultiTranslation and MultiRotation features
* Fix dumping nested Composite features
* Fix Mirror constraint due to failed unit test

src/FeaturesAPI/FeaturesAPI_Extrusion.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.h
src/SketchAPI/SketchAPI.i
src/SketchAPI/SketchAPI_Rotation.cpp
src/SketchAPI/SketchAPI_Rotation.h
src/SketchAPI/SketchAPI_Translation.cpp
src/SketchAPI/SketchAPI_Translation.h
src/SketchPlugin/Test/TestConstraintMirror.py
src/SketchSolver/SketchSolver_ConstraintMirror.cpp

index 525bddd1c6dd5b891b183eb76153a30355727cff..8f437310f4ac4ab4537ef45d6cd5711e296605df 100644 (file)
@@ -206,7 +206,7 @@ void FeaturesAPI_Extrusion::dump(ModelHighAPI_Dumper& theDumper) const
   theDumper << ")" << std::endl;
 
   if(anAttrSketch->isInitialized()) {
-    theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")";
+    theDumper << aBase << ".setNestedSketch(" << anAttrSketch << ")" << std::endl;
   }
 }
 
index d50d9652ac46677bd9f6cbf5b81f40bf8f2b1c23..efff259272624d4f7b7965828fcf4d6ff9760226 100644 (file)
@@ -19,6 +19,7 @@
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeRefAttrList.h>
+#include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeSelectionList.h>
@@ -185,8 +186,8 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_CompositeFeatur
       isForce = false;
     dumpFeature(aFeature, isForce);
   }
-  // dump command to update model
-  myDumpBuffer << "model.do()" << std::endl;
+  // dump empty line for appearance
+  myDumpBuffer << std::endl;
   return true;
 }
 
@@ -278,6 +279,12 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const std::string& theStrin
   return *this;
 }
 
+ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const bool theValue)
+{
+  myDumpBuffer << (theValue ? "True" : "False");
+  return *this;
+}
+
 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const int theValue)
 {
   myDumpBuffer << theValue;
@@ -436,6 +443,13 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
   return *this;
 }
 
+ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
+    const std::shared_ptr<ModelAPI_AttributeReference>& theReference)
+{
+  *this << theReference->value();
+  return *this;
+}
+
 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
     const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList)
 {
@@ -547,6 +561,12 @@ ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper,
   for (; anIt != aNotDumped.end(); ++anIt) {
     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
     theDumper.dumpFeature(aFeature, true);
+
+    // if the feature is composite, dump all its subs
+    CompositeFeaturePtr aCompFeat =
+        std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
+    if (aCompFeat)
+      theDumper.process(aCompFeat);
   }
 
   // then store currently dumped string
index 161e9e61a2d518e5b6886054ebaa7db538baca6d..2c9edffe4e80cc1f774c5119f111aec30c768837 100644 (file)
@@ -28,6 +28,7 @@ class ModelAPI_AttributeDouble;
 class ModelAPI_AttributeInteger;
 class ModelAPI_AttributeRefAttr;
 class ModelAPI_AttributeRefAttrList;
+class ModelAPI_AttributeReference;
 class ModelAPI_AttributeRefList;
 class ModelAPI_AttributeSelection;
 class ModelAPI_AttributeSelectionList;
@@ -103,6 +104,9 @@ public:
   /// Dump string
   MODELHIGHAPI_EXPORT
   ModelHighAPI_Dumper& operator<<(const std::string& theString);
+  /// Dump boolean
+  MODELHIGHAPI_EXPORT
+  ModelHighAPI_Dumper& operator<<(const bool theValue);
   /// Dump integer
   MODELHIGHAPI_EXPORT
   ModelHighAPI_Dumper& operator<<(const int theValue);
@@ -177,6 +181,9 @@ public:
   /// Dump AttributeSelectionList
   MODELHIGHAPI_EXPORT
   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList);
+  /// Dump AttributeReference
+  MODELHIGHAPI_EXPORT
+  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeReference>& theReference);
 
   /// Clear dump buffer
   MODELHIGHAPI_EXPORT
index 397038e0d0639ec07d8e1efd5869ba0a295fb7ad..1be2156ed81a4a6976d383c992a36daa9fdc7390 100644 (file)
   }
 }
 
+%typecheck(SWIG_TYPECHECK_POINTER) std::list<std::shared_ptr<ModelAPI_Object> >, const std::list<std::shared_ptr<ModelAPI_Object> >& {
+  std::shared_ptr<ModelAPI_Object> * temp_object;
+  std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
+  int newmem = 0;
+  if (PySequence_Check($input)) {
+    for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
+      PyObject * item = PySequence_GetItem($input, i);
+      if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+        if (temp_object) {
+          $1 = 1;
+        } else {
+          $1 = 0;
+          break;
+        }
+      } else
+      if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+        if (temp_interface) {
+          $1 = 1;
+        } else {
+          $1 = 0;
+          break;
+        }
+      }
+      Py_DECREF(item);
+    }
+  } else {
+    $1 = 0;
+  }
+}
+
 // all supported interfaces (the order is very important according dependencies: base class first)
 %include "SketchAPI_SketchEntity.h"
 %include "SketchAPI_Point.h"
index b7b5c546b4bfaa6ddf2c404f398849804adc8133..1f7624e09e7a0c716da8e8a8cc070f0f685ca2d9 100644 (file)
@@ -7,11 +7,12 @@
 //--------------------------------------------------------------------------------------
 #include "SketchAPI_Rotation.h"
 //--------------------------------------------------------------------------------------
+#include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Tools.h>
 //--------------------------------------------------------------------------------------
 SketchAPI_Rotation::SketchAPI_Rotation(
     const std::shared_ptr<ModelAPI_Feature> & theFeature)
-: SketchAPI_SketchEntity(theFeature)
+: ModelHighAPI_Interface(theFeature)
 {
   initialize();
 }
@@ -23,15 +24,14 @@ SketchAPI_Rotation::SketchAPI_Rotation(
     const ModelHighAPI_Double & theAngle,
     const ModelHighAPI_Integer & theNumberOfObjects,
     bool theFullValue)
-: SketchAPI_SketchEntity(theFeature)
+: ModelHighAPI_Interface(theFeature)
 {
   if (initialize()) {
     fillAttribute(theObjects, rotationList());
     fillAttribute(theCenter, center());
     fillAttribute(theAngle, angle());
     fillAttribute(theNumberOfObjects, numberOfObjects());
-    if (theFullValue)
-      fillAttribute("SingleAngle", valueType());
+    fillAttribute(theFullValue ? "FullAngle" : "SingleAngle", valueType());
 
     execute();
   }
@@ -43,3 +43,21 @@ SketchAPI_Rotation::~SketchAPI_Rotation()
 }
 
 //--------------------------------------------------------------------------------------
+
+void SketchAPI_Rotation::dump(ModelHighAPI_Dumper& theDumper) const
+{
+  FeaturePtr aBase = feature();
+  const std::string& aSketchName = theDumper.parentName(aBase);
+
+  AttributeRefListPtr aRotObjects = rotationList();
+  AttributeRefAttrPtr aCenter = center();
+  AttributeDoublePtr anAngle = angle();
+  AttributeIntegerPtr aNbCopies = numberOfObjects();
+  bool isFullValue = valueType()->value() != "SingleAngle";
+
+  theDumper << aBase << " = " << aSketchName << ".addRotation("
+            << aRotObjects << ", " << aCenter << ", " << anAngle << ", " << aNbCopies;
+  if (isFullValue)
+    theDumper << ", " << isFullValue;
+  theDumper << ")" << std::endl;
+}
index e5a3281b4531fa462ffb8366d8925c50f85f39ae..800c4c521ba25065dd1f600eefb3a7fe0fa5f593 100644 (file)
@@ -14,7 +14,8 @@
 
 #include <SketchPlugin_MultiRotation.h>
 
-#include "SketchAPI_SketchEntity.h"
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
 //--------------------------------------------------------------------------------------
 class ModelAPI_Object;
 class ModelHighAPI_Double;
@@ -25,7 +26,7 @@ class ModelHighAPI_RefAttr;
  * \ingroup CPPHighAPI
  * \brief Interface for Rotation feature
  */
-class SketchAPI_Rotation : public SketchAPI_SketchEntity
+class SketchAPI_Rotation : public ModelHighAPI_Interface
 {
 public:
   /// Constructor without values
@@ -53,6 +54,8 @@ public:
               rotatedObjects, SketchPlugin_MultiRotation::ENTITY_B(), ModelAPI_AttributeRefList, /** Rotated objects */
   )
 
+  /// Dump wrapped feature
+  virtual void dump(ModelHighAPI_Dumper& theDumper) const;
 };
 
 //! Pointer on Rotation object
index 0ba3e3b3faf624e36229b5052967bf8492d7fa7d..efa16508783246a5ab92300855c52571b213e8e0 100644 (file)
@@ -7,11 +7,12 @@
 //--------------------------------------------------------------------------------------
 #include "SketchAPI_Translation.h"
 //--------------------------------------------------------------------------------------
+#include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Tools.h>
 //--------------------------------------------------------------------------------------
 SketchAPI_Translation::SketchAPI_Translation(
     const std::shared_ptr<ModelAPI_Feature> & theFeature)
-: SketchAPI_SketchEntity(theFeature)
+: ModelHighAPI_Interface(theFeature)
 {
   initialize();
 }
@@ -23,15 +24,14 @@ SketchAPI_Translation::SketchAPI_Translation(
     const ModelHighAPI_RefAttr & thePoint2,
     const ModelHighAPI_Integer & theNumberOfObjects,
     bool theFullValue)
-: SketchAPI_SketchEntity(theFeature)
+: ModelHighAPI_Interface(theFeature)
 {
   if (initialize()) {
     fillAttribute(theObjects, translationList());
     fillAttribute(thePoint1, startPoint());
     fillAttribute(thePoint2, endPoint());
     fillAttribute(theNumberOfObjects, numberOfObjects());
-    if (theFullValue)
-      fillAttribute("SingleValue", valueType());
+    fillAttribute(theFullValue ? "FullValue" : "SingleValue", valueType());
 
     execute();
   }
@@ -43,3 +43,21 @@ SketchAPI_Translation::~SketchAPI_Translation()
 }
 
 //--------------------------------------------------------------------------------------
+
+void SketchAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
+{
+  FeaturePtr aBase = feature();
+  const std::string& aSketchName = theDumper.parentName(aBase);
+
+  AttributeRefListPtr aTransObjects = translationList();
+  AttributeRefAttrPtr aStart = startPoint();
+  AttributeRefAttrPtr aEnd   = endPoint();
+  AttributeIntegerPtr aNbCopies = numberOfObjects();
+  bool isFullValue = valueType()->value() != "SingleValue";
+
+  theDumper << aBase << " = " << aSketchName << ".addTranslation("
+            << aTransObjects << ", " << aStart << ", " << aEnd << ", " << aNbCopies;
+  if (isFullValue)
+    theDumper << ", " << isFullValue;
+  theDumper << ")" << std::endl;
+}
index 7b6da8f5eb526c884907f229ddfcf22c99b17459..4e3fd270f9391d825b8faca65584b2189b88c272 100644 (file)
@@ -14,7 +14,8 @@
 
 #include <SketchPlugin_MultiTranslation.h>
 
-#include "SketchAPI_SketchEntity.h"
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
 //--------------------------------------------------------------------------------------
 class ModelAPI_Object;
 class ModelHighAPI_Integer;
@@ -24,7 +25,7 @@ class ModelHighAPI_RefAttr;
  * \ingroup CPPHighAPI
  * \brief Interface for Translation feature
  */
-class SketchAPI_Translation : public SketchAPI_SketchEntity
+class SketchAPI_Translation : public ModelHighAPI_Interface
 {
 public:
   /// Constructor without values
@@ -52,6 +53,8 @@ public:
               translatedObjects, SketchPlugin_MultiTranslation::ENTITY_B(), ModelAPI_AttributeRefList, /** Translationed objects */
   )
 
+  /// Dump wrapped feature
+  virtual void dump(ModelHighAPI_Dumper& theDumper) const;
 };
 
 //! Pointer on Translation object
index bbf74982a86484fac94d9c9d0f80eca931c719e5..1d06c8d6abdad6aba2c08a000ff454666142d668 100644 (file)
@@ -28,7 +28,7 @@ def normalize(theDir):
     return [theDir[0] / aLen, theDir[1] / aLen]
 
 def checkMirror(theListInit, theListMirr, theMirrorLine):
-    TOL = 5.e-5
+    TOL = 6.e-5
     aListSize = theListInit.size()
     
     aLineStartPoint = geomDataAPI_Point2D(theMirrorLine.attribute("StartPoint"))
index b505b2f79fdc9bcf0b5bd21c3fb37c07a1df74d9..fdb181948a6649c6d11f454ecca509c53ba450b1 100644 (file)
@@ -79,18 +79,18 @@ void SketchSolver_ConstraintMirror::process()
   BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
   std::list<ConstraintWrapperPtr> aMirConstrList;
 
-  std::vector<EntityWrapperPtr>::iterator aBIt = aBaseList.begin();
+  // update mirrored features to be in the current group
   std::vector<EntityWrapperPtr>::iterator aMIt = aMirrorList.begin();
-  for (; aBIt != aBaseList.end(); ++aBIt, ++aMIt) {
+  for (; aMIt != aMirrorList.end(); ++aMIt)
+    myStorage->update((*aMIt)->baseFeature(), myGroupID);
+
+  std::vector<EntityWrapperPtr>::iterator aBIt = aBaseList.begin();
+  for (aMIt = aMirrorList.begin(); aBIt != aBaseList.end(); ++aBIt, ++aMIt) {
     aNewConstraints = aBuilder->createConstraint(
         myBaseConstraint, myGroupID, mySketchID, aConstrType,
         0.0, *aBIt, *aMIt, aMirrorLine);
     aMirConstrList.insert(aMirConstrList.end(), aNewConstraints.begin(), aNewConstraints.end());
   }
-
-  // update mirrored features to be in the current group
-  for (aMIt = aMirrorList.begin(); aMIt != aMirrorList.end(); ++aMIt)
-    myStorage->update((*aMIt)->baseFeature(), myGroupID);
   myStorage->addConstraint(myBaseConstraint, aMirConstrList);
 
   adjustConstraint();