summaryrefslogtreecommitdiff
path: root/src/IFSelect/IFSelect_ContextModif.cxx
blob: 3f051243198adae38ed396968780061240efe2ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
#include <IFSelect_ContextModif.ixx>
#include <IFSelect_Selection.hxx>
#include <Message_Messenger.hxx>
#include <Message.hxx>
#include <Standard_NoSuchObject.hxx>


//=======================================================================
//function : IFSelect_ContextModif
//purpose  : 
//=======================================================================

IFSelect_ContextModif::IFSelect_ContextModif(const Interface_Graph& graph,
                                             const Interface_CopyTool& TC,
                                             const Standard_CString filename)
     : thegraf (graph,Standard_False) , thefile (filename) ,
       thelist (graph.Size(),' ')
{
  themap = TC.Control();  thesel  = Standard_False;  thecurr = thecurt = 0;
  Standard_Integer nb = thelist.Length();
  Handle(Standard_Transient) newent;
  for (Standard_Integer i = 1; i <= nb; i ++) {
    if (themap->Search(graph.Entity(i),newent)) thelist.SetValue(i,'1');
  }
}


//=======================================================================
//function : IFSelect_ContextModif
//purpose  : 
//=======================================================================

IFSelect_ContextModif::IFSelect_ContextModif(const Interface_Graph& graph,
                                             const Standard_CString filename)
     : thegraf (graph,Standard_False) , thefile (filename) ,
       thelist (graph.Size(),' ')
{
  thesel  = Standard_False;  thecurr = thecurt = 0;
  Standard_Integer nb = thelist.Length();
  Handle(Standard_Transient) newent;
  for (Standard_Integer i = 1; i <= nb; i ++)  thelist.SetValue(i,'1');
}


//=======================================================================
//function : Select
//purpose  : 
//=======================================================================

void IFSelect_ContextModif::Select (Interface_EntityIterator& list)
{
  thesel = Standard_True;
  Standard_Integer nb = thelist.Length();
  for (Standard_Integer i = 1; i <= nb; i ++) thelist.SetValue(i,' ');
  for (list.Start(); list.More(); list.Next()) {
    Handle(Standard_Transient) start,newent;
    start = list.Value();
    Standard_Integer num = thegraf.EntityNumber(start);
    if (num > nb || num < 0) num = 0;
    if (themap.IsNull() && num > 0)  thelist.SetValue(num,'1');
    else if (themap->Search (start,newent)) {
      if (num > 0) thelist.SetValue(num,'1');
    }
  }
}


//=======================================================================
//function : OriginalGraph
//purpose  : 
//=======================================================================

const Interface_Graph& IFSelect_ContextModif::OriginalGraph () const
{
  return thegraf;
}


//=======================================================================
//function : OriginalModel
//purpose  : 
//=======================================================================

Handle(Interface_InterfaceModel) IFSelect_ContextModif::OriginalModel() const
{
  return thegraf.Model();
}


//=======================================================================
//function : SetProtocol
//purpose  : 
//=======================================================================

void IFSelect_ContextModif::SetProtocol(const Handle(Interface_Protocol)& prot)
{
  theprot = prot;
}


//=======================================================================
//function : Protocol
//purpose  : 
//=======================================================================

Handle(Interface_Protocol) IFSelect_ContextModif::Protocol() const
{
  return theprot;
}


//=======================================================================
//function : HasFileName
//purpose  : 
//=======================================================================

Standard_Boolean IFSelect_ContextModif::HasFileName() const
{
  return (thefile.Length() > 0);
}


//=======================================================================
//function : FileName
//purpose  : 
//=======================================================================

Standard_CString IFSelect_ContextModif::FileName () const
{
  return thefile.ToCString();
}


//=======================================================================
//function : Control
//purpose  : 
//=======================================================================

Handle(Interface_CopyControl) IFSelect_ContextModif::Control () const
{
  return themap;
}


//=======================================================================
//function : IsForNone
//purpose  : 
//=======================================================================

