0026781: Coding rules - eliminate GCC warning -Wunused-result
[occt.git] / src / IFSelect / IFSelect_SelectExplore.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <IFSelect_SelectExplore.hxx>
16 #include <Interface_EntityIterator.hxx>
17 #include <Interface_Graph.hxx>
18 #include <Standard_Transient.hxx>
19 #include <Standard_Type.hxx>
20 #include <TCollection_AsciiString.hxx>
21 #include <TColStd_IndexedMapOfTransient.hxx>
22
23 #include <stdio.h>
24 IFSelect_SelectExplore::IFSelect_SelectExplore (const Standard_Integer level)
25 : thelevel (level)    {  }
26
27
28     Standard_Integer  IFSelect_SelectExplore::Level () const
29       {  return thelevel;  }
30
31
32     Interface_EntityIterator  IFSelect_SelectExplore::RootResult
33   (const Interface_Graph& G) const
34 {
35 //  Attention, voila comme on procede
36 //  On a une IndexedMapOfTransient en entree (entites deja traitees/a traiter)
37 //    Elle est initialisee par InputResult
38 //  Et une map en sortie (resultats pris) -> le resultat sera unique
39 //  En entree, un curseur d entite courante
40 //  Pour chaque entite, on appelle Explore. 3 cas possibles :
41 //    retour False, on passe
42 //    retour True et liste vide, on prend cette entite sans aller plus loin
43 //    retour True et liste non vide, on ne prend pas cette entite mais on
44 //      considere son resultat.
45 //      Si dernier niveau, on le prend en entier. Sinon, il alimente l entree
46
47   Standard_Integer nb = G.Size();
48   TColStd_IndexedMapOfTransient entrees (nb);
49   TColStd_IndexedMapOfTransient result  (nb);
50 //  Initialisation
51   Standard_Integer i, j, level = 1, ilev = 0;
52   Interface_EntityIterator input; input = InputResult(G);
53   for (input.Start(); input.More(); input.Next())
54     i = entrees.Add (input.Value());
55   ilev = entrees.Extent();
56
57 // Exploration
58   for (i = 1; i <= nb; i ++) {
59     if (i > entrees.Extent()) break;
60     if (i > ilev)  {
61       level ++;
62       if (level > thelevel && thelevel > 0) break;
63       ilev = entrees.Extent();
64     }
65     Handle(Standard_Transient) ent = entrees.FindKey(i);
66     if (ent.IsNull()) continue;
67     Interface_EntityIterator exp;
68     if (!Explore (level,ent,G,exp)) continue;
69
70 //  On prend en compte : entite a prendre directement ?
71 //  reprendre liste en entree (niveau pas atteint) ou resultat (niveau atteint)
72     if (exp.NbEntities() == 0) {
73       j = result.Add (ent);
74       continue;
75     } else if (level == thelevel) {
76       for (exp.Start(); exp.More(); exp.Next()) j = result.Add (exp.Value());
77     } else {
78       for (exp.Start(); exp.More(); exp.Next()) j = entrees.Add (exp.Value());
79     }
80   }
81
82 //  On recolte le resultat
83   Interface_EntityIterator res;
84   nb = result.Extent();
85   for (j = 1; j <= nb; j ++) res.AddItem (result.FindKey(j));
86   return res;
87 }
88
89
90     TCollection_AsciiString  IFSelect_SelectExplore::Label () const
91 {
92   TCollection_AsciiString labl;
93   if (thelevel == 0) labl.AssignCat("(Recursive)");
94   else if (thelevel > 0) {
95     char lab[30];
96     sprintf (lab,"(Level %d)",thelevel);
97     labl.AssignCat(lab);
98   }
99   labl.AssignCat(ExploreLabel());
100   return labl;
101 }