Salome HOME
Transaction management in operations modifed.
[modules/gui.git] / src / GLViewer / GLViewer_AspectLine.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_AspectLine.cxx
23 // Created:   26/05/2005 3:17:00 PM
24
25 //================================================================
26 // Class       : GLViewer_AspectLine
27 // Description : Substitution of Prs2d_AspectLine for OpenGL
28 //================================================================
29 #include "GLViewer_AspectLine.h"
30
31 //=======================================================================
32 // Function: GLViewer_AspectLine
33 // Purpose :
34 //=======================================================================
35 GLViewer_AspectLine::GLViewer_AspectLine()
36 {
37     myNColor = QColor( 255, 255, 255 );
38     myHColor = QColor( 0, 255, 255 );
39     mySColor = QColor( 255, 0, 0 );
40
41     myLineWidth = 1.0;
42     myLineType = 0;
43 }
44
45 //=======================================================================
46 // Function: GLViewer_AspectLine
47 // Purpose :
48 //=======================================================================
49 GLViewer_AspectLine::GLViewer_AspectLine( int type, float width )
50 {
51     myNColor = QColor( 255, 255, 255 );
52     myHColor = QColor( 0, 255, 255 );
53     mySColor = QColor( 255, 0, 0 );
54
55     myLineWidth = width;
56     if( type == 1 || type == 0 )
57         myLineType = type;
58     else
59         myLineType = 0;
60 }
61
62 //=======================================================================
63 // Function: ~GLViewer_AspectLine
64 // Purpose :
65 //=======================================================================
66 GLViewer_AspectLine::~GLViewer_AspectLine()
67 {
68 }
69
70 //=======================================================================
71 // Function: setLineColors
72 // Purpose :
73 //=======================================================================
74 void GLViewer_AspectLine::setLineColors( QColor nc, QColor hc, QColor sc )
75 {
76     myNColor = nc;
77     myHColor = hc;
78     mySColor = sc;
79 }
80
81 //=======================================================================
82 // Function: setLineType
83 // Purpose :
84 //=======================================================================
85 int GLViewer_AspectLine::setLineType( const int type )
86 {
87     if( type == 1 || type == 0 )
88     {
89         myLineType = type;
90         return 0;
91     }
92     return 1;
93 }
94
95 //=======================================================================
96 // Function: setLineWidth
97 // Purpose :
98 //=======================================================================
99 int GLViewer_AspectLine::setLineWidth( const float width )
100 {
101     if( width > 0 )
102     {
103         myLineWidth = width;
104         return 0;
105     }
106     return 1;
107 }
108
109 //=======================================================================
110 // Function: getLineColors
111 // Purpose :
112 //=======================================================================
113 void GLViewer_AspectLine::getLineColors( QColor& nc, QColor& hc, QColor& sc ) const
114 {
115     nc = myNColor;
116     hc = myHColor;
117     sc = mySColor;
118 }
119
120 //=======================================================================
121 // Function: getByteCopy
122 // Purpose :
123 //=======================================================================
124 QByteArray GLViewer_AspectLine::getByteCopy() const
125 {
126     int anISize = sizeof( int );
127     int aFSize = sizeof( float );
128     int aNR = myNColor.red(), aNG = myNColor.green(), aNB = myNColor.blue();
129     int aHR = myHColor.red(), aHG = myHColor.green(), aHB = myHColor.blue();
130     int aSR = mySColor.red(), aSG = mySColor.green(), aSB = mySColor.blue();
131
132     QByteArray aResult( anISize * 10 + aFSize );
133
134     int i = 0;
135     
136     char* aPointer = (char*)&aNR;
137     for( i = 0; i < anISize; i++, aPointer++ )
138         aResult[i] = *aPointer;
139     aPointer = (char*)&aNG;
140     for( ; i < 2*anISize; i++, aPointer++ )
141         aResult[i] = *aPointer;
142     aPointer = (char*)&aNB;
143     for( ; i < 3*anISize; i++, aPointer++ )
144         aResult[i] = *aPointer;
145
146     aPointer = (char*)&aHR;
147     for( ; i < 4*anISize; i++, aPointer++ )
148         aResult[i] = *aPointer;
149     aPointer = (char*)&aHG;
150     for( ; i < 5*anISize; i++, aPointer++ )
151         aResult[i] = *aPointer;
152     aPointer = (char*)&aHB;
153     for( ; i < 6*anISize; i++, aPointer++ )
154         aResult[i] = *aPointer;
155
156     aPointer = (char*)&aSR;
157     for( ; i < 7*anISize; i++, aPointer++ )
158         aResult[i] = *aPointer;
159     aPointer = (char*)&aSG;
160     for( ; i < 8*anISize; i++, aPointer++ )
161         aResult[i] = *aPointer;
162     aPointer = (char*)&aSB;
163     for( ; i < 9*anISize; i++, aPointer++ )
164         aResult[i] = *aPointer;
165     
166     aPointer = (char*)&myLineWidth;
167     for( ; i < 9*anISize + aFSize; i++, aPointer++ )
168         aResult[i] = *aPointer;
169
170     aPointer = (char*)&myLineType;
171     for( ; i < 10*anISize + aFSize; i++, aPointer++ )
172         aResult[i] = *aPointer;    
173
174     return aResult;
175 }
176
177 //=======================================================================
178 // Function: fromByteCopy
179 // Purpose :
180 //=======================================================================
181 GLViewer_AspectLine* GLViewer_AspectLine::fromByteCopy( QByteArray theBytes )
182 {
183
184     int anISize = sizeof( int );
185     int aFSize = sizeof( float );
186     int aNR = 0, aNG = 0, aNB = 0;
187     int aHR = 0, aHG = 0, aHB = 0;
188     int aSR = 0, aSG = 0, aSB = 0;
189     int aLineType = 0;
190     float aLineWidth = 0;
191
192     int i = 0;
193
194     char* aPointer = (char*)&aNR;
195     for( i = 0; i < anISize; i++, aPointer++ )
196         *aPointer = theBytes[i];
197     aPointer = (char*)&aNG;
198     for( ; i < 2*anISize; i++, aPointer++ )
199         *aPointer = theBytes[i];
200     aPointer = (char*)&aNB;
201     for( ; i < 3*anISize; i++, aPointer++ )
202         *aPointer = theBytes[i];
203
204     aPointer = (char*)&aHR;
205     for( ; i < 4*anISize; i++, aPointer++ )
206         *aPointer = theBytes[i];
207     aPointer = (char*)&aHG;
208     for( ; i < 5*anISize; i++, aPointer++ )
209         *aPointer = theBytes[i];
210     aPointer = (char*)&aHB;
211     for( ; i < 6*anISize; i++, aPointer++ )
212         *aPointer = theBytes[i];
213
214     aPointer = (char*)&aSR;
215     for( ; i < 7*anISize; i++, aPointer++ )
216         *aPointer = theBytes[i];
217     aPointer = (char*)&aSG;
218     for( ; i < 8*anISize; i++, aPointer++ )
219         *aPointer = theBytes[i];
220     aPointer = (char*)&aSB;
221     for( ; i < 9*anISize; i++, aPointer++ )
222         *aPointer = theBytes[i];
223
224     aPointer = (char*)&aLineWidth;
225     for( ; i < 9*anISize + aFSize; i++, aPointer++ )
226         *aPointer = theBytes[i];
227
228     aPointer = (char*)&aLineType;
229     for( ; i < 10*anISize + aFSize; i++, aPointer++ )
230         *aPointer = theBytes[i];
231
232     GLViewer_AspectLine* anAspect = new GLViewer_AspectLine( aLineType, aLineWidth );
233     anAspect->setLineColors( QColor( aNR, aNG, aNB ), 
234                              QColor( aHR, aHG, aHB ), 
235                              QColor( aSR, aSG, aSB ) );
236     return anAspect;
237 }