]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_TranslateDriver.cxx
Salome HOME
if a shape to be rotated is a vertex, and it is located ON the Revolution Axis, then...
[modules/geom.git] / src / GEOMImpl / GEOMImpl_TranslateDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_TranslateDriver.hxx"
4 #include <GEOMImpl_ITranslate.hxx>
5 #include <GEOMImpl_Types.hxx>
6 #include "GEOM_Function.hxx"
7 #include <gp_Trsf.hxx>
8 #include <gp_Pnt.hxx>
9 #include <gp_Vec.hxx>
10 #include <BRepBuilderAPI_Transform.hxx>
11 #include <BRep_Builder.hxx>
12 #include <TopoDS.hxx>
13 #include <TopoDS_Shape.hxx>
14 #include <TopoDS_Edge.hxx>
15 #include <TopoDS_Compound.hxx>
16 #include <TopAbs.hxx>
17 #include <TopExp.hxx>
18 #include <TopoDS_Vertex.hxx>
19 #include <TopoDS_Edge.hxx>
20 #include <BRep_Tool.hxx>
21
22 //=======================================================================
23 //function : GetID
24 //purpose  :
25 //======================================================================= 
26 const Standard_GUID& GEOMImpl_TranslateDriver::GetID()
27 {
28   static Standard_GUID aTranslateDriver("FF1BBB03-5D14-4df2-980B-3A668264EA16");
29   return aTranslateDriver; 
30 }
31
32
33 //=======================================================================
34 //function : GEOMImpl_TranslateDriver
35 //purpose  : 
36 //=======================================================================
37
38 GEOMImpl_TranslateDriver::GEOMImpl_TranslateDriver() 
39 {
40 }
41
42 //=======================================================================
43 //function : Execute
44 //purpose  :
45 //======================================================================= 
46 Standard_Integer GEOMImpl_TranslateDriver::Execute(TFunction_Logbook& log) const
47 {
48   if(Label().IsNull())  return 0;    
49   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
50
51   if(aFunction.IsNull()) return 0;
52
53   GEOMImpl_ITranslate TI(aFunction);
54   gp_Trsf aTrsf;
55   gp_Pnt aP1, aP2;
56   Standard_Integer aType = aFunction->GetType();
57
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;
62
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;
71
72     aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aV1));
73     aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aV2));
74
75     aTrsf.SetTranslation(aP1, aP2);
76     BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
77     aShape = aTransformation.Shape();
78
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);
85
86     aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
87     aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
88
89     aTrsf.SetTranslation(aP1, aP2);
90     BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
91     aShape = aTransformation.Shape();
92   }
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();
98   }
99   else if(aType == TRANSLATE_1D) {
100     Standard_Real DX, DY, DZ, step = TI.GetStep1();
101     Standard_Integer nbtimes = TI.GetNbIter1();
102     gp_Vec myVec ;
103     TopoDS_Compound aCompound;
104     BRep_Builder B;
105     B.MakeCompound( aCompound );
106
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);
112
113     gp_Vec Vec(BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)), BRep_Tool::Pnt(TopExp::LastVertex(anEdge)));
114     Vec.Normalize();
115
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() );
124     }
125     aShape = aCompound;   
126   }
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();
130     gp_Vec myVec ;
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);
136
137     gp_Vec Vec1(BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)), BRep_Tool::Pnt(TopExp::LastVertex(anEdge)));
138     Vec1.Normalize();
139
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);
145
146     gp_Vec Vec2(BRep_Tool::Pnt(TopExp::FirstVertex(anEdge)), BRep_Tool::Pnt(TopExp::LastVertex(anEdge)));
147     Vec2.Normalize();
148
149     TopoDS_Compound aCompound;
150     BRep_Builder B;
151     B.MakeCompound( aCompound );
152     
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() );
162       }
163     }
164    aShape = aCompound;  
165   }
166   else return 0;
167
168  
169
170   if (aShape.IsNull()) return 0;
171
172   aFunction->SetValue(aShape);
173
174   log.SetTouched(Label()); 
175
176   return 1;
177 }
178
179
180 //=======================================================================
181 //function :  GEOMImpl_TranslateDriver_Type_
182 //purpose  :
183 //======================================================================= 
184 Standard_EXPORT Handle_Standard_Type& GEOMImpl_TranslateDriver_Type_()
185 {
186
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);
193  
194
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),
198                                                          1,
199                                                          (Standard_Address)_Ancestors,
200                                                          (Standard_Address)NULL);
201
202   return _aType;
203 }
204
205 //=======================================================================
206 //function : DownCast
207 //purpose  :
208 //======================================================================= 
209
210 const Handle(GEOMImpl_TranslateDriver) Handle(GEOMImpl_TranslateDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
211 {
212   Handle(GEOMImpl_TranslateDriver) _anOtherObject;
213
214   if (!AnObject.IsNull()) {
215      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_TranslateDriver))) {
216        _anOtherObject = Handle(GEOMImpl_TranslateDriver)((Handle(GEOMImpl_TranslateDriver)&)AnObject);
217      }
218   }
219
220   return _anOtherObject ;
221 }
222
223