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