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 #include "GLViewer_AspectLine.h"
30 GLViewer_AspectLine::GLViewer_AspectLine()
32 myNColor = QColor( 255, 255, 255 );
33 myHColor = QColor( 0, 255, 255 );
34 mySColor = QColor( 255, 0, 0 );
42 \param type: 0 for normal line and 1 for strip line
43 \param width - width of line
45 GLViewer_AspectLine::GLViewer_AspectLine( int type, float width )
47 myNColor = QColor( 255, 255, 255 );
48 myHColor = QColor( 0, 255, 255 );
49 mySColor = QColor( 255, 0, 0 );
52 if( type == 1 || type == 0 )
61 GLViewer_AspectLine::~GLViewer_AspectLine()
67 \param nc - normal color
68 \param hc - hilighting color
69 \param sc - selection color
71 void GLViewer_AspectLine::setLineColors( QColor nc, QColor hc, QColor sc )
80 \param type: 0 for normal line and 1 for strip line
82 int GLViewer_AspectLine::setLineType( const int type )
84 if( type == 1 || type == 0 )
94 \param width - new width of line
96 int GLViewer_AspectLine::setLineWidth( const float width )
107 \return colors of line
108 \param nc - variable for normal color
109 \param hc - variable for hilighting color
110 \param sc - variable for selection color
112 void GLViewer_AspectLine::getLineColors( QColor& nc, QColor& hc, QColor& sc ) const
120 \return binary representation of line aspect
122 QByteArray GLViewer_AspectLine::getByteCopy() const
124 int anISize = sizeof( int );
125 int aFSize = sizeof( float );
126 int aNR = myNColor.red(), aNG = myNColor.green(), aNB = myNColor.blue();
127 int aHR = myHColor.red(), aHG = myHColor.green(), aHB = myHColor.blue();
128 int aSR = mySColor.red(), aSG = mySColor.green(), aSB = mySColor.blue();
130 QByteArray aResult( anISize * 10 + aFSize );
134 char* aPointer = (char*)&aNR;
135 for( i = 0; i < anISize; i++, aPointer++ )
136 aResult[i] = *aPointer;
137 aPointer = (char*)&aNG;
138 for( ; i < 2*anISize; i++, aPointer++ )
139 aResult[i] = *aPointer;
140 aPointer = (char*)&aNB;
141 for( ; i < 3*anISize; i++, aPointer++ )
142 aResult[i] = *aPointer;
144 aPointer = (char*)&aHR;
145 for( ; i < 4*anISize; i++, aPointer++ )
146 aResult[i] = *aPointer;
147 aPointer = (char*)&aHG;
148 for( ; i < 5*anISize; i++, aPointer++ )
149 aResult[i] = *aPointer;
150 aPointer = (char*)&aHB;
151 for( ; i < 6*anISize; i++, aPointer++ )
152 aResult[i] = *aPointer;
154 aPointer = (char*)&aSR;
155 for( ; i < 7*anISize; i++, aPointer++ )
156 aResult[i] = *aPointer;
157 aPointer = (char*)&aSG;
158 for( ; i < 8*anISize; i++, aPointer++ )
159 aResult[i] = *aPointer;
160 aPointer = (char*)&aSB;
161 for( ; i < 9*anISize; i++, aPointer++ )
162 aResult[i] = *aPointer;
164 aPointer = (char*)&myLineWidth;
165 for( ; i < 9*anISize + aFSize; i++, aPointer++ )
166 aResult[i] = *aPointer;
168 aPointer = (char*)&myLineType;
169 for( ; i < 10*anISize + aFSize; i++, aPointer++ )
170 aResult[i] = *aPointer;
176 Sets line aspect from binary representation
178 GLViewer_AspectLine* GLViewer_AspectLine::fromByteCopy( QByteArray theBytes )
181 int anISize = sizeof( int );
182 int aFSize = sizeof( float );
183 int aNR = 0, aNG = 0, aNB = 0;
184 int aHR = 0, aHG = 0, aHB = 0;
185 int aSR = 0, aSG = 0, aSB = 0;
187 float aLineWidth = 0;
191 char* aPointer = (char*)&aNR;
192 for( i = 0; i < anISize; i++, aPointer++ )
193 *aPointer = theBytes[i];
194 aPointer = (char*)&aNG;
195 for( ; i < 2*anISize; i++, aPointer++ )
196 *aPointer = theBytes[i];
197 aPointer = (char*)&aNB;
198 for( ; i < 3*anISize; i++, aPointer++ )
199 *aPointer = theBytes[i];
201 aPointer = (char*)&aHR;
202 for( ; i < 4*anISize; i++, aPointer++ )
203 *aPointer = theBytes[i];
204 aPointer = (char*)&aHG;
205 for( ; i < 5*anISize; i++, aPointer++ )
206 *aPointer = theBytes[i];
207 aPointer = (char*)&aHB;
208 for( ; i < 6*anISize; i++, aPointer++ )
209 *aPointer = theBytes[i];
211 aPointer = (char*)&aSR;
212 for( ; i < 7*anISize; i++, aPointer++ )
213 *aPointer = theBytes[i];
214 aPointer = (char*)&aSG;
215 for( ; i < 8*anISize; i++, aPointer++ )
216 *aPointer = theBytes[i];
217 aPointer = (char*)&aSB;
218 for( ; i < 9*anISize; i++, aPointer++ )
219 *aPointer = theBytes[i];
221 aPointer = (char*)&aLineWidth;
222 for( ; i < 9*anISize + aFSize; i++, aPointer++ )
223 *aPointer = theBytes[i];
225 aPointer = (char*)&aLineType;
226 for( ; i < 10*anISize + aFSize; i++, aPointer++ )
227 *aPointer = theBytes[i];
229 GLViewer_AspectLine* anAspect = new GLViewer_AspectLine( aLineType, aLineWidth );
230 anAspect->setLineColors( QColor( aNR, aNG, aNB ),
231 QColor( aHR, aHG, aHB ),
232 QColor( aSR, aSG, aSB ) );