2 // Copyright (c) 1996-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License 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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
18 #define UNICOD //GG_041196
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
24 //-Design Implementation des methodes de package
27 #include <Aspect_Units.hxx>
28 #include <TCollection_AsciiString.hxx>
29 #include <TCollection_ExtendedString.hxx>
31 #include <Resource_Unicode.hxx>
35 #include <TColStd_Array2OfReal.hxx>
36 #include <OSD_Environment.hxx>
41 static 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
48 static 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
55 static Standard_CString Fnames[] = {
56 "A0","A1","A2","A3","A4","A5","KL","KS","JL","JS","HL","HS","GL","GS","F","E","D","C","B","A"
61 static TCollection_AsciiString astring;
62 static TCollection_ExtendedString estring;
64 static TCollection_AsciiString& _astring() {
65 static TCollection_AsciiString astring;
68 #define astring _astring()
70 static TCollection_ExtendedString& _estring() {
71 static TCollection_ExtendedString estring;
74 #define estring _estring()
77 // Returns size in meters
78 Standard_CString Aspect::ValuesOfFOSP (
79 const Aspect_FormatOfSheetPaper aFOSP,
80 Quantity_Length& Width,
81 Quantity_Length& Height) {
83 Standard_Integer Index = Standard_Integer (aFOSP);
85 Width = Quantity_Length (Widths[Index]) CENTIMETER;
86 Height = Quantity_Length (Heights[Index]) CENTIMETER;
91 //=========================================================================
92 Standard_CString Aspect::ToCString(const TCollection_ExtendedString &aString) {
93 Standard_PCharacter pstring;
96 Standard_Integer max_string = 2*aString.Length() + 2;
97 astring = TCollection_AsciiString(max_string,' ');
98 pstring = (Standard_PCharacter)astring.ToCString();
100 Resource_FormatType aType = Resource_Unicode::GetFormat();
101 if( (aType == Resource_EUC) || (aType == Resource_SJIS) ) {
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)) ) {
111 c += Standard_ExtCharacter((unsigned short)0xFEE0);
112 estring.SetValue(i,c);
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;
124 Resource_Unicode::ConvertUnicodeToEUC(estring,
127 p=(Standard_PCharacter)pstring;
133 else if( !Resource_Unicode::ConvertUnicodeToFormat(estring,
136 printf(" Aspect::ToCString.BAD string length %d\n",max_string);
138 if( aString.IsAscii() ) {
139 astring = aString; pstring = astring.ToCString();
141 pstring = (Standard_CString) aString.ToExtString();
148 Standard_Boolean Aspect::Inverse (const TColStd_Array2OfReal& aMat, TColStd_Array2OfReal& Result) {
150 Standard_Integer lr, ur, lc, uc;
151 Standard_Integer i, j, k, l;
153 Standard_Boolean BResult = Standard_False;
155 lr = aMat.LowerRow ();
156 ur = aMat.UpperRow ();
157 lc = aMat.LowerCol ();
158 uc = aMat.UpperCol ();
160 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) {
162 cout << "Inverse () : aMat not a 4x4 matrix" << endl << flush;
163 cout << "Inverse returns False => Error\n" << flush;
168 lr = Result.LowerRow ();
169 ur = Result.UpperRow ();
170 lc = Result.LowerCol ();
171 uc = Result.UpperCol ();
173 if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) {
175 cout << "Inverse () : Result not a 4x4 matrix" << endl << flush;
176 cout << "Inverse returns False => Error\n" << flush;
181 Standard_Integer ip1;
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.;
197 if (i == j-4) a [i][j] = 1.;
201 cout << "Matrice :\n";
202 for (i=1; i<=4; i++) {
204 cout << a [i][j] << " ";
210 for (i=1; i<=4; i++) {
213 /* Recherche pivot maximal */
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])) {
220 // amax = fabs (a [k][i]);
221 amax = (float ) fabs (a [k][i]);
222 } /* if (amax < abs (a [k][i])) */
224 /* Permutation eventuelle */
227 cout << "permutation des lignes "
228 << l << " et " << i << "\n" << flush;
233 for (j=1; j<=4; j++) {
239 } /* if (ip1 <= 4) */
243 cout << "p == 0.\n" << flush;
244 cout << "Inverse returns False => Error\n" << flush;
250 a [i][j] = a [i][j]/p;
254 if (j != i) a [k][j] = a [k][j] - a [k][i]*a [i][j];
256 a [k][i] = - a [k][i]/p;
257 a [i][i] = - a [i][i];
258 } /* for (i=1; i<=4; i++) */
260 /* Remise en ordre */
261 for (k=perm; k>0; k--) {
263 cout << "permutation des colonnes "
264 << tperm[k][1] << " et " << tperm[k][2] << "\n" << flush;
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;
275 Result (lr + i - 1, lc + j - 1) = a [i][j];
278 cout << "Inverse :\n";
279 for (i=lr; i<=ur; i++) {
280 for (j=lc; j<=uc; j++)
281 cout << Result (i, j) << " ";
284 cout << "Inverse returns True => Ok\n" << flush;
287 return Standard_True;