1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
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>
23 IMPLEMENT_STANDARD_RTTIEXT(IGESSelect_CounterOfLevelNumber,IFSelect_SignCounter)
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"); }
30 void IGESSelect_CounterOfLevelNumber::Clear ()
31 { IFSelect_SignCounter::Clear();
32 thelevels.Nullify(); thehigh = thenblists = 0; }
35 void IGESSelect_CounterOfLevelNumber::AddSign
36 (const Handle(Standard_Transient)& ent,
37 const Handle(Interface_InterfaceModel)& /*model*/)
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;
45 // Enregistrer ce/ces niveau(x)
46 if (levelist.IsNull()) AddLevel(ent,level);
48 Standard_Integer nb = levelist->NbPropertyValues();
49 for (Standard_Integer i = 1; i <= nb; i ++) {
50 level = levelist->LevelNumber(i);
58 void IGESSelect_CounterOfLevelNumber::AddLevel
59 (const Handle(Standard_Transient)& ent, const Standard_Integer level)
63 Add (ent,"LEVEL LIST");
66 if (thelevels.IsNull()) { thelevels =
67 new TColStd_HArray1OfInteger ( 0, (level > 100 ? level : 100) );
69 Standard_Integer upper = thelevels->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));
77 thelevels->SetValue (level,thelevels->Value(level)+1);
78 if (level > thehigh) thehigh = level;
80 // if (level == 0) Add(ent," NO LEVEL");
83 sprintf (signature,"%7d",level);
89 Standard_Integer IGESSelect_CounterOfLevelNumber::HighestLevel () const
92 Standard_Integer IGESSelect_CounterOfLevelNumber::NbTimesLevel
93 (const Standard_Integer level) const
95 if (level < 0) return thenblists;
96 if (level > thehigh) return 0;
97 return thelevels->Value(level);
101 Handle(TColStd_HSequenceOfInteger) IGESSelect_CounterOfLevelNumber::Levels
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);
112 Handle(TCollection_HAsciiString) IGESSelect_CounterOfLevelNumber::Sign
113 (const Handle(Standard_Transient)& ent,
114 const Handle(Interface_InterfaceModel)& /*model*/) const
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;
124 // puis ceux de AddLevel pour calculer la signature
125 if (level < 0) return new TCollection_HAsciiString ("LEVEL LIST");
127 sprintf (signature,"%7d",level);
128 return new TCollection_HAsciiString (signature);
132 void IGESSelect_CounterOfLevelNumber::PrintCount
133 (Standard_OStream& S) const
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;