b311480e |
1 | // Created on: 2000-03-01 |
2 | // Created by: Denis PASCAL |
973c2be1 |
3 | // Copyright (c) 2000-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
42cf5bc1 |
16 | |
17 | #include <CDF_Session.hxx> |
18 | #include <DBRep.hxx> |
19 | #include <DDocStd.hxx> |
7fd59977 |
20 | #include <DDocStd_DrawDocument.hxx> |
42cf5bc1 |
21 | #include <Draw.hxx> |
7fd59977 |
22 | #include <Draw_Interpretor.hxx> |
42cf5bc1 |
23 | #include <Standard_DomainError.hxx> |
24 | #include <Standard_GUID.hxx> |
7fd59977 |
25 | #include <TCollection_AsciiString.hxx> |
42cf5bc1 |
26 | #include <TDF_Attribute.hxx> |
7fd59977 |
27 | #include <TDF_Label.hxx> |
28 | #include <TDF_MapIteratorOfLabelMap.hxx> |
42cf5bc1 |
29 | #include <TDF_Tool.hxx> |
ec357c5c |
30 | #include <TDocStd_Application.hxx> |
42cf5bc1 |
31 | #include <TDocStd_Document.hxx> |
7fd59977 |
32 | |
6fe96f84 |
33 | #include <StdLDrivers.hxx> |
34 | #include <BinLDrivers.hxx> |
35 | #include <XmlLDrivers.hxx> |
36 | #include <StdDrivers.hxx> |
37 | #include <BinDrivers.hxx> |
38 | #include <XmlDrivers.hxx> |
39 | |
7fd59977 |
40 | //======================================================================= |
41 | //function : Find |
42 | //purpose : |
43 | //======================================================================= |
6fe96f84 |
44 | |
45 | const Handle(TDocStd_Application)& DDocStd::GetApplication() |
46 | { |
47 | static Handle(TDocStd_Application) anApp; |
48 | if (anApp.IsNull()) |
49 | { |
50 | anApp = new TDocStd_Application; |
51 | |
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); |
60 | } |
61 | return anApp; |
7fd59977 |
62 | } |
63 | |
64 | |
65 | //======================================================================= |
66 | //function : GetDocument |
67 | //purpose : |
68 | //======================================================================= |
69 | |
70 | Standard_Boolean DDocStd::GetDocument (Standard_CString& Name, |
71 | Handle(TDocStd_Document)& DOC, |
72 | const Standard_Boolean Complain) |
73 | { |
1c8fc6be |
74 | Handle(DDocStd_DrawDocument) DD = Handle(DDocStd_DrawDocument)::DownCast (Draw::GetExisting (Name)); |
7fd59977 |
75 | if (DD.IsNull()) { |
04232180 |
76 | if (Complain) std::cout << Name << " is not a Document" << std::endl; |
7fd59977 |
77 | return Standard_False; |
78 | } |
a9dde4a3 |
79 | Handle(TDocStd_Document) STDDOC = DD->GetDocument(); |
7fd59977 |
80 | if (!STDDOC.IsNull()) { |
81 | DOC = STDDOC; |
82 | return Standard_True; |
83 | } |
04232180 |
84 | if (Complain) std::cout << Name << " is not a CAF Document" << std::endl; |
7fd59977 |
85 | return Standard_False; |
86 | } |
87 | |
88 | |
89 | //======================================================================= |
90 | //function : Label |
91 | //purpose : try to retrieve a label |
92 | //======================================================================= |
93 | |
94 | Standard_Boolean DDocStd::Find (const Handle(TDocStd_Document)& D, |
95 | const Standard_CString Entry, |
96 | TDF_Label& Label, |
97 | const Standard_Boolean Complain) |
98 | { |
99 | Label.Nullify(); |
7fd59977 |
100 | TDF_Tool::Label(D->GetData(),Entry,Label,Standard_False); |
04232180 |
101 | if (Label.IsNull() && Complain) std::cout<<"No label for entry "<<Entry<<std::endl; |
7fd59977 |
102 | return !Label.IsNull(); |
103 | } |
104 | |
105 | //======================================================================= |
106 | //function : Find |
107 | //purpose : Try to retrieve an attribute. |
108 | //======================================================================= |
109 | |
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) |
115 | { |
7fd59977 |
116 | TDF_Label L; |
117 | if (Find(D,Entry,L,Complain)) { |
118 | if (L.FindAttribute(ID,A)) return Standard_True; |
04232180 |
119 | if (Complain) std::cout <<"attribute not found for entry : "<< Entry <<std::endl; |
7fd59977 |
120 | } |
121 | return Standard_False; |
122 | } |
123 | |
124 | |
125 | //======================================================================= |
126 | //function : ReturnLabel |
127 | //purpose : |
128 | //======================================================================= |
129 | |
130 | Draw_Interpretor& DDocStd::ReturnLabel(Draw_Interpretor& di, const TDF_Label& L) |
131 | { |
132 | TCollection_AsciiString S; |
133 | TDF_Tool::Entry(L,S); |
134 | di << S.ToCString(); |
135 | return di; |
136 | } |
137 | |
138 | //======================================================================= |
139 | //function : AllCommands |
140 | //purpose : |
141 | //======================================================================= |
142 | |
143 | void DDocStd::AllCommands(Draw_Interpretor& theCommands) |
144 | { |
145 | static Standard_Boolean done = Standard_False; |
146 | if (done) return; |
147 | done = Standard_True; |
148 | |
7fd59977 |
149 | // define commands |
150 | DDocStd::ApplicationCommands(theCommands); |
151 | DDocStd::DocumentCommands(theCommands); |
152 | DDocStd::ToolsCommands(theCommands); |
153 | DDocStd::MTMCommands(theCommands); |
ec964372 |
154 | DDocStd::ShapeSchemaCommands(theCommands); |
7fd59977 |
155 | } |