| 1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
| 2 | // |
| 3 | // The content of this file is subject to the Open CASCADE Technology Public |
| 4 | // License Version 6.5 (the "License"). You may not use the content of this file |
| 5 | // except in compliance with the License. Please obtain a copy of the License |
| 6 | // at http://www.opencascade.org and read it completely before using this file. |
| 7 | // |
| 8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
| 9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
| 10 | // |
| 11 | // The Original Code and all software distributed under the License is |
| 12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
| 13 | // Initial Developer hereby disclaims all such warranties, including without |
| 14 | // limitation, any warranties of merchantability, fitness for a particular |
| 15 | // purpose or non-infringement. Please see the License for the specific terms |
| 16 | // and conditions governing the rights and limitations under the License. |
| 17 | |
| 18 | #include <IFSelect_SelectExplore.ixx> |
| 19 | #include <TColStd_IndexedMapOfTransient.hxx> |
| 20 | #include <stdio.h> |
| 21 | |
| 22 | |
| 23 | IFSelect_SelectExplore::IFSelect_SelectExplore (const Standard_Integer level) |
| 24 | : thelevel (level) { } |
| 25 | |
| 26 | |
| 27 | Standard_Integer IFSelect_SelectExplore::Level () const |
| 28 | { return thelevel; } |
| 29 | |
| 30 | |
| 31 | Interface_EntityIterator IFSelect_SelectExplore::RootResult |
| 32 | (const Interface_Graph& G) const |
| 33 | { |
| 34 | // Attention, voila comme on procede |
| 35 | // On a une IndexedMapOfTransient en entree (entites deja traitees/a traiter) |
| 36 | // Elle est initialisee par InputResult |
| 37 | // Et une map en sortie (resultats pris) -> le resultat sera unique |
| 38 | // En entree, un curseur d entite courante |
| 39 | // Pour chaque entite, on appelle Explore. 3 cas possibles : |
| 40 | // retour False, on passe |
| 41 | // retour True et liste vide, on prend cette entite sans aller plus loin |
| 42 | // retour True et liste non vide, on ne prend pas cette entite mais on |
| 43 | // considere son resultat. |
| 44 | // Si dernier niveau, on le prend en entier. Sinon, il alimente l entree |
| 45 | |
| 46 | Standard_Integer nb = G.Size(); |
| 47 | TColStd_IndexedMapOfTransient entrees (nb); |
| 48 | TColStd_IndexedMapOfTransient result (nb); |
| 49 | // Initialisation |
| 50 | Standard_Integer i, j, level = 1, ilev = 0; |
| 51 | Interface_EntityIterator input; input = InputResult(G); |
| 52 | for (input.Start(); input.More(); input.Next()) |
| 53 | i = entrees.Add (input.Value()); |
| 54 | ilev = entrees.Extent(); |
| 55 | |
| 56 | // Exploration |
| 57 | for (i = 1; i <= nb; i ++) { |
| 58 | if (i > entrees.Extent()) break; |
| 59 | if (i > ilev) { |
| 60 | level ++; |
| 61 | if (level > thelevel && thelevel > 0) break; |
| 62 | ilev = entrees.Extent(); |
| 63 | } |
| 64 | Handle(Standard_Transient) ent = entrees.FindKey(i); |
| 65 | if (ent.IsNull()) continue; |
| 66 | Interface_EntityIterator exp; |
| 67 | if (!Explore (level,ent,G,exp)) continue; |
| 68 | |
| 69 | // On prend en compte : entite a prendre directement ? |
| 70 | // reprendre liste en entree (niveau pas atteint) ou resultat (niveau atteint) |
| 71 | if (exp.NbEntities() == 0) { |
| 72 | j = result.Add (ent); |
| 73 | continue; |
| 74 | } else if (level == thelevel) { |
| 75 | for (exp.Start(); exp.More(); exp.Next()) j = result.Add (exp.Value()); |
| 76 | } else { |
| 77 | for (exp.Start(); exp.More(); exp.Next()) j = entrees.Add (exp.Value()); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // On recolte le resultat |
| 82 | Interface_EntityIterator res; |
| 83 | nb = result.Extent(); |
| 84 | for (j = 1; j <= nb; j ++) res.AddItem (result.FindKey(j)); |
| 85 | return res; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | TCollection_AsciiString IFSelect_SelectExplore::Label () const |
| 90 | { |
| 91 | TCollection_AsciiString labl; |
| 92 | if (thelevel == 0) labl.AssignCat("(Recursive)"); |
| 93 | else if (thelevel > 0) { |
| 94 | char lab[30]; |
| 95 | sprintf (lab,"(Level %d)",thelevel); |
| 96 | labl.AssignCat(lab); |
| 97 | } |
| 98 | labl.AssignCat(ExploreLabel()); |
| 99 | return labl; |
| 100 | } |