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 <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>
27 IMPLEMENT_STANDARD_RTTIEXT(IGESSelect_CounterOfLevelNumber,IFSelect_SignCounter)
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"); }
34 void IGESSelect_CounterOfLevelNumber::Clear ()
35 { IFSelect_SignCounter::Clear();
36 thelevels.Nullify(); thehigh = thenblists = 0; }
39 void IGESSelect_CounterOfLevelNumber::AddSign
40 (const Handle(Standard_Transient)& ent,
41 const Handle(Interface_InterfaceModel)& /*model*/)
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;
49 // Enregistrer ce/ces niveau(x)
50 if (levelist.IsNull()) AddLevel(ent,level);
52 Standard_Integer nb = levelist->NbPropertyValues();
53 for (Standard_Integer i = 1; i <= nb; i ++) {
54 level = levelist->LevelNumber(i);
62 void IGESSelect_CounterOfLevelNumber::AddLevel
63 (const Handle(Standard_Transient)& ent, const Standard_Integer level)
67 Add (ent,"LEVEL LIST");
70 if (thelevels.IsNull()) { thelevels =
71 new TColStd_HArray1OfInteger ( 0, (level > 100 ? level : 100) );
73 Standard_Integer upper = thelevels->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));
81 thelevels->SetValue (level,thelevels->Value(level)+1);
82 if (level > thehigh) thehigh = level;
84 // if (level == 0) Add(ent," NO LEVEL");
87 sprintf (signature,"%7d",level);
93 Standard_Integer IGESSelect_CounterOfLevelNumber::HighestLevel () const
96 Standard_Integer IGESSelect_CounterOfLevelNumber::NbTimesLevel
97 (const Standard_Integer level) const
99 if (level < 0) return thenblists;
100 if (level > thehigh) return 0;
101 return thelevels->Value(level);
105 Handle(TColStd_HSequenceOfInteger) IGESSelect_CounterOfLevelNumber::Levels
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);
116 Handle(TCollection_HAsciiString) IGESSelect_CounterOfLevelNumber::Sign
117 (const Handle(Standard_Transient)& ent,
118 const Handle(Interface_InterfaceModel)& /*model*/) const
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;
128 // puis ceux de AddLevel pour calculer la signature
129 if (level < 0) return new TCollection_HAsciiString ("LEVEL LIST");
131 sprintf (signature,"%7d",level);
132 return new TCollection_HAsciiString (signature);
136 void IGESSelect_CounterOfLevelNumber::PrintCount
137 (const Handle(Message_Messenger)& S) const
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;