0022934: Wrong delete operator in IGESSelect_SelectFromDrawing.cxx / IGESSelect_Selec...
[occt.git] / src / IGESSelect / IGESSelect_ViewSorter.cxx
CommitLineData
7fd59977 1#include <IGESSelect_ViewSorter.ixx>
2#include <IGESData_IGESEntity.hxx>
3#include <IGESData_ViewKindEntity.hxx>
4#include <Interface_EntityIterator.hxx>
5#include <Interface_Macros.hxx>
6
7
8
9#define PourDrawing 404
10
11
12 IGESSelect_ViewSorter::IGESSelect_ViewSorter () { }
13
14 void IGESSelect_ViewSorter::SetModel
15 (const Handle(IGESData_IGESModel)& model) { themodel = model; }
16
17
18 void IGESSelect_ViewSorter::Clear ()
19{
20 Standard_Integer nb = themodel->NbEntities();
21 if (nb < 100) nb = 100;
22 themap.Clear(); themap.ReSize (nb);
23 theitems.Clear(); theitems.ReSize (nb);
24 thefinals.Clear(); thefinals.ReSize (nb);
25 theinditem.Clear(); theindfin.Clear(); // seq//
26}
27
28
29 Standard_Boolean IGESSelect_ViewSorter::Add
30 (const Handle(Standard_Transient)& ent)
31{
32 DeclareAndCast(IGESData_IGESEntity,igesent,ent);
33 if (!igesent.IsNull()) return AddEntity (igesent);
34 DeclareAndCast(TColStd_HSequenceOfTransient,list,ent);
35 if (!list.IsNull()) { AddList (list); return Standard_True; }
36 DeclareAndCast(Interface_InterfaceModel,model,ent);
37 if (!model.IsNull()) { AddModel (model); return Standard_True; }
38 return Standard_False;
39}
40
41 Standard_Boolean IGESSelect_ViewSorter::AddEntity
42 (const Handle(IGESData_IGESEntity)& igesent)
43{
44// Reception, controle de type et de map
45 if (igesent.IsNull()) return Standard_False;
46 if (themap.FindIndex(igesent)) return Standard_False;
47 themap.Add(igesent);
48// Recuperation de la vue (attention au cas du Drawing)
49 Handle(IGESData_IGESEntity) view;
50 if (igesent->TypeNumber() == PourDrawing) view = igesent; // DRAWING
51 else {
52 if (igesent->IsKind(STANDARD_TYPE(IGESData_ViewKindEntity))) view = igesent; // VIEW
53 else view = igesent->View();
54/*
55 DeclareAndCast(IGESData_ViewKindEntity,trueview,view);
56 if (!trueview.IsNull())
57 if (trueview->IsSingle()) view.Nullify(); // Multiple -> Nulle
58*/
59 }
60// On enregistre
61 Standard_Integer viewindex = 0; // 0 sera pour remain
62 if (!view.IsNull()) {
63 viewindex = theitems.FindIndex(view);
64 if (viewindex <= 0) viewindex = theitems.Add(view);
65 }
66 theinditem.Append(viewindex);
67 theindfin.Append(0);
68 return Standard_True;
69}
70
71
72 void IGESSelect_ViewSorter::AddList
73 (const Handle(TColStd_HSequenceOfTransient)& list)
74{
75 Standard_Integer nb = list->Length();
76 for (Standard_Integer i = 1; i <= nb; i ++) Add (list->Value(i));
77}
78
79 void IGESSelect_ViewSorter::AddModel
80 (const Handle(Interface_InterfaceModel)& model)
81{
82 DeclareAndCast(IGESData_IGESModel,igesmod,model);
83 if (igesmod.IsNull()) return;
84 Standard_Integer nb = igesmod->NbEntities();
85 for (Standard_Integer i = 1; i <= nb; i ++) AddEntity (igesmod->Entity(i));
86}
87
88 Standard_Integer IGESSelect_ViewSorter::NbEntities () const
89 { return themap.Extent(); }
90
91// ..... Attention .....
92
93 void IGESSelect_ViewSorter::SortSingleViews
94 (const Standard_Boolean alsoframes)
95{
96// Du tas initial, on ecarte : les vues nulles, et selon alsoframe les drawings
97// Vues nulles : cf theremain (remain initial reconduit)
98
99// Remarque : le filtre IsSingle a ete applique par Add
100 thefinals.Clear();
101 Standard_Integer nb = theinditem.Length();
102 //Standard_Integer numit = 0; //szv#4:S4163:12Mar99 not needed
103 for (Standard_Integer i = 1; i <= nb; i ++) {
104 Standard_Integer numitem = theinditem.Value(i);
105 Standard_Integer finalindex = 0; // 0 sera pour remain
106 if (numitem > 0) {
107 //numit = numitem; //szv#4:S4163:12Mar99 not needed
108 DeclareAndCast(IGESData_IGESEntity,item,theitems.FindKey(numitem));
109 Standard_Boolean ok = Standard_False;
110 if (alsoframes) ok = (item->TypeNumber() == PourDrawing);
111 if (!ok) {
112 DeclareAndCast(IGESData_ViewKindEntity,view,item);
113 if (!view.IsNull()) ok = view->IsSingle();
114 }
115 if (ok) {
116 finalindex = thefinals.FindIndex(item);
117 if (finalindex <= 0) finalindex = thefinals.Add(item);
118 }
119 }
120 theindfin.SetValue(i,finalindex);
121 }
122}
123
124
125 void IGESSelect_ViewSorter::SortDrawings (const Interface_Graph& G)
126{
127// Pour chaque item (vue ou drawing), drawing contenant, silya (sinon tant pis)
128
129 thefinals.Clear();
130 Standard_Integer nb = theinditem.Length();
131 //Standard_Integer numit = 0; //szv#4:S4163:12Mar99 not needed
132 for (Standard_Integer i = 1; i <= nb; i ++) {
133 Standard_Integer numitem = theinditem.Value(i);
134 Standard_Integer finalindex = 0; // 0 sera pour remain
135 if (numitem > 0) {
136 //numit = numitem; //szv#4:S4163:12Mar99 not needed
137 DeclareAndCast(IGESData_IGESEntity,item,theitems.FindKey(numitem));
138 if (item.IsNull()) continue;
139// Si cest un Drawing, il definit le Set. Sinon, chercher Drawing contenant
140 Handle(Standard_Transient) drawing;
141 if (item->TypeNumber() == PourDrawing) drawing = item;
142 else {
143 Interface_EntityIterator list = G.Sharings(item);
144 for (list.Start(); list.More(); list.Next()) {
145 DeclareAndCast(IGESData_IGESEntity,draw,list.Value());
146 if (draw.IsNull()) continue;
147 if (draw->TypeNumber() == PourDrawing) drawing = draw;
148 }
149 }
150 if (!drawing.IsNull()) {
151 finalindex = thefinals.FindIndex(drawing);
152 if (finalindex <= 0) finalindex = thefinals.Add(drawing);
153 }
154 }
155 theindfin.SetValue(i,finalindex);
156 }
157}
158
159// .... Queries ....
160
161 Standard_Integer IGESSelect_ViewSorter::NbSets
162 (const Standard_Boolean final) const
163{
164 if (final) return thefinals.Extent();
165 else return theitems.Extent();
166}
167
168 Handle(IGESData_IGESEntity) IGESSelect_ViewSorter::SetItem
169 (const Standard_Integer num, const Standard_Boolean final) const
170{
171 if (final) return GetCasted(IGESData_IGESEntity,thefinals.FindKey(num));
172 else return GetCasted(IGESData_IGESEntity,theitems.FindKey(num));
173}
174
175 Handle(IFSelect_PacketList) IGESSelect_ViewSorter::Sets
176 (const Standard_Boolean final) const
177{
178 Handle(IFSelect_PacketList) list = new IFSelect_PacketList(themodel);
179 Standard_Integer i, nb;
180 nb = (final ? theindfin.Length() : theinditem.Length());
181 Standard_Integer nbs = NbSets(final);
182 for (Standard_Integer num = 1; num <= nbs; num ++) {
183 list->AddPacket();
184 if (final) {
185// Attention a l unicite
186 for (i = 1; i <= nb; i ++) {
187 if (theindfin.Value(i) != num) continue;
188 list->Add (themap.FindKey(i));
189 }
190 } else {
191 for (i = 1; i <= nb; i ++) {
192 if (theinditem.Value(i) != num) continue;
193 list->Add (themap.FindKey(i));
194 }
195 }
196 }
197 return list;
198}