From 536d98e2247a945587b7e974e05eecba311c7fe4 Mon Sep 17 00:00:00 2001 From: kgv Date: Fri, 3 Apr 2015 21:41:52 +0300 Subject: [PATCH] 0025974: Visualization - fix misprints in method naming of Graphic3d_GraduatedTrihedron V3d_View::GetGraduatedTrihedron() - return configuration structure directly. OpenGl_View::TriedronDisplay() - do not re-create trihedron on each Display call. OpenGl_Trihedron::Setup() - eliminate global variables. OpenGl_PrimitiveArray::buildVBO() - release old VBOs before initialization. ViewerTest.hxx - move out package header from .cdl file. ViewerTest::ParseColor() - add new method to parse color arguments in common way. vzbufftrihedron - improve command syntax. vgraduatedtrihedron - add options -drawgrid and -drawaxes. --- .../Graphic3d_GraduatedTrihedron.hxx | 48 +-- src/Graphic3d/Graphic3d_GraphicDriver.cdl | 1 + src/OpenGl/OpenGl_AspectLine.hxx | 5 +- src/OpenGl/OpenGl_GraduatedTrihedron.cxx | 184 ++++----- src/OpenGl/OpenGl_GraduatedTrihedron.hxx | 53 ++- src/OpenGl/OpenGl_GraphicDriver.cxx | 25 +- src/OpenGl/OpenGl_GraphicDriver.hxx | 8 +- src/OpenGl/OpenGl_PrimitiveArray.cxx | 1 + src/OpenGl/OpenGl_PrimitiveArray.hxx | 3 + src/OpenGl/OpenGl_Trihedron.cxx | 252 +++++++------ src/OpenGl/OpenGl_Trihedron.hxx | 59 ++- src/OpenGl/OpenGl_View.cxx | 38 +- src/OpenGl/OpenGl_View.hxx | 16 +- src/OpenGl/OpenGl_View_2.cxx | 8 +- src/V3d/V3d_View.cdl | 5 +- src/V3d/V3d_View_4.cxx | 4 +- src/ViewerTest/FILES | 2 + src/ViewerTest/ViewerTest.cdl | 152 -------- src/ViewerTest/ViewerTest.cxx | 50 +++ src/ViewerTest/ViewerTest.hxx | 212 +++++++++++ src/ViewerTest/ViewerTest_ViewerCommands.cxx | 350 +++++++++++++----- src/Visual3d/Visual3d_View.cdl | 8 +- src/Visual3d/Visual3d_View.cxx | 12 +- tests/bugs/vis/bug22483_2 | 5 +- tests/bugs/vis/bug22483_3 | 6 +- tests/bugs/vis/bug22483_4 | 6 +- tests/bugs/vis/bug23484_1 | 4 +- 27 files changed, 918 insertions(+), 599 deletions(-) create mode 100644 src/ViewerTest/ViewerTest.hxx diff --git a/src/Graphic3d/Graphic3d_GraduatedTrihedron.hxx b/src/Graphic3d/Graphic3d_GraduatedTrihedron.hxx index f9fc58d2a0..13a46a7565 100644 --- a/src/Graphic3d/Graphic3d_GraduatedTrihedron.hxx +++ b/src/Graphic3d/Graphic3d_GraduatedTrihedron.hxx @@ -35,7 +35,7 @@ class Graphic3d_AxisAspect Graphic3d_AxisAspect (const TCollection_ExtendedString theName = "", const Quantity_Color theNameColor = Quantity_NOC_BLACK, const Quantity_Color theColor = Quantity_NOC_BLACK, const Standard_Integer theValuesOffset = 10, const Standard_Integer theNameOffset = 30, - const Standard_Integer theTickmarkNumber = 5, const Standard_Integer theTickmarkLength = 10, + const Standard_Integer theTickmarksNumber = 5, const Standard_Integer theTickmarksLength = 10, const Standard_Boolean theToDrawName = Standard_True, const Standard_Boolean theToDrawValues = Standard_True, const Standard_Boolean theToDrawTickmarks = Standard_True) @@ -44,8 +44,8 @@ class Graphic3d_AxisAspect myToDrawTickmarks (theToDrawTickmarks), myToDrawValues (theToDrawValues), myNameColor (theNameColor), - myTickmarkNumber (theTickmarkNumber), - myTickmarkLength (theTickmarkLength), + myTickmarksNumber (theTickmarksNumber), + myTickmarksLength (theTickmarksLength), myColor (theColor), myValuesOffset (theValuesOffset), myNameOffset (theNameOffset) @@ -57,13 +57,13 @@ public: const TCollection_ExtendedString& Name() const { return myName; } const Standard_Boolean ToDrawName() const { return myToDrawName; } - void SetToDrawName (const Standard_Boolean theToDraw) { myToDrawName = theToDraw; } + void SetDrawName (const Standard_Boolean theToDraw) { myToDrawName = theToDraw; } const Standard_Boolean ToDrawTickmarks() const { return myToDrawTickmarks; } - void SetToDrawTickmarks (const Standard_Boolean theToDraw) { myToDrawTickmarks = theToDraw; } + void SetDrawTickmarks (const Standard_Boolean theToDraw) { myToDrawTickmarks = theToDraw; } const Standard_Boolean ToDrawValues() const { return myToDrawValues; } - void SetToDrawValues (const Standard_Boolean theToDraw) { myToDrawValues = theToDraw; } + void SetDrawValues (const Standard_Boolean theToDraw) { myToDrawValues = theToDraw; } const Quantity_Color& NameColor() const { return myNameColor; } void SetNameColor (const Quantity_Color& theColor) { myNameColor = theColor; } @@ -74,11 +74,11 @@ public: //! Sets color of axis and values void SetColor (const Quantity_Color& theColor) { myColor = theColor; } - const Standard_Integer TickmarkNumber() const { return myTickmarkNumber; } - void SetTickmarkNumber (const Standard_Integer theValue) { myTickmarkNumber = theValue; } + const Standard_Integer TickmarksNumber() const { return myTickmarksNumber; } + void SetTickmarksNumber (const Standard_Integer theValue) { myTickmarksNumber = theValue; } - const Standard_Integer TickmarkLength() const { return myTickmarkLength; } - void SetTickmarkLength (const Standard_Integer theValue) { myTickmarkLength = theValue; } + const Standard_Integer TickmarksLength() const { return myTickmarksLength; } + void SetTickmarksLength (const Standard_Integer theValue) { myTickmarksLength = theValue; } const Standard_Integer ValuesOffset() const { return myValuesOffset; } void SetValuesOffset (const Standard_Integer theValue) { myValuesOffset = theValue; } @@ -96,12 +96,12 @@ protected: Quantity_Color myNameColor; - Standard_Integer myTickmarkNumber; //!< Number of splits along axes - Standard_Integer myTickmarkLength; //!< Length of tickmarks - Quantity_Color myColor; //!< Color of axis and values + Standard_Integer myTickmarksNumber; //!< Number of splits along axes + Standard_Integer myTickmarksLength; //!< Length of tickmarks + Quantity_Color myColor; //!< Color of axis and values - Standard_Integer myValuesOffset; //!< Offset for drawing values - Standard_Integer myNameOffset; //!< Offset for drawing name of axis + Standard_Integer myValuesOffset; //!< Offset for drawing values + Standard_Integer myNameOffset; //!< Offset for drawing name of axis }; //! Defines the class of a graduated trihedron. @@ -118,18 +118,18 @@ public: //! Default constructor //! Constructs the default graduated trihedron with grid, X, Y, Z axes, and tickmarks Graphic3d_GraduatedTrihedron (const TCollection_AsciiString& theNamesFont = "Arial", - const Font_FontAspect& theNameStyle = Font_FA_Bold, const Standard_Integer theNamesSize = 12, + const Font_FontAspect& theNamesStyle = Font_FA_Bold, const Standard_Integer theNamesSize = 12, const TCollection_AsciiString& theValuesFont = "Arial", const Font_FontAspect& theValuesStyle = Font_FA_Regular, const Standard_Integer theValuesSize = 12, - const Standard_ShortReal theArrowLength = 30.0f, const Quantity_Color theGridColor = Quantity_NOC_WHITE, + const Standard_ShortReal theArrowsLength = 30.0f, const Quantity_Color theGridColor = Quantity_NOC_WHITE, const Standard_Boolean theToDrawGrid = Standard_True, const Standard_Boolean theToDrawAxes = Standard_True) : myNamesFont (theNamesFont), - myNamesStyle (theNameStyle), + myNamesStyle (theNamesStyle), myNamesSize (theNamesSize), myValuesFont (theValuesFont), myValuesStyle (theValuesStyle), myValuesSize (theValuesSize), - myArrowLength (theArrowLength), + myArrowsLength (theArrowsLength), myGridColor (theGridColor), myToDrawGrid (theToDrawGrid), myToDrawAxes (theToDrawAxes), @@ -157,17 +157,17 @@ public: return myAxes (theIndex); } - const Standard_ShortReal ArrowLength() const { return myArrowLength; } - void SetArrowLength (const Standard_ShortReal theValue) { myArrowLength = theValue; } + const Standard_ShortReal ArrowsLength() const { return myArrowsLength; } + void SetArrowsLength (const Standard_ShortReal theValue) { myArrowsLength = theValue; } const Quantity_Color& GridColor() const { return myGridColor; } void SetGridColor (const Quantity_Color& theColor) {myGridColor = theColor; } const Standard_Boolean ToDrawGrid() const { return myToDrawGrid; } - void SetToDrawTickmarks (const Standard_Boolean theToDraw) { myToDrawGrid = theToDraw; } + void SetDrawGrid (const Standard_Boolean theToDraw) { myToDrawGrid = theToDraw; } const Standard_Boolean ToDrawAxes() const { return myToDrawAxes; } - void SetToDrawAxes (const Standard_Boolean theToDraw) { myToDrawAxes = theToDraw; } + void SetDrawAxes (const Standard_Boolean theToDraw) { myToDrawAxes = theToDraw; } const TCollection_AsciiString& NamesFont() const { return myNamesFont; } void SetNamesFont (const TCollection_AsciiString& theFont) { myNamesFont = theFont; } @@ -206,7 +206,7 @@ protected: protected: - Standard_ShortReal myArrowLength; + Standard_ShortReal myArrowsLength; Quantity_Color myGridColor; Standard_Boolean myToDrawGrid; diff --git a/src/Graphic3d/Graphic3d_GraphicDriver.cdl b/src/Graphic3d/Graphic3d_GraphicDriver.cdl index 0211cf5800..91fe6973a2 100644 --- a/src/Graphic3d/Graphic3d_GraphicDriver.cdl +++ b/src/Graphic3d/Graphic3d_GraphicDriver.cdl @@ -293,6 +293,7 @@ is ---------------------------------------- ZBufferTriedronSetup ( me : mutable; + theCView : CView from Graphic3d; XColor : NameOfColor from Quantity = Quantity_NOC_RED; YColor : NameOfColor from Quantity = Quantity_NOC_GREEN; ZColor : NameOfColor from Quantity = Quantity_NOC_BLUE1; diff --git a/src/OpenGl/OpenGl_AspectLine.hxx b/src/OpenGl/OpenGl_AspectLine.hxx index 2e35092c2e..68b54857b5 100644 --- a/src/OpenGl/OpenGl_AspectLine.hxx +++ b/src/OpenGl/OpenGl_AspectLine.hxx @@ -36,8 +36,9 @@ public: Standard_EXPORT void SetAspect (const CALL_DEF_CONTEXTLINE& theAspect); - const TEL_COLOUR & Color() const { return myColor; } - Aspect_TypeOfLine Type() const { return myType; } + const TEL_COLOUR& Color() const { return myColor; } + TEL_COLOUR& ChangeColor() { return myColor; } + Aspect_TypeOfLine Type() const { return myType; } float Width() const { return myWidth; } //! Init and return OpenGl shader program resource. diff --git a/src/OpenGl/OpenGl_GraduatedTrihedron.cxx b/src/OpenGl/OpenGl_GraduatedTrihedron.cxx index c4cc832cc5..9b804a11b7 100755 --- a/src/OpenGl/OpenGl_GraduatedTrihedron.cxx +++ b/src/OpenGl/OpenGl_GraduatedTrihedron.cxx @@ -35,34 +35,50 @@ #include #include +namespace +{ + static const OpenGl_TextParam THE_LABEL_PARAMS = + { + 16, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM + }; +} + // ======================================================================= // function : Constructor // purpose : // ======================================================================= -OpenGl_GraduatedTrihedron::OpenGl_GraduatedTrihedron (const Graphic3d_GraduatedTrihedron& theData) +OpenGl_GraduatedTrihedron::OpenGl_GraduatedTrihedron() : myMin (0.0f, 0.0f, 0.0f), - myMax (100.0f, 100.0f, 100.0f), - myData (theData) + myMax (100.0f, 100.0f, 100.0f) { + // +} + +// ======================================================================= +// function : SetValues +// purpose : +// ======================================================================= +void OpenGl_GraduatedTrihedron::SetValues (const Handle(OpenGl_Context)& theCtx, + const Graphic3d_GraduatedTrihedron& theData) +{ + Release (theCtx.operator->()); + myData = theData; + // Initialize text label parameters for x, y, and z axes myAxes[0] = Axis (myData.XAxisAspect(), OpenGl_Vec3 (1.0f, 0.0f, 0.0f)); myAxes[1] = Axis (myData.YAxisAspect(), OpenGl_Vec3 (0.0f, 1.0f, 0.0f)); myAxes[2] = Axis (myData.ZAxisAspect(), OpenGl_Vec3 (0.0f, 0.0f, 1.0f)); // Initialize constant primitives: text, arrows. - - myAxes[0].InitArrow (NULL, myData.ArrowLength(), OpenGl_Vec3 (0.0f, 0.0f, 1.0f)); - - myAxes[1].InitArrow (NULL, myData.ArrowLength(), OpenGl_Vec3 (0.0f, 0.0f, 1.0f)); - - myAxes[2].InitArrow (NULL, myData.ArrowLength(), OpenGl_Vec3 (1.0f, 0.0f, 0.0f)); - + myAxes[0].InitArrow (theCtx, myData.ArrowsLength(), OpenGl_Vec3 (0.0f, 0.0f, 1.0f)); + myAxes[1].InitArrow (theCtx, myData.ArrowsLength(), OpenGl_Vec3 (0.0f, 0.0f, 1.0f)); + myAxes[2].InitArrow (theCtx, myData.ArrowsLength(), OpenGl_Vec3 (1.0f, 0.0f, 0.0f)); for (Standard_Integer anIt = 0; anIt < 3; ++anIt) { - myAxes[anIt].Label.SetFontSize (NULL, theData.NamesSize()); + myAxes[anIt].Label.SetFontSize (theCtx, theData.NamesSize()); } - myLabelValues.SetFontSize (NULL, theData.ValuesSize()); + myLabelValues.SetFontSize (theCtx, theData.ValuesSize()); myAspectLabels.SetFontAspect (theData.NamesFontAspect()); myAspectLabels.ChangeFontName() = theData.NamesFont(); @@ -71,15 +87,9 @@ OpenGl_GraduatedTrihedron::OpenGl_GraduatedTrihedron (const Graphic3d_GraduatedT myAspectValues.ChangeFontName() = theData.ValuesFont(); // Grid aspect - Graphic3d_CAspectLine anAspect; - anAspect.IsDef = 1; - anAspect.IsSet = 1; - anAspect.Width = 1.0f; - anAspect.LineType = Aspect_TOL_SOLID; - anAspect.Color.r = (Standard_ShortReal) theData.GridColor().Red(); - anAspect.Color.g = (Standard_ShortReal) theData.GridColor().Green(); - anAspect.Color.b = (Standard_ShortReal) theData.GridColor().Blue(); - myGridLineAspect.SetAspect (anAspect); + myGridLineAspect.ChangeColor().rgb[0] = (Standard_ShortReal) theData.GridColor().Red(); + myGridLineAspect.ChangeColor().rgb[1] = (Standard_ShortReal) theData.GridColor().Green(); + myGridLineAspect.ChangeColor().rgb[2] = (Standard_ShortReal) theData.GridColor().Blue(); } // ======================================================================= @@ -310,7 +320,7 @@ Standard_ExtCharacter OpenGl_GraduatedTrihedron::getGridAxes (const Standard_Sho // function : renderLine // purpose : // ======================================================================= -void OpenGl_GraduatedTrihedron::renderLine (const OpenGl_PrimitiveArray* theLine, +void OpenGl_GraduatedTrihedron::renderLine (const OpenGl_PrimitiveArray& theLine, const Handle(OpenGl_Workspace)& theWorkspace, const OpenGl_Mat4& theMat, const Standard_ShortReal theXt, @@ -322,7 +332,7 @@ void OpenGl_GraduatedTrihedron::renderLine (const OpenGl_PrimitiveArray* theLine OpenGl_Utils::Translate (aMat, theXt, theYt, theZt); aContext->WorldViewState.SetCurrent (aMat); aContext->ApplyWorldViewMatrix(); - theLine->Render (theWorkspace); + theLine.Render (theWorkspace); } // ======================================================================= @@ -335,7 +345,7 @@ void OpenGl_GraduatedTrihedron::renderGridPlane (const Handle(OpenGl_Workspace)& OpenGl_Mat4& theMat) const { const Graphic3d_AxisAspect& aCurAspect = myData.AxisAspect (theIndex); - if (aCurAspect.TickmarkNumber() <= 0) + if (aCurAspect.TickmarksNumber() <= 0) { return; } @@ -343,10 +353,10 @@ void OpenGl_GraduatedTrihedron::renderGridPlane (const Handle(OpenGl_Workspace)& const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); Standard_ShortReal aStep = theGridAxes.Axes[theIndex].GetData()[theIndex] - * (myMax.GetData()[theIndex] - myMin.GetData()[theIndex]) / aCurAspect.TickmarkNumber(); + * (myMax.GetData()[theIndex] - myMin.GetData()[theIndex]) / aCurAspect.TickmarksNumber(); // NOTE: - // Get two other axes directions and draw lines Axis.TickmarkNumber times. + // Get two other axes directions and draw lines Axis.TickmarksNumber times. // Combining together from three axes, these lines will make a grid. for (Standard_Integer anIter = 1; anIter <= 2; ++anIter) { @@ -364,12 +374,12 @@ void OpenGl_GraduatedTrihedron::renderGridPlane (const Handle(OpenGl_Workspace)& aContext->ApplyWorldViewMatrix(); const OpenGl_Vec3 aStepVec (myAxes[theIndex].Direction * aStep); - for (Standard_Integer anIt = myData.ToDrawAxes() ? 1 : 0; anIt < aCurAspect.TickmarkNumber(); ++anIt) + for (Standard_Integer anIt = myData.ToDrawAxes() ? 1 : 0; anIt < aCurAspect.TickmarksNumber(); ++anIt) { OpenGl_Utils::Translate (aMat, aStepVec.x(), aStepVec.y(), aStepVec.z()); aContext->WorldViewState.SetCurrent (aMat); aContext->ApplyWorldViewMatrix(); - anAxis.Line->Render (theWorkspace); + anAxis.Line.Render (theWorkspace); } } } @@ -416,12 +426,12 @@ void OpenGl_GraduatedTrihedron::renderAxis (const Handle(OpenGl_Workspace)& theW aProjMat .Convert (aContext->ProjectionState.Current()); // Get the window's (fixed) coordinates for before matrixes modifications - OpenGl_Vec3 aEndPoint = -anAxis.Direction * myData.ArrowLength(); + OpenGl_Vec3 aEndPoint = -anAxis.Direction * myData.ArrowsLength(); OpenGl_Vec3 aWinPoint; OpenGl_Utils::Project (aEndPoint.x(), aEndPoint.y(), aEndPoint.z(), aModelMat, aProjMat, aViewport, aWinPoint.x(), aWinPoint.y(), aWinPoint.z()); - anAxis.Arrow->Render (theWorkspace); + anAxis.Arrow.Render (theWorkspace); theWorkspace->ActiveView()->EndTransformPersistence (aContext); // Get current Model-View and Projection states after the end of Transform Persistence @@ -445,7 +455,7 @@ void OpenGl_GraduatedTrihedron::renderAxis (const Handle(OpenGl_Workspace)& theW aContext->WorldViewState.SetCurrent (aModelMat); aContext->ApplyWorldViewMatrix(); - anAxis.Line->Render (theWorkspace); + anAxis.Line.Render (theWorkspace); } // ======================================================================= @@ -468,27 +478,27 @@ void OpenGl_GraduatedTrihedron::renderTickmarkLabels (const Handle(OpenGl_Worksp const Axis& anAxis = myAxes[theIndex]; const OpenGl_Vec3 aSizeVec (myMax - myMin); Standard_ShortReal aStep = theGridAxes.Axes[theIndex].GetData()[theIndex] - * (myMax.GetData()[theIndex] - myMin.GetData()[theIndex]) / aCurAspect.TickmarkNumber(); + * (myMax.GetData()[theIndex] - myMin.GetData()[theIndex]) / aCurAspect.TickmarksNumber(); OpenGl_Vec3 aDir = (theGridAxes.Ticks[theIndex] - theGridAxes.Origin).Normalized(); const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); - if (aCurAspect.ToDrawTickmarks() && aCurAspect.TickmarkNumber() > 0) + if (aCurAspect.ToDrawTickmarks() && aCurAspect.TickmarksNumber() > 0) { theWorkspace->SetAspectLine (&myGridLineAspect); OpenGl_Mat4 aModelMat (theMat); - anAxis.InitTickmark (aContext, aDir * (Standard_ShortReal) aCurAspect.TickmarkLength() * theDpix); + anAxis.InitTickmark (aContext, aDir * (Standard_ShortReal) aCurAspect.TickmarksLength() * theDpix); OpenGl_Utils::Translate (aModelMat, theGridAxes.Ticks[theIndex].x(), theGridAxes.Ticks[theIndex].y(), theGridAxes.Ticks[theIndex].z()); aContext->WorldViewState.SetCurrent (aModelMat); aContext->ApplyWorldViewMatrix(); OpenGl_Vec3 aStepVec = anAxis.Direction * aStep; - for (Standard_Integer anIter = 0; anIter <= aCurAspect.TickmarkNumber(); ++anIter) + for (Standard_Integer anIter = 0; anIter <= aCurAspect.TickmarksNumber(); ++anIter) { - anAxis.Tickmark->Render (theWorkspace); + anAxis.Tickmark.Render (theWorkspace); OpenGl_Utils::Translate (aModelMat, aStepVec.x(), aStepVec.y(), aStepVec.z()); aContext->WorldViewState.SetCurrent (aModelMat); aContext->ApplyWorldViewMatrix(); @@ -501,7 +511,7 @@ void OpenGl_GraduatedTrihedron::renderTickmarkLabels (const Handle(OpenGl_Worksp if (aCurAspect.ToDrawName()) { - Standard_Real anOffset = aCurAspect.NameOffset() + aCurAspect.TickmarkLength(); + Standard_Real anOffset = aCurAspect.NameOffset() + aCurAspect.TickmarksLength(); OpenGl_Vec3 aMiddle (theGridAxes.Ticks[theIndex] + aSizeVec * theGridAxes.Axes[theIndex] * 0.5f + aDir * (Standard_ShortReal)(theDpix * anOffset)); @@ -511,13 +521,13 @@ void OpenGl_GraduatedTrihedron::renderTickmarkLabels (const Handle(OpenGl_Worksp anAxis.Label.Render (theWorkspace); } - if (aCurAspect.ToDrawValues() && aCurAspect.TickmarkNumber() > 0) + if (aCurAspect.ToDrawValues() && aCurAspect.TickmarksNumber() > 0) { myAspectValues.ChangeColor() = anAxis.LineAspect.Color(); theWorkspace->SetAspectText (&myAspectValues); - Standard_Real anOffset = aCurAspect.ValuesOffset() + aCurAspect.TickmarkLength(); + Standard_Real anOffset = aCurAspect.ValuesOffset() + aCurAspect.TickmarksLength(); - for (Standard_Integer anIt = 0; anIt <= aCurAspect.TickmarkNumber(); ++anIt) + for (Standard_Integer anIt = 0; anIt <= aCurAspect.TickmarksNumber(); ++anIt) { sprintf (aTextValue, "%g", theGridAxes.Ticks[theIndex].GetData()[theIndex] + anIt * aStep); OpenGl_Vec3 aPos (theGridAxes.Ticks[theIndex] + anAxis.Direction* (Standard_ShortReal) (anIt * aStep) + aDir * (Standard_ShortReal) (theDpix * anOffset)); @@ -542,13 +552,15 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace)& theWorks if (myData.CubicAxesCallback) { myData.CubicAxesCallback (myData.PtrVisual3dView); - if (myAxes[0].Line == NULL || myAxes[1].Line == NULL || myAxes[2].Line == NULL - || OpenGl_Vec3 (anOldMin - myMin).Modulus() > Precision::Confusion() - || OpenGl_Vec3 (anOldMax - myMax).Modulus() > Precision::Confusion()) + if (!myAxes[0].Line.IsInitialized() + || !myAxes[1].Line.IsInitialized() + || !myAxes[2].Line.IsInitialized() + || OpenGl_Vec3 (anOldMin - myMin).Modulus() > Precision::Confusion() + || OpenGl_Vec3 (anOldMax - myMax).Modulus() > Precision::Confusion()) { - myAxes[0].InitLine (aContext, OpenGl_Vec3 (myMax.x() - myMin.x(), 0.0f, 0.0f)); - myAxes[1].InitLine (aContext, OpenGl_Vec3 (0.0f, myMax.y() - myMin.y(), 0.0f)); - myAxes[2].InitLine (aContext, OpenGl_Vec3 (0.0f, 0.0f, myMax.z() - myMin.z())); + myAxes[0].InitLine (aContext, OpenGl_Vec3 (myMax.x() - myMin.x(), 0.0f, 0.0f)); + myAxes[1].InitLine (aContext, OpenGl_Vec3 (0.0f, myMax.y() - myMin.y(), 0.0f)); + myAxes[2].InitLine (aContext, OpenGl_Vec3 (0.0f, 0.0f, myMax.z() - myMin.z())); } } @@ -690,57 +702,55 @@ void OpenGl_GraduatedTrihedron::SetMinMax (const OpenGl_Vec3& theMin, const Open // ======================================================================= // method : OpenGl_GraduatedTrihedron::Axis constructor -// purpose : +// purpose : // ======================================================================= OpenGl_GraduatedTrihedron::Axis::Axis (const Graphic3d_AxisAspect& theAspect, - const OpenGl_Vec3& theDirection) + const OpenGl_Vec3& theDirection) : Direction (theDirection), - Label (NCollection_String ((Standard_Utf16Char* )theAspect.Name().ToExtString()).ToCString(), - Direction, THE_LABEL_PARAMS) + Label (NCollection_String ((Standard_Utf16Char* )theAspect.Name().ToExtString()).ToCString(), theDirection, THE_LABEL_PARAMS), + Tickmark (NULL), + Line (NULL), + Arrow (NULL) { NameColor.rgb[0] = (Standard_ShortReal) theAspect.NameColor().Red(); NameColor.rgb[1] = (Standard_ShortReal) theAspect.NameColor().Green(); NameColor.rgb[2] = (Standard_ShortReal) theAspect.NameColor().Blue(); NameColor.rgb[3] = 1.0f; - // Fill aspect - Graphic3d_CAspectLine anAspect; - anAspect.IsDef = 1; - anAspect.IsSet = 1; - anAspect.Width = 1.0f; - anAspect.LineType = Aspect_TOL_SOLID; - anAspect.Color.r = (Standard_ShortReal) theAspect.Color().Red(); - anAspect.Color.g = (Standard_ShortReal) theAspect.Color().Green(); - anAspect.Color.b = (Standard_ShortReal) theAspect.Color().Blue(); - LineAspect.SetAspect (anAspect); - - // Create primitives - Line = new OpenGl_PrimitiveArray (NULL, Graphic3d_TOPA_SEGMENTS, NULL, NULL, NULL); - Tickmark = new OpenGl_PrimitiveArray (NULL, Graphic3d_TOPA_SEGMENTS, NULL, NULL, NULL); - Arrow = new OpenGl_PrimitiveArray (NULL, Graphic3d_TOPA_POLYLINES, NULL, NULL, NULL); + LineAspect.ChangeColor().rgb[0] = (Standard_ShortReal) theAspect.Color().Red(); + LineAspect.ChangeColor().rgb[1] = (Standard_ShortReal) theAspect.Color().Green(); + LineAspect.ChangeColor().rgb[2] = (Standard_ShortReal) theAspect.Color().Blue(); } // ======================================================================= -// method : OpenGl_GraduatedTrihedron::Axis operator = -// purpose : +// method : OpenGl_GraduatedTrihedron::Axis::~Axis +// purpose : // ======================================================================= -OpenGl_GraduatedTrihedron::Axis& - OpenGl_GraduatedTrihedron::Axis::operator= (const Axis& theOther) +OpenGl_GraduatedTrihedron::Axis::~Axis() { - Direction = theOther.Direction; - NameColor = theOther.NameColor; - LineAspect = theOther.LineAspect; - Label = theOther.Label; + // +} - Line->InitBuffers (NULL, Graphic3d_TOPA_SEGMENTS, theOther.Line->Indices(), theOther.Line->Attributes(), theOther.Line->Bounds()); - Tickmark->InitBuffers (NULL, Graphic3d_TOPA_SEGMENTS, theOther.Tickmark->Indices(), theOther.Tickmark->Attributes(), theOther.Tickmark->Bounds()); - Arrow->InitBuffers (NULL, Graphic3d_TOPA_POLYLINES, theOther.Arrow->Indices(), theOther.Arrow->Attributes(), theOther.Arrow->Bounds()); +// ======================================================================= +// method : OpenGl_GraduatedTrihedron::Axis operator= +// purpose : +// ======================================================================= +OpenGl_GraduatedTrihedron::Axis& OpenGl_GraduatedTrihedron::Axis::operator= (const Axis& theOther) +{ + Direction = theOther.Direction; + NameColor = theOther.NameColor; + LineAspect = theOther.LineAspect; + Label = theOther.Label; + + Line .InitBuffers (NULL, Graphic3d_TOPA_SEGMENTS, theOther.Line.Indices(), theOther.Line.Attributes(), theOther.Line.Bounds()); + Tickmark.InitBuffers (NULL, Graphic3d_TOPA_SEGMENTS, theOther.Tickmark.Indices(), theOther.Tickmark.Attributes(), theOther.Tickmark.Bounds()); + Arrow .InitBuffers (NULL, Graphic3d_TOPA_POLYLINES, theOther.Arrow.Indices(), theOther.Arrow.Attributes(), theOther.Arrow.Bounds()); return *this; } // ======================================================================= // method : InitArrow -// purpose : +// purpose : // ======================================================================= void OpenGl_GraduatedTrihedron::Axis::InitArrow (const Handle(OpenGl_Context)& theContext, const Standard_ShortReal theLength, @@ -769,8 +779,8 @@ void OpenGl_GraduatedTrihedron::Axis::InitArrow (const Handle(OpenGl_Context)& t anArray->AddVertex (aPoint3); anArray->AddVertex (aPoint1); - Arrow->InitBuffers (theContext, Graphic3d_TOPA_POLYLINES, - anArray->Indices(), anArray->Attributes(), anArray->Bounds()); + Arrow.InitBuffers (theContext, Graphic3d_TOPA_POLYLINES, + anArray->Indices(), anArray->Attributes(), anArray->Bounds()); } // ======================================================================= @@ -784,8 +794,8 @@ void OpenGl_GraduatedTrihedron::Axis::InitTickmark (const Handle(OpenGl_Context) Handle(Graphic3d_ArrayOfSegments) anArray = new Graphic3d_ArrayOfSegments (2); anArray->AddVertex (0.0f, 0.0f, 0.0f); anArray->AddVertex (theDir); - Tickmark->InitBuffers (theContext, Graphic3d_TOPA_SEGMENTS, - anArray->Indices(), anArray->Attributes(), anArray->Bounds()); + Tickmark.InitBuffers (theContext, Graphic3d_TOPA_SEGMENTS, + anArray->Indices(), anArray->Attributes(), anArray->Bounds()); } @@ -801,8 +811,8 @@ void OpenGl_GraduatedTrihedron::Axis::InitLine (const Handle(OpenGl_Context)& th anArray->AddVertex (0.0f, 0.0f, 0.0f); anArray->AddVertex (theDir); - Line->InitBuffers (theContext, Graphic3d_TOPA_SEGMENTS, - anArray->Indices(), anArray->Attributes(), anArray->Bounds()); + Line.InitBuffers (theContext, Graphic3d_TOPA_SEGMENTS, + anArray->Indices(), anArray->Attributes(), anArray->Bounds()); } // ======================================================================= @@ -811,8 +821,8 @@ void OpenGl_GraduatedTrihedron::Axis::InitLine (const Handle(OpenGl_Context)& th // ======================================================================= void OpenGl_GraduatedTrihedron::Axis::Release (OpenGl_Context* theCtx) { - Label.Release (theCtx); - Tickmark->Release (theCtx); - Line->Release (theCtx); - Arrow->Release (theCtx); + Label .Release (theCtx); + Tickmark.Release (theCtx); + Line .Release (theCtx); + Arrow .Release (theCtx); } diff --git a/src/OpenGl/OpenGl_GraduatedTrihedron.hxx b/src/OpenGl/OpenGl_GraduatedTrihedron.hxx index 1fd5936aea..97d852a289 100755 --- a/src/OpenGl/OpenGl_GraduatedTrihedron.hxx +++ b/src/OpenGl/OpenGl_GraduatedTrihedron.hxx @@ -29,11 +29,6 @@ class Visual3d_View; class OpenGl_View; -static const OpenGl_TextParam THE_LABEL_PARAMS = -{ - 16, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM -}; - //! This class allows to render Graduated Trihedron, i.e. trihedron with grid. //! it is based on Graphic3d_GraduatedTrihedron parameters and support its customization //! on construction level only. @@ -46,20 +41,27 @@ public: public: - OpenGl_GraduatedTrihedron (const Graphic3d_GraduatedTrihedron& theData); + //! Default constructor. + OpenGl_GraduatedTrihedron(); + //! Destructor. + virtual ~OpenGl_GraduatedTrihedron(); + + //! Draw the element. virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const; + //! Release OpenGL resources. virtual void Release (OpenGl_Context* theCtx); + //! Setup configuration. + void SetValues (const Handle(OpenGl_Context)& theCtx, + const Graphic3d_GraduatedTrihedron& theData); + //! Sets up-to-date values of scene bounding box. //! Can be used in callback mechanism to get up-to-date values. //! @sa Graphic3d_GraduatedTrihedron::CubicAxesCallback - void SetMinMax (const OpenGl_Vec3& theMin, const OpenGl_Vec3& theMax); - -protected: - - virtual ~OpenGl_GraduatedTrihedron(); + void SetMinMax (const OpenGl_Vec3& theMin, + const OpenGl_Vec3& theMax); private: @@ -72,23 +74,18 @@ private: TEL_COLOUR NameColor; OpenGl_AspectLine LineAspect; mutable OpenGl_Text Label; - mutable OpenGl_PrimitiveArray* Tickmark; - mutable OpenGl_PrimitiveArray* Line; - mutable OpenGl_PrimitiveArray* Arrow; + mutable OpenGl_PrimitiveArray Tickmark; + mutable OpenGl_PrimitiveArray Line; + mutable OpenGl_PrimitiveArray Arrow; public: Axis (const Graphic3d_AxisAspect& theAspect = Graphic3d_AxisAspect(), const OpenGl_Vec3& theDirection = OpenGl_Vec3 (1.0f, 0.0f, 0.0f)); - Axis& operator= (const Axis& theOther); + ~Axis(); - ~Axis() - { - OpenGl_Element::Destroy (NULL, Line); - OpenGl_Element::Destroy (NULL, Tickmark); - OpenGl_Element::Destroy (NULL, Arrow); - } + Axis& operator= (const Axis& theOther); void InitArrow (const Handle(OpenGl_Context)& theContext, const Standard_ShortReal theLength, @@ -101,6 +98,7 @@ private: const OpenGl_Vec3& theDir) const; void Release (OpenGl_Context* theCtx); + }; private: @@ -165,12 +163,12 @@ private: //! @param thaTx the X for vector of translation //! @param thaTy the Y for vector of translation //! @param thaTz the Z for vector of translation - void renderLine (const OpenGl_PrimitiveArray* theLine, - const Handle(OpenGl_Workspace)& theWorkspace, - const OpenGl_Mat4& theMat, - const Standard_ShortReal theXt, - const Standard_ShortReal theYt, - const Standard_ShortReal theZt) const; + void renderLine (const OpenGl_PrimitiveArray& theLine, + const Handle(OpenGl_Workspace)& theWorkspace, + const OpenGl_Mat4& theMat, + const Standard_ShortReal theXt, + const Standard_ShortReal theYt, + const Standard_ShortReal theZt) const; //! Render grid lines perpendecular the axis of input index //! @param theWorkspace [in] the OpenGl Workspace @@ -206,7 +204,6 @@ private: const GridAxes& theGridAxes, const Standard_ShortReal theDpix) const; - protected: //! @name Scene bounding box values OpenGl_Vec3 myMin; diff --git a/src/OpenGl/OpenGl_GraphicDriver.cxx b/src/OpenGl/OpenGl_GraphicDriver.cxx index 8c9385d9e4..813fc27402 100644 --- a/src/OpenGl/OpenGl_GraphicDriver.cxx +++ b/src/OpenGl/OpenGl_GraphicDriver.cxx @@ -492,14 +492,25 @@ Standard_Boolean OpenGl_GraphicDriver::Print (const Graphic3d_CView& theCView, // function : ZBufferTriedronSetup // purpose : // ======================================================================= -void OpenGl_GraphicDriver::ZBufferTriedronSetup (const Quantity_NameOfColor theXColor, +void OpenGl_GraphicDriver::ZBufferTriedronSetup (const Graphic3d_CView& theCView, + const Quantity_NameOfColor theXColor, const Quantity_NameOfColor theYColor, const Quantity_NameOfColor theZColor, const Standard_Real theSizeRatio, const Standard_Real theAxisDiametr, - const Standard_Integer theNbFacettes) + const Standard_Integer theNbFacets) { - OpenGl_Trihedron::Setup (theXColor, theYColor, theZColor, theSizeRatio, theAxisDiametr, theNbFacettes); + const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; + if (aCView == NULL) + { + return; + } + + OpenGl_Trihedron& aTrih = aCView->View->ChangeTrihedron(); + aTrih.SetArrowsColors (theXColor, theYColor, theZColor); + aTrih.SetSizeRatio (theSizeRatio); + aTrih.SetNbFacets (theNbFacets); + aTrih.SetArrowDiameter (theAxisDiametr); } // ======================================================================= @@ -515,7 +526,7 @@ void OpenGl_GraphicDriver::TriedronDisplay (const Graphic3d_CView& const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; if (aCView != NULL) { - aCView->View->TriedronDisplay (aCView->WS->GetGlContext(), thePosition, theColor, theScale, theAsWireframe); + aCView->View->TriedronDisplay (thePosition, theColor, theScale, theAsWireframe); } } @@ -633,12 +644,12 @@ void OpenGl_GraphicDriver::GraduatedTrihedronErase (const Graphic3d_CView& theCV // purpose : // ======================================================================= void OpenGl_GraphicDriver::GraduatedTrihedronMinMaxValues (const Graphic3d_CView& theView, - const Graphic3d_Vec3 theMin, - const Graphic3d_Vec3 theMax) + const Graphic3d_Vec3 theMin, + const Graphic3d_Vec3 theMax) { const OpenGl_CView* aCView = (const OpenGl_CView* )theView.ptrView; if (aCView != NULL) { - aCView->View->GraduatedTrihedron()->SetMinMax (theMin, theMax); + aCView->View->ChangeGraduatedTrihedron().SetMinMax (theMin, theMax); } } diff --git a/src/OpenGl/OpenGl_GraphicDriver.hxx b/src/OpenGl/OpenGl_GraphicDriver.hxx index 9f57853602..73b966191d 100644 --- a/src/OpenGl/OpenGl_GraphicDriver.hxx +++ b/src/OpenGl/OpenGl_GraphicDriver.hxx @@ -167,7 +167,13 @@ public: Standard_EXPORT void SetVisualisation (const Graphic3d_CView& ACView); Standard_EXPORT Standard_Boolean View (Graphic3d_CView& ACView); Standard_EXPORT void Environment (const Graphic3d_CView& ACView); - Standard_EXPORT void ZBufferTriedronSetup (const Quantity_NameOfColor XColor = Quantity_NOC_RED, const Quantity_NameOfColor YColor = Quantity_NOC_GREEN, const Quantity_NameOfColor ZColor = Quantity_NOC_BLUE1, const Standard_Real SizeRatio = 0.8, const Standard_Real AxisDiametr = 0.05, const Standard_Integer NbFacettes = 12); + Standard_EXPORT void ZBufferTriedronSetup (const Graphic3d_CView& theCView, + const Quantity_NameOfColor XColor = Quantity_NOC_RED, + const Quantity_NameOfColor YColor = Quantity_NOC_GREEN, + const Quantity_NameOfColor ZColor = Quantity_NOC_BLUE1, + const Standard_Real SizeRatio = 0.8, + const Standard_Real AxisDiametr = 0.05, + const Standard_Integer NbFacettes = 12); Standard_EXPORT void TriedronDisplay (const Graphic3d_CView& ACView, const Aspect_TypeOfTriedronPosition APosition = Aspect_TOTP_CENTER, const Quantity_NameOfColor AColor = Quantity_NOC_WHITE, const Standard_Real AScale = 0.02, const Standard_Boolean AsWireframe = Standard_True); Standard_EXPORT void TriedronErase (const Graphic3d_CView& ACView); Standard_EXPORT void TriedronEcho (const Graphic3d_CView& ACView, const Aspect_TypeOfTriedronEcho AType = Aspect_TOTE_NONE); diff --git a/src/OpenGl/OpenGl_PrimitiveArray.cxx b/src/OpenGl/OpenGl_PrimitiveArray.cxx index 4576d0c42c..4e8810ecab 100644 --- a/src/OpenGl/OpenGl_PrimitiveArray.cxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.cxx @@ -287,6 +287,7 @@ Standard_Boolean OpenGl_PrimitiveArray::buildVBO (const Handle(OpenGl_Context)& const Standard_Boolean theToKeepData) const { bool isNormalMode = theCtx->ToUseVbo(); + clearMemoryGL (theCtx); if (myAttribs.IsNull() || myAttribs->IsEmpty() || myAttribs->NbElements < 1 diff --git a/src/OpenGl/OpenGl_PrimitiveArray.hxx b/src/OpenGl/OpenGl_PrimitiveArray.hxx index 80a7fbdd56..c642f01dd3 100644 --- a/src/OpenGl/OpenGl_PrimitiveArray.hxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.hxx @@ -66,6 +66,9 @@ public: //! Notice that this flag does not indicate VBOs validity. Standard_Boolean IsInitialized() const { return myIsVboInit; } + //! Invalidate VBO content without destruction. + void Invalidate() const { myIsVboInit = Standard_False; } + //! @return primitive type (GL_LINES, GL_TRIANGLES and others) GLint DrawMode() const { return myDrawMode; } diff --git a/src/OpenGl/OpenGl_Trihedron.cxx b/src/OpenGl/OpenGl_Trihedron.cxx index 9773aed60c..eb19352bee 100644 --- a/src/OpenGl/OpenGl_Trihedron.cxx +++ b/src/OpenGl/OpenGl_Trihedron.cxx @@ -21,43 +21,15 @@ #include #include #include +#include -static const OpenGl_TextParam THE_LABEL_PARAMS = +namespace { - 16, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM -}; - -static const CALL_DEF_CONTEXTLINE myDefaultContextLine = -{ - 1, //IsDef - 1, //IsSet - { 1.F, 1.F, 1.F }, //Color - Aspect_TOL_SOLID, //LineType - 1.F //Width -}; - -static const CALL_DEF_CONTEXTTEXT myDefaultContextText = -{ - 1, //IsDef - 1, //IsSet - "Courier", //Font - 0.3F, //Space - 1.0F, //Expan - { 1.F, 1.F, 1.F }, //Color - Aspect_TOST_NORMAL, //Style - Aspect_TODT_NORMAL, //DisplayType - { 1.F, 1.F, 1.F }, //ColorSubTitle - 0, //TextZoomable - 0.F, //TextAngle - Font_FA_Regular //TextFontAspect -}; - -static TEL_COLOUR theXColor = {{ 1.F, 0.F, 0.F, 0.6F }}; -static TEL_COLOUR theYColor = {{ 0.F, 1.F, 0.F, 0.6F }}; -static TEL_COLOUR theZColor = {{ 0.F, 0.F, 1.F, 0.6F }}; -static float theRatio = 0.8f; -static float theDiameter = 0.05f; -static int theNbFacettes = 12; + static const OpenGl_TextParam THE_LABEL_PARAMS = + { + 16, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM + }; +} // ======================================================================= // function : resetTransformations @@ -198,12 +170,12 @@ void OpenGl_Trihedron::redraw (const Handle(OpenGl_Workspace)& theWorkspace) con anCircleArray->Attributes(), anCircleArray->Bounds()); } - if (!myDisk.IsDefined()) + if (!myDisk.IsInitialized()) { myDisk.Init (0.0, static_cast (aConeDiametr), myNbFacettes, 1); } - if (!myCone.IsDefined()) + if (!myCone.IsInitialized()) { myCone.Init (static_cast (aConeDiametr), 0.0f, static_cast (aConeLength), myNbFacettes, 1); } @@ -212,9 +184,9 @@ void OpenGl_Trihedron::redraw (const Handle(OpenGl_Workspace)& theWorkspace) con OpenGl_AspectFace anAspectY; OpenGl_AspectFace anAspectZ; OpenGl_AspectLine anAspectLine; - memcpy (anAspectX.ChangeIntFront().matcol.rgb, myXColor.rgb, sizeof (TEL_COLOUR)); - memcpy (anAspectY.ChangeIntFront().matcol.rgb, myYColor.rgb, sizeof (TEL_COLOUR)); - memcpy (anAspectZ.ChangeIntFront().matcol.rgb, myZColor.rgb, sizeof (TEL_COLOUR)); + memcpy (anAspectX.ChangeIntFront().matcol.rgb, myXColor.GetData(), sizeof (TEL_COLOUR)); + memcpy (anAspectY.ChangeIntFront().matcol.rgb, myYColor.GetData(), sizeof (TEL_COLOUR)); + memcpy (anAspectZ.ChangeIntFront().matcol.rgb, myZColor.GetData(), sizeof (TEL_COLOUR)); OpenGl_Mat4d aModelMatrix; aModelMatrix.Convert (aContext->WorldViewState.Current()); OpenGl_Mat4d aModelViewX (aModelMatrix); @@ -224,9 +196,9 @@ void OpenGl_Trihedron::redraw (const Handle(OpenGl_Workspace)& theWorkspace) con // Set line aspect const OpenGl_AspectLine* aCurrentAspectLine = theWorkspace->AspectLine (Standard_True); CALL_DEF_CONTEXTLINE aLineAspect = {1, 1, { 1.F, 1.F, 1.F }, aCurrentAspectLine->Type(), aCurrentAspectLine->Width()}; - aLineAspect.Color.r = myZColor.rgb[0]; - aLineAspect.Color.g = myZColor.rgb[1]; - aLineAspect.Color.b = myZColor.rgb[2]; + aLineAspect.Color.r = myZColor.r(); + aLineAspect.Color.g = myZColor.g(); + aLineAspect.Color.b = myZColor.b(); anAspectLine.SetAspect (aLineAspect); // Disable depth test and face culling @@ -271,9 +243,9 @@ void OpenGl_Trihedron::redraw (const Handle(OpenGl_Workspace)& theWorkspace) con aContext->WorldViewState.SetCurrent (aModelViewX); aContext->ApplyWorldViewMatrix(); - aLineAspect.Color.r = myXColor.rgb[0]; - aLineAspect.Color.g = myXColor.rgb[1]; - aLineAspect.Color.b = myXColor.rgb[2]; + aLineAspect.Color.r = myXColor.r(); + aLineAspect.Color.g = myXColor.g(); + aLineAspect.Color.b = myXColor.b(); anAspectLine.SetAspect (aLineAspect); theWorkspace->SetAspectLine (&anAspectLine); myLine.Render (theWorkspace); @@ -289,9 +261,9 @@ void OpenGl_Trihedron::redraw (const Handle(OpenGl_Workspace)& theWorkspace) con aContext->WorldViewState.SetCurrent (aModelViewY); aContext->ApplyWorldViewMatrix(); - aLineAspect.Color.r = myYColor.rgb[0]; - aLineAspect.Color.g = myYColor.rgb[1]; - aLineAspect.Color.b = myYColor.rgb[2]; + aLineAspect.Color.r = myYColor.r(); + aLineAspect.Color.g = myYColor.g(); + aLineAspect.Color.b = myYColor.b(); anAspectLine.SetAspect (aLineAspect); theWorkspace->SetAspectLine (&anAspectLine); myLine.Render (theWorkspace); @@ -343,14 +315,13 @@ void OpenGl_Trihedron::redraw (const Handle(OpenGl_Workspace)& theWorkspace) con // ======================================================================= void OpenGl_Trihedron::redrawZBuffer (const Handle(OpenGl_Workspace)& theWorkspace) const { - Handle(OpenGl_Context) aContext = theWorkspace->GetGlContext(); + Handle(OpenGl_Context) aContext = theWorkspace->GetGlContext(); aContext->WorldViewState.Push(); aContext->ProjectionState.Push(); resetTransformations (theWorkspace); - GLdouble aScale = myScale; - aScale *= myRatio; + const GLdouble aScale = myScale * myRatio; const OpenGl_AspectLine* anAspectLine = theWorkspace->AspectLine (Standard_True); const TEL_COLOUR& aLineColor = anAspectLine->Color(); @@ -365,24 +336,24 @@ void OpenGl_Trihedron::redrawZBuffer (const Handle(OpenGl_Workspace)& theWorkspa // Position des Axes GLdouble aTriedronAxeX[3] = { aScale, 0.0, 0.0 }; GLdouble aTriedronAxeY[3] = { 0.0, aScale, 0.0 }; - if (!myDisk.IsDefined()) + if (!myDisk.IsInitialized()) { myDisk.Init (static_cast (aCylinderDiametr), static_cast (aConeDiametr), myNbFacettes, 1); } - if (!mySphere.IsDefined()) + if (!mySphere.IsInitialized()) { mySphere.Init (static_cast (aCylinderDiametr * 2.0), myNbFacettes, myNbFacettes); } - if (!myCone.IsDefined()) + if (!myCone.IsInitialized()) { myCone.Init (static_cast (aConeDiametr), 0.0f, static_cast (aConeLength), myNbFacettes, 1); } - if (!myCylinder.IsDefined()) + if (!myCylinder.IsInitialized()) { myCylinder.Init (static_cast (aCylinderDiametr), static_cast (aCylinderDiametr), @@ -416,10 +387,10 @@ void OpenGl_Trihedron::redrawZBuffer (const Handle(OpenGl_Workspace)& theWorkspa OpenGl_AspectFace anAspectX; OpenGl_AspectFace anAspectY; OpenGl_AspectFace anAspectZ; - memcpy (anAspectX.ChangeIntFront().matcol.rgb, myXColor.rgb, sizeof (TEL_COLOUR)); - memcpy (anAspectY.ChangeIntFront().matcol.rgb, myYColor.rgb, sizeof (TEL_COLOUR)); - memcpy (anAspectZ.ChangeIntFront().matcol.rgb, myZColor.rgb, sizeof (TEL_COLOUR)); - memcpy (anAspectC.ChangeIntFront().matcol.rgb, aLineColor.rgb, sizeof (TEL_COLOUR)); + memcpy (anAspectX.ChangeIntFront().matcol.rgb, myXColor.GetData(), sizeof (TEL_COLOUR)); + memcpy (anAspectY.ChangeIntFront().matcol.rgb, myYColor.GetData(), sizeof (TEL_COLOUR)); + memcpy (anAspectZ.ChangeIntFront().matcol.rgb, myZColor.GetData(), sizeof (TEL_COLOUR)); + memcpy (anAspectC.ChangeIntFront().matcol.rgb, aLineColor.rgb, sizeof (TEL_COLOUR)); OpenGl_Mat4d aModelMatrix; aModelMatrix.Convert (aContext->WorldViewState.Current()); @@ -512,42 +483,26 @@ void OpenGl_Trihedron::redrawZBuffer (const Handle(OpenGl_Workspace)& theWorkspa // function : OpenGl_Trihedron // purpose : // ======================================================================= -OpenGl_Trihedron::OpenGl_Trihedron (const Aspect_TypeOfTriedronPosition thePosition, - const Quantity_NameOfColor theColor, - const Standard_Real theScale, - const Standard_Boolean theAsWireframe) -: myPos (thePosition), - myScale (theScale), - myIsWireframe (theAsWireframe), +OpenGl_Trihedron::OpenGl_Trihedron() +: myPos (Aspect_TOTP_LEFT_LOWER), + myScale (1.0), + myIsWireframe (Standard_False), + myXColor (1.0f, 0.0f, 0.0f, 0.6f), + myYColor (0.0f, 1.0f, 0.0f, 0.6f), + myZColor (0.0f, 0.0f, 1.0f, 0.6f), + myRatio (0.8f), + myDiameter (0.05f), + myNbFacettes (12), myLabelX ("X", OpenGl_Vec3(1.0f, 0.0f, 0.0f), THE_LABEL_PARAMS), myLabelY ("Y", OpenGl_Vec3(0.0f, 1.0f, 0.0f), THE_LABEL_PARAMS), myLabelZ ("Z", OpenGl_Vec3(0.0f, 0.0f, 1.0f), THE_LABEL_PARAMS), myLine (NULL), // do not register arrays UID - trihedron is not intended to be drawn by Ray Tracing engine myCircle (NULL) { - Standard_Real R,G,B; - Quantity_Color aColor (theColor); - aColor.Values (R, G, B, Quantity_TOC_RGB); - - CALL_DEF_CONTEXTLINE aLineAspect = myDefaultContextLine; - aLineAspect.Color.r = (float)R; - aLineAspect.Color.g = (float)G; - aLineAspect.Color.b = (float)B; - myAspectLine.SetAspect (aLineAspect); - - CALL_DEF_CONTEXTTEXT aTextAspect = myDefaultContextText; - aTextAspect.Color.r = (float)R; - aTextAspect.Color.g = (float)G; - aTextAspect.Color.b = (float)B; - myAspectText.SetAspect (aTextAspect); - - myXColor = theXColor; - myYColor = theYColor; - myZColor = theZColor; - - myRatio = theRatio; - myDiameter = theDiameter; - myNbFacettes = theNbFacettes; + const TEL_COLOUR aWhiteColor = {{ 1.0f, 1.0f, 1.0f, 1.0f }}; + myAspectLine.ChangeColor() = aWhiteColor; + myAspectText.ChangeColor() = aWhiteColor; + myAspectText.ChangeFontName() = "Courier"; } // ======================================================================= @@ -578,6 +533,96 @@ void OpenGl_Trihedron::Release (OpenGl_Context* theCtx) myCircle.Release (theCtx); } +// ======================================================================= +// function : invalidate +// purpose : +// ======================================================================= +void OpenGl_Trihedron::invalidate() +{ + myCone .Invalidate(); + myDisk .Invalidate(); + mySphere .Invalidate(); + myCylinder.Invalidate(); + myLine .Invalidate(); + myCircle .Invalidate(); +} + +// ======================================================================= +// function : SetScale +// purpose : +// ======================================================================= +void OpenGl_Trihedron::SetScale (const Standard_Real theScale) +{ + if (Abs (myScale - theScale) > Precision::Confusion()) + { + invalidate(); + } + myScale = theScale; +} + +// ======================================================================= +// function : SetSizeRatio +// purpose : +// ======================================================================= +void OpenGl_Trihedron::SetSizeRatio (const Standard_Real theRatio) +{ + if (Abs (Standard_Real(myRatio) - theRatio) > Precision::Confusion()) + { + invalidate(); + } + myRatio = float(theRatio); +} + +// ======================================================================= +// function : SetArrowDiameter +// purpose : +// ======================================================================= +void OpenGl_Trihedron::SetArrowDiameter (const Standard_Real theDiam) +{ + if (Abs (Standard_Real(myDiameter) - theDiam) > Precision::Confusion()) + { + invalidate(); + } + myDiameter = float(theDiam); +} + +// ======================================================================= +// function : SetNbFacets +// purpose : +// ======================================================================= +void OpenGl_Trihedron::SetNbFacets (const Standard_Integer theNbFacets) +{ + if (Abs (myNbFacettes - theNbFacets) > 0) + { + invalidate(); + } + myNbFacettes = theNbFacets; +} + +// ======================================================================= +// function : SetLabelsColor +// purpose : +// ======================================================================= +void OpenGl_Trihedron::SetLabelsColor (const Quantity_Color& theColor) +{ + myAspectText.ChangeColor().rgb[0] = float(theColor.Red()); + myAspectText.ChangeColor().rgb[1] = float(theColor.Green()); + myAspectText.ChangeColor().rgb[2] = float(theColor.Blue()); +} + +// ======================================================================= +// function : SetArrowsColors +// purpose : +// ======================================================================= +void OpenGl_Trihedron::SetArrowsColors (const Quantity_Color& theColorX, + const Quantity_Color& theColorY, + const Quantity_Color& theColorZ) +{ + myXColor = OpenGl_Vec4 (float(theColorX.Red()), float(theColorX.Green()), float(theColorX.Blue()), 0.6f); + myYColor = OpenGl_Vec4 (float(theColorY.Red()), float(theColorY.Green()), float(theColorY.Blue()), 0.6f); + myZColor = OpenGl_Vec4 (float(theColorZ.Red()), float(theColorZ.Green()), float(theColorZ.Blue()), 0.6f); +} + // ======================================================================= // function : Render // purpose : @@ -620,30 +665,3 @@ void OpenGl_Trihedron::Render (const Handle(OpenGl_Workspace)& theWorkspace) con theWorkspace->SetAspectText (aPrevAspectText); theWorkspace->SetAspectLine (aPrevAspectLine); } - -/*----------------------------------------------------------------------*/ -//call_ztriedron_setup -void OpenGl_Trihedron::Setup (const Quantity_NameOfColor XColor, const Quantity_NameOfColor YColor, const Quantity_NameOfColor ZColor, - const Standard_Real SizeRatio, const Standard_Real AxisDiametr, const Standard_Integer NbFacettes) -{ - Standard_Real R,G,B; - - Quantity_Color(XColor).Values(R, G, B, Quantity_TOC_RGB); - theXColor.rgb[0] = float (R); - theXColor.rgb[1] = float (G); - theXColor.rgb[2] = float (B); - - Quantity_Color(YColor).Values(R, G, B, Quantity_TOC_RGB); - theYColor.rgb[0] = float (R); - theYColor.rgb[1] = float (G); - theYColor.rgb[2] = float (B); - - Quantity_Color(ZColor).Values(R, G, B, Quantity_TOC_RGB); - theZColor.rgb[0] = float (R); - theZColor.rgb[1] = float (G); - theZColor.rgb[2] = float (B); - - theRatio = float (SizeRatio); - theDiameter = float (AxisDiametr); - theNbFacettes = NbFacettes; -} diff --git a/src/OpenGl/OpenGl_Trihedron.hxx b/src/OpenGl/OpenGl_Trihedron.hxx index adc7ad1c22..0bdf1d53b9 100755 --- a/src/OpenGl/OpenGl_Trihedron.hxx +++ b/src/OpenGl/OpenGl_Trihedron.hxx @@ -32,31 +32,55 @@ class OpenGl_Trihedron : public OpenGl_Element { public: - static void Setup(const Quantity_NameOfColor theXColor, - const Quantity_NameOfColor theYColor, - const Quantity_NameOfColor theZColor, - const Standard_Real theSizeRatio, - const Standard_Real theAxisDiametr, - const Standard_Integer theNbFacettes); + //! Default constructor. + OpenGl_Trihedron(); + + //! Destructor. + virtual ~OpenGl_Trihedron(); + + //! Render the element. + virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const; + + //! Release OpenGL resources. + virtual void Release (OpenGl_Context* theCtx); public: - OpenGl_Trihedron(const Aspect_TypeOfTriedronPosition thePosition, - const Quantity_NameOfColor theColor, - const Standard_Real theScale, - const Standard_Boolean theAsWireframe); + //! Switch wireframe / shaded trihedron. + void SetWireframe (const Standard_Boolean theAsWireframe) { myIsWireframe = theAsWireframe; } - virtual void Render(const Handle(OpenGl_Workspace)& theWorkspace) const; - virtual void Release(OpenGl_Context* theCtx); + //! Setup the corner to draw the trihedron. + void SetPosition (const Aspect_TypeOfTriedronPosition thePosition) { myPos = thePosition; } + + //! Setup the scale factor. + void SetScale (const Standard_Real theScale); + + //! Setup the size ratio factor. + void SetSizeRatio (const Standard_Real theRatio); + + //! Setup the arrow diameter. + void SetArrowDiameter (const Standard_Real theDiam); + + //! Setup the number of facets for tessellation. + void SetNbFacets (const Standard_Integer theNbFacets); + + //! Setup color of text labels. + void SetLabelsColor (const Quantity_Color& theColor); + + //! Setup per-arrow color. + void SetArrowsColors (const Quantity_Color& theColorX, + const Quantity_Color& theColorY, + const Quantity_Color& theColorZ); protected: - virtual ~OpenGl_Trihedron(); + //! Invalidate Primitve Arrays. + void invalidate(); void redraw(const Handle(OpenGl_Workspace)& theWorkspace) const; void redrawZBuffer(const Handle(OpenGl_Workspace)& theWorkspace) const; - //! Resets current model-view and projection transfprmations and sets + //! Resets current model-view and projection transformations and sets //! translation for trihedron position //! @sa Aspect_TypeOfTriedronPosition void resetTransformations (const Handle(OpenGl_Workspace)& theWorkspace) const; @@ -66,10 +90,9 @@ protected: Aspect_TypeOfTriedronPosition myPos; Standard_Real myScale; Standard_Boolean myIsWireframe; - // Parameters for z-buffered mode - TEL_COLOUR myXColor; - TEL_COLOUR myYColor; - TEL_COLOUR myZColor; + OpenGl_Vec4 myXColor; + OpenGl_Vec4 myYColor; + OpenGl_Vec4 myZColor; float myRatio; float myDiameter; int myNbFacettes; diff --git a/src/OpenGl/OpenGl_View.cxx b/src/OpenGl/OpenGl_View.cxx index bd963e7dd5..edfa8a5657 100644 --- a/src/OpenGl/OpenGl_View.cxx +++ b/src/OpenGl/OpenGl_View.cxx @@ -62,8 +62,8 @@ OpenGl_View::OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext, myZClip(myDefaultZClip), myCamera(AContext.Camera), myFog(myDefaultFog), - myTrihedron(NULL), - myGraduatedTrihedron(NULL), + myToShowTrihedron (false), + myToShowGradTrihedron (false), myVisualization(AContext.Visualization), myShadingModel ((Visual3d_TypeOfModel )AContext.Model), myAntiAliasing(Standard_False), @@ -86,8 +86,6 @@ OpenGl_View::OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext, OpenGl_View::~OpenGl_View() { ReleaseGlResources (NULL); // ensure ReleaseGlResources() was called within valid context - OpenGl_Element::Destroy (NULL, myTrihedron); - OpenGl_Element::Destroy (NULL, myGraduatedTrihedron); OpenGl_Element::Destroy (NULL, myBgGradientArray); OpenGl_Element::Destroy (NULL, myBgTextureArray); OpenGl_Element::Destroy (NULL, myTextureParams); @@ -95,14 +93,8 @@ OpenGl_View::~OpenGl_View() void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx) { - if (myTrihedron != NULL) - { - myTrihedron->Release (theCtx.operator->()); - } - if (myGraduatedTrihedron != NULL) - { - myGraduatedTrihedron->Release (theCtx.operator->()); - } + myTrihedron .Release (theCtx.operator->()); + myGraduatedTrihedron.Release (theCtx.operator->()); if (!myTextureEnv.IsNull()) { @@ -222,37 +214,41 @@ void OpenGl_View::SetFog (const Graphic3d_CView& theCView, /*----------------------------------------------------------------------*/ -void OpenGl_View::TriedronDisplay (const Handle(OpenGl_Context)& theCtx, - const Aspect_TypeOfTriedronPosition thePosition, +void OpenGl_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition, const Quantity_NameOfColor theColor, const Standard_Real theScale, const Standard_Boolean theAsWireframe) { - OpenGl_Element::Destroy (theCtx.operator->(), myTrihedron); - myTrihedron = new OpenGl_Trihedron (thePosition, theColor, theScale, theAsWireframe); + myToShowTrihedron = true; + myTrihedron.SetWireframe (theAsWireframe); + myTrihedron.SetPosition (thePosition); + myTrihedron.SetScale (theScale); + myTrihedron.SetLabelsColor (theColor); } /*----------------------------------------------------------------------*/ void OpenGl_View::TriedronErase (const Handle(OpenGl_Context)& theCtx) { - OpenGl_Element::Destroy (theCtx.operator->(), myTrihedron); + myToShowTrihedron = false; + myTrihedron.Release (theCtx.operator->()); } /*----------------------------------------------------------------------*/ -void OpenGl_View::GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx, +void OpenGl_View::GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx, const Graphic3d_GraduatedTrihedron& theData) { - OpenGl_Element::Destroy (theCtx.operator->(), myGraduatedTrihedron); - myGraduatedTrihedron = new OpenGl_GraduatedTrihedron (theData); + myToShowGradTrihedron = true; + myGraduatedTrihedron.SetValues (theCtx, theData); } /*----------------------------------------------------------------------*/ void OpenGl_View::GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx) { - OpenGl_Element::Destroy (theCtx.operator->(), myGraduatedTrihedron); + myToShowGradTrihedron = false; + myGraduatedTrihedron.Release (theCtx.operator->()); } /*----------------------------------------------------------------------*/ diff --git a/src/OpenGl/OpenGl_View.hxx b/src/OpenGl/OpenGl_View.hxx index 254d7051d2..3bddb4acfb 100644 --- a/src/OpenGl/OpenGl_View.hxx +++ b/src/OpenGl/OpenGl_View.hxx @@ -44,6 +44,8 @@ #include #include #include +#include +#include #include #include @@ -72,9 +74,7 @@ struct OPENGL_FOG }; struct OpenGl_Matrix; -class OpenGl_GraduatedTrihedron; class OpenGl_Structure; -class OpenGl_Trihedron; class Handle(OpenGl_PrinterContext); class OpenGl_StateCounter; @@ -102,14 +102,14 @@ class OpenGl_View : public MMgt_TShared void SetFog (const Graphic3d_CView& theCView, const Standard_Boolean theFlag); - void TriedronDisplay (const Handle(OpenGl_Context)& theCtx, - const Aspect_TypeOfTriedronPosition thePosition, + OpenGl_Trihedron& ChangeTrihedron() { return myTrihedron; } + void TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition, const Quantity_NameOfColor theColor, const Standard_Real theScale, const Standard_Boolean theAsWireframe); void TriedronErase (const Handle(OpenGl_Context)& theCtx); - OpenGl_GraduatedTrihedron* GraduatedTrihedron() const { return myGraduatedTrihedron; } + OpenGl_GraduatedTrihedron& ChangeGraduatedTrihedron() { return myGraduatedTrihedron; } void GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx, const Graphic3d_GraduatedTrihedron& theCubic); void GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx); @@ -246,8 +246,10 @@ protected: Handle(Graphic3d_Camera) myCamera; OPENGL_FOG myFog; - OpenGl_Trihedron* myTrihedron; - OpenGl_GraduatedTrihedron* myGraduatedTrihedron; + OpenGl_Trihedron myTrihedron; + OpenGl_GraduatedTrihedron myGraduatedTrihedron; + bool myToShowTrihedron; + bool myToShowGradTrihedron; //View_LABViewContext int myVisualization; diff --git a/src/OpenGl/OpenGl_View_2.cxx b/src/OpenGl/OpenGl_View_2.cxx index 652c0f25a7..2e79d4d2b8 100644 --- a/src/OpenGl/OpenGl_View_2.cxx +++ b/src/OpenGl/OpenGl_View_2.cxx @@ -780,13 +780,13 @@ void OpenGl_View::RedrawLayer2d (const Handle(OpenGl_PrinterContext)& thePrintCo void OpenGl_View::RedrawTrihedron (const Handle(OpenGl_Workspace) &theWorkspace) { // display global trihedron - if (myTrihedron != NULL) + if (myToShowTrihedron) { - myTrihedron->Render (theWorkspace); + myTrihedron.Render (theWorkspace); } - if (myGraduatedTrihedron != NULL) + if (myToShowGradTrihedron) { - myGraduatedTrihedron->Render (theWorkspace); + myGraduatedTrihedron.Render (theWorkspace); } } diff --git a/src/V3d/V3d_View.cdl b/src/V3d/V3d_View.cdl index 6c87fe5222..794ed0a77e 100644 --- a/src/V3d/V3d_View.cdl +++ b/src/V3d/V3d_View.cdl @@ -458,9 +458,10 @@ is ---Category: Graduated trihedron --------------------------------- - GetGraduatedTrihedron(me; - theTrigedronData: out GraduatedTrihedron from Graphic3d) + GetGraduatedTrihedron (me) + returns GraduatedTrihedron from Graphic3d ---Purpose: Returns data of a graduated trihedron. + ---C++: return const& is static; GraduatedTrihedronDisplay(me : mutable; diff --git a/src/V3d/V3d_View_4.cxx b/src/V3d/V3d_View_4.cxx index 63da14d4f3..f31649b0cc 100644 --- a/src/V3d/V3d_View_4.cxx +++ b/src/V3d/V3d_View_4.cxx @@ -271,9 +271,9 @@ void V3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho AType ) MyView->TriedronEcho (AType); } -void V3d_View::GetGraduatedTrihedron (Graphic3d_GraduatedTrihedron& theTrihedronData) const +const Graphic3d_GraduatedTrihedron& V3d_View::GetGraduatedTrihedron() const { - MyView->GetGraduatedTrihedron (theTrihedronData); + return MyView->GetGraduatedTrihedron(); } void V3d_View::GraduatedTrihedronDisplay(const Graphic3d_GraduatedTrihedron& theTrihedronData) diff --git a/src/ViewerTest/FILES b/src/ViewerTest/FILES index 005c1282f6..a56c75404a 100755 --- a/src/ViewerTest/FILES +++ b/src/ViewerTest/FILES @@ -10,3 +10,5 @@ ViewerTest_FilletCommands.cxx ViewerTest_VoxelCommands.cxx ViewerTest_OpenGlCommands.cxx ViewerTest_ViewerCommands_1.mm +ViewerTest.hxx +ViewerTest.cxx diff --git a/src/ViewerTest/ViewerTest.cdl b/src/ViewerTest/ViewerTest.cdl index 7d77fa5bb1..d28ea498d8 100644 --- a/src/ViewerTest/ViewerTest.cdl +++ b/src/ViewerTest/ViewerTest.cdl @@ -42,156 +42,4 @@ is MapTransientHasher from TColStd, AsciiString from TCollection); - - -- ---------------------------------------------------------------------- - -- Package methods - -- ---------------------------------------------------------------------- - - Factory (theDI : out Interpretor from Draw); - ---Purpose: Loads all Draw commands of V2d & V3d. Used for plugin. - - ---Category: Create the viewer.... - - ViewerInit ( thePxLeft, thePxTop : Integer from Standard = 0; - thePxWidth, thePxHeight : Integer from Standard = 0; - theViewName : CString from Standard = ""; - theDisplayName : CString from Standard = "") - returns AsciiString from TCollection; - ---Purpose: Creates view with default or custom name - -- and add this name in map to manage muliple views - -- implemented in ViewerTest_ViewerCommands.cxx - - ---Category: Manage the name of views - RemoveViewName (theName: AsciiString from TCollection); - - InitViewName (theName: AsciiString from TCollection; - theView: View from V3d); - - GetCurrentViewName returns AsciiString from TCollection; - - ---Category: Delete the viewer.... - RemoveView (theViewName : AsciiString from TCollection; - theToRemoveContext : Boolean from Standard = Standard_True); - ---Purpose: Removes view and clear all maps - -- with information about its resources if neccessary - - ---Category: Delete the viewer.... - RemoveView (theView : View from V3d; - theToRemoveContext : Boolean from Standard = Standard_True); - ---Purpose: Removes view and clear all maps - -- with information about its resources if neccessary - - ---Category: Selection in the viewer.... - - WClass returns TShared from MMgt is private; - ---C++: return const & - ---Purpose: Returns a window class that implements standard behavior of - -- all windows of the ViewerTest. This includes usual Open CASCADE - -- view conventions for mouse buttons (e.g. Ctrl+MB1 for zoom, - -- Ctrl+MB2 for pan, etc) and keyboard shortcuts. - -- This method is relevant for MS Windows only and respectively - -- returns WNT_WClass handle. - - PickShape (aType : ShapeEnum from TopAbs; - MaxPick : Integer from Standard = 5) returns Shape from TopoDS; - ---Purpose: waits until a shape of type is picked in the AIS Viewer and returns it. - -- if == TopAbs_Shape, any shape can be picked... - -- MaxPick is the Max number before exiting, if no pick is successfull - - - PickShapes (aType : ShapeEnum from TopAbs; - thepicked : in out HArray1OfShape from TopTools; - MaxPick : Integer from Standard = 5) - returns Boolean from Standard; - ---Purpose: wait until the array is filled with picked shapes. - -- returns True if the array is filled. - -- exit if number of unsuccesfull picks = - - PickObject(Type : KindOfInteractive from AIS = AIS_KOI_None; - Signature : Integer from Standard = -1; - MaxPick : Integer from Standard = 5) - returns InteractiveObject from AIS; - ---Purpose: waits until an interactive object of a given Type - -- and signature is picked (defaut values authorize - -- selection of any Interactive Object) - -- exit if number of unsuccesfull picks = - - PickObjects(thepicked : in out HArray1OfTransient from TColStd; - Type : KindOfInteractive from AIS = AIS_KOI_None; - Signature : Integer from Standard = -1; - MaxPick : Integer from Standard = 5) - returns Boolean from Standard; - ---Purpose: selection of several interactive objects. Number is given - -- by the size of - -- exit if number of unsuccesfull picks = - - - Commands (theCommands : in out Interpretor from Draw); - AviCommands(theCommands :in out Interpretor from Draw); - ViewerCommands(theCommands :in out Interpretor from Draw); - MyCommands (theCommands : in out Interpretor from Draw); -- My Own Com-s - RelationCommands(theCommands :in out Interpretor from Draw); - ObjectCommands(theCommands :in out Interpretor from Draw); - FilletCommands(theCommands :in out Interpretor from Draw); - VoxelCommands(theCommands :in out Interpretor from Draw); - OpenGlCommands(theCommands :in out Interpretor from Draw); - - GetMousePosition(xpix,ypix: out Integer from Standard); - - GetViewerFromContext returns Viewer from V3d; - - GetCollectorFromContext returns Viewer from V3d; - - GetAISContext returns InteractiveContext from AIS; - ---C++: return const & - GetNISContext returns InteractiveContext from NIS; - ---C++: return & - - SetAISContext (aContext: InteractiveContext from AIS); - - SetNISContext (aContext: InteractiveContext from NIS); - - CurrentView returns View from V3d; - ---C++: return const & - - CurrentView (aViou:View from V3d); - - Clear ; - - ---Category: Change behaviour on move,select,... events. - - SetEventManager (aMgr:EventManager from ViewerTest); - ---Purpose: puts as current eventmanager (the - -- move,select,...will be applied to - - UnsetEventManager; - ---Purpose: removes the last EventManager from the list. - - ResetEventManager; - ---Purpose: clear the list of EventManagers and - -- sets the default EventManager as current - - CurrentEventManager returns EventManager from ViewerTest; - - - ---Category: privateMethods... - - - RemoveSelected; - - StandardModeActivation(Mode : Integer from Standard); - - GetColorFromName(name: CString from Standard) - returns NameOfColor from Quantity; - - RedrawAllViews; - ---Purpose: redraws all defined views. - - SplitParameter (theString : AsciiString from TCollection; - theName : out AsciiString from TCollection; - theValue : out AsciiString from TCollection) - returns Boolean from Standard; - ---Purpose: Splits "parameter=value" string into separate - -- parameter and value strings. - -- @return TRUE if the string matches pattern "=" end; diff --git a/src/ViewerTest/ViewerTest.cxx b/src/ViewerTest/ViewerTest.cxx index 87447f768d..e842f9646a 100644 --- a/src/ViewerTest/ViewerTest.cxx +++ b/src/ViewerTest/ViewerTest.cxx @@ -106,6 +106,56 @@ Quantity_NameOfColor ViewerTest::GetColorFromName (const Standard_CString theNam return aColor; } +//======================================================================= +//function : ParseColor +//purpose : +//======================================================================= + +Standard_Integer ViewerTest::ParseColor (Standard_Integer theArgNb, + const char** theArgVec, + Quantity_Color& theColor) +{ + Quantity_NameOfColor aColor = Quantity_NOC_BLACK; + if (theArgNb >= 1 + && Quantity_Color::ColorFromName (theArgVec[0], aColor)) + { + theColor = aColor; + return 1; + } + else if (theArgNb >= 3) + { + const TCollection_AsciiString anRgbStr[3] = + { + theArgVec[0], + theArgVec[1], + theArgVec[2] + }; + if (!anRgbStr[0].IsRealValue() + || !anRgbStr[1].IsRealValue() + || !anRgbStr[2].IsRealValue()) + { + return 0; + } + + Graphic3d_Vec4d anRgb; + anRgb.x() = anRgbStr[0].RealValue(); + anRgb.y() = anRgbStr[1].RealValue(); + anRgb.z() = anRgbStr[2].RealValue(); + if (anRgb.x() < 0.0 || anRgb.x() > 1.0 + || anRgb.y() < 0.0 || anRgb.y() > 1.0 + || anRgb.z() < 0.0 || anRgb.z() > 1.0) + { + std::cout << "Error: RGB color values should be within range 0..1!\n"; + return 0; + } + + theColor.SetValues (anRgb.x(), anRgb.y(), anRgb.z(), Quantity_TOC_RGB); + return 3; + } + + return 0; +} + //======================================================================= //function : GetTypeNames //purpose : diff --git a/src/ViewerTest/ViewerTest.hxx b/src/ViewerTest/ViewerTest.hxx new file mode 100644 index 0000000000..562cc8ea6c --- /dev/null +++ b/src/ViewerTest/ViewerTest.hxx @@ -0,0 +1,212 @@ +// Copyright (c) 1997-1999 Matra Datavision +// Copyright (c) 1999-2015 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _ViewerTest_HeaderFile +#define _ViewerTest_HeaderFile + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class TCollection_AsciiString; +class V3d_View; +class MMgt_TShared; +class TopoDS_Shape; +class TopTools_HArray1OfShape; +class AIS_InteractiveObject; +class TColStd_HArray1OfTransient; +class V3d_Viewer; +class AIS_InteractiveContext; +class ViewerTest_EventManager; +class ViewerTest_EventManager; +class ViewerTest_DoubleMapOfInteractiveAndName; +class ViewerTest_DoubleMapNodeOfDoubleMapOfInteractiveAndName; +class ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName; +class Quantity_Color; + +class ViewerTest +{ +public: + + DEFINE_STANDARD_ALLOC + + //! Loads all Draw commands of V2d & V3d. Used for plugin. + Standard_EXPORT static void Factory (Draw_Interpretor& theDI); + + //! Creates view with default or custom name + //! and add this name in map to manage muliple views + //! implemented in ViewerTest_ViewerCommands.cxx + Standard_EXPORT static TCollection_AsciiString ViewerInit (const Standard_Integer thePxLeft = 0, + const Standard_Integer thePxTop = 0, + const Standard_Integer thePxWidth = 0, + const Standard_Integer thePxHeight = 0, + const Standard_CString theViewName = "", + const Standard_CString theDisplayName = ""); + + Standard_EXPORT static void RemoveViewName (const TCollection_AsciiString& theName); + + Standard_EXPORT static void InitViewName (const TCollection_AsciiString& theName, + const Handle(V3d_View)& theView); + + Standard_EXPORT static TCollection_AsciiString GetCurrentViewName(); + + //! Removes view and clear all maps + //! with information about its resources if necessary + Standard_EXPORT static void RemoveView (const TCollection_AsciiString& theViewName, + const Standard_Boolean theToRemoveContext = Standard_True); + + //! Removes view and clear all maps + //! with information about its resources if necessary + Standard_EXPORT static void RemoveView (const Handle(V3d_View)& theView, + const Standard_Boolean theToRemoveContext = Standard_True); + + //! waits until a shape of type is picked in the AIS Viewer and returns it. + //! if == TopAbs_Shape, any shape can be picked... + //! MaxPick is the Max number before exiting, if no pick is successful + Standard_EXPORT static TopoDS_Shape PickShape (const TopAbs_ShapeEnum aType, + const Standard_Integer MaxPick = 5); + + //! wait until the array is filled with picked shapes. + //! returns True if the array is filled. + //! exit if number of unsuccessful picks = + Standard_EXPORT static Standard_Boolean PickShapes (const TopAbs_ShapeEnum aType, + Handle(TopTools_HArray1OfShape)& thepicked, + const Standard_Integer MaxPick = 5); + + //! waits until an interactive object of a given Type + //! and signature is picked (default values authorize + //! selection of any Interactive Object) + //! exit if number of unsuccessful picks = + Standard_EXPORT static Handle(AIS_InteractiveObject) PickObject (const AIS_KindOfInteractive Type = AIS_KOI_None, + const Standard_Integer Signature = -1, + const Standard_Integer MaxPick = 5); + + //! selection of several interactive objects. + //! Number is given by the size of + //! exit if number of unsuccesfull picks = + Standard_EXPORT static Standard_Boolean PickObjects (Handle(TColStd_HArray1OfTransient)& thepicked, + const AIS_KindOfInteractive Type = AIS_KOI_None, + const Standard_Integer Signature = -1, + const Standard_Integer MaxPick = 5); + + Standard_EXPORT static void Commands (Draw_Interpretor& theCommands); + + Standard_EXPORT static void AviCommands (Draw_Interpretor& theCommands); + + Standard_EXPORT static void ViewerCommands (Draw_Interpretor& theCommands); + + Standard_EXPORT static void MyCommands (Draw_Interpretor& theCommands); + + Standard_EXPORT static void RelationCommands (Draw_Interpretor& theCommands); + + Standard_EXPORT static void ObjectCommands (Draw_Interpretor& theCommands); + + Standard_EXPORT static void FilletCommands (Draw_Interpretor& theCommands); + + Standard_EXPORT static void VoxelCommands (Draw_Interpretor& theCommands); + + Standard_EXPORT static void OpenGlCommands (Draw_Interpretor& theCommands); + + Standard_EXPORT static void GetMousePosition (Standard_Integer& xpix, Standard_Integer& ypix); + + Standard_EXPORT static Handle(V3d_Viewer) GetViewerFromContext(); + + Standard_EXPORT static Handle(V3d_Viewer) GetCollectorFromContext(); + + Standard_EXPORT static const Handle(AIS_InteractiveContext)& GetAISContext(); + + Standard_EXPORT static NIS_InteractiveContext& GetNISContext(); + + Standard_EXPORT static void SetAISContext (const Handle(AIS_InteractiveContext)& aContext); + + Standard_EXPORT static void SetNISContext (const NIS_InteractiveContext& aContext); + + Standard_EXPORT static const Handle(V3d_View)& CurrentView(); + + Standard_EXPORT static void CurrentView (const Handle(V3d_View)& aViou); + + Standard_EXPORT static void Clear(); + + //! puts theMgr as current eventmanager (the move,select,...will be applied to theMgr) + Standard_EXPORT static void SetEventManager (const Handle(ViewerTest_EventManager)& theMgr); + + //! removes the last EventManager from the list. + Standard_EXPORT static void UnsetEventManager(); + + //! clear the list of EventManagers and + //! sets the default EventManager as current + Standard_EXPORT static void ResetEventManager(); + + Standard_EXPORT static Handle(ViewerTest_EventManager) CurrentEventManager(); + + Standard_EXPORT static void RemoveSelected(); + + Standard_EXPORT static void StandardModeActivation (const Standard_Integer Mode); + + Standard_EXPORT static Quantity_NameOfColor GetColorFromName (const Standard_CString name); + + //! Parses color argument(s) specified within theArgVec[0], theArgVec[1] and theArgVec[2]. + //! Handles either color specified by name (single argument) + //! or by RGB components (3 arguments) in range 0..1. + //! The result is stored in theColor on success. + //! Returns number of handled arguments (1 or 3) or 0 on syntax error. + Standard_EXPORT static Standard_Integer ParseColor (Standard_Integer theArgNb, + const char** theArgVec, + Quantity_Color& theColor); + + //! redraws all defined views. + Standard_EXPORT static void RedrawAllViews(); + + //! Splits "parameter=value" string into separate + //! parameter and value strings. + //! @return TRUE if the string matches pattern "=" + Standard_EXPORT static Standard_Boolean SplitParameter (const TCollection_AsciiString& theString, + TCollection_AsciiString& theName, + TCollection_AsciiString& theValue); + +private: + + //! Returns a window class that implements standard behavior of + //! all windows of the ViewerTest. This includes usual Open CASCADE + //! view conventions for mouse buttons (e.g. Ctrl+MB1 for zoom, + //! Ctrl+MB2 for pan, etc) and keyboard shortcuts. + //! This method is relevant for MS Windows only and respectively + //! returns WNT_WClass handle. + Standard_EXPORT static const Handle(MMgt_TShared)& WClass(); + +friend class ViewerTest_EventManager; +friend class ViewerTest_DoubleMapOfInteractiveAndName; +friend class ViewerTest_DoubleMapNodeOfDoubleMapOfInteractiveAndName; +friend class ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName; + +}; + +#endif // _ViewerTest_HeaderFile diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index d32f2f5078..66192dd6f1 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -2857,94 +2857,228 @@ static int VScale(Draw_Interpretor& di, Standard_Integer argc, const char** argv return 0; } //============================================================================== -//function : VTestZBuffTrihedron -//purpose : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron +//function : VZBuffTrihedron +//purpose : //============================================================================== -static int VTestZBuffTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv) +static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/, + Standard_Integer theArgNb, + const char** theArgVec) { - Handle(V3d_View) V3dView = ViewerTest::CurrentView(); - if ( V3dView.IsNull() ) return 1; - - V3dView->ZBufferTriedronSetup(); - - if ( argc == 1 ) { - // Set up default trihedron parameters - V3dView->TriedronDisplay( Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER ); - } else - if ( argc == 7 ) + Handle(V3d_View) aView = ViewerTest::CurrentView(); + if (aView.IsNull()) { - Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER; - const char* aPosType = argv[1]; - - if ( strcmp(aPosType, "center") == 0 ) - { - aPosition = Aspect_TOTP_CENTER; - } else - if (strcmp(aPosType, "left_lower") == 0) - { - aPosition = Aspect_TOTP_LEFT_LOWER; - } else - if (strcmp(aPosType, "left_upper") == 0) - { - aPosition = Aspect_TOTP_LEFT_UPPER; - } else - if (strcmp(aPosType, "right_lower") == 0) - { - aPosition = Aspect_TOTP_RIGHT_LOWER; - } else - if (strcmp(aPosType, "right_upper") == 0) - { - aPosition = Aspect_TOTP_RIGHT_UPPER; - } else - { - di << argv[1] << " Invalid type of alignment" << "\n"; - di << "Must be one of [ center, left_lower," << "\n"; - di << "left_upper, right_lower, right_upper ]" << "\n"; - return 1; - } - - Standard_Real R = Draw::Atof(argv[2])/255.; - Standard_Real G = Draw::Atof(argv[3])/255.; - Standard_Real B = Draw::Atof(argv[4])/255.; - Quantity_Color aColor(R, G, B, Quantity_TOC_RGB); - - Standard_Real aScale = Draw::Atof(argv[5]); - - if( aScale <= 0.0 ) - { - di << argv[5] << " Invalid value. Must be > 0" << "\n"; - return 1; - } - - V3d_TypeOfVisualization aPresentation = V3d_ZBUFFER; - const char* aPresType = argv[6]; - - if ( strcmp(aPresType, "wireframe") == 0 ) - { - aPresentation = V3d_WIREFRAME; - } else - if (strcmp(aPresType, "zbuffer") == 0) - { - aPresentation = V3d_ZBUFFER; - } else - { - di << argv[6] << " Invalid type of visualization" << "\n"; - di << "Must be one of [ wireframe, zbuffer ]" << "\n"; - return 1; - } - - V3dView->TriedronDisplay( aPosition, aColor.Name(), aScale, aPresentation ); - - } else - { - di << argv[0] << " Invalid number of arguments" << "\n"; + std::cout << "Error: no active viewer!\n"; return 1; } - V3dView->View()->ZFitAll(); - V3dView->Redraw(); + ViewerTest_AutoUpdater anUpdateTool (ViewerTest::GetAISContext(), aView); + Aspect_TypeOfTriedronPosition aPosition = Aspect_TOTP_LEFT_LOWER; + V3d_TypeOfVisualization aVisType = V3d_ZBUFFER; + Quantity_Color aLabelsColor = Quantity_NOC_WHITE; + Quantity_Color anArrowColorX = Quantity_NOC_RED; + Quantity_Color anArrowColorY = Quantity_NOC_GREEN; + Quantity_Color anArrowColorZ = Quantity_NOC_BLUE1; + Standard_Real aScale = 0.1; + Standard_Real aSizeRatio = 0.8; + Standard_Real anArrowDiam = 0.05; + Standard_Integer aNbFacets = 12; + for (Standard_Integer anArgIter = 1; anArgIter < theArgNb; ++anArgIter) + { + Standard_CString anArg = theArgVec[anArgIter]; + TCollection_AsciiString aFlag (anArg); + aFlag.LowerCase(); + if (anUpdateTool.parseRedrawMode (aFlag)) + { + continue; + } + else if (aFlag == "-on") + { + continue; + } + else if (aFlag == "-off") + { + aView->TriedronErase(); + return 0; + } + else if (aFlag == "-pos" + || aFlag == "-position" + || aFlag == "-corner") + { + if (++anArgIter >= theArgNb) + { + std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; + return 1; + } + + TCollection_AsciiString aPosName (theArgVec[anArgIter]); + aPosName.LowerCase(); + if (aPosName == "center") + { + aPosition = Aspect_TOTP_CENTER; + } + else if (aPosName == "left_lower" + || aPosName == "lower_left" + || aPosName == "leftlower" + || aPosName == "lowerleft") + { + aPosition = Aspect_TOTP_LEFT_LOWER; + } + else if (aPosName == "left_upper" + || aPosName == "upper_left" + || aPosName == "leftupper" + || aPosName == "upperleft") + { + aPosition = Aspect_TOTP_LEFT_UPPER; + } + else if (aPosName == "right_lower" + || aPosName == "lower_right" + || aPosName == "rightlower" + || aPosName == "lowerright") + { + aPosition = Aspect_TOTP_RIGHT_LOWER; + } + else if (aPosName == "right_upper" + || aPosName == "upper_right" + || aPosName == "rightupper" + || aPosName == "upperright") + { + aPosition = Aspect_TOTP_RIGHT_UPPER; + } + else + { + std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown position '" << aPosName << "'\n"; + return 1; + } + } + else if (aFlag == "-type") + { + if (++anArgIter >= theArgNb) + { + std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; + return 1; + } + + TCollection_AsciiString aTypeName (theArgVec[anArgIter]); + aTypeName.LowerCase(); + if (aTypeName == "wireframe" + || aTypeName == "wire") + { + aVisType = V3d_WIREFRAME; + } + else if (aTypeName == "zbuffer" + || aTypeName == "shaded") + { + aVisType = V3d_ZBUFFER; + } + else + { + std::cerr << "Error: wrong syntax at '" << anArg << "' - unknown type '" << aTypeName << "'\n"; + } + } + else if (aFlag == "-scale") + { + if (++anArgIter >= theArgNb) + { + std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; + return 1; + } + + aScale = Draw::Atof (theArgVec[anArgIter]); + } + else if (aFlag == "-size" + || aFlag == "-sizeratio") + { + if (++anArgIter >= theArgNb) + { + std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; + return 1; + } + + aSizeRatio = Draw::Atof (theArgVec[anArgIter]); + } + else if (aFlag == "-arrowdiam" + || aFlag == "-arrowdiameter") + { + if (++anArgIter >= theArgNb) + { + std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; + return 1; + } + + anArrowDiam = Draw::Atof (theArgVec[anArgIter]); + } + else if (aFlag == "-nbfacets") + { + if (++anArgIter >= theArgNb) + { + std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; + return 1; + } + + aNbFacets = Draw::Atoi (theArgVec[anArgIter]); + } + else if (aFlag == "-colorlabel" + || aFlag == "-colorlabels") + { + Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, + theArgVec + anArgIter + 1, + aLabelsColor); + if (aNbParsed == 0) + { + std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; + return 1; + } + anArgIter += aNbParsed; + } + else if (aFlag == "-colorarrowx") + { + Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, + theArgVec + anArgIter + 1, + anArrowColorX); + if (aNbParsed == 0) + { + std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; + return 1; + } + anArgIter += aNbParsed; + } + else if (aFlag == "-colorarrowy") + { + Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, + theArgVec + anArgIter + 1, + anArrowColorY); + if (aNbParsed == 0) + { + std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; + return 1; + } + anArgIter += aNbParsed; + } + else if (aFlag == "-colorarrowz") + { + Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgNb - anArgIter - 1, + theArgVec + anArgIter + 1, + anArrowColorZ); + if (aNbParsed == 0) + { + std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; + return 1; + } + anArgIter += aNbParsed; + } + else + { + std::cerr << "Error: wrong syntax at '" << anArg << "'\n"; + return 1; + } + } + + aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(), + aSizeRatio, anArrowDiam, aNbFacets); + aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType); + aView->View()->ZFitAll(); return 0; } @@ -3720,7 +3854,8 @@ static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer th // On/off arguments if ((aKey.IsEqual ("xdrawname") || aKey.IsEqual ("ydrawname") || aKey.IsEqual ("zdrawname") || aKey.IsEqual ("xdrawticks") || aKey.IsEqual ("ydrawticks") || aKey.IsEqual ("zdrawticks") - || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues")) + || aKey.IsEqual ("xdrawvalues") || aKey.IsEqual ("ydrawvalues") || aKey.IsEqual ("zdrawvalues") + || aKey.IsEqual ("drawgrid") || aKey.IsEqual ("drawaxes")) && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off"))) { continue; @@ -3799,15 +3934,15 @@ static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer th } if (aMapOfArgs.Find ("xdrawname", aValues)) { - aTrihedronData.ChangeXAxisAspect().SetToDrawName (aValues->Value(1).IsEqual ("on")); + aTrihedronData.ChangeXAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); } if (aMapOfArgs.Find ("ydrawname", aValues)) { - aTrihedronData.ChangeYAxisAspect().SetToDrawName (aValues->Value(1).IsEqual ("on")); + aTrihedronData.ChangeYAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); } if (aMapOfArgs.Find ("zdrawname", aValues)) { - aTrihedronData.ChangeZAxisAspect().SetToDrawName (aValues->Value(1).IsEqual ("on")); + aTrihedronData.ChangeZAxisAspect().SetDrawName (aValues->Value(1).IsEqual ("on")); } if (aMapOfArgs.Find ("xnameoffset", aValues)) { @@ -3881,53 +4016,53 @@ static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer th // TICKMARKS if (aMapOfArgs.Find ("xticks", aValues)) { - aTrihedronData.ChangeXAxisAspect().SetTickmarkNumber (aValues->Value(1).IntegerValue()); + aTrihedronData.ChangeXAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); } if (aMapOfArgs.Find ("yticks", aValues)) { - aTrihedronData.ChangeYAxisAspect().SetTickmarkNumber (aValues->Value(1).IntegerValue()); + aTrihedronData.ChangeYAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); } if (aMapOfArgs.Find ("zticks", aValues)) { - aTrihedronData.ChangeZAxisAspect().SetTickmarkNumber (aValues->Value(1).IntegerValue()); + aTrihedronData.ChangeZAxisAspect().SetTickmarksNumber (aValues->Value(1).IntegerValue()); } if (aMapOfArgs.Find ("xticklength", aValues)) { - aTrihedronData.ChangeXAxisAspect().SetTickmarkLength (aValues->Value(1).IntegerValue()); + aTrihedronData.ChangeXAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); } if (aMapOfArgs.Find ("yticklength", aValues)) { - aTrihedronData.ChangeYAxisAspect().SetTickmarkLength (aValues->Value(1).IntegerValue()); + aTrihedronData.ChangeYAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); } if (aMapOfArgs.Find ("zticklength", aValues)) { - aTrihedronData.ChangeZAxisAspect().SetTickmarkLength (aValues->Value(1).IntegerValue()); + aTrihedronData.ChangeZAxisAspect().SetTickmarksLength (aValues->Value(1).IntegerValue()); } if (aMapOfArgs.Find ("xdrawticks", aValues)) { - aTrihedronData.ChangeXAxisAspect().SetToDrawTickmarks (aValues->Value(1).IsEqual ("on")); + aTrihedronData.ChangeXAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); } if (aMapOfArgs.Find ("ydrawticks", aValues)) { - aTrihedronData.ChangeYAxisAspect().SetToDrawTickmarks (aValues->Value(1).IsEqual ("on")); + aTrihedronData.ChangeYAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); } if (aMapOfArgs.Find ("zdrawticks", aValues)) { - aTrihedronData.ChangeZAxisAspect().SetToDrawTickmarks (aValues->Value(1).IsEqual ("on")); + aTrihedronData.ChangeZAxisAspect().SetDrawTickmarks (aValues->Value(1).IsEqual ("on")); } // VALUES if (aMapOfArgs.Find ("xdrawvalues", aValues)) { - aTrihedronData.ChangeXAxisAspect().SetToDrawValues (aValues->Value(1).IsEqual ("on")); + aTrihedronData.ChangeXAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); } if (aMapOfArgs.Find ("ydrawvalues", aValues)) { - aTrihedronData.ChangeYAxisAspect().SetToDrawValues (aValues->Value(1).IsEqual ("on")); + aTrihedronData.ChangeYAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); } if (aMapOfArgs.Find ("zdrawvalues", aValues)) { - aTrihedronData.ChangeZAxisAspect().SetToDrawValues (aValues->Value(1).IsEqual ("on")); + aTrihedronData.ChangeZAxisAspect().SetDrawValues (aValues->Value(1).IsEqual ("on")); } if (aMapOfArgs.Find ("xvaluesoffset", aValues)) { @@ -3945,7 +4080,7 @@ static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer th // ARROWS if (aMapOfArgs.Find ("arrowlength", aValues)) { - aTrihedronData.SetArrowLength ((Standard_ShortReal) aValues->Value(1).RealValue()); + aTrihedronData.SetArrowsLength ((Standard_ShortReal) aValues->Value(1).RealValue()); } // FONTS @@ -3958,6 +4093,15 @@ static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer th aTrihedronData.SetValuesFont (aValues->Value(1)); } + if (aMapOfArgs.Find ("drawgrid", aValues)) + { + aTrihedronData.SetDrawGrid (aValues->Value(1).IsEqual ("on")); + } + if (aMapOfArgs.Find ("drawaxes", aValues)) + { + aTrihedronData.SetDrawAxes (aValues->Value(1).IsEqual ("on")); + } + // The final step: display of erase trihedron if (toDisplay) { @@ -7995,10 +8139,13 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) "vscale : vscale X Y Z", __FILE__,VScale,group); theCommands.Add("vzbufftrihedron", - "vzbufftrihedron [center|left_lower|left_upper|right_lower|right_upper" - " textR=255 textG=255 textB=255 scale=0.1 wireframe|zbuffer]" - " : Displays a V3d_ZBUFFER'ed or V3d_WIREFRAME'd trihedron", - __FILE__,VTestZBuffTrihedron,group); + "vzbufftrihedron [{-on|-off}=-on] [-type {wireframe|zbuffer}=zbuffer]" + "\n\t\t: [-position center|left_lower|left_upper|right_lower|right_upper]" + "\n\t\t: [-scale value=0.1] [-size value=0.8] [-arrowDiam value=0.05]" + "\n\t\t: [-colorArrowX color=RED] [-colorArrowY color=GREEN] [-colorArrowZ color=BLUE]" + "\n\t\t: [-nbfacets value=12] [-colorLabels color=WHITE]" + "\n\t\t: Displays a trihedron", + __FILE__,VZBuffTrihedron,group); theCommands.Add("vrotate", "vrotate [[-mouseStart X Y] [-mouseMove X Y]]|[AX AY AZ [X Y Z]]" "\n : Option -mouseStart starts rotation according to the mouse position" @@ -8046,6 +8193,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) "\t[-xdrawticks on/off] [-ydrawticks on/off] [-zdrawticks on/off]\n" "\t[-xticks Number] [-yticks Number] [-zticks Number]\n" "\t[-xticklength IntVal] [-yticklength IntVal] [-zticklength IntVal]\n" + "\t[-drawgrid on/off] [-drawaxes on/off]\n" " - Displays or erases graduated trihedron" " - xname, yname, zname - names of axes, default: X, Y, Z\n" " - namefont - font of axes names. Default: Arial\n" diff --git a/src/Visual3d/Visual3d_View.cdl b/src/Visual3d/Visual3d_View.cdl index 899f8f77fb..34f60f09b4 100644 --- a/src/Visual3d/Visual3d_View.cdl +++ b/src/Visual3d/Visual3d_View.cdl @@ -514,11 +514,11 @@ is ---Category: Graduated trihedron ------------------------------------------ - GetGraduatedTrihedron(me; - theTrigedronData: out GraduatedTrihedron from Graphic3d) - returns Boolean from Standard + GetGraduatedTrihedron (me) + returns GraduatedTrihedron from Graphic3d is static; - ---Purpose: Returns data of a graduated trihedron if displayed (return value is True) + ---Purpose: Returns data of a graduated trihedron + ---C++: return const& GraduatedTrihedronDisplay(me : mutable; theTrigedronData: in GraduatedTrihedron from Graphic3d) diff --git a/src/Visual3d/Visual3d_View.cxx b/src/Visual3d/Visual3d_View.cxx index 5220020ae4..164096e86d 100644 --- a/src/Visual3d/Visual3d_View.cxx +++ b/src/Visual3d/Visual3d_View.cxx @@ -2060,7 +2060,7 @@ void Visual3d_View::ZBufferTriedronSetup (const Quantity_NameOfColor theXColor, const Standard_Real theAxisDiametr, const Standard_Integer theNbFacettes) { - myGraphicDriver->ZBufferTriedronSetup (theXColor, theYColor, theZColor, + myGraphicDriver->ZBufferTriedronSetup (MyCView, theXColor, theYColor, theZColor, theSizeRatio, theAxisDiametr, theNbFacettes); } @@ -2115,15 +2115,9 @@ static void SetMinMaxValuesCallback (Visual3d_View* theView) // function : GetGraduatedTrihedron // purpose : // ======================================================================= -Standard_Boolean Visual3d_View::GetGraduatedTrihedron (Graphic3d_GraduatedTrihedron& theTrihedronData) const +const Graphic3d_GraduatedTrihedron& Visual3d_View::GetGraduatedTrihedron() const { - if (!myGTrihedron.PtrVisual3dView) - { - return Standard_False; - } - - theTrihedronData = myGTrihedron; - return Standard_True; + return myGTrihedron; } // ======================================================================= diff --git a/tests/bugs/vis/bug22483_2 b/tests/bugs/vis/bug22483_2 index d4140cd2ad..24c1ef5a31 100755 --- a/tests/bugs/vis/bug22483_2 +++ b/tests/bugs/vis/bug22483_2 @@ -8,8 +8,7 @@ puts "" set BugNumber OCC22483 -vinit -vzbufftrihedron left_lower 255 255 255 0.1 zbuffer +vinit View1 +vzbufftrihedron -position left_lower -scale 0.1 -type zbuffer -colorLabels WHITE set only_screen 1 - diff --git a/tests/bugs/vis/bug22483_3 b/tests/bugs/vis/bug22483_3 index 60e3b1c4a3..31fe527201 100755 --- a/tests/bugs/vis/bug22483_3 +++ b/tests/bugs/vis/bug22483_3 @@ -8,9 +8,7 @@ puts "" set BugNumber OCC22483 -vinit -vzbufftrihedron right_upper 200 50 255 0.2 zbuffer +vinit View1 +vzbufftrihedron -position right_upper -scale 0.2 -type zbuffer -colorLabels 0.78 0.20 1.0 set only_screen 1 - - diff --git a/tests/bugs/vis/bug22483_4 b/tests/bugs/vis/bug22483_4 index e8e38532ff..40c20c2ce5 100755 --- a/tests/bugs/vis/bug22483_4 +++ b/tests/bugs/vis/bug22483_4 @@ -8,9 +8,7 @@ puts "" set BugNumber OCC22483 -vinit -vzbufftrihedron center 0 150 255 0.1 wireframe +vinit View1 +vzbufftrihedron -position center -scale 0.1 -type wireframe -colorLabels 0.0 0.59 1.0 set only_screen 1 - - diff --git a/tests/bugs/vis/bug23484_1 b/tests/bugs/vis/bug23484_1 index 25fd4282dd..378433d4f1 100644 --- a/tests/bugs/vis/bug23484_1 +++ b/tests/bugs/vis/bug23484_1 @@ -14,10 +14,10 @@ vinit View1 vfit vaxo -vzbufftrihedron left_lower 255 255 255 0.1 wireframe +vzbufftrihedron -scale 0.1 -type wireframe -position left_lower vdump $anImage1 -vzbufftrihedron center 255 255 255 0.1 wireframe +vzbufftrihedron -scale 0.1 -type wireframe -position center vdump $anImage2 vclear