diff --git a/dox/user_guides/draw_test_harness/draw_test_harness.md b/dox/user_guides/draw_test_harness/draw_test_harness.md index 2a5314b433..14800ee537 100644 --- a/dox/user_guides/draw_test_harness/draw_test_harness.md +++ b/dox/user_guides/draw_test_harness/draw_test_harness.md @@ -2306,7 +2306,7 @@ Creates *AIS_ConnectedInteractive* object from the input object and location and **Example:** ~~~~~ -Vinitvinit +vinit vpoint p1 0 0 0 vpoint p2 50 0 0 vsegment segment p1 p2 @@ -2425,9 +2425,10 @@ vdimension name {-angle|-length|-radius|-diameter} -shapes shape1 [shape2 [shape [-label left|right|hcenter|hfit top|bottom|vcenter|vfit] [-arrow external|internal|fit] [{-arrowlength|-arlen} RealArrowLength] [{-arrowangle|-arangle} ArrowAngle(degrees)] [-plane xoy|yoz|zox] - [-flyout FloatValue -extension FloatValue] [-value CustomNumberValue] - [-dispunits DisplayUnitsString] [-modelunits ModelUnitsString] - [-showunits | -hideunits] + [-flyout FloatValue -extension FloatValue] + [-autovalue] [-value CustomRealValue] [-textvalue CustomTextValue] + [-dispunits DisplayUnitsString] + [-modelunits ModelUnitsString] [-showunits | -hideunits] ~~~~~ Builds angle, length, radius or diameter dimension interactive object **name**. @@ -2436,6 +2437,7 @@ Builds angle, length, radius or diameter dimension interactive object **name**. **Example:** ~~~~~ +vinit vpoint p1 0 0 0 vpoint p2 50 50 0 vdimension dim1 -length -plane xoy -shapes p1 p2 @@ -2459,7 +2461,9 @@ vdimparam name [-text 3d|2d wf|sh|wireframe|shading IntegerSize] [{-arrowangle|-arangle} ArrowAngle(degrees)] [-plane xoy|yoz|zox] [-flyout FloatValue -extension FloatValue] - [-value CustomNumberValue] + [-autovalue] + [-value CustomRealValue] + [-textvalue CustomTextValue] [-dispunits DisplayUnitsString] [-modelunits ModelUnitsString] [-showunits | -hideunits] @@ -2469,10 +2473,14 @@ Sets parameters for angle, length, radius and diameter dimension **name**. **Example:** ~~~~~ +vinit vpoint p1 0 0 0 vpoint p2 50 50 0 vdimension dim1 -length -plane xoy -shapes p1 p2 vdimparam dim1 -flyout -15 -arrowlength 4 -showunits -value 10 +vfit +vdimparam dim1 -textvalue "w_1" +vdimparam dim1 -autovalue ~~~~~ @subsubsection occt_draw_4_4_22 vmovedim @@ -2489,6 +2497,7 @@ are adjusted. **Example:** ~~~~~ +vinit vpoint p1 0 0 0 vpoint p2 50 50 0 vdimension dim1 -length -plane xoy -shapes p1 p2 diff --git a/src/AIS/AIS_Dimension.cxx b/src/AIS/AIS_Dimension.cxx index dbf50de470..204c3296cd 100755 --- a/src/AIS/AIS_Dimension.cxx +++ b/src/AIS/AIS_Dimension.cxx @@ -99,8 +99,9 @@ namespace AIS_Dimension::AIS_Dimension (const AIS_KindOfDimension theType) : AIS_InteractiveObject (), mySelToleranceForText2d(0.0), + myValueType (ValueType_Computed), myCustomValue (0.0), - myIsValueCustom (Standard_False), + myCustomStringValue (), myIsTextPositionFixed (Standard_False), mySpecialSymbol (' '), myDisplaySpecialSymbol (AIS_DSS_No), @@ -118,18 +119,43 @@ AIS_Dimension::AIS_Dimension (const AIS_KindOfDimension theType) //======================================================================= void AIS_Dimension::SetCustomValue (const Standard_Real theValue) { - if (myIsValueCustom && myCustomValue == theValue) + if (myValueType == ValueType_CustomReal && myCustomValue == theValue) { return; } - myIsValueCustom = Standard_True; - + myValueType = ValueType_CustomReal; myCustomValue = theValue; SetToUpdate(); } +//======================================================================= +//function : SetCustomValue +//purpose : +//======================================================================= +void AIS_Dimension::SetCustomValue (const TCollection_ExtendedString& theValue) +{ + if (myValueType == ValueType_CustomText && myCustomStringValue == theValue) + { + return; + } + + myValueType = ValueType_CustomText; + myCustomStringValue = theValue; + + SetToUpdate(); +} + +//======================================================================= +//function : GetCustomValue +//purpose : +//======================================================================= +const TCollection_ExtendedString& AIS_Dimension::GetCustomValue () const +{ + return myCustomStringValue; +} + //======================================================================= //function : GetPlane //purpose : @@ -271,12 +297,20 @@ 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 (myValueType == ValueType_CustomText) + { + 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 55eb6ddfca..498eaa04db 100755 --- a/src/AIS/AIS_Dimension.hxx +++ b/src/AIS/AIS_Dimension.hxx @@ -202,6 +202,13 @@ protected: LabelPosition_VMask = LabelPosition_Above | LabelPosition_Below | LabelPosition_VCenter }; + enum ValueType + { + ValueType_Computed, + ValueType_CustomReal, + ValueType_CustomText + }; + public: //! Specifies supported presentation compute modes. @@ -227,7 +234,13 @@ public: //! during display of the presentation. Standard_Real GetValue() const { - return myIsValueCustom ? myCustomValue : ComputeValue(); + return myValueType == ValueType_CustomReal ? myCustomValue : ComputeValue(); + } + + //! Sets computed dimension value. Resets custom value mode if it was set. + void SetComputedValue () + { + myValueType = ValueType_Computed; } //! Sets user-defined dimension value. @@ -236,6 +249,15 @@ public: //! @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); + + //! Gets user-defined dimension value. + //! @return dimension value string. + Standard_EXPORT const TCollection_ExtendedString& GetCustomValue () const; + //! 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. @@ -649,8 +671,10 @@ protected: //! @name Selection geometry protected: //! @name Value properties + ValueType myValueType; //! type of value (computed or user-defined) 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). protected: //! @name Fixed text position properties diff --git a/src/ViewerTest/ViewerTest_RelationCommands.cxx b/src/ViewerTest/ViewerTest_RelationCommands.cxx index b210cf8e69..2d62d78217 100644 --- a/src/ViewerTest/ViewerTest_RelationCommands.cxx +++ b/src/ViewerTest/ViewerTest_RelationCommands.cxx @@ -193,7 +193,9 @@ static Standard_Boolean Get3DPointAtMousePosition (const gp_Pnt& theFirstPoint, // -arrowangle ArrowAngle(degrees) // -plane xoy|yoz|zox // -flyout FloatValue -extension FloatValue -// -value CustomNumberValue +// -autovalue +// -value CustomRealValue +// -textvalue CustomTextValue // -dispunits DisplayUnitsString // -modelunits ModelUnitsString // -showunits @@ -229,6 +231,12 @@ static int ParseDimensionParams (Standard_Integer theArgNum, } // Boolean flags + if (aParam.IsEqual ("-autovalue")) + { + theRealParams.Bind ("autovalue", 1); + continue; + } + if (aParam.IsEqual ("-showunits")) { theAspect->MakeUnitsDisplayed (Standard_True); @@ -440,6 +448,12 @@ static int ParseDimensionParams (Standard_Integer theArgNum, theRealParams.Bind ("value", Draw::Atof (aLocalParam.ToCString())); } + else if (aParam.IsEqual ("-textvalue")) + { + TCollection_AsciiString aLocalParam(theArgVec[++anIt]); + + theStringParams.Bind ("textvalue", aLocalParam); + } else if (aParam.IsEqual ("-modelunits")) { TCollection_AsciiString aLocalParam(theArgVec[++anIt]); @@ -475,11 +489,21 @@ static void SetDimensionParams (const Handle(AIS_Dimension)& theDim, theDim->SetFlyout (theRealParams.Find ("flyout")); } + if (theRealParams.IsBound ("autovalue")) + { + theDim->SetComputedValue(); + } + if (theRealParams.IsBound ("value")) { theDim->SetCustomValue (theRealParams.Find ("value")); } + if (theStringParams.IsBound ("textvalue")) + { + theDim->SetCustomValue (theStringParams.Find ("textvalue")); + } + if (theStringParams.IsBound ("modelunits")) { theDim->SetModelUnits (theStringParams.Find ("modelunits")); @@ -2744,7 +2768,9 @@ void ViewerTest::RelationCommands(Draw_Interpretor& theCommands) "[{-arrowangle|-arangle} ArrowAngle(degrees)]\n" "[-plane xoy|yoz|zox]\n" "[-flyout FloatValue -extension FloatValue]\n" - "[-value CustomNumberValue]\n" + "[-autovalue]\n" + "[-value CustomRealValue]\n" + "[-textvalue CustomTextValue]\n" "[-dispunits DisplayUnitsString]\n" "[-modelunits ModelUnitsString]\n" "[-showunits | -hideunits]\n" @@ -2763,6 +2789,7 @@ void ViewerTest::RelationCommands(Draw_Interpretor& theCommands) "[-plane xoy|yoz|zox]\n" "[-flyout FloatValue -extension FloatValue]\n" "[-value CustomNumberValue]\n" + "[-textvalue CustomTextValue]\n" "[-dispunits DisplayUnitsString]\n" "[-modelunits ModelUnitsString]\n" "[-showunits | -hideunits]\n" diff --git a/tests/bugs/vis/bug27688 b/tests/bugs/vis/bug27688 new file mode 100644 index 0000000000..3cc7095d74 --- /dev/null +++ b/tests/bugs/vis/bug27688 @@ -0,0 +1,34 @@ +puts "========" +puts "Visualization, AIS_Dimension - add possibility to set custom text value" +puts "========" + +# Test case creates three lenght dimensions where value is set as real, +# as text and is reset to auto value state. + +pload MODELING VISUALIZATION + +vinit +vpoint p1 0 0 0 +vpoint p2 50 50 0 + +vdimension dim1 -length -plane xoy -shapes p1 p2 +vdimparam dim1 -flyout -15 -arrowlength 4 -showunits -value 10 + + +vpoint p3 100 100 0 +vpoint p4 150 150 0 + +vdimension dim2 -length -plane xoy -shapes p3 p4 +vdimparam dim2 -flyout -15 -arrowlength 4 -hideunits -textvalue "w_1" +vfit + + +vpoint p5 200 200 0 +vpoint p6 250 250 0 + +vdimension dim3 -length -plane xoy -shapes p5 p6 +vdimparam dim3 -flyout -15 -arrowlength 4 -showunits -textvalue "w_1" +vdimparam dim3 -autovalue + +vfit +vdump $imagedir/${casename}.png