3 #include "GEOMImpl_TranslateDriver.hxx"
4 #include <GEOMImpl_ITranslate.hxx>
5 #include <GEOMImpl_Types.hxx>
6 #include "GEOM_Function.hxx"
10 #include <BRepBuilderAPI_Transform.hxx>
11 #include <BRep_Builder.hxx>
13 #include <TopoDS_Shape.hxx>
14 #include <TopoDS_Edge.hxx>
15 #include <TopoDS_Compound.hxx>
18 #include <TopoDS_Vertex.hxx>
19 #include <TopoDS_Edge.hxx>
20 #include <BRep_Tool.hxx>
22 //=======================================================================
25 //=======================================================================
26 const Standard_GUID& GEOMImpl_TranslateDriver::GetID()
28 static Standard_GUID aTranslateDriver("FF1BBB03-5D14-4df2-980B-3A668264EA16");
29 return aTranslateDriver;
33 //=======================================================================
34 //function : GEOMImpl_TranslateDriver
36 //=======================================================================
38 GEOMImpl_TranslateDriver::GEOMImpl_TranslateDriver()
42 //=======================================================================
45 //=======================================================================
46 Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const
48 if(Label().IsNull()) return 0;
49 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
51 if(aFunction.IsNull()) return 0;
53 GEOMImpl_ITranslate TI(aFunction);
56 Standard_Integer aType = aFunction->GetType();
58 Handle(GEOM_Function) anOriginalFunction = TI.GetOriginal();
59 if(anOriginalFunction.IsNull()) return 0;
60 TopoDS_Shape aShape, anOriginal = anOriginalFunction->GetValue();
61 if(anOriginal.IsNull()) return 0;
63 if(aType == TRANSLATE_TWO_POINTS || aType == TRANSLATE_TWO_POINTS_COPY) {
64 Handle(GEOM_Function) aPoint1 = TI.GetPoint1();
65 Handle(GEOM_Function) aPoint2 = TI.GetPoint2();
66 if(aPoint1.IsNull() || aPoint2.IsNull()) return 0;
67 TopoDS_Shape aV1 = aPoint1->GetValue();
68 TopoDS_Shape aV2 = aPoint2->GetValue();
69 if(aV1.IsNull() || aV1.ShapeType() != TopAbs_VERTEX) return 0;
70 if(aV2.IsNull() || aV2.ShapeType() != TopAbs_VERTEX) return 0;
72 aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aV1));
73 aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aV2));
75 aTrsf.SetTranslation(aP1, aP2);
76 BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
77 aShape = aTransformation.Shape();
79 } else if(aType == TRANSLATE_VECTOR || aType == TRANSLATE_VECTOR_COPY) {
80 Handle(GEOM_Function) aVector = TI.GetVector();
81 if(aVector.IsNull()) return 0;
82 TopoDS_Shape aV = aVector->GetValue();
83 if(aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) return 0;
84 TopoDS_Edge anEdge = TopoDS::Edge(aV);
86 aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
87 aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
89 aTrsf.SetTranslation(aP1, aP2);
90 BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
91 aShape = aTransformation.Shape();
93 else if(aType == TRANSLATE_XYZ || aType == TRANSLATE_XYZ_COPY) {
94 gp_Vec aVec(TI.GetDX(), TI.GetDY(), TI.GetDZ());
95 aTrsf.SetTranslation(aVec);
96 BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
97 aShape = aTransformation.Shape();
99 else if(aType == TRANSLATE_1D) {
100 Standard_Real DX, DY, DZ, step = TI.GetStep1();
101 Standard_Integer nbtimes = TI.GetNbIter1();
103 TopoDS_Compound aCompound;
105 B.MakeCompound( aCompound );
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 gp_Vec Vec(BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)), BRep_Tool::Pnt(TopExp::LastVertex(anEdge)));
116 for (int i = 0; i < nbtimes; i++ ) {
117 DX = i * step * Vec.X() ;
118 DY = i * step * Vec.Y() ;
119 DZ = i * step * Vec.Z() ;
120 myVec.SetCoord( DX, DY, DZ ) ;
121 aTrsf.SetTranslation(myVec) ;
122 BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False) ;
123 B.Add(aCompound , aTransformation.Shape() );
127 else if(aType == TRANSLATE_2D) {
128 Standard_Integer nbtimes1 = TI.GetNbIter1(), nbtimes2 = TI.GetNbIter2();
129 Standard_Real DX, DY, DZ, step1 = TI.GetStep1(), step2 = TI.GetStep2();
131 Handle(GEOM_Function) aVector = TI.GetVector();
132 if(aVector.IsNull()) return 0;
133 TopoDS_Shape aV = aVector->GetValue();
134 if(aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) return 0;
135 TopoDS_Edge anEdge = TopoDS::Edge(aV);
137 gp_Vec Vec1(BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)), BRep_Tool::Pnt(TopExp::LastVertex(anEdge)));
140 Handle(GEOM_Function) aVector2 = TI.GetVector2();
141 if(aVector2.IsNull()) return 0;
142 aV = aVector2->GetValue();
143 if(aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) return 0;
144 anEdge = TopoDS::Edge(aV);
146 gp_Vec Vec2(BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)), BRep_Tool::Pnt(TopExp::LastVertex(anEdge)));
149 TopoDS_Compound aCompound;
151 B.MakeCompound( aCompound );
153 for (int i = 0; i < nbtimes1; i++ ) {
154 for (int j = 0; j < nbtimes2; j++ ) {
155 DX = i * step1 * Vec1.X() + j * step2 * Vec2.X() ;
156 DY = i * step1 * Vec1.Y() + j * step2 * Vec2.Y() ;
157 DZ = i * step1 * Vec1.Z() + j * step2 * Vec2.Z() ;
158 myVec.SetCoord( DX, DY, DZ ) ;
159 aTrsf.SetTranslation(myVec) ;
160 BRepBuilderAPI_Transform myBRepTransformation(anOriginal, aTrsf, Standard_False) ;
161 B.Add(aCompound , myBRepTransformation.Shape() );
170 if (aShape.IsNull()) return 0;
172 aFunction->SetValue(aShape);
174 log.SetTouched(Label());
180 //=======================================================================
181 //function : GEOMImpl_TranslateDriver_Type_
183 //=======================================================================
184 Standard_EXPORT Handle_Standard_Type& GEOMImpl_TranslateDriver_Type_()
187 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
188 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
189 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
190 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
191 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
192 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
195 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
196 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_TranslateDriver",
197 sizeof(GEOMImpl_TranslateDriver),
199 (Standard_Address)_Ancestors,
200 (Standard_Address)NULL);
205 //=======================================================================
206 //function : DownCast
208 //=======================================================================
210 const Handle(GEOMImpl_TranslateDriver) Handle(GEOMImpl_TranslateDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
212 Handle(GEOMImpl_TranslateDriver) _anOtherObject;
214 if (!AnObject.IsNull()) {
215 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_TranslateDriver))) {
216 _anOtherObject = Handle(GEOMImpl_TranslateDriver)((Handle(GEOMImpl_TranslateDriver)&)AnObject);
220 return _anOtherObject ;