Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2000-01-19 |
2 | // Created by: data exchange team | |
973c2be1 | 3 | // Copyright (c) 2000-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
11 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
7fd59977 | 15 | |
7fd59977 | 16 | |
7fd59977 | 17 | #include <BRep_Builder.hxx> |
42cf5bc1 | 18 | #include <BRep_Tool.hxx> |
7fd59977 | 19 | #include <BRepBuilderAPI_MakeEdge.hxx> |
42cf5bc1 | 20 | #include <Geom2d_Curve.hxx> |
21 | #include <Geom_Curve.hxx> | |
22 | #include <Geom_Surface.hxx> | |
23 | #include <gp_Pnt.hxx> | |
24 | #include <gp_Pnt2d.hxx> | |
25 | #include <Interface_Static.hxx> | |
26 | #include <Message_ListIteratorOfListOfMsg.hxx> | |
27 | #include <Message_ListOfMsg.hxx> | |
28 | #include <Message_Msg.hxx> | |
29 | #include <Message_ProgressIndicator.hxx> | |
30 | #include <Resource_Manager.hxx> | |
7fd59977 | 31 | #include <ShapeAlgo.hxx> |
32 | #include <ShapeAlgo_AlgoContainer.hxx> | |
33 | #include <ShapeAlgo_ToolContainer.hxx> | |
42cf5bc1 | 34 | #include <ShapeAnalysis_Edge.hxx> |
35 | #include <ShapeBuild_Edge.hxx> | |
7fd59977 | 36 | #include <ShapeBuild_ReShape.hxx> |
42cf5bc1 | 37 | #include <ShapeCustom.hxx> |
7fd59977 | 38 | #include <ShapeExtend_DataMapOfShapeListOfMsg.hxx> |
39 | #include <ShapeExtend_MsgRegistrator.hxx> | |
7fd59977 | 40 | #include <ShapeFix_Edge.hxx> |
42cf5bc1 | 41 | #include <ShapeFix_Shape.hxx> |
42 | #include <ShapeProcess.hxx> | |
43 | #include <ShapeProcess_ShapeContext.hxx> | |
44 | #include <Standard_ErrorHandler.hxx> | |
45 | #include <Standard_Failure.hxx> | |
46 | #include <Standard_Transient.hxx> | |
47 | #include <Standard_Type.hxx> | |
48 | #include <TopExp.hxx> | |
49 | #include <TopoDS.hxx> | |
50 | #include <TopoDS_Edge.hxx> | |
51 | #include <TopoDS_Face.hxx> | |
52 | #include <TopoDS_Iterator.hxx> | |
53 | #include <TopoDS_Shape.hxx> | |
54 | #include <TopoDS_Vertex.hxx> | |
55 | #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx> | |
56 | #include <TopTools_DataMapOfShapeShape.hxx> | |
57 | #include <Transfer_FinderProcess.hxx> | |
58 | #include <Transfer_TransientListBinder.hxx> | |
59 | #include <Transfer_TransientProcess.hxx> | |
7fd59977 | 60 | #include <TransferBRep.hxx> |
7fd59977 | 61 | #include <TransferBRep_ShapeBinder.hxx> |
42cf5bc1 | 62 | #include <TransferBRep_ShapeMapper.hxx> |
63 | #include <UnitsMethods.hxx> | |
64 | #include <XSAlgo_AlgoContainer.hxx> | |
65 | #include <XSAlgo_ToolContainer.hxx> | |
53446383 | 66 | #include <TopExp_Explorer.hxx> |
7fd59977 | 67 | |
92efcf78 | 68 | IMPLEMENT_STANDARD_RTTIEXT(XSAlgo_AlgoContainer,MMgt_TShared) |
69 | ||
7fd59977 | 70 | //======================================================================= |
71 | //function : XSAlgo_AlgoContainer | |
72 | //purpose : | |
73 | //======================================================================= | |
7fd59977 | 74 | XSAlgo_AlgoContainer::XSAlgo_AlgoContainer() |
75 | { | |
76 | myTC = new XSAlgo_ToolContainer; | |
77 | } | |
78 | ||
79 | //======================================================================= | |
80 | //function : PrepareForTransfer | |
81 | //purpose : | |
82 | //======================================================================= | |
83 | ||
84 | void XSAlgo_AlgoContainer::PrepareForTransfer() const | |
85 | { | |
86 | UnitsMethods::SetCasCadeLengthUnit ( Interface_Static::IVal("xstep.cascade.unit") ); | |
87 | } | |
88 | ||
89 | //======================================================================= | |
90 | //function : ProcessShape | |
91 | //purpose : | |
92 | //======================================================================= | |
93 | ||
94 | TopoDS_Shape XSAlgo_AlgoContainer::ProcessShape (const TopoDS_Shape& shape, | |
95 | const Standard_Real Prec, | |
96 | const Standard_Real maxTol, | |
97 | const Standard_CString prscfile, | |
98 | const Standard_CString pseq, | |
b485ee79 KD |
99 | Handle(Standard_Transient)& info, |
100 | const Handle(Message_ProgressIndicator)& progress) const | |
7fd59977 | 101 | { |
102 | if ( shape.IsNull() ) return shape; | |
103 | ||
b485ee79 KD |
104 | Handle(ShapeProcess_ShapeContext) context = Handle(ShapeProcess_ShapeContext)::DownCast(info); |
105 | if ( context.IsNull() ) | |
106 | { | |
107 | Standard_CString rscfile = Interface_Static::CVal(prscfile); | |
108 | if (!rscfile) | |
109 | rscfile = prscfile; | |
110 | context = new ShapeProcess_ShapeContext(shape, rscfile); | |
111 | context->SetDetalisation(TopAbs_EDGE); | |
112 | if ( !progress.IsNull() ) | |
113 | context->SetProgress(progress); | |
7fd59977 | 114 | } |
115 | info = context; | |
116 | ||
117 | Standard_CString seq = Interface_Static::CVal ( pseq ); | |
118 | if ( ! seq ) seq = pseq; | |
119 | ||
120 | // if resource file is not loaded or does not define <seq>.exec.op, | |
121 | // do default fixes | |
122 | Handle(Resource_Manager) rsc = context->ResourceManager(); | |
123 | TCollection_AsciiString str ( seq ); | |
124 | str += ".exec.op"; | |
125 | if ( ! rsc->Find ( str.ToCString() ) ) { | |
0797d9d3 | 126 | #ifdef OCCT_DEBUG |
7fd59977 | 127 | { |
128 | static Standard_Integer time = 0; | |
129 | if ( ! time ) | |
130 | cout << "Warning: XSAlgo_AlgoContainer::ProcessShape(): Sequence " << str.ToCString() << | |
131 | " is not defined in " << prscfile << " resource; do default processing" << endl; | |
132 | time++; | |
133 | } | |
134 | #endif | |
881536e2 | 135 | // if reading, do default ShapeFix |
7fd59977 | 136 | if ( ! strncmp ( pseq, "read.", 5 ) ) { |
137 | try { | |
138 | OCC_CATCH_SIGNALS | |
139 | Handle(ShapeExtend_MsgRegistrator) msg = new ShapeExtend_MsgRegistrator; | |
140 | Handle(ShapeFix_Shape) sfs = ShapeAlgo::AlgoContainer()->ToolContainer()->FixShape(); | |
141 | sfs->Init ( shape ); | |
142 | sfs->SetMsgRegistrator ( msg ); | |
143 | sfs->SetPrecision ( Prec ); | |
144 | sfs->SetMaxTolerance ( maxTol ); | |
145 | sfs->FixFaceTool()->FixWireTool()->FixSameParameterMode() = Standard_False; | |
146 | sfs->FixSolidTool()->CreateOpenSolidMode() = Standard_False; | |
b485ee79 | 147 | sfs->Perform(progress); |
7fd59977 | 148 | |
149 | TopoDS_Shape S = sfs->Shape(); | |
150 | if ( ! S.IsNull() && S != shape ) { | |
151 | context->RecordModification ( sfs->Context(), msg ); | |
152 | context->SetResult ( S ); | |
153 | } | |
154 | } | |
155 | catch (Standard_Failure) { | |
0797d9d3 | 156 | #ifdef OCCT_DEBUG |
7fd59977 | 157 | cout << "Error: XSAlgo_AlgoContainer::ProcessShape(): Exception in ShapeFix::Shape" << endl; |
158 | Standard_Failure::Caught()->Print(cout); cout << endl; | |
159 | #endif | |
160 | } | |
161 | return context->Result(); | |
162 | } | |
881536e2 | 163 | // for writing, define default sequence of DirectFaces |
164 | else if ( ! strncmp ( pseq, "write.", 6 ) ) { | |
7fd59977 | 165 | rsc->SetResource ( str.ToCString(), "DirectFaces" ); |
166 | } | |
167 | } | |
168 | ||
169 | // Define runtime tolerances and do Shape Processing | |
170 | rsc->SetResource ( "Runtime.Tolerance", Prec ); | |
171 | rsc->SetResource ( "Runtime.MaxTolerance", maxTol ); | |
b485ee79 KD |
172 | |
173 | if ( !ShapeProcess::Perform(context, seq) ) | |
881536e2 | 174 | return shape; // return original shape |
b485ee79 | 175 | |
7fd59977 | 176 | return context->Result(); |
177 | } | |
178 | ||
179 | //======================================================================= | |
180 | //function : PerformFixShape | |
181 | //purpose : | |
182 | //======================================================================= | |
183 | ||
184 | /* | |
185 | TopoDS_Shape XSAlgo_AlgoContainer::PerformFixShape(const TopoDS_Shape& S, | |
186 | const Handle(Transfer_TransientProcess)& TP, | |
187 | const Standard_Real Prec, | |
188 | const Standard_Real MaxTol) const | |
189 | { | |
190 | if ( S.IsNull() ) return S; | |
191 | ||
192 | TopoDS_Shape shape = S; | |
193 | // fixing shape | |
194 | try { | |
195 | OCC_CATCH_SIGNALS | |
196 | Handle(ShapeFix_Shape) sfs = ShapeAlgo::AlgoContainer()->ToolContainer()->FixShape(); | |
197 | sfs->Init ( S ); | |
198 | sfs->SetMsgRegistrator ( new ShapeExtend_MsgRegistrator ); | |
199 | sfs->SetPrecision ( Prec ); | |
200 | sfs->SetMaxTolerance ( MaxTol ); | |
201 | sfs->FixFaceTool()->FixWireTool()->FixSameParameterMode() = Standard_False; | |
202 | sfs->Perform(); | |
203 | ||
204 | shape = sfs->Shape(); | |
205 | ||
206 | // to be removed when messages come | |
207 | if ( shape == S || shape.IsNull() ) return S; | |
208 | ||
209 | // update map to reflect the substitutions | |
210 | Handle(ShapeBuild_ReShape) context = sfs->Context(); | |
211 | const ShapeExtend_DataMapOfShapeListOfMsg& msgmap = | |
212 | Handle(ShapeExtend_MsgRegistrator)::DownCast (sfs->MsgRegistrator())->MapShape(); | |
213 | for ( Standard_Integer i=1; i <= TP->NbMapped(); i++ ) { | |
214 | Handle(Transfer_Binder) bnd = TP->MapItem ( i ); | |
215 | Handle(TransferBRep_ShapeBinder) sb = Handle(TransferBRep_ShapeBinder)::DownCast ( bnd ); | |
216 | if ( sb.IsNull() || sb->Result().IsNull() ) continue; | |
217 | ||
218 | TopoDS_Shape orig = sb->Result(); | |
219 | ||
220 | // update messages (messages must be taken from each level in the substitution map) | |
221 | TopoDS_Shape cur, next = orig; | |
222 | do { | |
223 | cur = next; | |
224 | Message_ListOfMsg msglist; | |
225 | if (msgmap.IsBound (cur)) { | |
226 | msglist = msgmap.Find (cur); | |
227 | for (Message_ListIteratorOfListOfMsg iter (msglist); iter.More(); iter.Next()) { | |
228 | const Message_Msg& msg = iter.Value(); | |
229 | sb->AddWarning (msg.Value(), msg.Original()); | |
230 | } | |
231 | } | |
232 | next = context->Value (cur); | |
233 | } while (cur != next); | |
234 | ||
235 | // update shapes | |
236 | TopoDS_Shape res; | |
237 | if ( ! context->Status ( orig, res, Standard_True ) ) continue; | |
238 | ||
239 | sb->SetResult ( res ); | |
240 | } | |
241 | } | |
242 | catch (Standard_Failure) { | |
0797d9d3 | 243 | #ifdef OCCT_DEBUG |
7fd59977 | 244 | cout << "Error: XSAlgo_AlgoContainer::PerformFixShape(): Exception in ShapeFix::Shape" << endl; |
245 | #endif | |
246 | } | |
247 | return shape; | |
248 | } | |
249 | */ | |
250 | ||
251 | // ============================================================================ | |
252 | // Method : MakeEdgeOnCurve | |
253 | // Purpose : for CheckPCurve | |
254 | // ============================================================================ | |
255 | ||
256 | static TopoDS_Edge MakeEdgeOnCurve(const TopoDS_Edge edge) | |
257 | { | |
258 | TopoDS_Edge result; | |
259 | //BRep_Builder B; // B not used - see below (skl) | |
260 | Handle(Geom_Curve) C3d; | |
261 | ShapeAnalysis_Edge sae; | |
262 | Standard_Real cf, cl; | |
263 | if (!sae.Curve3d (edge, C3d, cf, cl, Standard_False )) | |
264 | return result; | |
265 | gp_Pnt PV1 = C3d->Value(cf); | |
266 | gp_Pnt PV2 = C3d->Value(cl); | |
267 | BRepBuilderAPI_MakeEdge mkEdge(C3d, PV1, PV2, cf, cl); | |
268 | //:S4136 Standard_Real tol = BRep_Tool::Tolerance (edge); | |
269 | ShapeBuild_Edge SBE; //skl 10.07.2001 | |
270 | SBE.SetRange3d(mkEdge,cf,cl); //skl 10.07.2001 | |
271 | result = mkEdge.Edge(); | |
272 | //:S4136 B.UpdateEdge(result,tol); | |
273 | return result; | |
274 | } | |
275 | ||
276 | //======================================================================= | |
277 | //function : CheckPCurve | |
278 | //purpose : | |
279 | //======================================================================= | |
280 | ||
281 | Standard_Boolean XSAlgo_AlgoContainer::CheckPCurve (const TopoDS_Edge& E, | |
282 | const TopoDS_Face& face, | |
283 | const Standard_Real preci, | |
284 | const Standard_Boolean isSeam) const | |
285 | { | |
286 | Standard_Real w1, w2; | |
287 | Handle(Geom2d_Curve) thePC; | |
288 | ShapeAnalysis_Edge sae; | |
289 | if ( ! sae.PCurve (E, face, thePC, w1, w2, Standard_False ) ) { | |
290 | return Standard_False; | |
291 | } | |
292 | ||
293 | // Check for pcurve longer than surface | |
294 | Handle(Geom_Surface) surf = BRep_Tool::Surface(face); | |
295 | Standard_Real UF,UL,VF,VL; | |
296 | surf->Bounds (UF,UL,VF,VL); | |
297 | gp_Pnt2d PUV1, PUV2; | |
298 | PUV1 = thePC->Value(w1); | |
299 | PUV2 = thePC->Value(w2); | |
300 | // Multi-periodique ? mieux vaut jeter (attention aux valeurs infinies) | |
301 | Standard_Real DU = Abs (PUV1.X() - PUV2.X()); | |
302 | Standard_Real DV = Abs (PUV1.Y() - PUV2.Y()); | |
303 | if ( DU/8. > (UL/6. - UF/6.) || DV/8. > (VL/6. - VF/6.) ) { | |
304 | ShapeBuild_Edge().RemovePCurve(E,face); | |
0797d9d3 | 305 | #ifdef OCCT_DEBUG |
7fd59977 | 306 | cout<<"Removing pcuve periodic"<<endl; |
307 | #endif | |
308 | return Standard_False; | |
309 | } | |
310 | ||
311 | // Second Check : 2D and 3D consistency (if the Pcurve has not been | |
312 | // dropped) | |
313 | // On verifie aussi qu on ne s enroule pas trop ... | |
314 | // ex. : UVV en DEGRES sur une surface en RADIANS, recalee = 57 tours ! | |
315 | ||
316 | Handle(Geom_Curve) C3d; | |
317 | Standard_Real cf1, cl1; | |
318 | sae.Curve3d (E, C3d, cf1, cl1, Standard_False ); | |
319 | ||
320 | gp_Pnt P1 = surf->Value(PUV1.X(), PUV1.Y()); | |
321 | gp_Pnt P2 = surf->Value(PUV2.X(), PUV2.Y()); | |
322 | TopoDS_Vertex V1 = TopExp::FirstVertex(E); | |
323 | TopoDS_Vertex V2 = TopExp::LastVertex(E); | |
324 | gp_Pnt PV1 = ( C3d.IsNull() ? BRep_Tool::Pnt(V1) : C3d->Value(cf1) ); | |
325 | gp_Pnt PV2 = ( C3d.IsNull() ? BRep_Tool::Pnt(V2) : C3d->Value(cl1) ); | |
326 | Standard_Real Dist11 = PV1.Distance(P1), Dist22 = PV2.Distance(P2); | |
327 | ||
328 | if (!((Dist11 <= preci) && (Dist22 <= preci))) { | |
329 | ShapeBuild_Edge().RemovePCurve(E,face); | |
0797d9d3 | 330 | #ifdef OCCT_DEBUG |
7fd59977 | 331 | cout<<"Removing pcurve points"<<endl; |
332 | #endif | |
333 | return Standard_False; | |
334 | } | |
335 | ||
336 | // | |
337 | // pdn checking deviation between pcurve and 3D curve | |
338 | // | |
339 | ||
340 | // Make temporary edge for analysis | |
341 | if ( C3d.IsNull() ) return Standard_False; | |
342 | TopoDS_Edge edge = MakeEdgeOnCurve(E); | |
343 | ||
344 | // fill it with pcurve(s) | |
345 | BRep_Builder B; | |
346 | Handle(Geom2d_Curve) seamPC; | |
347 | if ( isSeam ) { | |
348 | Standard_Real f, l; | |
349 | TopoDS_Shape REdge = E.Reversed() ; | |
350 | if ( ! sae.PCurve ( TopoDS::Edge ( REdge ), | |
351 | face, seamPC, f, l, Standard_False ) || | |
352 | seamPC == thePC ) | |
353 | seamPC = Handle(Geom2d_Curve)::DownCast ( thePC->Copy() ); | |
354 | B.UpdateEdge ( edge, thePC, seamPC, face, 0.); | |
355 | } | |
356 | else B.UpdateEdge ( edge, thePC, face, 0.); | |
357 | B.Range(edge,face,w1,w2); | |
358 | B.SameRange(edge, Standard_False ); | |
359 | //:S4136 | |
360 | Standard_Integer SPmode = Interface_Static::IVal("read.stdsameparameter.mode"); | |
361 | if ( SPmode ) | |
362 | B.SameParameter (edge, Standard_False ); | |
363 | ||
364 | // call FixSP to see what it will do | |
365 | Handle(ShapeFix_Edge) sfe = new ShapeFix_Edge; | |
366 | sfe->FixSameParameter(edge); | |
367 | Standard_Real tol = BRep_Tool::Tolerance (edge); | |
368 | // Standard_Real tolV1 = BRep_Tool::Tolerance(TopExp::FirstVertex(edge)); | |
369 | // Standard_Real tolV2 = BRep_Tool::Tolerance(TopExp::LastVertex(edge)); | |
370 | Standard_Boolean sr = BRep_Tool::SameRange ( edge ); | |
371 | Standard_Boolean sp = BRep_Tool::SameParameter ( edge ); | |
372 | ||
373 | // if result is not nice, try to call projection and take the best | |
374 | if ( tol > Min ( 1., 2.*preci ) || ! sr ) { | |
375 | //pdn trying to recompute pcurve | |
376 | TopoDS_Edge edgePr = MakeEdgeOnCurve(E); | |
377 | sfe->FixAddPCurve(edgePr, face, isSeam, preci); | |
378 | sfe->FixSameParameter(edgePr); | |
379 | Standard_Real tolPr = BRep_Tool::Tolerance (edgePr); | |
380 | //pdn choose the best pcurve | |
381 | if ( tolPr < tol || ! sr ) { | |
382 | // tolV1 = BRep_Tool::Tolerance(TopExp::FirstVertex(edgePr)); | |
383 | // tolV2 = BRep_Tool::Tolerance(TopExp::LastVertex(edgePr)); | |
384 | sr = BRep_Tool::SameRange ( edgePr ); | |
385 | sp = BRep_Tool::SameParameter ( edgePr ); | |
386 | tol = tolPr; | |
387 | edge = edgePr; | |
388 | } | |
389 | } | |
390 | ||
391 | // get corrected pcurve from the temporary edge, and put to original | |
392 | sae.PCurve ( edge, face, thePC, w1, w2, Standard_False ); | |
393 | if ( isSeam ) { | |
394 | Standard_Real f, l; | |
395 | TopoDS_Shape REdge = edge.Reversed(); | |
396 | sae.PCurve ( TopoDS::Edge ( REdge ), face, seamPC, f, l, Standard_False ); | |
397 | if ( E.Orientation() == TopAbs_REVERSED ) //:abv 14.11.01: coneEl.sat loop | |
398 | B.UpdateEdge ( E, seamPC, thePC, face, tol ); | |
399 | else | |
400 | B.UpdateEdge ( E, thePC, seamPC, face, tol ); | |
401 | } | |
402 | else B.UpdateEdge ( E, thePC, face, tol ); | |
403 | ||
404 | B.UpdateVertex(V1,tol); | |
405 | B.UpdateVertex(V2,tol); | |
406 | B.Range(E,face, w1, w2); | |
407 | if(BRep_Tool::SameRange(E)) | |
408 | B.SameRange( E, sr ); | |
409 | if(BRep_Tool::SameParameter(E)) | |
410 | B.SameParameter ( E, sp ); | |
411 | ||
412 | return Standard_True; | |
413 | } | |
414 | ||
415 | //======================================================================= | |
416 | //function : MergeTransferInfo | |
417 | //purpose : | |
418 | //======================================================================= | |
419 | ||
420 | void XSAlgo_AlgoContainer::MergeTransferInfo(const Handle(Transfer_TransientProcess)& TP, | |
421 | const Handle(Standard_Transient) &info, | |
422 | const Standard_Integer startTPitem) const | |
423 | { | |
424 | Handle(ShapeProcess_ShapeContext) context = Handle(ShapeProcess_ShapeContext)::DownCast ( info ); | |
425 | if ( context.IsNull() ) return; | |
426 | ||
427 | const TopTools_DataMapOfShapeShape &map = context->Map(); | |
428 | Handle(ShapeExtend_MsgRegistrator) msg = context->Messages(); | |
429 | if ( map.Extent() <=0 && ( msg.IsNull() || msg->MapShape().Extent() <=0 ) ) | |
430 | return; | |
431 | ||
432 | Standard_Integer i = ( startTPitem >0 ? startTPitem : 1 ); | |
53446383 | 433 | for ( ; i <= TP->NbMapped(); i++ ) |
434 | { | |
7fd59977 | 435 | Handle(Transfer_Binder) bnd = TP->MapItem ( i ); |
436 | Handle(TransferBRep_ShapeBinder) sb = Handle(TransferBRep_ShapeBinder)::DownCast ( bnd ); | |
437 | if ( sb.IsNull() || sb->Result().IsNull() ) continue; | |
53446383 | 438 | |
7fd59977 | 439 | TopoDS_Shape orig = sb->Result(); |
53446383 | 440 | |
441 | if ( map.IsBound ( orig ) ) | |
442 | { | |
443 | sb->SetResult ( map.Find ( orig ) ); | |
444 | } | |
7fd59977 | 445 | else if ( !orig.Location().IsIdentity() ) |
446 | { | |
447 | TopLoc_Location aNullLoc; | |
448 | TopoDS_Shape atmpSh = orig.Located(aNullLoc); | |
449 | if ( map.IsBound ( atmpSh ) ) sb->SetResult ( map.Find ( atmpSh ) ); | |
450 | } | |
53446383 | 451 | else |
452 | { | |
453 | // Some of edges may be modified. | |
454 | BRepTools_ReShape aReShape; | |
455 | Standard_Boolean hasModifiedEdges = Standard_False; | |
456 | TopExp_Explorer anExpSE(orig, TopAbs_EDGE); | |
457 | ||
458 | // Remember modifications. | |
459 | for( ; anExpSE.More() ; anExpSE.Next() ) | |
460 | { | |
461 | if ( map.IsBound ( anExpSE.Current() ) ) | |
462 | { | |
463 | hasModifiedEdges = Standard_True; | |
464 | TopoDS_Shape aModifiedShape = map.Find( anExpSE.Current() ); | |
465 | aReShape.Replace(anExpSE.Current(), aModifiedShape); | |
466 | } | |
467 | } | |
468 | ||
469 | // Apply modifications and store result in binder. | |
470 | if (hasModifiedEdges) | |
471 | { | |
472 | TopoDS_Shape aRes = aReShape.Apply(orig); | |
473 | sb->SetResult ( aRes ); | |
474 | } | |
475 | } | |
476 | ||
7fd59977 | 477 | |
478 | // update messages | |
479 | if ( ! msg.IsNull() ) { | |
480 | const ShapeExtend_DataMapOfShapeListOfMsg& msgmap = msg->MapShape(); | |
481 | if ( msgmap.IsBound (orig) ) { | |
482 | const Message_ListOfMsg &msglist = msgmap.Find (orig); | |
483 | for (Message_ListIteratorOfListOfMsg iter (msglist); iter.More(); iter.Next()) { | |
484 | const Message_Msg& mess = iter.Value(); | |
485 | sb->AddWarning (TCollection_AsciiString(mess.Value()).ToCString(), | |
486 | TCollection_AsciiString(mess.Original()).ToCString()); | |
487 | } | |
488 | } | |
489 | } | |
490 | } | |
491 | } | |
492 | ||
493 | //======================================================================= | |
494 | //function : MergeTransferInfo | |
495 | //purpose : | |
496 | //======================================================================= | |
497 | ||
498 | void XSAlgo_AlgoContainer::MergeTransferInfo(const Handle(Transfer_FinderProcess)& FP, | |
499 | const Handle(Standard_Transient) &info) const | |
500 | { | |
501 | Handle(ShapeProcess_ShapeContext) context = Handle(ShapeProcess_ShapeContext)::DownCast ( info ); | |
502 | if ( context.IsNull() ) return; | |
503 | ||
504 | const TopTools_DataMapOfShapeShape &map = context->Map(); | |
505 | TopTools_DataMapIteratorOfDataMapOfShapeShape ShapeShapeIterator(map); | |
506 | Handle(ShapeExtend_MsgRegistrator) msg = context->Messages(); | |
507 | ||
508 | for ( ; ShapeShapeIterator.More(); ShapeShapeIterator.Next() ) { | |
509 | ||
510 | TopoDS_Shape orig = ShapeShapeIterator.Key(), res = ShapeShapeIterator.Value(); | |
511 | Handle(TransferBRep_ShapeMapper) resMapper = TransferBRep::ShapeMapper ( FP, res ); | |
512 | Handle(Transfer_Binder) resBinder = FP->Find ( resMapper ); | |
513 | ||
514 | if (resBinder.IsNull()) { | |
515 | resBinder = new TransferBRep_ShapeBinder(res); | |
516 | //if <orig> shape was splitted, put entities corresponding to new shapes | |
517 | // into Transfer_TransientListBinder. | |
518 | if ( orig.ShapeType() > res.ShapeType() ) { | |
519 | TopoDS_Shape sub; | |
520 | Handle(Transfer_TransientListBinder) TransientListBinder = new Transfer_TransientListBinder; | |
521 | for (TopoDS_Iterator it(res); it.More(); it.Next()) { | |
522 | Handle(Transfer_Finder) subMapper = TransferBRep::ShapeMapper ( FP, it.Value()); | |
523 | if (subMapper.IsNull()) continue; | |
524 | ||
525 | Handle(Standard_Transient) tr = FP->FindTransient ( subMapper ); | |
526 | if (tr.IsNull()) continue; | |
527 | TransientListBinder->AddResult(tr); | |
528 | sub = it.Value(); | |
529 | } | |
530 | if ( TransientListBinder->NbTransients() == 1 ) resBinder = new TransferBRep_ShapeBinder(sub); | |
531 | else if ( TransientListBinder->NbTransients() > 1 ) { | |
532 | resBinder->AddResult(TransientListBinder); | |
533 | // resBinder->SetNext(TransientListBinder, Standard_True); | |
0797d9d3 | 534 | #ifdef OCCT_DEBUG |
7fd59977 | 535 | cout<<"Info: TransientListBinder created for splitted shape"<<endl; |
536 | } | |
537 | else { | |
538 | cout<<"Warning: XSAlgo_AlgoContainer::MergeTransferInfo() " | |
539 | <<"No results were found for splitted shape. "<<endl; | |
540 | //<<"Transfer_FinderProcess->NbMapped() = "<<FP->NbMapped()<<endl; | |
541 | #endif | |
542 | } | |
543 | } | |
544 | } | |
545 | ||
546 | Handle(TransferBRep_ShapeMapper) origMapper= TransferBRep::ShapeMapper ( FP, orig); | |
547 | Handle(Transfer_Binder) origBinder = FP->Find ( origMapper ); | |
548 | if ( origBinder.IsNull() ) { | |
549 | FP->Bind(origMapper, resBinder); | |
550 | } | |
551 | else { | |
552 | origBinder->AddResult ( resBinder ); | |
553 | } | |
554 | ||
555 | // update messages | |
556 | if ( ! msg.IsNull() ) { | |
557 | const ShapeExtend_DataMapOfShapeListOfMsg& msgmap = msg->MapShape(); | |
558 | if ( msgmap.IsBound (orig) ) { | |
559 | const Message_ListOfMsg &msglist = msgmap.Find (orig); | |
560 | for (Message_ListIteratorOfListOfMsg iter (msglist); iter.More(); iter.Next()) { | |
561 | const Message_Msg& mess = iter.Value(); | |
562 | resBinder->AddWarning (TCollection_AsciiString(mess.Value()).ToCString(), | |
563 | TCollection_AsciiString(mess.Original()).ToCString()); | |
564 | } | |
565 | } | |
566 | } | |
567 | } | |
568 | } |