0024023: Revamp the OCCT Handle -- downcast (automatic)
[occt.git] / src / TNaming / TNaming_NamedShape.cxx
CommitLineData
b311480e 1// Created on: 1996-12-18
2// Created by: Yves FRICAUD
3// Copyright (c) 1996-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <TNaming_NamedShape.ixx>
18#include <TNaming_Builder.ixx>
19
20#include <TDF_Label.hxx>
21#include <TDF_Data.hxx>
22#include <TDF_DeltaOnAddition.hxx>
23#include <TDF_AttributeIterator.hxx>
24#include <TNaming_PtrNode.hxx>
25#include <TNaming_PtrRefShape.hxx>
26#include <TNaming_RefShape.hxx>
7fd59977 27#include <TNaming_UsedShapes.hxx>
28#include <TNaming_Tool.hxx>
29#include <TNaming_Iterator.hxx>
30#include <TNaming_NewShapeIterator.hxx>
31#include <TNaming_OldShapeIterator.hxx>
32#include <TNaming_SameShapeIterator.hxx>
33
34#include <TNaming_DeltaOnModification.hxx>
35#include <TNaming_DeltaOnRemoval.hxx>
36#include <Standard_NoMoreObject.hxx>
37#include <Standard_NoSuchObject.hxx>
38#include <Standard_ConstructionError.hxx>
39#include <Standard_NullObject.hxx>
40
41#include <gp_Pnt.hxx>
42#include <BRepBuilderAPI_MakeVertex.hxx>
43#include <TopoDS_Vertex.hxx>
44
45// Defines the nodes classes
46
47#include <Standard.hxx>
48#include <TNaming_CopyShape.hxx>
49
7fd59977 50//#define MDTV_DEB_HASL
51//=======================================================================
52//function : GetID
53//purpose :
54//=======================================================================
55
56const Standard_GUID& TNaming_NamedShape::GetID()
57{
58 static Standard_GUID TNaming_NamedShapeID("c4ef4200-568f-11d1-8940-080009dc3333");
59 return TNaming_NamedShapeID;
60}
61
62//=======================================================================
63//class: TNaming_Node
64//=======================================================================
65
66class TNaming_Node {
67public:
68 TNaming_Node(TNaming_PtrRefShape Old,
69 TNaming_PtrRefShape New)
70 : myOld(Old),myNew(New),
71 myAtt(0L),
72 nextSameAttribute(0L), nextSameOld(0L),nextSameNew(0L)
73 {}
74
75 //Label : Donne le Label
76 TDF_Label Label();
77
78 // NextSameShape
79 TNaming_Node* NextSameShape(TNaming_RefShape* prs);
80
81 // Test si l evolution est valide dans la transaction Trans
82 // ie : Trans n est pas anterieure a sa creation
83 // et Trans n est pas posterieure a son BackUp
84 Standard_Boolean IsValidInTrans(Standard_Integer Trans);
85
86 // Memory management
1c35b92f 87 DEFINE_STANDARD_ALLOC
7fd59977 88
89 TNaming_PtrRefShape myOld;
90 TNaming_PtrRefShape myNew;
91 TNaming_NamedShape* myAtt;
92 TNaming_PtrNode nextSameAttribute;
93 TNaming_PtrNode nextSameOld;
94 TNaming_PtrNode nextSameNew;
95};
96
97//=======================================================================
98//function : NextSameShape
99//purpose :
100//=======================================================================
101
102TNaming_Node* TNaming_Node::NextSameShape(TNaming_RefShape* prs)
103{
104 if (myOld == prs) return nextSameOld;
105 if (myNew == prs) return nextSameNew;
106 return nextSameNew;
107}
108
109//=======================================================================
110//function : Label
111//purpose :
112//=======================================================================
113
114TDF_Label TNaming_Node::Label()
115{
116 return myAtt->Label();
117}
118
119//=======================================================================
120//function : IsValidInTrans
121//purpose :
122//=======================================================================
123
124Standard_Boolean TNaming_Node::IsValidInTrans(Standard_Integer Trans)
125{
126 if (myAtt->Transaction() <= Trans && Trans <= myAtt->UntilTransaction()) {
127 return 1;
128 }
129 return 0;
130}
131
132//**********************************************************************
133// Methods of TNaming_NamedShape
134//**********************************************************************
135
136//=======================================================================
137//function : TNaming_NamedShape
138//purpose :
139//=======================================================================
140
141TNaming_NamedShape::TNaming_NamedShape()
142{
143 myNode = 0L;
144 myVersion = 0;
145}
146
147//=======================================================================
148//function : IsEmpty
149//purpose :
150//=======================================================================
151
152Standard_Boolean TNaming_NamedShape::IsEmpty () const
153{
154 TNaming_Iterator it (this);
155 return !it.More();
156}
157
158
159//=======================================================================
160//function : Get
161//purpose :
162//=======================================================================
163
164TopoDS_Shape TNaming_NamedShape::Get () const
165{
166 return TNaming_Tool::GetShape (this);
167}
168
169
170
171
172//=======================================================================
173//function : RemoveNode
174//purpose :
175//=======================================================================
176
177static void RemoveNode(Standard_Boolean MapExist ,
178 TNaming_DataMapOfShapePtrRefShape& M,
179 TNaming_Node*& N)
180{
181 TNaming_RefShape* pos = N->myOld;
182 if (pos != 0L) {
183 if (pos->FirstUse() == N) {
184 TNaming_Node* nextOld = N->nextSameOld;
185 if (nextOld != 0L)
997cf5f2
G
186 pos->FirstUse(nextOld);
187 else {
188 // le shape disparait
189 if (MapExist)
190 M.UnBind(pos->Shape());
997cf5f2
G
191 N->myOld = 0L;
192 if(pos != N->myNew)
193 {
194 delete pos;
195 pos = 0L;
196 }
997cf5f2 197 }
7fd59977 198 }
199 else {
200 TNaming_Node* pdn = pos->FirstUse();
201 while (pdn != 0L) {
997cf5f2
G
202
203 if (pdn->NextSameShape(pos) == N) {
204 if (pdn->myOld == pos) pdn->nextSameOld = N->nextSameOld;
205 else pdn->nextSameNew = N->nextSameOld;
206 break;
207 }
208 pdn = pdn->NextSameShape(pos);
7fd59977 209 }
210 }
211 }
212
213 TNaming_RefShape* pns = N->myNew;
214 if (pns != 0L) {
215 if (pns->FirstUse() == N) {
216 TNaming_Node* nextNew = N->nextSameNew;
217 if (nextNew != 0L)
997cf5f2 218 pns->FirstUse(nextNew);
7fd59977 219 else
997cf5f2
G
220 {
221 // le shape disparait
222 if (MapExist)
223 M.UnBind(pns->Shape());
224
225 pns->FirstUse(0L);
226 delete pns;
227 pns = 0L;
228
229 N->myNew = 0L;
230
231 }
7fd59977 232 }
233 else {
234 TNaming_Node* pdn = pns->FirstUse();
235 while (pdn != 0L) {
997cf5f2
G
236 if (pdn->NextSameShape(pns) == N) {
237 if (pdn->myOld == pns) pdn->nextSameOld = N->nextSameNew;
238 else pdn->nextSameNew = N->nextSameNew;
239 break;
240 }
241 pdn = pdn->NextSameShape(pns);
7fd59977 242 }
243 }
244 }
245}
246
247//=======================================================================
248//function : Clear
249//purpose :
250//=======================================================================
251
252void TNaming_NamedShape::Clear()
253{
254 if (Label().IsNull()) {
0797d9d3 255#ifdef OCCT_DEBUG_BUILDER
7fd59977 256 cout << "attention etat fantomatique" << endl;
257#endif
258 return;
259 }
260
261 Handle(TNaming_UsedShapes) US;
262
263 TNaming_DataMapOfShapePtrRefShape* M=NULL;
264
265 // Recuperation de la map si celle-ci n est pas deja detruite.
266 //Standard_Boolean MapExist = Ins.FindInRoot(TNaming_UsedShapes::GetID(),US);
267
268 Standard_Boolean MapExist = Label().Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
269 if (MapExist) M = &(US->Map());
270
271 TNaming_Node* p = myNode;
272 while (p != 0L) {
273 RemoveNode (MapExist,*M,p);
274 p = p->nextSameAttribute;
275 }
276
277 p = myNode;
278 TNaming_Node* q;
279 while (p != 0L) {
280 q = p;
281 p = p->nextSameAttribute;
997cf5f2
G
282 if( q !=0L)
283 {
284 delete q;
285 q = 0L;
286 }
7fd59977 287 }
288
289 myNode = 0L;
290}
291
292//=======================================================================
293//function : BeforeRemoval
294//purpose :
295//=======================================================================
296
297void TNaming_NamedShape::BeforeRemoval()
298{
299 Clear();
300}
301
302
303//=======================================================================
304//function : BeforeUndo
305//purpose : before application of a TDF_Delta.
306//=======================================================================
307
308Standard_Boolean TNaming_NamedShape::BeforeUndo
309 (const Handle(TDF_AttributeDelta)& /*anAttDelta*/,
310 const Standard_Boolean /*forceIt*/)
311{
312// if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) {
313// anAttDelta->Attribute()->BeforeRemoval();
314// }
315 return Standard_True;
316}
317
318//=======================================================================
319//function : AfterUndo
320//purpose : After application of a TDF_Delta.
321//=======================================================================
322
323Standard_Boolean TNaming_NamedShape::AfterUndo
324 (const Handle(TDF_AttributeDelta)& anAttDelta,
325 const Standard_Boolean /*forceIt*/)
326{
327 if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) {
328 Handle(TNaming_UsedShapes) US;
329
330 TNaming_DataMapOfShapePtrRefShape* M=NULL;
331
332 // Recuperation de la map si celle-ci n est pas deja detruite.
333 //Standard_Boolean MapExist = Ins.FindInRoot(TNaming_UsedShapes::GetID(),US);
334
335 Standard_Boolean MapExist = anAttDelta->Label().Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
336
337 if (MapExist) M = &(US->Map());
338
339 TNaming_Node* p = myNode;
340 while (p != 0L) {
341 RemoveNode (MapExist,*M,p);
342 p = p->nextSameAttribute;
343 }
344
345 p = myNode;
346 TNaming_Node* q;
347 while (p != 0L) {
348 q = p;
349 p = p->nextSameAttribute;
997cf5f2
G
350 if(q != 0L)
351 {
352 delete q;
353 q = 0L;
354 }
7fd59977 355 }
356
357 myNode = 0L;
358 }
359 return Standard_True;
360}
361
362
363//=======================================================================
364//function : BackupCopy
365//purpose :
366//=======================================================================
367
368Handle(TDF_Attribute) TNaming_NamedShape::BackupCopy() const
369{
370 // Remarque dans le copy il est important de reporter le noeud de l attribut
371 // pour ne pas casser le chemin nextSameShape.
372
373 Handle(TNaming_NamedShape) Cop = new TNaming_NamedShape();
374 Cop->myNode = myNode;
375 Cop->myEvolution = myEvolution;
376 Cop->myVersion = myVersion;
377
378 // Mise a jour de myAtt sur les noeuds dans l attribut.
379 TNaming_Node* CN = Cop->myNode;
380
381 Handle(TNaming_NamedShape) A = this;
382 A->myNode = 0L;
383
384 while (CN != 0L) {
385 CN->myAtt = Cop.operator->();
386 CN = CN->nextSameAttribute;
387 }
388 return Cop;
389}
390
391
392//=======================================================================
393//function : Restore
394//purpose :
395//=======================================================================
396
397void TNaming_NamedShape::Restore(const Handle(TDF_Attribute)& anAttribute)
398{
399 Clear();
400
401 TNaming_NamedShape* PAtt = (TNaming_NamedShape*)anAttribute.operator->();
402 myNode = PAtt->myNode;
403 myEvolution = PAtt->myEvolution;
404 myVersion = PAtt->myVersion;
405
406 // Mise a jour de myAtt sur les noeuds dans l attribut.
407 TNaming_Node* CN = myNode;
408 while (CN != 0L) {
409 CN->myAtt = this;
410 CN = CN->nextSameAttribute;
411 }
412 PAtt->myNode = 0L; //un noeud est dans un seul attribut.
413}
414
415
416//=======================================================================
417//function : DeltaOnModification
418//purpose :
419//=======================================================================
420
421Handle(TDF_DeltaOnModification) TNaming_NamedShape::DeltaOnModification
422(const Handle(TDF_Attribute)& anOldAttribute) const
423{
424
c5f3a425 425 return new TNaming_DeltaOnModification(Handle(TNaming_NamedShape)::DownCast (anOldAttribute));
7fd59977 426}
427
428//=======================================================================
429//function : DeltaOnModification
430//purpose :
431//=======================================================================
432
433void TNaming_NamedShape::DeltaOnModification(const Handle(TDF_DeltaOnModification)& aDelta)
434{
435 aDelta->Apply();
436}
437
438//=======================================================================
439//function : DeltaOnRemoval
440//purpose :
441//=======================================================================
442
443Handle(TDF_DeltaOnRemoval) TNaming_NamedShape::DeltaOnRemoval() const
444{
445 return new TNaming_DeltaOnRemoval(this);
446}
447
448//=======================================================================
449//function : NewEmpty
450//purpose :
451//=======================================================================
452
453Handle(TDF_Attribute) TNaming_NamedShape::NewEmpty () const
454{
455 return new TNaming_NamedShape();
456}
457
458//=======================================================================
7fd59977 459//function : Paste
460//purpose :
461//=======================================================================
462
463void TNaming_NamedShape::Paste(const Handle(TDF_Attribute)& into,
464 const Handle(TDF_RelocationTable)& Tab)
465const
466{
467 TDF_Label Lab = into->Label();
468 if (Lab.IsNull()) {
469 Standard_NullObject::Raise("TNaming_NamedShape::Paste");
470 }
471 TNaming_Builder B(Lab);
472
473 TNaming_Iterator It (this);
474 for ( ;It.More() ; It.Next()) {
475 const TopoDS_Shape& OS = It.OldShape();
476 const TopoDS_Shape& NS = It.NewShape();
477 TNaming_Evolution Status = It.Evolution();
478
479// Modification_1 24.06.99 (szy)
480 TopoDS_Shape copOS, copNS;
481 if(Status != TNaming_PRIMITIVE)
482 TNaming_CopyShape::CopyTool(OS, Tab->TransientTable(), copOS);
483 else copOS.Nullify();
484 if(Status != TNaming_DELETE )
485 TNaming_CopyShape::CopyTool(NS, Tab->TransientTable(), copNS);
486 else copNS.Nullify();
487
488 switch (Status) {
489 case TNaming_PRIMITIVE :
490 {
491 B.Generated(copNS);
492 break;
493 }
494 case TNaming_GENERATED :
495 {
496 B.Generated(copOS, copNS);
497 break;
498 }
499 case TNaming_MODIFY :
500 {
501 B.Modify(copOS, copNS);
502 break;
503 }
504 case TNaming_DELETE :
505 {
506 B.Delete (copOS);
507 break;
508 }
509 case TNaming_SELECTED :
510 {
511 B.Select(copNS,copOS);
512 break;
513 }
514
515 default:
516 break;
517 }
518 }
519}
520
521//=======================================================================
522//function : References
523//purpose :
524//=======================================================================
525
526void TNaming_NamedShape::References(const Handle(TDF_DataSet)& aDataSet) const
527{
528 // Recherche des dependances.
529 // Pour chaque OldShape de l attribut on ajoute au dataSet son label d origine.
530 TNaming_Node* Current = myNode;
531 while (Current != NULL) {
532 if (Current->myOld != NULL) {
533 TNaming_RefShape* prs = Current->myOld;
534 TNaming_Node* pdn = prs->FirstUse();
535
536 while (pdn != NULL) {
537 if (pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED) {
538 aDataSet->AddLabel(pdn->Label());
539 }
540 pdn = pdn->NextSameShape(prs);
541 }
542 }
543 Current = Current->nextSameAttribute;
544 }
545}
546
547
548//=======================================================================
549//function : Add
550//purpose :
551//=======================================================================
552
553void TNaming_NamedShape::Add(TNaming_Node*& pdn )
554{
555 pdn->myAtt = this;
c29a9290 556 if (myNode != 0L){
7fd59977 557 pdn->nextSameAttribute = myNode;
558 }
559 myNode = pdn;
560}
561
562//=======================================================================
563//function : Dump
564//purpose :
565//=======================================================================
566
567Standard_OStream& TNaming_NamedShape::Dump(Standard_OStream& anOS) const
568{
569 return anOS;
570}
571
572//***************************************
573// Fin Class Named_Shape.
574//***************************************
575
576
577//**********************************************************************
578// Methods of the TNaming_Builder class
579//**********************************************************************
580
581///=======================================================================
582//function : TNaming_Builder
583//purpose :
584//=======================================================================
585
586TNaming_Builder::TNaming_Builder (const TDF_Label& L)
587{
7fd59977 588 // Find or Build Map;
589 const TDF_Label& root = L.Root();
8b8bffc6 590 if (!root.FindAttribute(TNaming_UsedShapes::GetID(),myShapes)) {
591 myShapes = new TNaming_UsedShapes();
592 root.AddAttribute (myShapes);
7fd59977 593 }
7fd59977 594
595 //Find Or Build Attribute in LIns.
8b8bffc6 596 if (!L.FindAttribute(TNaming_NamedShape::GetID(),myAtt)) {
597 myAtt = new TNaming_NamedShape();
598 L.AddAttribute(myAtt);
7fd59977 599 }
600 else {
8b8bffc6 601 myAtt->Backup();
602 myAtt->Clear();
603 myAtt->myVersion++;
7fd59977 604 }
7fd59977 605}
606
607//=======================================================================
608//function : TNaming_Builder
609//purpose :
610//=======================================================================
611
612Handle(TNaming_NamedShape) TNaming_Builder::NamedShape() const
613{
614 return myAtt;
615}
616
617//=======================================================================
618//function : UpdateNextSameShape
619//purpose :
620//=======================================================================
621
622static void UpdateFirstUseOrNextSameShape(TNaming_RefShape*& prs,
623 TNaming_Node*& pdn)
624{
625 TNaming_Node* ldn = prs->FirstUse();
626 if (ldn == 0L) {
627 prs->FirstUse(pdn);
628 }
629 else {
630 TNaming_Node* cdn = ldn;
631 while (cdn != 0L) {
632 ldn = cdn;
633 cdn = cdn->NextSameShape(prs);
634 if (ldn == cdn) {
635 Standard_ConstructionError::Raise("UpdateFirstUseOrNextSameShape");
636 break;
637 }
638 }
639 // boucle interdite et inutile.
640 if (ldn != pdn) {
641 if (ldn->myOld == prs) ldn->nextSameOld = pdn;
642 if (ldn->myNew == prs) ldn->nextSameNew = pdn;
643 }
644 }
645}
646
647//=======================================================================
648//function : Generate
649//purpose :
650//=======================================================================
651
652void TNaming_Builder::Generated(const TopoDS_Shape& newShape)
653{
654 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_PRIMITIVE;
655 else {
656 if (myAtt->myEvolution != TNaming_PRIMITIVE)
657 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
658 }
659
660 TNaming_RefShape* pos = 0L;
661 TNaming_RefShape* pns;
662
8b8bffc6 663 if (myShapes->myMap.IsBound(newShape)) {
0797d9d3 664#ifdef OCCT_DEBUG_BUILDER
7fd59977 665 cout <<"TNaming_Builder::Generate : the shape is already in the attribute"<<endl;
666#endif
8b8bffc6 667 pns = myShapes->myMap.ChangeFind(newShape);
668 if (pns->FirstUse()->myAtt == myAtt.operator->()) {
7fd59977 669 Standard_ConstructionError::Raise("TNaming_Builder::Generate");
670 }
671 TNaming_Node* pdn = new TNaming_Node(pos,pns);
672 myAtt->Add(pdn);
673 UpdateFirstUseOrNextSameShape (pns,pdn);
674 }
675 else {
676 pns = new TNaming_RefShape(newShape);
677 TNaming_Node* pdn = new TNaming_Node(pos,pns);
678 pns ->FirstUse(pdn);
8b8bffc6 679 myShapes->myMap.Bind (newShape , pns);
7fd59977 680 myAtt->Add(pdn);
681 }
682}
683
684
685
686//=======================================================================
687//function : Delete
688//purpose :
689//=======================================================================
690
691void TNaming_Builder::Delete(const TopoDS_Shape& oldShape)
692{
693 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_DELETE;
694 else {
695 if (myAtt->myEvolution != TNaming_DELETE)
696 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
697 }
698
699 TNaming_RefShape* pns = 0L;
700 TNaming_RefShape* pos;
701
8b8bffc6 702 if (myShapes->myMap.IsBound(oldShape))
703 pos = myShapes->myMap.ChangeFind(oldShape);
7fd59977 704 else {
0797d9d3 705#ifdef OCCT_DEBUG_BUILDER
7fd59977 706 cout <<"TNaming_Builder::Delete : the shape is not in the data"<<endl;
707#endif
708 pos = new TNaming_RefShape(oldShape);
8b8bffc6 709 myShapes->myMap.Bind(oldShape, pos);
7fd59977 710 }
711 TNaming_Node* pdn = new TNaming_Node(pos,pns);
712 myAtt->Add(pdn);
713 UpdateFirstUseOrNextSameShape (pos,pdn);
714}
715
716//=======================================================================
717//function : Generate
718//purpose :
719//=======================================================================
720
721void TNaming_Builder::Generated(const TopoDS_Shape& oldShape,
722 const TopoDS_Shape& newShape)
723{
724 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_GENERATED;
725 else {
726 if (myAtt->myEvolution != TNaming_GENERATED)
727 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
728 }
729
730 if (oldShape.IsSame(newShape)) {
0797d9d3 731#ifdef OCCT_DEBUG_BUILDER
7fd59977 732 cout <<"TNaming_Builder::Generate : oldShape IsSame newShape"<<endl;
733#endif
734 return;
735 }
736 TNaming_RefShape* pos;
8b8bffc6 737 if (!myShapes->myMap.IsBound(oldShape)) {
7fd59977 738 pos = new TNaming_RefShape(oldShape);
8b8bffc6 739 myShapes->myMap.Bind(oldShape,pos);
7fd59977 740 }
741 else
8b8bffc6 742 pos = myShapes->myMap.ChangeFind(oldShape);
7fd59977 743
744 TNaming_RefShape* pns;
8b8bffc6 745 if (!myShapes->myMap.IsBound(newShape)) {
7fd59977 746 pns = new TNaming_RefShape(newShape);
8b8bffc6 747 myShapes->myMap.Bind(newShape,pns);
7fd59977 748 }
749 else
8b8bffc6 750 pns = myShapes->myMap.ChangeFind(newShape);
7fd59977 751
752 TNaming_Node* pdn = new TNaming_Node(pos,pns);
753 myAtt->Add(pdn);
754 UpdateFirstUseOrNextSameShape (pos,pdn);
755 UpdateFirstUseOrNextSameShape (pns,pdn);
756}
757
758
759//=======================================================================
760//function : Modify
761//purpose :
762//=======================================================================
763
764void TNaming_Builder::Modify(const TopoDS_Shape& oldShape,
765 const TopoDS_Shape& newShape)
766{
767 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_MODIFY;
768 else {
769 if (myAtt->myEvolution != TNaming_MODIFY)
770 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
771 }
772
773 if (oldShape.IsSame(newShape)) {
0797d9d3 774#ifdef OCCT_DEBUG_BUILDER
7fd59977 775 cout <<"TNaming_Builder::Modify : oldShape IsSame newShape"<<endl;
776#endif
777 return;
778 }
779 TNaming_RefShape* pos;
8b8bffc6 780 if (!myShapes->myMap.IsBound(oldShape)) {
7fd59977 781 pos = new TNaming_RefShape(oldShape);
8b8bffc6 782 myShapes->myMap.Bind(oldShape,pos);
7fd59977 783 }
784 else
8b8bffc6 785 pos = myShapes->myMap.ChangeFind(oldShape);
7fd59977 786
787 TNaming_RefShape* pns;
8b8bffc6 788 if (!myShapes->myMap.IsBound(newShape)) {
7fd59977 789 pns = new TNaming_RefShape(newShape);
8b8bffc6 790 myShapes->myMap.Bind(newShape,pns);
7fd59977 791 }
792 else
8b8bffc6 793 pns = myShapes->myMap.ChangeFind(newShape);
7fd59977 794
795 TNaming_Node* pdn = new TNaming_Node(pos,pns);
796 myAtt->Add(pdn);
797 UpdateFirstUseOrNextSameShape (pos,pdn);
798 UpdateFirstUseOrNextSameShape (pns,pdn);
799
800}
801
802//=======================================================================
7fd59977 803//function : Select
804//purpose :
805//=======================================================================
806void TNaming_Builder::Select (const TopoDS_Shape& S,
807 const TopoDS_Shape& InS)
808{
809 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_SELECTED;
810 else {
811 if (myAtt->myEvolution != TNaming_SELECTED)
812 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
813 }
814
7dcac1df 815 TNaming_RefShape* pos;
816 if (!myShapes->myMap.IsBound(InS)) {
817 pos = new TNaming_RefShape(InS);
818 myShapes->myMap.Bind(InS,pos);
7fd59977 819 }
7dcac1df 820 else
821 pos = myShapes->myMap.ChangeFind(InS);
7fd59977 822
823 TNaming_RefShape* pns;
8b8bffc6 824 if (!myShapes->myMap.IsBound(S)) {
7fd59977 825 pns = new TNaming_RefShape(S);
8b8bffc6 826 myShapes->myMap.Bind(S,pns);
7fd59977 827 }
828 else
8b8bffc6 829 pns = myShapes->myMap.ChangeFind(S);
7fd59977 830
831 TNaming_Node* pdn = new TNaming_Node(pos,pns);
832 myAtt->Add(pdn);
833 UpdateFirstUseOrNextSameShape (pos,pdn);
834 UpdateFirstUseOrNextSameShape (pns,pdn);
835}
836
837//**********************************************************************
838//Methods of the TNaming_Iterator class
839//**********************************************************************
840
841//=======================================================================
842//function : TNaming_Iterator
843//purpose :
844//=======================================================================
845
846TNaming_Iterator::TNaming_Iterator(const Handle(TNaming_NamedShape)& Att)
847:myTrans(-1)
848{
849 myNode = Att->myNode;
850}
851
852//=======================================================================
853//function : TNaming_Iterator
854//purpose :
855//=======================================================================
856
857TNaming_Iterator::TNaming_Iterator(const TDF_Label& Lab)
858:myTrans(-1)
859{
860 Handle(TNaming_NamedShape) Att;
861 if (Lab.FindAttribute(TNaming_NamedShape::GetID(),Att)) {
862 myNode = Att->myNode;
863 }
864 else {
865 myNode = 0L;
866 }
867}
868
869//=====================================================================
870//function : TNaming_Iterator
871//purpose :
872//=======================================================================
873
874TNaming_Iterator::TNaming_Iterator(const TDF_Label& Lab,
875 const Standard_Integer Trans)
876:myTrans(Trans)
877{
878 Handle(TNaming_NamedShape) Att;
879 if (Lab.FindAttribute(TNaming_NamedShape::GetID(),Trans,Att)) {
880 myNode = Att->myNode;
881 }
882 else {
883 myNode = 0L;
0797d9d3 884#ifdef OCCT_DEBUG
7fd59977 885 cout <<"TNaming_Iterator : No Shape for this label"<<endl;
886#endif
887 }
888}
889
890//=======================================================================
891//function : Next
892//purpose :
893//=======================================================================
894
895void TNaming_Iterator::Next()
896{
897 Standard_NoMoreObject_Raise_if(myNode == 0L,
898 "TNaming_Iterator::Next");
899 myNode = myNode->nextSameAttribute;
900}
901
902//=======================================================================
903//function : OldShape
904//purpose :
905//=======================================================================
906
907const TopoDS_Shape& TNaming_Iterator::OldShape() const
908{
909 Standard_NoSuchObject_Raise_if(myNode == 0L,
910 "TNaming_Iterator::OldShape");
911 if (myNode->myOld == 0L) {
912 static TopoDS_Shape NullShape;
913 return NullShape;
914 }
915 return myNode->myOld->Shape();
916}
917
918//=======================================================================
919//function : NewShape
920//purpose :
921//=======================================================================
922
923const TopoDS_Shape& TNaming_Iterator::NewShape() const
924{
925 Standard_NoSuchObject_Raise_if(myNode == 0L,
926 "TNaming_Iterator::NewShape");
927 if (myNode->myNew == 0L) {
928 static TopoDS_Shape NullShape;
929 return NullShape;
930 }
931 return myNode->myNew->Shape();
932}
933
934
935//=======================================================================
936//function : IsModification
937//purpose :
938//=======================================================================
939
940Standard_Boolean TNaming_Iterator::IsModification() const
941{
942 Standard_NoSuchObject_Raise_if(myNode == 0L,
943 "TNaming_Iterator::IsModification");
944 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
945 myNode->myAtt->myEvolution == TNaming_DELETE );
946}
947
948//=======================================================================
949//function : Evolution
950//purpose :
951//=======================================================================
952
953TNaming_Evolution TNaming_Iterator::Evolution() const
954{
955 Standard_NoSuchObject_Raise_if(myNode == 0L,
956 "TNaming_Iterator::IsModification");
957 return myNode->myAtt->myEvolution;
958}
959
960
961
962//**********************************************************************
963//Methods of the TNaming_NewShapeIterator class
964//**********************************************************************
965
966//=======================================================================
967//function : SelectSameShape
968//purpose : Selectionne le prochain noeud ou le shape est le meme que celui
969// de RS. Old = 0 si il doit etre new dans le noeud a chercher.
970// selection dans la transaction valide.
971// On saute aussi les noeud ou OS = NS;
972//=======================================================================
973
974static void SelectSameShape (TNaming_Node*& myNode,
975 Standard_Boolean Old,
976 TNaming_RefShape*& RS,
977 const Standard_Integer& Trans)
978{
979 TNaming_Node* pdn = myNode;
980
981 while (pdn != 0L) {
982 Standard_Boolean Valid;
983 if (Trans < 0) Valid = pdn->myAtt->IsValid();
984 else Valid = pdn->IsValidInTrans(Trans);
985
986 if (Valid)
eafb234b 987 {
7fd59977 988 if (Old) {
eafb234b 989 if( pdn->myOld == RS && pdn->myNew != 0L && pdn->myNew != RS) {
990 break;
991 }
7fd59977 992 }
993 else {
eafb234b 994 if( pdn->myNew == RS && pdn->myOld != 0L && pdn->myOld != RS) {
995 break;
996 }
7fd59977 997 }
eafb234b 998 }
7fd59977 999 pdn = pdn->NextSameShape(RS);
1000 }
1001 myNode = pdn;
1002}
1003
1004//=======================================================================
1005//function : TNaming_NewShapeIterator
1006//purpose :
1007//=======================================================================
1008
1009TNaming_NewShapeIterator::TNaming_NewShapeIterator
1010(const TopoDS_Shape& aShape,
1011 const Standard_Integer Trans,
1012 const Handle(TNaming_UsedShapes)& Shapes)
1013:myTrans(Trans)
1014{
1015 Standard_Boolean Old = Standard_True;
1016 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1017 myNode = RS->FirstUse();
1018 SelectSameShape(myNode,Old,RS,myTrans);
1019}
1020
1021//=======================================================================
1022//function : TNaming_NewShapeIterator
1023//purpose :
1024//=======================================================================
1025
1026TNaming_NewShapeIterator::TNaming_NewShapeIterator
1027(const TopoDS_Shape& aShape,
1028 const Standard_Integer Trans,
1029 const TDF_Label& access)
1030:myTrans(Trans)
1031{
1032 Handle(TNaming_UsedShapes) Shapes;
1033 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1034 Standard_Boolean Old = Standard_True;
1035 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1036 myNode = RS->FirstUse();
1037 SelectSameShape(myNode,Old,RS,myTrans);
1038 }
1039}
1040
1041//=======================================================================
1042//function : TNaming_NewShapeIterator
1043//purpose :
1044//=======================================================================
1045
1046TNaming_NewShapeIterator::TNaming_NewShapeIterator (const TNaming_Iterator& anIterator)
1047:myTrans(anIterator.myTrans)
1048{
1049 Standard_Boolean Old = Standard_True;
1050 myNode = anIterator.myNode;
1051 TNaming_RefShape* RS = myNode->myNew;
1052 if (RS == 0L)
1053 myNode = 0L; // No descendant
1054 else {
1055 // il faut repartir de la premiere utilisation.
1056 myNode = RS->FirstUse();
1057 SelectSameShape(myNode,Old,RS,myTrans);
1058 }
1059}
1060
1061//=======================================================================
1062//function : TNaming_NewShapeIterator
1063//purpose :
1064//=======================================================================
1065
1066TNaming_NewShapeIterator::TNaming_NewShapeIterator
1067(const TopoDS_Shape& aShape,
1068 const Handle(TNaming_UsedShapes)& Shapes)
1069:myTrans(-1)
1070{
1071 Standard_Boolean Old = Standard_True;
1072 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1073 myNode = RS->FirstUse();
1074 SelectSameShape(myNode,Old,RS,myTrans);
1075}
1076
1077//=======================================================================
1078//function : TNaming_NewShapeIterator
1079//purpose :
1080//=======================================================================
1081
1082TNaming_NewShapeIterator::TNaming_NewShapeIterator
1083(const TopoDS_Shape& aShape,
1084 const TDF_Label& access)
1085:myTrans(-1)
1086{
1087 Handle(TNaming_UsedShapes) Shapes;
1088 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1089 Standard_Boolean Old = Standard_True;
1090 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1091 myNode = RS->FirstUse();
1092 SelectSameShape(myNode,Old,RS,myTrans);
1093 }
1094}
1095
1096//=======================================================================
1097//function : TNaming_NewShapeIterator
1098//purpose :
1099//=======================================================================
1100
1101TNaming_NewShapeIterator::TNaming_NewShapeIterator(const TNaming_NewShapeIterator& anIterator)
1102:myTrans(anIterator.myTrans)
1103{
1104 Standard_Boolean Old = Standard_True;
1105 myNode = anIterator.myNode;
1106 TNaming_RefShape* RS = myNode->myNew;
1107 if (RS == 0L)
1108 myNode = 0L; // No descendant
1109 else {
1110 // il faut repartir de la premiere utilisation.
1111 myNode = RS->FirstUse();
1112 SelectSameShape(myNode,Old,RS,myTrans);
1113 }
1114}
1115
1116//=======================================================================
1117//function : Next
1118//purpose :
1119//=======================================================================
1120
1121void TNaming_NewShapeIterator::Next()
1122{
1123 Standard_Boolean Old = Standard_True;
1124 TNaming_RefShape* RS = myNode->myOld;
1125 myNode = myNode->NextSameShape(RS);
1126 SelectSameShape(myNode,Old,RS,myTrans);
1127}
1128
1129//=======================================================================
1130//function : Label
1131//purpose :
1132//=======================================================================
1133
1134TDF_Label TNaming_NewShapeIterator::Label() const
1135{
1136 Standard_NoSuchObject_Raise_if(myNode == 0L,
1137 "TNaming_NewShapeIterator::Label");
1138 return myNode->Label();
1139}
1140
1141//=======================================================================
1142//function : NamedShape
1143//purpose :
1144//=======================================================================
1145
1146Handle(TNaming_NamedShape) TNaming_NewShapeIterator::NamedShape() const
1147{
1148 Standard_NoSuchObject_Raise_if(myNode == 0L,
1149 "TNaming_NewShapeIterator::Label");
1150 return myNode->myAtt;
1151}
1152
1153//=======================================================================
1154//function : Shape
1155//purpose :
1156//=======================================================================
1157
1158const TopoDS_Shape& TNaming_NewShapeIterator::Shape() const
1159{
1160 Standard_NoSuchObject_Raise_if(myNode == 0L,
1161 "TNaming_NewShapeIterator::Shape");
1162 return myNode->myNew->Shape();
1163}
1164
1165//=======================================================================
1166//function : IsModification
1167//purpose :
1168//=======================================================================
1169
1170Standard_Boolean TNaming_NewShapeIterator::IsModification() const
1171{
1172 Standard_NoSuchObject_Raise_if(myNode == 0L,
1173 "TNaming_NewShapeIterator::IsModification");
1174
1175 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
1176 myNode->myAtt->myEvolution == TNaming_DELETE );
1177}
1178
1179//**********************************************************************
1180//Methods of the TNaming_OldShapeIterator class
1181//**********************************************************************
1182//=======================================================================
1183//function : TNaming_OldShapeIterator
1184//purpose :
1185//=======================================================================
1186
1187TNaming_OldShapeIterator::TNaming_OldShapeIterator
1188(const TopoDS_Shape& aShape,
1189 const Standard_Integer Trans,
1190 const Handle(TNaming_UsedShapes)& Shapes)
1191:myTrans(Trans)
1192{
1193 Standard_Boolean Old = Standard_False;
1194 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1195 myNode = RS->FirstUse();
1196 SelectSameShape(myNode,Old,RS,myTrans);
1197}
1198
1199//=======================================================================
1200//function : TNaming_OldShapeIterator
1201//purpose :
1202//=======================================================================
1203
1204TNaming_OldShapeIterator::TNaming_OldShapeIterator
1205(const TopoDS_Shape& aShape,
1206 const Standard_Integer Trans,
1207 const TDF_Label& access)
1208:myTrans(Trans)
1209{
1210 Handle(TNaming_UsedShapes) Shapes;
1211 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1212 Standard_Boolean Old = Standard_False;
1213 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1214 myNode = RS->FirstUse();
1215 SelectSameShape(myNode,Old,RS,myTrans);
1216 }
1217}
1218//=======================================================================
1219//function : TNaming_OldShapeIterator
1220//purpose :
1221//=======================================================================
1222
1223TNaming_OldShapeIterator::TNaming_OldShapeIterator
1224(const TopoDS_Shape& aShape,
1225 const Handle(TNaming_UsedShapes)& Shapes)
1226:myTrans(-1)
1227{
1228 Standard_Boolean Old = Standard_False;
1229 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1230 myNode = RS->FirstUse();
1231 SelectSameShape(myNode,Old,RS,myTrans);
1232}
1233
1234//=======================================================================
1235//function : TNaming_OldShapeIterator
1236//purpose :
1237//=======================================================================
1238
1239TNaming_OldShapeIterator::TNaming_OldShapeIterator
1240(const TopoDS_Shape& aShape,
1241 const TDF_Label& access)
1242:myTrans(-1)
1243{
1244 Handle(TNaming_UsedShapes) Shapes;
1245 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1246 Standard_Boolean Old = Standard_False;
1247 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1248 myNode = RS->FirstUse();
1249 SelectSameShape(myNode,Old,RS,myTrans);
1250 }
1251}
1252
1253//=======================================================================
1254//function : TNaming_OldShapeIterator
1255//purpose :
1256//=======================================================================
1257
1258TNaming_OldShapeIterator::TNaming_OldShapeIterator (const TNaming_Iterator& anIterator)
1259:myTrans(anIterator.myTrans)
1260{
1261 Standard_Boolean Old = Standard_False;
1262 myNode = anIterator.myNode;
1263 TNaming_RefShape* RS = myNode->myNew;
1264 if (RS == 0L)
1265 myNode = 0L; // No descendant
1266 else {
1267 // il faut repartir de la premiere utilisation.
1268 myNode = RS->FirstUse();
1269 SelectSameShape(myNode,Old,RS,myTrans);
1270 }
1271}
1272
1273//=======================================================================
1274//function : TNaming_OldShapeIterator
1275//purpose :
1276//=======================================================================
1277
1278TNaming_OldShapeIterator::TNaming_OldShapeIterator(const TNaming_OldShapeIterator& anIterator)
1279:myTrans(anIterator.myTrans)
1280{
1281 Standard_Boolean Old = Standard_False;
1282 myNode = anIterator.myNode;
1283 TNaming_RefShape* RS = myNode->myOld;
1284 if (RS == 0L)
1285 myNode = 0L; // No descendant
1286 else {
1287 // il faut repartir de la premiere utilisation.
1288 myNode = RS->FirstUse();
1289 SelectSameShape(myNode,Old,RS,myTrans);
1290 }
1291}
1292
1293//=======================================================================
1294//function : Next
1295//purpose :
1296//=======================================================================
1297
1298void TNaming_OldShapeIterator::Next()
1299{
1300 Standard_Boolean Old = Standard_False;
1301 TNaming_RefShape* RS = myNode->myNew;
1302 myNode = myNode->NextSameShape(RS);
1303 SelectSameShape(myNode,Old,RS,myTrans);
1304}
1305
1306//=======================================================================
1307//function : Label
1308//purpose :
1309//=======================================================================
1310
1311TDF_Label TNaming_OldShapeIterator::Label() const
1312{
1313 if (myNode == 0L) Standard_NoSuchObject::Raise("TNaming_OldShapeIterator::Label");
1314 return myNode->Label();
1315
1316}
1317
1318//=======================================================================
1319//function : NamedShape
1320//purpose :
1321//=======================================================================
1322
1323Handle(TNaming_NamedShape) TNaming_OldShapeIterator::NamedShape() const
1324{
1325 if (myNode == 0L) Standard_NoSuchObject::Raise("TNaming_OldShapeIterator::Label");
1326 return myNode->myAtt;
1327}
1328//=======================================================================
1329//function : Shape
1330//purpose :
1331//=======================================================================
1332
1333const TopoDS_Shape& TNaming_OldShapeIterator::Shape() const
1334{
1335 if(myNode == 0L) Standard_NoSuchObject::Raise("TNaming_OldShapeIterator::Shape");
1336 return myNode->myOld->Shape();
1337}
1338
1339//=======================================================================
1340//function : IsModification
1341//purpose :
1342//=======================================================================
1343
1344Standard_Boolean TNaming_OldShapeIterator::IsModification() const
1345{
1346 Standard_NoSuchObject_Raise_if(myNode == 0L,
1347 "TNaming_OldShapeIterator::IsModification");
1348 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
1349 myNode->myAtt->myEvolution == TNaming_DELETE );
1350}
1351
1352
1353//**********************************************************************
1354//Methods of the SameShapeIterator
1355//**********************************************************************
1356
1357//=======================================================================
1358//function :
1359//purpose :
1360//=======================================================================
1361
1362TNaming_SameShapeIterator::TNaming_SameShapeIterator
1363(const TopoDS_Shape& aShape,
1364 const Handle(TNaming_UsedShapes)& Shapes)
1365{
1366 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1367 myNode = RS->FirstUse();
1368 myIsNew = (myNode->myNew == RS);
1369}
1370
1371
1372//=======================================================================
1373//function : TNaming_SameShapeIterator
1374//purpose :
1375//=======================================================================
1376
1377TNaming_SameShapeIterator::TNaming_SameShapeIterator
1378(const TopoDS_Shape& aShape,
1379 const TDF_Label& access)
1380{
1381 Handle(TNaming_UsedShapes) Shapes;
1382 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1383 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1384 myNode = RS->FirstUse();
1385 myIsNew = (myNode->myNew == RS);
1386 }
1387}
1388
1389//=======================================================================
1390//function : Next
1391//purpose :
1392//=======================================================================
1393
1394void TNaming_SameShapeIterator::Next()
1395{
1396 TNaming_RefShape* prs;
1397 if (myIsNew) prs = myNode->myNew; else prs = myNode->myOld;
1398
1399 myNode = myNode->NextSameShape(prs);
1400 if (myNode != 0L) myIsNew = (myNode->myNew == prs);
1401}
1402
1403//=======================================================================
1404//function : Label
1405//purpose :
1406//=======================================================================
1407
1408TDF_Label TNaming_SameShapeIterator::Label() const
1409{
1410 Standard_NoSuchObject_Raise_if(myNode == 0L,
1411 "TNaming_SameShapeIterator::Label");
1412 return myNode->Label();
1413}
1414
1415
1416//**********************************************************************
1417//Methods of the TNaming_RefShape
1418//**********************************************************************
1419//=======================================================================
1420//function : Label
1421//purpose :
1422//=======================================================================
1423
1424TDF_Label TNaming_RefShape::Label() const
1425{
1426 return myFirstUse->myAtt->Label();
1427}
1428
1429//=======================================================================
1430//function : NamedShape
1431//purpose :
1432//=======================================================================
1433
1434Handle(TNaming_NamedShape) TNaming_RefShape::NamedShape() const
1435{
1436 return myFirstUse->myAtt;
1437}
1438
1439
1440//**********************************************************************
1441//Methods of the TNaming_Tool class
1442//**********************************************************************
1443
1444//=======================================================================
1445//function : HasLabel
1446//purpose :
1447//=======================================================================
1448
1449Standard_Boolean TNaming_Tool::HasLabel (const TDF_Label& access,
1450 const TopoDS_Shape& S)
1451{
1452 Handle(TNaming_UsedShapes) US;
1453 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US)) {
1454 return (US->Map().IsBound(S));
1455 }
0797d9d3 1456#ifdef OCCT_DEBUG_HASL
7fd59977 1457 cout << "##==> Sub-Shape has no Label!" <<endl;
1458#endif
1459 return Standard_False;
1460}
1461
1462
1463//=======================================================================
1464//function : Label
1465//purpose :
1466//=======================================================================
1467
1468TDF_Label TNaming_Tool::Label(const TDF_Label& access,
1469 const TopoDS_Shape& S,
1470 Standard_Integer& Trans)
1471{
1472 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(access,S),"TNaming_Tool::Label");
1473 Handle(TNaming_UsedShapes) US;
1474 access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1475 return TNaming_Tool::Label(US,S,Trans);
1476}
1477
1478
1479//=======================================================================
1480//function : IsValidInTrans
1481//purpose : un shape est valid tant que l attribut ou il est cree est valid
1482//=======================================================================
1483
1484Standard_Integer TNaming_Tool::ValidUntil (const TDF_Label& access, const TopoDS_Shape& S)
1485{
1486 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(access,S),"TNaming_Tool::ValidUntil");
1487 Handle(TNaming_UsedShapes) US;
1488 access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1489 return TNaming_Tool::ValidUntil(S,US);
1490}
1491
1492
1493//=======================================================================
1494//function : HasLabel
1495//purpose :
1496//=======================================================================
1497
1498Standard_Boolean TNaming_Tool::HasLabel(const Handle(TNaming_UsedShapes)& Shapes,
1499 const TopoDS_Shape& S)
1500{
1501 return (Shapes->Map().IsBound(S));
1502}
1503
1504
1505//=======================================================================
1506//function : Label
1507//purpose :
1508//=======================================================================
1509
1510TDF_Label TNaming_Tool::Label(const Handle(TNaming_UsedShapes)& Shapes,
1511 const TopoDS_Shape& S,
1512 Standard_Integer& Trans)
1513{
1514 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(Shapes,S),"TNaming_Tool::Label");
1515 TNaming_RefShape* prs = Shapes->Map().Find(S);
1516 TNaming_Node* pdn = prs->FirstUse();
1517
1518 while (pdn != 0L && !(pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED)){
1519 pdn = pdn->NextSameShape(prs);
1520 }
1521 if (pdn == 0L) pdn = prs->FirstUse();
1522
1523 TDF_Label L = pdn->Label();
1524 Trans = pdn->myAtt->Transaction();
1525 return L;
1526}
1527//=======================================================================
1528//function : NamedShape
1529//purpose :
1530//=======================================================================
1531Handle(TNaming_NamedShape) TNaming_Tool::NamedShape(const TopoDS_Shape& S,
1532 const TDF_Label& Acces)
1533{
1534 Handle(TNaming_UsedShapes) US;
1535 Acces.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1536 Handle(TNaming_NamedShape) NS;
1537
1538 if(!TNaming_Tool::HasLabel(US,S)) {
1539 return NS;
1540 }
1541
1542 TNaming_RefShape* prs = US->Map().Find(S);
1543 TNaming_Node* pdn = prs->FirstUse();
1544 TNaming_Node* res = 0L;
1545
1546 while (pdn != 0L) {
1547 if (pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED) {
1548 res = pdn;
1549 if (pdn->myAtt->Evolution() != TNaming_GENERATED) {
1550 // Les modifications sont privilegiees par rapport au generation.
1551 // Dans le cas des shapes qui sont a la fois des modifications et des generations
1552 // faces tangentes.
1553 break;
1554 }
1555 }
1556 pdn = pdn->NextSameShape(prs);
1557 }
1558
1559 if (res == 0L) return NS;
1560
1561 // VERUE EN ATTENDANT DE REVOIR ABORT 03/11/98
1562 // Protection pour eviter de renvoyer un attribut backuped
1563 TDF_Label Lab = res->Label();
1564 Lab.FindAttribute(TNaming_NamedShape::GetID(),NS);
1565 return NS;
1566 // return res->myAtt;
1567}
1568
1569//=======================================================================
1570//function : IsValidInTrans
1571//purpose : un shape est valid tant que l attribut ou il est cree est valid
1572//=======================================================================
1573
1574Standard_Integer TNaming_Tool::ValidUntil (const TopoDS_Shape& S,
1575 const Handle(TNaming_UsedShapes)& US)
1576{
1577 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(US,S),"TNaming_Tool::ValidUntil");
1578
1579 TNaming_RefShape* RS = US->Map().ChangeFind(S);
1580 Standard_Integer Cur;
1581 Standard_Integer Until = 0;
1582 TNaming_Node* Node = RS->FirstUse();
1583
1584 while (Node != 0L) {
1585 if (Node->myNew != 0L && Node->myNew == RS) {
1586 Cur = Node->myAtt->UntilTransaction();
1587 if (Cur > Until) Until = Cur;
1588 }
1589 Node = Node->NextSameShape(RS);
1590 }
1591 return Until;
1592}