summaryrefslogtreecommitdiff
path: root/src/IGESSelect/IGESSelect_CounterOfLevelNumber.cxx
blob: f0aa0474c0b5ffe291f0f9c9b5596b4a39fd799e (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <IGESSelect_CounterOfLevelNumber.ixx>
#include <IGESData_IGESEntity.hxx>
#include <IGESGraph_DefinitionLevel.hxx>
#include <Dico_DictionaryOfInteger.hxx>
#include <Interface_Macros.hxx>
#include <stdio.h>

#include <Message_Messenger.hxx>

    IGESSelect_CounterOfLevelNumber::IGESSelect_CounterOfLevelNumber
  (const Standard_Boolean withmap, const Standard_Boolean withlist)
    : IFSelect_SignCounter (withmap,withlist)
      {  thehigh = thenblists = 0;  SetName("IGES Level Number");  }

    void  IGESSelect_CounterOfLevelNumber::Clear ()
      {  IFSelect_SignCounter::Clear();
	 thelevels.Nullify();  thehigh = thenblists = 0;  }


    void  IGESSelect_CounterOfLevelNumber::AddSign
  (const Handle(Standard_Transient)& ent,
   const Handle(Interface_InterfaceModel)& /*model*/)
{
  DeclareAndCast(IGESData_IGESEntity,igesent,ent);
  if (igesent.IsNull()) return;
  DeclareAndCast(IGESGraph_DefinitionLevel,levelist,igesent->LevelList());
  Standard_Integer level = igesent->Level();
  if (levelist.IsNull() && level < 0) return;

//  Enregistrer ce/ces niveau(x)
  if (levelist.IsNull()) AddLevel(ent,level);
  else {
    Standard_Integer nb = levelist->NbPropertyValues();
    for (Standard_Integer i = 1; i <= nb; i ++) {
      level = levelist->LevelNumber(i);
      AddLevel(ent,level);
    }
    AddLevel(ent,-1);
  }
}


    void  IGESSelect_CounterOfLevelNumber::AddLevel
  (const Handle(Standard_Transient)& ent, const Standard_Integer level)
{
  if (level < 0) {
    thenblists ++;
    Add (ent,"LEVEL LIST");
    return;
  }
  if (thelevels.IsNull()) { thelevels =
    new TColStd_HArray1OfInteger ( 0, (level > 100 ? level : 100) );
			    thelevels->Init(0); }
  Standard_Integer upper = thelevels->Upper();
  if (level > upper) {
    Handle(TColStd_HArray1OfInteger) levels =
      new TColStd_HArray1OfInteger (0,level + 100);  levels->Init(0);
    for (Standard_Integer i = 1; i <= upper; i ++)
      levels->SetValue(i,thelevels->Value(i));
    thelevels = levels;
  }
  thelevels->SetValue (level,thelevels->Value(level)+1);
  if (level > thehigh) thehigh = level;

//  if (level == 0) Add(ent," NO LEVEL");
//  else {
    char signature[30];
    sprintf (signature,"%7d",level);
    Add (ent,signature);
//  }
}


    Standard_Integer  IGESSelect_CounterOfLevelNumber::HighestLevel () const
      {  return thehigh;  }

    Standard_Integer  IGESSelect_CounterOfLevelNumber::NbTimesLevel
  (const Standard_Integer level) const
{
  if (level < 0) return thenblists;
  if (level > thehigh) return 0;
  return thelevels->Value(level);
}


    Handle(TColStd_HSequenceOfInteger)  IGESSelect_CounterOfLevelNumber::Levels
  () const
{
  Handle(TColStd_HSequenceOfInteger) list = new TColStd_HSequenceOfInteger ();
  for (Standard_Integer i = 1; i <= thehigh; i ++) {
    if (thelevels->Value(i) > 0) list->Append(i);
  }
  return list;
}


    Handle(TCollection_HAsciiString)  IGESSelect_CounterOfLevelNumber::Sign
  (const Handle(Standard_Transient)& ent,
   const Handle(Interface_InterfaceModel)& /*model*/) const
{
  Handle(TCollection_HAsciiString) res;
//  reprend les termes de AddSign pour la preparation (lecture du level) ...
  DeclareAndCast(IGESData_IGESEntity,igesent,ent);
  if (igesent.IsNull()) return res;
  DeclareAndCast(IGESGraph_DefinitionLevel,levelist,igesent->LevelList());
  Standard_Integer level = igesent->Level();
  if (levelist.IsNull() && level < 0) return res;

//  puis ceux de AddLevel pour calculer la signature
  if (level < 0) return new TCollection_HAsciiString ("LEVEL LIST");
  char signature[30];
  sprintf (signature,"%7d",level);
  return new TCollection_HAsciiString (signature);
}


    void  IGESSelect_CounterOfLevelNumber::PrintCount
  (const Handle(Message_Messenger)& S) const
{
  IFSelect_SignatureList::PrintCount(S);
  S<<" Highest value : " << thehigh << endl;
  if (thenblists > 0) S<<"REMARK for LEVEL LIST : Entities are counted in"
    <<" <LEVEL LIST>\n, and in each Level value of their list"<<endl;
}