Salome HOME
7fa7155e692ce86cf22a932fbb703d189ca9570b
[modules/gui.git] / src / GLViewer / GLViewer_Compass.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  Author : OPEN CASCADE
24 // File:      GLViewer_Compass.cxx
25 // Created:   November, 2004
26 //
27 #include "GLViewer_Compass.h"
28 #include "GLViewer_Drawer.h"
29
30 /*!
31   Constructor
32   \param color        - a color of compass
33   \param size         - a diameter of compass
34   \param pos          - a position
35   \param WidthTop     - width of wide part of arrow
36   \param WidthBottom  - width of base part of arrow
37   \param HeightTop    - height of arrow header
38   \param HeightBottom - height of arrow cut on bottom
39 */
40 GLViewer_Compass::GLViewer_Compass ( const QColor& color, const int size, const Position pos,
41                                const int WidthTop, const int WidthBottom, const int HeightTop,
42                                const int HeightBottom )
43 {
44     myCol = color;
45     mySize = size;
46     myPos = pos;
47     myArrowWidthTop = WidthTop;
48     myArrowWidthBottom = WidthBottom;
49     myArrowHeightTop = HeightTop;
50     myArrowHeightBottom = HeightBottom;
51     myIsVisible = true;
52     QFont* aFont = new QFont("Times",16);
53     myFont = new GLViewer_TexFont( aFont );
54     isGenereted = false;
55     //myFont->generateTexture();
56 }
57
58 /*!
59   Destructor
60 */
61 GLViewer_Compass::~GLViewer_Compass()
62 {
63     delete myFont;
64 }
65
66 /*!
67   Sets parameters of compass
68   \param color        - a color of compass
69   \param size         - a diameter of compass
70   \param pos          - a position
71 */
72 void GLViewer_Compass::setCompass( const QColor& color, const int size, const Position pos )
73 {
74   myCol = color;
75   mySize = size;
76   myPos = pos;
77 }
78
79 /*!
80   Sets visibility of compass 
81   \param vis - new visibility state
82 */
83 void GLViewer_Compass::setVisible( const bool vis )
84 {
85   myIsVisible = vis;
86 }
87
88 /*!
89   Sets size of compass
90   \param size - new size
91 */
92 void GLViewer_Compass::setSize( const int size )
93 {
94   if( size > 0 )
95     mySize=size;
96 }
97
98 /*!
99   Sets arrow width top
100   \param WidthTop - new arrow width top
101 */
102 void GLViewer_Compass::setArrowWidthTop( const int WidthTop )
103 {
104   if( WidthTop < myArrowWidthBottom || WidthTop > mySize )
105     return;
106   myArrowWidthTop=WidthTop;
107 }
108
109 /*!
110   Sets arrow width bottom
111   \param WidthBot - new arrow width bottom
112 */
113 void GLViewer_Compass::setArrowWidthBottom( const int WidthBot )
114
115   if( WidthBot > myArrowWidthTop || WidthBot < 1 )
116     return;     
117   myArrowWidthBottom=WidthBot;
118 }
119
120 /*!
121   Sets arrow height top
122   \param HeightTop - new arrow height top
123 */
124 void GLViewer_Compass::setArrowHeightTop( const int HeightTop )
125 {
126   if( HeightTop > (2*mySize-myArrowHeightBottom ) || HeightTop < 1 )
127     return;
128   myArrowHeightTop=HeightTop;
129 }
130
131 /*!
132   Sets arrow height bottom
133   \param HeightBot - new arrow height bottom
134 */
135 void GLViewer_Compass::setArrowHeightBottom( const int HeightBot )
136 {
137   if( HeightBot > ( 2*mySize-myArrowHeightTop ) || HeightBot < 1)
138     return;
139   myArrowHeightBottom=HeightBot;
140 }
141
142 /*!
143   \return font of compass
144 */
145 GLViewer_TexFont* GLViewer_Compass::getFont()
146
147     if(!isGenereted) 
148     {
149         myFont->generateTexture();
150         isGenereted = true;
151     }    
152     return myFont;
153 }
154
155 /*!
156   Sets font of compass
157   \param theFont - new font
158 */
159 void GLViewer_Compass::setFont( QFont theFont )
160 {
161     delete myFont;
162     myFont = new GLViewer_TexFont( &theFont );
163