1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 //:l8 abv 15.01.99: CTS22022: writing correct pcurves for indirect tori
15 //:p5 abv 26.02.99: PRO18207: force copying of edge if any its pcurve is to be replaced
17 //S4181 pdn 20.04.99 Modification of indirect rectangular trimming surfaces and taking
18 // locations into account
19 //szv 03.01.01 PositiveCones merged in
21 #include <BRep_Builder.hxx>
22 #include <BRep_GCurve.hxx>
23 #include <BRep_TEdge.hxx>
24 #include <BRep_Tool.hxx>
25 #include <BRepTools.hxx>
26 #include <Geom2d_Curve.hxx>
27 #include <Geom_ConicalSurface.hxx>
28 #include <Geom_Curve.hxx>
29 #include <Geom_ElementarySurface.hxx>
30 #include <Geom_RectangularTrimmedSurface.hxx>
31 #include <Geom_Surface.hxx>
34 #include <Message_Msg.hxx>
35 #include <ShapeCustom_DirectModification.hxx>
36 #include <Standard_Type.hxx>
37 #include <TopLoc_Location.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Face.hxx>
41 #include <TopoDS_Vertex.hxx>
43 IMPLEMENT_STANDARD_RTTIEXT(ShapeCustom_DirectModification,ShapeCustom_Modification)
45 //=======================================================================
46 //function : ShapeCustom_DirectModification
48 //=======================================================================
49 ShapeCustom_DirectModification::ShapeCustom_DirectModification()
53 //S4181 returns 0 - none, 1 - indirect, 2 - negative cone, 3 - indirect negative cone
54 static Standard_Integer IsIndirectSurface (Handle(Geom_Surface) &S,
57 Standard_Integer result = 0;
59 Handle(Geom_Surface) TS = S;
60 while (TS->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface)))
61 TS = Handle(Geom_RectangularTrimmedSurface)::DownCast(TS)->BasisSurface();
63 Handle(Geom_ElementarySurface) ES = Handle(Geom_ElementarySurface)::DownCast(TS);
65 // is the surface indirect ?
66 gp_Trsf t = L.Transformation();
67 Standard_Boolean neg = t.IsNegative();
68 Standard_Boolean det = ( t.VectorialPart().Determinant() < 0.0 );
69 Standard_Boolean dir = ES->Position().Direct();
70 if ((neg != det) == dir) result = 1;
71 Handle(Geom_ConicalSurface) CS = Handle(Geom_ConicalSurface)::DownCast(ES);
73 // does the cone have negative semiangle ?
74 if ( CS->SemiAngle() < 0.0 ) result += 2;
82 //=======================================================================
83 //function : NewSurface
85 //=======================================================================
87 Standard_Boolean ShapeCustom_DirectModification::NewSurface (const TopoDS_Face& F,
88 Handle(Geom_Surface)& S,
91 Standard_Boolean& RevWires,
92 Standard_Boolean& RevFace)
94 S = BRep_Tool::Surface(F,L);
96 switch (IsIndirectSurface(S,L)) {
97 case 1: { // Indirect surface
98 // UReverse a copy of S
100 RevWires = Standard_True;
101 RevFace = Standard_True;
104 case 2: { // Negative cone
105 // U- and VReverse a copy of S
108 RevWires = Standard_False;
109 RevFace = Standard_False;
112 case 3: { // Indirect negative cone
113 // VReverse a copy of S
115 RevWires = Standard_True;
116 RevFace = Standard_True;
119 default: return Standard_False;
122 SendMsg( F, Message_Msg("DirectModification.NewSurface.MSG0"));
124 Tol = BRep_Tool::Tolerance(F);
126 return Standard_True;
129 //=======================================================================
130 //function : NewCurve
132 //=======================================================================
134 Standard_Boolean ShapeCustom_DirectModification::NewCurve (const TopoDS_Edge& E,
135 Handle(Geom_Curve)& C,
139 //:p5 abv 26 Feb 99: force copying of edge if any its pcurve will be replaced
140 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&E.TShape());
142 // iterate on pcurves
143 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
144 for ( ; itcr.More(); itcr.Next() ) {
145 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(itcr.Value());
146 if ( GC.IsNull() || ! GC->IsCurveOnSurface() ) continue;
147 Handle(Geom_Surface) S = GC->Surface();
148 TopLoc_Location Loc = GC->Location();
149 if ( ! IsIndirectSurface ( S, Loc ) ) continue;
151 C = BRep_Tool::Curve ( E, L, f, l );
152 if ( ! C.IsNull() ) C = Handle(Geom_Curve)::DownCast ( C->Copy() );
153 Tol = BRep_Tool::Tolerance(E);
154 return Standard_True;
156 return Standard_False;
159 //=======================================================================
160 //function : NewPoint
162 //=======================================================================
164 Standard_Boolean ShapeCustom_DirectModification::NewPoint (const TopoDS_Vertex& /*V*/,
166 Standard_Real& /*Tol*/)
168 // 3d points are never modified
169 return Standard_False;
172 //=======================================================================
173 //function : NewCurve2d
175 //=======================================================================
177 Standard_Boolean ShapeCustom_DirectModification::NewCurve2d (const TopoDS_Edge& E,
178 const TopoDS_Face& F,
179 const TopoDS_Edge& NewE,
180 const TopoDS_Face& NewF,
181 Handle(Geom2d_Curve)& C,
185 Handle(Geom_Surface) S = BRep_Tool::Surface(F,L);
187 Standard_Integer result = IsIndirectSurface ( S, L );
188 if ( !result && E.IsSame(NewE) ) return Standard_False;
191 C = BRep_Tool::CurveOnSurface( E, F, f, l );
192 Tol = BRep_Tool::Tolerance(E);
199 case 1: { // Indirect surface
200 // mirror the PCurve about the V axis
201 T.SetMirror(gp::OY2d());
202 C = Handle(Geom2d_Curve)::DownCast(C->Transformed(T));
205 case 2: { // Negative cone
206 // mirror the PCurve about the U and V axis
207 T.SetMirror(gp::OX2d());
208 C = Handle(Geom2d_Curve)::DownCast(C->Transformed(T));
209 T.SetMirror(gp::OY2d());
213 case 3: { // Indirect negative cone
214 // mirror the PCurve about the U axis
215 T.SetMirror(gp::OX2d());
216 C = Handle(Geom2d_Curve)::DownCast(C->Transformed(T));
221 //#26 rln When seam edge contains triangulations trimming is lost by BRep_Builder::UpdateEdge
222 if (BRepTools::IsReallyClosed (E, F)) {
223 //szv#4:S4163:12Mar99 SGI warning
224 TopoDS_Shape sh = NewE.Reversed();
225 Handle(Geom2d_Curve) tmp = BRep_Tool::CurveOnSurface( TopoDS::Edge(sh), NewF, f, l );
227 tmp = BRep_Tool::CurveOnSurface (E, F, f, l);
229 B.UpdateEdge (NewE, tmp, C, NewF, Tol);
230 B.Range (NewE, NewF, f, l);
231 //anyway, tmp will be removed later by BRepTools_Modifier
236 //:p5 abv 26 Feb 99: force copying of pcurves if edge was copied
237 if ( ! C.IsNull() ) C = Handle(Geom2d_Curve)::DownCast ( C->Copy() );
240 return Standard_True;
243 //=======================================================================
244 //function : NewParameter
246 //=======================================================================
248 Standard_Boolean ShapeCustom_DirectModification::NewParameter (const TopoDS_Vertex& /*V*/,
249 const TopoDS_Edge& /*E*/,
250 Standard_Real& /*P*/,
251 Standard_Real& /*Tol*/)
253 return Standard_False;
256 //=======================================================================
257 //function : Continuity
259 //=======================================================================
261 GeomAbs_Shape ShapeCustom_DirectModification::Continuity (const TopoDS_Edge& E,
262 const TopoDS_Face& F1,
263 const TopoDS_Face& F2,
264 const TopoDS_Edge& /*NewE*/,
265 const TopoDS_Face& /*NewF1*/,
266 const TopoDS_Face& /*NewF2*/)
268 return BRep_Tool::Continuity(E,F1,F2);