0026419: [Regression?] Export of a reversed face leads to crash in 6.9.0 although...
[occt.git] / src / GeomToIGES / GeomToIGES_GeomVector.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 // modif du 14/09/95 mjm
15 // prise en compte de l'unite choisi par l'utilisateur
16 // pour l'ecriture du fichier IGES.
17
18 #include <Geom_Direction.hxx>
19 #include <Geom_Vector.hxx>
20 #include <Geom_VectorWithMagnitude.hxx>
21 #include <GeomToIGES_GeomEntity.hxx>
22 #include <GeomToIGES_GeomVector.hxx>
23 #include <gp_Dir.hxx>
24 #include <gp_GTrsf.hxx>
25 #include <gp_Pnt.hxx>
26 #include <gp_Trsf.hxx>
27 #include <gp_XYZ.hxx>
28 #include <IGESData_IGESEntity.hxx>
29 #include <IGESData_ToolLocation.hxx>
30 #include <IGESGeom_CopiousData.hxx>
31 #include <IGESGeom_Direction.hxx>
32 #include <IGESGeom_Line.hxx>
33 #include <IGESGeom_Point.hxx>
34 #include <Interface_Macros.hxx>
35
36 //=============================================================================
37 // GeomToIGES_GeomVector
38 //=============================================================================
39 GeomToIGES_GeomVector::GeomToIGES_GeomVector()
40 :GeomToIGES_GeomEntity()
41 {
42 }
43
44
45 //=============================================================================
46 // GeomToIGES_GeomVector
47 //=============================================================================
48
49 GeomToIGES_GeomVector::GeomToIGES_GeomVector
50 (const GeomToIGES_GeomEntity& GE)
51 :GeomToIGES_GeomEntity(GE)
52 {
53 }
54
55
56 //=============================================================================
57 // Transfer des Entites Vector de Geom vers IGES
58 // TransferVector
59 //=============================================================================
60
61 Handle(IGESGeom_Direction) GeomToIGES_GeomVector::TransferVector
62 (const Handle(Geom_Vector)& start)
63 {
64   Handle(IGESGeom_Direction) res;
65   if (start.IsNull()) {
66     return res;
67   }
68
69   if (start->IsKind(STANDARD_TYPE(Geom_VectorWithMagnitude))) {
70     DeclareAndCast(Geom_VectorWithMagnitude, VMagn, start);
71     res = TransferVector(VMagn);
72   }
73   else if (start->IsKind(STANDARD_TYPE(Geom_Direction))) {
74     DeclareAndCast(Geom_Direction, Direction, start);
75     res = TransferVector(Direction);
76   }
77
78   return res;
79 }
80  
81
82 //=============================================================================
83 // Transfer des Entites VectorWithMagnitude de Geom vers IGES
84 // TransferVector
85 //=============================================================================
86
87 Handle(IGESGeom_Direction) GeomToIGES_GeomVector::TransferVector
88 (const Handle(Geom_VectorWithMagnitude)& start)
89 {
90   Handle(IGESGeom_Direction) Dir = new IGESGeom_Direction;
91   if (start.IsNull()) {
92     return Dir;
93   }
94
95   Standard_Real X,Y,Z;
96   start->Coord(X,Y,Z); 
97   Standard_Real M = start->Magnitude();
98   Dir->Init(gp_XYZ(X/(M*GetUnit()),Y/(M*GetUnit()),Z/(M*GetUnit())));
99   return Dir;
100 }
101  
102
103 //=============================================================================
104 // Transfer des Entites Direction de Geom vers IGES
105 // TransferVector
106 //=============================================================================
107
108 Handle(IGESGeom_Direction) GeomToIGES_GeomVector::TransferVector
109 (const Handle(Geom_Direction)& start)
110 {
111   Handle(IGESGeom_Direction) Dir = new IGESGeom_Direction;
112   if (start.IsNull()) {
113     return Dir;
114   }
115
116   Standard_Real X,Y,Z;
117   start->Coord(X,Y,Z);
118   Dir->Init(gp_XYZ(X/GetUnit(),Y/GetUnit(),Z/GetUnit()));
119   return Dir;
120 }