9ad792559424cc02e76d4960d05a86f4ef56484b
[occt.git] / src / DDocStd / DDocStd_Sample.cxx
1 // Created on: 1999-12-28
2 // Created by: Sergey RUIN
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23 #include <TDF_Data.hxx>
24 #include <TDF_Label.hxx>
25 #include <TDocStd_Application.hxx>
26 #include <TDocStd_Document.hxx>
27 #include <TDocStd_XLinkTool.hxx> 
28 #include <CDF_Session.hxx> 
29 //#include <AppSketch_Application.hxx>
30
31
32 // Unused :
33 #ifdef DEB
34 static void Sample()
35 {
36
37   
38   //...Creating application (example of sketch)
39
40   Handle(TDocStd_Application) app; // = new AppSketch_Application ();
41
42   // the application is now handled by the CDF_Session variable
43
44
45   //...Retrieving the  application
46
47
48   if (!CDF_Session::Exists()) {
49     Handle(CDF_Session) S = CDF_Session::CurrentSession();  
50     if (!S->HasCurrentApplication())  
51     Standard_DomainError::Raise("DDocStd::Find no applicative session");
52     app = Handle(TDocStd_Application)::DownCast(S->CurrentApplication());
53   }
54   else {
55     // none active application
56   }
57   
58   //...Creating the new document (document conatins a framework) 
59
60   Handle(TDocStd_Document) doc;
61   app->NewDocument("NewDocumentFormat", doc);
62   
63   //...Getting application to which the document belongs
64
65   app =  Handle(TDocStd_Application)::DownCast(doc->Application());
66
67
68   //...Getting application to which the document belongs
69
70   app =  Handle(TDocStd_Application)::DownCast(doc->Application());
71  
72
73   //...Getting data framework from document
74
75   Handle(TDF_Data) framework = doc->GetData();
76
77   //...Retrieving the document from a label of its framework
78
79   TDF_Label label; 
80   doc =  TDocStd_Document::Get(label);
81
82   //... Filling document with data
83
84   //Saving document in the file "/tmp/example.caf" give the full path
85
86   app->SaveAs(doc, "/tmp/example.caf");
87
88   //Closing document
89
90   app->Close(doc);
91
92   //Opening document stored in file
93
94   app->Open("/tmp/example.caf", doc);
95
96
97
98
99   //Coping content of a document to another document with possibility update copy in future
100
101   Handle(TDocStd_Document) doc1;  
102   Handle(TDocStd_Document) doc2;
103
104
105   TDF_Label source = doc1->GetData()->Root();
106   TDF_Label target = doc2->GetData()->Root();
107   TDocStd_XLinkTool XLinkTool;
108
109   //Coping content of a document to another document with possibility update copy in future
110
111   XLinkTool.CopyWithLink(target,source); //Now target document has a copy of source document , the copy also has
112                                                  //a link to have possibility update content of the copy if orginal changed
113
114   //...Something is chaneged in source document
115
116   //Updating copy in target document 
117
118   XLinkTool.UpdateLink(target);
119
120   //Cping content of a document to another document
121
122   XLinkTool.Copy(target, source); //Now target document has a copy of source document, there is no link between
123                                   //the copy  and original
124   
125   
126 }
127 #endif