summaryrefslogtreecommitdiff
path: root/src/IFSelect/IFSelect_SelectAnyList.cxx
blob: eba1b1a75737e4bc56147cdf5fa57542d09b4f64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <IFSelect_SelectAnyList.ixx>
#include <Interface_InterfaceError.hxx>
#include <stdio.h>

// ....    Definition de liste : methodes "deferred" NbItems & FillResult


    void  IFSelect_SelectAnyList::SetRange
  (const Handle(IFSelect_IntParam)& rankfrom,
   const Handle(IFSelect_IntParam)& rankto)
      {  thelower = rankfrom;  theupper = rankto;  }

    void  IFSelect_SelectAnyList::SetOne (const Handle(IFSelect_IntParam)& rank)
      {  thelower = theupper = rank;  }

    void  IFSelect_SelectAnyList::SetFrom
  (const Handle(IFSelect_IntParam)& rankfrom)
      {  thelower = rankfrom;  theupper.Nullify();  }

    void  IFSelect_SelectAnyList::SetUntil
  (const Handle(IFSelect_IntParam)& rankto)
      {  thelower.Nullify();  theupper = rankto;  }

    Standard_Boolean  IFSelect_SelectAnyList::HasLower () const 
      {  return (!thelower.IsNull());  }

    Handle(IFSelect_IntParam)  IFSelect_SelectAnyList::Lower () const 
      {  return thelower;  }

    Standard_Integer  IFSelect_SelectAnyList::LowerValue () const 
{
  if (thelower.IsNull()) return 0;
  return thelower->Value();
}

    Standard_Boolean  IFSelect_SelectAnyList::HasUpper () const 
      {  return (!theupper.IsNull());  }

    Handle(IFSelect_IntParam)  IFSelect_SelectAnyList::Upper () const 
      {  return theupper;  }

    Standard_Integer  IFSelect_SelectAnyList::UpperValue () const 
{
  if (theupper.IsNull()) return 0;
  return theupper->Value();
}

//  On prend les sous-entites de lower a upper (inclus)
    Interface_EntityIterator IFSelect_SelectAnyList::RootResult
  (const Interface_Graph& G) const
{
  Interface_EntityIterator input = InputResult(G);
  KeepInputEntity (input);    // selon type voulu
  if (input.NbEntities() > 1) Interface_InterfaceError::Raise
    ("SelectAnyList : more than ONE Entity in input");
  if (input.NbEntities() == 0) return input;

  Handle(Standard_Transient) ent;
  for (input.Start(); input.More(); input.Next())    ent = input.Value();

  Standard_Integer rankmax = NbItems(ent);
  Standard_Integer rankfrom = 1;
  if (!thelower.IsNull()) rankfrom = thelower->Value();
  Standard_Integer rankto;
  if (!theupper.IsNull()) rankto   = theupper->Value();
  else rankto = rankmax;
  if (rankfrom < 1) rankfrom = 1;
  if (rankto > rankmax) rankto = rankmax;

  Interface_EntityIterator iter;
  if (rankfrom <= rankto) FillResult(rankfrom,rankto,ent,iter);
  return iter;
}


    TCollection_AsciiString  IFSelect_SelectAnyList::Label () const 
{
  char lab[30];
  Standard_Integer rankfrom = 0;
  if (HasLower())  rankfrom = LowerValue();
  Standard_Integer rankto   = 0;
  if (HasUpper())  rankto   = UpperValue();
  if (rankfrom == rankto) sprintf(lab," (no %d)",rankfrom);
  else if (rankfrom == 0) sprintf(lab," (-> %d)",rankfrom);
  else if (rankto   == 0) sprintf(lab," (%d ->)",rankto);
  else                    sprintf(lab," (%d -> %d)",rankfrom,rankto);

  TCollection_AsciiString labl("In List ");
  labl.AssignCat(ListLabel());
  labl.AssignCat(lab);
  return labl;
}