diff --git a/src/AIS/AIS_AngleDimension.cxx b/src/AIS/AIS_AngleDimension.cxx index 2767e03107..f37afab0ad 100644 --- a/src/AIS/AIS_AngleDimension.cxx +++ b/src/AIS/AIS_AngleDimension.cxx @@ -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 : diff --git a/src/AIS/AIS_AngleDimension.hxx b/src/AIS/AIS_AngleDimension.hxx index 3a4495666d..445a754f1c 100755 --- a/src/AIS/AIS_AngleDimension.hxx +++ b/src/AIS/AIS_AngleDimension.hxx @@ -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; diff --git a/src/AIS/AIS_Dimension.cxx b/src/AIS/AIS_Dimension.cxx index a09e1a1da2..92703a57b4 100755 --- a/src/AIS/AIS_Dimension.cxx +++ b/src/AIS/AIS_Dimension.cxx @@ -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()) diff --git a/src/AIS/AIS_Dimension.hxx b/src/AIS/AIS_Dimension.hxx index 6992339ff9..d4c56afcfc 100755 --- a/src/AIS/AIS_Dimension.hxx +++ b/src/AIS/AIS_Dimension.hxx @@ -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.