Back to index

salome-geom  6.5.0
NMTTools_CheckerSI_1.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:        NMTTools_CheckerSI.cxx
00021 // Created:     Mon Feb 19 11:32:08 2007
00022 // Author:      Peter KURNEV
00023 //
00024 #include <NMTTools_CheckerSI.hxx>
00025 #include <NMTDS_ShapesDataStructure.hxx>
00026 #include <NMTDS_IteratorCheckerSI.hxx>
00027 
00028 #include <NMTDS_InterfPool.hxx>
00029 #include <TopoDS_Edge.hxx>
00030 #include <TopoDS_Vertex.hxx>
00031 #include <BOPTools_ListOfPaveBlock.hxx>
00032 #include <TopoDS.hxx>
00033 #include <BRep_Tool.hxx>
00034 #include <BOPTools_PaveSet.hxx>
00035 #include <BOPTools_PaveBlockIterator.hxx>
00036 #include <BOPTools_PaveBlock.hxx>
00037 #include <IntTools_Range.hxx>
00038 #include <BOPTools_Pave.hxx>
00039 #include <IntTools_ShrunkRange.hxx>
00040 #include <BOPTColStd_Failure.hxx>
00041 #include <BOPTColStd_Dump.hxx>
00042 #include <Geom_Curve.hxx>
00043 #include <gp_Pnt.hxx>
00044 
00045 
00046 
00047 static
00048   Standard_Boolean IsValid(const TopoDS_Edge& aE,
00049                            const TopoDS_Vertex& aV,
00050                            const Standard_Real aTV1,
00051                            const Standard_Real aTV2);
00052 
00053 //=======================================================================
00054 // function: PreparePaveBlocks
00055 // purpose:
00056 //=======================================================================
00057   void NMTTools_CheckerSI::PreparePaveBlocks(const TopAbs_ShapeEnum aType1,
00058                                              const TopAbs_ShapeEnum aType2)
00059 {
00060   NMTTools_PaveFiller::PreparePaveBlocks(aType1, aType2);
00061 }
00062 //=======================================================================
00063 // function: PreparePaveBlocks
00064 // purpose:
00065 //=======================================================================
00066   void NMTTools_CheckerSI::PreparePaveBlocks(const Standard_Integer nE)
00067 {
00068   myIsDone=Standard_False;
00069   //
00070   // char buf[32]={"SR"};
00071   Standard_Boolean bIsValid;
00072   Standard_Integer nV1, nV2, iErr;
00073   Standard_Real aT1, aT2;
00074   TopoDS_Edge aE;
00075   TopoDS_Vertex aV1, aV2;
00076   //
00077   BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool(myDS->RefEdge(nE));
00078   // Edge
00079   aE=TopoDS::Edge(myDS->Shape(nE));
00080   if (BRep_Tool::Degenerated(aE)) {
00081     myIsDone=Standard_True;
00082     return;
00083   }
00084   //
00085   BOPTools_PaveSet& aPS=myPavePool(myDS->RefEdge(nE));
00086 
00087   BOPTools_PaveBlockIterator aPBIt(nE, aPS);
00088   for (; aPBIt.More(); aPBIt.Next()) {
00089     BOPTools_PaveBlock& aPB=aPBIt.Value();
00090     const IntTools_Range& aRange=aPB.Range();
00091     //
00092     const BOPTools_Pave& aPave1=aPB.Pave1();
00093     nV1=aPave1.Index();
00094     aV1=TopoDS::Vertex(myDS->Shape(nV1));
00095     aT1=aPave1.Param();
00096     //
00097     const BOPTools_Pave& aPave2=aPB.Pave2();
00098     nV2=aPave2.Index();
00099     aV2=TopoDS::Vertex(myDS->Shape(nV2));
00100     aT2=aPave2.Param();
00101     //
00102     bIsValid=Standard_True;
00103     if (nV1==nV2) {
00104       bIsValid=IsValid(aE, aV1, aT1, aT2);
00105       if (!bIsValid) {
00106         //printf(" pb SR: nV    nE: %d  nV1:( %d %15.10lf ) nV2:( %d %15.10lf )\n", nE, nV1, aT1, nV2, aT2);
00107         myStopStatus=1;
00108       }
00109     }
00110     //
00111     IntTools_ShrunkRange aSR (aE, aV1, aV2, aRange, myContext);
00112     iErr=aSR.ErrorStatus();
00113     if (!aSR.IsDone()) {
00114       //printf(" pb SR: Done  nE: %d  nV1:( %d %15.10lf ) nV2:( %d %15.10lf )\n", nE, nV1, aT1, nV2, aT2);
00115       aSR.SetShrunkRange(aRange);
00116       //throw BOPTColStd_Failure(buf) ;
00117     }
00118     else if (iErr!=6) {
00119       CorrectShrunkRanges (0, aPave1, aSR);
00120       CorrectShrunkRanges (1, aPave2, aSR);
00121     }
00122     aPB.SetShrunkRange(aSR);
00123     aLPB.Append(aPB);
00124   } //for (; aPBIt.More(); aPBIt.Next())
00125   myIsDone=Standard_True;
00126 }
00127 
00128 //=======================================================================
00129 //function : IsValid
00130 //purpose  :
00131 //=======================================================================
00132 Standard_Boolean IsValid(const TopoDS_Edge& aE,
00133                          const TopoDS_Vertex& aV,
00134                          const Standard_Real aTV1,
00135                          const Standard_Real aTV2)
00136 {
00137   Standard_Boolean bRet;
00138   Standard_Integer i, aNbP, aNbP1;
00139   Standard_Real aTolV2, aTC1, aTC2, dT, aTC, aD2;
00140   Handle(Geom_Curve) aC;
00141   gp_Pnt aPV, aPC;
00142   //
00143   bRet=Standard_False;
00144   aTolV2=BRep_Tool::Tolerance(aV);
00145   aTolV2=aTolV2*aTolV2;
00146   aPV=BRep_Tool::Pnt(aV);
00147   aC=BRep_Tool::Curve(aE, aTC1, aTC2);
00148   aNbP=7;
00149   aNbP1=aNbP-1;
00150   dT=(aTV2-aTV1)/aNbP1;
00151   //
00152   for (i=1; i<aNbP-1 && !bRet ; ++i) {
00153     aTC=aTV1+dT*i;
00154     aC->D0(aTC, aPC);
00155     aD2=aPV.SquareDistance(aPC);
00156     bRet=aD2>aTolV2;
00157   }
00158   return bRet;
00159 }