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 IMPLEMENT_STANDARD_RTTIEXT(StepData_StepModel,Interface_InterfaceModel)
36 // Entete de fichier : liste d entites
37 StepData_StepModel::StepData_StepModel () { }
40 Handle(Standard_Transient) StepData_StepModel::Entity
41 (const Standard_Integer num) const
42 { return Value(num); } // nom plus joli
44 void StepData_StepModel::GetFromAnother
45 (const Handle(Interface_InterfaceModel)& other)
48 DeclareAndCast(StepData_StepModel,another,other);
49 if (another.IsNull()) return;
50 Interface_EntityIterator iter = another->Header();
51 // recopier le header. Attention, header distinct du contenu ...
52 Interface_CopyTool TC (this,StepData::HeaderProtocol());
53 for (; iter.More(); iter.Next()) {
54 Handle(Standard_Transient) newhead;
55 if (!TC.Copy(iter.Value(),newhead,Standard_False,Standard_False)) continue;
56 if (!newhead.IsNull()) theheader.Append(newhead);
60 Handle(Interface_InterfaceModel) StepData_StepModel::NewEmptyModel () const
61 { return new StepData_StepModel; }
64 Interface_EntityIterator StepData_StepModel::Header () const
66 Interface_EntityIterator iter;
67 theheader.FillIterator(iter);
71 Standard_Boolean StepData_StepModel::HasHeaderEntity
72 (const Handle(Standard_Type)& atype) const
73 { return (theheader.NbTypedEntities(atype) == 1); }
75 Handle(Standard_Transient) StepData_StepModel::HeaderEntity
76 (const Handle(Standard_Type)& atype) const
77 { return theheader.TypedEntity(atype); }
80 // Remplissage du Header
82 void StepData_StepModel::ClearHeader ()
83 { theheader.Clear(); }
86 void StepData_StepModel::AddHeaderEntity
87 (const Handle(Standard_Transient)& ent)
88 { theheader.Append(ent); }
91 void StepData_StepModel::VerifyCheck(Handle(Interface_Check)& ach) const
93 Interface_GeneralLib lib(StepData::HeaderProtocol());
94 Handle(StepData_StepModel) me (this);
95 Handle(Interface_Protocol) aHP = StepData::HeaderProtocol();
96 Interface_ShareTool sh(me,aHP);
97 Handle(Interface_GeneralModule) module; Standard_Integer CN;
98 for (Interface_EntityIterator iter = Header(); iter.More(); iter.Next()) {
99 Handle(Standard_Transient) head = iter.Value();
100 if (!lib.Select(head,module,CN)) continue;
101 module->CheckCase(CN,head,sh,ach);
106 void StepData_StepModel::DumpHeader
107 (const Handle(Message_Messenger)& S, const Standard_Integer /*level*/) const
109 // NB : level n est pas utilise
111 Handle(StepData_Protocol) stepro = StepData::HeaderProtocol();
112 Standard_Boolean iapro = !stepro.IsNull();
113 if (!iapro) S<<" -- WARNING : StepModel DumpHeader, Protocol not defined\n";
115 Interface_EntityIterator iter = Header();
116 Standard_Integer nb = iter.NbEntities();
117 S << " -- Step Model Header : " <<iter.NbEntities() << " Entities :\n";
118 for (iter.Start(); iter.More(); iter.Next()) {
119 S << " " << iter.Value()->DynamicType()->Name() << "\n";
121 if (!iapro || nb == 0) return;
122 S << " -- -- STEP MODEL HEADER CONTENT -- --" << Message_EndLine;
123 S << " -- Dumped with Protocol : " << stepro->DynamicType()->Name()
124 << " --"<<Message_EndLine;
126 Standard_SStream aSStream;
127 Handle(StepData_StepModel) me (this);
128 StepData_StepWriter SW(me);
129 SW.SendModel(stepro,Standard_True); // envoi HEADER seul
131 S << aSStream.str().c_str();
135 void StepData_StepModel::ClearLabels ()
136 { theidnums.Nullify(); }
138 void StepData_StepModel::SetIdentLabel
139 (const Handle(Standard_Transient)& ent, const Standard_Integer ident)
141 Standard_Integer num = Number(ent);
144 Standard_Integer nbEnt = NbEntities();
145 if(theidnums.IsNull())
147 theidnums = new TColStd_HArray1OfInteger(1,nbEnt);
150 else if(nbEnt > theidnums->Length())
152 Standard_Integer prevLength = theidnums->Length();
153 Handle(TColStd_HArray1OfInteger) idnums1 = new TColStd_HArray1OfInteger(1,nbEnt);
155 Standard_Integer k =1;
156 for( ; k <= prevLength; k++)
157 idnums1->SetValue(k , theidnums->Value(k));
160 theidnums->SetValue(num,ident);
164 Standard_Integer StepData_StepModel::IdentLabel
165 (const Handle(Standard_Transient)& ent) const
167 if(theidnums.IsNull())
169 Standard_Integer num = Number(ent);
170 return (!num ? 0 : theidnums->Value(num));
173 void StepData_StepModel::PrintLabel
174 (const Handle(Standard_Transient)& ent, const Handle(Message_Messenger)& S) const
176 Standard_Integer num = (theidnums.IsNull() ? 0 : Number(ent));
177 Standard_Integer nid = (!num ? 0 : theidnums->Value(num));
178 if (nid > 0) S<<"#"<<nid;
179 else if (num > 0) S<<"(#"<<num<<")";
183 Handle(TCollection_HAsciiString) StepData_StepModel::StringLabel
184 (const Handle(Standard_Transient)& ent) const
186 Handle(TCollection_HAsciiString) label;
188 Standard_Integer num = (theidnums.IsNull() ? 0 : Number(ent));
189 Standard_Integer nid = (!num ? 0 : theidnums->Value(num));
191 if (nid > 0) sprintf (text, "#%d",nid);
192 else if (num > 0) sprintf (text, "(#%d)",num);
193 else sprintf (text, "(#0..)");
195 label = new TCollection_HAsciiString(text);