0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / Geom / Geom_Axis2Placement.cxx
1 // Created on: 1993-03-09
2 // Created by: JCV
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Geom_Axis2Placement.hxx>
19 #include <Geom_Geometry.hxx>
20 #include <gp_Ax2.hxx>
21 #include <gp_Dir.hxx>
22 #include <gp_Pnt.hxx>
23 #include <gp_Trsf.hxx>
24 #include <Standard_ConstructionError.hxx>
25 #include <Standard_Type.hxx>
26
27 IMPLEMENT_STANDARD_RTTIEXT(Geom_Axis2Placement,Geom_AxisPlacement)
28
29 typedef Geom_Axis2Placement Axis2Placement;
30 typedef gp_Ax1  Ax1;
31 typedef gp_Dir  Dir;
32 typedef gp_Pnt  Pnt;
33 typedef gp_Trsf Trsf;
34 typedef gp_Vec  Vec;
35
36
37 //=======================================================================
38 //function : Copy
39 //purpose  : 
40 //=======================================================================
41
42 Handle(Geom_Geometry) Geom_Axis2Placement::Copy() const {
43
44   Handle(Geom_Axis2Placement) A2;
45   A2 = new Axis2Placement (axis.Location(), axis.Direction(), vxdir, vydir);
46   return A2;
47 }
48
49
50 //=======================================================================
51 //function : Geom_Axis2Placement
52 //purpose  : 
53 //=======================================================================
54
55 Geom_Axis2Placement::Geom_Axis2Placement (const gp_Ax2& A2) {
56
57    vxdir = A2. XDirection();
58    vydir = A2. YDirection();
59    axis  = A2.Axis();
60 }
61
62
63 //=======================================================================
64 //function : Geom_Axis2Placement
65 //purpose  : 
66 //=======================================================================
67
68 Geom_Axis2Placement::Geom_Axis2Placement (
69
70 const gp_Pnt& P,
71 const gp_Dir& N,
72 const gp_Dir& Vx) {
73
74   axis = gp_Ax1 (P, N);
75   vxdir = N.CrossCrossed (Vx, N);
76   vydir = N.Crossed (vxdir);
77 }
78
79
80 //=======================================================================
81 //function : Geom_Axis2Placement
82 //purpose  : 
83 //=======================================================================
84
85 Geom_Axis2Placement::Geom_Axis2Placement (
86
87 const gp_Pnt& P,
88 const gp_Dir& Vz,
89 const gp_Dir& Vx,
90 const gp_Dir& Vy
91
92 ) : vxdir (Vx), vydir (Vy) {
93
94   axis.SetLocation (P);
95   axis.SetDirection (Vz);
96 }
97
98
99 //=======================================================================
100 //function : XDirection
101 //purpose  : 
102 //=======================================================================
103
104 const gp_Dir& Geom_Axis2Placement::XDirection () const { return vxdir; }
105
106
107 //=======================================================================
108 //function : YDirection
109 //purpose  : 
110 //=======================================================================
111
112 const gp_Dir& Geom_Axis2Placement::YDirection () const {  return vydir; }
113
114
115 //=======================================================================
116 //function : SetAx2
117 //purpose  : 
118 //=======================================================================
119
120 void Geom_Axis2Placement::SetAx2 (const gp_Ax2& A2) {
121
122    vxdir = A2.XDirection();
123    vydir = A2.YDirection();
124    axis  = A2.Axis();
125 }
126
127
128 //=======================================================================
129 //function : SetDirection
130 //purpose  : 
131 //=======================================================================
132
133 void Geom_Axis2Placement::SetDirection (const gp_Dir& V) {
134
135    axis.SetDirection (V);
136    vxdir = V.CrossCrossed (vxdir, V);
137    vydir = V.Crossed (vxdir);
138 }
139
140
141 //=======================================================================
142 //function : SetXDirection
143 //purpose  : 
144 //=======================================================================
145
146 void Geom_Axis2Placement::SetXDirection (const gp_Dir& Vx) { 
147
148   vxdir = axis.Direction().CrossCrossed (Vx, axis.Direction());
149   vydir = axis.Direction().Crossed      (vxdir);
150 }
151
152
153
154 //=======================================================================
155 //function : SetYDirection
156 //purpose  : 
157 //=======================================================================
158
159 void Geom_Axis2Placement::SetYDirection (const gp_Dir& Vy) {
160
161   vxdir = Vy.Crossed (axis.Direction());
162   vydir = (axis.Direction()).Crossed (vxdir);
163 }
164
165
166 //=======================================================================
167 //function : Ax2
168 //purpose  : 
169 //=======================================================================
170
171 gp_Ax2 Geom_Axis2Placement::Ax2 () const {
172
173   return gp_Ax2 (axis.Location(), axis.Direction(), vxdir);
174 }
175
176
177 //=======================================================================
178 //function : Transform
179 //purpose  : 
180 //=======================================================================
181
182 void Geom_Axis2Placement::Transform (const gp_Trsf& T) {
183
184   //axis.Location().Transform (T);
185   axis.SetLocation(axis.Location().Transformed(T)); // 10-03-93
186   vxdir.Transform (T);
187   vydir.Transform (T);
188   axis.SetDirection (vxdir.Crossed (vydir));
189 }
190
191
192