1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // Author : OPEN CASCADE
23 // File: GLViewer_AspectLine.cxx
24 // Created: 26/05/2005 3:17:00 PM
26 #include "GLViewer_AspectLine.h"
31 GLViewer_AspectLine::GLViewer_AspectLine()
33 myNColor = QColor( 255, 255, 255 );
34 myHColor = QColor( 0, 255, 255 );
35 mySColor = QColor( 255, 0, 0 );
43 \param type: 0 for normal line and 1 for strip line
44 \param width - width of line
46 GLViewer_AspectLine::GLViewer_AspectLine( int type, float width )
48 myNColor = QColor( 255, 255, 255 );
49 myHColor = QColor( 0, 255, 255 );
50 mySColor = QColor( 255, 0, 0 );
53 if( type == 1 || type == 0 )
62 GLViewer_AspectLine::~GLViewer_AspectLine()
68 \param nc - normal color
69 \param hc - hilighting color
70 \param sc - selection color
72 void GLViewer_AspectLine::setLineColors( QColor nc, QColor hc, QColor sc )
81 \param type: 0 for normal line and 1 for strip line
83 int GLViewer_AspectLine::setLineType( const int type )
85 if( type == 1 || type == 0 )
95 \param width - new width of line
97 int GLViewer_AspectLine::setLineWidth( const float width )
108 \return colors of line
109 \param nc - variable for normal color
110 \param hc - variable for hilighting color
111 \param sc - variable for selection color
113 void GLViewer_AspectLine::getLineColors( QColor& nc, QColor& hc, QColor& sc ) const
121 \return binary representation of line aspect
123 QByteArray GLViewer_AspectLine::getByteCopy() const
125 int anISize = sizeof( int );
126 int aFSize = sizeof( float );
127 int aNR = myNColor.red(), aNG = myNColor.green(), aNB = myNColor.blue();
128 int aHR = myHColor.red(), aHG = myHColor.green(), aHB = myHColor.blue();
129 int aSR = mySColor.red(), aSG = mySColor.green(), aSB = mySColor.blue();
132 aResult.resize( 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;
178 Sets line aspect from binary representation
180 GLViewer_AspectLine* GLViewer_AspectLine::fromByteCopy( QByteArray theBytes )
183 int anISize = sizeof( int );
184 int aFSize = sizeof( float );
185 int aNR = 0, aNG = 0, aNB = 0;
186 int aHR = 0, aHG = 0, aHB = 0;
187 int aSR = 0, aSG = 0, aSB = 0;
189 float aLineWidth = 0;
193 char* aPointer = (char*)&aNR;
194 for( i = 0; i < anISize; i++, aPointer++ )
195 *aPointer = theBytes[i];
196 aPointer = (char*)&aNG;
197 for( ; i < 2*anISize; i++, aPointer++ )
198 *aPointer = theBytes[i];
199 aPointer = (char*)&aNB;
200 for( ; i < 3*anISize; i++, aPointer++ )
201 *aPointer = theBytes[i];
203 aPointer = (char*)&aHR;
204 for( ; i < 4*anISize; i++, aPointer++ )
205 *aPointer = theBytes[i];
206 aPointer = (char*)&aHG;
207 for( ; i < 5*anISize; i++, aPointer++ )
208 *aPointer = theBytes[i];
209 aPointer = (char*)&aHB;
210 for( ; i < 6*anISize; i++, aPointer++ )
211 *aPointer = theBytes[i];
213 aPointer = (char*)&aSR;
214 for( ; i < 7*anISize; i++, aPointer++ )
215 *aPointer = theBytes[i];
216 aPointer = (char*)&aSG;
217 for( ; i < 8*anISize; i++, aPointer++ )
218 *aPointer = theBytes[i];
219 aPointer = (char*)&aSB;
220 for( ; i < 9*anISize; i++, aPointer++ )
221 *aPointer = theBytes[i];
223 aPointer = (char*)&aLineWidth;
224 for( ; i < 9*anISize + aFSize; i++, aPointer++ )
225 *aPointer = theBytes[i];
227 aPointer = (char*)&aLineType;
228 for( ; i < 10*anISize + aFSize; i++, aPointer++ )
229 *aPointer = theBytes[i];
231 GLViewer_AspectLine* anAspect = new GLViewer_AspectLine( aLineType, aLineWidth );
232 anAspect->setLineColors( QColor( aNR, aNG, aNB ),
233 QColor( aHR, aHG, aHB ),
234 QColor( aSR, aSG, aSB ) );