Standard_Boolean IFSelect_ContextModif::IsForNone () const
{
  if (!thesel) return Standard_False;
  Standard_Integer nb = thelist.Length();
  for (Standard_Integer i = 1; i <= nb; i ++) {
    if (thelist.Value(i) != ' ') return Standard_False;
  }
  return Standard_True;
}


//=======================================================================
//function : IsForAll
//purpose  : 
//=======================================================================

Standard_Boolean IFSelect_ContextModif::IsForAll  () const
{
  return (!thesel);
}


//=======================================================================
//function : IsTransferred
//purpose  : 
//=======================================================================

Standard_Boolean IFSelect_ContextModif::IsTransferred
  (const Handle(Standard_Transient)& ent) const
{
  if (themap.IsNull()) return Standard_True;
  Handle(Standard_Transient) newent;
  return themap->Search(ent,newent);
}


//=======================================================================
//function : IsSelected
//purpose  : 
//=======================================================================

Standard_Boolean IFSelect_ContextModif::IsSelected
  (const Handle(Standard_Transient)& ent) const
{
  //  Select a deja verifie "IsTransferred"
  Standard_Integer num = thegraf.EntityNumber(ent);
  if (num == 0) return Standard_False;
  return (thelist.Value(num) != ' ');
}


//=======================================================================
//function : SelectedOriginal
//purpose  : 
//=======================================================================

Interface_EntityIterator IFSelect_ContextModif::SelectedOriginal () const
{
  Interface_EntityIterator list;
  Standard_Integer nb = thelist.Length();
  for (Standard_Integer i = 1; i <= nb; i ++) {
    if (thelist.Value(i) != ' ') list.GetOneItem (thegraf.Entity(i));
  }
  return list;
}


//=======================================================================
//function : SelectedResult
//purpose  : 
//=======================================================================

Interface_EntityIterator  IFSelect_ContextModif::SelectedResult () const
{
  Interface_EntityIterator list;
  Standard_Integer nb = thelist.Length();
  for (Standard_Integer i = 1; i <= nb; i ++) {
    Handle(Standard_Transient) newent;
    if (themap.IsNull()) newent = thegraf.Entity(i);
    else if (thelist.Value(i) != ' ') themap->Search (thegraf.Entity(i),newent);
    if (!newent.IsNull()) list.GetOneItem (newent);
  }
  return list;
}


//=======================================================================
//function : SelectedCount
//purpose  : 
//=======================================================================

Standard_Integer IFSelect_ContextModif::SelectedCount () const
{
  Standard_Integer nb = thelist.Length();
  Standard_Integer ns = 0;
  for (Standard_Integer i = 1; i <= nb; i ++)
    {  if (thelist.Value(i) != ' ') ns ++;  }
  return ns;
}


//=======================================================================
//function : Start
//purpose  : 
//=======================================================================

void IFSelect_ContextModif::Start ()
{
  thecurr = thecurt = 0;
  Next();
}


//=======================================================================
//function : More
//purpose  : 
//=======================================================================

Standard_Boolean IFSelect_ContextModif::More () const
{
  return (thecurr > 0);
}


//=======================================================================
//function : Next
//purpose  : 
//=======================================================================

void IFSelect_ContextModif::Next()
{
  Standard_Integer nb = thelist.Length();
//  thecurr = thecurt;
//  if (thecurr <= 0 && thecurt >= 0) return;
  for (Standard_Integer i = thecurr+1; i <= nb; i ++) {
    if (thelist.Value(i) != ' ')  {  thecurr = i;  thecurt ++;  return;  }
  }
  thecurr = thecurt = 0;
}


//=======================================================================
//function : ValueOriginal
//purpose  : 
//=======================================================================

Handle(Standard_Transient) IFSelect_ContextModif::ValueOriginal () const
{
  if (thecurr <= 0) Standard_NoSuchObject::Raise("IFSelect_ContextModif");
  return thegraf.Entity(thecurr);
}


//=======================================================================
//function : ValueResult
//purpose  : 
//=======================================================================

