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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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>
23 // ====================================================================================
24 // This sample contains template for typical actions with OCAF document at application
25 // level (store / retrieve)
26 // ====================================================================================
33 //...Creating application
35 Handle(TDocStd_Application) app = new TDocStd_Application;
37 //...Creating the new document (document contains a framework)
39 Handle(TDocStd_Document) doc;
40 app->NewDocument("Standard", doc);
42 //...Getting application to which the document belongs
44 app = Handle(TDocStd_Application)::DownCast(doc->Application());
47 //...Getting application to which the document belongs
49 app = Handle(TDocStd_Application)::DownCast(doc->Application());
52 //...Getting data framework from document
54 Handle(TDF_Data) framework = doc->GetData();
56 //...Retrieving the document from a label of its framework
59 doc = TDocStd_Document::Get(label);
61 //... Filling document with data
63 //Saving document in the file "/tmp/example.std" give the full path
65 app->SaveAs(doc, "/tmp/example.std");
71 //Opening document stored in file
73 app->Open("/tmp/example.std", doc);
78 //Coping content of a document to another document with possibility update copy in future
80 Handle(TDocStd_Document) doc1;
81 Handle(TDocStd_Document) doc2;
84 TDF_Label source = doc1->GetData()->Root();
85 TDF_Label target = doc2->GetData()->Root();
86 TDocStd_XLinkTool XLinkTool;
88 //Coping content of a document to another document with possibility update copy in future
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
93 //...Something is changed in source document
95 //Updating copy in target document
97 XLinkTool.UpdateLink(target);
99 //Cping content of a document to another document
101 XLinkTool.Copy(target, source); //Now target document has a copy of source document, there is no link between
102 //the copy and original