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