]> OCCT Git - occt-copy.git/commitdiff
AIS_Dimension is extended to use custom text value
authornds <nds@opencascade.com>
Fri, 17 Jun 2016 09:19:11 +0000 (12:19 +0300)
committernds <nds@opencascade.com>
Fri, 17 Jun 2016 09:19:11 +0000 (12:19 +0300)
AIS_AngleDimension is extended to visualize reversed angle and only one of arrows.

src/AIS/AIS_AngleDimension.cxx
src/AIS/AIS_AngleDimension.hxx
src/AIS/AIS_Dimension.cxx
src/AIS/AIS_Dimension.hxx

index 2767e031070218d3bee6add0368be704f4a7c69f..f37afab0ad904bb1740b0dbf253e8ddc069cb15a 100644 (file)
@@ -277,6 +277,8 @@ void AIS_AngleDimension::SetMeasuredGeometry (const TopoDS_Face& theFirstFace,
 //=======================================================================
 void AIS_AngleDimension::Init()
 {
+  SetAngleReversed (Standard_False);
+  SetArrowVisible (Standard_True, Standard_True);
   SetSpecialSymbol (THE_DEGREE_SYMBOL);
   SetDisplaySpecialSymbol (AIS_DSS_After);
   SetFlyout (15.0);
@@ -298,6 +300,12 @@ gp_Pnt AIS_AngleDimension::GetCenterOnArc (const gp_Pnt& theFirstAttach,
   }
   
   gp_Pln aPlane = aConstructPlane.Value();
+  if (myUseReverse) {
+    gp_Ax1 anAxis = aPlane.Axis();
+    gp_Dir aDir = anAxis.Direction();
+    aDir.Reverse();
+    aPlane.SetAxis(gp_Ax1(anAxis.Location(), aDir));
+  }
 
   Standard_Real aRadius = theFirstAttach.Distance (theCenter);
 
@@ -337,7 +345,13 @@ void AIS_AngleDimension::DrawArc (const Handle(Prs3d_Presentation)& thePresentat
   }
 
   gp_Pln aPlane = aConstructPlane.Value();
-
+  if (myUseReverse) {
+    gp_Ax1 anAxis = aPlane.Axis();
+    gp_Dir aDir = anAxis.Direction();
+    aDir.Reverse();
+    aPlane.SetAxis(gp_Ax1(anAxis.Location(), aDir));
+  }
+  
   // construct circle forming the arc
   gce_MakeCirc aConstructCircle (theCenter, aPlane, theRadius);
   if (!aConstructCircle.IsDone())
@@ -348,7 +362,7 @@ void AIS_AngleDimension::DrawArc (const Handle(Prs3d_Presentation)& thePresentat
   gp_Circ aCircle = aConstructCircle.Value();
 
   // construct the arc
-  GC_MakeArcOfCircle aConstructArc (aCircle, theFirstAttach, theSecondAttach, Standard_True);
+  GC_MakeArcOfCircle aConstructArc(aCircle, theFirstAttach, theSecondAttach, Standard_True);
   if (!aConstructArc.IsDone())
   {
     return;
@@ -362,7 +376,13 @@ void AIS_AngleDimension::DrawArc (const Handle(Prs3d_Presentation)& thePresentat
   // compute number of discretization elements in old-fanshioned way
   gp_Vec aCenterToFirstVec  (theCenter, theFirstAttach);
   gp_Vec aCenterToSecondVec (theCenter, theSecondAttach);
-  const Standard_Real anAngle = aCenterToFirstVec.Angle (aCenterToSecondVec);
+
+  gp_Ax1 anAxis = aPlane.Axis();
+  gp_Dir aDir = anAxis.Direction();
+  gp_Vec aRefVec(aDir);
+  Standard_Real anAngle = aCenterToFirstVec.AngleWithRef (aCenterToSecondVec, aRefVec);
+  if (anAngle < 0)
+    anAngle = 2.0 * M_PI + anAngle;
   const Standard_Integer aNbPoints = Max (4, Standard_Integer (50.0 * anAngle / M_PI));
 
   GCPnts_UniformAbscissa aMakePnts (anArcAdaptor, aNbPoints);
@@ -694,8 +714,8 @@ void AIS_AngleDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*
       if (theMode == ComputeMode_All || theMode == ComputeMode_Line)
       {
         DrawArc (thePresentation,
-                 isArrowsExternal ? aFirstAttach : aFirstArrowEnd,
-                 isArrowsExternal ? aSecondAttach : aSecondArrowEnd,
+                 (isArrowsExternal || !myFirstArrowVisible) ? aFirstAttach : aFirstArrowEnd,
+                 (isArrowsExternal || !mySecondArrowVisible) ? aSecondAttach : aSecondArrowEnd,
                  myCenterPoint,
                  Abs (GetFlyout()),
                  theMode);
@@ -707,7 +727,7 @@ void AIS_AngleDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*
     {
       DrawExtension (thePresentation,
                      anExtensionSize,
-                     isArrowsExternal ? aFirstArrowEnd : aFirstAttach,
+                     (isArrowsExternal && myFirstArrowVisible) ? aFirstArrowEnd : aFirstAttach,
                      aFirstExtensionDir,
                      aLabelString,
                      aLabelWidth,
@@ -720,7 +740,7 @@ void AIS_AngleDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*
     {
       DrawExtension (thePresentation,
                      anExtensionSize,
-                     isArrowsExternal ? aSecondArrowEnd : aSecondAttach,
+                     (isArrowsExternal && mySecondArrowVisible) ? aSecondArrowEnd : aSecondAttach,
                      aSecondExtensionDir,
                      aLabelString,
                      aLabelWidth,
@@ -736,8 +756,8 @@ void AIS_AngleDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*
     Prs3d_Root::NewGroup (thePresentation);
 
     DrawArc (thePresentation,
-             isArrowsExternal ? aFirstAttach  : aFirstArrowEnd,
-             isArrowsExternal ? aSecondAttach : aSecondArrowEnd,
+             (isArrowsExternal || !myFirstArrowVisible) ? aFirstAttach  : aFirstArrowEnd,
+             (isArrowsExternal || !mySecondArrowVisible) ? aSecondAttach : aSecondArrowEnd,
              myCenterPoint,
              Abs(GetFlyout ()),
              theMode);
@@ -748,15 +768,17 @@ void AIS_AngleDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*
   {
     Prs3d_Root::NewGroup (thePresentation);
 
-    DrawArrow (thePresentation, aFirstArrowBegin,  gp_Dir (aFirstArrowVec));
-    DrawArrow (thePresentation, aSecondArrowBegin, gp_Dir (aSecondArrowVec));
+    if (myFirstArrowVisible)
+      DrawArrow (thePresentation, aFirstArrowBegin,  gp_Dir (aFirstArrowVec));
+    if (mySecondArrowVisible)
+      DrawArrow (thePresentation, aSecondArrowBegin, gp_Dir (aSecondArrowVec));
   }
 
   if ((theMode == ComputeMode_All || theMode == ComputeMode_Line) && isArrowsExternal)
   {
     Prs3d_Root::NewGroup (thePresentation);
 
-    if (aHPosition != LabelPosition_Left)
+    if (aHPosition != LabelPosition_Left && myFirstArrowVisible)
     {
       DrawExtension (thePresentation,
                      aDimensionAspect->ArrowTailSize(),
@@ -768,7 +790,7 @@ void AIS_AngleDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*
                      LabelPosition_None);
     }
 
-    if (aHPosition != LabelPosition_Right)
+    if (aHPosition != LabelPosition_Right && mySecondArrowVisible)
     {
       DrawExtension (thePresentation,
                      aDimensionAspect->ArrowTailSize(),
@@ -902,13 +924,12 @@ Standard_Boolean AIS_AngleDimension::InitTwoEdgesAngle (gp_Pln& theComputedPlane
     // |
     // | <- dimension should be here
     // *----
-    myFirstPoint  = myCenterPoint.Distance (aFirstPoint1) > myCenterPoint.Distance (aLastPoint1)
-                  ? aFirstPoint1
-                  : aLastPoint1;
-
-    mySecondPoint = myCenterPoint.Distance (aFirstPoint2) > myCenterPoint.Distance (aLastPoint2)
-                  ? aFirstPoint2
-                  : aLastPoint2;
+    myFirstPoint  = !myCenterPoint.IsEqual(aFirstPoint1, Precision::Confusion())
+                    ? aFirstPoint1
+                    : aLastPoint1;
+    mySecondPoint = !myCenterPoint.IsEqual(aFirstPoint2, Precision::Confusion())
+                    ? aFirstPoint2
+                    : aLastPoint2;
   }
 
   return IsValidPoints (myFirstPoint, myCenterPoint, mySecondPoint);
@@ -1229,6 +1250,26 @@ void AIS_AngleDimension::SetTextPosition (const gp_Pnt& theTextPos)
   myFixedTextPosition = theTextPos;
 }
 
+//=======================================================================
+//function : SetAngleReversed
+//purpose  : 
+//=======================================================================
+void AIS_AngleDimension::SetAngleReversed(const Standard_Boolean& theUseReverse)
+{
+  myUseReverse = theUseReverse;
+}
+
+//=======================================================================
+//function : SetArrowVisible
+//purpose  : 
+//=======================================================================
+void AIS_AngleDimension::SetArrowVisible(const Standard_Boolean& theFirstArrowVisible,
+                                         const Standard_Boolean& theSecondArrowVisible)
+{
+  myFirstArrowVisible = theFirstArrowVisible;
+  mySecondArrowVisible = theSecondArrowVisible;
+}
+
 //=======================================================================
 //function : AdjustParameters
 //purpose  : 
index 3a4495666dbc8fecf848e083d5870edd618bf1e9..445a754f1c3540158025fa226e8819ab1a504869 100755 (executable)
@@ -207,6 +207,17 @@ public:
 
   Standard_EXPORT virtual const gp_Pnt GetTextPosition () const;
 
+  //! Sets state if the angle arc should be built reversing to the presentation plane.
+  //! Default state is not reversed
+  //! @param theUseReverse [in] the boolean state.
+  Standard_EXPORT void SetAngleReversed(const Standard_Boolean& theUseReverse);
+
+  //! Sets visible state of angle arrows. Default value is true for both
+  //! @param theFirstArrowVisible [in] the visibility of the first arrow.
+  //! @param theSecondArrowVisible [in] the visibility of the second arrow.
+  Standard_EXPORT void SetArrowVisible(const Standard_Boolean& theFirstArrowVisible,
+                                       const Standard_Boolean& theSecondArrowVisible);
+
 public:
 
   DEFINE_STANDARD_RTTI (AIS_AngleDimension)
@@ -335,6 +346,10 @@ protected:
                                                   const gp_Pnt& theSecondPoint) const;
 
 private:
+  Standard_Boolean myUseReverse;
+
+  Standard_Boolean myFirstArrowVisible;
+  Standard_Boolean mySecondArrowVisible;
 
   gp_Pnt myFirstPoint;
   gp_Pnt mySecondPoint;
index a09e1a1da27cf5cae4b1fd30c3bacfe2d4967ee6..92703a57b4de29a709e0587ba55bb7a0548d0413 100755 (executable)
@@ -99,7 +99,9 @@ AIS_Dimension::AIS_Dimension (const AIS_KindOfDimension theType)
 : AIS_InteractiveObject  (),
   mySelToleranceForText2d(0.0),
   myCustomValue          (0.0),
+  myCustomStringValue    (""),
   myIsValueCustom        (Standard_False),
+  myIsStringValueCustom  (Standard_False),
   myIsTextPositionFixed  (Standard_False), 
   mySpecialSymbol        (' '),
   myDisplaySpecialSymbol (AIS_DSS_No),
@@ -129,6 +131,24 @@ void AIS_Dimension::SetCustomValue (const Standard_Real theValue)
   SetToUpdate();
 }
 
+//=======================================================================
+//function : SetCustomValue
+//purpose  : 
+//=======================================================================
+void AIS_Dimension::SetCustomValue (const TCollection_ExtendedString& theValue)
+{
+  if (myIsStringValueCustom && myCustomStringValue == theValue)
+  {
+    return;
+  }
+
+  myIsStringValueCustom = Standard_True;
+
+  myCustomStringValue = theValue;
+
+  SetToUpdate();
+}
+
 //=======================================================================
 //function : GetPlane
 //purpose  : 
@@ -279,12 +299,18 @@ Standard_Real AIS_Dimension::ValueToDisplayUnits() const
 //=======================================================================
 TCollection_ExtendedString AIS_Dimension::GetValueString (Standard_Real& theWidth) const
 {
-  // format value string using "sprintf"
-  TCollection_AsciiString aFormatStr = myDrawer->DimensionAspect()->ValueStringFormat();
+  TCollection_ExtendedString aValueStr;
+  if (myIsStringValueCustom) {
+    aValueStr = myCustomStringValue;
+  }
+  else {
+    // format value string using "sprintf"
+    TCollection_AsciiString aFormatStr = myDrawer->DimensionAspect()->ValueStringFormat();
 
-  char aFmtBuffer[256];
-  sprintf (aFmtBuffer, aFormatStr.ToCString(), ValueToDisplayUnits());
-  TCollection_ExtendedString aValueStr = TCollection_ExtendedString (aFmtBuffer);
+    char aFmtBuffer[256];
+    sprintf (aFmtBuffer, aFormatStr.ToCString(), ValueToDisplayUnits());
+    aValueStr = TCollection_ExtendedString (aFmtBuffer);
+  }
 
   // add units to values string
   if (myDrawer->DimensionAspect()->IsUnitsDisplayed())
index 6992339ff9a56765f4e209d271ee71144740c96c..d4c56afcfc69307d66e866f46d0e1e1a98fb122b 100755 (executable)
@@ -219,22 +219,17 @@ public:
   //! @param theType [in] the type of dimension.
   Standard_EXPORT AIS_Dimension (const AIS_KindOfDimension theType);
 
-  //! Gets dimension measurement value. If the value to display is not
-  //! specified by user, then the dimension object is responsible to
-  //! compute it on its own in model space coordinates.
-  //! @return the dimension value (in model units) which is used
-  //! during display of the presentation.
-  Standard_Real GetValue() const
-  {
-    return myIsValueCustom ? myCustomValue : ComputeValue();
-  }
-
   //! Sets user-defined dimension value.
   //! The user-defined dimension value is specified in model space,
   //! and affect by unit conversion during the display.
   //! @param theValue [in] the user-defined value to display.
   Standard_EXPORT void SetCustomValue (const Standard_Real theValue);
 
+  //! Sets user-defined dimension value.
+  //! Unit conversion during the display is not applyed.
+  //! @param theValue [in] the user-defined value to display.
+  Standard_EXPORT void SetCustomValue (const TCollection_ExtendedString& theValue);
+
   //! Get the dimension plane in which the 2D dimension presentation is computed.
   //! By default, if plane is not defined by user, it is computed automatically
   //! after dimension geometry is computed.
@@ -383,6 +378,16 @@ protected:
 
   Standard_EXPORT Standard_Real ValueToDisplayUnits() const;
 
+  //! Gets dimension measurement value. If the value to display is not
+  //! specified by user, then the dimension object is responsible to
+  //! compute it on its own in model space coordinates.
+  //! @return the dimension value (in model units) which is used
+  //! during display of the presentation.
+  Standard_Real GetValue() const
+  {
+    return myIsValueCustom ? myCustomValue : ComputeValue();
+  }
+
   //! Get formatted value string and its model space width.
   //! @param theWidth [out] the model space with of the string.
   //! @return formatted dimension value string.
@@ -655,13 +660,15 @@ protected: //! @name Value properties
   Standard_Real    myCustomValue;   //!< Value of the dimension (computed or user-defined).
   Standard_Boolean myIsValueCustom; //!< Is user-defined value.
 
+  TCollection_ExtendedString myCustomStringValue; //!< Value of the dimension (computed or user-defined).
+  Standard_Boolean myIsStringValueCustom; //!< Is user-defined value.
+
 protected: //! @name Fixed text position properties
 
   gp_Pnt                  myFixedTextPosition;   //!< Stores text position fixed by user.
   Standard_Boolean        myIsTextPositionFixed; //!< Is the text label position fixed by user.
 
 protected: //! @name Units properties
-
   Standard_ExtCharacter    mySpecialSymbol;        //!< Special symbol.
   AIS_DisplaySpecialSymbol myDisplaySpecialSymbol; //!< Special symbol display options.