0031939: Coding - correction of spelling errors in comments [part 2]
[occt.git] / samples / ocafsamples / TDocStd_Sample.cxx
1 // Created on: 1999-12-28
2 // Created by: Sergey RUIN
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <TDF_Data.hxx>
18 #include <TDF_Label.hxx>
19 #include <TDocStd_Application.hxx>
20 #include <TDocStd_Document.hxx>
21 #include <TDocStd_XLinkTool.hxx> 
22
23 // ====================================================================================
24 // This sample contains template for typical actions with OCAF document at application 
25 // level (store / retrieve)
26 // ====================================================================================
27
28 #ifdef DEB
29 static void Sample()
30 {
31
32   
33   //...Creating application 
34
35   Handle(TDocStd_Application) app = new TDocStd_Application;
36   
37   //...Creating the new document (document contains a framework)
38
39   Handle(TDocStd_Document) doc;
40   app->NewDocument("Standard", doc);
41   
42   //...Getting application to which the document belongs
43
44   app =  Handle(TDocStd_Application)::DownCast(doc->Application());
45
46
47   //...Getting application to which the document belongs
48
49   app =  Handle(TDocStd_Application)::DownCast(doc->Application());
50  
51
52   //...Getting data framework from document
53
54   Handle(TDF_Data) framework = doc->GetData();
55
56   //...Retrieving the document from a label of its framework
57
58   TDF_Label label; 
59   doc =  TDocStd_Document::Get(label);
60
61   //... Filling document with data
62
63   //Saving document in the file "/tmp/example.std" give the full path
64
65   app->SaveAs(doc, "/tmp/example.std");
66
67   //Closing document
68
69   app->Close(doc);
70
71   //Opening document stored in file
72
73   app->Open("/tmp/example.std", doc);
74
75
76
77
78   //Coping content of a document to another document with possibility update copy in future
79
80   Handle(TDocStd_Document) doc1;  
81   Handle(TDocStd_Document) doc2;
82
83
84   TDF_Label source = doc1->GetData()->Root();
85   TDF_Label target = doc2->GetData()->Root();
86   TDocStd_XLinkTool XLinkTool;
87
88   //Coping content of a document to another document with possibility update copy in future
89
90   XLinkTool.CopyWithLink(target,source); //Now target document has a copy of source document , the copy also has
91                                                  //a link to have possibility update content of the copy if original changed
92
93   //...Something is changed in source document
94
95   //Updating copy in target document 
96
97   XLinkTool.UpdateLink(target);
98
99   //Cping content of a document to another document
100
101   XLinkTool.Copy(target, source); //Now target document has a copy of source document, there is no link between
102                                   //the copy  and original
103   
104   
105 }
106 #endif