Salome HOME
PAL10125 - by double click on reference original object becomes selected
[modules/gui.git] / src / GLViewer / GLViewer_AspectLine.cxx
1 // File:      GLViewer_AspectLine.cxx
2 // Created:   26/05/2005 3:17:00 PM
3 // Author:    Alexander BORODIN
4 // Copyright (C) CEA 2005
5
6 //================================================================
7 // Class       : GLViewer_AspectLine
8 // Description : Substitution of Prs2d_AspectLine for OpenGL
9 //================================================================
10 #include "GLViewer_AspectLine.h"
11
12 //=======================================================================
13 // Function: GLViewer_AspectLine
14 // Purpose :
15 //=======================================================================
16 GLViewer_AspectLine::GLViewer_AspectLine()
17 {
18     myNColor = QColor( 255, 255, 255 );
19     myHColor = QColor( 0, 255, 255 );
20     mySColor = QColor( 255, 0, 0 );
21
22     myLineWidth = 1.0;
23     myLineType = 0;
24 }
25
26 //=======================================================================
27 // Function: GLViewer_AspectLine
28 // Purpose :
29 //=======================================================================
30 GLViewer_AspectLine::GLViewer_AspectLine( int type, float width )
31 {
32     myNColor = QColor( 255, 255, 255 );
33     myHColor = QColor( 0, 255, 255 );
34     mySColor = QColor( 255, 0, 0 );
35
36     myLineWidth = width;
37     if( type == 1 || type == 0 )
38         myLineType = type;
39     else
40         myLineType = 0;
41 }
42
43 //=======================================================================
44 // Function: ~GLViewer_AspectLine
45 // Purpose :
46 //=======================================================================
47 GLViewer_AspectLine::~GLViewer_AspectLine()
48 {
49 }
50
51 //=======================================================================
52 // Function: setLineColors
53 // Purpose :
54 //=======================================================================
55 void GLViewer_AspectLine::setLineColors( QColor nc, QColor hc, QColor sc )
56 {
57     myNColor = nc;
58     myHColor = hc;
59     mySColor = sc;
60 }
61
62 //=======================================================================
63 // Function: setLineType
64 // Purpose :
65 //=======================================================================
66 int GLViewer_AspectLine::setLineType( const int type )
67 {
68     if( type == 1 || type == 0 )
69     {
70         myLineType = type;
71         return 0;
72     }
73     return 1;
74 }
75
76 //=======================================================================
77 // Function: setLineWidth
78 // Purpose :
79 //=======================================================================
80 int GLViewer_AspectLine::setLineWidth( const float width )
81 {
82     if( width > 0 )
83     {
84         myLineWidth = width;
85         return 0;
86     }
87     return 1;
88 }
89
90 //=======================================================================
91 // Function: getLineColors
92 // Purpose :
93 //=======================================================================
94 void GLViewer_AspectLine::getLineColors( QColor& nc, QColor& hc, QColor& sc ) const
95 {
96     nc = myNColor;
97     hc = myHColor;
98     sc = mySColor;
99 }
100
101 //=======================================================================
102 // Function: getByteCopy
103 // Purpose :
104 //=======================================================================
105 QByteArray GLViewer_AspectLine::getByteCopy() const
106 {
107     int anISize = sizeof( int );
108     int aFSize = sizeof( float );
109     int aNR = myNColor.red(), aNG = myNColor.green(), aNB = myNColor.blue();
110     int aHR = myHColor.red(), aHG = myHColor.green(), aHB = myHColor.blue();
111     int aSR = mySColor.red(), aSG = mySColor.green(), aSB = mySColor.blue();
112
113     QByteArray aResult( anISize * 10 + aFSize );
114
115     int i = 0;
116     
117     char* aPointer = (char*)&aNR;
118     for( i = 0; i < anISize; i++, aPointer++ )
119         aResult[i] = *aPointer;
120     aPointer = (char*)&aNG;
121     for( ; i < 2*anISize; i++, aPointer++ )
122         aResult[i] = *aPointer;
123     aPointer = (char*)&aNB;
124     for( ; i < 3*anISize; i++, aPointer++ )
125         aResult[i] = *aPointer;
126
127     aPointer = (char*)&aHR;
128     for( ; i < 4*anISize; i++, aPointer++ )
129         aResult[i] = *aPointer;
130     aPointer = (char*)&aHG;
131     for( ; i < 5*anISize; i++, aPointer++ )
132         aResult[i] = *aPointer;
133     aPointer = (char*)&aHB;
134     for( ; i < 6*anISize; i++, aPointer++ )
135         aResult[i] = *aPointer;
136
137     aPointer = (char*)&aSR;
138     for( ; i < 7*anISize; i++, aPointer++ )
139         aResult[i] = *aPointer;
140     aPointer = (char*)&aSG;
141     for( ; i < 8*anISize; i++, aPointer++ )
142         aResult[i] = *aPointer;
143     aPointer = (char*)&aSB;
144     for( ; i < 9*anISize; i++, aPointer++ )
145         aResult[i] = *aPointer;
146     
147     aPointer = (char*)&myLineWidth;
148     for( ; i < 9*anISize + aFSize; i++, aPointer++ )
149         aResult[i] = *aPointer;
150
151     aPointer = (char*)&myLineType;
152     for( ; i < 10*anISize + aFSize; i++, aPointer++ )
153         aResult[i] = *aPointer;    
154
155     return aResult;
156 }
157
158 //=======================================================================
159 // Function: fromByteCopy
160 // Purpose :
161 //=======================================================================
162 GLViewer_AspectLine* GLViewer_AspectLine::fromByteCopy( QByteArray theBytes )
163 {
164
165     int anISize = sizeof( int );
166     int aFSize = sizeof( float );
167     int aNR = 0, aNG = 0, aNB = 0;
168     int aHR = 0, aHG = 0, aHB = 0;
169     int aSR = 0, aSG = 0, aSB = 0;
170     int aLineType = 0;
171     float aLineWidth = 0;
172
173     int i = 0;
174
175     char* aPointer = (char*)&aNR;
176     for( i = 0; i < anISize; i++, aPointer++ )
177         *aPointer = theBytes[i];
178     aPointer = (char*)&aNG;
179     for( ; i < 2*anISize; i++, aPointer++ )
180         *aPointer = theBytes[i];
181     aPointer = (char*)&aNB;
182     for( ; i < 3*anISize; i++, aPointer++ )
183         *aPointer = theBytes[i];
184
185     aPointer = (char*)&aHR;
186     for( ; i < 4*anISize; i++, aPointer++ )
187         *aPointer = theBytes[i];
188     aPointer = (char*)&aHG;
189     for( ; i < 5*anISize; i++, aPointer++ )
190         *aPointer = theBytes[i];
191     aPointer = (char*)&aHB;
192     for( ; i < 6*anISize; i++, aPointer++ )
193         *aPointer = theBytes[i];
194
195     aPointer = (char*)&aSR;
196     for( ; i < 7*anISize; i++, aPointer++ )
197         *aPointer = theBytes[i];
198     aPointer = (char*)&aSG;
199     for( ; i < 8*anISize; i++, aPointer++ )
200         *aPointer = theBytes[i];
201     aPointer = (char*)&aSB;
202     for( ; i < 9*anISize; i++, aPointer++ )
203         *aPointer = theBytes[i];
204
205     aPointer = (char*)&aLineWidth;
206     for( ; i < 9*anISize + aFSize; i++, aPointer++ )
207         *aPointer = theBytes[i];
208
209     aPointer = (char*)&aLineType;
210     for( ; i < 10*anISize + aFSize; i++, aPointer++ )
211         *aPointer = theBytes[i];
212
213     GLViewer_AspectLine* anAspect = new GLViewer_AspectLine( aLineType, aLineWidth );
214     anAspect->setLineColors( QColor( aNR, aNG, aNB ), 
215                              QColor( aHR, aHG, aHB ), 
216                              QColor( aSR, aSG, aSB ) );
217     return anAspect;
218 }