1 // Created by: DAUTRY Philippe
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
18 //Version Date Purpose
19 // 0.0 Oct 3 1997 Creation
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>
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>
37 IMPLEMENT_STANDARD_RTTIEXT(DDF_Browser,Draw_Drawable3D)
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 ','
50 //=======================================================================
51 //function : DDF_Browser
53 //=======================================================================
55 DDF_Browser::DDF_Browser(const Handle(TDF_Data)& aDF)
60 //=======================================================================
63 //=======================================================================
65 void DDF_Browser::DrawOn(Draw_Display& /*dis*/) const
67 //cout<<"DDF_Browser"<<endl;
71 //=======================================================================
74 //=======================================================================
76 Handle(Draw_Drawable3D) DDF_Browser::Copy() const
77 { return new DDF_Browser(myDF); }
80 //=======================================================================
83 //=======================================================================
85 void DDF_Browser::Dump(Standard_OStream& S) const
87 S<<"DDF_Browser on a DF:"<<endl;
92 //=======================================================================
95 //=======================================================================
97 void DDF_Browser::Whatis(Draw_Interpretor& I) const
98 { I<<"Data Framework Browser"; }
101 //=======================================================================
104 //=======================================================================
106 void DDF_Browser::Data(const Handle(TDF_Data)& aDF)
110 //=======================================================================
113 //=======================================================================
115 Handle(TDF_Data) DDF_Browser::Data() const
119 //=======================================================================
120 //function : OpenRoot
122 //=======================================================================
124 TCollection_AsciiString DDF_Browser::OpenRoot() const
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))
134 TCollection_AsciiString tmpStr(name->Get(),'?');
135 tmpStr.ChangeAll(' ','_');
136 list.AssignCat(tmpStr);
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");
148 //=======================================================================
149 //function : OpenLabel
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.
155 // "AttributeList Modified|NotModified"
156 // The items are separated by "\\".
157 //=======================================================================
159 TCollection_AsciiString DDF_Browser::OpenLabel(const TDF_Label& aLab) const
161 Standard_Boolean split = Standard_False;
162 TCollection_AsciiString entry, list;
163 if (aLab.HasAttribute() || aLab.AttributesModified())
165 list.AssignCat("AttributeList");
166 list.AssignCat(TDF_BrowserSeparator2);
167 if (!aLab.AttributesModified()) list.AssignCat("Not");
168 list.AssignCat("Modified");
169 split = Standard_True;
171 Handle(TDataStd_Name) name;
172 for (TDF_ChildIterator itr(aLab); itr.More(); itr.Next())
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))
181 TCollection_AsciiString tmpStr(name->Get(),'?');
182 tmpStr.ChangeAll(' ','_');
183 list.AssignCat(tmpStr);
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);
191 list.AssignCat((itr.Value().HasAttribute() || itr.Value().HasChild())? "1" : "0");
192 split = Standard_True;
198 //=======================================================================
199 //function : OpenAttributeList
201 // an item is composed as follows:
202 // "DynamicType#MapIndex TransactionIndex Valid|Notvalid Forgotten|NotForgotten Backuped|NotBackuped"
203 // The items are separated by "\\".
204 //=======================================================================
206 TCollection_AsciiString DDF_Browser::OpenAttributeList
207 (const TDF_Label& aLab)
209 TCollection_AsciiString list;
210 Standard_Boolean split1 = Standard_False;
211 for (TDF_AttributeIterator itr(aLab,Standard_False);itr.More();itr.Next())
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());
223 list.AssignCat(TDF_BrowserSeparator2);
224 if (!att->IsValid()) list.AssignCat("Not");
225 list.AssignCat("Valid");
227 list.AssignCat(TDF_BrowserSeparator2);
228 if (!att->IsForgotten()) list.AssignCat("Not");
229 list.AssignCat("Forgotten");
231 list.AssignCat(TDF_BrowserSeparator2);
232 if (!att->IsBackuped()) list.AssignCat("Not");
233 list.AssignCat("Backuped");
235 list.AssignCat(TDF_BrowserSeparator2);
236 DDF_AttributeBrowser* br = DDF_AttributeBrowser::FindBrowser(att);
237 list.AssignCat(br? "1" : "0");
238 split1 = Standard_True;
244 //=======================================================================
245 //function : OpenAttribute
246 //purpose : Attribute's intrinsic information given by an attribute browser.
247 //=======================================================================
249 TCollection_AsciiString DDF_Browser::OpenAttribute
250 (const Standard_Integer anIndex)
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);
260 //=======================================================================
261 //function : Information
262 //purpose : Information about <myDF>.
263 //=======================================================================
265 TCollection_AsciiString DDF_Browser::Information() const
267 TCollection_AsciiString list;
272 //=======================================================================
273 //function : Information
274 //purpose : Information about a label.
275 //=======================================================================
277 TCollection_AsciiString DDF_Browser::Information(const TDF_Label& /*aLab*/) const
279 TCollection_AsciiString list;
284 //=======================================================================
285 //function : Information
286 //purpose : Information about an attribute.
287 //=======================================================================
289 TCollection_AsciiString DDF_Browser::Information(const Standard_Integer /*anIndex*/) const
291 TCollection_AsciiString list;