1 // Created by: DAUTRY Philippe
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
20 // --------------------
23 //Version Date Purpose
24 // 0.0 Sep 30 1997 Creation
28 #include <TDF_ClosureMode.hxx>
29 #include <TDF_ClosureTool.hxx>
30 #include <TDF_CopyTool.hxx>
33 #include <DDF_Data.hxx>
36 #include <Draw_Appli.hxx>
37 #include <Draw_Drawable3D.hxx>
38 #include <Draw_Interpretor.hxx>
40 #include <Standard_NotImplemented.hxx>
42 #include <TDF_ChildIterator.hxx>
43 #include <TDF_Data.hxx>
44 #include <TDF_DataSet.hxx>
45 #include <TDF_IDFilter.hxx>
46 #include <TDF_Label.hxx>
47 #include <TDF_RelocationTable.hxx>
48 #include <TDF_Tool.hxx>
49 #include <TDF_CopyLabel.hxx>
50 #include <TDF_CopyLabel.hxx>
51 #include <TDF_AttributeIterator.hxx>
52 #include <TDF_AttributeMap.hxx>
53 #include <TDF_MapIteratorOfAttributeMap.hxx>
56 //=======================================================================
58 //purpose : Creates a new data framework.
59 //=======================================================================
61 static Standard_Integer MakeDF (Draw_Interpretor& di,
67 Handle (Draw_Drawable3D) D = Draw::Get(a[1]);
68 Handle(DDF_Data) NewDDF;
71 NewDDF = Handle(DDF_Data)::DownCast (D);
72 if (!NewDDF.IsNull ()) {
73 di<<"DDF_BasicCommands::MakeDF - Sorry, this Data Framework already exists"<<"\n";
78 Handle(TDF_Data) NewDF = new TDF_Data ();
79 NewDDF = new DDF_Data (NewDF);
80 Draw::Set (a[1], NewDDF);
87 //=======================================================================
89 //purpose : Creates a new data framework.
90 //=======================================================================
92 static Standard_Integer ClearDF (Draw_Interpretor& di,
99 Handle (Draw_Drawable3D) D = Draw::Get(a[1]);
100 Handle(DDF_Data) DDF;
103 DDF = Handle(DDF_Data)::DownCast (D);
104 if (!DDF.IsNull ()) {
105 Handle(TDF_Data) DF = DDF->DataFramework ();
107 Handle(TDF_Data) NewEmpty = new TDF_Data;
108 DDF->DataFramework (NewEmpty);
115 di<<"DDF_BasicCommands::MakeDF - Sorry, this Data Framework doesn't exist"<<"\n";
121 //=======================================================================
124 //=======================================================================
126 static Standard_Integer CopyDF (Draw_Interpretor& /*di*/,
130 if (n < 4 || n > 5) return 1;
133 Handle(TDF_Data) DF1;
134 Handle(TDF_Data) DF2;
135 Standard_CString Entry1;
136 Standard_CString Entry2;
138 if (!DDF::GetDF (a[1], DF1)) return 1;
148 if (!DDF::GetDF (a[3], DF2)) return 1;
153 if (!DDF::FindLabel (DF1, Entry1, Label1)) return 1;
156 if (!DDF::FindLabel (DF2, Entry2, Label2, Standard_False)) {
157 DDF::AddLabel(DF2,Entry2,Label2);
161 Handle(TDF_DataSet) DataSet = new TDF_DataSet;
162 DataSet->AddLabel(Label1);
163 TDF_ClosureTool::Closure(DataSet);
164 Handle(TDF_RelocationTable) Reloc = new TDF_RelocationTable();
165 Reloc->SetRelocation(Label1,Label2);
166 TDF_CopyTool::Copy (DataSet, Reloc);
172 //=======================================================================
173 //function : MiniDumpDF
175 //=======================================================================
177 static Standard_Integer MiniDumpDF (Draw_Interpretor& di,
183 Handle (Draw_Drawable3D) D;
184 Handle(DDF_Data) DDF;
189 di<<"DDF_BasicCommands : Sorry this Data Framework doesn't exist"<<"\n";
190 return Standard_False;
193 DDF = Handle(DDF_Data)::DownCast (D);
196 di<<"DDF_BasicCommands : Sorry this Data Framework doesn't exist"<<"\n";
197 return Standard_False;
200 di<<"*********** Dump of "<<a[1]<<" ***********"<<"\n";
202 //DDF->DataFramework()->Dump(cout);
203 Standard_SStream aSStream;
204 DDF->DataFramework()->Dump(aSStream);
206 di << aSStream << "\n";
210 //=======================================================================
212 //purpose : eXtended deep dump of a DataFramework
213 //=======================================================================
215 static Standard_Integer XDumpDF (Draw_Interpretor& di,
221 Handle (Draw_Drawable3D) D;
222 Handle(DDF_Data) DDF;
227 di<<"DDF_BasicCommands : Sorry this Data Framework doesn't exist"<<"\n";
228 return Standard_False;
231 DDF = Handle(DDF_Data)::DownCast (D);
234 di<<"DDF_BasicCommands : Sorry this Data Framework doesn't exist"<<"\n";
235 return Standard_False;
238 di<<"*********** Dump of "<<a[1]<<" ***********"<<"\n";
240 TDF_IDFilter filter(Standard_False);
241 //TDF_Tool::ExtendedDeepDump(cout,DDF->DataFramework(),filter);
242 Standard_SStream aSStream;
243 TDF_Tool::ExtendedDeepDump(aSStream,DDF->DataFramework(),filter);
245 di << aSStream <<"\n";
251 //=======================================================================
252 //function : CopyLabel_SCopy
253 //purpose : CopyLabel (DF,fromlabel,tolabel)
254 //=======================================================================
256 static Standard_Integer CopyLabel_SCopy (Draw_Interpretor& di,Standard_Integer n, const char** a)
258 TDF_Label SOURCE,TARGET;
261 if(!DDF::GetDF(a[1], DF)) return 1;
262 if (!DDF::FindLabel(DF,a[2],SOURCE)) return 1;
263 if (DDF::FindLabel(DF,a[3],TARGET)) {
264 di << " target label is already setted "<< "\n";
267 DDF::AddLabel(DF,a[3],TARGET);
269 cop.Load(SOURCE, TARGET);
272 di << "copy not done" << "\n";
275 di << "DDF_CopyLabel : Error" << "\n";
279 //=======================================================================
280 //function : DDF_CheckAttr
281 //purpose : CheckAttr (DOC,label1,label2)
282 // : Checks references of attributes of label1 and label2
283 // : in order to find shareable attributes
284 //=======================================================================
286 static Standard_Integer DDF_CheckAttrs (Draw_Interpretor& di,Standard_Integer n, const char** a)
288 TDF_Label SOURCE,TARGET;
291 if(!DDF::GetDF(a[1], DF)) return 1;
292 if (!DDF::FindLabel(DF,a[2],SOURCE)) return 1;
293 if (!DDF::FindLabel(DF,a[3],TARGET)) return 1;
295 Handle(TDF_DataSet) ds1 = new TDF_DataSet();
296 Handle(TDF_DataSet) ds2 = new TDF_DataSet();
297 Standard_Boolean Shar = Standard_False;
298 for (TDF_AttributeIterator itr(SOURCE); itr.More(); itr.Next()) {
299 itr.Value()->References(ds1);
300 // cout<<"\tSource Attribute dynamic type = "<<itr.Value()->DynamicType()<<endl;
301 const TDF_AttributeMap& attMap = ds1->Attributes(); //attMap
302 for (TDF_MapIteratorOfAttributeMap attMItr(attMap);attMItr.More(); attMItr.Next()) {
303 Handle(TDF_Attribute) sAtt = attMItr.Key();
304 // cout<<"\t\tSource references attribute dynamic type = "<<sAtt->DynamicType()<<endl;
305 for (TDF_AttributeIterator itr2(TARGET); itr2.More(); itr2.Next()) {
306 itr2.Value()->References(ds2);
307 // cout<<"\t\t\tTARGET attribute dynamic type = "<<itr2.Value()->DynamicType()<<endl;
308 const TDF_AttributeMap& attMap2 = ds2->Attributes(); //attMap
309 for (TDF_MapIteratorOfAttributeMap attMItr2(attMap2);attMItr2.More(); attMItr2.Next()) {
310 Handle(TDF_Attribute) tAtt = attMItr2.Key();
311 // cout<<"\t\t\t\tTarget reference attribute dynamic type = "<<tAtt->DynamicType()<<endl;
312 if (tAtt->IsInstance(sAtt->DynamicType()))
314 TCollection_AsciiString entr1,entr2;
316 TDF_Tool::Entry(SOURCE, entr1);
317 TDF_Tool::Entry(TARGET, entr2);
318 //cout<<"\tSHAREABLE attribute(s) found between Lab1 = "<<entr1<<" and Lab2 = "<<entr2<<endl;
319 di<<"\tSHAREABLE attribute(s) found between Lab1 = "<<entr1.ToCString()<<" and Lab2 = "<<entr2.ToCString()<<"\n";
320 Shar = Standard_True;
322 TDF_Tool::Entry(sAtt->Label(), entr1);
323 //cout<<"\tAttribute dynamic type = "<<sAtt->DynamicType()<<",\tlocated on Label = "<<entr1<<endl;
324 di<<"\tAttribute dynamic type = ";
325 Standard_SStream aSStream;
326 sAtt->DynamicType()->Print(aSStream);
329 di<<",\tlocated on Label = "<<entr1.ToCString()<<"\n";
338 di << "Shareable attributes not found" << "\n";
341 di << "DDF_CheckAttrs : Error" << "\n";
345 //=======================================================================
346 //function : DDF_Checklabel
347 //purpose : CheckLabel (DOC,label1,label2)
348 // : prints all structure of first level attributes with its references
349 //=======================================================================
350 static Standard_Integer DDF_CheckLabel (Draw_Interpretor& di,Standard_Integer n, const char** a)
352 // TDF_Label SOURCE,TARGET;
356 if(!DDF::GetDF(a[1], DF)) return 1;
357 if (!DDF::FindLabel(DF,a[2],SOURCE)) return 1;
359 Handle(TDF_DataSet) ds1 = new TDF_DataSet();
360 for (TDF_AttributeIterator itr(SOURCE); itr.More(); itr.Next()) {
361 itr.Value()->References(ds1);
362 //cout<<"\tSource Attribute dynamic type = "<<itr.Value()->DynamicType()<<endl;
363 di<<"\tSource Attribute dynamic type = ";
364 Standard_SStream aSStream1;
365 itr.Value()->DynamicType()->Print(aSStream1);
367 di << aSStream1 << "\n";
368 const TDF_AttributeMap& attMap = ds1->Attributes(); //attMap
369 for (TDF_MapIteratorOfAttributeMap attMItr(attMap);attMItr.More(); attMItr.Next()) {
370 Handle(TDF_Attribute) sAtt = attMItr.Key();
371 TCollection_AsciiString entry;
372 TDF_Tool::Entry(sAtt->Label(), entry);
373 //cout<<"\t\tReferences attribute dynamic type = "<<sAtt->DynamicType()<<",\tLabel = "<<entry<<endl;
374 di<<"\t\tReferences attribute dynamic type = ";
375 Standard_SStream aSStream2;
376 sAtt->DynamicType()->Print(aSStream2);
378 di<<",\tLabel = "<<entry.ToCString()<<"\n";
385 di << "DDF_ChecLabel : Error" << "\n";
391 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
394 //=======================================================================
395 //function : DataCommands
397 //=======================================================================
399 void DDF::DataCommands (Draw_Interpretor& theCommands)
401 static Standard_Boolean done = Standard_False;
403 done = Standard_True;
405 const char* g = "DF Data Framework commands";
409 theCommands.Add ("MakeDF",
410 "Makes a new DF: MakeDF dfname",
411 __FILE__, MakeDF, g);
413 theCommands.Add ("ClearDF",
414 "Clears a DF: ClearDF dfname",
415 __FILE__, ClearDF, g);
417 theCommands.Add ("CopyDF",
418 "Copies a label: CopyDF dfname1 entry1 [dfname2] entry2",
419 __FILE__, CopyDF, g);
421 theCommands.Add ("XDumpDF",
422 "Exented deep dump of a DF (with attributes content): DumpDF dfname",
423 __FILE__, XDumpDF, g);
425 theCommands.Add ("MiniDumpDF",
426 "Mini dump of a DF (with attributes content): DumpDF dfname",
427 __FILE__, MiniDumpDF, g);
429 theCommands.Add ("CopyLabel",
430 "CopyLabel (DOC, from, to)",
431 __FILE__, CopyLabel_SCopy, g);
433 theCommands.Add("CheckAttrs","CheckAttrs DocName Lab1 Lab2 ",
434 __FILE__, DDF_CheckAttrs, g);
436 theCommands.Add("CheckLabel","CheckLabel DocName Label ",
437 __FILE__, DDF_CheckLabel, g);