1 // Created on: 1992-09-02
2 // Created by: Remi GILET
3 // Copyright (c) 1992-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 <gce_MakePln.hxx>
19 #include <gp.hxx>
20 #include <gp_Ax1.hxx>
21 #include <gp_Ax2.hxx>
22 #include <gp_Ax3.hxx>
23 #include <gp_Dir.hxx>
24 #include <gp_Pln.hxx>
25 #include <gp_Pnt.hxx>
26 #include <StdFail_NotDone.hxx>
27
gce_MakePln(const gp_Ax2 & A2)28 gce_MakePln::gce_MakePln(const gp_Ax2& A2)
29 {
30 ThePln = gp_Pln(gp_Ax3(A2));
31 TheError = gce_Done;
32 }
33
gce_MakePln(const gp_Pnt & P,const gp_Dir & V)34 gce_MakePln::gce_MakePln(const gp_Pnt& P,
35 const gp_Dir& V)
36 {
37 ThePln = gp_Pln(P,V);
38 TheError = gce_Done;
39 }
40
gce_MakePln(const gp_Pnt & P1,const gp_Pnt & P2)41 gce_MakePln::gce_MakePln(const gp_Pnt& P1,
42 const gp_Pnt& P2)
43 {
44 if (P1.Distance(P2) <= gp::Resolution()) { TheError = gce_ConfusedPoints; }
45 else {
46 gp_Dir dir(P2.XYZ()-P1.XYZ());
47 ThePln = gp_Pln(P1,dir);
48 TheError = gce_Done;
49 }
50 }
51
gce_MakePln(const Standard_Real A,const Standard_Real B,const Standard_Real C,const Standard_Real D)52 gce_MakePln::gce_MakePln(const Standard_Real A,
53 const Standard_Real B,
54 const Standard_Real C,
55 const Standard_Real D)
56 {
57 if (A*A + B*B + C*C <= gp::Resolution()) {
58 TheError = gce_BadEquation;
59 }
60 else {
61 ThePln = gp_Pln(A,B,C,D);
62 TheError = gce_Done;
63 }
64 }
65
66 //=========================================================================
67 // Creation d un gp_pln passant par trois points. +
68 //=========================================================================
69
gce_MakePln(const gp_Pnt & P1,const gp_Pnt & P2,const gp_Pnt & P3)70 gce_MakePln::gce_MakePln(const gp_Pnt& P1 ,
71 const gp_Pnt& P2 ,
72 const gp_Pnt& P3 )
73 {
74 gp_XYZ V1(P2.XYZ()-P1.XYZ());
75 gp_XYZ V2(P3.XYZ()-P1.XYZ());
76 gp_XYZ Norm(V1.Crossed(V2));
77 if (Norm.Modulus() < gp::Resolution()) { TheError = gce_ColinearPoints; }
78 else {
79 gp_Dir DNorm(Norm);
80 gp_Dir Dx(V1);
81 ThePln = gp_Pln(gp_Ax3(P1,DNorm,Dx));
82 TheError = gce_Done;
83 }
84 }
85
86 //=========================================================================
87 // Creation d un gp_pln parallele a un autre pln a une distance donnee. +
88 //=========================================================================
89
gce_MakePln(const gp_Pln & Pl,const Standard_Real Dist)90 gce_MakePln::gce_MakePln(const gp_Pln& Pl ,
91 const Standard_Real Dist )
92 {
93 gp_Pnt Center(Pl.Location().XYZ()+Dist*gp_XYZ(Pl.Axis().Direction().XYZ()));
94 ThePln=gp_Pln(gp_Ax3(Center,Pl.Axis().Direction(),Pl.XAxis().Direction()));
95 TheError = gce_Done;
96 }
97
98 //=========================================================================
99 // Creation d un gp_pln parallele a un autre pln passant par un point +
100 // <Point1>. +
101 //=========================================================================
102
gce_MakePln(const gp_Pln & Pl,const gp_Pnt & Point)103 gce_MakePln::gce_MakePln(const gp_Pln& Pl ,
104 const gp_Pnt& Point )
105 {
106 ThePln = gp_Pln(gp_Ax3(Point,Pl.Axis().Direction(),Pl.XAxis().Direction()));
107 TheError = gce_Done;
108 }
109
110 //=========================================================================
111 // Creation d un gp_pln a partir d un Ax1 (Point + Normale). +
112 //=========================================================================
113
gce_MakePln(const gp_Ax1 & Axis)114 gce_MakePln::gce_MakePln(const gp_Ax1& Axis )
115 {
116 ThePln = gp_Pln(Axis.Location(),Axis.Direction());
117 TheError = gce_Done;
118 }
119
120 //=========================================================================
121 // Creation d un gp_pln par un tableau de points. +
122 //=========================================================================
123
124 /*gce_MakePln::gce_MakePln(const gp_Array1OfPnt& Pts ,
125 Standard_Real ErrMax ,
126 Standard_Real ErrMean )
127 {
128 TheError = gce_ConfusedPoints;
129 }
130 */
Value() const131 const gp_Pln& gce_MakePln::Value () const
132 {
133 StdFail_NotDone_Raise_if (TheError != gce_Done,
134 "gce_MakePln::Value() - no result");
135 return ThePln;
136 }
137
Operator() const138 const gp_Pln& gce_MakePln::Operator() const
139 {
140 return Value();
141 }
142
operator gp_Pln() const143 gce_MakePln::operator gp_Pln() const
144 {
145 return Value();
146 }
147