2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_MirrorDriver.hxx>
6 #include <GEOMImpl_IMirror.hxx>
7 #include <GEOMImpl_Types.hxx>
8 #include <GEOM_Function.hxx>
10 #include <BRep_Tool.hxx>
11 #include <BRepBuilderAPI_Transform.hxx>
15 #include <TopoDS_Shape.hxx>
16 #include <TopoDS_Edge.hxx>
17 #include <TopoDS_Face.hxx>
18 #include <TopoDS_Vertex.hxx>
21 #include <Geom_Plane.hxx>
23 #include <gp_Trsf.hxx>
27 //=======================================================================
30 //=======================================================================
31 const Standard_GUID& GEOMImpl_MirrorDriver::GetID()
33 static Standard_GUID aMirrorDriver("FF1BBB57-5D14-4df2-980B-3A668264EA16");
38 //=======================================================================
39 //function : GEOMImpl_MirrorDriver
41 //=======================================================================
43 GEOMImpl_MirrorDriver::GEOMImpl_MirrorDriver()
47 //=======================================================================
50 //=======================================================================
51 Standard_Integer GEOMImpl_MirrorDriver::Execute(TFunction_Logbook& log) const
53 if (Label().IsNull()) return 0;
54 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
56 if (aFunction.IsNull()) return 0;
61 GEOMImpl_IMirror TI (aFunction);
62 Standard_Integer aType = aFunction->GetType();
64 Handle(GEOM_Function) anOriginalFunction = TI.GetOriginal();
65 if (anOriginalFunction.IsNull()) return 0;
67 TopoDS_Shape anOriginal = anOriginalFunction->GetValue();
68 if (anOriginal.IsNull()) return 0;
70 if (aType == MIRROR_PLANE || aType == MIRROR_PLANE_COPY) {
71 Handle(GEOM_Function) aPlane = TI.GetPlane();
72 if (aPlane.IsNull()) return 0;
73 TopoDS_Shape aFaceShape = aPlane->GetValue();
74 if (aFaceShape.IsNull() || aFaceShape.ShapeType() != TopAbs_FACE) return 0;
75 TopoDS_Face aFace = TopoDS::Face(aFaceShape);
77 Handle(Geom_Surface) surf = BRep_Tool::Surface(aFace);
78 Handle(Geom_Plane) myPlane = Handle(Geom_Plane)::DownCast(surf);
79 const gp_Ax3 pos = myPlane->Position();
80 const gp_Pnt loc = pos.Location(); /* location of the plane */
81 const gp_Dir dir = pos.Direction(); /* Main direction of the plane (Z axis) */
82 gp_Ax2 aPln (loc, dir);
83 aTrsf.SetMirror(aPln);
85 } else if (aType == MIRROR_AXIS || aType == MIRROR_AXIS_COPY) {
86 Handle(GEOM_Function) anAxis = TI.GetAxis();
87 if (anAxis.IsNull()) return 0;
88 TopoDS_Shape anAxisShape = anAxis->GetValue();
89 if (anAxisShape.IsNull() || anAxisShape.ShapeType() != TopAbs_EDGE) return 0;
90 TopoDS_Edge anEdge = TopoDS::Edge(anAxisShape);
92 gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
93 gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex (anEdge));
95 gp_Ax1 anAx1 (aP1, aV);
96 aTrsf.SetMirror(anAx1);
98 } else if (aType == MIRROR_POINT || aType == MIRROR_POINT_COPY) {
99 Handle(GEOM_Function) aPoint = TI.GetPoint();
100 if (aPoint.IsNull()) return 0;
101 TopoDS_Shape aVertexShape = aPoint->GetValue();
102 if (aVertexShape.IsNull() || aVertexShape.ShapeType() != TopAbs_VERTEX) return 0;
103 TopoDS_Vertex aVertex = TopoDS::Vertex(aVertexShape);
105 gp_Pnt aP = BRep_Tool::Pnt(aVertex);
111 BRepBuilderAPI_Transform aTransformation (anOriginal, aTrsf, Standard_False);
112 aShape = aTransformation.Shape();
114 if (aShape.IsNull()) return 0;
116 aFunction->SetValue(aShape);
118 log.SetTouched(Label());
124 //=======================================================================
125 //function : GEOMImpl_MirrorDriver_Type_
127 //=======================================================================
128 Standard_EXPORT Handle_Standard_Type& GEOMImpl_MirrorDriver_Type_()
131 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
132 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
133 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
134 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
135 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
136 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
139 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
140 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_MirrorDriver",
141 sizeof(GEOMImpl_MirrorDriver),
143 (Standard_Address)_Ancestors,
144 (Standard_Address)NULL);
149 //=======================================================================
150 //function : DownCast
152 //=======================================================================
154 const Handle(GEOMImpl_MirrorDriver) Handle(GEOMImpl_MirrorDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
156 Handle(GEOMImpl_MirrorDriver) _anOtherObject;
158 if (!AnObject.IsNull()) {
159 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_MirrorDriver))) {
160 _anOtherObject = Handle(GEOMImpl_MirrorDriver)((Handle(GEOMImpl_MirrorDriver)&)AnObject);
164 return _anOtherObject ;