0031501: Foundation Classes, Message_Printer - remove theToPutEndl argument -- prepar...
[occt.git] / src / IGESGeom / IGESGeom_Plane.cxx
CommitLineData
b311480e 1// Created by: CKY / Contract Toubro-Larsen
2// Copyright (c) 1993-1999 Matra Datavision
973c2be1 3// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
7fd59977 6//
d5f74e42 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
973c2be1 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.
7fd59977 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
16//--------------------------------------------------------------------
7fd59977 17//--------------------------------------------------------------------
18
7fd59977 19#include <gp_GTrsf.hxx>
42cf5bc1 20#include <gp_Pnt.hxx>
21#include <gp_XYZ.hxx>
22#include <IGESData_IGESEntity.hxx>
23#include <IGESGeom_Plane.hxx>
24#include <Standard_Type.hxx>
7fd59977 25
92efcf78 26IMPLEMENT_STANDARD_RTTIEXT(IGESGeom_Plane,IGESData_IGESEntity)
27
b311480e 28IGESGeom_Plane::IGESGeom_Plane () { }
7fd59977 29
30
31 void IGESGeom_Plane::Init
32 (const Standard_Real A, const Standard_Real B,
33 const Standard_Real C, const Standard_Real D,
34 const Handle(IGESData_IGESEntity)& aCurve,
35 const gp_XYZ& attach, const Standard_Real aSize)
36{
37 theA = A;
38 theB = B;
39 theC = C;
40 theD = D;
41 theCurve = aCurve;
42 theAttach = attach;
43 theSize = aSize;
44 InitTypeAndForm(108,FormNumber());
45// FormNumber : 0 No Curve. +1 Bound. -1 Hole
46}
47
48 void IGESGeom_Plane::SetFormNumber (const Standard_Integer form)
49{
50 Standard_Integer fn = 0;
51 if (form < 0) fn = -1;
52 if (form > 0) fn = 1;
53 InitTypeAndForm(108,fn);
54}
55
56 void IGESGeom_Plane::Equation
57 (Standard_Real& A, Standard_Real& B, Standard_Real& C, Standard_Real& D) const
58{
59 A = theA;
60 B = theB;
61 C = theC;
62 D = theD;
63}
64
65 Standard_Boolean IGESGeom_Plane::HasBoundingCurve () const
66{
67 return (!theCurve.IsNull());
68}
69
70 Standard_Boolean IGESGeom_Plane::HasBoundingCurveHole () const
71{
72 return ((FormNumber() == -1) && (!theCurve.IsNull()));
73}
74
75 Handle(IGESData_IGESEntity) IGESGeom_Plane::BoundingCurve () const
76{
77 return theCurve;
78}
79
80 Standard_Boolean IGESGeom_Plane::HasSymbolAttach () const
81{
82 return (theSize > 0);
83}
84
85 gp_Pnt IGESGeom_Plane::SymbolAttach () const
86{
87 gp_Pnt attach(theAttach);
88 return attach;
89}
90
91 gp_Pnt IGESGeom_Plane::TransformedSymbolAttach () const
92{
93 if (theSize > 0 && HasTransf())
94 {
95 gp_XYZ Symbol = theAttach;
96 Location().Transforms(Symbol);
97 return gp_Pnt(Symbol);
98 }
99 else return gp_Pnt(0, 0, 0);
100}
101
102 Standard_Real IGESGeom_Plane::SymbolSize () const
103{
104 return theSize;
105}
106
107 void IGESGeom_Plane::TransformedEquation
108 (Standard_Real& A, Standard_Real& B, Standard_Real& C, Standard_Real& D) const
109{
110 //eqn of plane AX + BY + CZ = D
111
112 Standard_Real x1,y1,z1,x2,y2,z2,x3,y3,z3;
113
114 //case 1 intersection of the plane with the XY plane.
115 x1 = 0.0;
116 y1 = 0.0;
117 z1 = theD / theC;
118
119 //case 2 intersection of the plane with the XZ plane.
120 x2 = 0.0;
121 y2 = theD / theB;
122 z2 = 0.0;
123
124 //case 3 intersection of the plane with the YZ plane.
125 x3 = theD / theA;
126 y3 = 0.0;
127 z3 = 0.0;
128 gp_XYZ P1(x1,y1,z1);
129 gp_XYZ P2(x2,y2,z2);
130 gp_XYZ P3(x3,y3,z3);
131 Location().Transforms(P1);
132 Location().Transforms(P2);
133 Location().Transforms(P3);
134 x1 = P1.X();
135 y1 = P1.Y();
136 z1 = P1.Z();
137 x2 = P2.X();
138 y2 = P2.Y();
139 z2 = P2.Z();
140 x3 = P3.X();
141 y3 = P3.Y();
142 z3 = P3.Z();
143
144/*
145 General eqn of plane can also be written as
146 a(x1 -x2) + b(y1 - y2) + c(z1 - z2) = 0
147 a(x3 - x2) + b(y3 - y2) + c(z3 -z2) = 0
148 Applying Cramer's Rule :
149 a b c
150 ------------- = --------------- = --------------- = k
151 |y3-y2 z3-z2| |z3-z2 x3-x2| |x3-x2 y3-y2|
152 |y1-y2 z1-z2| |z1-z2 x1-x2| |x1-x2 y1-y2|
153
154 .
155 . . a = c1*k , b = c2*k , c = c3*k
156 hence c1(x - x2) + c2(y - y2) + c3(z - z2) = 0
157
158*/
159 Standard_Real c1,c2,c3;
160
161 c1 = (y1*(-z3 + z2) + y2*(-z1 + z3) + y3*(z1 - z2));
162 c2 = (x1*(z3 - z2) + x2*(-z3 + z1) + x3*(-z1 + z2));
163 c3 = (x1*(-y3 + y2) + x2*(-y1 + y3) + x3*(y1 - y2));
164
165 A = c1;
166 B = c2;
167 C = c3;
168 D = c1*x2 + c2*y2 + c3*z3;
169}