0025266: Debug statements in the source are getting flushed on to the console
[occt.git] / src / DDF / DDF_BrowserCommands.cxx
1 // Created by: DAUTRY Philippe
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
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>
34 #include <OSD_File.hxx>
35
36 #ifdef WNT
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, 
48                                   Standard_Integer  n, 
49                                   const char**      a)
50 {
51   if (n<2)
52   {
53     cout << "Use: " << a[0] << " document [brower_name]" << endl;
54     return 1;
55   }
56   
57   Handle(TDF_Data) DF;
58   if (!DDF::GetDF (a[1], DF)) 
59   {
60     cout << "Error: document " << a[1] << " is not found" << endl;
61     return 1;
62   }
63
64   Handle(DDF_Browser) NewDDFBrowser = new DDF_Browser(DF);
65   TCollection_AsciiString name("browser_");
66   name += ((n == 3)? a[2] : a[1]);
67   Draw::Set (name.ToCString(), NewDDFBrowser);
68
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()) {
74 #ifdef DDF_DEB
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());
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, 
101                                      Standard_Integer  n, 
102                                      const char**      a)
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
112   TCollection_AsciiString list(lab.IsNull()? browser->OpenRoot() : browser->OpenLabel(lab));
113   di<<list.ToCString();
114   return 0;
115 }
116
117
118 //=======================================================================
119 //function : DFOpenAttributeList
120 //purpose  : 
121 //  arg 1  : Browser name
122 //  arg 2  : Label name
123 //=======================================================================
124
125 static Standard_Integer DFOpenAttributeList(Draw_Interpretor& di,
126                                             Standard_Integer  n,
127                                             const char**      a)
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
137   if (lab.IsNull())
138     return 1;
139
140   TCollection_AsciiString list(browser->OpenAttributeList(lab));
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
154 static Standard_Integer DFOpenAttribute (Draw_Interpretor& di, 
155                                          Standard_Integer  n, 
156                                          const char**      a)
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
163   const Standard_Integer index = Draw::Atoi(a[2]);
164   TCollection_AsciiString list = browser->OpenAttribute(index);
165   di<<list.ToCString();
166   return 0;
167 }
168
169
170 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
171
172
173 //=======================================================================
174 //function : BrowserCommands
175 //purpose  : 
176 //=======================================================================
177
178 void DDF::BrowserCommands (Draw_Interpretor& theCommands) 
179 {
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
211 }