0024057: Eliminate compiler warning C4100 in MSVC++ with warning level 4
[occt.git] / src / StepData / StepData_StepModel.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
7 //
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10 //
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
17
18 #include <StepData_StepModel.ixx>
19 #include <Standard_NoSuchObject.hxx>
20 #include <StepData_Protocol.hxx>
21 #include <StepData_StepWriter.hxx>
22
23 #include <StepData.hxx>
24 #include <Interface_CopyTool.hxx>
25 #include <Interface_GeneralLib.hxx>
26 #include <Interface_ShareTool.hxx>
27 #include <Interface_GeneralModule.hxx>
28 #include <Interface_Macros.hxx>
29 #include <stdio.h>
30
31
32 // Entete de fichier : liste d entites
33
34 StepData_StepModel::StepData_StepModel ()  {  }
35
36
37 Handle(Standard_Transient) StepData_StepModel::Entity
38 (const Standard_Integer num) const
39 {  return Value(num);  }      // nom plus joli
40
41 void StepData_StepModel::GetFromAnother
42 (const Handle(Interface_InterfaceModel)& other)
43 {
44   theheader.Clear();
45   DeclareAndCast(StepData_StepModel,another,other);
46   if (another.IsNull()) return;
47   Interface_EntityIterator iter = another->Header();
48   //  recopier le header. Attention, header distinct du contenu ...
49   Interface_CopyTool TC (this,StepData::HeaderProtocol());
50   for (; iter.More(); iter.Next()) {
51     Handle(Standard_Transient) newhead;
52     if (!TC.Copy(iter.Value(),newhead,Standard_False,Standard_False)) continue;
53     if (!newhead.IsNull()) theheader.Append(newhead);
54   }
55 }
56
57 Handle(Interface_InterfaceModel) StepData_StepModel::NewEmptyModel () const
58 {  return new StepData_StepModel;  }
59
60
61 Interface_EntityIterator StepData_StepModel::Header () const
62 {
63   Interface_EntityIterator iter;
64   theheader.FillIterator(iter);
65   return iter;
66 }
67
68 Standard_Boolean StepData_StepModel::HasHeaderEntity
69 (const Handle(Standard_Type)& atype) const
70 {  return (theheader.NbTypedEntities(atype) == 1);  }
71
72 Handle(Standard_Transient) StepData_StepModel::HeaderEntity
73 (const Handle(Standard_Type)& atype) const
74 {  return theheader.TypedEntity(atype);  }
75
76
77 //   Remplissage du Header
78
79 void StepData_StepModel::ClearHeader ()
80 {  theheader.Clear();  }
81
82
83 void StepData_StepModel::AddHeaderEntity
84 (const Handle(Standard_Transient)& ent)
85 {  theheader.Append(ent);  }
86
87
88 void StepData_StepModel::VerifyCheck(Handle(Interface_Check)& ach) const
89 {
90   Interface_GeneralLib lib(StepData::HeaderProtocol());
91   Interface_ShareTool sh(this,StepData::HeaderProtocol());
92   Handle(Interface_GeneralModule) module;  Standard_Integer CN;
93   for (Interface_EntityIterator iter = Header(); iter.More(); iter.Next()) {
94     Handle(Standard_Transient) head = iter.Value();
95     if (!lib.Select(head,module,CN)) continue;
96     module->CheckCase(CN,head,sh,ach);
97   }
98 }
99
100
101 void StepData_StepModel::DumpHeader
102 (const Handle(Message_Messenger)& S, const Standard_Integer /*level*/) const
103 {
104   //  NB : level n est pas utilise
105
106   Handle(StepData_Protocol) stepro = StepData::HeaderProtocol();
107   Standard_Boolean iapro = !stepro.IsNull();
108   if (!iapro) S<<" -- WARNING : StepModel DumpHeader, Protocol not defined\n";
109
110   Interface_EntityIterator iter = Header();
111   Standard_Integer nb = iter.NbEntities();
112   S << " --  Step Model Header : " <<iter.NbEntities() << " Entities :\n";
113   for (iter.Start(); iter.More(); iter.Next()) {
114     S << "  "  << iter.Value()->DynamicType()->Name() << "\n";
115   }
116   if (!iapro || nb == 0) return;
117   S << " --  --        STEP MODEL    HEADER  CONTENT      --  --" << endl;
118   S << " --   Dumped with Protocol : " << stepro->DynamicType()->Name()
119     << "   --"<<endl;
120
121   Standard_SStream aSStream;
122   StepData_StepWriter SW(this);
123   SW.SendModel(stepro,Standard_True);    // envoi HEADER seul
124   SW.Print(aSStream);
125   S << aSStream.str().c_str();
126 }
127
128
129 void  StepData_StepModel::ClearLabels ()
130 {  theidnums.Nullify();  }
131
132 void  StepData_StepModel::SetIdentLabel
133 (const Handle(Standard_Transient)& ent, const Standard_Integer ident)
134 {
135   Standard_Integer num = Number(ent);
136   if (!num) 
137     return;
138   if(theidnums.IsNull())
139   {
140     theidnums = new TColStd_HArray1OfInteger(1, NbEntities());
141     theidnums->Init(0);
142   }
143   theidnums->SetValue(num,ident);
144
145 }
146
147 Standard_Integer  StepData_StepModel::IdentLabel
148 (const Handle(Standard_Transient)& ent) const
149 {
150   if(theidnums.IsNull())
151     return 0;
152   Standard_Integer num = Number(ent);
153   return (!num ? 0 : theidnums->Value(num));
154  }
155
156 void  StepData_StepModel::PrintLabel
157 (const Handle(Standard_Transient)& ent, const Handle(Message_Messenger)& S) const
158 {
159   Standard_Integer num = (theidnums.IsNull() ? 0 : Number(ent));
160   Standard_Integer  nid = (!num ? 0 : theidnums->Value(num));
161   if      (nid > 0) S<<"#"<<nid;
162   else if (num > 0) S<<"(#"<<num<<")";
163   else              S<<"(#0..)";
164 }
165
166 Handle(TCollection_HAsciiString) StepData_StepModel::StringLabel
167 (const Handle(Standard_Transient)& ent) const
168 {
169   Handle(TCollection_HAsciiString) label;
170   char text[20];
171   Standard_Integer num = (theidnums.IsNull() ? 0 : Number(ent));
172   Standard_Integer  nid = (!num ? 0 : theidnums->Value(num));
173
174   if      (nid > 0) sprintf (text, "#%d",nid);
175   else if (num > 0) sprintf (text, "(#%d)",num);
176   else              sprintf (text, "(#0..)");
177
178   label = new TCollection_HAsciiString(text);
179   return label;
180 }