0022795: Make possible to display some presentable objects in overlay of others,...
[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
80 void* operator new(size_t aSize) {
81 return Standard::Allocate(aSize);
82 }
83
84/* attempt to eliminate compiler warning
85 void* operator new(size_t, void* aNode) {
86 return aNode;
87 }
88
89 void operator delete(void* aNode) {
90 Standard::Free(aNode);
91 }
92*/
93
94 void operator delete(void* aNode, size_t aSize) {
95 Standard::Free(aNode);
96 }
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{
621 Handle(TNaming_UsedShapes) Shapes;
622
623 // Find or Build Map;
624 const TDF_Label& root = L.Root();
625 if (!root.FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
626 Shapes = new TNaming_UsedShapes();
627 root.AddAttribute (Shapes);
628 }
629 myMap = &(Shapes->myMap);
630
631 //Find Or Build Attribute in LIns.
632 Handle(TNaming_NamedShape) Att;
633 if (!L.FindAttribute(TNaming_NamedShape::GetID(),Att)) {
634 Att = new TNaming_NamedShape();
635 L.AddAttribute(Att);
636 }
637 else {
638 Att->Backup();
639 Att->Clear();
640 Att->myVersion++;
641 }
642 myAtt = Att.operator->();
643}
644
645//=======================================================================
646//function : TNaming_Builder
647//purpose :
648//=======================================================================
649
650Handle(TNaming_NamedShape) TNaming_Builder::NamedShape() const
651{
652 return myAtt;
653}
654
655//=======================================================================
656//function : UpdateNextSameShape
657//purpose :
658//=======================================================================
659
660static void UpdateFirstUseOrNextSameShape(TNaming_RefShape*& prs,
661 TNaming_Node*& pdn)
662{
663 TNaming_Node* ldn = prs->FirstUse();
664 if (ldn == 0L) {
665 prs->FirstUse(pdn);
666 }
667 else {
668 TNaming_Node* cdn = ldn;
669 while (cdn != 0L) {
670 ldn = cdn;
671 cdn = cdn->NextSameShape(prs);
672 if (ldn == cdn) {
673 Standard_ConstructionError::Raise("UpdateFirstUseOrNextSameShape");
674 break;
675 }
676 }
677 // boucle interdite et inutile.
678 if (ldn != pdn) {
679 if (ldn->myOld == prs) ldn->nextSameOld = pdn;
680 if (ldn->myNew == prs) ldn->nextSameNew = pdn;
681 }
682 }
683}
684
685//=======================================================================
686//function : Generate
687//purpose :
688//=======================================================================
689
690void TNaming_Builder::Generated(const TopoDS_Shape& newShape)
691{
692 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_PRIMITIVE;
693 else {
694 if (myAtt->myEvolution != TNaming_PRIMITIVE)
695 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
696 }
697
698 TNaming_RefShape* pos = 0L;
699 TNaming_RefShape* pns;
700
701 if (myMap->IsBound(newShape)) {
702#ifdef DEB
703 cout <<"TNaming_Builder::Generate : the shape is already in the attribute"<<endl;
704#endif
705 pns = myMap->ChangeFind(newShape);
706 if (pns->FirstUse()->myAtt == myAtt) {
707 Standard_ConstructionError::Raise("TNaming_Builder::Generate");
708 }
709 TNaming_Node* pdn = new TNaming_Node(pos,pns);
710 myAtt->Add(pdn);
711 UpdateFirstUseOrNextSameShape (pns,pdn);
712 }
713 else {
714 pns = new TNaming_RefShape(newShape);
715 TNaming_Node* pdn = new TNaming_Node(pos,pns);
716 pns ->FirstUse(pdn);
717 myMap->Bind (newShape , pns);
718 myAtt->Add(pdn);
719 }
720}
721
722
723
724//=======================================================================
725//function : Delete
726//purpose :
727//=======================================================================
728
729void TNaming_Builder::Delete(const TopoDS_Shape& oldShape)
730{
731 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_DELETE;
732 else {
733 if (myAtt->myEvolution != TNaming_DELETE)
734 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
735 }
736
737 TNaming_RefShape* pns = 0L;
738 TNaming_RefShape* pos;
739
740 if (myMap->IsBound(oldShape))
741 pos = myMap->ChangeFind(oldShape);
742 else {
743#ifdef DEB
744 cout <<"TNaming_Builder::Delete : the shape is not in the data"<<endl;
745#endif
746 pos = new TNaming_RefShape(oldShape);
747 myMap->Bind(oldShape, pos);
748 }
749 TNaming_Node* pdn = new TNaming_Node(pos,pns);
750 myAtt->Add(pdn);
751 UpdateFirstUseOrNextSameShape (pos,pdn);
752}
753
754//=======================================================================
755//function : Generate
756//purpose :
757//=======================================================================
758
759void TNaming_Builder::Generated(const TopoDS_Shape& oldShape,
760 const TopoDS_Shape& newShape)
761{
762 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_GENERATED;
763 else {
764 if (myAtt->myEvolution != TNaming_GENERATED)
765 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
766 }
767
768 if (oldShape.IsSame(newShape)) {
769#ifdef DEB
770 cout <<"TNaming_Builder::Generate : oldShape IsSame newShape"<<endl;
771#endif
772 return;
773 }
774 TNaming_RefShape* pos;
775 if (!myMap->IsBound(oldShape)) {
776 pos = new TNaming_RefShape(oldShape);
777 myMap->Bind(oldShape,pos);
778 }
779 else
780 pos = myMap->ChangeFind(oldShape);
781
782 TNaming_RefShape* pns;
783 if (!myMap->IsBound(newShape)) {
784 pns = new TNaming_RefShape(newShape);
785 myMap->Bind(newShape,pns);
786 }
787 else
788 pns = myMap->ChangeFind(newShape);
789
790 TNaming_Node* pdn = new TNaming_Node(pos,pns);
791 myAtt->Add(pdn);
792 UpdateFirstUseOrNextSameShape (pos,pdn);
793 UpdateFirstUseOrNextSameShape (pns,pdn);
794}
795
796
797//=======================================================================
798//function : Modify
799//purpose :
800//=======================================================================
801
802void TNaming_Builder::Modify(const TopoDS_Shape& oldShape,
803 const TopoDS_Shape& newShape)
804{
805 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_MODIFY;
806 else {
807 if (myAtt->myEvolution != TNaming_MODIFY)
808 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
809 }
810
811 if (oldShape.IsSame(newShape)) {
812#ifdef DEB
813 cout <<"TNaming_Builder::Modify : oldShape IsSame newShape"<<endl;
814#endif
815 return;
816 }
817 TNaming_RefShape* pos;
818 if (!myMap->IsBound(oldShape)) {
819 pos = new TNaming_RefShape(oldShape);
820 myMap->Bind(oldShape,pos);
821 }
822 else
823 pos = myMap->ChangeFind(oldShape);
824
825 TNaming_RefShape* pns;
826 if (!myMap->IsBound(newShape)) {
827 pns = new TNaming_RefShape(newShape);
828 myMap->Bind(newShape,pns);
829 }
830 else
831 pns = myMap->ChangeFind(newShape);
832
833 TNaming_Node* pdn = new TNaming_Node(pos,pns);
834 myAtt->Add(pdn);
835 UpdateFirstUseOrNextSameShape (pos,pdn);
836 UpdateFirstUseOrNextSameShape (pns,pdn);
837
838}
839
840//=======================================================================
841//function : Modify
842//purpose :
843//=======================================================================
844
845void TNaming_Builder::Replace(const TopoDS_Shape& oldShape,
846 const TopoDS_Shape& newShape)
847{
848 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_REPLACE;
849 else {
850 if (myAtt->myEvolution != TNaming_REPLACE)
851 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
852 }
853
854 if (oldShape.IsSame(newShape)) {
855#ifdef DEB
856 cout <<"TNaming_Builder::Modify : oldShape IsSame newShape"<<endl;
857#endif
858 return;
859 }
860 TNaming_RefShape* pos;
861 if (!myMap->IsBound(oldShape)) {
862 pos = new TNaming_RefShape(oldShape);
863 myMap->Bind(oldShape,pos);
864 }
865 else
866 pos = myMap->ChangeFind(oldShape);
867
868 TNaming_RefShape* pns;
869 if (!myMap->IsBound(newShape)) {
870 pns = new TNaming_RefShape(newShape);
871 myMap->Bind(newShape,pns);
872 }
873 else
874 pns = myMap->ChangeFind(newShape);
875
876 TNaming_Node* pdn = new TNaming_Node(pos,pns);
877 myAtt->Add(pdn);
878 UpdateFirstUseOrNextSameShape (pos,pdn);
879 UpdateFirstUseOrNextSameShape (pns,pdn);
880
881}
882
883//=======================================================================
884static const TopoDS_Shape& DummyShapeToStoreOrientation (const TopAbs_Orientation Or)
885{
886 static TopoDS_Vertex aVForward, aVRev, aVInt, aVExt;
887 switch(Or) {
888 case TopAbs_FORWARD:
889 if(aVForward.IsNull()) {
890 gp_Pnt aPnt(0,0,0);
891 BRepBuilderAPI_MakeVertex aMake(aPnt);
892 aVForward = aMake.Vertex();
893 aVForward.Orientation(TopAbs_FORWARD);
894 }
895 return aVForward;
896 case TopAbs_REVERSED:
897 if(aVRev.IsNull()) {
898 gp_Pnt aPnt(0,0,0);
899 BRepBuilderAPI_MakeVertex aMake(aPnt);
900 aVRev = aMake.Vertex();
901 aVRev.Orientation(TopAbs_REVERSED);
902 }
903 return aVRev;
904 case TopAbs_INTERNAL:
905 if(aVInt.IsNull()) {
906 gp_Pnt aPnt(0,0,0);
907 BRepBuilderAPI_MakeVertex aMake(aPnt);
908 aVInt = aMake.Vertex();
909 aVInt.Orientation(TopAbs_INTERNAL);
910 }
911 return aVInt;
912 case TopAbs_EXTERNAL:
913 if(aVExt.IsNull()) {
914 gp_Pnt aPnt(0,0,0);
915 BRepBuilderAPI_MakeVertex aMake(aPnt);
916 aVExt = aMake.Vertex();
917 aVExt.Orientation(TopAbs_EXTERNAL);
918 }
919 return aVExt;
920 }
921 return aVForward;
922}
923
924//=======================================================================
925//function : Select
926//purpose :
927//=======================================================================
928void TNaming_Builder::Select (const TopoDS_Shape& S,
929 const TopoDS_Shape& InS)
930{
931 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_SELECTED;
932 else {
933 if (myAtt->myEvolution != TNaming_SELECTED)
934 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
935 }
936
937 TNaming_RefShape* pos;
938 if(S.ShapeType() != TopAbs_VERTEX) {
939 const TopoDS_Shape& aV = DummyShapeToStoreOrientation (S.Orientation());
940 if (!myMap->IsBound(aV)) {
941 pos = new TNaming_RefShape(aV);
942 myMap->Bind(aV,pos);
943 }
944 else
945 pos = myMap->ChangeFind(aV);
946 } else {
947 if (!myMap->IsBound(InS)) {
948 pos = new TNaming_RefShape(InS);
949 myMap->Bind(InS,pos);
950 }
951 else
952 pos = myMap->ChangeFind(InS);
953 }
954
955 TNaming_RefShape* pns;
956 if (!myMap->IsBound(S)) {
957 pns = new TNaming_RefShape(S);
958 myMap->Bind(S,pns);
959 }
960 else
961 pns = myMap->ChangeFind(S);
962
963 TNaming_Node* pdn = new TNaming_Node(pos,pns);
964 myAtt->Add(pdn);
965 UpdateFirstUseOrNextSameShape (pos,pdn);
966 UpdateFirstUseOrNextSameShape (pns,pdn);
967}
968
969//**********************************************************************
970//Methods of the TNaming_Iterator class
971//**********************************************************************
972
973//=======================================================================
974//function : TNaming_Iterator
975//purpose :
976//=======================================================================
977
978TNaming_Iterator::TNaming_Iterator(const Handle(TNaming_NamedShape)& Att)
979:myTrans(-1)
980{
981 myNode = Att->myNode;
982}
983
984//=======================================================================
985//function : TNaming_Iterator
986//purpose :
987//=======================================================================
988
989TNaming_Iterator::TNaming_Iterator(const TDF_Label& Lab)
990:myTrans(-1)
991{
992 Handle(TNaming_NamedShape) Att;
993 if (Lab.FindAttribute(TNaming_NamedShape::GetID(),Att)) {
994 myNode = Att->myNode;
995 }
996 else {
997 myNode = 0L;
998 }
999}
1000
1001//=====================================================================
1002//function : TNaming_Iterator
1003//purpose :
1004//=======================================================================
1005
1006TNaming_Iterator::TNaming_Iterator(const TDF_Label& Lab,
1007 const Standard_Integer Trans)
1008:myTrans(Trans)
1009{
1010 Handle(TNaming_NamedShape) Att;
1011 if (Lab.FindAttribute(TNaming_NamedShape::GetID(),Trans,Att)) {
1012 myNode = Att->myNode;
1013 }
1014 else {
1015 myNode = 0L;
1016#ifdef DEB
1017 cout <<"TNaming_Iterator : No Shape for this label"<<endl;
1018#endif
1019 }
1020}
1021
1022//=======================================================================
1023//function : Next
1024//purpose :
1025//=======================================================================
1026
1027void TNaming_Iterator::Next()
1028{
1029 Standard_NoMoreObject_Raise_if(myNode == 0L,
1030 "TNaming_Iterator::Next");
1031 myNode = myNode->nextSameAttribute;
1032}
1033
1034//=======================================================================
1035//function : OldShape
1036//purpose :
1037//=======================================================================
1038
1039const TopoDS_Shape& TNaming_Iterator::OldShape() const
1040{
1041 Standard_NoSuchObject_Raise_if(myNode == 0L,
1042 "TNaming_Iterator::OldShape");
1043 if (myNode->myOld == 0L) {
1044 static TopoDS_Shape NullShape;
1045 return NullShape;
1046 }
1047 return myNode->myOld->Shape();
1048}
1049
1050//=======================================================================
1051//function : NewShape
1052//purpose :
1053//=======================================================================
1054
1055const TopoDS_Shape& TNaming_Iterator::NewShape() const
1056{
1057 Standard_NoSuchObject_Raise_if(myNode == 0L,
1058 "TNaming_Iterator::NewShape");
1059 if (myNode->myNew == 0L) {
1060 static TopoDS_Shape NullShape;
1061 return NullShape;
1062 }
1063 return myNode->myNew->Shape();
1064}
1065
1066
1067//=======================================================================
1068//function : IsModification
1069//purpose :
1070//=======================================================================
1071
1072Standard_Boolean TNaming_Iterator::IsModification() const
1073{
1074 Standard_NoSuchObject_Raise_if(myNode == 0L,
1075 "TNaming_Iterator::IsModification");
1076 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
1077 myNode->myAtt->myEvolution == TNaming_DELETE );
1078}
1079
1080//=======================================================================
1081//function : Evolution
1082//purpose :
1083//=======================================================================
1084
1085TNaming_Evolution TNaming_Iterator::Evolution() const
1086{
1087 Standard_NoSuchObject_Raise_if(myNode == 0L,
1088 "TNaming_Iterator::IsModification");
1089 return myNode->myAtt->myEvolution;
1090}
1091
1092
1093
1094//**********************************************************************
1095//Methods of the TNaming_NewShapeIterator class
1096//**********************************************************************
1097
1098//=======================================================================
1099//function : SelectSameShape
1100//purpose : Selectionne le prochain noeud ou le shape est le meme que celui
1101// de RS. Old = 0 si il doit etre new dans le noeud a chercher.
1102// selection dans la transaction valide.
1103// On saute aussi les noeud ou OS = NS;
1104//=======================================================================
1105
1106static void SelectSameShape (TNaming_Node*& myNode,
1107 Standard_Boolean Old,
1108 TNaming_RefShape*& RS,
1109 const Standard_Integer& Trans)
1110{
1111 TNaming_Node* pdn = myNode;
1112
1113 while (pdn != 0L) {
1114 Standard_Boolean Valid;
1115 if (Trans < 0) Valid = pdn->myAtt->IsValid();
1116 else Valid = pdn->IsValidInTrans(Trans);
1117
1118 if (Valid)
1119 if (Old) {
1120 if( pdn->myOld == RS && pdn->myNew != 0L && pdn->myNew != RS) {
1121 break;
1122 }
1123 }
1124 else {
1125 if( pdn->myNew == RS && pdn->myOld != 0L && pdn->myOld != RS) {
1126 break;
1127 }
1128 }
1129 pdn = pdn->NextSameShape(RS);
1130 }
1131 myNode = pdn;
1132}
1133
1134//=======================================================================
1135//function : TNaming_NewShapeIterator
1136//purpose :
1137//=======================================================================
1138
1139TNaming_NewShapeIterator::TNaming_NewShapeIterator
1140(const TopoDS_Shape& aShape,
1141 const Standard_Integer Trans,
1142 const Handle(TNaming_UsedShapes)& Shapes)
1143:myTrans(Trans)
1144{
1145 Standard_Boolean Old = Standard_True;
1146 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1147 myNode = RS->FirstUse();
1148 SelectSameShape(myNode,Old,RS,myTrans);
1149}
1150
1151//=======================================================================
1152//function : TNaming_NewShapeIterator
1153//purpose :
1154//=======================================================================
1155
1156TNaming_NewShapeIterator::TNaming_NewShapeIterator
1157(const TopoDS_Shape& aShape,
1158 const Standard_Integer Trans,
1159 const TDF_Label& access)
1160:myTrans(Trans)
1161{
1162 Handle(TNaming_UsedShapes) Shapes;
1163 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1164 Standard_Boolean Old = Standard_True;
1165 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1166 myNode = RS->FirstUse();
1167 SelectSameShape(myNode,Old,RS,myTrans);
1168 }
1169}
1170
1171//=======================================================================
1172//function : TNaming_NewShapeIterator
1173//purpose :
1174//=======================================================================
1175
1176TNaming_NewShapeIterator::TNaming_NewShapeIterator (const TNaming_Iterator& anIterator)
1177:myTrans(anIterator.myTrans)
1178{
1179 Standard_Boolean Old = Standard_True;
1180 myNode = anIterator.myNode;
1181 TNaming_RefShape* RS = myNode->myNew;
1182 if (RS == 0L)
1183 myNode = 0L; // No descendant
1184 else {
1185 // il faut repartir de la premiere utilisation.
1186 myNode = RS->FirstUse();
1187 SelectSameShape(myNode,Old,RS,myTrans);
1188 }
1189}
1190
1191//=======================================================================
1192//function : TNaming_NewShapeIterator
1193//purpose :
1194//=======================================================================
1195
1196TNaming_NewShapeIterator::TNaming_NewShapeIterator
1197(const TopoDS_Shape& aShape,
1198 const Handle(TNaming_UsedShapes)& Shapes)
1199:myTrans(-1)
1200{
1201 Standard_Boolean Old = Standard_True;
1202 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1203 myNode = RS->FirstUse();
1204 SelectSameShape(myNode,Old,RS,myTrans);
1205}
1206
1207//=======================================================================
1208//function : TNaming_NewShapeIterator
1209//purpose :
1210//=======================================================================
1211
1212TNaming_NewShapeIterator::TNaming_NewShapeIterator
1213(const TopoDS_Shape& aShape,
1214 const TDF_Label& access)
1215:myTrans(-1)
1216{
1217 Handle(TNaming_UsedShapes) Shapes;
1218 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1219 Standard_Boolean Old = Standard_True;
1220 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1221 myNode = RS->FirstUse();
1222 SelectSameShape(myNode,Old,RS,myTrans);
1223 }
1224}
1225
1226//=======================================================================
1227//function : TNaming_NewShapeIterator
1228//purpose :
1229//=======================================================================
1230
1231TNaming_NewShapeIterator::TNaming_NewShapeIterator(const TNaming_NewShapeIterator& anIterator)
1232:myTrans(anIterator.myTrans)
1233{
1234 Standard_Boolean Old = Standard_True;
1235 myNode = anIterator.myNode;
1236 TNaming_RefShape* RS = myNode->myNew;
1237 if (RS == 0L)
1238 myNode = 0L; // No descendant
1239 else {
1240 // il faut repartir de la premiere utilisation.
1241 myNode = RS->FirstUse();
1242 SelectSameShape(myNode,Old,RS,myTrans);
1243 }
1244}
1245
1246//=======================================================================
1247//function : Next
1248//purpose :
1249//=======================================================================
1250
1251void TNaming_NewShapeIterator::Next()
1252{
1253 Standard_Boolean Old = Standard_True;
1254 TNaming_RefShape* RS = myNode->myOld;
1255 myNode = myNode->NextSameShape(RS);
1256 SelectSameShape(myNode,Old,RS,myTrans);
1257}
1258
1259//=======================================================================
1260//function : Label
1261//purpose :
1262//=======================================================================
1263
1264TDF_Label TNaming_NewShapeIterator::Label() const
1265{
1266 Standard_NoSuchObject_Raise_if(myNode == 0L,
1267 "TNaming_NewShapeIterator::Label");
1268 return myNode->Label();
1269}
1270
1271//=======================================================================
1272//function : NamedShape
1273//purpose :
1274//=======================================================================
1275
1276Handle(TNaming_NamedShape) TNaming_NewShapeIterator::NamedShape() const
1277{
1278 Standard_NoSuchObject_Raise_if(myNode == 0L,
1279 "TNaming_NewShapeIterator::Label");
1280 return myNode->myAtt;
1281}
1282
1283//=======================================================================
1284//function : Shape
1285//purpose :
1286//=======================================================================
1287
1288const TopoDS_Shape& TNaming_NewShapeIterator::Shape() const
1289{
1290 Standard_NoSuchObject_Raise_if(myNode == 0L,
1291 "TNaming_NewShapeIterator::Shape");
1292 return myNode->myNew->Shape();
1293}
1294
1295//=======================================================================
1296//function : IsModification
1297//purpose :
1298//=======================================================================
1299
1300Standard_Boolean TNaming_NewShapeIterator::IsModification() const
1301{
1302 Standard_NoSuchObject_Raise_if(myNode == 0L,
1303 "TNaming_NewShapeIterator::IsModification");
1304
1305 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
1306 myNode->myAtt->myEvolution == TNaming_DELETE );
1307}
1308
1309//**********************************************************************
1310//Methods of the TNaming_OldShapeIterator class
1311//**********************************************************************
1312//=======================================================================
1313//function : TNaming_OldShapeIterator
1314//purpose :
1315//=======================================================================
1316
1317TNaming_OldShapeIterator::TNaming_OldShapeIterator
1318(const TopoDS_Shape& aShape,
1319 const Standard_Integer Trans,
1320 const Handle(TNaming_UsedShapes)& Shapes)
1321:myTrans(Trans)
1322{
1323 Standard_Boolean Old = Standard_False;
1324 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1325 myNode = RS->FirstUse();
1326 SelectSameShape(myNode,Old,RS,myTrans);
1327}
1328
1329//=======================================================================
1330//function : TNaming_OldShapeIterator
1331//purpose :
1332//=======================================================================
1333
1334TNaming_OldShapeIterator::TNaming_OldShapeIterator
1335(const TopoDS_Shape& aShape,
1336 const Standard_Integer Trans,
1337 const TDF_Label& access)
1338:myTrans(Trans)
1339{
1340 Handle(TNaming_UsedShapes) Shapes;
1341 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
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 Handle(TNaming_UsedShapes)& Shapes)
1356:myTrans(-1)
1357{
1358 Standard_Boolean Old = Standard_False;
1359 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1360 myNode = RS->FirstUse();
1361 SelectSameShape(myNode,Old,RS,myTrans);
1362}
1363
1364//=======================================================================
1365//function : TNaming_OldShapeIterator
1366//purpose :
1367//=======================================================================
1368
1369TNaming_OldShapeIterator::TNaming_OldShapeIterator
1370(const TopoDS_Shape& aShape,
1371 const TDF_Label& access)
1372:myTrans(-1)
1373{
1374 Handle(TNaming_UsedShapes) Shapes;
1375 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1376 Standard_Boolean Old = Standard_False;
1377 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1378 myNode = RS->FirstUse();
1379 SelectSameShape(myNode,Old,RS,myTrans);
1380 }
1381}
1382
1383//=======================================================================
1384//function : TNaming_OldShapeIterator
1385//purpose :
1386//=======================================================================
1387
1388TNaming_OldShapeIterator::TNaming_OldShapeIterator (const TNaming_Iterator& anIterator)
1389:myTrans(anIterator.myTrans)
1390{
1391 Standard_Boolean Old = Standard_False;
1392 myNode = anIterator.myNode;
1393 TNaming_RefShape* RS = myNode->myNew;
1394 if (RS == 0L)
1395 myNode = 0L; // No descendant
1396 else {
1397 // il faut repartir de la premiere utilisation.
1398 myNode = RS->FirstUse();
1399 SelectSameShape(myNode,Old,RS,myTrans);
1400 }
1401}
1402
1403//=======================================================================
1404//function : TNaming_OldShapeIterator
1405//purpose :
1406//=======================================================================
1407
1408TNaming_OldShapeIterator::TNaming_OldShapeIterator(const TNaming_OldShapeIterator& anIterator)
1409:myTrans(anIterator.myTrans)
1410{
1411 Standard_Boolean Old = Standard_False;
1412 myNode = anIterator.myNode;
1413 TNaming_RefShape* RS = myNode->myOld;
1414 if (RS == 0L)
1415 myNode = 0L; // No descendant
1416 else {
1417 // il faut repartir de la premiere utilisation.
1418 myNode = RS->FirstUse();
1419 SelectSameShape(myNode,Old,RS,myTrans);
1420 }
1421}
1422
1423//=======================================================================
1424//function : Next
1425//purpose :
1426//=======================================================================
1427
1428void TNaming_OldShapeIterator::Next()
1429{
1430 Standard_Boolean Old = Standard_False;
1431 TNaming_RefShape* RS = myNode->myNew;
1432 myNode = myNode->NextSameShape(RS);
1433 SelectSameShape(myNode,Old,RS,myTrans);
1434}
1435
1436//=======================================================================
1437//function : Label
1438//purpose :
1439//=======================================================================
1440
1441TDF_Label TNaming_OldShapeIterator::Label() const
1442{
1443 if (myNode == 0L) Standard_NoSuchObject::Raise("TNaming_OldShapeIterator::Label");
1444 return myNode->Label();
1445
1446}
1447
1448//=======================================================================
1449//function : NamedShape
1450//purpose :
1451//=======================================================================
1452
1453Handle(TNaming_NamedShape) TNaming_OldShapeIterator::NamedShape() const
1454{
1455 if (myNode == 0L) Standard_NoSuchObject::Raise("TNaming_OldShapeIterator::Label");
1456 return myNode->myAtt;
1457}
1458//=======================================================================
1459//function : Shape
1460//purpose :
1461//=======================================================================
1462
1463const TopoDS_Shape& TNaming_OldShapeIterator::Shape() const
1464{
1465 if(myNode == 0L) Standard_NoSuchObject::Raise("TNaming_OldShapeIterator::Shape");
1466 return myNode->myOld->Shape();
1467}
1468
1469//=======================================================================
1470//function : IsModification
1471//purpose :
1472//=======================================================================
1473
1474Standard_Boolean TNaming_OldShapeIterator::IsModification() const
1475{
1476 Standard_NoSuchObject_Raise_if(myNode == 0L,
1477 "TNaming_OldShapeIterator::IsModification");
1478 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
1479 myNode->myAtt->myEvolution == TNaming_DELETE );
1480}
1481
1482
1483//**********************************************************************
1484//Methods of the SameShapeIterator
1485//**********************************************************************
1486
1487//=======================================================================
1488//function :
1489//purpose :
1490//=======================================================================
1491
1492TNaming_SameShapeIterator::TNaming_SameShapeIterator
1493(const TopoDS_Shape& aShape,
1494 const Handle(TNaming_UsedShapes)& Shapes)
1495{
1496 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1497 myNode = RS->FirstUse();
1498 myIsNew = (myNode->myNew == RS);
1499}
1500
1501
1502//=======================================================================
1503//function : TNaming_SameShapeIterator
1504//purpose :
1505//=======================================================================
1506
1507TNaming_SameShapeIterator::TNaming_SameShapeIterator
1508(const TopoDS_Shape& aShape,
1509 const TDF_Label& access)
1510{
1511 Handle(TNaming_UsedShapes) Shapes;
1512 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1513 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1514 myNode = RS->FirstUse();
1515 myIsNew = (myNode->myNew == RS);
1516 }
1517}
1518
1519//=======================================================================
1520//function : Next
1521//purpose :
1522//=======================================================================
1523
1524void TNaming_SameShapeIterator::Next()
1525{
1526 TNaming_RefShape* prs;
1527 if (myIsNew) prs = myNode->myNew; else prs = myNode->myOld;
1528
1529 myNode = myNode->NextSameShape(prs);
1530 if (myNode != 0L) myIsNew = (myNode->myNew == prs);
1531}
1532
1533//=======================================================================
1534//function : Label
1535//purpose :
1536//=======================================================================
1537
1538TDF_Label TNaming_SameShapeIterator::Label() const
1539{
1540 Standard_NoSuchObject_Raise_if(myNode == 0L,
1541 "TNaming_SameShapeIterator::Label");
1542 return myNode->Label();
1543}
1544
1545
1546//**********************************************************************
1547//Methods of the TNaming_RefShape
1548//**********************************************************************
1549//=======================================================================
1550//function : Label
1551//purpose :
1552//=======================================================================
1553
1554TDF_Label TNaming_RefShape::Label() const
1555{
1556 return myFirstUse->myAtt->Label();
1557}
1558
1559//=======================================================================
1560//function : NamedShape
1561//purpose :
1562//=======================================================================
1563
1564Handle(TNaming_NamedShape) TNaming_RefShape::NamedShape() const
1565{
1566 return myFirstUse->myAtt;
1567}
1568
1569
1570//**********************************************************************
1571//Methods of the TNaming_Tool class
1572//**********************************************************************
1573
1574//=======================================================================
1575//function : HasLabel
1576//purpose :
1577//=======================================================================
1578
1579Standard_Boolean TNaming_Tool::HasLabel (const TDF_Label& access,
1580 const TopoDS_Shape& S)
1581{
1582 Handle(TNaming_UsedShapes) US;
1583 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US)) {
1584 return (US->Map().IsBound(S));
1585 }
1586#ifdef MDTV_DEB_HASL
1587 cout << "##==> Sub-Shape has no Label!" <<endl;
1588#endif
1589 return Standard_False;
1590}
1591
1592
1593//=======================================================================
1594//function : Label
1595//purpose :
1596//=======================================================================
1597
1598TDF_Label TNaming_Tool::Label(const TDF_Label& access,
1599 const TopoDS_Shape& S,
1600 Standard_Integer& Trans)
1601{
1602 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(access,S),"TNaming_Tool::Label");
1603 Handle(TNaming_UsedShapes) US;
1604 access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1605 return TNaming_Tool::Label(US,S,Trans);
1606}
1607
1608
1609//=======================================================================
1610//function : IsValidInTrans
1611//purpose : un shape est valid tant que l attribut ou il est cree est valid
1612//=======================================================================
1613
1614Standard_Integer TNaming_Tool::ValidUntil (const TDF_Label& access, const TopoDS_Shape& S)
1615{
1616 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(access,S),"TNaming_Tool::ValidUntil");
1617 Handle(TNaming_UsedShapes) US;
1618 access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1619 return TNaming_Tool::ValidUntil(S,US);
1620}
1621
1622
1623//=======================================================================
1624//function : HasLabel
1625//purpose :
1626//=======================================================================
1627
1628Standard_Boolean TNaming_Tool::HasLabel(const Handle(TNaming_UsedShapes)& Shapes,
1629 const TopoDS_Shape& S)
1630{
1631 return (Shapes->Map().IsBound(S));
1632}
1633
1634
1635//=======================================================================
1636//function : Label
1637//purpose :
1638//=======================================================================
1639
1640TDF_Label TNaming_Tool::Label(const Handle(TNaming_UsedShapes)& Shapes,
1641 const TopoDS_Shape& S,
1642 Standard_Integer& Trans)
1643{
1644 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(Shapes,S),"TNaming_Tool::Label");
1645 TNaming_RefShape* prs = Shapes->Map().Find(S);
1646 TNaming_Node* pdn = prs->FirstUse();
1647
1648 while (pdn != 0L && !(pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED)){
1649 pdn = pdn->NextSameShape(prs);
1650 }
1651 if (pdn == 0L) pdn = prs->FirstUse();
1652
1653 TDF_Label L = pdn->Label();
1654 Trans = pdn->myAtt->Transaction();
1655 return L;
1656}
1657//=======================================================================
1658//function : NamedShape
1659//purpose :
1660//=======================================================================
1661Handle(TNaming_NamedShape) TNaming_Tool::NamedShape(const TopoDS_Shape& S,
1662 const TDF_Label& Acces)
1663{
1664 Handle(TNaming_UsedShapes) US;
1665 Acces.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1666 Handle(TNaming_NamedShape) NS;
1667
1668 if(!TNaming_Tool::HasLabel(US,S)) {
1669 return NS;
1670 }
1671
1672 TNaming_RefShape* prs = US->Map().Find(S);
1673 TNaming_Node* pdn = prs->FirstUse();
1674 TNaming_Node* res = 0L;
1675
1676 while (pdn != 0L) {
1677 if (pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED) {
1678 res = pdn;
1679 if (pdn->myAtt->Evolution() != TNaming_GENERATED) {
1680 // Les modifications sont privilegiees par rapport au generation.
1681 // Dans le cas des shapes qui sont a la fois des modifications et des generations
1682 // faces tangentes.
1683 break;
1684 }
1685 }
1686 pdn = pdn->NextSameShape(prs);
1687 }
1688
1689 if (res == 0L) return NS;
1690
1691 // VERUE EN ATTENDANT DE REVOIR ABORT 03/11/98
1692 // Protection pour eviter de renvoyer un attribut backuped
1693 TDF_Label Lab = res->Label();
1694 Lab.FindAttribute(TNaming_NamedShape::GetID(),NS);
1695 return NS;
1696 // return res->myAtt;
1697}
1698
1699//=======================================================================
1700//function : IsValidInTrans
1701//purpose : un shape est valid tant que l attribut ou il est cree est valid
1702//=======================================================================
1703
1704Standard_Integer TNaming_Tool::ValidUntil (const TopoDS_Shape& S,
1705 const Handle(TNaming_UsedShapes)& US)
1706{
1707 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(US,S),"TNaming_Tool::ValidUntil");
1708
1709 TNaming_RefShape* RS = US->Map().ChangeFind(S);
1710 Standard_Integer Cur;
1711 Standard_Integer Until = 0;
1712 TNaming_Node* Node = RS->FirstUse();
1713
1714 while (Node != 0L) {
1715 if (Node->myNew != 0L && Node->myNew == RS) {
1716 Cur = Node->myAtt->UntilTransaction();
1717 if (Cur > Until) Until = Cur;
1718 }
1719 Node = Node->NextSameShape(RS);
1720 }
1721 return Until;
1722}
1723
1724
1725//=======================================================================
1726//function : OldPaste
1727//purpose :
1728//=======================================================================
1729
1730void TNaming_NamedShape::OldPaste(const Handle(TDF_Attribute)& into,
1731 const Handle(TDF_RelocationTable)& /*Tab*/)
1732const
1733{
1734 TDF_Label Lab = into->Label();
1735 if (Lab.IsNull()) {
1736 Standard_NullObject::Raise("TNaming_NamedShape::Paste");
1737 }
1738 //TDF_Insertor Ins(Lab);
1739 //TNaming_Builder B(Ins);
1740 TNaming_Builder B(Lab);
1741
1742 TNaming_Iterator It (this);
1743 for ( ;It.More() ; It.Next()) {
1744 const TopoDS_Shape& OS = It.OldShape();
1745 const TopoDS_Shape& NS = It.NewShape();
1746 TNaming_Evolution Status = It.Evolution();
1747 switch (Status) {
1748 case TNaming_PRIMITIVE :
1749 {
1750 B.Generated(NS);
1751 break;
1752 }
1753 case TNaming_GENERATED :
1754 {
1755 B.Generated(OS,NS);
1756 break;
1757 }
1758 case TNaming_MODIFY :
1759 {
1760 B.Modify(OS,NS);
1761 break;
1762 }
1763 case TNaming_DELETE :
1764 {
1765 B.Delete (OS);
1766 break;
1767 }
1768 case TNaming_SELECTED :
1769 {
1770 B.Select(NS,OS);
1771 break;
1772 }
1773 case TNaming_REPLACE :
1774 B.Replace(OS,NS);
1775 }
1776 }
1777}
1778