Salome HOME
Issue 1299 Angle presentation: providing angle value attirbute in feature which serve...
authornds <nds@opencascade.com>
Thu, 17 Mar 2016 06:58:20 +0000 (09:58 +0300)
committernds <nds@opencascade.com>
Thu, 17 Mar 2016 06:58:20 +0000 (09:58 +0300)
src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp
src/SketchPlugin/SketchPlugin_ConstraintAngle.h
src/SketchPlugin/plugin-Sketch.xml
src/SketcherPrs/SketcherPrs_Angle.cpp
src/SketcherPrs/SketcherPrs_Angle.h
src/SketcherPrs/SketcherPrs_Tools.h

index 6f3f8b8535ce0289af9a1c6d9d505f3c67943eb6..8caf3ee8984a36308348c5d646ad04a08da52d6f 100644 (file)
@@ -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<ModelAPI_AttributeDouble>(
-      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<ModelAPI_AttributeDouble> 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<ModelAPI_AttributeDouble> 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<ModelAPI_AttributeInteger> 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<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
+    ModelAPI_AttributeDouble>(data()->attribute(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()));
+  double anAngle = aValueAttr->value();
+
+  std::shared_ptr<ModelAPI_Data> aData = data();
+  std::shared_ptr<ModelAPI_AttributeInteger> 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<ModelAPI_Data> aData = data();
index ed593ab5ebb3ab355a8a40cd0d36a992f8c761a0..c0f1c712c49a10da4a0c7e9e64ae309cf934a21d 100644 (file)
@@ -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();
 
index 51a14e57a17f27fdeff25dcc43e5ae4b0c3a6fad..8640c0635bbd5557f76ac99e7474cae9a35b3bda 100644 (file)
           <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
         </sketch_shape_selector>
         <sketch-2dpoint_flyout_selector id="ConstraintFlyoutValuePnt"  default="computed" internal="1" obligatory="0"/>
-        <doublevalue_editor label="Value" tooltip="Angle" id="ConstraintValue" default="computed" min="0" max="360" />
+        <doublevalue_editor label="Value" tooltip="Angle" id="AngleValue" default="computed" min="0" max="360" />
         <validator id="PartSet_AngleSelection"/>
-        <module_choice id="angle_type"
+        <module_choice id="AngleType"
           widget_type="radiobuttons"
           buttons_dir="horizontal"
           label="Operation type"
index 8d91021bc7e2d4a9137bf19e2c56e1bb634bd404..42934eb7fe09227b1ce8566ee16b38f143a06452 100644 (file)
@@ -90,7 +90,7 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP
 
   std::shared_ptr<ModelAPI_AttributeInteger> 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<GeomDataAPI_Point2D> 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);
index 343841feb700cb44ad7f25542a638b59b6f5aae7..0d87c02e3bc71cf56c8257d7a24d7bbd82be1431 100644 (file)
@@ -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
index 1af656aee3f2bc19dffa01065e6787bf0e1c26c9..7e10fac7321c37185c3ade40743b124821429844 100644 (file)
@@ -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