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