0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / StepToTopoDS / StepToTopoDS_MakeTransformed.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 //:n7 abv 16.02.99: treatment of CARTESIAN_TRSF_OP_3D placed to StepGeom_MkTransformed3d
15 // sln 23.10.2001. CTS23496: Verifying on error creation of directions is added (StepToTopoDS_MakeTransformed::Compute(...) function)
16
17 #include <Geom_Axis2Placement.hxx>
18 #include <Geom_CartesianPoint.hxx>
19 #include <Geom_Direction.hxx>
20 #include <gp_Ax3.hxx>
21 #include <gp_Trsf.hxx>
22 #include <gp_TrsfForm.hxx>
23 #include <StepGeom_Axis2Placement3d.hxx>
24 #include <StepGeom_CartesianPoint.hxx>
25 #include <StepGeom_CartesianTransformationOperator3d.hxx>
26 #include <StepGeom_Direction.hxx>
27 #include <StepRepr_ItemDefinedTransformation.hxx>
28 #include <StepRepr_MappedItem.hxx>
29 #include <StepRepr_Representation.hxx>
30 #include <StepRepr_RepresentationMap.hxx>
31 #include <StepToGeom.hxx>
32 #include <StepToTopoDS_MakeTransformed.hxx>
33 #include <TopLoc_Location.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <Transfer_Binder.hxx>
36 #include <Transfer_TransientProcess.hxx>
37 #include <TransferBRep_ShapeBinder.hxx>
38
39 //  + pour CartesianOperator3d
40 //=======================================================================
41 //function : StepToTopoDS_MakeTransformed
42 //purpose  : 
43 //=======================================================================
44
45 StepToTopoDS_MakeTransformed::StepToTopoDS_MakeTransformed ()
46 {
47 }
48
49 //=======================================================================
50 //function : Compute
51 //purpose  : 
52 //=======================================================================
53
54 Standard_Boolean  StepToTopoDS_MakeTransformed::Compute
55   (const Handle(StepGeom_Axis2Placement3d)& Origin,
56    const Handle(StepGeom_Axis2Placement3d)& Target)
57 {
58   theTrsf = gp_Trsf();  // reinit
59   if (Origin.IsNull() || Target.IsNull()) return Standard_False;
60
61   // sln 23.10.2001 : If the directions have not been created do nothing.  
62   Handle(Geom_Axis2Placement) theOrig = StepToGeom::MakeAxis2Placement (Origin);
63   if (theOrig.IsNull())
64     return Standard_False;
65   Handle(Geom_Axis2Placement) theTarg = StepToGeom::MakeAxis2Placement (Target);
66   if (theTarg.IsNull())
67     return Standard_False;
68
69   const gp_Ax3 ax3Orig(theOrig->Ax2());
70   const gp_Ax3 ax3Targ(theTarg->Ax2());
71
72   //  ne pas se tromper de sens !
73   theTrsf.SetTransformation(ax3Targ, ax3Orig);
74   return Standard_True;
75 }
76
77 //=======================================================================
78 //function : Compute
79 //purpose  : 
80 //=======================================================================
81
82 Standard_Boolean  StepToTopoDS_MakeTransformed::Compute
83   (const Handle(StepGeom_CartesianTransformationOperator3d)& Operator)
84 {
85   return StepToGeom::MakeTransformation3d (Operator, theTrsf);
86 }
87
88 //=======================================================================
89 //function : Transformation
90 //purpose  : 
91 //=======================================================================
92
93 const gp_Trsf&  StepToTopoDS_MakeTransformed::Transformation () const
94 {
95   return theTrsf;
96 }
97
98 //=======================================================================
99 //function : Transform
100 //purpose  : 
101 //=======================================================================
102
103 Standard_Boolean  StepToTopoDS_MakeTransformed::Transform
104   (TopoDS_Shape& shape) const
105 {
106   if (theTrsf.Form() == gp_Identity) return Standard_False;
107   TopLoc_Location theLoc(theTrsf);
108   shape.Move (theLoc);
109   return Standard_True;
110 }
111
112 //=======================================================================
113 //function : TranslateMappedItem
114 //purpose  : 
115 //=======================================================================
116
117 TopoDS_Shape  StepToTopoDS_MakeTransformed::TranslateMappedItem
118 (const Handle(StepRepr_MappedItem)& mapit,
119  const Handle(Transfer_TransientProcess)& TP)
120 {
121   TopoDS_Shape theResult;
122
123   //  Positionnement : 2 formules
124   //  1/ Ax2 dans Source et comme Target  : passage de Source a Target
125   //  2/ CartesianOperator3d comme Target : on applique
126
127   Handle(StepGeom_Axis2Placement3d) Origin = 
128     Handle(StepGeom_Axis2Placement3d)::DownCast(mapit->MappingSource()
129                                            ->MappingOrigin());
130   Handle(StepGeom_Axis2Placement3d) Target = 
131     Handle(StepGeom_Axis2Placement3d)::DownCast(mapit->MappingTarget());
132
133   Handle(StepGeom_CartesianTransformationOperator3d) CartOp =
134     Handle(StepGeom_CartesianTransformationOperator3d)::DownCast(mapit->MappingTarget());
135
136   Standard_Boolean ok = Standard_False;
137   if (!Origin.IsNull() && !Target.IsNull()) ok = Compute (Origin,Target);
138   else if (!CartOp.IsNull()) ok = Compute (CartOp);
139
140   if (!ok) TP->AddWarning (mapit,"Mapped Item, case not recognized, location ignored");
141
142   //  La Shape, et la mise en position
143   Handle(StepRepr_Representation) maprep = mapit->MappingSource()->MappedRepresentation();
144   Handle(Transfer_Binder) binder = TP->Find(maprep);
145   if (binder.IsNull())    binder = TP->Transferring(maprep);
146   Handle(TransferBRep_ShapeBinder) shbinder =
147     Handle(TransferBRep_ShapeBinder)::DownCast(binder);
148   if (shbinder.IsNull())  TP->AddWarning(mapit,"No Shape Produced");
149   else {
150     theResult = shbinder->Result();
151     Transform (theResult);
152   }
153
154   return theResult;
155 }