summaryrefslogtreecommitdiff
path: root/src/IFSelect/IFSelect_SelectPointed.cxx
blob: 25bcb30443bc1d1a92ef663e96e99a43582df412 (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
#include <IFSelect_SelectPointed.ixx>
#include <TColStd_MapOfTransient.hxx>



    IFSelect_SelectPointed::IFSelect_SelectPointed ()
    : theset (Standard_False)    {  }

    void  IFSelect_SelectPointed::Clear()
      {  theitems.Clear();  theset = Standard_False;  }

    Standard_Boolean  IFSelect_SelectPointed::IsSet () const
      {  return theset;  }

    void  IFSelect_SelectPointed::SetEntity
  (const Handle(Standard_Transient)& ent)
{
  theitems.Clear();
  theset = Standard_True;
  if (ent.IsNull()) return;
  theitems.Append (ent);
}

    void  IFSelect_SelectPointed::SetList
  (const Handle(TColStd_HSequenceOfTransient)& list)
{
  theitems.Clear();
  theset = Standard_True;
  if (list.IsNull()) return;
  Standard_Integer i,nb = list->Length();
  for (i = 1; i <= nb; i ++)  theitems.Append (list->Value(i));
}

//  ....    Editions

    Standard_Boolean  IFSelect_SelectPointed::Add
  (const Handle(Standard_Transient)& item)
{
  if (item.IsNull()) return Standard_False;
  for (Standard_Integer i = theitems.Length(); i >= 1; i --)
    if (item == theitems.Value(i)) return Standard_False;
  theitems.Append(item);
  theset = Standard_True;
  return Standard_True;
}

    Standard_Boolean  IFSelect_SelectPointed::Remove
  (const Handle(Standard_Transient)& item)
{
  if (item.IsNull()) return Standard_False;
  for (Standard_Integer i = theitems.Length(); i >= 1; i --)
    if (item == theitems.Value(i)) { theitems.Remove(i); return Standard_True;}
  return Standard_True;
}

    Standard_Boolean  IFSelect_SelectPointed::Toggle
  (const Handle(Standard_Transient)& item)
{
  if (item.IsNull()) return Standard_False;
  Standard_Integer num = 0;
  for (Standard_Integer i = theitems.Length(); i >= 1; i --)
    if (item == theitems.Value(i)) num = i;
  if (num == 0) theitems.Append(item);
  else          theitems.Remove(num);
  return (num == 0);
}

    Standard_Boolean  IFSelect_SelectPointed::AddList
  (const Handle(TColStd_HSequenceOfTransient)& list)
{
//   Optimise avec une Map
  Standard_Boolean res = Standard_False;
  if (list.IsNull()) return res;
  Standard_Integer i, nb = theitems.Length(), nl = list->Length();
  TColStd_MapOfTransient deja (nb+nl+1);
  for (i = 1; i <= nb; i ++) deja.Add (theitems.Value(i));

  for (i = 1; i <= nl; i ++) {
    if (!deja.Contains (list->Value(i)) ) theitems.Append (list->Value(i));
  }
  theset = Standard_True;
  return res;
}

    Standard_Boolean  IFSelect_SelectPointed::RemoveList
  (const Handle(TColStd_HSequenceOfTransient)& list)
{
  Standard_Boolean res = Standard_False;
  if (list.IsNull()) return res;
  Standard_Integer i, nb = list->Length();
  for (i = 1; i <= nb; i ++) res |= Remove (list->Value(i));
  return res;
}

    Standard_Boolean  IFSelect_SelectPointed::ToggleList
  (const Handle(TColStd_HSequenceOfTransient)& list)
{
  Standard_Boolean res = Standard_True;
  if (list.IsNull()) return res;
  Standard_Integer i, nb = list->Length();
  for (i = 1; i <= nb; i ++) res |= Toggle (list->Value(i));
  return res;
}


//  ....   Consultations

    Standard_Integer  IFSelect_SelectPointed::Rank
  (const Handle(Standard_Transient)& item) const
{
  if (item.IsNull()) return 0;
  for (Standard_Integer i = theitems.Length(); i >= 1; i --)
    if (item == theitems.Value(i)) return i;
  return 0;
}

    Standard_Integer  IFSelect_SelectPointed::NbItems () const
      {  return theitems.Length();  }

    Handle(Standard_Transient)  IFSelect_SelectPointed::Item
  (const Standard_Integer num) const
{
  Handle(Standard_Transient) item;
  if (num <= 0 || num > theitems.Length()) return item;
  return theitems.Value(num);
}

    void  IFSelect_SelectPointed::Update
  (const Handle(Interface_CopyControl)& control)
{
  Standard_Integer nb = theitems.Length();
  for (Standard_Integer i = nb; i > 0; i --) {
    Handle(Standard_Transient) enfr, ento;
    enfr = theitems.Value(i);
    if (!control->Search(enfr,ento)) theitems.Remove(i);
    else  theitems.SetValue(i,ento);
  }
}

    void  IFSelect_SelectPointed::Update
  (const Handle(IFSelect_Transformer)& trf)
{
  Standard_Integer nb = theitems.Length();
  for (Standard_Integer i = nb; i > 0; i --) {
    Handle(Standard_Transient) enfr, ento;
    enfr = theitems.Value(i);
    if (!trf->Updated(enfr,ento)) theitems.Remove(i);
    else  theitems.SetValue(i,ento);
  }
}

//  ....  Actions Generales

    Interface_EntityIterator  IFSelect_SelectPointed::RootResult
  (const Interface_Graph& G) const
{
  Interface_EntityIterator result;
  Standard_Integer nb = theitems.Length();
  for (Standard_Integer i = 1; i <= nb; i ++) {
    Handle(Standard_Transient) item = theitems.Value(i);
    if (G.EntityNumber(item) > 0) result.GetOneItem(item);
  }
  return result;
}

    TCollection_AsciiString  IFSelect_SelectPointed::Label () const
      {  return TCollection_AsciiString ("Pointed Entities");  }