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