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
StepToTopoDS_MakeTransformed()45 StepToTopoDS_MakeTransformed::StepToTopoDS_MakeTransformed ()
46 {
47 }
48
49 //=======================================================================
50 //function : Compute
51 //purpose :
52 //=======================================================================
53
Compute(const Handle (StepGeom_Axis2Placement3d)& Origin,const Handle (StepGeom_Axis2Placement3d)& Target)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
Compute(const Handle (StepGeom_CartesianTransformationOperator3d)& Operator)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
Transformation() const93 const gp_Trsf& StepToTopoDS_MakeTransformed::Transformation () const
94 {
95 return theTrsf;
96 }
97
98 //=======================================================================
99 //function : Transform
100 //purpose :
101 //=======================================================================
102
Transform(TopoDS_Shape & shape) const103 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
TranslateMappedItem(const Handle (StepRepr_MappedItem)& mapit,const Handle (Transfer_TransientProcess)& TP,const Message_ProgressRange & theProgress)117 TopoDS_Shape StepToTopoDS_MakeTransformed::TranslateMappedItem
118 (const Handle(StepRepr_MappedItem)& mapit,
119 const Handle(Transfer_TransientProcess)& TP,
120 const Message_ProgressRange& theProgress)
121 {
122 TopoDS_Shape theResult;
123
124 // Positionnement : 2 formules
125 // 1/ Ax2 dans Source et comme Target : passage de Source a Target
126 // 2/ CartesianOperator3d comme Target : on applique
127
128 Handle(StepGeom_Axis2Placement3d) Origin =
129 Handle(StepGeom_Axis2Placement3d)::DownCast(mapit->MappingSource()
130 ->MappingOrigin());
131 Handle(StepGeom_Axis2Placement3d) Target =
132 Handle(StepGeom_Axis2Placement3d)::DownCast(mapit->MappingTarget());
133
134 Handle(StepGeom_CartesianTransformationOperator3d) CartOp =
135 Handle(StepGeom_CartesianTransformationOperator3d)::DownCast(mapit->MappingTarget());
136
137 Standard_Boolean ok = Standard_False;
138 if (!Origin.IsNull() && !Target.IsNull()) ok = Compute (Origin,Target);
139 else if (!CartOp.IsNull()) ok = Compute (CartOp);
140
141 if (!ok) TP->AddWarning (mapit,"Mapped Item, case not recognized, location ignored");
142
143 // La Shape, et la mise en position
144 Handle(StepRepr_Representation) maprep = mapit->MappingSource()->MappedRepresentation();
145 Handle(Transfer_Binder) binder = TP->Find(maprep);
146 if (binder.IsNull()) binder = TP->Transferring(maprep, theProgress);
147 Handle(TransferBRep_ShapeBinder) shbinder =
148 Handle(TransferBRep_ShapeBinder)::DownCast(binder);
149 if (shbinder.IsNull()) TP->AddWarning(mapit,"No Shape Produced");
150 else {
151 theResult = shbinder->Result();
152 Transform (theResult);
153 }
154
155 return theResult;
156 }
157