0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / TDataXtd / TDataXtd_Plane.cxx
1 // Created on: 2009-04-06
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2009-2014 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
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>
22 #include <gp_Pln.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>
34 #include <TopAbs.hxx>
35 #include <TopoDS.hxx>
36 #include <TopoDS_Face.hxx>
37
38 IMPLEMENT_STANDARD_RTTIEXT(TDataXtd_Plane,TDF_Attribute)
39
40 //=======================================================================
41 //function : GetID
42 //purpose  : 
43 //=======================================================================
44 const Standard_GUID& TDataXtd_Plane::GetID () 
45 {
46   static Standard_GUID TDataXtd_PlaneID("2a96b60c-ec8b-11d0-bee7-080009dc3333");
47   return TDataXtd_PlaneID;
48 }
49
50  
51 //=======================================================================
52 //function : Set
53 //purpose  : 
54 //=======================================================================
55
56 Handle(TDataXtd_Plane) TDataXtd_Plane::Set (const TDF_Label& L)
57 {
58   Handle(TDataXtd_Plane) A;
59   if (!L.FindAttribute(TDataXtd_Plane::GetID(),A)) {
60     A = new TDataXtd_Plane (); 
61     L.AddAttribute(A);
62   }  
63   return A;
64 }
65
66
67
68 //=======================================================================
69 //function : Set
70 //purpose  : 
71 //=======================================================================
72
73 Handle(TDataXtd_Plane) TDataXtd_Plane::Set (const TDF_Label& L, const gp_Pln& P)
74
75   Handle(TDataXtd_Plane) A = Set (L);
76
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()
95               )
96              return A;
97          }
98        }
99   }
100
101   TNaming_Builder B(L);
102   B.Generated(BRepBuilderAPI_MakeFace(P));
103   return A;
104 }
105
106 //=======================================================================
107 //function : TDataXtd_Plane
108 //purpose  : 
109 //=======================================================================
110
111 TDataXtd_Plane::TDataXtd_Plane () { }
112
113
114 //=======================================================================
115 //function : ID
116 //purpose  : 
117 //=======================================================================
118
119 const Standard_GUID& TDataXtd_Plane::ID() const { return GetID(); }
120
121 //=======================================================================
122 //function : NewEmpty
123 //purpose  : 
124 //=======================================================================
125
126 Handle(TDF_Attribute) TDataXtd_Plane::NewEmpty () const
127 {  
128   return new TDataXtd_Plane(); 
129 }
130
131 //=======================================================================
132 //function : Restore
133 //purpose  : 
134 //=======================================================================
135
136 void TDataXtd_Plane::Restore(const Handle(TDF_Attribute)&)  {}
137
138 //=======================================================================
139 //function : Paste
140 //purpose  : 
141 //=======================================================================
142
143 void TDataXtd_Plane::Paste (const Handle(TDF_Attribute)&, const Handle(TDF_RelocationTable)&) const { }
144
145
146 //=======================================================================
147 //function : Dump
148 //purpose  : 
149 //=======================================================================
150
151 Standard_OStream& TDataXtd_Plane::Dump (Standard_OStream& anOS) const
152 {  
153   anOS << "Plane";
154   return anOS;
155 }