0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / gp / gp_Ax1.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 // JCV 1/10/90 Changement de nom du package vgeom -> gp
16 // JCV 12/12/90 modif introduction des classes XYZ et Mat dans le package
17 // LPA, JCV  07/92 passage sur C1.
18 // JCV 07/92 Introduction de la method Dump 
19
20 #define No_Standard_OutOfRange
21
22 #include <gp_Ax1.hxx>
23
24 #include <gp_Ax2.hxx>
25 #include <gp_Dir.hxx>
26 #include <gp_Pnt.hxx>
27 #include <gp_Vec.hxx>
28 #include <Standard_Dump.hxx>
29
30 Standard_Boolean gp_Ax1::IsCoaxial
31 (const gp_Ax1& Other, 
32  const Standard_Real AngularTolerance,
33  const Standard_Real LinearTolerance) const
34 {
35   gp_XYZ XYZ1 = loc.XYZ();
36   XYZ1.Subtract (Other.loc.XYZ());
37   XYZ1.Cross (Other.vdir.XYZ());
38   Standard_Real D1 = XYZ1.Modulus();
39   gp_XYZ XYZ2 = Other.loc.XYZ();
40   XYZ2.Subtract (loc.XYZ());
41   XYZ2.Cross (vdir.XYZ());
42   Standard_Real D2 = XYZ2.Modulus();
43   return (vdir.IsEqual (Other.vdir, AngularTolerance) &&
44           D1 <= LinearTolerance && D2 <= LinearTolerance);
45 }
46
47 void gp_Ax1::Mirror (const gp_Pnt& P)
48 {
49   loc.Mirror(P);
50   vdir.Reverse();
51 }
52
53 gp_Ax1 gp_Ax1::Mirrored (const gp_Pnt& P) const
54 {
55   gp_Ax1 A1 = *this;    
56   A1.Mirror (P);
57   return A1;
58 }
59
60 void gp_Ax1::Mirror (const gp_Ax1& A1)
61 {
62   loc.Mirror(A1);
63   vdir.Mirror(A1.vdir);
64 }
65
66 gp_Ax1 gp_Ax1::Mirrored (const gp_Ax1& A1) const
67 {
68   gp_Ax1 A = *this;
69   A.Mirror (A1);
70   return A;
71 }
72
73 void gp_Ax1::Mirror (const gp_Ax2& A2)
74 {
75   loc.Mirror  (A2);
76   vdir.Mirror (A2);
77 }
78
79 gp_Ax1 gp_Ax1::Mirrored (const gp_Ax2& A2) const
80 {
81   gp_Ax1 A1 = *this;
82   A1.Mirror (A2);
83   return A1;
84 }
85
86 void gp_Ax1::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
87 {
88   OCCT_DUMP_VECTOR_CLASS (theOStream, "Location", 3, loc.X(), loc.Y(), loc.Z())
89   OCCT_DUMP_VECTOR_CLASS (theOStream, "Direction", 3, vdir.X(), vdir.Y(), vdir.Z())
90 }
91
92 Standard_Boolean gp_Ax1::InitFromJson (const Standard_SStream& theSStream, Standard_Integer& theStreamPos)
93 {
94   Standard_Integer aPos = theStreamPos;
95   TCollection_AsciiString aStreamStr = Standard_Dump::Text (theSStream);
96
97   gp_XYZ& anXYZLoc = loc.ChangeCoord();
98   OCCT_INIT_VECTOR_CLASS (aStreamStr, "Location", aPos, 3,
99                           &anXYZLoc.ChangeCoord (1), &anXYZLoc.ChangeCoord (2), &anXYZLoc.ChangeCoord (3))
100   gp_XYZ aDir;
101   OCCT_INIT_VECTOR_CLASS (aStreamStr, "Direction", aPos, 3,
102                           &aDir.ChangeCoord (1), &aDir.ChangeCoord (2), &aDir.ChangeCoord (3))
103   SetDirection (aDir);
104
105   theStreamPos = aPos;
106   return Standard_True;
107 }