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