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

0025235: Draw Harness - improve commands vdimension and vdimparam

Make commands syntax to meet coding rules.
Correct angle dimension initialization to allow ellipse input geometry with equal radii.
Change default value of arrow angle for dimensions (from 20 to 12 degrees).
Add arlength, arangle, textmode, textsize to vdimension and vdimparam Draw commands.
Add color parameter to vdimension and vdimparam.
Display dimensions by default.

Add dimensions demo script samples/tcl/dimensions.tcl.

Add file for test case for issue CR25235
This commit is contained in:
aba
2014-10-02 14:02:20 +04:00
committed by bugmaster
parent 52d4584155
commit 0499eb0670
23 changed files with 667 additions and 526 deletions

View File

@@ -68,6 +68,7 @@
#include <TCollection_ExtendedString.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>
#include <Units.hxx>
#include <Units_UnitsDictionary.hxx>
@@ -1019,6 +1020,48 @@ Standard_Boolean AIS_Dimension::CircleFromPlanarFace (const TopoDS_Face& theFace
return Standard_False;
}
//=======================================================================
//function : CircleFromEdge
//purpose : if possible computes circle from edge
//=======================================================================
Standard_Boolean AIS_Dimension::CircleFromEdge (const TopoDS_Edge& theEdge,
gp_Circ& theCircle,
gp_Pnt& theFirstPoint,
gp_Pnt& theLastPoint)
{
BRepAdaptor_Curve anAdaptedCurve (theEdge);
switch (anAdaptedCurve.GetType())
{
case GeomAbs_Circle:
{
theCircle = anAdaptedCurve.Circle();
break;
}
case GeomAbs_Ellipse:
{
gp_Elips anEll = anAdaptedCurve.Ellipse();
if ((anEll.MinorRadius() - anEll.MajorRadius()) >= Precision::Confusion())
{
return Standard_False;
}
theCircle = gp_Circ(anEll.Position(),anEll.MinorRadius());
break;
}
case GeomAbs_Line:
case GeomAbs_Hyperbola:
case GeomAbs_Parabola:
case GeomAbs_BezierCurve:
case GeomAbs_BSplineCurve:
case GeomAbs_OtherCurve:
default:
return Standard_False;
}
theFirstPoint = anAdaptedCurve.Value (anAdaptedCurve.FirstParameter());
theLastPoint = anAdaptedCurve.Value (anAdaptedCurve.LastParameter());
return Standard_True;
}
//=======================================================================
//function : InitCircularDimension
//purpose :
@@ -1036,122 +1079,126 @@ Standard_Boolean AIS_Dimension::InitCircularDimension (const TopoDS_Shape& theSh
Standard_Real aFirstParam = 0.0;
Standard_Real aLastParam = 0.0;
// discover circular geometry
if (theShape.ShapeType() == TopAbs_FACE)
// Discover circular geometry
switch (theShape.ShapeType())
{
AIS::GetPlaneFromFace (TopoDS::Face (theShape), aPln, aBasisSurf, aSurfType, anOffset);
if (aSurfType == AIS_KOS_Plane)
case TopAbs_FACE:
{
Handle(Geom_Curve) aCurve;
if (!CircleFromPlanarFace (TopoDS::Face (theShape), aCurve, aFirstPoint, aLastPoint))
{
return Standard_False;
}
AIS::GetPlaneFromFace (TopoDS::Face (theShape), aPln, aBasisSurf, aSurfType, anOffset);
theCircle = Handle(Geom_Circle)::DownCast (aCurve)->Circ();
}
else
{
gp_Pnt aCurPos;
BRepAdaptor_Surface aSurf1 (TopoDS::Face (theShape));
Standard_Real aFirstU = aSurf1.FirstUParameter();
Standard_Real aLastU = aSurf1.LastUParameter();
Standard_Real aFirstV = aSurf1.FirstVParameter();
Standard_Real aLastV = aSurf1.LastVParameter();
Standard_Real aMidU = (aFirstU + aLastU) * 0.5;
Standard_Real aMidV = (aFirstV + aLastV) * 0.5;
aSurf1.D0 (aMidU, aMidV, aCurPos);
Handle (Adaptor3d_HCurve) aBasisCurve;
Standard_Boolean isExpectedType = Standard_False;
if (aSurfType == AIS_KOS_Cylinder)
if (aSurfType == AIS_KOS_Plane)
{
isExpectedType = Standard_True;
}
else
{
if (aSurfType == AIS_KOS_Revolution)
Handle(Geom_Curve) aCurve;
if (!CircleFromPlanarFace (TopoDS::Face (theShape), aCurve, aFirstPoint, aLastPoint))
{
aBasisCurve = aSurf1.BasisCurve();
if (aBasisCurve->GetType() == GeomAbs_Line)
{
isExpectedType = Standard_True;
}
return Standard_False;
}
else if (aSurfType == AIS_KOS_Extrusion)
{
aBasisCurve = aSurf1.BasisCurve();
if (aBasisCurve->GetType() == GeomAbs_Circle)
{
isExpectedType = Standard_True;
}
}
}
if (!isExpectedType)
{
return Standard_False;
}
Handle(Geom_Curve) aCurve;
aCurve = aBasisSurf->VIso(aMidV);
if (aCurve->DynamicType() == STANDARD_TYPE (Geom_Circle))
{
theCircle = Handle(Geom_Circle)::DownCast (aCurve)->Circ();
}
else if (aCurve->DynamicType() == STANDARD_TYPE (Geom_TrimmedCurve))
{
Handle(Geom_TrimmedCurve) aTrimmedCurve = Handle(Geom_TrimmedCurve)::DownCast (aCurve);
aFirstU = aTrimmedCurve->FirstParameter();
aLastU = aTrimmedCurve->LastParameter();
if (aTrimmedCurve->BasisCurve()->DynamicType() == STANDARD_TYPE (Geom_Circle))
{
theCircle = Handle(Geom_Circle)::DownCast(aTrimmedCurve->BasisCurve())->Circ();
}
}
else
{
// Compute a circle from 3 points on "aCurve"
gp_Pnt aP1, aP2;
aSurf1.D0 (aFirstU, aMidV, aP1);
aSurf1.D0 (aLastU, aMidV, aP2);
GC_MakeCircle aMkCirc (aP1, aCurPos, aP2);
theCircle = aMkCirc.Value()->Circ();
}
gp_Pnt aCurPos;
BRepAdaptor_Surface aSurf1 (TopoDS::Face (theShape));
Standard_Real aFirstU = aSurf1.FirstUParameter();
Standard_Real aLastU = aSurf1.LastUParameter();
Standard_Real aFirstV = aSurf1.FirstVParameter();
Standard_Real aLastV = aSurf1.LastVParameter();
Standard_Real aMidU = (aFirstU + aLastU) * 0.5;
Standard_Real aMidV = (aFirstV + aLastV) * 0.5;
aSurf1.D0 (aMidU, aMidV, aCurPos);
Handle (Adaptor3d_HCurve) aBasisCurve;
Standard_Boolean isExpectedType = Standard_False;
if (aSurfType == AIS_KOS_Cylinder)
{
isExpectedType = Standard_True;
}
else
{
if (aSurfType == AIS_KOS_Revolution)
{
aBasisCurve = aSurf1.BasisCurve();
if (aBasisCurve->GetType() == GeomAbs_Line)
{
isExpectedType = Standard_True;
}
}
else if (aSurfType == AIS_KOS_Extrusion)
{
aBasisCurve = aSurf1.BasisCurve();
if (aBasisCurve->GetType() == GeomAbs_Circle)
{
isExpectedType = Standard_True;
}
}
}
aFirstPoint = ElCLib::Value (aFirstU, theCircle);
aLastPoint = ElCLib::Value (aLastU, theCircle);
if (!isExpectedType)
{
return Standard_False;
}
Handle(Geom_Curve) aCurve = aBasisSurf->VIso(aMidV);
if (aCurve->DynamicType() == STANDARD_TYPE (Geom_Circle))
{
theCircle = Handle(Geom_Circle)::DownCast (aCurve)->Circ();
}
else if (aCurve->DynamicType() == STANDARD_TYPE (Geom_TrimmedCurve))
{
Handle(Geom_TrimmedCurve) aTrimmedCurve = Handle(Geom_TrimmedCurve)::DownCast (aCurve);
aFirstU = aTrimmedCurve->FirstParameter();
aLastU = aTrimmedCurve->LastParameter();
if (aTrimmedCurve->BasisCurve()->DynamicType() == STANDARD_TYPE (Geom_Circle))
{
theCircle = Handle(Geom_Circle)::DownCast(aTrimmedCurve->BasisCurve())->Circ();
}
}
else
{
// Compute a circle from 3 points on "aCurve"
gp_Pnt aP1, aP2;
aSurf1.D0 (aFirstU, aMidV, aP1);
aSurf1.D0 (aLastU, aMidV, aP2);
GC_MakeCircle aMkCirc (aP1, aCurPos, aP2);
theCircle = aMkCirc.Value()->Circ();
}
aFirstPoint = ElCLib::Value (aFirstU, theCircle);
aLastPoint = ElCLib::Value (aLastU, theCircle);
}
break;
}
}
else // TopAbs_EDGE | TopAbs_WIRE
{
TopoDS_Edge anEdge;
if (theShape.ShapeType() == TopAbs_WIRE)
case TopAbs_WIRE:
{
TopoDS_Edge anEdge;
TopExp_Explorer anIt (theShape, TopAbs_EDGE);
if (anIt.More())
{
anEdge = TopoDS::Edge (anIt.Current());
}
if (!AIS_Dimension::CircleFromEdge (anEdge, theCircle, aFirstPoint, aLastPoint))
{
return Standard_False;
}
break;
}
else if (theShape.ShapeType() == TopAbs_EDGE)
case TopAbs_EDGE:
{
anEdge = TopoDS::Edge (theShape);
TopoDS_Edge anEdge = TopoDS::Edge (theShape);
if (!AIS_Dimension::CircleFromEdge (anEdge, theCircle, aFirstPoint, aLastPoint))
{
return Standard_False;
}
break;
}
else // Unexpected type of shape
{
case TopAbs_COMPOUND:
case TopAbs_COMPSOLID:
case TopAbs_SOLID:
case TopAbs_SHELL:
case TopAbs_VERTEX:
case TopAbs_SHAPE:
default:
return Standard_False;
}
BRepAdaptor_Curve anAdaptedCurve (anEdge);
if (anAdaptedCurve.GetType() != GeomAbs_Circle)
{
return Standard_False;
}
theCircle = anAdaptedCurve.Circle();
aFirstPoint = anAdaptedCurve.Value (anAdaptedCurve.FirstParameter());
aLastPoint = anAdaptedCurve.Value (anAdaptedCurve.LastParameter());
}
theIsClosed = aFirstPoint.IsEqual (aLastPoint, Precision::Confusion());

