Salome HOME
Using test for testing number of sub-shapes.
[modules/shaper.git] / src / SketcherPrs / SketcherPrs_Angle.cpp
index d46643fd9c375075d0a5ad7fd2a2114020239162..03a74c4fb05f5b2322998a3aef23f127b2e93398 100644 (file)
@@ -5,8 +5,8 @@
 // Author:      Vitaly SMETANNIKOV
 
 #include "SketcherPrs_Angle.h"
-#include "SketcherPrs_Tools.h"
 #include "SketcherPrs_DimensionStyleListener.h"
+#include "SketcherPrs_Tools.h"
 
 #include <SketchPlugin_ConstraintAngle.h>
 #include <SketchPlugin_Constraint.h>
 #include <TopExp.hxx>
 #include <BRep_Tool.hxx>
 
-#include <Events_Error.h>
-
 #define PI 3.1415926535897932
 
-IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Angle, AIS_AngleDimension_);
-IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Angle, AIS_AngleDimension_);
+//#ifndef WNT
+//  #define COMPILATION_CORRECTION
+//#endif
 
-SketcherPrs_Angle::SketcherPrs_Angle(ModelAPI_Feature* theConstraint, 
+IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Angle, AIS_AngleDimension);
+
+SketcherPrs_Angle::SketcherPrs_Angle(ModelAPI_Feature* theConstraint,
                                      const std::shared_ptr<GeomAPI_Ax3>& thePlane)
-: AIS_AngleDimension_(gp_Pnt(0,0,0), gp_Pnt(1,0,0), gp_Pnt(0,1,0)), myConstraint(theConstraint),
+: AIS_AngleDimension(gp_Pnt(0,0,0), gp_Pnt(1,0,0), gp_Pnt(0,1,0)), myConstraint(theConstraint),
   mySketcherPlane(thePlane),
   myFirstPoint(gp_Pnt(0,0,0)), myCenterPoint(gp_Pnt(1,0,0)), mySecondPoint(gp_Pnt(0,1,0)),
