1 // Created on: 1994-09-23
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16 
17 
18 #include <Geom2d_Curve.hxx>
19 #include <Geom2d_TrimmedCurve.hxx>
20 #include <Geom2dLProp_CurAndInf2d.hxx>
21 #include <gp_Pnt2d.hxx>
22 #include <MAT2d_CutCurve.hxx>
23 #include <Precision.hxx>
24 #include <Standard_OutOfRange.hxx>
25 #include <TColGeom2d_SequenceOfCurve.hxx>
26 
27 //=======================================================================
28 //function : MAT2d_CutCurve
29 //purpose  :
30 //=======================================================================
MAT2d_CutCurve()31 MAT2d_CutCurve::MAT2d_CutCurve()
32 {
33 }
34 
35 
36 //=======================================================================
37 //function : MAT2d_CutCurve
38 //purpose  :
39 //=======================================================================
40 
MAT2d_CutCurve(const Handle (Geom2d_Curve)& C)41 MAT2d_CutCurve::MAT2d_CutCurve(const Handle(Geom2d_Curve)& C)
42 {
43   Perform (C);
44 }
45 
46 
47 //=======================================================================
48 //function : Perform
49 //purpose  :
50 //=======================================================================
51 
Perform(const Handle (Geom2d_Curve)& C)52 void MAT2d_CutCurve::Perform(const Handle(Geom2d_Curve)& C)
53 {
54   theCurves.Clear();
55 
56   Geom2dLProp_CurAndInf2d     Sommets;
57   Handle(Geom2d_TrimmedCurve) TrimC;
58   Standard_Real               UF,UL,UC;
59   gp_Pnt2d                    PF,PL,PC;
60   Standard_Real               PTol  = Precision::PConfusion()*10;
61   Standard_Real               Tol   = Precision::Confusion()*10;
62   Standard_Boolean            YaCut = Standard_False;
63   Sommets.Perform (C);
64 
65   if (Sommets.IsDone() && !Sommets.IsEmpty()) {
66     UF = C->FirstParameter();
67     UL = C->LastParameter ();
68     PF = C->Value(UF);
69     PL = C->Value(UL);
70 
71     for (Standard_Integer i = 1; i <= Sommets.NbPoints(); i++) {
72       UC = Sommets.Parameter(i);
73 
74       PC = C->Value(UC);
75       if (UC - UF > PTol && PC.Distance(PF) > Tol) {
76 	if ( UL - UC < PTol || PL.Distance(PC) < Tol) {
77 	  break;
78 	}
79 	TrimC = new Geom2d_TrimmedCurve(C,UF,UC);
80 	theCurves.Append(TrimC);
81 	UF    = UC;
82 	PF    = PC;
83 	YaCut = Standard_True;
84       }
85     }
86     if (YaCut) {
87       TrimC = new Geom2d_TrimmedCurve(C,UF,UL);
88       theCurves.Append(TrimC);
89     }
90   }
91 }
92 
93 
94 //=======================================================================
95 //function : UnModified
96 //purpose  :
97 //=======================================================================
98 
UnModified() const99 Standard_Boolean MAT2d_CutCurve::UnModified() const
100 {
101   return theCurves.IsEmpty();
102 }
103 
104 
105 //=======================================================================
106 //function : NbCurves
107 //purpose  :
108 //=======================================================================
109 
NbCurves() const110 Standard_Integer MAT2d_CutCurve::NbCurves() const
111 {
112   if (UnModified()) {throw Standard_OutOfRange();}
113   return theCurves.Length();
114 }
115 
116 
117 //=======================================================================
118 //function : Value
119 //purpose  :
120 //=======================================================================
121 
Handle(Geom2d_TrimmedCurve)122 Handle(Geom2d_TrimmedCurve) MAT2d_CutCurve::Value (
123    const Standard_Integer Index)
124 const
125 {
126   if (UnModified()) {throw Standard_OutOfRange();}
127   if ( Index < 1 || Index > theCurves.Length()) {
128     throw Standard_OutOfRange();
129   }
130   return Handle(Geom2d_TrimmedCurve)::DownCast(theCurves.Value(Index));
131 }
132 
133 
134