Back to index

salome-gui  6.5.0
GLViewer_AspectLine.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  Author : OPEN CASCADE
00024 // File:      GLViewer_AspectLine.cxx
00025 // Created:   26/05/2005 3:17:00 PM
00026 //
00027 #include "GLViewer_AspectLine.h"
00028 
00032 GLViewer_AspectLine::GLViewer_AspectLine()
00033 {
00034     myNColor = QColor( 255, 255, 255 );
00035     myHColor = QColor( 0, 255, 255 );
00036     mySColor = QColor( 255, 0, 0 );
00037 
00038     myLineWidth = 1.0;
00039     myLineType = 0;
00040 }
00041 
00047 GLViewer_AspectLine::GLViewer_AspectLine( int type, float width )
00048 {
00049     myNColor = QColor( 255, 255, 255 );
00050     myHColor = QColor( 0, 255, 255 );
00051     mySColor = QColor( 255, 0, 0 );
00052 
00053     myLineWidth = width;
00054     if( type == 1 || type == 0 )
00055         myLineType = type;
00056     else
00057         myLineType = 0;
00058 }
00059 
00063 GLViewer_AspectLine::~GLViewer_AspectLine()
00064 {
00065 }
00066 
00073 void GLViewer_AspectLine::setLineColors( QColor nc, QColor hc, QColor sc )
00074 {
00075     myNColor = nc;
00076     myHColor = hc;
00077     mySColor = sc;
00078 }
00079 
00084 int GLViewer_AspectLine::setLineType( const int type )
00085 {
00086     if( type == 1 || type == 0 )
00087     {
00088         myLineType = type;
00089         return 0;
00090     }
00091     return 1;
00092 }
00093 
00098 int GLViewer_AspectLine::setLineWidth( const float width )
00099 {
00100     if( width > 0 )
00101     {
00102         myLineWidth = width;
00103         return 0;
00104     }
00105     return 1;
00106 }
00107 
00114 void GLViewer_AspectLine::getLineColors( QColor& nc, QColor& hc, QColor& sc ) const
00115 {
00116     nc = myNColor;
00117     hc = myHColor;
00118     sc = mySColor;
00119 }
00120 
00124 QByteArray GLViewer_AspectLine::getByteCopy() const
00125 {
00126     int anISize = sizeof( int );
00127     int aFSize = sizeof( float );
00128     int aNR = myNColor.red(), aNG = myNColor.green(), aNB = myNColor.blue();
00129     int aHR = myHColor.red(), aHG = myHColor.green(), aHB = myHColor.blue();
00130     int aSR = mySColor.red(), aSG = mySColor.green(), aSB = mySColor.blue();
00131 
00132     QByteArray aResult;
00133     aResult.resize( anISize * 10 + aFSize );
00134 
00135     int i = 0;
00136     
00137     char* aPointer = (char*)&aNR;
00138     for( i = 0; i < anISize; i++, aPointer++ )
00139         aResult[i] = *aPointer;
00140     aPointer = (char*)&aNG;
00141     for( ; i < 2*anISize; i++, aPointer++ )
00142         aResult[i] = *aPointer;
00143     aPointer = (char*)&aNB;
00144     for( ; i < 3*anISize; i++, aPointer++ )
00145         aResult[i] = *aPointer;
00146 
00147     aPointer = (char*)&aHR;
00148     for( ; i < 4*anISize; i++, aPointer++ )
00149         aResult[i] = *aPointer;
00150     aPointer = (char*)&aHG;
00151     for( ; i < 5*anISize; i++, aPointer++ )
00152         aResult[i] = *aPointer;
00153     aPointer = (char*)&aHB;
00154     for( ; i < 6*anISize; i++, aPointer++ )
00155         aResult[i] = *aPointer;
00156 
00157     aPointer = (char*)&aSR;
00158     for( ; i < 7*anISize; i++, aPointer++ )
00159         aResult[i] = *aPointer;
00160     aPointer = (char*)&aSG;
00161     for( ; i < 8*anISize; i++, aPointer++ )
00162         aResult[i] = *aPointer;
00163     aPointer = (char*)&aSB;
00164     for( ; i < 9*anISize; i++, aPointer++ )
00165         aResult[i] = *aPointer;
00166     
00167     aPointer = (char*)&myLineWidth;
00168     for( ; i < 9*anISize + aFSize; i++, aPointer++ )
00169         aResult[i] = *aPointer;
00170 
00171     aPointer = (char*)&myLineType;
00172     for( ; i < 10*anISize + aFSize; i++, aPointer++ )
00173         aResult[i] = *aPointer;    
00174 
00175     return aResult;
00176 }
00177 
00181 GLViewer_AspectLine* GLViewer_AspectLine::fromByteCopy( QByteArray theBytes )
00182 {
00183 
00184     int anISize = sizeof( int );
00185     int aFSize = sizeof( float );
00186     int aNR = 0, aNG = 0, aNB = 0;
00187     int aHR = 0, aHG = 0, aHB = 0;
00188     int aSR = 0, aSG = 0, aSB = 0;
00189     int aLineType = 0;
00190     float aLineWidth = 0;
00191 
00192     int i = 0;
00193 
00194     char* aPointer = (char*)&aNR;
00195     for( i = 0; i < anISize; i++, aPointer++ )
00196         *aPointer = theBytes[i];
00197     aPointer = (char*)&aNG;
00198     for( ; i < 2*anISize; i++, aPointer++ )
00199         *aPointer = theBytes[i];
00200     aPointer = (char*)&aNB;
00201     for( ; i < 3*anISize; i++, aPointer++ )
00202         *aPointer = theBytes[i];
00203 
00204     aPointer = (char*)&aHR;
00205     for( ; i < 4*anISize; i++, aPointer++ )
00206         *aPointer = theBytes[i];
00207     aPointer = (char*)&aHG;
00208     for( ; i < 5*anISize; i++, aPointer++ )
00209         *aPointer = theBytes[i];
00210     aPointer = (char*)&aHB;
00211     for( ; i < 6*anISize; i++, aPointer++ )
00212         *aPointer = theBytes[i];
00213 
00214     aPointer = (char*)&aSR;
00215     for( ; i < 7*anISize; i++, aPointer++ )
00216         *aPointer = theBytes[i];
00217     aPointer = (char*)&aSG;
00218     for( ; i < 8*anISize; i++, aPointer++ )
00219         *aPointer = theBytes[i];
00220     aPointer = (char*)&aSB;
00221     for( ; i < 9*anISize; i++, aPointer++ )
00222         *aPointer = theBytes[i];
00223 
00224     aPointer = (char*)&aLineWidth;
00225     for( ; i < 9*anISize + aFSize; i++, aPointer++ )
00226         *aPointer = theBytes[i];
00227 
00228     aPointer = (char*)&aLineType;
00229     for( ; i < 10*anISize + aFSize; i++, aPointer++ )
00230         *aPointer = theBytes[i];
00231 
00232     GLViewer_AspectLine* anAspect = new GLViewer_AspectLine( aLineType, aLineWidth );
00233     anAspect->setLineColors( QColor( aNR, aNG, aNB ), 
00234                              QColor( aHR, aHG, aHB ), 
00235                              QColor( aSR, aSG, aSB ) );
00236     return anAspect;
00237 }