0029355: OCCT 6.9.1 persistence restored in OCCT 7.2.0 not working
[occt.git] / src / DDF / DDF_DataCommands.cxx
CommitLineData
b311480e 1// Created by: DAUTRY Philippe
2// Copyright (c) 1997-1999 Matra Datavision
973c2be1 3// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
7fd59977 16// --------------------
7fd59977 17
18// Version: 0.0
b311480e 19//Version Date Purpose
7fd59977 20// 0.0 Sep 30 1997 Creation
21
22
23
24#include <TDF_ClosureMode.hxx>
25#include <TDF_ClosureTool.hxx>
26#include <TDF_CopyTool.hxx>
27
28#include <DDF.hxx>
29#include <DDF_Data.hxx>
30
31#include <Draw.hxx>
32#include <Draw_Appli.hxx>
33#include <Draw_Drawable3D.hxx>
34#include <Draw_Interpretor.hxx>
35
36#include <Standard_NotImplemented.hxx>
37
38#include <TDF_ChildIterator.hxx>
39#include <TDF_Data.hxx>
40#include <TDF_DataSet.hxx>
41#include <TDF_IDFilter.hxx>
42#include <TDF_Label.hxx>
43#include <TDF_RelocationTable.hxx>
44#include <TDF_Tool.hxx>
45#include <TDF_CopyLabel.hxx>
46#include <TDF_CopyLabel.hxx>
47#include <TDF_AttributeIterator.hxx>
48#include <TDF_AttributeMap.hxx>
49#include <TDF_MapIteratorOfAttributeMap.hxx>
50
51
52//=======================================================================
53//function : MakeDF
54//purpose : Creates a new data framework.
55//=======================================================================
56
57static Standard_Integer MakeDF (Draw_Interpretor& di,
58 Standard_Integer n,
59 const char** a)
60{
61 if (n < 2) return 1;
62
63 Handle (Draw_Drawable3D) D = Draw::Get(a[1]);
64 Handle(DDF_Data) NewDDF;
65
66 if (!D.IsNull ()) {
67 NewDDF = Handle(DDF_Data)::DownCast (D);
68 if (!NewDDF.IsNull ()) {
586db386 69 di<<"DDF_BasicCommands::MakeDF - Sorry, this Data Framework already exists\n";
7fd59977 70 return 0;
71 }
72 }
73
74 Handle(TDF_Data) NewDF = new TDF_Data ();
75 NewDDF = new DDF_Data (NewDF);
76 Draw::Set (a[1], NewDDF);
77 //DeltaDS.Nullify();
78 return 0;
79}
80
81
82
83//=======================================================================
84//function : ClearDF
85//purpose : Creates a new data framework.
86//=======================================================================
87
88static Standard_Integer ClearDF (Draw_Interpretor& di,
89 Standard_Integer n,
90 const char** a)
91
92{
93 if (n < 2) return 1;
94
95 Handle (Draw_Drawable3D) D = Draw::Get(a[1]);
96 Handle(DDF_Data) DDF;
97
98 if (!D.IsNull ()) {
99 DDF = Handle(DDF_Data)::DownCast (D);
100 if (!DDF.IsNull ()) {
101 Handle(TDF_Data) DF = DDF->DataFramework ();
102 if (!DF.IsNull ()) {
103 Handle(TDF_Data) NewEmpty = new TDF_Data;
104 DDF->DataFramework (NewEmpty);
105 //DeltaDS.Nullify();
106 }
107 return 0;
108 }
109 }
110
586db386 111 di<<"DDF_BasicCommands::MakeDF - Sorry, this Data Framework doesn't exist\n";
7fd59977 112
113 return 0;
114}
115
116
117//=======================================================================
118//function : CopyDF
119//purpose : CopyDF.
120//=======================================================================
121
122static Standard_Integer CopyDF (Draw_Interpretor& /*di*/,
123 Standard_Integer n,
124 const char** a)
125{
126 if (n < 4 || n > 5) return 1;
127
128
129 Handle(TDF_Data) DF1;
130 Handle(TDF_Data) DF2;
131 Standard_CString Entry1;
132 Standard_CString Entry2;
133
134 if (!DDF::GetDF (a[1], DF1)) return 1;
135
136 Entry1 = a[2];
137 Entry2 = a[3];
138
139 if (n == 4) {
140 DF2 = DF1;
141 Entry2 = a[3];
142 }
143 else if (n == 5) {
144 if (!DDF::GetDF (a[3], DF2)) return 1;
145 Entry2 = a[4];
146 }
147
148 TDF_Label Label1;
149 if (!DDF::FindLabel (DF1, Entry1, Label1)) return 1;
150
151 TDF_Label Label2;
152 if (!DDF::FindLabel (DF2, Entry2, Label2, Standard_False)) {
153 DDF::AddLabel(DF2,Entry2,Label2);
154 }
155
156
157 Handle(TDF_DataSet) DataSet = new TDF_DataSet;
9f446594 158 DataSet->AddLabel(Label1);
7fd59977 159 TDF_ClosureTool::Closure(DataSet);
160 Handle(TDF_RelocationTable) Reloc = new TDF_RelocationTable();
161 Reloc->SetRelocation(Label1,Label2);
162 TDF_CopyTool::Copy (DataSet, Reloc);
163
164 return 0;
165}
166
167
168//=======================================================================
169//function : MiniDumpDF
170//purpose :
171//=======================================================================
172
173static Standard_Integer MiniDumpDF (Draw_Interpretor& di,
174 Standard_Integer n,
175 const char** a)
176{
177 if (n < 2) return 1;
178
179 Handle (Draw_Drawable3D) D;
180 Handle(DDF_Data) DDF;
181
182 D = Draw::Get(a[1]);
183
184 if (D.IsNull ()) {
586db386 185 di<<"DDF_BasicCommands : Sorry this Data Framework doesn't exist\n";
7fd59977 186 return Standard_False;
187 }
188
189 DDF = Handle(DDF_Data)::DownCast (D);
190
191 if (DDF.IsNull ()) {
586db386 192 di<<"DDF_BasicCommands : Sorry this Data Framework doesn't exist\n";
7fd59977 193 return Standard_False;
194 }
195
586db386 196 di<<"*********** Dump of "<<a[1]<<" ***********\n";
7fd59977 197
198 //DDF->DataFramework()->Dump(cout);
199 Standard_SStream aSStream;
200 DDF->DataFramework()->Dump(aSStream);
201 aSStream << ends;
202 di << aSStream << "\n";
203
204 return 0;
205}
206//=======================================================================
207//function : XDumpDF
208//purpose : eXtended deep dump of a DataFramework
209//=======================================================================
210
211static Standard_Integer XDumpDF (Draw_Interpretor& di,
212 Standard_Integer n,
213 const char** a)
214{
215 if (n < 2) return 1;
216
217 Handle (Draw_Drawable3D) D;
218 Handle(DDF_Data) DDF;
219
220 D = Draw::Get(a[1]);
221
222 if (D.IsNull ()) {
586db386 223 di<<"DDF_BasicCommands : Sorry this Data Framework doesn't exist\n";
7fd59977 224 return Standard_False;
225 }
226
227 DDF = Handle(DDF_Data)::DownCast (D);
228
229 if (DDF.IsNull ()) {
586db386 230 di<<"DDF_BasicCommands : Sorry this Data Framework doesn't exist\n";
7fd59977 231 return Standard_False;
232 }
233
586db386 234 di<<"*********** Dump of "<<a[1]<<" ***********\n";
7fd59977 235
236 TDF_IDFilter filter(Standard_False);
237 //TDF_Tool::ExtendedDeepDump(cout,DDF->DataFramework(),filter);
238 Standard_SStream aSStream;
239 TDF_Tool::ExtendedDeepDump(aSStream,DDF->DataFramework(),filter);
240 aSStream << ends;
241 di << aSStream <<"\n";
242
243 return 0;
244}
245
246
247//=======================================================================
248//function : CopyLabel_SCopy
249//purpose : CopyLabel (DF,fromlabel,tolabel)
250//=======================================================================
251
252static Standard_Integer CopyLabel_SCopy (Draw_Interpretor& di,Standard_Integer n, const char** a)
253{
254 TDF_Label SOURCE,TARGET;
255 if (n == 4) {
256 Handle(TDF_Data) DF;
257 if(!DDF::GetDF(a[1], DF)) return 1;
258 if (!DDF::FindLabel(DF,a[2],SOURCE)) return 1;
259 if (DDF::FindLabel(DF,a[3],TARGET)) {
586db386 260 di << " target label is already setted \n";
7fd59977 261 return 1;
262 }
263 DDF::AddLabel(DF,a[3],TARGET);
264 TDF_CopyLabel cop;
265 cop.Load(SOURCE, TARGET);
266 cop.Perform();
267 if (!cop.IsDone())
586db386 268 di << "copy not done\n";
7fd59977 269 return 0;
270 }
586db386 271 di << "DDF_CopyLabel : Error\n";
7fd59977 272 return 1;
273}
274
275//=======================================================================
276//function : DDF_CheckAttr
277//purpose : CheckAttr (DOC,label1,label2)
278// : Checks references of attributes of label1 and label2
279// : in order to find shareable attributes
280//=======================================================================
281
282static Standard_Integer DDF_CheckAttrs (Draw_Interpretor& di,Standard_Integer n, const char** a)
283{
284 TDF_Label SOURCE,TARGET;
285 if (n == 4) {
286 Handle(TDF_Data) DF;
287 if(!DDF::GetDF(a[1], DF)) return 1;
288 if (!DDF::FindLabel(DF,a[2],SOURCE)) return 1;
289 if (!DDF::FindLabel(DF,a[3],TARGET)) return 1;
290
291 Handle(TDF_DataSet) ds1 = new TDF_DataSet();
292 Handle(TDF_DataSet) ds2 = new TDF_DataSet();
293 Standard_Boolean Shar = Standard_False;
294 for (TDF_AttributeIterator itr(SOURCE); itr.More(); itr.Next()) {
295 itr.Value()->References(ds1);
296// cout<<"\tSource Attribute dynamic type = "<<itr.Value()->DynamicType()<<endl;
297 const TDF_AttributeMap& attMap = ds1->Attributes(); //attMap
298 for (TDF_MapIteratorOfAttributeMap attMItr(attMap);attMItr.More(); attMItr.Next()) {
299 Handle(TDF_Attribute) sAtt = attMItr.Key();
300// cout<<"\t\tSource references attribute dynamic type = "<<sAtt->DynamicType()<<endl;
301 for (TDF_AttributeIterator itr2(TARGET); itr2.More(); itr2.Next()) {
302 itr2.Value()->References(ds2);
303// cout<<"\t\t\tTARGET attribute dynamic type = "<<itr2.Value()->DynamicType()<<endl;
304 const TDF_AttributeMap& attMap2 = ds2->Attributes(); //attMap
305 for (TDF_MapIteratorOfAttributeMap attMItr2(attMap2);attMItr2.More(); attMItr2.Next()) {
306 Handle(TDF_Attribute) tAtt = attMItr2.Key();
307// cout<<"\t\t\t\tTarget reference attribute dynamic type = "<<tAtt->DynamicType()<<endl;
308 if (tAtt->IsInstance(sAtt->DynamicType()))
309 if(tAtt == sAtt) {
310 TCollection_AsciiString entr1,entr2;
311 if(!Shar) {
312 TDF_Tool::Entry(SOURCE, entr1);
313 TDF_Tool::Entry(TARGET, entr2);
314 //cout<<"\tSHAREABLE attribute(s) found between Lab1 = "<<entr1<<" and Lab2 = "<<entr2<<endl;
315 di<<"\tSHAREABLE attribute(s) found between Lab1 = "<<entr1.ToCString()<<" and Lab2 = "<<entr2.ToCString()<<"\n";
316 Shar = Standard_True;
317 }
318 TDF_Tool::Entry(sAtt->Label(), entr1);
319 //cout<<"\tAttribute dynamic type = "<<sAtt->DynamicType()<<",\tlocated on Label = "<<entr1<<endl;
69ff08ff 320 di<<"\tAttribute dynamic type = " << sAtt->DynamicType()->Name();
7fd59977 321 di<<",\tlocated on Label = "<<entr1.ToCString()<<"\n";
322 }
323 }
324 ds2->Clear();
325 }
326 }
327 ds1->Clear();
328 }
329 if(!Shar)
586db386 330 di << "Shareable attributes not found\n";
7fd59977 331 return 0;
332 }
586db386 333 di << "DDF_CheckAttrs : Error\n";
7fd59977 334 return 1;
335}
336
337//=======================================================================
338//function : DDF_Checklabel
339//purpose : CheckLabel (DOC,label1,label2)
340// : prints all structure of first level attributes with its references
341//=======================================================================
342static Standard_Integer DDF_CheckLabel (Draw_Interpretor& di,Standard_Integer n, const char** a)
343{
344// TDF_Label SOURCE,TARGET;
345 TDF_Label SOURCE;
346 if (n == 3) {
347 Handle(TDF_Data) DF;
348 if(!DDF::GetDF(a[1], DF)) return 1;
349 if (!DDF::FindLabel(DF,a[2],SOURCE)) return 1;
350
351 Handle(TDF_DataSet) ds1 = new TDF_DataSet();
352 for (TDF_AttributeIterator itr(SOURCE); itr.More(); itr.Next()) {
353 itr.Value()->References(ds1);
354 //cout<<"\tSource Attribute dynamic type = "<<itr.Value()->DynamicType()<<endl;
69ff08ff 355 di<<"\tSource Attribute dynamic type = " << itr.Value()->DynamicType()->Name() << "\n";
7fd59977 356 const TDF_AttributeMap& attMap = ds1->Attributes(); //attMap
357 for (TDF_MapIteratorOfAttributeMap attMItr(attMap);attMItr.More(); attMItr.Next()) {
358 Handle(TDF_Attribute) sAtt = attMItr.Key();
359 TCollection_AsciiString entry;
360 TDF_Tool::Entry(sAtt->Label(), entry);
361 //cout<<"\t\tReferences attribute dynamic type = "<<sAtt->DynamicType()<<",\tLabel = "<<entry<<endl;
69ff08ff 362 di<<"\t\tReferences attribute dynamic type = " << sAtt->DynamicType()->Name();
7fd59977 363 di<<",\tLabel = "<<entry.ToCString()<<"\n";
364 }
365 ds1->Clear();
366 }
367
368 return 0;
369 }
586db386 370 di << "DDF_ChecLabel : Error\n";
7fd59977 371 return 1;
372}
373
374
375
376// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
377
378
379//=======================================================================
380//function : DataCommands
381//purpose :
382//=======================================================================
383
384void DDF::DataCommands (Draw_Interpretor& theCommands)
385{
386 static Standard_Boolean done = Standard_False;
387 if (done) return;
388 done = Standard_True;
389
390 const char* g = "DF Data Framework commands";
391
392 // Data Framework :
393 // ++++++++++++++++
394 theCommands.Add ("MakeDF",
395 "Makes a new DF: MakeDF dfname",
396 __FILE__, MakeDF, g);
397
398 theCommands.Add ("ClearDF",
399 "Clears a DF: ClearDF dfname",
400 __FILE__, ClearDF, g);
401
402 theCommands.Add ("CopyDF",
403 "Copies a label: CopyDF dfname1 entry1 [dfname2] entry2",
404 __FILE__, CopyDF, g);
405
406 theCommands.Add ("XDumpDF",
407 "Exented deep dump of a DF (with attributes content): DumpDF dfname",
408 __FILE__, XDumpDF, g);
409
410 theCommands.Add ("MiniDumpDF",
411 "Mini dump of a DF (with attributes content): DumpDF dfname",
412 __FILE__, MiniDumpDF, g);
413
414 theCommands.Add ("CopyLabel",
415 "CopyLabel (DOC, from, to)",
416 __FILE__, CopyLabel_SCopy, g);
417
418 theCommands.Add("CheckAttrs","CheckAttrs DocName Lab1 Lab2 ",
419 __FILE__, DDF_CheckAttrs, g);
420
421 theCommands.Add("CheckLabel","CheckLabel DocName Label ",
422 __FILE__, DDF_CheckLabel, g);
423
424}