0024428: Implementation of LGPL license
[occt.git] / samples / ocafsamples / TDocStd_Sample.cxx
... / ...
CommitLineData
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
30// ====================================================================================
31// This sample contains template for typical actions with OCAF document at application
32// level (store / retrieve)
33// ====================================================================================
34
35#ifdef DEB
36static void Sample()
37{
38
39
40 //...Creating application
41
42 Handle(TDocStd_Application) app;
43
44 // the application is now handled by the CDF_Session variable
45
46
47 //...Retrieving the application
48
49
50 if (!CDF_Session::Exists()) {
51 Handle(CDF_Session) S = CDF_Session::CurrentSession();
52 if (!S->HasCurrentApplication())
53 Standard_DomainError::Raise("DDocStd::Find no applicative session");
54 app = Handle(TDocStd_Application)::DownCast(S->CurrentApplication());
55 }
56 else {
57 // none active application
58 }
59
60 //...Creating the new document (document conatins a framework)
61
62 Handle(TDocStd_Document) doc;
63 app->NewDocument("Standard", doc);
64
65 //...Getting application to which the document belongs
66
67 app = Handle(TDocStd_Application)::DownCast(doc->Application());
68
69
70 //...Getting application to which the document belongs
71
72 app = Handle(TDocStd_Application)::DownCast(doc->Application());
73
74
75 //...Getting data framework from document
76
77 Handle(TDF_Data) framework = doc->GetData();
78
79 //...Retrieving the document from a label of its framework
80
81 TDF_Label label;
82 doc = TDocStd_Document::Get(label);
83
84 //... Filling document with data
85
86 //Saving document in the file "/tmp/example.std" give the full path
87
88 app->SaveAs(doc, "/tmp/example.std");
89
90 //Closing document
91
92 app->Close(doc);
93
94 //Opening document stored in file
95
96 app->Open("/tmp/example.std", doc);
97
98
99
100
101 //Coping content of a document to another document with possibility update copy in future
102
103 Handle(TDocStd_Document) doc1;
104 Handle(TDocStd_Document) doc2;
105
106
107 TDF_Label source = doc1->GetData()->Root();
108 TDF_Label target = doc2->GetData()->Root();
109 TDocStd_XLinkTool XLinkTool;
110
111 //Coping content of a document to another document with possibility update copy in future
112
113 XLinkTool.CopyWithLink(target,source); //Now target document has a copy of source document , the copy also has
114 //a link to have possibility update content of the copy if orginal changed
115
116 //...Something is chaneged in source document
117
118 //Updating copy in target document
119
120 XLinkTool.UpdateLink(target);
121
122 //Cping content of a document to another document
123
124 XLinkTool.Copy(target, source); //Now target document has a copy of source document, there is no link between
125 //the copy and original
126
127
128}
129#endif