From 046a1c9dd9cd3466853678e32ca5ad7870c5d116 Mon Sep 17 00:00:00 2001 From: aba Date: Thu, 8 Oct 2015 17:44:02 +0300 Subject: [PATCH] 0026754: Visualization - provide API to display AIS_Trihedron presentation without axes labels: - added ToDrawLabels option to Prs3d_DatumAspect, by default it is set to true - AIS_Trihedron (uses DsgPrs_DatumPrs) and AIS_Axis: labels are drawn if ToDrawLabels option in the datum aspect is enabled --- src/AIS/AIS_Axis.cxx | 7 +- src/AIS/AIS_Trihedron.cxx | 35 +++-- src/AIS/AIS_Trihedron.hxx | 7 +- src/DsgPrs/DsgPrs_DatumPrs.cxx | 18 ++- src/Prs3d/Prs3d_DatumAspect.cxx | 42 ++++-- src/Prs3d/Prs3d_DatumAspect.hxx | 14 +- src/ViewerTest/ViewerTest_ObjectCommands.cxx | 128 +++++++++++++++---- tests/bugs/vis/bug26754 | 31 +++++ 8 files changed, 212 insertions(+), 70 deletions(-) create mode 100644 tests/bugs/vis/bug26754 diff --git a/src/AIS/AIS_Axis.cxx b/src/AIS/AIS_Axis.cxx index 05b1fb30a4..a1300ba373 100644 --- a/src/AIS/AIS_Axis.cxx +++ b/src/AIS/AIS_Axis.cxx @@ -177,8 +177,11 @@ void AIS_Axis::Compute(const Handle(PrsMgr_PresentationManager3d)&, GeomAdaptor_Curve curv(myComponent); StdPrs_Curve::Add(aPresentation,curv,myDrawer); } - else { - DsgPrs_XYZAxisPresentation::Add(aPresentation,myLineAspect,myDir,myVal,myText,myPfirst,myPlast); + else + { + DsgPrs_XYZAxisPresentation::Add (aPresentation,myLineAspect,myDir,myVal, + myDrawer->DatumAspect()->ToDrawLabels() ? myText : "", + myPfirst, myPlast); } } diff --git a/src/AIS/AIS_Trihedron.cxx b/src/AIS/AIS_Trihedron.cxx index 34682dbd0e..a966a4424c 100644 --- a/src/AIS/AIS_Trihedron.cxx +++ b/src/AIS/AIS_Trihedron.cxx @@ -62,14 +62,13 @@ //purpose : //======================================================================= AIS_Trihedron::AIS_Trihedron(const Handle(Geom_Axis2Placement)& aComponent): -myComponent(aComponent), -myHasOwnSize(Standard_False), -myHasOwnTextColor(Standard_False), -myHasOwnArrowColor(Standard_False) - -{ LoadSubObjects();} - - +myComponent (aComponent), +myHasOwnSize (Standard_False), +myHasOwnTextColor (Standard_False), +myHasOwnArrowColor (Standard_False) +{ + LoadSubObjects(); +} //======================================================================= //function : SetComponent @@ -182,7 +181,10 @@ Standard_Real AIS_Trihedron::Size() const Handle(AIS_Axis) AIS_Trihedron::XAxis() const { Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[1]); - if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_XAxis); + if (anAxis.IsNull()) + { + anAxis = new AIS_Axis (myComponent,AIS_TOAX_XAxis); + } return anAxis; } @@ -193,7 +195,11 @@ Handle(AIS_Axis) AIS_Trihedron::XAxis() const Handle(AIS_Axis) AIS_Trihedron::YAxis() const { Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[2]); - if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_YAxis); + if (anAxis.IsNull()) + { + anAxis = new AIS_Axis (myComponent,AIS_TOAX_YAxis); + } + return anAxis; } @@ -204,7 +210,10 @@ Handle(AIS_Axis) AIS_Trihedron::YAxis() const Handle(AIS_Axis) AIS_Trihedron::Axis() const { Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[3]); - if (anAxis.IsNull()) anAxis = new AIS_Axis (myComponent,AIS_TOAX_ZAxis); + if (anAxis.IsNull()) + { + anAxis = new AIS_Axis (myComponent,AIS_TOAX_ZAxis); + } return anAxis; } @@ -366,9 +375,7 @@ void AIS_Trihedron::ComputeSelection(const Handle(SelectMgr_Selection)& aSelecti Handle(AIS_Axis) anAxis = Handle(AIS_Axis)::DownCast(myShapes[anIdx]); Handle(Prs3d_Drawer) aDrawer = anAxis->Attributes(); Handle(Prs3d_DatumAspect) aDatum = myDrawer->DatumAspect(); - aDrawer->DatumAspect()->SetAxisLength (aDatum->FirstAxisLength(), - aDatum->SecondAxisLength(), - aDatum->ThirdAxisLength()); + aDrawer->SetDatumAspect (aDatum); anAxisType = anAxis->TypeOfAxis(); anAxis->SetAxis2Placement (myComponent, anAxisType); diff --git a/src/AIS/AIS_Trihedron.hxx b/src/AIS/AIS_Trihedron.hxx index 8b02b8a02d..7cbe30c5eb 100644 --- a/src/AIS/AIS_Trihedron.hxx +++ b/src/AIS/AIS_Trihedron.hxx @@ -168,9 +168,6 @@ public: //! Removes the non-default settings for width set in SetWidth. Standard_EXPORT void UnsetWidth() Standard_OVERRIDE; - - - DEFINE_STANDARD_RTTI(AIS_Trihedron,AIS_InteractiveObject) protected: @@ -189,6 +186,8 @@ private: Standard_EXPORT void LoadSubObjects(); +protected: + Handle(Geom_Axis2Placement) myComponent; Handle(AIS_InteractiveObject) myShapes[7]; Standard_Boolean myHasOwnSize; @@ -196,8 +195,6 @@ private: Quantity_NameOfColor myOwnTextColor; Standard_Boolean myHasOwnArrowColor; Quantity_NameOfColor myOwnArrowColor; - - }; diff --git a/src/DsgPrs/DsgPrs_DatumPrs.cxx b/src/DsgPrs/DsgPrs_DatumPrs.cxx index eb5d8a7a36..be964ee45d 100755 --- a/src/DsgPrs/DsgPrs_DatumPrs.cxx +++ b/src/DsgPrs/DsgPrs_DatumPrs.cxx @@ -45,6 +45,8 @@ void DsgPrs_DatumPrs::Add (const Handle(Prs3d_Presentation)& thePresentation, Quantity_Length anAxisLength; Quantity_Length anArrowAngle = theDrawer->ArrowAspect()->Angle(); + const Standard_Boolean toDrawLabels = theDrawer->DatumAspect()->ToDrawLabels(); + Handle(Graphic3d_ArrayOfSegments) aPrims; if (aDatumAspect->DrawFirstAndSecondAxis()) { @@ -61,7 +63,10 @@ void DsgPrs_DatumPrs::Add (const Handle(Prs3d_Presentation)& thePresentation, Prs3d_Arrow::Draw(thePresentation,aPoint1,aXDir,anArrowAngle,anAxisLength/10.); aGroup->SetPrimitivesAspect(theDrawer->TextAspect()->Aspect()); Graphic3d_Vertex aVertex1(aPoint1.X(),aPoint1.Y(),aPoint1.Z()); - aGroup->Text(Standard_CString("X"), aVertex1,16.); + if (toDrawLabels) + { + aGroup->Text (Standard_CString ("X"), aVertex1, 16.0); + } anAxisLength = aDatumAspect->SecondAxisLength(); const gp_Pnt aPoint2(anOrigin.XYZ() + aYDir.XYZ()*anAxisLength); @@ -76,7 +81,10 @@ void DsgPrs_DatumPrs::Add (const Handle(Prs3d_Presentation)& thePresentation, Prs3d_Arrow::Draw(thePresentation,aPoint2,aYDir,anArrowAngle,anAxisLength/10.); aGroup->SetPrimitivesAspect(theDrawer->TextAspect()->Aspect()); Graphic3d_Vertex aVertex2(aPoint2.X(),aPoint2.Y(),aPoint2.Z()); - aGroup->Text(Standard_CString("Y"), aVertex2,16.); + if (toDrawLabels) + { + aGroup->Text (Standard_CString ("Y"), aVertex2, 16.0); + } } if (aDatumAspect->DrawThirdAxis()) { @@ -93,7 +101,9 @@ void DsgPrs_DatumPrs::Add (const Handle(Prs3d_Presentation)& thePresentation, Prs3d_Arrow::Draw(thePresentation,aPoint3,aZDir,anArrowAngle,anAxisLength/10.); aGroup->SetPrimitivesAspect(theDrawer->TextAspect()->Aspect()); Graphic3d_Vertex aVertex3(aPoint3.X(),aPoint3.Y(),aPoint3.Z()); - aGroup->Text(Standard_CString("Z"), aVertex3,16.); + if (toDrawLabels) + { + aGroup->Text (Standard_CString ("Z"), aVertex3, 16.0); + } } } - diff --git a/src/Prs3d/Prs3d_DatumAspect.cxx b/src/Prs3d/Prs3d_DatumAspect.cxx index d8c00103ad..474b7151cf 100644 --- a/src/Prs3d/Prs3d_DatumAspect.cxx +++ b/src/Prs3d/Prs3d_DatumAspect.cxx @@ -17,19 +17,17 @@ #include #include -Prs3d_DatumAspect::Prs3d_DatumAspect () { - - myFirstAxisAspect = new Prs3d_LineAspect - (Quantity_NOC_PEACHPUFF,Aspect_TOL_SOLID,1.); - mySecondAxisAspect = new Prs3d_LineAspect - (Quantity_NOC_PEACHPUFF,Aspect_TOL_SOLID,1.); - myThirdAxisAspect = new Prs3d_LineAspect - (Quantity_NOC_PEACHPUFF,Aspect_TOL_SOLID,1.); - myDrawFirstAndSecondAxis = Standard_True; - myDrawThirdAxis = Standard_True; - myFirstAxisLength = 10.; - mySecondAxisLength = 10.; - myThirdAxisLength = 10.; +Prs3d_DatumAspect::Prs3d_DatumAspect() +: myDrawFirstAndSecondAxis (Standard_True), + myDrawThirdAxis (Standard_True), + myToDrawLabels (Standard_True), + myFirstAxisLength (10.0), + mySecondAxisLength (10.0), + myThirdAxisLength (10.0) +{ + myFirstAxisAspect = new Prs3d_LineAspect (Quantity_NOC_PEACHPUFF,Aspect_TOL_SOLID, 1.0); + mySecondAxisAspect = new Prs3d_LineAspect (Quantity_NOC_PEACHPUFF,Aspect_TOL_SOLID, 1.0); + myThirdAxisAspect = new Prs3d_LineAspect (Quantity_NOC_PEACHPUFF,Aspect_TOL_SOLID, 1.0); } Handle(Prs3d_LineAspect) Prs3d_DatumAspect::FirstAxisAspect() const { @@ -96,3 +94,21 @@ Quantity_Length Prs3d_DatumAspect::ThirdAxisLength () const { return myThirdAxisLength; } + +//======================================================================= +//function : SetToDrawLabels +//purpose : +//======================================================================= +void Prs3d_DatumAspect::SetToDrawLabels (const Standard_Boolean theToDraw) +{ + myToDrawLabels = theToDraw; +} + +//======================================================================= +//function : ToDrawLabels +//purpose : +//======================================================================= +Standard_Boolean Prs3d_DatumAspect::ToDrawLabels() const +{ + return myToDrawLabels; +} diff --git a/src/Prs3d/Prs3d_DatumAspect.hxx b/src/Prs3d/Prs3d_DatumAspect.hxx index 71c8e22953..60ae8a4189 100644 --- a/src/Prs3d/Prs3d_DatumAspect.hxx +++ b/src/Prs3d/Prs3d_DatumAspect.hxx @@ -36,7 +36,6 @@ class Prs3d_DatumAspect : public Prs3d_BasicAspect public: - //! An empty framework to define the display of datums. Standard_EXPORT Prs3d_DatumAspect(); @@ -73,29 +72,26 @@ public: //! Returns the length of the displayed third axis. Standard_EXPORT Quantity_Length ThirdAxisLength() const; + //! Sets option to draw or not to draw text labels for axes + Standard_EXPORT void SetToDrawLabels (const Standard_Boolean theToDraw); - + //! @return true if axes labels are drawn + Standard_EXPORT Standard_Boolean ToDrawLabels() const; DEFINE_STANDARD_RTTI(Prs3d_DatumAspect,Prs3d_BasicAspect) -protected: - - - - private: - Handle(Prs3d_LineAspect) myFirstAxisAspect; Handle(Prs3d_LineAspect) mySecondAxisAspect; Handle(Prs3d_LineAspect) myThirdAxisAspect; Standard_Boolean myDrawFirstAndSecondAxis; Standard_Boolean myDrawThirdAxis; + Standard_Boolean myToDrawLabels; Quantity_Length myFirstAxisLength; Quantity_Length mySecondAxisLength; Quantity_Length myThirdAxisLength; - }; diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index a83f43d849..e65b696ca5 100644 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -128,6 +128,7 @@ #include #include +#include #include #include #include @@ -136,6 +137,7 @@ #include #include +#include #ifdef _WIN32 # define _CRT_SECURE_NO_DEPRECATE @@ -241,47 +243,126 @@ static int VTrihedron2D (Draw_Interpretor& di, Standard_Integer argc, const char //Draw arg : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] //============================================================================== -static int VTrihedron (Draw_Interpretor& theDi, +static int VTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const char** theArgVec) { - if (theArgsNb != 2 && theArgsNb != 5 && theArgsNb != 11) + if (theArgsNb < 2 || theArgsNb > 11) { - theDi << theArgVec[0] << " Syntax error\n"; + std::cout << theArgVec[0] << " syntax error\n"; return 1; } + // Parse parameters + NCollection_DataMap aMapOfArgs; + TCollection_AsciiString aParseKey; + for (Standard_Integer anArgIt = 1; anArgIt < theArgsNb; ++anArgIt) + { + TCollection_AsciiString anArg (theArgVec [anArgIt]); + + if (anArg.Value (1) == '-' && !anArg.IsRealValue()) + { + aParseKey = anArg; + aParseKey.Remove (1); + aParseKey.LowerCase(); + aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString); + continue; + } + + if (aParseKey.IsEmpty()) + { + continue; + } + + aMapOfArgs(aParseKey)->Append (anArg); + } + + // Check parameters + if ( (aMapOfArgs.IsBound ("xaxis") && !aMapOfArgs.IsBound ("zaxis")) + || (!aMapOfArgs.IsBound ("xaxis") && aMapOfArgs.IsBound ("zaxis")) ) + { + std::cout << theArgVec[0] << " error: -xaxis and -yaxis parameters are to set together.\n"; + return 1; + } + + for (NCollection_DataMap::Iterator aMapIt (aMapOfArgs); + aMapIt.More(); aMapIt.Next()) + { + const TCollection_AsciiString& aKey = aMapIt.Key(); + const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value(); + + // Bool key, without arguments + if (aKey.IsEqual ("hidelabels") && anArgs->IsEmpty()) + { + continue; + } + + if ( (aKey.IsEqual ("xaxis") || aKey.IsEqual ("zaxis") || aKey.IsEqual ("origin")) && anArgs->Length() == 3 + && anArgs->Value(1).IsRealValue() && anArgs->Value(2).IsRealValue() && anArgs->Value(3).IsRealValue() ) + { + continue; + } + } + + // Process parameters gp_Pnt anOrigin (0.0, 0.0, 0.0); gp_Dir aDirZ = gp::DZ(); gp_Dir aDirX = gp::DX(); - Standard_Integer anArgIter = 2; // 1st is an IO name - if (anArgIter < theArgsNb) - { - anOrigin.SetX (Draw::Atof (theArgVec[anArgIter++])); - anOrigin.SetY (Draw::Atof (theArgVec[anArgIter++])); - anOrigin.SetZ (Draw::Atof (theArgVec[anArgIter++])); - if (anArgIter < theArgsNb) - { - Standard_Real aX = Draw::Atof (theArgVec[anArgIter++]); - Standard_Real aY = Draw::Atof (theArgVec[anArgIter++]); - Standard_Real aZ = Draw::Atof (theArgVec[anArgIter++]); - aDirZ.SetCoord (aX, aY, aZ); - aX = Draw::Atof (theArgVec[anArgIter++]); - aY = Draw::Atof (theArgVec[anArgIter++]); - aZ = Draw::Atof (theArgVec[anArgIter++]); - aDirX.SetCoord (aX, aY, aZ); - } + Handle(TColStd_HSequenceOfAsciiString) aValues; + + if (aMapOfArgs.Find ("origin", aValues)) + { + anOrigin.SetX (aValues->Value(1).RealValue()); + anOrigin.SetY (aValues->Value(2).RealValue()); + anOrigin.SetZ (aValues->Value(3).RealValue()); + } + + Handle(TColStd_HSequenceOfAsciiString) aValues2; + if (aMapOfArgs.Find ("xaxis", aValues) && aMapOfArgs.Find ("zaxis", aValues2)) + { + Standard_Real aX = aValues->Value(1).RealValue(); + Standard_Real aY = aValues->Value(2).RealValue(); + Standard_Real aZ = aValues->Value(3).RealValue(); + aDirX.SetCoord (aX, aY, aZ); + + aX = aValues->Value(1).RealValue(); + aY = aValues->Value(2).RealValue(); + aZ = aValues->Value(3).RealValue(); + aDirZ.SetCoord (aX, aY, aZ); } if (!aDirZ.IsNormal (aDirX, M_PI / 180.0)) { - theDi << theArgVec[0] << " - VectorX is not normal to VectorZ\n"; + std::cout << theArgVec[0] << " error - VectorX is not normal to VectorZ\n"; return 1; } Handle(Geom_Axis2Placement) aPlacement = new Geom_Axis2Placement (anOrigin, aDirZ, aDirX); Handle(AIS_Trihedron) aShape = new AIS_Trihedron (aPlacement); + + if (aMapOfArgs.Find ("hidelabels", aValues)) + { + const Handle(Prs3d_Drawer)& aDrawer = aShape->Attributes(); + + if(!aDrawer->HasOwnDatumAspect()) + { + Handle(Prs3d_DatumAspect) aDefAspect = ViewerTest::GetAISContext()->DefaultDrawer()->DatumAspect(); + + Handle(Prs3d_DatumAspect) aDatumAspect = new Prs3d_DatumAspect(); + aDatumAspect->FirstAxisAspect()->SetAspect (aDefAspect->FirstAxisAspect()->Aspect()); + aDatumAspect->SecondAxisAspect()->SetAspect (aDefAspect->SecondAxisAspect()->Aspect()); + aDatumAspect->ThirdAxisAspect()->SetAspect (aDefAspect->ThirdAxisAspect()->Aspect()); + aDatumAspect->SetAxisLength (aDefAspect->FirstAxisLength(), + aDefAspect->SecondAxisLength(), + aDefAspect->ThirdAxisLength()); + + aDrawer->SetDatumAspect (aDatumAspect); + } + + aDrawer->DatumAspect()->SetToDrawLabels (Standard_False); + } + VDisplayAISObject (theArgVec[1], aShape); return 0; } @@ -6223,8 +6304,9 @@ void ViewerTest::ObjectCommands(Draw_Interpretor& theCommands) { const char *group ="AISObjects"; theCommands.Add("vtrihedron", - "vtrihedron : vtrihedron name [Xo] [Yo] [Zo] [Zu] [Zv] [Zw] [Xu] [Xv] [Xw] " - "\n\t\t: Creates a new *AIS_Trihedron* object. If no argument is set, the default trihedron (0XYZ) is created.", + "vtrihedron : vtrihedron name [ -origin x y z ] [ -zaxis u v w -xaxis u v w ] [ -hidelabels ]" + "\n\t\t: Creates a new *AIS_Trihedron* object. If no argument is set, the default trihedron (0XYZ) is created." + "\n\t\t: -hidelabels allows to draw trihedron without axes labels. By default, they are displayed.", __FILE__,VTrihedron,group); theCommands.Add("vtri2d", diff --git a/tests/bugs/vis/bug26754 b/tests/bugs/vis/bug26754 new file mode 100644 index 0000000000..3b172e0f09 --- /dev/null +++ b/tests/bugs/vis/bug26754 @@ -0,0 +1,31 @@ +puts "================================================================" +puts "CR26754" +puts "Visualization - provide API to display AIS_Trihedron presentation without axes labels" +puts "================================================================" +puts "" + +set anImage1 $imagedir/${casename}_1.png +set anImage2 $imagedir/${casename}_2.png +set anImage3 $imagedir/${casename}_3.png + +vinit +vclear +vaxo + +vtrihedron t -hidelabels +vzoom 4 + +vdump $anImage1 + +set anX 204 +set anY 100 + +vselect $anX $anY + +vdump $anImage2 + +vselmode 2 1 + +vselect $anX $anY + +vdump $anImage3 \ No newline at end of file