0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / DDF / DDF_BrowserCommands.cxx
CommitLineData
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
47static 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
100static Standard_Integer DFOpenLabel (Draw_Interpretor& di,
f767df4e 101 Standard_Integer n,
102 const char** a)
7fd59977 103{
104 if (n < 2) return 1;
105
106 Handle(DDF_Browser) browser =
107 Handle(DDF_Browser)::DownCast (Draw::Get(a[1], Standard_True));
108
109 TDF_Label lab;
110 if (n == 3) TDF_Tool::Label(browser->Data(),a[2],lab);
111
f767df4e 112 TCollection_AsciiString list(lab.IsNull()? browser->OpenRoot() : browser->OpenLabel(lab));
113 di<<list.ToCString();
7fd59977 114 return 0;
115}
116
117
118//=======================================================================
119//function : DFOpenAttributeList
120//purpose :
121// arg 1 : Browser name
122// arg 2 : Label name
123//=======================================================================
124
125static Standard_Integer DFOpenAttributeList(Draw_Interpretor& di,
f767df4e 126 Standard_Integer n,
127 const char** a)
7fd59977 128{
129 if (n < 3) return 1;
130
131 Handle(DDF_Browser) browser =
132 Handle(DDF_Browser)::DownCast (Draw::Get(a[1], Standard_True));
133
134 TDF_Label lab;
135 TDF_Tool::Label(browser->Data(),a[2],lab);
136
f767df4e 137 if (lab.IsNull())
7fd59977 138 return 1;
7fd59977 139
f767df4e 140 TCollection_AsciiString list(browser->OpenAttributeList(lab));
7fd59977 141 di << list.ToCString();
142 return 0;
143}
144
145
146
147//=======================================================================
148//function : DFOpenAttribute
149//purpose :
150// arg 1 : Browser name
151// arg 2 : Attribute index
152//=======================================================================
153
154static Standard_Integer DFOpenAttribute (Draw_Interpretor& di,
f767df4e 155 Standard_Integer n,
156 const char** a)
7fd59977 157{
158 if (n < 3) return 1;
159
160 Handle(DDF_Browser) browser =
161 Handle(DDF_Browser)::DownCast (Draw::Get(a[1], Standard_True));
162
91322f44 163 const Standard_Integer index = Draw::Atoi(a[2]);
7fd59977 164 TCollection_AsciiString list = browser->OpenAttribute(index);
7fd59977 165 di<<list.ToCString();
166 return 0;
167}
168
169
170// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
171
172
7fd59977 173//=======================================================================
174//function : BrowserCommands
175//purpose :
176//=======================================================================
177
178void DDF::BrowserCommands (Draw_Interpretor& theCommands)
179{
7fd59977 180 static Standard_Boolean done = Standard_False;
181 if (done) return;
182 done = Standard_True;
183
184 const char* g = "DF browser commands";
185
186 theCommands.Add
187 ("DFBrowse",
188 "Creates a browser on a df: DFBrowse dfname [browsername]",
189 __FILE__, DFBrowse, g);
190
191 theCommands.Add
192 ("DFOpenLabel",
193 "DON'T USE THIS COMMAND RESERVED TO THE BROWSER!\nReturns the list of sub-label entries: DFOpenLabel browsername [label]",
194 __FILE__, DFOpenLabel, g);
195
196 theCommands.Add
197 ("DFOpenAttributeList",
198 "DON'T USE THIS COMMAND RESERVED TO THE BROWSER!\nReturns the attribute list of a label: DFOpenLabel browsername label",
199 __FILE__, DFOpenAttributeList, g);
200
201 theCommands.Add
202 ("DFOpenAttribute",
203 "DON'T USE THIS COMMAND RESERVED TO THE BROWSER!\nReturns the reference list of an attribute: DFOpenLabel browsername attributeindex",
204 __FILE__, DFOpenAttribute, g);
205#if 0
206 theCommands.Add
207 ("DFDisplayInfo",
208 "DON'T USE THIS COMMAND RESERVED TO THE BROWSER!\nReturns information about an attribute, a df or a label: DFDisplayInfo {#} | {browsername [label]}",
209 __FILE__, DFDisplayInfo, g);
210#endif
7fd59977 211}