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 | |
25e59720 | 68 | IMPLEMENT_STANDARD_RTTIEXT(XSAlgo_AlgoContainer,Standard_Transient) |
92efcf78 | 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 | } | |
9775fa61 | 155 | catch (Standard_Failure const& anException) { |
0797d9d3 | 156 | #ifdef OCCT_DEBUG |
7fd59977 | 157 | cout << "Error: XSAlgo_AlgoContainer::ProcessShape(): Exception in ShapeFix::Shape" << endl; |
9775fa61 | 158 | anException.Print(cout); cout << endl; |
7fd59977 | 159 | #endif |
9775fa61 | 160 | (void)anException; |
161 | } | |
7fd59977 | 162 | return context->Result(); |
163 | } | |
881536e2 | 164 | // for writing, define default sequence of DirectFaces |
165 | else if ( ! strncmp ( pseq, "write.", 6 ) ) { | |
7fd59977 | 166 | rsc->SetResource ( str.ToCString(), "DirectFaces" ); |
167 | } | |
168 | } | |
169 | ||
170 | // Define runtime tolerances and do Shape Processing | |
171 | rsc->SetResource ( "Runtime.Tolerance", Prec ); | |
172 | rsc->SetResource ( "Runtime.MaxTolerance", maxTol ); | |
b485ee79 KD |
173 | |
174 | if ( !ShapeProcess::Perform(context, seq) ) | |
881536e2 | 175 | return shape; // return original shape |
b485ee79 | 176 | |
7fd59977 | 177 | return context->Result(); |
178 | } | |
179 | ||
180 | //======================================================================= | |
181 | //function : PerformFixShape | |
182 | //purpose : | |
183 | //======================================================================= | |
184 | ||
185 | /* | |
186 | TopoDS_Shape XSAlgo_AlgoContainer::PerformFixShape(const TopoDS_Shape& S, | |
187 | const Handle(Transfer_TransientProcess)& TP, | |
188 | const Standard_Real Prec, | |
189 | const Standard_Real MaxTol) const | |
190 | { | |
191 | if ( S.IsNull() ) return S; | |
192 | ||
193 | TopoDS_Shape shape = S; | |
194 | // fixing shape | |
195 | try { | |
196 | OCC_CATCH_SIGNALS | |
197 | Handle(ShapeFix_Shape) sfs = ShapeAlgo::AlgoContainer()->ToolContainer()->FixShape(); | |
198 | sfs->Init ( S ); | |
199 | sfs->SetMsgRegistrator ( new ShapeExtend_MsgRegistrator ); | |
200 | sfs->SetPrecision ( Prec ); | |
201 | sfs->SetMaxTolerance ( MaxTol ); | |
202 | sfs->FixFaceTool()->FixWireTool()->FixSameParameterMode() = Standard_False; | |
203 | sfs->Perform(); | |
204 | ||
205 | shape = sfs->Shape(); | |
206 | ||
207 | // to be removed when messages come | |
208 | if ( shape == S || shape.IsNull() ) return S; | |
209 | ||
210 | // update map to reflect the substitutions | |
211 | Handle(ShapeBuild_ReShape) context = sfs->Context(); | |
212 | const ShapeExtend_DataMapOfShapeListOfMsg& msgmap = | |
213 | Handle(ShapeExtend_MsgRegistrator)::DownCast (sfs->MsgRegistrator())->MapShape(); | |
214 | for ( Standard_Integer i=1; i <= TP->NbMapped(); i++ ) { | |
215 | Handle(Transfer_Binder) bnd = TP->MapItem ( i ); | |
216 | Handle(TransferBRep_ShapeBinder) sb = Handle(TransferBRep_ShapeBinder)::DownCast ( bnd ); | |
217 | if ( sb.IsNull() || sb->Result().IsNull() ) continue; | |
218 | ||
219 | TopoDS_Shape orig = sb->Result(); | |
220 | ||
221 | // update messages (messages must be taken from each level in the substitution map) | |
222 | TopoDS_Shape cur, next = orig; | |
223 | do { | |
224 | cur = next; | |
225 | Message_ListOfMsg msglist; | |
226 | if (msgmap.IsBound (cur)) { | |
227 | msglist = msgmap.Find (cur); | |
228 | for (Message_ListIteratorOfListOfMsg iter (msglist); iter.More(); iter.Next()) { | |
229 | const Message_Msg& msg = iter.Value(); | |
230 | sb->AddWarning (msg.Value(), msg.Original()); | |
231 | } | |
232 | } | |
233 | next = context->Value (cur); | |
234 | } while (cur != next); | |
235 | ||
236 | // update shapes | |
237 | TopoDS_Shape res; | |
238 | if ( ! context->Status ( orig, res, Standard_True ) ) continue; | |
239 | ||
240 | sb->SetResult ( res ); | |
241 | } | |
242 | } | |
243 | catch (Standard_Failure) { | |
0797d9d3 | 244 | #ifdef OCCT_DEBUG |
7fd59977 | 245 | cout << "Error: XSAlgo_AlgoContainer::PerformFixShape(): Exception in ShapeFix::Shape" << endl; |
246 | #endif | |
247 | } | |
248 | return shape; | |
249 | } | |
250 | */ | |
251 | ||
252 | // ============================================================================ | |
253 | // Method : MakeEdgeOnCurve | |
254 | // Purpose : for CheckPCurve | |
255 | // ============================================================================ | |
256 | ||
257 | static TopoDS_Edge MakeEdgeOnCurve(const TopoDS_Edge edge) | |
258 | { | |
259 | TopoDS_Edge result; | |
260 | //BRep_Builder B; // B not used - see below (skl) | |
261 | Handle(Geom_Curve) C3d; | |
262 | ShapeAnalysis_Edge sae; | |
263 | Standard_Real cf, cl; | |
264 | if (!sae.Curve3d (edge, C3d, cf, cl, Standard_False )) | |
265 | return result; | |
266 | gp_Pnt PV1 = C3d->Value(cf); | |
267 | gp_Pnt PV2 = C3d->Value(cl); | |
268 | BRepBuilderAPI_MakeEdge mkEdge(C3d, PV1, PV2, cf, cl); | |
269 | //:S4136 Standard_Real tol = BRep_Tool::Tolerance (edge); | |
270 | ShapeBuild_Edge SBE; //skl 10.07.2001 | |
271 | SBE.SetRange3d(mkEdge,cf,cl); //skl 10.07.2001 | |
272 | result = mkEdge.Edge(); | |
273 | //:S4136 B.UpdateEdge(result,tol); | |
274 | return result; | |
275 | } | |
276 | ||
277 | //======================================================================= | |
278 | //function : CheckPCurve | |
279 | //purpose : | |
280 | //======================================================================= | |
281 | ||
282 | Standard_Boolean XSAlgo_AlgoContainer::CheckPCurve (const TopoDS_Edge& E, | |
283 | const TopoDS_Face& face, | |
284 | const Standard_Real preci, | |
285 | const Standard_Boolean isSeam) const | |
286 | { | |
287 | Standard_Real w1, w2; | |
288 | Handle(Geom2d_Curve) thePC; | |
289 | ShapeAnalysis_Edge sae; | |
290 | if ( ! sae.PCurve (E, face, thePC, w1, w2, Standard_False ) ) { | |
291 | return Standard_False; | |
292 | } | |
293 | ||
294 | // Check for pcurve longer than surface | |
295 | Handle(Geom_Surface) surf = BRep_Tool::Surface(face); | |
296 | Standard_Real UF,UL,VF,VL; | |
297 | surf->Bounds (UF,UL,VF,VL); | |
298 | gp_Pnt2d PUV1, PUV2; | |
299 | PUV1 = thePC->Value(w1); | |
300 | PUV2 = thePC->Value(w2); | |
301 | // Multi-periodique ? mieux vaut jeter (attention aux valeurs infinies) | |
302 | Standard_Real DU = Abs (PUV1.X() - PUV2.X()); | |
303 | Standard_Real DV = Abs (PUV1.Y() - PUV2.Y()); | |
304 | if ( DU/8. > (UL/6. - UF/6.) || DV/8. > (VL/6. - VF/6.) ) { | |
305 | ShapeBuild_Edge().RemovePCurve(E,face); | |
0797d9d3 | 306 | #ifdef OCCT_DEBUG |
7fd59977 | 307 | cout<<"Removing pcuve periodic"<<endl; |
308 | #endif | |
309 | return Standard_False; | |
310 | } | |
311 | ||
312 | // Second Check : 2D and 3D consistency (if the Pcurve has not been | |
313 | // dropped) | |
314 | // On verifie aussi qu on ne s enroule pas trop ... | |
315 | // ex. : UVV en DEGRES sur une surface en RADIANS, recalee = 57 tours ! | |
316 | ||
317 | Handle(Geom_Curve) C3d; | |
318 | Standard_Real cf1, cl1; | |
319 | sae.Curve3d (E, C3d, cf1, cl1, Standard_False ); | |
320 | ||
321 | gp_Pnt P1 = surf->Value(PUV1.X(), PUV1.Y()); | |
322 | gp_Pnt P2 = surf->Value(PUV2.X(), PUV2.Y()); | |
323 | TopoDS_Vertex V1 = TopExp::FirstVertex(E); | |
324 | TopoDS_Vertex V2 = TopExp::LastVertex(E); | |
325 | gp_Pnt PV1 = ( C3d.IsNull() ? BRep_Tool::Pnt(V1) : C3d->Value(cf1) ); | |
326 | gp_Pnt PV2 = ( C3d.IsNull() ? BRep_Tool::Pnt(V2) : C3d->Value(cl1) ); | |
327 | Standard_Real Dist11 = PV1.Distance(P1), Dist22 = PV2.Distance(P2); | |
328 | ||
329 | if (!((Dist11 <= preci) && (Dist22 <= preci))) { | |
330 | ShapeBuild_Edge().RemovePCurve(E,face); | |
0797d9d3 | 331 | #ifdef OCCT_DEBUG |
7fd59977 | 332 | cout<<"Removing pcurve points"<<endl; |
333 | #endif | |
334 | return Standard_False; | |
335 | } | |
336 | ||
337 | // | |
338 | // pdn checking deviation between pcurve and 3D curve | |
339 | // | |
340 | ||
341 | // Make temporary edge for analysis | |
342 | if ( C3d.IsNull() ) return Standard_False; | |
343 | TopoDS_Edge edge = MakeEdgeOnCurve(E); | |
344 | ||
345 | // fill it with pcurve(s) | |
346 | BRep_Builder B; | |
347 | Handle(Geom2d_Curve) seamPC; | |
348 | if ( isSeam ) { | |
349 | Standard_Real f, l; | |
350 | TopoDS_Shape REdge = E.Reversed() ; | |
351 | if ( ! sae.PCurve ( TopoDS::Edge ( REdge ), | |
352 | face, seamPC, f, l, Standard_False ) || | |
353 | seamPC == thePC ) | |
354 | seamPC = Handle(Geom2d_Curve)::DownCast ( thePC->Copy() ); | |
355 | B.UpdateEdge ( edge, thePC, seamPC, face, 0.); | |
356 | } | |
357 | else B.UpdateEdge ( edge, thePC, face, 0.); | |
358 | B.Range(edge,face,w1,w2); | |
359 | B.SameRange(edge, Standard_False ); | |
360 | //:S4136 | |
361 | Standard_Integer SPmode = Interface_Static::IVal("read.stdsameparameter.mode"); | |
362 | if ( SPmode ) | |
363 | B.SameParameter (edge, Standard_False ); | |
364 | ||
365 | // call FixSP to see what it will do | |
366 | Handle(ShapeFix_Edge) sfe = new ShapeFix_Edge; | |
367 | sfe->FixSameParameter(edge); | |
368 | Standard_Real tol = BRep_Tool::Tolerance (edge); | |
369 | // Standard_Real tolV1 = BRep_Tool::Tolerance(TopExp::FirstVertex(edge)); | |
370 | // Standard_Real tolV2 = BRep_Tool::Tolerance(TopExp::LastVertex(edge)); | |
371 | Standard_Boolean sr = BRep_Tool::SameRange ( edge ); | |
372 | Standard_Boolean sp = BRep_Tool::SameParameter ( edge ); | |
373 | ||
374 | // if result is not nice, try to call projection and take the best | |
375 | if ( tol > Min ( 1., 2.*preci ) || ! sr ) { | |
376 | //pdn trying to recompute pcurve | |
377 | TopoDS_Edge edgePr = MakeEdgeOnCurve(E); | |
378 | sfe->FixAddPCurve(edgePr, face, isSeam, preci); | |
379 | sfe->FixSameParameter(edgePr); | |
380 | Standard_Real tolPr = BRep_Tool::Tolerance (edgePr); | |
381 | //pdn choose the best pcurve | |
382 | if ( tolPr < tol || ! sr ) { | |
383 | // tolV1 = BRep_Tool::Tolerance(TopExp::FirstVertex(edgePr)); | |
384 | // tolV2 = BRep_Tool::Tolerance(TopExp::LastVertex(edgePr)); | |
385 | sr = BRep_Tool::SameRange ( edgePr ); | |
386 | sp = BRep_Tool::SameParameter ( edgePr ); | |
387 | tol = tolPr; | |
388 | edge = edgePr; | |
389 | } | |
390 | } | |
391 | ||
392 | // get corrected pcurve from the temporary edge, and put to original | |
393 | sae.PCurve ( edge, face, thePC, w1, w2, Standard_False ); | |
394 | if ( isSeam ) { | |
395 | Standard_Real f, l; | |
396 | TopoDS_Shape REdge = edge.Reversed(); | |
397 | sae.PCurve ( TopoDS::Edge ( REdge ), face, seamPC, f, l, Standard_False ); | |
398 | if ( E.Orientation() == TopAbs_REVERSED ) //:abv 14.11.01: coneEl.sat loop | |
399 | B.UpdateEdge ( E, seamPC, thePC, face, tol ); | |
400 | else | |
401 | B.UpdateEdge ( E, thePC, seamPC, face, tol ); | |
402 | } | |
403 | else B.UpdateEdge ( E, thePC, face, tol ); | |
404 | ||
405 | B.UpdateVertex(V1,tol); | |
406 | B.UpdateVertex(V2,tol); | |
407 | B.Range(E,face, w1, w2); | |
408 | if(BRep_Tool::SameRange(E)) | |
409 | B.SameRange( E, sr ); | |
410 | if(BRep_Tool::SameParameter(E)) | |
411 | B.SameParameter ( E, sp ); | |
412 | ||
413 | return Standard_True; | |
414 | } | |
415 | ||
416 | //======================================================================= | |
417 | //function : MergeTransferInfo | |
418 | //purpose : | |
419 | //======================================================================= | |
420 | ||
421 | void XSAlgo_AlgoContainer::MergeTransferInfo(const Handle(Transfer_TransientProcess)& TP, | |
422 | const Handle(Standard_Transient) &info, | |
423 | const Standard_Integer startTPitem) const | |
424 | { | |
425 | Handle(ShapeProcess_ShapeContext) context = Handle(ShapeProcess_ShapeContext)::DownCast ( info ); | |
426 | if ( context.IsNull() ) return; | |
427 | ||
428 | const TopTools_DataMapOfShapeShape &map = context->Map(); | |
429 | Handle(ShapeExtend_MsgRegistrator) msg = context->Messages(); | |
430 | if ( map.Extent() <=0 && ( msg.IsNull() || msg->MapShape().Extent() <=0 ) ) | |
431 | return; | |
432 | ||
433 | Standard_Integer i = ( startTPitem >0 ? startTPitem : 1 ); | |
53446383 | 434 | for ( ; i <= TP->NbMapped(); i++ ) |
435 | { | |
7fd59977 | 436 | Handle(Transfer_Binder) bnd = TP->MapItem ( i ); |
437 | Handle(TransferBRep_ShapeBinder) sb = Handle(TransferBRep_ShapeBinder)::DownCast ( bnd ); | |
438 | if ( sb.IsNull() || sb->Result().IsNull() ) continue; | |
53446383 | 439 | |
7fd59977 | 440 | TopoDS_Shape orig = sb->Result(); |
53446383 | 441 | |
442 | if ( map.IsBound ( orig ) ) | |
443 | { | |
444 | sb->SetResult ( map.Find ( orig ) ); | |
445 | } | |
7fd59977 | 446 | else if ( !orig.Location().IsIdentity() ) |
447 | { | |
448 | TopLoc_Location aNullLoc; | |
449 | TopoDS_Shape atmpSh = orig.Located(aNullLoc); | |
450 | if ( map.IsBound ( atmpSh ) ) sb->SetResult ( map.Find ( atmpSh ) ); | |
451 | } | |
53446383 | 452 | else |
453 | { | |
454 | // Some of edges may be modified. | |
455 | BRepTools_ReShape aReShape; | |
456 | Standard_Boolean hasModifiedEdges = Standard_False; | |
457 | TopExp_Explorer anExpSE(orig, TopAbs_EDGE); | |
458 | ||
459 | // Remember modifications. | |
460 | for( ; anExpSE.More() ; anExpSE.Next() ) | |
461 | { | |
462 | if ( map.IsBound ( anExpSE.Current() ) ) | |
463 | { | |
464 | hasModifiedEdges = Standard_True; | |
465 | TopoDS_Shape aModifiedShape = map.Find( anExpSE.Current() ); | |
466 | aReShape.Replace(anExpSE.Current(), aModifiedShape); | |
467 | } | |
468 | } | |
469 | ||
470 | // Apply modifications and store result in binder. | |
471 | if (hasModifiedEdges) | |
472 | { | |
473 | TopoDS_Shape aRes = aReShape.Apply(orig); | |
474 | sb->SetResult ( aRes ); | |
475 | } | |
476 | } | |
477 | ||
7fd59977 | 478 | |
479 | // update messages | |
480 | if ( ! msg.IsNull() ) { | |
481 | const ShapeExtend_DataMapOfShapeListOfMsg& msgmap = msg->MapShape(); | |
482 | if ( msgmap.IsBound (orig) ) { | |
483 | const Message_ListOfMsg &msglist = msgmap.Find (orig); | |
484 | for (Message_ListIteratorOfListOfMsg iter (msglist); iter.More(); iter.Next()) { | |
485 | const Message_Msg& mess = iter.Value(); | |
486 | sb->AddWarning (TCollection_AsciiString(mess.Value()).ToCString(), | |
487 | TCollection_AsciiString(mess.Original()).ToCString()); | |
488 | } | |
489 | } | |
490 | } | |
491 | } | |
492 | } | |
493 | ||
494 | //======================================================================= | |
495 | //function : MergeTransferInfo | |
496 | //purpose : | |
497 | //======================================================================= | |
498 | ||
499 | void XSAlgo_AlgoContainer::MergeTransferInfo(const Handle(Transfer_FinderProcess)& FP, | |
500 | const Handle(Standard_Transient) &info) const | |
501 | { | |
502 | Handle(ShapeProcess_ShapeContext) context = Handle(ShapeProcess_ShapeContext)::DownCast ( info ); | |
503 | if ( context.IsNull() ) return; | |
504 | ||
505 | const TopTools_DataMapOfShapeShape &map = context->Map(); | |
506 | TopTools_DataMapIteratorOfDataMapOfShapeShape ShapeShapeIterator(map); | |
507 | Handle(ShapeExtend_MsgRegistrator) msg = context->Messages(); | |
508 | ||
509 | for ( ; ShapeShapeIterator.More(); ShapeShapeIterator.Next() ) { | |
510 | ||
511 | TopoDS_Shape orig = ShapeShapeIterator.Key(), res = ShapeShapeIterator.Value(); | |
512 | Handle(TransferBRep_ShapeMapper) resMapper = TransferBRep::ShapeMapper ( FP, res ); | |
513 | Handle(Transfer_Binder) resBinder = FP->Find ( resMapper ); | |
514 | ||
515 | if (resBinder.IsNull()) { | |
516 | resBinder = new TransferBRep_ShapeBinder(res); | |
517 | //if <orig> shape was splitted, put entities corresponding to new shapes | |
518 | // into Transfer_TransientListBinder. | |
519 | if ( orig.ShapeType() > res.ShapeType() ) { | |
520 | TopoDS_Shape sub; | |
521 | Handle(Transfer_TransientListBinder) TransientListBinder = new Transfer_TransientListBinder; | |
522 | for (TopoDS_Iterator it(res); it.More(); it.Next()) { | |
523 | Handle(Transfer_Finder) subMapper = TransferBRep::ShapeMapper ( FP, it.Value()); | |
524 | if (subMapper.IsNull()) continue; | |
525 | ||
526 | Handle(Standard_Transient) tr = FP->FindTransient ( subMapper ); | |
527 | if (tr.IsNull()) continue; | |
528 | TransientListBinder->AddResult(tr); | |
529 | sub = it.Value(); | |
530 | } | |
531 | if ( TransientListBinder->NbTransients() == 1 ) resBinder = new TransferBRep_ShapeBinder(sub); | |
532 | else if ( TransientListBinder->NbTransients() > 1 ) { | |
533 | resBinder->AddResult(TransientListBinder); | |
534 | // resBinder->SetNext(TransientListBinder, Standard_True); | |
0797d9d3 | 535 | #ifdef OCCT_DEBUG |
7fd59977 | 536 | cout<<"Info: TransientListBinder created for splitted shape"<<endl; |
537 | } | |
538 | else { | |
539 | cout<<"Warning: XSAlgo_AlgoContainer::MergeTransferInfo() " | |
540 | <<"No results were found for splitted shape. "<<endl; | |
541 | //<<"Transfer_FinderProcess->NbMapped() = "<<FP->NbMapped()<<endl; | |
542 | #endif | |
543 | } | |
544 | } | |
545 | } | |
546 | ||
547 | Handle(TransferBRep_ShapeMapper) origMapper= TransferBRep::ShapeMapper ( FP, orig); | |
548 | Handle(Transfer_Binder) origBinder = FP->Find ( origMapper ); | |
549 | if ( origBinder.IsNull() ) { | |
550 | FP->Bind(origMapper, resBinder); | |
551 | } | |
552 | else { | |
553 | origBinder->AddResult ( resBinder ); | |
554 | } | |
555 | ||
556 | // update messages | |
557 | if ( ! msg.IsNull() ) { | |
558 | const ShapeExtend_DataMapOfShapeListOfMsg& msgmap = msg->MapShape(); | |
559 | if ( msgmap.IsBound (orig) ) { | |
560 | const Message_ListOfMsg &msglist = msgmap.Find (orig); | |
561 | for (Message_ListIteratorOfListOfMsg iter (msglist); iter.More(); iter.Next()) { | |
562 | const Message_Msg& mess = iter.Value(); | |
563 | resBinder->AddWarning (TCollection_AsciiString(mess.Value()).ToCString(), | |
564 | TCollection_AsciiString(mess.Original()).ToCString()); | |
565 | } | |
566 | } | |
567 | } | |
568 | } | |
569 | } |