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 | |
42cf5bc1 |
14 | |
15 | #include <IFSelect_IntParam.hxx> |
16 | #include <IFSelect_SelectAnyList.hxx> |
17 | #include <Interface_EntityIterator.hxx> |
18 | #include <Interface_Graph.hxx> |
7fd59977 |
19 | #include <Interface_InterfaceError.hxx> |
42cf5bc1 |
20 | #include <Standard_OutOfRange.hxx> |
21 | #include <Standard_Transient.hxx> |
22 | #include <Standard_Type.hxx> |
23 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
24 | |
42cf5bc1 |
25 | #include <stdio.h> |
92efcf78 |
26 | IMPLEMENT_STANDARD_RTTIEXT(IFSelect_SelectAnyList,IFSelect_SelectDeduct) |
27 | |
7fd59977 |
28 | // .... Definition de liste : methodes "deferred" NbItems & FillResult |
b311480e |
29 | void IFSelect_SelectAnyList::SetRange |
7fd59977 |
30 | (const Handle(IFSelect_IntParam)& rankfrom, |
31 | const Handle(IFSelect_IntParam)& rankto) |
32 | { thelower = rankfrom; theupper = rankto; } |
33 | |
34 | void IFSelect_SelectAnyList::SetOne (const Handle(IFSelect_IntParam)& rank) |
35 | { thelower = theupper = rank; } |
36 | |
37 | void IFSelect_SelectAnyList::SetFrom |
38 | (const Handle(IFSelect_IntParam)& rankfrom) |
39 | { thelower = rankfrom; theupper.Nullify(); } |
40 | |
41 | void IFSelect_SelectAnyList::SetUntil |
42 | (const Handle(IFSelect_IntParam)& rankto) |
43 | { thelower.Nullify(); theupper = rankto; } |
44 | |
45 | Standard_Boolean IFSelect_SelectAnyList::HasLower () const |
46 | { return (!thelower.IsNull()); } |
47 | |
48 | Handle(IFSelect_IntParam) IFSelect_SelectAnyList::Lower () const |
49 | { return thelower; } |
50 | |
51 | Standard_Integer IFSelect_SelectAnyList::LowerValue () const |
52 | { |
53 | if (thelower.IsNull()) return 0; |
54 | return thelower->Value(); |
55 | } |
56 | |
57 | Standard_Boolean IFSelect_SelectAnyList::HasUpper () const |
58 | { return (!theupper.IsNull()); } |
59 | |
60 | Handle(IFSelect_IntParam) IFSelect_SelectAnyList::Upper () const |
61 | { return theupper; } |
62 | |
63 | Standard_Integer IFSelect_SelectAnyList::UpperValue () const |
64 | { |
65 | if (theupper.IsNull()) return 0; |
66 | return theupper->Value(); |
67 | } |
68 | |
69 | // On prend les sous-entites de lower a upper (inclus) |
70 | Interface_EntityIterator IFSelect_SelectAnyList::RootResult |
71 | (const Interface_Graph& G) const |
72 | { |
73 | Interface_EntityIterator input = InputResult(G); |
74 | KeepInputEntity (input); // selon type voulu |
9775fa61 |
75 | if (input.NbEntities() > 1) throw Interface_InterfaceError("SelectAnyList : more than ONE Entity in input"); |
7fd59977 |
76 | if (input.NbEntities() == 0) return input; |
77 | |
78 | Handle(Standard_Transient) ent; |
79 | for (input.Start(); input.More(); input.Next()) ent = input.Value(); |
80 | |
81 | Standard_Integer rankmax = NbItems(ent); |
82 | Standard_Integer rankfrom = 1; |
83 | if (!thelower.IsNull()) rankfrom = thelower->Value(); |
84 | Standard_Integer rankto; |
85 | if (!theupper.IsNull()) rankto = theupper->Value(); |
86 | else rankto = rankmax; |
87 | if (rankfrom < 1) rankfrom = 1; |
88 | if (rankto > rankmax) rankto = rankmax; |
89 | |
90 | Interface_EntityIterator iter; |
91 | if (rankfrom <= rankto) FillResult(rankfrom,rankto,ent,iter); |
92 | return iter; |
93 | } |
94 | |
95 | |
96 | TCollection_AsciiString IFSelect_SelectAnyList::Label () const |
97 | { |
98 | char lab[30]; |
99 | Standard_Integer rankfrom = 0; |
100 | if (HasLower()) rankfrom = LowerValue(); |
101 | Standard_Integer rankto = 0; |
102 | if (HasUpper()) rankto = UpperValue(); |
103 | if (rankfrom == rankto) sprintf(lab," (no %d)",rankfrom); |
104 | else if (rankfrom == 0) sprintf(lab," (-> %d)",rankfrom); |
105 | else if (rankto == 0) sprintf(lab," (%d ->)",rankto); |
106 | else sprintf(lab," (%d -> %d)",rankfrom,rankto); |
107 | |
108 | TCollection_AsciiString labl("In List "); |
109 | labl.AssignCat(ListLabel()); |
110 | labl.AssignCat(lab); |
111 | return labl; |
112 | } |