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