2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_TranslateDriver.hxx>
5 #include <GEOMImpl_ITranslate.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include <GEOM_Function.hxx>
11 #include <BRepBuilderAPI_Transform.hxx>
12 #include <BRep_Builder.hxx>
14 #include <TopoDS_Shape.hxx>
15 #include <TopoDS_Edge.hxx>
16 #include <TopoDS_Compound.hxx>
19 #include <TopoDS_Vertex.hxx>
20 #include <TopoDS_Edge.hxx>
21 #include <BRep_Tool.hxx>
23 //=======================================================================
26 //=======================================================================
27 const Standard_GUID& GEOMImpl_TranslateDriver::GetID()
29 static Standard_GUID aTranslateDriver("FF1BBB03-5D14-4df2-980B-3A668264EA16");
30 return aTranslateDriver;
34 //=======================================================================
35 //function : GEOMImpl_TranslateDriver
37 //=======================================================================
39 GEOMImpl_TranslateDriver::GEOMImpl_TranslateDriver()
43 //=======================================================================
46 //=======================================================================
47 Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const
49 if(Label().IsNull()) return 0;
50 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
52 if(aFunction.IsNull()) return 0;
54 GEOMImpl_ITranslate TI(aFunction);
57 Standard_Integer aType = aFunction->GetType();
59 Handle(GEOM_Function) anOriginalFunction = TI.GetOriginal();
60 if(anOriginalFunction.IsNull()) return 0;
61 TopoDS_Shape aShape, anOriginal = anOriginalFunction->GetValue();
62 if(anOriginal.IsNull()) return 0;
64 if(aType == TRANSLATE_TWO_POINTS || aType == TRANSLATE_TWO_POINTS_COPY) {
65 Handle(GEOM_Function) aPoint1 = TI.GetPoint1();
66 Handle(GEOM_Function) aPoint2 = TI.GetPoint2();
67 if(aPoint1.IsNull() || aPoint2.IsNull()) return 0;
68 TopoDS_Shape aV1 = aPoint1->GetValue();
69 TopoDS_Shape aV2 = aPoint2->GetValue();
70 if(aV1.IsNull() || aV1.ShapeType() != TopAbs_VERTEX) return 0;
71 if(aV2.IsNull() || aV2.ShapeType() != TopAbs_VERTEX) return 0;
73 aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aV1));
74 aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aV2));
76 aTrsf.SetTranslation(aP1, aP2);
77 BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
78 aShape = aTransformation.Shape();
80 } else if(aType == TRANSLATE_VECTOR || aType == TRANSLATE_VECTOR_COPY) {
81 Handle(GEOM_Function) aVector = TI.GetVector();
82 if(aVector.IsNull()) return 0;
83 TopoDS_Shape aV = aVector->GetValue();
84 if(aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) return 0;
85 TopoDS_Edge anEdge = TopoDS::Edge(aV);
87 aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
88 aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
90 aTrsf.SetTranslation(aP1, aP2);
91 BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
92 aShape = aTransformation.Shape();
94 else if(aType == TRANSLATE_XYZ || aType == TRANSLATE_XYZ_COPY) {
95 gp_Vec aVec(TI.GetDX(), TI.GetDY(), TI.GetDZ());
96 aTrsf.SetTranslation(aVec);
97 BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
98 aShape = aTransformation.Shape();
100 else if(aType == TRANSLATE_1D) {
101 Standard_Real DX, DY, DZ, step = TI.GetStep1();
102 Standard_Integer nbtimes = TI.GetNbIter1();
104 TopoDS_Compound aCompound;
106 B.MakeCompound( aCompound );
108 Handle(GEOM_Function) aVector = TI.GetVector();
109 if(aVector.IsNull()) return 0;
110 TopoDS_Shape aV = aVector->GetValue();
111 if(aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) return 0;
112 TopoDS_Edge anEdge = TopoDS::Edge(aV);
114 gp_Vec Vec(BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)), BRep_Tool::Pnt(TopExp::LastVertex(anEdge)));
117 for (int i = 0; i < nbtimes; i++ ) {
118 DX = i * step * Vec.X() ;
119 DY = i * step * Vec.Y() ;
120 DZ = i * step * Vec.Z() ;
121 myVec.SetCoord( DX, DY, DZ ) ;
122 aTrsf.SetTranslation(myVec) ;
123 BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False) ;
124 B.Add(aCompound , aTransformation.Shape() );
128 else if(aType == TRANSLATE_2D) {
129 Standard_Integer nbtimes1 = TI.GetNbIter1(), nbtimes2 = TI.GetNbIter2();
130 Standard_Real DX, DY, DZ, step1 = TI.GetStep1(), step2 = TI.GetStep2();
132 Handle(GEOM_Function) aVector = TI.GetVector();
133 if(aVector.IsNull()) return 0;
134 TopoDS_Shape aV = aVector->GetValue();
135 if(aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) return 0;
136 TopoDS_Edge anEdge = TopoDS::Edge(aV);
138 gp_Vec Vec1(BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)), BRep_Tool::Pnt(TopExp::LastVertex(anEdge)));
141 Handle(GEOM_Function) aVector2 = TI.GetVector2();
142 if(aVector2.IsNull()) return 0;
143 aV = aVector2->GetValue();
144 if(aV.IsNull() || aV.ShapeType() != TopAbs_EDGE) return 0;
145 anEdge = TopoDS::Edge(aV);
147 gp_Vec Vec2(BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)), BRep_Tool::Pnt(TopExp::LastVertex(anEdge)));
150 TopoDS_Compound aCompound;
152 B.MakeCompound( aCompound );
154 for (int i = 0; i < nbtimes1; i++ ) {
155 for (int j = 0; j < nbtimes2; j++ ) {
156 DX = i * step1 * Vec1.X() + j * step2 * Vec2.X() ;
157 DY = i * step1 * Vec1.Y() + j * step2 * Vec2.Y() ;
158 DZ = i * step1 * Vec1.Z() + j * step2 * Vec2.Z() ;
159 myVec.SetCoord( DX, DY, DZ ) ;
160 aTrsf.SetTranslation(myVec) ;
161 BRepBuilderAPI_Transform myBRepTransformation(anOriginal, aTrsf, Standard_False) ;
162 B.Add(aCompound , myBRepTransformation.Shape() );
171 if (aShape.IsNull()) return 0;
173 aFunction->SetValue(aShape);
175 log.SetTouched(Label());
181 //=======================================================================
182 //function : GEOMImpl_TranslateDriver_Type_
184 //=======================================================================
185 Standard_EXPORT Handle_Standard_Type& GEOMImpl_TranslateDriver_Type_()
188 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
189 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
190 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
191 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
192 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
193 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
196 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
197 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_TranslateDriver",
198 sizeof(GEOMImpl_TranslateDriver),
200 (Standard_Address)_Ancestors,
201 (Standard_Address)NULL);
206 //=======================================================================
207 //function : DownCast
209 //=======================================================================
211 const Handle(GEOMImpl_TranslateDriver) Handle(GEOMImpl_TranslateDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
213 Handle(GEOMImpl_TranslateDriver) _anOtherObject;
215 if (!AnObject.IsNull()) {
216 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_TranslateDriver))) {
217 _anOtherObject = Handle(GEOMImpl_TranslateDriver)((Handle(GEOMImpl_TranslateDriver)&)AnObject);
221 return _anOtherObject ;