1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_TranslateDriver.hxx>
24 #include <GEOMImpl_ITranslate.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
27 #include <gp_Trsf.hxx>
30 #include <BRepBuilderAPI_Transform.hxx>
31 #include <BRep_Builder.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Compound.hxx>
38 #include <TopoDS_Vertex.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <BRep_Tool.hxx>
42 //=======================================================================
45 //=======================================================================
46 const Standard_GUID& GEOMImpl_TranslateDriver::GetID()
48 static Standard_GUID aTranslateDriver("FF1BBB03-5D14-4df2-980B-3A668264EA16");
49 return aTranslateDriver;
53 //=======================================================================
54 //function : GEOMImpl_TranslateDriver
56 //=======================================================================
58 GEOMImpl_TranslateDriver::GEOMImpl_TranslateDriver()
62 //=======================================================================
65 //=======================================================================
66 Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const
68 if (Label().IsNull()) return 0;
69 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
71 if (aFunction.IsNull()) return 0;
73 GEOMImpl_ITranslate TI(aFunction);
76 Standard_Integer aType = aFunction->GetType();
78 Handle(GEOM_Function) anOriginalFunction = TI.GetOriginal();
79 if (anOriginalFunction.IsNull()) return 0;
80 TopoDS_Shape aShape, anOriginal = anOriginalFunction->GetValue();
81 if (anOriginal.IsNull()) return 0;
83 if (aType == TRANSLATE_TWO_POINTS || aType == TRANSLATE_TWO_POINTS_COPY) {
84 Handle(GEOM_Function) aPoint1 = TI.GetPoint1();
85 Handle(GEOM_Function) aPoint2 = TI.GetPoint2();
86 if(aPoint1.IsNull() || aPoint2.IsNull()) return 0;
87 TopoDS_Shape aV1 = aPoint1->GetValue();
88 TopoDS_Shape aV2 = aPoint2->GetValue();
89 if(aV1.IsNull() || aV1.ShapeType() != TopAbs_VERTEX) return 0;
90 if(aV2.IsNull() || aV2.ShapeType() != TopAbs_VERTEX) return 0;
92 aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aV1));
93 aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aV2));
95 aTrsf.SetTranslation(aP1, aP2);
96 //NPAL18620: performance problem: multiple locations are accumulated
97 // in shape and need a great time to process
98 //BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
99 //aShape = aTransformation.Shape();
100 TopLoc_Location aLocOrig = anOriginal.Location();
101 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
102 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
103 aShape = anOriginal.Located(aLocRes);
105 else if (aType == TRANSLATE_VECTOR || aType == TRANSLATE_VECTOR_COPY) {
106 Handle(GEOM_Function) aVector = TI.GetVector();
107 if(aVector.IsNull()) return 0;
108 TopoDS_Shape aV = aVector->GetValue();
109 if(aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) return 0;
110 TopoDS_Edge anEdge = TopoDS::Edge(aV);
112 aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
113 aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
115 aTrsf.SetTranslation(aP1, aP2);
116 //NPAL18620: performance problem: multiple locations are accumulated
117 // in shape and need a great time to process
118 //BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
119 //aShape = aTransformation.Shape();
120 TopLoc_Location aLocOrig = anOriginal.Location();
121 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
122 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
123 aShape = anOriginal.Located(aLocRes);
125 else if (aType == TRANSLATE_XYZ || aType == TRANSLATE_XYZ_COPY) {
126 gp_Vec aVec (TI.GetDX(), TI.GetDY(), TI.GetDZ());
127 aTrsf.SetTranslation(aVec);
128 //NPAL18620: performance problem: multiple locations are accumulated
129 // in shape and need a great time to process
130 //BRepBuilderAPI_Transform aTransformation (anOriginal, aTrsf, Standard_False);
131 //aShape = aTransformation.Shape();
132 TopLoc_Location aLocOrig = anOriginal.Location();
133 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
134 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
135 aShape = anOriginal.Located(aLocRes);
137 else if (aType == TRANSLATE_1D) {
138 Standard_Real DX, DY, DZ, step = TI.GetStep1();
139 Standard_Integer nbtimes = TI.GetNbIter1();
141 TopoDS_Compound aCompound;
143 B.MakeCompound( aCompound );
145 Handle(GEOM_Function) aVector = TI.GetVector();
146 if(aVector.IsNull()) return 0;
147 TopoDS_Shape aV = aVector->GetValue();
148 if(aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) return 0;
149 TopoDS_Edge anEdge = TopoDS::Edge(aV);
151 gp_Vec Vec(BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)), BRep_Tool::Pnt(TopExp::LastVertex(anEdge)));
154 TopLoc_Location aLocOrig = anOriginal.Location();
155 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
157 for (int i = 0; i < nbtimes; i++) {
158 DX = i * step * Vec.X();
159 DY = i * step * Vec.Y();
160 DZ = i * step * Vec.Z();
161 aVec.SetCoord( DX, DY, DZ );
162 aTrsf.SetTranslation(aVec);
163 //NPAL18620: performance problem: multiple locations are accumulated
164 // in shape and need a great time to process
165 //BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
166 //B.Add(aCompound, aTransformation.Shape());
167 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
168 B.Add(aCompound, anOriginal.Located(aLocRes));
172 else if (aType == TRANSLATE_2D) {
173 Standard_Integer nbtimes1 = TI.GetNbIter1(), nbtimes2 = TI.GetNbIter2();
174 Standard_Real DX, DY, DZ, step1 = TI.GetStep1(), step2 = TI.GetStep2();
176 Handle(GEOM_Function) aVector = TI.GetVector();
177 if(aVector.IsNull()) return 0;
178 TopoDS_Shape aV = aVector->GetValue();
179 if(aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) return 0;
180 TopoDS_Edge anEdge = TopoDS::Edge(aV);
182 gp_Vec Vec1(BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)), BRep_Tool::Pnt(TopExp::LastVertex(anEdge)));
185 Handle(GEOM_Function) aVector2 = TI.GetVector2();
186 if(aVector2.IsNull()) return 0;
187 aV = aVector2->GetValue();
188 if(aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) return 0;
189 anEdge = TopoDS::Edge(aV);
191 gp_Vec Vec2(BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)), BRep_Tool::Pnt(TopExp::LastVertex(anEdge)));
194 TopoDS_Compound aCompound;
196 B.MakeCompound( aCompound );
198 TopLoc_Location aLocOrig = anOriginal.Location();
199 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
201 for (int i = 0; i < nbtimes1; i++) {
202 for (int j = 0; j < nbtimes2; j++) {
203 DX = i * step1 * Vec1.X() + j * step2 * Vec2.X();
204 DY = i * step1 * Vec1.Y() + j * step2 * Vec2.Y();
205 DZ = i * step1 * Vec1.Z() + j * step2 * Vec2.Z();
206 aVec.SetCoord( DX, DY, DZ );
207 aTrsf.SetTranslation(aVec);
208 //NPAL18620: performance problem: multiple locations are accumulated
209 // in shape and need a great time to process
210 //BRepBuilderAPI_Transform aBRepTransformation(anOriginal, aTrsf, Standard_False);
211 //B.Add(aCompound, aBRepTransformation.Shape());
212 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
213 B.Add(aCompound, anOriginal.Located(aLocRes));
221 if (aShape.IsNull()) return 0;
223 aFunction->SetValue(aShape);
225 log.SetTouched(Label());
231 //=======================================================================
232 //function : GEOMImpl_TranslateDriver_Type_
234 //=======================================================================
235 Standard_EXPORT Handle_Standard_Type& GEOMImpl_TranslateDriver_Type_()
238 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
239 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
240 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
241 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
242 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
243 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
245 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
246 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_TranslateDriver",
247 sizeof(GEOMImpl_TranslateDriver),
249 (Standard_Address)_Ancestors,
250 (Standard_Address)NULL);
255 //=======================================================================
256 //function : DownCast
258 //=======================================================================
259 const Handle(GEOMImpl_TranslateDriver) Handle(GEOMImpl_TranslateDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
261 Handle(GEOMImpl_TranslateDriver) _anOtherObject;
263 if (!AnObject.IsNull()) {
264 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_TranslateDriver))) {
265 _anOtherObject = Handle(GEOMImpl_TranslateDriver)((Handle(GEOMImpl_TranslateDriver)&)AnObject);
269 return _anOtherObject;