View File

@@ -37,6 +37,7 @@
#include <Standard.hxx>
#include <TCollection_ExtendedString.hxx>
#include <TColgp_HSequenceOfPnt.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <NCollection_Sequence.hxx>
@@ -451,16 +452,6 @@ protected:
const gp_Pnt& theFirstPoint,
const gp_Pnt& theSecondPoint);
//! If it is possible extracts circle from planar face.
//! @param theFace [in] the planar face.
//! @param theCurve [out] the circular curve.
//! @param theFirstPoint [out] the point of the first parameter of the circlular curve.
//! @param theSecondPoint [out] the point of the last parameter of the circlular curve.
//! @return TRUE in case of successful circle extraction.
Standard_EXPORT Standard_Boolean CircleFromPlanarFace (const TopoDS_Face& theFace,
Handle(Geom_Curve)& theCurve,
gp_Pnt& theFirstPoint,
gp_Pnt& theLastPoint);
//! Performs initialization of circle and middle arc point from the passed
//! shape which is assumed to contain circular geometry.
@@ -532,6 +523,30 @@ protected:
gp_Pln& thePlane,
Standard_Boolean& theIsPlaneOld) const;
protected: //! @name Static auxilliary methods for geometry extraction
//! If it is possible extracts circle from planar face.
//! @param theFace [in] the planar face
//! @param theCurve [out] the circular curve
//! @param theFirstPoint [out] the point of the first parameter of the circlular curve
//! @param theSecondPoint [out] the point of the last parameter of the circlular curve
//! @return TRUE in case of successful circle extraction
static Standard_Boolean CircleFromPlanarFace (const TopoDS_Face& theFace,
Handle(Geom_Curve)& theCurve,
gp_Pnt& theFirstPoint,
gp_Pnt& theLastPoint);
//! If it is possible extracts circle from the edge.
//! @param theEdge [in] input edge to extract circle from
//! @param theCircle [out] circle
//! @param theFirstPoint [out] the point of the first parameter of the circlular curve
//! @param theSecondPoint [out] the point of the last parameter of the circlular curve
//! @return TRUE in case of successful circle extraction.
static Standard_Boolean CircleFromEdge (const TopoDS_Edge& theEdge,
gp_Circ& theCircle,
gp_Pnt& theFirstPoint,
gp_Pnt& theLastPoint);
protected: //! @name Behavior to implement
//! Override this method to compute automatically dimension plane

