2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_RotateDriver.hxx>
5 #include <GEOMImpl_IRotate.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include <GEOM_Function.hxx>
13 #include <BRepBuilderAPI_Transform.hxx>
15 #include <TopoDS_Vertex.hxx>
16 #include <TopoDS_Shape.hxx>
17 #include <TopoDS_Compound.hxx>
20 #include <TopoDS_Vertex.hxx>
21 #include <TopoDS_Edge.hxx>
22 #include <BRep_Tool.hxx>
23 #include <BRep_Builder.hxx>
24 #include <GeomAPI_ProjectPointOnCurve.hxx>
25 #include <Geom_Line.hxx>
26 #include <GProp_GProps.hxx>
27 #include <BRepGProp.hxx>
28 #include <Precision.hxx>
30 //=======================================================================
33 //=======================================================================
34 const Standard_GUID& GEOMImpl_RotateDriver::GetID()
36 static Standard_GUID aRotateDriver("FF1BBB56-5D14-4df2-980B-3A668264EA16");
41 //=======================================================================
42 //function : GEOMImpl_RotateDriver
44 //=======================================================================
46 GEOMImpl_RotateDriver::GEOMImpl_RotateDriver()
50 //=======================================================================
53 //=======================================================================
54 Standard_Integer GEOMImpl_RotateDriver::Execute(TFunction_Logbook& log) const
56 if(Label().IsNull()) return 0;
57 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
59 if(aFunction.IsNull()) return 0;
61 GEOMImpl_IRotate RI(aFunction);
63 Standard_Integer aType = aFunction->GetType();
64 Handle(GEOM_Function) anOriginalFunction = RI.GetOriginal();
65 if(anOriginalFunction.IsNull()) return 0;
66 TopoDS_Shape aShape, anOriginal = anOriginalFunction->GetValue();
67 if(anOriginal.IsNull()) return 0;
69 if(aType == ROTATE || aType == ROTATE_COPY) {
70 Handle(GEOM_Function) anAxis = RI.GetAxis();
71 if(anAxis.IsNull()) return 0;
72 TopoDS_Shape A = anAxis->GetValue();
73 if(A.IsNull() || A.ShapeType() != TopAbs_EDGE) return 0;
74 TopoDS_Edge anEdge = TopoDS::Edge(A);
76 gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
77 gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
78 gp_Dir aDir(gp_Vec(aP1, aP2));
79 gp_Ax1 anAx1(aP1, aDir);
80 Standard_Real anAngle = RI.GetAngle();
81 aTrsf.SetRotation(anAx1, anAngle);
83 BRepBuilderAPI_Transform aTransformation(anOriginal, aTrsf, Standard_False);
84 aShape = aTransformation.Shape();
86 else if(aType == ROTATE_1D) {
88 Handle(GEOM_Function) anAxis = RI.GetAxis();
89 if(anAxis.IsNull()) return 0;
90 TopoDS_Shape A = anAxis->GetValue();
91 if(A.IsNull() || A.ShapeType() != TopAbs_EDGE) return 0;
92 TopoDS_Edge anEdge = TopoDS::Edge(A);
94 gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
95 gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
96 gp_Dir D(gp_Vec(aP1, aP2)) ;
100 Standard_Integer nbtimes = RI.GetNbIter1();
101 Standard_Real angle = 360.0/nbtimes ;
103 TopoDS_Compound aCompound;
105 B.MakeCompound( aCompound );
107 for (int i = 0; i < nbtimes; i++ ) {
108 aTrsf.SetRotation(AX1, i*angle*PI180) ;
109 BRepBuilderAPI_Transform myBRepTransformation(anOriginal, aTrsf, Standard_False) ;
110 B.Add( aCompound, myBRepTransformation.Shape() );
115 else if(aType == ROTATE_2D) {
116 Standard_Real DX, DY, DZ ;
119 Handle(GEOM_Function) anAxis = RI.GetAxis();
120 if(anAxis.IsNull()) return 0;
121 TopoDS_Shape A = anAxis->GetValue();
122 if(A.IsNull() || A.ShapeType() != TopAbs_EDGE) return 0;
123 TopoDS_Edge anEdge = TopoDS::Edge(A);
124 gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
125 gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdge));
126 gp_Dir D(gp_Vec(aP1, aP2)) ;
131 gp_Trsf theTransformation1 ;
132 gp_Trsf theTransformation2 ;
134 GProp_GProps System ;
136 if ( anOriginal.ShapeType() == TopAbs_VERTEX) {
137 P1 = BRep_Tool::Pnt(TopoDS::Vertex( anOriginal ));
139 else if ( anOriginal.ShapeType() == TopAbs_EDGE || anOriginal.ShapeType() == TopAbs_WIRE ) {
140 BRepGProp::LinearProperties(anOriginal, System);
141 P1 = System.CentreOfMass() ;
143 else if ( anOriginal.ShapeType() == TopAbs_FACE || anOriginal.ShapeType() == TopAbs_SHELL ) {
144 BRepGProp::SurfaceProperties(anOriginal, System);
145 P1 = System.CentreOfMass() ;
148 BRepGProp::VolumeProperties(anOriginal, System);
149 P1 = System.CentreOfMass() ;
152 Handle(Geom_Line) Line = new Geom_Line(AX1);
153 GeomAPI_ProjectPointOnCurve aPrjTool( P1, Line ) ;
154 gp_Pnt P2 = aPrjTool.NearestPoint();
156 if ( P1.IsEqual(P2, Precision::Confusion() ) ) return 0;
158 gp_Vec Vec(P1.X()-P2.X(), P1.Y()-P2.Y(), P1.Z()-P2.Z()) ;
161 Standard_Integer nbtimes2 = RI.GetNbIter2();
162 Standard_Integer nbtimes1 = RI.GetNbIter1();
163 Standard_Real step = RI.GetStep();
164 Standard_Real ang = RI.GetAngle();
167 TopoDS_Compound aCompound;
169 B.MakeCompound( aCompound );
170 for (int i = 0; i < nbtimes2; i++ ) {
171 for (int j = 0; j < nbtimes1; j++ ) {
172 DX = i * step * Vec.X() ;
173 DY = i * step * Vec.Y() ;
174 DZ = i * step * Vec.Z() ;
175 myVec.SetCoord( DX, DY, DZ ) ;
176 theTransformation1.SetTranslation(myVec) ;
177 theTransformation2.SetRotation(AX1, j*ang*PI180) ;
178 BRepBuilderAPI_Transform myBRepTransformation1(anOriginal, theTransformation1, Standard_False) ;
179 BRepBuilderAPI_Transform myBRepTransformation2(myBRepTransformation1.Shape(), theTransformation2, Standard_False) ;
180 B.Add( aCompound, myBRepTransformation2.Shape() );
192 if (aShape.IsNull()) return 0;
194 aFunction->SetValue(aShape);
196 log.SetTouched(Label());
202 //=======================================================================
203 //function : GEOMImpl_RotateDriver_Type_
205 //=======================================================================
206 Standard_EXPORT Handle_Standard_Type& GEOMImpl_RotateDriver_Type_()
209 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
210 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
211 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
212 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
213 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
214 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
217 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
218 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_RotateDriver",
219 sizeof(GEOMImpl_RotateDriver),
221 (Standard_Address)_Ancestors,
222 (Standard_Address)NULL);
227 //=======================================================================
228 //function : DownCast
230 //=======================================================================
232 const Handle(GEOMImpl_RotateDriver) Handle(GEOMImpl_RotateDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
234 Handle(GEOMImpl_RotateDriver) _anOtherObject;
236 if (!AnObject.IsNull()) {
237 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_RotateDriver))) {
238 _anOtherObject = Handle(GEOMImpl_RotateDriver)((Handle(GEOMImpl_RotateDriver)&)AnObject);
242 return _anOtherObject ;