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
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.
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.
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.
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 //#include <AppSketch_Application.hxx>
38 //...Creating application (example of sketch)
40 Handle(TDocStd_Application) app; // = new AppSketch_Application ();
42 // the application is now handled by the CDF_Session variable
45 //...Retrieving the application
48 if (!CDF_Session::Exists()) {
49 Handle(CDF_Session) S = CDF_Session::CurrentSession();
50 if (!S->HasCurrentApplication())
51 Standard_DomainError::Raise("DDocStd::Find no applicative session");
52 app = Handle(TDocStd_Application)::DownCast(S->CurrentApplication());
55 // none active application
58 //...Creating the new document (document conatins a framework)
60 Handle(TDocStd_Document) doc;
61 app->NewDocument("NewDocumentFormat", doc);
63 //...Getting application to which the document belongs
65 app = Handle(TDocStd_Application)::DownCast(doc->Application());
68 //...Getting application to which the document belongs
70 app = Handle(TDocStd_Application)::DownCast(doc->Application());
73 //...Getting data framework from document
75 Handle(TDF_Data) framework = doc->GetData();
77 //...Retrieving the document from a label of its framework
80 doc = TDocStd_Document::Get(label);
82 //... Filling document with data
84 //Saving document in the file "/tmp/example.caf" give the full path
86 app->SaveAs(doc, "/tmp/example.caf");
92 //Opening document stored in file
94 app->Open("/tmp/example.caf", doc);
99 //Coping content of a document to another document with possibility update copy in future
101 Handle(TDocStd_Document) doc1;
102 Handle(TDocStd_Document) doc2;
105 TDF_Label source = doc1->GetData()->Root();
106 TDF_Label target = doc2->GetData()->Root();
107 TDocStd_XLinkTool XLinkTool;
109 //Coping content of a document to another document with possibility update copy in future
111 XLinkTool.CopyWithLink(target,source); //Now target document has a copy of source document , the copy also has
112 //a link to have possibility update content of the copy if orginal changed
114 //...Something is chaneged in source document
116 //Updating copy in target document
118 XLinkTool.UpdateLink(target);
120 //Cping content of a document to another document
122 XLinkTool.Copy(target, source); //Now target document has a copy of source document, there is no link between
123 //the copy and original