]> 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 05:12:17 +0000 (08:12 +0300)
committerazv <azv@opencascade.com>
Wed, 10 Aug 2016 05:12:17 +0000 (08:12 +0300)
* Process different types of constraint Angle

src/ModelHighAPI/ModelHighAPI_Tools.cpp
src/ModelHighAPI/ModelHighAPI_Tools.h
src/SketchAPI/CMakeLists.txt
src/SketchAPI/SketchAPI_Constraint.cpp
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchAPI/SketchAPI_Sketch.h
src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp

index 438b2b145b62093c1dffda876c4a271a0d56a75f..f61e4169d3dfd4303919b76df26ae312759c4c41 100644 (file)
@@ -88,6 +88,11 @@ void fillAttribute(const ModelHighAPI_Integer & theValue,
 {
   theValue.fillAttribute(theAttribute);
 }
+void fillAttribute(int theValue,
+                   const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute)
+{
+  theAttribute->setValue(theValue);
+}
 
 //--------------------------------------------------------------------------------------
 void fillAttribute(const ModelHighAPI_RefAttr & theValue,
index e278e282ffaea348315cb646804d5aee9551c9a8..789d43a0c2fc34e13fd655fd9884db73bf0f0836 100644 (file)
@@ -77,6 +77,10 @@ MODELHIGHAPI_EXPORT
 void fillAttribute(const ModelHighAPI_Integer & theValue,
                    const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute);
 
+MODELHIGHAPI_EXPORT
+void fillAttribute(int theValue,
+                   const std::shared_ptr<ModelAPI_AttributeInteger> & theAttribute);
+
 MODELHIGHAPI_EXPORT
 void fillAttribute(const ModelHighAPI_RefAttr & theValue,
                    const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute);
index 3bd9afe905d54a3e75e0942fc3fcdaafec89ddc2..18db87fc55a7507001a22d4a3a258095c5a5bb9b 100644 (file)
@@ -46,6 +46,7 @@ INCLUDE_DIRECTORIES(
   ${PROJECT_SOURCE_DIR}/src/ModelAPI
   ${PROJECT_SOURCE_DIR}/src/GeomDataAPI
   ${PROJECT_SOURCE_DIR}/src/ModelHighAPI
+  ${PROJECT_SOURCE_DIR}/src/SketcherPrs
 )
 
 # Plugin headers dependency
index 5bee50db1a70399f95101714f9bacfe74157d6d5..150c73e93d879603810bd197c077fcf6ca122d56 100644 (file)
@@ -25,6 +25,8 @@
 #include <SketchPlugin_ConstraintTangent.h>
 #include <SketchPlugin_ConstraintVertical.h>
 
+#include <SketcherPrs_Tools.h>
+
 SketchAPI_Constraint::SketchAPI_Constraint(
     const std::shared_ptr<ModelAPI_Feature> & theFeature)
 : ModelHighAPI_Interface(theFeature)
@@ -110,6 +112,19 @@ static const std::string& constraintTypeToSetter(const std::string& theType)
   return DUMMY;
 }
 
+static std::string angleTypeToString(int theAngleType)
+{
+  switch (theAngleType) {
+  case SketcherPrs_Tools::ANGLE_COMPLEMENTARY:
+    return std::string("Complementary");
+  case SketcherPrs_Tools::ANGLE_BACKWARD:
+    return std::string("Backward");
+  default:
+    break;
+  }
+  return std::string();
+}
+
 void SketchAPI_Constraint::dump(ModelHighAPI_Dumper& theDumper) const
 {
   ConstraintPtr aConstraint = std::dynamic_pointer_cast<SketchPlugin_Constraint>(feature());
@@ -119,9 +134,14 @@ void SketchAPI_Constraint::dump(ModelHighAPI_Dumper& theDumper) const
   const std::string& aSetter = constraintTypeToSetter(aConstraint->getKind());
   if (aSetter.empty())
     return; // incorrect constraint type
+  bool isAngle = aConstraint->getKind() == SketchPlugin_ConstraintAngle::ID();
+  std::string aSetterSuffix;
+  if (isAngle)
+    aSetterSuffix = angleTypeToString(aConstraint->integer(
+                    SketchPlugin_ConstraintAngle::TYPE_ID())->value());
 
   const std::string& aSketchName = theDumper.parentName(aConstraint);
-  theDumper << aConstraint << " = " << aSketchName << "." << aSetter << "(";
+  theDumper << aConstraint << " = " << aSketchName << "." << aSetter << aSetterSuffix << "(";
 
   bool isFirstAttr = true;
   for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) {
@@ -132,7 +152,8 @@ void SketchAPI_Constraint::dump(ModelHighAPI_Dumper& theDumper) const
     }
   }
 
-  AttributeDoublePtr aValueAttr = aConstraint->real(SketchPlugin_Constraint::VALUE());
+  AttributeDoublePtr aValueAttr = aConstraint->real(
+      isAngle ? SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID() :SketchPlugin_Constraint::VALUE());
   if (aValueAttr && aValueAttr->isInitialized())
     theDumper << ", " << aValueAttr;
 
