#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>
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 :
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;
+ Handle(Geom_Curve) aCurve;
+ if (!CircleFromPlanarFace (TopoDS::Face (theShape), aCurve, aFirstPoint, aLastPoint))
+ {
+ return Standard_False;
+ }
+
+ theCircle = Handle(Geom_Circle)::DownCast (aCurve)->Circ();
}
else
{
- if (aSurfType == AIS_KOS_Revolution)
+ 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)
{
- aBasisCurve = aSurf1.BasisCurve();
- if (aBasisCurve->GetType() == GeomAbs_Line)
- {
- isExpectedType = Standard_True;
- }
+ isExpectedType = Standard_True;
}
- else if (aSurfType == AIS_KOS_Extrusion)
+ else
{
- aBasisCurve = aSurf1.BasisCurve();
- if (aBasisCurve->GetType() == GeomAbs_Circle)
+ if (aSurfType == AIS_KOS_Revolution)
{
- isExpectedType = Standard_True;
+ 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;
+ }
}
}
- }
- if (!isExpectedType)
- {
- return Standard_False;
- }
+ 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))
+ Handle(Geom_Curve) aCurve = aBasisSurf->VIso(aMidV);
+ if (aCurve->DynamicType() == STANDARD_TYPE (Geom_Circle))
{
- theCircle = Handle(Geom_Circle)::DownCast(aTrimmedCurve->BasisCurve())->Circ();
+ 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();
}
- }
- 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);
+ 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)
- {
- anEdge = TopoDS::Edge (theShape);
- }
- else // Unexpected type of shape
+ case TopAbs_EDGE:
{
- return Standard_False;
+ TopoDS_Edge anEdge = TopoDS::Edge (theShape);
+ if (!AIS_Dimension::CircleFromEdge (anEdge, theCircle, aFirstPoint, aLastPoint))
+ {
+ return Standard_False;
+ }
+ break;
}
-
- BRepAdaptor_Curve anAdaptedCurve (anEdge);
- if (anAdaptedCurve.GetType() != GeomAbs_Circle)
- {
+ case TopAbs_COMPOUND:
+ case TopAbs_COMPSOLID:
+ case TopAbs_SOLID:
+ case TopAbs_SHELL:
+ case TopAbs_VERTEX:
+ case TopAbs_SHAPE:
+ default:
return Standard_False;
- }
-
- theCircle = anAdaptedCurve.Circle();
- aFirstPoint = anAdaptedCurve.Value (anAdaptedCurve.FirstParameter());
- aLastPoint = anAdaptedCurve.Value (anAdaptedCurve.LastParameter());
}
theIsClosed = aFirstPoint.IsEqual (aLastPoint, Precision::Confusion());
}
//=======================================================================
-//function : VDimBuilder
-//purpose : Command for building dimension presentations: angle,
-// length, radius, diameter
+//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 VDimBuilder(Draw_Interpretor& theDi, Standard_Integer theArgsNb, const char** theArgs)
+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)
{
- if (theArgsNb < 2)
- {
- std::cerr << theArgs[0] << ": command argument is required. Type help for more information.\n";
- return 1;
- }
+ theIsCustomPlane = Standard_False;
+ theIsCustomFlyout = Standard_False;
- // Parse parameters
- TCollection_AsciiString aDimType(theArgs[1]);
- AIS_KindOfDimension aKindOfDimension;
- if (aDimType == "length")
- {
- aKindOfDimension = AIS_KOD_LENGTH;
- }
- else if (aDimType == "angle")
+ // Begin from the second parameter: the first on eis dimension name
+ for (Standard_Integer anIt = theStartIndex; anIt < theArgNum; ++anIt)
{
- aKindOfDimension = AIS_KOD_PLANEANGLE;
- }
- else if (aDimType == "radius")
- {
- aKindOfDimension = AIS_KOD_RADIUS;
- }
- 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";
- 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;
+ TCollection_AsciiString aParam (theArgVec[anIt]);
+ aParam.LowerCase();
- 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))
+ if (aParam.Search ("-") == -1)
{
- aParamName.LowerCase();
- aParamValue.LowerCase();
+ continue;
+ }
- if (aParamName == "text")
+ // 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)
{
- anAspect->MakeText3d (aParamValue == "3d");
+ std::cerr << "Error: unknown parameter '" << aParam << "'\n";
+ return 1;
}
- else if (aParamName == "name")
- {
- if (aParamValue.IsEmpty())
- {
- std::cerr << theArgs[0] << ": no name for dimension.\n";
- return 1;
- }
- aName = aParamValue;
- }
- else if (aParamName == "plane")
+ do
{
- 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")
+ anIt++;
+ TCollection_AsciiString anArgString = theArgVec[anIt];
+ Handle(AIS_InteractiveObject) anAISObject;
+ Standard_CString aStr = anArgString.ToCString();
+ TopoDS_Shape aShape = DBRep::Get (aStr);
+ if (!aShape.IsNull())
{
- aWorkingPlane = gp_Pln (gp_Ax3 (gp::YOZ()));
+ anAISObject = new AIS_Shape (aShape);
}
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)
+ if (!GetMapOfAIS().IsBound2 (anArgString))
{
- aValue.Trunc (aSeparatorPos - 1);
- aParamValue.Remove (aSeparatorPos, 1);
+ std::cerr << "Error: shape with name '" << aStr << "' is not found.\n";
+ return 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")
+ anAISObject = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anArgString));
+ if (anAISObject.IsNull())
{
- 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";
+ std::cerr << "Error: " << aStr <<" is not a shape.\n";
return 1;
}
}
+ theShapeList->Append (anAISObject);
}
- else if (aParamName == "flyout")
+ while (anIt + 1 < theArgNum && theArgVec[anIt + 1][0] != '-');
+ }
+ else if (aParam.IsEqual ("-text"))
+ {
+ do
{
- if (!aParamValue.IsRealValue())
+ anIt++;
+ TCollection_AsciiString aValue (theArgVec[anIt]);
+ aValue.LowerCase();
+ if (aValue.IsEqual ("3d"))
{
- std::cerr << theArgs[0] << ": numeric value expected for flyout.\n";
- return 1;
+ theAspect->MakeText3d (Standard_True);
}
-
- aCustomFlyout = aParamValue.RealValue();
-
- isCustomFlyout = Standard_True;
- }
- else if (aParamName == "arrows")
- {
- if (aParamValue == "external")
+ 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"))
{
- anAspect->SetArrowOrientation (Prs3d_DAO_External);
+ theAspect->MakeTextShaded (Standard_True);
}
- else if (aParamValue == "internal")
+ else if (aValue.IsIntegerValue()) // text size
{
- anAspect->SetArrowOrientation (Prs3d_DAO_Internal);
+ theAspect->TextAspect()->SetHeight (Draw::Atoi (aValue.ToCString()));
}
- else if (aParamValue == "fit")
+ }
+ 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
{
- anAspect->SetArrowOrientation (Prs3d_DAO_Fit);
+ 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 << theArgs[0] << ": unknow parameter: \"" << aParamName << "\".\n";
+ std::cerr << "Error: wrong plane '" << aValue << "'.\n";
return 1;
}
}
- else // Shape
+ else if (aParam.IsEqual ("-flyout"))
{
- if (!GetMapOfAIS().IsBound2 (anArgString))
+ TCollection_AsciiString aParam (theArgVec[++anIt]);
+ if (!aParam.IsRealValue())
{
- std::cerr << theArgs[0] << ": wrong name of shape. May be here is a wrong parameter.\n";
+ std::cerr << "Error: flyout for dimension should be real value.\n";
return 1;
}
- Handle(AIS_InteractiveObject) aShape = Handle(AIS_InteractiveObject)::DownCast (GetMapOfAIS().Find2 (anArgString));
- if (aShape.IsNull())
+ 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 << theArgs[0] << ": wrong name of shape. Not a shape.\n";
+ std::cerr << "Error: extension size for dimension should be real value.\n";
return 1;
}
-
- aShapes.Append (aShape);
+ theAspect->SetExtensionSize (Draw::Atof (aParam.ToCString()));
+ }
+ else
+ {
+ std::cerr << "Error: unknown parameter '" << aParam << "'.\n";
+ return 1;
}
}
- if (aName.IsEmpty())
+ 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)
+{
+ if (theArgsNb < 2)
+ {
+ std::cerr << "Error: wrong number of arguments.\n";
+ return 1;
+ }
+
+ // Parse parameters
+ 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")
+ {
+ aKindOfDimension = AIS_KOD_LENGTH;
+ }
+ else if (aDimType == "-angle")
+ {
+ aKindOfDimension = AIS_KOD_PLANEANGLE;
+ }
+ else if (aDimType == "-radius")
+ {
+ aKindOfDimension = AIS_KOD_RADIUS;
+ }
+ else if (aDimType == "-diameter" || aDimType == "-diam")
+ {
+ aKindOfDimension = AIS_KOD_DIAMETER;
+ }
+ else
{
- std::cerr << theArgs[0] << ": no name for dimension.\n";
+ std::cerr << "Error: wrong type of dimension.\n";
return 1;
}
+
+ ParseDimensionParams (theArgsNb, theArgs, 3,
+ anAspect,isPlaneCustom,aWorkingPlane,
+ isCustomFlyout,aCustomFlyout, &aShapes);
+
// Build dimension
Handle(AIS_Dimension) aDim;
switch (aKindOfDimension)
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
break;
}
-
case AIS_KOD_PLANEANGLE:
{
if (aShapes.Extent() == 1 && aShapes.First()->Type()==AIS_KOI_Shape)
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
{
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
{
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
{
break;
}
-
default:
{
std::cerr << theArgs[0] << ": wrong type of dimension. Type help for more information.\n";
}
}
+ // 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)
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;
}
//=======================================================================
//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)
{
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";
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();
-
- 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;
- }
-
- 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();
+ aDim->SetCustomPlane (aWorkingPlane);
+ }
- 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;
- }
+ if (isCustomFlyout)
+ {
+ aDim->SetFlyout (aCustomFlyout);
+ }
- 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;
}
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);
__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);
}