1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
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>
24 IFSelect_SelectExplore::IFSelect_SelectExplore (const Standard_Integer level)
25 : thelevel (level) { }
28 Standard_Integer IFSelect_SelectExplore::Level () const
32 Interface_EntityIterator IFSelect_SelectExplore::RootResult
33 (const Interface_Graph& G) const
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
47 Standard_Integer nb = G.Size();
48 TColStd_IndexedMapOfTransient entrees (nb);
49 TColStd_IndexedMapOfTransient result (nb);
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();
58 for (i = 1; i <= nb; i ++) {
59 if (i > entrees.Extent()) break;
62 if (level > thelevel && thelevel > 0) break;
63 ilev = entrees.Extent();
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;
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) {
75 } else if (level == thelevel) {
76 for (exp.Start(); exp.More(); exp.Next()) j = result.Add (exp.Value());
78 for (exp.Start(); exp.More(); exp.Next()) j = entrees.Add (exp.Value());
82 // On recolte le resultat
83 Interface_EntityIterator res;
85 for (j = 1; j <= nb; j ++) res.AddItem (result.FindKey(j));
90 TCollection_AsciiString IFSelect_SelectExplore::Label () const
92 TCollection_AsciiString labl;
93 if (thelevel == 0) labl.AssignCat("(Recursive)");
94 else if (thelevel > 0) {
96 sprintf (lab,"(Level %d)",thelevel);
99 labl.AssignCat(ExploreLabel());