0030611: Coding Rules - eliminate GCC compiler warnings -Wcatch-value
[occt.git] / src / ShapeCustom / ShapeCustom.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 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
973c2be1 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14//#71 rln 09.03.99: S4135: new class _TrsfModification and method ::ScaleShape
15// abv 08.05.99: S4190: new class and method ConvertToRevolution
16// gka 01.08.99 S4188 : new class and method LimitDegreeShape
17// abv 16.06.99 general function ApplyModifier() implemented
18// gka 21.06.99 general LimitDegreeShape renamed to BSplineRestriction
19// szv 03.01.01 PositiveCones merged with DirectFaces
20#include <ShapeCustom.hxx>
21#include <ShapeCustom_DirectModification.hxx>
22#include <ShapeCustom_TrsfModification.hxx>
23#include <ShapeCustom_ConvertToRevolution.hxx>
24#include <ShapeCustom_BSplineRestriction.hxx>
25#include <ShapeCustom_ConvertToBSpline.hxx>
26#include <ShapeCustom_SweptToElementary.hxx>
27
28#include <gp_Trsf.hxx>
29#include <GeomAbs_Shape.hxx>
30#include <TopoDS_Shape.hxx>
31#include <TopoDS_Compound.hxx>
32#include <TopoDS_Iterator.hxx>
33#include <BRep_Builder.hxx>
34#include <BRepTools_Modifier.hxx>
b350f6ee 35#include <ShapeBuild_ReShape.hxx>
36#include <Standard_ErrorHandler.hxx>
7fd59977 37
b350f6ee 38#include <Message_ProgressIndicator.hxx>
39#include <Message_ProgressSentry.hxx>
7fd59977 40
41//=======================================================================
42//function : ApplyModifier
43//purpose : static
44//=======================================================================
45
46TopoDS_Shape ShapeCustom::ApplyModifier (const TopoDS_Shape &S,
47 const Handle(BRepTools_Modification) &M,
48 TopTools_DataMapOfShapeShape &context,
b350f6ee 49 BRepTools_Modifier& MD,
50 const Handle(Message_ProgressIndicator) & aProgress,
51 const Handle(ShapeBuild_ReShape) & aReShape)
7fd59977 52{
53 // protect against INTERNAL/EXTERNAL shapes
54 TopoDS_Shape SF = S.Oriented(TopAbs_FORWARD);
55
56 // Process COMPOUNDs separately in order to handle sharing in assemblies
57 if ( SF.ShapeType() == TopAbs_COMPOUND ) {
58 Standard_Boolean locModified = Standard_False;
59 TopoDS_Compound C;
60 BRep_Builder B;
61 B.MakeCompound ( C );
b350f6ee 62
b2d1851c 63 Standard_Integer aShapeCount = SF.NbChildren();
b350f6ee 64 Message_ProgressSentry aPSentry(aProgress, "Applying Modifier For Solids", 0, aShapeCount, 1);
65 for ( TopoDS_Iterator it(SF); it.More() && aPSentry.More(); it.Next(), aPSentry.Next() ) {
7fd59977 66 TopoDS_Shape shape = it.Value();
67 TopLoc_Location L = shape.Location(), nullLoc;
68 shape.Location ( nullLoc );
69 TopoDS_Shape res;
70 if ( context.IsBound ( shape ) )
b350f6ee 71 res = context.Find ( shape ).Oriented ( shape.Orientation() );
72 else
73 res = ApplyModifier ( shape, M, context ,MD, aProgress);
74
7fd59977 75 if ( ! res.IsSame ( shape ) ) {
76 context.Bind ( shape, res );
77 locModified = Standard_True;
78 }
79 res.Location ( L );
80 B.Add ( C, res );
81 }
b350f6ee 82
83 if ( !aPSentry.More() )
84 {
85 // Was cancelled
86 return S;
87 }
88
7fd59977 89 if ( ! locModified ) return S;
90 context.Bind ( SF, C );
91 return C.Oriented ( S.Orientation() );
92 }
93
b350f6ee 94 Message_ProgressSentry aPSentry(aProgress, "Modify the Shape", 0, 1, 1);
7fd59977 95 // Modify the shape
7fd59977 96 MD.Init(SF);
b350f6ee 97 MD.Perform(M, aProgress);
98
99 if ( !aPSentry.More() || !MD.IsDone() ) return S;
100 if ( !aReShape.IsNull() )
101 {
102 for(TopoDS_Iterator theIterator(SF,Standard_False);theIterator.More();theIterator.Next())
103 {
104 const TopoDS_Shape & current = theIterator.Value();
105 TopoDS_Shape result;
106 try
107 {
108 OCC_CATCH_SIGNALS
109 result = MD.ModifiedShape( current );
110 }
a738b534 111 catch (Standard_NoSuchObject const&)
b350f6ee 112 {
113 // the sub shape isn't in the map
114 result.Nullify();
115 }
116
117 if (!result.IsNull() && !current.IsSame(result))
118 {
119 aReShape->Replace(current, result);
120 }
121 }
122 }
123
7fd59977 124 return MD.ModifiedShape(SF).Oriented(S.Orientation());
125}
126
127
128//=======================================================================
129//function : DirectFaces
130//purpose :
131//=======================================================================
132
133TopoDS_Shape ShapeCustom::DirectFaces (const TopoDS_Shape& S)
134{
135 // Create a modification description
136 Handle(ShapeCustom_DirectModification) DM =
137 new ShapeCustom_DirectModification();
138 TopTools_DataMapOfShapeShape context;
139 BRepTools_Modifier MD;
140 return ApplyModifier ( S, DM, context, MD );
141}
142
143
144//=======================================================================
145//function : ScaleShape
146//purpose :
147//=======================================================================
148
149TopoDS_Shape ShapeCustom::ScaleShape (const TopoDS_Shape& S, const Standard_Real scale)
150{
151 // Create a modification description
152 gp_Trsf T;
153 T.SetScale (gp_Pnt (0, 0, 0), scale);
154 Handle(ShapeCustom_TrsfModification) TM = new ShapeCustom_TrsfModification(T);
155 TopTools_DataMapOfShapeShape context;
156 BRepTools_Modifier MD;
157 return ShapeCustom::ApplyModifier ( S, TM, context,MD );
158}
159
160
161//=======================================================================
162//function : BSplineRestriction
163//purpose :
164//=======================================================================
165
166TopoDS_Shape ShapeCustom::BSplineRestriction (const TopoDS_Shape& S, const Standard_Real Tol3d,
167 const Standard_Real Tol2d, const Standard_Integer MaxDegree,
168 const Standard_Integer MaxNbSegment,
169 const GeomAbs_Shape Continuity3d,
170 const GeomAbs_Shape Continuity2d,
171 const Standard_Boolean Degree,
172 const Standard_Boolean Rational,
173 const Handle(ShapeCustom_RestrictionParameters)& aParameters)
174{
175 // Create a modification description
176
177 Handle(ShapeCustom_BSplineRestriction) BSR = new ShapeCustom_BSplineRestriction();
178 BSR->SetTol3d(Tol3d);
179 BSR->SetTol2d(Tol2d);
180 BSR->SetMaxDegree(MaxDegree);
181 BSR->SetMaxNbSegments(MaxNbSegment);
182 BSR->SetContinuity3d(Continuity3d);
183 BSR->SetContinuity2d(Continuity2d);
184 BSR->SetPriority(Degree);
185 BSR->SetConvRational(Rational);
186 BSR->SetRestrictionParameters(aParameters);
187 // Modify the shape
188 TopTools_DataMapOfShapeShape context;
189 BRepTools_Modifier MD;
190 return ShapeCustom::ApplyModifier ( S, BSR, context ,MD);
191}
192
193
194//=======================================================================
195//function : ConvertToRevolution
196//purpose :
197//=======================================================================
198
199TopoDS_Shape ShapeCustom::ConvertToRevolution (const TopoDS_Shape& S)
200{
201 // Create a modification description
202 Handle(ShapeCustom_ConvertToRevolution) CRev =
203 new ShapeCustom_ConvertToRevolution();
204 TopTools_DataMapOfShapeShape context;
205 BRepTools_Modifier MD;
206 return ShapeCustom::ApplyModifier ( S, CRev, context,MD );
207}
208
209
210//=======================================================================
211//function : SweptToElementary
212//purpose :
213//=======================================================================
214
215TopoDS_Shape ShapeCustom::SweptToElementary (const TopoDS_Shape& S)
216{
217 // Create a modification description
218 Handle(ShapeCustom_SweptToElementary) SE =
219 new ShapeCustom_SweptToElementary();
220 TopTools_DataMapOfShapeShape context;
221 BRepTools_Modifier MD;
222 return ShapeCustom::ApplyModifier(S,SE,context,MD);
223}
224
225
226//=======================================================================
227//function : ConvertToBSpline
228//purpose :
229//=======================================================================
230
231TopoDS_Shape ShapeCustom::ConvertToBSpline (const TopoDS_Shape& S,
232 const Standard_Boolean extrMode,
233 const Standard_Boolean revolMode,
234 const Standard_Boolean offsetMode,
235 const Standard_Boolean planeMode)
236{
237 // Create a modification description
238 Handle(ShapeCustom_ConvertToBSpline) BSRev = new ShapeCustom_ConvertToBSpline();
239 BSRev->SetExtrusionMode(extrMode);
240 BSRev->SetRevolutionMode(revolMode);
241 BSRev->SetOffsetMode(offsetMode);
242 BSRev->SetPlaneMode(planeMode);
243 TopTools_DataMapOfShapeShape context;
244 BRepTools_Modifier MD;
245 return ShapeCustom::ApplyModifier ( S, BSRev, context, MD);
246}