1 // File: GLViewer_AspectLine.cxx
2 // Created: 26/05/2005 3:17:00 PM
3 // Author: Alexander BORODIN
4 // Copyright (C) CEA 2005
6 //================================================================
7 // Class : GLViewer_AspectLine
8 // Description : Substitution of Prs2d_AspectLine for OpenGL
9 //================================================================
10 #include "GLViewer_AspectLine.h"
12 //=======================================================================
13 // Function: GLViewer_AspectLine
15 //=======================================================================
16 GLViewer_AspectLine::GLViewer_AspectLine()
18 myNColor = QColor( 255, 255, 255 );
19 myHColor = QColor( 0, 255, 255 );
20 mySColor = QColor( 255, 0, 0 );
26 //=======================================================================
27 // Function: GLViewer_AspectLine
29 //=======================================================================
30 GLViewer_AspectLine::GLViewer_AspectLine( int type, float width )
32 myNColor = QColor( 255, 255, 255 );
33 myHColor = QColor( 0, 255, 255 );
34 mySColor = QColor( 255, 0, 0 );
37 if( type == 1 || type == 0 )
43 //=======================================================================
44 // Function: ~GLViewer_AspectLine
46 //=======================================================================
47 GLViewer_AspectLine::~GLViewer_AspectLine()
51 //=======================================================================
52 // Function: setLineColors
54 //=======================================================================
55 void GLViewer_AspectLine::setLineColors( QColor nc, QColor hc, QColor sc )
62 //=======================================================================
63 // Function: setLineType
65 //=======================================================================
66 int GLViewer_AspectLine::setLineType( const int type )
68 if( type == 1 || type == 0 )
76 //=======================================================================
77 // Function: setLineWidth
79 //=======================================================================
80 int GLViewer_AspectLine::setLineWidth( const float width )
90 //=======================================================================
91 // Function: getLineColors
93 //=======================================================================
94 void GLViewer_AspectLine::getLineColors( QColor& nc, QColor& hc, QColor& sc ) const
101 //=======================================================================
102 // Function: getByteCopy
104 //=======================================================================
105 QByteArray GLViewer_AspectLine::getByteCopy() const
107 int anISize = sizeof( int );
108 int aFSize = sizeof( float );
109 int aNR = myNColor.red(), aNG = myNColor.green(), aNB = myNColor.blue();
110 int aHR = myHColor.red(), aHG = myHColor.green(), aHB = myHColor.blue();
111 int aSR = mySColor.red(), aSG = mySColor.green(), aSB = mySColor.blue();
113 QByteArray aResult( anISize * 10 + aFSize );
117 char* aPointer = (char*)&aNR;
118 for( i = 0; i < anISize; i++, aPointer++ )
119 aResult[i] = *aPointer;
120 aPointer = (char*)&aNG;
121 for( ; i < 2*anISize; i++, aPointer++ )
122 aResult[i] = *aPointer;
123 aPointer = (char*)&aNB;
124 for( ; i < 3*anISize; i++, aPointer++ )
125 aResult[i] = *aPointer;
127 aPointer = (char*)&aHR;
128 for( ; i < 4*anISize; i++, aPointer++ )
129 aResult[i] = *aPointer;
130 aPointer = (char*)&aHG;
131 for( ; i < 5*anISize; i++, aPointer++ )
132 aResult[i] = *aPointer;
133 aPointer = (char*)&aHB;
134 for( ; i < 6*anISize; i++, aPointer++ )
135 aResult[i] = *aPointer;
137 aPointer = (char*)&aSR;
138 for( ; i < 7*anISize; i++, aPointer++ )
139 aResult[i] = *aPointer;
140 aPointer = (char*)&aSG;
141 for( ; i < 8*anISize; i++, aPointer++ )
142 aResult[i] = *aPointer;
143 aPointer = (char*)&aSB;
144 for( ; i < 9*anISize; i++, aPointer++ )
145 aResult[i] = *aPointer;
147 aPointer = (char*)&myLineWidth;
148 for( ; i < 9*anISize + aFSize; i++, aPointer++ )
149 aResult[i] = *aPointer;
151 aPointer = (char*)&myLineType;
152 for( ; i < 10*anISize + aFSize; i++, aPointer++ )
153 aResult[i] = *aPointer;
158 //=======================================================================
159 // Function: fromByteCopy
161 //=======================================================================
162 GLViewer_AspectLine* GLViewer_AspectLine::fromByteCopy( QByteArray theBytes )
165 int anISize = sizeof( int );
166 int aFSize = sizeof( float );
167 int aNR = 0, aNG = 0, aNB = 0;
168 int aHR = 0, aHG = 0, aHB = 0;
169 int aSR = 0, aSG = 0, aSB = 0;
171 float aLineWidth = 0;
175 char* aPointer = (char*)&aNR;
176 for( i = 0; i < anISize; i++, aPointer++ )
177 *aPointer = theBytes[i];
178 aPointer = (char*)&aNG;
179 for( ; i < 2*anISize; i++, aPointer++ )
180 *aPointer = theBytes[i];
181 aPointer = (char*)&aNB;
182 for( ; i < 3*anISize; i++, aPointer++ )
183 *aPointer = theBytes[i];
185 aPointer = (char*)&aHR;
186 for( ; i < 4*anISize; i++, aPointer++ )
187 *aPointer = theBytes[i];
188 aPointer = (char*)&aHG;
189 for( ; i < 5*anISize; i++, aPointer++ )
190 *aPointer = theBytes[i];
191 aPointer = (char*)&aHB;
192 for( ; i < 6*anISize; i++, aPointer++ )
193 *aPointer = theBytes[i];
195 aPointer = (char*)&aSR;
196 for( ; i < 7*anISize; i++, aPointer++ )
197 *aPointer = theBytes[i];
198 aPointer = (char*)&aSG;
199 for( ; i < 8*anISize; i++, aPointer++ )
200 *aPointer = theBytes[i];
201 aPointer = (char*)&aSB;
202 for( ; i < 9*anISize; i++, aPointer++ )
203 *aPointer = theBytes[i];
205 aPointer = (char*)&aLineWidth;
206 for( ; i < 9*anISize + aFSize; i++, aPointer++ )
207 *aPointer = theBytes[i];
209 aPointer = (char*)&aLineType;
210 for( ; i < 10*anISize + aFSize; i++, aPointer++ )
211 *aPointer = theBytes[i];
213 GLViewer_AspectLine* anAspect = new GLViewer_AspectLine( aLineType, aLineWidth );
214 anAspect->setLineColors( QColor( aNR, aNG, aNB ),
215 QColor( aHR, aHG, aHB ),
216 QColor( aSR, aSG, aSB ) );