b311480e |
1 | // Created on: 1997-03-10 |
2 | // Created by: Stagiaire Francois DUMONT |
3 | // Copyright (c) 1997-1999 Matra Datavision |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | // |
6 | // The content of this file is subject to the Open CASCADE Technology Public |
7 | // License Version 6.5 (the "License"). You may not use the content of this file |
8 | // except in compliance with the License. Please obtain a copy of the License |
9 | // at http://www.opencascade.org and read it completely before using this file. |
10 | // |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
13 | // |
14 | // The Original Code and all software distributed under the License is |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
16 | // Initial Developer hereby disclaims all such warranties, including without |
17 | // limitation, any warranties of merchantability, fitness for a particular |
18 | // purpose or non-infringement. Please see the License for the specific terms |
19 | // and conditions governing the rights and limitations under the License. |
20 | |
7fd59977 |
21 | |
22 | |
23 | #include <BRepAlgo.ixx> |
24 | #include <BRepTools_WireExplorer.hxx> |
25 | #include <BRep_Tool.hxx> |
26 | #include <BRepLib_MakeEdge.hxx> |
27 | #include <BRepLib_MakeWire.hxx> |
28 | #include <gp_Pnt.hxx> |
29 | #include <GeomConvert.hxx> |
30 | #include <GeomLProp.hxx> |
31 | #include <Geom_TrimmedCurve.hxx> |
32 | #include <Precision.hxx> |
33 | #include <Standard_ConstructionError.hxx> |
34 | #include <TColGeom_Array1OfBSplineCurve.hxx> |
35 | #include <TColGeom_HArray1OfBSplineCurve.hxx> |
36 | #include <TColStd_Array1OfReal.hxx> |
37 | #include <TColStd_Array1OfBoolean.hxx> |
38 | #include <TopoDS_Edge.hxx> |
39 | #include <TopoDS_Vertex.hxx> |
40 | #include <TopLoc_Location.hxx> |
41 | #include <TopExp.hxx> |
42 | |
43 | //======================================================================= |
44 | //function : ConcatenateWire |
45 | //purpose : |
46 | //======================================================================= |
47 | |
48 | TopoDS_Wire BRepAlgo::ConcatenateWire(const TopoDS_Wire& W, |
49 | const GeomAbs_Shape Option, |
50 | const Standard_Real TolAngular) |
51 | { |
52 | |
53 | |
54 | Standard_Integer nb_curve, //number of curves in the Wire |
55 | index; |
56 | BRepTools_WireExplorer WExp(W) ; |
57 | TopoDS_Edge edge; |
58 | TopLoc_Location L ; |
59 | Standard_Real First=0.,Last=0., //extremal values for the curve |
60 | First0 =0., |
61 | toler =0., |
62 | tolleft,tolright; //Vertex tolerances |
63 | TopoDS_Vertex Vfirst,Vlast; //Vertex of the Wire |
64 | gp_Pnt Pfirst,Plast; //, Pint; corresponding points |
65 | |
66 | BRepLib_MakeWire MakeResult; |
67 | Standard_Real closed_tolerance =0.0; |
68 | Standard_Boolean closed_flag = Standard_False ; |
69 | |
70 | nb_curve = 0; |
71 | |
72 | while ( WExp.More()){ //computation of the curve number |
73 | nb_curve++ ; |
74 | WExp.Next(); |
75 | } |
76 | |
77 | if (nb_curve > 1) { |
78 | TColGeom_Array1OfBSplineCurve tab(0,nb_curve-1); //array of the wire's curve |
79 | TColStd_Array1OfReal tabtolvertex(0,nb_curve-2); //array of the tolerance's vertex |
80 | |
81 | WExp.Init(W); |
82 | |
83 | for (index=0 ;index<nb_curve; index++){ //main loop |
84 | edge = WExp.Current() ; |
85 | tab(index) = GeomConvert::CurveToBSplineCurve(new //storage in a array |
86 | Geom_TrimmedCurve(BRep_Tool::Curve(edge,L,First,Last),First,Last)); |
87 | tab(index)->Transform(L.Transformation()); |
88 | GeomConvert::C0BSplineToC1BSplineCurve(tab(index),Precision::Confusion()); |
89 | |
90 | if (index >= 1){ //continuity test loop |
91 | if (edge.Orientation()==TopAbs_REVERSED) |
92 | tab(index)->Reverse(); |
93 | tolleft=BRep_Tool::Tolerance(TopExp::LastVertex(edge)); |
94 | tolright=BRep_Tool::Tolerance(TopExp::FirstVertex(edge)); |
95 | tabtolvertex(index-1)=Max(tolleft,tolright); |
96 | } |
97 | |
98 | if(index==0){ //storage of the first edge features |
99 | First0=First; |
100 | if(edge.Orientation()==TopAbs_REVERSED){ //(usefull for the closed wire) |
101 | Vfirst=TopExp::LastVertex(edge); |
102 | tab(index)->Reverse(); |
103 | } |
104 | else |
105 | Vfirst=TopExp::FirstVertex(edge); |
106 | } |
107 | |
108 | if(index==nb_curve-1){ //storage of the last edge features |
109 | if(edge.Orientation()==TopAbs_REVERSED) |
110 | Vlast=TopExp::FirstVertex(edge); |
111 | else |
112 | Vlast=TopExp::LastVertex(edge); |
113 | } |
114 | WExp.Next() ; |
115 | } |
116 | |
117 | if (BRep_Tool::Tolerance(Vfirst)>BRep_Tool::Tolerance(Vlast)) //computation of the closing tolerance |
118 | toler=BRep_Tool::Tolerance(Vfirst); |
119 | else |
120 | toler=BRep_Tool::Tolerance(Vlast); |
121 | |
122 | Pfirst=BRep_Tool::Pnt(Vfirst); |
123 | Plast=BRep_Tool::Pnt(Vlast); |
124 | |
125 | if ((Pfirst.Distance(Plast)<=toler)&& //C0 continuity test at the closing point |
126 | (GeomLProp::Continuity(tab(nb_curve-1),tab(0),Last,First0, |
127 | Standard_True,Standard_True, |
128 | toler, TolAngular)>=GeomAbs_G1)) |
129 | { |
130 | closed_tolerance =toler; //if ClosedG1!=0 it will be True and |
131 | closed_flag = Standard_True ; |
132 | } //with the toler value |
133 | Handle(TColGeom_HArray1OfBSplineCurve) concatcurve; //array of the concatenated curves |
134 | Handle(TColStd_HArray1OfInteger) ArrayOfIndices; //array of the remining Vertex |
135 | if (Option==GeomAbs_G1) |
136 | GeomConvert::ConcatG1(tab, |
137 | tabtolvertex, |
138 | concatcurve, |
139 | closed_flag, |
140 | closed_tolerance) ; //G1 concatenation |
141 | else |
142 | GeomConvert::ConcatC1(tab, |
143 | tabtolvertex, |
144 | ArrayOfIndices, |
145 | concatcurve, |
146 | closed_flag, |
147 | closed_tolerance); //C1 concatenation |
148 | |
149 | for (index=0;index<=(concatcurve->Length()-1);index++){ //building of the resulting Wire |
150 | BRepLib_MakeEdge EdgeBuilder(concatcurve->Value(index)); |
151 | edge = EdgeBuilder.Edge(); |
152 | MakeResult.Add(edge); |
153 | } |
154 | |
155 | } |
156 | else { |
157 | TColGeom_Array1OfBSplineCurve tab(0,0); //array of the wire's curve |
158 | TColStd_Array1OfReal tabtolvertex(0,0); //array of the tolerance's vertex |
159 | WExp.Init(W); |
160 | |
161 | edge = WExp.Current() ; |
162 | tab(0) = GeomConvert::CurveToBSplineCurve(new //storage in a array |
163 | Geom_TrimmedCurve(BRep_Tool::Curve(edge,L,First,Last),First,Last)); |
164 | tab(0)->Transform(L.Transformation()); |
165 | GeomConvert::C0BSplineToC1BSplineCurve(tab(0),Precision::Confusion()); |
166 | if (edge.Orientation()==TopAbs_REVERSED) |
167 | tab(0)->Reverse(); |
168 | tolleft=BRep_Tool::Tolerance(TopExp::LastVertex(edge)); |
169 | tolright=BRep_Tool::Tolerance(TopExp::FirstVertex(edge)); |
170 | tabtolvertex(0)=Max(tolleft,tolright); |
171 | if(edge.Orientation()==TopAbs_REVERSED){ //(usefull for the closed wire) |
172 | Vfirst=TopExp::LastVertex(edge); |
173 | Vlast=TopExp::FirstVertex(edge); |
174 | } |
175 | else { |
176 | |
177 | Vfirst=TopExp::FirstVertex(edge); |
178 | Vlast = TopExp::LastVertex(edge) ; |
179 | } |
180 | Pfirst=BRep_Tool::Pnt(Vfirst); |
181 | Plast=BRep_Tool::Pnt(Vlast); |
182 | if ((Pfirst.Distance(Plast)<=toler)&& //C0 continuity test at the closing point |
183 | (GeomLProp::Continuity(tab(0),tab(0),Last,First, |
184 | Standard_True,Standard_True, |
185 | toler, TolAngular)>=GeomAbs_G1)) |
186 | { |
187 | closed_tolerance =toler; //if ClosedG1!=0 it will be True and |
188 | closed_flag = Standard_True ; |
189 | } //with the toler value |
190 | Handle(TColGeom_HArray1OfBSplineCurve) concatcurve; //array of the concatenated curves |
191 | Handle(TColStd_HArray1OfInteger) ArrayOfIndices; //array of the remining Vertex |
192 | if (Option==GeomAbs_G1) |
193 | GeomConvert::ConcatG1(tab, |
194 | tabtolvertex, |
195 | concatcurve, |
196 | closed_flag, |
197 | closed_tolerance) ; //G1 concatenation |
198 | else |
199 | GeomConvert::ConcatC1(tab, |
200 | tabtolvertex, |
201 | ArrayOfIndices, |
202 | concatcurve, |
203 | closed_flag, |
204 | closed_tolerance); //C1 concatenation |
205 | |
206 | for (index=0;index<=(concatcurve->Length()-1);index++){ //building of the resulting Wire |
207 | BRepLib_MakeEdge EdgeBuilder(concatcurve->Value(index)); |
208 | edge = EdgeBuilder.Edge(); |
209 | MakeResult.Add(edge); |
210 | } |
211 | } |
212 | return MakeResult.Wire() ; |
213 | |
214 | } |
215 | |
216 | |
217 | |
218 | |