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> |
bc228f77 |
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 | |
8a39adb7 |
35 | Handle(TDocStd_Application) app = new TDocStd_Application; |
bc228f77 |
36 | |
a110c4a3 |
37 | //...Creating the new document (document contains a framework) |
bc228f77 |
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 |
a110c4a3 |
91 | //a link to have possibility update content of the copy if original changed |
bc228f77 |
92 | |
a110c4a3 |
93 | //...Something is changed in source document |
bc228f77 |
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 |