0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / IGESSelect / IGESSelect_CounterOfLevelNumber.cxx
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 <Dico_DictionaryOfInteger.hxx>
16 #include <IGESData_IGESEntity.hxx>
17 #include <IGESGraph_DefinitionLevel.hxx>
18 #include <IGESSelect_CounterOfLevelNumber.hxx>
19 #include <Interface_InterfaceModel.hxx>
20 #include <Interface_Macros.hxx>
21 #include <Message_Messenger.hxx>
22 #include <Standard_Transient.hxx>
23 #include <Standard_Type.hxx>
24 #include <TCollection_HAsciiString.hxx>
25
26 #include <stdio.h>
27 IMPLEMENT_STANDARD_RTTIEXT(IGESSelect_CounterOfLevelNumber,IFSelect_SignCounter)
28
29 IGESSelect_CounterOfLevelNumber::IGESSelect_CounterOfLevelNumber
30   (const Standard_Boolean withmap, const Standard_Boolean withlist)
31     : IFSelect_SignCounter (withmap,withlist)
32       {  thehigh = thenblists = 0;  SetName("IGES Level Number");  }
33
34     void  IGESSelect_CounterOfLevelNumber::Clear ()
35       {  IFSelect_SignCounter::Clear();
36          thelevels.Nullify();  thehigh = thenblists = 0;  }
37
38
39     void  IGESSelect_CounterOfLevelNumber::AddSign
40   (const Handle(Standard_Transient)& ent,
41    const Handle(Interface_InterfaceModel)& /*model*/)
42 {
43   DeclareAndCast(IGESData_IGESEntity,igesent,ent);
44   if (igesent.IsNull()) return;
45   DeclareAndCast(IGESGraph_DefinitionLevel,levelist,igesent->LevelList());
46   Standard_Integer level = igesent->Level();
47   if (levelist.IsNull() && level < 0) return;
48
49 //  Enregistrer ce/ces niveau(x)
50   if (levelist.IsNull()) AddLevel(ent,level);
51   else {
52     Standard_Integer nb = levelist->NbPropertyValues();
53     for (Standard_Integer i = 1; i <= nb; i ++) {
54       level = levelist->LevelNumber(i);
55       AddLevel(ent,level);
56     }
57     AddLevel(ent,-1);
58   }
59 }
60
61
62     void  IGESSelect_CounterOfLevelNumber::AddLevel
63   (const Handle(Standard_Transient)& ent, const Standard_Integer level)
64 {
65   if (level < 0) {
66     thenblists ++;
67     Add (ent,"LEVEL LIST");
68     return;
69   }
70   if (thelevels.IsNull()) { thelevels =
71     new TColStd_HArray1OfInteger ( 0, (level > 100 ? level : 100) );
72                             thelevels->Init(0); }
73   Standard_Integer upper = thelevels->Upper();
74   if (level > upper) {
75     Handle(TColStd_HArray1OfInteger) levels =
76       new TColStd_HArray1OfInteger (0,level + 100);  levels->Init(0);
77     for (Standard_Integer i = 1; i <= upper; i ++)
78       levels->SetValue(i,thelevels->Value(i));
79     thelevels = levels;
80   }
81   thelevels->SetValue (level,thelevels->Value(level)+1);
82   if (level > thehigh) thehigh = level;
83
84 //  if (level == 0) Add(ent," NO LEVEL");
85 //  else {
86     char signature[30];
87     sprintf (signature,"%7d",level);
88     Add (ent,signature);
89 //  }
90 }
91
92
93     Standard_Integer  IGESSelect_CounterOfLevelNumber::HighestLevel () const
94       {  return thehigh;  }
95
96     Standard_Integer  IGESSelect_CounterOfLevelNumber::NbTimesLevel
97   (const Standard_Integer level) const
98 {
99   if (level < 0) return thenblists;
100   if (level > thehigh) return 0;
101   return thelevels->Value(level);
102 }
103
104
105     Handle(TColStd_HSequenceOfInteger)  IGESSelect_CounterOfLevelNumber::Levels
106   () const
107 {
108   Handle(TColStd_HSequenceOfInteger) list = new TColStd_HSequenceOfInteger ();
109   for (Standard_Integer i = 1; i <= thehigh; i ++) {
110     if (thelevels->Value(i) > 0) list->Append(i);
111   }
112   return list;
113 }
114
115
116     Handle(TCollection_HAsciiString)  IGESSelect_CounterOfLevelNumber::Sign
117   (const Handle(Standard_Transient)& ent,
118    const Handle(Interface_InterfaceModel)& /*model*/) const
119 {
120   Handle(TCollection_HAsciiString) res;
121 //  reprend les termes de AddSign pour la preparation (lecture du level) ...
122   DeclareAndCast(IGESData_IGESEntity,igesent,ent);
123   if (igesent.IsNull()) return res;
124   DeclareAndCast(IGESGraph_DefinitionLevel,levelist,igesent->LevelList());
125   Standard_Integer level = igesent->Level();
126   if (levelist.IsNull() && level < 0) return res;
127
128 //  puis ceux de AddLevel pour calculer la signature
129   if (level < 0) return new TCollection_HAsciiString ("LEVEL LIST");
130   char signature[30];
131   sprintf (signature,"%7d",level);
132   return new TCollection_HAsciiString (signature);
133 }
134
135
136     void  IGESSelect_CounterOfLevelNumber::PrintCount
137   (const Handle(Message_Messenger)& S) const
138 {
139   IFSelect_SignatureList::PrintCount(S);
140   S<<" Highest value : " << thehigh << endl;
141   if (thenblists > 0) S<<"REMARK for LEVEL LIST : Entities are counted in"
142     <<" <LEVEL LIST>\n, and in each Level value of their list"<<endl;
143 }