b311480e |
1 | // Created by: DAUTRY Philippe |
2 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
3 | // Copyright (c) 1999-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. |
b311480e |
15 | |
7fd59977 |
16 | #include <stdio.h> |
17 | |
18 | #include <DDF.hxx> |
19 | #include <DDF_Browser.hxx> |
20 | #include <DDF_Data.hxx> |
21 | |
22 | #include <Draw.hxx> |
23 | #include <Draw_Appli.hxx> |
24 | #include <Draw_Drawable3D.hxx> |
25 | #include <Draw_Interpretor.hxx> |
26 | |
27 | #include <TDF_Label.hxx> |
28 | #include <TDF_ChildIterator.hxx> |
29 | #include <TDF_AttributeIterator.hxx> |
30 | #include <TDF_Tool.hxx> |
31 | |
32 | #include <TCollection_AsciiString.hxx> |
33 | #include <TCollection_HAsciiString.hxx> |
409cc8d1 |
34 | #include <OSD_File.hxx> |
35 | |
57c28b61 |
36 | #ifdef _MSC_VER |
7fd59977 |
37 | #include <stdio.h> |
38 | #endif |
39 | |
40 | //======================================================================= |
41 | //function : DFBrowse |
42 | //purpose : |
43 | // arg 1 : DF name |
44 | // [arg 2] : Browser name |
45 | //======================================================================= |
46 | |
47 | static Standard_Integer DFBrowse (Draw_Interpretor& di, |
f767df4e |
48 | Standard_Integer n, |
49 | const char** a) |
7fd59977 |
50 | { |
409cc8d1 |
51 | if (n<2) |
52 | { |
53 | cout << "Use: " << a[0] << " document [brower_name]" << endl; |
54 | return 1; |
55 | } |
7fd59977 |
56 | |
57 | Handle(TDF_Data) DF; |
409cc8d1 |
58 | if (!DDF::GetDF (a[1], DF)) |
59 | { |
60 | cout << "Error: document " << a[1] << " is not found" << endl; |
61 | return 1; |
62 | } |
7fd59977 |
63 | |
64 | Handle(DDF_Browser) NewDDFBrowser = new DDF_Browser(DF); |
f767df4e |
65 | TCollection_AsciiString name("browser_"); |
66 | name += ((n == 3)? a[2] : a[1]); |
67 | Draw::Set (name.ToCString(), NewDDFBrowser); |
7fd59977 |
68 | |
409cc8d1 |
69 | // Load Tcl Script |
70 | TCollection_AsciiString aTclScript (getenv ("CSF_DrawPluginDefaults")); |
71 | aTclScript.AssignCat ( "/dftree.tcl" ); |
72 | OSD_File aTclScriptFile (aTclScript); |
73 | if (aTclScriptFile.Exists()) { |
0797d9d3 |
74 | #ifdef OCCT_DEBUG |
409cc8d1 |
75 | cout << "Load " << aTclScript << endl; |
76 | #endif |
77 | di.EvalFile( aTclScript.ToCString() ); |
78 | } |
79 | else |
80 | { |
81 | cout << "Error: Could not load script " << aTclScript << endl; |
82 | cout << "Check environment variable CSF_DrawPluginDefaults" << endl; |
83 | } |
84 | |
85 | // Call command dftree defined in dftree.tcl |
86 | TCollection_AsciiString aCommand = "dftree "; |
87 | aCommand.AssignCat(name); |
88 | di.Eval(aCommand.ToCString()); |
7fd59977 |
89 | return 0; |
90 | } |
91 | |
92 | |
93 | //======================================================================= |
94 | //function : DFOpenLabel |
95 | //purpose : |
96 | // arg 1 : Browser name |
97 | // [arg 2] : Label name |
98 | //======================================================================= |
99 | |
100 | static Standard_Integer DFOpenLabel (Draw_Interpretor& di, |
f767df4e |
101 | Standard_Integer n, |
102 | const char** a) |
7fd59977 |
103 | { |
104 | if (n < 2) return 1; |
105 | |
1c8fc6be |
106 | Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (a[1])); |
107 | if (browser.IsNull()) |
108 | { |
109 | std::cout << "Syntax error: browser '" << a[1] << "' not found\n"; |
110 | return 1; |
111 | } |
7fd59977 |
112 | |
113 | TDF_Label lab; |
114 | if (n == 3) TDF_Tool::Label(browser->Data(),a[2],lab); |
115 | |
f767df4e |
116 | TCollection_AsciiString list(lab.IsNull()? browser->OpenRoot() : browser->OpenLabel(lab)); |
117 | di<<list.ToCString(); |
7fd59977 |
118 | return 0; |
119 | } |
120 | |
121 | |
122 | //======================================================================= |
123 | //function : DFOpenAttributeList |
124 | //purpose : |
125 | // arg 1 : Browser name |
126 | // arg 2 : Label name |
127 | //======================================================================= |
128 | |
129 | static Standard_Integer DFOpenAttributeList(Draw_Interpretor& di, |
f767df4e |
130 | Standard_Integer n, |
131 | const char** a) |
7fd59977 |
132 | { |
133 | if (n < 3) return 1; |
134 | |
1c8fc6be |
135 | Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (a[1])); |
136 | if (browser.IsNull()) |
137 | { |
138 | std::cout << "Syntax error: browser '" << a[1] << "' not found\n"; |
139 | return 1; |
140 | } |
7fd59977 |
141 | |
142 | TDF_Label lab; |
143 | TDF_Tool::Label(browser->Data(),a[2],lab); |
144 | |
f767df4e |
145 | if (lab.IsNull()) |
7fd59977 |
146 | return 1; |
7fd59977 |
147 | |
f767df4e |
148 | TCollection_AsciiString list(browser->OpenAttributeList(lab)); |
7fd59977 |
149 | di << list.ToCString(); |
150 | return 0; |
151 | } |
152 | |
153 | |
154 | |
155 | //======================================================================= |
156 | //function : DFOpenAttribute |
157 | //purpose : |
158 | // arg 1 : Browser name |
159 | // arg 2 : Attribute index |
160 | //======================================================================= |
161 | |
162 | static Standard_Integer DFOpenAttribute (Draw_Interpretor& di, |
f767df4e |
163 | Standard_Integer n, |
164 | const char** a) |
7fd59977 |
165 | { |
166 | if (n < 3) return 1; |
167 | |
1c8fc6be |
168 | Handle(DDF_Browser) browser = Handle(DDF_Browser)::DownCast (Draw::GetExisting (a[1])); |
169 | if (browser.IsNull()) |
170 | { |
171 | std::cout << "Syntax error: browser '" << a[1] << "' not found\n"; |
172 | return 1; |
173 | } |
7fd59977 |
174 | |
91322f44 |
175 | const Standard_Integer index = Draw::Atoi(a[2]); |
7fd59977 |
176 | TCollection_AsciiString list = browser->OpenAttribute(index); |
7fd59977 |
177 | di<<list.ToCString(); |
178 | return 0; |
179 | } |
180 | |
181 | |
182 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
183 | |
184 | |
7fd59977 |
185 | //======================================================================= |
186 | //function : BrowserCommands |
187 | //purpose : |
188 | //======================================================================= |
189 | |
190 | void DDF::BrowserCommands (Draw_Interpretor& theCommands) |
191 | { |
7fd59977 |
192 | static Standard_Boolean done = Standard_False; |
193 | if (done) return; |
194 | done = Standard_True; |
195 | |
196 | const char* g = "DF browser commands"; |
197 | |
198 | theCommands.Add |
199 | ("DFBrowse", |
200 | "Creates a browser on a df: DFBrowse dfname [browsername]", |
201 | __FILE__, DFBrowse, g); |
202 | |
203 | theCommands.Add |
204 | ("DFOpenLabel", |
205 | "DON'T USE THIS COMMAND RESERVED TO THE BROWSER!\nReturns the list of sub-label entries: DFOpenLabel browsername [label]", |
206 | __FILE__, DFOpenLabel, g); |
207 | |
208 | theCommands.Add |
209 | ("DFOpenAttributeList", |
210 | "DON'T USE THIS COMMAND RESERVED TO THE BROWSER!\nReturns the attribute list of a label: DFOpenLabel browsername label", |
211 | __FILE__, DFOpenAttributeList, g); |
212 | |
213 | theCommands.Add |
214 | ("DFOpenAttribute", |
215 | "DON'T USE THIS COMMAND RESERVED TO THE BROWSER!\nReturns the reference list of an attribute: DFOpenLabel browsername attributeindex", |
216 | __FILE__, DFOpenAttribute, g); |
217 | #if 0 |
218 | theCommands.Add |
219 | ("DFDisplayInfo", |
220 | "DON'T USE THIS COMMAND RESERVED TO THE BROWSER!\nReturns information about an attribute, a df or a label: DFDisplayInfo {#} | {browsername [label]}", |
221 | __FILE__, DFDisplayInfo, g); |
222 | #endif |
7fd59977 |
223 | } |