]> 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>
Wed, 10 Aug 2016 10:37:40 +0000 (13:37 +0300)
committerazv <azv@opencascade.com>
Wed, 10 Aug 2016 10:38:33 +0000 (13:38 +0300)
* Dump Mirror constraint
* Specific dump methods for AttributeRefList and AttributeRefAttrList
* Bug with Mirror constraint processing has been fixed (PlaneGCS solver)

src/ModelHighAPI/CMakeLists.txt
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.h
src/SketchAPI/SketchAPI_Constraint.cpp
src/SketchAPI/SketchAPI_Mirror.cpp
src/SketchAPI/SketchAPI_Mirror.h
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp

index d92154841749757bb82135c7e422a7aeee17581c..dbecf0c6b4720a799a109e04830dc282d45b66eb 100644 (file)
@@ -55,11 +55,13 @@ SET(SWIG_LINK_LIBRARIES
 )
 
 INCLUDE_DIRECTORIES(
+  ${PROJECT_SOURCE_DIR}/src/Config
   ${PROJECT_SOURCE_DIR}/src/Events
   ${PROJECT_SOURCE_DIR}/src/GeomAPI
   ${PROJECT_SOURCE_DIR}/src/GeomDataAPI
   ${PROJECT_SOURCE_DIR}/src/ModelAPI
   ${PROJECT_SOURCE_DIR}/src/PartSetPlugin
+  ${PROJECT_SOURCE_DIR}/src/SketchPlugin
   ${CAS_INCLUDE_DIRS}
 )
 
index 72d4623cc8f85345e737b76ab8b49454af458ebf..d50d9652ac46677bd9f6cbf5b81f40bf8f2b1c23 100644 (file)
@@ -18,6 +18,8 @@
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefAttrList.h>
+#include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
@@ -30,6 +32,8 @@
 
 #include <PartSetPlugin_Part.h>
 
+#include <SketchPlugin_SketchEntity.h>
+
 #include <OSD_OpenFile.hxx>
 
 #include <algorithm>
@@ -171,8 +175,15 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_CompositeFeatur
   int aNbSubs = theComposite->numberOfSubs();
   for (int anIndex = 0; anIndex < aNbSubs; ++anIndex) {
     FeaturePtr aFeature = theComposite->subFeature(anIndex);
-    if (!isDumped(aFeature))
-      dumpFeature(aFeature, true);
+    if (isDumped(aFeature))
+      continue;
+    bool isForce = true;
+    // check the feature is a sketch entity and a copy of another entity
+    std::shared_ptr<SketchPlugin_SketchEntity> aSketchEntity =
+        std::dynamic_pointer_cast<SketchPlugin_SketchEntity>(aFeature);
+    if (aSketchEntity && aSketchEntity->isCopy())
+      isForce = false;
+    dumpFeature(aFeature, isForce);
   }
   // dump command to update model
   myDumpBuffer << "model.do()" << std::endl;
@@ -239,6 +250,7 @@ void ModelHighAPI_Dumper::dumpEntitySetName()
     myDumpBuffer << ".feature()";
   myDumpBuffer << ".data().setName(\"" << aName << "\")" << std::endl;
 #endif
+  myNames[myLastEntityWithName].second = false; // don't dump "setName" for the entity twice
   myLastEntityWithName = EntityPtr();
 }
 
@@ -370,7 +382,7 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
   return *this;
 }
 
-ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const EntityPtr& theEntity)
+ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity)
 {
   myDumpBuffer << name(theEntity);
   if (myNames[theEntity].second)
@@ -379,16 +391,85 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const EntityPtr& theEntity)
   return *this;
 }
 
+ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const ObjectPtr& theObject)
+{
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+  myDumpBuffer << name(aFeature);
+  return *this;
+}
+
+ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const AttributePtr& theAttr)
+{
+  FeaturePtr anOwner = ModelAPI_Feature::feature(theAttr->owner());
+  myDumpBuffer << name(anOwner) << "." << attributeGetter(anOwner, theAttr->id()) << "()";
+  return *this;
+}
+
 ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
     const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr)
 {
-  if (theRefAttr->isObject()) {
-    FeaturePtr aFeature = ModelAPI_Feature::feature(theRefAttr->object());
-    myDumpBuffer << name(aFeature);
+  if (theRefAttr->isObject())
+    *this << theRefAttr->object();
+  else
+    *this << theRefAttr->attr();
+  return *this;
+}
+
+ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
+    const std::shared_ptr<ModelAPI_AttributeRefAttrList>& theRefAttrList)
+{
+  myDumpBuffer << "[";
+  std::list<std::pair<ObjectPtr, AttributePtr> > aList = theRefAttrList->list();
+  bool isAdded = false;
+  std::list<std::pair<ObjectPtr, AttributePtr> >::const_iterator anIt = aList.begin();
+  for (; anIt != aList.end(); ++anIt) {
+    if (isAdded)
+      myDumpBuffer << ", ";
+    else
+      isAdded = true;
+    if (anIt->first)
+      *this << anIt->first;
+    else if (anIt->second)
+      * this << anIt->second;
+  }
+  myDumpBuffer << "]";
+  return *this;
+}
+
+ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
+    const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList)
+{
+  static const int aThreshold = 2;
+  // if number of elements in the list if greater than a threshold,
+  // dump it in a separate line with specific name
+  std::string aDumped = myDumpBuffer.str();
+  if (aDumped.empty() || theRefList->size() <= aThreshold) {
+    myDumpBuffer << "[";
+    std::list<ObjectPtr> aList = theRefList->list();
+    bool isAdded = false;
+    std::list<ObjectPtr>::const_iterator anIt = aList.begin();
+    for (; anIt != aList.end(); ++anIt) {
+      if (isAdded)
+        myDumpBuffer << ", ";
+      else
+        isAdded = true;
+
+      *this << *anIt;
+    }
+    myDumpBuffer << "]";
   } else {
-    AttributePtr anAttr = theRefAttr->attr();
-    FeaturePtr anOwner = ModelAPI_Feature::feature(anAttr->owner());
-    myDumpBuffer << name(anOwner) << "." << attributeGetter(anOwner, anAttr->id()) << "()";
+    // clear buffer and store list "as is"
+    myDumpBuffer = std::ostringstream();
+    *this << theRefList;
+    // save buffer and clear it again
+    std::string aDumpedList = myDumpBuffer.str();
+    myDumpBuffer = std::ostringstream();
+    // obtain name of list
+    FeaturePtr anOwner = ModelAPI_Feature::feature(theRefList->owner());
+    std::string aListName = name(anOwner) + "_objects";
+    // store all previous data
+    myDumpBuffer << aListName << " = " << aDumpedList << std::endl
+                 << aDumped << aListName;
   }
   return *this;
 }
index 30cdce0883d38bcda70ec674527973e5d149690d..161e9e61a2d518e5b6886054ebaa7db538baca6d 100644 (file)
@@ -22,10 +22,13 @@ class GeomDataAPI_Dir;
 class GeomDataAPI_Point;
 class GeomDataAPI_Point2D;
 
+class ModelAPI_Attribute;
 class ModelAPI_AttributeBoolean;
 class ModelAPI_AttributeDouble;
 class ModelAPI_AttributeInteger;
 class ModelAPI_AttributeRefAttr;
+class ModelAPI_AttributeRefAttrList;
+class ModelAPI_AttributeRefList;
 class ModelAPI_AttributeSelection;
 class ModelAPI_AttributeSelectionList;
 class ModelAPI_AttributeString;
@@ -33,6 +36,7 @@ class ModelAPI_CompositeFeature;
 class ModelAPI_Document;
 class ModelAPI_Entity;
 class ModelAPI_Feature;
+class ModelAPI_Object;
 
 typedef std::shared_ptr<ModelAPI_Entity>  EntityPtr;
 typedef std::shared_ptr<ModelAPI_Feature> FeaturePtr;
@@ -147,11 +151,26 @@ public:
   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeString>& theAttrStr);
   /// Dump name of entity and remember to dump "setName" if the entity has user-defined name
   MODELHIGHAPI_EXPORT
-  ModelHighAPI_Dumper& operator<<(const EntityPtr& theEntity);
+  ModelHighAPI_Dumper& operator<<(const FeaturePtr& theEntity);
+
+  /// Dump Attribute
+  MODELHIGHAPI_EXPORT
+  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_Attribute>& theAttr);
+  /// Dump Object
+  MODELHIGHAPI_EXPORT
+  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_Object>& theObject);
 
   /// Dump AttributeRefAttr
   MODELHIGHAPI_EXPORT
   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttr>& theRefAttr);
+  /// Dump AttributeRefAttrList as follows:
+  /// "[obj1, obj2, obj3, ...]"
+  MODELHIGHAPI_EXPORT
+  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefAttrList>& theRefAttrList);
+  /// Dump AttributeRefList as follows:
+  /// "[obj1, obj2, obj3, ...]"
+  MODELHIGHAPI_EXPORT
+  ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeRefList>& theRefList);
   /// Dump AttributeSelection
   MODELHIGHAPI_EXPORT
   ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
