b311480e |
1 | // Created by: DAUTRY Philippe |
2 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
b311480e |
15 | |
7fd59977 |
16 | // -------------------- |
7fd59977 |
17 | // Version: 0.0 |
b311480e |
18 | //Version Date Purpose |
7fd59977 |
19 | // 0.0 Nov 27 1997 Creation |
20 | |
7fd59977 |
21 | #include <DDataStd.hxx> |
42cf5bc1 |
22 | #include <DDataStd_TreeBrowser.hxx> |
23 | #include <Draw_Display.hxx> |
24 | #include <Draw_Drawable3D.hxx> |
25 | #include <Standard_Type.hxx> |
7fd59977 |
26 | #include <TCollection_AsciiString.hxx> |
27 | #include <TCollection_ExtendedString.hxx> |
42cf5bc1 |
28 | #include <TDataStd_Name.hxx> |
29 | #include <TDataStd_TreeNode.hxx> |
7fd59977 |
30 | #include <TDF.hxx> |
42cf5bc1 |
31 | #include <TDF_Label.hxx> |
32 | #include <TDF_Tool.hxx> |
7fd59977 |
33 | |
92efcf78 |
34 | IMPLEMENT_STANDARD_RTTIEXT(DDataStd_TreeBrowser,Draw_Drawable3D) |
35 | |
7fd59977 |
36 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
37 | // Communication convention with tcl: |
38 | // tcl waits for a string of characters, being an information list. |
39 | // In this list, each item is separated from another by a separator: '\'. |
40 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7fd59977 |
41 | #define TDF_BrowserSeparator1 '\\' |
42 | #define TDF_BrowserSeparator2 ' ' |
43 | #define TDF_BrowserSeparator3 '#' |
44 | #define TDF_BrowserSeparator4 ',' |
45 | |
46 | |
47 | //======================================================================= |
48 | //function : DDesign_TreeNodeBrowser |
49 | //purpose : |
50 | //======================================================================= |
51 | |
52 | DDataStd_TreeBrowser::DDataStd_TreeBrowser(const TDF_Label& aLabel) |
53 | : myRoot(aLabel) |
54 | {} |
55 | |
56 | |
57 | //======================================================================= |
58 | //function : DrawOn |
59 | //purpose : |
60 | //======================================================================= |
61 | |
35e08fe8 |
62 | void DDataStd_TreeBrowser::DrawOn(Draw_Display& /*dis*/) const |
7fd59977 |
63 | { cout<<"DDataStd_TreeBrowser"<<endl; } |
64 | |
65 | |
66 | //======================================================================= |
67 | //function : Copy |
68 | //purpose : |
69 | //======================================================================= |
70 | |
71 | Handle(Draw_Drawable3D) DDataStd_TreeBrowser::Copy() const |
72 | { return new DDataStd_TreeBrowser(myRoot); } |
73 | |
74 | |
75 | //======================================================================= |
76 | //function : Dump |
77 | //purpose : |
78 | //======================================================================= |
79 | |
80 | void DDataStd_TreeBrowser::Dump(Standard_OStream& S) const |
81 | { |
82 | S<<"DDataStd_TreeBrowser on a label: "<<endl; |
83 | S<<myRoot; |
84 | } |
85 | |
86 | |
87 | //======================================================================= |
88 | //function : Whatis |
89 | //purpose : |
90 | //======================================================================= |
91 | |
92 | void DDataStd_TreeBrowser::Whatis(Draw_Interpretor& I) const |
93 | { I<<"function browser"; } |
94 | |
95 | |
96 | //======================================================================= |
97 | //function : Label |
98 | //purpose : |
99 | //======================================================================= |
100 | |
101 | void DDataStd_TreeBrowser::Label(const TDF_Label& aLabel) |
102 | { myRoot = aLabel; } |
103 | |
104 | |
105 | //======================================================================= |
106 | //function : Label |
107 | //purpose : |
108 | //======================================================================= |
109 | |
110 | TDF_Label DDataStd_TreeBrowser::Label() const |
111 | { return myRoot; } |
112 | |
113 | |
114 | //======================================================================= |
115 | //function : OpenRoot |
116 | //purpose : |
117 | //======================================================================= |
118 | |
119 | TCollection_AsciiString DDataStd_TreeBrowser::OpenRoot() const |
120 | { |
121 | TCollection_AsciiString list; |
122 | Handle(TDataStd_TreeNode) TN; |
123 | if (myRoot.FindAttribute (TDataStd_TreeNode::GetDefaultTreeID(),TN)) { |
124 | OpenNode(TN,list); |
125 | } |
126 | return list; |
127 | } |
128 | |
129 | |
130 | //======================================================================= |
131 | //function : OpenNode |
132 | //purpose : |
133 | // the items are separated by "\\". |
134 | //======================================================================= |
135 | |
136 | TCollection_AsciiString DDataStd_TreeBrowser::OpenNode(const TDF_Label& aLabel) const |
137 | { |
138 | TCollection_AsciiString list; |
139 | Handle(TDataStd_TreeNode) nodeToOpen; |
140 | if (aLabel.FindAttribute(TDataStd_TreeNode::GetDefaultTreeID(), nodeToOpen)) { |
141 | Standard_Boolean split = Standard_False; |
142 | Handle(TDataStd_TreeNode) current = nodeToOpen->First(); |
143 | while (!current.IsNull()) { |
144 | if (split) list.AssignCat(TDF_BrowserSeparator1); |
145 | OpenNode(current,list); |
146 | split = Standard_True; |
147 | current = current->Next(); |
148 | } |
149 | } |
150 | return list; |
151 | } |
152 | |
153 | |
154 | //======================================================================= |
155 | //function : OpenNode |
156 | //purpose : |
157 | // An item is composed as follows: |
158 | // "LabelEntry "Name" DynamicType Executable|Forgotten Failed|Success First|Null [ LabelFather]" |
159 | // First/Null : has/has not child |
160 | //======================================================================= |
161 | |
162 | void DDataStd_TreeBrowser::OpenNode (const Handle(TDataStd_TreeNode)& aTreeNode, |
163 | TCollection_AsciiString& aList) const |
164 | { |
165 | // Label entry. -0 |
166 | TCollection_AsciiString tmp; |
167 | TDF_Tool::Entry(aTreeNode->Label(),tmp); |
168 | aList.AssignCat(tmp); |
169 | // Name -1 |
170 | aList.AssignCat(TDF_BrowserSeparator2); |
171 | Handle(TDataStd_Name) name; |
172 | aList.AssignCat("\""); |
173 | if (aTreeNode->Label().FindAttribute(TDataStd_Name::GetID(),name)) { |
174 | TCollection_AsciiString tmpStr(name->Get(),'?'); |
175 | tmpStr.ChangeAll(' ','_'); |
176 | aList.AssignCat(tmpStr); |
177 | } |
178 | aList.AssignCat("\""); |
179 | // Dynamic type. -2 |
180 | aList.AssignCat(TDF_BrowserSeparator2); |
181 | TCollection_ExtendedString ext; |
182 | if (TDF::ProgIDFromGUID(aTreeNode->ID(), ext)) |
183 | aList.AssignCat(TCollection_AsciiString(ext,'?')); |
184 | else aList.AssignCat(aTreeNode->DynamicType()->Name()); |
185 | // Executable or Forgotten? -3 |
186 | // aList.AssignCat(TDF_BrowserSeparator2); |
187 | // if (aTreeNode->IsExecutable()) aList.AssignCat("Executable"); |
188 | // else aList.AssignCat("Forgotten"); |
189 | // Failed or Success? -4 |
190 | // aList.AssignCat(TDF_BrowserSeparator2); |
191 | // if (aTreeNode->Failed()) aList.AssignCat("Failed"); |
192 | // else aList.AssignCat("Success"); |
193 | //Children? -3 |
194 | aList.AssignCat(TDF_BrowserSeparator2); |
195 | if (aTreeNode->First().IsNull()) aList.AssignCat("Null"); |
196 | else aList.AssignCat("First"); |
197 | // Father? -4 |
198 | aList.AssignCat(TDF_BrowserSeparator2); |
199 | if (!aTreeNode->HasFather()) aList.AssignCat("Null"); |
200 | else { |
201 | TDF_Tool::Entry(aTreeNode->Father()->Label(),tmp); |
202 | aList.AssignCat(tmp); |
203 | } |
204 | // First? -5 |
205 | aList.AssignCat(TDF_BrowserSeparator2); |
206 | if (!aTreeNode->HasFirst()) aList.AssignCat("Null"); |
207 | else { |
208 | TDF_Tool::Entry(aTreeNode->First()->Label(),tmp); |
209 | aList.AssignCat(tmp); |
210 | } |
211 | // Next? -6 |
212 | aList.AssignCat(TDF_BrowserSeparator2); |
213 | if (!aTreeNode->HasNext()) aList.AssignCat("Null"); |
214 | else { |
215 | TDF_Tool::Entry(aTreeNode->Next()->Label(),tmp); |
216 | aList.AssignCat(tmp); |
217 | } |
218 | // Previous? -7 |
219 | aList.AssignCat(TDF_BrowserSeparator2); |
220 | if (!aTreeNode->HasPrevious()) aList.AssignCat("Null"); |
221 | else { |
222 | TDF_Tool::Entry(aTreeNode->Previous()->Label(),tmp); |
223 | aList.AssignCat(tmp); |
224 | } |
225 | } |