1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0024412: TKV3d, Dimensions - Possibility to customize text position was lost:

AIS_Dimension::GetTextPosition() and AIS_Dimension::SetTextPosition() methods were added.
Added possibility to set and unset text label alignment respectively to the attach points after text position changed.
Added test cases to check text positioning with dimension parameters and with setting 3D point.
Corrected DRAW commands vmovedim, vangledim, vdistdim, vradiusdim.
Corrections of AIS_Dimension::SetTextPosition(): aspect parameters are not changed inside it.
Layout mode was removed; test cases and vdimparams, vdimension  commands were corrected.
remarks: coding style, removing redundant code of LayoutMode enumeration.
This commit is contained in:
aba 2014-02-13 12:43:56 +04:00 committed by apn
parent 3b010a7435
commit af203d549a
16 changed files with 1842 additions and 839 deletions

View File

@ -241,19 +241,23 @@ is
KOI_Datum,
KOI_Shape,
KOI_Object,
KOI_Relation;
--- Purpose: Declares the type of Interactive Object.
-- This is one of the following:
-- - the Datum
-- - the Object
-- - the Relation
-- - the None type.
-- The Datum is the construction element. These include
-- points, lines, axes and planes. The object brings
-- together topological shapes. The Relation includes
-- dimensions and constraints. When the object is of an
-- unknown type, the None type is declared.
KOI_Relation,
KOI_Dimension;
--- Purpose: Declares the type of Interactive Object.
-- This is one of the following:
-- - the Datum
-- - the Object
-- - the Relation
-- - the Dimension
-- - the None type.
-- The Datum is the construction element. These include
-- points, lines, axes and planes. The object brings
-- together topological shapes. The Relation includes
-- dimensions and constraints. The Dimension includes
-- length, radius, diameter and angle dimensions.
-- When the object is of an unknown type, the None
-- type is declared.
enumeration ClearMode is
CM_All,
CM_Interactive,

View File

