7fd59977 |
1 | //:l8 abv 15.01.99: CTS22022: writing correct pcurves for indirect tori |
2 | //:p5 abv 26.02.99: PRO18207: force copying of edge if any its pcurve is to be replaced |
3 | //szv#4 S4163 |
4 | //S4181 pdn 20.04.99 Modification of indirect rectangular trimming surfaces and taking |
5 | // locations into account |
6 | //szv 03.01.01 PositiveCones merged in |
7 | #include <ShapeCustom_DirectModification.ixx> |
8 | |
9 | #include <gp_Mat.hxx> |
10 | #include <Geom_ConicalSurface.hxx> |
11 | #include <Geom_ElementarySurface.hxx> |
12 | #include <Geom_RectangularTrimmedSurface.hxx> |
13 | |
14 | #include <Precision.hxx> |
15 | #include <TopoDS.hxx> |
16 | #include <BRep_Builder.hxx> |
17 | #include <BRep_Tool.hxx> |
18 | #include <BRepTools.hxx> |
19 | #include <BRep_TEdge.hxx> |
20 | #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx> |
21 | #include <BRep_GCurve.hxx> |
22 | |
23 | //======================================================================= |
24 | //function : ShapeCustom_DirectModification |
25 | //purpose : |
26 | //======================================================================= |
27 | |
28 | ShapeCustom_DirectModification::ShapeCustom_DirectModification() |
29 | { |
30 | } |
31 | |
32 | //S4181 returns 0 - none, 1 - indirect, 2 - negative cone, 3 - indirect negative cone |
33 | static Standard_Integer IsIndirectSurface (Handle(Geom_Surface) &S, |
34 | TopLoc_Location &L) |
35 | { |
36 | Standard_Integer result = 0; |
37 | |
38 | Handle(Geom_Surface) TS = S; |
39 | while (TS->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) |
40 | TS = Handle(Geom_RectangularTrimmedSurface)::DownCast(TS)->BasisSurface(); |
41 | |
42 | Handle(Geom_ElementarySurface) ES = Handle(Geom_ElementarySurface)::DownCast(TS); |
43 | if (!ES.IsNull()) { |
44 | // is the surface indirect ? |
45 | gp_Trsf t = L.Transformation(); |
46 | Standard_Boolean neg = t.IsNegative(); |
47 | Standard_Boolean det = ( t.VectorialPart().Determinant() < 0.0 ); |
48 | Standard_Boolean dir = ES->Position().Direct(); |
49 | if ( (Standard_Boolean)( neg != det ) == dir ) result = 1; |
50 | Handle(Geom_ConicalSurface) CS = Handle(Geom_ConicalSurface)::DownCast(ES); |
51 | if (!CS.IsNull()) { |
52 | // does the cone have negative semiangle ? |
53 | if ( CS->SemiAngle() < 0.0 ) result += 2; |
54 | } |
55 | if (result) S = TS; |
56 | } |
57 | |
58 | return result; |
59 | } |
60 | |
61 | //======================================================================= |
62 | //function : NewSurface |
63 | //purpose : |
64 | //======================================================================= |
65 | |
66 | Standard_Boolean ShapeCustom_DirectModification::NewSurface (const TopoDS_Face& F, |
67 | Handle(Geom_Surface)& S, |
68 | TopLoc_Location& L, |
69 | Standard_Real& Tol, |
70 | Standard_Boolean& RevWires, |
71 | Standard_Boolean& RevFace) |
72 | { |
73 | S = BRep_Tool::Surface(F,L); |
74 | |
75 | switch (IsIndirectSurface(S,L)) { |
76 | case 1: { // Indirect surface |
77 | // UReverse a copy of S |
78 | S = S->UReversed(); |
79 | RevWires = Standard_True; |
80 | RevFace = Standard_True; |
81 | break; |
82 | } |
83 | case 2: { // Negative cone |
84 | // U- and VReverse a copy of S |
85 | S = S->VReversed(); |
86 | S->UReverse(); |
87 | RevWires = Standard_False; |
88 | RevFace = Standard_False; |
89 | break; |
90 | } |
91 | case 3: { // Indirect negative cone |
92 | // VReverse a copy of S |
93 | S = S->VReversed(); |
94 | RevWires = Standard_True; |
95 | RevFace = Standard_True; |
96 | break; |
97 | } |
98 | default: return Standard_False; |
99 | } |
100 | |
101 | Tol = BRep_Tool::Tolerance(F); |
102 | |
103 | return Standard_True; |
104 | } |
105 | |
106 | //======================================================================= |
107 | //function : NewCurve |
108 | //purpose : |
109 | //======================================================================= |
110 | |
111 | Standard_Boolean ShapeCustom_DirectModification::NewCurve (const TopoDS_Edge& E, |
112 | Handle(Geom_Curve)& C, |
113 | TopLoc_Location& L, |
114 | Standard_Real& Tol) |
115 | { |
116 | //:p5 abv 26 Feb 99: force copying of edge if any its pcurve will be replaced |
117 | Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&E.TShape()); |
118 | |
119 | // iterate on pcurves |
120 | BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves()); |
121 | for ( ; itcr.More(); itcr.Next() ) { |
122 | Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value()); |
123 | if ( GC.IsNull() || ! GC->IsCurveOnSurface() ) continue; |
124 | Handle(Geom_Surface) S = GC->Surface(); |
125 | TopLoc_Location Loc = GC->Location(); |
126 | if ( ! IsIndirectSurface ( S, Loc ) ) continue; |
127 | Standard_Real f, l; |
128 | C = BRep_Tool::Curve ( E, L, f, l ); |
129 | if ( ! C.IsNull() ) C = Handle(Geom_Curve)::DownCast ( C->Copy() ); |
130 | Tol = BRep_Tool::Tolerance(E); |
131 | return Standard_True; |
132 | } |
133 | return Standard_False; |
134 | } |
135 | |
136 | //======================================================================= |
137 | //function : NewPoint |
138 | //purpose : |
139 | //======================================================================= |
140 | |
141 | Standard_Boolean ShapeCustom_DirectModification::NewPoint (const TopoDS_Vertex& /*V*/, |
142 | gp_Pnt& /*P*/, |
143 | Standard_Real& /*Tol*/) |
144 | { |
145 | // 3d points are never modified |
146 | return Standard_False; |
147 | } |
148 | |
149 | //======================================================================= |
150 | //function : NewCurve2d |
151 | //purpose : |
152 | //======================================================================= |
153 | |
154 | Standard_Boolean ShapeCustom_DirectModification::NewCurve2d (const TopoDS_Edge& E, |
155 | const TopoDS_Face& F, |
156 | const TopoDS_Edge& NewE, |
157 | const TopoDS_Face& NewF, |
158 | Handle(Geom2d_Curve)& C, |
159 | Standard_Real& Tol) |
160 | { |
161 | TopLoc_Location L; |
162 | Handle(Geom_Surface) S = BRep_Tool::Surface(F,L); |
163 | |
164 | Standard_Integer result = IsIndirectSurface ( S, L ); |
165 | if ( !result && E.IsSame(NewE) ) return Standard_False; |
166 | |
167 | Standard_Real f, l; |
168 | C = BRep_Tool::CurveOnSurface( E, F, f, l ); |
169 | Tol = BRep_Tool::Tolerance(E); |
170 | |
171 | if ( result ) { |
172 | |
173 | gp_Trsf2d T; |
174 | |
175 | switch (result) { |
176 | case 1: { // Indirect surface |
177 | // mirror the PCurve about the V axis |
178 | T.SetMirror(gp::OY2d()); |
179 | C = Handle(Geom2d_Curve)::DownCast(C->Transformed(T)); |
180 | break; |
181 | } |
182 | case 2: { // Negative cone |
183 | // mirror the PCurve about the U and V axis |
184 | T.SetMirror(gp::OX2d()); |
185 | C = Handle(Geom2d_Curve)::DownCast(C->Transformed(T)); |
186 | T.SetMirror(gp::OY2d()); |
187 | C->Transform(T); |
188 | break; |
189 | } |
190 | case 3: { // Indirect negative cone |
191 | // mirror the PCurve about the U axis |
192 | T.SetMirror(gp::OX2d()); |
193 | C = Handle(Geom2d_Curve)::DownCast(C->Transformed(T)); |
194 | break; |
195 | } |
196 | } |
197 | |
198 | //#26 rln When seam edge contains triangulations trimming is lost by BRep_Builder::UpdateEdge |
199 | if (BRepTools::IsReallyClosed (E, F)) { |
200 | //szv#4:S4163:12Mar99 SGI warning |
201 | TopoDS_Shape sh = NewE.Reversed(); |
202 | Handle(Geom2d_Curve) tmp = BRep_Tool::CurveOnSurface( TopoDS::Edge(sh), NewF, f, l ); |
203 | if (tmp.IsNull()) { |
204 | tmp = BRep_Tool::CurveOnSurface (E, F, f, l); |
205 | BRep_Builder B; |
206 | B.UpdateEdge (NewE, tmp, C, NewF, Tol); |
207 | B.Range (NewE, NewF, f, l); |
208 | //anyway, tmp will be removed later by BRepTools_Modifier |
209 | } |
210 | } |
211 | } |
212 | else { |
213 | //:p5 abv 26 Feb 99: force copying of pcurves if edge was copied |
214 | if ( ! C.IsNull() ) C = Handle(Geom2d_Curve)::DownCast ( C->Copy() ); |
215 | } |
216 | |
217 | return Standard_True; |
218 | } |
219 | |
220 | //======================================================================= |
221 | //function : NewParameter |
222 | //purpose : |
223 | //======================================================================= |
224 | |
225 | Standard_Boolean ShapeCustom_DirectModification::NewParameter (const TopoDS_Vertex& /*V*/, |
226 | const TopoDS_Edge& /*E*/, |
227 | Standard_Real& /*P*/, |
228 | Standard_Real& /*Tol*/) |
229 | { |
230 | return Standard_False; |
231 | } |
232 | |
233 | //======================================================================= |
234 | //function : Continuity |
235 | //purpose : |
236 | //======================================================================= |
237 | |
238 | GeomAbs_Shape ShapeCustom_DirectModification::Continuity (const TopoDS_Edge& E, |
239 | const TopoDS_Face& F1, |
240 | const TopoDS_Face& F2, |
241 | const TopoDS_Edge& /*NewE*/, |
242 | const TopoDS_Face& /*NewF1*/, |
243 | const TopoDS_Face& /*NewF2*/) |
244 | { |
245 | return BRep_Tool::Continuity(E,F1,F2); |
246 | } |