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