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>
22 #include <CDF_Session.hxx>
24 // ====================================================================================
25 // This sample contains template for typical actions with OCAF document at application
26 // level (store / retrieve)
27 // ====================================================================================
34 //...Creating application
36 Handle(TDocStd_Application) app;
38 // the application is now handled by the CDF_Session variable
41 //...Retrieving the application
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());
51 // none active application
54 //...Creating the new document (document conatins a framework)
56 Handle(TDocStd_Document) doc;
57 app->NewDocument("Standard", doc);
59 //...Getting application to which the document belongs
61 app = Handle(TDocStd_Application)::DownCast(doc->Application());
64 //...Getting application to which the document belongs
66 app = Handle(TDocStd_Application)::DownCast(doc->Application());
69 //...Getting data framework from document
71 Handle(TDF_Data) framework = doc->GetData();
73 //...Retrieving the document from a label of its framework
76 doc = TDocStd_Document::Get(label);
78 //... Filling document with data
80 //Saving document in the file "/tmp/example.std" give the full path
82 app->SaveAs(doc, "/tmp/example.std");
88 //Opening document stored in file
90 app->Open("/tmp/example.std", doc);
95 //Coping content of a document to another document with possibility update copy in future
97 Handle(TDocStd_Document) doc1;
98 Handle(TDocStd_Document) doc2;
101 TDF_Label source = doc1->GetData()->Root();
102 TDF_Label target = doc2->GetData()->Root();
103 TDocStd_XLinkTool XLinkTool;
105 //Coping content of a document to another document with possibility update copy in future
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
110 //...Something is chaneged in source document
112 //Updating copy in target document
114 XLinkTool.UpdateLink(target);
116 //Cping content of a document to another document
118 XLinkTool.Copy(target, source); //Now target document has a copy of source document, there is no link between
119 //the copy and original