1 // File: ShapeFix_Shape.cxx
2 // Created: Wed Aug 09 12:27:47 1999
3 // Author: Galina Kulikova
4 // <gka@nnov.matra-dtv.fr>
6 #include <ShapeFix_Shape.ixx>
8 #include <Precision.hxx>
11 #include <TopoDS_Edge.hxx>
12 #include <TopoDS_Wire.hxx>
13 #include <TopoDS_Face.hxx>
14 #include <TopoDS_Iterator.hxx>
15 #include <TopExp_Explorer.hxx>
17 #include <TopAbs_ShapeEnum.hxx>
18 #include <BRepTools.hxx>
19 #include <BRep_Builder.hxx>
21 #include <ShapeFix.hxx>
22 #include <ShapeBuild_ReShape.hxx>
23 #include <ShapeFix_Edge.hxx>
24 #include <ShapeFix_Wire.hxx>
25 #include <ShapeFix_Face.hxx>
26 #include <ShapeFix_Shell.hxx>
27 #include <ShapeFix_Solid.hxx>
29 #include <Message_ProgressSentry.hxx>
31 //=======================================================================
32 //function : ShapeFix_Shape
34 //=======================================================================
36 ShapeFix_Shape::ShapeFix_Shape()
38 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
43 myFixSameParameterMode = -1;
44 myFixVertexPositionMode =0;
45 myFixSolid = new ShapeFix_Solid;
48 //=======================================================================
49 //function : ShapeFix_Shape
51 //=======================================================================
53 ShapeFix_Shape::ShapeFix_Shape(const TopoDS_Shape& shape)
55 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
60 myFixSameParameterMode = -1;
61 myFixSolid = new ShapeFix_Solid;
62 myFixVertexPositionMode =0;
66 //=======================================================================
69 //=======================================================================
71 void ShapeFix_Shape::Init(const TopoDS_Shape& shape)
74 if ( Context().IsNull() ) {
75 SetContext ( new ShapeBuild_ReShape );
76 Context()->ModeConsiderLocation() = Standard_True;
81 //=======================================================================
84 //=======================================================================
86 Standard_Boolean ShapeFix_Shape::Perform(const Handle(Message_ProgressIndicator)& theProgress)
88 Standard_Integer savFixSmallAreaWireMode = 0;
90 Handle(ShapeFix_Face) fft = Handle(ShapeFix_Face)::DownCast( FixFaceTool() );
91 if ( !fft.IsNull() ) {
92 savFixSmallAreaWireMode = fft->FixSmallAreaWireMode();
93 if ( savFixSmallAreaWireMode == -1 &&
94 myShape.ShapeType() == TopAbs_FACE ) {
95 fft->FixSmallAreaWireMode() = Standard_True;
99 myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
100 Standard_Boolean status = Standard_False;
103 //gka fix for sharing assembly
104 TopLoc_Location nullLoc,L;
105 L = myShape.Location();
106 TopoDS_Shape aShapeNullLoc = myShape;
107 aShapeNullLoc.Location(nullLoc);
108 if(myMapFixingShape.Contains(aShapeNullLoc)) {
110 myResult = Context()->Apply(myShape);
111 status = Standard_True;
114 else myMapFixingShape.Add(aShapeNullLoc);
115 //---------------------------------------
117 TopoDS_Shape S = Context()->Apply(myShape);
118 if ( NeedFix ( myFixVertexPositionMode ) )
119 ShapeFix::FixVertexPosition(S,Precision(),Context());
123 // Open progress indication scope for the following fix stages:
124 // - Fix on Solid or Shell;
125 // - Fix same parameterization;
126 Message_ProgressSentry aPSentry(theProgress, "Fixing stage", 0, 2, 1);
129 case TopAbs_COMPOUND:
130 case TopAbs_COMPSOLID: {
131 TopoDS_Shape shape = myShape;
132 Standard_Boolean savFixSameParameterMode = myFixSameParameterMode;
133 myFixSameParameterMode = Standard_False;
135 Standard_Integer aShapesNb = 0;
136 for ( TopoDS_Iterator anIter(S); anIter.More(); anIter.Next() )
139 // Open progress indication scope for sub-shape fixing
140 Message_ProgressSentry aPSentry(theProgress, "Fixing sub-shape", 0, aShapesNb, 1);
141 for ( TopoDS_Iterator anIter(S); anIter.More() && aPSentry.More(); anIter.Next(), aPSentry.Next() )
143 myShape = anIter.Value();
144 if ( Perform(theProgress) )
145 status = Standard_True;
147 if ( !aPSentry.More() )
148 return Standard_False; // aborted execution
150 myFixSameParameterMode = savFixSameParameterMode;
155 if ( !NeedFix(myFixSolidMode) )
157 myFixSolid->Init(TopoDS::Solid(S));
158 myFixSolid->SetContext(Context());
160 if ( myFixSolid->Perform(theProgress) )
161 status = Standard_True;
163 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE4 );
167 if ( !NeedFix(myFixShellMode) )
169 Handle(ShapeFix_Shell) sfsh = FixShellTool();
170 sfsh->Init( TopoDS::Shell(S) );
171 sfsh->SetContext( Context() );
173 if ( sfsh->Perform(theProgress) )
174 status = Standard_True;
176 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE4 );
180 if ( ! NeedFix ( myFixFaceMode ) ) break;
181 Handle(ShapeFix_Face) sff = FixFaceTool();
182 Standard_Integer savTopoMode = sff->FixWireTool()->ModifyTopologyMode();
183 sff->FixWireTool()->ModifyTopologyMode() = Standard_True;
184 sff->Init(TopoDS::Face(S));
185 sff->SetContext(Context());
188 status = Standard_True;
190 sff->FixWireTool()->ModifyTopologyMode() = savTopoMode;
191 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
195 if ( ! NeedFix ( myFixWireMode ) ) break;
196 Handle(ShapeFix_Wire) sfw = FixWireTool();
197 Standard_Integer savTopoMode = sfw->ModifyTopologyMode();
198 Standard_Integer savClosedMode = sfw->ClosedWireMode();
199 sfw->ModifyTopologyMode() = Standard_True;
201 sfw->ClosedWireMode() = Standard_False;
202 sfw->SetFace(TopoDS_Face());
203 sfw->Load(TopoDS::Wire(S));
204 sfw->SetContext(Context());
206 status = Standard_True;
207 Context()->Replace(S,sfw->Wire()); // replace for wire only
209 sfw->ModifyTopologyMode() = savTopoMode;
210 sfw->ClosedWireMode() = savClosedMode;
211 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
215 Handle(ShapeFix_Edge) sfe = FixEdgeTool();
216 if(sfe->FixVertexTolerance(TopoDS::Edge(S)))
217 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
225 // Switch to the second progress indication scope if it exists
228 myResult = Context()->Apply(S);
230 if ( NeedFix(myFixSameParameterMode) )
232 SameParameter(myResult, Standard_False, theProgress);
236 fft->FixSmallAreaWireMode() = savFixSmallAreaWireMode;
241 //=======================================================================
242 //function : SameParameter
244 //=======================================================================
246 void ShapeFix_Shape::SameParameter(const TopoDS_Shape& sh,
247 const Standard_Boolean enforce,
248 const Handle(Message_ProgressIndicator)& theProgress)
250 ShapeFix::SameParameter(sh, enforce, 0.0, theProgress);
253 //=======================================================================
256 //=======================================================================
258 TopoDS_Shape ShapeFix_Shape::Shape() const
263 //=======================================================================
264 //function : SetMsgRegistrator
266 //=======================================================================
268 void ShapeFix_Shape::SetMsgRegistrator(const Handle(ShapeExtend_BasicMsgRegistrator)& msgreg)
270 ShapeFix_Root::SetMsgRegistrator ( msgreg );
271 myFixSolid->SetMsgRegistrator ( msgreg );
274 //=======================================================================
275 //function : SetPrecision
277 //=======================================================================
279 void ShapeFix_Shape::SetPrecision (const Standard_Real preci)
281 ShapeFix_Root::SetPrecision ( preci );
282 myFixSolid->SetPrecision ( preci );
285 //=======================================================================
286 //function : SetMinTolerance
288 //=======================================================================
290 void ShapeFix_Shape::SetMinTolerance (const Standard_Real mintol)
292 ShapeFix_Root::SetMinTolerance ( mintol );
293 myFixSolid->SetMinTolerance ( mintol );
296 //=======================================================================
297 //function : SetMaxTolerance
299 //=======================================================================
301 void ShapeFix_Shape::SetMaxTolerance (const Standard_Real maxtol)
303 ShapeFix_Root::SetMaxTolerance ( maxtol );
304 myFixSolid->SetMaxTolerance ( maxtol );
306 //=======================================================================
309 //=======================================================================
311 Standard_Boolean ShapeFix_Shape::Status (const ShapeExtend_Status status) const
313 return ShapeExtend::DecodeStatus ( myStatus, status );