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)
75 Handle(Draw_Drawable3D) D = Draw::Get(Name,Standard_False);
77 Handle(DDocStd_DrawDocument) DD = Handle(DDocStd_DrawDocument)::DownCast (D);
79 if (Complain) cout << Name << " is not a Document" << endl;
80 return Standard_False;
82 Handle(TDocStd_Document) STDDOC = DD->GetDocument();
83 if (!STDDOC.IsNull()) {
87 if (Complain) cout << Name << " is not a CAF Document" << endl;
88 return Standard_False;
92 //=======================================================================
94 //purpose : try to retrieve a label
95 //=======================================================================
97 Standard_Boolean DDocStd::Find (const Handle(TDocStd_Document)& D,
98 const Standard_CString Entry,
100 const Standard_Boolean Complain)
103 TDF_Tool::Label(D->GetData(),Entry,Label,Standard_False);
104 if (Label.IsNull() && Complain) cout<<"No label for entry "<<Entry<<endl;
105 return !Label.IsNull();
108 //=======================================================================
110 //purpose : Try to retrieve an attribute.
111 //=======================================================================
113 Standard_Boolean DDocStd::Find (const Handle(TDocStd_Document)& D,
114 const Standard_CString Entry,
115 const Standard_GUID& ID,
116 Handle(TDF_Attribute)& A,
117 const Standard_Boolean Complain)
120 if (Find(D,Entry,L,Complain)) {
121 if (L.FindAttribute(ID,A)) return Standard_True;
122 if (Complain) cout <<"attribute not found for entry : "<< Entry <<endl;
124 return Standard_False;
128 //=======================================================================
129 //function : ReturnLabel
131 //=======================================================================
133 Draw_Interpretor& DDocStd::ReturnLabel(Draw_Interpretor& di, const TDF_Label& L)
135 TCollection_AsciiString S;
136 TDF_Tool::Entry(L,S);
141 //=======================================================================
142 //function : AllCommands
144 //=======================================================================
146 void DDocStd::AllCommands(Draw_Interpretor& theCommands)
148 static Standard_Boolean done = Standard_False;
150 done = Standard_True;
153 DDocStd::ApplicationCommands(theCommands);
154 DDocStd::DocumentCommands(theCommands);
155 DDocStd::ToolsCommands(theCommands);
156 DDocStd::MTMCommands(theCommands);
157 DDocStd::ShapeSchemaCommands(theCommands);