-  myAngle(90), myValue("90"), myFlyOutPoint(0, 0.5, 0)
+  myValue(90., false, ""), myFlyOutPoint(0, 0.5, 0)
 {
   myAspect = new Prs3d_DimensionAspect();
   myAspect->MakeArrows3d(false);
@@ -46,9 +47,8 @@ SketcherPrs_Angle::SketcherPrs_Angle(ModelAPI_Feature* theConstraint,
   myAspect->MakeUnitsDisplayed(false);
   myAspect->TextAspect()->SetHeight(SketcherPrs_Tools::getDefaultTextHeight());
   myAspect->ArrowAspect()->SetLength(SketcherPrs_Tools::getArrowSize());
-  
+
   SetDimensionAspect(myAspect);
-  SetSelToleranceForText2d(SketcherPrs_Tools::getDefaultTextHeight());
 
   myStyleListener = new SketcherPrs_DimensionStyleListener();
 }
@@ -75,7 +75,7 @@ bool SketcherPrs_Angle::readyToDisplay(ModelAPI_Feature* theConstraint,
   DataPtr aData = theConstraint->data();
 
   // Flyout point
-  std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = 
+  std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
     std::dynamic_pointer_cast<GeomDataAPI_Point2D>
     (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
   if (!aFlyoutAttr->isInitialized())
@@ -89,8 +89,10 @@ bool SketcherPrs_Angle::readyToDisplay(ModelAPI_Feature* theConstraint,
   if (!anAttr2->isInitialized())
     return aReadyToDisplay;
 
-  FeaturePtr aLineA = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A());
-  FeaturePtr aLineB = SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B());
+  FeaturePtr aLineA =
+    SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_A());
+  FeaturePtr aLineB =
+    SketcherPrs_Tools::getFeatureLine(aData, SketchPlugin_Constraint::ENTITY_B());
 
   if (!aLineA.get() || !aLineB.get())
     return aReadyToDisplay;
@@ -105,16 +107,22 @@ bool SketcherPrs_Angle::readyToDisplay(ModelAPI_Feature* theConstraint,
       aLineB->attribute(SketchPlugin_Line::END_ID()));
 
   std::shared_ptr<GeomAPI_Angle2d> anAng;
-  if (!aData->attribute(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_FIRST_LINE_ID())->isInitialized() ||
-      !aData->attribute(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID())->isInitialized())
+  bool isFirstPnt = aData->attribute(
+    SketchPlugin_ConstraintAngle::ANGLE_REVERSED_FIRST_LINE_ID())->isInitialized();
+  bool isSecondPnt = aData->attribute(
+    SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID())->isInitialized();
+  if (!isFirstPnt || !isSecondPnt)
     anAng = std::shared_ptr<GeomAPI_Angle2d>(new GeomAPI_Angle2d(
         aStartA->pnt(), aEndA->pnt(), aStartB->pnt(), aEndB->pnt()));
   else {
     std::shared_ptr<GeomAPI_Lin2d> aLine1(new GeomAPI_Lin2d(aStartA->pnt(), aEndA->pnt()));
-    bool isReversed1 = aData->boolean(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_FIRST_LINE_ID())->value();
+    bool isReversed1 =
+      aData->boolean(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_FIRST_LINE_ID())->value();
     std::shared_ptr<GeomAPI_Lin2d> aLine2(new GeomAPI_Lin2d(aStartB->pnt(), aEndB->pnt()));
-    bool isReversed2 = aData->boolean(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID())->value();
-    anAng = std::shared_ptr<GeomAPI_Angle2d>(new GeomAPI_Angle2d(aLine1, isReversed1, aLine2, isReversed2));
+    bool isReversed2 =
+      aData->boolean(SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID())->value();
+    anAng = std::shared_ptr<GeomAPI_Angle2d>(
+      new GeomAPI_Angle2d(aLine1, isReversed1, aLine2, isReversed2));
   }
 
   gp_Pnt2d aFirstPoint = anAng->firstPoint()->impl<gp_Pnt2d>();
@@ -134,27 +142,27 @@ bool SketcherPrs_Angle::readyToDisplay(ModelAPI_Feature* theConstraint,
 
 
 void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
-                                const Handle(Prs3d_Presentation)& thePresentation, 
+                                const Handle(Prs3d_Presentation)& thePresentation,
                                 const Standard_Integer theMode)
 {
   gp_Pnt aFirstPoint, aSecondPoint, aCenterPoint;
-  bool aReadyToDisplay = readyToDisplay(myConstraint, mySketcherPlane, aFirstPoint, aSecondPoint, aCenterPoint);
+  bool aReadyToDisplay = readyToDisplay(myConstraint, mySketcherPlane,
+                                        aFirstPoint, aSecondPoint, aCenterPoint);
   if (aReadyToDisplay) {
     myFirstPoint = aFirstPoint;
     mySecondPoint = aSecondPoint;
     myCenterPoint = aCenterPoint;
 
     DataPtr aData = myConstraint->data();
-    AttributeDoublePtr aVal = aData->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID());
-    myAngle = aVal->value();
-    myValue = aVal->text();
+    AttributeDoublePtr anAttributeValue =
+      aData->real(SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID());
+    myValue.init(anAttributeValue);
 
-    myHasParameters = aVal->usedParameters().size() > 0;
-
-    std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = 
+    std::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
                                 std::dynamic_pointer_cast<GeomDataAPI_Point2D>
                                 (aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()));
-    std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = mySketcherPlane->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
+    std::shared_ptr<GeomAPI_Pnt> aFlyoutPnt =
+      mySketcherPlane->to3D(aFlyoutAttr->x(), aFlyoutAttr->y());
     myFlyOutPoint = aFlyoutPnt->impl<gp_Pnt>();
   }
 
