]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Dump for deflection
authordbv <dbv@opencascade.com>
Tue, 6 Sep 2016 13:31:21 +0000 (16:31 +0300)
committerdbv <dbv@opencascade.com>
Tue, 6 Sep 2016 13:31:57 +0000 (16:31 +0300)
src/ModelHighAPI/CMakeLists.txt
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.h
src/ModelHighAPI/ModelHighAPI_Selection.cpp
src/ModelHighAPI/ModelHighAPI_Selection.h
src/ModelHighAPI/Test/TestDeflectionDump.py [new file with mode: 0644]

index a5280ec4ecc1879e47d7e02706c8fbd721845fbf..9607e5fa2fbc8616f882ad1a45ccb455c935f78a 100644 (file)
@@ -93,4 +93,5 @@ ADD_UNIT_TESTS(
   TestInteger.py
   TestRefAttr.py
   TestReference.py
+  TestDeflectionDump.py
 )
index c2ae64971f3a46d898f999a93937f4de45c5a959..855f98b5f2e19955106f3649cbdd33ab2b5e1606 100644 (file)
@@ -7,8 +7,11 @@
 //--------------------------------------------------------------------------------------
 #include "ModelHighAPI_Dumper.h"
 
+#include <Config_PropManager.h>
+
 #include <GeomAPI_Pnt.h>
 #include <GeomAPI_Dir.h>
+#include <GeomAPI_ShapeExplorer.h>
 
 #include <GeomDataAPI_Dir.h>
 #include <GeomDataAPI_Point.h>
@@ -30,6 +33,8 @@
 #include <ModelAPI_Entity.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_ResultPart.h>
 
 #include <PartSetPlugin_Part.h>
@@ -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<ResultPtr>& aResults = theEntity->results();
   std::list<ResultPtr>::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));
index cdd2fdde6bb8d737432e3319e98ba74814140761..01d8667569980c58bddaf7382d2c61b79cd8556c 100644 (file)
@@ -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
index 536e22710957bd1e3740e992a7434f96a7dcf0be..e66fdb5945d41c744a54586400d615a18a4240ff 100644 (file)
@@ -7,6 +7,7 @@
 //--------------------------------------------------------------------------------------
 #include "ModelHighAPI_Selection.h"
 
+#include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeIntArray.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeSelectionList.h>
@@ -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);
+}
index b138b8f009962002f990485681593e80e997f573..782edec4b2f060e3d042596b93d7f8b94640c13e 100644 (file)
@@ -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 (file)
index 0000000..49b0c87
--- /dev/null
@@ -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())