0024870: Provide OCCT RTTI test cases
[occt.git] / src / StepToGeom / StepToGeom_MakeTransformation3d.cxx
1 // Created on: 1999-02-16
2 // Created by: Andrey BETENEV
3 // Copyright (c) 1999-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 // sln 23.10.2001. CTS23496: If problems with creation of direction occur default direction is used (StepToGeom_MakeTransformation3d(...) function)
18
19 #include <Geom_CartesianPoint.hxx>
20 #include <Geom_Direction.hxx>
21 #include <gp_Ax3.hxx>
22 #include <gp_Trsf.hxx>
23 #include <StepGeom_CartesianPoint.hxx>
24 #include <StepGeom_CartesianTransformationOperator3d.hxx>
25 #include <StepGeom_Direction.hxx>
26 #include <StepToGeom_MakeCartesianPoint.hxx>
27 #include <StepToGeom_MakeDirection.hxx>
28 #include <StepToGeom_MakeTransformation3d.hxx>
29
30 //=======================================================================
31 //function : StepToGeom_MakeTransformation3d
32 //purpose  : 
33 //=======================================================================
34 Standard_Boolean StepToGeom_MakeTransformation3d::Convert (const Handle(StepGeom_CartesianTransformationOperator3d)& SCTO, gp_Trsf& CT)
35 {
36   Handle(Geom_CartesianPoint) CP;
37   if (StepToGeom_MakeCartesianPoint::Convert(SCTO->LocalOrigin(),CP))
38   {
39     const gp_Pnt Pgp = CP->Pnt();
40
41     // sln 23.10.2001. CTS23496: If problems with creation of direction occur default direction is used
42     gp_Dir D1(1.,0.,0.);
43     const Handle(StepGeom_Direction) A1 = SCTO->Axis1();
44     if (!A1.IsNull()) {
45       Handle(Geom_Direction) D;
46       if (StepToGeom_MakeDirection::Convert(A1,D))
47         D1 = D->Dir();
48     }
49
50     gp_Dir D2(0.,1.,0.);
51     const Handle(StepGeom_Direction) A2 = SCTO->Axis2();
52     if (!A2.IsNull()) {
53       Handle(Geom_Direction) D;
54       if (StepToGeom_MakeDirection::Convert(A2,D))
55         D2 = D->Dir();
56     }
57
58     Standard_Boolean isDefaultDirectionUsed = Standard_True;
59     gp_Dir D3;
60     const Handle(StepGeom_Direction) A3 = SCTO->Axis3();
61     if (!A3.IsNull()) {
62       Handle(Geom_Direction) D;
63           if(StepToGeom_MakeDirection::Convert(A3,D)) {
64         D3 = D->Dir();
65         isDefaultDirectionUsed = Standard_False;
66       }
67     }
68     if(isDefaultDirectionUsed) 
69       D3 = D1.Crossed(D2);
70
71     const gp_Ax3 result(Pgp,D3,D1);
72     CT.SetTransformation(result);
73     CT = CT.Inverted(); //:n8 abv 16 Feb 99: tr8_as2_db.stp: reverse for accordance with LV tool
74     return Standard_True;
75   }
76   return Standard_False;
77 }