973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | |
42cf5bc1 |
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> |
7fd59977 |
22 | |
42cf5bc1 |
23 | #include <stdio.h> |
92efcf78 |
24 | IMPLEMENT_STANDARD_RTTIEXT(IFSelect_SelectExplore,IFSelect_SelectDeduct) |
25 | |
7fd59977 |
26 | IFSelect_SelectExplore::IFSelect_SelectExplore (const Standard_Integer level) |
27 | : thelevel (level) { } |
28 | |
29 | |
30 | Standard_Integer IFSelect_SelectExplore::Level () const |
31 | { return thelevel; } |
32 | |
33 | |
34 | Interface_EntityIterator IFSelect_SelectExplore::RootResult |
35 | (const Interface_Graph& G) const |
36 | { |
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 |
48 | |
49 | Standard_Integer nb = G.Size(); |
50 | TColStd_IndexedMapOfTransient entrees (nb); |
51 | TColStd_IndexedMapOfTransient result (nb); |
52 | // Initialisation |
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(); |
58 | |
59 | // Exploration |
60 | for (i = 1; i <= nb; i ++) { |
61 | if (i > entrees.Extent()) break; |
62 | if (i > ilev) { |
63 | level ++; |
64 | if (level > thelevel && thelevel > 0) break; |
65 | ilev = entrees.Extent(); |
66 | } |
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; |
71 | |
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) { |
75 | j = result.Add (ent); |
76 | continue; |
77 | } else if (level == thelevel) { |
78 | for (exp.Start(); exp.More(); exp.Next()) j = result.Add (exp.Value()); |
79 | } else { |
80 | for (exp.Start(); exp.More(); exp.Next()) j = entrees.Add (exp.Value()); |
81 | } |
82 | } |
83 | |
84 | // On recolte le resultat |
85 | Interface_EntityIterator res; |
86 | nb = result.Extent(); |
87 | for (j = 1; j <= nb; j ++) res.AddItem (result.FindKey(j)); |
88 | return res; |
89 | } |
90 | |
91 | |
92 | TCollection_AsciiString IFSelect_SelectExplore::Label () const |
93 | { |
94 | TCollection_AsciiString labl; |
95 | if (thelevel == 0) labl.AssignCat("(Recursive)"); |
96 | else if (thelevel > 0) { |
97 | char lab[30]; |
98 | sprintf (lab,"(Level %d)",thelevel); |
99 | labl.AssignCat(lab); |
100 | } |
101 | labl.AssignCat(ExploreLabel()); |
102 | return labl; |
103 | } |