From: nds Date: Thu, 17 Mar 2016 06:58:20 +0000 (+0300) Subject: Issue 1299 Angle presentation: providing angle value attirbute in feature which serve... X-Git-Tag: V_2.3.0~380 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6967e5c6b1993581cc0711ec4c95bb01f74224b7;p=modules%2Fshaper.git Issue 1299 Angle presentation: providing angle value attirbute in feature which serves to calculate value for solver. --- diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp index 6f3f8b853..8caf3ee89 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp @@ -41,6 +41,7 @@ void SketchPlugin_ConstraintAngle::initAttributes() data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId()); data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(SketchPlugin_ConstraintAngle::TYPE_ID(), ModelAPI_AttributeInteger::typeId()); } @@ -62,11 +63,12 @@ void SketchPlugin_ConstraintAngle::execute() return; AttributeDoublePtr anAttrValue = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Constraint::VALUE())); + aData->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID())); if (!anAttrValue->isInitialized()) { double anAngle = calculateAngle(); anAttrValue->setValue(anAngle); + updateAngleValue(); } // the value should to be computed here, not in the getAISObject in order to change the model value // inside the object transaction. This is important for creating a constraint by preselection. @@ -100,10 +102,11 @@ 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_Constraint::VALUE())); + ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID())); if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value double anAngle = calculateAngle(); aValueAttr->setValue(anAngle); + updateAngleValue(); } } else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) { // Recalculate flyout point in local coordinates @@ -127,6 +130,16 @@ void SketchPlugin_ConstraintAngle::attributeChanged(const std::string& theID) aFlyoutAttr->setValue(aFlyoutAttr->x() + tolerance, aFlyoutAttr->y()); myFlyoutUpdate = false; } + else if (theID == SketchPlugin_ConstraintAngle::TYPE_ID()) { + std::shared_ptr aValueAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID())); + double anAngle = calculateAngle(); + aValueAttr->setValue(anAngle); + updateAngleValue(); + } + else if (theID == SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()) { + updateAngleValue(); + } } double SketchPlugin_ConstraintAngle::calculateAngle() @@ -179,9 +192,51 @@ double SketchPlugin_ConstraintAngle::calculateAngle() anAngle = fabs(aDirAngle) * 180.0 / PI; //anAngle = fabs(aDirA->angle(aDirB)) * 180.0 / PI; + std::shared_ptr aTypeAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeInteger>(aData->attribute(SketchPlugin_ConstraintAngle::TYPE_ID())); + SketcherPrs_Tools::AngleType anAngleType = (SketcherPrs_Tools::AngleType)(aTypeAttr->value()); + switch (anAngleType) { + case SketcherPrs_Tools::ANGLE_DIRECT: + break; + case SketcherPrs_Tools::ANGLE_SUPPLEMENTARY: + anAngle = 180 - anAngle; + break; + case SketcherPrs_Tools::ANGLE_BACKWARD: + anAngle = 360 - anAngle; + break; + default: + break; + } return anAngle; } +void SketchPlugin_ConstraintAngle::updateAngleValue() +{ + std::shared_ptr aValueAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID())); + double anAngle = aValueAttr->value(); + + std::shared_ptr aData = data(); + std::shared_ptr aTypeAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeInteger>(aData->attribute(SketchPlugin_ConstraintAngle::TYPE_ID())); + SketcherPrs_Tools::AngleType anAngleType = (SketcherPrs_Tools::AngleType)(aTypeAttr->value()); + switch (anAngleType) { + case SketcherPrs_Tools::ANGLE_DIRECT: + break; + case SketcherPrs_Tools::ANGLE_SUPPLEMENTARY: + anAngle = 180 - anAngle; + break; + case SketcherPrs_Tools::ANGLE_BACKWARD: + anAngle = 360 - anAngle; + break; + default: + break; + } + aValueAttr = std::dynamic_pointer_cast< + ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_Constraint::VALUE())); + aValueAttr->setValue(anAngle); +} + void SketchPlugin_ConstraintAngle::move(double theDeltaX, double theDeltaY) { std::shared_ptr aData = data(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.h b/src/SketchPlugin/SketchPlugin_ConstraintAngle.h index ed593ab5e..c0f1c712c 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.h @@ -37,10 +37,17 @@ class SketchPlugin_ConstraintAngle : public SketchPlugin_ConstraintBase /// attribute name of operation type inline static const std::string& TYPE_ID() { - static const std::string MY_TYPE_ID("angle_type"); + static const std::string MY_TYPE_ID("AngleType"); return MY_TYPE_ID; } + /// attribute name of operation type + inline static const std::string& ANGLE_VALUE_ID() + { + static const std::string MY_ANGLE_VALUE_ID("AngleValue"); + return MY_ANGLE_VALUE_ID; + } + /// \brief Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); @@ -71,6 +78,9 @@ class SketchPlugin_ConstraintAngle : public SketchPlugin_ConstraintBase /// Calculate current value of the angle double calculateAngle(); + /// Update value of VALUE attribute by the combination of the current angle type and angle value + void updateAngleValue(); + /// \brief Use plugin manager for features creation SketchPlugin_ConstraintAngle(); diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 51a14e57a..8640c0635 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -204,9 +204,9 @@ - + - aTypeAttr = std::dynamic_pointer_cast< ModelAPI_AttributeInteger>(aData->attribute(SketchPlugin_ConstraintAngle::TYPE_ID())); - AngleType anAngleType = (AngleType)(aTypeAttr->value()); + SketcherPrs_Tools::AngleType anAngleType = (SketcherPrs_Tools::AngleType)(aTypeAttr->value()); // Flyout point std::shared_ptr aFlyoutAttr = @@ -115,13 +115,13 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP TopoDS_Edge aEdge2 = TopoDS::Edge(aTEdge2); switch (anAngleType) { - case ANGLE_DIRECT: { + case SketcherPrs_Tools::ANGLE_DIRECT: { SetGeometryOrientedAngle(true, false); SetArrowVisible(Standard_False, Standard_True); SetMeasuredGeometry(aEdge1, aEdge2); } break; - case ANGLE_SUPPLEMENTARY: { + case SketcherPrs_Tools::ANGLE_SUPPLEMENTARY: { // to calculate center, first and end points SetGeometryOrientedAngle(false, false); SetMeasuredGeometry(aEdge1, aEdge2); @@ -134,7 +134,7 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP SetMeasuredGeometry(aFirstPnt, aCenterPnt, aSecondPnt); } break; - case ANGLE_BACKWARD: { + case SketcherPrs_Tools::ANGLE_BACKWARD: { SetGeometryOrientedAngle(true, true); SetArrowVisible(Standard_False, Standard_True); SetMeasuredGeometry(aEdge1, aEdge2); @@ -157,13 +157,13 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP SetFlyout(aDist); // Angle value is in degrees - AttributeDoublePtr aVal = aData->real(SketchPlugin_Constraint::VALUE()); + AttributeDoublePtr aVal = aData->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()); SetCustomValue(aVal->value() * PI / 180.0); myAspect->SetExtensionSize(myAspect->ArrowAspect()->Length()); myAspect->SetArrowTailSize(myAspect->ArrowAspect()->Length()); - AttributeDoublePtr aValue = myConstraint->data()->real(SketchPlugin_Constraint::VALUE()); + AttributeDoublePtr aValue = myConstraint->data()->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()); SketcherPrs_Tools::setDisplaySpecialSymbol(this, aValue->usedParameters().size() > 0); AIS_AngleDimension::Compute(thePresentationManager, thePresentation, theMode); diff --git a/src/SketcherPrs/SketcherPrs_Angle.h b/src/SketcherPrs/SketcherPrs_Angle.h index 343841feb..0d87c02e3 100644 --- a/src/SketcherPrs/SketcherPrs_Angle.h +++ b/src/SketcherPrs/SketcherPrs_Angle.h @@ -22,14 +22,6 @@ DEFINE_STANDARD_HANDLE(SketcherPrs_Angle, AIS_AngleDimension) */ class SketcherPrs_Angle : public AIS_AngleDimension { -public: - /// Type of angle - enum AngleType{ - ANGLE_DIRECT, ///< Angle from the first line to the second line - ANGLE_SUPPLEMENTARY, ///< Additional angle to the angle from first to second line - ANGLE_BACKWARD ///< Angle from the second line to the first line - }; - public: /// Constructor /// \param theConstraint a constraint feature diff --git a/src/SketcherPrs/SketcherPrs_Tools.h b/src/SketcherPrs/SketcherPrs_Tools.h index 1af656aee..7e10fac73 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.h +++ b/src/SketcherPrs/SketcherPrs_Tools.h @@ -41,6 +41,13 @@ namespace SketcherPrs_Tools { Sel_Dimension_Text }; + /// Type of angle + enum AngleType{ + ANGLE_DIRECT, ///< Angle from the first line to the second line + ANGLE_SUPPLEMENTARY, ///< Additional angle to the angle from first to second line + ANGLE_BACKWARD ///< Angle from the second line to the first line + }; + /// Returns attribute object referenced by feature /// \param theFeature a feature /// \param theAttrName an attribute name