Integration of OCCT 6.5.0 from SVN
[occt.git] / src / StepData / StepData_StepModel.cxx
1 #include <StepData_StepModel.ixx>
2 #include <Standard_NoSuchObject.hxx>
3 #include <StepData_Protocol.hxx>
4 #include <StepData_StepWriter.hxx>
5
6 #include <StepData.hxx>
7 #include <Interface_CopyTool.hxx>
8 #include <Interface_GeneralLib.hxx>
9 #include <Interface_ShareTool.hxx>
10 #include <Interface_GeneralModule.hxx>
11 #include <Interface_Macros.hxx>
12 #include <stdio.h>
13
14
15 // Entete de fichier : liste d entites
16
17     StepData_StepModel::StepData_StepModel ()  {  }
18
19     void  StepData_StepModel::Reservate (const Standard_Integer nbent)
20 {
21   Interface_InterfaceModel::Reservate(nbent);
22   if (nbent > theidnums.NbBuckets()) theidnums.ReSize (nbent);
23 }
24
25     Handle(Standard_Transient) StepData_StepModel::Entity
26       (const Standard_Integer num) const
27       {  return Value(num);  }      // nom plus joli
28
29     void StepData_StepModel::GetFromAnother
30   (const Handle(Interface_InterfaceModel)& other)
31 {
32   theheader.Clear();
33   DeclareAndCast(StepData_StepModel,another,other);
34   if (another.IsNull()) return;
35   Interface_EntityIterator iter = another->Header();
36 //  recopier le header. Attention, header distinct du contenu ...
37   Interface_CopyTool TC (this,StepData::HeaderProtocol());
38   for (; iter.More(); iter.Next()) {
39     Handle(Standard_Transient) newhead;
40     if (!TC.Copy(iter.Value(),newhead,Standard_False,Standard_False)) continue;
41     if (!newhead.IsNull()) theheader.Append(newhead);
42   }
43 }
44
45     Handle(Interface_InterfaceModel) StepData_StepModel::NewEmptyModel () const
46       {  return new StepData_StepModel;  }
47
48
49     Interface_EntityIterator StepData_StepModel::Header () const
50 {
51   Interface_EntityIterator iter;
52   theheader.FillIterator(iter);
53   return iter;
54 }
55
56     Standard_Boolean StepData_StepModel::HasHeaderEntity
57       (const Handle(Standard_Type)& atype) const
58       {  return (theheader.NbTypedEntities(atype) == 1);  }
59
60     Handle(Standard_Transient) StepData_StepModel::HeaderEntity
61       (const Handle(Standard_Type)& atype) const
62       {  return theheader.TypedEntity(atype);  }
63
64
65 //   Remplissage du Header
66
67     void StepData_StepModel::ClearHeader ()
68       {  theheader.Clear();  }
69
70
71     void StepData_StepModel::AddHeaderEntity
72   (const Handle(Standard_Transient)& ent)
73       {  theheader.Append(ent);  }
74
75
76 void StepData_StepModel::VerifyCheck(Handle(Interface_Check)& ach) const
77 {
78   Interface_GeneralLib lib(StepData::HeaderProtocol());
79   Interface_ShareTool sh(this,StepData::HeaderProtocol());
80   Handle(Interface_GeneralModule) module;  Standard_Integer CN;
81   for (Interface_EntityIterator iter = Header(); iter.More(); iter.Next()) {
82     Handle(Standard_Transient) head = iter.Value();
83     if (!lib.Select(head,module,CN)) continue;
84     module->CheckCase(CN,head,sh,ach);
85   }
86 }
87
88
89     void StepData_StepModel::DumpHeader
90   (const Handle(Message_Messenger)& S, const Standard_Integer /*level*/) const
91 {
92 //  NB : level n est pas utilise
93
94   Handle(StepData_Protocol) stepro = StepData::HeaderProtocol();
95   Standard_Boolean iapro = !stepro.IsNull();
96   if (!iapro) S<<" -- WARNING : StepModel DumpHeader, Protocol not defined\n";
97
98   Interface_EntityIterator iter = Header();
99   Standard_Integer nb = iter.NbEntities();
100   S << " --  Step Model Header : " <<iter.NbEntities() << " Entities :\n";
101   for (iter.Start(); iter.More(); iter.Next()) {
102     S << "  "  << iter.Value()->DynamicType()->Name() << "\n";
103   }
104   if (!iapro || nb == 0) return;
105   S << " --  --        STEP MODEL    HEADER  CONTENT      --  --" << endl;
106   S << " --   Dumped with Protocol : " << stepro->DynamicType()->Name()
107     << "   --"<<endl;
108
109   Standard_SStream aSStream;
110   StepData_StepWriter SW(this);
111   SW.SendModel(stepro,Standard_True);    // envoi HEADER seul
112   SW.Print(aSStream);
113   S << aSStream.str().c_str();
114 }
115
116
117     void  StepData_StepModel::ClearLabels ()
118       {  theidnums.Clear();  }
119
120     void  StepData_StepModel::SetIdentLabel
121   (const Handle(Standard_Transient)& ent, const Standard_Integer ident)
122 {
123   if (Number(ent) == 0) return;
124   if (theidnums.NbBuckets() < NbEntities()) theidnums.ReSize (NbEntities());
125   if (theidnums.IsBound(ent)) theidnums.ChangeFind(ent) = ident;
126   else theidnums.Bind (ent,ident);
127 }
128
129     Standard_Integer  StepData_StepModel::IdentLabel
130   (const Handle(Standard_Transient)& ent) const
131 {
132   if (theidnums.IsBound(ent)) return theidnums.Find(ent);
133   return 0;
134 }
135
136     void  StepData_StepModel::PrintLabel
137   (const Handle(Standard_Transient)& ent, const Handle(Message_Messenger)& S) const
138 {
139   Standard_Integer num = 0 , nid = 0;
140   if (theidnums.IsBound(ent)) nid = theidnums.Find(ent);
141   if (nid <= 0) num = Number(ent);
142
143   if      (nid > 0) S<<"#"<<nid;
144   else if (num > 0) S<<"(#"<<num<<")";
145   else              S<<"(#0..)";
146 }
147
148     Handle(TCollection_HAsciiString) StepData_StepModel::StringLabel
149   (const Handle(Standard_Transient)& ent) const
150 {
151   Handle(TCollection_HAsciiString) label;
152   char text[20];
153   Standard_Integer num = 0 , nid = 0;
154   if (theidnums.IsBound(ent)) nid = theidnums.Find(ent);
155   if (nid <= 0) num = Number(ent);
156
157   if      (nid > 0) sprintf (text, "#%d",nid);
158   else if (num > 0) sprintf (text, "(#%d)",num);
159   else              sprintf (text, "(#0..)");
160
161   label = new TCollection_HAsciiString(text);
162   return label;
163 }