0c63f2f8 |
1 | // Created on: 2016-11-29 |
2 | // Created by: Irina KRYLOVA |
3 | // Copyright (c) 2016 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 | |
bc73b006 |
16 | #include <XCAFDoc_ClippingPlaneTool.hxx> |
0c63f2f8 |
17 | |
18 | #include <TCollection_HAsciiString.hxx> |
19 | #include <TDataStd_Integer.hxx> |
20 | #include <TDataStd_Name.hxx> |
21 | #include <TDataStd_TreeNode.hxx> |
22 | #include <TDataXtd_Geometry.hxx> |
23 | #include <TDataXtd_Plane.hxx> |
24 | #include <TDF_Attribute.hxx> |
25 | #include <TDF_ChildIDIterator.hxx> |
26 | #include <XCAFDoc.hxx> |
0c63f2f8 |
27 | |
28 | IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_ClippingPlaneTool, TDF_Attribute) |
29 | |
30 | //======================================================================= |
31 | //function : BaseLabel |
32 | //purpose : |
33 | //======================================================================= |
34 | |
35 | TDF_Label XCAFDoc_ClippingPlaneTool::BaseLabel() const |
36 | { |
37 | return Label(); |
38 | } |
39 | |
40 | //======================================================================= |
41 | //function : IsClippingPlane |
42 | //purpose : |
43 | //======================================================================= |
44 | |
45 | Standard_Boolean XCAFDoc_ClippingPlaneTool::IsClippingPlane(const TDF_Label& theLabel) const |
46 | { |
47 | if (theLabel.Father() != Label()) |
48 | return Standard_False; |
49 | |
50 | Handle(TDataXtd_Plane) aPlaneAttribute; |
51 | if (!theLabel.FindAttribute(TDataXtd_Plane::GetID(), aPlaneAttribute)) |
52 | return Standard_False; |
53 | return Standard_True; |
54 | } |
55 | |
56 | //======================================================================= |
57 | //function : GetClippingPlane |
58 | //purpose : |
59 | //======================================================================= |
60 | |
61 | Standard_Boolean XCAFDoc_ClippingPlaneTool::GetClippingPlane(const TDF_Label& theLabel, |
62 | gp_Pln& thePlane, TCollection_ExtendedString& theName, Standard_Boolean &theCapping) const |
63 | { |
64 | if (theLabel.Father() != Label()) |
65 | return Standard_False; |
66 | |
67 | Handle(TDataXtd_Plane) aPlaneAttribute; |
68 | if (!theLabel.FindAttribute(TDataXtd_Plane::GetID(), aPlaneAttribute)) |
69 | return Standard_False; |
70 | |
71 | TDataXtd_Geometry::Plane(aPlaneAttribute->Label(), thePlane); |
72 | Handle(TDataStd_Name) aNameAttribute; |
73 | if (theLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttribute)) |
74 | theName = aNameAttribute->Get(); |
75 | |
76 | Handle(TDataStd_Integer) aCappingAttribute; |
77 | if (theLabel.FindAttribute(TDataStd_Integer::GetID(), aCappingAttribute)) |
78 | theCapping = (aCappingAttribute->Get() == 1); |
79 | |
80 | return Standard_True; |
81 | } |
82 | |
83 | //======================================================================= |
84 | //function : GetClippingPlane |
85 | //purpose : |
86 | //======================================================================= |
87 | |
88 | Standard_Boolean XCAFDoc_ClippingPlaneTool::GetClippingPlane(const TDF_Label& theLabel, |
89 | gp_Pln& thePlane, Handle(TCollection_HAsciiString)& theName, Standard_Boolean &theCapping) const |
90 | { |
91 | TCollection_ExtendedString anExtName; |
92 | if (!GetClippingPlane(theLabel, thePlane, anExtName, theCapping)) |
93 | return Standard_False; |
94 | theName = new TCollection_HAsciiString(anExtName); |
95 | return Standard_True; |
96 | } |
97 | |
98 | //======================================================================= |
99 | //function : AddClippingPlane |
100 | //purpose : |
101 | //======================================================================= |
102 | |
103 | TDF_Label XCAFDoc_ClippingPlaneTool::AddClippingPlane(const gp_Pln thePlane, const TCollection_ExtendedString theName) const |
104 | { |
105 | TDF_Label aLabel; |
106 | TDF_LabelSequence aClippingPlanes; |
107 | GetClippingPlanes(aClippingPlanes); |
108 | for (Standard_Integer i = 1; i <= aClippingPlanes.Length(); i++) { |
109 | gp_Pln aPlane; |
110 | TCollection_ExtendedString aName; |
111 | Standard_Boolean aCapping; |
112 | GetClippingPlane(aClippingPlanes.Value(i), aPlane, aName, aCapping); |
113 | if (!aName.IsEqual(theName)) |
114 | continue; |
115 | if (aPlane.Axis().Angle(thePlane.Axis()) > Precision::Angular()) |
116 | continue; |
117 | if (aPlane.XAxis().Angle(thePlane.XAxis()) > Precision::Angular()) |
118 | continue; |
119 | if (aPlane.YAxis().Angle(thePlane.YAxis()) > Precision::Angular()) |
120 | continue; |
121 | return aClippingPlanes.Value(i); |
122 | } |
123 | |
124 | // create a new clipping plane entry |
125 | TDF_TagSource aTag; |
126 | aLabel = aTag.NewChild(Label()); |
127 | |
128 | TDataXtd_Plane::Set(aLabel, thePlane); |
129 | if (!theName.IsEmpty()) |
130 | TDataStd_Name::Set(aLabel, theName); |
131 | |
132 | return aLabel; |
133 | } |
134 | |
135 | //======================================================================= |
136 | //function : AddClippingPlane |
137 | //purpose : |
138 | //======================================================================= |
139 | |
140 | TDF_Label XCAFDoc_ClippingPlaneTool::AddClippingPlane(const gp_Pln thePlane, const Handle(TCollection_HAsciiString)& theName) const |
141 | { |
142 | TCollection_ExtendedString anExtName = TCollection_ExtendedString(theName->String()); |
143 | return AddClippingPlane(thePlane, anExtName); |
144 | } |
145 | |
146 | |
147 | //======================================================================= |
148 | //function : AddClippingPlane |
149 | //purpose : |
150 | //======================================================================= |
151 | |
152 | TDF_Label XCAFDoc_ClippingPlaneTool::AddClippingPlane(const gp_Pln thePlane, const TCollection_ExtendedString theName, const Standard_Boolean theCapping) const |
153 | { |
154 | TDF_Label aLabel = AddClippingPlane(thePlane, theName); |
155 | Standard_Integer aCappingVal = (theCapping) ? 1 : 0; |
156 | TDataStd_Integer::Set(aLabel, aCappingVal); |
157 | |
158 | return aLabel; |
159 | } |
160 | |
161 | //======================================================================= |
162 | //function : AddClippingPlane |
163 | //purpose : |
164 | //======================================================================= |
165 | |
166 | TDF_Label XCAFDoc_ClippingPlaneTool::AddClippingPlane(const gp_Pln thePlane, const Handle(TCollection_HAsciiString)& theName, const Standard_Boolean theCapping) const |
167 | { |
168 | TCollection_ExtendedString anExtName = TCollection_ExtendedString(theName->String()); |
169 | return AddClippingPlane(thePlane, anExtName, theCapping); |
170 | } |
171 | |
172 | //======================================================================= |
173 | //function : RemoveClippingPlane |
174 | //purpose : |
175 | //======================================================================= |
176 | |
177 | Standard_Boolean XCAFDoc_ClippingPlaneTool::RemoveClippingPlane(const TDF_Label& theLabel) const |
178 | { |
179 | Handle(TDataStd_TreeNode) Node; |
180 | if (!IsClippingPlane(theLabel) || theLabel.FindAttribute(XCAFDoc::ViewRefPlaneGUID(), Node)) |
181 | return Standard_False; |
182 | |
183 | theLabel.ForgetAllAttributes(Standard_True); |
184 | return Standard_True; |
185 | } |
186 | |
187 | //======================================================================= |
188 | //function : GetClippingPlanes |
189 | //purpose : |
190 | //======================================================================= |
191 | |
192 | void XCAFDoc_ClippingPlaneTool::GetClippingPlanes(TDF_LabelSequence& theLabels) const |
193 | { |
194 | theLabels.Clear(); |
195 | |
196 | TDF_ChildIDIterator ChildIDIterator(Label(), TDataXtd_Plane::GetID()); |
197 | for (; ChildIDIterator.More(); ChildIDIterator.Next()) { |
198 | TDF_Label aLabel = ChildIDIterator.Value()->Label(); |
199 | if (IsClippingPlane(aLabel)) theLabels.Append(aLabel); |
200 | } |
201 | } |
202 | |
203 | //======================================================================= |
204 | //function : UpdateClippingPlane |
205 | //purpose : |
206 | //======================================================================= |
207 | |
208 | void XCAFDoc_ClippingPlaneTool::UpdateClippingPlane(const TDF_Label& theLabel, |
209 | const gp_Pln thePlane, const TCollection_ExtendedString theName) const |
210 | { |
211 | if (theLabel.Father() != Label()) |
212 | return; |
213 | |
214 | Handle(TDataXtd_Plane) aPlaneAttribute; |
215 | if (!theLabel.FindAttribute(TDataXtd_Plane::GetID(), aPlaneAttribute)) |
216 | return; |
217 | theLabel.ForgetAttribute(TDataXtd_Plane::GetID()); |
218 | TDataXtd_Plane::Set(theLabel, thePlane); |
219 | theLabel.ForgetAttribute(TDataStd_Name::GetID()); |
220 | TDataStd_Name::Set(theLabel, theName); |
221 | } |
222 | |
223 | //======================================================================= |
224 | //function : SetCapping |
225 | //purpose : |
226 | //======================================================================= |
227 | |
228 | void XCAFDoc_ClippingPlaneTool::SetCapping(const TDF_Label& theClippingPlaneL, const Standard_Boolean theCapping) |
229 | { |
230 | if (theClippingPlaneL.Father() != Label()) |
231 | return; |
232 | |
233 | theClippingPlaneL.ForgetAttribute(TDataStd_Integer::GetID()); |
234 | Standard_Integer aCappingVal = (theCapping) ? 1 : 0; |
235 | TDataStd_Integer::Set(theClippingPlaneL, aCappingVal); |
236 | } |
237 | |
238 | //======================================================================= |
239 | //function : GetCapping |
240 | //purpose : |
241 | //======================================================================= |
242 | |
243 | Standard_Boolean XCAFDoc_ClippingPlaneTool::GetCapping(const TDF_Label& theClippingPlaneL) const |
244 | { |
245 | if (theClippingPlaneL.Father() != Label()) |
246 | return Standard_False; |
247 | |
248 | Handle(TDataStd_Integer) aCappingAttribute; |
249 | if (theClippingPlaneL.FindAttribute(TDataStd_Integer::GetID(), aCappingAttribute)) |
250 | return (aCappingAttribute->Get() == 1); |
251 | |
252 | return Standard_False; |
253 | } |
254 | |
255 | //======================================================================= |
256 | //function : GetCapping |
257 | //purpose : |
258 | //======================================================================= |
259 | |
260 | Standard_Boolean XCAFDoc_ClippingPlaneTool::GetCapping(const TDF_Label& theClippingPlaneL, Standard_Boolean &theCapping) const |
261 | { |
262 | if (theClippingPlaneL.Father() != Label()) |
263 | return Standard_False; |
264 | |
265 | Handle(TDataStd_Integer) aCappingAttribute; |
266 | if (theClippingPlaneL.FindAttribute(TDataStd_Integer::GetID(), aCappingAttribute)) { |
267 | theCapping = (aCappingAttribute->Get() == 1); |
268 | return Standard_True; |
269 | } |
270 | |
271 | return Standard_False; |
272 | } |
273 | |
274 | //======================================================================= |
275 | //function : GetID |
276 | //purpose : |
277 | //======================================================================= |
278 | |
279 | const Standard_GUID& XCAFDoc_ClippingPlaneTool::GetID() |
280 | { |
281 | static Standard_GUID ColorTblID ("efd213ea-6dfd-11d4-b9c8-0060b0ee281b"); |
282 | return ColorTblID; |
283 | } |
284 | |
285 | //======================================================================= |
286 | //function : Set |
287 | //purpose : |
288 | //======================================================================= |
289 | |
290 | Handle(XCAFDoc_ClippingPlaneTool) XCAFDoc_ClippingPlaneTool::Set(const TDF_Label& L) |
291 | { |
292 | Handle(XCAFDoc_ClippingPlaneTool) A; |
293 | if (!L.FindAttribute(XCAFDoc_ClippingPlaneTool::GetID(), A)) { |
294 | A = new XCAFDoc_ClippingPlaneTool(); |
295 | L.AddAttribute(A); |
296 | } |
297 | return A; |
298 | } |
299 | |
300 | //======================================================================= |
301 | //function : ID |
302 | //purpose : |
303 | //======================================================================= |
304 | |
305 | const Standard_GUID& XCAFDoc_ClippingPlaneTool::ID() const |
306 | { |
307 | return GetID(); |
308 | } |
309 | |
310 | //======================================================================= |
311 | //function : Restore |
312 | //purpose : |
313 | //======================================================================= |
314 | |
315 | void XCAFDoc_ClippingPlaneTool::Restore(const Handle(TDF_Attribute)& /*with*/) |
316 | { |
317 | } |
318 | |
319 | //======================================================================= |
320 | //function : NewEmpty |
321 | //purpose : |
322 | //======================================================================= |
323 | |
324 | Handle(TDF_Attribute) XCAFDoc_ClippingPlaneTool::NewEmpty() const |
325 | { |
326 | return new XCAFDoc_ClippingPlaneTool; |
327 | } |
328 | |
329 | //======================================================================= |
330 | //function : Paste |
331 | //purpose : |
332 | //======================================================================= |
333 | |
334 | void XCAFDoc_ClippingPlaneTool::Paste(const Handle(TDF_Attribute)& /*into*/, |
335 | const Handle(TDF_RelocationTable)& /*RT*/) const |
336 | { |
337 | } |
338 | |
339 | //======================================================================= |
340 | //function : XCAFDoc_ClippingPlaneTool |
341 | //purpose : |
342 | //======================================================================= |
343 | |
344 | XCAFDoc_ClippingPlaneTool::XCAFDoc_ClippingPlaneTool() |
345 | { |
346 | } |
347 | |
bc73b006 |
348 | //======================================================================= |
349 | //function : DumpJson |
350 | //purpose : |
351 | //======================================================================= |
352 | void XCAFDoc_ClippingPlaneTool::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const |
353 | { |
354 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) |
355 | |
356 | OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute) |
357 | } |
358 | |