1 // Created on: 2000-03-01
2 // Created by: Denis PASCAL
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <CDF_Session.hxx>
19 #include <DDocStd.hxx>
20 #include <DDocStd_DrawDocument.hxx>
22 #include <Draw_Interpretor.hxx>
23 #include <Standard_DomainError.hxx>
24 #include <Standard_GUID.hxx>
25 #include <TCollection_AsciiString.hxx>
26 #include <TDF_Attribute.hxx>
27 #include <TDF_Label.hxx>
28 #include <TDF_MapIteratorOfLabelMap.hxx>
29 #include <TDF_Tool.hxx>
30 #include <TDocStd_Application.hxx>
31 #include <TDocStd_Document.hxx>
33 #include <StdLDrivers.hxx>
34 #include <BinLDrivers.hxx>
35 #include <XmlLDrivers.hxx>
36 #include <StdDrivers.hxx>
37 #include <BinDrivers.hxx>
38 #include <XmlDrivers.hxx>
40 //=======================================================================
43 //=======================================================================
45 const Handle(TDocStd_Application)& DDocStd::GetApplication()
47 static Handle(TDocStd_Application) anApp;
50 anApp = new TDocStd_Application;
52 // Initialize standard document formats at creation - they should
53 // be available even if this DRAW plugin is not loaded by pload command
54 StdLDrivers::DefineFormat(anApp);
55 BinLDrivers::DefineFormat(anApp);
56 XmlLDrivers::DefineFormat(anApp);
57 StdDrivers::DefineFormat(anApp);
58 BinDrivers::DefineFormat(anApp);
59 XmlDrivers::DefineFormat(anApp);
65 //=======================================================================
66 //function : GetDocument
68 //=======================================================================
70 Standard_Boolean DDocStd::GetDocument (Standard_CString& Name,
71 Handle(TDocStd_Document)& DOC,
72 const Standard_Boolean Complain)
74 Handle(DDocStd_DrawDocument) DD = Handle(DDocStd_DrawDocument)::DownCast (Draw::GetExisting (Name));
76 if (Complain) cout << Name << " is not a Document" << endl;
77 return Standard_False;
79 Handle(TDocStd_Document) STDDOC = DD->GetDocument();
80 if (!STDDOC.IsNull()) {
84 if (Complain) cout << Name << " is not a CAF Document" << endl;
85 return Standard_False;
89 //=======================================================================
91 //purpose : try to retrieve a label
92 //=======================================================================
94 Standard_Boolean DDocStd::Find (const Handle(TDocStd_Document)& D,
95 const Standard_CString Entry,
97 const Standard_Boolean Complain)
100 TDF_Tool::Label(D->GetData(),Entry,Label,Standard_False);
101 if (Label.IsNull() && Complain) cout<<"No label for entry "<<Entry<<endl;
102 return !Label.IsNull();
105 //=======================================================================
107 //purpose : Try to retrieve an attribute.
108 //=======================================================================
110 Standard_Boolean DDocStd::Find (const Handle(TDocStd_Document)& D,
111 const Standard_CString Entry,
112 const Standard_GUID& ID,
113 Handle(TDF_Attribute)& A,
114 const Standard_Boolean Complain)
117 if (Find(D,Entry,L,Complain)) {
118 if (L.FindAttribute(ID,A)) return Standard_True;
119 if (Complain) cout <<"attribute not found for entry : "<< Entry <<endl;
121 return Standard_False;
125 //=======================================================================
126 //function : ReturnLabel
128 //=======================================================================
130 Draw_Interpretor& DDocStd::ReturnLabel(Draw_Interpretor& di, const TDF_Label& L)
132 TCollection_AsciiString S;
133 TDF_Tool::Entry(L,S);
138 //=======================================================================
139 //function : AllCommands
141 //=======================================================================
143 void DDocStd::AllCommands(Draw_Interpretor& theCommands)
145 static Standard_Boolean done = Standard_False;
147 done = Standard_True;
150 DDocStd::ApplicationCommands(theCommands);
151 DDocStd::DocumentCommands(theCommands);
152 DDocStd::ToolsCommands(theCommands);
153 DDocStd::MTMCommands(theCommands);
154 DDocStd::ShapeSchemaCommands(theCommands);