0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / IFSelect / IFSelect_SelectAnyList.cxx
... / ...
CommitLineData
1// Copyright (c) 1999-2014 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
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.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14
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>
24
25#include <stdio.h>
26IMPLEMENT_STANDARD_RTTIEXT(IFSelect_SelectAnyList,IFSelect_SelectDeduct)
27
28// .... Definition de liste : methodes "deferred" NbItems & FillResult
29void IFSelect_SelectAnyList::SetRange
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
75 if (input.NbEntities() > 1) Interface_InterfaceError::Raise
76 ("SelectAnyList : more than ONE Entity in input");
77 if (input.NbEntities() == 0) return input;
78
79 Handle(Standard_Transient) ent;
80 for (input.Start(); input.More(); input.Next()) ent = input.Value();
81
82 Standard_Integer rankmax = NbItems(ent);
83 Standard_Integer rankfrom = 1;
84 if (!thelower.IsNull()) rankfrom = thelower->Value();
85 Standard_Integer rankto;
86 if (!theupper.IsNull()) rankto = theupper->Value();
87 else rankto = rankmax;
88 if (rankfrom < 1) rankfrom = 1;
89 if (rankto > rankmax) rankto = rankmax;
90
91 Interface_EntityIterator iter;
92 if (rankfrom <= rankto) FillResult(rankfrom,rankto,ent,iter);
93 return iter;
94}
95
96
97 TCollection_AsciiString IFSelect_SelectAnyList::Label () const
98{
99 char lab[30];
100 Standard_Integer rankfrom = 0;
101 if (HasLower()) rankfrom = LowerValue();
102 Standard_Integer rankto = 0;
103 if (HasUpper()) rankto = UpperValue();
104 if (rankfrom == rankto) sprintf(lab," (no %d)",rankfrom);
105 else if (rankfrom == 0) sprintf(lab," (-> %d)",rankfrom);
106 else if (rankto == 0) sprintf(lab," (%d ->)",rankto);
107 else sprintf(lab," (%d -> %d)",rankfrom,rankto);
108
109 TCollection_AsciiString labl("In List ");
110 labl.AssignCat(ListLabel());
111 labl.AssignCat(lab);
112 return labl;
113}