1 // Created by: DAUTRY Philippe
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // --------------------
19 //Version Date Purpose
20 // 0.0 Sep 30 1997 Creation
24 #include <TDF_ClosureMode.hxx>
25 #include <TDF_ClosureTool.hxx>
26 #include <TDF_CopyTool.hxx>
29 #include <DDF_Data.hxx>
32 #include <Draw_Appli.hxx>
33 #include <Draw_Drawable3D.hxx>
34 #include <Draw_Interpretor.hxx>
36 #include <Standard_NotImplemented.hxx>
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>
52 //=======================================================================
54 //purpose : Creates a new data framework.
55 //=======================================================================
57 static Standard_Integer MakeDF (Draw_Interpretor& di,
63 Handle (Draw_Drawable3D) D = Draw::Get(a[1]);
64 Handle(DDF_Data) NewDDF;
67 NewDDF = Handle(DDF_Data)::DownCast (D);
68 if (!NewDDF.IsNull ()) {
69 di<<"DDF_BasicCommands::MakeDF - Sorry, this Data Framework already exists"<<"\n";
74 Handle(TDF_Data) NewDF = new TDF_Data ();
75 NewDDF = new DDF_Data (NewDF);
76 Draw::Set (a[1], NewDDF);
83 //=======================================================================
85 //purpose : Creates a new data framework.
86 //=======================================================================
88 static Standard_Integer ClearDF (Draw_Interpretor& di,
95 Handle (Draw_Drawable3D) D = Draw::Get(a[1]);
99 DDF = Handle(DDF_Data)::DownCast (D);
100 if (!DDF.IsNull ()) {
101 Handle(TDF_Data) DF = DDF->DataFramework ();
103 Handle(TDF_Data) NewEmpty = new TDF_Data;
104 DDF->DataFramework (NewEmpty);
111 di<<"DDF_BasicCommands::MakeDF - Sorry, this Data Framework doesn't exist"<<"\n";
117 //=======================================================================
120 //=======================================================================
122 static Standard_Integer CopyDF (Draw_Interpretor& /*di*/,
126 if (n < 4 || n > 5) return 1;
129 Handle(TDF_Data) DF1;
130 Handle(TDF_Data) DF2;
131 Standard_CString Entry1;
132 Standard_CString Entry2;
134 if (!DDF::GetDF (a[1], DF1)) return 1;
144 if (!DDF::GetDF (a[3], DF2)) return 1;
149 if (!DDF::FindLabel (DF1, Entry1, Label1)) return 1;
152 if (!DDF::FindLabel (DF2, Entry2, Label2, Standard_False)) {
153 DDF::AddLabel(DF2,Entry2,Label2);
157 Handle(TDF_DataSet) DataSet = new TDF_DataSet;
158 DataSet->AddLabel(Label1);
159 TDF_ClosureTool::Closure(DataSet);
160 Handle(TDF_RelocationTable) Reloc = new TDF_RelocationTable();
161 Reloc->SetRelocation(Label1,Label2);
162 TDF_CopyTool::Copy (DataSet, Reloc);
168 //=======================================================================
169 //function : MiniDumpDF
171 //=======================================================================
173 static Standard_Integer MiniDumpDF (Draw_Interpretor& di,
179 Handle (Draw_Drawable3D) D;
180 Handle(DDF_Data) DDF;
185 di<<"DDF_BasicCommands : Sorry this Data Framework doesn't exist"<<"\n";
186 return Standard_False;
189 DDF = Handle(DDF_Data)::DownCast (D);
192 di<<"DDF_BasicCommands : Sorry this Data Framework doesn't exist"<<"\n";
193 return Standard_False;
196 di<<"*********** Dump of "<<a[1]<<" ***********"<<"\n";
198 //DDF->DataFramework()->Dump(cout);
199 Standard_SStream aSStream;
200 DDF->DataFramework()->Dump(aSStream);
202 di << aSStream << "\n";
206 //=======================================================================
208 //purpose : eXtended deep dump of a DataFramework
209 //=======================================================================
211 static Standard_Integer XDumpDF (Draw_Interpretor& di,
217 Handle (Draw_Drawable3D) D;
218 Handle(DDF_Data) DDF;
223 di<<"DDF_BasicCommands : Sorry this Data Framework doesn't exist"<<"\n";
224 return Standard_False;
227 DDF = Handle(DDF_Data)::DownCast (D);
230 di<<"DDF_BasicCommands : Sorry this Data Framework doesn't exist"<<"\n";
231 return Standard_False;
234 di<<"*********** Dump of "<<a[1]<<" ***********"<<"\n";
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);
241 di << aSStream <<"\n";
247 //=======================================================================
248 //function : CopyLabel_SCopy
249 //purpose : CopyLabel (DF,fromlabel,tolabel)
250 //=======================================================================
252 static Standard_Integer CopyLabel_SCopy (Draw_Interpretor& di,Standard_Integer n, const char** a)
254 TDF_Label SOURCE,TARGET;
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)) {
260 di << " target label is already setted "<< "\n";
263 DDF::AddLabel(DF,a[3],TARGET);
265 cop.Load(SOURCE, TARGET);
268 di << "copy not done" << "\n";
271 di << "DDF_CopyLabel : Error" << "\n";
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 //=======================================================================
282 static Standard_Integer DDF_CheckAttrs (Draw_Interpretor& di,Standard_Integer n, const char** a)
284 TDF_Label SOURCE,TARGET;
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;
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()))
310 TCollection_AsciiString entr1,entr2;
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;
318 TDF_Tool::Entry(sAtt->Label(), entr1);
319 //cout<<"\tAttribute dynamic type = "<<sAtt->DynamicType()<<",\tlocated on Label = "<<entr1<<endl;
320 di<<"\tAttribute dynamic type = " << sAtt->DynamicType()->Name();
321 di<<",\tlocated on Label = "<<entr1.ToCString()<<"\n";
330 di << "Shareable attributes not found" << "\n";
333 di << "DDF_CheckAttrs : Error" << "\n";
337 //=======================================================================
338 //function : DDF_Checklabel
339 //purpose : CheckLabel (DOC,label1,label2)
340 // : prints all structure of first level attributes with its references
341 //=======================================================================
342 static Standard_Integer DDF_CheckLabel (Draw_Interpretor& di,Standard_Integer n, const char** a)
344 // TDF_Label SOURCE,TARGET;
348 if(!DDF::GetDF(a[1], DF)) return 1;
349 if (!DDF::FindLabel(DF,a[2],SOURCE)) return 1;
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;
355 di<<"\tSource Attribute dynamic type = " << itr.Value()->DynamicType()->Name() << "\n";
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;
362 di<<"\t\tReferences attribute dynamic type = " << sAtt->DynamicType()->Name();
363 di<<",\tLabel = "<<entry.ToCString()<<"\n";
370 di << "DDF_ChecLabel : Error" << "\n";
376 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
379 //=======================================================================
380 //function : DataCommands
382 //=======================================================================
384 void DDF::DataCommands (Draw_Interpretor& theCommands)
386 static Standard_Boolean done = Standard_False;
388 done = Standard_True;
390 const char* g = "DF Data Framework commands";
394 theCommands.Add ("MakeDF",
395 "Makes a new DF: MakeDF dfname",
396 __FILE__, MakeDF, g);
398 theCommands.Add ("ClearDF",
399 "Clears a DF: ClearDF dfname",
400 __FILE__, ClearDF, g);
402 theCommands.Add ("CopyDF",
403 "Copies a label: CopyDF dfname1 entry1 [dfname2] entry2",
404 __FILE__, CopyDF, g);
406 theCommands.Add ("XDumpDF",
407 "Exented deep dump of a DF (with attributes content): DumpDF dfname",
408 __FILE__, XDumpDF, g);
410 theCommands.Add ("MiniDumpDF",
411 "Mini dump of a DF (with attributes content): DumpDF dfname",
412 __FILE__, MiniDumpDF, g);
414 theCommands.Add ("CopyLabel",
415 "CopyLabel (DOC, from, to)",
416 __FILE__, CopyLabel_SCopy, g);
418 theCommands.Add("CheckAttrs","CheckAttrs DocName Lab1 Lab2 ",
419 __FILE__, DDF_CheckAttrs, g);
421 theCommands.Add("CheckLabel","CheckLabel DocName Label ",
422 __FILE__, DDF_CheckLabel, g);