Commit | Line | Data |
---|---|---|
973c2be1 | 1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 2 | // |
973c2be1 | 3 | // This file is part of Open CASCADE Technology software library. |
b311480e | 4 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 10 | // |
973c2be1 | 11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. | |
b311480e | 13 | |
7fd59977 | 14 | #include <StepData_StepModel.ixx> |
15 | #include <Standard_NoSuchObject.hxx> | |
16 | #include <StepData_Protocol.hxx> | |
17 | #include <StepData_StepWriter.hxx> | |
18 | ||
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> | |
25 | #include <stdio.h> | |
26 | ||
27 | ||
28 | // Entete de fichier : liste d entites | |
29 | ||
bc650d41 | 30 | StepData_StepModel::StepData_StepModel () { } |
7fd59977 | 31 | |
7fd59977 | 32 | |
bc650d41 G |
33 | Handle(Standard_Transient) StepData_StepModel::Entity |
34 | (const Standard_Integer num) const | |
35 | { return Value(num); } // nom plus joli | |
7fd59977 | 36 | |
bc650d41 G |
37 | void StepData_StepModel::GetFromAnother |
38 | (const Handle(Interface_InterfaceModel)& other) | |
7fd59977 | 39 | { |
40 | theheader.Clear(); | |
41 | DeclareAndCast(StepData_StepModel,another,other); | |
42 | if (another.IsNull()) return; | |
43 | Interface_EntityIterator iter = another->Header(); | |
bc650d41 | 44 | // recopier le header. Attention, header distinct du contenu ... |
7fd59977 | 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); | |
50 | } | |
51 | } | |
52 | ||
bc650d41 G |
53 | Handle(Interface_InterfaceModel) StepData_StepModel::NewEmptyModel () const |
54 | { return new StepData_StepModel; } | |
7fd59977 | 55 | |
56 | ||
bc650d41 | 57 | Interface_EntityIterator StepData_StepModel::Header () const |
7fd59977 | 58 | { |
59 | Interface_EntityIterator iter; | |
60 | theheader.FillIterator(iter); | |
61 | return iter; | |
62 | } | |
63 | ||
bc650d41 G |
64 | Standard_Boolean StepData_StepModel::HasHeaderEntity |
65 | (const Handle(Standard_Type)& atype) const | |
66 | { return (theheader.NbTypedEntities(atype) == 1); } | |
7fd59977 | 67 | |
bc650d41 G |
68 | Handle(Standard_Transient) StepData_StepModel::HeaderEntity |
69 | (const Handle(Standard_Type)& atype) const | |
70 | { return theheader.TypedEntity(atype); } | |
7fd59977 | 71 | |
72 | ||
73 | // Remplissage du Header | |
74 | ||
bc650d41 G |
75 | void StepData_StepModel::ClearHeader () |
76 | { theheader.Clear(); } | |
7fd59977 | 77 | |
78 | ||
bc650d41 G |
79 | void StepData_StepModel::AddHeaderEntity |
80 | (const Handle(Standard_Transient)& ent) | |
81 | { theheader.Append(ent); } | |
7fd59977 | 82 | |
83 | ||
84 | void StepData_StepModel::VerifyCheck(Handle(Interface_Check)& ach) const | |
85 | { | |
86 | Interface_GeneralLib lib(StepData::HeaderProtocol()); | |
87 | Interface_ShareTool sh(this,StepData::HeaderProtocol()); | |
88 | Handle(Interface_GeneralModule) module; Standard_Integer CN; | |
89 | for (Interface_EntityIterator iter = Header(); iter.More(); iter.Next()) { | |
90 | Handle(Standard_Transient) head = iter.Value(); | |
91 | if (!lib.Select(head,module,CN)) continue; | |
92 | module->CheckCase(CN,head,sh,ach); | |
93 | } | |
94 | } | |
95 | ||
96 | ||
bc650d41 G |
97 | void StepData_StepModel::DumpHeader |
98 | (const Handle(Message_Messenger)& S, const Standard_Integer /*level*/) const | |
7fd59977 | 99 | { |
bc650d41 | 100 | // NB : level n est pas utilise |
7fd59977 | 101 | |
102 | Handle(StepData_Protocol) stepro = StepData::HeaderProtocol(); | |
103 | Standard_Boolean iapro = !stepro.IsNull(); | |
104 | if (!iapro) S<<" -- WARNING : StepModel DumpHeader, Protocol not defined\n"; | |
105 | ||
106 | Interface_EntityIterator iter = Header(); | |
107 | Standard_Integer nb = iter.NbEntities(); | |
108 | S << " -- Step Model Header : " <<iter.NbEntities() << " Entities :\n"; | |
109 | for (iter.Start(); iter.More(); iter.Next()) { | |
110 | S << " " << iter.Value()->DynamicType()->Name() << "\n"; | |
111 | } | |
112 | if (!iapro || nb == 0) return; | |
113 | S << " -- -- STEP MODEL HEADER CONTENT -- --" << endl; | |
114 | S << " -- Dumped with Protocol : " << stepro->DynamicType()->Name() | |
115 | << " --"<<endl; | |
116 | ||
117 | Standard_SStream aSStream; | |
118 | StepData_StepWriter SW(this); | |
119 | SW.SendModel(stepro,Standard_True); // envoi HEADER seul | |
120 | SW.Print(aSStream); | |
121 | S << aSStream.str().c_str(); | |
122 | } | |
123 | ||
124 | ||
bc650d41 G |
125 | void StepData_StepModel::ClearLabels () |
126 | { theidnums.Nullify(); } | |
7fd59977 | 127 | |
bc650d41 G |
128 | void StepData_StepModel::SetIdentLabel |
129 | (const Handle(Standard_Transient)& ent, const Standard_Integer ident) | |
7fd59977 | 130 | { |
bc650d41 G |
131 | Standard_Integer num = Number(ent); |
132 | if (!num) | |
133 | return; | |
134 | if(theidnums.IsNull()) | |
135 | { | |
136 | theidnums = new TColStd_HArray1OfInteger(1, NbEntities()); | |
137 | theidnums->Init(0); | |
138 | } | |
139 | theidnums->SetValue(num,ident); | |
7fd59977 | 140 | |
7fd59977 | 141 | } |
142 | ||
bc650d41 G |
143 | Standard_Integer StepData_StepModel::IdentLabel |
144 | (const Handle(Standard_Transient)& ent) const | |
7fd59977 | 145 | { |
bc650d41 G |
146 | if(theidnums.IsNull()) |
147 | return 0; | |
148 | Standard_Integer num = Number(ent); | |
149 | return (!num ? 0 : theidnums->Value(num)); | |
150 | } | |
151 | ||
152 | void StepData_StepModel::PrintLabel | |
153 | (const Handle(Standard_Transient)& ent, const Handle(Message_Messenger)& S) const | |
154 | { | |
155 | Standard_Integer num = (theidnums.IsNull() ? 0 : Number(ent)); | |
156 | Standard_Integer nid = (!num ? 0 : theidnums->Value(num)); | |
7fd59977 | 157 | if (nid > 0) S<<"#"<<nid; |
158 | else if (num > 0) S<<"(#"<<num<<")"; | |
159 | else S<<"(#0..)"; | |
160 | } | |
161 | ||
bc650d41 G |
162 | Handle(TCollection_HAsciiString) StepData_StepModel::StringLabel |
163 | (const Handle(Standard_Transient)& ent) const | |
7fd59977 | 164 | { |
165 | Handle(TCollection_HAsciiString) label; | |
166 | char text[20]; | |
bc650d41 G |
167 | Standard_Integer num = (theidnums.IsNull() ? 0 : Number(ent)); |
168 | Standard_Integer nid = (!num ? 0 : theidnums->Value(num)); | |
7fd59977 | 169 | |
170 | if (nid > 0) sprintf (text, "#%d",nid); | |
171 | else if (num > 0) sprintf (text, "(#%d)",num); | |
172 | else sprintf (text, "(#0..)"); | |
173 | ||
174 | label = new TCollection_HAsciiString(text); | |
175 | return label; | |
176 | } |