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_SelectRange.hxx>
17 #include <Interface_InterfaceModel.hxx>
18 #include <Standard_DomainError.hxx>
19 #include <Standard_Transient.hxx>
20 #include <Standard_Type.hxx>
21 #include <TCollection_AsciiString.hxx>
24 IMPLEMENT_STANDARD_RTTIEXT(IFSelect_SelectRange,IFSelect_SelectExtract)
26 IFSelect_SelectRange::IFSelect_SelectRange () { }
28 void IFSelect_SelectRange::SetRange
29 (const Handle(IFSelect_IntParam)& rankfrom,
30 const Handle(IFSelect_IntParam)& rankto)
31 { thelower = rankfrom; theupper = rankto; }
33 void IFSelect_SelectRange::SetOne (const Handle(IFSelect_IntParam)& rank)
34 { thelower = theupper = rank; }
36 void IFSelect_SelectRange::SetFrom
37 (const Handle(IFSelect_IntParam)& rankfrom)
38 { thelower = rankfrom; theupper.Nullify(); }
40 void IFSelect_SelectRange::SetUntil
41 (const Handle(IFSelect_IntParam)& rankto)
42 { thelower.Nullify(); theupper = rankto; }
45 Standard_Boolean IFSelect_SelectRange::HasLower () const
46 { return (!thelower.IsNull()); }
48 Handle(IFSelect_IntParam) IFSelect_SelectRange::Lower () const
51 Standard_Integer IFSelect_SelectRange::LowerValue () const
53 if (thelower.IsNull()) return 0;
54 return thelower->Value();
57 Standard_Boolean IFSelect_SelectRange::HasUpper () const
58 { return (!theupper.IsNull()); }
60 Handle(IFSelect_IntParam) IFSelect_SelectRange::Upper () const
63 Standard_Integer IFSelect_SelectRange::UpperValue () const
65 if (theupper.IsNull()) return 0;
66 return theupper->Value();
69 Standard_Boolean IFSelect_SelectRange::Sort
70 (const Standard_Integer rank, const Handle(Standard_Transient)& ,
71 const Handle(Interface_InterfaceModel)& ) const
73 Standard_Integer rankfrom = 0;
74 if (!thelower.IsNull()) rankfrom = thelower->Value();
75 Standard_Integer rankto = 0;
76 if (!theupper.IsNull()) rankto = theupper->Value();
77 return (rank >= rankfrom && (rankto == 0 || rankto >= rank));
80 TCollection_AsciiString IFSelect_SelectRange::ExtractLabel () const
83 Standard_Integer rankfrom = 0;
84 if (!thelower.IsNull()) rankfrom = thelower->Value();
85 Standard_Integer rankto = 0;
86 if (!theupper.IsNull()) rankto = theupper->Value();
87 if (rankfrom == rankto) sprintf(lab,"Rank no %d",rankfrom);
88 else if (rankfrom == 0) sprintf(lab,"Until no %d",rankto);
89 else if (rankto == 0) sprintf(lab,"From no %d",rankto);
90 else sprintf(lab,"From %d Until %d",rankfrom,rankto);
92 return TCollection_AsciiString(lab);