0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / XSControl / XSControl_Utils.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
42cf5bc1 14
15#include <BRep_Builder.hxx>
16#include <BRepTools.hxx>
17#include <Interface_HArray1OfHAsciiString.hxx>
7fd59977 18#include <Interface_Macros.hxx>
19#include <Interface_MSG.hxx>
42cf5bc1 20#include <Message.hxx>
21#include <Message_Messenger.hxx>
22#include <Standard_Transient.hxx>
23#include <Standard_TypeMismatch.hxx>
24#include <TCollection_AsciiString.hxx>
25#include <TCollection_ExtendedString.hxx>
26#include <TCollection_HAsciiString.hxx>
27#include <TCollection_HExtendedString.hxx>
28#include <TColStd_HArray1OfTransient.hxx>
7fd59977 29#include <TColStd_HSequenceOfAsciiString.hxx>
30#include <TColStd_HSequenceOfExtendedString.hxx>
42cf5bc1 31#include <TopExp_Explorer.hxx>
7fd59977 32#include <TopoDS.hxx>
7fd59977 33#include <TopoDS_Compound.hxx>
42cf5bc1 34#include <TopoDS_HShape.hxx>
7fd59977 35#include <TopoDS_Iterator.hxx>
42cf5bc1 36#include <TopoDS_Shape.hxx>
37#include <TopoDS_Shell.hxx>
38#include <TopoDS_Wire.hxx>
7fd59977 39#include <Transfer_SimpleBinderOfTransient.hxx>
42cf5bc1 40#include <TransferBRep.hxx>
41#include <TransferBRep_ShapeBinder.hxx>
42#include <TransferBRep_ShapeMapper.hxx>
43#include <XSControl_Utils.hxx>
7fd59977 44
45static TCollection_AsciiString bufasc;
46static TCollection_ExtendedString bufext;
47static const Standard_ExtString voidext = { 0 };
48
49
50 XSControl_Utils::XSControl_Utils () { }
51
52// #########################################################
53// ####### Fonctions de TRACE #######
54
55 void XSControl_Utils::TraceLine (const Standard_CString line) const
56{
57 Handle(Message_Messenger) sout = Message::DefaultMessenger();
58 sout<<line<<endl;
59}
60
61 void XSControl_Utils::TraceLines (const Handle(Standard_Transient)& lines) const
62{
63 Handle(Message_Messenger) sout = Message::DefaultMessenger();
64 Standard_Integer i,nb;
65 DeclareAndCast(TColStd_HSequenceOfHAsciiString,linha,lines);
66 if (!linha.IsNull()) {
67 nb = linha->Length();
68 for (i = 1; i <= nb; i ++)
69 if (!linha->Value(i).IsNull()) sout<<linha->Value(i)->ToCString()<<endl;
70 return;
71 }
72 DeclareAndCast(TColStd_HSequenceOfAsciiString,lina,lines);
73 if (!lina.IsNull()) {
74 nb = lina->Length();
75 for (i = 1; i <= nb; i ++)
76 sout<<lina->Value(i).ToCString()<<endl;
77 return;
78 }
79 DeclareAndCast(TColStd_HSequenceOfHExtendedString,linhe,lines);
80 if (!linhe.IsNull()) {
81 nb = linhe->Length();
82 for (i = 1; i <= nb; i ++)
83 if (!linhe->Value(i).IsNull())
84 sout << linhe->Value(i) << endl;
85 return;
86 }
87 DeclareAndCast(TColStd_HSequenceOfExtendedString,linee,lines);
88 if (!linee.IsNull()) {
89 nb = linee->Length();
90 for (i = 1; i <= nb; i ++)
91 sout << linee->Value(i) << endl;
92 return;
93 }
94 DeclareAndCast(TCollection_HAsciiString,lin1a,lines);
95 if (!lin1a.IsNull()) sout<<lin1a;
96 DeclareAndCast(TCollection_HExtendedString,lin1e,lines);
97 if (!lin1e.IsNull()) sout<<lin1e;
98}
99
100
101// #########################################################
102// ####### TRANSIENT : Quelques acces de base #######
103
104 Standard_Boolean XSControl_Utils::IsKind
105 (const Handle(Standard_Transient)& item, const Handle(Standard_Type)& what) const
106{
107 if (item.IsNull()) return Standard_False;
108 if (what.IsNull()) return Standard_False;
109 return item->IsKind(what);
110}
111
112 Standard_CString XSControl_Utils::TypeName
113 (const Handle(Standard_Transient)& item, const Standard_Boolean nopk) const
114{
115 if (item.IsNull()) return "";
116 DeclareAndCast(Standard_Type,atype,item);
117 if (atype.IsNull()) atype = item->DynamicType();
118 Standard_CString tn = atype->Name();
119 if (!nopk) return tn;
120 for (int i = 0; tn[i] != '\0'; i ++) {
121 if (tn[i] == '_') return &tn[i+1];
122 }
123 return tn;
124}
125
126
127// ####### TRANSIENT : Fonctions de liste #######
128
129 Handle(Standard_Transient) XSControl_Utils::TraValue
130 (const Handle(Standard_Transient)& seqval, const Standard_Integer num) const
131{
132 Handle(Standard_Transient) val;
133 if (num < 1) return val;
134 if (seqval.IsNull()) return val;
135 DeclareAndCast(TColStd_HSequenceOfHAsciiString,seqs,seqval);
136 if (!seqs.IsNull())
137 { if (num <= seqs->Length()) val = seqs->Value(num); return val; }
138 DeclareAndCast(TColStd_HSequenceOfTransient,seqt,seqval);
139 if (!seqt.IsNull())
140 { if (num <= seqt->Length()) val = seqt->Value(num); return val; }
141// Standard_TypeMismatch::Raise("XSControl_Utils::SeqTraValue");
142 return val;
143}
144
145 Handle(TColStd_HSequenceOfTransient) XSControl_Utils::NewSeqTra () const
146 { return new TColStd_HSequenceOfTransient(); }
147
148 void XSControl_Utils::AppendTra
149 (const Handle(TColStd_HSequenceOfTransient)& seqval,
150 const Handle(Standard_Transient)& traval) const
151 { seqval->Append (traval); }
152
153
154// ####### DATES #######
155
156 Standard_CString XSControl_Utils::DateString
157 (const Standard_Integer yy, const Standard_Integer mm,
158 const Standard_Integer dd, const Standard_Integer hh,
159 const Standard_Integer mn, const Standard_Integer ss) const
160{
161 char ladate[50];
162 Interface_MSG::TDate (ladate, yy,mm,dd,hh,mn,ss);
163 bufasc.Clear(); bufasc.AssignCat(ladate);
164 return bufasc.ToCString();
165}
166
167 void XSControl_Utils::DateValues
168 (const Standard_CString text,
169 Standard_Integer& yy, Standard_Integer& mm, Standard_Integer& dd,
170 Standard_Integer& hh, Standard_Integer& mn, Standard_Integer& ss) const
171 { Interface_MSG::NDate (text, yy,mm,dd,hh,mn,ss); }
172
173
174// ##########################################################
175// ####### STRING : Ascii de base #######
176
177 Standard_CString XSControl_Utils::ToCString
178 (const Handle(TCollection_HAsciiString)& strval) const
179 {
180//JR/Hp
181 Standard_CString astr = (Standard_CString ) (strval.IsNull() ? "" : strval->ToCString());
182 return astr ;
183// return (strval.IsNull() ? "" : strval->ToCString());
184 }
185
186 Standard_CString XSControl_Utils::ToCString
187 (const TCollection_AsciiString& strval) const
188 { return strval.ToCString(); }
189
190 Handle(TCollection_HAsciiString) XSControl_Utils::ToHString
191 (const Standard_CString strcon) const
192 { return new TCollection_HAsciiString(strcon); }
193
194 TCollection_AsciiString XSControl_Utils::ToAString
195 (const Standard_CString strcon) const
196 { return TCollection_AsciiString(strcon); }
197
198// ####### STRING : Extended de base #######
199
200 Standard_ExtString XSControl_Utils::ToEString
201 (const Handle(TCollection_HExtendedString)& strval) const
202 { return (strval.IsNull() ? voidext : strval->ToExtString()); }
203
204 Standard_ExtString XSControl_Utils::ToEString
205 (const TCollection_ExtendedString& strval) const
206 { return strval.ToExtString(); }
207
208 Handle(TCollection_HExtendedString) XSControl_Utils::ToHString
209 (const Standard_ExtString strcon) const
210 { return new TCollection_HExtendedString(strcon); }
211
212 TCollection_ExtendedString XSControl_Utils::ToXString
213 (const Standard_ExtString strcon) const
214 { return TCollection_ExtendedString(strcon); }
215
216// ####### STRING : Ascii <-> Extended #######
217
218 Standard_ExtString XSControl_Utils::AsciiToExtended (const Standard_CString str) const
219{
220 bufext.Clear(); bufext = TCollection_ExtendedString (str);
221 return bufext.ToExtString();
222}
223
224 Standard_Boolean XSControl_Utils::IsAscii (const Standard_ExtString str) const
225{
226 bufext.Clear(); bufext.AssignCat (str);
227 return bufext.IsAscii();
228}
229
230 Standard_CString XSControl_Utils::ExtendedToAscii (const Standard_ExtString str) const
231{
232 bufext.Clear(); bufext.AssignCat (str); bufasc.Clear();
233 Standard_Integer i, nb = bufext.Length();
234 for (i = 1; i <= nb; i ++) {
235 int unext = bufext.Value(i);
236 unext = unext & 127;
237 char uncar = char(unext);
238 bufasc.AssignCat (uncar);
239 }
240 return bufasc.ToCString();
241}
242
243// ####### STRING : LISTES #######
244
245 Standard_CString XSControl_Utils::CStrValue
246 (const Handle(Standard_Transient)& list, const Standard_Integer num) const
247{
248 DeclareAndCast(TColStd_HSequenceOfHAsciiString,linha,list);
249 if (!linha.IsNull()) {
250//JR/Hp
251 Standard_CString astr = (Standard_CString )
252 (num > linha->Length() ? "" : linha->Value(num)->ToCString());
253 return astr ;
254// return (num > linha->Length() ? "" : linha->Value(num)->ToCString());
255 }
256
257 DeclareAndCast(TColStd_HSequenceOfAsciiString,lina,list);
258 if (!lina.IsNull()) {
259//JR/Hp
260 Standard_CString astr = (Standard_CString )
261 (num > lina->Length() ? "" : lina->Value(num).ToCString());
262 return astr ;
263// return (num > lina->Length() ? "" : lina->Value(num).ToCString());
264 }
265
266 DeclareAndCast(TColStd_HSequenceOfHExtendedString,linhe,list);
267 if (!linhe.IsNull()) {
268//JR/Hp
269 Standard_CString astr = (Standard_CString )
270 (num > linhe->Length() ? "" : ExtendedToAscii(linhe->Value(num)->ToExtString()));
271 return astr ;
272// return (num > linhe->Length() ? "" : ExtendedToAscii(linhe->Value(num)->ToExtString()));
273 }
274
275 DeclareAndCast(TColStd_HSequenceOfExtendedString,linee,list);
276 if (!linee.IsNull()) {
277//JR/Hp
278 Standard_CString astr = (Standard_CString )
279 (num > linee->Length() ? "" : ExtendedToAscii(linee->Value(num).ToExtString()));
280 return astr ;
281// return (num > linee->Length() ? "" : ExtendedToAscii(linee->Value(num).T
282 }
283
284 DeclareAndCast(TCollection_HAsciiString,lin1a,list);
285 if (!lin1a.IsNull()) return lin1a->ToCString();
286 DeclareAndCast(TCollection_HExtendedString,lin1e,list);
287 if (!lin1e.IsNull()) return ExtendedToAscii(lin1e->ToExtString());
288 return "";
289}
290
291
292 Standard_ExtString XSControl_Utils::EStrValue
293 (const Handle(Standard_Transient)& list, const Standard_Integer num) const
294{
295 DeclareAndCast(TColStd_HSequenceOfHAsciiString,linha,list);
296 if (!linha.IsNull()) return
297 (num > linha->Length() ? voidext : AsciiToExtended(linha->Value(num)->ToCString()));
298
299 DeclareAndCast(TColStd_HSequenceOfAsciiString,lina,list);
300 if (!lina.IsNull())
301 (num > lina->Length() ? voidext : AsciiToExtended(lina->Value(num).ToCString()));
302
303 DeclareAndCast(TColStd_HSequenceOfHExtendedString,linhe,list);
304 if (!linhe.IsNull()) return
305 (num > linhe->Length() ? voidext : linhe->Value(num)->ToExtString());
306
307 DeclareAndCast(TColStd_HSequenceOfExtendedString,linee,list);
308 if (!linee.IsNull()) return
309 (num > linee->Length() ? voidext : linee->Value(num).ToExtString());
310
311 DeclareAndCast(TCollection_HAsciiString,lin1a,list);
312 if (!lin1a.IsNull()) return AsciiToExtended(lin1a->ToCString());
313 DeclareAndCast(TCollection_HExtendedString,lin1e,list);
314 if (!lin1e.IsNull()) return lin1e->ToExtString();
315 return voidext;
316}
317
318 Handle(TColStd_HSequenceOfHAsciiString) XSControl_Utils::NewSeqCStr () const
319 { return new TColStd_HSequenceOfHAsciiString(); }
320
321 void XSControl_Utils::AppendCStr
322 (const Handle(TColStd_HSequenceOfHAsciiString)& seqval,
323 const Standard_CString strval) const
324 { seqval->Append (new TCollection_HAsciiString(strval)); }
325
326 Handle(TColStd_HSequenceOfHExtendedString) XSControl_Utils::NewSeqEStr () const
327 { return new TColStd_HSequenceOfHExtendedString(); }
328
329 void XSControl_Utils::AppendEStr
330 (const Handle(TColStd_HSequenceOfHExtendedString)& seqval,
331 const Standard_ExtString strval) const
332 { seqval->Append (new TCollection_HExtendedString(strval)); }
333
334
335// ##########################################################
336// ####### SHAPES : Acces de base #######
337
338 Standard_Boolean XSControl_Utils::WriteShape
339 (const TopoDS_Shape& shape,
340 const Standard_CString filename) const
341 { return BRepTools::Write (shape,filename); }
342
343 TopoDS_Shape XSControl_Utils::NewShape () const
344 { TopoDS_Shape shape; return shape; }
345
346 Standard_Boolean XSControl_Utils::ReadShape
347 (TopoDS_Shape& shape,
348 const Standard_CString filename) const
349{
350 BRep_Builder B;
351 return BRepTools::Read (shape,filename,B);
352}
353
354 Standard_Boolean XSControl_Utils::IsNullShape (const TopoDS_Shape& shape) const
355 { return shape.IsNull(); }
356
357
358 TopoDS_Shape XSControl_Utils::CompoundFromSeq
359 (const Handle(TopTools_HSequenceOfShape)& seqval) const
360{
361 BRep_Builder B;
362 TopoDS_Compound C;
363 B.MakeCompound(C);
364 Standard_Integer i,n = seqval->Length();
365 for (i = 1; i <= n ; i ++) B.Add(C,seqval->Value(i));
366 return C;
367}
368
369 TopAbs_ShapeEnum XSControl_Utils::ShapeType
370 (const TopoDS_Shape& shape, const Standard_Boolean compound) const
371{
372 if (shape.IsNull()) return TopAbs_SHAPE;
373 TopAbs_ShapeEnum res = shape.ShapeType();
374 if (!compound || res != TopAbs_COMPOUND) return res;
375 res = TopAbs_SHAPE;
376 for (TopoDS_Iterator iter(shape); iter.More(); iter.Next()) {
377 TopoDS_Shape sh = iter.Value();
378 if (sh.IsNull()) continue;
379 TopAbs_ShapeEnum typ = sh.ShapeType();
380 if (typ == TopAbs_COMPOUND) typ = ShapeType (sh,compound);
381 if (res == TopAbs_SHAPE) res = typ;
382// Egalite : OK; Pseudo-Egalite : EDGE/WIRE ou FACE/SHELL
383 else if (res == TopAbs_EDGE && typ == TopAbs_WIRE) res = typ;
384 else if (res == TopAbs_WIRE && typ == TopAbs_EDGE) continue;
385 else if (res == TopAbs_FACE && typ == TopAbs_SHELL) res = typ;
386 else if (res == TopAbs_SHELL && typ == TopAbs_FACE) continue;
387 else if (res != typ) return TopAbs_COMPOUND;
388 }
389 return res;
390}
391
392 TopoDS_Shape XSControl_Utils::SortedCompound
393 (const TopoDS_Shape& shape, const TopAbs_ShapeEnum type,
394 const Standard_Boolean explore, const Standard_Boolean compound) const
395{
396 if (shape.IsNull()) return shape;
397 TopAbs_ShapeEnum typ = shape.ShapeType();
398 TopoDS_Shape sh, sh0;
399 Standard_Integer nb = 0;
400
401// Compound : on le prend, soit tel quel, soit son contenu
402 if (typ == TopAbs_COMPOUND || typ == TopAbs_COMPSOLID) {
403 TopoDS_Compound C;
404 BRep_Builder B;
405 B.MakeCompound (C);
406 for (TopoDS_Iterator it(shape); it.More(); it.Next()) {
407 sh0 = SortedCompound (it.Value(),type,explore,compound);
408 if (sh0.IsNull()) continue;
409 sh = sh0;
410 typ = sh.ShapeType();
411 if (typ == TopAbs_COMPOUND && !compound) {
412 for (TopoDS_Iterator it2 (sh); it2.More(); it2.Next())
413 { nb ++; sh = it2.Value(); B.Add (C, sh); }
414 }
415 else { nb ++; B.Add (C,sh); }
416 }
417 if (nb == 0) C.Nullify();
418 else if (nb == 1) return sh;
419 return C;
420 }
421
422// Egalite : OK; Pseudo-Egalite : EDGE/WIRE ou FACE/SHELL
423 if (typ == type) return shape;
424 if (typ == TopAbs_EDGE && type == TopAbs_WIRE) {
425 BRep_Builder B;
426 TopoDS_Wire W;
427 B.MakeWire (W);
428 B.Add (W,shape); // ne passe pas ! : TopoDS::Edge(shape)
429 return W;
430 }
431 if (typ == TopAbs_FACE && type == TopAbs_SHELL) {
432 BRep_Builder B;
433 TopoDS_Shell S;
434 B.MakeShell (S);
435 B.Add (S,shape); // ne passe pas ! : TopoDS::Face(shape));
ab860031 436 S.Closed (BRep_Tool::IsClosed (S));
7fd59977 437 return S;
438 }
439
440// Le reste : selon exploration
441 if (!explore) {
442 TopoDS_Shape nulsh;
443 return nulsh;
444 }
445
446// Ici, on doit explorer
447// SOLID + mode COMPOUND : reconduire les SHELLs
448 if (typ == TopAbs_SOLID && compound) {
449 TopoDS_Compound C;
450 BRep_Builder B;
451 B.MakeCompound (C);
452 for (TopoDS_Iterator it(shape); it.More(); it.Next()) {
453 sh0 = SortedCompound (it.Value(),type,explore,compound);
454 if (sh0.IsNull()) continue;
455 sh = sh0;
456 nb ++; B.Add (C,sh);
457 }
458 if (nb == 0) C.Nullify();
459 else if (nb == 1) return sh;
460 return C;
461 }
462
463// Exploration classique
464 TopoDS_Compound CC;
465 BRep_Builder BB;
466 BB.MakeCompound(CC);
467 for (TopExp_Explorer expl (shape,type); expl.More(); expl.Next()) {
468 nb ++; sh = expl.Current();
469 BB.Add (CC,sh);
470 }
471 if (nb == 0) CC.Nullify();
472 else if (nb == 1) return sh;
473 return CC;
474}
475
476
477// ####### SHAPES : Liste #######
478
479 TopoDS_Shape XSControl_Utils::ShapeValue
480 (const Handle(TopTools_HSequenceOfShape)& seqval, const Standard_Integer num) const
481{
482 TopoDS_Shape shape;
483 if (seqval.IsNull()) return shape;
484 if (num > 0 && num <= seqval->Length()) shape = seqval->Value(num);
485 return shape;
486}
487
488 Handle(TopTools_HSequenceOfShape) XSControl_Utils::NewSeqShape () const
489 { return new TopTools_HSequenceOfShape(); }
490
491 void XSControl_Utils::AppendShape
492 (const Handle(TopTools_HSequenceOfShape)& seqval, const TopoDS_Shape& shape) const
493 { seqval->Append (shape); }
494
495// ####### SHAPES <-> Transient #######
496
497 Handle(Standard_Transient) XSControl_Utils::ShapeBinder
498 (const TopoDS_Shape& shape, const Standard_Boolean hs) const
499 { if (hs) return new TopoDS_HShape (shape);
500 else return new TransferBRep_ShapeBinder (shape); }
501
502 TopoDS_Shape XSControl_Utils::BinderShape
503 (const Handle(Standard_Transient)& tr) const
504{
505 TopoDS_Shape sh;
506 DeclareAndCast(Transfer_Binder,sb,tr);
507 if (!sb.IsNull()) return TransferBRep::ShapeResult(sb);
508 DeclareAndCast(TransferBRep_ShapeMapper,sm,tr);
509 if (!sm.IsNull()) return sm->Value();
510 DeclareAndCast(TopoDS_HShape,hs,tr);
511 if (!hs.IsNull()) return hs->Shape();
512 return sh;
513}
514
515
516// ##########################################################
517// ####### LISTES : Fonctions Generales #######
518
519 Standard_Integer XSControl_Utils::SeqLength
520 (const Handle(Standard_Transient)& seqval) const
521{
522 if (seqval.IsNull()) return 0;
523 DeclareAndCast(TColStd_HSequenceOfHAsciiString,seqs,seqval);
524 if (!seqs.IsNull()) return seqs->Length();
525 DeclareAndCast(TColStd_HSequenceOfAsciiString,seqa,seqval);
526 if (!seqa.IsNull()) return seqa->Length();
527 DeclareAndCast(TColStd_HSequenceOfHExtendedString,seqe,seqval);
528 if (!seqe.IsNull()) return seqe->Length();
529 DeclareAndCast(TColStd_HSequenceOfHExtendedString,seqx,seqval);
530 if (!seqx.IsNull()) return seqx->Length();
531
532 DeclareAndCast(TColStd_HSequenceOfTransient,seqt,seqval);
533 if (!seqt.IsNull()) return seqt->Length();
534 DeclareAndCast(TopTools_HSequenceOfShape,seqh,seqval);
535 if (!seqh.IsNull()) return seqh->Length();
536 DeclareAndCast(TColStd_HSequenceOfInteger,seqi,seqval);
537 if (!seqi.IsNull()) return seqi->Length();
538// Standard_TypeMismatch::Raise("XSControl_Utils::SeqLength");
539 return 0;
540}
541
542 Handle(Standard_Transient) XSControl_Utils::SeqToArr
543 (const Handle(Standard_Transient)& seqval, const Standard_Integer first) const
544{
545 Standard_Integer i,lng;
546 Handle(Standard_Transient) val;
547 if (seqval.IsNull()) return val;
548 DeclareAndCast(TColStd_HSequenceOfHAsciiString,seqs,seqval);
549 if (!seqs.IsNull()) {
550 lng = seqs->Length();
551 Handle(Interface_HArray1OfHAsciiString) arrs =
552 new Interface_HArray1OfHAsciiString(first,lng-first+1);
553 for (i = 1; i <= lng; i ++) arrs->SetValue (i-first+1,seqs->Value(i));
554 return arrs;
555 }
556 DeclareAndCast(TColStd_HSequenceOfTransient,seqt,seqval);
557 if (!seqt.IsNull()) {
558 lng = seqt->Length();
559 Handle(TColStd_HArray1OfTransient) arrt =
560 new TColStd_HArray1OfTransient(first,lng-first+1);
561 for (i = 1; i <= lng; i ++) arrt->SetValue (i-first+1,seqt->Value(i));
562 return arrt;
563 }
564 Standard_TypeMismatch::Raise("XSControl_Utils::SeqToArr");
565 return val;
566}
567
568
569 Handle(Standard_Transient) XSControl_Utils::ArrToSeq
570 (const Handle(Standard_Transient)& arrval) const
571{
572 Standard_Integer i,first,last;
573 Handle(Standard_Transient) val;
574 if (arrval.IsNull()) return val;
575 DeclareAndCast(Interface_HArray1OfHAsciiString,arrs,arrval);
576 if (!arrs.IsNull()) {
577 first = arrs->Lower();
578 last = arrs->Upper();
579 Handle(TColStd_HSequenceOfHAsciiString) seqs =
580 new TColStd_HSequenceOfHAsciiString();
581 for (i = first; i <= last; i ++) seqs->Append (arrs->Value(i));
582 return seqs;
583 }
584 DeclareAndCast(TColStd_HArray1OfTransient,arrt,arrval);
585 if (!arrt.IsNull()) {
586 first = arrt->Lower();
587 last = arrt->Upper();
588 Handle(TColStd_HSequenceOfTransient) seqt =
589 new TColStd_HSequenceOfTransient();
590 for (i = first; i <= last; i ++) seqt->Append (arrt->Value(i));
591 return seqt;
592 }
593 Standard_TypeMismatch::Raise("XSControl_Utils::ArrToSeq");
594 return val;
595}
596
597
598 Standard_Integer XSControl_Utils::SeqIntValue
599 (const Handle(TColStd_HSequenceOfInteger)& seqval,
600 const Standard_Integer num) const
601{
602 if (seqval.IsNull()) return 0;
603 return seqval->Value(num);
604}