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