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.
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>
34 // Entete de fichier : liste d entites
35 StepData_StepModel::StepData_StepModel () { }
38 Handle(Standard_Transient) StepData_StepModel::Entity
39 (const Standard_Integer num) const
40 { return Value(num); } // nom plus joli
42 void StepData_StepModel::GetFromAnother
43 (const Handle(Interface_InterfaceModel)& other)
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);
58 Handle(Interface_InterfaceModel) StepData_StepModel::NewEmptyModel () const
59 { return new StepData_StepModel; }
62 Interface_EntityIterator StepData_StepModel::Header () const
64 Interface_EntityIterator iter;
65 theheader.FillIterator(iter);
69 Standard_Boolean StepData_StepModel::HasHeaderEntity
70 (const Handle(Standard_Type)& atype) const
71 { return (theheader.NbTypedEntities(atype) == 1); }
73 Handle(Standard_Transient) StepData_StepModel::HeaderEntity
74 (const Handle(Standard_Type)& atype) const
75 { return theheader.TypedEntity(atype); }
78 // Remplissage du Header
80 void StepData_StepModel::ClearHeader ()
81 { theheader.Clear(); }
84 void StepData_StepModel::AddHeaderEntity
85 (const Handle(Standard_Transient)& ent)
86 { theheader.Append(ent); }
89 void StepData_StepModel::VerifyCheck(Handle(Interface_Check)& ach) const
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);
104 void StepData_StepModel::DumpHeader
105 (const Handle(Message_Messenger)& S, const Standard_Integer /*level*/) const
107 // NB : level n est pas utilise
109 Handle(StepData_Protocol) stepro = StepData::HeaderProtocol();
110 Standard_Boolean iapro = !stepro.IsNull();
111 if (!iapro) S<<" -- WARNING : StepModel DumpHeader, Protocol not defined\n";
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";
119 if (!iapro || nb == 0) return;
120 S << " -- -- STEP MODEL HEADER CONTENT -- --" << endl;
121 S << " -- Dumped with Protocol : " << stepro->DynamicType()->Name()
124 Standard_SStream aSStream;
125 Handle(StepData_StepModel) me (this);
126 StepData_StepWriter SW(me);
127 SW.SendModel(stepro,Standard_True); // envoi HEADER seul
129 S << aSStream.str().c_str();
133 void StepData_StepModel::ClearLabels ()
134 { theidnums.Nullify(); }
136 void StepData_StepModel::SetIdentLabel
137 (const Handle(Standard_Transient)& ent, const Standard_Integer ident)
139 Standard_Integer num = Number(ent);
142 if(theidnums.IsNull())
144 theidnums = new TColStd_HArray1OfInteger(1, NbEntities());
147 theidnums->SetValue(num,ident);
151 Standard_Integer StepData_StepModel::IdentLabel
152 (const Handle(Standard_Transient)& ent) const
154 if(theidnums.IsNull())
156 Standard_Integer num = Number(ent);
157 return (!num ? 0 : theidnums->Value(num));
160 void StepData_StepModel::PrintLabel
161 (const Handle(Standard_Transient)& ent, const Handle(Message_Messenger)& S) const
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<<")";
170 Handle(TCollection_HAsciiString) StepData_StepModel::StringLabel
171 (const Handle(Standard_Transient)& ent) const
173 Handle(TCollection_HAsciiString) label;
175 Standard_Integer num = (theidnums.IsNull() ? 0 : Number(ent));
176 Standard_Integer nid = (!num ? 0 : theidnums->Value(num));
178 if (nid > 0) sprintf (text, "#%d",nid);
179 else if (num > 0) sprintf (text, "(#%d)",num);
180 else sprintf (text, "(#0..)");
182 label = new TCollection_HAsciiString(text);