From: azv Date: Fri, 12 Aug 2016 06:49:40 +0000 (+0300) Subject: Dump Python in the High Level Parameterized Geometry API (issue #1648) X-Git-Tag: V_2.5.0~137^2~66 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=36f31da5fb55f268a1983d775c140f6a89ff56cb;p=modules%2Fshaper.git Dump Python in the High Level Parameterized Geometry API (issue #1648) * Avoid dependency of SketchPlugin in ModelHighAPI/CMakeLists.txt * Sketch should dump "model.do()" command * Check copied sketch features by corresponding API feature --- diff --git a/src/ModelHighAPI/CMakeLists.txt b/src/ModelHighAPI/CMakeLists.txt index dbecf0c6b..7b650a573 100644 --- a/src/ModelHighAPI/CMakeLists.txt +++ b/src/ModelHighAPI/CMakeLists.txt @@ -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} ) diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index 55cd9f2c7..5bd5df4a5 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -33,8 +33,6 @@ #include -#include - #include #include @@ -192,16 +190,8 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptrsubFeature(anIndex); if (isDumped(aFeature)) continue; - bool isForce = true; - // check the feature is a sketch entity and a copy of another entity - std::shared_ptr aSketchEntity = - std::dynamic_pointer_cast(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; diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.h b/src/ModelHighAPI/ModelHighAPI_Dumper.h index 2bab94d9c..880de6c8b 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.h +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.h @@ -204,6 +204,7 @@ private: bool process(const std::shared_ptr& theDoc); /// Iterate all features in composite feature and dump them into intermediate buffer + MODELHIGHAPI_EXPORT bool process(const std::shared_ptr& theComposite); /// Check the entity is already dumped @@ -227,6 +228,8 @@ private: protected: std::set myNotDumpedEntities; ///< list of entities, used by other features but not dumped yet + + friend class SketchAPI_Sketch; }; #endif diff --git a/src/SketchAPI/SketchAPI_Arc.cpp b/src/SketchAPI/SketchAPI_Arc.cpp index 696bd9ab5..ba8e4cb8b 100644 --- a/src/SketchAPI/SketchAPI_Arc.cpp +++ b/src/SketchAPI/SketchAPI_Arc.cpp @@ -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); diff --git a/src/SketchAPI/SketchAPI_Circle.cpp b/src/SketchAPI/SketchAPI_Circle.cpp index 7ffcfd0cb..8403b5896 100644 --- a/src/SketchAPI/SketchAPI_Circle.cpp +++ b/src/SketchAPI/SketchAPI_Circle.cpp @@ -240,6 +240,9 @@ void SketchAPI_Circle::setThirdPoint(const std::shared_ptr& 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); diff --git a/src/SketchAPI/SketchAPI_Line.cpp b/src/SketchAPI/SketchAPI_Line.cpp index 2b868adb6..e06448ecd 100644 --- a/src/SketchAPI/SketchAPI_Line.cpp +++ b/src/SketchAPI/SketchAPI_Line.cpp @@ -130,6 +130,9 @@ void SketchAPI_Line::setEndPoint(const std::shared_ptr & 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); diff --git a/src/SketchAPI/SketchAPI_Point.cpp b/src/SketchAPI/SketchAPI_Point.cpp index 10719adb5..4e44f259c 100644 --- a/src/SketchAPI/SketchAPI_Point.cpp +++ b/src/SketchAPI/SketchAPI_Point.cpp @@ -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); diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index 09411948d..d7e719450 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -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(aBase); + theDumper.process(aCompFeat); + // necessary to be sure that the result of sketch was built + theDumper << "model.do()" << std::endl; } diff --git a/src/SketchAPI/SketchAPI_SketchEntity.cpp b/src/SketchAPI/SketchAPI_SketchEntity.cpp index 13b4afeaa..3e5f4f824 100644 --- a/src/SketchAPI/SketchAPI_SketchEntity.cpp +++ b/src/SketchAPI/SketchAPI_SketchEntity.cpp @@ -53,3 +53,11 @@ void SketchAPI_SketchEntity::dump(ModelHighAPI_Dumper& theDumper) const theDumper << aName << ".setAuxiliary(" << anAux << ")" < aSketchEntity = + std::dynamic_pointer_cast(feature()); + return aSketchEntity && aSketchEntity->isCopy(); +} diff --git a/src/SketchAPI/SketchAPI_SketchEntity.h b/src/SketchAPI/SketchAPI_SketchEntity.h index 583eaafa0..fcc863900 100644 --- a/src/SketchAPI/SketchAPI_SketchEntity.h +++ b/src/SketchAPI/SketchAPI_SketchEntity.h @@ -44,6 +44,9 @@ protected: std::shared_ptr myAuxiliary; bool initialize(); + + /// Check the entity is a copy of another feature + bool isCopy() const; }; //! Pointer on SketchEntity object