From 1f3c5058f27ddcbc23af3b05820e4433bb1009db Mon Sep 17 00:00:00 2001 From: mkrylova Date: Wed, 16 Jun 2021 16:21:17 +0300 Subject: [PATCH] 0032389: Visualization, AIS_Axis - simple ray creation and displaying - Added constructor to create axis by gp_Ax1 - Added possibility to display axis as ray - Added function SetDisplayAspect to set required visualization parameters --- src/AIS/AIS_Axis.cxx | 43 +++++++++++++++++--- src/AIS/AIS_Axis.hxx | 14 +++++-- src/ViewerTest/ViewerTest_ViewerCommands.cxx | 24 +++-------- 3 files changed, 54 insertions(+), 27 deletions(-) diff --git a/src/AIS/AIS_Axis.cxx b/src/AIS/AIS_Axis.cxx index 21977f796a..2be1c37c20 100644 --- a/src/AIS/AIS_Axis.cxx +++ b/src/AIS/AIS_Axis.cxx @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -56,7 +57,6 @@ myIsXYZAxis(Standard_False) gp_Dir thedir = myComponent->Position().Direction(); gp_Pnt loc = myComponent->Position().Location(); -//POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH"); Standard_Real aLength = UnitsAPI::AnyToLS(250000., "mm"); myPfirst = loc.XYZ() + aLength*thedir.XYZ(); myPlast = loc.XYZ() - aLength*thedir.XYZ(); @@ -73,7 +73,6 @@ myTypeOfAxis(anAxisType), myIsXYZAxis(Standard_True) { Handle (Prs3d_DatumAspect) DA = new Prs3d_DatumAspect(); -//POP Standard_Real aLength = UnitsAPI::CurrentToLS (100. ,"LENGTH"); Standard_Real aLength; try { aLength = UnitsAPI::AnyToLS(100. ,"mm"); @@ -104,12 +103,36 @@ AIS_Axis::AIS_Axis(const Handle(Geom_Axis1Placement)& anAxis) gp_Dir thedir = myComponent->Position().Direction(); gp_Pnt loc = myComponent->Position().Location(); -//POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH"); Standard_Real aLength = UnitsAPI::AnyToLS(250000. ,"mm"); myPfirst = loc.XYZ() + aLength*thedir.XYZ(); myPlast = loc.XYZ() - aLength*thedir.XYZ(); } +//======================================================================= +//function : AIS_Axis +//purpose : +//======================================================================= +AIS_Axis::AIS_Axis (const gp_Ax1& theAxis, const Standard_Real theLength) +: myComponent (new Geom_Line (theAxis)), + myTypeOfAxis (AIS_TOAX_ZAxis), + myIsXYZAxis (Standard_True) +{ + myDir = theAxis.Direction(); + myPfirst = theAxis.Location(); + if (theLength <= 0 && theLength != -1) + { + throw Standard_NumericError ("AIS_Axis::AIS_Axis : invalid value for theLength parameter"); + } + myVal = (theLength == -1) ? UnitsAPI::AnyToLS (250000., "mm") : theLength; + myPlast = myPfirst.XYZ() + myVal * myDir.XYZ(); + SetInfiniteState(); + Handle(Prs3d_DatumAspect) aDatumAspect = new Prs3d_DatumAspect(); + aDatumAspect->SetDrawLabels (Standard_False); + myDrawer->SetDatumAspect (aDatumAspect); + Handle(Prs3d_LineAspect) aDefaultLineAspect = new Prs3d_LineAspect (Quantity_NOC_RED, Aspect_TOL_SOLID, 1.0); + myDrawer->SetLineAspect (aDefaultLineAspect); + myLineAspect = myDrawer->LineAspect(); +} //======================================================================= //function : SetComponent @@ -125,7 +148,6 @@ void AIS_Axis::SetComponent(const Handle(Geom_Line)& aComponent) gp_Dir thedir = myComponent->Position().Direction(); gp_Pnt loc = myComponent->Position().Location(); -//POP Standard_Real aLength = UnitsAPI::CurrentToLS (250000. ,"LENGTH"); Standard_Real aLength = UnitsAPI::AnyToLS(250000. ,"mm"); myPfirst = loc.XYZ() + aLength*thedir.XYZ(); myPlast = loc.XYZ() - aLength*thedir.XYZ(); @@ -166,7 +188,7 @@ void AIS_Axis::Compute (const Handle(PrsMgr_PresentationManager)& , const Standard_Integer ) { thePrs->SetInfiniteState (myInfiniteState); - thePrs->SetDisplayPriority(5); + thePrs->SetDisplayPriority (5); if (!myIsXYZAxis) { GeomAdaptor_Curve curv (myComponent); @@ -230,6 +252,17 @@ void AIS_Axis::SetWidth(const Standard_Real aValue) SynchronizeAspects(); } +//======================================================================= +//function : SetDisplayAspect +//purpose : +//======================================================================= +void AIS_Axis::SetDisplayAspect (const Handle(Prs3d_LineAspect)& theNewLineAspect) +{ + myDrawer->SetLineAspect (theNewLineAspect); + myLineAspect = myDrawer->LineAspect(); + SetColor (theNewLineAspect->Aspect()->Color()); +} + //======================================================================= //function : ComputeFields //purpose : diff --git a/src/AIS/AIS_Axis.hxx b/src/AIS/AIS_Axis.hxx index 725464c39a..23a928c2fc 100644 --- a/src/AIS/AIS_Axis.hxx +++ b/src/AIS/AIS_Axis.hxx @@ -49,6 +49,11 @@ public: //! Initializes the axis1 position anAxis. Standard_EXPORT AIS_Axis(const Handle(Geom_Axis1Placement)& anAxis); + //! Initializes the ray as axis with start point and direction + //! @param[in] theAxis Start point and direction of the ray + //! @param[in] theLength Optional length of the ray (ray is infinite by default). + Standard_EXPORT AIS_Axis (const gp_Ax1& theAxis, const Standard_Real theLength = -1); + //! Returns the axis entity aComponent and identifies it //! as a component of a shape. const Handle(Geom_Line)& Component() const { return myComponent; } @@ -89,11 +94,14 @@ public: virtual AIS_KindOfInteractive Type() const Standard_OVERRIDE { return AIS_KindOfInteractive_Datum; } Standard_EXPORT void SetColor (const Quantity_Color& aColor) Standard_OVERRIDE; - + Standard_EXPORT void SetWidth (const Standard_Real aValue) Standard_OVERRIDE; - + + //! Set required visualization parameters. + Standard_EXPORT void SetDisplayAspect (const Handle(Prs3d_LineAspect)& theNewDatumAspect); + Standard_EXPORT void UnsetColor() Standard_OVERRIDE; - + Standard_EXPORT void UnsetWidth() Standard_OVERRIDE; private: diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index dbed9e289a..ea30197f9c 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -7224,16 +7224,9 @@ static Standard_Integer VSelectByAxis (Draw_Interpretor& theDI, Quantity_Color anAxisColor = Quantity_NOC_GREEN; Handle(Geom_Axis2Placement) anAx2Axis = new Geom_Axis2Placement (gp_Ax2(anAxisLocation, anAxisDirection)); - Handle(AIS_Axis) anAISAxis = new AIS_Axis (anAx2Axis, AIS_TOAX_ZAxis); - const Handle(Prs3d_Drawer)& anAxisDrawer = anAISAxis->Attributes(); - anAxisDrawer->SetOwnDatumAspects(); - Standard_Real aLength = UnitsAPI::AnyToLS (250000., "mm"); - anAxisDrawer->DatumAspect()->SetAxisLength (aLength, aLength, aLength); - anAxisDrawer->DatumAspect()->SetDrawLabels (false); - anAxisDrawer->DatumAspect()->SetDrawArrows (true); - anAISAxis->SetColor (Quantity_NOC_GREEN); - anAISAxis->SetAxis2Placement (anAx2Axis, AIS_TOAX_ZAxis); // This is workaround to update axis length - ViewerTest::Display (TCollection_AsciiString(aName) + "_axis", anAISAxis, false); + Handle(AIS_Axis) anAISAxis = new AIS_Axis (gp_Ax1 (anAxisLocation, anAxisDirection)); + anAISAxis->SetColor (anAxisColor); + ViewerTest::Display (TCollection_AsciiString (aName) + "_axis", anAISAxis, false); // Display axis start point Handle(AIS_Point) anAISStartPnt = new AIS_Point (new Geom_CartesianPoint (anAxisLocation)); @@ -7253,16 +7246,9 @@ static Standard_Integer VSelectByAxis (Draw_Interpretor& theDI, Standard_Real aNormalLength = aNormalLengths.Value (anIndex + 1); if (aNormal.SquareModulus() > ShortRealEpsilon()) { - Handle(Geom_Axis2Placement) anAx2Normal = - new Geom_Axis2Placement(gp_Ax2(aPoint, gp_Dir((Standard_Real )aNormal.x(), (Standard_Real )aNormal.y(), (Standard_Real )aNormal.z()))); - Handle(AIS_Axis) anAISNormal = new AIS_Axis (anAx2Normal, AIS_TOAX_ZAxis); - const Handle(Prs3d_Drawer)& aNormalDrawer = anAISNormal->Attributes(); - aNormalDrawer->SetOwnDatumAspects(); - aNormalDrawer->DatumAspect()->SetAxisLength (aNormalLength, aNormalLength, aNormalLength); - aNormalDrawer->DatumAspect()->SetDrawLabels (false); - aNormalDrawer->DatumAspect()->SetDrawArrows (true); + gp_Dir aNormalDir ((Standard_Real)aNormal.x(), (Standard_Real)aNormal.y(), (Standard_Real)aNormal.z()); + Handle(AIS_Axis) anAISNormal = new AIS_Axis (gp_Ax1 (aPoint, aNormalDir), aNormalLength); anAISNormal->SetColor (Quantity_NOC_BLUE); - anAISNormal->SetAxis2Placement (anAx2Normal, AIS_TOAX_ZAxis); // This is workaround to update axis length anAISNormal->SetInfiniteState (false); ViewerTest::Display (TCollection_AsciiString(aName) + "_normal_" + anIndex, anAISNormal, false); } -- 2.39.5