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