3 #include "GEOMImpl_MirrorDriver.hxx"
5 #include <GEOMImpl_IMirror.hxx>
6 #include <GEOMImpl_Types.hxx>
7 #include "GEOM_Function.hxx"
9 #include <BRep_Tool.hxx>
10 #include <BRepBuilderAPI_Transform.hxx>
14 #include <TopoDS_Shape.hxx>
15 #include <TopoDS_Edge.hxx>
16 #include <TopoDS_Face.hxx>
17 #include <TopoDS_Vertex.hxx>
20 #include <Geom_Plane.hxx>
22 #include <gp_Trsf.hxx>
26 //=======================================================================
29 //=======================================================================
30 const Standard_GUID& GEOMImpl_MirrorDriver::GetID()
32 static Standard_GUID aMirrorDriver("FF1BBB57-5D14-4df2-980B-3A668264EA16");
37 //=======================================================================
38 //function : GEOMImpl_MirrorDriver
40 //=======================================================================
42 GEOMImpl_MirrorDriver::GEOMImpl_MirrorDriver()
46 //=======================================================================
49 //=======================================================================
50 Standard_Integer GEOMImpl_MirrorDriver::Execute(TFunction_Logbook& log) const
52 if (Label().IsNull()) return 0;
53 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
55 if (aFunction.IsNull()) return 0;
60 GEOMImpl_IMirror TI (aFunction);
61 Standard_Integer aType = aFunction->GetType();
63 Handle(GEOM_Function) anOriginalFunction = TI.GetOriginal();
64 if (anOriginalFunction.IsNull()) return 0;
66 TopoDS_Shape anOriginal = anOriginalFunction->GetValue();
67 if (anOriginal.IsNull()) return 0;
69 if (aType == MIRROR_PLANE || aType == MIRROR_PLANE_COPY) {
70 Handle(GEOM_Function) aPlane = TI.GetPlane();
71 if (aPlane.IsNull()) return 0;
72 TopoDS_Shape aFaceShape = aPlane->GetValue();
73 if (aFaceShape.IsNull() || aFaceShape.ShapeType() != TopAbs_FACE) return 0;
74 TopoDS_Face aFace = TopoDS::Face(aFaceShape);
76 Handle(Geom_Surface) surf = BRep_Tool::Surface(aFace);
77 Handle(Geom_Plane) myPlane = Handle(Geom_Plane)::DownCast(surf);
78 const gp_Ax3 pos = myPlane->Position();
79 const gp_Pnt loc = pos.Location(); /* location of the plane */
80 const gp_Dir dir = pos.Direction(); /* Main direction of the plane (Z axis) */
81 gp_Ax2 aPln (loc, dir);
82 aTrsf.SetMirror(aPln);
84 } else if (aType == MIRROR_AXIS || aType == MIRROR_AXIS_COPY) {
85 Handle(GEOM_Function) anAxis = TI.GetAxis();
86 if (anAxis.IsNull()) return 0;
87 TopoDS_Shape anAxisShape = anAxis->GetValue();
88 if (anAxisShape.IsNull() || anAxisShape.ShapeType() != TopAbs_EDGE) return 0;
89 TopoDS_Edge anEdge = TopoDS::Edge(anAxisShape);
91 gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
92 gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex (anEdge));
94 gp_Ax1 anAx1 (aP1, aV);
95 aTrsf.SetMirror(anAx1);
97 } else if (aType == MIRROR_POINT || aType == MIRROR_POINT_COPY) {
98 Handle(GEOM_Function) aPoint = TI.GetPoint();
99 if (aPoint.IsNull()) return 0;
100 TopoDS_Shape aVertexShape = aPoint->GetValue();
101 if (aVertexShape.IsNull() || aVertexShape.ShapeType() != TopAbs_VERTEX) return 0;
102 TopoDS_Vertex aVertex = TopoDS::Vertex(aVertexShape);
104 gp_Pnt aP = BRep_Tool::Pnt(aVertex);
110 BRepBuilderAPI_Transform aTransformation (anOriginal, aTrsf, Standard_False);
111 aShape = aTransformation.Shape();
113 if (aShape.IsNull()) return 0;
115 aFunction->SetValue(aShape);
117 log.SetTouched(Label());
123 //=======================================================================
124 //function : GEOMImpl_MirrorDriver_Type_
126 //=======================================================================
127 Standard_EXPORT Handle_Standard_Type& GEOMImpl_MirrorDriver_Type_()
130 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
131 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
132 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
133 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
134 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
135 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
138 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
139 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_MirrorDriver",
140 sizeof(GEOMImpl_MirrorDriver),
142 (Standard_Address)_Ancestors,
143 (Standard_Address)NULL);
148 //=======================================================================
149 //function : DownCast
151 //=======================================================================
153 const Handle(GEOMImpl_MirrorDriver) Handle(GEOMImpl_MirrorDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
155 Handle(GEOMImpl_MirrorDriver) _anOtherObject;
157 if (!AnObject.IsNull()) {
158 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_MirrorDriver))) {
159 _anOtherObject = Handle(GEOMImpl_MirrorDriver)((Handle(GEOMImpl_MirrorDriver)&)AnObject);
163 return _anOtherObject ;