bc228f77 |
1 | // Created on: 1999-12-28 |
2 | // Created by: Sergey RUIN |
3 | // Copyright (c) 1999-1999 Matra Datavision |
480bf81e |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
bc228f77 |
5 | // |
480bf81e |
6 | // This file is part of Open CASCADE Technology software library. |
bc228f77 |
7 | // |
480bf81e |
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. |
bc228f77 |
13 | // |
480bf81e |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
bc228f77 |
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 | #include <CDF_Session.hxx> |
23 | |
24 | // ==================================================================================== |
25 | // This sample contains template for typical actions with OCAF document at application |
26 | // level (store / retrieve) |
27 | // ==================================================================================== |
28 | |
29 | #ifdef DEB |
30 | static void Sample() |
31 | { |
32 | |
33 | |
34 | //...Creating application |
35 | |
36 | Handle(TDocStd_Application) app; |
37 | |
38 | // the application is now handled by the CDF_Session variable |
39 | |
40 | |
41 | //...Retrieving the application |
42 | |
43 | |
44 | if (!CDF_Session::Exists()) { |
45 | Handle(CDF_Session) S = CDF_Session::CurrentSession(); |
46 | if (!S->HasCurrentApplication()) |
47 | Standard_DomainError::Raise("DDocStd::Find no applicative session"); |
48 | app = Handle(TDocStd_Application)::DownCast(S->CurrentApplication()); |
49 | } |
50 | else { |
51 | // none active application |
52 | } |
53 | |
54 | //...Creating the new document (document conatins a framework) |
55 | |
56 | Handle(TDocStd_Document) doc; |
57 | app->NewDocument("Standard", doc); |
58 | |
59 | //...Getting application to which the document belongs |
60 | |
61 | app = Handle(TDocStd_Application)::DownCast(doc->Application()); |
62 | |
63 | |
64 | //...Getting application to which the document belongs |
65 | |
66 | app = Handle(TDocStd_Application)::DownCast(doc->Application()); |
67 | |
68 | |
69 | //...Getting data framework from document |
70 | |
71 | Handle(TDF_Data) framework = doc->GetData(); |
72 | |
73 | //...Retrieving the document from a label of its framework |
74 | |
75 | TDF_Label label; |
76 | doc = TDocStd_Document::Get(label); |
77 | |
78 | //... Filling document with data |
79 | |
80 | //Saving document in the file "/tmp/example.std" give the full path |
81 | |
82 | app->SaveAs(doc, "/tmp/example.std"); |
83 | |
84 | //Closing document |
85 | |
86 | app->Close(doc); |
87 | |
88 | //Opening document stored in file |
89 | |
90 | app->Open("/tmp/example.std", doc); |
91 | |
92 | |
93 | |
94 | |
95 | //Coping content of a document to another document with possibility update copy in future |
96 | |
97 | Handle(TDocStd_Document) doc1; |
98 | Handle(TDocStd_Document) doc2; |
99 | |
100 | |
101 | TDF_Label source = doc1->GetData()->Root(); |
102 | TDF_Label target = doc2->GetData()->Root(); |
103 | TDocStd_XLinkTool XLinkTool; |
104 | |
105 | //Coping content of a document to another document with possibility update copy in future |
106 | |
107 | XLinkTool.CopyWithLink(target,source); //Now target document has a copy of source document , the copy also has |
108 | //a link to have possibility update content of the copy if orginal changed |
109 | |
110 | //...Something is chaneged in source document |
111 | |
112 | //Updating copy in target document |
113 | |
114 | XLinkTool.UpdateLink(target); |
115 | |
116 | //Cping content of a document to another document |
117 | |
118 | XLinkTool.Copy(target, source); //Now target document has a copy of source document, there is no link between |
119 | //the copy and original |
120 | |
121 | |
122 | } |
123 | #endif |