0028044: Data Exchange - implement data structures for Saved Views
[occt.git] / src / XCAFDoc / XCAFDoc_View.cxx
CommitLineData
2df785d7 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_ClippingPlane,
45 ChildLab_FrontPlaneDistance,
46 ChildLab_BackPlaneDistance,
47 ChildLab_ViewVolumeSidesClipping
48};
49
50//=======================================================================
51//function : XCAFDoc_View
52//purpose :
53//=======================================================================
54XCAFDoc_View::XCAFDoc_View()
55{
56}
57
58
59//=======================================================================
60//function : GetID
61//purpose :
62//=======================================================================
63const Standard_GUID& XCAFDoc_View::GetID()
64{
65 static Standard_GUID ViewID ("efd213e8-6dfd-11d4-b9c8-0060b0ee281b");
66 return ViewID;
67}
68
69//=======================================================================
70//function : Set
71//purpose :
72//=======================================================================
73Handle(XCAFDoc_View) XCAFDoc_View::Set(const TDF_Label& theLabel)
74{
75 Handle(XCAFDoc_View) A;
76 if (!theLabel.FindAttribute(XCAFDoc_View::GetID(), A)) {
77 A = new XCAFDoc_View();
78 theLabel.AddAttribute(A);
79 }
80 return A;
81}
82
83//=======================================================================
84//function : SetObject
85//purpose :
86//=======================================================================
87void XCAFDoc_View::SetObject (const Handle(XCAFView_Object)& theObject)
88{
89 Backup();
90
91 TDF_ChildIterator anIter(Label());
92 for(;anIter.More(); anIter.Next())
93 {
94 anIter.Value().ForgetAllAttributes();
95 }
96
97 // Name
98 TDataStd_AsciiString::Set(Label().FindChild(ChildLab_Name), theObject->Name()->String());
99
100 // Type
101 TDataStd_Integer::Set(Label().FindChild(ChildLab_Type), theObject->Type());
102
103 // Projection point
104 TDataXtd_Point::Set(Label().FindChild(ChildLab_ProjectionPoint), theObject->ProjectionPoint());
105
106 // View direction
107 gp_Ax1 aViewDir(gp_Pnt(), theObject->ViewDirection());
108 TDataXtd_Axis::Set(Label().FindChild(ChildLab_ViewDirection), aViewDir);
109
110 // Up direction
111 gp_Ax1 anUpDir(gp_Pnt(), theObject->UpDirection());
112 TDataXtd_Axis::Set(Label().FindChild(ChildLab_UpDirection), anUpDir);
113
114 // Zoom factor
115 TDataStd_Real::Set(Label().FindChild(ChildLab_ZoomFactor), theObject->ZoomFactor());
116
117 // Window horizontal size
118 TDataStd_Real::Set(Label().FindChild(ChildLab_WindowHorizontalSize), theObject->WindowHorizontalSize());
119
120 // Window vertical size
121 TDataStd_Real::Set(Label().FindChild(ChildLab_WindowVerticalSize), theObject->WindowVerticalSize());
122
123 // Clipping plane
124 if (theObject->HasClippingPlane())
125 {
126 TDataXtd_Plane::Set(Label().FindChild(ChildLab_ClippingPlane), theObject->ClippingPlane());
127 }
128
129 // Front plane clipping
130 if (theObject->HasFrontPlaneClipping())
131 {
132 TDataStd_Real::Set(Label().FindChild(ChildLab_FrontPlaneDistance), theObject->FrontPlaneDistance());
133 }
134
135 // Back plane clipping
136 if (theObject->HasBackPlaneClipping())
137 {
138 TDataStd_Real::Set(Label().FindChild(ChildLab_BackPlaneDistance), theObject->BackPlaneDistance());
139 }
140
141 // View volume sides clipping
142 Standard_Integer aValue = theObject->HasViewVolumeSidesClipping() ? 1 : 0;
143 TDataStd_Integer::Set(Label().FindChild(ChildLab_ViewVolumeSidesClipping), aValue);
144}
145
146//=======================================================================
147//function : GetObject
148//purpose :
149//=======================================================================
150Handle(XCAFView_Object) XCAFDoc_View::GetObject() const
151{
152 Handle(XCAFView_Object) anObj = new XCAFView_Object();
153
154 // Name
155 Handle(TDataStd_AsciiString) aName;
156 if (Label().FindChild(ChildLab_Name).FindAttribute(TDataStd_AsciiString::GetID(), aName))
157 {
158 anObj->SetName(new TCollection_HAsciiString(aName->Get()));
159 }
160
161 // Type
162 Handle(TDataStd_Integer) aType;
163 if (Label().FindChild(ChildLab_Type).FindAttribute(TDataStd_Integer::GetID(), aType))
164 {
165 anObj->SetType((XCAFView_ProjectionType)aType->Get());
166 }
167
168 // Projection point
169 Handle(TDataXtd_Point) aPointAttr;
170 if (Label().FindChild(ChildLab_ProjectionPoint).FindAttribute(TDataXtd_Point::GetID(), aPointAttr)) {
171 gp_Pnt aPoint;
172 TDataXtd_Geometry::Point(aPointAttr->Label(), aPoint);
173 anObj->SetProjectionPoint(aPoint);
174 }
175
176 // View direction
177 Handle(TDataXtd_Axis) aViewDirAttr;
178 if (Label().FindChild(ChildLab_ViewDirection).FindAttribute(TDataXtd_Axis::GetID(), aViewDirAttr)) {
179 gp_Ax1 aDir;
180 TDataXtd_Geometry::Axis(aViewDirAttr->Label(), aDir);
181 anObj->SetViewDirection(aDir.Direction());
182 }
183
184 // Up direction
185 Handle(TDataXtd_Axis) anUpDirAttr;
186 if (Label().FindChild(ChildLab_UpDirection).FindAttribute(TDataXtd_Axis::GetID(), anUpDirAttr)) {
187 gp_Ax1 aDir;
188 TDataXtd_Geometry::Axis(anUpDirAttr->Label(), aDir);
189 anObj->SetUpDirection(aDir.Direction());
190 }
191
192 // Zoom factor
193 Handle(TDataStd_Real) aZoomFactor;
194 if (Label().FindChild(ChildLab_ZoomFactor).FindAttribute(TDataStd_Real::GetID(), aZoomFactor))
195 {
196 anObj->SetZoomFactor(aZoomFactor->Get());
197 }
198
199 // Window horizontal size
200 Handle(TDataStd_Real) aWindowHorizontalSize;
201 if (Label().FindChild(ChildLab_WindowHorizontalSize).FindAttribute(TDataStd_Real::GetID(), aWindowHorizontalSize))
202 {
203 anObj->SetWindowHorizontalSize(aWindowHorizontalSize->Get());
204 }
205
206 // Window vertical size
207 Handle(TDataStd_Real) aWindowVerticalSize;
208 if (Label().FindChild(ChildLab_WindowVerticalSize).FindAttribute(TDataStd_Real::GetID(), aWindowVerticalSize))
209 {
210 anObj->SetWindowVerticalSize(aWindowVerticalSize->Get());
211 }
212
213 // Clipping plane
214 Handle(TDataXtd_Plane) aPlaneAttr;
215 if (Label().FindChild(ChildLab_ClippingPlane).FindAttribute(TDataXtd_Plane::GetID(), aPlaneAttr)) {
216 gp_Pln aPlane;
217 TDataXtd_Geometry::Plane(aPlaneAttr->Label(), aPlane);
218 anObj->SetClippingPlane(aPlane);
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 return anObj;
244}
245
246//=======================================================================
247//function : ID
248//purpose :
249//=======================================================================
250const Standard_GUID& XCAFDoc_View::ID() const
251{
252 return GetID();
253}
254
255//=======================================================================
256//function : Restore
257//purpose :
258//=======================================================================
259void XCAFDoc_View::Restore(const Handle(TDF_Attribute)& /*With*/)
260{
261}
262
263
264//=======================================================================
265//function : NewEmpty
266//purpose :
267//=======================================================================
268Handle(TDF_Attribute) XCAFDoc_View::NewEmpty() const
269{
270 return new XCAFDoc_View();
271}
272
273
274//=======================================================================
275//function : Paste
276//purpose :
277//=======================================================================
278void XCAFDoc_View::Paste(const Handle(TDF_Attribute)& /*Into*/,
279 const Handle(TDF_RelocationTable)& /*RT*/) const
280{
281}