index d86f075dffc9683d6cd38683114fe2b35eccebe0..ef4962054ad22dece73aa6d672fdd60b7cf2f862 100644 (file)
@@ -24,6 +24,7 @@
 #include <SketchPlugin_ConstraintRigid.h>
 #include <SketchPlugin_ConstraintTangent.h>
 #include <SketchPlugin_ConstraintVertical.h>
+#include <SketcherPrs_Tools.h>
 //--------------------------------------------------------------------------------------
 #include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_ResultConstruction.h>
@@ -406,9 +407,10 @@ std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngle(
     const ModelHighAPI_RefAttr & theLine2,
     const ModelHighAPI_Double & theValue)
 {
-  // TODO(spo): is support of angle type necessary?
   std::shared_ptr<ModelAPI_Feature> aFeature =
       compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
+  fillAttribute(SketcherPrs_Tools::ANGLE_DIRECT,
+      aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
   fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
   fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
   fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
@@ -416,6 +418,40 @@ std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngle(
   return aFeature;
 }
 
+std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngleComplementary(
+    const ModelHighAPI_RefAttr & theLine1,
+    const ModelHighAPI_RefAttr & theLine2,
+    const ModelHighAPI_Double & theValue)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+      compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
+  fillAttribute(SketcherPrs_Tools::ANGLE_COMPLEMENTARY,
+      aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
+  fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
+  fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
+  fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
+//  fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
+  aFeature->execute();
+  return aFeature;
+}
+
+std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setAngleBackward(
+    const ModelHighAPI_RefAttr & theLine1,
+    const ModelHighAPI_RefAttr & theLine2,
+    const ModelHighAPI_Double & theValue)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+      compositeFeature()->addFeature(SketchPlugin_ConstraintAngle::ID());
+  fillAttribute(SketcherPrs_Tools::ANGLE_BACKWARD,
+      aFeature->integer(SketchPlugin_ConstraintAngle::TYPE_ID()));
+  fillAttribute(theValue, aFeature->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
+  fillAttribute(theLine1, aFeature->refattr(SketchPlugin_Constraint::ENTITY_A()));
+  fillAttribute(theLine2, aFeature->refattr(SketchPlugin_Constraint::ENTITY_B()));
+//  fillAttribute(theValue, aFeature->real(SketchPlugin_Constraint::VALUE()));
+  aFeature->execute();
+  return aFeature;
+}
+
 std::shared_ptr<ModelAPI_Feature> SketchAPI_Sketch::setCoincident(
     const ModelHighAPI_RefAttr & thePoint1,
     const ModelHighAPI_RefAttr & thePoint2)
index 1e17d9daa22c079f03caea22e816a9553ca9ce0b..dcf06446dc2d42b4dd03a17e5775e1102cf7b65a 100644 (file)
@@ -244,6 +244,20 @@ public:
       const ModelHighAPI_RefAttr & theLine2,
       const ModelHighAPI_Double & theValue);
 
+  /// Set complementary angle
+  SKETCHAPI_EXPORT
+  std::shared_ptr<ModelAPI_Feature> setAngleComplementary(
+      const ModelHighAPI_RefAttr & theLine1,
+      const ModelHighAPI_RefAttr & theLine2,
+      const ModelHighAPI_Double & theValue);
+
+  /// Set backward angle (= 360 - angle)
+  SKETCHAPI_EXPORT
+  std::shared_ptr<ModelAPI_Feature> setAngleBackward(
+      const ModelHighAPI_RefAttr & theLine1,
+      const ModelHighAPI_RefAttr & theLine2,
+      const ModelHighAPI_Double & theValue);
+
   /// Set coincident
   SKETCHAPI_EXPORT
   std::shared_ptr<ModelAPI_Feature> setCoincident(
index 8fb29c48c33e5866c795c9acc2c01e5798af491e..e66758f034347fdc6e765e30a82bf04b412d2f7f 100644 (file)
@@ -105,9 +105,12 @@ void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID)
 
   if (theID == SketchPlugin_Constraint::ENTITY_A() || 
       theID == SketchPlugin_Constraint::ENTITY_B()) {
-    std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
-        ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
-    if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value
+    AttributeDoublePtr aValueAttr = real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID());
+    AttributeDoublePtr aConstrValueAttr = real(SketchPlugin_Constraint::VALUE());
+    // only if one of attributes is not initialized, try to compute the current value
+    if (!aValueAttr->isInitialized() || !aConstrValueAttr->isInitialized()) {
+      if (aValueAttr->isInitialized() && !aConstrValueAttr->isInitialized()) // initialize base value of constraint
+        updateConstraintValueByAngleValue();
       double anAngle = calculateAngle();
       aValueAttr->setValue(anAngle);
       updateConstraintValueByAngleValue();