1 #include <StepData_StepModel.ixx>
2 #include <Standard_NoSuchObject.hxx>
3 #include <StepData_Protocol.hxx>
4 #include <StepData_StepWriter.hxx>
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>
15 // Entete de fichier : liste d entites
17 StepData_StepModel::StepData_StepModel () { }
19 void StepData_StepModel::Reservate (const Standard_Integer nbent)
21 Interface_InterfaceModel::Reservate(nbent);
22 if (nbent > theidnums.NbBuckets()) theidnums.ReSize (nbent);
25 Handle(Standard_Transient) StepData_StepModel::Entity
26 (const Standard_Integer num) const
27 { return Value(num); } // nom plus joli
29 void StepData_StepModel::GetFromAnother
30 (const Handle(Interface_InterfaceModel)& other)
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);
45 Handle(Interface_InterfaceModel) StepData_StepModel::NewEmptyModel () const
46 { return new StepData_StepModel; }
49 Interface_EntityIterator StepData_StepModel::Header () const
51 Interface_EntityIterator iter;
52 theheader.FillIterator(iter);
56 Standard_Boolean StepData_StepModel::HasHeaderEntity
57 (const Handle(Standard_Type)& atype) const
58 { return (theheader.NbTypedEntities(atype) == 1); }
60 Handle(Standard_Transient) StepData_StepModel::HeaderEntity
61 (const Handle(Standard_Type)& atype) const
62 { return theheader.TypedEntity(atype); }
65 // Remplissage du Header
67 void StepData_StepModel::ClearHeader ()
68 { theheader.Clear(); }
71 void StepData_StepModel::AddHeaderEntity
72 (const Handle(Standard_Transient)& ent)
73 { theheader.Append(ent); }
76 void StepData_StepModel::VerifyCheck(Handle(Interface_Check)& ach) const
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);
89 void StepData_StepModel::DumpHeader
90 (const Handle(Message_Messenger)& S, const Standard_Integer /*level*/) const
92 // NB : level n est pas utilise
94 Handle(StepData_Protocol) stepro = StepData::HeaderProtocol();
95 Standard_Boolean iapro = !stepro.IsNull();
96 if (!iapro) S<<" -- WARNING : StepModel DumpHeader, Protocol not defined\n";
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";
104 if (!iapro || nb == 0) return;
105 S << " -- -- STEP MODEL HEADER CONTENT -- --" << endl;
106 S << " -- Dumped with Protocol : " << stepro->DynamicType()->Name()
109 Standard_SStream aSStream;
110 StepData_StepWriter SW(this);
111 SW.SendModel(stepro,Standard_True); // envoi HEADER seul
113 S << aSStream.str().c_str();
117 void StepData_StepModel::ClearLabels ()
118 { theidnums.Clear(); }
120 void StepData_StepModel::SetIdentLabel
121 (const Handle(Standard_Transient)& ent, const Standard_Integer ident)
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);
129 Standard_Integer StepData_StepModel::IdentLabel
130 (const Handle(Standard_Transient)& ent) const
132 if (theidnums.IsBound(ent)) return theidnums.Find(ent);
136 void StepData_StepModel::PrintLabel
137 (const Handle(Standard_Transient)& ent, const Handle(Message_Messenger)& S) const
139 Standard_Integer num = 0 , nid = 0;
140 if (theidnums.IsBound(ent)) nid = theidnums.Find(ent);
141 if (nid <= 0) num = Number(ent);
143 if (nid > 0) S<<"#"<<nid;
144 else if (num > 0) S<<"(#"<<num<<")";
148 Handle(TCollection_HAsciiString) StepData_StepModel::StringLabel
149 (const Handle(Standard_Transient)& ent) const
151 Handle(TCollection_HAsciiString) label;
153 Standard_Integer num = 0 , nid = 0;
154 if (theidnums.IsBound(ent)) nid = theidnums.Find(ent);
155 if (nid <= 0) num = Number(ent);
157 if (nid > 0) sprintf (text, "#%d",nid);
158 else if (num > 0) sprintf (text, "(#%d)",num);
159 else sprintf (text, "(#0..)");
161 label = new TCollection_HAsciiString(text);