0023024: Update headers of OCCT files
[occt.git] / src / IGESSelect / IGESSelect_Activator.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 <Standard_ErrorHandler.hxx>
19#include <Standard_Failure.hxx>
20
21#include <IGESSelect_Activator.ixx>
22#include <Interface_EntityIterator.hxx>
23#include <Interface_Macros.hxx>
24#include <IFSelect_WorkSession.hxx>
25#include <IFSelect_WorkLibrary.hxx>
26
27#include <IGESData_IGESModel.hxx>
28#include <IGESData_IGESEntity.hxx>
29#include <IGESData_Protocol.hxx>
30#include <IFSelect_IntParam.hxx>
31#include <TCollection_HAsciiString.hxx>
32
33#include <IGESSelect_IGESTypeForm.hxx>
34
35#include <IGESSelect_ViewSorter.hxx>
36#include <IFSelect_PacketList.hxx>
37
38#include <IGESSelect_DispPerSingleView.hxx>
39#include <IGESSelect_DispPerDrawing.hxx>
40
41#include <IFSelect_SelectSignature.hxx>
42#include <IGESSelect_SelectVisibleStatus.hxx>
43#include <IGESSelect_SelectLevelNumber.hxx>
44#include <IGESSelect_SelectName.hxx>
45
46#include <IGESSelect_SelectFromSingleView.hxx>
47#include <IGESSelect_SelectFromDrawing.hxx>
48#include <IGESSelect_SelectSingleViewFrom.hxx>
49#include <IGESSelect_SelectDrawingFrom.hxx>
50
51#include <IGESSelect_SelectBypassGroup.hxx>
52
53#include <IGESSelect_FloatFormat.hxx>
54#include <IGESSelect_UpdateCreationDate.hxx>
55#include <IGESSelect_UpdateLastChange.hxx>
56#include <IGESSelect_UpdateFileName.hxx>
57#include <IGESSelect_SetVersion5.hxx>
58#include <IGESSelect_SetGlobalParameter.hxx>
59
60#include <IGESSelect_AutoCorrect.hxx>
61#include <IGESSelect_ComputeStatus.hxx>
62#include <IGESSelect_RebuildDrawings.hxx>
63#include <IGESSelect_RebuildGroups.hxx>
64#include <IGESSelect_AddGroup.hxx>
65
66#include <IGESSelect_SplineToBSpline.hxx>
67
68#include <TColStd_HSequenceOfTransient.hxx>
69#include <IGESSelect_WorkLibrary.hxx>
70#include <stdio.h>
71
72
73
74static int initActivator = 0;
75
76 IGESSelect_Activator::IGESSelect_Activator ()
77{
78 if (initActivator) return; initActivator = 1;
79// Add ( 0,"load");
80// Add ( 0,"loadiges"); // homonyme
81 SetForGroup ("XSTEP-IGES");
82
83 Add ( 5,"listviews");
84 Add ( 6,"listdrawings");
85 Add ( 7,"listsviews");
86
87 AddSet (10,"igestype");
88 AddSet (11,"bypassgroup");
89 AddSet (12,"igesname");
90 AddSet (13,"igesvisible");
91 AddSet (14,"igeslevel");
92
93 AddSet (21,"igesfromdrawing");
94 AddSet (22,"igesfromview");
95 AddSet (23,"igesdrawingfrom");
96 AddSet (24,"igesviewfrom");
97
98 AddSet (31,"igesdispdrawing");
99 AddSet (32,"igesdispview");
100
101 AddSet (40,"floatformat");
102 AddSet (41,"setglobalparam");
103 AddSet (42,"setversion5");
104 AddSet (43,"updatecreationdate");
105 AddSet (44,"updatelastchange");
106 AddSet (45,"updatefilename");
107
108 AddSet (50,"autocorrect");
109 AddSet (51,"computestatus");
110 AddSet (52,"rebuildgroups");
111 AddSet (53,"rebuilddrawings");
112 AddSet (54,"addgroup");
113
114 AddSet (60,"splinetobspline");
115
116 Add (70,"setuseflag");
117}
118
119
120 IFSelect_ReturnStatus IGESSelect_Activator::Do
121 (const Standard_Integer number,
122 const Handle(IFSelect_SessionPilot)& pilot)
123{
124 Standard_Integer argc = pilot->NbWords();
125 const Standard_CString arg1 = pilot->Word(1).ToCString();
126 const Standard_CString arg2 = pilot->Word(2).ToCString();
127// const Standard_CString arg3 = pilot->Word(3).ToCString();
128 Handle(IFSelect_WorkSession) WS = pilot->Session();
129
130 switch (number) {
131
132 case 5 : // **** ListViews (sans tri complementaire)
133 case 6 : // **** ListDrawings
134 case 7 : { // **** ListS(ingle)Views
135 Standard_Integer listmode = 0;
136 if (argc == 2 && arg1[0] == '?') argc = -1;
137 if (argc < 2) {
138 cout<<"Ajouter un argument pour avoir :\n"<<
139 " l : liste resumee"<<
140 " c : liste complete par item (mais pas pour remaining)\n"<<
141 " r : idem + liste complete remaining\n"<<
142 " sur tout le modele. Ajouter nom selection pour lister sur une partie"<<endl;
143 return (argc >= 0 ? IFSelect_RetError : IFSelect_RetVoid);
144 }
145 if (arg1[0] == 'l') {
146 listmode = 0; cout<<"Liste resumee";
147 }
148 else if (arg1[0] == 'c') {
149 listmode = 1; cout<<"Liste complete par item (pas pour Remaining)"<<endl;
150 }
151 else if (arg1[0] == 'r') {
152 listmode = 2; cout<<"Liste complete par item et pour Remaining"<<endl;
153 }
154 else {
155 cout<<"Parametre de listage non compris"<<endl; return IFSelect_RetError;
156 }
157
158 Handle(IGESSelect_ViewSorter) vs = new IGESSelect_ViewSorter;
159 vs->SetModel(GetCasted(IGESData_IGESModel,WS->Model()));
160 if (argc == 2) vs->AddModel(WS->Model());
161 else {
162// on demande une selection
163 DeclareAndCast(IFSelect_Selection,sel,WS->NamedItem(arg2));
164 if (sel.IsNull()) {
165 cout<<"Pas une selection : "<<arg2<<endl;
166 return IFSelect_RetError;
167 }
168 vs->AddList (WS->SelectionResult(sel));
169 }
170 Standard_Boolean listdr = (number > 5);
171 if (number == 6) vs->SortDrawings(WS->Graph());
172 if (number == 7) vs->SortSingleViews(Standard_True);
173 Handle(IFSelect_PacketList) sets = vs->Sets(listdr);
174 Standard_Integer nb = vs->NbSets(listdr);
175 cout<<" -- ViewSorter for";
176 if (number == 5) cout<<" Views & Drawings";
177 if (number == 6) cout<<" Drawings only (complete)";
178 if (number == 7) cout<<" Single Views & Drawing Frames";
179 cout<<", on "<<vs->NbEntities()<<" ent.s, give "<<nb<<" Sets"<<endl;
180
181 Interface_EntityIterator iter;
182 for (Standard_Integer i = 1; i <= nb; i ++) {
183 cout<<" -- Set n0 "<<i<<" Item=entity n0: "<<
184 WS->Model()->Number(vs->SetItem(i,listdr))<<" List:";
185 cout<<sets->NbEntities(i)<<" ent.s:"<<endl;
186 if (listmode == 0) continue;
187 iter = sets->Entities(i);
188 WS->ListEntities (iter,0);
189 }
190
191 cout <<" -- Remaining Entities (not yet sorted) :"
192 <<sets->NbDuplicated(0,Standard_False)<<endl;
193 if (listmode < 2) return IFSelect_RetVoid;
194 iter = sets->Duplicated(0,Standard_False);
195 WS->ListEntities(iter,0);
196 return IFSelect_RetVoid;
197 }
198
199 case 10 : { // **** IGESType (form Type/Form)
200 if (argc < 2) {
201 cout<<"Donner le n0 de type desire, + en option la forme\n"
202 <<" Si pas de forme, prend toutes les formes du type demande"<<endl;
203 return IFSelect_RetError;
204 }
205 char signature[20];
206 if (argc == 2) sprintf(signature,"%s",arg1);
207 else sprintf(signature,"%s %s",arg1,arg2);
208 Handle(IFSelect_SelectSignature) sel = new IFSelect_SelectSignature
209 (new IGESSelect_IGESTypeForm, signature,(argc > 2));
210 return pilot->RecordItem (sel);
211 }
212
213 case 11 : { // **** IGES BypassGroup
214 return pilot->RecordItem (new IGESSelect_SelectBypassGroup);
215 }
216
217 case 12 : { // **** IGES Name
218 if (argc < 2) {
219 cout<<"Donner un Nom de TextParam pour IGESName"<<endl;
220 return IFSelect_RetError;
221 }
222 Handle(IGESSelect_SelectName) sel = new IGESSelect_SelectName;
223 sel->SetName
224 (GetCasted(TCollection_HAsciiString,WS->NamedItem(arg1)) );
225 return pilot->RecordItem (sel);
226 }
227
228 case 13 : { // **** IGES VisibleStatus
229 return pilot->RecordItem (new IGESSelect_SelectVisibleStatus);
230 }
231
232 case 14 : { // **** IGES LevelNumber
233 if (argc < 2) {
234 cout<<"Donner nom IntParam pour Level"<<endl;
235 return IFSelect_RetError;
236 }
237 DeclareAndCast(IFSelect_IntParam,lev,WS->NamedItem(arg1));
238 if (lev.IsNull()) {
239 cout<<arg1<<" : pas un IntParam (pour Level)"<<endl;
240 return IFSelect_RetError;
241 }
242 Handle(IGESSelect_SelectLevelNumber) sel = new IGESSelect_SelectLevelNumber;
243 sel->SetLevelNumber(lev);
244 return pilot->RecordItem (sel);
245 }
246
247 case 21 : { // **** IGES FromDrawing
248 return pilot->RecordItem (new IGESSelect_SelectFromDrawing);
249 }
250 case 22 : { // **** IGES FromSingleView
251 return pilot->RecordItem (new IGESSelect_SelectFromSingleView);
252 }
253 case 23 : { // **** IGES FromDrawing
254 return pilot->RecordItem (new IGESSelect_SelectDrawingFrom);
255 }
256 case 24 : { // **** IGES FromDrawing
257 return pilot->RecordItem (new IGESSelect_SelectSingleViewFrom);
258 }
259
260 case 31 : { // **** IGES DispatchPerDrawing
261 return pilot->RecordItem (new IGESSelect_DispPerDrawing);
262 }
263 case 32 : { // **** IGES DispatchPerSingleView
264 return pilot->RecordItem (new IGESSelect_DispPerSingleView);
265 }
266
267 case 40 : { // **** FloatFormat
268 char prem = ' ';
269 if (argc < 2) prem = '?';
270 else if (argc == 5) {
271 cout<<"floatformat tout court donne les formes admises"<<endl;
272 return IFSelect_RetError;
273 }
274 else prem = arg1[0];
275 Standard_Boolean zerosup=Standard_False;
276 Standard_Integer digits = 0;
277 if (prem == 'N' || prem == 'n') zerosup = Standard_False;
278 else if (prem == 'Z' || prem == 'z') zerosup = Standard_True;
279 else if (prem >= 48 && prem <= 57) digits = atoi(arg1);
280 else {
281 cout<<"floatformat digits, digits=nb de chiffres signifiants, ou\n"
282 << "floatformat NZ %mainformat [%rangeformat [Rmin Rmax]]\n"
283 <<" NZ : N ou n pour Non-zero-suppress, Z ou z pour zero-suppress\n"
284 <<" %mainformat : format principal type printf, ex,: %E\n"
285 <<" + optionnel : format secondaire (flottants autour de 1.) :\n"
286 <<" %rangeformat Rmin Rmax : format type printf entre Rmin et Rmax\n"
287 <<" %rangeformat tout seul : format type printf entre 0.1 et 1000.\n"
288 <<flush;
289 return (prem == '?' ? IFSelect_RetVoid : IFSelect_RetError);
290 }
291 Standard_Real Rmin=0., Rmax=0.;
292 if (argc > 4) {
293 Rmin = atof(pilot->Word(4).ToCString());
294 Rmax = atof(pilot->Word(5).ToCString());
295 if (Rmin <= 0 || Rmax <= 0) { cout<<"intervalle : donner reels > 0"<<endl; return IFSelect_RetError; }
296 }
297 Handle(IGESSelect_FloatFormat) fm = new IGESSelect_FloatFormat;
298 if (argc == 2) fm->SetDefault(digits);
299 else {
300 fm->SetZeroSuppress(zerosup);
301 fm->SetFormat (arg2);
302 if (argc == 4) fm->SetFormatForRange(pilot->Word(3).ToCString());
303 else if (argc >= 6) fm->SetFormatForRange(pilot->Word(3).ToCString(),Rmin,Rmax);
304 else fm->SetFormatForRange("");
305 }
306 return pilot->RecordItem(fm);
307 }
308
309 case 41 : { // **** SetGlobalParameter
310 if (argc < 3) {
311 cout<<"Donner entier=n0 param a changer + nom TextParam pour la valeur"<<endl;
312 return IFSelect_RetError;
313 }
314 Standard_Integer numpar = atoi(arg1);
315 if (numpar <= 0) {
316 cout<<"Pas un n0 de param global correct:"<<arg1<<endl;
317 return IFSelect_RetError;
318 }
319 DeclareAndCast(TCollection_HAsciiString,val,WS->NamedItem(arg2));
320 if (val.IsNull()) {
321 cout<<"Pas un nom de TextParam:"<<arg2<<endl;
322 return IFSelect_RetError;
323 }
324 Handle(IGESSelect_SetGlobalParameter) mod =
325 new IGESSelect_SetGlobalParameter(numpar);
326 mod->SetValue(val);
327 return pilot->RecordItem (mod);
328 }
329
330 case 42 : { // **** Set IGES Version 5.1
331 return pilot->RecordItem (new IGESSelect_SetVersion5);
332 }
333 case 43 : { // **** Update Creation Date
334 return pilot->RecordItem (new IGESSelect_UpdateCreationDate);
335 }
336 case 44 : { // **** Update Last Change Date
337 return pilot->RecordItem (new IGESSelect_UpdateLastChange);
338 }
339 case 45 : { // **** Update File Name
340 return pilot->RecordItem (new IGESSelect_UpdateFileName);
341 }
342
343 case 50 : { // **** AutoCorrect
344 return pilot->RecordItem (new IGESSelect_AutoCorrect);
345 }
346 case 51 : { // **** Compute Status
347 return pilot->RecordItem (new IGESSelect_ComputeStatus);
348 }
349 case 52 : { // **** Rebuild Groups
350 return pilot->RecordItem (new IGESSelect_RebuildGroups);
351 }
352 case 53 : { // **** Rebuild Drawings
353 return pilot->RecordItem (new IGESSelect_RebuildDrawings);
354 }
355 case 54 : { // **** Add Group
356 return pilot->RecordItem (new IGESSelect_AddGroup);
357 }
358
359 case 60 : { // **** Spline To BSpline
360 if (argc < 2) {
361 cout<<"Pour SplineToBSpline, donner mode :\n"<<
362 " n pour normal, t pour tryC2"<<endl;
363 return IFSelect_RetError;
364 }
365 Standard_Boolean tryC2;
366 if (arg1[0] == 'n' || arg1[0] == 'N')
367 tryC2 = Standard_False;
368 else if (arg1[0] == 't' || arg1[0] == 'T')
369 tryC2 = Standard_True;
370 else {
371 cout<<" Mode incorrect : "<<arg1<<endl;
372 return IFSelect_RetError;
373 }
374 Handle(IGESSelect_SplineToBSpline) conv =
375 new IGESSelect_SplineToBSpline (tryC2);
376 return pilot->RecordItem(conv);
377 }
378
379 case 70 : { // **** SetUseFlag
380 Standard_Integer usefl = atoi (arg1);
381 if (argc > 2) {
382 Handle(TColStd_HSequenceOfTransient) list = WS->GiveList(pilot->CommandPart(2));
383 Standard_Integer i, nb = list->Length();
384 for (i = 1; i <= nb; i ++) {
385 DeclareAndCast(IGESData_IGESEntity,ent,list->Value(i));
386 if (!ent.IsNull()) ent->InitStatus
387 (ent->BlankStatus(),ent->SubordinateStatus(),usefl,ent->HierarchyStatus());
388 }
389 }
390 else {
391 Standard_Integer i, nb = WS->NbStartingEntities();
392 for (i = 1; i <= nb; i ++) {
393 DeclareAndCast(IGESData_IGESEntity,ent,WS->StartingEntity(i));
394 if (!ent.IsNull()) ent->InitStatus
395 (ent->BlankStatus(),ent->SubordinateStatus(),usefl,ent->HierarchyStatus());
396 }
397 }
398 return IFSelect_RetDone;
399 }
400
401 default : break;
402 }
403 return IFSelect_RetVoid;
404
405}
406
407Standard_CString IGESSelect_Activator::Help
408 (const Standard_Integer number) const
409{
410 switch (number) {
411 case 5 : return "Liste Vues (tous types). Nom selection sinon tout modele";
412 case 6 : return "Liste Drawings. Nom selection sinon tout modele";
413 case 7 : return "Liste Vues SIMPLES. Nom selection sinon tout modele";
414
415 case 10 : return "type:integer [form:integer] : cree Select IGESType";
416 case 11 : return "cree Select Bypass Group";
417 case 12 : return "name:TextParam : cree Select Name (Name/Label)";
418 case 13 : return "cree Select Visible Status (Blank Status = 0 sinon 1)";
419 case 14 : return "level:IntParam : cree Select LevelNumber";
420
421 case 21 : return "cree Select From Drawing";
422 case 22 : return "cree Select From Single View";
423 case 23 : return "cree Select Drawing From, drawing(s) pour une liste d entites";
424 case 24 : return "cree Select View From, views pour une liste d entites";
425
426 case 31 : return "cree Dispatch Per Drawing";
427 case 32 : return "cree Dispatch Per SingleView";
428
429 case 40 : return "options... : cree FloatFormat ... floatformat tout court->help";
430 case 41 : return "numpar:integer value:TextParam : cree Set Global Param";
431 case 42 : return "cree Set Version -> 5.1";
432 case 43 : return "cree Update Creation Date";
433 case 44 : return "cree Update Last Change Date";
434 case 45 : return "cree Update File Name (dynamic)";
435
436 case 50 : return "cree AutoCorrect";
437 case 51 : return "cree Compute Status (in D.E.)";
438 case 52 : return "cree Rebuild Groups";
439 case 53 : return "cree Rebuild Drawings";
440 case 54 : return "cree AddGroup";
441
442 case 60 : return "cree SplineToBSpline Conversion";
443
444 case 70 : return "useflag givelist : Set Use Flag to value";
445
446 default : break;
447 }
448 return "??";
449}