0024059: Eliminate compiler warning C4701 in MSVC++ with warning level 4
[occt.git] / src / TNaming / TNaming_Localizer.cxx
CommitLineData
b311480e 1// Created on: 1997-06-11
2// Created by: Yves FRICAUD
3// Copyright (c) 1997-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23#include <TNaming_Localizer.ixx>
24#include <TNaming_Identifier.hxx>
25#include <TNaming_ShapesSet.hxx>
26#include <TNaming_ListIteratorOfListOfMapOfShape.hxx>
27#include <TNaming_ListIteratorOfListOfIndexedDataMapOfShapeListOfShape.hxx>
28#include <TNaming_DataMapOfShapeShapesSet.hxx>
29#include <TNaming_IteratorOnShapesSet.hxx>
30#include <TNaming_Evolution.hxx>
31#include <TNaming_Iterator.hxx>
32#include <TNaming_NewShapeIterator.hxx>
33#include <TNaming_OldShapeIterator.hxx>
34#include <TNaming_Tool.hxx>
35#include <TNaming_ListOfNamedShape.hxx>
36#include <TNaming_ListIteratorOfListOfNamedShape.hxx>
37#include <TDF_Label.hxx>
38#include <TopoDS_Iterator.hxx>
39#include <TopTools_ListOfShape.hxx>
40#include <TopTools_ListIteratorOfListOfShape.hxx>
41#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
42#include <TopTools_MapIteratorOfMapOfShape.hxx>
43#include <TopExp.hxx>
44#include <TopExp_Explorer.hxx>
45
46#define OCC351
47#ifdef DEB
48//#define MDTV_DEB_SC
49#ifdef MDTV_DEB_SC
50#include <TDF_Tool.hxx>
51#include <TDF_MapIteratorOfLabelMap.hxx>
52
53#include <TCollection_AsciiString.hxx>
54#include <BRepTools.hxx>
55void LPrintEntry(const TDF_Label& label)
56{
57 TCollection_AsciiString entry;
58 TDF_Tool::Entry(label, entry);
59 cout << "LabelEntry = "<< entry << endl;
60}
61static void LWrite(const TopoDS_Shape& shape,
62 const Standard_CString filename)
63{
64 char buf[256];
65 if(strlen(filename) > 256) return;
66#if defined WNT
67 strcpy_s (buf, filename);
68#else
69 strcpy (buf, filename);
70#endif
71 char* p = buf;
72 while (*p) {
73 if(*p == ':')
74 *p = '-';
75 p++;
76 }
77 ofstream save (buf);
78 if(!save)
79 cout << "File " << buf << " was not created: rdstate = " << save.rdstate() << endl;
80 save << "DBRep_DrawableShape" << endl << endl;
81 if(!shape.IsNull()) BRepTools::Write(shape, save);
82 save.close();
83}
84
85//=======================================================================
86static void LWriteNSOnLabel (const Handle(TNaming_NamedShape)& NS,
87 const Standard_CString filename)
88{
89 if(!NS.IsNull() && !NS->IsEmpty() ) {
90 TCollection_AsciiString aNam (filename);
91 TCollection_AsciiString oldS ("_Old");
92 TCollection_AsciiString newS ("_New_");
93 Standard_Integer i(0);
94 TNaming_Iterator it(NS);
95 for(;it.More(); it.Next(),i++) {
96 TCollection_AsciiString aName1 = aNam + oldS + i + ".brep";
97 TCollection_AsciiString aName2 = aNam + newS + i + ".brep";
98 const TopoDS_Shape& oldShape = it.OldShape();
99 const TopoDS_Shape& newShape = it.NewShape();
100 if(!oldShape.IsNull())
101 LWrite ( oldShape, aName1.ToCString());
102 if(!newShape.IsNull())
103 LWrite ( newShape, aName2.ToCString());
104 }
105 }
106}
107#endif
108#endif
109//=======================================================================
110 //function : FindFeatureInAncestors
111//purpose : Cherche les ancetres de S qui sont sous des labels
112//=======================================================================
113
114void TNaming_Localizer::FindFeaturesInAncestors
115(const TopoDS_Shape& S,
116 const TopoDS_Shape& Context,
117 TopTools_MapOfShape& AncInFeature)
118{
119#ifdef MDTV_DEB_SC
120 LWrite(S, "Localizer_S.brep");
121 LWrite(Context, "Localizer_Context.brep");
122#endif
123
124 const TopTools_IndexedDataMapOfShapeListOfShape& Anc = Ancestors(Context,S.ShapeType());
125
126 if (Anc.Contains(S)) {
127#ifdef MDTV_DEB_SC
128 cout <<"Localizer: S in ancestor" <<endl;
129#endif
130 const TopTools_ListOfShape& L = Anc.FindFromKey(S);
131 TopTools_ListIteratorOfListOfShape itL(L);
132 for (; itL.More(); itL.Next()) {
133 const TopoDS_Shape& AS = itL.Value();
134#ifdef MDTV_DEB_SC
135 LWrite(AS, "Localizer_AS.brep");
136#endif
137 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(AS,myUS->Label());
138 if (!NS.IsNull()) {
139// if (TNaming_Tool::HasLabel(myUS,AS)) {
140 AncInFeature.Add(AS);
141 }
142 else if (AS.ShapeType() > TopAbs_FACE) {
143 FindFeaturesInAncestors (AS, Context, AncInFeature);
144 }
145 else {
146#ifdef DEB
147 cout <<" TNaming_Localization : Failure in the research of ancetres in TDF"<<endl;
148#endif
149 }
150 }
151
152 }
153 else {
154#ifdef DEB
155 cout <<" TNaming_Localization : S n est pas dans le solide"<<endl;//S is not in the solid
156#endif
157 }
158}
159
160//=======================================================================
161//function : SubShapes
162//purpose :
163//=======================================================================
164
165const TopTools_MapOfShape& TNaming_Localizer::SubShapes (const TopoDS_Shape& In,
166 const TopAbs_ShapeEnum TS)
167{
168
169 TopTools_ListIteratorOfListOfShape itS(myShapeWithSubShapes) ;
170 TNaming_ListIteratorOfListOfMapOfShape itSS(mySubShapes);
171// Standard_Boolean Found = Standard_False;
172 for (; itS.More(); itS.Next(),itSS.Next()) {
173 if (In.IsSame(itS.Value())) {
174 TopTools_MapOfShape& SubShapes = itSS.Value();
175 for (TopExp_Explorer exp(In,TS); exp.More(); exp.Next()) {
176 const TopoDS_Shape& SS = exp.Current();
177 if (SubShapes.Contains(SS)) {
178 break;
179 }
180 SubShapes.Add(SS);
181 }
182 return SubShapes;
183 }
184 }
185
186 TopTools_MapOfShape emptyMap;
187 mySubShapes.Prepend(emptyMap);
188 myShapeWithSubShapes.Prepend(In);
189
190 TopTools_MapOfShape& SubShapes = mySubShapes.First();
191 for (TopExp_Explorer exp(In,TS); exp.More(); exp.Next()) {
192 const TopoDS_Shape& SS = exp.Current();
193 if (SubShapes.Contains(SS)) {
194 break;
195 }
196 SubShapes.Add(SS);
197 }
198 return SubShapes;
199}
200
201
202//=======================================================================
203//function : Ancestors
204//purpose :
205//=======================================================================
206
207const TopTools_IndexedDataMapOfShapeListOfShape& TNaming_Localizer::Ancestors
208(const TopoDS_Shape& In,
209 const TopAbs_ShapeEnum TS)
210{
211 TopTools_ListIteratorOfListOfShape itS(myShapeWithAncestors) ;
212 TNaming_ListIteratorOfListOfIndexedDataMapOfShapeListOfShape itA(myAncestors);
213// Standard_Boolean Found = Standard_False;
214 for (; itS.More(); itS.Next(),itA.Next()) {
215 if (In.IsSame(itS.Value())) {
216 //-----------------------
217 // Ancetres existent.
218 //-----------------------
219 TopTools_IndexedDataMapOfShapeListOfShape& Anc = itA.Value();
220
221 TopExp_Explorer exp(In,TS);
222#ifdef DEB
223 if (!exp.More()) cout <<" TNaming_Localization : Construction ancetres impossible"<<endl;
224#endif
225 const TopoDS_Shape& SS = exp.Current();
226
227 if (Anc.Contains(SS)) {
228 return Anc;
229 }
230 else {
231 //----------------------------
232 // Completion des ancetres.
233 //----------------------------
234 TopAbs_ShapeEnum TA = TopAbs_FACE;
235 if (TS == TopAbs_EDGE) TA = TopAbs_FACE;
236 if (TS == TopAbs_VERTEX) TA = TopAbs_EDGE;
237 if (TA >= In.ShapeType()) {
238 TopExp::MapShapesAndAncestors(In, TS, TA, Anc);
239 }
240 else {
241#ifdef DEB
242 cout <<" TNaming_Localization : Construction ancetres impossible"<<endl;
243#endif
244 }
245 }
246 return Anc;
247 }
248 }
249 //-----------------------------------
250 // Construction des ancetres
251 //-----------------------------------
252 TopTools_IndexedDataMapOfShapeListOfShape emptyAnc;
253 myShapeWithAncestors.Prepend(In);
254 myAncestors .Prepend(emptyAnc);
1d47d8d0 255
7fd59977 256 TopAbs_ShapeEnum TA=TopAbs_COMPOUND;
1d47d8d0 257
446b69ba
S
258 if (TS == TopAbs_VERTEX) TA = TopAbs_EDGE;
259 else if (TS == TopAbs_EDGE) TA = TopAbs_FACE;
260 else if (TS == TopAbs_FACE) TA = TopAbs_SOLID;
261 if ((TS == TopAbs_EDGE || TS == TopAbs_VERTEX || TS == TopAbs_FACE) && TA >= In.ShapeType()) {
7fd59977 262 TopExp::MapShapesAndAncestors(In, TS, TA, myAncestors.First());
263 }
264 else {
265#ifdef DEB
266 cout <<" TNaming_Localization : Construction ancetres impossible"<<endl;
267#endif
268 }
269 return myAncestors.First();
270}
271
272//=======================================================================
273//function : IsNew
274//purpose :
275//=======================================================================
276
277Standard_Boolean TNaming_Localizer::IsNew (const TopoDS_Shape& S,
278 const Handle(TNaming_NamedShape)& NS)
279{
280 TNaming_Iterator itLab(NS);
281 for (; itLab.More(); itLab.Next()) {
282 if (itLab.OldShape().IsSame(S)) {
283 return Standard_False;
284 break;
285 }
286 if (itLab.NewShape().IsSame(S)) {
287 return Standard_True;
288 break;
289 }
290 }
291#ifdef DEB
292 cout <<"TNaming_Localizer:IsNewInLab : Shape n est pas dans le Label."<<endl;
293#endif
294 return Standard_False;
295}
296
297
298//=======================================================================
299//function : Back
300//purpose :
301//=======================================================================
302
303void TNaming_Localizer::GoBack (const TopoDS_Shape& S,
304 const TDF_Label& Lab,
305 const TNaming_Evolution Evol,
306 TopTools_ListOfShape& LBS,
307 TNaming_ListOfNamedShape& LBNS)
308{
309// Standard_Integer TrDef;
310
311 TNaming_OldShapeIterator it(S,myCurTrans,myUS);
312 TopoDS_Shape Sol;
313 if (!it.More()) {
314 //-----------------------------------------------------------
315 // Pas d'ascendants => Recherche et exploration du contenant
316 //----------------------------------------------------------
317 TDF_Label Father = Lab.Father();
318 TNaming_Iterator itLab(Father);
319 for (; itLab.More(); itLab.Next()) {
320 Sol = itLab.OldShape();
321 break;
322 }
323 //-------------------------------------------
324 // Recherche des ancetres dans des features.
325 //-------------------------------------------
326 if (!Sol.IsNull()) {
327 TopTools_MapOfShape AncInFeature;
328 FindFeaturesInAncestors (S, Sol, AncInFeature);
329 TopTools_MapIteratorOfMapOfShape itF(AncInFeature);
330 for ( ; itF.More(); itF.Next()) {
d3f26155 331 const TopoDS_Shape& AncOfS = itF.Key();
332 LBS .Append(AncOfS);
333 LBNS.Append(TNaming_Tool::NamedShape(AncOfS,Lab));
7fd59977 334 }
335 }
336 }
337 else {
338 for ( ; it.More(); it.Next()) {
d3f26155 339 // if (it.NamedShape()->Evolution() != TNaming_SELECTED) {
7fd59977 340 if (it.NamedShape()->Evolution() == Evol) {
d3f26155 341 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(it.Shape(),Lab);
342 if (!NS.IsNull()) {
343 LBS.Append (it.Shape());
344 LBNS.Append (TNaming_Tool::NamedShape(it.Shape(),Lab));
345 }
346 else {
7fd59977 347#ifdef DEB
d3f26155 348 cout <<"TNaming_Localizer: Shape modifie sans avoir ete cree"<<endl;
7fd59977 349#endif
d3f26155 350 }
7fd59977 351 }
352 }
353 }
354}
355/*
356//=======================================================================
357//function : Backward
358//purpose :
359//=======================================================================
360
361void TNaming_Localizer::Backward (const TopoDS_Shape& S,
362 TDF_LabelMap& Primitives,
363 TopTools_MapOfShape& ValidShapes)
364{
365 Standard_Integer PrevTrans = myCurTrans - 1;
366 Standard_Integer TrDef;
367 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
368 TNaming_Evolution Evol = Evolution(Lab);
369
370
371 TopTools_ListOfShape LBS;
372 TDF_LabelList LBLab;
373
374 GoBack(S,Lab,LBS,LBLab);
375
376
377 TopTools_ListIteratorOfListOfShape itLBS (LBS);
378 TDF_ListIteratorOfLabelList itLBLab(LBLab);
379
380 if (LBS.IsEmpty()) {
381 Primitives.Add(Lab);
382 }
383 for ( ; itLBS.More(); itLBS.Next(), itLBLab.Next()) {
384 const TopoDS_Shape& OS = itLBS.Value();
385 const TDF_Label& LabOS = itLBLab.Value();
386
387 Evol = Evolution(LabOS);
388
389 if (TNaming_Tool::ValidUntil(OS,myUS) >= myCurTrans) {
390 //---------------------------------------------------------
391 // Le Shape est valid dans la transaction myCurTrans => STOP
392 //---------------------------------------------------------
393 ValidShapes.Add(OS);
394 }
395 else if (Evol == TNaming_PRIMITIVE) {
396 Primitives.Add(LabOS);
397 }
398 else if ((Evol == TNaming_GENERATED) && IsNewInLab (OS,LabOS,PrevTrans)) {
399 //--------------------------------------------------------------
400 // Passage par une generation
401 // le shape dans myCurTrans descendra d un element de cet attribut.
402 // Localisation de OS dans la transaction courrante.
403 // les shapes obtenus seront des antecedants du shape cherche.
404 //--------------------------------------------------------------
405
406 // A faire seulememt si OS est un newShape dans LabOS.
407 TNaming_ShapesSet ResGen;
408 TopoDS_Shape PrevIn;
409 TDF_Label Father = LabOS.Father();
410 TNaming_Iterator itLab(Father,PrevTrans);
411 for (; itLab.More(); itLab.Next()) {
412 PrevIn= itLab.OldShape();
413 break;
414 }
415 Localize(PrevIn,LabOS,OS,ResGen);
416 for (TNaming_IteratorOnShapesSet itLoc(ResGen); itLoc.More(); itLoc.Next()) {
417 ValidShapes.Add(itLoc.Value());
418 }
419 }
420 else if (Evol == TNaming_SELECTED) {
421 //PAS FINI.
422 TNaming_ShapesSet ResSel;
423 TopoDS_Shape PrevIn,CurIn;
424// FindIn (LabOS,PrevIn,CurIn);
425 Localize(PrevIn,CurIn,OS,ResSel);
426 for (TNaming_IteratorOnShapesSet itLoc(ResSel); itLoc.More(); itLoc.Next()) {
427 ValidShapes.Add(itLoc.Value());
428 }
429 }
430 else {
431 Backward(itLBS.Value(),Primitives,ValidShapes);
432 }
433 }
434}
435*/
436
437//=======================================================================
438//function : NamedShape
439//purpose :
440//=======================================================================
441
442Handle(TNaming_NamedShape) NamedShape(const TDF_Label& Lab)
443{
444 Handle(TNaming_NamedShape) NS;
445 Lab.FindAttribute(TNaming_NamedShape::GetID(),NS);
446 return NS;
447}
448
449//=======================================================================
450//function : Backward
451//purpose :
452//=======================================================================
453
454void TNaming_Localizer::Backward (const Handle(TNaming_NamedShape)& NS,
455 const TopoDS_Shape& S,
456 TNaming_MapOfNamedShape& Primitives,
457 TopTools_MapOfShape& Shapes)
458{
459 TNaming_Evolution Evol = NS->Evolution();
460 TDF_Label LabNS = NS->Label();
461
462 TopTools_ListOfShape LBS;
463 TNaming_ListOfNamedShape LBNS;
464
465 GoBack(S,LabNS,Evol,LBS,LBNS);
466
467
468 TopTools_ListIteratorOfListOfShape itLBS (LBS);
469 TNaming_ListIteratorOfListOfNamedShape itLBNS (LBNS);
470
471 if (LBS.IsEmpty()) {
472 Primitives.Add(NS);
473 }
474 for ( ; itLBS.More(); itLBS.Next(), itLBNS.Next()) {
475 const TopoDS_Shape& OS = itLBS.Value();
476 Handle(TNaming_NamedShape) NOS = itLBNS.Value();
477 Evol = NOS->Evolution();
478 if (Evol == TNaming_PRIMITIVE) {
479 Primitives.Add(NOS);
480 }
481 else if (Evol == TNaming_GENERATED) {
482 Shapes.Add(OS);
483 }
484 else {
485 Backward(NOS, itLBS.Value(),Primitives,Shapes);
486 }
487 }
488}
489
490//=======================================================================
491//function : ValidCandidat
492//purpose :
493//=======================================================================
494
495#ifdef DEB
496/*static Standard_Boolean StoreValid (const TopoDS_Shape& S,
497 const TopTools_MapOfShape& ShapeOfSol,
498 TopAbs_ShapeEnum TargetType,
499 TNaming_ShapesSet& Res)
500{
501 Standard_Boolean Valid = Standard_False;
502
503 if (ShapeOfSol.Contains(S)) {
504 if (S.ShapeType() == TargetType) {
505 Res.Add(S);
506 return Standard_True;
507 }
508 else if (S.ShapeType() < TargetType) {
509 for (TopExp_Explorer exp(S,TargetType); exp.More(); exp.Next()) {
510 const TopoDS_Shape& SS = exp.Current();
511 Res.Add(SS);
512 Valid = Standard_True;
513 }
514 }
515 }
516 return Valid;
517}*/
518#endif
519
520/*
521//=======================================================================
522//function : Forward
523//purpose :
524//=======================================================================
525
526void TNaming_Localizer::GoForward(const TopoDS_Shape& S,
527 const TopTools_MapOfShape& Target,
528 const TopAbs_ShapeEnum TargetType,
529 TNaming_ShapesSet& Res)
530
531{
532 Standard_Integer TrDef;
533 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
534 if (StoreValid (S, Target, TargetType, Res)) {
535 return;
536 }
537 TNaming_Evolution Evol = Evolution(Lab);
538 TNaming_NewShapeIterator NewIt(S,myCurTrans,myUS);
539
540 for ( ; NewIt.More(); NewIt.Next()) {
541 const TopoDS_Shape& NS = NewIt.Shape();
542 GoForward ( NS, Target, TargetType, Res);
543 }
544}
545
546*/
547
548//=======================================================================
549//function : FindNeighbourg
550//purpose :
551//=======================================================================
552
553void TNaming_Localizer::FindNeighbourg (const TopoDS_Shape& Sol,
554 const TopoDS_Shape& S,
555 TopTools_MapOfShape& Neighbourg)
556{
557 TopAbs_ShapeEnum TA = S.ShapeType();
7fd59977 558 TopAbs_ShapeEnum TS=TopAbs_COMPOUND;
1d47d8d0 559
7fd59977 560 if (TA == TopAbs_FACE) TS = TopAbs_EDGE;
561 if (TA == TopAbs_EDGE) TS = TopAbs_VERTEX;
562 if (TA == TopAbs_VERTEX) TS = TopAbs_VERTEX; // szy 30.03.10
563 const TopTools_IndexedDataMapOfShapeListOfShape& Anc = Ancestors(Sol,TS);
564// szy 30.03.10 to process case when Candidate is of type Vertex
565// if (TA == TopAbs_VERTEX) {
566//#ifdef DEB
567// cout <<"construction voisins des vertex impossible"<<endl;
568//#endif
569// return;
570// }
571 for (TopExp_Explorer Exp(S,TS); Exp.More(); Exp.Next()) {
572 const TopoDS_Shape& SS = Exp.Current();
573 if (!Anc.Contains(SS)) {
574 //----------------------------------------------------
575 // Construction des ancetres
576 //----------------------------------------------------
577 break;
578 }
579 else {
580 TopTools_ListIteratorOfListOfShape itL(Anc.FindFromKey(SS));
581 for ( ; itL.More(); itL.Next()) {
582 if (!itL.Value().IsSame(S)) {
583 Neighbourg.Add(itL.Value());
584 }
585 }
586 }
587 }
588}
589
590//=======================================================================
591//function : TNaming_Localizer
592//purpose :
593//=======================================================================
594
595TNaming_Localizer::TNaming_Localizer()
596{
597}
598
599
600//=======================================================================
601//function : Init
602//purpose :
603//=======================================================================
604
605void TNaming_Localizer::Init(const Handle(TNaming_UsedShapes)& US,
606 const Standard_Integer CurTrans)
607{
608 myUS = US;
609 myCurTrans = CurTrans;
610}
611
612
613//=======================================================================
614//function : Explode
615//purpose :
616//=======================================================================
617
618#ifdef DEB
619/*static void Explode (TNaming_ShapesSet& Res,
620 TopAbs_ShapeEnum TS,
621 TNaming_ShapesSet& ResGoodType)
622{
623 TNaming_IteratorOnShapesSet it(Res);
624 for ( ; it.More(); it.Next()) {
625 const TopoDS_Shape& S = it.Value();
626 TopExp_Explorer exp(S,TS);
627 for (; exp.More(); exp.Next()) {
628 ResGoodType.Add(exp.Current());
629 }
630 }
631} */
632#endif
633
634/*
635//=======================================================================
636//function : Localize
637//purpose :
638//=======================================================================
639
640void TNaming_Localizer::Localize(const TopoDS_Shape& PrevIn,
641 const TopoDS_Shape& CurIn ,
642 const TopoDS_Shape& S,
643 TNaming_ShapesSet& Res)
644{
645 Res.Clear();
646 TDF_LabelMap Primitives;
647 TopTools_MapOfShape ValidShapes;
648 Standard_Integer PrevTrans = myCurTrans-1;
649
650 const TopTools_MapOfShape& CurSubShapes = SubShapes (CurIn,S.ShapeType());
651
652 Standard_Boolean HasLabel = TNaming_Tool::HasLabel(myUS,S);
653
654 if (HasLabel) {
655 Standard_Integer TrDef;
656 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
657 TNaming_Evolution Evol = Evolution(Lab);
658 if (Evol == TNaming_PRIMITIVE) {
659 //------------------------
660 // Label est une primitive
661 //------------------------
662 Primitives.Add(Lab);
663 Forward (CurSubShapes,S.ShapeType(),Primitives,ValidShapes,Res);
664 return;
665 }
666 if ((Evol == TNaming_GENERATED) && IsNewInLab (S,Lab,PrevTrans)) {
667 Localize(PrevIn,Lab,S,Res);
668 return;
669 }
670 }
671
672 if (HasLabel && HasAscendant(myUS,S,PrevTrans)) {
673 //-------------------
674 // Remontee Descente.
675 //-------------------
676 Backward (S, Primitives, ValidShapes);
677 Forward (CurSubShapes,S.ShapeType(),Primitives,ValidShapes,Res);
678 }
679 else {
680 //----------------------------------------------
681 // Localisation des ancetres.
682 //----------------------------------------------
683 TopTools_MapOfShape AncInFeature;
684 FindFeaturesInAncestors (S, PrevIn, AncInFeature);
685 TopTools_MapIteratorOfMapOfShape itF(AncInFeature);
686 Standard_Boolean First = Standard_True;
687
688 for ( ; itF.More(); itF.Next()) {
689 const TopoDS_Shape& AncOfS = itF.Key();
690 TNaming_ShapesSet ResAnc;
691
692 Localize (PrevIn, CurIn, AncOfS, ResAnc);
693
694 //---------------------------
695 // Res = Commun des resultats
696 //---------------------------
697 if (First) {
698 Explode (ResAnc,S.ShapeType(),Res);
699 First = 0;
700 }
701 else {
702 TNaming_ShapesSet ResGoodType;
703 Explode (ResAnc,S.ShapeType(),ResGoodType);
704 Res.Filter(ResGoodType);
705 }
706 }
707 }
708}
709*/
710
711//=======================================================================
712//function : FindGenerator
713//purpose : Finds all generators of the <S> kept in <NS>
714//=======================================================================
715
716void TNaming_Localizer::FindGenerator (const Handle(TNaming_NamedShape)& NS,
717 const TopoDS_Shape& S,
718 TopTools_ListOfShape& theListOfGenerators)
719
720{
721 Handle(TNaming_UsedShapes) US;
722 TDF_Label LabNS = NS->Label();
723 (LabNS.Root()).FindAttribute(TNaming_UsedShapes::GetID(),US);
724
725 for (TNaming_OldShapeIterator it (S,US); it.More(); it.Next()) {
726 if (it.Label() == LabNS) {
727 theListOfGenerators.Append(it.Shape());
728// break; //szy 16.10.03
729
730 }
731 }
732}
733
734//=======================================================================
735//function : FindShapeContext
736//purpose : Finds context of the shape <S>.
737// : Looks for all oldshapes kept at father label of <NS>.
738// : If <S> validated as subshape of one of the old shapes -
739// : this oldshape is Context.
740//=======================================================================
741
742void TNaming_Localizer::FindShapeContext (const Handle(TNaming_NamedShape)& NS,
743 const TopoDS_Shape& S,
744 TopoDS_Shape& SC)
745
746{
747#ifdef MDTV_DEB_SC
748 LWrite(S, "FSC_Sel.brep"); LPrintEntry( NS->Label());
749#endif
750 TopTools_ListOfShape aList;
751 TDF_Label Father = NS->Label().Father();
752 TNaming_Iterator itLab(Father);
753 for (; itLab.More(); itLab.Next()) {
754 aList.Append(itLab.OldShape()); //szy
755 }
756// szy
757 TopTools_ListIteratorOfListOfShape it(aList);
758 Standard_Boolean found = 0;
759 for(;it.More();it.Next()) {
760 SC = it.Value();
761#ifdef MDTV_DEB_SC
762 LWrite(SC, "FSC_OldShape.brep");
763#endif
764 if (SC.IsNull()) continue;
765 else {
766 if (SC.ShapeType() < S.ShapeType()) {
767 for (TopExp_Explorer exp(SC,S.ShapeType()); exp.More(); exp.Next()) {
768 if (exp.Current().IsSame(S)) {
769 found = 1;
770#ifdef MDTV_DEB_SC
771 cout << "Find Context shape = " << SC.TShape() << "ShapeType = " << SC.ShapeType() <<endl;
772#endif
773 break;
774 }
775 }
776 if(found) break;
777 }
778 }
779 }
780// end szy
781#ifdef OCC351
782 if (!SC.IsNull()) {
783 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(SC,Father);
784 if (!aNS.IsNull()) {
785#ifdef MDTV_DEB_SC
786 cout << "FindShapeContext: ";LPrintEntry(aNS->Label());
787#endif
788 if (aNS->Label().Father().FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
789 TopoDS_Shape aShape;
790#ifdef MDTV_DEB_SC
791 LWriteNSOnLabel(aNS, "FSC");
792#endif
793 TNaming_Iterator anIter(aNS->Label());
794 for(;anIter.More();anIter.Next()) {
795 aShape = anIter.NewShape();
796 if (!aShape.IsNull()) break;
797 }
798 if (!aShape.IsNull()) SC=aShape;
799 }
800 }
801 }
802#endif
803
804}
805
806/*
807//=======================================================================
808//function : Localize
809//purpose :
810//=======================================================================
811
812void TNaming_Localizer::Localize(const TopoDS_Shape& PrevIn,
813 const TDF_Label& InLab ,
814 const TopoDS_Shape& S,
815 TNaming_ShapesSet& Res)
816{
817 Res.Clear();
818 TDF_LabelMap Primitives;
819 TopTools_MapOfShape ValidShapes;
820 Standard_Integer PrevTrans = myCurTrans - 1;
821
822 //---------------------------------------------
823 // Recuperation du nouveau contenant generateur.
824 //---------------------------------------------
825 TopoDS_Shape CurIn;
826 TDF_Label Father = InLab.Father();
827 TNaming_Iterator itLab(Father,myCurTrans);
828 for (; itLab.More(); itLab.Next()) {
829 CurIn= itLab.OldShape();
830 break;
831 }
832
833 Standard_Boolean First = 1;
834 TNaming_OldShapeIterator OldIt(S, PrevTrans,myUS);
835
836 for (; OldIt.More(); OldIt.Next()) {
837 if (OldIt.Label().IsEqual(InLab)) {
838 TNaming_ShapesSet RO;
839 TNaming_ShapesSet RInLab;
840 const TopoDS_Shape& OS = OldIt.Shape();
841 //---------------------------------
842 // Localisation des generateurs.
843 //---------------------------------
844 Localize(PrevIn,CurIn ,OS, RO);
845
846 //--------------------------------------------------------------------
847 // Resultat = intersection des descendants(dans InLab) des generateurs
848 //--------------------------------------------------------------------
849 TNaming_IteratorOnShapesSet itRO(RO);
850 for (; itRO.More(); itRO.Next()) {
851 const TopoDS_Shape& CO = itRO.Value();
852 TNaming_NewShapeIterator NewIt(CO,myCurTrans,myUS);
853 for (; NewIt.More(); NewIt.Next()) {
854 if (NewIt.Label().IsEqual(InLab)) {
855 if (First) Res.Add(NewIt.Shape());
856 else {
857 RInLab.Add(NewIt.Shape());
858 }
859 }
860 }
861 }
862 if (!First) Res.Filter(RInLab);
863 First = Standard_False;
864 }
865 }
866}
867
868//=======================================================================
869//function : Forward
870//purpose :
871//=======================================================================
872
873void TNaming_Localizer::Forward(const TopTools_MapOfShape& CurSubShapes,
874 const TopAbs_ShapeEnum TS,
875 const TDF_LabelMap& Primitives,
876 const TopTools_MapOfShape& ValidShapes,
877 TNaming_ShapesSet& Res)
878{
879 //-------------------------------------------------------
880 // Descente dans la transaction courrante = myCurTrans
881 //----------------------------------------------------------
882 TopTools_MapIteratorOfMapOfShape itV(ValidShapes);
883 Standard_Boolean First = 1;
884 Standard_Boolean YaFromValid = 0;
885 Standard_Boolean YaFromPrimitives = 0;
886
887 for (; itV.More(); itV.Next()) {
888 YaFromValid = 1;
889 const TopoDS_Shape& NS = itV.Key();
890 if (First) {
891 GoForward (NS, CurSubShapes, TS, Res);
892 First = 0;
893 }
894 else {
895 TNaming_ShapesSet ResNS;
896 GoForward (NS, CurSubShapes, TS, ResNS);
897 Res.Filter(ResNS);
898 }
899 }
900
901 TDF_MapIteratorOfLabelMap itP(Primitives);
902 TNaming_ShapesSet ResPrim;
903
904 for ( ; itP.More(); itP.Next()) {
905 YaFromPrimitives = 1;
906 const TDF_Label& Lab = itP.Key();
907 TNaming_Iterator itL(Lab,myCurTrans);
908 TNaming_ShapesSet ResLab;
909
910 for (; itL.More(); itL.Next()) {
911 const TopoDS_Shape& NS = itL.NewShape();
912 GoForward (NS, CurSubShapes, TS, ResLab);
913 }
914 if (First) {
915 ResPrim = ResLab;
916 First = 0;
917 }
918 else
919 ResPrim.Filter(ResLab);
920 }
921
922 if (YaFromValid) {
923 if (YaFromPrimitives) {
924 Res.Filter(ResPrim);
925 }
926 }
927 else {
928 Res = ResPrim;
929 }
930}
931
932
933//=======================================================================
934//function : FilterbyNeighbourgs
935//purpose :
936//=======================================================================
937
938void TNaming_Localizer::FilterByNeighbourgs(const TopoDS_Shape& PrevIn,
939 const TopoDS_Shape& CurIn ,
940 const TopoDS_Shape& S,
941 TNaming_ShapesSet& Res)
942{
943 TopTools_MapOfShape Neighbourg;
944 TopAbs_ShapeEnum TA = S.ShapeType();
945 TopAbs_ShapeEnum TS = TopAbs_ShapeEnum (S.ShapeType()+1);
946 TNaming_DataMapOfShapeShapesSet MapShapeRes;
947 const TopTools_IndexedDataMapOfShapeListOfShape& PreAnc =
948 Ancestors(PrevIn,TS);
949
950 //--------------------------------
951 // Construction des Voisins.
952 //--------------------------------
953 FindNeighbourg (PrevIn,PreAnc,S,Neighbourg);
954 TopTools_MapIteratorOfMapOfShape itNeig(Neighbourg);
955
956 TNaming_ShapesSet NewNeig;
957 for (; itNeig.More(); itNeig.Next()) {
958 const TopoDS_Shape& Neig = itNeig.Key();
959 //--------------------------------------------
960 // Localisation des voisins.
961 //--------------------------------------------
962 if (!MapShapeRes.IsBound(Neig)) {
963 TNaming_ShapesSet ResNeig;
964 Localize(PrevIn,CurIn,Neig,ResNeig);
965 MapShapeRes.Bind(Neig,ResNeig);
966 NewNeig.Add(ResNeig);
967 }
968 else {
969 NewNeig.Add(MapShapeRes(Neig));
970 }
971 }
972
973 //---------------------------------------------
974 // Filtre la solution par le resultat du voisin.
975 // ie : F est solution si ses voisins dans CurSol
976 // sont dans les descendants des voisins
977 //---------------------------------------------
978 TNaming_ShapesSet Reject;
979 TNaming_IteratorOnShapesSet itRes(Res);
980
981 const TopTools_IndexedDataMapOfShapeListOfShape& CurAnc =
982 Ancestors(CurIn,TS);
983
984 for (; itRes.More(); itRes.Next()) {
985 const TopoDS_Shape& Cand = itRes.Value();
986 TopTools_MapOfShape Neighbourg;
987 FindNeighbourg (CurIn,CurAnc,Cand,Neighbourg);
988 TopTools_MapIteratorOfMapOfShape itNeig(Neighbourg);
989 for (; itNeig.More(); itNeig.Next()) {
990 const TopoDS_Shape& Neig = itNeig.Key();
991 if (!NewNeig.Contains(Neig)) {
992 Reject.Add(Cand);
993 break;
994 }
995 }
996 }
997 Res.Remove(Reject);
998}
999*/