0024750: Replace instantiations of TCollection generic classes by NCollection templat...
[occt.git] / src / DDF / DDF_Browser.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 //              ---------------
17
18 // Version:     0.0
19 //Version       Date            Purpose
20 //              0.0     Oct  3 1997     Creation
21
22
23 #include <DDF_Browser.ixx>
24
25 #include <DDF_AttributeBrowser.hxx>
26
27 #include <TDF_Tool.hxx>
28 #include <TDF_ChildIterator.hxx>
29 #include <TDF_AttributeIterator.hxx>
30 #include <TDF_Attribute.hxx>
31 #include <TDF.hxx>
32
33 #include <TDataStd_Name.hxx>
34
35 #include <TCollection_ExtendedString.hxx>
36
37 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
38 // Communication convention with tcl:
39 // tcl waits for a string of characters, being an information list.
40 // In this list, each item is separated from another by a separator: '\'.
41 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
42
43 #define TDF_BrowserSeparator1 '\\'
44 #define TDF_BrowserSeparator2 ' '
45 #define TDF_BrowserSeparator3 '#'
46 #define TDF_BrowserSeparator4 ','
47
48
49 //=======================================================================
50 //function : DDF_Browser
51 //purpose  : 
52 //=======================================================================
53
54 DDF_Browser::DDF_Browser(const Handle(TDF_Data)& aDF)
55 : myDF(aDF)
56 {}
57
58
59 //=======================================================================
60 //function : DrawOn
61 //purpose  : 
62 //=======================================================================
63
64 void DDF_Browser::DrawOn(Draw_Display& /*dis*/) const
65
66   //cout<<"DDF_Browser"<<endl; 
67 }
68
69
70 //=======================================================================
71 //function : Copy
72 //purpose  : 
73 //=======================================================================
74
75 Handle(Draw_Drawable3D) DDF_Browser::Copy() const
76 { return new DDF_Browser(myDF); }
77
78
79 //=======================================================================
80 //function : Dump
81 //purpose  : 
82 //=======================================================================
83
84 void DDF_Browser::Dump(Standard_OStream& S) const
85 {
86   S<<"DDF_Browser on a DF:"<<endl;
87   S<<myDF;
88 }
89
90
91 //=======================================================================
92 //function : Whatis
93 //purpose  : 
94 //=======================================================================
95
96 void DDF_Browser::Whatis(Draw_Interpretor& I) const
97 { I<<"Data Framework Browser"; }
98
99
100 //=======================================================================
101 //function : Data
102 //purpose  : 
103 //=======================================================================
104
105 void DDF_Browser::Data(const Handle(TDF_Data)& aDF) 
106 { myDF = aDF; }
107
108
109 //=======================================================================
110 //function : Data
111 //purpose  : 
112 //=======================================================================
113
114 Handle(TDF_Data) DDF_Browser::Data() const
115 { return myDF; }
116
117
118 //=======================================================================
119 //function : OpenRoot
120 //purpose  : 
121 //=======================================================================
122
123 TCollection_AsciiString DDF_Browser::OpenRoot() const
124 {
125   TCollection_AsciiString list;
126   const TDF_Label& root = myDF->Root();
127   TDF_Tool::Entry(root,list);
128   Handle(TDataStd_Name) name;
129   list.AssignCat(TDF_BrowserSeparator2);
130   list.AssignCat("\"");
131   if (root.FindAttribute(TDataStd_Name::GetID(),name))
132   {
133     TCollection_AsciiString tmpStr(name->Get(),'?');
134     tmpStr.ChangeAll(' ','_');
135     list.AssignCat(tmpStr);
136   }
137   list.AssignCat("\"");
138   list.AssignCat(TDF_BrowserSeparator2);
139   if (!root.MayBeModified()) list.AssignCat("Not");
140   list.AssignCat("Modified");
141   list.AssignCat(TDF_BrowserSeparator2);
142   list.AssignCat((root.HasAttribute() || root.HasChild())? "1" : "0");
143   return list;
144 }
145
146
147 //=======================================================================
148 //function : OpenLabel
149 //purpose  : 
150 // an item is composed as follows:
151 // "Entry "Name" Modified|NotModified 0|1"
152 // the end bit shows if the label has attributes or children.
153 // The 1st can be
154 // "AttributeList Modified|NotModified"
155 // The items are separated by "\\".
156 //=======================================================================
157
158 TCollection_AsciiString DDF_Browser::OpenLabel(const TDF_Label& aLab) const
159 {
160   Standard_Boolean split = Standard_False;
161   TCollection_AsciiString entry, list;
162   if (aLab.HasAttribute() || aLab.AttributesModified())
163   {
164     list.AssignCat("AttributeList");
165     list.AssignCat(TDF_BrowserSeparator2);
166     if (!aLab.AttributesModified()) list.AssignCat("Not");
167     list.AssignCat("Modified");
168     split = Standard_True;
169   }
170   Handle(TDataStd_Name) name;
171   for (TDF_ChildIterator itr(aLab); itr.More(); itr.Next())
172   {
173     if (split) list.AssignCat(TDF_BrowserSeparator1);
174     TDF_Tool::Entry(itr.Value(),entry);
175     list.AssignCat(entry);
176     list.AssignCat(TDF_BrowserSeparator2);
177     list.AssignCat("\"");
178     if (itr.Value().FindAttribute(TDataStd_Name::GetID(),name))
179     {
180       TCollection_AsciiString tmpStr(name->Get(),'?');
181       tmpStr.ChangeAll(' ','_');
182       list.AssignCat(tmpStr);
183     }
184     list.AssignCat("\"");
185     list.AssignCat(TDF_BrowserSeparator2);
186     if (!itr.Value().MayBeModified()) list.AssignCat("Not");
187     list.AssignCat("Modified");
188     list.AssignCat(TDF_BrowserSeparator2);
189     // May be open.
190     list.AssignCat((itr.Value().HasAttribute() || itr.Value().HasChild())? "1" : "0");
191     split = Standard_True;
192   }
193   return list;
194 }
195
196
197 //=======================================================================
198 //function : OpenAttributeList
199 //purpose  : 
200 // an item is composed as follows:
201 // "DynamicType#MapIndex TransactionIndex Valid|Notvalid Forgotten|NotForgotten Backuped|NotBackuped"
202 // The items are separated by "\\".
203 //=======================================================================
204
205 TCollection_AsciiString DDF_Browser::OpenAttributeList
206   (const TDF_Label& aLab) 
207 {
208   TCollection_AsciiString list;
209   Standard_Boolean split1 = Standard_False;
210   for (TDF_AttributeIterator itr(aLab,Standard_False);itr.More();itr.Next())
211   {
212     if (split1) list.AssignCat(TDF_BrowserSeparator1);
213     const Handle(TDF_Attribute)& att = itr.Value();
214     const Standard_Integer index = myAttMap.Add(att);
215     TCollection_AsciiString indexStr(index);
216     list.AssignCat(att->DynamicType()->Name());
217     list.AssignCat(TDF_BrowserSeparator3);
218     list.AssignCat(indexStr);
219     list.AssignCat(TDF_BrowserSeparator2);
220     list.AssignCat(att->Transaction());
221     // Valid.
222     list.AssignCat(TDF_BrowserSeparator2);
223     if (!att->IsValid()) list.AssignCat("Not");
224     list.AssignCat("Valid");
225     // Forgotten.
226     list.AssignCat(TDF_BrowserSeparator2);
227     if (!att->IsForgotten()) list.AssignCat("Not");
228     list.AssignCat("Forgotten");
229     // Backuped.
230     list.AssignCat(TDF_BrowserSeparator2);
231     if (!att->IsBackuped()) list.AssignCat("Not");
232     list.AssignCat("Backuped");
233     // May be open.
234     list.AssignCat(TDF_BrowserSeparator2);
235     DDF_AttributeBrowser* br = DDF_AttributeBrowser::FindBrowser(att);
236     list.AssignCat(br? "1" : "0");
237     split1 = Standard_True;
238   }
239   return list;
240 }
241
242
243 //=======================================================================
244 //function : OpenAttribute
245 //purpose  : Attribute's intrinsic information given by an attribute browser.
246 //=======================================================================
247
248 TCollection_AsciiString DDF_Browser::OpenAttribute
249   (const Standard_Integer anIndex) 
250 {
251   TCollection_AsciiString list;
252   Handle(TDF_Attribute) att = myAttMap.FindKey(anIndex);
253   DDF_AttributeBrowser* br = DDF_AttributeBrowser::FindBrowser(att);
254   if (br) list = br->Open(att);
255   return list;
256 }
257
258
259 //=======================================================================
260 //function : Information
261 //purpose  : Information about <myDF>.
262 //=======================================================================
263
264 TCollection_AsciiString DDF_Browser::Information() const
265 {
266   TCollection_AsciiString list;
267   return list;
268 }
269
270
271 //=======================================================================
272 //function : Information
273 //purpose  : Information about a label.
274 //=======================================================================
275
276 TCollection_AsciiString DDF_Browser::Information(const TDF_Label& /*aLab*/) const
277 {
278   TCollection_AsciiString list;
279   return list;
280 }
281
282
283 //=======================================================================
284 //function : Information
285 //purpose  : Information about an attribute.
286 //=======================================================================
287
288 TCollection_AsciiString DDF_Browser::Information(const Standard_Integer /*anIndex*/) const
289 {
290   TCollection_AsciiString list;
291   return list;
292 }