1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <Standard_Stream.hxx>
25 #include <GEOMImpl_MirrorDriver.hxx>
27 #include <GEOMImpl_IMirror.hxx>
28 #include <GEOMImpl_Types.hxx>
29 #include <GEOM_Function.hxx>
31 #include <BRep_Tool.hxx>
32 #include <BRepBuilderAPI_Transform.hxx>
33 #include <BRepBuilderAPI_MakeVertex.hxx>
34 #include <BRepClass_FaceClassifier.hxx>
35 #include <BRepTools.hxx>
40 #include <TopoDS_Shape.hxx>
41 #include <TopoDS_Edge.hxx>
42 #include <TopoDS_Face.hxx>
43 #include <TopoDS_Vertex.hxx>
44 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
46 #include <Geom_Plane.hxx>
48 #include <gp_Trsf.hxx>
52 //=======================================================================
55 //=======================================================================
56 const Standard_GUID& GEOMImpl_MirrorDriver::GetID()
58 static Standard_GUID aMirrorDriver("FF1BBB57-5D14-4df2-980B-3A668264EA16");
63 //=======================================================================
64 //function : GEOMImpl_MirrorDriver
66 //=======================================================================
68 GEOMImpl_MirrorDriver::GEOMImpl_MirrorDriver()
72 //=======================================================================
75 //=======================================================================
76 Standard_Integer GEOMImpl_MirrorDriver::Execute(LOGBOOK& log) const
78 if (Label().IsNull()) return 0;
79 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
81 if (aFunction.IsNull()) return 0;
86 GEOMImpl_IMirror TI (aFunction);
87 Standard_Integer aType = aFunction->GetType();
89 Handle(GEOM_Function) anOriginalFunction = TI.GetOriginal();
90 if (anOriginalFunction.IsNull()) return 0;
92 TopoDS_Shape anOriginal = anOriginalFunction->GetValue();
93 if (anOriginal.IsNull()) return 0;
95 // Bug 12158: Check for standalone (not included in faces) degenerated edges
96 TopTools_IndexedDataMapOfShapeListOfShape aEFMap;
97 TopExp::MapShapesAndAncestors(anOriginal, TopAbs_EDGE, TopAbs_FACE, aEFMap);
98 Standard_Integer i, nbE = aEFMap.Extent();
99 for (i = 1; i <= nbE; i++) {
100 TopoDS_Shape anEdgeSh = aEFMap.FindKey(i);
101 if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeSh))) {
102 const TopTools_ListOfShape& aFaces = aEFMap.FindFromIndex(i);
103 if (aFaces.IsEmpty())
104 Standard_ConstructionError::Raise
105 ("Mirror aborted : cannot process standalone degenerated edge");
110 if (aType == MIRROR_PLANE || aType == MIRROR_PLANE_COPY) {
111 Handle(GEOM_Function) aPlane = TI.GetPlane();
112 if (aPlane.IsNull()) return 0;
113 TopoDS_Shape aFaceShape = aPlane->GetValue();
114 if (aFaceShape.IsNull() || aFaceShape.ShapeType() != TopAbs_FACE) return 0;
115 TopoDS_Face aFace = TopoDS::Face(aFaceShape);
117 Handle(Geom_Surface) surf = BRep_Tool::Surface(aFace);
118 Handle(Geom_Plane) myPlane = Handle(Geom_Plane)::DownCast(surf);
119 const gp_Ax3 pos = myPlane->Position();
120 const gp_Pnt loc = pos.Location(); /* location of the plane */
121 const gp_Dir dir = pos.Direction(); /* Main direction of the plane (Z axis) */
122 gp_Ax2 aPln (loc, dir);
123 aTrsf.SetMirror(aPln);
125 else if (aType == MIRROR_AXIS || aType == MIRROR_AXIS_COPY) {
126 Handle(GEOM_Function) anAxis = TI.GetAxis();
127 if (anAxis.IsNull()) return 0;
128 TopoDS_Shape anAxisShape = anAxis->GetValue();
129 if (anAxisShape.IsNull() || anAxisShape.ShapeType() != TopAbs_EDGE) return 0;
130 TopoDS_Edge anEdge = TopoDS::Edge(anAxisShape);
132 gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
133 gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex (anEdge));
134 gp_Vec aV (aP1, aP2);
135 gp_Ax1 anAx1 (aP1, aV);
136 aTrsf.SetMirror(anAx1);
138 else if (aType == MIRROR_POINT || aType == MIRROR_POINT_COPY) {
139 Handle(GEOM_Function) aPoint = TI.GetPoint();
140 if (aPoint.IsNull()) return 0;
141 TopoDS_Shape aVertexShape = aPoint->GetValue();
142 if (aVertexShape.IsNull() || aVertexShape.ShapeType() != TopAbs_VERTEX) return 0;
143 TopoDS_Vertex aVertex = TopoDS::Vertex(aVertexShape);
145 gp_Pnt aP = BRep_Tool::Pnt(aVertex);
152 BRepBuilderAPI_Transform aTransformation (anOriginal, aTrsf, Standard_False);
153 aShape = aTransformation.Shape();
155 if (aShape.IsNull()) return 0;
157 aFunction->SetValue(aShape);
159 #if OCC_VERSION_MAJOR < 7
160 log.SetTouched(Label());
162 log->SetTouched(Label());
168 //================================================================================
170 * \brief Returns a name of creation operation and names and values of creation parameters
172 //================================================================================
174 bool GEOMImpl_MirrorDriver::
175 GetCreationInformation(std::string& theOperationName,
176 std::vector<GEOM_Param>& theParams)
178 if (Label().IsNull()) return 0;
179 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
181 GEOMImpl_IMirror aCI( function );
182 Standard_Integer aType = function->GetType();
184 theOperationName = "MIRROR";
188 case MIRROR_PLANE_COPY:
189 AddParam( theParams, "Object", aCI.GetOriginal() );
190 AddParam( theParams, "Plane Mirror", aCI.GetPlane() );
193 case MIRROR_AXIS_COPY:
194 AddParam( theParams, "Object", aCI.GetOriginal() );
195 AddParam( theParams, "Axis Mirror", aCI.GetAxis() );
198 case MIRROR_POINT_COPY:
199 AddParam( theParams, "Object", aCI.GetOriginal() );
200 AddParam( theParams, "Point Mirror", aCI.GetPoint() );
209 OCCT_IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_MirrorDriver,GEOM_BaseDriver);