1 // Created on: 2009-04-06
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2009-2014 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.
17 #include <BRep_Tool.hxx>
18 #include <BRepBuilderAPI_MakeFace.hxx>
19 #include <Geom_Plane.hxx>
20 #include <Geom_RectangularTrimmedSurface.hxx>
21 #include <GeomLib_IsPlanarSurface.hxx>
23 #include <Standard_GUID.hxx>
24 #include <Standard_Type.hxx>
25 #include <TDataStd.hxx>
26 #include <TDataXtd.hxx>
27 #include <TDataXtd_Plane.hxx>
28 #include <TDF_Attribute.hxx>
29 #include <TDF_Label.hxx>
30 #include <TDF_RelocationTable.hxx>
31 #include <TNaming_Builder.hxx>
32 #include <TNaming_NamedShape.hxx>
33 #include <TNaming_Tool.hxx>
36 #include <TopoDS_Face.hxx>
38 IMPLEMENT_STANDARD_RTTIEXT(TDataXtd_Plane,TDF_Attribute)
40 //=======================================================================
43 //=======================================================================
44 const Standard_GUID& TDataXtd_Plane::GetID ()
46 static Standard_GUID TDataXtd_PlaneID("2a96b60c-ec8b-11d0-bee7-080009dc3333");
47 return TDataXtd_PlaneID;
51 //=======================================================================
54 //=======================================================================
56 Handle(TDataXtd_Plane) TDataXtd_Plane::Set (const TDF_Label& L)
58 Handle(TDataXtd_Plane) A;
59 if (!L.FindAttribute(TDataXtd_Plane::GetID(),A)) {
60 A = new TDataXtd_Plane ();
68 //=======================================================================
71 //=======================================================================
73 Handle(TDataXtd_Plane) TDataXtd_Plane::Set (const TDF_Label& L, const gp_Pln& P)
75 Handle(TDataXtd_Plane) A = Set (L);
77 Handle(TNaming_NamedShape) aNS;
78 if(L.FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
79 if(!aNS->Get().IsNull())
80 if(aNS->Get().ShapeType() == TopAbs_FACE) {
81 TopoDS_Face aFace = TopoDS::Face(aNS->Get());
82 Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace);
83 GeomLib_IsPlanarSurface aChecker(aSurface);
84 if(aChecker.IsPlanar()) {
85 gp_Pln aPlane = aChecker.Plan();
86 if(aPlane.Location().X() == P.Location().X() &&
87 aPlane.Location().Y() == P.Location().Y() &&
88 aPlane.Location().Z() == P.Location().Z() &&
89 aPlane.Axis().Location().X() == P.Axis().Location().X() &&
90 aPlane.Axis().Location().Y() == P.Axis().Location().Y() &&
91 aPlane.Axis().Location().Z() == P.Axis().Location().Z() &&
92 aPlane.Axis().Direction().X() == P.Axis().Direction().X() &&
93 aPlane.Axis().Direction().Y() == P.Axis().Direction().Y() &&
94 aPlane.Axis().Direction().Z() == P.Axis().Direction().Z()
101 TNaming_Builder B(L);
102 B.Generated(BRepBuilderAPI_MakeFace(P));
106 //=======================================================================
107 //function : TDataXtd_Plane
109 //=======================================================================
111 TDataXtd_Plane::TDataXtd_Plane () { }
114 //=======================================================================
117 //=======================================================================
119 const Standard_GUID& TDataXtd_Plane::ID() const { return GetID(); }
121 //=======================================================================
122 //function : NewEmpty
124 //=======================================================================
126 Handle(TDF_Attribute) TDataXtd_Plane::NewEmpty () const
128 return new TDataXtd_Plane();
131 //=======================================================================
134 //=======================================================================
136 void TDataXtd_Plane::Restore(const Handle(TDF_Attribute)&) {}
138 //=======================================================================
141 //=======================================================================
143 void TDataXtd_Plane::Paste (const Handle(TDF_Attribute)&, const Handle(TDF_RelocationTable)&) const { }
146 //=======================================================================
149 //=======================================================================
151 Standard_OStream& TDataXtd_Plane::Dump (Standard_OStream& anOS) const