Back to index

salome-geom  6.5.0
NMTDS_Tools.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // File:        NMTDS_Tools.cxx
00021 // Created:     Tue Feb 20 14:57:28 2007
00022 // Author:      Peter KURNEV
00023 
00024 #include <NMTDS_Tools.hxx>
00025 #include <TopoDS_Vertex.hxx>
00026 #include <gp_Pnt.hxx>
00027 #include <BRep_Tool.hxx>
00028 #include <TopoDS_Shape.hxx>
00029 #include <TopTools_IndexedDataMapOfShapeShape.hxx>
00030 #include <TopAbs_ShapeEnum.hxx>
00031 #include <TopoDS_Iterator.hxx>
00032 #include <BRep_Builder.hxx>
00033 
00034 void CopySource(const TopoDS_Shape& aS,
00035                 TopTools_IndexedDataMapOfShapeShape& aMapSS,
00036                 TopoDS_Shape& aSC);
00037 
00038 //=======================================================================
00039 //function : CopyShape
00040 //purpose  :
00041 //=======================================================================
00042   void NMTDS_Tools::CopyShape(const TopoDS_Shape& aS,
00043                               TopoDS_Shape& aSC)
00044 {
00045   TopTools_IndexedDataMapOfShapeShape aMapSS;
00046   //
00047   CopySource(aS, aMapSS, aSC);
00048 }
00049 //=======================================================================
00050 //function : CopyShape
00051 //purpose  :
00052 //=======================================================================
00053   void NMTDS_Tools::CopyShape(const TopoDS_Shape& aS,
00054                               TopoDS_Shape& aSC,
00055                               TopTools_IndexedDataMapOfShapeShape& aMapSS)
00056 {
00057   CopySource(aS, aMapSS, aSC);
00058 }
00059 //=======================================================================
00060 //function : CopySource
00061 //purpose  :
00062 //=======================================================================
00063 void CopySource(const TopoDS_Shape& aS,
00064                 TopTools_IndexedDataMapOfShapeShape& aMapSS,
00065                 TopoDS_Shape& aSC)
00066 {
00067   Standard_Boolean bFree;
00068   TopAbs_ShapeEnum aT;
00069   TopoDS_Iterator aIt;
00070   TopoDS_Shape aSF;
00071   BRep_Builder BB;
00072   //
00073   aT=aS.ShapeType();
00074   //
00075   if (aMapSS.Contains(aS)) {
00076     aSC=aMapSS.ChangeFromKey(aS);
00077     aSC.Orientation(aS.Orientation());
00078     return;
00079   }
00080   else {
00081     aSC=aS.EmptyCopied();
00082     aMapSS.Add(aS, aSC);
00083   }
00084   //
00085   bFree=aSC.Free();
00086   aSC.Free(Standard_True);
00087   aSF=aS;
00088   if (aT==TopAbs_EDGE){
00089     TopAbs_Orientation aOr;
00090     //
00091     aOr=aS.Orientation();
00092     if(aOr==TopAbs_INTERNAL) {
00093       aSF.Orientation(TopAbs_FORWARD);
00094     }
00095   }
00096   aIt.Initialize(aSF);
00097   for (; aIt.More();  aIt.Next()) {
00098     TopoDS_Shape aSCx;
00099     //
00100     const TopoDS_Shape& aSx=aIt.Value();
00101     //
00102     CopySource (aSx, aMapSS, aSCx);
00103     //
00104     aSCx.Orientation(aSx.Orientation());
00105     BB.Add(aSC, aSCx);
00106   }
00107   aSC.Free(bFree);
00108 }
00109 //=======================================================================
00110 // function: ComputeVV
00111 // purpose:
00112 //=======================================================================
00113   Standard_Integer NMTDS_Tools::ComputeVV(const TopoDS_Vertex& aV1,
00114                                           const TopoDS_Vertex& aV2)
00115 {
00116   Standard_Real aTolV1, aTolV2, aTolSum, aTolSum2, aD2;
00117   gp_Pnt aP1, aP2;
00118   //
00119   aTolV1=BRep_Tool::Tolerance(aV1);
00120   aTolV2=BRep_Tool::Tolerance(aV2);
00121   aTolSum=aTolV1+aTolV2;
00122   aTolSum2=aTolSum*aTolSum;
00123   //
00124   aP1=BRep_Tool::Pnt(aV1);
00125   aP2=BRep_Tool::Pnt(aV2);
00126   //
00127   aD2=aP1.SquareDistance(aP2);
00128   if (aD2>aTolSum2) {
00129     return -1;
00130   }
00131   return 0;
00132 }
00133 //=======================================================================
00134 // function: HasBRep
00135 // purpose:
00136 //=======================================================================
00137   Standard_Boolean NMTDS_Tools::HasBRep(const TopAbs_ShapeEnum aTi)
00138 {
00139   return (aTi==TopAbs_VERTEX || aTi==TopAbs_EDGE || aTi==TopAbs_FACE);
00140 }
00141 //=======================================================================
00142 //function : TypeToInteger
00143 //purpose  :
00144 //=======================================================================
00145   Standard_Integer NMTDS_Tools::TypeToInteger(const TopAbs_ShapeEnum aType1,
00146                                             const TopAbs_ShapeEnum aType2)
00147 {
00148   Standard_Integer iRet, iT1, iT2, iX;
00149   //
00150   iRet=-1;
00151   iT1=(Standard_Integer)aType1;
00152   iT2=(Standard_Integer)aType2;
00153   //
00154   iX=iT2*10+iT1;
00155   switch (iX) {
00156     case 77:
00157       iRet=5; // VV
00158       break;
00159     case 76:
00160     case 67:
00161       iRet=4; // VE
00162       break;
00163     case 74:
00164     case 47:
00165       iRet=2; // VF
00166       break;
00167     case 66:
00168       iRet=3; // EE
00169       break;
00170     case 64:
00171     case 46:
00172       iRet=1; // EF
00173       break;
00174     case 44:
00175       iRet=0; // FF
00176       break;
00177     default:
00178       break;
00179   }
00180   return iRet;
00181 }