index 150c73e93d879603810bd197c077fcf6ca122d56..6870cc63dabc3c30ec06159a208be514e0f714b2 100644 (file)
@@ -127,7 +127,8 @@ static std::string angleTypeToString(int theAngleType)
 
 void SketchAPI_Constraint::dump(ModelHighAPI_Dumper& theDumper) const
 {
-  ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(feature());
+  FeaturePtr aBase = feature();
+  ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(aBase);
   if (!aConstraint)
     return; // dump constraints only
 
@@ -141,7 +142,7 @@ void SketchAPI_Constraint::dump(ModelHighAPI_Dumper& theDumper) const
                     SketchPlugin_ConstraintAngle::TYPE_ID())->value());
 
   const std::string& aSketchName = theDumper.parentName(aConstraint);
-  theDumper << aConstraint << " = " << aSketchName << "." << aSetter << aSetterSuffix << "(";
+  theDumper << aBase << " = " << aSketchName << "." << aSetter << aSetterSuffix << "(";
 
   bool isFirstAttr = true;
   for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) {
index d6166e79c594a2d8b81f46f0f75abf2b5bef6cf6..32abfc90bf3ddebb0f6ff9a1e36acc88dfcebab0 100644 (file)
@@ -7,12 +7,13 @@
 //--------------------------------------------------------------------------------------
 #include "SketchAPI_Mirror.h"
 //--------------------------------------------------------------------------------------
+#include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Selection.h>
 #include <ModelHighAPI_Tools.h>
 //--------------------------------------------------------------------------------------
 SketchAPI_Mirror::SketchAPI_Mirror(
     const std::shared_ptr<ModelAPI_Feature> & theFeature)
-: SketchAPI_SketchEntity(theFeature)
+: ModelHighAPI_Interface(theFeature)
 {
   initialize();
 }
@@ -21,7 +22,7 @@ SketchAPI_Mirror::SketchAPI_Mirror(
     const std::shared_ptr<ModelAPI_Feature> & theFeature,
     const ModelHighAPI_RefAttr & theMirrorLine,
     const std::list<std::shared_ptr<ModelAPI_Object> > & theObjects)
-: SketchAPI_SketchEntity(theFeature)
+: ModelHighAPI_Interface(theFeature)
 {
   if (initialize()) {
     fillAttribute(theMirrorLine, mirrorLine());
@@ -37,3 +38,14 @@ SketchAPI_Mirror::~SketchAPI_Mirror()
 }
 
 //--------------------------------------------------------------------------------------
+
+void SketchAPI_Mirror::dump(ModelHighAPI_Dumper& theDumper) const
+{
+  FeaturePtr aBase = feature();
+  const std::string& aSketchName = theDumper.parentName(aBase);
+
+  AttributeRefAttrPtr aMirrorLine = mirrorLine();
+  AttributeRefListPtr aMirrorObjects = mirrorList();
+  theDumper << aBase << " = " << aSketchName << ".addMirror(" << aMirrorLine << ", "
+            << aMirrorObjects << ")" << std::endl;
+}
index 9cd2d54887bcfc74fb185d4589a29050462d131b..ab77061ea8671ad68ffb505cd9b2061d58201e15 100644 (file)
@@ -14,7 +14,8 @@
 
 #include <SketchPlugin_ConstraintMirror.h>
 
-#include "SketchAPI_SketchEntity.h"
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
 //--------------------------------------------------------------------------------------
 class ModelAPI_Object;
 class ModelHighAPI_RefAttr;
@@ -23,7 +24,7 @@ class ModelHighAPI_RefAttr;
  * \ingroup CPPHighAPI
  * \brief Interface for Mirror feature
  */
-class SketchAPI_Mirror : public SketchAPI_SketchEntity
+class SketchAPI_Mirror : public ModelHighAPI_Interface
 {
 public:
   /// Constructor without values
@@ -45,6 +46,8 @@ public:
               mirroredObjects, SketchPlugin_ConstraintMirror::ENTITY_C(), ModelAPI_AttributeRefList, /** Mirrored objects */
   )
 
+  /// Dump wrapped feature
+  virtual void dump(ModelHighAPI_Dumper& theDumper) const;
 };
 
 //! Pointer on Mirror object
index 5e101d2401e376e45e682b762ee37f6cb7dff7cb..b73391a9175c22212a054b603c2b4f17ca892ef4 100644 (file)
@@ -1204,5 +1204,12 @@ void adjustMirror(ConstraintWrapperPtr theConstraint)
 
   if (aPoints.size() == 2)
     makeMirrorPoints(aPoints[0], aPoints[1], aMirrorLine);
+
+  // update scales of constraints
+  std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aGCSConstraint = 
+      std::dynamic_pointer_cast<PlaneGCSSolver_ConstraintWrapper>(theConstraint);
+  std::list<GCSConstraintPtr>::const_iterator aCIt = aGCSConstraint->constraints().begin();
+  for (; aCIt != aGCSConstraint->constraints().end(); ++aCIt)
+    (*aCIt)->rescale();
 }