Salome HOME
new files added
[modules/gui.git] / src / GLViewer / GLViewer_AspectLine.cxx
1 /***************************************************************************
2 **  Class:   GLViewer_AspectLine
3 **  Descr:   Substitution of Prs2d_AspectLine for OpenGL
4 **  Module:  GLViewer
5 **  Created: UI team, 05.11.02
6 ****************************************************************************/
7
8 //#include <GLViewerAfx.h>
9 #include "GLViewer_AspectLine.h"
10
11 GLViewer_AspectLine::GLViewer_AspectLine()
12 {
13     myNColor = QColor( 255, 255, 255 );
14     myHColor = QColor( 0, 255, 255 );
15     mySColor = QColor( 255, 0, 0 );
16
17     myLineWidth = 1.0;
18     myLineType = 0;
19 }
20
21 GLViewer_AspectLine::GLViewer_AspectLine( int type, float width )
22 {
23     myNColor = QColor( 255, 255, 255 );
24     myHColor = QColor( 0, 255, 255 );
25     mySColor = QColor( 255, 0, 0 );
26
27     myLineWidth = width;
28     if( type == 1 || type == 0 )
29         myLineType = type;
30     else
31         myLineType = 0;
32 }
33
34 GLViewer_AspectLine::~GLViewer_AspectLine()
35 {
36 }
37
38 void GLViewer_AspectLine::setLineColors( QColor nc, QColor hc, QColor sc )
39 {
40     myNColor = nc;
41     myHColor = hc;
42     mySColor = sc;
43 }
44
45 int GLViewer_AspectLine::setLineType( const int type )
46 {
47     if( type == 1 || type == 0 )
48     {
49         myLineType = type;
50         return 0;
51     }
52     return 1;
53 }
54
55 int GLViewer_AspectLine::setLineWidth( const float width )
56 {
57     if( width > 0 )
58     {
59         myLineWidth = width;
60         return 0;
61     }
62     return 1;
63 }
64
65 void GLViewer_AspectLine::getLineColors( QColor& nc, QColor& hc, QColor& sc ) const
66 {
67     nc = myNColor;
68     hc = myHColor;
69     sc = mySColor;
70 }
71
72 QByteArray GLViewer_AspectLine::getByteCopy() const
73 {
74     int anISize = sizeof( int );
75     int aFSize = sizeof( float );
76     int aNR = myNColor.red(), aNG = myNColor.green(), aNB = myNColor.blue();
77     int aHR = myHColor.red(), aHG = myHColor.green(), aHB = myHColor.blue();
78     int aSR = mySColor.red(), aSG = mySColor.green(), aSB = mySColor.blue();
79
80     QByteArray aResult( anISize * 10 + aFSize );
81
82     int i = 0;
83     
84     char* aPointer = (char*)&aNR;
85     for( i = 0; i < anISize; i++, aPointer++ )
86         aResult[i] = *aPointer;
87     aPointer = (char*)&aNG;
88     for( ; i < 2*anISize; i++, aPointer++ )
89         aResult[i] = *aPointer;
90     aPointer = (char*)&aNB;
91     for( ; i < 3*anISize; i++, aPointer++ )
92         aResult[i] = *aPointer;
93
94     aPointer = (char*)&aHR;
95     for( ; i < 4*anISize; i++, aPointer++ )
96         aResult[i] = *aPointer;
97     aPointer = (char*)&aHG;
98     for( ; i < 5*anISize; i++, aPointer++ )
99         aResult[i] = *aPointer;
100     aPointer = (char*)&aHB;
101     for( ; i < 6*anISize; i++, aPointer++ )
102         aResult[i] = *aPointer;
103
104     aPointer = (char*)&aSR;
105     for( ; i < 7*anISize; i++, aPointer++ )
106         aResult[i] = *aPointer;
107     aPointer = (char*)&aSG;
108     for( ; i < 8*anISize; i++, aPointer++ )
109         aResult[i] = *aPointer;
110     aPointer = (char*)&aSB;
111     for( ; i < 9*anISize; i++, aPointer++ )
112         aResult[i] = *aPointer;
113     
114     aPointer = (char*)&myLineWidth;
115     for( ; i < 9*anISize + aFSize; i++, aPointer++ )
116         aResult[i] = *aPointer;
117
118     aPointer = (char*)&myLineType;
119     for( ; i < 10*anISize + aFSize; i++, aPointer++ )
120         aResult[i] = *aPointer;    
121
122     return aResult;
123 }
124
125 GLViewer_AspectLine* GLViewer_AspectLine::fromByteCopy( QByteArray theBytes )
126 {
127
128     int anISize = sizeof( int );
129     int aFSize = sizeof( float );
130     int aNR = 0, aNG = 0, aNB = 0;
131     int aHR = 0, aHG = 0, aHB = 0;
132     int aSR = 0, aSG = 0, aSB = 0;
133     int aLineType = 0;
134     float aLineWidth = 0;
135
136     int i = 0;
137
138     char* aPointer = (char*)&aNR;
139     for( i = 0; i < anISize; i++, aPointer++ )
140         *aPointer = theBytes[i];
141     aPointer = (char*)&aNG;
142     for( ; i < 2*anISize; i++, aPointer++ )
143         *aPointer = theBytes[i];
144     aPointer = (char*)&aNB;
145     for( ; i < 3*anISize; i++, aPointer++ )
146         *aPointer = theBytes[i];
147
148     aPointer = (char*)&aHR;
149     for( ; i < 4*anISize; i++, aPointer++ )
150         *aPointer = theBytes[i];
151     aPointer = (char*)&aHG;
152     for( ; i < 5*anISize; i++, aPointer++ )
153         *aPointer = theBytes[i];
154     aPointer = (char*)&aHB;
155     for( ; i < 6*anISize; i++, aPointer++ )
156         *aPointer = theBytes[i];
157
158     aPointer = (char*)&aSR;
159     for( ; i < 7*anISize; i++, aPointer++ )
160         *aPointer = theBytes[i];
161     aPointer = (char*)&aSG;
162     for( ; i < 8*anISize; i++, aPointer++ )
163         *aPointer = theBytes[i];
164     aPointer = (char*)&aSB;
165     for( ; i < 9*anISize; i++, aPointer++ )
166         *aPointer = theBytes[i];
167
168     aPointer = (char*)&aLineWidth;
169     for( ; i < 9*anISize + aFSize; i++, aPointer++ )
170         *aPointer = theBytes[i];
171
172     aPointer = (char*)&aLineType;
173     for( ; i < 10*anISize + aFSize; i++, aPointer++ )
174         *aPointer = theBytes[i];
175
176     GLViewer_AspectLine* anAspect = new GLViewer_AspectLine( aLineType, aLineWidth );
177     anAspect->setLineColors( QColor( aNR, aNG, aNB ), 
178                              QColor( aHR, aHG, aHB ), 
179                              QColor( aSR, aSG, aSB ) );
180     return anAspect;
181 }