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