@ -48,6 +48,7 @@
#include <Select3D_SensitiveGroup.hxx>
#include <Select3D_SensitiveSegment.hxx>
#include <SelectMgr_Selection.hxx>
#include <Standard_ProgramError.hxx>
#include <UnitsAPI.hxx>
IMPLEMENT_STANDARD_HANDLE (AIS_AngleDimension, AIS_Dimension)
@ -152,7 +153,7 @@ void AIS_AngleDimension::SetMeasuredGeometry (const TopoDS_Edge& theFirstEdge,
if (myIsValid && !myIsPlaneCustom)
{
myPlane = aComputedPlane;
ComputePlane();
}
myIsValid &= CheckPlane (myPlane);
@ -300,7 +301,7 @@ void AIS_AngleDimension::Init()
//=======================================================================
gp_Pnt AIS_AngleDimension::GetCenterOnArc (const gp_Pnt& theFirstAttach,
const gp_Pnt& theSecondAttach,
const gp_Pnt& theCenter)
const gp_Pnt& theCenter) const
{
// construct plane where the circle and the arc are located
gce_MakePln aConstructPlane (theFirstAttach, theSecondAttach, theCenter);
@ -583,7 +584,7 @@ Standard_Real AIS_AngleDimension::ComputeValue() const
Standard_Real anAngle = aVec2.AngleWithRef (aVec1, GetPlane().Axis().Direction());
return anAngle > 0.0 ? anAngle : (2.0 * M_PI - anAngle);
return anAngle > 0.0 ? anAngle : (2.0 * M_PI + anAngle);
}
//=======================================================================
@ -619,31 +620,23 @@ void AIS_AngleDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*
aLabelWidth += aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN * 2.0;
}
gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
// Get parameters from aspect or adjust it according with custom text position
Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
Prs3d_DimensionTextHorizontalPosition aHorisontalTextPos = aDimensionAspect->TextHorizontalPosition();
if (IsTextPositionCustom())
{
AdjustParameters (myFixedTextPosition,anExtensionSize, aHorisontalTextPos);
}
// Handle user-defined and automatic arrow placement
bool isArrowsExternal = false;
switch (aDimensionAspect->ArrowOrientation())
{
case Prs3d_DAO_External: isArrowsExternal = true; break;
case Prs3d_DAO_Internal: isArrowsExternal = false; break;
case Prs3d_DAO_Fit:
{
gp_Vec anAttachVector (aFirstAttach, aSecondAttach);
Standard_Real aDimensionWidth = anAttachVector.Magnitude();
Standard_Boolean isArrowsExternal = Standard_False;
Standard_Integer aLabelPosition = LabelPosition_None;
// add margin to ensure a small tail between text and arrow
Standard_Real anArrowMargin = aDimensionAspect->IsText3d()
? aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN
: 0.0;
FitTextAlignment (aHorisontalTextPos, aLabelPosition, isArrowsExternal);
Standard_Real anArrowsWidth = (anArrowLength + anArrowMargin) * 2.0;
isArrowsExternal = aDimensionWidth < aLabelWidth + anArrowsWidth;
break;
}
}
gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
//Arrows positions and directions
gp_Vec aWPDir = gp_Vec (GetPlane().Axis().Direction());
@ -670,38 +663,9 @@ void AIS_AngleDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*
aFirstArrowEnd = aFirstAttach.Translated (-aFirstArrowVec);
aSecondArrowEnd = aSecondAttach.Translated (-aSecondArrowVec);
Standard_Integer aLabelPosition = LabelPosition_None;
// Handle user-defined and automatic text placement
switch (aDimensionAspect->TextHorizontalPosition())
{
case Prs3d_DTHP_Left : aLabelPosition |= LabelPosition_Left; break;
case Prs3d_DTHP_Right : aLabelPosition |= LabelPosition_Right; break;
case Prs3d_DTHP_Center: aLabelPosition |= LabelPosition_HCenter; break;
case Prs3d_DTHP_Fit:
{
gp_Vec anAttachVector (aFirstAttach, aSecondAttach);
Standard_Real aDimensionWidth = anAttachVector.Magnitude();
Standard_Real anArrowsWidth = anArrowLength * 2.0;
Standard_Real aContentWidth = isArrowsExternal ? aLabelWidth : aLabelWidth + anArrowsWidth;
aLabelPosition |= aDimensionWidth < aContentWidth ? LabelPosition_Left : LabelPosition_HCenter;
break;
}
}
switch (aDimensionAspect->TextVerticalPosition())
{
case Prs3d_DTVP_Above : aLabelPosition |= LabelPosition_Above; break;
case Prs3d_DTVP_Below : aLabelPosition |= LabelPosition_Below; break;
case Prs3d_DTVP_Center : aLabelPosition |= LabelPosition_VCenter; break;
}
// Group1: stenciling text and the angle dimension arc
Prs3d_Root::NewGroup (thePresentation);
Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
Standard_Integer aHPosition = aLabelPosition & LabelPosition_HMask;
// draw text label
@ -729,7 +693,8 @@ void AIS_AngleDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*
if (theMode == ComputeMode_All || theMode == ComputeMode_Text)
{
gp_Vec aDimensionDir (aFirstAttach, aSecondAttach);
gp_Pnt aTextPos = GetCenterOnArc (aFirstAttach, aSecondAttach, myCenterPoint);
gp_Pnt aTextPos = IsTextPositionCustom() ? myFixedTextPosition
: GetCenterOnArc (aFirstAttach, aSecondAttach, myCenterPoint);
gp_Dir aTextDir = aDimensionDir;
DrawText (thePresentation,
@ -807,7 +772,7 @@ void AIS_AngleDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*
if (aHPosition != LabelPosition_Left)
{
DrawExtension (thePresentation,
anExtensionSize,
aDimensionAspect->ArrowTailSize(),
aFirstArrowEnd,
aFirstExtensionDir,
THE_EMPTY_LABEL_STRING,
@ -819,7 +784,7 @@ void AIS_AngleDimension::Compute (const Handle(PrsMgr_PresentationManager3d)& /*
if (aHPosition != LabelPosition_Right)
{
DrawExtension (thePresentation,
anExtensionSize,
aDimensionAspect->ArrowTailSize(),
aSecondArrowEnd,
aSecondExtensionDir,
THE_EMPTY_LABEL_STRING,
@ -1184,3 +1149,272 @@ Standard_Boolean AIS_AngleDimension::IsValidPoints (const gp_Pnt& theFirstPoint,
&& gp_Vec (theCenterPoint, theFirstPoint).Angle (
gp_Vec (theCenterPoint, theSecondPoint)) > Precision::Angular();
}
//=======================================================================
//function : GetTextPosition
//purpose :
//=======================================================================
const gp_Pnt AIS_AngleDimension::GetTextPosition() const
{
if (!IsValid())
{
return gp::Origin();
}
if (IsTextPositionCustom())
{
return myFixedTextPosition;
}
// Counts text position according to the dimension parameters
gp_Pnt aTextPosition (gp::Origin());
Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
// Prepare label string and compute its geometrical width
Standard_Real aLabelWidth;
TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth);
gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec(myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
// Handle user-defined and automatic arrow placement
Standard_Boolean isArrowsExternal = Standard_False;
Standard_Integer aLabelPosition = LabelPosition_None;
FitTextAlignment (aDimensionAspect->TextHorizontalPosition(),
aLabelPosition, isArrowsExternal);
// Get text position
switch (aLabelPosition & LabelPosition_HMask)
{
case LabelPosition_HCenter:
{
aTextPosition = GetCenterOnArc (aFirstAttach, aSecondAttach, myCenterPoint);
}
break;
case LabelPosition_Left:
{
gp_Dir aPlaneNormal = gp_Vec (aFirstAttach, aSecondAttach) ^ gp_Vec (myCenterPoint, aFirstAttach);
gp_Dir anExtensionDir = aPlaneNormal ^ gp_Vec (myCenterPoint, aFirstAttach);
Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
Standard_Real anOffset = isArrowsExternal
? anExtensionSize + aDimensionAspect->ArrowAspect()->Length()
: anExtensionSize;
gp_Vec anExtensionVec = gp_Vec (anExtensionDir) * -anOffset;
aTextPosition = aFirstAttach.Translated (anExtensionVec);
}
break;
case LabelPosition_Right:
{
gp_Dir aPlaneNormal = gp_Vec (aFirstAttach, aSecondAttach) ^ gp_Vec (myCenterPoint, aFirstAttach);
gp_Dir anExtensionDir = aPlaneNormal ^ gp_Vec (myCenterPoint, aSecondAttach);
Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
Standard_Real anOffset = isArrowsExternal
? anExtensionSize + aDimensionAspect->ArrowAspect()->Length()
: anExtensionSize;
gp_Vec anExtensionVec = gp_Vec (anExtensionDir) * anOffset;
aTextPosition = aSecondAttach.Translated (anExtensionVec);
}
break;
}
return aTextPosition;
}
//=======================================================================
//function : SetTextPosition
//purpose :
//=======================================================================
void AIS_AngleDimension::SetTextPosition (const gp_Pnt& theTextPos)
{
if (!IsValid())
{
return;
}
// The text position point for angle dimension should belong to the working plane.
if (!GetPlane().Contains (theTextPos, Precision::Confusion()))
{
Standard_ProgramError::Raise ("The text position point for angle dimension doesn't belong to the working plane.");
}
myIsTextPositionFixed = Standard_True;
myFixedTextPosition = theTextPos;
}
//=======================================================================
//function : AdjustAspectParameters
//purpose :
//=======================================================================
void AIS_AngleDimension::AdjustParameters (const gp_Pnt& theTextPos,
Standard_Real& theExtensionSize,
Prs3d_DimensionTextHorizontalPosition& theAlignment)
{
Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
Standard_Real anArrowLength = aDimensionAspect->ArrowAspect()->Length();
// Compute flyout direction vector.
gp_Dir aPlaneNormal = GetPlane().Axis().Direction();
gp_Dir aTargetPointsDir = gce_MakeDir (myFirstPoint, mySecondPoint);
// Build circle with radius that is equal to distance from text position to the center point.
Standard_Real aRadius = gp_Vec (myCenterPoint, theTextPos).Magnitude();
// Set attach points in positive direction of the flyout.
gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, myFirstPoint).Normalized() * aRadius);
gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, mySecondPoint).Normalized() * aRadius);
gce_MakeCirc aConstructCircle (myCenterPoint, GetPlane(), aRadius);
if (!aConstructCircle.IsDone())
{
return;
}
gp_Circ aCircle = aConstructCircle.Value();
// Default values
theExtensionSize = aDimensionAspect->ArrowAspect()->Length();
theAlignment = Prs3d_DTHP_Center;
Standard_Real aParamBeg = ElCLib::Parameter (aCircle, aFirstAttach);
Standard_Real aParamEnd = ElCLib::Parameter (aCircle, aSecondAttach);
if (aParamEnd < aParamBeg)
{
Standard_Real aParam = aParamEnd;
aParamEnd = aParamBeg;
aParamBeg = aParam;
}
ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
Standard_Real aTextPar = ElCLib::Parameter (aCircle , theTextPos);
// Horizontal center
if (aTextPar > aParamBeg && aTextPar < aParamEnd)
{
myFlyout = aRadius;
SetToUpdate();
return;
}
aParamBeg += M_PI;
aParamEnd += M_PI;
ElCLib::AdjustPeriodic (0.0, M_PI * 2, Precision::PConfusion(), aParamBeg, aParamEnd);
if (aTextPar > aParamBeg && aTextPar < aParamEnd)
{
myFlyout = -aRadius;
SetToUpdate();
return;
}
// Text on the extensions
gp_Lin aFirstLine = gce_MakeLin (myCenterPoint, myFirstPoint);
gp_Lin aSecondLine = gce_MakeLin (myCenterPoint, mySecondPoint);
gp_Pnt aFirstTextProj = AIS::Nearest (aFirstLine, theTextPos);
gp_Pnt aSecondTextProj = AIS::Nearest (aSecondLine, theTextPos);
Standard_Real aFirstDist = aFirstTextProj.Distance (theTextPos);
Standard_Real aSecondDist = aSecondTextProj.Distance (theTextPos);
if (aFirstDist <= aSecondDist)
{
aRadius = myCenterPoint.Distance (aFirstTextProj);
Standard_Real aNewExtensionSize = aFirstDist - anArrowLength;
theExtensionSize = aNewExtensionSize < 0.0 ? 0.0 : aNewExtensionSize;
theAlignment = Prs3d_DTHP_Left;
gp_Vec aPosFlyoutDir = gp_Vec (myCenterPoint, myFirstPoint).Normalized().Scaled (aRadius);
myFlyout = aFirstTextProj.Distance (myCenterPoint.Translated (aPosFlyoutDir)) > Precision::Confusion()
? -aRadius : aRadius;
}
else
{
aRadius = myCenterPoint.Distance (aSecondTextProj);
Standard_Real aNewExtensionSize = aSecondDist - anArrowLength;
theExtensionSize = aNewExtensionSize < 0.0 ? 0.0 : aNewExtensionSize;
theAlignment = Prs3d_DTHP_Right;
gp_Vec aPosFlyoutDir = gp_Vec (myCenterPoint, mySecondPoint).Normalized().Scaled (aRadius);
myFlyout = aSecondTextProj.Distance (myCenterPoint.Translated (aPosFlyoutDir)) > Precision::Confusion()
? -aRadius : aRadius;
}
}
//=======================================================================
//function : FitTextAlignment
//purpose :
//=======================================================================
void AIS_AngleDimension::FitTextAlignment (const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
Standard_Integer& theLabelPosition,
Standard_Boolean& theIsArrowsExternal) const
{
Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
Quantity_Length anArrowLength = aDimensionAspect->ArrowAspect()->Length();
// Prepare label string and compute its geometrical width
Standard_Real aLabelWidth;
TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth);
// add margins to label width
if (aDimensionAspect->IsText3d())
{
aLabelWidth += aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN * 2.0;
}
gp_Pnt aFirstAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, myFirstPoint).Normalized() * GetFlyout());
gp_Pnt aSecondAttach = myCenterPoint.Translated (gp_Vec (myCenterPoint, mySecondPoint).Normalized() * GetFlyout());
// Handle user-defined and automatic arrow placement
switch (aDimensionAspect->ArrowOrientation())
{
case Prs3d_DAO_External: theIsArrowsExternal = true; break;
case Prs3d_DAO_Internal: theIsArrowsExternal = false; break;
case Prs3d_DAO_Fit:
{
gp_Vec anAttachVector (aFirstAttach, aSecondAttach);
Standard_Real aDimensionWidth = anAttachVector.Magnitude();
// Add margin to ensure a small tail between text and arrow
Standard_Real anArrowMargin = aDimensionAspect->IsText3d()
? aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN
: 0.0;
Standard_Real anArrowsWidth = (anArrowLength + anArrowMargin) * 2.0;
theIsArrowsExternal = aDimensionWidth < aLabelWidth + anArrowsWidth;
break;
}
}
// Handle user-defined and automatic text placement
switch (theHorizontalTextPos)
{
case Prs3d_DTHP_Left : theLabelPosition |= LabelPosition_Left; break;
case Prs3d_DTHP_Right : theLabelPosition |= LabelPosition_Right; break;
case Prs3d_DTHP_Center: theLabelPosition |= LabelPosition_HCenter; break;
case Prs3d_DTHP_Fit:
{
gp_Vec anAttachVector (aFirstAttach, aSecondAttach);
Standard_Real aDimensionWidth = anAttachVector.Magnitude();
Standard_Real anArrowsWidth = anArrowLength * 2.0;
Standard_Real aContentWidth = theIsArrowsExternal ? aLabelWidth : aLabelWidth + anArrowsWidth;
theLabelPosition |= aDimensionWidth < aContentWidth ? LabelPosition_Left : LabelPosition_HCenter;
break;
}
}
switch (aDimensionAspect->TextVerticalPosition())
{
case Prs3d_DTVP_Above : theLabelPosition |= LabelPosition_Above; break;
case Prs3d_DTVP_Below : theLabelPosition |= LabelPosition_Below; break;
case Prs3d_DTVP_Center : theLabelPosition |= LabelPosition_VCenter; break;
}
}

View File

@ -47,8 +47,8 @@ DEFINE_STANDARD_HANDLE (AIS_AngleDimension, AIS_Dimension)
//! as through three defined points can be built only one plane.
//! Therefore, if user-defined plane differs from this one, the dimension can't be built.
//!
//! In cases of two planes automatical plane by default is built on point of the
//! origin of parametrical space of the first face (the basis surface) so, that
//! In cases of two planes automatic plane by default is built on point of the
//! origin of parametric space of the first face (the basis surface) so, that
//! the working plane and two faces intersection forms minimal angle between the faces.
//! User can define the other point which the dimension plane should pass through
//! using the appropriate constructor. This point can lay on the one of the faces or not.
@ -188,15 +188,25 @@ public:
const gp_Pnt& thePoint);
//! @return the display units string.
Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits () const;
Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const;
//! @return the model units string.
Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits () const;
Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const;
Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits);
Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits);
//! Principle of horizontal text alignment settings:
//! - divide circle into two halves according to attachment points
//! - if aTextPos is between attach points -> Center + positive flyout
//! - if aTextPos is not between attach points but in this half -> Left or Right + positive flyout
//! - if aTextPos is between reflections of attach points -> Center + negative flyout
//! - if aTextPos is not between reflections of attach points -> Left or Right + negative flyout
Standard_EXPORT virtual void SetTextPosition (const gp_Pnt& theTextPos);
Standard_EXPORT virtual const gp_Pnt GetTextPosition () const;
public:
DEFINE_STANDARD_RTTI (AIS_AngleDimension)
@ -212,7 +222,7 @@ protected:
//! @return the center of the dimension arc (the main dimension line in case of angle).
Standard_EXPORT gp_Pnt GetCenterOnArc (const gp_Pnt& theFirstAttach,
const gp_Pnt& theSecondAttach,
const gp_Pnt& theCenter);
const gp_Pnt& theCenter) const;
//! Draws main dimension line (arc).
//! @param thePresentation [in] the dimension presentation.
@ -247,6 +257,29 @@ protected:
const Standard_Integer theMode,
const Standard_Integer theLabelPosition);
//! Fits text alignment relatively to the dimension line;
//! it computes the value of label position and arrow orientation
//! according set in the aspect and dimension properties.
//! @param theHorizontalTextPos [in] the horizontal alignment for text position.
//! @param theLabelPosition [out] the label position, contains bits that defines
//! vertical and horizontal alignment. (for internal usage in count text position).
//! @param theIsArrowExternal [out] is the arrows external,
//! if arrow orientation in the dimension aspect is Prs3d_DAO_Fit, it fits arrow
//! orientation automatically.
Standard_EXPORT void FitTextAlignment (const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
Standard_Integer& theLabelPosition,
Standard_Boolean& theIsArrowsExternal) const;
//! Adjusts aspect parameters according the text position:
//! extension size, vertical text alignment and flyout.
//! It changes flyout of the dimension.
//! @param theTextPos [in] the user defined 3d point of text position.
//! @param theExtensionSize [out] the adjusted extension size.
//! @param theAlignment [out] the horizontal label alignment.
Standard_EXPORT void AdjustParameters (const gp_Pnt& theTextPos,
Standard_Real& theExtensionSize,
Prs3d_DimensionTextHorizontalPosition& theAlignment);
protected:
Standard_EXPORT virtual void ComputePlane();

View File

@ -296,7 +296,7 @@ void AIS_DiameterDimension::Compute (const Handle(PrsMgr_PresentationManager3d)&
gp_Pnt aFirstPnt (gp::Origin());
gp_Pnt aSecondPnt (gp::Origin());
ComputeSidePoints (myCircle, GetPlane(), aFirstPnt, aSecondPnt);
ComputeSidePoints (myCircle, aFirstPnt, aSecondPnt);
DrawLinearDimension (thePresentation, theMode, aFirstPnt, aSecondPnt);
}
@ -315,7 +315,7 @@ void AIS_DiameterDimension::ComputeFlyoutSelection (const Handle(SelectMgr_Selec
gp_Pnt aFirstPnt (gp::Origin());
gp_Pnt aSecondPnt (gp::Origin());
ComputeSidePoints (myCircle, GetPlane(), aFirstPnt, aSecondPnt);
ComputeSidePoints (myCircle, aFirstPnt, aSecondPnt);
ComputeLinearFlyouts (theSelection, theEntityOwner, aFirstPnt, aSecondPnt);
}
@ -324,15 +324,14 @@ void AIS_DiameterDimension::ComputeFlyoutSelection (const Handle(SelectMgr_Selec
//function : ComputeSidePoints
//purpose :
//=======================================================================
void AIS_DiameterDimension::ComputeSidePoints (const gp_Circ& /*theCircle*/,
const gp_Pln& /*thePlane*/,
void AIS_DiameterDimension::ComputeSidePoints (const gp_Circ& theCircle,
gp_Pnt& theFirstPnt,
gp_Pnt& theSecondPnt)
{
theFirstPnt = AnchorPoint();
gp_Vec aRadiusVector (myCircle.Location(), theFirstPnt);
theSecondPnt = myCircle.Location().Translated (-aRadiusVector);
gp_Vec aRadiusVector (theCircle.Location(), theFirstPnt);
theSecondPnt = theCircle.Location().Translated (-aRadiusVector);
}
//=======================================================================
@ -358,3 +357,35 @@ Standard_Boolean AIS_DiameterDimension::IsValidAnchor (const gp_Circ& theCircle,
return Abs (anAnchorDist - aRadius) > Precision::Confusion()
&& aCirclePlane.Contains (theAnchor, Precision::Confusion());
}
//=======================================================================
//function : GetTextPosition
//purpose :
//=======================================================================
const gp_Pnt AIS_DiameterDimension::GetTextPosition() const
{
if (IsTextPositionCustom())
{
return myFixedTextPosition;
}
// Counts text position according to the dimension parameters
return GetTextPositionForLinear (myAnchorPoint, myCircle.Location());
}
//=======================================================================
//function : GetTextPosition
//purpose :
//=======================================================================
void AIS_DiameterDimension::SetTextPosition (const gp_Pnt& theTextPos)
{
if (!myIsValid)
{
return;
}
myIsTextPositionFixed = Standard_True;
myFixedTextPosition = theTextPos;
SetToUpdate();
}

View File

@ -114,15 +114,19 @@ public:
Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Shape& theShape);
//! @return the display units string.
Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits () const;
Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const;
//! @return the model units string.
Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits () const;
Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const;
Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits);
Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits);
Standard_EXPORT virtual void SetTextPosition (const gp_Pnt& theTextPos);
Standard_EXPORT virtual const gp_Pnt GetTextPosition() const;
public:
DEFINE_STANDARD_RTTI(AIS_DiameterDimension)
@ -154,16 +158,14 @@ protected:
protected:
//! Compute points on the circle sides for the specified dimension plane.
//! Compute points on the circle sides for the dimension plane.
//! Program error exception is raised if the dimension plane "x" direction
//! is orthogonal to plane (the "impossible" case). The passed dimension plane
//! is the one specially computed to locate dimension presentation in circle.
//! @param theCircle [in] the circle.
//! @param thePlane [in] the dimension presentation plane computed.
//! @param theFirstPnt [out] the first point.
//! @param theSecondPnt [out] the second point.
Standard_EXPORT void ComputeSidePoints (const gp_Circ& theCircle,
const gp_Pln& thePlane,
gp_Pnt& theFirstPnt,
gp_Pnt& theSecondPnt);

View File

@ -25,11 +25,13 @@
#include <ElCLib.hxx>
#include <Font_BRepFont.hxx>
#include <GC_MakeCircle.hxx>
#include <Geom_Line.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <Geom_Circle.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <gce_MakeDir.hxx>
#include <gce_MakeLin.hxx>
#include <gce_MakePln.hxx>
#include <Graphic3d_ArrayOfSegments.hxx>
#include <Graphic3d_ArrayOfTriangles.hxx>
#include <Graphic3d_AspectLine3d.hxx>
@ -59,6 +61,7 @@
#include <Poly_Array1OfTriangle.hxx>
#include <Poly_Triangulation.hxx>
#include <Standard_CString.hxx>
#include <Standard_ProgramError.hxx>
#include <StdPrs_ShadedShape.hxx>
#include <StdPrs_WFShape.hxx>
#include <TCollection_AsciiString.hxx>
@ -70,7 +73,6 @@
#include <Units_UnitsDictionary.hxx>
#include <UnitsAPI.hxx>
#include <UnitsAPI_SystemUnits.hxx>
#include <Standard_ProgramError.hxx>
IMPLEMENT_STANDARD_HANDLE(AIS_Dimension, AIS_InteractiveObject)
IMPLEMENT_STANDARD_RTTIEXT(AIS_Dimension, AIS_InteractiveObject)
@ -154,6 +156,9 @@ void AIS_Dimension::SetCustomPlane (const gp_Pln& thePlane)
myPlane = thePlane;
myIsPlaneCustom = Standard_True;
// Disable fixed text position
UnsetFixedTextPosition();
// Check validity if geometry has been set already.
if (myIsValid)
{
@ -234,6 +239,9 @@ void AIS_Dimension::SetFlyout (const Standard_Real theFlyout)
myFlyout = theFlyout;
// Disable fixed text position
UnsetFixedTextPosition();
SetToUpdate();
}
@ -620,25 +628,8 @@ void AIS_Dimension::DrawLinearDimension (const Handle(Prs3d_Presentation)& thePr
Standard_ProgramError::Raise ("Can not build presentation for equal points.");
}
// compute dimension line points
gp_Ax1 aPlaneNormal = GetPlane().Axis();
gp_Dir aTargetPointsVector = gce_MakeDir (theFirstPoint, theSecondPoint);
// compute flyout direction vector
gp_Dir aFlyoutVector = aPlaneNormal.Direction() ^ aTargetPointsVector;
// create lines for layouts
gp_Lin aLine1 (theFirstPoint, aFlyoutVector);
gp_Lin aLine2 (theSecondPoint, aFlyoutVector);
// Get flyout end points
gp_Pnt aLineBegPoint = ElCLib::Value (ElCLib::Parameter (aLine1, theFirstPoint) + GetFlyout(), aLine1);
gp_Pnt aLineEndPoint = ElCLib::Value (ElCLib::Parameter (aLine2, theSecondPoint) + GetFlyout(), aLine2);
Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
gp_Lin aDimensionLine = gce_MakeLin (aLineBegPoint, aLineEndPoint);
// For extensions we need to know arrow size, text size and extension size: get it from aspect
Quantity_Length anArrowLength = aDimensionAspect->ArrowAspect()->Length();
Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
@ -653,28 +644,37 @@ void AIS_Dimension::DrawLinearDimension (const Handle(Prs3d_Presentation)& thePr
}
// handle user-defined and automatic arrow placement
bool isArrowsExternal = false;
switch (aDimensionAspect->ArrowOrientation())
Standard_Boolean isArrowsExternal = Standard_False;
Standard_Integer aLabelPosition = LabelPosition_None;
Prs3d_DimensionTextHorizontalPosition aHorisontalTextPos = aDimensionAspect->TextHorizontalPosition();
if (IsTextPositionCustom())
{
case Prs3d_DAO_External: isArrowsExternal = true; break;
case Prs3d_DAO_Internal: isArrowsExternal = false; break;
case Prs3d_DAO_Fit:
{
// add margin to ensure a small tail between text and arrow
Standard_Real anArrowMargin = aDimensionAspect->IsText3d()
? aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN
: 0.0;
AdjustParametersForLinear (myFixedTextPosition, theFirstPoint, theSecondPoint,
anExtensionSize, aHorisontalTextPos);
Standard_Real aDimensionWidth = aLineBegPoint.Distance (aLineEndPoint);
Standard_Real anArrowsWidth = theIsOneSide
? anArrowLength + anArrowMargin
: (anArrowLength + anArrowMargin) * 2.0;
isArrowsExternal = aDimensionWidth < aLabelWidth + anArrowsWidth;
break;
}
}
FitTextAlignmentForLinear (theFirstPoint, theSecondPoint, theIsOneSide, aHorisontalTextPos,
aLabelPosition, isArrowsExternal);
// compute dimension line points
gp_Ax1 aPlaneNormal = GetPlane().Axis();
gp_Dir aTargetPointsVector = gce_MakeDir (theFirstPoint, theSecondPoint);
// compute flyout direction vector
gp_Dir aFlyoutVector = aPlaneNormal.Direction() ^ aTargetPointsVector;
// create lines for layouts
gp_Lin aLine1 (theFirstPoint, aFlyoutVector);
gp_Lin aLine2 (theSecondPoint, aFlyoutVector);
// Get flyout end points
gp_Pnt aLineBegPoint = ElCLib::Value (ElCLib::Parameter (aLine1, theFirstPoint) + GetFlyout(), aLine1);
gp_Pnt aLineEndPoint = ElCLib::Value (ElCLib::Parameter (aLine2, theSecondPoint) + GetFlyout(), aLine2);
gp_Lin aDimensionLine = gce_MakeLin (aLineBegPoint, aLineEndPoint);
// compute arrows positions and directions
gp_Dir aFirstArrowDir = aDimensionLine.Direction().Reversed();
gp_Dir aSecondArrowDir = aDimensionLine.Direction();
@ -703,32 +703,6 @@ void AIS_Dimension::DrawLinearDimension (const Handle(Prs3d_Presentation)& thePr
gp_Pnt aCenterLineEnd = isArrowsExternal || theIsOneSide
? aLineEndPoint : aSecondArrowEnd;
Standard_Integer aLabelPosition = LabelPosition_None;
// handle user-defined and automatic text placement
switch (aDimensionAspect->TextHorizontalPosition())
{
case Prs3d_DTHP_Left : aLabelPosition |= LabelPosition_Left; break;
case Prs3d_DTHP_Right : aLabelPosition |= LabelPosition_Right; break;
case Prs3d_DTHP_Center: aLabelPosition |= LabelPosition_HCenter; break;
case Prs3d_DTHP_Fit:
{
Standard_Real aDimensionWidth = aLineBegPoint.Distance (aLineEndPoint);
Standard_Real anArrowsWidth = theIsOneSide ? anArrowLength : 2.0 * anArrowLength;
Standard_Real aContentWidth = isArrowsExternal ? aLabelWidth : aLabelWidth + anArrowsWidth;
aLabelPosition |= aDimensionWidth < aContentWidth ? LabelPosition_Left : LabelPosition_HCenter;
break;
}
}
// handle vertical text placement options
switch (aDimensionAspect->TextVerticalPosition())
{
case Prs3d_DTVP_Above : aLabelPosition |= LabelPosition_Above; break;
case Prs3d_DTVP_Below : aLabelPosition |= LabelPosition_Below; break;
case Prs3d_DTVP_Center : aLabelPosition |= LabelPosition_VCenter; break;
}
switch (aLabelPosition & LabelPosition_HMask)
{
@ -740,7 +714,8 @@ void AIS_Dimension::DrawLinearDimension (const Handle(Prs3d_Presentation)& thePr
// add label on dimension or extension line to presentation
Prs3d_Root::NewGroup (thePresentation);
gp_Pnt aTextPos = (aCenterLineBegin.XYZ() + aCenterLineEnd.XYZ()) * 0.5;
gp_Pnt aTextPos = IsTextPositionCustom() ? myFixedTextPosition
: (aCenterLineBegin.XYZ() + aCenterLineEnd.XYZ()) * 0.5;
gp_Dir aTextDir = aDimensionLine.Direction();
// add text primitives
@ -831,12 +806,12 @@ void AIS_Dimension::DrawLinearDimension (const Handle(Prs3d_Presentation)& thePr
// add arrow extension lines to presentation
Prs3d_Root::NewGroup (thePresentation);
DrawExtension (thePresentation, anExtensionSize,
DrawExtension (thePresentation, aDimensionAspect->ArrowTailSize(),
aFirstArrowEnd, aFirstExtensionDir,
THE_EMPTY_LABEL, 0.0, theMode, LabelPosition_None);
if (!theIsOneSide)
{
DrawExtension (thePresentation, anExtensionSize,
DrawExtension (thePresentation, aDimensionAspect->ArrowTailSize(),
aSecondArrowEnd, aSecondExtensionDir,
THE_EMPTY_LABEL, 0.0, theMode, LabelPosition_None);
}
@ -900,7 +875,7 @@ void AIS_Dimension::DrawLinearDimension (const Handle(Prs3d_Presentation)& thePr
// add extension lines for external arrows
Prs3d_Root::NewGroup (thePresentation);
DrawExtension (thePresentation, anExtensionSize,
DrawExtension (thePresentation, aDimensionAspect->ArrowTailSize(),
aSecondArrowEnd, aSecondExtensionDir,
THE_EMPTY_LABEL, 0.0, theMode, LabelPosition_None);
}
@ -960,7 +935,7 @@ void AIS_Dimension::DrawLinearDimension (const Handle(Prs3d_Presentation)& thePr
// add extension lines for external arrows
Prs3d_Root::NewGroup (thePresentation);
DrawExtension (thePresentation, anExtensionSize,
DrawExtension (thePresentation, aDimensionAspect->ArrowTailSize(),
aFirstArrowEnd, aFirstExtensionDir,
THE_EMPTY_LABEL, 0.0, theMode, LabelPosition_None);
}
@ -1366,3 +1341,247 @@ void AIS_Dimension::PointsForArrow (const gp_Pnt& thePeakPnt,
theSidePnt1 = ElCLib::Value ( anEdgeLength, anEdgeLin);
theSidePnt2 = ElCLib::Value (-anEdgeLength, anEdgeLin);
}
//=======================================================================
//function : GetTextPositionForLinear
//purpose :
//=======================================================================
gp_Pnt AIS_Dimension::GetTextPositionForLinear (const gp_Pnt& theFirstPoint,
const gp_Pnt& theSecondPoint,
const Standard_Boolean theIsOneSide) const
{
if (!myIsValid)
{
return gp::Origin();
}
gp_Pnt aTextPosition (gp::Origin());
Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
// Get label alignment and arrow orientation.
Standard_Integer aLabelPosition = 0;
Standard_Boolean isArrowsExternal = Standard_False;
FitTextAlignmentForLinear (theFirstPoint, theSecondPoint, theIsOneSide,
aDimensionAspect->TextHorizontalPosition(),
aLabelPosition, isArrowsExternal);
// Compute dimension line points.
gp_Dir aPlaneNormal = GetPlane().Axis().Direction();
gp_Vec aTargetPointsVec (theFirstPoint, theSecondPoint);
// Compute flyout direction vector
gp_Dir aFlyoutVector = aPlaneNormal ^ gp_Dir (aTargetPointsVec);
// create lines for layouts
gp_Lin aLine1 (theFirstPoint, aFlyoutVector);
gp_Lin aLine2 (theSecondPoint, aFlyoutVector);
// Get flyout end points
gp_Pnt aLineBegPoint = ElCLib::Value (ElCLib::Parameter (aLine1, theFirstPoint) + GetFlyout(), aLine1);
gp_Pnt aLineEndPoint = ElCLib::Value (ElCLib::Parameter (aLine2, theSecondPoint) + GetFlyout(), aLine2);
// Get text position.
switch (aLabelPosition & LabelPosition_HMask)
{
case LabelPosition_Left:
{
gp_Dir aTargetPointsDir = gce_MakeDir (theFirstPoint, theSecondPoint);
Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
Standard_Real anOffset = isArrowsExternal
? anExtensionSize + aDimensionAspect->ArrowAspect()->Length()
: anExtensionSize;
gp_Vec anExtensionVec = gp_Vec (aTargetPointsDir) * -anOffset;
aTextPosition = aLineEndPoint.Translated (anExtensionVec);
}
break;
case LabelPosition_Right:
{
gp_Dir aTargetPointsDir = gce_MakeDir (theFirstPoint, theSecondPoint);
Standard_Real anExtensionSize = aDimensionAspect->ExtensionSize();
Standard_Real anOffset = isArrowsExternal
? anExtensionSize + aDimensionAspect->ArrowAspect()->Length()
: anExtensionSize;
gp_Vec anExtensionVec = gp_Vec (aTargetPointsDir) * anOffset;
aTextPosition = aLineBegPoint.Translated (anExtensionVec);
}
break;
case LabelPosition_HCenter:
{
aTextPosition = (aLineBegPoint.XYZ() + aLineEndPoint.XYZ()) * 0.5;
}
break;
}
return aTextPosition;
}
//=======================================================================
//function : AdjustAspectParameters
//purpose :
//=======================================================================
void AIS_Dimension::AdjustParametersForLinear (const gp_Pnt& theTextPos,
const gp_Pnt& theFirstPoint,
const gp_Pnt& theSecondPoint,
Standard_Real& theExtensionSize,
Prs3d_DimensionTextHorizontalPosition& theAlignment)
{
Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
Standard_Real anArrowLength = aDimensionAspect->ArrowAspect()->Length();
//Set new automatic plane.
myPlane = gce_MakePln (theTextPos, theFirstPoint, theSecondPoint);
myIsPlaneCustom = Standard_False;
// Compute dimension line points.
gp_Dir aPlaneNormal = GetPlane().Axis().Direction();
gp_Dir aTargetPointsDir = gce_MakeDir (theFirstPoint, theSecondPoint);
gp_Vec aTargetPointsVec (theFirstPoint, theSecondPoint);
// Compute flyout direction vector.
gp_Dir aPositiveFlyout = aPlaneNormal ^ aTargetPointsDir;
// Set flyout.
gp_Vec aFirstToTextVec (theFirstPoint, theTextPos);
Standard_Real aCos = aFirstToTextVec.Normalized() * gp_Vec (aTargetPointsDir);
gp_Pnt aTextPosProj = theFirstPoint.Translated
(gp_Vec (aTargetPointsDir) * aFirstToTextVec.Magnitude() * aCos);
// Compute flyout value and direction.
gp_Vec aFlyoutVector = gp_Vec (aTextPosProj, theTextPos);
myFlyout = gp_Dir (aFlyoutVector).IsOpposite (aPositiveFlyout, Precision::Angular())
? -aFlyoutVector.Magnitude()
: aFlyoutVector.Magnitude();
// Compute attach points (through which main dimension line passes).
gp_Pnt aFirstAttach = theFirstPoint.Translated (aFlyoutVector);
gp_Pnt aSecondAttach = theSecondPoint.Translated (aFlyoutVector);
// Set horisontal text alignment.
if (aCos < 0.0)
{
theAlignment = Prs3d_DTHP_Left;
Standard_Real aNewExtSize = theTextPos.Distance (aFirstAttach) - anArrowLength;
theExtensionSize = aNewExtSize < 0.0 ? 0.0 : aNewExtSize;
}
else if (aTextPosProj.Distance (theFirstPoint) > theFirstPoint.Distance (theSecondPoint))
{
theAlignment = Prs3d_DTHP_Right;
Standard_Real aNewExtSize = theTextPos.Distance (aSecondAttach) - anArrowLength;
theExtensionSize = aNewExtSize < 0.0 ? 0.0 : aNewExtSize;
}
else
{
theAlignment = Prs3d_DTHP_Center;
}
}
//=======================================================================
//function : FitTextAlignmentForLinear
//purpose :
//=======================================================================
void AIS_Dimension::FitTextAlignmentForLinear (const gp_Pnt& theFirstPoint,
const gp_Pnt& theSecondPoint,
const Standard_Boolean theIsOneSide,
const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
Standard_Integer& theLabelPosition,
Standard_Boolean& theIsArrowsExternal) const
{
theLabelPosition = LabelPosition_None;
theIsArrowsExternal = Standard_False;
// Compute dimension line points
gp_Ax1 aPlaneNormal = GetPlane().Axis();
gp_Dir aTargetPointsVector = gce_MakeDir (theFirstPoint, theSecondPoint);
// compute flyout direction vector
gp_Dir aFlyoutVector = aPlaneNormal.Direction() ^ aTargetPointsVector;
// create lines for layouts
gp_Lin aLine1 (theFirstPoint, aFlyoutVector);
gp_Lin aLine2 (theSecondPoint, aFlyoutVector);
// Get flyout end points
gp_Pnt aLineBegPoint = ElCLib::Value (ElCLib::Parameter (aLine1, theFirstPoint) + GetFlyout(), aLine1);
gp_Pnt aLineEndPoint = ElCLib::Value (ElCLib::Parameter (aLine2, theSecondPoint) + GetFlyout(), aLine2);
Handle(Prs3d_DimensionAspect) aDimensionAspect = myDrawer->DimensionAspect();
gp_Lin aDimensionLine = gce_MakeLin (aLineBegPoint, aLineEndPoint);
// For extensions we need to know arrow size, text size and extension size: get it from aspect
Quantity_Length anArrowLength = aDimensionAspect->ArrowAspect()->Length();
// prepare label string and compute its geometrical width
Standard_Real aLabelWidth;
TCollection_ExtendedString aLabelString = GetValueString (aLabelWidth);
// Add margins to cut dimension lines for 3d text
if (aDimensionAspect->IsText3d())
{
aLabelWidth += aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN * 2.0;
}
// Handle user-defined and automatic arrow placement
switch (aDimensionAspect->ArrowOrientation())
{
case Prs3d_DAO_External: theIsArrowsExternal = true; break;
case Prs3d_DAO_Internal: theIsArrowsExternal = false; break;
case Prs3d_DAO_Fit:
{
// Add margin to ensure a small tail between text and arrow
Standard_Real anArrowMargin = aDimensionAspect->IsText3d()
? aDimensionAspect->TextAspect()->Height() * THE_3D_TEXT_MARGIN
: 0.0;
Standard_Real aDimensionWidth = aLineBegPoint.Distance (aLineEndPoint);
Standard_Real anArrowsWidth = theIsOneSide
? anArrowLength + anArrowMargin
: (anArrowLength + anArrowMargin) * 2.0;
theIsArrowsExternal = aDimensionWidth < aLabelWidth + anArrowsWidth;
break;
}
}
// Handle user-defined and automatic text placement
switch (theHorizontalTextPos)
{
case Prs3d_DTHP_Left : theLabelPosition |= LabelPosition_Left; break;
case Prs3d_DTHP_Right : theLabelPosition |= LabelPosition_Right; break;
case Prs3d_DTHP_Center: theLabelPosition |= LabelPosition_HCenter; break;
case Prs3d_DTHP_Fit:
{
Standard_Real aDimensionWidth = aLineBegPoint.Distance (aLineEndPoint);
Standard_Real anArrowsWidth = theIsOneSide ? anArrowLength : 2.0 * anArrowLength;
Standard_Real aContentWidth = theIsArrowsExternal ? aLabelWidth : aLabelWidth + anArrowsWidth;
theLabelPosition |= aDimensionWidth < aContentWidth ? LabelPosition_Left : LabelPosition_HCenter;
break;
}
}
// Handle vertical text placement options
switch (aDimensionAspect->TextVerticalPosition())
{
case Prs3d_DTVP_Above : theLabelPosition |= LabelPosition_Above; break;
case Prs3d_DTVP_Below : theLabelPosition |= LabelPosition_Below; break;
case Prs3d_DTVP_Center : theLabelPosition |= LabelPosition_VCenter; break;
}
}
//=======================================================================
//function : UnsetFixedTextPosition
//purpose :
//=======================================================================
void AIS_Dimension::UnsetFixedTextPosition()
{
myIsTextPositionFixed = Standard_False;
myFixedTextPosition = gp::Origin();
}

View File

@ -56,11 +56,11 @@ DEFINE_STANDARD_HANDLE(AIS_Dimension, AIS_InteractiveObject)
//! The specified by user units are stored in the dimension's drawer.
//!
//! As a drawing, the dimension is composed from the following components:
//! - Attachement (binding) points. The points where the dimension lines attaches to, for
//! - Attachment (binding) points. The points where the dimension lines attaches to, for
//! length dimensions the distances are measured between these points.
//! - Main dimension line. The which extends from the attachement points in "up" direction,
//! - Main dimension line. The which extends from the attachment points in "up" direction,
//! and which contains text label on it with value string.
//! - Flyouts. The lines connecting the attachement points with main dimension line.
//! - Flyouts. The lines connecting the attachment points with main dimension line.
//! - Extension. The lines used to extend the main dimension line in the cases when text
//! or arrows do not fit into the main dimension line due to their size.
//! - Arrows.
@ -75,7 +75,7 @@ DEFINE_STANDARD_HANDLE(AIS_Dimension, AIS_InteractiveObject)
//! |flyout flyout|
//! | |
//! +-----------------------------------+
//! attachement attachement
//! attachment attachment
//! point point
//!
//! Angular dimensions:
@ -130,19 +130,46 @@ DEFINE_STANDARD_HANDLE(AIS_Dimension, AIS_InteractiveObject)
//!
//! The dimension support two local selection modes: main dimension line selection and text label
//! selection. These modes can be used to develop interactive modification of dimension presentations.
//! The component hilighting in these selection modes is provided by AIS_DimensionOwner class.
//! The component highlighting in these selection modes is provided by AIS_DimensionOwner class.
//! Please note that selection is unavailable until the presentation is computed.
//!
//! The specific drawing attributes are controlled through Prs3d_DimensionAspect. The one can change
//! color, arrows, text and arrow style and specify positioning of value label by setting corresponding
//! values to the aspect.
//!
//! Such set of parameters that consists of:
//! - flyout size and direction,
//! - user-defined dimension plane,
//! - horizontal and vertical text alignment
//! can be uniquely replaced with text position in 3d space. Therefore, there are methods to convert
//! this set of parameters to the text position and vice versa:
//!
//! - If the fixed text position is defined by user, called SetTextPosition (theTextPos) method converts
//! this 3d point to the set of parameters including adjusting of the dimension plane (this plane will be
//! automatic plane, NOT user-defined one).
//! If the fixed text position is set, the flag myIsFixedTextPosition is set to TRUE.
//! ATTENSION! myIsFixedTextPosition fixes all parameters of the set from recomputing inside
//! SetMeasureGeometry() methods. Parameters in dimension aspect (they are horizontal text position
//! and extension size) are adjusted on presentation computing step, user-defined values in
//! dimension aspect are not changed.
//! But plane and flyout as dimension position parameters are changed by SetTextPosition() method
//! according with user-defined text position.
//! If parameters from the set are changed by user with calls of setters, it leads to disabling of
//! fixed text position (myIsFixedTextPosition is set to FALSE).
//! If the fixed text position is set and geometry is changed by user (SetMeasureGeometry() method
//! is called) and the geometry doesn't satisfy computed dimension plane, the dimension is not valid.
//!
//! - If the set of parameters was set by user (may be without the user-defined plane or with it),
//! it can be converted to the text position by calling the method GetTextPosition(). In this case
//! the text position is NOT fixed, and SetMeasureGeometry() without user-defined plane adjusts
//! the automatic plane according input geometry (if it is possible).
//!
class AIS_Dimension : public AIS_InteractiveObject
{
protected:
//! Geometry type defines type of shapes on which the dimension is to be built.
//! Some type of geometry allows automatical plane computing and
//! Some type of geometry allows automatic plane computing and
//! can be built without user-defined plane
//! Another types can't be built without user-defined plane.
enum GeometryType
@ -212,8 +239,8 @@ public:
//! By default, if plane is not defined by user, it is computed automatically
//! after dimension geometry is computed.
//! If computed dimension geometry (points) can't be placed on the user-defined
//! plane, dimension geometry was set as unvalid (validity flag is set to false)
//! and dimension presentation wil not be computed.
//! plane, dimension geometry was set as invalid (validity flag is set to false)
//! and dimension presentation will not be computed.
//! If user-defined plane allow geometry placement on it, it will be used for
//! computing of the dimension presentation.
//! @return dimension plane used for presentation computing.
@ -233,6 +260,22 @@ public:
//! computed automatically.
Standard_EXPORT void UnsetCustomPlane() { myIsPlaneCustom = Standard_False; }
//! @return TRUE if text position is set by user with method SetTextPosition().
Standard_Boolean IsTextPositionCustom() const
{
return myIsTextPositionFixed;
}
//! Fixes the absolute text position and adjusts flyout, plane and text alignment
//! according to it. Updates presentation if the text position is valid.
//! ATTENTION! It does not change vertical text alignment.
//! @param theTextPos [in] the point of text position.
virtual void SetTextPosition (const gp_Pnt& /*theTextPos*/) { }
//! Computes absolute text position from dimension parameters
//! (flyout, plane and text alignment).
virtual const gp_Pnt GetTextPosition () const { return gp_Pnt(); }
public:
//! Gets the dimension aspect from AIS object drawer.
@ -256,7 +299,7 @@ public:
//! @return the kind of interactive.
virtual AIS_KindOfInteractive Type() const
{
return AIS_KOI_Relation;
return AIS_KOI_Dimension;
}
//! Returns true if the class of objects accepts the display mode theMode.
@ -295,6 +338,10 @@ public:
Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& /*theUnits*/) { }
//! Unsets user defined text positioning and enables text positioning
//! by other parameters: text alignment, extension size, flyout and custom plane.
Standard_EXPORT void UnsetFixedTextPosition();
public:
//! Returns selection tolerance for text2d:
@ -321,7 +368,7 @@ public:
Standard_EXPORT void SetFlyout (const Standard_Real theFlyout);
//! Check that the input geometry for dimension is valid and the
//! presentation can be succesfully computed.
//! presentation can be successfully computed.
//! @return TRUE if dimension geometry is ok.
Standard_Boolean IsValid() const
{
@ -426,6 +473,59 @@ protected:
gp_Circ& theCircle,
gp_Pnt& theMiddleArcPoint,
Standard_Boolean& theIsClosed);
//! Produce points for triangular arrow face.
//! @param thePeakPnt [in] the arrow peak position.
//! @param theDirection [in] the arrow direction.
//! @param thePlane [in] the face plane.
//! @param theArrowLength [in] the length of arrow.
//! @param theArrowAngle [in] the angle of arrow.
//! @param theSidePnt1 [out] the first side point.
//! @param theSidePnt2 [out] the second side point.
Standard_EXPORT void PointsForArrow (const gp_Pnt& thePeakPnt,
const gp_Dir& theDirection,
const gp_Dir& thePlane,
const Standard_Real theArrowLength,
const Standard_Real theArrowAngle,
gp_Pnt& theSidePnt1,
gp_Pnt& theSidePnt2);
//! Compute point of text position for dimension parameters
//! for linear kinds of dimensions (length, radius, diameter).
Standard_EXPORT gp_Pnt GetTextPositionForLinear (const gp_Pnt& theFirstPoint,
const gp_Pnt& theSecondPoint,
const Standard_Boolean theIsOneSide = Standard_False) const;
//! Fits text alignment relatively to the dimension line.
//! @param theFirstPoint [in] the first attachment point.
//! @param theSecondPoint [in] the second attachment point.
//! @param theIsOneSide [in] is the arrow displayed only on the one side of the dimension.
//! @param theHorizontalTextPos [in] the text horizontal position (alignment).
//! @param theLabelPosition [out] the label position, contains bits that defines
//! vertical and horizontal alignment. (for internal usage in count text position)
//! @param theIsArrowExternal [out] is the arrows external,
//! if arrow orientation in the dimension aspect is Prs3d_DAO_Fit, it fits arrow
//! orientation automatically.
void FitTextAlignmentForLinear (const gp_Pnt& theFirstPoint,
const gp_Pnt& theSecondPoint,
const Standard_Boolean theIsOneSide,
const Prs3d_DimensionTextHorizontalPosition& theHorizontalTextPos,
Standard_Integer& theLabelPosition,
Standard_Boolean& theIsArrowsExternal) const;
//! Adjusts aspect parameters according the text position:
//! extension size, vertical text alignment and flyout.
//! It changes working plane and flyout of linear dimension.
//! @param theTextPos [in] the user defined 3d point of text position
//! @param theFirstPoint [in] the first point of linear measurement.
//! @param theSecondPoint [in] the second point of linear measurement.
//! @param theExtensionSize [out] the adjusted extension size
//! @param theAlignment [out] the horizontal label alignment.
void AdjustParametersForLinear (const gp_Pnt& theTextPos,
const gp_Pnt& theFirstPoint,
const gp_Pnt& theSecondPoint,
Standard_Real& theExtensionSize,
Prs3d_DimensionTextHorizontalPosition& theAlignment);
protected: //! @name Behavior to implement
@ -455,22 +555,6 @@ protected: //! @name Behavior to implement
virtual void ComputeFlyoutSelection (const Handle(SelectMgr_Selection)&,
const Handle(SelectMgr_EntityOwner)&) {}
//! Produce points for triangular arrow face.
//! @param thePeakPnt [in] the arrow peak position.
//! @param theDirection [in] the arrow direction.
//! @param thePlane [in] the face plane.
//! @param theArrowLength [in] the length of arrow.
//! @param theArrowAngle [in] the angle of arrow.
//! @param thePeakPnt [in] the arrow peak point.
//! @param theSidePnt1 [in] the first side point.
//! @param theSidePnt2 [in] the second side point.
Standard_EXPORT void PointsForArrow (const gp_Pnt& thePeakPnt,
const gp_Dir& theDirection,
const gp_Dir& thePlane,
const Standard_Real theArrowLength,
const Standard_Real theArrowAngle,
gp_Pnt& theSidePnt1,
gp_Pnt& theSidePnt2);
//! Base procedure of computing selection (based on selection geometry data).
//! @param theSelection [in] the selection structure to will with primitives.
@ -525,7 +609,7 @@ protected: //! @name Selection geometry
}
}
//! Add new curve entry and return the referenece to populate it.
//! Add new curve entry and return the reference to populate it.
Curve& NewCurve()
{
DimensionLine.Append( new Curve );
@ -533,7 +617,7 @@ protected: //! @name Selection geometry
return *aLastCurve;
}
//! Add new arrow entry and return the referenece to populate it.
//! Add new arrow entry and return the reference to populate it.
Arrow& NewArrow()
{
Arrows.Append( new Arrow );
@ -550,6 +634,11 @@ protected: //! @name Value properties
Standard_Real myCustomValue; //!< Value of the dimension (computed or user-defined).
Standard_Boolean myIsValueCustom; //!< 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.
@ -559,10 +648,10 @@ protected: //! @name Geometrical properties
GeometryType myGeometryType; //!< defines type of shapes on which the dimension is to be built.
gp_Pln myPlane; //!< Plane where dimension will be built (computed or user defined).
gp_Pln myPlane; //!< Plane where dimension will be built (computed or user defined).
Standard_Boolean myIsPlaneCustom; //!< Is plane defined by user (otherwise it will be computed automatically).
Standard_Real myFlyout; //!< Flyout distance.
Standard_Boolean myIsValid; //!< Is dimension geometry properly defined.
Standard_Real myFlyout; //!< Flyout distance.
Standard_Boolean myIsValid; //!< Is dimension geometry properly defined.
private:

View File

@ -708,3 +708,35 @@ Standard_Boolean AIS_LengthDimension::InitOneShapePoints (const TopoDS_Shape& th
return IsValidPoints (myFirstPoint, mySecondPoint);
}
//=======================================================================
//function : GetTextPosition
//purpose :
//=======================================================================
const gp_Pnt AIS_LengthDimension::GetTextPosition() const
{
if (IsTextPositionCustom())
{
return myFixedTextPosition;
}
// Counts text position according to the dimension parameters
return GetTextPositionForLinear (myFirstPoint, mySecondPoint);
}
//=======================================================================
//function : SetTextPosition
//purpose :
//=======================================================================
void AIS_LengthDimension::SetTextPosition (const gp_Pnt& theTextPos)
{
if (!myIsValid)
{
return;
}
myIsTextPositionFixed = Standard_True;
myFixedTextPosition = theTextPos;
SetToUpdate();
}

View File

@ -187,15 +187,19 @@ public:
const TopoDS_Shape& theSecondShape);
//! @return the display units string.
Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits () const;
Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const;
//! @return the model units string.
Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits () const;
Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const;
Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits);
Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits);
Standard_EXPORT virtual void SetTextPosition (const gp_Pnt& theTextPos);
Standard_EXPORT virtual const gp_Pnt GetTextPosition() const;
public:
DEFINE_STANDARD_RTTI(AIS_LengthDimension)

View File

@ -262,3 +262,35 @@ Standard_Boolean AIS_RadiusDimension::IsValidAnchor (const gp_Circ& theCircle,
return Abs (anAnchorDist - aRadius) > Precision::Confusion()
&& aCirclePlane.Contains (theAnchor, Precision::Confusion());
}
//=======================================================================
//function : GetTextPosition
//purpose :
//=======================================================================
const gp_Pnt AIS_RadiusDimension::GetTextPosition() const
{
if (IsTextPositionCustom())
{
return myFixedTextPosition;
}
// Counts text position according to the dimension parameters
return GetTextPositionForLinear (myAnchorPoint, myCircle.Location(), Standard_True);
}
//=======================================================================
//function : GetTextPosition
//purpose :
//=======================================================================
void AIS_RadiusDimension::SetTextPosition (const gp_Pnt& theTextPos)
{
if (!myIsValid)
{
return;
}
myIsTextPositionFixed = Standard_True;
myFixedTextPosition = theTextPos;
SetToUpdate();
}

View File

@ -50,7 +50,7 @@ public:
//! orientation by location of the first point on that circle.
//! @param theCircle [in] the circle to measure.
//! @param theAnchorPoint [in] the point to define the position
//! of the dimension attachement on the circle.
//! of the dimension attachment on the circle.
Standard_EXPORT AIS_RadiusDimension (const gp_Circ& theCircle,
const gp_Pnt& theAnchorPoint);
@ -88,7 +88,7 @@ public:
//! Measure radius of the circle and orient the dimension so
//! the dimension lines attaches to anchor point on the circle.
//! The dimension will become invalid if the radiuss of the circle
//! The dimension will become invalid if the radius of the circle
//! is less than Precision::Confusion().
//! @param theCircle [in] the circle to measure.
//! @param theAnchorPoint [in] the point to attach the dimension lines.
@ -102,15 +102,19 @@ public:
Standard_EXPORT void SetMeasuredGeometry (const TopoDS_Shape& theShape);
//! @return the display units string.
Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits () const;
Standard_EXPORT virtual const TCollection_AsciiString& GetDisplayUnits() const;
//! @return the model units string.
Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits () const;
Standard_EXPORT virtual const TCollection_AsciiString& GetModelUnits() const;
Standard_EXPORT virtual void SetDisplayUnits (const TCollection_AsciiString& theUnits);
Standard_EXPORT virtual void SetModelUnits (const TCollection_AsciiString& theUnits);
Standard_EXPORT virtual void SetTextPosition (const gp_Pnt& theTextPos);
Standard_EXPORT virtual const gp_Pnt GetTextPosition() const;
public:
DEFINE_STANDARD_RTTI (AIS_RadiusDimension)

View File

@ -106,6 +106,12 @@ is
ExtensionSize (me) returns Real from Standard;
---Purpose: Returns extension size.
SetArrowTailSize (me : mutable; theSize : Real from Standard);
---Purpose: Set size for arrow tail (extension without text).
ArrowTailSize (me) returns Real from Standard;
---Purpose: Returns arrow tail size.
SetValueStringFormat (me : mutable; theFormat : AsciiString from TCollection);
---Purpose: Sets "sprintf"-syntax format for formatting dimension value labels.
@ -138,7 +144,10 @@ fields
myExtensionSize : Real from Standard;
---Purpose: Size of arrow extensions.
-- The length of arrow tails if arrows are located outside dimension line.
-- The length of arrow tail with text if arrows are located outside dimension line.
myArrowTailSize : Real from Standard;
---Purpose: Size of arrow tail (extension without text).
myValueStringFormat : AsciiString from TCollection;
---Purpose: "sprintf"-syntax format for formatting dimension value labels.

View File

@ -46,9 +46,10 @@ Prs3d_DimensionAspect::Prs3d_DimensionAspect()
myArrowAspect->SetColor (Quantity_NOC_LAWNGREEN);
myArrowAspect->SetAngle (M_PI * 20.0 / 180.0);
myArrowAspect->SetLength (6.0);
myExtensionSize = 6.0;
myValueStringFormat = "%g";
myToDisplayUnits = Standard_False;
myExtensionSize = 6.0;
myArrowTailSize = 6.0;
myValueStringFormat = "%g";
myToDisplayUnits = Standard_False;
}
//=======================================================================
@ -261,6 +262,24 @@ Standard_Real Prs3d_DimensionAspect::ExtensionSize() const
return myExtensionSize;
}
//=======================================================================
//function : SetShortExtensionSize
//purpose :
//=======================================================================
void Prs3d_DimensionAspect::SetArrowTailSize (const Standard_Real theSize)
{
myArrowTailSize = theSize;
}
//=======================================================================
//function : ShortExtensionSize
//purpose :
//=======================================================================
Standard_Real Prs3d_DimensionAspect::ArrowTailSize() const
{
return myArrowTailSize;
}
//=======================================================================
//function : SetValueStringFormat
//purpose :

File diff suppressed because it is too large Load Diff

48
tests/bugs/vis/bug24412_1 Normal file
View File

@ -0,0 +1,48 @@
puts "============"
puts "CR24412"
puts "============"
puts ""
#######################################################################
# TKV3d, Dimensions - Possibility to customize text position was lost
# Test position setting for linear dimension
#######################################################################
pload ALL
set anImage1 $imagedir/${casename}_1.png
set anImage2 $imagedir/${casename}_2.png
vinit Viewer1/View1
vpoint circ_p1 0 10 30
vpoint circ_p2 30 10 0
vpoint circ_p3 60 10 30
vcircle circ circ_p1 circ_p2 circ_p3 0
vdisplay circ
vdimension diameter name=diam circ
vdisplay diam
# Change text position
vmovedim diam 15 15 15
vfit
# Check that text position was changed and the text is not aligned
set x_coord 166
set y_coord 226
checkcolor $x_coord $y_coord 0.46 0.9 0
if { $stat != 1 } {
puts "Error : Text position of dimension is incorrect."
}
vdump $anImage1
# Update dimension parameters and set automatic text positioning
vdimparam diam flyout=-5
vfit
# Check that text position was changed according to flyout
set x_coord 213
set y_coord 179
checkcolor $x_coord $y_coord 0.46 0.9 0
if { $stat != 1 } {
puts "Error : Text position of dimension after layout changing is incorrect."
}
vdump $anImage2

46
tests/bugs/vis/bug24412_2 Normal file
View File

@ -0,0 +1,46 @@
puts "============"
puts "CR24412"
puts "============"
puts ""
#######################################################################
# TKV3d, Dimensions - Possibility to customize text position was lost
# Test position setting for angular dimension
#######################################################################
pload ALL
set anImage1 $imagedir/${casename}_1.png
set anImage2 $imagedir/${casename}_2.png
vinit Viewer1/View1
vpoint ang_p1 0 0 30
vpoint ang_p2 30 0 0
vpoint ang_p3 60 0 30
vdimension angle name=ang ang_p1 ang_p2 ang_p3
vdisplay ang
vmovedim ang 5 0 5
vfit
# Check that text position was changed and the text is not aligned
set x_coord 60
set y_coord 189
checkcolor $x_coord $y_coord 0.46 0.9 0
if { $stat != 1 } {
puts "Error : Text position of dimension is incorrect."
}
vdump $anImage1
# Update dimension parameters and set automatic text positioning
vdimparam ang flyout=-5
vfit
# Check that text position was changed according to flyout
set x_coord 206
set y_coord 312
checkcolor $x_coord $y_coord 0.46 0.9 0
if { $stat != 1 } {
puts "Error : Text position of dimension after layout changing is incorrect."
}
vdump $anImage2