0024263: TNaming_CopyShape::CopyTool failure
[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;
7fd59977 284 }
285 if (itLab.NewShape().IsSame(S)) {
286 return Standard_True;
7fd59977 287 }
288 }
289#ifdef DEB
290 cout <<"TNaming_Localizer:IsNewInLab : Shape n est pas dans le Label."<<endl;
291#endif
292 return Standard_False;
293}
294
295
296//=======================================================================
297//function : Back
298//purpose :
299//=======================================================================
300
301void TNaming_Localizer::GoBack (const TopoDS_Shape& S,
302 const TDF_Label& Lab,
303 const TNaming_Evolution Evol,
304 TopTools_ListOfShape& LBS,
305 TNaming_ListOfNamedShape& LBNS)
306{
307// Standard_Integer TrDef;
308
309 TNaming_OldShapeIterator it(S,myCurTrans,myUS);
310 TopoDS_Shape Sol;
311 if (!it.More()) {
312 //-----------------------------------------------------------
313 // Pas d'ascendants => Recherche et exploration du contenant
314 //----------------------------------------------------------
b2197f93 315 const TDF_Label& Father = Lab.Father();
7fd59977 316 TNaming_Iterator itLab(Father);
b2197f93 317 if(itLab.More())
318 Sol = itLab.OldShape();
7fd59977 319 //-------------------------------------------
320 // Recherche des ancetres dans des features.
321 //-------------------------------------------
322 if (!Sol.IsNull()) {
323 TopTools_MapOfShape AncInFeature;
324 FindFeaturesInAncestors (S, Sol, AncInFeature);
325 TopTools_MapIteratorOfMapOfShape itF(AncInFeature);
326 for ( ; itF.More(); itF.Next()) {
d3f26155 327 const TopoDS_Shape& AncOfS = itF.Key();
328 LBS .Append(AncOfS);
329 LBNS.Append(TNaming_Tool::NamedShape(AncOfS,Lab));
7fd59977 330 }
331 }
332 }
333 else {
334 for ( ; it.More(); it.Next()) {
d3f26155 335 // if (it.NamedShape()->Evolution() != TNaming_SELECTED) {
7fd59977 336 if (it.NamedShape()->Evolution() == Evol) {
d3f26155 337 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape(it.Shape(),Lab);
338 if (!NS.IsNull()) {
339 LBS.Append (it.Shape());
340 LBNS.Append (TNaming_Tool::NamedShape(it.Shape(),Lab));
341 }
342 else {
7fd59977 343#ifdef DEB
d3f26155 344 cout <<"TNaming_Localizer: Shape modifie sans avoir ete cree"<<endl;
7fd59977 345#endif
d3f26155 346 }
7fd59977 347 }
348 }
349 }
350}
351/*
352//=======================================================================
353//function : Backward
354//purpose :
355//=======================================================================
356
357void TNaming_Localizer::Backward (const TopoDS_Shape& S,
358 TDF_LabelMap& Primitives,
359 TopTools_MapOfShape& ValidShapes)
360{
361 Standard_Integer PrevTrans = myCurTrans - 1;
362 Standard_Integer TrDef;
363 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
364 TNaming_Evolution Evol = Evolution(Lab);
365
366
367 TopTools_ListOfShape LBS;
368 TDF_LabelList LBLab;
369
370 GoBack(S,Lab,LBS,LBLab);
371
372
373 TopTools_ListIteratorOfListOfShape itLBS (LBS);
374 TDF_ListIteratorOfLabelList itLBLab(LBLab);
375
376 if (LBS.IsEmpty()) {
377 Primitives.Add(Lab);
378 }
379 for ( ; itLBS.More(); itLBS.Next(), itLBLab.Next()) {
380 const TopoDS_Shape& OS = itLBS.Value();
381 const TDF_Label& LabOS = itLBLab.Value();
382
383 Evol = Evolution(LabOS);
384
385 if (TNaming_Tool::ValidUntil(OS,myUS) >= myCurTrans) {
386 //---------------------------------------------------------
387 // Le Shape est valid dans la transaction myCurTrans => STOP
388 //---------------------------------------------------------
389 ValidShapes.Add(OS);
390 }
391 else if (Evol == TNaming_PRIMITIVE) {
392 Primitives.Add(LabOS);
393 }
394 else if ((Evol == TNaming_GENERATED) && IsNewInLab (OS,LabOS,PrevTrans)) {
395 //--------------------------------------------------------------
396 // Passage par une generation
397 // le shape dans myCurTrans descendra d un element de cet attribut.
398 // Localisation de OS dans la transaction courrante.
399 // les shapes obtenus seront des antecedants du shape cherche.
400 //--------------------------------------------------------------
401
402 // A faire seulememt si OS est un newShape dans LabOS.
403 TNaming_ShapesSet ResGen;
404 TopoDS_Shape PrevIn;
405 TDF_Label Father = LabOS.Father();
406 TNaming_Iterator itLab(Father,PrevTrans);
407 for (; itLab.More(); itLab.Next()) {
408 PrevIn= itLab.OldShape();
409 break;
410 }
411 Localize(PrevIn,LabOS,OS,ResGen);
412 for (TNaming_IteratorOnShapesSet itLoc(ResGen); itLoc.More(); itLoc.Next()) {
413 ValidShapes.Add(itLoc.Value());
414 }
415 }
416 else if (Evol == TNaming_SELECTED) {
417 //PAS FINI.
418 TNaming_ShapesSet ResSel;
419 TopoDS_Shape PrevIn,CurIn;
420// FindIn (LabOS,PrevIn,CurIn);
421 Localize(PrevIn,CurIn,OS,ResSel);
422 for (TNaming_IteratorOnShapesSet itLoc(ResSel); itLoc.More(); itLoc.Next()) {
423 ValidShapes.Add(itLoc.Value());
424 }
425 }
426 else {
427 Backward(itLBS.Value(),Primitives,ValidShapes);
428 }
429 }
430}
431*/
432
433//=======================================================================
434//function : NamedShape
435//purpose :
436//=======================================================================
437
438Handle(TNaming_NamedShape) NamedShape(const TDF_Label& Lab)
439{
440 Handle(TNaming_NamedShape) NS;
441 Lab.FindAttribute(TNaming_NamedShape::GetID(),NS);
442 return NS;
443}
444
445//=======================================================================
446//function : Backward
447//purpose :
448//=======================================================================
449
450void TNaming_Localizer::Backward (const Handle(TNaming_NamedShape)& NS,
451 const TopoDS_Shape& S,
452 TNaming_MapOfNamedShape& Primitives,
453 TopTools_MapOfShape& Shapes)
454{
455 TNaming_Evolution Evol = NS->Evolution();
456 TDF_Label LabNS = NS->Label();
457
458 TopTools_ListOfShape LBS;
459 TNaming_ListOfNamedShape LBNS;
460
461 GoBack(S,LabNS,Evol,LBS,LBNS);
462
463
464 TopTools_ListIteratorOfListOfShape itLBS (LBS);
465 TNaming_ListIteratorOfListOfNamedShape itLBNS (LBNS);
466
467 if (LBS.IsEmpty()) {
468 Primitives.Add(NS);
469 }
470 for ( ; itLBS.More(); itLBS.Next(), itLBNS.Next()) {
471 const TopoDS_Shape& OS = itLBS.Value();
472 Handle(TNaming_NamedShape) NOS = itLBNS.Value();
473 Evol = NOS->Evolution();
474 if (Evol == TNaming_PRIMITIVE) {
475 Primitives.Add(NOS);
476 }
477 else if (Evol == TNaming_GENERATED) {
478 Shapes.Add(OS);
479 }
480 else {
481 Backward(NOS, itLBS.Value(),Primitives,Shapes);
482 }
483 }
484}
485
486//=======================================================================
487//function : ValidCandidat
488//purpose :
489//=======================================================================
490
491#ifdef DEB
492/*static Standard_Boolean StoreValid (const TopoDS_Shape& S,
493 const TopTools_MapOfShape& ShapeOfSol,
494 TopAbs_ShapeEnum TargetType,
495 TNaming_ShapesSet& Res)
496{
497 Standard_Boolean Valid = Standard_False;
498
499 if (ShapeOfSol.Contains(S)) {
500 if (S.ShapeType() == TargetType) {
501 Res.Add(S);
502 return Standard_True;
503 }
504 else if (S.ShapeType() < TargetType) {
505 for (TopExp_Explorer exp(S,TargetType); exp.More(); exp.Next()) {
506 const TopoDS_Shape& SS = exp.Current();
507 Res.Add(SS);
508 Valid = Standard_True;
509 }
510 }
511 }
512 return Valid;
513}*/
514#endif
515
516/*
517//=======================================================================
518//function : Forward
519//purpose :
520//=======================================================================
521
522void TNaming_Localizer::GoForward(const TopoDS_Shape& S,
523 const TopTools_MapOfShape& Target,
524 const TopAbs_ShapeEnum TargetType,
525 TNaming_ShapesSet& Res)
526
527{
528 Standard_Integer TrDef;
529 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
530 if (StoreValid (S, Target, TargetType, Res)) {
531 return;
532 }
533 TNaming_Evolution Evol = Evolution(Lab);
534 TNaming_NewShapeIterator NewIt(S,myCurTrans,myUS);
535
536 for ( ; NewIt.More(); NewIt.Next()) {
537 const TopoDS_Shape& NS = NewIt.Shape();
538 GoForward ( NS, Target, TargetType, Res);
539 }
540}
541
542*/
543
544//=======================================================================
545//function : FindNeighbourg
546//purpose :
547//=======================================================================
548
549void TNaming_Localizer::FindNeighbourg (const TopoDS_Shape& Sol,
550 const TopoDS_Shape& S,
551 TopTools_MapOfShape& Neighbourg)
552{
553 TopAbs_ShapeEnum TA = S.ShapeType();
7fd59977 554 TopAbs_ShapeEnum TS=TopAbs_COMPOUND;
1d47d8d0 555
7fd59977 556 if (TA == TopAbs_FACE) TS = TopAbs_EDGE;
557 if (TA == TopAbs_EDGE) TS = TopAbs_VERTEX;
558 if (TA == TopAbs_VERTEX) TS = TopAbs_VERTEX; // szy 30.03.10
559 const TopTools_IndexedDataMapOfShapeListOfShape& Anc = Ancestors(Sol,TS);
560// szy 30.03.10 to process case when Candidate is of type Vertex
561// if (TA == TopAbs_VERTEX) {
562//#ifdef DEB
563// cout <<"construction voisins des vertex impossible"<<endl;
564//#endif
565// return;
566// }
567 for (TopExp_Explorer Exp(S,TS); Exp.More(); Exp.Next()) {
568 const TopoDS_Shape& SS = Exp.Current();
569 if (!Anc.Contains(SS)) {
570 //----------------------------------------------------
571 // Construction des ancetres
572 //----------------------------------------------------
573 break;
574 }
575 else {
576 TopTools_ListIteratorOfListOfShape itL(Anc.FindFromKey(SS));
577 for ( ; itL.More(); itL.Next()) {
578 if (!itL.Value().IsSame(S)) {
579 Neighbourg.Add(itL.Value());
580 }
581 }
582 }
583 }
584}
585
586//=======================================================================
587//function : TNaming_Localizer
588//purpose :
589//=======================================================================
590
591TNaming_Localizer::TNaming_Localizer()
592{
593}
594
595
596//=======================================================================
597//function : Init
598//purpose :
599//=======================================================================
600
601void TNaming_Localizer::Init(const Handle(TNaming_UsedShapes)& US,
602 const Standard_Integer CurTrans)
603{
604 myUS = US;
605 myCurTrans = CurTrans;
606}
607
608
609//=======================================================================
610//function : Explode
611//purpose :
612//=======================================================================
613
614#ifdef DEB
615/*static void Explode (TNaming_ShapesSet& Res,
616 TopAbs_ShapeEnum TS,
617 TNaming_ShapesSet& ResGoodType)
618{
619 TNaming_IteratorOnShapesSet it(Res);
620 for ( ; it.More(); it.Next()) {
621 const TopoDS_Shape& S = it.Value();
622 TopExp_Explorer exp(S,TS);
623 for (; exp.More(); exp.Next()) {
624 ResGoodType.Add(exp.Current());
625 }
626 }
627} */
628#endif
629
630/*
631//=======================================================================
632//function : Localize
633//purpose :
634//=======================================================================
635
636void TNaming_Localizer::Localize(const TopoDS_Shape& PrevIn,
637 const TopoDS_Shape& CurIn ,
638 const TopoDS_Shape& S,
639 TNaming_ShapesSet& Res)
640{
641 Res.Clear();
642 TDF_LabelMap Primitives;
643 TopTools_MapOfShape ValidShapes;
644 Standard_Integer PrevTrans = myCurTrans-1;
645
646 const TopTools_MapOfShape& CurSubShapes = SubShapes (CurIn,S.ShapeType());
647
648 Standard_Boolean HasLabel = TNaming_Tool::HasLabel(myUS,S);
649
650 if (HasLabel) {
651 Standard_Integer TrDef;
652 TDF_Label Lab = TNaming_Tool::Label (myUS, S, TrDef);
653 TNaming_Evolution Evol = Evolution(Lab);
654 if (Evol == TNaming_PRIMITIVE) {
655 //------------------------
656 // Label est une primitive
657 //------------------------
658 Primitives.Add(Lab);
659 Forward (CurSubShapes,S.ShapeType(),Primitives,ValidShapes,Res);
660 return;
661 }
662 if ((Evol == TNaming_GENERATED) && IsNewInLab (S,Lab,PrevTrans)) {
663 Localize(PrevIn,Lab,S,Res);
664 return;
665 }
666 }
667
668 if (HasLabel && HasAscendant(myUS,S,PrevTrans)) {
669 //-------------------
670 // Remontee Descente.
671 //-------------------
672 Backward (S, Primitives, ValidShapes);
673 Forward (CurSubShapes,S.ShapeType(),Primitives,ValidShapes,Res);
674 }
675 else {
676 //----------------------------------------------
677 // Localisation des ancetres.
678 //----------------------------------------------
679 TopTools_MapOfShape AncInFeature;
680 FindFeaturesInAncestors (S, PrevIn, AncInFeature);
681 TopTools_MapIteratorOfMapOfShape itF(AncInFeature);
682 Standard_Boolean First = Standard_True;
683
684 for ( ; itF.More(); itF.Next()) {
685 const TopoDS_Shape& AncOfS = itF.Key();
686 TNaming_ShapesSet ResAnc;
687
688 Localize (PrevIn, CurIn, AncOfS, ResAnc);
689
690 //---------------------------
691 // Res = Commun des resultats
692 //---------------------------
693 if (First) {
694 Explode (ResAnc,S.ShapeType(),Res);
695 First = 0;
696 }
697 else {
698 TNaming_ShapesSet ResGoodType;
699 Explode (ResAnc,S.ShapeType(),ResGoodType);
700 Res.Filter(ResGoodType);
701 }
702 }
703 }
704}
705*/
706
707//=======================================================================
708//function : FindGenerator
709//purpose : Finds all generators of the <S> kept in <NS>
710//=======================================================================
711
712void TNaming_Localizer::FindGenerator (const Handle(TNaming_NamedShape)& NS,
713 const TopoDS_Shape& S,
714 TopTools_ListOfShape& theListOfGenerators)
715
716{
717 Handle(TNaming_UsedShapes) US;
718 TDF_Label LabNS = NS->Label();
719 (LabNS.Root()).FindAttribute(TNaming_UsedShapes::GetID(),US);
720
721 for (TNaming_OldShapeIterator it (S,US); it.More(); it.Next()) {
722 if (it.Label() == LabNS) {
723 theListOfGenerators.Append(it.Shape());
724// break; //szy 16.10.03
725
726 }
727 }
728}
729
730//=======================================================================
731//function : FindShapeContext
732//purpose : Finds context of the shape <S>.
733// : Looks for all oldshapes kept at father label of <NS>.
734// : If <S> validated as subshape of one of the old shapes -
735// : this oldshape is Context.
736//=======================================================================
737
738void TNaming_Localizer::FindShapeContext (const Handle(TNaming_NamedShape)& NS,
739 const TopoDS_Shape& S,
740 TopoDS_Shape& SC)
741
742{
743#ifdef MDTV_DEB_SC
744 LWrite(S, "FSC_Sel.brep"); LPrintEntry( NS->Label());
745#endif
746 TopTools_ListOfShape aList;
747 TDF_Label Father = NS->Label().Father();
748 TNaming_Iterator itLab(Father);
749 for (; itLab.More(); itLab.Next()) {
750 aList.Append(itLab.OldShape()); //szy
751 }
752// szy
753 TopTools_ListIteratorOfListOfShape it(aList);
754 Standard_Boolean found = 0;
755 for(;it.More();it.Next()) {
756 SC = it.Value();
757#ifdef MDTV_DEB_SC
758 LWrite(SC, "FSC_OldShape.brep");
759#endif
760 if (SC.IsNull()) continue;
761 else {
762 if (SC.ShapeType() < S.ShapeType()) {
763 for (TopExp_Explorer exp(SC,S.ShapeType()); exp.More(); exp.Next()) {
764 if (exp.Current().IsSame(S)) {
765 found = 1;
766#ifdef MDTV_DEB_SC
767 cout << "Find Context shape = " << SC.TShape() << "ShapeType = " << SC.ShapeType() <<endl;
768#endif
769 break;
770 }
771 }
772 if(found) break;
773 }
774 }
775 }
776// end szy
777#ifdef OCC351
778 if (!SC.IsNull()) {
779 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(SC,Father);
780 if (!aNS.IsNull()) {
781#ifdef MDTV_DEB_SC
782 cout << "FindShapeContext: ";LPrintEntry(aNS->Label());
783#endif
784 if (aNS->Label().Father().FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
785 TopoDS_Shape aShape;
786#ifdef MDTV_DEB_SC
787 LWriteNSOnLabel(aNS, "FSC");
788#endif
789 TNaming_Iterator anIter(aNS->Label());
790 for(;anIter.More();anIter.Next()) {
791 aShape = anIter.NewShape();
792 if (!aShape.IsNull()) break;
793 }
794 if (!aShape.IsNull()) SC=aShape;
795 }
796 }
797 }
798#endif
799
800}
801
802/*
803//=======================================================================
804//function : Localize
805//purpose :
806//=======================================================================
807
808void TNaming_Localizer::Localize(const TopoDS_Shape& PrevIn,
809 const TDF_Label& InLab ,
810 const TopoDS_Shape& S,
811 TNaming_ShapesSet& Res)
812{
813 Res.Clear();
814 TDF_LabelMap Primitives;
815 TopTools_MapOfShape ValidShapes;
816 Standard_Integer PrevTrans = myCurTrans - 1;
817
818 //---------------------------------------------
819 // Recuperation du nouveau contenant generateur.
820 //---------------------------------------------
821 TopoDS_Shape CurIn;
822 TDF_Label Father = InLab.Father();
823 TNaming_Iterator itLab(Father,myCurTrans);
824 for (; itLab.More(); itLab.Next()) {
825 CurIn= itLab.OldShape();
826 break;
827 }
828
829 Standard_Boolean First = 1;
830 TNaming_OldShapeIterator OldIt(S, PrevTrans,myUS);
831
832 for (; OldIt.More(); OldIt.Next()) {
833 if (OldIt.Label().IsEqual(InLab)) {
834 TNaming_ShapesSet RO;
835 TNaming_ShapesSet RInLab;
836 const TopoDS_Shape& OS = OldIt.Shape();
837 //---------------------------------
838 // Localisation des generateurs.
839 //---------------------------------
840 Localize(PrevIn,CurIn ,OS, RO);
841
842 //--------------------------------------------------------------------
843 // Resultat = intersection des descendants(dans InLab) des generateurs
844 //--------------------------------------------------------------------
845 TNaming_IteratorOnShapesSet itRO(RO);
846 for (; itRO.More(); itRO.Next()) {
847 const TopoDS_Shape& CO = itRO.Value();
848 TNaming_NewShapeIterator NewIt(CO,myCurTrans,myUS);
849 for (; NewIt.More(); NewIt.Next()) {
850 if (NewIt.Label().IsEqual(InLab)) {
851 if (First) Res.Add(NewIt.Shape());
852 else {
853 RInLab.Add(NewIt.Shape());
854 }
855 }
856 }
857 }
858 if (!First) Res.Filter(RInLab);
859 First = Standard_False;
860 }
861 }
862}
863
864//=======================================================================
865//function : Forward
866//purpose :
867//=======================================================================
868
869void TNaming_Localizer::Forward(const TopTools_MapOfShape& CurSubShapes,
870 const TopAbs_ShapeEnum TS,
871 const TDF_LabelMap& Primitives,
872 const TopTools_MapOfShape& ValidShapes,
873 TNaming_ShapesSet& Res)
874{
875 //-------------------------------------------------------
876 // Descente dans la transaction courrante = myCurTrans
877 //----------------------------------------------------------
878 TopTools_MapIteratorOfMapOfShape itV(ValidShapes);
879 Standard_Boolean First = 1;
880 Standard_Boolean YaFromValid = 0;
881 Standard_Boolean YaFromPrimitives = 0;
882
883 for (; itV.More(); itV.Next()) {
884 YaFromValid = 1;
885 const TopoDS_Shape& NS = itV.Key();
886 if (First) {
887 GoForward (NS, CurSubShapes, TS, Res);
888 First = 0;
889 }
890 else {
891 TNaming_ShapesSet ResNS;
892 GoForward (NS, CurSubShapes, TS, ResNS);
893 Res.Filter(ResNS);
894 }
895 }
896
897 TDF_MapIteratorOfLabelMap itP(Primitives);
898 TNaming_ShapesSet ResPrim;
899
900 for ( ; itP.More(); itP.Next()) {
901 YaFromPrimitives = 1;
902 const TDF_Label& Lab = itP.Key();
903 TNaming_Iterator itL(Lab,myCurTrans);
904 TNaming_ShapesSet ResLab;
905
906 for (; itL.More(); itL.Next()) {
907 const TopoDS_Shape& NS = itL.NewShape();
908 GoForward (NS, CurSubShapes, TS, ResLab);
909 }
910 if (First) {
911 ResPrim = ResLab;
912 First = 0;
913 }
914 else
915 ResPrim.Filter(ResLab);
916 }
917
918 if (YaFromValid) {
919 if (YaFromPrimitives) {
920 Res.Filter(ResPrim);
921 }
922 }
923 else {
924 Res = ResPrim;
925 }
926}
927
928
929//=======================================================================
930//function : FilterbyNeighbourgs
931//purpose :
932//=======================================================================
933
934void TNaming_Localizer::FilterByNeighbourgs(const TopoDS_Shape& PrevIn,
935 const TopoDS_Shape& CurIn ,
936 const TopoDS_Shape& S,
937 TNaming_ShapesSet& Res)
938{
939 TopTools_MapOfShape Neighbourg;
940 TopAbs_ShapeEnum TA = S.ShapeType();
941 TopAbs_ShapeEnum TS = TopAbs_ShapeEnum (S.ShapeType()+1);
942 TNaming_DataMapOfShapeShapesSet MapShapeRes;
943 const TopTools_IndexedDataMapOfShapeListOfShape& PreAnc =
944 Ancestors(PrevIn,TS);
945
946 //--------------------------------
947 // Construction des Voisins.
948 //--------------------------------
949 FindNeighbourg (PrevIn,PreAnc,S,Neighbourg);
950 TopTools_MapIteratorOfMapOfShape itNeig(Neighbourg);
951
952 TNaming_ShapesSet NewNeig;
953 for (; itNeig.More(); itNeig.Next()) {
954 const TopoDS_Shape& Neig = itNeig.Key();
955 //--------------------------------------------
956 // Localisation des voisins.
957 //--------------------------------------------
958 if (!MapShapeRes.IsBound(Neig)) {
959 TNaming_ShapesSet ResNeig;
960 Localize(PrevIn,CurIn,Neig,ResNeig);
961 MapShapeRes.Bind(Neig,ResNeig);
962 NewNeig.Add(ResNeig);
963 }
964 else {
965 NewNeig.Add(MapShapeRes(Neig));
966 }
967 }
968
969 //---------------------------------------------
970 // Filtre la solution par le resultat du voisin.
971 // ie : F est solution si ses voisins dans CurSol
972 // sont dans les descendants des voisins
973 //---------------------------------------------
974 TNaming_ShapesSet Reject;
975 TNaming_IteratorOnShapesSet itRes(Res);
976
977 const TopTools_IndexedDataMapOfShapeListOfShape& CurAnc =
978 Ancestors(CurIn,TS);
979
980 for (; itRes.More(); itRes.Next()) {
981 const TopoDS_Shape& Cand = itRes.Value();
982 TopTools_MapOfShape Neighbourg;
983 FindNeighbourg (CurIn,CurAnc,Cand,Neighbourg);
984 TopTools_MapIteratorOfMapOfShape itNeig(Neighbourg);
985 for (; itNeig.More(); itNeig.Next()) {
986 const TopoDS_Shape& Neig = itNeig.Key();
987 if (!NewNeig.Contains(Neig)) {
988 Reject.Add(Cand);
989 break;
990 }
991 }
992 }
993 Res.Remove(Reject);
994}
995*/