mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-09-18 14:27:39 +03:00
0027688: Visualization, AIS_Dimension - add possibility to set custom text value
Implementation of custom text in dimension presentation; Test case is provided for this bug; Code correction: Standard_EXPORT is removed for inline method. Minor correction of test case bugs/vis/bug27688
This commit is contained in:
@@ -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())
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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"
|
||||
|
Reference in New Issue
Block a user