1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <GEOMImpl_TranslateDriver.hxx>
24 #include <GEOMImpl_ITranslate.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
27 #include <GEOMUtils.hxx>
29 #include <BRep_Tool.hxx>
30 #include <BRep_Builder.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Compound.hxx>
39 #include <gp_Trsf.hxx>
43 //=======================================================================
46 //=======================================================================
47 const Standard_GUID& GEOMImpl_TranslateDriver::GetID()
49 static Standard_GUID aTranslateDriver("FF1BBB03-5D14-4df2-980B-3A668264EA16");
50 return aTranslateDriver;
54 //=======================================================================
55 //function : GEOMImpl_TranslateDriver
57 //=======================================================================
59 GEOMImpl_TranslateDriver::GEOMImpl_TranslateDriver()
63 //=======================================================================
66 //=======================================================================
67 Standard_Integer GEOMImpl_TranslateDriver::Execute(LOGBOOK& log) const
69 if (Label().IsNull()) return 0;
70 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
72 if (aFunction.IsNull()) return 0;
74 GEOMImpl_ITranslate TI (aFunction);
77 Standard_Integer aType = aFunction->GetType();
79 Handle(GEOM_Function) anOriginalFunction = TI.GetOriginal();
80 if (anOriginalFunction.IsNull()) return 0;
81 TopoDS_Shape aShape, anOriginal = anOriginalFunction->GetValue();
82 if (anOriginal.IsNull()) return 0;
84 if (aType == TRANSLATE_TWO_POINTS || aType == TRANSLATE_TWO_POINTS_COPY) {
85 Handle(GEOM_Function) aPoint1 = TI.GetPoint1();
86 Handle(GEOM_Function) aPoint2 = TI.GetPoint2();
87 if(aPoint1.IsNull() || aPoint2.IsNull()) return 0;
88 TopoDS_Shape aV1 = aPoint1->GetValue();
89 TopoDS_Shape aV2 = aPoint2->GetValue();
90 if(aV1.IsNull() || aV1.ShapeType() != TopAbs_VERTEX) return 0;
91 if(aV2.IsNull() || aV2.ShapeType() != TopAbs_VERTEX) return 0;
93 aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aV1));
94 aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aV2));
96 aTrsf.SetTranslation(aP1, aP2);
97 //NPAL18620: performance problem: multiple locations are accumulated
98 // in shape and need a great time to process
99 //BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
100 //aShape = aTransformation.Shape();
101 TopLoc_Location aLocOrig = anOriginal.Location();
102 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
103 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
104 aShape = anOriginal.Located(aLocRes);
106 else if (aType == TRANSLATE_VECTOR || aType == TRANSLATE_VECTOR_COPY) {
107 Handle(GEOM_Function) aVector = TI.GetVector();
108 if(aVector.IsNull()) return 0;
109 TopoDS_Shape aV = aVector->GetValue();
110 if(aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) return 0;
111 TopoDS_Edge anEdge = TopoDS::Edge(aV);
113 aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
114 aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
116 aTrsf.SetTranslation(aP1, aP2);
117 //NPAL18620: performance problem: multiple locations are accumulated
118 // in shape and need a great time to process
119 //BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
120 //aShape = aTransformation.Shape();
121 TopLoc_Location aLocOrig = anOriginal.Location();
122 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
123 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
124 aShape = anOriginal.Located(aLocRes);
126 else if (aType == TRANSLATE_VECTOR_DISTANCE) {
127 Handle(GEOM_Function) aVector = TI.GetVector();
128 double aDistance = TI.GetDistance();
129 if(aVector.IsNull()) return 0;
130 TopoDS_Shape aV = aVector->GetValue();
131 if(aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) return 0;
132 TopoDS_Edge anEdge = TopoDS::Edge(aV);
134 aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
135 aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
137 gp_Vec aVec (aP1, aP2);
139 aTrsf.SetTranslation(aVec * aDistance);
141 TopLoc_Location aLocOrig = anOriginal.Location();
142 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
143 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
144 aShape = anOriginal.Located(aLocRes);
146 else if (aType == TRANSLATE_XYZ || aType == TRANSLATE_XYZ_COPY) {
147 gp_Vec aVec (TI.GetDX(), TI.GetDY(), TI.GetDZ());
148 aTrsf.SetTranslation(aVec);
149 //NPAL18620: performance problem: multiple locations are accumulated
150 // in shape and need a great time to process
151 //BRepBuilderAPI_Transform aTransformation (anOriginal, aTrsf, Standard_False);
152 //aShape = aTransformation.Shape();
153 TopLoc_Location aLocOrig = anOriginal.Location();
154 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
155 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
156 aShape = anOriginal.Located(aLocRes);
158 else if (aType == TRANSLATE_1D) {
159 Standard_Real DX, DY, DZ, step = TI.GetStep1();
160 Standard_Integer nbtimes = TI.GetNbIter1();
162 TopoDS_Compound aCompound;
164 B.MakeCompound( aCompound );
166 Handle(GEOM_Function) aVector = TI.GetVector();
167 gp_Vec Vec = gp::DX();
168 if (!aVector.IsNull()) {
169 Vec = GEOMUtils::GetVector( aVector->GetValue(), Standard_False );
173 TopLoc_Location aLocOrig = anOriginal.Location();
174 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
176 for (int i = 0; i < nbtimes; i++) {
177 DX = i * step * Vec.X();
178 DY = i * step * Vec.Y();
179 DZ = i * step * Vec.Z();
180 aVec.SetCoord( DX, DY, DZ );
181 aTrsf.SetTranslation(aVec);
182 //NPAL18620: performance problem: multiple locations are accumulated
183 // in shape and need a great time to process
184 //BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
185 //B.Add(aCompound, aTransformation.Shape());
186 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
187 B.Add(aCompound, anOriginal.Located(aLocRes));
191 else if (aType == TRANSLATE_2D) {
192 Standard_Integer nbtimes1 = TI.GetNbIter1(), nbtimes2 = TI.GetNbIter2();
193 Standard_Real DX, DY, DZ, step1 = TI.GetStep1(), step2 = TI.GetStep2();
194 Handle(GEOM_Function) aVector = TI.GetVector();
195 Handle(GEOM_Function) aVector2 = TI.GetVector2();
197 gp_Vec Vec1 = gp::DX();
198 gp_Vec Vec2 = gp::DY();
200 if (!aVector.IsNull()) {
201 Vec1 = GEOMUtils::GetVector( aVector->GetValue(), Standard_False );
205 if (!aVector2.IsNull()) {
206 Vec2 = GEOMUtils::GetVector( aVector2->GetValue(), Standard_False );
210 TopoDS_Compound aCompound;
212 B.MakeCompound(aCompound);
214 TopLoc_Location aLocOrig = anOriginal.Location();
215 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
218 for (int i = 0; i < nbtimes1; i++) {
219 for (int j = 0; j < nbtimes2; j++) {
220 DX = i * step1 * Vec1.X() + j * step2 * Vec2.X();
221 DY = i * step1 * Vec1.Y() + j * step2 * Vec2.Y();
222 DZ = i * step1 * Vec1.Z() + j * step2 * Vec2.Z();
223 aVec.SetCoord( DX, DY, DZ );
224 aTrsf.SetTranslation(aVec);
225 //NPAL18620: performance problem: multiple locations are accumulated
226 // in shape and need a great time to process
227 //BRepBuilderAPI_Transform aBRepTransformation(anOriginal, aTrsf, Standard_False);
228 //B.Add(aCompound, aBRepTransformation.Shape());
229 TopLoc_Location aLocRes (aTrsf * aTrsfOrig);
230 B.Add(aCompound, anOriginal.Located(aLocRes));
237 if (aShape.IsNull()) return 0;
239 if ( !GEOMUtils::CheckShape(aShape, true) && !GEOMUtils::FixShapeTolerance(aShape) )
240 Standard_ConstructionError::Raise("Scaling aborted : algorithm has produced an invalid shape result");
242 aFunction->SetValue(aShape);
244 #if OCC_VERSION_MAJOR < 7
245 log.SetTouched(Label());
247 log->SetTouched(Label());
253 //================================================================================
255 * \brief Returns a name of creation operation and names and values of creation parameters
257 //================================================================================
259 bool GEOMImpl_TranslateDriver::
260 GetCreationInformation(std::string& theOperationName,
261 std::vector<GEOM_Param>& theParams)
263 if (Label().IsNull()) return 0;
264 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
266 GEOMImpl_ITranslate aCI( function );
267 Standard_Integer aType = function->GetType();
270 case TRANSLATE_TWO_POINTS:
271 case TRANSLATE_TWO_POINTS_COPY:
272 theOperationName = "TRANSLATION";
273 AddParam( theParams, "Object", aCI.GetOriginal() );
274 AddParam( theParams, "Point 1", aCI.GetPoint1() );
275 AddParam( theParams, "Point 2", aCI.GetPoint2() );
277 case TRANSLATE_VECTOR:
278 case TRANSLATE_VECTOR_COPY:
279 theOperationName = "TRANSLATION";
280 AddParam( theParams, "Object", aCI.GetOriginal() );
281 AddParam( theParams, "Vector", aCI.GetVector() );
283 case TRANSLATE_VECTOR_DISTANCE:
284 theOperationName = "TRANSLATION";
285 AddParam( theParams, "Object", aCI.GetOriginal() );
286 AddParam( theParams, "Vector", aCI.GetVector() );
287 AddParam( theParams, "Distance", aCI.GetDistance() );
290 case TRANSLATE_XYZ_COPY:
291 theOperationName = "TRANSLATION";
292 AddParam( theParams, "Object", aCI.GetOriginal() );
293 AddParam( theParams, "Dx", aCI.GetDX() );
294 AddParam( theParams, "Dy", aCI.GetDY() );
295 AddParam( theParams, "Dz", aCI.GetDZ() );
298 theOperationName = "MUL_TRANSLATION";
299 AddParam( theParams, "Main Object", aCI.GetOriginal() );
300 AddParam( theParams, "Vector", aCI.GetVector(), "DX" );
301 AddParam( theParams, "Step", aCI.GetStep1() );
302 AddParam( theParams, "Nb. Times", aCI.GetNbIter1() );
305 theOperationName = "MUL_TRANSLATION";
306 AddParam( theParams, "Main Object", aCI.GetOriginal() );
307 AddParam( theParams, "Vector U", aCI.GetVector(), "DX" );
308 AddParam( theParams, "Vector V", aCI.GetVector2(), "DY" );
309 AddParam( theParams, "Step U", aCI.GetStep1() );
310 AddParam( theParams, "Nb. Times U", aCI.GetNbIter1() );
311 AddParam( theParams, "Step V", aCI.GetStep2() );
312 AddParam( theParams, "Nb. Times V", aCI.GetNbIter2() );
321 OCCT_IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_TranslateDriver,GEOM_BaseDriver);