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