1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <StepData_StepModel.ixx>
15 #include <Standard_NoSuchObject.hxx>
16 #include <StepData_Protocol.hxx>
17 #include <StepData_StepWriter.hxx>
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>
28 // Entete de fichier : liste d entites
30 StepData_StepModel::StepData_StepModel () { }
33 Handle(Standard_Transient) StepData_StepModel::Entity
34 (const Standard_Integer num) const
35 { return Value(num); } // nom plus joli
37 void StepData_StepModel::GetFromAnother
38 (const Handle(Interface_InterfaceModel)& other)
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);
53 Handle(Interface_InterfaceModel) StepData_StepModel::NewEmptyModel () const
54 { return new StepData_StepModel; }
57 Interface_EntityIterator StepData_StepModel::Header () const
59 Interface_EntityIterator iter;
60 theheader.FillIterator(iter);
64 Standard_Boolean StepData_StepModel::HasHeaderEntity
65 (const Handle(Standard_Type)& atype) const
66 { return (theheader.NbTypedEntities(atype) == 1); }
68 Handle(Standard_Transient) StepData_StepModel::HeaderEntity
69 (const Handle(Standard_Type)& atype) const
70 { return theheader.TypedEntity(atype); }
73 // Remplissage du Header
75 void StepData_StepModel::ClearHeader ()
76 { theheader.Clear(); }
79 void StepData_StepModel::AddHeaderEntity
80 (const Handle(Standard_Transient)& ent)
81 { theheader.Append(ent); }
84 void StepData_StepModel::VerifyCheck(Handle(Interface_Check)& ach) const
86 Interface_GeneralLib lib(StepData::HeaderProtocol());
87 Handle(StepData_StepModel) me (this);
88 Handle(Interface_Protocol) aHP = StepData::HeaderProtocol();
89 Interface_ShareTool sh(me,aHP);
90 Handle(Interface_GeneralModule) module; Standard_Integer CN;
91 for (Interface_EntityIterator iter = Header(); iter.More(); iter.Next()) {
92 Handle(Standard_Transient) head = iter.Value();
93 if (!lib.Select(head,module,CN)) continue;
94 module->CheckCase(CN,head,sh,ach);
99 void StepData_StepModel::DumpHeader
100 (const Handle(Message_Messenger)& S, const Standard_Integer /*level*/) const
102 // NB : level n est pas utilise
104 Handle(StepData_Protocol) stepro = StepData::HeaderProtocol();
105 Standard_Boolean iapro = !stepro.IsNull();
106 if (!iapro) S<<" -- WARNING : StepModel DumpHeader, Protocol not defined\n";
108 Interface_EntityIterator iter = Header();
109 Standard_Integer nb = iter.NbEntities();
110 S << " -- Step Model Header : " <<iter.NbEntities() << " Entities :\n";
111 for (iter.Start(); iter.More(); iter.Next()) {
112 S << " " << iter.Value()->DynamicType()->Name() << "\n";
114 if (!iapro || nb == 0) return;
115 S << " -- -- STEP MODEL HEADER CONTENT -- --" << endl;
116 S << " -- Dumped with Protocol : " << stepro->DynamicType()->Name()
119 Standard_SStream aSStream;
120 Handle(StepData_StepModel) me (this);
121 StepData_StepWriter SW(me);
122 SW.SendModel(stepro,Standard_True); // envoi HEADER seul
124 S << aSStream.str().c_str();
128 void StepData_StepModel::ClearLabels ()
129 { theidnums.Nullify(); }
131 void StepData_StepModel::SetIdentLabel
132 (const Handle(Standard_Transient)& ent, const Standard_Integer ident)
134 Standard_Integer num = Number(ent);
137 if(theidnums.IsNull())
139 theidnums = new TColStd_HArray1OfInteger(1, NbEntities());
142 theidnums->SetValue(num,ident);
146 Standard_Integer StepData_StepModel::IdentLabel
147 (const Handle(Standard_Transient)& ent) const
149 if(theidnums.IsNull())
151 Standard_Integer num = Number(ent);
152 return (!num ? 0 : theidnums->Value(num));
155 void StepData_StepModel::PrintLabel
156 (const Handle(Standard_Transient)& ent, const Handle(Message_Messenger)& S) const
158 Standard_Integer num = (theidnums.IsNull() ? 0 : Number(ent));
159 Standard_Integer nid = (!num ? 0 : theidnums->Value(num));
160 if (nid > 0) S<<"#"<<nid;
161 else if (num > 0) S<<"(#"<<num<<")";
165 Handle(TCollection_HAsciiString) StepData_StepModel::StringLabel
166 (const Handle(Standard_Transient)& ent) const
168 Handle(TCollection_HAsciiString) label;
170 Standard_Integer num = (theidnums.IsNull() ? 0 : Number(ent));
171 Standard_Integer nid = (!num ? 0 : theidnums->Value(num));
173 if (nid > 0) sprintf (text, "#%d",nid);
174 else if (num > 0) sprintf (text, "(#%d)",num);
175 else sprintf (text, "(#0..)");
177 label = new TCollection_HAsciiString(text);