b311480e |
1 | // Created on: 2000-03-01 |
2 | // Created by: Denis PASCAL |
3 | // Copyright (c) 2000-2012 OPEN CASCADE SAS |
4 | // |
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. |
9 | // |
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. |
12 | // |
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. |
19 | |
7fd59977 |
20 | |
21 | #include <DDocStd.ixx> |
22 | #include <DDocStd_DrawDocument.hxx> |
23 | #include <TDocStd_Document.hxx> |
24 | #include <Draw_Interpretor.hxx> |
7fd59977 |
25 | #include <TCollection_AsciiString.hxx> |
26 | #include <Draw.hxx> |
27 | #include <TDF_Tool.hxx> |
28 | #include <TDF_Label.hxx> |
29 | #include <TDF_MapIteratorOfLabelMap.hxx> |
30 | #include <DBRep.hxx> |
31 | #include <TDocStd_Document.hxx> |
32 | #include <CDF_Session.hxx> |
33 | #include <Standard_DomainError.hxx> |
34 | |
35 | |
36 | //======================================================================= |
37 | //function : Find |
38 | //purpose : |
39 | //======================================================================= |
40 | |
41 | Standard_Boolean DDocStd::Find (Handle(TDocStd_Application)& A, |
35e08fe8 |
42 | const Standard_Boolean /*Complain*/) |
7fd59977 |
43 | { |
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()); |
51 | A = APP; |
52 | return Standard_True; |
53 | } |
54 | |
55 | |
56 | //======================================================================= |
57 | //function : GetDocument |
58 | //purpose : |
59 | //======================================================================= |
60 | |
61 | Standard_Boolean DDocStd::GetDocument (Standard_CString& Name, |
62 | Handle(TDocStd_Document)& DOC, |
63 | const Standard_Boolean Complain) |
64 | { |
65 | |
66 | Handle(Draw_Drawable3D) D = Draw::Get(Name,Standard_False); |
67 | |
68 | Handle(DDocStd_DrawDocument) DD = Handle(DDocStd_DrawDocument)::DownCast (D); |
69 | if (DD.IsNull()) { |
70 | if (Complain) cout << Name << " is not a Document" << endl; |
71 | return Standard_False; |
72 | } |
73 | Handle(TDocStd_Document) STDDOC = Handle(TDocStd_Document)::DownCast(DD->GetDocument()); |
74 | if (!STDDOC.IsNull()) { |
75 | DOC = STDDOC; |
76 | return Standard_True; |
77 | } |
78 | if (Complain) cout << Name << " is not a CAF Document" << endl; |
79 | return Standard_False; |
80 | } |
81 | |
82 | |
83 | //======================================================================= |
84 | //function : Label |
85 | //purpose : try to retrieve a label |
86 | //======================================================================= |
87 | |
88 | Standard_Boolean DDocStd::Find (const Handle(TDocStd_Document)& D, |
89 | const Standard_CString Entry, |
90 | TDF_Label& Label, |
91 | const Standard_Boolean Complain) |
92 | { |
93 | Label.Nullify(); |
7fd59977 |
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(); |
97 | } |
98 | |
99 | //======================================================================= |
100 | //function : Find |
101 | //purpose : Try to retrieve an attribute. |
102 | //======================================================================= |
103 | |
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) |
109 | { |
7fd59977 |
110 | TDF_Label L; |
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; |
114 | } |
115 | return Standard_False; |
116 | } |
117 | |
118 | |
119 | //======================================================================= |
120 | //function : ReturnLabel |
121 | //purpose : |
122 | //======================================================================= |
123 | |
124 | Draw_Interpretor& DDocStd::ReturnLabel(Draw_Interpretor& di, const TDF_Label& L) |
125 | { |
126 | TCollection_AsciiString S; |
127 | TDF_Tool::Entry(L,S); |
128 | di << S.ToCString(); |
129 | return di; |
130 | } |
131 | |
132 | //======================================================================= |
133 | //function : AllCommands |
134 | //purpose : |
135 | //======================================================================= |
136 | |
137 | void DDocStd::AllCommands(Draw_Interpretor& theCommands) |
138 | { |
139 | static Standard_Boolean done = Standard_False; |
140 | if (done) return; |
141 | done = Standard_True; |
142 | |
143 | |
144 | // define commands |
145 | DDocStd::ApplicationCommands(theCommands); |
146 | DDocStd::DocumentCommands(theCommands); |
147 | DDocStd::ToolsCommands(theCommands); |
148 | DDocStd::MTMCommands(theCommands); |
149 | } |