Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / GLViewer / GLViewer_Compass.cxx
1 //  Copyright (C) 2007-2008  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.
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 //  Author : OPEN CASCADE
23 // File:      GLViewer_Compass.cxx
24 // Created:   November, 2004
25 //
26 #include "GLViewer_Compass.h"
27 #include "GLViewer_Drawer.h"
28
29 /*!
30   Constructor
31   \param color        - a color of compass
32   \param size         - a diameter of compass
33   \param pos          - a position
34   \param WidthTop     - width of wide part of arrow
35   \param WidthBottom  - width of base part of arrow
36   \param HeightTop    - height of arrow header
37   \param HeightBottom - height of arrow cut on bottom
38 */
39 GLViewer_Compass::GLViewer_Compass ( const QColor& color, const int size, const Position pos,
40                                const int WidthTop, const int WidthBottom, const int HeightTop,
41                                const int HeightBottom )
42 {
43     myCol = color;
44     mySize = size;
45     myPos = pos;
46     myArrowWidthTop = WidthTop;
47     myArrowWidthBottom = WidthBottom;
48     myArrowHeightTop = HeightTop;
49     myArrowHeightBottom = HeightBottom;
50     myIsVisible = true;
51     QFont* aFont = new QFont("Times",16);
52     myFont = new GLViewer_TexFont( aFont );
53     isGenereted = false;
54     //myFont->generateTexture();
55 }
56
57 /*!
58   Destructor
59 */
60 GLViewer_Compass::~GLViewer_Compass()
61 {
62     delete myFont;
63 }
64
65 /*!
66   Sets parameters of compass
67   \param color        - a color of compass
68   \param size         - a diameter of compass
69   \param pos          - a position
70 */
71 void GLViewer_Compass::setCompass( const QColor& color, const int size, const Position pos )
72 {
73   myCol = color;
74   mySize = size;
75   myPos = pos;
76 }
77
78 /*!
79   Sets visibility of compass 
80   \param vis - new visibility state
81 */
82 void GLViewer_Compass::setVisible( const bool vis )
83 {
84   myIsVisible = vis;
85 }
86
87 /*!
88   Sets size of compass
89   \param size - new size
90 */
91 void GLViewer_Compass::setSize( const int size )
92 {
93   if( size > 0 )
94     mySize=size;
95 }
96
97 /*!
98   Sets arrow width top
99   \param WidthTop - new arrow width top
100 */
101 void GLViewer_Compass::setArrowWidthTop( const int WidthTop )
102 {
103   if( WidthTop < myArrowWidthBottom || WidthTop > mySize )
104     return;
105   myArrowWidthTop=WidthTop;
106 }
107
108 /*!
109   Sets arrow width bottom
110   \param WidthBot - new arrow width bottom
111 */
112 void GLViewer_Compass::setArrowWidthBottom( const int WidthBot )
113
114   if( WidthBot > myArrowWidthTop || WidthBot < 1 )
115     return;     
116   myArrowWidthBottom=WidthBot;
117 }
118
119 /*!
120   Sets arrow height top
121   \param HeightTop - new arrow height top
122 */
123 void GLViewer_Compass::setArrowHeightTop( const int HeightTop )
124 {
125   if( HeightTop > (2*mySize-myArrowHeightBottom ) || HeightTop < 1 )
126     return;
127   myArrowHeightTop=HeightTop;
128 }
129
130 /*!
131   Sets arrow height bottom
132   \param HeightBot - new arrow height bottom
133 */
134 void GLViewer_Compass::setArrowHeightBottom( const int HeightBot )
135 {
136   if( HeightBot > ( 2*mySize-myArrowHeightTop ) || HeightBot < 1)
137     return;
138   myArrowHeightBottom=HeightBot;
139 }
140
141 /*!
142   \return font of compass
143 */
144 GLViewer_TexFont* GLViewer_Compass::getFont()
145
146     if(!isGenereted) 
147     {
148         myFont->generateTexture();
149         isGenereted = true;
150     }    
151     return myFont;
152 }
153
154 /*!
155   Sets font of compass
156   \param theFont - new font
157 */
158 void GLViewer_Compass::setFont( QFont theFont )
159 {
160     delete myFont;
161     myFont = new GLViewer_TexFont( &theFont );
162