Test for 0022778: Bug in BRepMesh
[occt.git] / src / XSControl / XSControl_Functions.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18#include <XSControl_Functions.ixx>
19
20#include <XSControl.hxx>
21#include <XSControl_Controller.hxx>
22#include <IFSelect_Profile.hxx>
23#include <IFSelect_Option.hxx>
24#include <MoniTool_TypedValue.hxx>
25#include <Interface_Static.hxx>
26#include <TColStd_HSequenceOfAsciiString.hxx>
27
28#include <XSControl_WorkSession.hxx>
29#include <IFSelect_Act.hxx>
30#include <IFSelect_SessionPilot.hxx>
31#include <IFSelect_Functions.hxx>
32#include <TCollection_HAsciiString.hxx>
33#include <TColStd_HSequenceOfHAsciiString.hxx>
34
35#include <Interface_InterfaceModel.hxx>
36#include <Transfer_TransientProcess.hxx>
37#include <Transfer_FinderProcess.hxx>
38#include <Transfer_Binder.hxx>
39#include <Interface_CheckIterator.hxx>
40#include <IFSelect_CheckCounter.hxx>
41#include <Transfer_TransferIterator.hxx>
42#include <Transfer_IteratorOfProcessForTransient.hxx>
43
44#include <Dico_IteratorOfDictionaryOfInteger.hxx>
45
46//#include <TransferBRep_ShapeBinder.hxx>
47//#include <TransferBRep_ShapeListBinder.hxx>
48//#include <TransferBRep_ShapeMapper.hxx>
49//#include <TransferBRep_OrientedShapeMapper.hxx>
50
51#include <XSControl_TransferWriter.hxx>
52#include <XSControl_TransferReader.hxx>
53#include <TColStd_HSequenceOfTransient.hxx>
54#include <Transfer_ResultFromModel.hxx>
55#include <XSControl_SelectForTransfer.hxx>
56
57#include <Interface_Macros.hxx>
58#include <Message_Messenger.hxx>
59#include <Message.hxx>
60
61// #######################################################################
62// ## ##
63// ## ##
64// ## FUNCTIONS ##
65// ## ##
66// ## ##
67// #######################################################################
68
69
70//=======================================================================
71//function : xinit
72//=======================================================================
73static IFSelect_ReturnStatus XSControl_xinit(const Handle(IFSelect_SessionPilot)& pilot)
74{
75 Standard_Integer argc = pilot->NbWords();
76 const Standard_CString arg1 = pilot->Arg(1);
77 // **** xinit ****
78 if (argc > 1) return (XSControl::Session(pilot)->SelectNorm(arg1) ?
79 IFSelect_RetDone : IFSelect_RetFail);
80 Handle(Message_Messenger) sout = Message::DefaultMessenger();
81 sout<<"Selected Norm:"<<XSControl::Session(pilot)->SelectedNorm()<<endl;
82 return IFSelect_RetVoid;
83}
84
85
86//=======================================================================
87//function : xnorm
88//=======================================================================
89static IFSelect_ReturnStatus XSControl_xnorm(const Handle(IFSelect_SessionPilot)& pilot)
90{
91 Standard_Integer argc = pilot->NbWords();
92 const Standard_CString arg1 = pilot->Arg(1);
93 // **** xnorm ****
94 Handle(XSControl_WorkSession) WS = XSControl::Session(pilot);
95 Handle(XSControl_Controller) control = WS->NormAdaptor();
96 Handle(Message_Messenger) sout = Message::DefaultMessenger();
97 if (argc == 1)
98 sout<<"Current Norm. xnorm newnorm [profile] to change , xnorm ? for the list"<<endl;
99 else sout<<"Current Norm :"<<endl;
100 if (control.IsNull()) sout<<"no norm currently defined"<<endl;
101 else
102 sout<<" Long Name (complete) : "<<control->Name(Standard_False)<<endl
103 << " Short name (resource) : "<<control->Name(Standard_True)<<endl;
104 if (argc == 1) return IFSelect_RetVoid;
105
106 if (arg1[0] == '?') {
107 sout<<"List of available norms"<<endl;
108 Standard_Integer i,nb;
109 Handle(TColStd_HSequenceOfHAsciiString) norms = XSControl_Controller::ListRecorded(-1);
110 nb = norms->Length();
111 sout<<"Short Proper Names (complete names) : "<<nb<<" :";
112 for (i = 1; i <= nb; i ++) sout<<" "<<norms->Value(i)->ToCString();
113 sout<<endl;
114 norms = XSControl_Controller::ListRecorded(1);
115 nb = norms->Length();
116 sout<<"Long Proper Names (resource names) : "<<nb<<" :";
117 for (i = 1; i <= nb; i ++) sout<<" "<<norms->Value(i)->ToCString();
118 sout<<endl;
119 norms = XSControl_Controller::ListRecorded(0);
120 nb = norms->Length();
121 sout<<"All Norm Names (short, long and aliases) "<<nb<<" :";
122 for (i = 1; i <= nb; i ++) sout<<" "<<norms->Value(i)->ToCString();
123 sout<<endl;
124 sout<<"To change, xnorm newnorm"<<endl;
125 return IFSelect_RetVoid;
126 }
127
128 control = XSControl_Controller::Recorded(arg1);
129 if (control.IsNull()) { sout<<" No norm named : "<<arg1<<endl; return IFSelect_RetError; }
130 else {
131 WS->SetController(control);
132 sout<<"new norm : "<<control->Name()<<endl;
133 if (argc > 2) {
134 const Standard_CString arg2 = pilot->Arg(2);
135 if (!control->Profile()->SetCurrent (arg2))
136 sout<<"profile could not be set to "<<arg2<<endl;
137 }
138 sout<<"current profile : "<<control->Profile()->Current()<<endl;
139
140 IFSelect_Activator::SetCurrentAlias (WS->SelectedNorm(Standard_True));
141 return IFSelect_RetDone;
142 }
143 return IFSelect_RetVoid;
144}
145
146
147//=======================================================================
148//function : xprofile
149//=======================================================================
150static IFSelect_ReturnStatus XSControl_xprofile(const Handle(IFSelect_SessionPilot)& pilot)
151{
152 Standard_Integer argc = pilot->NbWords();
153 const Standard_CString arg1 = pilot->Arg(1);
154 // **** xprofile ****
155 Handle(XSControl_WorkSession) WS = XSControl::Session(pilot);
156 Handle(XSControl_Controller) control = WS->NormAdaptor();
157 if (control.IsNull()) return IFSelect_RetFail;
158 Handle(IFSelect_Profile) prof = control->Profile();
159 Handle(Message_Messenger) sout = Message::DefaultMessenger();
160 sout<<"Current Profile : "<<prof->Current().ToCString()<<endl;
161
162 if (argc < 2) {
163 sout<<"xprofile ? for list of profile confs"<<endl
164 << "xprofile . to apply the current profile (after editing)"<<endl
165 << "xprofile profname to select one and apply it"<<endl
166 << "xprofile profname . to record current profile as profname"<<endl
167 <<" (in followings, profname may be replaced by . for current profile)"<<endl
168 << "xprofile profname ? to list its definition"<<endl
169 << "xprofile profname - to clear it completely"<<endl
170 << "xprofile profname optname casename to edit an option of it"<<endl
171 << "xprofile profname - optname to clear an option from it"<<endl;
172 return IFSelect_RetVoid;
173 }
174
175 if (argc == 2) {
176 if (arg1[0] == '?') {
177 Handle(TColStd_HSequenceOfAsciiString) confs = prof->ConfList();
178 Standard_Integer i, nb = confs->Length();
179 sout<<"List of Available Profile Configurations : "<<nb<<" Items"<<endl;
180 for (i = 1; i <= nb; i ++) sout<<confs->Value(i).ToCString()<<endl;
181 return IFSelect_RetVoid;
182 } else if (arg1[0] == '.' && arg1[1] == '\0') {
183 if (!control->ApplyProfile(WS,".")) {
184 sout<<"Applying current profile has failed"<<endl;
185 return IFSelect_RetFail;
186 }
187 return IFSelect_RetDone;
188 } else {
189
190 // Select a Profile
191 if (!control->ApplyProfile(WS,arg1)) {
192 sout<<"Setting "<<arg1<<" as current has failed"<<endl;
193 return IFSelect_RetFail;
194 }
195 sout<<"Setting "<<arg1<<" as current"<<endl;
196 return IFSelect_RetDone;
197 }
198 }
199
200 if (argc == 3) {
201 const Standard_CString arg2 = pilot->Arg(2);
202
203 // List the definition of a profile
204 if (arg2[0] == '?') {
205 Handle(TColStd_HSequenceOfAsciiString) opts, cases;
206 prof->SwitchList (arg1,opts,cases);
207 Standard_Integer i,nb = opts->Length();
208 sout<<"Option -- Case -- ("<<nb<<" switches on configuration "<<arg1<<")"<<endl;
209 for (i = 1; i <= nb; i ++) {
210 sout<<opts->Value(i).ToCString()<<" "<<cases->Value(i).ToCString()<<endl;
211 }
212 return IFSelect_RetVoid;
213
214 // Clear a profile
215 } else if (arg2[0] == '-' && arg2[1] == '\0') {
216 if (!prof->ClearConf(arg1)) {
217 sout<<"Clearing profile "<<arg2<<" has failed"<<endl;
218 return IFSelect_RetFail;
219 }
220 return IFSelect_RetDone;
221
222 // Merge Profile arg2 to arg1
223 } else {
224 if (!prof->HasConf (arg1)) prof->AddConf (arg1);
225 if (!prof->AddFromOtherConf (arg1,arg2)) {
226 sout<<"Merging profile "<<arg2<<" to "<<arg1<<" has failed"<<endl;
227 return IFSelect_RetFail;
228 }
229 return IFSelect_RetDone;
230 }
231 }
232
233 // Editing / Adding a switch in a profile
234 if (argc == 4) {
235 const Standard_CString arg2 = pilot->Arg(2);
236 const Standard_CString arg3 = pilot->Arg(3);
237
238 // Removing a switch
239 if (arg2[0] == '-' && arg2[1] == '\0') {
240 if (!prof->RemoveSwitch (arg1,arg3)) {
241 sout<<"Removing switch on option "<<arg3<<" in profile "<<arg1<<" has failed"<<endl;
242 return IFSelect_RetFail;
243 }
244 sout<<"Edition of profile "<<arg1<<" done. To apply it : xprofile "<<arg1<<endl;
245 return IFSelect_RetDone;
246
247 // Setting a switch
248 } else {
249 if (!prof->AddSwitch (arg1,arg2,arg3)) {
250 sout<<"Setting profile "<<arg1<<" for option "<<arg2<<" to case "<<arg3<<" has failed"<<endl;
251 return IFSelect_RetFail;
252 }
253 sout<<"Edition of profile "<<arg1<<" done. To apply it : xprofile "<<arg1<<endl;
254 return IFSelect_RetDone;
255 }
256 }
257
258 return IFSelect_RetVoid;
259}
260
261
262//=======================================================================
263//function : xoption
264//=======================================================================
265static IFSelect_ReturnStatus XSControl_xoption(const Handle(IFSelect_SessionPilot)& pilot)
266{
267 Standard_Integer argc = pilot->NbWords();
268 const Standard_CString arg1 = pilot->Arg(1);
269 const Standard_CString arg2 = pilot->Arg(2);
270 const Standard_CString arg3 = pilot->Arg(3);
271 // **** xoption ****
272 Handle(XSControl_WorkSession) WS = XSControl::Session(pilot);
273 Handle(XSControl_Controller) control = WS->NormAdaptor();
274 if (control.IsNull()) return IFSelect_RetFail;
275 Handle(IFSelect_Profile) prof = control->Profile();
276 Handle(Message_Messenger) sout = Message::DefaultMessenger();
277 sout<<"Current Profile : "<<prof->Current().ToCString()<<endl;
278
279 if (argc < 2) {
280 sout<<"xoption anopt : query an option"<<endl
281 << "xoption anopt newcase : switch (basic definition)"
282 <<" (but is superseded by current configuration)"<<endl
283 <<"xoption + optname [param] : create an option on a parameter"<<endl
284 <<" (param absent is taken param=optname)"
285 <<"xoption anopt + casename [value] : add a case for a parameter"<<endl
286 <<" (value absent is taken value=casename)"<<endl;
287
288 Handle(TColStd_HSequenceOfAsciiString) optlist = prof->OptionList();
289 Standard_Integer iopt, nbopt = optlist->Length();
290 sout<<"Total : "<<nbopt<<" Options"<<endl;
291 for (iopt = 1; iopt <= nbopt; iopt ++) {
292 TCollection_AsciiString optname = optlist->Value(iopt);
293 Handle(IFSelect_Option) opt = prof->Option (optname.ToCString());
294 sout<<optname.ToCString()<<" : "<<opt->CaseName()<<endl;
295 }
296 return IFSelect_RetVoid;
297 }
298
299 // xoption optname : description
300
301 if (argc == 2) {
302 Handle(IFSelect_Option) opt = prof->Option (arg1);
303 if (opt.IsNull()) { sout<<"Not a recorded Option : "<<arg1<<endl; return IFSelect_RetError; }
304
305 // On va lister les valeurs admises
306 Handle(TColStd_HSequenceOfAsciiString) caselist = opt->ItemList();
307 Standard_Integer icase, nbcase = caselist->Length();
308 Handle(MoniTool_TypedValue) tv = opt->TypedValue();
309 if (tv.IsNull()) sout<<"Option : "<<arg1<<" Type : "<<opt->Type()->Name();
310 else sout<<"Option : "<<arg1<<" TypedValue. Name : "<<tv->Name()<<endl<<" Definition : "<<tv->Definition();
311
312 sout<<endl<<" Current Case (basic) : "<<opt->CaseName()<<" Total : "<<nbcase<<" Cases :"<<endl;
313 for (icase = 1; icase <= nbcase; icase ++) {
314 const TCollection_AsciiString& acase = caselist->Value(icase);
315 sout<<acase.ToCString();
316
317 // Aliases ?
318 Handle(TColStd_HSequenceOfAsciiString) aliases = opt->Aliases(acase.ToCString());
319 Standard_Integer ial, nbal = (aliases.IsNull() ? 0 : aliases->Length());
320 if (nbal > 0) sout<<" - Alias:";
321 for (ial = 1; ial <= nbal; ial ++) sout<<" "<<aliases->Value(ial);
322 if (!tv.IsNull()) {
323 // TypedValue : on peut afficher la valeur
324 Handle(TCollection_HAsciiString) str;
325 opt->Item (acase.ToCString(),str);
326 if (!str.IsNull()) sout<<" - Value:"<<str->ToCString();
327 }
328
329 sout<<endl;
330 }
331 return IFSelect_RetVoid;
332 }
333
334 // xoption + optname [paramname]
335 if (argc >= 3 && arg1[0] == '+' && arg1[1] == '\0') {
336 Standard_CString parname = pilot->Arg(argc-1);
337 Handle(Interface_Static) param = Interface_Static::Static(parname);
338 if (param.IsNull()) { sout<<"No static parameter is named "<<parname<<endl;
339 return IFSelect_RetError; }
340 Handle(IFSelect_Option) opt = new IFSelect_Option(param,arg2);
341 prof->AddOption (opt);
342 return IFSelect_RetDone;
343 }
344
345 // xoption optname + case [val]
346 if (argc >= 4 && arg2[0] == '+' && arg2[1] == '\0') {
347 Handle(IFSelect_Option) opt = prof->Option (arg1);
348 if (opt.IsNull()) { sout<<"Not a recorded Option : "<<arg1<<endl; return IFSelect_RetError; }
349 Handle(MoniTool_TypedValue) tv = opt->TypedValue();
350 if (tv.IsNull()) { sout<<"Option not for a Parameter : "<<arg1<<endl; return IFSelect_RetError; }
351 Standard_CString valname = pilot->Arg(argc-1);
352 if (!opt->AddBasic (arg3,valname)) {
353 sout<<"Option "<<arg1<<" : not an allowed value : "<<valname<<endl;
354 return IFSelect_RetError;
355 }
356 return IFSelect_RetDone;
357 }
358
359 // xoption optname newcase : edition
360 if (argc == 3) {
361 Handle(IFSelect_Option) opt = prof->Option (arg1);
362 if (opt.IsNull()) { sout<<"Not a recorded Option : "<<arg1<<endl; return IFSelect_RetError; }
363 if (!opt->Switch (arg2)) {
364 sout<<"Option : "<<arg1<<" , Not a suitable case : "<<arg2<<endl;
365 return IFSelect_RetFail;
366 }
367 sout<<"Option : "<<arg1<<" switched to case : "<<arg2<<endl;
368 return IFSelect_RetDone;
369 }
370
371
372 return IFSelect_RetVoid;
373}
374
375
376//=======================================================================
377//function : newmodel
378//=======================================================================
379static IFSelect_ReturnStatus XSControl_newmodel(const Handle(IFSelect_SessionPilot)& pilot)
380{
381 // **** newmodel ****
382 if (!XSControl::Session(pilot)->NewModel().IsNull()) return IFSelect_RetDone;
383 Handle(Message_Messenger) sout = Message::DefaultMessenger();
384 sout<<"No new Model produced"<<endl;
385 return IFSelect_RetFail;
386}
387
388
389//=======================================================================
390//function : tpclear
391//=======================================================================
392static IFSelect_ReturnStatus XSControl_tpclear(const Handle(IFSelect_SessionPilot)& pilot)
393{
394 // **** tpclear/twclear ****
395 Standard_Boolean modew = Standard_False;
396 if (pilot->Word(0).Value(2) == 'w') modew = Standard_True;
397 Handle(Transfer_FinderProcess) FP = XSControl::Session(pilot)->MapWriter();
398 Handle(Transfer_TransientProcess) TP = XSControl::Session(pilot)->MapReader();
399 Handle(Message_Messenger) sout = Message::DefaultMessenger();
400 if ( modew) { if(!FP.IsNull()) FP->Clear(); else sout<<"No Transfer Write"<<endl; }
401 else { if(!TP.IsNull()) TP->Clear(); else sout<<"No Transfer Read"<<endl; }
402 return IFSelect_RetDone;
403}
404
405
406//=======================================================================
407//function : tpstat
408//=======================================================================
409static IFSelect_ReturnStatus XSControl_tpstat(const Handle(IFSelect_SessionPilot)& pilot)
410{
411 Standard_Integer argc = pilot->NbWords();
412 const Standard_CString arg1 = pilot->Arg(1);
413 //const Standard_CString arg2 = pilot->Arg(2);
414 Handle(Transfer_TransientProcess) TP= XSControl::Session(pilot)->MapReader();
415 Handle(Message_Messenger) sout = Message::DefaultMessenger();
416 if (TP.IsNull()) { sout<<"No Transfer Read"<<endl; return IFSelect_RetError;}
417 // **** tpstat ****
418
419 Standard_Integer mod1 = -1;
420 Standard_Integer mod2 = 0;
421 // g : general c : check (compte) C (liste) f : fails(compte) F (liste)
422 // resultats racines : n : n0s entites s : status b : binders
423 // t : compte par type r : compte par resultat l : liste(type-resultat)
424 // *n *s *b *t *r *l : idem sur tout
425 // ?n etc.. : idem sur resultats anormaux
426 // ? tout court pour help
427
428 if (argc > 1) {
429 char a2 = arg1[1]; if (a2 == '\0') a2 = '!';
430 switch (arg1[0]) {
431 case 'g' : mod1 = 0; break;
432 case 'c' : mod1 = 4; mod2 = 4; break;
433 case 'C' : mod1 = 4; mod2 = 2; break;
434 case 'f' : mod1 = 5; mod2 = 4; break;
435 case 'F' : mod1 = 5; mod2 = 2; break;
436 case '*' : mod1 = 2; break;
437 case '?' : mod1 = 3; break;
438 default : mod1 = 1; if (argc > 2) mod1 = 2; a2 = arg1[0]; break;
439 }
440 if (mod1 < 1 || mod1 > 3) a2 = '!';
441 switch (a2) {
442 case 'n' : mod2 = 0; break;
443 case 's' : mod2 = 1; break;
444 case 'b' : mod2 = 2; break;
445 case 't' : mod2 = 3; break;
446 case 'r' : mod2 = 4; break;
447 case 'l' : mod2 = 5; break;
448 case 'L' : mod2 = 6; break;
449 case '!' : break;
450 case '?' : mod1 = -1; break;
451 default : mod1 = -2; break;
452 }
453 }
454 // A present help eventuel
455 if (mod1 < -1) sout<<"Unknown Mode"<<endl;
456 if (mod1 < 0) {
457 sout<<"Modes available :\n"
458 <<"g : general c : checks (count) C (list)"<<"\n"
459 <<" f : fails (count) F (list)"<<"\n"
460 <<" n : numbers of transferred entities (on TRANSFER ROOTS)"<<"\n"
461 <<" s : their status (type entity-result , presence checks)"<<"\n"
462 <<" b : detail of binders"<<"\n"
463 <<" t : count per entity type r : per type/status result"<<"\n"
464 <<" l : count per couple type entity/result"<<"\n"
465 <<" L : list per couple type entity/result"<<"\n"
466 <<" *n *s *b *t *r *l *L : idem on ALL recorded items"<<"\n"
467 <<" ?n ?s ?b ?t ... : idem on abnormal items"<<"\n"
468 <<" n select : n applied on a selection idem for s b t r l"<<endl;
469 if (mod1 < -1) return IFSelect_RetError;
470 return IFSelect_RetVoid;
471 }
472
473 if (!TP.IsNull()) {
474 sout<<"TransferRead :";
475 if (TP->Model() != pilot->Session()->Model()) sout<<"Model differs from the session";
476 Handle(TColStd_HSequenceOfTransient) list =
477 IFSelect_Functions::GiveList(pilot->Session(),pilot->CommandPart(2));
478 XSControl_TransferReader::PrintStatsOnList (TP,list,mod1,mod2);
479// TP->PrintStats (1,sout);
480 }
481 else sout<<"TransferRead : not defined"<<endl;
482 return IFSelect_RetVoid;
483}
484
485
486//=======================================================================
487//function : tpent
488//=======================================================================
489static IFSelect_ReturnStatus XSControl_tpent(const Handle(IFSelect_SessionPilot)& pilot)
490{
491 Standard_Integer argc = pilot->NbWords();
492 const Standard_CString arg1 = pilot->Arg(1);
493 Handle(Transfer_TransientProcess) TP= XSControl::Session(pilot)->MapReader();
494 // **** tpent ****
495 Handle(Message_Messenger) sout = Message::DefaultMessenger();
496 if (TP.IsNull()) { sout<<"No Transfer Read"<<endl; return IFSelect_RetError;}
497 Handle(Interface_InterfaceModel) model = TP->Model();
498 if (model.IsNull()) return IFSelect_RetFail;
499
500 if (argc < 2) { sout<<"Give ENTITY NUMBER (IN MODEL TransferProcess)"<<endl; return IFSelect_RetError; }
501 Standard_Integer num = atoi(arg1);
502 if (num <= 0 || num > model->NbEntities()) { sout<<"Number not in [1 - "<<model->NbEntities()<<"]"<<endl; return IFSelect_RetError; }
503 Handle(Standard_Transient) ent = model->Value(num);
504 Standard_Integer index = TP->MapIndex (ent);
505 if (index == 0) sout<<"Entity "<<num<<" not recorded in transfer"<<endl;
506 else XSControl::Session(pilot)->PrintTransferStatus (index,Standard_False,sout);
507 return IFSelect_RetVoid;
508}
509
510
511//=======================================================================
512//function : tpitem
513//=======================================================================
514static IFSelect_ReturnStatus XSControl_tpitem(const Handle(IFSelect_SessionPilot)& pilot)
515{
516 Standard_Integer argc = pilot->NbWords();
517 const Standard_CString arg1 = pilot->Arg(1);
518// **** tpitem/tproot/twitem/twroot ****
519 Handle(Message_Messenger) sout = Message::DefaultMessenger();
520 if (argc < 2) { sout<<"Give ITEM NUMBER (in TransferProcess)"<<endl; return IFSelect_RetError; }
521 Standard_Integer num = atoi(arg1);
522 if (pilot->Word(0).Value(3) == 'r') num = -num;
523 Standard_Boolean modew = Standard_False;
524 if (pilot->Word(0).Value(2) == 'w') modew = Standard_True;
525 Handle(Transfer_Binder) binder;
526 Handle(Transfer_Finder) finder;
527 Handle(Standard_Transient) ent;
528 if (!XSControl::Session(pilot)->PrintTransferStatus(num,modew,sout))
529 sout<<" - Num="<<num<<" incorrect"<<endl;
530 return IFSelect_RetVoid;
531}
532
533
534//=======================================================================
535//function : tpatr
536//=======================================================================
537static IFSelect_ReturnStatus XSControl_tpatr(const Handle(IFSelect_SessionPilot)& /*pilot*/)
538{
539/*skl
540 Standard_Integer argc = pilot->NbWords();
541 const Standard_CString arg1 = pilot->Arg(1);
542 Handle(XSControl_WorkSession) WS = XSControl::Session(pilot);
543 Handle(Transfer_TransientProcess) TP = WS->MapReader();
544
545 Handle(Message_Messenger) sout = Message::DefaultMessenger();
546 // tpatr tout court : liste tous les attributs
547 // tpatr nomatr : sur cet attribut, liste les valeurs par entite
548
549 if (argc < 2) {
550 Handle(Dico_DictionaryOfInteger) list = TP->Attributes();
551 for (Dico_IteratorOfDictionaryOfInteger iter(list); iter.More(); iter.Next()) {
552 TCollection_AsciiString name = iter.Name();
553 Standard_Integer nbatr = iter.Value();
554 Interface_ParamType aty = TP->AttributeType (name.ToCString());
555 sout<<"Name : "<<name<<" Count="<<nbatr<<" Type : ";
556 switch (aty) {
557 case Interface_ParamInteger : sout<<"Integer"; break;
558 case Interface_ParamReal : sout<<"Real"; break;
559 case Interface_ParamIdent : sout<<"Object"; break;
560 case Interface_ParamText : sout<<"String"; break;
561 default : sout<<"(Mixed)";
562 }
563 sout<<endl;
564 }
565 }
566
567 else {
568
569 Standard_Integer num , nb = 0;
570 sout<<"Attribute Name : "<<arg1<<endl;
571 for (num = TP->NextItemWithAttribute(arg1,0); num > 0;
572 num = TP->NextItemWithAttribute(arg1,num)) {
573 nb ++;
574 sout<<"Item "<<num<<" , Entity ";
575 WS->Model()->Print(TP->Mapped(num),sout);
576 Handle(Transfer_Binder) bnd = TP->MapItem (num);
577 Interface_ParamType aty = bnd->AttributeType(arg1);
578 switch (aty) {
579 case Interface_ParamInteger : sout<<" Integer="<<bnd->IntegerAttribute(arg1); break;
580 case Interface_ParamReal : sout<<" Real="<<bnd->RealAttribute(arg1); break;
581 case Interface_ParamIdent : sout<<" Object,Type:"<<bnd->Attribute(arg1)->DynamicType()->Name(); break;
582 case Interface_ParamText : sout<<" String="<<bnd->StringAttribute(arg1);
583 default : sout<<"(none)"; break;
584 }
585 sout<<endl;
586 }
587 sout<<"Attribute Name : "<<arg1<<" on "<<nb<<" Items"<<endl;
588 }
589skl*/
590
591 return IFSelect_RetVoid;
592}
593
594
595//=======================================================================
596//function : trecord
597//=======================================================================
598static IFSelect_ReturnStatus XSControl_trecord(const Handle(IFSelect_SessionPilot)& pilot)
599{
600 Standard_Integer argc = pilot->NbWords();
601 const Standard_CString arg1 = pilot->Arg(1);
602 Handle(Transfer_TransientProcess) TP = XSControl::Session(pilot)->MapReader();
603// **** trecord : TransferReader ****
604 Standard_Boolean tous = (argc == 1);
605 Standard_Integer num = -1;
606 Handle(Interface_InterfaceModel) mdl = XSControl::Session(pilot)->Model();
607 Handle(XSControl_TransferReader) TR = XSControl::Session(pilot)->TransferReader();
608 Handle(Standard_Transient) ent;
609 Handle(Message_Messenger) sout = Message::DefaultMessenger();
610 if (mdl.IsNull() || TR.IsNull() || TP.IsNull())
611 { sout<<" init not done"<<endl; return IFSelect_RetError; }
612 if (!tous) num = atoi(arg1);
613 // Enregistrer les racines
614 if (tous) {
615 Standard_Integer nb = TP->NbRoots();
616 sout<<" Recording "<<nb<<" Roots"<<endl;
617 for (Standard_Integer i = 1; i <= nb; i ++) {
618 ent = TP->Root(i);
619 if (TR->RecordResult (ent)) sout<<" Root n0."<<i<<endl;
620 else sout<<" Root n0."<<i<<" not recorded"<<endl;
621 }
622 } else {
623 if (num < 1 || num > mdl->NbEntities()) sout<<"incorrect number:"<<num<<endl;
624 else if (TR->RecordResult(mdl->Value(num))) sout<<" Entity n0."<<num<<endl;
625 else sout<<" Entity n0."<<num<<" not recorded"<<endl;
626 }
627 return IFSelect_RetDone;
628}
629
630
631//=======================================================================
632//function : trstat
633//=======================================================================
634static IFSelect_ReturnStatus XSControl_trstat(const Handle(IFSelect_SessionPilot)& pilot)
635{
636 Standard_Integer argc = pilot->NbWords();
637 const Standard_CString arg1 = pilot->Arg(1);
638 Handle(Message_Messenger) sout = Message::DefaultMessenger();
639// **** trstat : TransferReader ****
640 Handle(XSControl_TransferReader) TR = XSControl::Session(pilot)->TransferReader();
641 if (TR.IsNull()) { sout<<" init not done"<<endl; return IFSelect_RetError; }
642 Handle(Interface_InterfaceModel) mdl = TR->Model();
643 if (mdl.IsNull()) { sout<<" No model"<<endl; return IFSelect_RetError; }
644 sout<<" Statistics : FileName : "<<TR->FileName()<<endl;
645 if (argc == 1) {
646 // stats generales
647 TR->PrintStats(10,0);
648 } else {
649 // stats unitaires
650 Standard_Integer num = atoi(arg1);
651 if (num < 1 || num > mdl->NbEntities()) { sout<<" incorrect number:"<<arg1<<endl; return IFSelect_RetError; }
652 Handle(Standard_Transient) ent = mdl->Value(num);
653 if (!TR->IsRecorded(ent)) { sout<<" Entity "<<num<<" not recorded"<<endl; return IFSelect_RetError; }
654 Handle(Transfer_ResultFromModel) RM = TR->FinalResult(ent);
655 Handle(TColStd_HSequenceOfTransient) list = TR->CheckedList(ent);
656 Standard_Integer i, nb = list->Length();
657 if (nb > 0) sout<<" Entities implied by Check/Result :"<<nb<<" i.e.:";
658 for (i = 1; i <= nb; i ++) { sout<<" "; mdl->Print(list->Value(i),sout); }
659 sout<<endl;
660 if (RM.IsNull()) { sout<<" no other info"<<endl; return IFSelect_RetVoid; }
661 Interface_CheckIterator chl = RM->CheckList(Standard_False);
662 pilot->Session()->PrintCheckList(chl,Standard_False,IFSelect_EntitiesByItem);
663 }
664 return IFSelect_RetVoid;
665}
666
667
668//=======================================================================
669//function : trbegin
670//=======================================================================
671static IFSelect_ReturnStatus XSControl_trbegin(const Handle(IFSelect_SessionPilot)& pilot)
672{
673 // **** trbegin : TransferReader ****
674 Handle(XSControl_TransferReader) TR = XSControl::Session(pilot)->TransferReader();
675 Standard_Boolean init = TR.IsNull();
676 if (pilot->NbWords() > 1) { if (pilot->Arg(1)[0] == 'i') init = Standard_True; }
677 if (init) {
678 XSControl::Session(pilot)->InitTransferReader (0);
679 TR = XSControl::Session(pilot)->TransferReader();
680 if (TR.IsNull()) {
681 Handle(Message_Messenger) sout = Message::DefaultMessenger();
682 sout<<" init not done or failed"<<endl;
683 return IFSelect_RetError;
684 }
685 }
686 TR->BeginTransfer();
687 return IFSelect_RetDone;
688}
689
690
691//=======================================================================
692//function : tread
693//=======================================================================
694static IFSelect_ReturnStatus XSControl_tread(const Handle(IFSelect_SessionPilot)& pilot)
695{
696 Standard_Integer argc = pilot->NbWords();
697 //const Standard_CString arg1 = pilot->Arg(1);
698 // **** tread : TransferReader ****
699 Handle(Message_Messenger) sout = Message::DefaultMessenger();
700 Handle(XSControl_TransferReader) TR = XSControl::Session(pilot)->TransferReader();
701 if (TR.IsNull()) { sout<<" init not done"<<endl; return IFSelect_RetError; }
702 Handle(Interface_InterfaceModel) mdl = TR->Model();
703 if (mdl.IsNull()) { sout<<" No model"<<endl; return IFSelect_RetError; }
704 if (argc < 2) {
705// DeclareAndCast(IFSelect_Selection,sel,pilot->Session()->NamedItem("xst-model-roots"));
706 Handle(Standard_Transient) sel = pilot->Session()->NamedItem("xst-model-roots");
707 if (sel.IsNull()) { sout<<"Select Roots absent"<<endl; return IFSelect_RetError; }
708 Handle(TColStd_HSequenceOfTransient) list = pilot->Session()->GiveList(sel);
709 sout<<" Transferring all roots i.e. : "<<TR->TransferList(list)<<endl;
710 } else {
711 Handle(TColStd_HSequenceOfTransient) list =
712 IFSelect_Functions::GiveList(pilot->Session(),pilot->CommandPart(1));
713 sout<<" Transfer of "<<list->Length()<<" entities"<<endl;
714 Standard_Integer nb = TR->TransferList(list);
715 sout<<" Gives "<<nb<<" results"<<endl;
716 }
717 return IFSelect_RetDone;
718}
719
720
721//=======================================================================
722//function : trtp
723//=======================================================================
724static IFSelect_ReturnStatus XSControl_trtp(const Handle(IFSelect_SessionPilot)& pilot)
725{
726 // **** TReader -> TProcess ****
727 Handle(XSControl_TransferReader) TR = XSControl::Session(pilot)->TransferReader();
728 Handle(Message_Messenger) sout = Message::DefaultMessenger();
729 if (TR.IsNull()) sout<<" No TransferReader"<<endl;
730 else if (TR->TransientProcess().IsNull()) sout<<" Transfer Reader without Process"<<endl;
731 ////else { XSDRAW::SetTransferProcess(TR->TransientProcess()); return IFSelect_RetDone; }
732 return IFSelect_RetVoid;
733}
734
735
736//=======================================================================
737//function : tptr
738//=======================================================================
739static IFSelect_ReturnStatus XSControl_tptr(const Handle(IFSelect_SessionPilot)& pilot)
740{
741 // **** TProcess -> TReader ****
742 XSControl::Session(pilot)->InitTransferReader (3);
743 return IFSelect_RetDone;
744}
745
746
747//=======================================================================
748//function : twmode
749//=======================================================================
750static IFSelect_ReturnStatus XSControl_twmode(const Handle(IFSelect_SessionPilot)& pilot)
751{
752 Standard_Integer argc = pilot->NbWords();
753 const Standard_CString arg1 = pilot->Arg(1);
754 // **** twmode ****
755 Handle(XSControl_TransferWriter) TW = XSControl::Session(pilot)->TransferWriter();
756 Handle(XSControl_Controller) control = XSControl::Session(pilot)->NormAdaptor();
757 Standard_Integer modemin,modemax;
758 Handle(Message_Messenger) sout = Message::DefaultMessenger();
759 if (control->ModeWriteBounds (modemin,modemax)) {
760 sout<<"Write Mode : allowed values "<<modemin<<" to "<<modemax<<endl;
761 for (Standard_Integer modd = modemin; modd <= modemax; modd ++) {
762 sout<<modd<<" : "<<control->ModeWriteHelp (modd)<<endl;;
763 }
764 }
765 sout<<"Write Mode : actual = "<<TW->TransferMode()<<endl;
766 if (argc <= 1) return IFSelect_RetVoid;
767 Standard_Integer mod = atoi(arg1);
768 sout<<"New value -> "<<arg1<<endl;
769 TW->SetTransferMode(mod);
770 if (!control->IsModeWrite (mod)) sout<<"Warning : this new value is not supported"<<endl;
771 return IFSelect_RetDone;
772}
773
774
775//=======================================================================
776//function : twstat
777//=======================================================================
778static IFSelect_ReturnStatus XSControl_twstat(const Handle(IFSelect_SessionPilot)& pilot)
779{
780 //Standard_Integer argc = pilot->NbWords();
781 //const Standard_CString arg1 = pilot->Arg(1);
782 //const Standard_CString arg2 = pilot->Arg(2);
783 Handle(Transfer_FinderProcess) FP = XSControl::Session(pilot)->MapWriter();
784 // **** twstat ****
785 // Pour Write
786 Handle(Message_Messenger) sout = Message::DefaultMessenger();
787 if (!FP.IsNull()) {
788 sout<<"TransferWrite:";
789 // XSControl_TransferWriter::PrintStatsProcess (FP,mod1,mod2);
790 FP->PrintStats (1,sout);
791 }
792 else sout<<"TransferWrite: not defined"<<endl;
793 return IFSelect_RetVoid;
794}
795
796
797//=======================================================================
798//function : settransfert
799//=======================================================================
800static IFSelect_ReturnStatus XSControl_settransfert(const Handle(IFSelect_SessionPilot)& pilot)
801{
802 // **** SelectForTransfer ****
803 return pilot->RecordItem(new XSControl_SelectForTransfer(XSControl::Session(pilot)->TransferReader()));
804}
805
806
807
808static int initactor = 0;
809
810//=======================================================================
811//function : Init
812//purpose :
813//=======================================================================
814
815void XSControl_Functions::Init ()
816{
817 if (initactor) return; initactor = 1;
818 IFSelect_Act::SetGroup("DE: General");
819
820 IFSelect_Act::AddFunc ("xinit","[norm:string to change norme] reinitialises according to the norm",XSControl_xinit);
821 IFSelect_Act::AddFunc ("xnorm","displays current norm +norm : changes it",XSControl_xnorm);
822 IFSelect_Act::AddFunc ("xprofile","displays current profile +prof : changes it",XSControl_xprofile);
823 IFSelect_Act::AddFunc ("xoption","lists options +opt : lists cases +case : changes current case",XSControl_xoption);
824
825 IFSelect_Act::AddFunc ("newmodel","produces a new empty model, for the session",XSControl_newmodel);
826
827 IFSelect_Act::AddFunc ("tpclear","Clears TransferProcess (READ)",XSControl_tpclear);
828 IFSelect_Act::AddFunc ("twclear","Clears TransferProcess (WRITE)",XSControl_tpclear);
829
830 IFSelect_Act::AddFunc ("tpstat","Statistics on TransferProcess (READ)",XSControl_tpstat);
831
832 IFSelect_Act::AddFunc ("tpent","[num:integer] Statistics on an entity of the model (READ)",XSControl_tpent);
833
834 IFSelect_Act::AddFunc ("tpitem","[num:integer] Statistics on ITEM of transfer (READ)" ,XSControl_tpitem);
835 IFSelect_Act::AddFunc ("tproot","[num:integer] Statistics on a ROOT of transfert (READ)" ,XSControl_tpitem);
836 IFSelect_Act::AddFunc ("twitem","[num:integer] Statistics on an ITEM of transfer (WRITE)" ,XSControl_tpitem);
837 IFSelect_Act::AddFunc ("twroot","[num:integer] Statistics on a ROOT of transfer (WRITE)",XSControl_tpitem);
838 IFSelect_Act::AddFunc ("tpatr","[name] List all Attributes, or values for a Name",XSControl_tpatr);
839
840 IFSelect_Act::AddFunc ("trecord","record : all root results; or num : for entity n0.num",XSControl_trecord);
841 IFSelect_Act::AddFunc ("trstat","general statistics; or num : stats on entity n0 num",XSControl_trstat);
842 IFSelect_Act::AddFunc ("trbegin","begin-transfer-reader [init]",XSControl_trbegin);
843 IFSelect_Act::AddFunc ("tread","transfers all roots, or num|sel|sel num : entity list, by transfer-reader",XSControl_tread);
844
845 IFSelect_Act::AddFunc ("trtp","feeds commands tp... with results from tr...",XSControl_trtp);
846 IFSelect_Act::AddFunc ("tptr","feeds tr... from tp... (may be incomplete)",XSControl_tptr);
847
848 IFSelect_Act::AddFunc ("twmode","displays mode transfer write, + num changes it",XSControl_twmode);
849 IFSelect_Act::AddFunc ("twstat","Statistics on TransferProcess (WRITE)",XSControl_twstat);
850
851 IFSelect_Act::AddFSet ("selecttransfer","selection (recognize from transfer actor)",XSControl_settransfert);
852}