Salome HOME
updated copyright message
[modules/gui.git] / src / GLViewer / GLViewer_AspectLine.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  Author : OPEN CASCADE
24 // File:      GLViewer_AspectLine.cxx
25 // Created:   26/05/2005 3:17:00 PM
26 //
27 #include "GLViewer_AspectLine.h"
28
29 /*!
30   Default constructor
31 */
32 GLViewer_AspectLine::GLViewer_AspectLine()
33 {
34     myNColor = QColor( 255, 255, 255 );
35     myHColor = QColor( 0, 255, 255 );
36     mySColor = QColor( 255, 0, 0 );
37
38     myLineWidth = 1.0;
39     myLineType = 0;
40 }
41
42 /*!
43   Constructor
44   \param type: 0 for normal line and 1 for strip line
45   \param width - width of line
46 */
47 GLViewer_AspectLine::GLViewer_AspectLine( int type, float width )
48 {
49     myNColor = QColor( 255, 255, 255 );
50     myHColor = QColor( 0, 255, 255 );
51     mySColor = QColor( 255, 0, 0 );
52
53     myLineWidth = width;
54     if( type == 1 || type == 0 )
55         myLineType = type;
56     else
57         myLineType = 0;
58 }
59
60 /*!
61   Destructor
62 */
63 GLViewer_AspectLine::~GLViewer_AspectLine()
64 {
65 }
66
67 /*!
68   Sets line color
69   \param nc - normal color
70   \param hc - hilighting color
71   \param sc - selection color
72 */
73 void GLViewer_AspectLine::setLineColors( QColor nc, QColor hc, QColor sc )
74 {
75     myNColor = nc;
76     myHColor = hc;
77     mySColor = sc;
78 }
79
80 /*!
81   Sets type of line
82   \param type: 0 for normal line and 1 for strip line
83 */
84 int GLViewer_AspectLine::setLineType( const int type )
85 {
86     if( type == 1 || type == 0 )
87     {
88         myLineType = type;
89         return 0;
90     }
91     return 1;
92 }
93
94 /*!
95   Sets width of line
96   \param width - new width of line
97 */
98 int GLViewer_AspectLine::setLineWidth( const float width )
99 {
100     if( width > 0 )
101     {
102         myLineWidth = width;
103         return 0;
104     }
105     return 1;
106 }
107
108 /*!
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
113 */
114 void GLViewer_AspectLine::getLineColors( QColor& nc, QColor& hc, QColor& sc ) const
115 {
116     nc = myNColor;
117     hc = myHColor;
118     sc = mySColor;
119 }
120
121 /*!
122   \return binary representation of line aspect
123 */
124 QByteArray GLViewer_AspectLine::getByteCopy() const
125 {
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();
131
132     QByteArray aResult;
133     aResult.resize( anISize * 10 + aFSize );
134
135     int i = 0;
136     
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;
146
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;
156
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;
166     
167     aPointer = (char*)&myLineWidth;
168     for( ; i < 9*anISize + aFSize; i++, aPointer++ )
169         aResult[i] = *aPointer;
170
171     aPointer = (char*)&myLineType;
172     for( ; i < 10*anISize + aFSize; i++, aPointer++ )
173         aResult[i] = *aPointer;    
174
175     return aResult;
176 }
177
178 /*!
179   Sets line aspect from binary representation
180 */
181 GLViewer_AspectLine* GLViewer_AspectLine::fromByteCopy( QByteArray theBytes )
182 {
183
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;
189     int aLineType = 0;
190     float aLineWidth = 0;
191
192     int i = 0;
193
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];
203
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];
213
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];
223
224     aPointer = (char*)&aLineWidth;
225     for( ; i < 9*anISize + aFSize; i++, aPointer++ )
226         *aPointer = theBytes[i];
227
228     aPointer = (char*)&aLineType;
229     for( ; i < 10*anISize + aFSize; i++, aPointer++ )
230         *aPointer = theBytes[i];
231
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 ) );
236     return anAspect;
237 }