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 <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>
35 IMPLEMENT_STANDARD_RTTIEXT(DDF_Browser,Draw_Drawable3D)
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 ','
48 //=======================================================================
49 //function : DDF_Browser
51 //=======================================================================
53 DDF_Browser::DDF_Browser(const Handle(TDF_Data)& aDF)
58 //=======================================================================
61 //=======================================================================
63 void DDF_Browser::DrawOn(Draw_Display& /*dis*/) const
65 //std::cout<<"DDF_Browser"<<std::endl;
69 //=======================================================================
72 //=======================================================================
74 Handle(Draw_Drawable3D) DDF_Browser::Copy() const
75 { return new DDF_Browser(myDF); }
78 //=======================================================================
81 //=======================================================================
83 void DDF_Browser::Dump(Standard_OStream& S) const
85 S<<"DDF_Browser on a DF:"<<std::endl;
90 //=======================================================================
93 //=======================================================================
95 void DDF_Browser::Whatis(Draw_Interpretor& I) const
96 { I<<"Data Framework Browser"; }
99 //=======================================================================
102 //=======================================================================
104 void DDF_Browser::Data(const Handle(TDF_Data)& aDF)
108 //=======================================================================
111 //=======================================================================
113 Handle(TDF_Data) DDF_Browser::Data() const
117 //=======================================================================
118 //function : OpenRoot
120 //=======================================================================
122 TCollection_AsciiString DDF_Browser::OpenRoot() const
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))
132 TCollection_AsciiString tmpStr(name->Get());
133 tmpStr.ChangeAll(' ','_');
134 list.AssignCat(tmpStr);
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");
146 //=======================================================================
147 //function : OpenLabel
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.
153 // "AttributeList Modified|NotModified"
154 // The items are separated by "\\".
155 //=======================================================================
157 TCollection_AsciiString DDF_Browser::OpenLabel(const TDF_Label& aLab) const
159 Standard_Boolean split = Standard_False;
160 TCollection_AsciiString entry, list;
161 if (aLab.HasAttribute() || aLab.AttributesModified())
163 list.AssignCat("AttributeList");
164 list.AssignCat(TDF_BrowserSeparator2);
165 if (!aLab.AttributesModified()) list.AssignCat("Not");
166 list.AssignCat("Modified");
167 split = Standard_True;
169 Handle(TDataStd_Name) name;
170 for (TDF_ChildIterator itr(aLab); itr.More(); itr.Next())
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))
179 TCollection_AsciiString tmpStr(name->Get());
180 tmpStr.ChangeAll(' ','_');
181 list.AssignCat(tmpStr);
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);
189 list.AssignCat((itr.Value().HasAttribute() || itr.Value().HasChild())? "1" : "0");
190 split = Standard_True;
196 //=======================================================================
197 //function : OpenAttributeList
199 // an item is composed as follows:
200 // "DynamicType#MapIndex TransactionIndex Valid|Notvalid Forgotten|NotForgotten Backuped|NotBackuped"
201 // The items are separated by "\\".
202 //=======================================================================
204 TCollection_AsciiString DDF_Browser::OpenAttributeList
205 (const TDF_Label& aLab)
207 TCollection_AsciiString list;
208 Standard_Boolean split1 = Standard_False;
209 for (TDF_AttributeIterator itr(aLab,Standard_False);itr.More();itr.Next())
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());
221 list.AssignCat(TDF_BrowserSeparator2);
222 if (!att->IsValid()) list.AssignCat("Not");
223 list.AssignCat("Valid");
225 list.AssignCat(TDF_BrowserSeparator2);
226 if (!att->IsForgotten()) list.AssignCat("Not");
227 list.AssignCat("Forgotten");
229 list.AssignCat(TDF_BrowserSeparator2);
230 if (!att->IsBackuped()) list.AssignCat("Not");
231 list.AssignCat("Backuped");
233 list.AssignCat(TDF_BrowserSeparator2);
234 DDF_AttributeBrowser* br = DDF_AttributeBrowser::FindBrowser(att);
235 list.AssignCat(br? "1" : "0");
236 split1 = Standard_True;
242 //=======================================================================
243 //function : OpenAttribute
244 //purpose : Attribute's intrinsic information given by an attribute browser.
245 //=======================================================================
247 TCollection_AsciiString DDF_Browser::OpenAttribute
248 (const Standard_Integer anIndex)
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);
258 //=======================================================================
259 //function : Information
260 //purpose : Information about <myDF>.
261 //=======================================================================
263 TCollection_AsciiString DDF_Browser::Information() const
265 TCollection_AsciiString list;
270 //=======================================================================
271 //function : Information
272 //purpose : Information about a label.
273 //=======================================================================
275 TCollection_AsciiString DDF_Browser::Information(const TDF_Label& /*aLab*/) const
277 TCollection_AsciiString list;
282 //=======================================================================
283 //function : Information
284 //purpose : Information about an attribute.
285 //=======================================================================
287 TCollection_AsciiString DDF_Browser::Information(const Standard_Integer /*anIndex*/) const
289 TCollection_AsciiString list;