summaryrefslogtreecommitdiff
path: root/src/IGESSelect/IGESSelect_ViewSorter.cxx
blob: f30b86aded4330f71db398fbe31bd0805f674dcf (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
#include <IGESSelect_ViewSorter.ixx>
#include <IGESData_IGESEntity.hxx>
#include <IGESData_ViewKindEntity.hxx>
#include <Interface_EntityIterator.hxx>
#include <Interface_Macros.hxx>



#define PourDrawing 404


    IGESSelect_ViewSorter::IGESSelect_ViewSorter  ()    {  }

    void  IGESSelect_ViewSorter::SetModel
  (const Handle(IGESData_IGESModel)& model)    {  themodel = model;  }


    void  IGESSelect_ViewSorter::Clear ()
{
  Standard_Integer nb = themodel->NbEntities();
  if (nb < 100) nb = 100;
  themap.Clear();      themap.ReSize (nb);
  theitems.Clear();    theitems.ReSize (nb);
  thefinals.Clear();   thefinals.ReSize (nb);
  theinditem.Clear();  theindfin.Clear();  // seq//
}


    Standard_Boolean  IGESSelect_ViewSorter::Add
  (const Handle(Standard_Transient)& ent)
{
  DeclareAndCast(IGESData_IGESEntity,igesent,ent);
  if (!igesent.IsNull()) return AddEntity (igesent);
  DeclareAndCast(TColStd_HSequenceOfTransient,list,ent);
  if (!list.IsNull())  {  AddList  (list);   return Standard_True;  }
  DeclareAndCast(Interface_InterfaceModel,model,ent);
  if (!model.IsNull()) {  AddModel (model);  return Standard_True;  }
  return Standard_False;
}

    Standard_Boolean  IGESSelect_ViewSorter::AddEntity
  (const Handle(IGESData_IGESEntity)& igesent)
{
//  Reception, controle de type et de map
  if (igesent.IsNull()) return Standard_False;
  if (themap.FindIndex(igesent)) return Standard_False;
  themap.Add(igesent);
//  Recuperation de la vue (attention au cas du Drawing)
  Handle(IGESData_IGESEntity) view;
  if (igesent->TypeNumber() == PourDrawing) view = igesent;  // DRAWING
  else {
    if (igesent->IsKind(STANDARD_TYPE(IGESData_ViewKindEntity))) view = igesent; // VIEW
    else view = igesent->View();
/*
    DeclareAndCast(IGESData_ViewKindEntity,trueview,view);
    if (!trueview.IsNull())
      if (trueview->IsSingle()) view.Nullify();  // Multiple -> Nulle
*/
  }
//  On enregistre
  Standard_Integer viewindex = 0;  // 0 sera pour remain
  if (!view.IsNull()) {
    viewindex = theitems.FindIndex(view);
    if (viewindex <= 0) viewindex = theitems.Add(view);
  }
  theinditem.Append(viewindex);
  theindfin.Append(0);
  return Standard_True;
}


    void  IGESSelect_ViewSorter::AddList
  (const Handle(TColStd_HSequenceOfTransient)& list)
{
  Standard_Integer nb = list->Length();
  for (Standard_Integer i = 1; i <= nb; i ++) Add (list->Value(i));
}

    void  IGESSelect_ViewSorter::AddModel
  (const Handle(Interface_InterfaceModel)& model)
{
  DeclareAndCast(IGESData_IGESModel,igesmod,model);
  if (igesmod.IsNull()) return;
  Standard_Integer nb = igesmod->NbEntities();
  for (Standard_Integer i = 1; i <= nb; i ++) AddEntity (igesmod->Entity(i));
}

    Standard_Integer  IGESSelect_ViewSorter::NbEntities () const
      {  return themap.Extent();  }

//  .....    Attention    .....

    void  IGESSelect_ViewSorter::SortSingleViews
  (const Standard_Boolean alsoframes)
{
// Du tas initial, on ecarte : les vues nulles, et selon alsoframe les drawings
// Vues nulles : cf theremain (remain initial reconduit)

//  Remarque : le filtre IsSingle a ete applique par Add
  thefinals.Clear();
  Standard_Integer nb = theinditem.Length();
  //Standard_Integer numit = 0; //szv#4:S4163:12Mar99 not needed
  for (Standard_Integer i = 1; i <= nb; i ++) {
    Standard_Integer numitem = theinditem.Value(i);
    Standard_Integer finalindex = 0;  // 0 sera pour remain
    if (numitem > 0) {
      //numit = numitem; //szv#4:S4163:12Mar99 not needed
      DeclareAndCast(IGESData_IGESEntity,item,theitems.FindKey(numitem));
      Standard_Boolean ok = Standard_False;
      if (alsoframes)  ok = (item->TypeNumber() == PourDrawing);
      if (!ok) {
	DeclareAndCast(IGESData_ViewKindEntity,view,item);
	if (!view.IsNull()) ok = view->IsSingle();
      }
      if (ok) {
	finalindex = thefinals.FindIndex(item);
	if (finalindex <= 0) finalindex = thefinals.Add(item);
      }
    }
    theindfin.SetValue(i,finalindex);
  }
}


    void  IGESSelect_ViewSorter::SortDrawings (const Interface_Graph& G)
{
// Pour chaque item (vue ou drawing), drawing contenant, silya (sinon tant pis)

  thefinals.Clear();
  Standard_Integer nb = theinditem.Length();
  //Standard_Integer numit = 0; //szv#4:S4163:12Mar99 not needed
  for (Standard_Integer i = 1; i <= nb; i ++) {
    Standard_Integer numitem = theinditem.Value(i);
    Standard_Integer finalindex = 0;  // 0 sera pour remain
    if (numitem > 0) {
      //numit = numitem; //szv#4:S4163:12Mar99 not needed
      DeclareAndCast(IGESData_IGESEntity,item,theitems.FindKey(numitem));
      if (item.IsNull()) continue;
//  Si cest un Drawing, il definit le Set. Sinon, chercher Drawing contenant
      Handle(Standard_Transient) drawing;
      if (item->TypeNumber() == PourDrawing) drawing = item;
      else {
	Interface_EntityIterator list = G.Sharings(item);
	for (list.Start(); list.More(); list.Next()) {
	  DeclareAndCast(IGESData_IGESEntity,draw,list.Value());
	  if (draw.IsNull()) continue;
	  if (draw->TypeNumber() == PourDrawing) drawing = draw;
	}
      }
      if (!drawing.IsNull()) {
	finalindex = thefinals.FindIndex(drawing);
	if (finalindex <= 0) finalindex = thefinals.Add(drawing);
      }
    }
    theindfin.SetValue(i,finalindex);
  }
}

//  ....    Queries    ....

    Standard_Integer  IGESSelect_ViewSorter::NbSets
  (const Standard_Boolean final) const
{
  if (final) return thefinals.Extent();
  else       return theitems.Extent();
}

    Handle(IGESData_IGESEntity)  IGESSelect_ViewSorter::SetItem
  (const Standard_Integer num, const Standard_Boolean final) const
{
  if (final) return GetCasted(IGESData_IGESEntity,thefinals.FindKey(num));
  else       return GetCasted(IGESData_IGESEntity,theitems.FindKey(num));
}

    Handle(IFSelect_PacketList)  IGESSelect_ViewSorter::Sets
  (const Standard_Boolean final) const
{
  Handle(IFSelect_PacketList) list = new IFSelect_PacketList(themodel);
  Standard_Integer i, nb;
  nb = (final ? theindfin.Length() : theinditem.Length());
  Standard_Integer nbs = NbSets(final);
  for (Standard_Integer num = 1; num <= nbs; num ++) {
    list->AddPacket();
    if (final) {
//    Attention a l unicite
      for (i = 1; i <= nb; i ++) {
	if (theindfin.Value(i) != num) continue;
	list->Add (themap.FindKey(i));
      }
    } else {
      for (i = 1; i <= nb; i ++) {
	if (theinditem.Value(i) != num) continue;
	list->Add (themap.FindKey(i));
      }
    }
  }
  return list;
}