0024428: Implementation of LGPL license
[occt.git] / src / Aspect / Aspect.cxx
CommitLineData
b311480e 1// Created by: CAL
2// Copyright (c) 1996-1999 Matra Datavision
973c2be1 3// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
973c2be1 7// This library is free software; you can redistribute it and / or modify it
8// under the terms of the GNU Lesser General Public version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#define XTRACE
17
18#define UNICOD //GG_041196
19// Conformite UNICODE
20
7fd59977 21// Modified 22/12/97 : FMN ; Remplacement getenv par OSD_Environment
22// 27/12/98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
23// JR 02.01.100 : Implicit conversions
7fd59977 24//-Design Implementation des methodes de package
25
26#include <Aspect.hxx>
27#include <Aspect_Units.hxx>
28#include <TCollection_AsciiString.hxx>
29#include <TCollection_ExtendedString.hxx>
30#ifdef UNICOD
31#include <Resource_Unicode.hxx>
32#include <stdlib.h>
33#endif
34
35#include <TColStd_Array2OfReal.hxx>
36#include <OSD_Environment.hxx>
37
38# include <stdio.h>
39
40// Valeurs en cms !
41static Quantity_Length Widths[20] = {
42 84.1, 59.4, 42.0, 29.7, 21.0,
43 14.85, 101.6, 101.6, 86.36, 86.36,
44 71.12, 71.12, 27.94, 27.94, 71.12,
45 86.36, 55.88, 43.18, 27.94, 21.59
46};
47
48static Quantity_Length Heights[20] = {
49 118.9, 84.1, 59.4, 42.0, 29.7,
50 21.0, 363.22, 139.7, 447.04, 139.7,
51 363.22, 111.76, 228.6, 57.15, 101.6,
52 111.76, 86.36, 55.88, 43.18, 27.94
53};
54
55static Standard_CString Fnames[] = {
56 "A0","A1","A2","A3","A4","A5","KL","KS","JL","JS","HL","HS","GL","GS","F","E","D","C","B","A"
57};
58
59#define LOPTIM
60#ifndef LOPTIM
61static TCollection_AsciiString astring;
62static TCollection_ExtendedString estring;
63#else
64static TCollection_AsciiString& _astring() {
65 static TCollection_AsciiString astring;
66return astring;
67}
68#define astring _astring()
69
70static TCollection_ExtendedString& _estring() {
71 static TCollection_ExtendedString estring;
72return estring;
73}
74#define estring _estring()
75#endif // LOPTIM
76
77// Returns size in meters
78Standard_CString Aspect::ValuesOfFOSP (
79 const Aspect_FormatOfSheetPaper aFOSP,
80 Quantity_Length& Width,
81 Quantity_Length& Height) {
82
83Standard_Integer Index = Standard_Integer (aFOSP);
84
85 Width = Quantity_Length (Widths[Index]) CENTIMETER;
86 Height = Quantity_Length (Heights[Index]) CENTIMETER;
87
88 return Fnames[Index];
89}
90
91//=========================================================================
92Standard_CString Aspect::ToCString(const TCollection_ExtendedString &aString) {
93Standard_PCharacter pstring;
94
95#ifdef UNICOD
96 Standard_Integer max_string = 2*aString.Length() + 2;
97 astring = TCollection_AsciiString(max_string,' ');
98 pstring = (Standard_PCharacter)astring.ToCString();
99 estring = aString;
100 Resource_FormatType aType = Resource_Unicode::GetFormat();
101 if( (aType == Resource_EUC) || (aType == Resource_SJIS) ) {
102 Standard_Integer i;
103 Standard_ExtCharacter c;
104 for( i=1 ; i<=aString.Length() ; i++ ) {
105 c = estring.Value(i);
106 if( (c >= 0) && (c <= Standard_ExtCharacter(0x0020)) ) {
107 c = Standard_ExtCharacter(0x3000);
108 estring.SetValue(i,c);
109 } else if( (c > Standard_ExtCharacter(0x0020)) &&
110 (c <= Standard_ExtCharacter(0x007F)) ) {
105aae76 111 c += Standard_ExtCharacter((unsigned short)0xFEE0);
7fd59977 112 estring.SetValue(i,c);
113 }
114 }
115 }
116
117// char *jf = getenv("CSF_JIS_Font");
118// if (((aType == Resource_EUC) || (aType == Resource_SJIS)) && (jf!=((char *)0))) {
119 OSD_Environment aVariable("CSF_JIS_Font");
120 TCollection_AsciiString jf(aVariable.Value());
121 if (((aType == Resource_EUC) || (aType == Resource_SJIS)) && (jf.Length() != 0)) {
122 Standard_PCharacter p;
123
124 Resource_Unicode::ConvertUnicodeToEUC(estring,
125 pstring,
126 max_string);
127 p=(Standard_PCharacter)pstring;
128 while ((*p)!='\0') {
129 *p &= 0x7F ;
130 p++;
131 }
132 }
133 else if( !Resource_Unicode::ConvertUnicodeToFormat(estring,
134 pstring,
135 max_string) )
136 printf(" Aspect::ToCString.BAD string length %d\n",max_string);
137#else
138 if( aString.IsAscii() ) {
139 astring = aString; pstring = astring.ToCString();
140 } else {
141 pstring = (Standard_CString) aString.ToExtString();
142 }
143#endif
144
145 return pstring;
146}
147
148Standard_Boolean Aspect::Inverse (const TColStd_Array2OfReal& aMat, TColStd_Array2OfReal& Result) {
149
150Standard_Integer lr, ur, lc, uc;
151Standard_Integer i, j, k, l;
152
153Standard_Boolean BResult = Standard_False;
154
155 lr = aMat.LowerRow ();
156 ur = aMat.UpperRow ();
157 lc = aMat.LowerCol ();
158 uc = aMat.UpperCol ();
159
160 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) {
161#ifdef TRACE
162 cout << "Inverse () : aMat not a 4x4 matrix" << endl << flush;
163 cout << "Inverse returns False => Error\n" << flush;
164#endif
165 return BResult;
166 }
167
168 lr = Result.LowerRow ();
169 ur = Result.UpperRow ();
170 lc = Result.LowerCol ();
171 uc = Result.UpperCol ();
172
173 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) {
174#ifdef TRACE
175 cout << "Inverse () : Result not a 4x4 matrix" << endl << flush;
176 cout << "Inverse returns False => Error\n" << flush;
177#endif
178 return BResult;
179 }
180
181Standard_Integer ip1;
182
183float a [5][9];
184float amax, p;
185int tperm [5][3];
186int perm = 0;
187
188 for (i=1; i<=4; i++)
189 for (j=1; j<=4; j++) {
190// a [i][j] = aMat (lr + i - 1, lc + j - 1);
191 a [i][j] = (float ) aMat (lr + i - 1, lc + j - 1);
192 if (i == j) Result (lr + i - 1, lc + j - 1) = 1.;
193 else Result (lr + i - 1, lc + j - 1) = 0.;
194 }
195 for (i=1; i<=4; i++)
196 for (j=5; j<=8; j++)
197 if (i == j-4) a [i][j] = 1.;
198 else a [i][j] = 0.;
199
200#ifdef TRACE
201 cout << "Matrice :\n";
202 for (i=1; i<=4; i++) {
203 for (j=1; j<=4; j++)
204 cout << a [i][j] << " ";
205 cout << endl;
206 }
207 cout << flush;
208#endif
209
210 for (i=1; i<=4; i++) {
211 ip1 = i + 1;
212 if (ip1 <= 4) {
213 /* Recherche pivot maximal */
214 l = i;
215// amax = fabs (a [i][i]);
216 amax = (float ) fabs (a [i][i]);
217 for (k=ip1; k<=4; k++) {
218 if (amax < fabs (a [k][i])) {
219 l = k;
220// amax = fabs (a [k][i]);
221 amax = (float ) fabs (a [k][i]);
222 } /* if (amax < abs (a [k][i])) */
223 }
224 /* Permutation eventuelle */
225 if (l != i) {
226#ifdef TRACE
227 cout << "permutation des lignes "
228 << l << " et " << i << "\n" << flush;
229#endif
230 perm ++;
231 tperm [perm][1] = l;
232 tperm [perm][2] = i;
233 for (j=1; j<=4; j++) {
234 p = a [i][j];
235 a [i][j] = a [l][j];
236 a [l][j] = p;
237 }
238 } /* if (l != i) */
239 } /* if (ip1 <= 4) */
240 p = a [i][i];
241 if (p == 0.) {
242#ifdef TRACE
243 cout << "p == 0.\n" << flush;
244 cout << "Inverse returns False => Error\n" << flush;
245#endif
246 return BResult;
247 }
248 /* Substitution */
249 for (j=1; j<=4; j++)
250 a [i][j] = a [i][j]/p;
251 for (k=1; k<=4; k++)
252 if (k != i)
253 for (j=1; j<=4; j++)
254 if (j != i) a [k][j] = a [k][j] - a [k][i]*a [i][j];
255 for (k=1; k<=4; k++)
256 a [k][i] = - a [k][i]/p;
257 a [i][i] = - a [i][i];
258 } /* for (i=1; i<=4; i++) */
259
260 /* Remise en ordre */
261 for (k=perm; k>0; k--) {
262#ifdef TRACE
263 cout << "permutation des colonnes "
264 << tperm[k][1] << " et " << tperm[k][2] << "\n" << flush;
265#endif
266 for (i=1; i<=4; i++) {
267 p = a [i][tperm[k][1]];
268 a [i][tperm[k][1]] = a [i][tperm[k][2]];
269 a [i][tperm[k][2]] = p;
270 }
271 }
272
273 for (i=1; i<=4; i++)
274 for (j=1; j<=4; j++)
275 Result (lr + i - 1, lc + j - 1) = a [i][j];
276
277#ifdef TRACE
278 cout << "Inverse :\n";
279 for (i=lr; i<=ur; i++) {
280 for (j=lc; j<=uc; j++)
281 cout << Result (i, j) << " ";
282 cout << endl;
283 }
284 cout << "Inverse returns True => Ok\n" << flush;
285#endif
286
287 return Standard_True;
288}