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