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