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