// Created on: 1999-03-09 // Created by: Roman LYGIN // Copyright (c) 1999-1999 Matra Datavision // Copyright (c) 1999-2014 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // // This library is free software; you can redistribute it and/or modify it under // the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. // // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static Standard_Integer ContToInteger( const GeomAbs_Shape Cont) { Standard_Integer result =0; switch(Cont) { case GeomAbs_C0: case GeomAbs_G1: result = 0; break; case GeomAbs_C1: case GeomAbs_G2: result = 1; break; case GeomAbs_C2: result = 2; break; case GeomAbs_C3: result = 3; break; default : result = 4; break; } return result; } static Standard_Integer directfaces(Draw_Interpretor& di, Standard_Integer argc, const char** argv) { if (argc < 3) { di<<"Donner un nom de SHAPE + un nom de RESULTAT\n"; return 1 /* Error */; } Standard_CString arg1 = argv[1]; Standard_CString arg2 = argv[2]; TopoDS_Shape Shape = DBRep::Get(arg2); if (Shape.IsNull()) { di<<"Shape unknown : "< Result : "< Precision::PConfusion()) { aNum++; continue; } } else { Standard_Real aDL = theKnots(i) - theLast; if(fabs(aDL) <= Precision::PConfusion() || aDL > Precision::PConfusion()) break; aNum++; } } return aNum; } static void expcurv2d(const Handle(Geom2d_Curve)& aCurve, TColStd_Array2OfInteger& Nb, const Standard_Integer Degree, const Standard_Integer MaxSeg, const Standard_Integer theCont, Standard_Real theFirst, Standard_Real theLast) { if(aCurve.IsNull()) return; if (aCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) { Handle(Geom2d_TrimmedCurve) tmp = Handle(Geom2d_TrimmedCurve)::DownCast (aCurve); Handle(Geom2d_Curve) BasCurve = tmp->BasisCurve(); expcurv2d(BasCurve,Nb,Degree,MaxSeg,theCont,theFirst,theLast); return; } if (aCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve))) { Handle(Geom2d_OffsetCurve) tmp = Handle(Geom2d_OffsetCurve)::DownCast (aCurve); Handle(Geom2d_Curve) BasCurve = tmp->BasisCurve(); expcurv2d(BasCurve,Nb,Degree,MaxSeg,theCont,theFirst,theLast); return; } Standard_Integer aCont = ContToInteger(aCurve->Continuity()); if(aCurve->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve))) { Handle(Geom2d_BSplineCurve) Bs = Handle(Geom2d_BSplineCurve)::DownCast(aCurve); if(Bs->Degree() > Degree) Nb.ChangeValue(1,1)++; if(Bs->NbKnots() -1 > MaxSeg) Nb.ChangeValue(1,2)++; if(Bs->IsRational()) Nb.ChangeValue(1,3)++; if(aCont < theCont && Bs->NbKnots() > 2) { TColStd_Array1OfReal aKnots(1,Bs->NbKnots()); Bs->Knots(aKnots); Standard_Integer nbInt = ckeckKnots(aKnots,theFirst,theLast); if(nbInt >1) Nb.ChangeValue(1,4)++; } return; } if (aCurve->IsKind(STANDARD_TYPE(Geom2d_BezierCurve))) { Handle(Geom2d_BezierCurve) Bs = Handle(Geom2d_BezierCurve)::DownCast(aCurve); if(Bs->Degree() > Degree) Nb.ChangeValue(2,1)++; if(Bs->IsRational()) Nb.ChangeValue(2,3)++; if(aCont < theCont) { Nb.ChangeValue(2,4)++; } return; } else Nb.ChangeValue(1,5)++; return; } static void expcurv(const Handle(Geom_Curve)& aCurve, TColStd_Array2OfInteger& Nb, const Standard_Integer Degree, const Standard_Integer MaxSeg, const Standard_Integer theCont, Standard_Real theFirst, Standard_Real theLast) { if(aCurve.IsNull()) return; if (aCurve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) { Handle(Geom_TrimmedCurve) tmp = Handle(Geom_TrimmedCurve)::DownCast (aCurve); Handle(Geom_Curve) BasCurve = tmp->BasisCurve(); expcurv(BasCurve,Nb,Degree,MaxSeg,theCont,theFirst,theLast); return; } if (aCurve->IsKind(STANDARD_TYPE(Geom_OffsetCurve))) { Handle(Geom_OffsetCurve) tmp = Handle(Geom_OffsetCurve)::DownCast (aCurve); Handle(Geom_Curve) BasCurve = tmp->BasisCurve(); expcurv(BasCurve,Nb,Degree,MaxSeg,theCont,theFirst,theLast); return; } Standard_Integer aCont = ContToInteger(aCurve->Continuity()); if(aCurve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) { Handle(Geom_BSplineCurve) Bs = Handle(Geom_BSplineCurve)::DownCast(aCurve); if(Bs->Degree() > Degree) Nb.ChangeValue(1,1)++; if(Bs->NbKnots() -1 > MaxSeg) Nb.ChangeValue(1,2)++; if(Bs->IsRational()) Nb.ChangeValue(1,3)++; if(aCont < theCont && Bs->NbKnots() > 2) { TColStd_Array1OfReal aKnots(1,Bs->NbKnots()); Bs->Knots(aKnots); Standard_Integer nbInt = ckeckKnots(aKnots,theFirst,theLast); if(nbInt >1) Nb.ChangeValue(1,4)++; } return; } if (aCurve->IsKind(STANDARD_TYPE(Geom_BezierCurve))) { Handle(Geom_BezierCurve) Bs = Handle(Geom_BezierCurve)::DownCast(aCurve); if(Bs->Degree() > Degree) Nb.ChangeValue(2,1)++; if(Bs->IsRational()) Nb.ChangeValue(2,3)++; if(aCont < theCont) Nb.ChangeValue(2,4)++; return; } else Nb.ChangeValue(1,5)++; return; } static void expsurf(const Handle(Geom_Surface)& aSurface, TColStd_Array2OfInteger& NbSurf, const Standard_Integer Degree, const Standard_Integer MaxSeg, const Standard_Integer theCont) { if (aSurface.IsNull()) return; if (aSurface->IsKind(STANDARD_TYPE(Geom_SweptSurface))) { Handle(Geom_SweptSurface) aSurf = Handle(Geom_SweptSurface)::DownCast(aSurface); Handle(Geom_Curve) BasCurve = aSurf->BasisCurve(); expcurv(BasCurve,NbSurf,Degree,MaxSeg,theCont,BasCurve->FirstParameter(), BasCurve->LastParameter()); return; } if (aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) { Handle(Geom_RectangularTrimmedSurface) aSurf = Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface); Handle(Geom_Surface) theSurf = aSurf->BasisSurface(); expsurf(theSurf,NbSurf,Degree,MaxSeg,theCont); return; } if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) { Handle(Geom_OffsetSurface) aSurf = Handle(Geom_OffsetSurface)::DownCast(aSurface); Handle(Geom_Surface) theSurf = aSurf->BasisSurface(); expsurf(theSurf,NbSurf,Degree,MaxSeg,theCont); return; } Standard_Integer aCont = ContToInteger(aSurface->Continuity()); if (aSurface->IsKind(STANDARD_TYPE(Geom_BSplineSurface))) { Handle(Geom_BSplineSurface) BS = Handle(Geom_BSplineSurface)::DownCast(aSurface); if(BS->UDegree() > Degree || BS->VDegree() > Degree) NbSurf.ChangeValue(1,1)++; if(((BS->NbUKnots()-1) * (BS->NbVKnots()-1)) >MaxSeg) NbSurf.ChangeValue(1,2)++; if(BS->IsURational() || BS->IsVRational()) NbSurf.ChangeValue(1,3)++; if(aCont < theCont) NbSurf.ChangeValue(1,4)++; return; } if (aSurface->IsKind(STANDARD_TYPE(Geom_BezierSurface))) { Handle(Geom_BezierSurface) BS = Handle(Geom_BezierSurface)::DownCast(aSurface); if(BS->UDegree() > Degree || BS->VDegree() > Degree) NbSurf.ChangeValue(2,1)++; if(BS->IsURational() || BS->IsVRational()) NbSurf.ChangeValue(2,3)++; if(aCont < theCont) NbSurf.ChangeValue(2,4)++; return; } if(aSurface->IsKind(STANDARD_TYPE(Geom_Plane))) { NbSurf.ChangeValue(1,5)++; } else NbSurf.ChangeValue(2,5)++; } static Standard_Integer expshape(Draw_Interpretor& di, Standard_Integer argc, const char** argv) { if (argc <4) { di << "Incorrect number of arguments. Must be 3\n"; return 1 /* Error */; } Standard_CString arg2 = argv[1]; TopoDS_Shape Shape = DBRep::Get(arg2); Standard_Integer Degree = Draw::Atoi(argv[2]); Standard_Integer MaxSeg = Draw::Atoi(argv[3]); GeomAbs_Shape aCont3 = GeomAbs_C0; Standard_Integer k = 4; if( argc > k) { if(strcmp(argv[k],"C0") == 0) aCont3 = GeomAbs_C0; else if (strcmp(argv[k],"C1") == 0) aCont3 = GeomAbs_C1; else if (strcmp(argv[k],"C2") == 0) aCont3 = GeomAbs_C2; else if (strcmp(argv[k],"C3") == 0) aCont3 = GeomAbs_C3; else if (strcmp(argv[k],"CN") == 0) aCont3 = GeomAbs_CN; else if (strcmp(argv[k],"G1") == 0) aCont3 = GeomAbs_C0; else if (strcmp(argv[k],"G2") == 0) aCont3 = GeomAbs_C1; else { di<< "Invalid argument Cont3e\n"; return 1; } } Standard_Integer aCont = ContToInteger(aCont3); TColStd_Array2OfInteger NbSurf(1,2,1,5); TColStd_Array2OfInteger NbCurv(1,2,1,5); TColStd_Array2OfInteger NbCurv2d(1,2,1,5); Standard_Integer nbSeam =0; NbSurf.Init(0); NbCurv.Init(0); NbCurv2d.Init(0); if (Shape.IsNull()) { di << "Shape unknown: " << arg2 << "\n"; return 1 /* Error */; } TopExp_Explorer Ex; Standard_Integer nbF =1; for (Ex.Init(Shape,TopAbs_FACE); Ex.More(); Ex.Next(),nbF++) { TopoDS_Face F = TopoDS::Face(Ex.Current()); TopLoc_Location L; Handle(Geom_Surface) aSurface = BRep_Tool::Surface(F,L); expsurf(aSurface,NbSurf,Degree,MaxSeg,aCont); TopExp_Explorer exp; Standard_Integer nbE = 1; for(exp.Init(F,TopAbs_EDGE); exp.More(); exp.Next(),nbE++) { TopoDS_Edge E = TopoDS::Edge(exp.Current()); if(BRep_Tool::IsClosed(E,F)) nbSeam++; Standard_Real First,Last; Handle(Geom_Curve) aCurve = BRep_Tool::Curve(E,L,First, Last); expcurv(aCurve,NbCurv,Degree,MaxSeg,aCont,First, Last); Standard_Real First2d,Last2d; Handle(Geom2d_Curve) aCurve2d = BRep_Tool::CurveOnSurface(E,F,First2d,Last2d); expcurv2d(aCurve2d,NbCurv2d,Degree,MaxSeg,aCont,First2d,Last2d); } } di<<"Number of seam edges - "< Result : "<