Handle(Standard_Transient) IFSelect_ContextModif::ValueResult   () const
{
  if (thecurr <= 0) Standard_NoSuchObject::Raise("IFSelect_ContextModif");
  Handle(Standard_Transient) ent,newent;
  ent = thegraf.Entity(thecurr);
  if (themap.IsNull()) newent = ent;
  else themap->Search(ent,newent);
  return newent;
}


//=======================================================================
//function : TraceModifier
//purpose  : 
//=======================================================================

void IFSelect_ContextModif::TraceModifier
  (const Handle(IFSelect_GeneralModifier)& modif)
{
  if (modif.IsNull()) return;

  Handle(Message_Messenger) sout = Message::DefaultMessenger();
  sout << "---   Run Modifier:" << endl;
  Handle(IFSelect_Selection) sel = modif->Selection();
  if (!sel.IsNull()) sout<<"      Selection:"<<sel->Label();
  else               sout<<"  (no Selection)";

//  on va simplement compter les entites
  Standard_Integer ne = 0, nb = thelist.Length();
  for (Standard_Integer i = 1; i <= nb; i ++) {
    if (thelist.Value(i) != ' ') ne ++;
  }
  if (nb == ne) sout<<"  All Model ("<<nb<<" Entities)"<<endl;
  else          sout<<"  Entities,Total:"<<nb<<" Concerned:"<<ne<<endl;
}


//=======================================================================
//function : Trace
//purpose  : 
//=======================================================================

void IFSelect_ContextModif::Trace (const Standard_CString mess)
{
//  Trace courante
  if (thecurr <= 0) return;
  Handle(Message_Messenger) sout = Message::DefaultMessenger();
  if (ValueOriginal() == ValueResult())
    sout<<"--  ContextModif. Entity  n0 "<<thecurr<<endl;
  else
    sout<<"--  ContextModif. Entity in Original, n0 "<<thecurr<<" in Result, n0 "
      <<thecurt<<endl;
  if (mess[0] != '\0') sout<<"--  Message:"<<mess<<endl;
}


//=======================================================================
//function : AddCheck
//purpose  : 
//=======================================================================

void IFSelect_ContextModif::AddCheck(const Handle(Interface_Check)& check)
{
  if (check->NbFails() + check->NbWarnings() == 0) return;
  const Handle(Standard_Transient)& ent = check->Entity();
  Standard_Integer num = thegraf.EntityNumber(ent);
  if (num == 0 && !ent.IsNull()) num = -1;  // force enregistrement
  thechek.Add(check,num);
}


//=======================================================================
//function : AddWarning
//purpose  : 
//=======================================================================

void IFSelect_ContextModif::AddWarning(const Handle(Standard_Transient)& start,
                                       const Standard_CString mess,
                                       const Standard_CString orig)
{
  thechek.CCheck(thegraf.EntityNumber(start))->AddWarning(mess,orig);
}


//=======================================================================
//function : AddFail
//purpose  : 
//=======================================================================

void IFSelect_ContextModif::AddFail(const Handle(Standard_Transient)& start,
                                    const Standard_CString mess,
                                    const Standard_CString orig)
{
  thechek.CCheck(thegraf.EntityNumber(start))->AddFail(mess,orig);
}


//=======================================================================
//function : CCheck
//purpose  : 
//=======================================================================

Handle(Interface_Check) IFSelect_ContextModif::CCheck(const Standard_Integer num)
{
  Handle(Interface_Check) ach = thechek.CCheck(num);
  if (num > 0 && num <= thegraf.Size()) ach->SetEntity(thegraf.Entity(num));
  return ach;
}


//=======================================================================
//function : CCheck
//purpose  : 
//=======================================================================

Handle(Interface_Check) IFSelect_ContextModif::CCheck
       (const Handle(Standard_Transient)& ent)
{
  Standard_Integer num = thegraf.EntityNumber(ent);
  if (num == 0) num = -1;    // force l enregistrement
  Handle(Interface_Check)& ach = thechek.CCheck(num);
  ach->SetEntity(ent);
  return ach;
}


//=======================================================================
//function : CheckList
//purpose  : 
//=======================================================================

Interface_CheckIterator IFSelect_ContextModif::CheckList () const
{
  return thechek;
}