1 // Created on: 2000-03-01
2 // Created by: Denis PASCAL
3 // Copyright (c) 2000-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <DDocStd.ixx>
22 #include <DDocStd_DrawDocument.hxx>
23 #include <TDocStd_Document.hxx>
24 #include <Draw_Interpretor.hxx>
25 #include <TCollection_AsciiString.hxx>
27 #include <TDF_Tool.hxx>
28 #include <TDF_Label.hxx>
29 #include <TDF_MapIteratorOfLabelMap.hxx>
31 #include <TDocStd_Document.hxx>
32 #include <CDF_Session.hxx>
33 #include <Standard_DomainError.hxx>
36 //=======================================================================
39 //=======================================================================
41 Standard_Boolean DDocStd::Find (Handle(TDocStd_Application)& A,
42 const Standard_Boolean Complain)
44 if (!CDF_Session::Exists())
45 Standard_DomainError::Raise("DDocStd::Find no applicative session");
46 Handle(CDF_Session) S = CDF_Session::CurrentSession();
47 Handle(TDocStd_Application) APP;
48 if (!S->HasCurrentApplication())
49 Standard_DomainError::Raise("DDocStd::Find no applicative session");
50 APP = Handle(TDocStd_Application)::DownCast(S->CurrentApplication());
56 //=======================================================================
57 //function : GetDocument
59 //=======================================================================
61 Standard_Boolean DDocStd::GetDocument (Standard_CString& Name,
62 Handle(TDocStd_Document)& DOC,
63 const Standard_Boolean Complain)
66 Handle(Draw_Drawable3D) D = Draw::Get(Name,Standard_False);
68 Handle(DDocStd_DrawDocument) DD = Handle(DDocStd_DrawDocument)::DownCast (D);
70 if (Complain) cout << Name << " is not a Document" << endl;
71 return Standard_False;
73 Handle(TDocStd_Document) STDDOC = Handle(TDocStd_Document)::DownCast(DD->GetDocument());
74 if (!STDDOC.IsNull()) {
78 if (Complain) cout << Name << " is not a CAF Document" << endl;
79 return Standard_False;
83 //=======================================================================
85 //purpose : try to retrieve a label
86 //=======================================================================
88 Standard_Boolean DDocStd::Find (const Handle(TDocStd_Document)& D,
89 const Standard_CString Entry,
91 const Standard_Boolean Complain)
94 TDF_Tool::Label(D->GetData(),Entry,Label,Standard_False);
95 if (Label.IsNull() && Complain) cout<<"No label for entry "<<Entry<<endl;
96 return !Label.IsNull();
99 //=======================================================================
101 //purpose : Try to retrieve an attribute.
102 //=======================================================================
104 Standard_Boolean DDocStd::Find (const Handle(TDocStd_Document)& D,
105 const Standard_CString Entry,
106 const Standard_GUID& ID,
107 Handle(TDF_Attribute)& A,
108 const Standard_Boolean Complain)
111 if (Find(D,Entry,L,Complain)) {
112 if (L.FindAttribute(ID,A)) return Standard_True;
113 if (Complain) cout <<"attribute not found for entry : "<< Entry <<endl;
115 return Standard_False;
119 //=======================================================================
120 //function : ReturnLabel
122 //=======================================================================
124 Draw_Interpretor& DDocStd::ReturnLabel(Draw_Interpretor& di, const TDF_Label& L)
126 TCollection_AsciiString S;
127 TDF_Tool::Entry(L,S);
132 //=======================================================================
133 //function : AllCommands
135 //=======================================================================
137 void DDocStd::AllCommands(Draw_Interpretor& theCommands)
139 static Standard_Boolean done = Standard_False;
141 done = Standard_True;
145 DDocStd::ApplicationCommands(theCommands);
146 DDocStd::DocumentCommands(theCommands);
147 DDocStd::ToolsCommands(theCommands);
148 DDocStd::MTMCommands(theCommands);