1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
23 // Author : OPEN CASCADE
24 // File: GLViewer_AspectLine.cxx
25 // Created: 26/05/2005 3:17:00 PM
27 #include "GLViewer_AspectLine.h"
32 GLViewer_AspectLine::GLViewer_AspectLine()
34 myNColor = QColor( 255, 255, 255 );
35 myHColor = QColor( 0, 255, 255 );
36 mySColor = QColor( 255, 0, 0 );
44 \param type: 0 for normal line and 1 for strip line
45 \param width - width of line
47 GLViewer_AspectLine::GLViewer_AspectLine( int type, float width )
49 myNColor = QColor( 255, 255, 255 );
50 myHColor = QColor( 0, 255, 255 );
51 mySColor = QColor( 255, 0, 0 );
54 if( type == 1 || type == 0 )
63 GLViewer_AspectLine::~GLViewer_AspectLine()
69 \param nc - normal color
70 \param hc - hilighting color
71 \param sc - selection color
73 void GLViewer_AspectLine::setLineColors( QColor nc, QColor hc, QColor sc )
82 \param type: 0 for normal line and 1 for strip line
84 int GLViewer_AspectLine::setLineType( const int type )
86 if( type == 1 || type == 0 )
96 \param width - new width of line
98 int GLViewer_AspectLine::setLineWidth( const float width )
109 \return colors of line
110 \param nc - variable for normal color
111 \param hc - variable for hilighting color
112 \param sc - variable for selection color
114 void GLViewer_AspectLine::getLineColors( QColor& nc, QColor& hc, QColor& sc ) const
122 \return binary representation of line aspect
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();
133 aResult.resize( anISize * 10 + aFSize );
137 char* aPointer = (char*)&aNR;
138 for( i = 0; i < anISize; i++, aPointer++ )
139 aResult[i] = *aPointer;
140 aPointer = (char*)&aNG;
141 for( ; i < 2*anISize; i++, aPointer++ )
142 aResult[i] = *aPointer;
143 aPointer = (char*)&aNB;
144 for( ; i < 3*anISize; i++, aPointer++ )
145 aResult[i] = *aPointer;
147 aPointer = (char*)&aHR;
148 for( ; i < 4*anISize; i++, aPointer++ )
149 aResult[i] = *aPointer;
150 aPointer = (char*)&aHG;
151 for( ; i < 5*anISize; i++, aPointer++ )
152 aResult[i] = *aPointer;
153 aPointer = (char*)&aHB;
154 for( ; i < 6*anISize; i++, aPointer++ )
155 aResult[i] = *aPointer;
157 aPointer = (char*)&aSR;
158 for( ; i < 7*anISize; i++, aPointer++ )
159 aResult[i] = *aPointer;
160 aPointer = (char*)&aSG;
161 for( ; i < 8*anISize; i++, aPointer++ )
162 aResult[i] = *aPointer;
163 aPointer = (char*)&aSB;
164 for( ; i < 9*anISize; i++, aPointer++ )
165 aResult[i] = *aPointer;
167 aPointer = (char*)&myLineWidth;
168 for( ; i < 9*anISize + aFSize; i++, aPointer++ )
169 aResult[i] = *aPointer;
171 aPointer = (char*)&myLineType;
172 for( ; i < 10*anISize + aFSize; i++, aPointer++ )
173 aResult[i] = *aPointer;
179 Sets line aspect from binary representation
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 ) );