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_IntParam.hxx>
16 #include <IFSelect_SelectAnyList.hxx>
17 #include <Interface_EntityIterator.hxx>
18 #include <Interface_Graph.hxx>
19 #include <Interface_InterfaceError.hxx>
20 #include <Standard_OutOfRange.hxx>
21 #include <Standard_Transient.hxx>
22 #include <Standard_Type.hxx>
23 #include <TCollection_AsciiString.hxx>
26 IMPLEMENT_STANDARD_RTTIEXT(IFSelect_SelectAnyList,IFSelect_SelectDeduct)
28 // .... Definition de liste : methodes "deferred" NbItems & FillResult
29 void IFSelect_SelectAnyList::SetRange
30 (const Handle(IFSelect_IntParam)& rankfrom,
31 const Handle(IFSelect_IntParam)& rankto)
32 { thelower = rankfrom; theupper = rankto; }
34 void IFSelect_SelectAnyList::SetOne (const Handle(IFSelect_IntParam)& rank)
35 { thelower = theupper = rank; }
37 void IFSelect_SelectAnyList::SetFrom
38 (const Handle(IFSelect_IntParam)& rankfrom)
39 { thelower = rankfrom; theupper.Nullify(); }
41 void IFSelect_SelectAnyList::SetUntil
42 (const Handle(IFSelect_IntParam)& rankto)
43 { thelower.Nullify(); theupper = rankto; }
45 Standard_Boolean IFSelect_SelectAnyList::HasLower () const
46 { return (!thelower.IsNull()); }
48 Handle(IFSelect_IntParam) IFSelect_SelectAnyList::Lower () const
51 Standard_Integer IFSelect_SelectAnyList::LowerValue () const
53 if (thelower.IsNull()) return 0;
54 return thelower->Value();
57 Standard_Boolean IFSelect_SelectAnyList::HasUpper () const
58 { return (!theupper.IsNull()); }
60 Handle(IFSelect_IntParam) IFSelect_SelectAnyList::Upper () const
63 Standard_Integer IFSelect_SelectAnyList::UpperValue () const
65 if (theupper.IsNull()) return 0;
66 return theupper->Value();
69 // On prend les sous-entites de lower a upper (inclus)
70 Interface_EntityIterator IFSelect_SelectAnyList::RootResult
71 (const Interface_Graph& G) const
73 Interface_EntityIterator input = InputResult(G);
74 KeepInputEntity (input); // selon type voulu
75 if (input.NbEntities() > 1) throw Interface_InterfaceError("SelectAnyList : more than ONE Entity in input");
76 if (input.NbEntities() == 0) return input;
78 Handle(Standard_Transient) ent;
79 for (input.Start(); input.More(); input.Next()) ent = input.Value();
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;
90 Interface_EntityIterator iter;
91 if (rankfrom <= rankto) FillResult(rankfrom,rankto,ent,iter);
96 TCollection_AsciiString IFSelect_SelectAnyList::Label () const
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);
108 TCollection_AsciiString labl("In List ");
109 labl.AssignCat(ListLabel());