1 // Created on: 2016-10-19
2 // Created by: Irina KRYLOVA
3 // Copyright (c) 2016 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.
16 #include <XCAFDoc_View.hxx>
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>
32 IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_View, TDF_Attribute)
38 ChildLab_ProjectionPoint,
39 ChildLab_ViewDirection,
42 ChildLab_WindowHorizontalSize,
43 ChildLab_WindowVerticalSize,
44 ChildLab_FrontPlaneDistance,
45 ChildLab_BackPlaneDistance,
46 ChildLab_ViewVolumeSidesClipping,
47 ChildLab_ClippingExpression,
51 //=======================================================================
52 //function : XCAFDoc_View
54 //=======================================================================
55 XCAFDoc_View::XCAFDoc_View()
60 //=======================================================================
63 //=======================================================================
64 const Standard_GUID& XCAFDoc_View::GetID()
66 static Standard_GUID ViewID ("efd213e8-6dfd-11d4-b9c8-0060b0ee281b");
70 //=======================================================================
73 //=======================================================================
74 Handle(XCAFDoc_View) XCAFDoc_View::Set(const TDF_Label& theLabel)
76 Handle(XCAFDoc_View) A;
77 if (!theLabel.FindAttribute(XCAFDoc_View::GetID(), A)) {
78 A = new XCAFDoc_View();
79 theLabel.AddAttribute(A);
84 //=======================================================================
85 //function : SetObject
87 //=======================================================================
88 void XCAFDoc_View::SetObject (const Handle(XCAFView_Object)& theObject)
92 TDF_ChildIterator anIter(Label());
93 for(;anIter.More(); anIter.Next())
95 anIter.Value().ForgetAllAttributes();
99 TDataStd_AsciiString::Set(Label().FindChild(ChildLab_Name), theObject->Name()->String());
102 TDataStd_Integer::Set(Label().FindChild(ChildLab_Type), theObject->Type());
105 TDataXtd_Point::Set(Label().FindChild(ChildLab_ProjectionPoint), theObject->ProjectionPoint());
108 gp_Ax1 aViewDir(gp_Pnt(), theObject->ViewDirection());
109 TDataXtd_Axis::Set(Label().FindChild(ChildLab_ViewDirection), aViewDir);
112 gp_Ax1 anUpDir(gp_Pnt(), theObject->UpDirection());
113 TDataXtd_Axis::Set(Label().FindChild(ChildLab_UpDirection), anUpDir);
116 TDataStd_Real::Set(Label().FindChild(ChildLab_ZoomFactor), theObject->ZoomFactor());
118 // Window horizontal size
119 TDataStd_Real::Set(Label().FindChild(ChildLab_WindowHorizontalSize), theObject->WindowHorizontalSize());
121 // Window vertical size
122 TDataStd_Real::Set(Label().FindChild(ChildLab_WindowVerticalSize), theObject->WindowVerticalSize());
124 // Front plane clipping
125 if (theObject->HasFrontPlaneClipping())
127 TDataStd_Real::Set(Label().FindChild(ChildLab_FrontPlaneDistance), theObject->FrontPlaneDistance());
130 // Back plane clipping
131 if (theObject->HasBackPlaneClipping())
133 TDataStd_Real::Set(Label().FindChild(ChildLab_BackPlaneDistance), theObject->BackPlaneDistance());
136 // View volume sides clipping
137 Standard_Integer aValue = theObject->HasViewVolumeSidesClipping() ? 1 : 0;
138 TDataStd_Integer::Set(Label().FindChild(ChildLab_ViewVolumeSidesClipping), aValue);
140 // Clipping Expression
141 if (!theObject->ClippingExpression().IsNull())
142 TDataStd_AsciiString::Set(Label().FindChild(ChildLab_ClippingExpression), theObject->ClippingExpression()->String());
145 if (theObject->HasGDTPoints())
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));
154 //=======================================================================
155 //function : GetObject
157 //=======================================================================
158 Handle(XCAFView_Object) XCAFDoc_View::GetObject() const
160 Handle(XCAFView_Object) anObj = new XCAFView_Object();
163 Handle(TDataStd_AsciiString) aName;
164 if (Label().FindChild(ChildLab_Name).FindAttribute(TDataStd_AsciiString::GetID(), aName))
166 anObj->SetName(new TCollection_HAsciiString(aName->Get()));
170 Handle(TDataStd_Integer) aType;
171 if (Label().FindChild(ChildLab_Type).FindAttribute(TDataStd_Integer::GetID(), aType))
173 anObj->SetType((XCAFView_ProjectionType)aType->Get());
177 Handle(TDataXtd_Point) aPointAttr;
178 if (Label().FindChild(ChildLab_ProjectionPoint).FindAttribute(TDataXtd_Point::GetID(), aPointAttr)) {
180 TDataXtd_Geometry::Point(aPointAttr->Label(), aPoint);
181 anObj->SetProjectionPoint(aPoint);
185 Handle(TDataXtd_Axis) aViewDirAttr;
186 if (Label().FindChild(ChildLab_ViewDirection).FindAttribute(TDataXtd_Axis::GetID(), aViewDirAttr)) {
188 TDataXtd_Geometry::Axis(aViewDirAttr->Label(), aDir);
189 anObj->SetViewDirection(aDir.Direction());
193 Handle(TDataXtd_Axis) anUpDirAttr;
194 if (Label().FindChild(ChildLab_UpDirection).FindAttribute(TDataXtd_Axis::GetID(), anUpDirAttr)) {
196 TDataXtd_Geometry::Axis(anUpDirAttr->Label(), aDir);
197 anObj->SetUpDirection(aDir.Direction());
201 Handle(TDataStd_Real) aZoomFactor;
202 if (Label().FindChild(ChildLab_ZoomFactor).FindAttribute(TDataStd_Real::GetID(), aZoomFactor))
204 anObj->SetZoomFactor(aZoomFactor->Get());
207 // Window horizontal size
208 Handle(TDataStd_Real) aWindowHorizontalSize;
209 if (Label().FindChild(ChildLab_WindowHorizontalSize).FindAttribute(TDataStd_Real::GetID(), aWindowHorizontalSize))
211 anObj->SetWindowHorizontalSize(aWindowHorizontalSize->Get());
214 // Window vertical size
215 Handle(TDataStd_Real) aWindowVerticalSize;
216 if (Label().FindChild(ChildLab_WindowVerticalSize).FindAttribute(TDataStd_Real::GetID(), aWindowVerticalSize))
218 anObj->SetWindowVerticalSize(aWindowVerticalSize->Get());
221 // Front plane clipping
222 Handle(TDataStd_Real) aFrontPlaneDistance;
223 if (Label().FindChild(ChildLab_FrontPlaneDistance).FindAttribute(TDataStd_Real::GetID(), aFrontPlaneDistance))
225 anObj->SetFrontPlaneDistance(aFrontPlaneDistance->Get());
228 // Back plane clipping
229 Handle(TDataStd_Real) aBackPlaneDistance;
230 if (Label().FindChild(ChildLab_BackPlaneDistance).FindAttribute(TDataStd_Real::GetID(), aBackPlaneDistance))
232 anObj->SetBackPlaneDistance(aBackPlaneDistance->Get());
235 // View volume sides clipping
236 Handle(TDataStd_Integer) aViewVolumeSidesClipping;
237 if (Label().FindChild(ChildLab_ViewVolumeSidesClipping).FindAttribute(TDataStd_Integer::GetID(), aViewVolumeSidesClipping))
239 Standard_Boolean aValue = (aViewVolumeSidesClipping->Get() == 1);
240 anObj->SetViewVolumeSidesClipping(aValue);
244 Handle(TDataStd_AsciiString) aClippingExpression;
245 if (Label().FindChild(ChildLab_ClippingExpression).FindAttribute(TDataStd_AsciiString::GetID(), aClippingExpression))
247 anObj->SetClippingExpression(new TCollection_HAsciiString(aClippingExpression->Get()));
251 if (!Label().FindChild(ChildLab_GDTPoints, Standard_False).IsNull()) {
252 TDF_Label aPointsLabel = Label().FindChild(ChildLab_GDTPoints);
254 // Find out the number of stored GDT-points in Ocaf tree.
255 Standard_Integer aNbGDTPoints = 0;
256 Handle(TDataXtd_Point) aGDTPointAttr;
257 TDF_ChildIterator anItrPnts (aPointsLabel, Standard_False);
258 for (; anItrPnts.More(); anItrPnts.Next()) {
259 if (anItrPnts.Value().FindAttribute (TDataXtd_Point::GetID(), aGDTPointAttr))
263 // Allocate the GDT-points and fill them in from Ocaf tree.
265 anObj->CreateGDTPoints (aNbGDTPoints);
266 const Standard_Integer aNbChildren = aPointsLabel.NbChildren();
267 for (Standard_Integer aLabelIndex = 1, aPointIndex = 1; aLabelIndex <= aNbChildren; aLabelIndex++) {
269 if (aPointsLabel.FindChild (aLabelIndex).FindAttribute (TDataXtd_Point::GetID(), aGDTPointAttr)) {
270 TDataXtd_Geometry::Point (aGDTPointAttr->Label(), aPoint);
271 anObj->SetGDTPoint (aPointIndex++, aPoint);
280 //=======================================================================
283 //=======================================================================
284 const Standard_GUID& XCAFDoc_View::ID() const
289 //=======================================================================
292 //=======================================================================
293 void XCAFDoc_View::Restore(const Handle(TDF_Attribute)& /*With*/)
298 //=======================================================================
299 //function : NewEmpty
301 //=======================================================================
302 Handle(TDF_Attribute) XCAFDoc_View::NewEmpty() const
304 return new XCAFDoc_View();
308 //=======================================================================
311 //=======================================================================
312 void XCAFDoc_View::Paste(const Handle(TDF_Attribute)& /*Into*/,
313 const Handle(TDF_RelocationTable)& /*RT*/) const