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