0023934: Compiler warnings in MS VC++ 10
[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//=======================================================================
470//function : static GetLocation 23.06.99 (szy)
471//purpose : service: returns copy of Location if exist Relocation
472//=======================================================================
473
474static TopLoc_Location GetLocation(const TopLoc_Location& L,
475 const Handle(TDF_RelocationTable)& RT)
476{
477 TopLoc_Location result;
478
479 if (!L.IsIdentity()) {
480 Handle(TopLoc_Datum3D) TD;
481 if(!RT->HasTransientRelocation(L.FirstDatum(), TD))
482#ifdef DEB
483 cout <<"TNaming_Named_Shape::Paste : Relocation for TopLocation don't exist" << endl;
484#endif
485 result = GetLocation(L.NextLocation(), RT) *
486 TopLoc_Location(TD).Powered(L.FirstPower());
487 }
488 return result;
489}
490
491//=======================================================================
492//function : Paste
493//purpose :
494//=======================================================================
495
496void TNaming_NamedShape::Paste(const Handle(TDF_Attribute)& into,
497 const Handle(TDF_RelocationTable)& Tab)
498const
499{
500 TDF_Label Lab = into->Label();
501 if (Lab.IsNull()) {
502 Standard_NullObject::Raise("TNaming_NamedShape::Paste");
503 }
504 TNaming_Builder B(Lab);
505
506 TNaming_Iterator It (this);
507 for ( ;It.More() ; It.Next()) {
508 const TopoDS_Shape& OS = It.OldShape();
509 const TopoDS_Shape& NS = It.NewShape();
510 TNaming_Evolution Status = It.Evolution();
511
512// Modification_1 24.06.99 (szy)
513 TopoDS_Shape copOS, copNS;
514 if(Status != TNaming_PRIMITIVE)
515 TNaming_CopyShape::CopyTool(OS, Tab->TransientTable(), copOS);
516 else copOS.Nullify();
517 if(Status != TNaming_DELETE )
518 TNaming_CopyShape::CopyTool(NS, Tab->TransientTable(), copNS);
519 else copNS.Nullify();
520
521 switch (Status) {
522 case TNaming_PRIMITIVE :
523 {
524 B.Generated(copNS);
525 break;
526 }
527 case TNaming_GENERATED :
528 {
529 B.Generated(copOS, copNS);
530 break;
531 }
532 case TNaming_MODIFY :
533 {
534 B.Modify(copOS, copNS);
535 break;
536 }
537 case TNaming_DELETE :
538 {
539 B.Delete (copOS);
540 break;
541 }
542 case TNaming_SELECTED :
543 {
544 B.Select(copNS,copOS);
545 break;
546 }
547
548 default:
549 break;
550 }
551 }
552}
553
554//=======================================================================
555//function : References
556//purpose :
557//=======================================================================
558
559void TNaming_NamedShape::References(const Handle(TDF_DataSet)& aDataSet) const
560{
561 // Recherche des dependances.
562 // Pour chaque OldShape de l attribut on ajoute au dataSet son label d origine.
563 TNaming_Node* Current = myNode;
564 while (Current != NULL) {
565 if (Current->myOld != NULL) {
566 TNaming_RefShape* prs = Current->myOld;
567 TNaming_Node* pdn = prs->FirstUse();
568
569 while (pdn != NULL) {
570 if (pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED) {
571 aDataSet->AddLabel(pdn->Label());
572 }
573 pdn = pdn->NextSameShape(prs);
574 }
575 }
576 Current = Current->nextSameAttribute;
577 }
578}
579
580
581//=======================================================================
582//function : Add
583//purpose :
584//=======================================================================
585
586void TNaming_NamedShape::Add(TNaming_Node*& pdn )
587{
588 pdn->myAtt = this;
589 if (!myNode == 0L){
590 pdn->nextSameAttribute = myNode;
591 }
592 myNode = pdn;
593}
594
595//=======================================================================
596//function : Dump
597//purpose :
598//=======================================================================
599
600Standard_OStream& TNaming_NamedShape::Dump(Standard_OStream& anOS) const
601{
602 return anOS;
603}
604
605//***************************************
606// Fin Class Named_Shape.
607//***************************************
608
609
610//**********************************************************************
611// Methods of the TNaming_Builder class
612//**********************************************************************
613
614///=======================================================================
615//function : TNaming_Builder
616//purpose :
617//=======================================================================
618
619TNaming_Builder::TNaming_Builder (const TDF_Label& L)
620{
7fd59977 621 // Find or Build Map;
622 const TDF_Label& root = L.Root();
8b8bffc6 623 if (!root.FindAttribute(TNaming_UsedShapes::GetID(),myShapes)) {
624 myShapes = new TNaming_UsedShapes();
625 root.AddAttribute (myShapes);
7fd59977 626 }
7fd59977 627
628 //Find Or Build Attribute in LIns.
8b8bffc6 629 if (!L.FindAttribute(TNaming_NamedShape::GetID(),myAtt)) {
630 myAtt = new TNaming_NamedShape();
631 L.AddAttribute(myAtt);
7fd59977 632 }
633 else {
8b8bffc6 634 myAtt->Backup();
635 myAtt->Clear();
636 myAtt->myVersion++;
7fd59977 637 }
7fd59977 638}
639
640//=======================================================================
641//function : TNaming_Builder
642//purpose :
643//=======================================================================
644
645Handle(TNaming_NamedShape) TNaming_Builder::NamedShape() const
646{
647 return myAtt;
648}
649
650//=======================================================================
651//function : UpdateNextSameShape
652//purpose :
653//=======================================================================
654
655static void UpdateFirstUseOrNextSameShape(TNaming_RefShape*& prs,
656 TNaming_Node*& pdn)
657{
658 TNaming_Node* ldn = prs->FirstUse();
659 if (ldn == 0L) {
660 prs->FirstUse(pdn);
661 }
662 else {
663 TNaming_Node* cdn = ldn;
664 while (cdn != 0L) {
665 ldn = cdn;
666 cdn = cdn->NextSameShape(prs);
667 if (ldn == cdn) {
668 Standard_ConstructionError::Raise("UpdateFirstUseOrNextSameShape");
669 break;
670 }
671 }
672 // boucle interdite et inutile.
673 if (ldn != pdn) {
674 if (ldn->myOld == prs) ldn->nextSameOld = pdn;
675 if (ldn->myNew == prs) ldn->nextSameNew = pdn;
676 }
677 }
678}
679
680//=======================================================================
681//function : Generate
682//purpose :
683//=======================================================================
684
685void TNaming_Builder::Generated(const TopoDS_Shape& newShape)
686{
687 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_PRIMITIVE;
688 else {
689 if (myAtt->myEvolution != TNaming_PRIMITIVE)
690 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
691 }
692
693 TNaming_RefShape* pos = 0L;
694 TNaming_RefShape* pns;
695
8b8bffc6 696 if (myShapes->myMap.IsBound(newShape)) {
7fd59977 697#ifdef DEB
698 cout <<"TNaming_Builder::Generate : the shape is already in the attribute"<<endl;
699#endif
8b8bffc6 700 pns = myShapes->myMap.ChangeFind(newShape);
701 if (pns->FirstUse()->myAtt == myAtt.operator->()) {
7fd59977 702 Standard_ConstructionError::Raise("TNaming_Builder::Generate");
703 }
704 TNaming_Node* pdn = new TNaming_Node(pos,pns);
705 myAtt->Add(pdn);
706 UpdateFirstUseOrNextSameShape (pns,pdn);
707 }
708 else {
709 pns = new TNaming_RefShape(newShape);
710 TNaming_Node* pdn = new TNaming_Node(pos,pns);
711 pns ->FirstUse(pdn);
8b8bffc6 712 myShapes->myMap.Bind (newShape , pns);
7fd59977 713 myAtt->Add(pdn);
714 }
715}
716
717
718
719//=======================================================================
720//function : Delete
721//purpose :
722//=======================================================================
723
724void TNaming_Builder::Delete(const TopoDS_Shape& oldShape)
725{
726 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_DELETE;
727 else {
728 if (myAtt->myEvolution != TNaming_DELETE)
729 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
730 }
731
732 TNaming_RefShape* pns = 0L;
733 TNaming_RefShape* pos;
734
8b8bffc6 735 if (myShapes->myMap.IsBound(oldShape))
736 pos = myShapes->myMap.ChangeFind(oldShape);
7fd59977 737 else {
738#ifdef DEB
739 cout <<"TNaming_Builder::Delete : the shape is not in the data"<<endl;
740#endif
741 pos = new TNaming_RefShape(oldShape);
8b8bffc6 742 myShapes->myMap.Bind(oldShape, pos);
7fd59977 743 }
744 TNaming_Node* pdn = new TNaming_Node(pos,pns);
745 myAtt->Add(pdn);
746 UpdateFirstUseOrNextSameShape (pos,pdn);
747}
748
749//=======================================================================
750//function : Generate
751//purpose :
752//=======================================================================
753
754void TNaming_Builder::Generated(const TopoDS_Shape& oldShape,
755 const TopoDS_Shape& newShape)
756{
757 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_GENERATED;
758 else {
759 if (myAtt->myEvolution != TNaming_GENERATED)
760 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
761 }
762
763 if (oldShape.IsSame(newShape)) {
764#ifdef DEB
765 cout <<"TNaming_Builder::Generate : oldShape IsSame newShape"<<endl;
766#endif
767 return;
768 }
769 TNaming_RefShape* pos;
8b8bffc6 770 if (!myShapes->myMap.IsBound(oldShape)) {
7fd59977 771 pos = new TNaming_RefShape(oldShape);
8b8bffc6 772 myShapes->myMap.Bind(oldShape,pos);
7fd59977 773 }
774 else
8b8bffc6 775 pos = myShapes->myMap.ChangeFind(oldShape);
7fd59977 776
777 TNaming_RefShape* pns;
8b8bffc6 778 if (!myShapes->myMap.IsBound(newShape)) {
7fd59977 779 pns = new TNaming_RefShape(newShape);
8b8bffc6 780 myShapes->myMap.Bind(newShape,pns);
7fd59977 781 }
782 else
8b8bffc6 783 pns = myShapes->myMap.ChangeFind(newShape);
7fd59977 784
785 TNaming_Node* pdn = new TNaming_Node(pos,pns);
786 myAtt->Add(pdn);
787 UpdateFirstUseOrNextSameShape (pos,pdn);
788 UpdateFirstUseOrNextSameShape (pns,pdn);
789}
790
791
792//=======================================================================
793//function : Modify
794//purpose :
795//=======================================================================
796
797void TNaming_Builder::Modify(const TopoDS_Shape& oldShape,
798 const TopoDS_Shape& newShape)
799{
800 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_MODIFY;
801 else {
802 if (myAtt->myEvolution != TNaming_MODIFY)
803 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
804 }
805
806 if (oldShape.IsSame(newShape)) {
807#ifdef DEB
808 cout <<"TNaming_Builder::Modify : oldShape IsSame newShape"<<endl;
809#endif
810 return;
811 }
812 TNaming_RefShape* pos;
8b8bffc6 813 if (!myShapes->myMap.IsBound(oldShape)) {
7fd59977 814 pos = new TNaming_RefShape(oldShape);
8b8bffc6 815 myShapes->myMap.Bind(oldShape,pos);
7fd59977 816 }
817 else
8b8bffc6 818 pos = myShapes->myMap.ChangeFind(oldShape);
7fd59977 819
820 TNaming_RefShape* pns;
8b8bffc6 821 if (!myShapes->myMap.IsBound(newShape)) {
7fd59977 822 pns = new TNaming_RefShape(newShape);
8b8bffc6 823 myShapes->myMap.Bind(newShape,pns);
7fd59977 824 }
825 else
8b8bffc6 826 pns = myShapes->myMap.ChangeFind(newShape);
7fd59977 827
828 TNaming_Node* pdn = new TNaming_Node(pos,pns);
829 myAtt->Add(pdn);
830 UpdateFirstUseOrNextSameShape (pos,pdn);
831 UpdateFirstUseOrNextSameShape (pns,pdn);
832
833}
834
835//=======================================================================
7fd59977 836//function : Select
837//purpose :
838//=======================================================================
839void TNaming_Builder::Select (const TopoDS_Shape& S,
840 const TopoDS_Shape& InS)
841{
842 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_SELECTED;
843 else {
844 if (myAtt->myEvolution != TNaming_SELECTED)
845 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
846 }
847
7dcac1df 848 TNaming_RefShape* pos;
849 if (!myShapes->myMap.IsBound(InS)) {
850 pos = new TNaming_RefShape(InS);
851 myShapes->myMap.Bind(InS,pos);
7fd59977 852 }
7dcac1df 853 else
854 pos = myShapes->myMap.ChangeFind(InS);
7fd59977 855
856 TNaming_RefShape* pns;
8b8bffc6 857 if (!myShapes->myMap.IsBound(S)) {
7fd59977 858 pns = new TNaming_RefShape(S);
8b8bffc6 859 myShapes->myMap.Bind(S,pns);
7fd59977 860 }
861 else
8b8bffc6 862 pns = myShapes->myMap.ChangeFind(S);
7fd59977 863
864 TNaming_Node* pdn = new TNaming_Node(pos,pns);
865 myAtt->Add(pdn);
866 UpdateFirstUseOrNextSameShape (pos,pdn);
867 UpdateFirstUseOrNextSameShape (pns,pdn);
868}
869
870//**********************************************************************
871//Methods of the TNaming_Iterator class
872//**********************************************************************
873
874//=======================================================================
875//function : TNaming_Iterator
876//purpose :
877//=======================================================================
878
879TNaming_Iterator::TNaming_Iterator(const Handle(TNaming_NamedShape)& Att)
880:myTrans(-1)
881{
882 myNode = Att->myNode;
883}
884
885//=======================================================================
886//function : TNaming_Iterator
887//purpose :
888//=======================================================================
889
890TNaming_Iterator::TNaming_Iterator(const TDF_Label& Lab)
891:myTrans(-1)
892{
893 Handle(TNaming_NamedShape) Att;
894 if (Lab.FindAttribute(TNaming_NamedShape::GetID(),Att)) {
895 myNode = Att->myNode;
896 }
897 else {
898 myNode = 0L;
899 }
900}
901
902//=====================================================================
903//function : TNaming_Iterator
904//purpose :
905//=======================================================================
906
907TNaming_Iterator::TNaming_Iterator(const TDF_Label& Lab,
908 const Standard_Integer Trans)
909:myTrans(Trans)
910{
911 Handle(TNaming_NamedShape) Att;
912 if (Lab.FindAttribute(TNaming_NamedShape::GetID(),Trans,Att)) {
913 myNode = Att->myNode;
914 }
915 else {
916 myNode = 0L;
917#ifdef DEB
918 cout <<"TNaming_Iterator : No Shape for this label"<<endl;
919#endif
920 }
921}
922
923//=======================================================================
924//function : Next
925//purpose :
926//=======================================================================
927
928void TNaming_Iterator::Next()
929{
930 Standard_NoMoreObject_Raise_if(myNode == 0L,
931 "TNaming_Iterator::Next");
932 myNode = myNode->nextSameAttribute;
933}
934
935//=======================================================================
936//function : OldShape
937//purpose :
938//=======================================================================
939
940const TopoDS_Shape& TNaming_Iterator::OldShape() const
941{
942 Standard_NoSuchObject_Raise_if(myNode == 0L,
943 "TNaming_Iterator::OldShape");
944 if (myNode->myOld == 0L) {
945 static TopoDS_Shape NullShape;
946 return NullShape;
947 }
948 return myNode->myOld->Shape();
949}
950
951//=======================================================================
952//function : NewShape
953//purpose :
954//=======================================================================
955
956const TopoDS_Shape& TNaming_Iterator::NewShape() const
957{
958 Standard_NoSuchObject_Raise_if(myNode == 0L,
959 "TNaming_Iterator::NewShape");
960 if (myNode->myNew == 0L) {
961 static TopoDS_Shape NullShape;
962 return NullShape;
963 }
964 return myNode->myNew->Shape();
965}
966
967
968//=======================================================================
969//function : IsModification
970//purpose :
971//=======================================================================
972
973Standard_Boolean TNaming_Iterator::IsModification() const
974{
975 Standard_NoSuchObject_Raise_if(myNode == 0L,
976 "TNaming_Iterator::IsModification");
977 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
978 myNode->myAtt->myEvolution == TNaming_DELETE );
979}
980
981//=======================================================================
982//function : Evolution
983//purpose :
984//=======================================================================
985
986TNaming_Evolution TNaming_Iterator::Evolution() const
987{
988 Standard_NoSuchObject_Raise_if(myNode == 0L,
989 "TNaming_Iterator::IsModification");
990 return myNode->myAtt->myEvolution;
991}
992
993
994
995//**********************************************************************
996//Methods of the TNaming_NewShapeIterator class
997//**********************************************************************
998
999//=======================================================================
1000//function : SelectSameShape
1001//purpose : Selectionne le prochain noeud ou le shape est le meme que celui
1002// de RS. Old = 0 si il doit etre new dans le noeud a chercher.
1003// selection dans la transaction valide.
1004// On saute aussi les noeud ou OS = NS;
1005//=======================================================================
1006
1007static void SelectSameShape (TNaming_Node*& myNode,
1008 Standard_Boolean Old,
1009 TNaming_RefShape*& RS,
1010 const Standard_Integer& Trans)
1011{
1012 TNaming_Node* pdn = myNode;
1013
1014 while (pdn != 0L) {
1015 Standard_Boolean Valid;
1016 if (Trans < 0) Valid = pdn->myAtt->IsValid();
1017 else Valid = pdn->IsValidInTrans(Trans);
1018
1019 if (Valid)
1020 if (Old) {
1021 if( pdn->myOld == RS && pdn->myNew != 0L && pdn->myNew != RS) {
1022 break;
1023 }
1024 }
1025 else {
1026 if( pdn->myNew == RS && pdn->myOld != 0L && pdn->myOld != RS) {
1027 break;
1028 }
1029 }
1030 pdn = pdn->NextSameShape(RS);
1031 }
1032 myNode = pdn;
1033}
1034
1035//=======================================================================
1036//function : TNaming_NewShapeIterator
1037//purpose :
1038//=======================================================================
1039
1040TNaming_NewShapeIterator::TNaming_NewShapeIterator
1041(const TopoDS_Shape& aShape,
1042 const Standard_Integer Trans,
1043 const Handle(TNaming_UsedShapes)& Shapes)
1044:myTrans(Trans)
1045{
1046 Standard_Boolean Old = Standard_True;
1047 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1048 myNode = RS->FirstUse();
1049 SelectSameShape(myNode,Old,RS,myTrans);
1050}
1051
1052//=======================================================================
1053//function : TNaming_NewShapeIterator
1054//purpose :
1055//=======================================================================
1056
1057TNaming_NewShapeIterator::TNaming_NewShapeIterator
1058(const TopoDS_Shape& aShape,
1059 const Standard_Integer Trans,
1060 const TDF_Label& access)
1061:myTrans(Trans)
1062{
1063 Handle(TNaming_UsedShapes) Shapes;
1064 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1065 Standard_Boolean Old = Standard_True;
1066 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
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 (const TNaming_Iterator& anIterator)
1078:myTrans(anIterator.myTrans)
1079{
1080 Standard_Boolean Old = Standard_True;
1081 myNode = anIterator.myNode;
1082 TNaming_RefShape* RS = myNode->myNew;
1083 if (RS == 0L)
1084 myNode = 0L; // No descendant
1085 else {
1086 // il faut repartir de la premiere utilisation.
1087 myNode = RS->FirstUse();
1088 SelectSameShape(myNode,Old,RS,myTrans);
1089 }
1090}
1091
1092//=======================================================================
1093//function : TNaming_NewShapeIterator
1094//purpose :
1095//=======================================================================
1096
1097TNaming_NewShapeIterator::TNaming_NewShapeIterator
1098(const TopoDS_Shape& aShape,
1099 const Handle(TNaming_UsedShapes)& Shapes)
1100:myTrans(-1)
1101{
1102 Standard_Boolean Old = Standard_True;
1103 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1104 myNode = RS->FirstUse();
1105 SelectSameShape(myNode,Old,RS,myTrans);
1106}
1107
1108//=======================================================================
1109//function : TNaming_NewShapeIterator
1110//purpose :
1111//=======================================================================
1112
1113TNaming_NewShapeIterator::TNaming_NewShapeIterator
1114(const TopoDS_Shape& aShape,
1115 const TDF_Label& access)
1116:myTrans(-1)
1117{
1118 Handle(TNaming_UsedShapes) Shapes;
1119 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1120 Standard_Boolean Old = Standard_True;
1121 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1122 myNode = RS->FirstUse();
1123 SelectSameShape(myNode,Old,RS,myTrans);
1124 }
1125}
1126
1127//=======================================================================
1128//function : TNaming_NewShapeIterator
1129//purpose :
1130//=======================================================================
1131
1132TNaming_NewShapeIterator::TNaming_NewShapeIterator(const TNaming_NewShapeIterator& anIterator)
1133:myTrans(anIterator.myTrans)
1134{
1135 Standard_Boolean Old = Standard_True;
1136 myNode = anIterator.myNode;
1137 TNaming_RefShape* RS = myNode->myNew;
1138 if (RS == 0L)
1139 myNode = 0L; // No descendant
1140 else {
1141 // il faut repartir de la premiere utilisation.
1142 myNode = RS->FirstUse();
1143 SelectSameShape(myNode,Old,RS,myTrans);
1144 }
1145}
1146
1147//=======================================================================
1148//function : Next
1149//purpose :
1150//=======================================================================
1151
1152void TNaming_NewShapeIterator::Next()
1153{
1154 Standard_Boolean Old = Standard_True;
1155 TNaming_RefShape* RS = myNode->myOld;
1156 myNode = myNode->NextSameShape(RS);
1157 SelectSameShape(myNode,Old,RS,myTrans);
1158}
1159
1160//=======================================================================
1161//function : Label
1162//purpose :
1163//=======================================================================
1164
1165TDF_Label TNaming_NewShapeIterator::Label() const
1166{
1167 Standard_NoSuchObject_Raise_if(myNode == 0L,
1168 "TNaming_NewShapeIterator::Label");
1169 return myNode->Label();
1170}
1171
1172//=======================================================================
1173//function : NamedShape
1174//purpose :
1175//=======================================================================
1176
1177Handle(TNaming_NamedShape) TNaming_NewShapeIterator::NamedShape() const
1178{
1179 Standard_NoSuchObject_Raise_if(myNode == 0L,
1180 "TNaming_NewShapeIterator::Label");
1181 return myNode->myAtt;
1182}
1183
1184//=======================================================================
1185//function : Shape
1186//purpose :
1187//=======================================================================
1188
1189const TopoDS_Shape& TNaming_NewShapeIterator::Shape() const
1190{
1191 Standard_NoSuchObject_Raise_if(myNode == 0L,
1192 "TNaming_NewShapeIterator::Shape");
1193 return myNode->myNew->Shape();
1194}
1195
1196//=======================================================================
1197//function : IsModification
1198//purpose :
1199//=======================================================================
1200
1201Standard_Boolean TNaming_NewShapeIterator::IsModification() const
1202{
1203 Standard_NoSuchObject_Raise_if(myNode == 0L,
1204 "TNaming_NewShapeIterator::IsModification");
1205
1206 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
1207 myNode->myAtt->myEvolution == TNaming_DELETE );
1208}
1209
1210//**********************************************************************
1211//Methods of the TNaming_OldShapeIterator class
1212//**********************************************************************
1213//=======================================================================
1214//function : TNaming_OldShapeIterator
1215//purpose :
1216//=======================================================================
1217
1218TNaming_OldShapeIterator::TNaming_OldShapeIterator
1219(const TopoDS_Shape& aShape,
1220 const Standard_Integer Trans,
1221 const Handle(TNaming_UsedShapes)& Shapes)
1222:myTrans(Trans)
1223{
1224 Standard_Boolean Old = Standard_False;
1225 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1226 myNode = RS->FirstUse();
1227 SelectSameShape(myNode,Old,RS,myTrans);
1228}
1229
1230//=======================================================================
1231//function : TNaming_OldShapeIterator
1232//purpose :
1233//=======================================================================
1234
1235TNaming_OldShapeIterator::TNaming_OldShapeIterator
1236(const TopoDS_Shape& aShape,
1237 const Standard_Integer Trans,
1238 const TDF_Label& access)
1239:myTrans(Trans)
1240{
1241 Handle(TNaming_UsedShapes) Shapes;
1242 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1243 Standard_Boolean Old = Standard_False;
1244 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1245 myNode = RS->FirstUse();
1246 SelectSameShape(myNode,Old,RS,myTrans);
1247 }
1248}
1249//=======================================================================
1250//function : TNaming_OldShapeIterator
1251//purpose :
1252//=======================================================================
1253
1254TNaming_OldShapeIterator::TNaming_OldShapeIterator
1255(const TopoDS_Shape& aShape,
1256 const Handle(TNaming_UsedShapes)& Shapes)
1257:myTrans(-1)
1258{
1259 Standard_Boolean Old = Standard_False;
1260 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1261 myNode = RS->FirstUse();
1262 SelectSameShape(myNode,Old,RS,myTrans);
1263}
1264
1265//=======================================================================
1266//function : TNaming_OldShapeIterator
1267//purpose :
1268//=======================================================================
1269
1270TNaming_OldShapeIterator::TNaming_OldShapeIterator
1271(const TopoDS_Shape& aShape,
1272 const TDF_Label& access)
1273:myTrans(-1)
1274{
1275 Handle(TNaming_UsedShapes) Shapes;
1276 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1277 Standard_Boolean Old = Standard_False;
1278 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
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_Iterator& anIterator)
1290:myTrans(anIterator.myTrans)
1291{
1292 Standard_Boolean Old = Standard_False;
1293 myNode = anIterator.myNode;
1294 TNaming_RefShape* RS = myNode->myNew;
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 : TNaming_OldShapeIterator
1306//purpose :
1307//=======================================================================
1308
1309TNaming_OldShapeIterator::TNaming_OldShapeIterator(const TNaming_OldShapeIterator& anIterator)
1310:myTrans(anIterator.myTrans)
1311{
1312 Standard_Boolean Old = Standard_False;
1313 myNode = anIterator.myNode;
1314 TNaming_RefShape* RS = myNode->myOld;
1315 if (RS == 0L)
1316 myNode = 0L; // No descendant
1317 else {
1318 // il faut repartir de la premiere utilisation.
1319 myNode = RS->FirstUse();
1320 SelectSameShape(myNode,Old,RS,myTrans);
1321 }
1322}
1323
1324//=======================================================================
1325//function : Next
1326//purpose :
1327//=======================================================================
1328
1329void TNaming_OldShapeIterator::Next()
1330{
1331 Standard_Boolean Old = Standard_False;
1332 TNaming_RefShape* RS = myNode->myNew;
1333 myNode = myNode->NextSameShape(RS);
1334 SelectSameShape(myNode,Old,RS,myTrans);
1335}
1336
1337//=======================================================================
1338//function : Label
1339//purpose :
1340//=======================================================================
1341
1342TDF_Label TNaming_OldShapeIterator::Label() const
1343{
1344 if (myNode == 0L) Standard_NoSuchObject::Raise("TNaming_OldShapeIterator::Label");
1345 return myNode->Label();
1346
1347}
1348
1349//=======================================================================
1350//function : NamedShape
1351//purpose :
1352//=======================================================================
1353
1354Handle(TNaming_NamedShape) TNaming_OldShapeIterator::NamedShape() const
1355{
1356 if (myNode == 0L) Standard_NoSuchObject::Raise("TNaming_OldShapeIterator::Label");
1357 return myNode->myAtt;
1358}
1359//=======================================================================
1360//function : Shape
1361//purpose :
1362//=======================================================================
1363
1364const TopoDS_Shape& TNaming_OldShapeIterator::Shape() const
1365{
1366 if(myNode == 0L) Standard_NoSuchObject::Raise("TNaming_OldShapeIterator::Shape");
1367 return myNode->myOld->Shape();
1368}
1369
1370//=======================================================================
1371//function : IsModification
1372//purpose :
1373//=======================================================================
1374
1375Standard_Boolean TNaming_OldShapeIterator::IsModification() const
1376{
1377 Standard_NoSuchObject_Raise_if(myNode == 0L,
1378 "TNaming_OldShapeIterator::IsModification");
1379 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
1380 myNode->myAtt->myEvolution == TNaming_DELETE );
1381}
1382
1383
1384//**********************************************************************
1385//Methods of the SameShapeIterator
1386//**********************************************************************
1387
1388//=======================================================================
1389//function :
1390//purpose :
1391//=======================================================================
1392
1393TNaming_SameShapeIterator::TNaming_SameShapeIterator
1394(const TopoDS_Shape& aShape,
1395 const Handle(TNaming_UsedShapes)& Shapes)
1396{
1397 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1398 myNode = RS->FirstUse();
1399 myIsNew = (myNode->myNew == RS);
1400}
1401
1402
1403//=======================================================================
1404//function : TNaming_SameShapeIterator
1405//purpose :
1406//=======================================================================
1407
1408TNaming_SameShapeIterator::TNaming_SameShapeIterator
1409(const TopoDS_Shape& aShape,
1410 const TDF_Label& access)
1411{
1412 Handle(TNaming_UsedShapes) Shapes;
1413 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1414 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1415 myNode = RS->FirstUse();
1416 myIsNew = (myNode->myNew == RS);
1417 }
1418}
1419
1420//=======================================================================
1421//function : Next
1422//purpose :
1423//=======================================================================
1424
1425void TNaming_SameShapeIterator::Next()
1426{
1427 TNaming_RefShape* prs;
1428 if (myIsNew) prs = myNode->myNew; else prs = myNode->myOld;
1429
1430 myNode = myNode->NextSameShape(prs);
1431 if (myNode != 0L) myIsNew = (myNode->myNew == prs);
1432}
1433
1434//=======================================================================
1435//function : Label
1436//purpose :
1437//=======================================================================
1438
1439TDF_Label TNaming_SameShapeIterator::Label() const
1440{
1441 Standard_NoSuchObject_Raise_if(myNode == 0L,
1442 "TNaming_SameShapeIterator::Label");
1443 return myNode->Label();
1444}
1445
1446
1447//**********************************************************************
1448//Methods of the TNaming_RefShape
1449//**********************************************************************
1450//=======================================================================
1451//function : Label
1452//purpose :
1453//=======================================================================
1454
1455TDF_Label TNaming_RefShape::Label() const
1456{
1457 return myFirstUse->myAtt->Label();
1458}
1459
1460//=======================================================================
1461//function : NamedShape
1462//purpose :
1463//=======================================================================
1464
1465Handle(TNaming_NamedShape) TNaming_RefShape::NamedShape() const
1466{
1467 return myFirstUse->myAtt;
1468}
1469
1470
1471//**********************************************************************
1472//Methods of the TNaming_Tool class
1473//**********************************************************************
1474
1475//=======================================================================
1476//function : HasLabel
1477//purpose :
1478//=======================================================================
1479
1480Standard_Boolean TNaming_Tool::HasLabel (const TDF_Label& access,
1481 const TopoDS_Shape& S)
1482{
1483 Handle(TNaming_UsedShapes) US;
1484 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US)) {
1485 return (US->Map().IsBound(S));
1486 }
1487#ifdef MDTV_DEB_HASL
1488 cout << "##==> Sub-Shape has no Label!" <<endl;
1489#endif
1490 return Standard_False;
1491}
1492
1493
1494//=======================================================================
1495//function : Label
1496//purpose :
1497//=======================================================================
1498
1499TDF_Label TNaming_Tool::Label(const TDF_Label& access,
1500 const TopoDS_Shape& S,
1501 Standard_Integer& Trans)
1502{
1503 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(access,S),"TNaming_Tool::Label");
1504 Handle(TNaming_UsedShapes) US;
1505 access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1506 return TNaming_Tool::Label(US,S,Trans);
1507}
1508
1509
1510//=======================================================================
1511//function : IsValidInTrans
1512//purpose : un shape est valid tant que l attribut ou il est cree est valid
1513//=======================================================================
1514
1515Standard_Integer TNaming_Tool::ValidUntil (const TDF_Label& access, const TopoDS_Shape& S)
1516{
1517 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(access,S),"TNaming_Tool::ValidUntil");
1518 Handle(TNaming_UsedShapes) US;
1519 access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1520 return TNaming_Tool::ValidUntil(S,US);
1521}
1522
1523
1524//=======================================================================
1525//function : HasLabel
1526//purpose :
1527//=======================================================================
1528
1529Standard_Boolean TNaming_Tool::HasLabel(const Handle(TNaming_UsedShapes)& Shapes,
1530 const TopoDS_Shape& S)
1531{
1532 return (Shapes->Map().IsBound(S));
1533}
1534
1535
1536//=======================================================================
1537//function : Label
1538//purpose :
1539//=======================================================================
1540
1541TDF_Label TNaming_Tool::Label(const Handle(TNaming_UsedShapes)& Shapes,
1542 const TopoDS_Shape& S,
1543 Standard_Integer& Trans)
1544{
1545 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(Shapes,S),"TNaming_Tool::Label");
1546 TNaming_RefShape* prs = Shapes->Map().Find(S);
1547 TNaming_Node* pdn = prs->FirstUse();
1548
1549 while (pdn != 0L && !(pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED)){
1550 pdn = pdn->NextSameShape(prs);
1551 }
1552 if (pdn == 0L) pdn = prs->FirstUse();
1553
1554 TDF_Label L = pdn->Label();
1555 Trans = pdn->myAtt->Transaction();
1556 return L;
1557}
1558//=======================================================================
1559//function : NamedShape
1560//purpose :
1561//=======================================================================
1562Handle(TNaming_NamedShape) TNaming_Tool::NamedShape(const TopoDS_Shape& S,
1563 const TDF_Label& Acces)
1564{
1565 Handle(TNaming_UsedShapes) US;
1566 Acces.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1567 Handle(TNaming_NamedShape) NS;
1568
1569 if(!TNaming_Tool::HasLabel(US,S)) {
1570 return NS;
1571 }
1572
1573 TNaming_RefShape* prs = US->Map().Find(S);
1574 TNaming_Node* pdn = prs->FirstUse();
1575 TNaming_Node* res = 0L;
1576
1577 while (pdn != 0L) {
1578 if (pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED) {
1579 res = pdn;
1580 if (pdn->myAtt->Evolution() != TNaming_GENERATED) {
1581 // Les modifications sont privilegiees par rapport au generation.
1582 // Dans le cas des shapes qui sont a la fois des modifications et des generations
1583 // faces tangentes.
1584 break;
1585 }
1586 }
1587 pdn = pdn->NextSameShape(prs);
1588 }
1589
1590 if (res == 0L) return NS;
1591
1592 // VERUE EN ATTENDANT DE REVOIR ABORT 03/11/98
1593 // Protection pour eviter de renvoyer un attribut backuped
1594 TDF_Label Lab = res->Label();
1595 Lab.FindAttribute(TNaming_NamedShape::GetID(),NS);
1596 return NS;
1597 // return res->myAtt;
1598}
1599
1600//=======================================================================
1601//function : IsValidInTrans
1602//purpose : un shape est valid tant que l attribut ou il est cree est valid
1603//=======================================================================
1604
1605Standard_Integer TNaming_Tool::ValidUntil (const TopoDS_Shape& S,
1606 const Handle(TNaming_UsedShapes)& US)
1607{
1608 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(US,S),"TNaming_Tool::ValidUntil");
1609
1610 TNaming_RefShape* RS = US->Map().ChangeFind(S);
1611 Standard_Integer Cur;
1612 Standard_Integer Until = 0;
1613 TNaming_Node* Node = RS->FirstUse();
1614
1615 while (Node != 0L) {
1616 if (Node->myNew != 0L && Node->myNew == RS) {
1617 Cur = Node->myAtt->UntilTransaction();
1618 if (Cur > Until) Until = Cur;
1619 }
1620 Node = Node->NextSameShape(RS);
1621 }
1622 return Until;
1623}