3 #include "GEOMImpl_RotateDriver.hxx"
4 #include <GEOMImpl_IRotate.hxx>
5 #include <GEOMImpl_Types.hxx>
6 #include "GEOM_Function.hxx"
12 #include <BRepBuilderAPI_Transform.hxx>
14 #include <TopoDS_Vertex.hxx>
15 #include <TopoDS_Shape.hxx>
16 #include <TopoDS_Compound.hxx>
19 #include <TopoDS_Vertex.hxx>
20 #include <TopoDS_Edge.hxx>
21 #include <BRep_Tool.hxx>
22 #include <BRep_Builder.hxx>
23 #include <GeomAPI_ProjectPointOnCurve.hxx>
24 #include <Geom_Line.hxx>
25 #include <GProp_GProps.hxx>
26 #include <BRepGProp.hxx>
27 #include <Precision.hxx>
29 //=======================================================================
32 //=======================================================================
33 const Standard_GUID& GEOMImpl_RotateDriver::GetID()
35 static Standard_GUID aRotateDriver("FF1BBB56-5D14-4df2-980B-3A668264EA16");
40 //=======================================================================
41 //function : GEOMImpl_RotateDriver
43 //=======================================================================
45 GEOMImpl_RotateDriver::GEOMImpl_RotateDriver()
49 //=======================================================================
52 //=======================================================================
53 Standard_Integer GEOMImpl_RotateDriver::Execute(TFunction_Logbook& log) const
55 if(Label().IsNull()) return 0;
56 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
58 if(aFunction.IsNull()) return 0;
60 GEOMImpl_IRotate RI(aFunction);
62 Standard_Integer aType = aFunction->GetType();
63 Handle(GEOM_Function) anOriginalFunction = RI.GetOriginal();
64 if(anOriginalFunction.IsNull()) return 0;
65 TopoDS_Shape aShape, anOriginal = anOriginalFunction->GetValue();
66 if(anOriginal.IsNull()) return 0;
68 if(aType == ROTATE || aType == ROTATE_COPY) {
69 Handle(GEOM_Function) anAxis = RI.GetAxis();
70 if(anAxis.IsNull()) return 0;
71 TopoDS_Shape A = anAxis->GetValue();
72 if(A.IsNull() || A.ShapeType() != TopAbs_EDGE) return 0;
73 TopoDS_Edge anEdge = TopoDS::Edge(A);
75 gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
76 gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
77 gp_Dir aDir(gp_Vec(aP1, aP2));
78 gp_Ax1 anAx1(aP1, aDir);
79 Standard_Real anAngle = RI.GetAngle();
80 aTrsf.SetRotation(anAx1, anAngle);
82 BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
83 aShape = aTransformation.Shape();
85 else if(aType == ROTATE_1D) {
87 Handle(GEOM_Function) anAxis = RI.GetAxis();
88 if(anAxis.IsNull()) return 0;
89 TopoDS_Shape A = anAxis->GetValue();
90 if(A.IsNull() || A.ShapeType() != TopAbs_EDGE) return 0;
91 TopoDS_Edge anEdge = TopoDS::Edge(A);
93 gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
94 gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
95 gp_Dir D(gp_Vec(aP1, aP2)) ;
99 Standard_Integer nbtimes = RI.GetNbIter1();
100 Standard_Real angle = 360.0/nbtimes ;
102 TopoDS_Compound aCompound;
104 B.MakeCompound( aCompound );
106 for (int i = 0; i < nbtimes; i++ ) {
107 aTrsf.SetRotation(AX1, i*angle*PI180) ;
108 BRepBuilderAPI_Transform myBRepTransformation(anOriginal, aTrsf, Standard_False) ;
109 B.Add( aCompound, myBRepTransformation.Shape() );
114 else if(aType == ROTATE_2D) {
115 Standard_Real DX, DY, DZ ;
118 Handle(GEOM_Function) anAxis = RI.GetAxis();
119 if(anAxis.IsNull()) return 0;
120 TopoDS_Shape A = anAxis->GetValue();
121 if(A.IsNull() || A.ShapeType() != TopAbs_EDGE) return 0;
122 TopoDS_Edge anEdge = TopoDS::Edge(A);
123 gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
124 gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
125 gp_Dir D(gp_Vec(aP1, aP2)) ;
130 gp_Trsf theTransformation1 ;
131 gp_Trsf theTransformation2 ;
133 GProp_GProps System ;
135 if ( anOriginal.ShapeType() == TopAbs_VERTEX) {
136 P1 = BRep_Tool::Pnt(TopoDS::Vertex( anOriginal ));
138 else if ( anOriginal.ShapeType() == TopAbs_EDGE || anOriginal.ShapeType() == TopAbs_WIRE ) {
139 BRepGProp::LinearProperties(anOriginal, System);
140 P1 = System.CentreOfMass() ;
142 else if ( anOriginal.ShapeType() == TopAbs_FACE || anOriginal.ShapeType() == TopAbs_SHELL ) {
143 BRepGProp::SurfaceProperties(anOriginal, System);
144 P1 = System.CentreOfMass() ;
147 BRepGProp::VolumeProperties(anOriginal, System);
148 P1 = System.CentreOfMass() ;
151 Handle(Geom_Line) Line = new Geom_Line(AX1);
152 gp_Pnt P2 = GeomAPI_ProjectPointOnCurve( P1, Line ) ;
154 if ( P1.IsEqual(P2, Precision::Confusion() ) ) return 0;
156 gp_Vec Vec(P1.X()-P2.X(), P1.Y()-P2.Y(), P1.Z()-P2.Z()) ;
159 Standard_Integer nbtimes2 = RI.GetNbIter2();
160 Standard_Integer nbtimes1 = RI.GetNbIter1();
161 Standard_Real step = RI.GetStep();
162 Standard_Real ang = RI.GetAngle();
165 TopoDS_Compound aCompound;
167 B.MakeCompound( aCompound );
168 for (int i = 0; i < nbtimes2; i++ ) {
169 for (int j = 0; j < nbtimes1; j++ ) {
170 DX = i * step * Vec.X() ;
171 DY = i * step * Vec.Y() ;
172 DZ = i * step * Vec.Z() ;
173 myVec.SetCoord( DX, DY, DZ ) ;
174 theTransformation1.SetTranslation(myVec) ;
175 theTransformation2.SetRotation(AX1, j*ang*PI180) ;
176 BRepBuilderAPI_Transform myBRepTransformation1(anOriginal, theTransformation1, Standard_False) ;
177 BRepBuilderAPI_Transform myBRepTransformation2(myBRepTransformation1.Shape(), theTransformation2, Standard_False) ;
178 B.Add( aCompound, myBRepTransformation2.Shape() );
190 if (aShape.IsNull()) return 0;
192 aFunction->SetValue(aShape);
194 log.SetTouched(Label());
200 //=======================================================================
201 //function : GEOMImpl_RotateDriver_Type_
203 //=======================================================================
204 Standard_EXPORT Handle_Standard_Type& GEOMImpl_RotateDriver_Type_()
207 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
208 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
209 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
210 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
211 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
212 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
215 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
216 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_RotateDriver",
217 sizeof(GEOMImpl_RotateDriver),
219 (Standard_Address)_Ancestors,
220 (Standard_Address)NULL);
225 //=======================================================================
226 //function : DownCast
228 //=======================================================================
230 const Handle(GEOMImpl_RotateDriver) Handle(GEOMImpl_RotateDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
232 Handle(GEOMImpl_RotateDriver) _anOtherObject;
234 if (!AnObject.IsNull()) {
235 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_RotateDriver))) {
236 _anOtherObject = Handle(GEOMImpl_RotateDriver)((Handle(GEOMImpl_RotateDriver)&)AnObject);
240 return _anOtherObject ;