diff --git a/src/Graphic3d/FILES b/src/Graphic3d/FILES index 47cf7ee261..716a5f76e8 100755 --- a/src/Graphic3d/FILES +++ b/src/Graphic3d/FILES @@ -21,7 +21,7 @@ Graphic3d_CTexture.hxx Graphic3d_CLight.hxx Graphic3d_CUserDraw.hxx Graphic3d_CView.hxx -Graphic3d_CGraduatedTrihedron.hxx +Graphic3d_GraduatedTrihedron.hxx Graphic3d_ViewAffinity.hxx Graphic3d_ViewAffinity.cxx Graphic3d_MapOfObject.hxx diff --git a/src/Graphic3d/Graphic3d.cdl b/src/Graphic3d/Graphic3d.cdl index 4dcc3a754d..aa020313be 100644 --- a/src/Graphic3d/Graphic3d.cdl +++ b/src/Graphic3d/Graphic3d.cdl @@ -405,7 +405,7 @@ is ---Purpose: Describes rendering parameters and effects. ---Category: Imported types - imported CGraduatedTrihedron; + imported GraduatedTrihedron; ---Category: Imported types imported ClipPlane; diff --git a/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cdl b/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cdl index c19aa03d0e..5273bb6af5 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cdl +++ b/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cdl @@ -38,6 +38,7 @@ uses Buffer_Handle from Graphic3d, BoundBuffer_Handle from Graphic3d, IndexBuffer_Handle from Graphic3d, + Vec3 from Graphic3d, Color from Quantity, Pnt from gp, Pnt2d from gp, @@ -87,6 +88,7 @@ is raises OutOfRange from Standard; -- if the actual vertex number is >= ---C++: inline + ---C++: alias "Standard_Integer AddVertex (const Graphic3d_Vec3& theVertex);" AddVertex( me:mutable; X,Y,Z: Real from Standard) diff --git a/src/Graphic3d/Graphic3d_ArrayOfPrimitives.lxx b/src/Graphic3d/Graphic3d_ArrayOfPrimitives.lxx index 34708f1adf..783b98b6a5 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfPrimitives.lxx +++ b/src/Graphic3d/Graphic3d_ArrayOfPrimitives.lxx @@ -63,6 +63,11 @@ inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& th return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z()); } +inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Graphic3d_Vec3& theVertex) +{ + return AddVertex (theVertex.x(), theVertex.y(), theVertex.z()); +} + inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ) diff --git a/src/Graphic3d/Graphic3d_CGraduatedTrihedron.hxx b/src/Graphic3d/Graphic3d_CGraduatedTrihedron.hxx deleted file mode 100644 index 44061de7b8..0000000000 --- a/src/Graphic3d/Graphic3d_CGraduatedTrihedron.hxx +++ /dev/null @@ -1,104 +0,0 @@ -// Created on: 2011-03-06 -// Created by: Sergey ZERCHANINOV -// Copyright (c) 2011-2014 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 _Graphic3d_CGraduatedTrihedron_HeaderFile -#define _Graphic3d_CGraduatedTrihedron_HeaderFile - -#include -#include -#include -#include -#include -#include - -class Visual3d_View; - -//! Defines the C structure of a graduated trihedron. -class Graphic3d_CGraduatedTrihedron -{ -public: - typedef void (*minMaxValuesCallback)(Visual3d_View*); -public: - /* Default constructor. Nullifies the view pointer */ - Graphic3d_CGraduatedTrihedron () : xdrawname ( Standard_False ), - ydrawname ( Standard_False ), - zdrawname ( Standard_False ), - xdrawvalues ( Standard_False ), - ydrawvalues ( Standard_False ), - zdrawvalues ( Standard_False ), - drawgrid ( Standard_False ), - drawaxes ( Standard_False ), - nbx ( 0 ),nby ( 0 ),nbz ( 0 ), - xoffset ( 0 ),yoffset ( 0 ),zoffset ( 0 ), - xaxisoffset ( 0 ),yaxisoffset ( 0 ),zaxisoffset ( 0 ), - xdrawtickmarks ( Standard_False ), - ydrawtickmarks ( Standard_False ), - zdrawtickmarks ( Standard_False ), - xtickmarklength ( 0 ), ytickmarklength ( 0 ), ztickmarklength ( 0 ), - styleOfNames ( Font_FA_Undefined ), - sizeOfNames ( 0 ), - styleOfValues ( Font_FA_Undefined ), - sizeOfValues ( 0 ), - cbCubicAxes ( NULL ), - ptrVisual3dView(NULL) - { - // - } - - /* Names of axes */ - TCollection_ExtendedString xname, yname, zname; - /* Draw names */ - Standard_Boolean xdrawname, ydrawname, zdrawname; - /* Draw values */ - Standard_Boolean xdrawvalues, ydrawvalues, zdrawvalues; - /* Draw grid */ - Standard_Boolean drawgrid; - /* Draw axes */ - Standard_Boolean drawaxes; - /* Number of splits along axes */ - Standard_Integer nbx, nby, nbz; - /* Offset for drawing values */ - Standard_Integer xoffset, yoffset, zoffset; - /* Offset for drawing names of axes */ - Standard_Integer xaxisoffset, yaxisoffset, zaxisoffset; - /* Draw tickmarks */ - Standard_Boolean xdrawtickmarks, ydrawtickmarks, zdrawtickmarks; - /* Length of tickmarks */ - Standard_Integer xtickmarklength, ytickmarklength, ztickmarklength; - /* Grid color */ - Quantity_Color gridcolor; - /* Colors of axis names */ - Quantity_Color xnamecolor, ynamecolor, znamecolor; - /* Colors of axis and values */ - Quantity_Color xcolor, ycolor, zcolor; - /* Font name of names of axes: Courier, Arial, ... */ - TCollection_AsciiString fontOfNames; - /* Style of names of axes: OSD_FA_Regular, OSD_FA_Bold, ... */ - Font_FontAspect styleOfNames; - /* Size of names of axes: 8, 10, 12, 14, ... */ - Standard_Integer sizeOfNames; - /* Font name of values: Courier, Arial, ... */ - TCollection_AsciiString fontOfValues; - /* Style of values: OSD_FA_Regular, OSD_FA_Bold, ... */ - Font_FontAspect styleOfValues; - /* Size of values: 8, 10, 12, 14, ... */ - Standard_Integer sizeOfValues; - - /* Callback function to define boundary box of displayed objects */ - minMaxValuesCallback cbCubicAxes; - Visual3d_View* ptrVisual3dView; -}; - -#endif /*Graphic3d_CGraduatedTrihedron_HeaderFile*/ diff --git a/src/Graphic3d/Graphic3d_GraduatedTrihedron.hxx b/src/Graphic3d/Graphic3d_GraduatedTrihedron.hxx new file mode 100644 index 0000000000..8b277e830d --- /dev/null +++ b/src/Graphic3d/Graphic3d_GraduatedTrihedron.hxx @@ -0,0 +1,218 @@ +// Created on: 2011-03-06 +// Created by: Sergey ZERCHANINOV +// Copyright (c) 2011-2014 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 _Graphic3d_GraduatedTrihedron_HeaderFile +#define _Graphic3d_GraduatedTrihedron_HeaderFile + +#include +#include +#include +#include +#include +#include +#include + +class Visual3d_View; + +//! Class that stores style for one graduated trihedron axis such as colors, lengths and customization flags. +//! It is used in Graphic3d_GraduatedTrihedron. +class Graphic3d_AxisAspect +{ + public: + + 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_Boolean theToDrawName = Standard_True, + const Standard_Boolean theToDrawValues = Standard_True, + const Standard_Boolean theToDrawTickmarks = Standard_True) + : myName (theName), + myToDrawName (theToDrawName), + myToDrawTickmarks (theToDrawTickmarks), + myToDrawValues (theToDrawValues), + myNameColor (theNameColor), + myTickmarkNumber (theTickmarkNumber), + myTickmarkLength (theTickmarkLength), + myColor (theColor), + myValuesOffset (theValuesOffset), + myNameOffset (theNameOffset) + { } + +public: + + void SetName (const TCollection_ExtendedString& theName) { myName = theName; } + const TCollection_ExtendedString& Name() const { return myName; } + + const Standard_Boolean ToDrawName() const { return myToDrawName; } + void SetToDrawName (const Standard_Boolean theToDraw) { myToDrawName = theToDraw; } + + const Standard_Boolean ToDrawTickmarks() const { return myToDrawTickmarks; } + void SetToDrawTickmarks (const Standard_Boolean theToDraw) { myToDrawTickmarks = theToDraw; } + + const Standard_Boolean ToDrawValues() const { return myToDrawValues; } + void SetToDrawValues (const Standard_Boolean theToDraw) { myToDrawValues = theToDraw; } + + const Quantity_Color& NameColor() const { return myNameColor; } + void SetNameColor (const Quantity_Color& theColor) { myNameColor = theColor; } + + //! Color of axis and values + const Quantity_Color& Color() const { return myColor; } + + //! 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 TickmarkLength() const { return myTickmarkLength; } + void SetTickmarkLength (const Standard_Integer theValue) { myTickmarkLength = theValue; } + + const Standard_Integer ValuesOffset() const { return myValuesOffset; } + void SetValuesOffset (const Standard_Integer theValue) { myValuesOffset = theValue; } + + const Standard_Integer NameOffset() const { return myNameOffset; } + void SetNameOffset (const Standard_Integer theValue) { myNameOffset = theValue; } + +protected: + + TCollection_ExtendedString myName; + + Standard_Boolean myToDrawName; + Standard_Boolean myToDrawTickmarks; + Standard_Boolean myToDrawValues; + + 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 myValuesOffset; //!< Offset for drawing values + Standard_Integer myNameOffset; //!< Offset for drawing name of axis +}; + +//! Defines the class of a graduated trihedron. +//! It contains main style parameters for implementation of graduated trihedron +//! @sa OpenGl_GraduatedTrihedron +class Graphic3d_GraduatedTrihedron +{ +public: + + typedef void (*MinMaxValuesCallback) (Visual3d_View*); + +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 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_Boolean theToDrawGrid = Standard_True, const Standard_Boolean theToDrawAxes = Standard_True) + : myNamesFont (theNamesFont), + myNamesStyle (theNameStyle), + myNamesSize (theNamesSize), + myValuesFont (theValuesFont), + myValuesStyle (theValuesStyle), + myValuesSize (theValuesSize), + myArrowLength (theArrowLength), + myGridColor (theGridColor), + myToDrawGrid (theToDrawGrid), + myToDrawAxes (theToDrawAxes), + myAxes(0, 2) + { + myAxes (0) = Graphic3d_AxisAspect ("X", Quantity_NOC_RED, Quantity_NOC_RED); + myAxes (1) = Graphic3d_AxisAspect ("Y", Quantity_NOC_GREEN, Quantity_NOC_GREEN); + myAxes (2) = Graphic3d_AxisAspect ("Z", Quantity_NOC_BLUE1, Quantity_NOC_BLUE1); + PtrVisual3dView = NULL; + } + +public: + + Graphic3d_AxisAspect& ChangeXAxisAspect() { return myAxes(0); } + Graphic3d_AxisAspect& ChangeYAxisAspect() { return myAxes(1); } + Graphic3d_AxisAspect& ChangeZAxisAspect() { return myAxes(2); } + + const Graphic3d_AxisAspect& XAxisAspect() const { return myAxes(0); } + const Graphic3d_AxisAspect& YAxisAspect() const { return myAxes(1); } + const Graphic3d_AxisAspect& ZAxisAspect() const { return myAxes(2); } + + const Graphic3d_AxisAspect& AxisAspect (const Standard_Integer theIndex) const + { + Standard_OutOfRange_Raise_if (theIndex < 0 || theIndex > 2, "Graphic3d_GraduatedTrihedron::AxisAspect: theIndex is out of bounds [0,2]."); + return myAxes (theIndex); + } + + const Standard_ShortReal ArrowLength() const { return myArrowLength; } + void SetArrowLength (const Standard_ShortReal theValue) { myArrowLength = 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; } + + const Standard_Boolean ToDrawAxes() const { return myToDrawAxes; } + void SetToDrawAxes (const Standard_Boolean theToDraw) { myToDrawAxes = theToDraw; } + + const TCollection_AsciiString& NamesFont() const { return myNamesFont; } + void SetNamesFont (const TCollection_AsciiString& theFont) { myNamesFont = theFont; } + + const Font_FontAspect& NamesFontAspect() const { return myNamesStyle; } + void SetNamesFontAspect (const Font_FontAspect& theAspect) { myNamesStyle = theAspect; } + + const Standard_Integer NamesSize() const { return myNamesSize; } + void SetNamesSize (const Standard_Integer theValue) { myNamesSize = theValue; } + + const TCollection_AsciiString& ValuesFont () const { return myValuesFont; } + void SetValuesFont (const TCollection_AsciiString& theFont) { myValuesFont = theFont; } + + const Font_FontAspect& ValuesFontAspect() const { return myValuesStyle; } + void SetValuesFontAspect (const Font_FontAspect& theAspect) { myValuesStyle = theAspect; } + + const Standard_Integer ValuesSize() const { return myValuesSize; } + void SetValuesSize (const Standard_Integer theValue) { myValuesSize = theValue; } + +public: + + MinMaxValuesCallback CubicAxesCallback; //!< Callback function to define boundary box of displayed objects + Visual3d_View* PtrVisual3dView; + +protected: + + TCollection_AsciiString myNamesFont; //!< Font name of names of axes: Courier, Arial, ... + Font_FontAspect myNamesStyle; //!< Style of names of axes: OSD_FA_Regular, OSD_FA_Bold,.. + Standard_Integer myNamesSize; //!< Size of names of axes: 8, 10,.. + +protected: + + TCollection_AsciiString myValuesFont; //!< Font name of values: Courier, Arial, ... + Font_FontAspect myValuesStyle; //!< Style of values: OSD_FA_Regular, OSD_FA_Bold, ... + Standard_Integer myValuesSize; //!< Size of values: 8, 10, 12, 14, ... + +protected: + + Standard_ShortReal myArrowLength; + Quantity_Color myGridColor; + + Standard_Boolean myToDrawGrid; + Standard_Boolean myToDrawAxes; + + NCollection_Array1 myAxes; //!< X, Y and Z axes parameters + +}; +#endif // Graphic3d_GraduatedTrihedron_HeaderFile diff --git a/src/Graphic3d/Graphic3d_GraphicDriver.cdl b/src/Graphic3d/Graphic3d_GraphicDriver.cdl index eb31bcb699..0211cf5800 100644 --- a/src/Graphic3d/Graphic3d_GraphicDriver.cdl +++ b/src/Graphic3d/Graphic3d_GraphicDriver.cdl @@ -86,8 +86,9 @@ uses CUserDraw from Graphic3d, NListOfHAsciiString from Graphic3d, FontAspect from Font, - CGraduatedTrihedron from Graphic3d, + GraduatedTrihedron from Graphic3d, ClipPlane from Graphic3d, + Vec3 from Graphic3d, Ax2 from gp raises @@ -328,24 +329,26 @@ is --------------------------------- GraduatedTrihedronDisplay(me : mutable; - view : CView from Graphic3d; - cubic : CGraduatedTrihedron from Graphic3d) + theView : CView from Graphic3d; + theCubic : GraduatedTrihedron from Graphic3d) ---Purpose: call_togl_graduatedtrihedron_display is deferred; GraduatedTrihedronErase(me : mutable; - view : CView from Graphic3d) + theView : CView from Graphic3d) ---Purpose: call_togl_graduatedtrihedron_erase is deferred; - GraduatedTrihedronMinMaxValues(me : mutable; - xmin : ShortReal from Standard; - ymin : ShortReal from Standard; - zmin : ShortReal from Standard; - xmax : ShortReal from Standard; - ymax : ShortReal from Standard; - zmax : ShortReal from Standard) - ---Purpose: call_togl_graduatedtrihedron_minmaxvalues + GraduatedTrihedronMinMaxValues (me : mutable; + theView : CView from Graphic3d; + theMin : Vec3 from Graphic3d; + theMax : Vec3 from Graphic3d) + ---Purpose: Sets minimum and maximum points of scene bounding box for Graduated Trihedron + -- stored in graphic view object. + -- @param theView [in] current graphic view + -- @param theMin [in] the minimum point of scene. + -- @param theMax [in] the maximum point of scene. + is deferred; ---------------------------------- diff --git a/src/OpenGl/OpenGl_GraduatedTrihedron.cxx b/src/OpenGl/OpenGl_GraduatedTrihedron.cxx index 1054441d09..c4cc832cc5 100755 --- a/src/OpenGl/OpenGl_GraduatedTrihedron.cxx +++ b/src/OpenGl/OpenGl_GraduatedTrihedron.cxx @@ -14,7 +14,7 @@ // commercial license or contractual agreement. #include - +#include #include #include #include @@ -23,191 +23,72 @@ #include #endif -#include #include + +#include +#include +#include +#include #include #include #include +#include +#include -const OpenGl_AspectLine myDefaultAspectLine; - -static const OpenGl_TextParam THE_LABEL_PARAMS = +// ======================================================================= +// function : Constructor +// purpose : +// ======================================================================= +OpenGl_GraduatedTrihedron::OpenGl_GraduatedTrihedron (const Graphic3d_GraduatedTrihedron& theData) +: myMin (0.0f, 0.0f, 0.0f), + myMax (100.0f, 100.0f, 100.0f), + myData (theData) { - 16, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM -}; + // 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)); -/* Bounding box */ -float xmin = 0.0f, ymin = 0.0f, zmin = 0.0f, xmax = 100.0f, ymax = 100.0f, zmax = 100.0f; + // Initialize constant primitives: text, arrows. -/* Normal of the view (not normalized!) */ -static float getNormal(float* normal) -{ -#if !defined(GL_ES_VERSION_2_0) - GLint viewport[4]; - GLdouble model_matrix[16], proj_matrix[16]; + myAxes[0].InitArrow (NULL, myData.ArrowLength(), OpenGl_Vec3 (0.0f, 0.0f, 1.0f)); - glGetDoublev(GL_MODELVIEW_MATRIX, model_matrix); - glGetDoublev(GL_PROJECTION_MATRIX, proj_matrix); - glGetIntegerv(GL_VIEWPORT, viewport); + myAxes[1].InitArrow (NULL, myData.ArrowLength(), OpenGl_Vec3 (0.0f, 0.0f, 1.0f)); - double x1, y1, z1, x2, y2, z2, x3, y3, z3; - OpenGl_Utils::UnProject (viewport[0], - viewport[1], - 0.0, - OpenGl_Mat4d::Map (model_matrix), - OpenGl_Mat4d::Map (proj_matrix), - viewport, - x1, - y1, - z1); + myAxes[2].InitArrow (NULL, myData.ArrowLength(), OpenGl_Vec3 (1.0f, 0.0f, 0.0f)); - OpenGl_Utils::UnProject (viewport[0] + viewport[2], - viewport[1], - 0.0, - OpenGl_Mat4d::Map (model_matrix), - OpenGl_Mat4d::Map (proj_matrix), - viewport, - x2, - y2, - z2); + for (Standard_Integer anIt = 0; anIt < 3; ++anIt) + { + myAxes[anIt].Label.SetFontSize (NULL, theData.NamesSize()); + } - OpenGl_Utils::UnProject (viewport[0], - viewport[1] + viewport[3], - 0.0, - OpenGl_Mat4d::Map (model_matrix), - OpenGl_Mat4d::Map (proj_matrix), - viewport, - x3, - y3, - z3); + myLabelValues.SetFontSize (NULL, theData.ValuesSize()); - /* Normal out of user is p1p3^p1p2 */ - const double dx1 = x3 - x1; - const double dy1 = y3 - y1; - const double dz1 = z3 - z1; - const double dx2 = x2 - x1; - const double dy2 = y2 - y1; - const double dz2 = z2 - z1; - normal[0] = (float) (dy1 * dz2 - dz1 * dy2); - normal[1] = (float) (dz1 * dx2 - dx1 * dz2); - normal[2] = (float) (dx1 * dy2 - dy1 * dx2); + myAspectLabels.SetFontAspect (theData.NamesFontAspect()); + myAspectLabels.ChangeFontName() = theData.NamesFont(); - /* Distance corresponding to 1 pixel */ - const float width = (float) sqrt(dx2 * dx2 + dy2 * dy2 + dz2 * dz2); - return width / (float) viewport[2]; -#else - return 1.0f; -#endif + myAspectValues.SetFontAspect (theData.ValuesFontAspect()); + 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); } -static float getDistance2Corner(float* normal, float* center, float x, float y, float z) +// ======================================================================= +// function : Destructor +// purpose : +// ======================================================================= +OpenGl_GraduatedTrihedron::~OpenGl_GraduatedTrihedron() { - return normal[0] * (x - center[0]) + normal[1] * (y - center[1]) + normal[2] * (z - center[2]); -} - -static char getFarestCorner(float d000, float d100, float d010, float d001, - float d110, float d101, float d011, float d111) -{ - if (d000 > 0.0f && - d000 > d100 && d000 > d010 && d000 > d001 && d000 > d110 && - d000 > d101 && d000 > d011 && d000 > d111) - { - return 1; - } - else if (d100 > 0.0f && - d100 > d000 && d100 > d010 && d100 > d001 && d100 > d110 && - d100 > d101 && d100 > d011 && d100 > d111) - { - return 2; - } - else if (d010 > 0.0f && - d010 > d000 && d010 > d100 && d010 > d001 && d010 > d110 && - d010 > d101 && d010 > d011 && d010 > d111) - { - return 3; - } - else if (d001 > 0.0f && - d001 > d000 && d001 > d100 && d001 > d010 && d001 > d110 && - d001 > d101 && d001 > d011 && d001 > d111) - { - return 4; - } - else if (d110 > 0.0f && - d110 > d000 && d110 > d100 && d110 > d010 && d110 > d001 && - d110 > d101 && d110 > d011 && d110 > d111) - { - return 5; - } - else if (d101 > 0.0f && - d101 > d000 && d101 > d100 && d101 > d010 && d101 > d001 && - d101 > d110 && d101 > d011 && d101 > d111) - { - return 6; - } - else if (d011 > 0.0f && - d011 > d000 && d011 > d100 && d011 > d010 && d011 > d001 && - d011 > d110 && d011 > d101 && d011 > d111) - { - return 7; - } - return 8; /* d111 */ -} - -static void drawArrow(float x1, float y1, float z1, - float x2, float y2, float z2, - float xn, float yn, float zn) -{ -#if !defined(GL_ES_VERSION_2_0) - float h, r; - float xa, ya, za; - float x0, y0, z0; - float xr, yr, zr; - float xa1, ya1, za1, xa2, ya2, za2; - - /* Start of arrow: at 10% from the end */ - x0 = x1 + 0.9f * (x2 - x1); y0 = y1 + 0.9f * (y2 - y1); z0 = z1 + 0.9f * (z2 - z1); - - /* Base of the arrow */ - xa = (x2 - x0); ya = (y2 - y0); za = (z2 - z0); - - /* Height of the arrow */ - h = sqrtf(xa * xa + ya * ya + za * za); - if (h <= 0.0f) - return; - xa = xa / h; ya = ya / h; za = za / h; - - /* Radial direction to the arrow */ - xr = ya * zn - za * yn; - yr = za * xn - xa * zn; - zr = xa * yn - ya * xn; - - /* Normalize the radial vector */ - r = sqrtf(xr * xr + yr * yr + zr * zr); - if (r <= 0.0f) - return; - xr = xr / r; yr = yr / r; zr = zr / r; - - /* First point of the base of the arrow */ - r = 0.2f * h; - xr = r * xr; yr = r * yr; zr = r * zr; - xa1 = x0 + xr; ya1 = y0 + yr; za1 = z0 + zr; - - /* Second point of the base of the arrow */ - xa2 = x0 - xr; ya2 = y0 - yr; za2 = z0 - zr; - - /* Draw a line to the arrow */ - glBegin(GL_LINES); - glVertex3f(x1, y1, z1); - glVertex3f(x0, y0, z0); - glEnd(); - - /* Draw a triangle of the arrow */ - glBegin(GL_LINE_LOOP); - glVertex3f(xa1, ya1, za1); - glVertex3f(xa2, ya2, za2); - glVertex3f(x2, y2, z2); - glEnd(); -#endif + // } // ======================================================================= @@ -216,788 +97,722 @@ static void drawArrow(float x1, float y1, float z1, // ======================================================================= void OpenGl_GraduatedTrihedron::Release (OpenGl_Context* theCtx) { - myLabelX.Release (theCtx); - myLabelY.Release (theCtx); - myLabelZ.Release (theCtx); + myAxes[0].Release (theCtx); + myAxes[1].Release (theCtx); + myAxes[2].Release (theCtx); myLabelValues.Release (theCtx); } -OpenGl_GraduatedTrihedron::OpenGl_GraduatedTrihedron (const Graphic3d_CGraduatedTrihedron& theData) -: myLabelX (NCollection_String ((Standard_Utf16Char* )theData.xname.ToExtString()).ToCString(), OpenGl_Vec3(1.0f, 0.0f, 0.0f), THE_LABEL_PARAMS), - myLabelY (NCollection_String ((Standard_Utf16Char* )theData.yname.ToExtString()).ToCString(), OpenGl_Vec3(0.0f, 1.0f, 0.0f), THE_LABEL_PARAMS), - myLabelZ (NCollection_String ((Standard_Utf16Char* )theData.zname.ToExtString()).ToCString(), OpenGl_Vec3(0.0f, 0.0f, 1.0f), THE_LABEL_PARAMS), - myToDrawXName (theData.xdrawname == Standard_True), - myToDrawYName (theData.ydrawname == Standard_True), - myToDrawZName (theData.zdrawname == Standard_True), - myToDrawXValues (theData.xdrawvalues == Standard_True), - myToDrawYValues (theData.ydrawvalues == Standard_True), - myToDrawZValues (theData.zdrawvalues == Standard_True), - myToDrawGrid (theData.drawgrid == Standard_True), - myToDrawAxes (theData.drawaxes == Standard_True), - myNbX (theData.nbx), - myNbY (theData.nby), - myNbZ (theData.nbz), - myXOffset (theData.xoffset), - myYOffset (theData.yoffset), - myZOffset (theData.zoffset), - myXAxisOffset (theData.xaxisoffset), - myYAxisOffset (theData.yaxisoffset), - myZAxisOffset (theData.zaxisoffset), - myDrawXTickmarks (theData.xdrawtickmarks), - myDrawYTickmarks (theData.ydrawtickmarks), - myDrawZTickmarks (theData.zdrawtickmarks), - myXTickmarkLength (theData.xtickmarklength), - myYTickmarkLength (theData.ytickmarklength), - myZTickmarkLength (theData.ztickmarklength), - myCbCubicAxes (theData.cbCubicAxes), - myPtrVisual3dView (theData.ptrVisual3dView) +// ======================================================================= +// method : getNormal +// purpose : Normal of the view (not normalized!) +// ======================================================================= +Standard_ShortReal OpenGl_GraduatedTrihedron::getNormal (const Handle(OpenGl_Context)& theContext, + OpenGl_Vec3& theNormal) const { - myAspectLabels.ChangeFontName() = theData.fontOfNames; - myAspectValues.ChangeFontName() = theData.fontOfValues; - myAspectLabels.SetFontAspect (theData.styleOfNames); - myAspectValues.SetFontAspect (theData.styleOfValues); - myLabelX.SetFontSize (NULL, theData.sizeOfNames); - myLabelY.SetFontSize (NULL, theData.sizeOfNames); - myLabelZ.SetFontSize (NULL, theData.sizeOfNames); - myLabelValues.SetFontSize (NULL, theData.sizeOfValues); + GLint aViewport[4] = {}; + glGetIntegerv(GL_VIEWPORT, aViewport); - // Grid color - myGridColor[0] = (float) theData.gridcolor.Red(); - myGridColor[1] = (float) theData.gridcolor.Green(); - myGridColor[2] = (float) theData.gridcolor.Blue(); - // X name color - myXNameColor.rgb[0] = (float )theData.xnamecolor.Red(); - myXNameColor.rgb[1] = (float )theData.xnamecolor.Green(); - myXNameColor.rgb[2] = (float )theData.xnamecolor.Blue(); - myXNameColor.rgb[3] = 1.0f; - // Y name color - myYNameColor.rgb[0] = (float )theData.ynamecolor.Red(); - myYNameColor.rgb[1] = (float )theData.ynamecolor.Green(); - myYNameColor.rgb[2] = (float )theData.ynamecolor.Blue(); - myYNameColor.rgb[3] = 1.0f; - // Z name color - myZNameColor.rgb[0] = (float )theData.znamecolor.Red(); - myZNameColor.rgb[1] = (float )theData.znamecolor.Green(); - myZNameColor.rgb[2] = (float )theData.znamecolor.Blue(); - myZNameColor.rgb[3] = 1.0f; - // X color of axis and values - myXColor.rgb[0] = (float )theData.xcolor.Red(); - myXColor.rgb[1] = (float )theData.xcolor.Green(); - myXColor.rgb[2] = (float )theData.xcolor.Blue(); - myXColor.rgb[3] = 1.0f; - // Y color of axis and values - myYColor.rgb[0] = (float )theData.ycolor.Red(); - myYColor.rgb[1] = (float )theData.ycolor.Green(); - myYColor.rgb[2] = (float )theData.ycolor.Blue(); - myYColor.rgb[3] = 1.0f; - // Z color of axis and values - myZColor.rgb[0] = (float )theData.zcolor.Red(); - myZColor.rgb[1] = (float )theData.zcolor.Green(); - myZColor.rgb[2] = (float )theData.zcolor.Blue(); - myZColor.rgb[3] = 1.0f; + OpenGl_Mat4 aModelMatrix; + OpenGl_Mat4 aProjMatrix; + aModelMatrix.Convert (theContext->ModelWorldState.Current() * theContext->WorldViewState.Current()); + aProjMatrix .Convert (theContext->ProjectionState.Current()); + + OpenGl_Vec3 aPoint1, aPoint2, aPoint3; + OpenGl_Utils::UnProject ((Standard_ShortReal) aViewport[0], + (Standard_ShortReal) aViewport[1], + 0.0f, + aModelMatrix, aProjMatrix, aViewport, + aPoint1.x(), aPoint1.y(), aPoint1.z()); + + OpenGl_Utils::UnProject ((Standard_ShortReal) (aViewport[0] + aViewport[2]), + (Standard_ShortReal) aViewport[1], + 0.0f, + aModelMatrix, aProjMatrix, aViewport, + aPoint2.x(), aPoint2.y(), aPoint2.z()); + + OpenGl_Utils::UnProject ((Standard_ShortReal) aViewport[0], + (Standard_ShortReal) (aViewport[1] + aViewport[3]), + 0.0f, + aModelMatrix, aProjMatrix, aViewport, + aPoint3.x(), aPoint3.y(), aPoint3.z()); + + const OpenGl_Vec3 aD1 = aPoint3 - aPoint1; + const OpenGl_Vec3 aD2 = aPoint2 - aPoint1; + theNormal = OpenGl_Vec3::Cross (aD1, aD2); + + // Distance corresponding to 1 pixel + return aD2.Modulus() / (float) aViewport[2]; } -OpenGl_GraduatedTrihedron::~OpenGl_GraduatedTrihedron() +// ======================================================================= +// method : getDistancetoCorner +// purpose : +// ======================================================================= +Standard_ShortReal OpenGl_GraduatedTrihedron::getDistanceToCorner (const OpenGl_Vec3& theNormal, + const OpenGl_Vec3& theCenter, + const Standard_ShortReal theX, + const Standard_ShortReal theY, + const Standard_ShortReal theZ) const { - // + return theNormal.x() * (theX - theCenter.x()) + + theNormal.y() * (theY - theCenter.y()) + + theNormal.z() * (theZ - theCenter.z()); } -//call_graduatedtrihedron_redraw -void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace)& theWorkspace) const +// ======================================================================= +// method : getGridAxes +// purpose : +// ======================================================================= +Standard_ExtCharacter OpenGl_GraduatedTrihedron::getGridAxes (const Standard_ShortReal theCorners[8], + GridAxes& theGridAxes) const { -#if !defined(GL_ES_VERSION_2_0) - const OpenGl_AspectLine *oldAspectLine = theWorkspace->SetAspectLine(&myDefaultAspectLine); - theWorkspace->AspectLine(Standard_True); + // Find the farest corner + Standard_Byte aMaxIndex = 0; + Standard_ShortReal aMax = theCorners[aMaxIndex] > 0.0f ? theCorners[aMaxIndex] : 0.0f; - /* Update boundary box */ - if (myCbCubicAxes) - myCbCubicAxes(myPtrVisual3dView); - - /* Disable lighting for lines */ - GLboolean light = glIsEnabled(GL_LIGHTING); - if (light) - glDisable(GL_LIGHTING); - - /* Find the farest point of bounding box */ - - /* Get normal of the view out of user. */ - /* Also, the method return distance corresponding to 1 pixel */ - float normal[3]; - float dpix = getNormal(normal); - - /* Normalize normal */ - float d = sqrtf(normal[0] * normal[0] + normal[1] * normal[1] + normal[2] * normal[2]); - normal[0] /= d; - normal[1] /= d; - normal[2] /= d; - - /* Get central point of bounding box */ - float center[3]; - center[0] = 0.5f * (xmin + xmax); - center[1] = 0.5f * (ymin + ymax); - center[2] = 0.5f * (zmin + zmax); - - /* Check distance to corners of bounding box along the normal */ - float d000 = getDistance2Corner(normal, center, xmin, ymin, zmin); - float d100 = getDistance2Corner(normal, center, xmax, ymin, zmin); - float d010 = getDistance2Corner(normal, center, xmin, ymax, zmin); - float d001 = getDistance2Corner(normal, center, xmin, ymin, zmax); - float d110 = getDistance2Corner(normal, center, xmax, ymax, zmin); - float d101 = getDistance2Corner(normal, center, xmax, ymin, zmax); - float d011 = getDistance2Corner(normal, center, xmin, ymax, zmax); - float d111 = getDistance2Corner(normal, center, xmax, ymax, zmax); - unsigned char farestCorner = getFarestCorner(d000, d100, d010, d001, d110, d101, d011, d111); - - /* Choose axes for the grid. */ - float LX1[6], LX2[6], LX3[6]; /* Lines along X direction */ - float LY1[6], LY2[6], LY3[6]; /* Lines along Y direction */ - float LZ1[6], LZ2[6], LZ3[6]; /* Lines along Z direction */ - unsigned char LX1draw = 0, LX2draw = 0, LX3draw = 0; /* Allows drawing of X-line (000 - 100 is forbidden) */ - unsigned char LY1draw = 0, LY2draw = 0, LY3draw = 0; /* Allows drawing of Y-line (000 - 010 is forbidden) */ - unsigned char LZ1draw = 0, LZ2draw = 0, LZ3draw = 0; /* Allows drawing of Z-line (000 - 001 is forbidden) */ - - /* The first axis will be used for drawing the text and the values. */ - switch (farestCorner) + for (Standard_Byte anIt = 0; anIt < 8; ++anIt) { - case 1: /* d000 */ + if (theCorners[anIt] > aMax) { - /* 001 - 101 */ - LX1draw = 1; - LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmax; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmax; - /* 000 - 100 */ - LX2draw = 0; /* forbidden! */ - LX2[0] = xmin; LX2[1] = ymin; LX2[2] = zmin; LX2[3] = xmax; LX2[4] = ymin; LX2[5] = zmin; - /* 010 - 110 */ - LX3draw = 1; - LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmin; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmin; - - /* 100 - 110 */ - LY1draw = 1; - LY1[0] = xmax; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmax; LY1[4] = ymax; LY1[5] = zmin; - /* 000 - 010 */ - LY2draw = 0; /* forbidden! */ - LY2[0] = xmin; LY2[1] = ymin; LY2[2] = zmin; LY2[3] = xmin; LY2[4] = ymax; LY2[5] = zmin; - /* 001 - 011 */ - LY3draw = 1; - LY3[0] = xmin; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmin; LY3[4] = ymax; LY3[5] = zmax; - - /* 100 - 101 */ - LZ1draw = 1; - LZ1[0] = xmax; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmax; LZ1[4] = ymin; LZ1[5] = zmax; - /* 000 - 001 */ - LZ2draw = 0; /* forbidden! */ - LZ2[0] = xmin; LZ2[1] = ymin; LZ2[2] = zmin; LZ2[3] = xmin; LZ2[4] = ymin; LZ2[5] = zmax; - /* 010 - 011 */ - LZ3draw = 1; - LZ3[0] = xmin; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmin; LZ3[4] = ymax; LZ3[5] = zmax; - - break; - } - case 2: /* d100 */ - { - /* 001 - 101 */ - LX1draw = 1; - LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmax; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmax; - /* 000 - 100 */ - LX2draw = 0; /* forbidden! */ - LX2[0] = xmin; LX2[1] = ymin; LX2[2] = zmin; LX2[3] = xmax; LX2[4] = ymin; LX2[5] = zmin; - /* 010 - 110 */ - LX3draw = 1; - LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmin; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmin; - - /* 000 - 010 */ - LY1draw = 0; /* forbidden! */ - LY1[0] = xmin; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmin; LY1[4] = ymax; LY1[5] = zmin; - /* 100 - 110 */ - LY2draw = 1; - LY2[0] = xmax; LY2[1] = ymin; LY2[2] = zmin; LY2[3] = xmax; LY2[4] = ymax; LY2[5] = zmin; - /* 101 - 111 */ - LY3draw = 1; - LY3[0] = xmax; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmax; LY3[4] = ymax; LY3[5] = zmax; - - /* 000 - 001 */ - LZ1draw = 0; /* forbidden! */ - LZ1[0] = xmin; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmin; LZ1[4] = ymin; LZ1[5] = zmax; - /* 100 - 101 */ - LZ2draw = 1; - LZ2[0] = xmax; LZ2[1] = ymin; LZ2[2] = zmin; LZ2[3] = xmax; LZ2[4] = ymin; LZ2[5] = zmax; - /* 110 - 111 */ - LZ3draw = 1; - LZ3[0] = xmax; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmax; LZ3[4] = ymax; LZ3[5] = zmax; - - break; - } - case 3: /* d010 */ - { - /* 000 - 100 */ - LX1draw = 0; /* forbidden */ - LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmin; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmin; - /* 010 - 110 */ - LX2draw = 1; - LX2[0] = xmin; LX2[1] = ymax; LX2[2] = zmin; LX2[3] = xmax; LX2[4] = ymax; LX2[5] = zmin; - /* 011 - 111 */ - LX3draw = 1; - LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmax; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmax; - - /* 100 - 110 */ - LY1draw = 1; - LY1[0] = xmax; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmax; LY1[4] = ymax; LY1[5] = zmin; - /* 000 - 010 */ - LY2draw = 0; /* forbidden */ - LY2[0] = xmin; LY2[1] = ymin; LY2[2] = zmin; LY2[3] = xmin; LY2[4] = ymax; LY2[5] = zmin; - /* 001 - 011 */ - LY3draw = 1; - LY3[0] = xmin; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmin; LY3[4] = ymax; LY3[5] = zmax; - - /* 110 - 111 */ - LZ1draw = 1; - LZ1[0] = xmax; LZ1[1] = ymax; LZ1[2] = zmin; LZ1[3] = xmax; LZ1[4] = ymax; LZ1[5] = zmax; - /* 010 - 011 */ - LZ2draw = 1; - LZ2[0] = xmin; LZ2[1] = ymax; LZ2[2] = zmin; LZ2[3] = xmin; LZ2[4] = ymax; LZ2[5] = zmax; - /* 000 - 001 */ - LZ3draw = 0; /* forbidden */ - LZ3[0] = xmin; LZ3[1] = ymin; LZ3[2] = zmin; LZ3[3] = xmin; LZ3[4] = ymin; LZ3[5] = zmax; - - break; - } - case 4: /* d001 */ - { - /* 000 - 100 */ - LX1draw = 0; /* forbidden */ - LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmin; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmin; - /* 001 - 101 */ - LX2draw = 1; - LX2[0] = xmin; LX2[1] = ymin; LX2[2] = zmax; LX2[3] = xmax; LX2[4] = ymin; LX2[5] = zmax; - /* 011 - 111 */ - LX3draw = 1; - LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmax; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmax; - - /* 000 - 010 */ - LY1draw = 0; /* forbidden */ - LY1[0] = xmin; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmin; LY1[4] = ymax; LY1[5] = zmin; - /* 001 - 011 */ - LY2draw = 1; - LY2[0] = xmin; LY2[1] = ymin; LY2[2] = zmax; LY2[3] = xmin; LY2[4] = ymax; LY2[5] = zmax; - /* 101 - 111 */ - LY3draw = 1; - LY3[0] = xmax; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmax; LY3[4] = ymax; LY3[5] = zmax; - - /* 100 - 101 */ - LZ1draw = 1; - LZ1[0] = xmax; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmax; LZ1[4] = ymin; LZ1[5] = zmax; - /* 000 - 001 */ - LZ2draw = 0; /* forbidden */ - LZ2[0] = xmin; LZ2[1] = ymin; LZ2[2] = zmin; LZ2[3] = xmin; LZ2[4] = ymin; LZ2[5] = zmax; - /* 010 - 011 */ - LZ3draw = 1; - LZ3[0] = xmin; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmin; LZ3[4] = ymax; LZ3[5] = zmax; - - break; - } - case 5: /* d110 */ - { - /* 000 - 100 */ - LX1draw = 0; /* forbidden */ - LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmin; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmin; - /* 010 - 110 */ - LX2draw = 1; - LX2[0] = xmin; LX2[1] = ymax; LX2[2] = zmin; LX2[3] = xmax; LX2[4] = ymax; LX2[5] = zmin; - /* 011 - 111 */ - LX3draw = 1; - LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmax; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmax; - - /* 000 - 010 */ - LY1draw = 0; /* forbidden */ - LY1[0] = xmin; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmin; LY1[4] = ymax; LY1[5] = zmin; - /* 100 - 110 */ - LY2draw = 1; - LY2[0] = xmax; LY2[1] = ymin; LY2[2] = zmin; LY2[3] = xmax; LY2[4] = ymax; LY2[5] = zmin; - /* 101 - 111 */ - LY3draw = 1; - LY3[0] = xmax; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmax; LY3[4] = ymax; LY3[5] = zmax; - - /* 100 - 101 */ - LZ1draw = 1; - LZ1[0] = xmax; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmax; LZ1[4] = ymin; LZ1[5] = zmax; - /* 110 - 111 */ - LZ2draw = 1; - LZ2[0] = xmax; LZ2[1] = ymax; LZ2[2] = zmin; LZ2[3] = xmax; LZ2[4] = ymax; LZ2[5] = zmax; - /* 010 - 011 */ - LZ3draw = 1; - LZ3[0] = xmin; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmin; LZ3[4] = ymax; LZ3[5] = zmax; - - break; - } - case 6: /* d101 */ - { - /* 000 - 100 */ - LX1draw = 0; /* forbidden */ - LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmin; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmin; - /* 001 - 101 */ - LX2draw = 1; - LX2[0] = xmin; LX2[1] = ymin; LX2[2] = zmax; LX2[3] = xmax; LX2[4] = ymin; LX2[5] = zmax; - /* 011 - 111 */ - LX3draw = 1; - LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmax; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmax; - - /* 100 - 110 */ - LY1draw = 1; - LY1[0] = xmax; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmax; LY1[4] = ymax; LY1[5] = zmin; - /* 101 - 111 */ - LY2draw = 1; - LY2[0] = xmax; LY2[1] = ymin; LY2[2] = zmax; LY2[3] = xmax; LY2[4] = ymax; LY2[5] = zmax; - /* 001 - 011 */ - LY3draw = 1; - LY3[0] = xmin; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmin; LY3[4] = ymax; LY3[5] = zmax; - - /* 000 - 001 */ - LZ1draw = 0; /* forbidden */ - LZ1[0] = xmin; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmin; LZ1[4] = ymin; LZ1[5] = zmax; - /* 100 - 101 */ - LZ2draw = 1; - LZ2[0] = xmax; LZ2[1] = ymin; LZ2[2] = zmin; LZ2[3] = xmax; LZ2[4] = ymin; LZ2[5] = zmax; - /* 110 - 111 */ - LZ3draw = 1; - LZ3[0] = xmax; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmax; LZ3[4] = ymax; LZ3[5] = zmax; - - break; - } - case 7: /* d011 */ - { - /* 001 - 101 */ - LX1draw = 1; - LX1[0] = xmin; LX1[1] = ymin; LX1[2] = zmax; LX1[3] = xmax; LX1[4] = ymin; LX1[5] = zmax; - /* 011 - 111 */ - LX2draw = 1; - LX2[0] = xmin; LX2[1] = ymax; LX2[2] = zmax; LX2[3] = xmax; LX2[4] = ymax; LX2[5] = zmax; - /* 010 - 110 */ - LX3draw = 1; - LX3[0] = xmin; LX3[1] = ymax; LX3[2] = zmin; LX3[3] = xmax; LX3[4] = ymax; LX3[5] = zmin; - - /* 000 - 010 */ - LY1draw = 0; /* forbidden */ - LY1[0] = xmin; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmin; LY1[4] = ymax; LY1[5] = zmin; - /* 001 - 011 */ - LY2draw = 1; - LY2[0] = xmin; LY2[1] = ymin; LY2[2] = zmax; LY2[3] = xmin; LY2[4] = ymax; LY2[5] = zmax; - /* 101 - 111 */ - LY3draw = 1; - LY3[0] = xmax; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmax; LY3[4] = ymax; LY3[5] = zmax; - - /* 000 - 001 */ - LZ1draw = 0; /* forbidden */ - LZ1[0] = xmin; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmin; LZ1[4] = ymin; LZ1[5] = zmax; - /* 010 - 011 */ - LZ2draw = 1; - LZ2[0] = xmin; LZ2[1] = ymax; LZ2[2] = zmin; LZ2[3] = xmin; LZ2[4] = ymax; LZ2[5] = zmax; - /* 110 - 111 */ - LZ3draw = 1; - LZ3[0] = xmax; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmax; LZ3[4] = ymax; LZ3[5] = zmax; - - break; - } - case 8: /* d111 */ - { - /* 010 - 110 */ - LX1draw = 1; - LX1[0] = xmin; LX1[1] = ymax; LX1[2] = zmin; LX1[3] = xmax; LX1[4] = ymax; LX1[5] = zmin; - /* 011 - 111 */ - LX2draw = 1; - LX2[0] = xmin; LX2[1] = ymax; LX2[2] = zmax; LX2[3] = xmax; LX2[4] = ymax; LX2[5] = zmax; - /* 001 - 101 */ - LX3draw = 1; - LX3[0] = xmin; LX3[1] = ymin; LX3[2] = zmax; LX3[3] = xmax; LX3[4] = ymin; LX3[5] = zmax; - - /* 100 - 110 */ - LY1draw = 1; - LY1[0] = xmax; LY1[1] = ymin; LY1[2] = zmin; LY1[3] = xmax; LY1[4] = ymax; LY1[5] = zmin; - /* 101 - 111 */ - LY2draw = 1; - LY2[0] = xmax; LY2[1] = ymin; LY2[2] = zmax; LY2[3] = xmax; LY2[4] = ymax; LY2[5] = zmax; - /* 001 - 011 */ - LY3draw = 1; - LY3[0] = xmin; LY3[1] = ymin; LY3[2] = zmax; LY3[3] = xmin; LY3[4] = ymax; LY3[5] = zmax; - - /* 100 - 101 */ - LZ1draw = 1; - LZ1[0] = xmax; LZ1[1] = ymin; LZ1[2] = zmin; LZ1[3] = xmax; LZ1[4] = ymin; LZ1[5] = zmax; - /* 110 - 111 */ - LZ2draw = 1; - LZ2[0] = xmax; LZ2[1] = ymax; LZ2[2] = zmin; LZ2[3] = xmax; LZ2[4] = ymax; LZ2[5] = zmax; - /* 010 - 011 */ - LZ3draw = 1; - LZ3[0] = xmin; LZ3[1] = ymax; LZ3[2] = zmin; LZ3[3] = xmin; LZ3[4] = ymax; LZ3[5] = zmax; - - break; + aMax = theCorners[anIt]; + aMaxIndex = anIt; } } - // Draw the graduated trihedron - unsigned int i, offset; - float m1[3], m2[3]; - float step, dx, dy, dz; - - // Grid - if (myToDrawGrid) + switch (aMaxIndex) { - glColor3fv(myGridColor); - glBegin(GL_LINES); - // Boundary grid-lines - if (LX1draw == 1) + case 0: // (0,0,0) { - glVertex3fv(&(LX1[0])); - glVertex3fv(&(LX1[3])); - } - if (LX2draw == 1) - { - glVertex3fv(&(LX2[0])); - glVertex3fv(&(LX2[3])); - } - if (LX3draw == 1) - { - glVertex3fv(&(LX3[0])); - glVertex3fv(&(LX3[3])); - } - if (LY1draw == 1) - { - glVertex3fv(&(LY1[0])); - glVertex3fv(&(LY1[3])); - } - if (LY2draw == 1) - { - glVertex3fv(&(LY2[0])); - glVertex3fv(&(LY2[3])); - } - if (LY3draw == 1) - { - glVertex3fv(&(LY3[0])); - glVertex3fv(&(LY3[3])); - } - if (LZ1draw == 1) - { - glVertex3fv(&(LZ1[0])); - glVertex3fv(&(LZ1[3])); - } - if (LZ2draw == 1) - { - glVertex3fv(&(LZ2[0])); - glVertex3fv(&(LZ2[3])); - } - if (LZ3draw == 1) - { - glVertex3fv(&(LZ3[0])); - glVertex3fv(&(LZ3[3])); - } - glEnd(); + theGridAxes.Origin = OpenGl_Vec3 (myMin.x(), myMin.y(), myMin.z()); + theGridAxes.Axes[0] = OpenGl_Vec3 (1.0f, 0.0f, 0.0f); + theGridAxes.Axes[1] = OpenGl_Vec3 (0.0f, 1.0f, 0.0f); + theGridAxes.Axes[2] = OpenGl_Vec3 (0.0f, 0.0f, 1.0f); - /* Intermediate grid-lines */ - /* X-Grid lines */ - if (myNbX > 0) - { - i = myToDrawAxes ? 1 : 0; - step = fabsf(LX1[3] - LX1[0]) / (float) myNbX; - while (i < myNbX) - { - glBegin(GL_LINE_STRIP); - glVertex3f(LX1[0] + i * step, LX1[1], LX1[2]); - glVertex3f(LX2[0] + i * step, LX2[1], LX2[2]); - glVertex3f(LX3[0] + i * step, LX3[1], LX3[2]); - glEnd(); - i++; - } - } - /* Y-Grid lines */ - if (myNbY > 0) - { - i = myToDrawAxes ? 1 : 0; - step = fabsf(LY1[4] - LY1[1]) / (float) myNbY; - while (i < myNbY) - { - glBegin(GL_LINE_STRIP); - glVertex3f(LY1[0], LY1[1] + i * step, LY1[2]); - glVertex3f(LY2[0], LY2[1] + i * step, LY2[2]); - glVertex3f(LY3[0], LY3[1] + i * step, LY3[2]); - glEnd(); - i++; - } - } - /* Z-Grid lines */ - if (myNbZ > 0) - { - i = myToDrawAxes ? 1 : 0; - step = fabsf(LZ1[5] - LZ1[2]) / (float) myNbZ; + theGridAxes.Ticks[0] = OpenGl_Vec3 (myMin.x(), myMin.y(), myMax.z()); + theGridAxes.Ticks[1] = OpenGl_Vec3 (myMax.x(), myMin.y(), myMin.z()); + theGridAxes.Ticks[2] = OpenGl_Vec3 (myMax.x(), myMin.y(), myMin.z()); - while (i < myNbZ) - { - glBegin(GL_LINE_STRIP); - glVertex3f(LZ1[0], LZ1[1], LZ1[2] + i * step); - glVertex3f(LZ2[0], LZ2[1], LZ2[2] + i * step); - glVertex3f(LZ3[0], LZ3[1], LZ3[2] + i * step); - glEnd(); - i++; - } + return OOZ_XOZ | OYO_XYO | + XOO_XYO | OOZ_OYZ | + XOO_XOZ | OYO_OYZ; + } + case 1: // (0,0,1) + { + theGridAxes.Origin = OpenGl_Vec3 (myMin.x(), myMin.y(), myMax.z()); + theGridAxes.Axes[0] = OpenGl_Vec3 (1.0f, 0.0f, 0.0f); + theGridAxes.Axes[1] = OpenGl_Vec3 (0.0f, 1.0f, 0.0f); + theGridAxes.Axes[2] = OpenGl_Vec3 (0.0f, 0.0f, -1.0f); + + theGridAxes.Ticks[0] = OpenGl_Vec3 (myMin.x(), myMin.y(), myMin.z()); + theGridAxes.Ticks[1] = OpenGl_Vec3 (myMin.x(), myMin.y(), myMin.z()); + theGridAxes.Ticks[2] = OpenGl_Vec3 (myMax.x(), myMin.y(), myMax.z()); + + return OOZ_XOZ | OYZ_XYZ | + OOZ_OYZ | XOZ_XYZ | + XOO_XOZ | OYO_OYZ; + } + case 2: // (0,1,0) + { + theGridAxes.Origin = OpenGl_Vec3 (myMin.x(), myMax.y(), myMin.z()); + theGridAxes.Axes[0] = OpenGl_Vec3 (1.0f, 0.0f, 0.0f); + theGridAxes.Axes[1] = OpenGl_Vec3 (0.0f, -1.0f, 0.0f); + theGridAxes.Axes[2] = OpenGl_Vec3 (0.0f, 0.0f, 1.0f); + + theGridAxes.Ticks[0] = OpenGl_Vec3 (myMin.x(), myMin.y(), myMin.z()); + theGridAxes.Ticks[1] = OpenGl_Vec3 (myMax.x(), myMax.y(), myMin.z()); + theGridAxes.Ticks[2] = OpenGl_Vec3 (myMax.x(), myMax.y(), myMin.z()); + + return OYO_XYO | OYZ_XYZ | + XOO_XYO | OOZ_OYZ | + XYO_XYZ | OYO_OYZ; + } + case 3: // (0,1,1) + { + theGridAxes.Origin = OpenGl_Vec3 (myMin.x(), myMax.y(), myMax.z()); + theGridAxes.Axes[0] = OpenGl_Vec3 (1.0f, 0.0f, 0.0f); + theGridAxes.Axes[1] = OpenGl_Vec3 (0.0f, -1.0f, 0.0f); + theGridAxes.Axes[2] = OpenGl_Vec3 (0.0f, 0.0f, -1.0f); + + theGridAxes.Ticks[0] = OpenGl_Vec3 (myMin.x(), myMin.y(), myMax.z()); + theGridAxes.Ticks[1] = OpenGl_Vec3 (myMin.x(), myMax.y(), myMin.z()); + theGridAxes.Ticks[2] = OpenGl_Vec3 (myMin.x(), myMin.y(), myMax.z()); + + return OOZ_XOZ | OYZ_XYZ | OYO_XYO | + OOZ_OYZ | XOZ_XYZ | + OYO_OYZ | XYO_XYZ; + } + case 4: // (1,0,0) + { + theGridAxes.Origin = OpenGl_Vec3 (myMax.x(), myMin.y(), myMin.z()); + theGridAxes.Axes[0] = OpenGl_Vec3 (-1, 0, 0); + theGridAxes.Axes[1] = OpenGl_Vec3 (0, 1, 0); + theGridAxes.Axes[2] = OpenGl_Vec3 (0, 0, 1); + + theGridAxes.Ticks[0] = OpenGl_Vec3 (myMax.x(), myMin.y(), myMax.z()); + theGridAxes.Ticks[1] = OpenGl_Vec3 (myMin.x(), myMin.y(), myMin.z()); + theGridAxes.Ticks[2] = OpenGl_Vec3 (myMin.x(), myMin.y(), myMin.z()); + + return OOZ_XOZ | OYO_XYO | + XOO_XYO | XOZ_XYZ | + XOO_XOZ | XYO_XYZ; + } + case 5: // (1,0,1) + { + theGridAxes.Origin = OpenGl_Vec3 (myMax.x(), myMin.y(), myMax.z()); + theGridAxes.Axes[0] = OpenGl_Vec3 (-1, 0, 0); + theGridAxes.Axes[1] = OpenGl_Vec3 (0, 1, 0); + theGridAxes.Axes[2] = OpenGl_Vec3 (0, 0, -1); + + theGridAxes.Ticks[0] = OpenGl_Vec3 (myMax.x(), myMin.y(), myMin.z()); + theGridAxes.Ticks[1] = OpenGl_Vec3 (myMax.x(), myMin.y(), myMin.z()); + theGridAxes.Ticks[2] = OpenGl_Vec3 (myMin.x(), myMin.y(), myMax.z()); + + return OOZ_XOZ | OYZ_XYZ | + XOO_XYO | XOZ_XYZ | OOZ_OYZ | + XOO_XOZ | XYO_XYZ; + } + case 6: // (1,1,0) + { + theGridAxes.Origin = OpenGl_Vec3 (myMax.x(), myMax.y(), myMin.z()); + theGridAxes.Axes[0] = OpenGl_Vec3 (-1, 0, 0); + theGridAxes.Axes[1] = OpenGl_Vec3 (0, -1, 0); + theGridAxes.Axes[2] = OpenGl_Vec3 (0, 0, 1); + + theGridAxes.Ticks[0] = OpenGl_Vec3 (myMax.x(), myMin.y(), myMin.z()); + theGridAxes.Ticks[1] = OpenGl_Vec3 (myMin.x(), myMax.y(), myMin.z()); + theGridAxes.Ticks[2] = OpenGl_Vec3 (myMax.x(), myMin.y(), myMin.z()); + + return OYO_XYO | OYZ_XYZ | + XOO_XYO | XOZ_XYZ | + XOO_XOZ | XYO_XYZ | OYO_OYZ; + } + case 7: // (1,1,1) + default: + { + theGridAxes.Origin = OpenGl_Vec3 (myMax.x(), myMax.y(), myMax.z()); + theGridAxes.Axes[0] = OpenGl_Vec3 (-1, 0, 0); + theGridAxes.Axes[1] = OpenGl_Vec3 (0, -1, 0); + theGridAxes.Axes[2] = OpenGl_Vec3 (0, 0, -1); + + theGridAxes.Ticks[0] = OpenGl_Vec3 (myMax.x(), myMax.y(), myMin.z()); + theGridAxes.Ticks[1] = OpenGl_Vec3 (myMax.x(), myMax.y(), myMin.z()); + theGridAxes.Ticks[2] = OpenGl_Vec3 (myMax.x(), myMin.y(), myMax.z()); + + return OYO_XYO | OYZ_XYZ | OOZ_XOZ | + XOO_XYO | XOZ_XYZ | OOZ_OYZ | + XOO_XOZ | XYO_XYZ | OYO_OYZ; + } + } +} + +// ======================================================================= +// function : renderLine +// purpose : +// ======================================================================= +void OpenGl_GraduatedTrihedron::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 +{ + const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); + OpenGl_Mat4 aMat (theMat); + OpenGl_Utils::Translate (aMat, theXt, theYt, theZt); + aContext->WorldViewState.SetCurrent (aMat); + aContext->ApplyWorldViewMatrix(); + theLine->Render (theWorkspace); +} + +// ======================================================================= +// function : renderGridPlane +// purpose : +// ======================================================================= +void OpenGl_GraduatedTrihedron::renderGridPlane (const Handle(OpenGl_Workspace)& theWorkspace, + const Standard_Integer& theIndex, + const GridAxes& theGridAxes, + OpenGl_Mat4& theMat) const +{ + const Graphic3d_AxisAspect& aCurAspect = myData.AxisAspect (theIndex); + if (aCurAspect.TickmarkNumber() <= 0) + { + return; + } + + const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); + + Standard_ShortReal aStep = theGridAxes.Axes[theIndex].GetData()[theIndex] + * (myMax.GetData()[theIndex] - myMin.GetData()[theIndex]) / aCurAspect.TickmarkNumber(); + + // NOTE: + // Get two other axes directions and draw lines Axis.TickmarkNumber times. + // Combining together from three axes, these lines will make a grid. + for (Standard_Integer anIter = 1; anIter <= 2; ++anIter) + { + OpenGl_Mat4 aMat (theMat); + const Standard_Integer anIndex = (theIndex + anIter) % 3; + const Axis& anAxis = myAxes[anIndex]; + OpenGl_Vec3 aStart (theGridAxes.Origin); + if (theGridAxes.Axes[anIndex].GetData()[anIndex] < 0.0) + { + aStart.ChangeData()[anIndex] = myMin.GetData()[anIndex]; + } + + OpenGl_Utils::Translate (aMat, aStart.x(), aStart.y(), aStart.z()); + aContext->WorldViewState.SetCurrent (aMat); + aContext->ApplyWorldViewMatrix(); + + const OpenGl_Vec3 aStepVec (myAxes[theIndex].Direction * aStep); + for (Standard_Integer anIt = myData.ToDrawAxes() ? 1 : 0; anIt < aCurAspect.TickmarkNumber(); ++anIt) + { + OpenGl_Utils::Translate (aMat, aStepVec.x(), aStepVec.y(), aStepVec.z()); + aContext->WorldViewState.SetCurrent (aMat); + aContext->ApplyWorldViewMatrix(); + anAxis.Line->Render (theWorkspace); + } + } +} + +// ======================================================================= +// function : renderAxis +// purpose : +// ======================================================================= +void OpenGl_GraduatedTrihedron::renderAxis (const Handle(OpenGl_Workspace)& theWorkspace, + const Standard_Integer& theIndex, + const OpenGl_Mat4& theMat) const +{ + const Axis& anAxis = myAxes[theIndex]; + + theWorkspace->SetAspectLine (&anAxis.LineAspect); + const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); + + // Reset transformations + aContext->WorldViewState.SetCurrent (theMat); + aContext->ApplyWorldViewMatrix(); + + // Render arrow + + TEL_TRANSFORM_PERSISTENCE aTransMode; + aTransMode.mode = Graphic3d_TMF_ZoomPers; + OpenGl_Vec3 anArrowVec = myMin + anAxis.Direction * (myMax - myMin); + aTransMode.pointX = anArrowVec.x(); + aTransMode.pointY = anArrowVec.y(); + aTransMode.pointZ = anArrowVec.z(); + + theWorkspace->ActiveView()->BeginTransformPersistence (aContext, &aTransMode); + + // NOTE: + // OpenGl_View applies Transform Persistence only in Projection Matrix. + // Take into account Transform Persistence + aContext->ApplyModelViewMatrix(); + + // Get current Model-View and Projection states + OpenGl_Mat4 aModelMat; + OpenGl_Mat4 aProjMat; + GLint aViewport[4]; + aContext->core11fwd->glGetIntegerv (GL_VIEWPORT, aViewport); + aModelMat.Convert (aContext->ModelWorldState.Current() * aContext->WorldViewState.Current()); + aProjMat .Convert (aContext->ProjectionState.Current()); + + // Get the window's (fixed) coordinates for before matrixes modifications + OpenGl_Vec3 aEndPoint = -anAxis.Direction * myData.ArrowLength(); + 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); + theWorkspace->ActiveView()->EndTransformPersistence (aContext); + + // Get current Model-View and Projection states after the end of Transform Persistence + aModelMat.Convert (aContext->ModelWorldState.Current() * aContext->WorldViewState.Current()); + aProjMat .Convert (aContext->ProjectionState.Current()); + + // Get start point of zoom persistent arrow + OpenGl_Vec3 anArrowStart; + OpenGl_Utils::UnProject (aWinPoint.x(), aWinPoint.y(), aWinPoint.z(), + aModelMat, aProjMat, aViewport, + anArrowStart.x(), anArrowStart.y(), anArrowStart.z()); + // Render axis line + + aModelMat = theMat; + OpenGl_Utils::Translate (aModelMat, myMin.x(), myMin.y(), myMin.z()); + + Standard_ShortReal aScaleFactor = ( (anArrowStart - myMin)*anAxis.Direction ).Modulus() + / (anAxis.Direction * (myMax - myMin) ).Modulus(); + OpenGl_Vec3 aScaleAxes = anAxis.Direction * aScaleFactor; + OpenGl_Utils::Scale (aModelMat, aScaleAxes.x(), aScaleAxes.y(), aScaleAxes.z()); + + aContext->WorldViewState.SetCurrent (aModelMat); + aContext->ApplyWorldViewMatrix(); + anAxis.Line->Render (theWorkspace); +} + +// ======================================================================= +// function : renderTickmarkTextLabels +// purpose : +// ======================================================================= +void OpenGl_GraduatedTrihedron::renderTickmarkLabels (const Handle(OpenGl_Workspace)& theWorkspace, + const OpenGl_Mat4& theMat, + const Standard_Integer theIndex, + const GridAxes& theGridAxes, + const Standard_ShortReal theDpix) const +{ + const Graphic3d_AxisAspect& aCurAspect = myData.AxisAspect (theIndex); + if (!aCurAspect.ToDrawName() && !aCurAspect.ToDrawValues()) + { + return; + } + + Standard_Character aTextValue[128]; + 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(); + + OpenGl_Vec3 aDir = (theGridAxes.Ticks[theIndex] - theGridAxes.Origin).Normalized(); + const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); + + if (aCurAspect.ToDrawTickmarks() && aCurAspect.TickmarkNumber() > 0) + { + theWorkspace->SetAspectLine (&myGridLineAspect); + + OpenGl_Mat4 aModelMat (theMat); + + anAxis.InitTickmark (aContext, aDir * (Standard_ShortReal) aCurAspect.TickmarkLength() * 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) + { + anAxis.Tickmark->Render (theWorkspace); + OpenGl_Utils::Translate (aModelMat, aStepVec.x(), aStepVec.y(), aStepVec.z()); + aContext->WorldViewState.SetCurrent (aModelMat); + aContext->ApplyWorldViewMatrix(); + } + } + + // Restore matrix + aContext->WorldViewState.SetCurrent (theMat); + aContext->ApplyWorldViewMatrix(); + + if (aCurAspect.ToDrawName()) + { + Standard_Real anOffset = aCurAspect.NameOffset() + aCurAspect.TickmarkLength(); + + OpenGl_Vec3 aMiddle (theGridAxes.Ticks[theIndex] + aSizeVec * theGridAxes.Axes[theIndex] * 0.5f + aDir * (Standard_ShortReal)(theDpix * anOffset)); + + myAspectLabels.ChangeColor() = anAxis.NameColor; + theWorkspace->SetAspectText (&myAspectLabels); + anAxis.Label.SetPosition (aMiddle); + anAxis.Label.Render (theWorkspace); + } + + if (aCurAspect.ToDrawValues() && aCurAspect.TickmarkNumber() > 0) + { + myAspectValues.ChangeColor() = anAxis.LineAspect.Color(); + theWorkspace->SetAspectText (&myAspectValues); + Standard_Real anOffset = aCurAspect.ValuesOffset() + aCurAspect.TickmarkLength(); + + for (Standard_Integer anIt = 0; anIt <= aCurAspect.TickmarkNumber(); ++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)); + myLabelValues.Init (theWorkspace->GetGlContext(), aTextValue, aPos); + myLabelValues.Render (theWorkspace); + } + } +} + +// ======================================================================= +// function : Render +// purpose : call_graduatedtrihedron_redraw +// ======================================================================= +void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace)& theWorkspace) const +{ + const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); + + // Update boundary box + OpenGl_Vec3 anOldMin = myMin; + OpenGl_Vec3 anOldMax = myMax; + + 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()) + { + 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())); + } + } + + // Find the farest point of bounding box + + // Get normal of the view out of user and distance corresponding to 1 pixel + OpenGl_Vec3 aNormal; + Standard_ShortReal aDpix = getNormal (aContext, aNormal); + aNormal.Normalize(); + + // Get central point of bounding box + OpenGl_Vec3 aCenter; + aCenter = (myMin + myMax) * 0.5f; + + // Check distance to corners of bounding box along the normal + Standard_ShortReal aCorners[8]; + aCorners[0] = getDistanceToCorner (aNormal, aCenter, myMin.x(), myMin.y(), myMin.z()); + aCorners[1] = getDistanceToCorner (aNormal, aCenter, myMin.x(), myMin.y(), myMax.z()); + aCorners[2] = getDistanceToCorner (aNormal, aCenter, myMin.x(), myMax.y(), myMin.z()); + aCorners[3] = getDistanceToCorner (aNormal, aCenter, myMin.x(), myMax.y(), myMax.z()); + aCorners[4] = getDistanceToCorner (aNormal, aCenter, myMax.x(), myMin.y(), myMin.z()); + aCorners[5] = getDistanceToCorner (aNormal, aCenter, myMax.x(), myMin.y(), myMax.z()); + aCorners[6] = getDistanceToCorner (aNormal, aCenter, myMax.x(), myMax.y(), myMin.z()); + aCorners[7] = getDistanceToCorner (aNormal, aCenter, myMax.x(), myMax.y(), myMax.z()); + + // NOTE: + // (0, 0, 1), (0, 1, 0) and (0, 0, 1) directions from (myMin.x(), Ymin, Zmin) point + // are reserved for trihedron axes. + // So for the grid here are 9 edges of cube, + // and, depending on the farest point, 2 or 3 of them may not be drawn + // if they overlap displayed model. + + // Write an axes state what axes of bounding box are to be drawn + GridAxes aGridAxes; + Standard_ExtCharacter anAxesState = getGridAxes (aCorners, aGridAxes); + + // Remember current aspects + const OpenGl_AspectLine* anOldAspectLine = theWorkspace->AspectLine (Standard_False); + const OpenGl_AspectText* anOldAspectText = theWorkspace->AspectText (Standard_False); + + OpenGl_Mat4 aModelMatrix; + aModelMatrix.Convert (aContext->WorldViewState.Current()); + + // Remember model-view matrix + aContext->WorldViewState.Push(); + aContext->WorldViewState.SetCurrent (aModelMatrix); + aContext->ApplyWorldViewMatrix(); + + if (myData.ToDrawGrid()) + { + theWorkspace->SetAspectLine (&myGridLineAspect); + + // render grid edges + if (anAxesState & XOO_XYO) + { + renderLine (myAxes[1].Line, theWorkspace, aModelMatrix, myMax.x(), myMin.y(), myMin.z()); + } + + if (anAxesState & XOO_XOZ) + { + renderLine (myAxes[2].Line,theWorkspace, aModelMatrix, myMax.x(), myMin.y(), myMin.z()); + } + + if (anAxesState & OYO_OYZ) + { + renderLine (myAxes[2].Line, theWorkspace, aModelMatrix, myMin.x(), myMax.y(), myMin.z()); + } + + if (anAxesState & OYO_XYO) + { + renderLine (myAxes[0].Line, theWorkspace, aModelMatrix, myMin.x(), myMax.y(), myMin.z()); + } + + if (anAxesState & OOZ_XOZ) + { + renderLine (myAxes[0].Line, theWorkspace, aModelMatrix, myMin.z(), myMin.y(), myMax.z()); + } + + if (anAxesState & OOZ_OYZ) + { + renderLine (myAxes[1].Line, theWorkspace, aModelMatrix, myMin.x(), myMin.y(), myMax.z()); + } + + if (anAxesState & OYZ_XYZ) + { + renderLine (myAxes[0].Line, theWorkspace, aModelMatrix, myMin.x(), myMax.y(), myMax.z()); + } + + if (anAxesState & XOZ_XYZ) + { + renderLine (myAxes[1].Line, theWorkspace, aModelMatrix, myMax.x(), myMin.y(), myMax.z()); + } + + if (anAxesState & XYO_XYZ) + { + renderLine (myAxes[2].Line, theWorkspace, aModelMatrix, myMax.x(), myMax.y(), myMin.z()); + } + + for (Standard_Integer anIter = 0 ; anIter < 3; ++anIter) + { + renderGridPlane (theWorkspace, anIter, aGridAxes, aModelMatrix); } } // Axes (arrows) - if (myToDrawAxes) + if (myData.ToDrawAxes()) { - // X-axis - glColor3fv(myXColor.rgb); - drawArrow(xmin, ymin, zmin, xmax, ymin, zmin, normal[0], normal[1], normal[2]); - - // Y-axis - glColor3fv(myYColor.rgb); - drawArrow(xmin, ymin, zmin, xmin, ymax, zmin, normal[0], normal[1], normal[2]); - - // Z-axis - glColor3fv(myZColor.rgb); - drawArrow(xmin, ymin, zmin, xmin, ymin, zmax, normal[0], normal[1], normal[2]); + for (Standard_Integer anIter = 0; anIter < 3; ++anIter) + { + renderAxis (theWorkspace, anIter, aModelMatrix); + } } // Names of axes & values - char textValue[128]; - - if (myToDrawXName || myToDrawXValues) + for (Standard_Integer anIter = 0; anIter < 3; ++anIter) { - // Middle point of the first X-axis - m1[0] = 0.5f * (LX1[0] + LX1[3]); - m1[1] = 0.5f * (LX1[1] + LX1[4]); - m1[2] = 0.5f * (LX1[2] + LX1[5]); - - // Middle point of the second X-axis - m2[0] = 0.5f * (LX2[0] + LX2[3]); - m2[1] = 0.5f * (LX2[1] + LX2[4]); - m2[2] = 0.5f * (LX2[2] + LX2[5]); - - // Apply offset to m1 - dy = m1[1] - m2[1]; - if (fabsf(dy) > 1.e-7f) - { - dy = (dy > 0.0f)? 1.0f : -1.0f; - } - dz = m1[2] - m2[2]; - if (fabsf(dz) > 1.e-7f) - { - dz = (dz > 0.0f)? 1.0f : -1.0f; - } - m2[1] = dpix * dy; - m2[2] = dpix * dz; - - // Name of X-axis - if (myToDrawXName) - { - offset = myXAxisOffset + myXTickmarkLength; - - // draw axes labels - myAspectLabels.ChangeColor() = myXNameColor; - const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectLabels); - myLabelX.SetPosition (OpenGl_Vec3(m1[0], m1[1] + offset * m2[1], m1[2] + offset * m2[2])); - myLabelX.Render (theWorkspace); - theWorkspace->SetAspectText (aPrevAspectText); - } - - // X-values - if (myToDrawXValues && myNbX > 0) - { - myAspectValues.ChangeColor() = myXColor; - const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectValues); - - step = fabsf(LX1[3] - LX1[0]) / (float) myNbX; - offset = myXOffset + myXTickmarkLength; - for (unsigned int anIter = 0; anIter <= myNbX; ++anIter) - { - sprintf (textValue, "%g", LX1[0] + anIter * step); - myLabelValues.Init (theWorkspace->GetGlContext(), textValue, - OpenGl_Vec3(LX1[0] + anIter * step, m1[1] + offset * m2[1], m1[2] + offset * m2[2])); - myLabelValues.Render (theWorkspace); - } - theWorkspace->SetAspectText (aPrevAspectText); - } - - // X-tickmark - if (myDrawXTickmarks && myNbX > 0) - { - glColor3fv(myGridColor); - - step = fabsf(LX1[3] - LX1[0]) / (float) myNbX; - for (unsigned int anIter = 0; anIter <= myNbX; ++anIter) - { - glBegin(GL_LINES); - glVertex3f(LX1[0] + anIter * step, m1[1], m1[2]); - glVertex3f(LX1[0] + anIter * step, m1[1] + myXTickmarkLength * m2[1], m1[2] + myXTickmarkLength * m2[2]); - glEnd(); - } - } + // Restore current matrix + aContext->WorldViewState.SetCurrent (aModelMatrix); + aContext->ApplyWorldViewMatrix(); + renderTickmarkLabels (theWorkspace, aModelMatrix, anIter, aGridAxes, aDpix); } - if (myToDrawYName || myToDrawYValues) - { - // Middle point of the first Y-axis - m1[0] = 0.5f * (LY1[0] + LY1[3]); - m1[1] = 0.5f * (LY1[1] + LY1[4]); - m1[2] = 0.5f * (LY1[2] + LY1[5]); + theWorkspace->SetAspectLine (anOldAspectLine); + theWorkspace->SetAspectText (anOldAspectText); - // Middle point of the second Y-axis - m2[0] = 0.5f * (LY2[0] + LY2[3]); - m2[1] = 0.5f * (LY2[1] + LY2[4]); - m2[2] = 0.5f * (LY2[2] + LY2[5]); - - // Apply offset to m1 - dx = m1[0] - m2[0]; - if (fabsf(dx) > 1.e-7f) - { - dx = (dx > 0.0f)? 1.0f : -1.0f; - } - dz = m1[2] - m2[2]; - if (fabsf(dz) > 1.e-7f) - { - dz = (dz > 0.0f)? 1.0f : -1.0f; - } - - m2[0] = dpix * dx; - m2[2] = dpix * dz; - - // Name of Y-axis - if (myToDrawYName) - { - offset = myYAxisOffset + myYTickmarkLength; - - myAspectLabels.ChangeColor() = myYNameColor; - const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectLabels); - myLabelY.SetPosition (OpenGl_Vec3(m1[0] + offset * m2[0], m1[1], m1[2] + offset * m2[2])); - myLabelY.Render (theWorkspace); - theWorkspace->SetAspectText (aPrevAspectText); - } - - // Y-values - if (myToDrawYValues && myNbY > 0) - { - myAspectValues.ChangeColor() = myYColor; - const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectValues); - - step = fabsf(LY1[4] - LY1[1]) / (float) myNbY; - offset = myYOffset + myYTickmarkLength; - for (unsigned int anIter = 0; anIter <= myNbY; ++anIter) - { - sprintf (textValue, "%g", LY1[1] + anIter * step); - myLabelValues.Init (theWorkspace->GetGlContext(), textValue, - OpenGl_Vec3(m1[0] + offset * m2[0], LY1[1] + anIter * step, m1[2] + offset * m2[2])); - myLabelValues.Render (theWorkspace); - } - theWorkspace->SetAspectText (aPrevAspectText); - } - - // Y-tickmark - if (myDrawYTickmarks && myNbY > 0) - { - glColor3fv(myGridColor); - - i = 0; - step = fabsf(LY1[4] - LY1[1]) / (float) myNbY; - while (i <= myNbY) - { - glBegin(GL_LINES); - glVertex3f(m1[0], LY1[1] + i * step, m1[2]); - glVertex3f(m1[0] + myYTickmarkLength * m2[0], LY1[1] + i * step, m1[2] + myYTickmarkLength * m2[2]); - glEnd(); - i++; - } - } - } - - if (myToDrawZName || myToDrawZValues) - { - // Middle point of the first Z-axis - m1[0] = 0.5f * (LZ1[0] + LZ1[3]); - m1[1] = 0.5f * (LZ1[1] + LZ1[4]); - m1[2] = 0.5f * (LZ1[2] + LZ1[5]); - - // Middle point of the second Z-axis - m2[0] = 0.5f * (LZ2[0] + LZ2[3]); - m2[1] = 0.5f * (LZ2[1] + LZ2[4]); - m2[2] = 0.5f * (LZ2[2] + LZ2[5]); - - // Apply offset to m1 - dx = m1[0] - m2[0]; - if (fabsf(dx) > 1.e-7f) - { - dx = (dx > 0.0f)? 1.0f : -1.0f; - } - dy = m1[1] - m2[1]; - if (fabsf(dy) > 1.e-7f) - { - dy = (dy > 0.0f)? 1.0f : -1.0f; - } - - m2[0] = dpix * dx; - m2[1] = dpix * dy; - - // Name of Z-axis - if (myToDrawZName) - { - offset = myZAxisOffset + myZTickmarkLength; - - myAspectLabels.ChangeColor() = myZNameColor; - const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectLabels); - myLabelZ.SetPosition (OpenGl_Vec3(m1[0] + offset * m2[0], m1[1] + offset * m2[1], m1[2])); - myLabelZ.Render (theWorkspace); - theWorkspace->SetAspectText (aPrevAspectText); - } - - // Z-values - if (myToDrawZValues && myNbZ > 0) - { - myAspectValues.ChangeColor() = myZColor; - const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectValues); - - step = fabsf(LZ1[5] - LZ1[2]) / (float) myNbZ; - offset = myZOffset + myZTickmarkLength; - for (unsigned int anIter = 0; anIter <= myNbZ; ++anIter) - { - sprintf (textValue, "%g", LZ1[2] + anIter * step); - myLabelValues.Init (theWorkspace->GetGlContext(), textValue, - OpenGl_Vec3(m1[0] + offset * m2[0], m1[1] + offset * m2[1], LZ1[2] + anIter * step)); - myLabelValues.Render (theWorkspace); - } - theWorkspace->SetAspectText (aPrevAspectText); - } - - // Z-tickmark - if (myDrawZTickmarks && myNbZ > 0) - { - glColor3fv(myGridColor); - - i = 0; - step = fabsf(LZ1[5] - LZ1[2]) / (float) myNbZ; - while (i <= myNbZ) - { - glBegin(GL_LINES); - glVertex3f(m1[0], m1[1], LZ1[2] + i * step); - glVertex3f(m1[0] + myZTickmarkLength * m2[0], m1[1] + myZTickmarkLength * m2[1], LZ1[2] + i * step); - glEnd(); - i++; - } - } - } - - // Activate the lighting if it was turned off by this method call - if (light) - glEnable(GL_LIGHTING); - - theWorkspace->SetAspectLine(oldAspectLine); -#endif + aContext->WorldViewState.Pop(); + aContext->ApplyWorldViewMatrix(); } -//call_graduatedtrihedron_minmaxvalues -void OpenGl_GraduatedTrihedron::SetMinMax (const Standard_ShortReal xMin, const Standard_ShortReal yMin, const Standard_ShortReal zMin, - const Standard_ShortReal xMax, const Standard_ShortReal yMax, const Standard_ShortReal zMax) +// ======================================================================= +// method : SetMinMax +// purpose : +// ======================================================================= +void OpenGl_GraduatedTrihedron::SetMinMax (const OpenGl_Vec3& theMin, const OpenGl_Vec3& theMax) { - xmin = xMin; - ymin = yMin; - zmin = zMin; - xmax = xMax; - ymax = yMax; - zmax = zMax; + myMin = theMin; + myMax = theMax; +} + +// ======================================================================= +// method : OpenGl_GraduatedTrihedron::Axis constructor +// purpose : +// ======================================================================= +OpenGl_GraduatedTrihedron::Axis::Axis (const Graphic3d_AxisAspect& theAspect, + const OpenGl_Vec3& theDirection) +: Direction (theDirection), + Label (NCollection_String ((Standard_Utf16Char* )theAspect.Name().ToExtString()).ToCString(), + Direction, THE_LABEL_PARAMS) +{ + 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); +} + +// ======================================================================= +// 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 : +// ======================================================================= +void OpenGl_GraduatedTrihedron::Axis::InitArrow (const Handle(OpenGl_Context)& theContext, + const Standard_ShortReal theLength, + const OpenGl_Vec3& theNormal) const +{ + // Draw from the end point of the aris + OpenGl_Vec3 aLengthVec = -Direction * theLength; + + // Radial direction to the arrow + OpenGl_Vec3 aRadial = OpenGl_Vec3::Cross (this->Direction, theNormal); + if (aRadial.Modulus() < (Standard_ShortReal) Precision::Confusion()) + { + return; + } + aRadial = aRadial.Normalized() * theLength * 0.2f; + + // Initialize arrow primitive array + // Make loop from polyline + const OpenGl_Vec3 aPoint1 = aRadial + aLengthVec; + const OpenGl_Vec3 aPoint2 (0.0f, 0.0f, 0.0f); + const OpenGl_Vec3 aPoint3 = -aRadial + aLengthVec; + + Handle(Graphic3d_ArrayOfPolylines) anArray = new Graphic3d_ArrayOfPolylines (4); + anArray->AddVertex (aPoint1); + anArray->AddVertex (aPoint2); + anArray->AddVertex (aPoint3); + anArray->AddVertex (aPoint1); + + Arrow->InitBuffers (theContext, Graphic3d_TOPA_POLYLINES, + anArray->Indices(), anArray->Attributes(), anArray->Bounds()); +} + +// ======================================================================= +// function : InitTickmark +// purpose : +// ======================================================================= +void OpenGl_GraduatedTrihedron::Axis::InitTickmark (const Handle(OpenGl_Context)& theContext, + const OpenGl_Vec3& theDir) const +{ + + 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()); + +} + +// ======================================================================= +// function : InitLine +// purpose : +// ======================================================================= +void OpenGl_GraduatedTrihedron::Axis::InitLine (const Handle(OpenGl_Context)& theContext, + const OpenGl_Vec3& theDir) const +{ + + Handle(Graphic3d_ArrayOfSegments) anArray = new Graphic3d_ArrayOfSegments (2); + anArray->AddVertex (0.0f, 0.0f, 0.0f); + anArray->AddVertex (theDir); + + Line->InitBuffers (theContext, Graphic3d_TOPA_SEGMENTS, + anArray->Indices(), anArray->Attributes(), anArray->Bounds()); +} + +// ======================================================================= +// function : Release +// purpose : +// ======================================================================= +void OpenGl_GraduatedTrihedron::Axis::Release (OpenGl_Context* 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 e08b20268e..1fd5936aea 100755 --- a/src/OpenGl/OpenGl_GraduatedTrihedron.hxx +++ b/src/OpenGl/OpenGl_GraduatedTrihedron.hxx @@ -16,70 +16,230 @@ #ifndef _OpenGl_GraduatedTrihedron_Header #define _OpenGl_GraduatedTrihedron_Header +#include +#include +#include +#include +#include +#include #include - +#include #include -#include 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. +//! @sa Graphic3d_GraduatedTrihedron class OpenGl_GraduatedTrihedron : public OpenGl_Element { +public: + + DEFINE_STANDARD_ALLOC public: - static void SetMinMax (const Standard_ShortReal xMin, const Standard_ShortReal yMin, const Standard_ShortReal zMin, - const Standard_ShortReal xMax, const Standard_ShortReal yMax, const Standard_ShortReal zMax); - -public: - - OpenGl_GraduatedTrihedron (const Graphic3d_CGraduatedTrihedron& theData); + OpenGl_GraduatedTrihedron (const Graphic3d_GraduatedTrihedron& theData); virtual void Render (const Handle(OpenGl_Workspace)& theWorkspace) const; + virtual void Release (OpenGl_Context* theCtx); + //! 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(); +private: + + //! Axis of trihedron. It incapsulates geometry and style. + class Axis + { + public: + + OpenGl_Vec3 Direction; + TEL_COLOUR NameColor; + OpenGl_AspectLine LineAspect; + mutable OpenGl_Text Label; + 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() + { + OpenGl_Element::Destroy (NULL, Line); + OpenGl_Element::Destroy (NULL, Tickmark); + OpenGl_Element::Destroy (NULL, Arrow); + } + + void InitArrow (const Handle(OpenGl_Context)& theContext, + const Standard_ShortReal theLength, + const OpenGl_Vec3& theNormal) const; + + void InitTickmark (const Handle(OpenGl_Context)& theContext, + const OpenGl_Vec3& theDir) const; + + void InitLine (const Handle(OpenGl_Context)& theContext, + const OpenGl_Vec3& theDir) const; + + void Release (OpenGl_Context* theCtx); + }; + +private: + + //! Struct for triple of orthonormal vectors + //! and origin point, and axes for tickmarks. + //! It may be not a right or left coordinate system. + struct GridAxes + { + public: + GridAxes() + : Origin (0, 0, 0) + { + Axes[0] = OpenGl_Vec3 (1.0f, 0.0f, 0.0f); + Axes[1] = OpenGl_Vec3 (0.0f, 1.0f, 0.0f); + Axes[2] = OpenGl_Vec3 (0.0f, 0.0f, 1.0f); + + Ticks[0] = OpenGl_Vec3 (0.0f, 0.0f, 0.0f); + Ticks[1] = OpenGl_Vec3 (0.0f, 0.0f, 0.0f); + Ticks[2] = OpenGl_Vec3 (0.0f, 0.0f, 0.0f); + } + + public: //! @name Main grid directions + OpenGl_Vec3 Origin; + OpenGl_Vec3 Axes[3]; + + public: //! @name Directions for tickmarks + OpenGl_Vec3 Ticks[3]; + }; + +private: + + //! Gets normal of the view out of user. + //! @param theContext [in] OpenGL Context + //! @param theNormal [out] normal of the view out of user + //! @return distance corresponding to 1 pixel + Standard_ShortReal getNormal (const Handle(OpenGl_Context)& theContext, + OpenGl_Vec3& theNormal) const; + + //! Gets distance to point (theX, theY, theZ) of bounding box along the normal + //! @param theNormal [in] normal of the view out of user + //! @param theCenter [in] geometry center of bounding box + //! @param theX [in] x of target point + //! @param theY [in] y of target point + //! @param theZ [in] z of terget point + Standard_ShortReal getDistanceToCorner (const OpenGl_Vec3& theNormal, + const OpenGl_Vec3& theCenter, + const Standard_ShortReal theX, + const Standard_ShortReal theY, + const Standard_ShortReal theZ) const; + + //! Gets axes of grid + //! @param theCorners [in] the corners of grid + //! @param theGridAxes [out] grid axes, the base of graduated trihedron grid. + Standard_ExtCharacter getGridAxes (const Standard_ShortReal theCorners[8], + GridAxes& theGridAxes) const; + + //! Render line from the transformed primitive array myLine + //! @param theWorkspace [in] the OpenGl Workspace + //! @param theMat [in] theMat that containes base transformation and is used for appling + //! translation and rotation + //! @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; + + //! Render grid lines perpendecular the axis of input index + //! @param theWorkspace [in] the OpenGl Workspace + //! @param theIndex [in] index of axis + //! @param theGridAxes [in] grid axes + //! @param theMat [in] theMat that containes base transformation and is used for appling + //! translation and rotation + void renderGridPlane (const Handle(OpenGl_Workspace)& theWorkspace, + const Standard_Integer& theIndex, + const GridAxes& theGridAxes, + OpenGl_Mat4& theMat) const; + + + //! Render the axis of input index + //! @param theWorkspace [in] the OpenGl Workspace + //! @param theIndex [in] index of axis + //! @param theMat [in] theMat that containes base transformation and is used for appling + //! translation and rotation + void renderAxis (const Handle(OpenGl_Workspace)& theWorkspace, + const Standard_Integer& theIndex, + const OpenGl_Mat4& theMat) const; + + //! Render grid labels, tickmark lines and labels + //! @param theWorkspace [in] the OpenGl Workspace + //! @param theMat [in] theMat that containes base transformation and is used for appling + //! translation and rotation + //! @param theIndex [in] index of axis + //! @param theGridAxes [in] grid axes + //! @param theDpix [in] distance corresponding to 1 pixel + void renderTickmarkLabels (const Handle(OpenGl_Workspace)& theWorkspace, + const OpenGl_Mat4& theMat, + const Standard_Integer theIndex, + const GridAxes& theGridAxes, + const Standard_ShortReal theDpix) const; + + +protected: //! @name Scene bounding box values + + OpenGl_Vec3 myMin; + OpenGl_Vec3 myMax; + protected: - mutable OpenGl_Text myLabelX; - mutable OpenGl_Text myLabelY; - mutable OpenGl_Text myLabelZ; + Axis myAxes[3]; //!< Axes for trihedron + + Graphic3d_GraduatedTrihedron myData; + + OpenGl_AspectLine myGridLineAspect; //!< Color grid properties + +protected: //! @name Labels properties + mutable OpenGl_Text myLabelValues; mutable OpenGl_AspectText myAspectLabels; mutable OpenGl_AspectText myAspectValues; - TEL_COLOUR myXNameColor; - TEL_COLOUR myYNameColor; - TEL_COLOUR myZNameColor; - bool myToDrawXName; - bool myToDrawYName; - bool myToDrawZName; - bool myToDrawXValues; - bool myToDrawYValues; - bool myToDrawZValues; - bool myToDrawGrid; - bool myToDrawAxes; - unsigned int myNbX, myNbY, myNbZ; - int myXOffset, myYOffset, myZOffset; - int myXAxisOffset, myYAxisOffset, myZAxisOffset; - Standard_Boolean myDrawXTickmarks; - Standard_Boolean myDrawYTickmarks; - Standard_Boolean myDrawZTickmarks; - unsigned int myXTickmarkLength, myYTickmarkLength, myZTickmarkLength; - float myGridColor[3]; - TEL_COLOUR myXColor; - TEL_COLOUR myYColor; - TEL_COLOUR myZColor; - Graphic3d_CGraduatedTrihedron::minMaxValuesCallback myCbCubicAxes; - Visual3d_View* myPtrVisual3dView; +private: -public: - - DEFINE_STANDARD_ALLOC + enum AxisFlags + { + XOO_XYO = 1 << 1, + XOO_XOZ = 1 << 2, + OYO_OYZ = 1 << 3, + OYO_XYO = 1 << 4, + OOZ_XOZ = 1 << 5, + OOZ_OYZ = 1 << 6, + OYZ_XYZ = 1 << 7, + XOZ_XYZ = 1 << 8, + XYO_XYZ = 1 << 9 + }; }; diff --git a/src/OpenGl/OpenGl_GraphicDriver.cxx b/src/OpenGl/OpenGl_GraphicDriver.cxx index 6f679451c4..8c9385d9e4 100644 --- a/src/OpenGl/OpenGl_GraphicDriver.cxx +++ b/src/OpenGl/OpenGl_GraphicDriver.cxx @@ -606,7 +606,7 @@ void OpenGl_GraphicDriver::SetBgGradientStyle (const Graphic3d_CView& t // purpose : // ======================================================================= void OpenGl_GraphicDriver::GraduatedTrihedronDisplay (const Graphic3d_CView& theCView, - const Graphic3d_CGraduatedTrihedron& theCubic) + const Graphic3d_GraduatedTrihedron& theCubic) { const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; if (aCView != NULL) @@ -632,12 +632,13 @@ void OpenGl_GraphicDriver::GraduatedTrihedronErase (const Graphic3d_CView& theCV // function : GraduatedTrihedronMinMaxValues // purpose : // ======================================================================= -void OpenGl_GraphicDriver::GraduatedTrihedronMinMaxValues (const Standard_ShortReal theMinX, - const Standard_ShortReal theMinY, - const Standard_ShortReal theMinZ, - const Standard_ShortReal theMaxX, - const Standard_ShortReal theMaxY, - const Standard_ShortReal theMaxZ) +void OpenGl_GraphicDriver::GraduatedTrihedronMinMaxValues (const Graphic3d_CView& theView, + const Graphic3d_Vec3 theMin, + const Graphic3d_Vec3 theMax) { - OpenGl_GraduatedTrihedron::SetMinMax (theMinX, theMinY, theMinZ, theMaxX, theMaxY, theMaxZ); + const OpenGl_CView* aCView = (const OpenGl_CView* )theView.ptrView; + if (aCView != NULL) + { + aCView->View->GraduatedTrihedron()->SetMinMax (theMin, theMax); + } } diff --git a/src/OpenGl/OpenGl_GraphicDriver.hxx b/src/OpenGl/OpenGl_GraphicDriver.hxx index cb5d482ca9..9f57853602 100644 --- a/src/OpenGl/OpenGl_GraphicDriver.hxx +++ b/src/OpenGl/OpenGl_GraphicDriver.hxx @@ -46,7 +46,7 @@ #include #include #include -#include +#include #include #include #include @@ -171,9 +171,28 @@ public: 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); - Standard_EXPORT void GraduatedTrihedronDisplay (const Graphic3d_CView& view, const Graphic3d_CGraduatedTrihedron& cubic); - Standard_EXPORT void GraduatedTrihedronErase (const Graphic3d_CView& view); - Standard_EXPORT void GraduatedTrihedronMinMaxValues (const Standard_ShortReal xmin, const Standard_ShortReal ymin, const Standard_ShortReal zmin, const Standard_ShortReal xmax, const Standard_ShortReal ymax, const Standard_ShortReal zmax); + + //! Displays Graduated trihedron + //! @param theView [in] the graphic view + //! @param theCubic [in] Graduated Trihedon parameters. + //! @sa OpenGl_GraduatedTrihedron + //! @sa Graphic3d_GraduatedTrihedron + Standard_EXPORT void GraduatedTrihedronDisplay (const Graphic3d_CView& theView, const Graphic3d_GraduatedTrihedron& theCubic); + + //! Erases Graduated Trihedron from the view. + //! theView [in] graphic view + //! @sa OpenGl_GraduatedTrihedron + Standard_EXPORT void GraduatedTrihedronErase (const Graphic3d_CView& theView); + + //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron + //! stored in graphic view object. + //! @param theView [in] current graphic view + //! @param theMin [in] the minimum point of scene. + //! @param theMax [in] the maximum point of scene. + //! @sa OpenGl_GraduatedTrihedron + Standard_EXPORT void GraduatedTrihedronMinMaxValues (const Graphic3d_CView& theView, + const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax); + Standard_EXPORT void Layer (Aspect_CLayer2d& ACLayer); Standard_EXPORT void RemoveLayer (const Aspect_CLayer2d& ACLayer); Standard_EXPORT void BeginLayer (const Aspect_CLayer2d& ACLayer); diff --git a/src/OpenGl/OpenGl_PrimitiveArray.cxx b/src/OpenGl/OpenGl_PrimitiveArray.cxx index 52da8723e3..8269297008 100755 --- a/src/OpenGl/OpenGl_PrimitiveArray.cxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.cxx @@ -624,49 +624,8 @@ OpenGl_PrimitiveArray::OpenGl_PrimitiveArray (const OpenGl_GraphicDriver* // dummy index buffer? myIndices.Nullify(); } - if (myAttribs.IsNull()) - { - return; - } - switch (theType) - { - case Graphic3d_TOPA_POINTS: - myDrawMode = GL_POINTS; - break; - case Graphic3d_TOPA_POLYLINES: - myDrawMode = GL_LINE_STRIP; - break; - case Graphic3d_TOPA_SEGMENTS: - myDrawMode = GL_LINES; - break; - case Graphic3d_TOPA_TRIANGLES: - myDrawMode = GL_TRIANGLES; - break; - case Graphic3d_TOPA_TRIANGLESTRIPS: - myDrawMode = GL_TRIANGLE_STRIP; - break; - case Graphic3d_TOPA_TRIANGLEFANS: - myDrawMode = GL_TRIANGLE_FAN; - break; - #if !defined(GL_ES_VERSION_2_0) - case Graphic3d_TOPA_POLYGONS: - myDrawMode = GL_POLYGON; - break; - case Graphic3d_TOPA_QUADRANGLES: - myDrawMode = GL_QUADS; - break; - case Graphic3d_TOPA_QUADRANGLESTRIPS: - myDrawMode = GL_QUAD_STRIP; - break; - #else - case Graphic3d_TOPA_POLYGONS: - case Graphic3d_TOPA_QUADRANGLES: - case Graphic3d_TOPA_QUADRANGLESTRIPS: - #endif - case Graphic3d_TOPA_UNDEFINED: - break; - } + setDrawMode (theType); } // ======================================================================= @@ -835,3 +794,77 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace aCtx->BindProgram (NULL); } + +// ======================================================================= +// function : setDrawMode +// purpose : +// ======================================================================= +void OpenGl_PrimitiveArray::setDrawMode (const Graphic3d_TypeOfPrimitiveArray theType) +{ + if (myAttribs.IsNull()) + { + myDrawMode = DRAW_MODE_NONE; + return; + } + + switch (theType) + { + case Graphic3d_TOPA_POINTS: + myDrawMode = GL_POINTS; + break; + case Graphic3d_TOPA_POLYLINES: + myDrawMode = GL_LINE_STRIP; + break; + case Graphic3d_TOPA_SEGMENTS: + myDrawMode = GL_LINES; + break; + case Graphic3d_TOPA_TRIANGLES: + myDrawMode = GL_TRIANGLES; + break; + case Graphic3d_TOPA_TRIANGLESTRIPS: + myDrawMode = GL_TRIANGLE_STRIP; + break; + case Graphic3d_TOPA_TRIANGLEFANS: + myDrawMode = GL_TRIANGLE_FAN; + break; + #if !defined(GL_ES_VERSION_2_0) + case Graphic3d_TOPA_POLYGONS: + myDrawMode = GL_POLYGON; + break; + case Graphic3d_TOPA_QUADRANGLES: + myDrawMode = GL_QUADS; + break; + case Graphic3d_TOPA_QUADRANGLESTRIPS: + myDrawMode = GL_QUAD_STRIP; + break; + #else + case Graphic3d_TOPA_POLYGONS: + case Graphic3d_TOPA_QUADRANGLES: + case Graphic3d_TOPA_QUADRANGLESTRIPS: + #endif + case Graphic3d_TOPA_UNDEFINED: + break; + } +} + +// ======================================================================= +// function : InitBuffers +// purpose : +// ======================================================================= +void OpenGl_PrimitiveArray::InitBuffers (const Handle(OpenGl_Context)& theContext, + const Graphic3d_TypeOfPrimitiveArray theType, + const Handle(Graphic3d_IndexBuffer)& theIndices, + const Handle(Graphic3d_Buffer)& theAttribs, + const Handle(Graphic3d_BoundBuffer)& theBounds) +{ + // Release old graphic resources + Release (theContext.operator->()); + + myIndices = theIndices; + myAttribs = theAttribs; + myBounds = theBounds; + + setDrawMode (theType); +} + + diff --git a/src/OpenGl/OpenGl_PrimitiveArray.hxx b/src/OpenGl/OpenGl_PrimitiveArray.hxx index 97956d026d..1ddb670c27 100644 --- a/src/OpenGl/OpenGl_PrimitiveArray.hxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.hxx @@ -69,6 +69,13 @@ public: //! Returns unique ID of primitive array. const Standard_Size GetUID() const { return myUID; } + //! Initialize indices, attributes and bounds with new data. + void InitBuffers (const Handle(OpenGl_Context)& theContext, + const Graphic3d_TypeOfPrimitiveArray theType, + const Handle(Graphic3d_IndexBuffer)& theIndices, + const Handle(Graphic3d_Buffer)& theAttribs, + const Handle(Graphic3d_BoundBuffer)& theBounds); + protected: //! VBO initialization procedures @@ -95,6 +102,11 @@ private: void drawMarkers (const Handle(OpenGl_Workspace)& theWorkspace) const; + //! Sets OpenGL draw mode according to the input type of primitive array. + //! If buffer of attributes is empty, draw mode is set to NONE to avoid invalid array rendering. + //! @param theType type of primitive array. + void setDrawMode (const Graphic3d_TypeOfPrimitiveArray theType); + protected: //! Destructor diff --git a/src/OpenGl/OpenGl_Utils.hxx b/src/OpenGl/OpenGl_Utils.hxx index 9bdfdf220f..39702c147d 100644 --- a/src/OpenGl/OpenGl_Utils.hxx +++ b/src/OpenGl/OpenGl_Utils.hxx @@ -447,9 +447,9 @@ static Standard_Boolean OpenGl_Utils::Project (const T anOut.z() *= anOut.w(); // Map x, y and z to range 0-1 - anOut.x() = anOut.x() * 0.5 + 0.5; - anOut.y() = anOut.y() * 0.5 + 0.5; - anOut.z() = anOut.z() * 0.5 + 0.5; + anOut.x() = anOut.x() * static_cast (0.5) + static_cast (0.5); + anOut.y() = anOut.y() * static_cast (0.5) + static_cast (0.5); + anOut.z() = anOut.z() * static_cast (0.5) + static_cast (0.5); // Map x,y to viewport anOut.x() = anOut.x() * theViewport[2] + theViewport[0]; diff --git a/src/OpenGl/OpenGl_View.cxx b/src/OpenGl/OpenGl_View.cxx index 30acf66ecf..bd963e7dd5 100644 --- a/src/OpenGl/OpenGl_View.cxx +++ b/src/OpenGl/OpenGl_View.cxx @@ -242,7 +242,7 @@ void OpenGl_View::TriedronErase (const Handle(OpenGl_Context)& theCtx) /*----------------------------------------------------------------------*/ void OpenGl_View::GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx, - const Graphic3d_CGraduatedTrihedron& theData) + const Graphic3d_GraduatedTrihedron& theData) { OpenGl_Element::Destroy (theCtx.operator->(), myGraduatedTrihedron); myGraduatedTrihedron = new OpenGl_GraduatedTrihedron (theData); diff --git a/src/OpenGl/OpenGl_View.hxx b/src/OpenGl/OpenGl_View.hxx index 8afca96622..254d7051d2 100644 --- a/src/OpenGl/OpenGl_View.hxx +++ b/src/OpenGl/OpenGl_View.hxx @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include #include @@ -109,8 +109,9 @@ class OpenGl_View : public MMgt_TShared const Standard_Boolean theAsWireframe); void TriedronErase (const Handle(OpenGl_Context)& theCtx); + OpenGl_GraduatedTrihedron* GraduatedTrihedron() const { return myGraduatedTrihedron; } void GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx, - const Graphic3d_CGraduatedTrihedron& theCubic); + const Graphic3d_GraduatedTrihedron& theCubic); void GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx); Standard_Real Height () const { return myCamera->ViewDimensions().X(); } diff --git a/src/V3d/V3d_View.cdl b/src/V3d/V3d_View.cdl index bab9e91328..6c87fe5222 100644 --- a/src/V3d/V3d_View.cdl +++ b/src/V3d/V3d_View.cdl @@ -122,6 +122,7 @@ uses ExtendedString from TCollection, PrintAlgo from Aspect, ClipPlane_Handle from Graphic3d, + GraduatedTrihedron from Graphic3d, SequenceOfHClipPlane from Graphic3d, RenderingMode from Graphic3d, RenderingParams from Graphic3d, @@ -458,110 +459,12 @@ is --------------------------------- GetGraduatedTrihedron(me; - -- Names of axes -- - xname, yname, zname : out ExtendedString from TCollection; - -- Draw names -- - xdrawname, ydrawname, zdrawname : out Boolean from Standard; - -- Draw values -- - xdrawvalues, ydrawvalues, zdrawvalues : out Boolean from Standard; - -- Draw grid -- - drawgrid : out Boolean from Standard; - -- Draw axes -- - drawaxes : out Boolean from Standard; - -- Number of splits along axes -- - nbx, nby, nbz : out Integer from Standard; - -- Offset for drawing values -- - xoffset, yoffset, zoffset : out Integer from Standard; - -- Offset for drawing names of axes -- - xaxisoffset, yaxisoffset, zaxisoffset : out Integer from Standard; - -- Draw tickmarks -- - xdrawtickmarks, ydrawtickmarks, zdrawtickmarks : out Boolean from Standard; - -- Length of tickmarks -- - xtickmarklength, ytickmarklength, ztickmarklength : out Integer from Standard; - -- Grid color -- - gridcolor : out Color from Quantity; - -- Colors of axis names -- - xnamecolor, ynamecolor, znamecolor : out Color from Quantity; - -- Colors of axis and values -- - xcolor, ycolor, zcolor : out Color from Quantity; - -- Name of font for names of axes -- - fontOfNames : out AsciiString from TCollection; - -- Style of names of axes -- - styleOfNames : out FontAspect from Font; - -- Size of names of axes -- - sizeOfNames : out Integer from Standard; - -- Name of font for values -- - fontOfValues : out AsciiString from TCollection; - -- Style of values -- - styleOfValues : out FontAspect from Font; - -- Size of values -- - sizeOfValues : out Integer from Standard) + theTrigedronData: out GraduatedTrihedron from Graphic3d) ---Purpose: Returns data of a graduated trihedron. is static; GraduatedTrihedronDisplay(me : mutable; - -- Names of axes -- - xname : ExtendedString from TCollection = "X"; - yname : ExtendedString from TCollection = "Y"; - zname : ExtendedString from TCollection = "Z"; - -- Draw names -- - xdrawname : Boolean from Standard = Standard_True; - ydrawname : Boolean from Standard = Standard_True; - zdrawname : Boolean from Standard = Standard_True; - -- Draw values -- - xdrawvalues : Boolean from Standard = Standard_True; - ydrawvalues : Boolean from Standard = Standard_True; - zdrawvalues : Boolean from Standard = Standard_True; - -- Draw grid -- - drawgrid : Boolean from Standard = Standard_True; - -- Draw axes -- - drawaxes : Boolean from Standard = Standard_True; - -- Number of splits along axes -- - nbx : Integer from Standard = 3; - nby : Integer from Standard = 3; - nbz : Integer from Standard = 3; - -- Offset for drawing values -- - xoffset : Integer from Standard = 10; - yoffset : Integer from Standard = 10; - zoffset : Integer from Standard = 10; - -- Offset for drawing names of axes -- - xaxisoffset : Integer from Standard = 30; - yaxisoffset : Integer from Standard = 30; - zaxisoffset : Integer from Standard = 30; - -- Draw tickmarks -- - xdrawtickmarks : Boolean from Standard = Standard_True; - ydrawtickmarks : Boolean from Standard = Standard_True; - zdrawtickmarks : Boolean from Standard = Standard_True; - -- Length of tickmarks -- - xtickmarklength : Integer from Standard = 10; - ytickmarklength : Integer from Standard = 10; - ztickmarklength : Integer from Standard = 10; - -- Grid color -- - gridcolor : Color from Quantity = Quantity_NOC_WHITE; - -- X name color -- - xnamecolor : Color from Quantity = Quantity_NOC_RED; - -- Y name color -- - ynamecolor : Color from Quantity = Quantity_NOC_GREEN; - -- Z name color -- - znamecolor : Color from Quantity = Quantity_NOC_BLUE1; - -- X color of axis and values -- - xcolor : Color from Quantity = Quantity_NOC_RED; - -- Y color of axis and values -- - ycolor : Color from Quantity = Quantity_NOC_GREEN; - -- Z color of axis and values -- - zcolor : Color from Quantity = Quantity_NOC_BLUE1; - -- Name of font for names of axes -- - fontOfNames : AsciiString from TCollection = "Arial"; - -- Style of names of axes -- - styleOfNames : FontAspect from Font = Font_FA_Bold; - -- Size of names of axes -- - sizeOfNames : Integer from Standard = 12; - -- Name of font for values -- - fontOfValues : AsciiString from TCollection = "Arial"; - -- Style of values -- - styleOfValues : FontAspect from Font = Font_FA_Regular; - -- Size of values -- - sizeOfValues : Integer from Standard = 12) + theTrigedronData: in GraduatedTrihedron from Graphic3d) ---Purpose: Displays a graduated trihedron. is static; diff --git a/src/V3d/V3d_View_4.cxx b/src/V3d/V3d_View_4.cxx index 7b44fdec93..63da14d4f3 100644 --- a/src/V3d/V3d_View_4.cxx +++ b/src/V3d/V3d_View_4.cxx @@ -16,7 +16,7 @@ #include #include - + #include #include @@ -271,261 +271,17 @@ void V3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho AType ) MyView->TriedronEcho (AType); } -void V3d_View::GetGraduatedTrihedron(/* Names of axes */ - TCollection_ExtendedString &xname, - TCollection_ExtendedString &yname, - TCollection_ExtendedString &zname, - /* Draw names */ - Standard_Boolean& xdrawname, - Standard_Boolean& ydrawname, - Standard_Boolean& zdrawname, - /* Draw values */ - Standard_Boolean& xdrawvalues, - Standard_Boolean& ydrawvalues, - Standard_Boolean& zdrawvalues, - /* Draw grid */ - Standard_Boolean& drawgrid, - /* Draw axes */ - Standard_Boolean& drawaxes, - /* Number of splits along axes */ - Standard_Integer& nbx, - Standard_Integer& nby, - Standard_Integer& nbz, - /* Offset for drawing values */ - Standard_Integer& xoffset, - Standard_Integer& yoffset, - Standard_Integer& zoffset, - /* Offset for drawing names of axes */ - Standard_Integer& xaxisoffset, - Standard_Integer& yaxisoffset, - Standard_Integer& zaxisoffset, - /* Draw tickmarks */ - Standard_Boolean& xdrawtickmarks, - Standard_Boolean& ydrawtickmarks, - Standard_Boolean& zdrawtickmarks, - /* Length of tickmarks */ - Standard_Integer& xtickmarklength, - Standard_Integer& ytickmarklength, - Standard_Integer& ztickmarklength, - /* Grid color */ - Quantity_Color& gridcolor, - /* X name color */ - Quantity_Color& xnamecolor, - /* Y name color */ - Quantity_Color& ynamecolor, - /* Z name color */ - Quantity_Color& znamecolor, - /* X color of axis and values */ - Quantity_Color& xcolor, - /* Y color of axis and values */ - Quantity_Color& ycolor, - /* Z color of axis and values */ - Quantity_Color& zcolor, - /* Name of font for names of axes */ - TCollection_AsciiString &fontOfNames, - /* Style of names of axes */ - Font_FontAspect& styleOfNames, - /* Size of names of axes */ - Standard_Integer& sizeOfNames, - /* Name of font for values */ - TCollection_AsciiString &fontOfValues, - /* Style of values */ - Font_FontAspect& styleOfValues, - /* Size of values */ - Standard_Integer& sizeOfValues) const +void V3d_View::GetGraduatedTrihedron (Graphic3d_GraduatedTrihedron& theTrihedronData) const { - MyView->GetGraduatedTrihedron(/* Names of axes */ - xname, - yname, - zname, - /* Draw names */ - xdrawname, - ydrawname, - zdrawname, - /* Draw values */ - xdrawvalues, - ydrawvalues, - zdrawvalues, - /* Draw grid */ - drawgrid, - /* Draw axes */ - drawaxes, - /* Number of splits along axes */ - nbx, - nby, - nbz, - /* Offset for drawing values */ - xoffset, - yoffset, - zoffset, - /* Offset for drawing names of axes */ - xaxisoffset, - yaxisoffset, - zaxisoffset, - /* Draw tickmarks */ - xdrawtickmarks, - ydrawtickmarks, - zdrawtickmarks, - /* Length of tickmarks */ - xtickmarklength, - ytickmarklength, - ztickmarklength, - /* Grid color */ - gridcolor, - /* X name color */ - xnamecolor, - /* Y name color */ - ynamecolor, - /* Z name color */ - znamecolor, - /* X color of axis and values */ - xcolor, - /* Y color of axis and values */ - ycolor, - /* Z color of axis and values */ - zcolor, - /* Name of font for names of axes */ - fontOfNames, - /* Style of names of axes */ - styleOfNames, - /* Size of names of axes */ - sizeOfNames, - /* Name of font for values */ - fontOfValues, - /* Style of values */ - styleOfValues, - /* Size of values */ - sizeOfValues); + MyView->GetGraduatedTrihedron (theTrihedronData); } -void V3d_View::GraduatedTrihedronDisplay(/* Names of axes */ - const TCollection_ExtendedString &xname, - const TCollection_ExtendedString &yname, - const TCollection_ExtendedString &zname, - /* Draw names */ - const Standard_Boolean xdrawname, - const Standard_Boolean ydrawname, - const Standard_Boolean zdrawname, - /* Draw values */ - const Standard_Boolean xdrawvalues, - const Standard_Boolean ydrawvalues, - const Standard_Boolean zdrawvalues, - /* Draw grid */ - const Standard_Boolean drawgrid, - /* Draw axes */ - const Standard_Boolean drawaxes, - /* Number of splits along axes */ - const Standard_Integer nbx, - const Standard_Integer nby, - const Standard_Integer nbz, - /* Offset for drawing values */ - const Standard_Integer xoffset, - const Standard_Integer yoffset, - const Standard_Integer zoffset, - /* Offset for drawing names of axes */ - const Standard_Integer xaxisoffset, - const Standard_Integer yaxisoffset, - const Standard_Integer zaxisoffset, - /* Draw tickmarks */ - const Standard_Boolean xdrawtickmarks, - const Standard_Boolean ydrawtickmarks, - const Standard_Boolean zdrawtickmarks, - /* Length of tickmarks */ - const Standard_Integer xtickmarklength, - const Standard_Integer ytickmarklength, - const Standard_Integer ztickmarklength, - /* Grid color */ - const Quantity_Color& gridcolor, - /* X name color */ - const Quantity_Color& xnamecolor, - /* Y name color */ - const Quantity_Color& ynamecolor, - /* Z name color */ - const Quantity_Color& znamecolor, - /* X color of axis and values */ - const Quantity_Color& xcolor, - /* Y color of axis and values */ - const Quantity_Color& ycolor, - /* Z color of axis and values */ - const Quantity_Color& zcolor, - /* Name of font for names of axes */ - const TCollection_AsciiString &fontOfNames, - /* Style of names of axes */ - const Font_FontAspect styleOfNames, - /* Size of names of axes */ - const Standard_Integer sizeOfNames, - /* Name of font for values */ - const TCollection_AsciiString &fontOfValues, - /* Style of values */ - const Font_FontAspect styleOfValues, - /* Size of values */ - const Standard_Integer sizeOfValues) +void V3d_View::GraduatedTrihedronDisplay(const Graphic3d_GraduatedTrihedron& theTrihedronData) { - MyView->GraduatedTrihedronDisplay(/* Names of axes */ - xname, - yname, - zname, - /* Draw names */ - xdrawname, - ydrawname, - zdrawname, - /* Draw values */ - xdrawvalues, - ydrawvalues, - zdrawvalues, - /* Draw grid */ - drawgrid, - /* Draw axes */ - drawaxes, - /* Number of splits along axes */ - nbx, - nby, - nbz, - /* Offset for drawing values */ - xoffset, - yoffset, - zoffset, - /* Offset for drawing names of axes */ - xaxisoffset, - yaxisoffset, - zaxisoffset, - /* Draw tickmarks */ - xdrawtickmarks, - ydrawtickmarks, - zdrawtickmarks, - /* Length of tickmarks */ - xtickmarklength, - ytickmarklength, - ztickmarklength, - /* Grid color */ - gridcolor, - /* X name color */ - xnamecolor, - /* Y name color */ - ynamecolor, - /* Z name color */ - znamecolor, - /* X color of axis and values */ - xcolor, - /* Y color of axis and values */ - ycolor, - /* Z color of axis and values */ - zcolor, - /* Name of font for names of axes */ - fontOfNames, - /* Style of names of axes */ - styleOfNames, - /* Size of names of axes */ - sizeOfNames, - /* Name of font for values */ - fontOfValues, - /* Style of values */ - styleOfValues, - /* Size of values */ - sizeOfValues); + MyView->GraduatedTrihedronDisplay(theTrihedronData); } void V3d_View::GraduatedTrihedronErase() { - MyView->GraduatedTrihedronErase(); + MyView->GraduatedTrihedronErase(); } diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index df3d13ddee..f6d3d3dc5e 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -3646,103 +3647,328 @@ static int VColorScale (Draw_Interpretor& theDI, //============================================================================== //function : VGraduatedTrihedron -//purpose : Displays a graduated trihedron +//purpose : Displays or hides a graduated trihedron //============================================================================== - -static void AddMultibyteString (TCollection_ExtendedString &name, const char *arg) +static Standard_Boolean GetColor (const TCollection_AsciiString& theValue, + Quantity_Color& theColor) { - const char *str = arg; - while (*str) + Quantity_NameOfColor aColorName; + TCollection_AsciiString aVal = theValue; + aVal.UpperCase(); + if (!Quantity_Color::ColorFromName (aVal.ToCString(), aColorName)) { - unsigned short c1 = *str++; - unsigned short c2 = *str++; - if (!c1 || !c2) break; - name += (Standard_ExtCharacter)((c1 << 8) | c2); + return Standard_False; } + theColor = Quantity_Color (aColorName); + return Standard_True; } -static int VGraduatedTrihedron(Draw_Interpretor& di, Standard_Integer argc, const char** argv) +static int VGraduatedTrihedron (Draw_Interpretor& /*theDi*/, Standard_Integer theArgNum, const char** theArgs) { - // Check arguments - if (argc != 2 && argc < 5) + if (theArgNum < 2) { - di<<"Error: "< aMapOfArgs; + TCollection_AsciiString aParseKey; + for (Standard_Integer anArgIt = 1; anArgIt < theArgNum; ++anArgIt) { - ViewerTest::ViewerInit(); - aV3dView = ViewerTest::CurrentView(); - if( aV3dView.IsNull() ) + TCollection_AsciiString anArg (theArgs [anArgIt]); + + if (anArg.Value (1) == '-' && !anArg.IsRealValue()) { - di << "Error: Cannot create a 3D view\n"; - return 1; //TCL_ERROR + aParseKey = anArg; + aParseKey.Remove (1); + aParseKey.LowerCase(); + aMapOfArgs.Bind (aParseKey, new TColStd_HSequenceOfAsciiString); + continue; } + + if (aParseKey.IsEmpty()) + { + continue; + } + + aMapOfArgs(aParseKey)->Append (anArg); } - // Erase (==0) or display (!=0) - const int display = Draw::Atoi(argv[1]); - - if (display) + // Check parameters + for (NCollection_DataMap::Iterator aMapIt (aMapOfArgs); + aMapIt.More(); aMapIt.Next()) { - // Text font - TCollection_AsciiString font; - if (argc < 6) - font.AssignCat("Courier"); - else - font.AssignCat(argv[5]); + const TCollection_AsciiString& aKey = aMapIt.Key(); + const Handle(TColStd_HSequenceOfAsciiString)& anArgs = aMapIt.Value(); - // Text is multibyte - const Standard_Boolean isMultibyte = (argc < 7)? Standard_False : (Draw::Atoi(argv[6]) != 0); - - // Set axis names - TCollection_ExtendedString xname, yname, zname; - if (argc >= 5) + // Bool key, without arguments + if ((aKey.IsEqual ("on") || aKey.IsEqual ("off")) + && anArgs->IsEmpty()) { - if (isMultibyte) - { - AddMultibyteString(xname, argv[2]); - AddMultibyteString(yname, argv[3]); - AddMultibyteString(zname, argv[4]); - } - else - { - xname += argv[2]; - yname += argv[3]; - zname += argv[4]; - } - } - else - { - xname += "X (mm)"; - yname += "Y (mm)"; - zname += "Z (mm)"; + continue; } - aV3dView->GraduatedTrihedronDisplay(xname, yname, zname, - Standard_True/*xdrawname*/, Standard_True/*ydrawname*/, Standard_True/*zdrawname*/, - Standard_True/*xdrawvalues*/, Standard_True/*ydrawvalues*/, Standard_True/*zdrawvalues*/, - Standard_True/*drawgrid*/, - Standard_True/*drawaxes*/, - 5/*nbx*/, 5/*nby*/, 5/*nbz*/, - 10/*xoffset*/, 10/*yoffset*/, 10/*zoffset*/, - 30/*xaxisoffset*/, 30/*yaxisoffset*/, 30/*zaxisoffset*/, - Standard_True/*xdrawtickmarks*/, Standard_True/*ydrawtickmarks*/, Standard_True/*zdrawtickmarks*/, - 10/*xtickmarklength*/, 10/*ytickmarklength*/, 10/*ztickmarklength*/, - Quantity_NOC_WHITE/*gridcolor*/, - Quantity_NOC_RED/*xnamecolor*/,Quantity_NOC_GREEN/*ynamecolor*/,Quantity_NOC_BLUE1/*znamecolor*/, - Quantity_NOC_RED/*xcolor*/,Quantity_NOC_GREEN/*ycolor*/,Quantity_NOC_BLUE1/*zcolor*/,font); + // One argument + if ( (aKey.IsEqual ("xname") || aKey.IsEqual ("yname") || aKey.IsEqual ("zname")) + && anArgs->Length() == 1) + { + continue; + } + + // 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")) + && anArgs->Length() == 1 && (anArgs->Value(1).IsEqual ("on") || anArgs->Value(1).IsEqual ("off"))) + { + continue; + } + + // One string argument + if ( (aKey.IsEqual ("xnamecolor") || aKey.IsEqual ("ynamecolor") || aKey.IsEqual ("znamecolor") + || aKey.IsEqual ("xcolor") || aKey.IsEqual ("ycolor") || aKey.IsEqual ("zcolor")) + && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue()) + { + continue; + } + + // One integer argument + if ( (aKey.IsEqual ("xticks") || aKey.IsEqual ("yticks") || aKey.IsEqual ("zticks") + || aKey.IsEqual ("xticklength") || aKey.IsEqual ("yticklength") || aKey.IsEqual ("zticklength") + || aKey.IsEqual ("xnameoffset") || aKey.IsEqual ("ynameoffset") || aKey.IsEqual ("znameoffset") + || aKey.IsEqual ("xvaluesoffset") || aKey.IsEqual ("yvaluesoffset") || aKey.IsEqual ("zvaluesoffset")) + && anArgs->Length() == 1 && anArgs->Value(1).IsIntegerValue()) + { + continue; + } + + // One real argument + if ( aKey.IsEqual ("arrowlength") + && anArgs->Length() == 1 && (anArgs->Value(1).IsIntegerValue() || anArgs->Value(1).IsRealValue())) + { + continue; + } + + // Two string arguments + if ( (aKey.IsEqual ("namefont") || aKey.IsEqual ("valuesfont")) + && anArgs->Length() == 1 && !anArgs->Value(1).IsIntegerValue() && !anArgs->Value(1).IsRealValue()) + { + continue; + } + + TCollection_AsciiString aLowerKey; + aLowerKey = "-"; + aLowerKey += aKey; + aLowerKey.LowerCase(); + std::cout << theArgs[0] << ": " << aLowerKey << " is unknown option, or the arguments are unacceptable.\n"; + std::cout << "Type help for more information.\n"; + return 1; + } + + Handle(AIS_InteractiveContext) anAISContext = ViewerTest::GetAISContext(); + if (anAISContext.IsNull()) + { + std::cout << theArgs[0] << ": " << " please use 'vinit' command to initialize view.\n"; + return 1; + } + + Standard_Boolean toDisplay = Standard_True; + Quantity_Color aColor; + Graphic3d_GraduatedTrihedron aTrihedronData; + // Process parameters + Handle(TColStd_HSequenceOfAsciiString) aValues; + if (aMapOfArgs.Find ("off", aValues)) + { + toDisplay = Standard_False; + } + + // AXES NAMES + if (aMapOfArgs.Find ("xname", aValues)) + { + aTrihedronData.ChangeXAxisAspect().SetName (aValues->Value(1)); + } + if (aMapOfArgs.Find ("yname", aValues)) + { + aTrihedronData.ChangeYAxisAspect().SetName (aValues->Value(1)); + } + if (aMapOfArgs.Find ("zname", aValues)) + { + aTrihedronData.ChangeZAxisAspect().SetName (aValues->Value(1)); + } + if (aMapOfArgs.Find ("xdrawname", aValues)) + { + aTrihedronData.ChangeXAxisAspect().SetToDrawName (aValues->Value(1).IsEqual ("on")); + } + if (aMapOfArgs.Find ("ydrawname", aValues)) + { + aTrihedronData.ChangeYAxisAspect().SetToDrawName (aValues->Value(1).IsEqual ("on")); + } + if (aMapOfArgs.Find ("zdrawname", aValues)) + { + aTrihedronData.ChangeZAxisAspect().SetToDrawName (aValues->Value(1).IsEqual ("on")); + } + if (aMapOfArgs.Find ("xnameoffset", aValues)) + { + aTrihedronData.ChangeXAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); + } + if (aMapOfArgs.Find ("ynameoffset", aValues)) + { + aTrihedronData.ChangeYAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); + } + if (aMapOfArgs.Find ("znameoffset", aValues)) + { + aTrihedronData.ChangeZAxisAspect().SetNameOffset (aValues->Value(1).IntegerValue()); + } + + // COLORS + if (aMapOfArgs.Find ("xnamecolor", aValues)) + { + if (!GetColor (aValues->Value(1), aColor)) + { + std::cout << theArgs[0] << "error: -xnamecolor wrong color name.\n"; + return 1; + } + aTrihedronData.ChangeXAxisAspect().SetNameColor (aColor); + } + if (aMapOfArgs.Find ("ynamecolor", aValues)) + { + if (!GetColor (aValues->Value(1), aColor)) + { + std::cout << theArgs[0] << "error: -ynamecolor wrong color name.\n"; + return 1; + } + aTrihedronData.ChangeYAxisAspect().SetNameColor (aColor); + } + if (aMapOfArgs.Find ("znamecolor", aValues)) + { + if (!GetColor (aValues->Value(1), aColor)) + { + std::cout << theArgs[0] << "error: -znamecolor wrong color name.\n"; + return 1; + } + aTrihedronData.ChangeZAxisAspect().SetNameColor (aColor); + } + if (aMapOfArgs.Find ("xcolor", aValues)) + { + if (!GetColor (aValues->Value(1), aColor)) + { + std::cout << theArgs[0] << "error: -xcolor wrong color name.\n"; + return 1; + } + aTrihedronData.ChangeXAxisAspect().SetColor (aColor); + } + if (aMapOfArgs.Find ("ycolor", aValues)) + { + if (!GetColor (aValues->Value(1), aColor)) + { + std::cout << theArgs[0] << "error: -ycolor wrong color name.\n"; + return 1; + } + aTrihedronData.ChangeYAxisAspect().SetColor (aColor); + } + if (aMapOfArgs.Find ("zcolor", aValues)) + { + if (!GetColor (aValues->Value(1), aColor)) + { + std::cout << theArgs[0] << "error: -zcolor wrong color name.\n"; + return 1; + } + aTrihedronData.ChangeZAxisAspect().SetColor (aColor); + } + + // TICKMARKS + if (aMapOfArgs.Find ("xticks", aValues)) + { + aTrihedronData.ChangeXAxisAspect().SetTickmarkNumber (aValues->Value(1).IntegerValue()); + } + if (aMapOfArgs.Find ("yticks", aValues)) + { + aTrihedronData.ChangeYAxisAspect().SetTickmarkNumber (aValues->Value(1).IntegerValue()); + } + if (aMapOfArgs.Find ("zticks", aValues)) + { + aTrihedronData.ChangeZAxisAspect().SetTickmarkNumber (aValues->Value(1).IntegerValue()); + } + if (aMapOfArgs.Find ("xticklength", aValues)) + { + aTrihedronData.ChangeXAxisAspect().SetTickmarkLength (aValues->Value(1).IntegerValue()); + } + if (aMapOfArgs.Find ("yticklength", aValues)) + { + aTrihedronData.ChangeYAxisAspect().SetTickmarkLength (aValues->Value(1).IntegerValue()); + } + if (aMapOfArgs.Find ("zticklength", aValues)) + { + aTrihedronData.ChangeZAxisAspect().SetTickmarkLength (aValues->Value(1).IntegerValue()); + } + if (aMapOfArgs.Find ("xdrawticks", aValues)) + { + aTrihedronData.ChangeXAxisAspect().SetToDrawTickmarks (aValues->Value(1).IsEqual ("on")); + } + if (aMapOfArgs.Find ("ydrawticks", aValues)) + { + aTrihedronData.ChangeYAxisAspect().SetToDrawTickmarks (aValues->Value(1).IsEqual ("on")); + } + if (aMapOfArgs.Find ("zdrawticks", aValues)) + { + aTrihedronData.ChangeZAxisAspect().SetToDrawTickmarks (aValues->Value(1).IsEqual ("on")); + } + + // VALUES + if (aMapOfArgs.Find ("xdrawvalues", aValues)) + { + aTrihedronData.ChangeXAxisAspect().SetToDrawValues (aValues->Value(1).IsEqual ("on")); + } + if (aMapOfArgs.Find ("ydrawvalues", aValues)) + { + aTrihedronData.ChangeYAxisAspect().SetToDrawValues (aValues->Value(1).IsEqual ("on")); + } + if (aMapOfArgs.Find ("zdrawvalues", aValues)) + { + aTrihedronData.ChangeZAxisAspect().SetToDrawValues (aValues->Value(1).IsEqual ("on")); + } + if (aMapOfArgs.Find ("xvaluesoffset", aValues)) + { + aTrihedronData.ChangeXAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); + } + if (aMapOfArgs.Find ("yvaluesoffset", aValues)) + { + aTrihedronData.ChangeYAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); + } + if (aMapOfArgs.Find ("zvaluesoffset", aValues)) + { + aTrihedronData.ChangeZAxisAspect().SetValuesOffset (aValues->Value(1).IntegerValue()); + } + + // ARROWS + if (aMapOfArgs.Find ("arrowlength", aValues)) + { + aTrihedronData.SetArrowLength ((Standard_ShortReal) aValues->Value(1).RealValue()); + } + + // FONTS + if (aMapOfArgs.Find ("namefont", aValues)) + { + aTrihedronData.SetNamesFont (aValues->Value(1)); + } + if (aMapOfArgs.Find ("valuesfont", aValues)) + { + aTrihedronData.SetValuesFont (aValues->Value(1)); + } + + // The final step: display of erase trihedron + if (toDisplay) + { + ViewerTest::CurrentView()->GraduatedTrihedronDisplay (aTrihedronData); } else - aV3dView->GraduatedTrihedronErase(); + { + ViewerTest::CurrentView()->GraduatedTrihedronErase(); + } ViewerTest::GetAISContext()->UpdateCurrentViewer(); - aV3dView->Redraw(); + ViewerTest::CurrentView()->Redraw(); return 0; } @@ -7808,7 +8034,27 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands) "Available text positions: left, right, center, none;\n", __FILE__,VColorScale,group); theCommands.Add("vgraduatedtrihedron", - "vgraduatedtrihedron : 1/0 (display/erase) [Xname Yname Zname [Font [isMultibyte]]]", + "vgraduatedtrihedron : -on/-off [-xname Name] [-yname Name] [-zname Name] [-arrowlength Value]\n" + "\t[-namefont Name] [-valuesfont Name]\n" + "\t[-xdrawname on/off] [-ydrawname on/off] [-zdrawname on/off]\n" + "\t[-xnameoffset IntVal] [-ynameoffset IntVal] [-znameoffset IntVal]" + "\t[-xnamecolor Color] [-ynamecolor Color] [-znamecolor Color]\n" + "\t[-xdrawvalues on/off] [-ydrawvalues on/off] [-zdrawvalues on/off]\n" + "\t[-xvaluesoffset IntVal] [-yvaluesoffset IntVal] [-zvaluesoffset IntVal]" + "\t[-xcolor Color] [-ycolor Color] [-zcolor Color]\n" + "\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" + " - Displays or erases graduated trihedron" + " - xname, yname, zname - names of axes, default: X, Y, Z\n" + " - namefont - font of axes names. Default: Arial\n" + " - xnameoffset, ynameoffset, znameoffset - offset of name from values or tickmarks or axis. Default: 30\n" + " - xnamecolor, ynamecolor, znamecolor - colors of axes names\n" + " - xvaluesoffset, yvaluesoffset, zvaluesoffset - offset of values from tickmarks or axis. Default: 10\n" + " - valuesfont - font of axes values. Default: Arial\n" + " - xcolor, ycolor, zcolor - color of axis and values\n" + " - xticks, yticks, xzicks - number of tickmark on axes. Default: 5\n" + " - xticklength, yticklength, xzicklength - length of tickmark on axes. Default: 10\n", __FILE__,VGraduatedTrihedron,group); theCommands.Add("vprintview" , "vprintview : width height filename [algo=0] [tile_width tile_height] : Test print algorithm: algo = 0 - stretch, algo = 1 - tile", diff --git a/src/Visual3d/Visual3d_View.cdl b/src/Visual3d/Visual3d_View.cdl index 9405974201..899f8f77fb 100644 --- a/src/Visual3d/Visual3d_View.cdl +++ b/src/Visual3d/Visual3d_View.cdl @@ -104,7 +104,7 @@ uses FontAspect from Font, AsciiString from TCollection, ExtendedString from TCollection, - CGraduatedTrihedron from Graphic3d, + GraduatedTrihedron from Graphic3d, NMapOfTransient from Graphic3d, TypeOfStructure from Graphic3d, @@ -515,87 +515,13 @@ is ------------------------------------------ GetGraduatedTrihedron(me; - -- Names of axes -- - xname, yname, zname : out ExtendedString from TCollection; - -- Draw names -- - xdrawname, ydrawname, zdrawname : out Boolean from Standard; - -- Draw values -- - xdrawvalues, ydrawvalues, zdrawvalues : out Boolean from Standard; - -- Draw grid -- - drawgrid : out Boolean from Standard; - -- Draw axes -- - drawaxes : out Boolean from Standard; - -- Number of splits along axes -- - nbx, nby, nbz : out Integer from Standard; - -- Offset for drawing values -- - xoffset, yoffset, zoffset : out Integer from Standard; - -- Offset for drawing names of axes -- - xaxisoffset, yaxisoffset, zaxisoffset : out Integer from Standard; - -- Draw tickmarks -- - xdrawtickmarks, ydrawtickmarks, zdrawtickmarks : out Boolean from Standard; - -- Length of tickmarks -- - xtickmarklength, ytickmarklength, ztickmarklength : out Integer from Standard; - -- Grid color -- - gridcolor : out Color from Quantity; - -- Colors of axis names -- - xnamecolor, ynamecolor, znamecolor : out Color from Quantity; - -- Colors of axis and values -- - xcolor, ycolor, zcolor : out Color from Quantity; - -- Name of font for names of axes -- - fontOfNames : out AsciiString from TCollection; - -- Style of names of axes -- - styleOfNames : out FontAspect from Font; - -- Size of names of axes -- - sizeOfNames : out Integer from Standard; - -- Name of font for values -- - fontOfValues : out AsciiString from TCollection; - -- Style of values -- - styleOfValues : out FontAspect from Font; - -- Size of values -- - sizeOfValues : out Integer from Standard) + theTrigedronData: out GraduatedTrihedron from Graphic3d) returns Boolean from Standard is static; ---Purpose: Returns data of a graduated trihedron if displayed (return value is True) GraduatedTrihedronDisplay(me : mutable; - -- Names of axes -- - xname, yname, zname : ExtendedString from TCollection; - -- Draw names -- - xdrawname, ydrawname, zdrawname : Boolean from Standard; - -- Draw values -- - xdrawvalues, ydrawvalues, zdrawvalues : Boolean from Standard; - -- Draw grid -- - drawgrid : Boolean from Standard; - -- Draw axes -- - drawaxes : Boolean from Standard; - -- Number of splits along axes -- - nbx, nby, nbz : Integer from Standard; - -- Offset for drawing values -- - xoffset, yoffset, zoffset : Integer from Standard; - -- Offset for drawing names of axes -- - xaxisoffset, yaxisoffset, zaxisoffset : Integer from Standard; - -- Draw tickmarks -- - xdrawtickmarks, ydrawtickmarks, zdrawtickmarks : Boolean from Standard; - -- Length of tickmarks -- - xtickmarklength, ytickmarklength, ztickmarklength : Integer from Standard; - -- Grid color -- - gridcolor : Color from Quantity; - -- Colors of axis names -- - xnamecolor, ynamecolor, znamecolor : Color from Quantity; - -- Colors of axis and values -- - xcolor, ycolor, zcolor : Color from Quantity; - -- Name of font for names of axes -- - fontOfNames : AsciiString from TCollection; - -- Style of names of axes -- - styleOfNames : FontAspect from Font; - -- Size of names of axes -- - sizeOfNames : Integer from Standard; - -- Name of font for values -- - fontOfValues : AsciiString from TCollection; - -- Style of values -- - styleOfValues : FontAspect from Font; - -- Size of values -- - sizeOfValues : Integer from Standard) + theTrigedronData: in GraduatedTrihedron from Graphic3d) ---Purpose: Displays a graduated trihedron. is static; @@ -1195,7 +1121,7 @@ fields myStructsDisplayed : MapOfStructure from Graphic3d; myImmediateStructures : MapOfStructure from Graphic3d; - MyGTrihedron : CGraduatedTrihedron from Graphic3d; + myGTrihedron : GraduatedTrihedron from Graphic3d; myDefaultCamera : Camera_Handle from Graphic3d; diff --git a/src/Visual3d/Visual3d_View.cxx b/src/Visual3d/Visual3d_View.cxx index 7bfe697c81..42cfb67ced 100644 --- a/src/Visual3d/Visual3d_View.cxx +++ b/src/Visual3d/Visual3d_View.cxx @@ -2084,14 +2084,18 @@ void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho theType) static void SetMinMaxValuesCallback (Visual3d_View* theView) { + Graphic3d_CView* aCView = (Graphic3d_CView* )(theView->CView()); Bnd_Box aBox = theView->MinMaxValues(); if (!aBox.IsVoid()) { gp_Pnt aMin = aBox.CornerMin(); gp_Pnt aMax = aBox.CornerMax(); + + Graphic3d_Vec3 aMinVec ((Standard_ShortReal )aMin.X(), (Standard_ShortReal )aMin.Y(), (Standard_ShortReal )aMin.Z()); + Graphic3d_Vec3 aMaxVec ((Standard_ShortReal )aMax.X(), (Standard_ShortReal )aMax.Y(), (Standard_ShortReal )aMax.Z()); const Handle(Graphic3d_GraphicDriver)& aDriver = theView->GraphicDriver(); - aDriver->GraduatedTrihedronMinMaxValues ((Standard_ShortReal )aMin.X(), (Standard_ShortReal )aMin.Y(), (Standard_ShortReal )aMin.Z(), - (Standard_ShortReal )aMax.X(), (Standard_ShortReal )aMax.Y(), (Standard_ShortReal )aMax.Z()); + aDriver->GraduatedTrihedronMinMaxValues (*aCView, aMinVec, aMaxVec); + } } @@ -2099,90 +2103,14 @@ static void SetMinMaxValuesCallback (Visual3d_View* theView) // function : GetGraduatedTrihedron // purpose : // ======================================================================= -Standard_Boolean Visual3d_View::GetGraduatedTrihedron (TCollection_ExtendedString& theXName, - TCollection_ExtendedString& theYName, - TCollection_ExtendedString& theZName, - Standard_Boolean& theToDrawXName, - Standard_Boolean& theToDrawYName, - Standard_Boolean& theToDrawZName, - Standard_Boolean& theToDrawXValues, - Standard_Boolean& theToDrawYValues, - Standard_Boolean& theToDrawZValues, - Standard_Boolean& theToDrawGrid, - Standard_Boolean& theToDrawAxes, - Standard_Integer& theNbX, - Standard_Integer& theNbY, - Standard_Integer& theNbZ, - Standard_Integer& theXOffset, - Standard_Integer& theYOffset, - Standard_Integer& theZOffset, - Standard_Integer& theXAxisOffset, - Standard_Integer& theYAxisOffset, - Standard_Integer& theZAxisOffset, - Standard_Boolean& theToDrawXTickMarks, - Standard_Boolean& theToDrawYTickMarks, - Standard_Boolean& theToDrawZTickMarks, - Standard_Integer& theXTickMarkLength, - Standard_Integer& theYTickMarkLength, - Standard_Integer& theZTickMarkLength, - Quantity_Color& theGridColor, - Quantity_Color& theXNameColor, - Quantity_Color& theYNameColor, - Quantity_Color& theZNameColor, - Quantity_Color& theXColor, - Quantity_Color& theYColor, - Quantity_Color& theZColor, - TCollection_AsciiString& theFontOfNames, - Font_FontAspect& theStyleOfNames, - Standard_Integer& theSizeOfNames, - TCollection_AsciiString& theFontOfValues, - Font_FontAspect& theStyleOfValues, - Standard_Integer& theSizeOfValues) const +Standard_Boolean Visual3d_View::GetGraduatedTrihedron (Graphic3d_GraduatedTrihedron& theTrihedronData) const { - if (!MyGTrihedron.ptrVisual3dView) + if (!myGTrihedron.PtrVisual3dView) { return Standard_False; } - theXName = MyGTrihedron.xname; - theYName = MyGTrihedron.yname; - theZName = MyGTrihedron.zname; - theToDrawXName = MyGTrihedron.xdrawname; - theToDrawYName = MyGTrihedron.ydrawname; - theToDrawZName = MyGTrihedron.zdrawname; - theToDrawXValues = MyGTrihedron.xdrawvalues; - theToDrawYValues = MyGTrihedron.ydrawvalues; - theToDrawZValues = MyGTrihedron.zdrawvalues; - theToDrawGrid = MyGTrihedron.drawgrid; - theToDrawAxes = MyGTrihedron.drawaxes; - theNbX = MyGTrihedron.nbx; - theNbY = MyGTrihedron.nby; - theNbZ = MyGTrihedron.nbz; - theXOffset = MyGTrihedron.xoffset; - theYOffset = MyGTrihedron.yoffset; - theZOffset = MyGTrihedron.zoffset; - theXAxisOffset = MyGTrihedron.xaxisoffset; - theYAxisOffset = MyGTrihedron.yaxisoffset; - theZAxisOffset = MyGTrihedron.zaxisoffset; - theToDrawXTickMarks = MyGTrihedron.xdrawtickmarks; - theToDrawYTickMarks = MyGTrihedron.ydrawtickmarks; - theToDrawZTickMarks = MyGTrihedron.zdrawtickmarks; - theXTickMarkLength = MyGTrihedron.xtickmarklength; - theYTickMarkLength = MyGTrihedron.ytickmarklength; - theZTickMarkLength = MyGTrihedron.ztickmarklength; - theGridColor = MyGTrihedron.gridcolor; - theXNameColor = MyGTrihedron.xnamecolor; - theYNameColor = MyGTrihedron.ynamecolor; - theZNameColor = MyGTrihedron.znamecolor; - theXColor = MyGTrihedron.xcolor; - theYColor = MyGTrihedron.ycolor; - theZColor = MyGTrihedron.zcolor; - theFontOfNames = MyGTrihedron.fontOfNames; - theStyleOfNames = MyGTrihedron.styleOfNames; - theSizeOfNames = MyGTrihedron.sizeOfNames; - theFontOfValues = MyGTrihedron.fontOfValues; - theStyleOfValues = MyGTrihedron.styleOfValues; - theSizeOfValues = MyGTrihedron.sizeOfValues; + theTrihedronData = myGTrihedron; return Standard_True; } @@ -2190,89 +2118,14 @@ Standard_Boolean Visual3d_View::GetGraduatedTrihedron (TCollection_ExtendedStrin // function : GraduatedTrihedronDisplay // purpose : // ======================================================================= -void Visual3d_View::GraduatedTrihedronDisplay (const TCollection_ExtendedString& theXName, - const TCollection_ExtendedString& theYName, - const TCollection_ExtendedString& theZName, - const Standard_Boolean theToDrawXName, - const Standard_Boolean theToDrawYName, - const Standard_Boolean theToDrawZName, - const Standard_Boolean theToDrawXValues, - const Standard_Boolean theToDrawYValues, - const Standard_Boolean theToDrawZValues, - const Standard_Boolean theToDrawGrid, - const Standard_Boolean theToDrawAxes, - const Standard_Integer theNbX, - const Standard_Integer theNbY, - const Standard_Integer theNbZ, - const Standard_Integer theXOffset, - const Standard_Integer theYOffset, - const Standard_Integer theZOffset, - const Standard_Integer theXAxisOffset, - const Standard_Integer theYAxisOffset, - const Standard_Integer theZAxisOffset, - const Standard_Boolean theToDrawXTickMarks, - const Standard_Boolean theToDrawYTickMarks, - const Standard_Boolean theToDrawZTickMarks, - const Standard_Integer theXTickMarkLength, - const Standard_Integer theYTickMarkLength, - const Standard_Integer theZTickMarkLength, - const Quantity_Color& theGridColor, - const Quantity_Color& theXNameColor, - const Quantity_Color& theYNameColor, - const Quantity_Color& theZNameColor, - const Quantity_Color& theXColor, - const Quantity_Color& theYColor, - const Quantity_Color& theZColor, - const TCollection_AsciiString& theFontOfNames, - const Font_FontAspect theStyleOfNames, - const Standard_Integer theSizeOfNames, - const TCollection_AsciiString& theFontOfValues, - const Font_FontAspect theStyleOfValues, - const Standard_Integer theSizeOfValues) +void Visual3d_View::GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) { - MyGTrihedron.xname = theXName; - MyGTrihedron.yname = theYName; - MyGTrihedron.zname = theZName; - MyGTrihedron.xdrawname = theToDrawXName; - MyGTrihedron.ydrawname = theToDrawYName; - MyGTrihedron.zdrawname = theToDrawZName; - MyGTrihedron.xdrawvalues = theToDrawXValues; - MyGTrihedron.ydrawvalues = theToDrawYValues; - MyGTrihedron.zdrawvalues = theToDrawZValues; - MyGTrihedron.drawgrid = theToDrawGrid; - MyGTrihedron.drawaxes = theToDrawAxes; - MyGTrihedron.nbx = theNbX; - MyGTrihedron.nby = theNbY; - MyGTrihedron.nbz = theNbZ; - MyGTrihedron.xoffset = theXOffset; - MyGTrihedron.yoffset = theYOffset; - MyGTrihedron.zoffset = theZOffset; - MyGTrihedron.xaxisoffset = theXAxisOffset; - MyGTrihedron.yaxisoffset = theYAxisOffset; - MyGTrihedron.zaxisoffset = theZAxisOffset; - MyGTrihedron.xdrawtickmarks = theToDrawXTickMarks; - MyGTrihedron.ydrawtickmarks = theToDrawYTickMarks; - MyGTrihedron.zdrawtickmarks = theToDrawZTickMarks; - MyGTrihedron.xtickmarklength = theXTickMarkLength; - MyGTrihedron.ytickmarklength = theYTickMarkLength; - MyGTrihedron.ztickmarklength = theZTickMarkLength; - MyGTrihedron.gridcolor = theGridColor; - MyGTrihedron.xnamecolor = theXNameColor; - MyGTrihedron.ynamecolor = theYNameColor; - MyGTrihedron.znamecolor = theZNameColor; - MyGTrihedron.xcolor = theXColor; - MyGTrihedron.ycolor = theYColor; - MyGTrihedron.zcolor = theZColor; - MyGTrihedron.fontOfNames = theFontOfNames; - MyGTrihedron.styleOfNames = theStyleOfNames; - MyGTrihedron.sizeOfNames = theSizeOfNames; - MyGTrihedron.fontOfValues = theFontOfValues; - MyGTrihedron.styleOfValues = theStyleOfValues; - MyGTrihedron.sizeOfValues = theSizeOfValues; + myGTrihedron = theTrihedronData; - MyGTrihedron.ptrVisual3dView = this; - MyGTrihedron.cbCubicAxes = SetMinMaxValuesCallback; - myGraphicDriver->GraduatedTrihedronDisplay (MyCView, MyGTrihedron); + myGTrihedron.PtrVisual3dView = this; + myGTrihedron.CubicAxesCallback = SetMinMaxValuesCallback; + + myGraphicDriver->GraduatedTrihedronDisplay (MyCView, myGTrihedron); } // ======================================================================= @@ -2281,7 +2134,7 @@ void Visual3d_View::GraduatedTrihedronDisplay (const TCollection_ExtendedString& // ======================================================================= void Visual3d_View::GraduatedTrihedronErase() { - MyGTrihedron.ptrVisual3dView = NULL; + myGTrihedron.PtrVisual3dView = NULL; myGraphicDriver->GraduatedTrihedronErase (MyCView); } diff --git a/tests/bugs/vis/bug25611_1 b/tests/bugs/vis/bug25611_1 new file mode 100644 index 0000000000..be7e3e093b --- /dev/null +++ b/tests/bugs/vis/bug25611_1 @@ -0,0 +1,23 @@ +puts "========" +puts "OCC25611" +puts "========" +puts "" +############################################################################ +puts "Displaying \'zbufftrihedron\' interferes with \'vgraduatedtrihedron\'" +############################################################################ + +set anImage $imagedir/${casename}.png + +vinit View1 +psphere s 10 +vdisplay s +vaxo +vfit +vsetdispmode s 1 +vgraduatedtrihedron -on +vzbufftrihedron + +vdump $anImage +vclear +vclose View1 + diff --git a/tests/bugs/vis/bug25611_2 b/tests/bugs/vis/bug25611_2 new file mode 100644 index 0000000000..b64762b64d --- /dev/null +++ b/tests/bugs/vis/bug25611_2 @@ -0,0 +1,38 @@ +puts "========" +puts "OCC25611" +puts "========" +puts "" +############################################################################ +puts "Displaying \'zbufftrihedron\' interferes with \'vgraduatedtrihedron\'" +puts "Test graduated trihedron parameters" +############################################################################ + +set anImage1 $imagedir/${casename}_1.png +set anImage2 $imagedir/${casename}_2.png +set anImage3 $imagedir/${casename}_3.png +set anImage4 $imagedir/${casename}_4.png + +vinit View1 +psphere s 10 +vdisplay s +vaxo +vfit +vsetdispmode s 1 + +# Font and color parameters +vgraduatedtrihedron -on -xname X(mm) -yname Y(mm) -zname Z(mm) -xnamecolor PINK -ycolor GREENYELLOW -namefont Courier -valuesfont Courier +vdump $anImage1 + +# Boolean parameters +vgraduatedtrihedron -on -xdrawname off -ydrawvalues off -zdrawticks off +vdump $anImage2 + +# Tickmark parameters +vgraduatedtrihedron -on -xticks 10 -xticklength 15 -xvaluesoffset 20 -xnameoffset 40 +vdump $anImage3 + +#Arrow parameters +vgraduatedtrihedron -on -arrowlength 50 +vdump $anImage4 +vclose View1 +