1 // Copyright (C) 2005 OPEN CASCADE
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.
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.
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
17 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
19 // Author : OPEN CASCADE
22 // File: GLViewer_AspectLine.cxx
23 // Created: 26/05/2005 3:17:00 PM
25 //================================================================
26 // Class : GLViewer_AspectLine
27 // Description : Substitution of Prs2d_AspectLine for OpenGL
28 //================================================================
29 #include "GLViewer_AspectLine.h"
31 //=======================================================================
32 // Function: GLViewer_AspectLine
34 //=======================================================================
35 GLViewer_AspectLine::GLViewer_AspectLine()
37 myNColor = QColor( 255, 255, 255 );
38 myHColor = QColor( 0, 255, 255 );
39 mySColor = QColor( 255, 0, 0 );
45 //=======================================================================
46 // Function: GLViewer_AspectLine
48 //=======================================================================
49 GLViewer_AspectLine::GLViewer_AspectLine( int type, float width )
51 myNColor = QColor( 255, 255, 255 );
52 myHColor = QColor( 0, 255, 255 );
53 mySColor = QColor( 255, 0, 0 );
56 if( type == 1 || type == 0 )
62 //=======================================================================
63 // Function: ~GLViewer_AspectLine
65 //=======================================================================
66 GLViewer_AspectLine::~GLViewer_AspectLine()
70 //=======================================================================
71 // Function: setLineColors
73 //=======================================================================
74 void GLViewer_AspectLine::setLineColors( QColor nc, QColor hc, QColor sc )
81 //=======================================================================
82 // Function: setLineType
84 //=======================================================================
85 int GLViewer_AspectLine::setLineType( const int type )
87 if( type == 1 || type == 0 )
95 //=======================================================================
96 // Function: setLineWidth
98 //=======================================================================
99 int GLViewer_AspectLine::setLineWidth( const float width )
109 //=======================================================================
110 // Function: getLineColors
112 //=======================================================================
113 void GLViewer_AspectLine::getLineColors( QColor& nc, QColor& hc, QColor& sc ) const
120 //=======================================================================
121 // Function: getByteCopy
123 //=======================================================================
124 QByteArray GLViewer_AspectLine::getByteCopy() const
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();
132 QByteArray aResult( anISize * 10 + aFSize );
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;
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;
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;
166 aPointer = (char*)&myLineWidth;
167 for( ; i < 9*anISize + aFSize; i++, aPointer++ )
168 aResult[i] = *aPointer;
170 aPointer = (char*)&myLineType;
171 for( ; i < 10*anISize + aFSize; i++, aPointer++ )
172 aResult[i] = *aPointer;
177 //=======================================================================
178 // Function: fromByteCopy
180 //=======================================================================
181 GLViewer_AspectLine* GLViewer_AspectLine::fromByteCopy( QByteArray theBytes )
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;
190 float aLineWidth = 0;
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];
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];
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];
224 aPointer = (char*)&aLineWidth;
225 for( ; i < 9*anISize + aFSize; i++, aPointer++ )
226 *aPointer = theBytes[i];
228 aPointer = (char*)&aLineType;
229 for( ; i < 10*anISize + aFSize; i++, aPointer++ )
230 *aPointer = theBytes[i];
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 ) );