Back to index

salome-geom  6.5.0
GEOMImpl_MirrorDriver.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include <Standard_Stream.hxx>
00024 
00025 #include <GEOMImpl_MirrorDriver.hxx>
00026 
00027 #include <GEOMImpl_IMirror.hxx>
00028 #include <GEOMImpl_Types.hxx>
00029 #include <GEOM_Function.hxx>
00030 
00031 #include <BRep_Tool.hxx>
00032 #include <BRepBuilderAPI_Transform.hxx>
00033 #include <BRepBuilderAPI_MakeVertex.hxx>
00034 #include <BRepClass_FaceClassifier.hxx>
00035 #include <BRepTools.hxx>
00036 
00037 #include <TopAbs.hxx>
00038 #include <TopExp.hxx>
00039 #include <TopoDS.hxx>
00040 #include <TopoDS_Shape.hxx>
00041 #include <TopoDS_Edge.hxx>
00042 #include <TopoDS_Face.hxx>
00043 #include <TopoDS_Vertex.hxx>
00044 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
00045 
00046 #include <Geom_Plane.hxx>
00047 
00048 #include <gp_Trsf.hxx>
00049 #include <gp_Pnt.hxx>
00050 #include <gp_Vec.hxx>
00051 
00052 //=======================================================================
00053 //function : GetID
00054 //purpose  :
00055 //======================================================================= 
00056 const Standard_GUID& GEOMImpl_MirrorDriver::GetID()
00057 {
00058   static Standard_GUID aMirrorDriver("FF1BBB57-5D14-4df2-980B-3A668264EA16");
00059   return aMirrorDriver; 
00060 }
00061 
00062 
00063 //=======================================================================
00064 //function : GEOMImpl_MirrorDriver
00065 //purpose  : 
00066 //=======================================================================
00067 
00068 GEOMImpl_MirrorDriver::GEOMImpl_MirrorDriver() 
00069 {
00070 }
00071 
00072 //=======================================================================
00073 //function : Execute
00074 //purpose  :
00075 //======================================================================= 
00076 Standard_Integer GEOMImpl_MirrorDriver::Execute(TFunction_Logbook& log) const
00077 {
00078   if (Label().IsNull())  return 0;    
00079   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00080 
00081   if (aFunction.IsNull()) return 0;
00082 
00083   TopoDS_Shape aShape;
00084   gp_Trsf aTrsf;
00085 
00086   GEOMImpl_IMirror TI (aFunction);
00087   Standard_Integer aType = aFunction->GetType();
00088 
00089   Handle(GEOM_Function) anOriginalFunction = TI.GetOriginal();
00090   if (anOriginalFunction.IsNull()) return 0;
00091 
00092   TopoDS_Shape anOriginal = anOriginalFunction->GetValue();
00093   if (anOriginal.IsNull()) return 0;
00094 
00095   // Bug 12158: Check for standalone (not included in faces) degenerated edges
00096   TopTools_IndexedDataMapOfShapeListOfShape aEFMap;
00097   TopExp::MapShapesAndAncestors(anOriginal, TopAbs_EDGE, TopAbs_FACE, aEFMap);
00098   Standard_Integer i, nbE = aEFMap.Extent();
00099   for (i = 1; i <= nbE; i++) {
00100     TopoDS_Shape anEdgeSh = aEFMap.FindKey(i);
00101     if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeSh))) {
00102       const TopTools_ListOfShape& aFaces = aEFMap.FindFromIndex(i);
00103       if (aFaces.IsEmpty())
00104         Standard_ConstructionError::Raise
00105           ("Mirror aborted : cannot process standalone degenerated edge");
00106     }
00107   }
00108 
00109   // Perform Mirror
00110   if (aType == MIRROR_PLANE || aType == MIRROR_PLANE_COPY) {
00111     Handle(GEOM_Function) aPlane = TI.GetPlane();
00112     if (aPlane.IsNull()) return 0;
00113     TopoDS_Shape aFaceShape = aPlane->GetValue();
00114     if (aFaceShape.IsNull() || aFaceShape.ShapeType() != TopAbs_FACE) return 0;
00115     TopoDS_Face aFace = TopoDS::Face(aFaceShape);
00116 
00117     Handle(Geom_Surface) surf = BRep_Tool::Surface(aFace);
00118     Handle(Geom_Plane) myPlane = Handle(Geom_Plane)::DownCast(surf);
00119     const gp_Ax3 pos = myPlane->Position();
00120     const gp_Pnt loc = pos.Location();  /* location of the plane */
00121     const gp_Dir dir = pos.Direction(); /* Main direction of the plane (Z axis) */
00122     gp_Ax2 aPln (loc, dir);
00123     aTrsf.SetMirror(aPln);
00124   }
00125   else if (aType == MIRROR_AXIS || aType == MIRROR_AXIS_COPY) {
00126     Handle(GEOM_Function) anAxis = TI.GetAxis();
00127     if (anAxis.IsNull()) return 0;
00128     TopoDS_Shape anAxisShape = anAxis->GetValue();
00129     if (anAxisShape.IsNull() || anAxisShape.ShapeType() != TopAbs_EDGE) return 0;
00130     TopoDS_Edge anEdge = TopoDS::Edge(anAxisShape);
00131 
00132     gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge));
00133     gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex (anEdge));
00134     gp_Vec aV (aP1, aP2);
00135     gp_Ax1 anAx1 (aP1, aV);
00136     aTrsf.SetMirror(anAx1);
00137   }
00138   else if (aType == MIRROR_POINT || aType == MIRROR_POINT_COPY) {
00139     Handle(GEOM_Function) aPoint = TI.GetPoint();
00140     if (aPoint.IsNull()) return 0;
00141     TopoDS_Shape aVertexShape = aPoint->GetValue();
00142     if (aVertexShape.IsNull() || aVertexShape.ShapeType() != TopAbs_VERTEX) return 0;
00143     TopoDS_Vertex aVertex = TopoDS::Vertex(aVertexShape);
00144 
00145     gp_Pnt aP = BRep_Tool::Pnt(aVertex);
00146     aTrsf.SetMirror(aP);
00147   }
00148   else {
00149     return 0;
00150   }
00151 
00152   BRepBuilderAPI_Transform aTransformation (anOriginal, aTrsf, Standard_False);
00153   aShape = aTransformation.Shape();
00154 
00155   if (aShape.IsNull()) return 0;
00156 
00157   aFunction->SetValue(aShape);
00158 
00159   log.SetTouched(Label()); 
00160 
00161   return 1;
00162 }
00163 
00164 
00165 //=======================================================================
00166 //function :  GEOMImpl_MirrorDriver_Type_
00167 //purpose  :
00168 //======================================================================= 
00169 Standard_EXPORT Handle_Standard_Type& GEOMImpl_MirrorDriver_Type_()
00170 {
00171 
00172   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
00173   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
00174   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
00175   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
00176   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
00177   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
00178  
00179 
00180   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
00181   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_MirrorDriver",
00182                                                          sizeof(GEOMImpl_MirrorDriver),
00183                                                          1,
00184                                                          (Standard_Address)_Ancestors,
00185                                                          (Standard_Address)NULL);
00186 
00187   return _aType;
00188 }
00189 
00190 //=======================================================================
00191 //function : DownCast
00192 //purpose  :
00193 //======================================================================= 
00194 
00195 const Handle(GEOMImpl_MirrorDriver) Handle(GEOMImpl_MirrorDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
00196 {
00197   Handle(GEOMImpl_MirrorDriver) _anOtherObject;
00198 
00199   if (!AnObject.IsNull()) {
00200      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_MirrorDriver))) {
00201        _anOtherObject = Handle(GEOMImpl_MirrorDriver)((Handle(GEOMImpl_MirrorDriver)&)AnObject);
00202      }
00203   }
00204 
00205   return _anOtherObject;
00206 }