]> 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>
Fri, 12 Aug 2016 06:49:40 +0000 (09:49 +0300)
committerazv <azv@opencascade.com>
Fri, 12 Aug 2016 06:49:40 +0000 (09:49 +0300)
* Avoid dependency of SketchPlugin in ModelHighAPI/CMakeLists.txt
* Sketch should dump "model.do()" command
* Check copied sketch features by corresponding API feature

src/ModelHighAPI/CMakeLists.txt
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.h
src/SketchAPI/SketchAPI_Arc.cpp
src/SketchAPI/SketchAPI_Circle.cpp
src/SketchAPI/SketchAPI_Line.cpp
src/SketchAPI/SketchAPI_Point.cpp
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchAPI/SketchAPI_SketchEntity.cpp
src/SketchAPI/SketchAPI_SketchEntity.h

index dbecf0c6b4720a799a109e04830dc282d45b66eb..7b650a573cf8c4746ce19a15ece7a5d14e85b17a 100644 (file)
@@ -61,7 +61,6 @@ INCLUDE_DIRECTORIES(
   ${PROJECT_SOURCE_DIR}/src/GeomDataAPI
   ${PROJECT_SOURCE_DIR}/src/ModelAPI
   ${PROJECT_SOURCE_DIR}/src/PartSetPlugin
-  ${PROJECT_SOURCE_DIR}/src/SketchPlugin
   ${CAS_INCLUDE_DIRS}
 )
 
index 55cd9f2c7583fdd1e37b0e476daad817aeb60c92..5bd5df4a5113d24f6717c2c500c2923ee2408f61 100644 (file)
@@ -33,8 +33,6 @@
 
 #include <PartSetPlugin_Part.h>
 
-#include <SketchPlugin_SketchEntity.h>
-
 #include <OSD_OpenFile.hxx>
 
 #include <fstream>
@@ -192,16 +190,8 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_CompositeFeatur
     FeaturePtr aFeature = theComposite->subFeature(anIndex);
     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);
+    dumpFeature(aFeature, true);
   }
-  // dump empty line for appearance
-  myDumpBuffer << std::endl;
   return true;
 }
 
@@ -583,6 +573,10 @@ ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper,
       theDumper.process(aCompFeat);
   }
 
+  // avoid multiple empty lines
+  size_t anInd = std::string::npos;
+  while ((anInd = aBufCopy.find("\n\n\n")) != std::string::npos)
+    aBufCopy.erase(anInd, 1);
   // then store currently dumped string
   theDumper.myFullDump << aBufCopy;
 
index 2bab94d9cda8d91308ae67eff6eaab376265d1e8..880de6c8b6d9ef62182ea3501d9a1c48678cbbe9 100644 (file)
@@ -204,6 +204,7 @@ private:
   bool process(const std::shared_ptr<ModelAPI_Document>& theDoc);
 
   /// Iterate all features in composite feature and dump them into intermediate buffer
+  MODELHIGHAPI_EXPORT
   bool process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite);
 
   /// Check the entity is already dumped
@@ -227,6 +228,8 @@ private:
 
 protected:
   std::set<EntityPtr> myNotDumpedEntities;  ///< list of entities, used by other features but not dumped yet
+
+  friend class SketchAPI_Sketch;
 };
 
 #endif
index 696bd9ab51571257375a0d9d4ef1ac1dbf47ec46..ba8e4cb8b10cb473f447f5a9ee77e560612d2579 100644 (file)
@@ -237,6 +237,9 @@ void SketchAPI_Arc::setAngle(double theAngle)
 //==================================================================================================
 void SketchAPI_Arc::dump(ModelHighAPI_Dumper& theDumper) const
 {
+  if (isCopy())
+    return; // no need to dump copied feature
+
   FeaturePtr aBase = feature();
   const std::string& aSketchName = theDumper.parentName(aBase);
 
index 7ffcfd0cb80ecc4c5d8dfc29a7e88ae526d03184..8403b5896bce6a5dcf8ca51dc17dc6c36ffd2a0a 100644 (file)
@@ -240,6 +240,9 @@ void SketchAPI_Circle::setThirdPoint(const std::shared_ptr<GeomAPI_Pnt2d>& thePo
 //==================================================================================================
 void SketchAPI_Circle::dump(ModelHighAPI_Dumper& theDumper) const
 {
+  if (isCopy())
+    return; // no need to dump copied feature
+
   FeaturePtr aBase = feature();
   const std::string& aSketchName = theDumper.parentName(aBase);
 
index 2b868adb6f28e053f103cfd5afdf715f63c2f346..e06448ecdc1daa5a61c7bdce2119e03f05a44af1 100644 (file)
@@ -130,6 +130,9 @@ void SketchAPI_Line::setEndPoint(const std::shared_ptr<GeomAPI_Pnt2d> & thePoint
 
 void SketchAPI_Line::dump(ModelHighAPI_Dumper& theDumper) const
 {
+  if (isCopy())
+    return; // no need to dump copied feature
+
   FeaturePtr aBase = feature();
   const std::string& aSketchName = theDumper.parentName(aBase);
 
index 10719adb55b7ac6071f3a05c3eb3df6240cd51af..4e44f259c2a70200cba00f40efaa09eb34b1ce11 100644 (file)
@@ -100,6 +100,9 @@ void SketchAPI_Point::setByExternalName(const std::string & theExternalName)
 
 void SketchAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
 {
+  if (isCopy())
+    return; // no need to dump copied feature
+
   FeaturePtr aBase = feature();
   const std::string& aSketchName = theDumper.parentName(aBase);
 
index 09411948d4d4d40d7566adc9f525fd24a347258b..d7e7194508870fb555d775b4b14f2bc15135ef21 100644 (file)
@@ -657,4 +657,10 @@ void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
                 << ", model.defaultPlane(\"" << aPlaneName << "\"))" << std::endl;
     }
   }
+
+  // dump sketch's subfeatures
+  CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aBase);
+  theDumper.process(aCompFeat);
+  // necessary to be sure that the result of sketch was built
+  theDumper << "model.do()" << std::endl;
 }
index 13b4afeaabea606efb9ecf4c2ae283222cb13a59..3e5f4f82446cbb63600d70da8e938a6104636b91 100644 (file)
@@ -53,3 +53,11 @@ void SketchAPI_SketchEntity::dump(ModelHighAPI_Dumper& theDumper) const
     theDumper << aName << ".setAuxiliary(" << anAux << ")" <<std::endl;
   }
 }
+
+bool SketchAPI_SketchEntity::isCopy() const
+{
+  // check the feature is a copy of another entity
+  std::shared_ptr<SketchPlugin_SketchEntity> aSketchEntity =
+      std::dynamic_pointer_cast<SketchPlugin_SketchEntity>(feature());
+  return aSketchEntity && aSketchEntity->isCopy();
+}
index 583eaafa084ad138237a4832c9343fbf9d4e3d5d..fcc8639008b85b916dccf3e3249039ee7581297d 100644 (file)
@@ -44,6 +44,9 @@ protected:
   std::shared_ptr<ModelAPI_AttributeBoolean> myAuxiliary;
 
   bool initialize();
+
+  /// Check the entity is a copy of another feature
+  bool isCopy() const;
 };
 
 //! Pointer on SketchEntity object