From: azv Date: Wed, 10 Aug 2016 05:12:17 +0000 (+0300) Subject: Dump Python in the High Level Parameterized Geometry API (issue #1648) X-Git-Tag: V_2.5.0~137^2~81 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=086aa81da7d411db27b5f8a51ecba2dd0804b847;p=modules%2Fshaper.git Dump Python in the High Level Parameterized Geometry API (issue #1648) * Process different types of constraint Angle --- diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.cpp b/src/ModelHighAPI/ModelHighAPI_Tools.cpp index 438b2b145..f61e4169d 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Tools.cpp @@ -88,6 +88,11 @@ void fillAttribute(const ModelHighAPI_Integer & theValue, { theValue.fillAttribute(theAttribute); } +void fillAttribute(int theValue, + const std::shared_ptr & theAttribute) +{ + theAttribute->setValue(theValue); +} //-------------------------------------------------------------------------------------- void fillAttribute(const ModelHighAPI_RefAttr & theValue, diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.h b/src/ModelHighAPI/ModelHighAPI_Tools.h index e278e282f..789d43a0c 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.h +++ b/src/ModelHighAPI/ModelHighAPI_Tools.h @@ -77,6 +77,10 @@ MODELHIGHAPI_EXPORT void fillAttribute(const ModelHighAPI_Integer & theValue, const std::shared_ptr & theAttribute); +MODELHIGHAPI_EXPORT +void fillAttribute(int theValue, + const std::shared_ptr & theAttribute); + MODELHIGHAPI_EXPORT void fillAttribute(const ModelHighAPI_RefAttr & theValue, const std::shared_ptr & theAttribute); diff --git a/src/SketchAPI/CMakeLists.txt b/src/SketchAPI/CMakeLists.txt index 3bd9afe90..18db87fc5 100644 --- a/src/SketchAPI/CMakeLists.txt +++ b/src/SketchAPI/CMakeLists.txt @@ -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 diff --git a/src/SketchAPI/SketchAPI_Constraint.cpp b/src/SketchAPI/SketchAPI_Constraint.cpp index 5bee50db1..150c73e93 100644 --- a/src/SketchAPI/SketchAPI_Constraint.cpp +++ b/src/SketchAPI/SketchAPI_Constraint.cpp @@ -25,6 +25,8 @@ #include #include +#include + SketchAPI_Constraint::SketchAPI_Constraint( const std::shared_ptr & 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(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; diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index d86f075df..ef4962054 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -24,6 +24,7 @@ #include #include #include +#include //-------------------------------------------------------------------------------------- #include #include @@ -406,9 +407,10 @@ std::shared_ptr SketchAPI_Sketch::setAngle( const ModelHighAPI_RefAttr & theLine2, const ModelHighAPI_Double & theValue) { - // TODO(spo): is support of angle type necessary? std::shared_ptr 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 SketchAPI_Sketch::setAngle( return aFeature; } +std::shared_ptr SketchAPI_Sketch::setAngleComplementary( + const ModelHighAPI_RefAttr & theLine1, + const ModelHighAPI_RefAttr & theLine2, + const ModelHighAPI_Double & theValue) +{ + std::shared_ptr 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 SketchAPI_Sketch::setAngleBackward( + const ModelHighAPI_RefAttr & theLine1, + const ModelHighAPI_RefAttr & theLine2, + const ModelHighAPI_Double & theValue) +{ + std::shared_ptr 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 SketchAPI_Sketch::setCoincident( const ModelHighAPI_RefAttr & thePoint1, const ModelHighAPI_RefAttr & thePoint2) diff --git a/src/SketchAPI/SketchAPI_Sketch.h b/src/SketchAPI/SketchAPI_Sketch.h index 1e17d9daa..dcf06446d 100644 --- a/src/SketchAPI/SketchAPI_Sketch.h +++ b/src/SketchAPI/SketchAPI_Sketch.h @@ -244,6 +244,20 @@ public: const ModelHighAPI_RefAttr & theLine2, const ModelHighAPI_Double & theValue); + /// Set complementary angle + SKETCHAPI_EXPORT + std::shared_ptr setAngleComplementary( + const ModelHighAPI_RefAttr & theLine1, + const ModelHighAPI_RefAttr & theLine2, + const ModelHighAPI_Double & theValue); + + /// Set backward angle (= 360 - angle) + SKETCHAPI_EXPORT + std::shared_ptr setAngleBackward( + const ModelHighAPI_RefAttr & theLine1, + const ModelHighAPI_RefAttr & theLine2, + const ModelHighAPI_Double & theValue); + /// Set coincident SKETCHAPI_EXPORT std::shared_ptr setCoincident( diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp index 8fb29c48c..e66758f03 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp @@ -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 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();