1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_MirrorDriver.hxx>
25 #include <GEOMImpl_IMirror.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOM_Function.hxx>
29 #include <BRep_Tool.hxx>
30 #include <BRepBuilderAPI_Transform.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Edge.hxx>
36 #include <TopoDS_Face.hxx>
37 #include <TopoDS_Vertex.hxx>
40 #include <Geom_Plane.hxx>
42 #include <gp_Trsf.hxx>
46 //=======================================================================
49 //=======================================================================
50 const Standard_GUID& GEOMImpl_MirrorDriver::GetID()
52 static Standard_GUID aMirrorDriver("FF1BBB57-5D14-4df2-980B-3A668264EA16");
57 //=======================================================================
58 //function : GEOMImpl_MirrorDriver
60 //=======================================================================
62 GEOMImpl_MirrorDriver::GEOMImpl_MirrorDriver()
66 //=======================================================================
69 //=======================================================================
70 Standard_Integer GEOMImpl_MirrorDriver::Execute(TFunction_Logbook& log) const
72 if (Label().IsNull()) return 0;
73 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
75 if (aFunction.IsNull()) return 0;
80 GEOMImpl_IMirror TI (aFunction);
81 Standard_Integer aType = aFunction->GetType();
83 Handle(GEOM_Function) anOriginalFunction = TI.GetOriginal();
84 if (anOriginalFunction.IsNull()) return 0;
86 TopoDS_Shape anOriginal = anOriginalFunction->GetValue();
87 if (anOriginal.IsNull()) return 0;
89 if (aType == MIRROR_PLANE || aType == MIRROR_PLANE_COPY) {
90 Handle(GEOM_Function) aPlane = TI.GetPlane();
91 if (aPlane.IsNull()) return 0;
92 TopoDS_Shape aFaceShape = aPlane->GetValue();
93 if (aFaceShape.IsNull() || aFaceShape.ShapeType() != TopAbs_FACE) return 0;
94 TopoDS_Face aFace = TopoDS::Face(aFaceShape);
96 Handle(Geom_Surface) surf = BRep_Tool::Surface(aFace);
97 Handle(Geom_Plane) myPlane = Handle(Geom_Plane)::DownCast(surf);
98 const gp_Ax3 pos = myPlane->Position();
99 const gp_Pnt loc = pos.Location(); /* location of the plane */
100 const gp_Dir dir = pos.Direction(); /* Main direction of the plane (Z axis) */
101 gp_Ax2 aPln (loc, dir);
102 aTrsf.SetMirror(aPln);
104 } else if (aType == MIRROR_AXIS || aType == MIRROR_AXIS_COPY) {
105 Handle(GEOM_Function) anAxis = TI.GetAxis();
106 if (anAxis.IsNull()) return 0;
107 TopoDS_Shape anAxisShape = anAxis->GetValue();
108 if (anAxisShape.IsNull() || anAxisShape.ShapeType() != TopAbs_EDGE) return 0;
109 TopoDS_Edge anEdge = TopoDS::Edge(anAxisShape);
111 gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
112 gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex (anEdge));
113 gp_Vec aV (aP1, aP2);
114 gp_Ax1 anAx1 (aP1, aV);
115 aTrsf.SetMirror(anAx1);
117 } else if (aType == MIRROR_POINT || aType == MIRROR_POINT_COPY) {
118 Handle(GEOM_Function) aPoint = TI.GetPoint();
119 if (aPoint.IsNull()) return 0;
120 TopoDS_Shape aVertexShape = aPoint->GetValue();
121 if (aVertexShape.IsNull() || aVertexShape.ShapeType() != TopAbs_VERTEX) return 0;
122 TopoDS_Vertex aVertex = TopoDS::Vertex(aVertexShape);
124 gp_Pnt aP = BRep_Tool::Pnt(aVertex);
130 BRepBuilderAPI_Transform aTransformation (anOriginal, aTrsf, Standard_False);
131 aShape = aTransformation.Shape();
133 if (aShape.IsNull()) return 0;
135 aFunction->SetValue(aShape);
137 log.SetTouched(Label());
143 //=======================================================================
144 //function : GEOMImpl_MirrorDriver_Type_
146 //=======================================================================
147 Standard_EXPORT Handle_Standard_Type& GEOMImpl_MirrorDriver_Type_()
150 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
151 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
152 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
153 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
154 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
155 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
158 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
159 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_MirrorDriver",
160 sizeof(GEOMImpl_MirrorDriver),
162 (Standard_Address)_Ancestors,
163 (Standard_Address)NULL);
168 //=======================================================================
169 //function : DownCast
171 //=======================================================================
173 const Handle(GEOMImpl_MirrorDriver) Handle(GEOMImpl_MirrorDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
175 Handle(GEOMImpl_MirrorDriver) _anOtherObject;
177 if (!AnObject.IsNull()) {
178 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_MirrorDriver))) {
179 _anOtherObject = Handle(GEOMImpl_MirrorDriver)((Handle(GEOMImpl_MirrorDriver)&)AnObject);
183 return _anOtherObject ;