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