Warnings on vc14 were eliminated
[occt.git] / src / XCAFDoc / XCAFDoc_View.cxx
... / ...
CommitLineData
1// Created on: 2016-10-19
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
16#include <XCAFDoc_View.hxx>
17
18#include <Standard_GUID.hxx>
19#include <TDataStd_AsciiString.hxx>
20#include <TDataStd_Integer.hxx>
21#include <TDataStd_Real.hxx>
22#include <TDataStd_RealArray.hxx>
23#include <TDataXtd_Axis.hxx>
24#include <TDataXtd_Geometry.hxx>
25#include <TDataXtd_Plane.hxx>
26#include <TDataXtd_Point.hxx>
27#include <TDF_ChildIterator.hxx>
28#include <TColStd_HArray1OfReal.hxx>
29#include <XCAFDoc.hxx>
30#include <XCAFView_Object.hxx>
31
32IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_View, TDF_Attribute)
33
34enum ChildLab
35{
36 ChildLab_Name = 1,
37 ChildLab_Type,
38 ChildLab_ProjectionPoint,
39 ChildLab_ViewDirection,
40 ChildLab_UpDirection,
41 ChildLab_ZoomFactor,
42 ChildLab_WindowHorizontalSize,
43 ChildLab_WindowVerticalSize,
44 ChildLab_FrontPlaneDistance,
45 ChildLab_BackPlaneDistance,
46 ChildLab_ViewVolumeSidesClipping,
47 ChildLab_ClippingExpression,
48 ChildLab_GDTPoints
49};
50
51//=======================================================================
52//function : XCAFDoc_View
53//purpose :
54//=======================================================================
55XCAFDoc_View::XCAFDoc_View()
56{
57}
58
59
60//=======================================================================
61//function : GetID
62//purpose :
63//=======================================================================
64const Standard_GUID& XCAFDoc_View::GetID()
65{
66 static Standard_GUID ViewID ("efd213e8-6dfd-11d4-b9c8-0060b0ee281b");
67 return ViewID;
68}
69
70//=======================================================================
71//function : Set
72//purpose :
73//=======================================================================
74Handle(XCAFDoc_View) XCAFDoc_View::Set(const TDF_Label& theLabel)
75{
76 Handle(XCAFDoc_View) A;
77 if (!theLabel.FindAttribute(XCAFDoc_View::GetID(), A)) {
78 A = new XCAFDoc_View();
79 theLabel.AddAttribute(A);
80 }
81 return A;
82}
83
84//=======================================================================
85//function : SetObject
86//purpose :
87//=======================================================================
88void XCAFDoc_View::SetObject (const Handle(XCAFView_Object)& theObject)
89{
90 Backup();
91
92 TDF_ChildIterator anIter(Label());
93 for(;anIter.More(); anIter.Next())
94 {
95 anIter.Value().ForgetAllAttributes();
96 }
97
98 // Name
99 TDataStd_AsciiString::Set(Label().FindChild(ChildLab_Name), theObject->Name()->String());
100
101 // Type
102 TDataStd_Integer::Set(Label().FindChild(ChildLab_Type), theObject->Type());
103
104 // Projection point
105 TDataXtd_Point::Set(Label().FindChild(ChildLab_ProjectionPoint), theObject->ProjectionPoint());
106
107 // View direction
108 gp_Ax1 aViewDir(gp_Pnt(), theObject->ViewDirection());
109 TDataXtd_Axis::Set(Label().FindChild(ChildLab_ViewDirection), aViewDir);
110
111 // Up direction
112 gp_Ax1 anUpDir(gp_Pnt(), theObject->UpDirection());
113 TDataXtd_Axis::Set(Label().FindChild(ChildLab_UpDirection), anUpDir);
114
115 // Zoom factor
116 TDataStd_Real::Set(Label().FindChild(ChildLab_ZoomFactor), theObject->ZoomFactor());
117
118 // Window horizontal size
119 TDataStd_Real::Set(Label().FindChild(ChildLab_WindowHorizontalSize), theObject->WindowHorizontalSize());
120
121 // Window vertical size
122 TDataStd_Real::Set(Label().FindChild(ChildLab_WindowVerticalSize), theObject->WindowVerticalSize());
123
124 // Front plane clipping
125 if (theObject->HasFrontPlaneClipping())
126 {
127 TDataStd_Real::Set(Label().FindChild(ChildLab_FrontPlaneDistance), theObject->FrontPlaneDistance());
128 }
129
130 // Back plane clipping
131 if (theObject->HasBackPlaneClipping())
132 {
133 TDataStd_Real::Set(Label().FindChild(ChildLab_BackPlaneDistance), theObject->BackPlaneDistance());
134 }
135
136 // View volume sides clipping
137 Standard_Integer aValue = theObject->HasViewVolumeSidesClipping() ? 1 : 0;
138 TDataStd_Integer::Set(Label().FindChild(ChildLab_ViewVolumeSidesClipping), aValue);
139
140 // Clipping Expression
141 if (!theObject->ClippingExpression().IsNull())
142 TDataStd_AsciiString::Set(Label().FindChild(ChildLab_ClippingExpression), theObject->ClippingExpression()->String());
143
144 // GDT points
145 if (theObject->HasGDTPoints())
146 {
147 TDF_Label aPointsLabel = Label().FindChild(ChildLab_GDTPoints);
148 for (Standard_Integer i = 1; i <= theObject->NbGDTPoints(); i++) {
149 TDataXtd_Point::Set(aPointsLabel.FindChild(i), theObject->GDTPoint(i));
150 }
151 }
152}
153
154//=======================================================================
155//function : GetObject
156//purpose :
157//=======================================================================
158Handle(XCAFView_Object) XCAFDoc_View::GetObject() const
159{
160 Handle(XCAFView_Object) anObj = new XCAFView_Object();
161
162 // Name
163 Handle(TDataStd_AsciiString) aName;
164 if (Label().FindChild(ChildLab_Name).FindAttribute(TDataStd_AsciiString::GetID(), aName))
165 {
166 anObj->SetName(new TCollection_HAsciiString(aName->Get()));
167 }
168
169 // Type
170 Handle(TDataStd_Integer) aType;
171 if (Label().FindChild(ChildLab_Type).FindAttribute(TDataStd_Integer::GetID(), aType))
172 {
173 anObj->SetType((XCAFView_ProjectionType)aType->Get());
174 }
175
176 // Projection point
177 Handle(TDataXtd_Point) aPointAttr;
178 if (Label().FindChild(ChildLab_ProjectionPoint).FindAttribute(TDataXtd_Point::GetID(), aPointAttr)) {
179 gp_Pnt aPoint;
180 TDataXtd_Geometry::Point(aPointAttr->Label(), aPoint);
181 anObj->SetProjectionPoint(aPoint);
182 }
183
184 // View direction
185 Handle(TDataXtd_Axis) aViewDirAttr;
186 if (Label().FindChild(ChildLab_ViewDirection).FindAttribute(TDataXtd_Axis::GetID(), aViewDirAttr)) {
187 gp_Ax1 aDir;
188 TDataXtd_Geometry::Axis(aViewDirAttr->Label(), aDir);
189 anObj->SetViewDirection(aDir.Direction());
190 }
191
192 // Up direction
193 Handle(TDataXtd_Axis) anUpDirAttr;
194 if (Label().FindChild(ChildLab_UpDirection).FindAttribute(TDataXtd_Axis::GetID(), anUpDirAttr)) {
195 gp_Ax1 aDir;
196 TDataXtd_Geometry::Axis(anUpDirAttr->Label(), aDir);
197 anObj->SetUpDirection(aDir.Direction());
198 }
199
200 // Zoom factor
201 Handle(TDataStd_Real) aZoomFactor;
202 if (Label().FindChild(ChildLab_ZoomFactor).FindAttribute(TDataStd_Real::GetID(), aZoomFactor))
203 {
204 anObj->SetZoomFactor(aZoomFactor->Get());
205 }
206
207 // Window horizontal size
208 Handle(TDataStd_Real) aWindowHorizontalSize;
209 if (Label().FindChild(ChildLab_WindowHorizontalSize).FindAttribute(TDataStd_Real::GetID(), aWindowHorizontalSize))
210 {
211 anObj->SetWindowHorizontalSize(aWindowHorizontalSize->Get());
212 }
213
214 // Window vertical size
215 Handle(TDataStd_Real) aWindowVerticalSize;
216 if (Label().FindChild(ChildLab_WindowVerticalSize).FindAttribute(TDataStd_Real::GetID(), aWindowVerticalSize))
217 {
218 anObj->SetWindowVerticalSize(aWindowVerticalSize->Get());
219 }
220
221 // Front plane clipping
222 Handle(TDataStd_Real) aFrontPlaneDistance;
223 if (Label().FindChild(ChildLab_FrontPlaneDistance).FindAttribute(TDataStd_Real::GetID(), aFrontPlaneDistance))
224 {
225 anObj->SetFrontPlaneDistance(aFrontPlaneDistance->Get());
226 }
227
228 // Back plane clipping
229 Handle(TDataStd_Real) aBackPlaneDistance;
230 if (Label().FindChild(ChildLab_BackPlaneDistance).FindAttribute(TDataStd_Real::GetID(), aBackPlaneDistance))
231 {
232 anObj->SetBackPlaneDistance(aBackPlaneDistance->Get());
233 }
234
235 // View volume sides clipping
236 Handle(TDataStd_Integer) aViewVolumeSidesClipping;
237 if (Label().FindChild(ChildLab_ViewVolumeSidesClipping).FindAttribute(TDataStd_Integer::GetID(), aViewVolumeSidesClipping))
238 {
239 Standard_Boolean aValue = (aViewVolumeSidesClipping->Get() == 1);
240 anObj->SetViewVolumeSidesClipping(aValue);
241 }
242
243 // Name
244 Handle(TDataStd_AsciiString) aClippingExpression;
245 if (Label().FindChild(ChildLab_ClippingExpression).FindAttribute(TDataStd_AsciiString::GetID(), aClippingExpression))
246 {
247 anObj->SetClippingExpression(new TCollection_HAsciiString(aClippingExpression->Get()));
248 }
249
250 // GDT Points
251 if (!Label().FindChild(ChildLab_GDTPoints, Standard_False).IsNull()) {
252 TDF_Label aPointsLabel = Label().FindChild(ChildLab_GDTPoints);
253 anObj->CreateGDTPoints(aPointsLabel.NbChildren());
254 for (Standard_Integer i = 1; i <= aPointsLabel.NbChildren(); i++) {
255 gp_Pnt aPoint;
256 Handle(TDataXtd_Point) aGDTPointAttr;
257 aPointsLabel.FindChild(i).FindAttribute(TDataXtd_Point::GetID(), aGDTPointAttr);
258 TDataXtd_Geometry::Point(aGDTPointAttr->Label(), aPoint);
259 anObj->SetGDTPoint(i, aPoint);
260 }
261 }
262
263 return anObj;
264}
265
266//=======================================================================
267//function : ID
268//purpose :
269//=======================================================================
270const Standard_GUID& XCAFDoc_View::ID() const
271{
272 return GetID();
273}
274
275//=======================================================================
276//function : Restore
277//purpose :
278//=======================================================================
279void XCAFDoc_View::Restore(const Handle(TDF_Attribute)& /*With*/)
280{
281}
282
283
284//=======================================================================
285//function : NewEmpty
286//purpose :
287//=======================================================================
288Handle(TDF_Attribute) XCAFDoc_View::NewEmpty() const
289{
290 return new XCAFDoc_View();
291}
292
293
294//=======================================================================
295//function : Paste
296//purpose :
297//=======================================================================
298void XCAFDoc_View::Paste(const Handle(TDF_Attribute)& /*Into*/,
299 const Handle(TDF_RelocationTable)& /*RT*/) const
300{
301}