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 IMPLEMENT_STANDARD_RTTIEXT(IFSelect_SelectExplore,IFSelect_SelectDeduct)
26 IFSelect_SelectExplore::IFSelect_SelectExplore (const Standard_Integer level)
27 : thelevel (level) { }
30 Standard_Integer IFSelect_SelectExplore::Level () const
34 Interface_EntityIterator IFSelect_SelectExplore::RootResult
35 (const Interface_Graph& G) const
37 // Attention, voila comme on procede
38 // On a une IndexedMapOfTransient en entree (entites deja traitees/a traiter)
39 // Elle est initialisee par InputResult
40 // Et une map en sortie (resultats pris) -> le resultat sera unique
41 // En entree, un curseur d entite courante
42 // Pour chaque entite, on appelle Explore. 3 cas possibles :
43 // retour False, on passe
44 // retour True et liste vide, on prend cette entite sans aller plus loin
45 // retour True et liste non vide, on ne prend pas cette entite mais on
46 // considere son resultat.
47 // Si dernier niveau, on le prend en entier. Sinon, il alimente l entree
49 Standard_Integer nb = G.Size();
50 TColStd_IndexedMapOfTransient entrees (nb);
51 TColStd_IndexedMapOfTransient result (nb);
53 Standard_Integer i, j, level = 1, ilev = 0;
54 Interface_EntityIterator input; input = InputResult(G);
55 for (input.Start(); input.More(); input.Next())
56 i = entrees.Add (input.Value());
57 ilev = entrees.Extent();
60 for (i = 1; i <= nb; i ++) {
61 if (i > entrees.Extent()) break;
64 if (level > thelevel && thelevel > 0) break;
65 ilev = entrees.Extent();
67 Handle(Standard_Transient) ent = entrees.FindKey(i);
68 if (ent.IsNull()) continue;
69 Interface_EntityIterator exp;
70 if (!Explore (level,ent,G,exp)) continue;
72 // On prend en compte : entite a prendre directement ?
73 // reprendre liste en entree (niveau pas atteint) ou resultat (niveau atteint)
74 if (exp.NbEntities() == 0) {
77 } else if (level == thelevel) {
78 for (exp.Start(); exp.More(); exp.Next()) j = result.Add (exp.Value());
80 for (exp.Start(); exp.More(); exp.Next()) j = entrees.Add (exp.Value());
84 // On recolte le resultat
85 Interface_EntityIterator res;
87 for (j = 1; j <= nb; j ++) res.AddItem (result.FindKey(j));
92 TCollection_AsciiString IFSelect_SelectExplore::Label () const
94 TCollection_AsciiString labl;
95 if (thelevel == 0) labl.AssignCat("(Recursive)");
96 else if (thelevel > 0) {
98 sprintf (lab,"(Level %d)",thelevel);
101 labl.AssignCat(ExploreLabel());