From: dbv Date: Tue, 6 Sep 2016 13:31:21 +0000 (+0300) Subject: Dump for deflection X-Git-Tag: V_2.5.0~41 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=625c6cae75d4d29ea4e3b0265d65b9fecc694d87;p=modules%2Fshaper.git Dump for deflection --- diff --git a/src/ModelHighAPI/CMakeLists.txt b/src/ModelHighAPI/CMakeLists.txt index a5280ec4e..9607e5fa2 100644 --- a/src/ModelHighAPI/CMakeLists.txt +++ b/src/ModelHighAPI/CMakeLists.txt @@ -93,4 +93,5 @@ ADD_UNIT_TESTS( TestInteger.py TestRefAttr.py TestReference.py + TestDeflectionDump.py ) diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index c2ae64971..855f98b5f 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -7,8 +7,11 @@ //-------------------------------------------------------------------------------------- #include "ModelHighAPI_Dumper.h" +#include + #include #include +#include #include #include @@ -30,6 +33,8 @@ #include #include #include +#include +#include #include #include @@ -401,6 +406,14 @@ void ModelHighAPI_Dumper::dumpEntitySetName() << ", " << aColor->value(2) << ")" << std::endl; } } + // set result deflection + if (!isDefaultDeflection(*aResIt)) { + AttributeDoublePtr aDeflectionAttr = (*aResIt)->data()->real(ModelAPI_Result::DEFLECTION_ID()); + if(aDeflectionAttr && aDeflectionAttr->isInitialized()) { + *this << *aResIt; + myDumpBuffer << ".setDeflection(" << aDeflectionAttr->value() << ")" << std::endl; + } + } } myEntitiesStack.pop(); @@ -428,6 +441,40 @@ bool ModelHighAPI_Dumper::isDefaultColor(const ResultPtr& theResult) const return aDefault == aColorInfo.str(); } +bool ModelHighAPI_Dumper::isDefaultDeflection(const ResultPtr& theResult) const +{ + AttributeDoublePtr aDeflectionAttr = theResult->data()->real(ModelAPI_Result::DEFLECTION_ID()); + if(!aDeflectionAttr && !aDeflectionAttr->isInitialized()) { + return true; + } + + double aCurrent = aDeflectionAttr->value(); + double aDefault = -1; + + bool isConstruction = false; + std::string aResultGroup = theResult->groupName(); + if (aResultGroup == ModelAPI_ResultConstruction::group()) + isConstruction = true; + else if (aResultGroup == ModelAPI_ResultBody::group()) { + GeomShapePtr aGeomShape = theResult->shape(); + if (aGeomShape.get()) { + // if the shape could not be exploded on faces, it contains only wires, edges, and vertices + // correction of deviation for them should not influence to the application performance + GeomAPI_ShapeExplorer anExp(aGeomShape, GeomAPI_Shape::FACE); + isConstruction = !anExp.more(); + } + } + if (isConstruction) + aDefault = Config_PropManager::real("Visualization", "construction_deflection", + ModelAPI_ResultConstruction::DEFAULT_DEFLECTION()); + else + aDefault = Config_PropManager::real("Visualization", "body_deflection", + ModelAPI_ResultBody::DEFAULT_DEFLECTION()); + + + return abs(aCurrent - aDefault) < 1.e-12; +} + ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const char theChar) { myDumpBuffer << theChar; @@ -566,7 +613,7 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity const std::list& aResults = theEntity->results(); std::list::const_iterator aResIt = aResults.begin(); for (; aResIt != aResults.end(); ++aResIt) - if (!myNames[*aResIt].myIsDefault || !isDefaultColor(*aResIt)) + if (!myNames[*aResIt].myIsDefault || !isDefaultColor(*aResIt) || !isDefaultDeflection(*aResIt)) aResultsWithNameOrColor.push_back(*aResIt); // store just dumped entity to stack myEntitiesStack.push(LastDumpedEntity(theEntity, isUserDefinedName, aResultsWithNameOrColor)); diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.h b/src/ModelHighAPI/ModelHighAPI_Dumper.h index cdd2fdde6..01d866756 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.h +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.h @@ -246,6 +246,9 @@ private: /// Check the result feature has default color bool isDefaultColor(const ResultPtr& theResult) const; + /// Check the result feature has default deflection + bool isDefaultDeflection(const ResultPtr& theResult) const; + private: struct EntityName { std::string myCurrentName; ///< default name of current feature diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.cpp b/src/ModelHighAPI/ModelHighAPI_Selection.cpp index 536e22710..e66fdb594 100644 --- a/src/ModelHighAPI/ModelHighAPI_Selection.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Selection.cpp @@ -7,6 +7,7 @@ //-------------------------------------------------------------------------------------- #include "ModelHighAPI_Selection.h" +#include #include #include #include @@ -111,3 +112,13 @@ void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue) aColor->setValue(1, theGreen); aColor->setValue(2, theBlue); } + +void ModelHighAPI_Selection::setDeflection(double theValue) +{ + if (myVariantType != VT_ResultSubShapePair) + return; + + AttributeDoublePtr aDeflectionAttr = myResultSubShapePair.first->data()->real(ModelAPI_Result::DEFLECTION_ID()); + + aDeflectionAttr->setValue(theValue); +} diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.h b/src/ModelHighAPI/ModelHighAPI_Selection.h index b138b8f00..782edec4b 100644 --- a/src/ModelHighAPI/ModelHighAPI_Selection.h +++ b/src/ModelHighAPI/ModelHighAPI_Selection.h @@ -84,6 +84,10 @@ public: MODELHIGHAPI_EXPORT void setColor(int theRed, int theGreen, int theBlue); + /// Change result's deflection + MODELHIGHAPI_EXPORT + void setDeflection(double theValue); + private: VariantType myVariantType; ResultSubShapePair myResultSubShapePair; diff --git a/src/ModelHighAPI/Test/TestDeflectionDump.py b/src/ModelHighAPI/Test/TestDeflectionDump.py new file mode 100644 index 000000000..49b0c87ba --- /dev/null +++ b/src/ModelHighAPI/Test/TestDeflectionDump.py @@ -0,0 +1,15 @@ +import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchCircle_1 = Sketch_1.addCircle(-325.90051457976, -18.010291595197, 258.003584159371) +model.do() +Sketch_1.result()[0].setDeflection(5e-006) +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f")], model.selection(), 10, 0) +Extrusion_1.result()[0].setDeflection(0.5) +model.end() + +assert(model.checkPythonDump())