1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
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)
17 #include <Geom_Axis2Placement.hxx>
18 #include <Geom_CartesianPoint.hxx>
19 #include <Geom_Direction.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>
39 // + pour CartesianOperator3d
40 //=======================================================================
41 //function : StepToTopoDS_MakeTransformed
43 //=======================================================================
45 StepToTopoDS_MakeTransformed::StepToTopoDS_MakeTransformed ()
49 //=======================================================================
52 //=======================================================================
54 Standard_Boolean StepToTopoDS_MakeTransformed::Compute
55 (const Handle(StepGeom_Axis2Placement3d)& Origin,
56 const Handle(StepGeom_Axis2Placement3d)& Target)
58 theTrsf = gp_Trsf(); // reinit
59 if (Origin.IsNull() || Target.IsNull()) return Standard_False;
61 // sln 23.10.2001 : If the directions have not been created do nothing.
62 Handle(Geom_Axis2Placement) theOrig = StepToGeom::MakeAxis2Placement (Origin);
64 return Standard_False;
65 Handle(Geom_Axis2Placement) theTarg = StepToGeom::MakeAxis2Placement (Target);
67 return Standard_False;
69 const gp_Ax3 ax3Orig(theOrig->Ax2());
70 const gp_Ax3 ax3Targ(theTarg->Ax2());
72 // ne pas se tromper de sens !
73 theTrsf.SetTransformation(ax3Targ, ax3Orig);
77 //=======================================================================
80 //=======================================================================
82 Standard_Boolean StepToTopoDS_MakeTransformed::Compute
83 (const Handle(StepGeom_CartesianTransformationOperator3d)& Operator)
85 return StepToGeom::MakeTransformation3d (Operator, theTrsf);
88 //=======================================================================
89 //function : Transformation
91 //=======================================================================
93 const gp_Trsf& StepToTopoDS_MakeTransformed::Transformation () const
98 //=======================================================================
99 //function : Transform
101 //=======================================================================
103 Standard_Boolean StepToTopoDS_MakeTransformed::Transform
104 (TopoDS_Shape& shape) const
106 if (theTrsf.Form() == gp_Identity) return Standard_False;
107 TopLoc_Location theLoc(theTrsf);
109 return Standard_True;
112 //=======================================================================
113 //function : TranslateMappedItem
115 //=======================================================================
117 TopoDS_Shape StepToTopoDS_MakeTransformed::TranslateMappedItem
118 (const Handle(StepRepr_MappedItem)& mapit,
119 const Handle(Transfer_TransientProcess)& TP)
121 TopoDS_Shape theResult;
123 // Positionnement : 2 formules
124 // 1/ Ax2 dans Source et comme Target : passage de Source a Target
125 // 2/ CartesianOperator3d comme Target : on applique
127 Handle(StepGeom_Axis2Placement3d) Origin =
128 Handle(StepGeom_Axis2Placement3d)::DownCast(mapit->MappingSource()
130 Handle(StepGeom_Axis2Placement3d) Target =
131 Handle(StepGeom_Axis2Placement3d)::DownCast(mapit->MappingTarget());
133 Handle(StepGeom_CartesianTransformationOperator3d) CartOp =
134 Handle(StepGeom_CartesianTransformationOperator3d)::DownCast(mapit->MappingTarget());
136 Standard_Boolean ok = Standard_False;
137 if (!Origin.IsNull() && !Target.IsNull()) ok = Compute (Origin,Target);
138 else if (!CartOp.IsNull()) ok = Compute (CartOp);
140 if (!ok) TP->AddWarning (mapit,"Mapped Item, case not recognized, location ignored");
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");
150 theResult = shbinder->Result();
151 Transform (theResult);