1 // Created on: 1996-12-18
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRepBuilderAPI_MakeVertex.hxx>
20 #include <Standard.hxx>
21 #include <Standard_ConstructionError.hxx>
22 #include <Standard_GUID.hxx>
23 #include <Standard_NoMoreObject.hxx>
24 #include <Standard_NoSuchObject.hxx>
25 #include <Standard_NullObject.hxx>
26 #include <Standard_Type.hxx>
27 #include <TDF_Attribute.hxx>
28 #include <TDF_AttributeDelta.hxx>
29 #include <TDF_AttributeIterator.hxx>
30 #include <TDF_Data.hxx>
31 #include <TDF_DataSet.hxx>
32 #include <TDF_DeltaOnAddition.hxx>
33 #include <TDF_DeltaOnModification.hxx>
34 #include <TDF_DeltaOnRemoval.hxx>
35 #include <TDF_Label.hxx>
36 #include <TDF_RelocationTable.hxx>
37 #include <TNaming_Builder.hxx>
38 #include <TNaming_CopyShape.hxx>
39 #include <TNaming_DeltaOnModification.hxx>
40 #include <TNaming_DeltaOnRemoval.hxx>
41 #include <TNaming_Iterator.hxx>
42 #include <TNaming_NamedShape.hxx>
43 #include <TNaming_NewShapeIterator.hxx>
44 #include <TNaming_OldShapeIterator.hxx>
45 #include <TNaming_PtrNode.hxx>
46 #include <TNaming_PtrRefShape.hxx>
47 #include <TNaming_RefShape.hxx>
48 #include <TNaming_SameShapeIterator.hxx>
49 #include <TNaming_Tool.hxx>
50 #include <TNaming_UsedShapes.hxx>
51 #include <TopoDS_Shape.hxx>
52 #include <TopoDS_Vertex.hxx>
54 IMPLEMENT_STANDARD_RTTIEXT(TNaming_NamedShape,TDF_Attribute)
56 // Defines the nodes classes
57 //#define MDTV_DEB_HASL
58 //=======================================================================
61 //=======================================================================
62 const Standard_GUID& TNaming_NamedShape::GetID()
64 static Standard_GUID TNaming_NamedShapeID("c4ef4200-568f-11d1-8940-080009dc3333");
65 return TNaming_NamedShapeID;
68 //=======================================================================
70 //=======================================================================
74 TNaming_Node(TNaming_PtrRefShape Old,
75 TNaming_PtrRefShape New)
76 : myOld(Old),myNew(New),
78 nextSameAttribute(0L), nextSameOld(0L),nextSameNew(0L)
81 //Label : Donne le Label
85 TNaming_Node* NextSameShape(TNaming_RefShape* prs);
87 // Test si l evolution est valide dans la transaction Trans
88 // ie : Trans n est pas anterieure a sa creation
89 // et Trans n est pas posterieure a son BackUp
90 Standard_Boolean IsValidInTrans(Standard_Integer Trans);
95 TNaming_PtrRefShape myOld;
96 TNaming_PtrRefShape myNew;
97 TNaming_NamedShape* myAtt;
98 TNaming_PtrNode nextSameAttribute;
99 TNaming_PtrNode nextSameOld;
100 TNaming_PtrNode nextSameNew;
103 //=======================================================================
104 //function : NextSameShape
106 //=======================================================================
108 TNaming_Node* TNaming_Node::NextSameShape(TNaming_RefShape* prs)
110 if (myOld == prs) return nextSameOld;
111 if (myNew == prs) return nextSameNew;
115 //=======================================================================
118 //=======================================================================
120 TDF_Label TNaming_Node::Label()
122 return myAtt->Label();
125 //=======================================================================
126 //function : IsValidInTrans
128 //=======================================================================
130 Standard_Boolean TNaming_Node::IsValidInTrans(Standard_Integer Trans)
132 if (myAtt->Transaction() <= Trans && Trans <= myAtt->UntilTransaction()) {
138 //**********************************************************************
139 // Methods of TNaming_NamedShape
140 //**********************************************************************
142 //=======================================================================
143 //function : TNaming_NamedShape
145 //=======================================================================
147 TNaming_NamedShape::TNaming_NamedShape()
153 //=======================================================================
156 //=======================================================================
158 Standard_Boolean TNaming_NamedShape::IsEmpty () const
160 TNaming_Iterator it (this);
165 //=======================================================================
168 //=======================================================================
170 TopoDS_Shape TNaming_NamedShape::Get () const
172 return TNaming_Tool::GetShape (this);
178 //=======================================================================
179 //function : RemoveNode
181 //=======================================================================
183 static void RemoveNode(Standard_Boolean MapExist ,
184 TNaming_DataMapOfShapePtrRefShape& M,
187 TNaming_RefShape* pos = N->myOld;
189 if (pos->FirstUse() == N) {
190 TNaming_Node* nextOld = N->nextSameOld;
192 pos->FirstUse(nextOld);
194 // le shape disparait
196 M.UnBind(pos->Shape());
206 TNaming_Node* pdn = pos->FirstUse();
209 if (pdn->NextSameShape(pos) == N) {
210 if (pdn->myOld == pos) pdn->nextSameOld = N->nextSameOld;
211 else pdn->nextSameNew = N->nextSameOld;
214 pdn = pdn->NextSameShape(pos);
219 TNaming_RefShape* pns = N->myNew;
221 if (pns->FirstUse() == N) {
222 TNaming_Node* nextNew = N->nextSameNew;
224 pns->FirstUse(nextNew);
227 // le shape disparait
229 M.UnBind(pns->Shape());
240 TNaming_Node* pdn = pns->FirstUse();
242 if (pdn->NextSameShape(pns) == N) {
243 if (pdn->myOld == pns) pdn->nextSameOld = N->nextSameNew;
244 else pdn->nextSameNew = N->nextSameNew;
247 pdn = pdn->NextSameShape(pns);
253 //=======================================================================
256 //=======================================================================
258 void TNaming_NamedShape::Clear()
260 if (Label().IsNull()) {
261 #ifdef OCCT_DEBUG_BUILDER
262 cout << "attention etat fantomatique" << endl;
267 Handle(TNaming_UsedShapes) US;
269 TNaming_DataMapOfShapePtrRefShape* M=NULL;
271 // Recuperation de la map si celle-ci n est pas deja detruite.
272 //Standard_Boolean MapExist = Ins.FindInRoot(TNaming_UsedShapes::GetID(),US);
274 Standard_Boolean MapExist = Label().Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
275 if (MapExist) M = &(US->Map());
277 TNaming_Node* p = myNode;
279 RemoveNode (MapExist,*M,p);
280 p = p->nextSameAttribute;
287 p = p->nextSameAttribute;
298 //=======================================================================
299 //function : BeforeRemoval
301 //=======================================================================
303 void TNaming_NamedShape::BeforeRemoval()
309 //=======================================================================
310 //function : BeforeUndo
311 //purpose : before application of a TDF_Delta.
312 //=======================================================================
314 Standard_Boolean TNaming_NamedShape::BeforeUndo
315 (const Handle(TDF_AttributeDelta)& /*anAttDelta*/,
316 const Standard_Boolean /*forceIt*/)
318 // if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) {
319 // anAttDelta->Attribute()->BeforeRemoval();
321 return Standard_True;
324 //=======================================================================
325 //function : AfterUndo
326 //purpose : After application of a TDF_Delta.
327 //=======================================================================
329 Standard_Boolean TNaming_NamedShape::AfterUndo
330 (const Handle(TDF_AttributeDelta)& anAttDelta,
331 const Standard_Boolean /*forceIt*/)
333 if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) {
334 Handle(TNaming_UsedShapes) US;
336 TNaming_DataMapOfShapePtrRefShape* M=NULL;
338 // Recuperation de la map si celle-ci n est pas deja detruite.
339 //Standard_Boolean MapExist = Ins.FindInRoot(TNaming_UsedShapes::GetID(),US);
341 Standard_Boolean MapExist = anAttDelta->Label().Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
343 if (MapExist) M = &(US->Map());
345 TNaming_Node* p = myNode;
347 RemoveNode (MapExist,*M,p);
348 p = p->nextSameAttribute;
355 p = p->nextSameAttribute;
365 return Standard_True;
369 //=======================================================================
370 //function : BackupCopy
372 //=======================================================================
374 Handle(TDF_Attribute) TNaming_NamedShape::BackupCopy() const
376 // Remarque dans le copy il est important de reporter le noeud de l attribut
377 // pour ne pas casser le chemin nextSameShape.
379 Handle(TNaming_NamedShape) Cop = new TNaming_NamedShape();
380 Cop->myNode = myNode;
381 Cop->myEvolution = myEvolution;
382 Cop->myVersion = myVersion;
384 // Mise a jour de myAtt sur les noeuds dans l attribut.
385 TNaming_Node* CN = Cop->myNode;
387 Handle(TNaming_NamedShape) A = this;
391 CN->myAtt = Cop.operator->();
392 CN = CN->nextSameAttribute;
398 //=======================================================================
401 //=======================================================================
403 void TNaming_NamedShape::Restore(const Handle(TDF_Attribute)& anAttribute)
407 TNaming_NamedShape* PAtt = (TNaming_NamedShape*)anAttribute.operator->();
408 myNode = PAtt->myNode;
409 myEvolution = PAtt->myEvolution;
410 myVersion = PAtt->myVersion;
412 // Mise a jour de myAtt sur les noeuds dans l attribut.
413 TNaming_Node* CN = myNode;
416 CN = CN->nextSameAttribute;
418 PAtt->myNode = 0L; //un noeud est dans un seul attribut.
422 //=======================================================================
423 //function : DeltaOnModification
425 //=======================================================================
427 Handle(TDF_DeltaOnModification) TNaming_NamedShape::DeltaOnModification
428 (const Handle(TDF_Attribute)& anOldAttribute) const
431 return new TNaming_DeltaOnModification(Handle(TNaming_NamedShape)::DownCast (anOldAttribute));
434 //=======================================================================
435 //function : DeltaOnModification
437 //=======================================================================
439 void TNaming_NamedShape::DeltaOnModification(const Handle(TDF_DeltaOnModification)& aDelta)
444 //=======================================================================
445 //function : DeltaOnRemoval
447 //=======================================================================
449 Handle(TDF_DeltaOnRemoval) TNaming_NamedShape::DeltaOnRemoval() const
451 return new TNaming_DeltaOnRemoval(this);
454 //=======================================================================
455 //function : NewEmpty
457 //=======================================================================
459 Handle(TDF_Attribute) TNaming_NamedShape::NewEmpty () const
461 return new TNaming_NamedShape();
464 //=======================================================================
467 //=======================================================================
469 void TNaming_NamedShape::Paste(const Handle(TDF_Attribute)& into,
470 const Handle(TDF_RelocationTable)& Tab)
473 TDF_Label Lab = into->Label();
475 throw Standard_NullObject("TNaming_NamedShape::Paste");
477 TNaming_Builder B(Lab);
479 TNaming_Iterator It (this);
480 for ( ;It.More() ; It.Next()) {
481 const TopoDS_Shape& OS = It.OldShape();
482 const TopoDS_Shape& NS = It.NewShape();
483 TNaming_Evolution Status = It.Evolution();
485 // Modification_1 24.06.99 (szy)
486 TopoDS_Shape copOS, copNS;
487 if(Status != TNaming_PRIMITIVE)
488 TNaming_CopyShape::CopyTool(OS, Tab->TransientTable(), copOS);
489 else copOS.Nullify();
490 if(Status != TNaming_DELETE )
491 TNaming_CopyShape::CopyTool(NS, Tab->TransientTable(), copNS);
492 else copNS.Nullify();
495 case TNaming_PRIMITIVE :
500 case TNaming_GENERATED :
502 B.Generated(copOS, copNS);
505 case TNaming_MODIFY :
507 B.Modify(copOS, copNS);
510 case TNaming_DELETE :
515 case TNaming_SELECTED :
517 B.Select(copNS,copOS);
527 //=======================================================================
528 //function : References
530 //=======================================================================
532 void TNaming_NamedShape::References(const Handle(TDF_DataSet)& aDataSet) const
534 // Recherche des dependances.
535 // Pour chaque OldShape de l attribut on ajoute au dataSet son label d origine.
536 TNaming_Node* Current = myNode;
537 while (Current != NULL) {
538 if (Current->myOld != NULL) {
539 TNaming_RefShape* prs = Current->myOld;
540 TNaming_Node* pdn = prs->FirstUse();
542 while (pdn != NULL) {
543 if (pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED) {
544 aDataSet->AddLabel(pdn->Label());
546 pdn = pdn->NextSameShape(prs);
549 Current = Current->nextSameAttribute;
554 //=======================================================================
557 //=======================================================================
559 void TNaming_NamedShape::Add(TNaming_Node*& pdn )
563 pdn->nextSameAttribute = myNode;
568 //=======================================================================
571 //=======================================================================
573 Standard_OStream& TNaming_NamedShape::Dump(Standard_OStream& anOS) const
578 //***************************************
579 // Fin Class Named_Shape.
580 //***************************************
583 //**********************************************************************
584 // Methods of the TNaming_Builder class
585 //**********************************************************************
587 ///=======================================================================
588 //function : TNaming_Builder
590 //=======================================================================
592 TNaming_Builder::TNaming_Builder (const TDF_Label& L)
594 // Find or Build Map;
595 const TDF_Label& root = L.Root();
596 if (!root.FindAttribute(TNaming_UsedShapes::GetID(),myShapes)) {
597 myShapes = new TNaming_UsedShapes();
598 root.AddAttribute (myShapes);
601 //Find Or Build Attribute in LIns.
602 if (!L.FindAttribute(TNaming_NamedShape::GetID(),myAtt)) {
603 myAtt = new TNaming_NamedShape();
604 L.AddAttribute(myAtt);
613 //=======================================================================
614 //function : TNaming_Builder
616 //=======================================================================
618 Handle(TNaming_NamedShape) TNaming_Builder::NamedShape() const
623 //=======================================================================
624 //function : UpdateNextSameShape
626 //=======================================================================
628 static void UpdateFirstUseOrNextSameShape(TNaming_RefShape*& prs,
631 TNaming_Node* ldn = prs->FirstUse();
636 TNaming_Node* cdn = ldn;
639 cdn = cdn->NextSameShape(prs);
641 throw Standard_ConstructionError("UpdateFirstUseOrNextSameShape");
645 // boucle interdite et inutile.
647 if (ldn->myOld == prs) ldn->nextSameOld = pdn;
648 if (ldn->myNew == prs) ldn->nextSameNew = pdn;
653 //=======================================================================
654 //function : Generate
656 //=======================================================================
658 void TNaming_Builder::Generated(const TopoDS_Shape& newShape)
660 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_PRIMITIVE;
662 if (myAtt->myEvolution != TNaming_PRIMITIVE)
663 throw Standard_ConstructionError("TNaming_Builder : not same evolution");
666 TNaming_RefShape* pos = 0L;
667 TNaming_RefShape* pns;
669 if (myShapes->myMap.IsBound(newShape)) {
670 #ifdef OCCT_DEBUG_BUILDER
671 cout <<"TNaming_Builder::Generate : the shape is already in the attribute"<<endl;
673 pns = myShapes->myMap.ChangeFind(newShape);
674 if (pns->FirstUse()->myAtt == myAtt.operator->()) {
675 throw Standard_ConstructionError("TNaming_Builder::Generate");
677 TNaming_Node* pdn = new TNaming_Node(pos,pns);
679 UpdateFirstUseOrNextSameShape (pns,pdn);
682 pns = new TNaming_RefShape(newShape);
683 TNaming_Node* pdn = new TNaming_Node(pos,pns);
685 myShapes->myMap.Bind (newShape , pns);
692 //=======================================================================
695 //=======================================================================
697 void TNaming_Builder::Delete(const TopoDS_Shape& oldShape)
699 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_DELETE;
701 if (myAtt->myEvolution != TNaming_DELETE)
702 throw Standard_ConstructionError("TNaming_Builder : not same evolution");
705 TNaming_RefShape* pns = 0L;
706 TNaming_RefShape* pos;
708 if (myShapes->myMap.IsBound(oldShape))
709 pos = myShapes->myMap.ChangeFind(oldShape);
711 #ifdef OCCT_DEBUG_BUILDER
712 cout <<"TNaming_Builder::Delete : the shape is not in the data"<<endl;
714 pos = new TNaming_RefShape(oldShape);
715 myShapes->myMap.Bind(oldShape, pos);
717 TNaming_Node* pdn = new TNaming_Node(pos,pns);
719 UpdateFirstUseOrNextSameShape (pos,pdn);
722 //=======================================================================
723 //function : Generate
725 //=======================================================================
727 void TNaming_Builder::Generated(const TopoDS_Shape& oldShape,
728 const TopoDS_Shape& newShape)
730 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_GENERATED;
732 if (myAtt->myEvolution != TNaming_GENERATED)
733 throw Standard_ConstructionError("TNaming_Builder : not same evolution");
736 if (oldShape.IsSame(newShape)) {
737 #ifdef OCCT_DEBUG_BUILDER
738 cout <<"TNaming_Builder::Generate : oldShape IsSame newShape"<<endl;
742 TNaming_RefShape* pos;
743 if (!myShapes->myMap.IsBound(oldShape)) {
744 pos = new TNaming_RefShape(oldShape);
745 myShapes->myMap.Bind(oldShape,pos);
748 pos = myShapes->myMap.ChangeFind(oldShape);
750 TNaming_RefShape* pns;
751 if (!myShapes->myMap.IsBound(newShape)) {
752 pns = new TNaming_RefShape(newShape);
753 myShapes->myMap.Bind(newShape,pns);
756 pns = myShapes->myMap.ChangeFind(newShape);
758 TNaming_Node* pdn = new TNaming_Node(pos,pns);
760 UpdateFirstUseOrNextSameShape (pos,pdn);
761 UpdateFirstUseOrNextSameShape (pns,pdn);
765 //=======================================================================
768 //=======================================================================
770 void TNaming_Builder::Modify(const TopoDS_Shape& oldShape,
771 const TopoDS_Shape& newShape)
773 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_MODIFY;
775 if (myAtt->myEvolution != TNaming_MODIFY)
776 throw Standard_ConstructionError("TNaming_Builder : not same evolution");
779 if (oldShape.IsSame(newShape)) {
780 #ifdef OCCT_DEBUG_BUILDER
781 cout <<"TNaming_Builder::Modify : oldShape IsSame newShape"<<endl;
785 TNaming_RefShape* pos;
786 if (!myShapes->myMap.IsBound(oldShape)) {
787 pos = new TNaming_RefShape(oldShape);
788 myShapes->myMap.Bind(oldShape,pos);
791 pos = myShapes->myMap.ChangeFind(oldShape);
793 TNaming_RefShape* pns;
794 if (!myShapes->myMap.IsBound(newShape)) {
795 pns = new TNaming_RefShape(newShape);
796 myShapes->myMap.Bind(newShape,pns);
799 pns = myShapes->myMap.ChangeFind(newShape);
801 TNaming_Node* pdn = new TNaming_Node(pos,pns);
803 UpdateFirstUseOrNextSameShape (pos,pdn);
804 UpdateFirstUseOrNextSameShape (pns,pdn);
808 //=======================================================================
811 //=======================================================================
812 void TNaming_Builder::Select (const TopoDS_Shape& S,
813 const TopoDS_Shape& InS)
815 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_SELECTED;
817 if (myAtt->myEvolution != TNaming_SELECTED)
818 throw Standard_ConstructionError("TNaming_Builder : not same evolution");
821 TNaming_RefShape* pos;
822 if (!myShapes->myMap.IsBound(InS)) {
823 pos = new TNaming_RefShape(InS);
824 myShapes->myMap.Bind(InS,pos);
827 pos = myShapes->myMap.ChangeFind(InS);
829 TNaming_RefShape* pns;
830 if (!myShapes->myMap.IsBound(S)) {
831 pns = new TNaming_RefShape(S);
832 myShapes->myMap.Bind(S,pns);
835 pns = myShapes->myMap.ChangeFind(S);
837 TNaming_Node* pdn = new TNaming_Node(pos,pns);
839 UpdateFirstUseOrNextSameShape (pos,pdn);
840 UpdateFirstUseOrNextSameShape (pns,pdn);
843 //**********************************************************************
844 //Methods of the TNaming_Iterator class
845 //**********************************************************************
847 //=======================================================================
848 //function : TNaming_Iterator
850 //=======================================================================
852 TNaming_Iterator::TNaming_Iterator(const Handle(TNaming_NamedShape)& Att)
855 myNode = Att->myNode;
858 //=======================================================================
859 //function : TNaming_Iterator
861 //=======================================================================
863 TNaming_Iterator::TNaming_Iterator(const TDF_Label& Lab)
866 Handle(TNaming_NamedShape) Att;
867 if (Lab.FindAttribute(TNaming_NamedShape::GetID(),Att)) {
868 myNode = Att->myNode;
875 //=====================================================================
876 //function : TNaming_Iterator
878 //=======================================================================
880 TNaming_Iterator::TNaming_Iterator(const TDF_Label& Lab,
881 const Standard_Integer Trans)
884 Handle(TDF_Attribute) Att;
885 if (Lab.FindAttribute(TNaming_NamedShape::GetID(),Trans,Att)) {
886 myNode = Handle(TNaming_NamedShape)::DownCast (Att)->myNode;
891 cout <<"TNaming_Iterator : No Shape for this label"<<endl;
896 //=======================================================================
899 //=======================================================================
901 void TNaming_Iterator::Next()
903 Standard_NoMoreObject_Raise_if(myNode == 0L,
904 "TNaming_Iterator::Next");
905 myNode = myNode->nextSameAttribute;
908 //=======================================================================
909 //function : OldShape
911 //=======================================================================
913 const TopoDS_Shape& TNaming_Iterator::OldShape() const
915 Standard_NoSuchObject_Raise_if(myNode == 0L,
916 "TNaming_Iterator::OldShape");
917 if (myNode->myOld == 0L) {
918 static TopoDS_Shape NullShape;
921 return myNode->myOld->Shape();
924 //=======================================================================
925 //function : NewShape
927 //=======================================================================
929 const TopoDS_Shape& TNaming_Iterator::NewShape() const
931 Standard_NoSuchObject_Raise_if(myNode == 0L,
932 "TNaming_Iterator::NewShape");
933 if (myNode->myNew == 0L) {
934 static TopoDS_Shape NullShape;
937 return myNode->myNew->Shape();
941 //=======================================================================
942 //function : IsModification
944 //=======================================================================
946 Standard_Boolean TNaming_Iterator::IsModification() const
948 Standard_NoSuchObject_Raise_if(myNode == 0L,
949 "TNaming_Iterator::IsModification");
950 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
951 myNode->myAtt->myEvolution == TNaming_DELETE );
954 //=======================================================================
955 //function : Evolution
957 //=======================================================================
959 TNaming_Evolution TNaming_Iterator::Evolution() const
961 Standard_NoSuchObject_Raise_if(myNode == 0L,
962 "TNaming_Iterator::IsModification");
963 return myNode->myAtt->myEvolution;
968 //**********************************************************************
969 //Methods of the TNaming_NewShapeIterator class
970 //**********************************************************************
972 //=======================================================================
973 //function : SelectSameShape
974 //purpose : Selectionne le prochain noeud ou le shape est le meme que celui
975 // de RS. Old = 0 si il doit etre new dans le noeud a chercher.
976 // selection dans la transaction valide.
977 // On saute aussi les noeud ou OS = NS;
978 //=======================================================================
980 static void SelectSameShape (TNaming_Node*& myNode,
981 Standard_Boolean Old,
982 TNaming_RefShape*& RS,
983 const Standard_Integer& Trans)
985 TNaming_Node* pdn = myNode;
988 Standard_Boolean Valid;
989 if (Trans < 0) Valid = pdn->myAtt->IsValid();
990 else Valid = pdn->IsValidInTrans(Trans);
995 if( pdn->myOld == RS && pdn->myNew != 0L && pdn->myNew != RS) {
1000 if( pdn->myNew == RS && pdn->myOld != 0L && pdn->myOld != RS) {
1005 pdn = pdn->NextSameShape(RS);
1010 //=======================================================================
1011 //function : TNaming_NewShapeIterator
1013 //=======================================================================
1015 TNaming_NewShapeIterator::TNaming_NewShapeIterator
1016 (const TopoDS_Shape& aShape,
1017 const Standard_Integer Trans,
1018 const Handle(TNaming_UsedShapes)& Shapes)
1021 Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape),
1022 "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");
1023 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1024 myNode = RS->FirstUse();
1025 Standard_Boolean Old(Standard_True);
1026 SelectSameShape(myNode,Old,RS,myTrans);
1029 //=======================================================================
1030 //function : TNaming_NewShapeIterator
1032 //=======================================================================
1034 TNaming_NewShapeIterator::TNaming_NewShapeIterator
1035 (const TopoDS_Shape& aShape,
1036 const Standard_Integer Trans,
1037 const TDF_Label& access)
1040 Handle(TNaming_UsedShapes) Shapes;
1041 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1042 Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape),
1043 "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");
1044 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1045 myNode = RS->FirstUse();
1046 Standard_Boolean Old(Standard_True);
1047 SelectSameShape(myNode,Old,RS,myTrans);
1051 //=======================================================================
1052 //function : TNaming_NewShapeIterator
1054 //=======================================================================
1056 TNaming_NewShapeIterator::TNaming_NewShapeIterator (const TNaming_Iterator& anIterator)
1057 :myTrans(anIterator.myTrans)
1059 Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
1060 "TNaming_NewShapeIterator::TNaming_NewShapeIterator");
1061 myNode = anIterator.myNode;
1062 TNaming_RefShape* RS = myNode->myNew;
1064 myNode = 0L; // No descendant
1066 // il faut repartir de la premiere utilisation.
1067 myNode = RS->FirstUse();
1068 Standard_Boolean Old(Standard_True);
1069 SelectSameShape(myNode,Old,RS,myTrans);
1073 //=======================================================================
1074 //function : TNaming_NewShapeIterator
1076 //=======================================================================
1078 TNaming_NewShapeIterator::TNaming_NewShapeIterator
1079 (const TopoDS_Shape& aShape,
1080 const Handle(TNaming_UsedShapes)& Shapes)
1083 Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape),
1084 "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");
1085 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1086 myNode = RS->FirstUse();
1087 Standard_Boolean Old(Standard_True);
1088 SelectSameShape(myNode,Old,RS,myTrans);
1091 //=======================================================================
1092 //function : TNaming_NewShapeIterator
1094 //=======================================================================
1096 TNaming_NewShapeIterator::TNaming_NewShapeIterator
1097 (const TopoDS_Shape& aShape,
1098 const TDF_Label& access)
1101 Handle(TNaming_UsedShapes) Shapes;
1102 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1103 Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape),
1104 "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");
1105 Standard_Boolean Old(Standard_True);
1106 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1107 myNode = RS->FirstUse();
1108 SelectSameShape(myNode,Old,RS,myTrans);
1112 //=======================================================================
1113 //function : TNaming_NewShapeIterator
1115 //=======================================================================
1117 TNaming_NewShapeIterator::TNaming_NewShapeIterator(const TNaming_NewShapeIterator& anIterator)
1118 :myTrans(anIterator.myTrans)
1120 Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
1121 "TNaming_NewShapeIterator::TNaming_NewShapeIterator");
1122 myNode = anIterator.myNode;
1123 TNaming_RefShape* RS = myNode->myNew;
1125 myNode = 0L; // No descendant
1127 // il faut repartir de la premiere utilisation.
1128 myNode = RS->FirstUse();
1129 Standard_Boolean Old(Standard_True);
1130 SelectSameShape(myNode,Old,RS,myTrans);
1134 //=======================================================================
1137 //=======================================================================
1139 void TNaming_NewShapeIterator::Next()
1141 TNaming_RefShape* RS = myNode->myOld;
1142 myNode = myNode->NextSameShape(RS);
1143 Standard_Boolean Old(Standard_True);
1144 SelectSameShape(myNode,Old,RS,myTrans);
1147 //=======================================================================
1150 //=======================================================================
1152 TDF_Label TNaming_NewShapeIterator::Label() const
1154 Standard_NoSuchObject_Raise_if(myNode == 0L,
1155 "TNaming_NewShapeIterator::Label");
1156 return myNode->Label();
1159 //=======================================================================
1160 //function : NamedShape
1162 //=======================================================================
1164 Handle(TNaming_NamedShape) TNaming_NewShapeIterator::NamedShape() const
1166 Standard_NoSuchObject_Raise_if(myNode == 0L,
1167 "TNaming_NewShapeIterator::Label");
1168 return myNode->myAtt;
1171 //=======================================================================
1174 //=======================================================================
1176 const TopoDS_Shape& TNaming_NewShapeIterator::Shape() const
1178 Standard_NoSuchObject_Raise_if(myNode == 0L,
1179 "TNaming_NewShapeIterator::Shape");
1180 return myNode->myNew->Shape();
1183 //=======================================================================
1184 //function : IsModification
1186 //=======================================================================
1188 Standard_Boolean TNaming_NewShapeIterator::IsModification() const
1190 Standard_NoSuchObject_Raise_if(myNode == 0L,
1191 "TNaming_NewShapeIterator::IsModification");
1193 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
1194 myNode->myAtt->myEvolution == TNaming_DELETE );
1197 //**********************************************************************
1198 //Methods of the TNaming_OldShapeIterator class
1199 //**********************************************************************
1200 //=======================================================================
1201 //function : TNaming_OldShapeIterator
1203 //=======================================================================
1205 TNaming_OldShapeIterator::TNaming_OldShapeIterator
1206 (const TopoDS_Shape& aShape,
1207 const Standard_Integer Trans,
1208 const Handle(TNaming_UsedShapes)& Shapes)
1211 Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape),
1212 "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape");
1213 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1214 myNode = RS->FirstUse();
1215 Standard_Boolean Old(Standard_False);
1216 SelectSameShape(myNode,Old,RS,myTrans);
1219 //=======================================================================
1220 //function : TNaming_OldShapeIterator
1222 //=======================================================================
1224 TNaming_OldShapeIterator::TNaming_OldShapeIterator
1225 (const TopoDS_Shape& aShape,
1226 const Standard_Integer Trans,
1227 const TDF_Label& access)
1230 Handle(TNaming_UsedShapes) Shapes;
1231 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1232 Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape),
1233 "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape");
1234 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1235 myNode = RS->FirstUse();
1236 Standard_Boolean Old(Standard_False);
1237 SelectSameShape(myNode,Old,RS,myTrans);
1240 //=======================================================================
1241 //function : TNaming_OldShapeIterator
1243 //=======================================================================
1245 TNaming_OldShapeIterator::TNaming_OldShapeIterator
1246 (const TopoDS_Shape& aShape,
1247 const Handle(TNaming_UsedShapes)& Shapes)
1250 Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape),
1251 "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape");
1252 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1253 myNode = RS->FirstUse();
1254 Standard_Boolean Old(Standard_False);
1255 SelectSameShape(myNode,Old,RS,myTrans);
1258 //=======================================================================
1259 //function : TNaming_OldShapeIterator
1261 //=======================================================================
1263 TNaming_OldShapeIterator::TNaming_OldShapeIterator
1264 (const TopoDS_Shape& aShape,
1265 const TDF_Label& access)
1268 Handle(TNaming_UsedShapes) Shapes;
1269 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1270 Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape),
1271 "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape");
1272 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1273 myNode = RS->FirstUse();
1274 Standard_Boolean Old(Standard_False);
1275 SelectSameShape(myNode,Old,RS,myTrans);
1279 //=======================================================================
1280 //function : TNaming_OldShapeIterator
1282 //=======================================================================
1284 TNaming_OldShapeIterator::TNaming_OldShapeIterator (const TNaming_Iterator& anIterator)
1285 :myTrans(anIterator.myTrans)
1287 Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
1288 "TNaming_OldShapeIterator::TNaming_OldShapeIterator");
1289 myNode = anIterator.myNode;
1290 TNaming_RefShape* RS = myNode->myNew;
1292 myNode = 0L; // No descendant
1294 // il faut repartir de la premiere utilisation.
1295 myNode = RS->FirstUse();
1296 Standard_Boolean Old(Standard_False);
1297 SelectSameShape(myNode,Old,RS,myTrans);
1301 //=======================================================================
1302 //function : TNaming_OldShapeIterator
1304 //=======================================================================
1306 TNaming_OldShapeIterator::TNaming_OldShapeIterator(const TNaming_OldShapeIterator& anIterator)
1307 :myTrans(anIterator.myTrans)
1309 Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
1310 "TNaming_OldShapeIterator::TNaming_OldShapeIterator");
1311 myNode = anIterator.myNode;
1312 TNaming_RefShape* RS = myNode->myOld;
1314 myNode = 0L; // No descendant
1316 // il faut repartir de la premiere utilisation.
1317 myNode = RS->FirstUse();
1318 Standard_Boolean Old(Standard_False);
1319 SelectSameShape(myNode,Old,RS,myTrans);
1323 //=======================================================================
1326 //=======================================================================
1328 void TNaming_OldShapeIterator::Next()
1330 Standard_Boolean Old = Standard_False;
1331 TNaming_RefShape* RS = myNode->myNew;
1332 myNode = myNode->NextSameShape(RS);
1333 SelectSameShape(myNode,Old,RS,myTrans);
1336 //=======================================================================
1339 //=======================================================================
1341 TDF_Label TNaming_OldShapeIterator::Label() const
1343 if (myNode == 0L) throw Standard_NoSuchObject("TNaming_OldShapeIterator::Label");
1344 return myNode->Label();
1348 //=======================================================================
1349 //function : NamedShape
1351 //=======================================================================
1353 Handle(TNaming_NamedShape) TNaming_OldShapeIterator::NamedShape() const
1355 if (myNode == 0L) throw Standard_NoSuchObject("TNaming_OldShapeIterator::Label");
1356 return myNode->myAtt;
1358 //=======================================================================
1361 //=======================================================================
1363 const TopoDS_Shape& TNaming_OldShapeIterator::Shape() const
1365 if(myNode == 0L) throw Standard_NoSuchObject("TNaming_OldShapeIterator::Shape");
1366 return myNode->myOld->Shape();
1369 //=======================================================================
1370 //function : IsModification
1372 //=======================================================================
1374 Standard_Boolean TNaming_OldShapeIterator::IsModification() const
1376 Standard_NoSuchObject_Raise_if(myNode == 0L,
1377 "TNaming_OldShapeIterator::IsModification");
1378 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
1379 myNode->myAtt->myEvolution == TNaming_DELETE );
1383 //**********************************************************************
1384 //Methods of the SameShapeIterator
1385 //**********************************************************************
1387 //=======================================================================
1390 //=======================================================================
1392 TNaming_SameShapeIterator::TNaming_SameShapeIterator
1393 (const TopoDS_Shape& aShape,
1394 const Handle(TNaming_UsedShapes)& Shapes)
1396 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1397 myNode = RS->FirstUse();
1398 myIsNew = (myNode->myNew == RS);
1402 //=======================================================================
1403 //function : TNaming_SameShapeIterator
1405 //=======================================================================
1407 TNaming_SameShapeIterator::TNaming_SameShapeIterator
1408 (const TopoDS_Shape& aShape,
1409 const TDF_Label& access)
1411 Handle(TNaming_UsedShapes) Shapes;
1412 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1413 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1414 myNode = RS->FirstUse();
1415 myIsNew = (myNode->myNew == RS);
1419 //=======================================================================
1422 //=======================================================================
1424 void TNaming_SameShapeIterator::Next()
1426 TNaming_RefShape* prs;
1427 if (myIsNew) prs = myNode->myNew; else prs = myNode->myOld;
1429 myNode = myNode->NextSameShape(prs);
1430 if (myNode != 0L) myIsNew = (myNode->myNew == prs);
1433 //=======================================================================
1436 //=======================================================================
1438 TDF_Label TNaming_SameShapeIterator::Label() const
1440 Standard_NoSuchObject_Raise_if(myNode == 0L,
1441 "TNaming_SameShapeIterator::Label");
1442 return myNode->Label();
1446 //**********************************************************************
1447 //Methods of the TNaming_RefShape
1448 //**********************************************************************
1449 //=======================================================================
1452 //=======================================================================
1454 TDF_Label TNaming_RefShape::Label() const
1456 return myFirstUse->myAtt->Label();
1459 //=======================================================================
1460 //function : NamedShape
1462 //=======================================================================
1464 Handle(TNaming_NamedShape) TNaming_RefShape::NamedShape() const
1466 return myFirstUse->myAtt;
1470 //**********************************************************************
1471 //Methods of the TNaming_Tool class
1472 //**********************************************************************
1474 //=======================================================================
1475 //function : HasLabel
1477 //=======================================================================
1479 Standard_Boolean TNaming_Tool::HasLabel (const TDF_Label& access,
1480 const TopoDS_Shape& S)
1482 Handle(TNaming_UsedShapes) US;
1483 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US)) {
1484 return (US->Map().IsBound(S));
1486 #ifdef OCCT_DEBUG_HASL
1487 cout << "##==> Sub-Shape has no Label!" <<endl;
1489 return Standard_False;
1493 //=======================================================================
1496 //=======================================================================
1498 TDF_Label TNaming_Tool::Label(const TDF_Label& access,
1499 const TopoDS_Shape& S,
1500 Standard_Integer& Trans)
1502 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(access,S),"TNaming_Tool::Label");
1503 Handle(TNaming_UsedShapes) US;
1504 access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1505 return TNaming_Tool::Label(US,S,Trans);
1509 //=======================================================================
1510 //function : IsValidInTrans
1511 //purpose : un shape est valid tant que l attribut ou il est cree est valid
1512 //=======================================================================
1514 Standard_Integer TNaming_Tool::ValidUntil (const TDF_Label& access, const TopoDS_Shape& S)
1516 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(access,S),"TNaming_Tool::ValidUntil");
1517 Handle(TNaming_UsedShapes) US;
1518 access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1519 return TNaming_Tool::ValidUntil(S,US);
1523 //=======================================================================
1524 //function : HasLabel
1526 //=======================================================================
1528 Standard_Boolean TNaming_Tool::HasLabel(const Handle(TNaming_UsedShapes)& Shapes,
1529 const TopoDS_Shape& S)
1531 return (Shapes->Map().IsBound(S));
1535 //=======================================================================
1538 //=======================================================================
1540 TDF_Label TNaming_Tool::Label(const Handle(TNaming_UsedShapes)& Shapes,
1541 const TopoDS_Shape& S,
1542 Standard_Integer& Trans)
1544 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(Shapes,S),"TNaming_Tool::Label");
1545 TNaming_RefShape* prs = Shapes->Map().Find(S);
1546 TNaming_Node* pdn = prs->FirstUse();
1548 while (pdn != 0L && !(pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED)){
1549 pdn = pdn->NextSameShape(prs);
1551 if (pdn == 0L) pdn = prs->FirstUse();
1553 TDF_Label L = pdn->Label();
1554 Trans = pdn->myAtt->Transaction();
1557 //=======================================================================
1558 //function : NamedShape
1560 //=======================================================================
1561 Handle(TNaming_NamedShape) TNaming_Tool::NamedShape(const TopoDS_Shape& S,
1562 const TDF_Label& Acces)
1564 Handle(TNaming_UsedShapes) US;
1565 Acces.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1566 Handle(TNaming_NamedShape) NS;
1568 if(!TNaming_Tool::HasLabel(US,S)) {
1572 TNaming_RefShape* prs = US->Map().Find(S);
1573 TNaming_Node* pdn = prs->FirstUse();
1574 TNaming_Node* res = 0L;
1577 if (pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED) {
1579 if (pdn->myAtt->Evolution() != TNaming_GENERATED) {
1580 // Les modifications sont privilegiees par rapport au generation.
1581 // Dans le cas des shapes qui sont a la fois des modifications et des generations
1586 pdn = pdn->NextSameShape(prs);
1589 if (res == 0L) return NS;
1591 // VERUE EN ATTENDANT DE REVOIR ABORT 03/11/98
1592 // Protection pour eviter de renvoyer un attribut backuped
1593 TDF_Label Lab = res->Label();
1594 Lab.FindAttribute(TNaming_NamedShape::GetID(),NS);
1596 // return res->myAtt;
1599 //=======================================================================
1600 //function : IsValidInTrans
1601 //purpose : un shape est valid tant que l attribut ou il est cree est valid
1602 //=======================================================================
1604 Standard_Integer TNaming_Tool::ValidUntil (const TopoDS_Shape& S,
1605 const Handle(TNaming_UsedShapes)& US)
1607 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(US,S),"TNaming_Tool::ValidUntil");
1609 TNaming_RefShape* RS = US->Map().ChangeFind(S);
1610 Standard_Integer Cur;
1611 Standard_Integer Until = 0;
1612 TNaming_Node* Node = RS->FirstUse();
1614 while (Node != 0L) {
1615 if (Node->myNew != 0L && Node->myNew == RS) {
1616 Cur = Node->myAtt->UntilTransaction();
1617 if (Cur > Until) Until = Cur;
1619 Node = Node->NextSameShape(RS);