1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-16 10:08:36 +03:00

0026083: Coding Rules - Poor design of Graphic3d_GraduatedTrihedron

- Made class Graphic3d_AxisAspect publicly nested in Graphic3d_GraduatedTrihedron.
- Removed public PtrView field from trihedron and obtained it from OpenGL_Workspace while rendering.
- Made CubicAxesCallback protected and provided corresponding getter/setter.
- Renamed AxisAspect() to AxisAspectAt().
This commit is contained in:
achesnok 2021-08-04 14:37:46 +03:00
parent 27e64adb38
commit 1b5eb2be23
4 changed files with 76 additions and 67 deletions

View File

@ -26,13 +26,21 @@
class Graphic3d_CView; class Graphic3d_CView;
//! Defines the class of a graduated trihedron.
//! It contains main style parameters for implementation of graduated trihedron
//! @sa OpenGl_GraduatedTrihedron
class Graphic3d_GraduatedTrihedron
{
public:
//! Class that stores style for one graduated trihedron axis such as colors, lengths and customization flags. //! Class that stores style for one graduated trihedron axis such as colors, lengths and customization flags.
//! It is used in Graphic3d_GraduatedTrihedron. //! It is used in Graphic3d_GraduatedTrihedron.
class Graphic3d_AxisAspect class AxisAspect
{ {
public: public:
Graphic3d_AxisAspect (const TCollection_ExtendedString theName = "", const Quantity_Color theNameColor = Quantity_NOC_BLACK, AxisAspect (const TCollection_ExtendedString theName = "", const Quantity_Color theNameColor = Quantity_NOC_BLACK,
const Quantity_Color theColor = Quantity_NOC_BLACK, const Quantity_Color theColor = Quantity_NOC_BLACK,
const Standard_Integer theValuesOffset = 10, const Standard_Integer theNameOffset = 30, const Standard_Integer theValuesOffset = 10, const Standard_Integer theNameOffset = 30,
const Standard_Integer theTickmarksNumber = 5, const Standard_Integer theTickmarksLength = 10, const Standard_Integer theTickmarksNumber = 5, const Standard_Integer theTickmarksLength = 10,
@ -104,11 +112,6 @@ protected:
Standard_Integer myNameOffset; //!< Offset for drawing name of axis 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: public:
typedef void (*MinMaxValuesCallback) (Graphic3d_CView*); typedef void (*MinMaxValuesCallback) (Graphic3d_CView*);
@ -123,7 +126,8 @@ public:
const Font_FontAspect& theValuesStyle = Font_FA_Regular, const Standard_Integer theValuesSize = 12, const Font_FontAspect& theValuesStyle = Font_FA_Regular, const Standard_Integer theValuesSize = 12,
const Standard_ShortReal theArrowsLength = 30.0f, const Quantity_Color theGridColor = Quantity_NOC_WHITE, const Standard_ShortReal theArrowsLength = 30.0f, const Quantity_Color theGridColor = Quantity_NOC_WHITE,
const Standard_Boolean theToDrawGrid = Standard_True, const Standard_Boolean theToDrawAxes = Standard_True) const Standard_Boolean theToDrawGrid = Standard_True, const Standard_Boolean theToDrawAxes = Standard_True)
: myNamesFont (theNamesFont), : myCubicAxesCallback (NULL),
myNamesFont (theNamesFont),
myNamesStyle (theNamesStyle), myNamesStyle (theNamesStyle),
myNamesSize (theNamesSize), myNamesSize (theNamesSize),
myValuesFont (theValuesFont), myValuesFont (theValuesFont),
@ -135,29 +139,28 @@ public:
myToDrawAxes (theToDrawAxes), myToDrawAxes (theToDrawAxes),
myAxes(0, 2) myAxes(0, 2)
{ {
myAxes (0) = Graphic3d_AxisAspect ("X", Quantity_NOC_RED, Quantity_NOC_RED); myAxes (0) = AxisAspect ("X", Quantity_NOC_RED, Quantity_NOC_RED);
myAxes (1) = Graphic3d_AxisAspect ("Y", Quantity_NOC_GREEN, Quantity_NOC_GREEN); myAxes (1) = AxisAspect ("Y", Quantity_NOC_GREEN, Quantity_NOC_GREEN);
myAxes (2) = Graphic3d_AxisAspect ("Z", Quantity_NOC_BLUE1, Quantity_NOC_BLUE1); myAxes (2) = AxisAspect ("Z", Quantity_NOC_BLUE1, Quantity_NOC_BLUE1);
PtrView = NULL;
} }
public: public:
Graphic3d_AxisAspect& ChangeXAxisAspect() { return myAxes(0); } AxisAspect& ChangeXAxisAspect() { return myAxes(0); }
Graphic3d_AxisAspect& ChangeYAxisAspect() { return myAxes(1); } AxisAspect& ChangeYAxisAspect() { return myAxes(1); }
Graphic3d_AxisAspect& ChangeZAxisAspect() { return myAxes(2); } AxisAspect& ChangeZAxisAspect() { return myAxes(2); }
Graphic3d_AxisAspect& ChangeAxisAspect (const Standard_Integer theIndex) AxisAspect& ChangeAxisAspect (const Standard_Integer theIndex)
{ {
Standard_OutOfRange_Raise_if (theIndex < 0 || theIndex > 2, "Graphic3d_GraduatedTrihedron::ChangeAxisAspect: theIndex is out of bounds [0,2]."); Standard_OutOfRange_Raise_if (theIndex < 0 || theIndex > 2, "Graphic3d_GraduatedTrihedron::ChangeAxisAspect: theIndex is out of bounds [0,2].");
return myAxes (theIndex); return myAxes (theIndex);
} }
const Graphic3d_AxisAspect& XAxisAspect() const { return myAxes(0); } const AxisAspect& XAxisAspect() const { return myAxes(0); }
const Graphic3d_AxisAspect& YAxisAspect() const { return myAxes(1); } const AxisAspect& YAxisAspect() const { return myAxes(1); }
const Graphic3d_AxisAspect& ZAxisAspect() const { return myAxes(2); } const AxisAspect& ZAxisAspect() const { return myAxes(2); }
const Graphic3d_AxisAspect& AxisAspect (const Standard_Integer theIndex) const const AxisAspect& AxisAspectAt (const Standard_Integer theIndex) const
{ {
Standard_OutOfRange_Raise_if (theIndex < 0 || theIndex > 2, "Graphic3d_GraduatedTrihedron::AxisAspect: theIndex is out of bounds [0,2]."); Standard_OutOfRange_Raise_if (theIndex < 0 || theIndex > 2, "Graphic3d_GraduatedTrihedron::AxisAspect: theIndex is out of bounds [0,2].");
return myAxes (theIndex); return myAxes (theIndex);
@ -193,13 +196,21 @@ public:
Standard_Integer ValuesSize() const { return myValuesSize; } Standard_Integer ValuesSize() const { return myValuesSize; }
void SetValuesSize (const Standard_Integer theValue) { myValuesSize = theValue; } void SetValuesSize (const Standard_Integer theValue) { myValuesSize = theValue; }
public: Standard_Boolean CubicAxesCallback(Graphic3d_CView* theView) const
{
MinMaxValuesCallback CubicAxesCallback; //!< Callback function to define boundary box of displayed objects if (myCubicAxesCallback != NULL)
Graphic3d_CView* PtrView; {
myCubicAxesCallback (theView);
return Standard_True;
}
return Standard_False;
}
void SetCubicAxesCallback (const MinMaxValuesCallback theCallback) { myCubicAxesCallback = theCallback; }
protected: protected:
MinMaxValuesCallback myCubicAxesCallback; //!< Callback function to define boundary box of displayed objects
TCollection_AsciiString myNamesFont; //!< Font name of names of axes: Courier, Arial, ... 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,.. Font_FontAspect myNamesStyle; //!< Style of names of axes: OSD_FA_Regular, OSD_FA_Bold,..
Standard_Integer myNamesSize; //!< Size of names of axes: 8, 10,.. Standard_Integer myNamesSize; //!< Size of names of axes: 8, 10,..
@ -218,7 +229,7 @@ protected:
Standard_Boolean myToDrawGrid; Standard_Boolean myToDrawGrid;
Standard_Boolean myToDrawAxes; Standard_Boolean myToDrawAxes;
NCollection_Array1<Graphic3d_AxisAspect> myAxes; //!< X, Y and Z axes parameters NCollection_Array1<AxisAspect> myAxes; //!< X, Y and Z axes parameters
}; };
#endif // Graphic3d_GraduatedTrihedron_HeaderFile #endif // Graphic3d_GraduatedTrihedron_HeaderFile

View File

@ -355,7 +355,7 @@ void OpenGl_GraduatedTrihedron::renderGridPlane (const Handle(OpenGl_Workspace)&
const GridAxes& theGridAxes, const GridAxes& theGridAxes,
OpenGl_Mat4& theMat) const OpenGl_Mat4& theMat) const
{ {
const Graphic3d_AxisAspect& aCurAspect = myData.AxisAspect (theIndex); const Graphic3d_GraduatedTrihedron::AxisAspect& aCurAspect = myData.AxisAspectAt (theIndex);
if (aCurAspect.TickmarksNumber() <= 0) if (aCurAspect.TickmarksNumber() <= 0)
{ {
return; return;
@ -475,7 +475,7 @@ void OpenGl_GraduatedTrihedron::renderTickmarkLabels (const Handle(OpenGl_Worksp
const GridAxes& theGridAxes, const GridAxes& theGridAxes,
const Standard_ShortReal theDpix) const const Standard_ShortReal theDpix) const
{ {
const Graphic3d_AxisAspect& aCurAspect = myData.AxisAspect (theIndex); const Graphic3d_GraduatedTrihedron::AxisAspect& aCurAspect = myData.AxisAspectAt (theIndex);
if (!aCurAspect.ToDrawName() && !aCurAspect.ToDrawValues()) if (!aCurAspect.ToDrawName() && !aCurAspect.ToDrawValues())
{ {
return; return;
@ -566,9 +566,8 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace)& theWorks
OpenGl_Vec3 anOldMin = myMin; OpenGl_Vec3 anOldMin = myMin;
OpenGl_Vec3 anOldMax = myMax; OpenGl_Vec3 anOldMax = myMax;
if (myData.CubicAxesCallback) if (myData.CubicAxesCallback(theWorkspace->View()))
{ {
myData.CubicAxesCallback (myData.PtrView);
if (!myAxes[0].Line.IsInitialized() if (!myAxes[0].Line.IsInitialized()
|| !myAxes[1].Line.IsInitialized() || !myAxes[1].Line.IsInitialized()
|| !myAxes[2].Line.IsInitialized() || !myAxes[2].Line.IsInitialized()
@ -719,7 +718,7 @@ void OpenGl_GraduatedTrihedron::SetMinMax (const OpenGl_Vec3& theMin, const Open
// method : OpenGl_GraduatedTrihedron::Axis constructor // method : OpenGl_GraduatedTrihedron::Axis constructor
// purpose : // purpose :
// ======================================================================= // =======================================================================
OpenGl_GraduatedTrihedron::Axis::Axis (const Graphic3d_AxisAspect& theAspect, OpenGl_GraduatedTrihedron::Axis::Axis (const Graphic3d_GraduatedTrihedron::AxisAspect& theAspect,
const OpenGl_Vec3& theDirection) const OpenGl_Vec3& theDirection)
: Direction (theDirection), : Direction (theDirection),
Tickmark (NULL), Tickmark (NULL),

View File

@ -81,7 +81,8 @@ private:
public: public:
Axis (const Graphic3d_AxisAspect& theAspect = Graphic3d_AxisAspect(), Axis (const Graphic3d_GraduatedTrihedron::AxisAspect& theAspect =
Graphic3d_GraduatedTrihedron::AxisAspect(),
const OpenGl_Vec3& theDirection = OpenGl_Vec3 (1.0f, 0.0f, 0.0f)); const OpenGl_Vec3& theDirection = OpenGl_Vec3 (1.0f, 0.0f, 0.0f));
~Axis(); ~Axis();

View File

@ -433,8 +433,7 @@ static void SetMinMaxValuesCallback (Graphic3d_CView* theView)
void OpenGl_View::GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) void OpenGl_View::GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData)
{ {
myGTrihedronData = theTrihedronData; myGTrihedronData = theTrihedronData;
myGTrihedronData.PtrView = this; myGTrihedronData.SetCubicAxesCallback (SetMinMaxValuesCallback);
myGTrihedronData.CubicAxesCallback = SetMinMaxValuesCallback;
myGraduatedTrihedron.SetValues (myGTrihedronData); myGraduatedTrihedron.SetValues (myGTrihedronData);
myToShowGradTrihedron = true; myToShowGradTrihedron = true;
} }
@ -445,7 +444,6 @@ void OpenGl_View::GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron&
// ======================================================================= // =======================================================================
void OpenGl_View::GraduatedTrihedronErase() void OpenGl_View::GraduatedTrihedronErase()
{ {
myGTrihedronData.PtrView = NULL;
myGraduatedTrihedron.Release (myWorkspace->GetGlContext().operator->()); myGraduatedTrihedron.Release (myWorkspace->GetGlContext().operator->());
myToShowGradTrihedron = false; myToShowGradTrihedron = false;
} }