@@ -166,10 +174,14 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP
   double aDist = -1;
   switch (anAngleType) {
     case SketcherPrs_Tools::ANGLE_DIRECT: {
-      SetArrowVisible(Standard_False/*first*/, Standard_True/*second*/);
+#ifndef COMPILATION_CORRECTION
+      SetArrowsVisibility(AIS_TOAV_Second);
+#endif
       SetMeasuredGeometry(myFirstPoint, myCenterPoint, mySecondPoint);
+#ifndef COMPILATION_CORRECTION
       bool isReversedPlanes = isAnglePlaneReversedToSketchPlane();
-      SetAngleReversed(!isReversedPlanes);
+      SetType(!isReversedPlanes ? AIS_TOA_Exterior : AIS_TOA_Interior);
+#endif
     }
     break;
     case SketcherPrs_Tools::ANGLE_COMPLEMENTARY: {
@@ -178,14 +190,20 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP
       gp_Pnt aFirstPoint = aCenterPoint.Translated(
                           gp_Vec(myCenterPoint, myFirstPoint).Normalized() * (-anEdge1Length));
       SetMeasuredGeometry(aFirstPoint, myCenterPoint, mySecondPoint);
-      SetAngleReversed(false);
+#ifndef COMPILATION_CORRECTION
+      SetType(AIS_TOA_Interior);
+#endif
     }
     break;
     case SketcherPrs_Tools::ANGLE_BACKWARD: {
-      SetArrowVisible(Standard_False/*first*/, Standard_True/*second*/);
+#ifndef COMPILATION_CORRECTION
+      SetArrowsVisibility(AIS_TOAV_Second);
+#endif
       SetMeasuredGeometry(myFirstPoint, myCenterPoint, mySecondPoint);
       bool isReversedPlanes = isAnglePlaneReversedToSketchPlane();
-      SetAngleReversed(isReversedPlanes);
+#ifndef COMPILATION_CORRECTION
+      SetType(isReversedPlanes ? AIS_TOA_Exterior : AIS_TOA_Interior);
+#endif
     }
     break;
     default:
@@ -195,16 +213,13 @@ void SketcherPrs_Angle::Compute(const Handle(PrsMgr_PresentationManager3d)& theP
     aDist = calculateDistanceToFlyoutPoint();
   SetFlyout(aDist);
 
-  // Angle value is in degrees
-  SetCustomValue(myAngle);
+  // Update text visualization: parameter value or parameter text
+  myStyleListener->updateDimensions(this, myValue);
 
   myAspect->SetExtensionSize(myAspect->ArrowAspect()->Length());
   myAspect->SetArrowTailSize(myAspect->ArrowAspect()->Length());
 
-  // Update text visualization: parameter value or parameter text
-  myStyleListener->updateDimensions(this, myHasParameters, myValue);
-
-  AIS_AngleDimension_::Compute(thePresentationManager, thePresentation, theMode);
+  AIS_AngleDimension::Compute(thePresentationManager, thePresentation, theMode);
 
   if (!aReadyToDisplay)
     SketcherPrs_Tools::sendEmptyPresentationError(myConstraint,
@@ -231,10 +246,11 @@ void SketcherPrs_Angle::ComputeSelection(const Handle(SelectMgr_Selection)& aSel
   default: {
     // there are own selection modes, so the others should be ignored
     // otherwise, the text selection appears in the viewer
-    return; 
+    return;
   }
   }
-  AIS_AngleDimension_::ComputeSelection(aSelection, aMode);
+  SetSelToleranceForText2d(SketcherPrs_Tools::getTextHeight());
+  AIS_AngleDimension::ComputeSelection(aSelection, aMode);
 }
 
 bool SketcherPrs_Angle::isAnglePlaneReversedToSketchPlane()
@@ -252,11 +268,5 @@ bool SketcherPrs_Angle::isAnglePlaneReversedToSketchPlane()
 
 double SketcherPrs_Angle::calculateDistanceToFlyoutPoint()
 {
-  gp_Dir aBisector((myFirstPoint.XYZ() + mySecondPoint.XYZ()) * 0.5 - myCenterPoint.XYZ());
-  //gp_Pnt aFlyPnt(aFlyoutPnt->x(), aFlyoutPnt->y(), aFlyoutPnt->z());
-  gp_XYZ aFlyDir = myFlyOutPoint.XYZ() - myCenterPoint.XYZ();
-  double aDistance = aFlyDir.Dot(aBisector.XYZ());
-  // make a positive distance in order to AIS angle presentation is not reversed
-  aDistance = fabs(aDistance);
-  return aDistance;
+  return myFlyOutPoint.Distance(myCenterPoint);
 }