0024428: Implementation of LGPL license
[occt.git] / src / IGESSelect / IGESSelect_CounterOfLevelNumber.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
973c2be1 5// This library is free software; you can redistribute it and / or modify it
6// under the terms of the GNU Lesser General Public 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14#include <IGESSelect_CounterOfLevelNumber.ixx>
15#include <IGESData_IGESEntity.hxx>
16#include <IGESGraph_DefinitionLevel.hxx>
17#include <Dico_DictionaryOfInteger.hxx>
18#include <Interface_Macros.hxx>
19#include <stdio.h>
20
21#include <Message_Messenger.hxx>
22
b311480e 23IGESSelect_CounterOfLevelNumber::IGESSelect_CounterOfLevelNumber
7fd59977 24 (const Standard_Boolean withmap, const Standard_Boolean withlist)
25 : IFSelect_SignCounter (withmap,withlist)
26 { thehigh = thenblists = 0; SetName("IGES Level Number"); }
27
28 void IGESSelect_CounterOfLevelNumber::Clear ()
29 { IFSelect_SignCounter::Clear();
30 thelevels.Nullify(); thehigh = thenblists = 0; }
31
32
33 void IGESSelect_CounterOfLevelNumber::AddSign
34 (const Handle(Standard_Transient)& ent,
35 const Handle(Interface_InterfaceModel)& /*model*/)
36{
37 DeclareAndCast(IGESData_IGESEntity,igesent,ent);
38 if (igesent.IsNull()) return;
39 DeclareAndCast(IGESGraph_DefinitionLevel,levelist,igesent->LevelList());
40 Standard_Integer level = igesent->Level();
41 if (levelist.IsNull() && level < 0) return;
42
43// Enregistrer ce/ces niveau(x)
44 if (levelist.IsNull()) AddLevel(ent,level);
45 else {
46 Standard_Integer nb = levelist->NbPropertyValues();
47 for (Standard_Integer i = 1; i <= nb; i ++) {
48 level = levelist->LevelNumber(i);
49 AddLevel(ent,level);
50 }
51 AddLevel(ent,-1);
52 }
53}
54
55
56 void IGESSelect_CounterOfLevelNumber::AddLevel
57 (const Handle(Standard_Transient)& ent, const Standard_Integer level)
58{
59 if (level < 0) {
60 thenblists ++;
61 Add (ent,"LEVEL LIST");
62 return;
63 }
64 if (thelevels.IsNull()) { thelevels =
65 new TColStd_HArray1OfInteger ( 0, (level > 100 ? level : 100) );
66 thelevels->Init(0); }
67 Standard_Integer upper = thelevels->Upper();
68 if (level > upper) {
69 Handle(TColStd_HArray1OfInteger) levels =
70 new TColStd_HArray1OfInteger (0,level + 100); levels->Init(0);
71 for (Standard_Integer i = 1; i <= upper; i ++)
72 levels->SetValue(i,thelevels->Value(i));
73 thelevels = levels;
74 }
75 thelevels->SetValue (level,thelevels->Value(level)+1);
76 if (level > thehigh) thehigh = level;
77
78// if (level == 0) Add(ent," NO LEVEL");
79// else {
80 char signature[30];
81 sprintf (signature,"%7d",level);
82 Add (ent,signature);
83// }
84}
85
86
87 Standard_Integer IGESSelect_CounterOfLevelNumber::HighestLevel () const
88 { return thehigh; }
89
90 Standard_Integer IGESSelect_CounterOfLevelNumber::NbTimesLevel
91 (const Standard_Integer level) const
92{
93 if (level < 0) return thenblists;
94 if (level > thehigh) return 0;
95 return thelevels->Value(level);
96}
97
98
99 Handle(TColStd_HSequenceOfInteger) IGESSelect_CounterOfLevelNumber::Levels
100 () const
101{
102 Handle(TColStd_HSequenceOfInteger) list = new TColStd_HSequenceOfInteger ();
103 for (Standard_Integer i = 1; i <= thehigh; i ++) {
104 if (thelevels->Value(i) > 0) list->Append(i);
105 }
106 return list;
107}
108
109
110 Handle(TCollection_HAsciiString) IGESSelect_CounterOfLevelNumber::Sign
111 (const Handle(Standard_Transient)& ent,
112 const Handle(Interface_InterfaceModel)& /*model*/) const
113{
114 Handle(TCollection_HAsciiString) res;
115// reprend les termes de AddSign pour la preparation (lecture du level) ...
116 DeclareAndCast(IGESData_IGESEntity,igesent,ent);
117 if (igesent.IsNull()) return res;
118 DeclareAndCast(IGESGraph_DefinitionLevel,levelist,igesent->LevelList());
119 Standard_Integer level = igesent->Level();
120 if (levelist.IsNull() && level < 0) return res;
121
122// puis ceux de AddLevel pour calculer la signature
123 if (level < 0) return new TCollection_HAsciiString ("LEVEL LIST");
124 char signature[30];
125 sprintf (signature,"%7d",level);
126 return new TCollection_HAsciiString (signature);
127}
128
129
130 void IGESSelect_CounterOfLevelNumber::PrintCount
131 (const Handle(Message_Messenger)& S) const
132{
133 IFSelect_SignatureList::PrintCount(S);
134 S<<" Highest value : " << thehigh << endl;
135 if (thenblists > 0) S<<"REMARK for LEVEL LIST : Entities are counted in"
136 <<" <LEVEL LIST>\n, and in each Level value of their list"<<endl;
137}