View File

@@ -44,7 +44,7 @@ Prs3d_DimensionAspect::Prs3d_DimensionAspect()
myTextAspect->SetVerticalJustification (Graphic3d_VTA_CENTER);
myArrowAspect = new Prs3d_ArrowAspect;
myArrowAspect->SetColor (Quantity_NOC_LAWNGREEN);
myArrowAspect->SetAngle (M_PI * 20.0 / 180.0);
myArrowAspect->SetAngle (M_PI * 12.0 / 180.0);
myArrowAspect->SetLength (6.0);
myExtensionSize = 6.0;
myArrowTailSize = 6.0;

View File

@@ -165,213 +165,286 @@ static Standard_Boolean Get3DPointAtMousePosition (const gp_Pnt& theFirstPoint,
return Standard_True;
}
//=======================================================================
//function : ParseDimensionParams
//purpose : Auxilliary function: sets aspect parameters for
// length, angle, radius and diameter dimension.
//
//draw args: -text [3d|2d] [wf|sh|wireframe|shading] [Size]
// -label [left|right|hcenter|hfit] [top|bottom|vcenter|vfit]
// -arrow [external|internal|fit] [Length(int)]
// -arrowangle ArrowAngle(degrees)
// -plane xoy|yoz|zox
// -flyout FloatValue -extension FloatValue
//
// Warning! flyout is not an aspect value, it is for dimension parameter
// likewise text position, but text position override other paramaters
// For this use 'vmovedim'.
//=======================================================================
static int ParseDimensionParams (Standard_Integer theArgNum,
const char** theArgVec,
Standard_Integer theStartIndex,
const Handle(Prs3d_DimensionAspect)& theAspect,
Standard_Boolean& theIsCustomPlane,
gp_Pln& thePlane,
Standard_Boolean& theIsCustomFlyout,
Standard_Real& theFlyoutSize,
NCollection_List<Handle(AIS_InteractiveObject)>* theShapeList = NULL)
{
theIsCustomPlane = Standard_False;
theIsCustomFlyout = Standard_False;
// Begin from the second parameter: the first on eis dimension name
for (Standard_Integer anIt = theStartIndex; anIt < theArgNum; ++anIt)
{
TCollection_AsciiString aParam (theArgVec[anIt]);
aParam.LowerCase();
if (aParam.Search ("-") == -1)
{
continue;
}
// Before all non-boolean flags parsing check if a flag have at least one value.
if (anIt + 1 >= theArgNum)
{
std::cerr << "Error: "<< aParam <<" flag should have value.\n";
return 1;
}
// Non-boolean flags
if (aParam.IsEqual ("-shape")
|| aParam.IsEqual ("-shapes"))
{
if (!theShapeList)
{
std::cerr << "Error: unknown parameter '" << aParam << "'\n";
return 1;
}
do
{
anIt++;
TCollection_AsciiString anArgString = theArgVec[anIt];
Handle(AIS_InteractiveObject) anAISObject;
Standard_CString aStr = anArgString.ToCString();
TopoDS_Shape aShape = DBRep::Get (aStr);
if (!aShape.IsNull())
{
anAISObject = new AIS_Shape (aShape);
}
else
{
if (!GetMapOfAIS().IsBound2 (anArgString))
{
std::cerr << "Error: shape with name '" << aStr << "' is not found.\n";
return 1;
}
anAISObject = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anArgString));
if (anAISObject.IsNull())
{
std::cerr << "Error: " << aStr <<" is not a shape.\n";
return 1;
}
}
theShapeList->Append (anAISObject);
}
while (anIt + 1 < theArgNum && theArgVec[anIt + 1][0] != '-');
}
else if (aParam.IsEqual ("-text"))
{
do
{
anIt++;
TCollection_AsciiString aValue (theArgVec[anIt]);
aValue.LowerCase();
if (aValue.IsEqual ("3d"))
{
theAspect->MakeText3d (Standard_True);
}
else if (aValue.IsEqual ("2d"))
{
theAspect->MakeText3d (Standard_False);
}
else if (aValue.IsEqual ("wf") || aValue.IsEqual ("wireframe"))
{
theAspect->MakeTextShaded (Standard_False);
}
else if ( aValue.IsEqual ("sh") || aValue.IsEqual ("shading"))
{
theAspect->MakeTextShaded (Standard_True);
}
else if (aValue.IsIntegerValue()) // text size
{
theAspect->TextAspect()->SetHeight (Draw::Atoi (aValue.ToCString()));
}
}
while (anIt + 1 < theArgNum && theArgVec[anIt + 1][0] != '-');
}
else if (aParam.IsEqual ("-label"))
{
do
{
anIt++;
TCollection_AsciiString aParamValue (theArgVec[anIt]);
aParamValue.LowerCase();
if (aParamValue == "left") { theAspect->SetTextHorizontalPosition (Prs3d_DTHP_Left); }
else if (aParamValue == "right") { theAspect->SetTextHorizontalPosition (Prs3d_DTHP_Right); }
else if (aParamValue == "hcenter") { theAspect->SetTextHorizontalPosition (Prs3d_DTHP_Center);}
else if (aParamValue == "hfit") { theAspect->SetTextHorizontalPosition (Prs3d_DTHP_Fit); }
else if (aParamValue == "above") { theAspect->SetTextVerticalPosition (Prs3d_DTVP_Above); }
else if (aParamValue == "below") { theAspect->SetTextVerticalPosition (Prs3d_DTVP_Below); }
else if (aParamValue == "vcenter") { theAspect->SetTextVerticalPosition (Prs3d_DTVP_Center);}
else
{
std::cerr << "Error: invalid label position: '" << aParamValue << "'.\n";
return 1;
}
}
while (anIt + 1 < theArgNum && theArgVec[anIt+1][0] != '-');
}
else if (aParam.IsEqual ("-arrow"))
{
do
{
anIt++;
TCollection_AsciiString aParam (theArgVec[anIt]);
aParam.LowerCase();
if (aParam == "external") { theAspect->SetArrowOrientation (Prs3d_DAO_External); }
if (aParam == "internal") { theAspect->SetArrowOrientation (Prs3d_DAO_Internal); }
if (aParam == "fit") { theAspect->SetArrowOrientation (Prs3d_DAO_Fit); }
if (aParam.IsRealValue()) { theAspect->ArrowAspect()->SetLength (Draw::Atof (aParam.ToCString())); }
}
while (anIt + 1 < theArgNum && theArgVec[anIt + 1][0] != '-');
}
else if (aParam.IsEqual ("-arrowangle"))
{
TCollection_AsciiString aValue (theArgVec[++anIt]);
if (!aValue.IsRealValue())
{
std::cerr << "Error: arrow angle should be float degree value.\n";
return 1;
}
theAspect->ArrowAspect()->SetAngle (Draw::Atof (aValue.ToCString()));
}
else if (aParam.IsEqual ("-plane"))
{
TCollection_AsciiString aValue (theArgVec[++anIt]);
aValue.LowerCase();
if (aValue == "xoy")
{
theIsCustomPlane = Standard_True;
thePlane = gp_Pln (gp_Ax3 (gp::XOY()));
}
else if (aValue == "zox")
{
theIsCustomPlane = Standard_True;
thePlane = gp_Pln (gp_Ax3 (gp::ZOX()));
}
else if (aValue == "yoz")
{
theIsCustomPlane = Standard_True;
thePlane = gp_Pln (gp_Ax3 (gp::YOZ()));
}
else
{
std::cerr << "Error: wrong plane '" << aValue << "'.\n";
return 1;
}
}
else if (aParam.IsEqual ("-flyout"))
{
TCollection_AsciiString aParam (theArgVec[++anIt]);
if (!aParam.IsRealValue())
{
std::cerr << "Error: flyout for dimension should be real value.\n";
return 1;
}
theIsCustomFlyout = Standard_True;
theFlyoutSize = Draw::Atoi (aParam.ToCString());
}
else if (aParam.IsEqual ("-color"))
{
theAspect->SetCommonColor (Quantity_Color (ViewerTest::GetColorFromName (theArgVec[++anIt])));
}
else if (aParam.IsEqual ("-extension"))
{
TCollection_AsciiString aParam (theArgVec[++anIt]);
if (!aParam.IsRealValue())
{
std::cerr << "Error: extension size for dimension should be real value.\n";
return 1;
}
theAspect->SetExtensionSize (Draw::Atof (aParam.ToCString()));
}
else
{
std::cerr << "Error: unknown parameter '" << aParam << "'.\n";
return 1;
}
}
return 0;
}
//=======================================================================
//function : VDimBuilder
//purpose : Command for building dimension presentations: angle,
// length, radius, diameter
//=======================================================================
static int VDimBuilder(Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgs)
static int VDimBuilder (Draw_Interpretor& /*theDi*/,
Standard_Integer theArgsNb,
const char** theArgs)
{
if (theArgsNb < 2)
{
std::cerr << theArgs[0] << ": command argument is required. Type help for more information.\n";
std::cerr << "Error: wrong number of arguments.\n";
return 1;
}
// Parse parameters
TCollection_AsciiString aDimType(theArgs[1]);
TCollection_AsciiString aName (theArgs[1]);
NCollection_List<Handle(AIS_InteractiveObject)> aShapes;
Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect;
Standard_Boolean isPlaneCustom = Standard_False;
gp_Pln aWorkingPlane;
Standard_Boolean isCustomFlyout = Standard_False;
Standard_Real aCustomFlyout = 0.0;
TCollection_AsciiString aDimType(theArgs[2]);
aDimType.LowerCase();
AIS_KindOfDimension aKindOfDimension;
if (aDimType == "length")
if (aDimType == "-length")
{
aKindOfDimension = AIS_KOD_LENGTH;
}
else if (aDimType == "angle")
else if (aDimType == "-angle")
{
aKindOfDimension = AIS_KOD_PLANEANGLE;
}
else if (aDimType == "radius")
else if (aDimType == "-radius")
{
aKindOfDimension = AIS_KOD_RADIUS;
}
else if (aDimType == "diameter" || aDimType == "diam")
else if (aDimType == "-diameter" || aDimType == "-diam")
{
aKindOfDimension = AIS_KOD_DIAMETER;
}
else
{
std::cerr << theArgs[0] << ": wrong type of dimension. Type help for more information.\n";
std::cerr << "Error: wrong type of dimension.\n";
return 1;
}
NCollection_List<Handle(AIS_InteractiveObject)> aShapes;
Handle(Prs3d_DimensionAspect) anAspect = new Prs3d_DimensionAspect;
Standard_Boolean isPlaneCustom = Standard_False;
TCollection_AsciiString aName;
gp_Pln aWorkingPlane;
Standard_Boolean isCustomFlyout = Standard_False;
Standard_Real aCustomFlyout = 0.0;
for (Standard_Integer anIt = 2; anIt < theArgsNb; ++anIt)
{
TCollection_AsciiString anArgString = theArgs[anIt];
TCollection_AsciiString aParamName;
TCollection_AsciiString aParamValue;
if (ViewerTest::SplitParameter (anArgString, aParamName, aParamValue))
{
aParamName.LowerCase();
aParamValue.LowerCase();
if (aParamName == "text")
{
anAspect->MakeText3d (aParamValue == "3d");
}
else if (aParamName == "name")
{
if (aParamValue.IsEmpty())
{
std::cerr << theArgs[0] << ": no name for dimension.\n";
return 1;
}
aName = aParamValue;
}
else if (aParamName == "plane")
{
if (aParamValue == "xoy")
{
aWorkingPlane = gp_Pln (gp_Ax3 (gp::XOY()));
}
else if (aParamValue == "zox")
{
aWorkingPlane = gp_Pln (gp_Ax3 (gp::ZOX()));
}
else if (aParamValue == "yoz")
{
aWorkingPlane = gp_Pln (gp_Ax3 (gp::YOZ()));
}
else
{
std::cerr << theArgs[0] << ": wrong plane.\n";
return 1;
}
isPlaneCustom = Standard_True;
}
else if (aParamName == "label")
{
NCollection_List<TCollection_AsciiString> aListOfLabelVals;
while (aParamValue.Length() > 0)
{
TCollection_AsciiString aValue = aParamValue;
Standard_Integer aSeparatorPos = aParamValue.Search (",");
if (aSeparatorPos >= 0)
{
aValue.Trunc (aSeparatorPos - 1);
aParamValue.Remove (aSeparatorPos, 1);
}
aListOfLabelVals.Append (aValue);
aParamValue.Remove (1, aValue.Length());
}
NCollection_List<TCollection_AsciiString>::Iterator aLabelValueIt (aListOfLabelVals);
for ( ; aLabelValueIt.More(); aLabelValueIt.Next())
{
aParamValue = aLabelValueIt.Value();
if (aParamValue == "left")
{
anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Left);
}
else if (aParamValue == "right")
{
anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Right);
}
else if (aParamValue == "hcenter")
{
anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Center);
}
else if (aParamValue == "hfit")
{
anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Fit);
}
else if (aParamValue == "above")
{
anAspect->SetTextVerticalPosition (Prs3d_DTVP_Above);
}
else if (aParamValue == "below")
{
anAspect->SetTextVerticalPosition (Prs3d_DTVP_Below);
}
else if (aParamValue == "vcenter")
{
anAspect->SetTextVerticalPosition (Prs3d_DTVP_Center);
}
else
{
std::cerr << theArgs[0] << ": invalid label position: \"" << aParamValue << "\".\n";
return 1;
}
}
}
else if (aParamName == "flyout")
{
if (!aParamValue.IsRealValue())
{
std::cerr << theArgs[0] << ": numeric value expected for flyout.\n";
return 1;
}
aCustomFlyout = aParamValue.RealValue();
isCustomFlyout = Standard_True;
}
else if (aParamName == "arrows")
{
if (aParamValue == "external")
{
anAspect->SetArrowOrientation (Prs3d_DAO_External);
}
else if (aParamValue == "internal")
{
anAspect->SetArrowOrientation (Prs3d_DAO_Internal);
}
else if (aParamValue == "fit")
{
anAspect->SetArrowOrientation (Prs3d_DAO_Fit);
}
}
else
{
std::cerr << theArgs[0] << ": unknow parameter: \"" << aParamName << "\".\n";
return 1;
}
}
else // Shape
{
if (!GetMapOfAIS().IsBound2 (anArgString))
{
std::cerr << theArgs[0] << ": wrong name of shape. May be here is a wrong parameter.\n";
return 1;
}
Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anArgString));
if (aShape.IsNull())
{
std::cerr << theArgs[0] << ": wrong name of shape. Not a shape.\n";
return 1;
}
aShapes.Append (aShape);
}
}
if (aName.IsEmpty())
{
std::cerr << theArgs[0] << ": no name for dimension.\n";
return 1;
}
ParseDimensionParams (theArgsNb, theArgs, 3,
anAspect,isPlaneCustom,aWorkingPlane,
isCustomFlyout,aCustomFlyout, &aShapes);
// Build dimension
Handle(AIS_Dimension) aDim;
@@ -387,26 +460,33 @@ static int VDimBuilder(Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
if (aShapes.Extent() == 1)
{
if (aShapes.First()->Type() == AIS_KOI_Shape
&& (Handle(AIS_Shape)::DownCast(aShapes.First()))->Shape().ShapeType() != TopAbs_EDGE)
&& (Handle(AIS_Shape)::DownCast(aShapes.First()))->Shape().ShapeType() != TopAbs_EDGE)
{
std::cerr << theArgs[0] << ": wrong shape type.\n";
return 1;
}
aDim = new AIS_LengthDimension (TopoDS::Edge ((Handle(AIS_Shape)::DownCast(aShapes.First()))->Shape()), aWorkingPlane);
// Adjust working plane
TopoDS_Edge anEdge = TopoDS::Edge ((Handle(AIS_Shape)::DownCast(aShapes.First()))->Shape());
TopoDS_Vertex aFirst, aSecond;
TopExp::Vertices (anEdge, aFirst, aSecond);
aWorkingPlane.SetLocation (BRep_Tool::Pnt(aFirst));
aDim = new AIS_LengthDimension (anEdge, aWorkingPlane);
}
else if (aShapes.Extent() == 2)
{
if (aShapes.First()->Type() == AIS_KOI_Shape && aShapes.Last()->Type() == AIS_KOI_Shape)
aDim = new AIS_LengthDimension ((Handle(AIS_Shape)::DownCast(aShapes.First ()))->Shape(),
(Handle(AIS_Shape)::DownCast(aShapes.Last ()))->Shape(),
aWorkingPlane);
(Handle(AIS_Shape)::DownCast(aShapes.Last ()))->Shape(),
aWorkingPlane);
else// AIS_Point
{
Handle(AIS_Point) aPoint1 = Handle(AIS_Point)::DownCast(aShapes.First ());
Handle(AIS_Point) aPoint2 = Handle(AIS_Point)::DownCast(aShapes.Last ());
// Adjust working plane
aWorkingPlane.SetLocation (BRep_Tool::Pnt(aPoint1->Vertex()));
aDim = new AIS_LengthDimension (aPoint1->Component()->Pnt(),
aPoint2->Component()->Pnt(),
aWorkingPlane);
aPoint2->Component()->Pnt(),
aWorkingPlane);
}
}
else
@@ -417,7 +497,6 @@ static int VDimBuilder(Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
break;
}
case AIS_KOD_PLANEANGLE:
{
if (aShapes.Extent() == 1 && aShapes.First()->Type()==AIS_KOI_Shape)
@@ -431,8 +510,8 @@ static int VDimBuilder(Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
Handle(AIS_Shape) aShape1 = Handle(AIS_Shape)::DownCast(aShapes.First());
Handle(AIS_Shape) aShape2 = Handle(AIS_Shape)::DownCast(aShapes.Last());
if (!aShape1.IsNull() && !aShape2.IsNull()
&& aShape1->Shape().ShapeType() == TopAbs_EDGE
&& aShape2->Shape().ShapeType() == TopAbs_EDGE)
&& aShape1->Shape().ShapeType() == TopAbs_EDGE
&& aShape2->Shape().ShapeType() == TopAbs_EDGE)
aDim = new AIS_AngleDimension (TopoDS::Edge(aShape1->Shape()),TopoDS::Edge(aShape2->Shape()));
else
{
@@ -467,14 +546,26 @@ static int VDimBuilder(Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
break;
}
case AIS_KOD_RADIUS: // radius of the circle
{
if (aShapes.Extent() == 1)
{
Handle(AIS_Circle) aShape = Handle(AIS_Circle)::DownCast (aShapes.First());
gp_Circ aCircle = aShape->Circle()->Circ();
aDim = new AIS_RadiusDimension (aCircle);
if (aShapes.First()->DynamicType() == STANDARD_TYPE(AIS_Circle))
{
Handle(AIS_Circle) aShape = Handle(AIS_Circle)::DownCast (aShapes.First());
gp_Circ aCircle = aShape->Circle()->Circ();
aDim = new AIS_RadiusDimension (aCircle);
}
else
{
Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aShapes.First());
if (aShape.IsNull())
{
std::cerr << "Error: shape for radius is of wrong type.\n";
return 1;
}
aDim = new AIS_RadiusDimension (aShape->Shape());
}
}
else
{
@@ -484,14 +575,26 @@ static int VDimBuilder(Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
break;
}
case AIS_KOD_DIAMETER:
{
if (aShapes.Extent() == 1)
{
Handle(AIS_Circle) aShape = Handle(AIS_Circle)::DownCast (aShapes.First());
gp_Circ aCircle = aShape->Circle()->Circ();
aDim = new AIS_DiameterDimension (aCircle);
if (aShapes.First()->DynamicType() == STANDARD_TYPE(AIS_Circle))
{
Handle(AIS_Circle) aShape = Handle(AIS_Circle)::DownCast (aShapes.First());
gp_Circ aCircle = aShape->Circle()->Circ();
aDim = new AIS_DiameterDimension (aCircle);
}
else
{
Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (aShapes.First());
if (aShape.IsNull())
{
std::cerr << "Error: shape for radius is of wrong type.\n";
return 1;
}
aDim = new AIS_DiameterDimension (aShape->Shape());
}
}
else
{
@@ -501,7 +604,6 @@ static int VDimBuilder(Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
break;
}
default:
{
std::cerr << theArgs[0] << ": wrong type of dimension. Type help for more information.\n";
@@ -509,6 +611,14 @@ static int VDimBuilder(Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
}
}
// Check dimension geometry
if (!aDim->IsValid())
{
std::cerr << theArgs[0] << ":dimension geometry is invalid, " << aDimType.ToCString()
<< " dimension can't be build on input shapes.\n";
return 1;
}
aDim->SetDimensionAspect (anAspect);
if (isCustomFlyout)
@@ -516,16 +626,7 @@ static int VDimBuilder(Draw_Interpretor& theDi, Standard_Integer theArgsNb, cons
aDim->SetFlyout (aCustomFlyout);
}
if (GetMapOfAIS().IsBound2(aName))
{
theDi << theArgs[0] << ": shape with name " << aName.ToCString ()<< " already exists. It will be replaced\n";
Handle(AIS_InteractiveObject) anObj =
Handle(AIS_InteractiveObject)::DownCast(GetMapOfAIS().Find2(aName));
TheAISContext()->Remove(anObj, Standard_False);
GetMapOfAIS().UnBind2(aName);
}
GetMapOfAIS().Bind (aDim,aName);
VDisplayAISObject (aName,aDim);
return 0;
}
@@ -2330,10 +2431,9 @@ static int VSymmetricBuilder(Draw_Interpretor& di, Standard_Integer argc, const
//=======================================================================
//function : VDimParam
//purpose : Moves dimension or relation text label to defined or picked
// position and updates the object.
//purpose : Sets aspect parameters to dimension.
//=======================================================================
static int VDimParam (Draw_Interpretor& theDi, Standard_Integer theArgNum, const char** theArgVec)
static int VDimParam (Draw_Interpretor& theDi, Standard_Integer theArgNum, const char** theArgVec)
{
if (theArgNum < 3)
{
@@ -2341,8 +2441,14 @@ static int VDimParam (Draw_Interpretor& theDi, Standard_Integer theArgNum, const
return 1;
}
// Get dimension name
TCollection_AsciiString aName (theArgVec[1]);
gp_Pln aWorkingPlane;
Standard_Real aCustomFlyout = 0.0;
Standard_Boolean isCustomPlane = Standard_False;
Standard_Boolean isCustomFlyout = Standard_False;
Standard_Boolean toUpdate = Standard_True;
if (!GetMapOfAIS().IsBound2 (aName))
{
theDi << theArgVec[0] << "error: no object with this name.\n";
@@ -2355,152 +2461,36 @@ static int VDimParam (Draw_Interpretor& theDi, Standard_Integer theArgNum, const
theDi << theArgVec[0] << "error: no dimension with this name.\n";
return 1;
}
Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast (anObject);
Handle(Prs3d_DimensionAspect) anAspect = aDim->DimensionAspect();
// Parse parameters
gp_Pln aWorkingPlane;
Standard_Real aCustomFlyout = 0.0;
ParseDimensionParams (theArgNum, theArgVec, 2, anAspect,
isCustomPlane, aWorkingPlane,
isCustomFlyout, aCustomFlyout);
for (Standard_Integer anIt = 2; anIt < theArgNum; ++anIt)
if (isCustomPlane)
{
TCollection_AsciiString anArgString = theArgVec[anIt];
TCollection_AsciiString aParamName;
TCollection_AsciiString aParamValue;
if (ViewerTest::SplitParameter (anArgString, aParamName, aParamValue))
{
aParamName.LowerCase();
aParamValue.LowerCase();
aDim->SetCustomPlane (aWorkingPlane);
}
if (aParamName == "text")
{
anAspect->MakeText3d (aParamValue == "3d");
}
else if (aParamName == "name")
{
if (aParamValue.IsEmpty())
{
std::cerr << theArgVec[0] << ": no name for dimension.\n";
return 1;
}
if (isCustomFlyout)
{
aDim->SetFlyout (aCustomFlyout);
}
aName = aParamValue;
}
else if (aParamName == "plane")
{
if (aParamValue == "xoy")
{
aWorkingPlane = gp_Pln (gp_Ax3 (gp::XOY()));
}
else if (aParamValue == "zox")
{
aWorkingPlane = gp_Pln (gp_Ax3 (gp::ZOX()));
}
else if (aParamValue == "yoz")
{
aWorkingPlane = gp_Pln (gp_Ax3 (gp::YOZ()));
}
else
{
std::cerr << theArgVec[0] << ": wrong plane.\n";
return 1;
}
}
else if (aParamName == "label")
{
NCollection_List<TCollection_AsciiString> aListOfLabelVals;
while (aParamValue.Length() > 0)
{
TCollection_AsciiString aValue = aParamValue;
Standard_Integer aSeparatorPos = aParamValue.Search (",");
if (aSeparatorPos >= 0)
{
aValue.Trunc (aSeparatorPos - 1);
aParamValue.Remove (aSeparatorPos, 1);
}
aListOfLabelVals.Append (aValue);
aParamValue.Remove (1, aValue.Length());
}
NCollection_List<TCollection_AsciiString>::Iterator aLabelValueIt (aListOfLabelVals);
for ( ; aLabelValueIt.More(); aLabelValueIt.Next())
{
aParamValue = aLabelValueIt.Value();
if (aParamValue == "left")
{
anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Left);
}
else if (aParamValue == "right")
{
anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Right);
}
else if (aParamValue == "hcenter")
{
anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Center);
}
else if (aParamValue == "hfit")
{
anAspect->SetTextHorizontalPosition (Prs3d_DTHP_Fit);
}
else if (aParamValue == "above")
{
anAspect->SetTextVerticalPosition (Prs3d_DTVP_Above);
}
else if (aParamValue == "below")
{
anAspect->SetTextVerticalPosition (Prs3d_DTVP_Below);
}
else if (aParamValue == "vcenter")
{
anAspect->SetTextVerticalPosition (Prs3d_DTVP_Center);
}
else
{
std::cerr << theArgVec[0] << ": invalid label position: \"" << aParamValue << "\".\n";
return 1;
}
}
}
else if (aParamName == "flyout")
{
if (!aParamValue.IsRealValue())
{
std::cerr << theArgVec[0] << ": numeric value expected for flyout.\n";
return 1;
}
aCustomFlyout = aParamValue.RealValue();
aDim->SetFlyout (aCustomFlyout);
}
else if (aParamName == "arrows")
{
if (aParamValue == "external")
{
anAspect->SetArrowOrientation (Prs3d_DAO_External);
}
else if (aParamValue == "internal")
{
anAspect->SetArrowOrientation (Prs3d_DAO_Internal);
}
else if (aParamValue == "fit")
{
anAspect->SetArrowOrientation (Prs3d_DAO_Fit);
}
}
else
{
std::cerr << theArgVec[0] << ": unknow parameter: \"" << aParamName << "\".\n";
return 1;
}
}
if (!aDim->IsValid())
{
std::cerr << "Error: Dimension geometry or plane is not valid.\n";
return 1;
}
// Redisplay a dimension after parameter changing.
ViewerTest::GetAISContext()->Redisplay (aDim);
if (ViewerTest::GetAISContext()->IsDisplayed (aDim))
{
ViewerTest::GetAISContext()->Redisplay (aDim, toUpdate);
}
return 0;
}
@@ -2681,18 +2671,24 @@ void ViewerTest::RelationCommands(Draw_Interpretor& theCommands)
const char *group = "AISRelations";
theCommands.Add("vdimension",
"vdimension {angle|length|radius|diameter} name={Dim_Name} shape1 [shape2 [shape3]]\n"
" [text={2d|3d}] [plane={xoy|yoz|zox}]\n"
" [label={left|right|hcenter|hfit},{above|below|vcenter}]\n"
" [flyout=value] [arrows={external|internal|fit}]\n"
"vdimension name {-angle|-length|-radius|-diameter} -shapes shape1 [shape2 [shape3]]\n"
"[-text 3d|2d,wf|sh|wireframe|shading,Size]\n"
"[-label left|right|hcenter|hfit,top|bottom|vcenter|vfit]\n"
"[-arrow external|internal|fit,Length(int)]\n"
"[-arrowangle ArrowAngle(degrees)]\n"
"[-plane xoy|yoz|zox]\n"
"[-flyout FloatValue -extension FloatValue]\n"
" -Builds angle, length, radius and diameter dimensions.\n",
__FILE__,VDimBuilder,group);
theCommands.Add("vdimparam",
"vdimparam Dim_Name"
" [text={2d|3d}] [plane={xoy|yoz|zox}]\n"
" [label={left|right|hcenter|hfit},{above|below|vcenter}]\n"
" [flyout=value] [arrows={external|internal|fit}]\n"
"vdimparam name"
"[-text 3d|2d,wf|sh|wireframe|shading,Size]\n"
"[-label left|right|hcenter|hfit,top|bottom|vcenter|vfit]\n"
"[-arrow external|internal|fit,Length(int)]\n"
"[-arrowangle ArrowAngle(degrees)]\n"
"[-plane xoy|yoz|zox]\n"
"[-flyout FloatValue -extension FloatValue]\n"
" -Sets parameters for angle, length, radius and diameter dimensions.\n",
__FILE__,VDimParam,group);
@@ -2754,7 +2750,8 @@ void ViewerTest::RelationCommands(Draw_Interpretor& theCommands)
__FILE__,VSymmetricBuilder ,group);
theCommands.Add("vmovedim",
"vmovedim [name] : move Mouse in the viewer; click MB1 to stop motion...",
"vmovedim [name] [x y z]: moves picked or named (if name defined) "
"dimension to picked mouse position or input point.",
__FILE__,VMoveDim,group);
}