0023081: This is desirable to retrieve GPU memory information from graphic driver
[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// -----------------------
7fd59977 21
22// Version: 0.0
b311480e 23//Version Date Purpose
7fd59977 24// 0.0 Oct 3 1997 Creation
25
26#include <stdio.h>
27
28#include <DDF.hxx>
29#include <DDF_Browser.hxx>
30#include <DDF_Data.hxx>
31
32#include <Draw.hxx>
33#include <Draw_Appli.hxx>
34#include <Draw_Drawable3D.hxx>
35#include <Draw_Interpretor.hxx>
36
37#include <TDF_Label.hxx>
38#include <TDF_ChildIterator.hxx>
39#include <TDF_AttributeIterator.hxx>
40#include <TDF_Tool.hxx>
41
42#include <TCollection_AsciiString.hxx>
43#include <TCollection_HAsciiString.hxx>
44#ifdef WNT
45#include <stdio.h>
46#endif
47
48//=======================================================================
49//function : DFBrowse
50//purpose :
51// arg 1 : DF name
52// [arg 2] : Browser name
53//=======================================================================
54
55static Standard_Integer DFBrowse (Draw_Interpretor& di,
f767df4e 56 Standard_Integer n,
57 const char** a)
7fd59977 58{
59 if (n<2) return 1;
60
61 Handle(TDF_Data) DF;
62 if (!DDF::GetDF (a[1], DF)) return 1;
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
7fd59977 69 TCollection_AsciiString inst1("dftree ");
70 inst1.AssignCat(name);
71 di.Eval(inst1.ToCString());
72 return 0;
73}
74
75
76//=======================================================================
77//function : DFOpenLabel
78//purpose :
79// arg 1 : Browser name
80// [arg 2] : Label name
81//=======================================================================
82
83static Standard_Integer DFOpenLabel (Draw_Interpretor& di,
f767df4e 84 Standard_Integer n,
85 const char** a)
7fd59977 86{
87 if (n < 2) return 1;
88
89 Handle(DDF_Browser) browser =
90 Handle(DDF_Browser)::DownCast (Draw::Get(a[1], Standard_True));
91
92 TDF_Label lab;
93 if (n == 3) TDF_Tool::Label(browser->Data(),a[2],lab);
94
f767df4e 95 TCollection_AsciiString list(lab.IsNull()? browser->OpenRoot() : browser->OpenLabel(lab));
96 di<<list.ToCString();
7fd59977 97 return 0;
98}
99
100
101//=======================================================================
102//function : DFOpenAttributeList
103//purpose :
104// arg 1 : Browser name
105// arg 2 : Label name
106//=======================================================================
107
108static Standard_Integer DFOpenAttributeList(Draw_Interpretor& di,
f767df4e 109 Standard_Integer n,
110 const char** a)
7fd59977 111{
112 if (n < 3) return 1;
113
114 Handle(DDF_Browser) browser =
115 Handle(DDF_Browser)::DownCast (Draw::Get(a[1], Standard_True));
116
117 TDF_Label lab;
118 TDF_Tool::Label(browser->Data(),a[2],lab);
119
f767df4e 120 if (lab.IsNull())
7fd59977 121 return 1;
7fd59977 122
f767df4e 123 TCollection_AsciiString list(browser->OpenAttributeList(lab));
7fd59977 124 di << list.ToCString();
125 return 0;
126}
127
128
129
130//=======================================================================
131//function : DFOpenAttribute
132//purpose :
133// arg 1 : Browser name
134// arg 2 : Attribute index
135//=======================================================================
136
137static Standard_Integer DFOpenAttribute (Draw_Interpretor& di,
f767df4e 138 Standard_Integer n,
139 const char** a)
7fd59977 140{
141 if (n < 3) return 1;
142
143 Handle(DDF_Browser) browser =
144 Handle(DDF_Browser)::DownCast (Draw::Get(a[1], Standard_True));
145
f767df4e 146 const Standard_Integer index = atoi(a[2]);
7fd59977 147 TCollection_AsciiString list = browser->OpenAttribute(index);
7fd59977 148 di<<list.ToCString();
149 return 0;
150}
151
152
153// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
154
155
7fd59977 156//=======================================================================
157//function : BrowserCommands
158//purpose :
159//=======================================================================
160
161void DDF::BrowserCommands (Draw_Interpretor& theCommands)
162{
7fd59977 163 static Standard_Boolean done = Standard_False;
164 if (done) return;
165 done = Standard_True;
166
167 const char* g = "DF browser commands";
168
169 theCommands.Add
170 ("DFBrowse",
171 "Creates a browser on a df: DFBrowse dfname [browsername]",
172 __FILE__, DFBrowse, g);
173
174 theCommands.Add
175 ("DFOpenLabel",
176 "DON'T USE THIS COMMAND RESERVED TO THE BROWSER!\nReturns the list of sub-label entries: DFOpenLabel browsername [label]",
177 __FILE__, DFOpenLabel, g);
178
179 theCommands.Add
180 ("DFOpenAttributeList",
181 "DON'T USE THIS COMMAND RESERVED TO THE BROWSER!\nReturns the attribute list of a label: DFOpenLabel browsername label",
182 __FILE__, DFOpenAttributeList, g);
183
184 theCommands.Add
185 ("DFOpenAttribute",
186 "DON'T USE THIS COMMAND RESERVED TO THE BROWSER!\nReturns the reference list of an attribute: DFOpenLabel browsername attributeindex",
187 __FILE__, DFOpenAttribute, g);
188#if 0
189 theCommands.Add
190 ("DFDisplayInfo",
191 "DON'T USE THIS COMMAND RESERVED TO THE BROWSER!\nReturns information about an attribute, a df or a label: DFDisplayInfo {#} | {browsername [label]}",
192 __FILE__, DFDisplayInfo, g);
193#endif
7fd59977 194}