1 // Created on: 1996-12-18
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
24 #include <TNaming_NamedShape.ixx>
25 #include <TNaming_Builder.ixx>
27 #include <TDF_Label.hxx>
28 #include <TDF_Data.hxx>
29 #include <TDF_DeltaOnAddition.hxx>
30 #include <TDF_AttributeIterator.hxx>
31 #include <TNaming_PtrNode.hxx>
32 #include <TNaming_PtrRefShape.hxx>
33 #include <TNaming_RefShape.hxx>
34 #include <TNaming_PtrDataMapOfShapePtrRefShape.hxx>
35 #include <TNaming_UsedShapes.hxx>
36 #include <TNaming_Tool.hxx>
37 #include <TNaming_Iterator.hxx>
38 #include <TNaming_NewShapeIterator.hxx>
39 #include <TNaming_OldShapeIterator.hxx>
40 #include <TNaming_SameShapeIterator.hxx>
42 #include <TNaming_DeltaOnModification.hxx>
43 #include <TNaming_DeltaOnRemoval.hxx>
44 #include <Standard_NoMoreObject.hxx>
45 #include <Standard_NoSuchObject.hxx>
46 #include <Standard_ConstructionError.hxx>
47 #include <Standard_NullObject.hxx>
50 #include <BRepBuilderAPI_MakeVertex.hxx>
51 #include <TopoDS_Vertex.hxx>
53 // Defines the nodes classes
55 #include <Standard.hxx>
56 #include <TNaming_CopyShape.hxx>
58 #define BUC60921 //SRN 15/05/01 : Fixes the memory leak due to pointer to RefShape is not deleted
59 //#define MDTV_DEB_HASL
60 //=======================================================================
63 //=======================================================================
65 const Standard_GUID& TNaming_NamedShape::GetID()
67 static Standard_GUID TNaming_NamedShapeID("c4ef4200-568f-11d1-8940-080009dc3333");
68 return TNaming_NamedShapeID;
71 //=======================================================================
73 //=======================================================================
77 TNaming_Node(TNaming_PtrRefShape Old,
78 TNaming_PtrRefShape New)
79 : myOld(Old),myNew(New),
81 nextSameAttribute(0L), nextSameOld(0L),nextSameNew(0L)
84 //Label : Donne le Label
88 TNaming_Node* NextSameShape(TNaming_RefShape* prs);
90 // Test si l evolution est valide dans la transaction Trans
91 // ie : Trans n est pas anterieure a sa creation
92 // et Trans n est pas posterieure a son BackUp
93 Standard_Boolean IsValidInTrans(Standard_Integer Trans);
98 TNaming_PtrRefShape myOld;
99 TNaming_PtrRefShape myNew;
100 TNaming_NamedShape* myAtt;
101 TNaming_PtrNode nextSameAttribute;
102 TNaming_PtrNode nextSameOld;
103 TNaming_PtrNode nextSameNew;
106 //=======================================================================
107 //function : NextSameShape
109 //=======================================================================
111 TNaming_Node* TNaming_Node::NextSameShape(TNaming_RefShape* prs)
113 if (myOld == prs) return nextSameOld;
114 if (myNew == prs) return nextSameNew;
118 //=======================================================================
121 //=======================================================================
123 TDF_Label TNaming_Node::Label()
125 return myAtt->Label();
128 //=======================================================================
129 //function : IsValidInTrans
131 //=======================================================================
133 Standard_Boolean TNaming_Node::IsValidInTrans(Standard_Integer Trans)
135 if (myAtt->Transaction() <= Trans && Trans <= myAtt->UntilTransaction()) {
141 //**********************************************************************
142 // Methods of TNaming_NamedShape
143 //**********************************************************************
145 //=======================================================================
146 //function : TNaming_NamedShape
148 //=======================================================================
150 TNaming_NamedShape::TNaming_NamedShape()
156 //=======================================================================
159 //=======================================================================
161 Standard_Boolean TNaming_NamedShape::IsEmpty () const
163 TNaming_Iterator it (this);
168 //=======================================================================
171 //=======================================================================
173 TopoDS_Shape TNaming_NamedShape::Get () const
175 return TNaming_Tool::GetShape (this);
181 //=======================================================================
182 //function : RemoveNode
184 //=======================================================================
186 static void RemoveNode(Standard_Boolean MapExist ,
187 TNaming_DataMapOfShapePtrRefShape& M,
190 TNaming_RefShape* pos = N->myOld;
192 if (pos->FirstUse() == N) {
193 TNaming_Node* nextOld = N->nextSameOld;
195 pos->FirstUse(nextOld);
197 // le shape disparait
199 M.UnBind(pos->Shape());
211 TNaming_Node* pdn = pos->FirstUse();
214 if (pdn->NextSameShape(pos) == N) {
215 if (pdn->myOld == pos) pdn->nextSameOld = N->nextSameOld;
216 else pdn->nextSameNew = N->nextSameOld;
219 pdn = pdn->NextSameShape(pos);
224 TNaming_RefShape* pns = N->myNew;
226 if (pns->FirstUse() == N) {
227 TNaming_Node* nextNew = N->nextSameNew;
229 pns->FirstUse(nextNew);
232 // le shape disparait
234 M.UnBind(pns->Shape());
245 TNaming_Node* pdn = pns->FirstUse();
247 if (pdn->NextSameShape(pns) == N) {
248 if (pdn->myOld == pns) pdn->nextSameOld = N->nextSameNew;
249 else pdn->nextSameNew = N->nextSameNew;
252 pdn = pdn->NextSameShape(pns);
258 //=======================================================================
261 //=======================================================================
263 void TNaming_NamedShape::Clear()
265 if (Label().IsNull()) {
267 cout << "attention etat fantomatique" << endl;
272 Handle(TNaming_UsedShapes) US;
274 TNaming_DataMapOfShapePtrRefShape* M=NULL;
276 // Recuperation de la map si celle-ci n est pas deja detruite.
277 //Standard_Boolean MapExist = Ins.FindInRoot(TNaming_UsedShapes::GetID(),US);
279 Standard_Boolean MapExist = Label().Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
280 if (MapExist) M = &(US->Map());
282 TNaming_Node* p = myNode;
284 RemoveNode (MapExist,*M,p);
285 p = p->nextSameAttribute;
292 p = p->nextSameAttribute;
303 //=======================================================================
304 //function : BeforeRemoval
306 //=======================================================================
308 void TNaming_NamedShape::BeforeRemoval()
314 //=======================================================================
315 //function : BeforeUndo
316 //purpose : before application of a TDF_Delta.
317 //=======================================================================
319 Standard_Boolean TNaming_NamedShape::BeforeUndo
320 (const Handle(TDF_AttributeDelta)& /*anAttDelta*/,
321 const Standard_Boolean /*forceIt*/)
323 // if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) {
324 // anAttDelta->Attribute()->BeforeRemoval();
326 return Standard_True;
329 //=======================================================================
330 //function : AfterUndo
331 //purpose : After application of a TDF_Delta.
332 //=======================================================================
334 Standard_Boolean TNaming_NamedShape::AfterUndo
335 (const Handle(TDF_AttributeDelta)& anAttDelta,
336 const Standard_Boolean /*forceIt*/)
338 if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) {
339 Handle(TNaming_UsedShapes) US;
341 TNaming_DataMapOfShapePtrRefShape* M=NULL;
343 // Recuperation de la map si celle-ci n est pas deja detruite.
344 //Standard_Boolean MapExist = Ins.FindInRoot(TNaming_UsedShapes::GetID(),US);
346 Standard_Boolean MapExist = anAttDelta->Label().Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
348 if (MapExist) M = &(US->Map());
350 TNaming_Node* p = myNode;
352 RemoveNode (MapExist,*M,p);
353 p = p->nextSameAttribute;
360 p = p->nextSameAttribute;
370 return Standard_True;
374 //=======================================================================
375 //function : BackupCopy
377 //=======================================================================
379 Handle(TDF_Attribute) TNaming_NamedShape::BackupCopy() const
381 // Remarque dans le copy il est important de reporter le noeud de l attribut
382 // pour ne pas casser le chemin nextSameShape.
384 Handle(TNaming_NamedShape) Cop = new TNaming_NamedShape();
385 Cop->myNode = myNode;
386 Cop->myEvolution = myEvolution;
387 Cop->myVersion = myVersion;
389 // Mise a jour de myAtt sur les noeuds dans l attribut.
390 TNaming_Node* CN = Cop->myNode;
392 Handle(TNaming_NamedShape) A = this;
396 CN->myAtt = Cop.operator->();
397 CN = CN->nextSameAttribute;
403 //=======================================================================
406 //=======================================================================
408 void TNaming_NamedShape::Restore(const Handle(TDF_Attribute)& anAttribute)
412 TNaming_NamedShape* PAtt = (TNaming_NamedShape*)anAttribute.operator->();
413 myNode = PAtt->myNode;
414 myEvolution = PAtt->myEvolution;
415 myVersion = PAtt->myVersion;
417 // Mise a jour de myAtt sur les noeuds dans l attribut.
418 TNaming_Node* CN = myNode;
421 CN = CN->nextSameAttribute;
423 PAtt->myNode = 0L; //un noeud est dans un seul attribut.
427 //=======================================================================
428 //function : DeltaOnModification
430 //=======================================================================
432 Handle(TDF_DeltaOnModification) TNaming_NamedShape::DeltaOnModification
433 (const Handle(TDF_Attribute)& anOldAttribute) const
436 return new TNaming_DeltaOnModification(*((Handle(TNaming_NamedShape)*)&anOldAttribute));
439 //=======================================================================
440 //function : DeltaOnModification
442 //=======================================================================
444 void TNaming_NamedShape::DeltaOnModification(const Handle(TDF_DeltaOnModification)& aDelta)
449 //=======================================================================
450 //function : DeltaOnRemoval
452 //=======================================================================
454 Handle(TDF_DeltaOnRemoval) TNaming_NamedShape::DeltaOnRemoval() const
456 return new TNaming_DeltaOnRemoval(this);
459 //=======================================================================
460 //function : NewEmpty
462 //=======================================================================
464 Handle(TDF_Attribute) TNaming_NamedShape::NewEmpty () const
466 return new TNaming_NamedShape();
469 //=======================================================================
472 //=======================================================================
474 void TNaming_NamedShape::Paste(const Handle(TDF_Attribute)& into,
475 const Handle(TDF_RelocationTable)& Tab)
478 TDF_Label Lab = into->Label();
480 Standard_NullObject::Raise("TNaming_NamedShape::Paste");
482 TNaming_Builder B(Lab);
484 TNaming_Iterator It (this);
485 for ( ;It.More() ; It.Next()) {
486 const TopoDS_Shape& OS = It.OldShape();
487 const TopoDS_Shape& NS = It.NewShape();
488 TNaming_Evolution Status = It.Evolution();
490 // Modification_1 24.06.99 (szy)
491 TopoDS_Shape copOS, copNS;
492 if(Status != TNaming_PRIMITIVE)
493 TNaming_CopyShape::CopyTool(OS, Tab->TransientTable(), copOS);
494 else copOS.Nullify();
495 if(Status != TNaming_DELETE )
496 TNaming_CopyShape::CopyTool(NS, Tab->TransientTable(), copNS);
497 else copNS.Nullify();
500 case TNaming_PRIMITIVE :
505 case TNaming_GENERATED :
507 B.Generated(copOS, copNS);
510 case TNaming_MODIFY :
512 B.Modify(copOS, copNS);
515 case TNaming_DELETE :
520 case TNaming_SELECTED :
522 B.Select(copNS,copOS);
532 //=======================================================================
533 //function : References
535 //=======================================================================
537 void TNaming_NamedShape::References(const Handle(TDF_DataSet)& aDataSet) const
539 // Recherche des dependances.
540 // Pour chaque OldShape de l attribut on ajoute au dataSet son label d origine.
541 TNaming_Node* Current = myNode;
542 while (Current != NULL) {
543 if (Current->myOld != NULL) {
544 TNaming_RefShape* prs = Current->myOld;
545 TNaming_Node* pdn = prs->FirstUse();
547 while (pdn != NULL) {
548 if (pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED) {
549 aDataSet->AddLabel(pdn->Label());
551 pdn = pdn->NextSameShape(prs);
554 Current = Current->nextSameAttribute;
559 //=======================================================================
562 //=======================================================================
564 void TNaming_NamedShape::Add(TNaming_Node*& pdn )
568 pdn->nextSameAttribute = myNode;
573 //=======================================================================
576 //=======================================================================
578 Standard_OStream& TNaming_NamedShape::Dump(Standard_OStream& anOS) const
583 //***************************************
584 // Fin Class Named_Shape.
585 //***************************************
588 //**********************************************************************
589 // Methods of the TNaming_Builder class
590 //**********************************************************************
592 ///=======================================================================
593 //function : TNaming_Builder
595 //=======================================================================
597 TNaming_Builder::TNaming_Builder (const TDF_Label& L)
599 // Find or Build Map;
600 const TDF_Label& root = L.Root();
601 if (!root.FindAttribute(TNaming_UsedShapes::GetID(),myShapes)) {
602 myShapes = new TNaming_UsedShapes();
603 root.AddAttribute (myShapes);
606 //Find Or Build Attribute in LIns.
607 if (!L.FindAttribute(TNaming_NamedShape::GetID(),myAtt)) {
608 myAtt = new TNaming_NamedShape();
609 L.AddAttribute(myAtt);
618 //=======================================================================
619 //function : TNaming_Builder
621 //=======================================================================
623 Handle(TNaming_NamedShape) TNaming_Builder::NamedShape() const
628 //=======================================================================
629 //function : UpdateNextSameShape
631 //=======================================================================
633 static void UpdateFirstUseOrNextSameShape(TNaming_RefShape*& prs,
636 TNaming_Node* ldn = prs->FirstUse();
641 TNaming_Node* cdn = ldn;
644 cdn = cdn->NextSameShape(prs);
646 Standard_ConstructionError::Raise("UpdateFirstUseOrNextSameShape");
650 // boucle interdite et inutile.
652 if (ldn->myOld == prs) ldn->nextSameOld = pdn;
653 if (ldn->myNew == prs) ldn->nextSameNew = pdn;
658 //=======================================================================
659 //function : Generate
661 //=======================================================================
663 void TNaming_Builder::Generated(const TopoDS_Shape& newShape)
665 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_PRIMITIVE;
667 if (myAtt->myEvolution != TNaming_PRIMITIVE)
668 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
671 TNaming_RefShape* pos = 0L;
672 TNaming_RefShape* pns;
674 if (myShapes->myMap.IsBound(newShape)) {
676 cout <<"TNaming_Builder::Generate : the shape is already in the attribute"<<endl;
678 pns = myShapes->myMap.ChangeFind(newShape);
679 if (pns->FirstUse()->myAtt == myAtt.operator->()) {
680 Standard_ConstructionError::Raise("TNaming_Builder::Generate");
682 TNaming_Node* pdn = new TNaming_Node(pos,pns);
684 UpdateFirstUseOrNextSameShape (pns,pdn);
687 pns = new TNaming_RefShape(newShape);
688 TNaming_Node* pdn = new TNaming_Node(pos,pns);
690 myShapes->myMap.Bind (newShape , pns);
697 //=======================================================================
700 //=======================================================================
702 void TNaming_Builder::Delete(const TopoDS_Shape& oldShape)
704 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_DELETE;
706 if (myAtt->myEvolution != TNaming_DELETE)
707 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
710 TNaming_RefShape* pns = 0L;
711 TNaming_RefShape* pos;
713 if (myShapes->myMap.IsBound(oldShape))
714 pos = myShapes->myMap.ChangeFind(oldShape);
717 cout <<"TNaming_Builder::Delete : the shape is not in the data"<<endl;
719 pos = new TNaming_RefShape(oldShape);
720 myShapes->myMap.Bind(oldShape, pos);
722 TNaming_Node* pdn = new TNaming_Node(pos,pns);
724 UpdateFirstUseOrNextSameShape (pos,pdn);
727 //=======================================================================
728 //function : Generate
730 //=======================================================================
732 void TNaming_Builder::Generated(const TopoDS_Shape& oldShape,
733 const TopoDS_Shape& newShape)
735 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_GENERATED;
737 if (myAtt->myEvolution != TNaming_GENERATED)
738 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
741 if (oldShape.IsSame(newShape)) {
743 cout <<"TNaming_Builder::Generate : oldShape IsSame newShape"<<endl;
747 TNaming_RefShape* pos;
748 if (!myShapes->myMap.IsBound(oldShape)) {
749 pos = new TNaming_RefShape(oldShape);
750 myShapes->myMap.Bind(oldShape,pos);
753 pos = myShapes->myMap.ChangeFind(oldShape);
755 TNaming_RefShape* pns;
756 if (!myShapes->myMap.IsBound(newShape)) {
757 pns = new TNaming_RefShape(newShape);
758 myShapes->myMap.Bind(newShape,pns);
761 pns = myShapes->myMap.ChangeFind(newShape);
763 TNaming_Node* pdn = new TNaming_Node(pos,pns);
765 UpdateFirstUseOrNextSameShape (pos,pdn);
766 UpdateFirstUseOrNextSameShape (pns,pdn);
770 //=======================================================================
773 //=======================================================================
775 void TNaming_Builder::Modify(const TopoDS_Shape& oldShape,
776 const TopoDS_Shape& newShape)
778 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_MODIFY;
780 if (myAtt->myEvolution != TNaming_MODIFY)
781 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
784 if (oldShape.IsSame(newShape)) {
786 cout <<"TNaming_Builder::Modify : oldShape IsSame newShape"<<endl;
790 TNaming_RefShape* pos;
791 if (!myShapes->myMap.IsBound(oldShape)) {
792 pos = new TNaming_RefShape(oldShape);
793 myShapes->myMap.Bind(oldShape,pos);
796 pos = myShapes->myMap.ChangeFind(oldShape);
798 TNaming_RefShape* pns;
799 if (!myShapes->myMap.IsBound(newShape)) {
800 pns = new TNaming_RefShape(newShape);
801 myShapes->myMap.Bind(newShape,pns);
804 pns = myShapes->myMap.ChangeFind(newShape);
806 TNaming_Node* pdn = new TNaming_Node(pos,pns);
808 UpdateFirstUseOrNextSameShape (pos,pdn);
809 UpdateFirstUseOrNextSameShape (pns,pdn);
813 //=======================================================================
816 //=======================================================================
817 void TNaming_Builder::Select (const TopoDS_Shape& S,
818 const TopoDS_Shape& InS)
820 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_SELECTED;
822 if (myAtt->myEvolution != TNaming_SELECTED)
823 Standard_ConstructionError::Raise("TNaming_Builder : not same evolution");
826 TNaming_RefShape* pos;
827 if (!myShapes->myMap.IsBound(InS)) {
828 pos = new TNaming_RefShape(InS);
829 myShapes->myMap.Bind(InS,pos);
832 pos = myShapes->myMap.ChangeFind(InS);
834 TNaming_RefShape* pns;
835 if (!myShapes->myMap.IsBound(S)) {
836 pns = new TNaming_RefShape(S);
837 myShapes->myMap.Bind(S,pns);
840 pns = myShapes->myMap.ChangeFind(S);
842 TNaming_Node* pdn = new TNaming_Node(pos,pns);
844 UpdateFirstUseOrNextSameShape (pos,pdn);
845 UpdateFirstUseOrNextSameShape (pns,pdn);
848 //**********************************************************************
849 //Methods of the TNaming_Iterator class
850 //**********************************************************************
852 //=======================================================================
853 //function : TNaming_Iterator
855 //=======================================================================
857 TNaming_Iterator::TNaming_Iterator(const Handle(TNaming_NamedShape)& Att)
860 myNode = Att->myNode;
863 //=======================================================================
864 //function : TNaming_Iterator
866 //=======================================================================
868 TNaming_Iterator::TNaming_Iterator(const TDF_Label& Lab)
871 Handle(TNaming_NamedShape) Att;
872 if (Lab.FindAttribute(TNaming_NamedShape::GetID(),Att)) {
873 myNode = Att->myNode;
880 //=====================================================================
881 //function : TNaming_Iterator
883 //=======================================================================
885 TNaming_Iterator::TNaming_Iterator(const TDF_Label& Lab,
886 const Standard_Integer Trans)
889 Handle(TNaming_NamedShape) Att;
890 if (Lab.FindAttribute(TNaming_NamedShape::GetID(),Trans,Att)) {
891 myNode = Att->myNode;
896 cout <<"TNaming_Iterator : No Shape for this label"<<endl;
901 //=======================================================================
904 //=======================================================================
906 void TNaming_Iterator::Next()
908 Standard_NoMoreObject_Raise_if(myNode == 0L,
909 "TNaming_Iterator::Next");
910 myNode = myNode->nextSameAttribute;
913 //=======================================================================
914 //function : OldShape
916 //=======================================================================
918 const TopoDS_Shape& TNaming_Iterator::OldShape() const
920 Standard_NoSuchObject_Raise_if(myNode == 0L,
921 "TNaming_Iterator::OldShape");
922 if (myNode->myOld == 0L) {
923 static TopoDS_Shape NullShape;
926 return myNode->myOld->Shape();
929 //=======================================================================
930 //function : NewShape
932 //=======================================================================
934 const TopoDS_Shape& TNaming_Iterator::NewShape() const
936 Standard_NoSuchObject_Raise_if(myNode == 0L,
937 "TNaming_Iterator::NewShape");
938 if (myNode->myNew == 0L) {
939 static TopoDS_Shape NullShape;
942 return myNode->myNew->Shape();
946 //=======================================================================
947 //function : IsModification
949 //=======================================================================
951 Standard_Boolean TNaming_Iterator::IsModification() const
953 Standard_NoSuchObject_Raise_if(myNode == 0L,
954 "TNaming_Iterator::IsModification");
955 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
956 myNode->myAtt->myEvolution == TNaming_DELETE );
959 //=======================================================================
960 //function : Evolution
962 //=======================================================================
964 TNaming_Evolution TNaming_Iterator::Evolution() const
966 Standard_NoSuchObject_Raise_if(myNode == 0L,
967 "TNaming_Iterator::IsModification");
968 return myNode->myAtt->myEvolution;
973 //**********************************************************************
974 //Methods of the TNaming_NewShapeIterator class
975 //**********************************************************************
977 //=======================================================================
978 //function : SelectSameShape
979 //purpose : Selectionne le prochain noeud ou le shape est le meme que celui
980 // de RS. Old = 0 si il doit etre new dans le noeud a chercher.
981 // selection dans la transaction valide.
982 // On saute aussi les noeud ou OS = NS;
983 //=======================================================================
985 static void SelectSameShape (TNaming_Node*& myNode,
986 Standard_Boolean Old,
987 TNaming_RefShape*& RS,
988 const Standard_Integer& Trans)
990 TNaming_Node* pdn = myNode;
993 Standard_Boolean Valid;
994 if (Trans < 0) Valid = pdn->myAtt->IsValid();
995 else Valid = pdn->IsValidInTrans(Trans);
1000 if( pdn->myOld == RS && pdn->myNew != 0L && pdn->myNew != RS) {
1005 if( pdn->myNew == RS && pdn->myOld != 0L && pdn->myOld != RS) {
1010 pdn = pdn->NextSameShape(RS);
1015 //=======================================================================
1016 //function : TNaming_NewShapeIterator
1018 //=======================================================================
1020 TNaming_NewShapeIterator::TNaming_NewShapeIterator
1021 (const TopoDS_Shape& aShape,
1022 const Standard_Integer Trans,
1023 const Handle(TNaming_UsedShapes)& Shapes)
1026 Standard_Boolean Old = Standard_True;
1027 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1028 myNode = RS->FirstUse();
1029 SelectSameShape(myNode,Old,RS,myTrans);
1032 //=======================================================================
1033 //function : TNaming_NewShapeIterator
1035 //=======================================================================
1037 TNaming_NewShapeIterator::TNaming_NewShapeIterator
1038 (const TopoDS_Shape& aShape,
1039 const Standard_Integer Trans,
1040 const TDF_Label& access)
1043 Handle(TNaming_UsedShapes) Shapes;
1044 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1045 Standard_Boolean Old = Standard_True;
1046 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1047 myNode = RS->FirstUse();
1048 SelectSameShape(myNode,Old,RS,myTrans);
1052 //=======================================================================
1053 //function : TNaming_NewShapeIterator
1055 //=======================================================================
1057 TNaming_NewShapeIterator::TNaming_NewShapeIterator (const TNaming_Iterator& anIterator)
1058 :myTrans(anIterator.myTrans)
1060 Standard_Boolean Old = Standard_True;
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 SelectSameShape(myNode,Old,RS,myTrans);
1072 //=======================================================================
1073 //function : TNaming_NewShapeIterator
1075 //=======================================================================
1077 TNaming_NewShapeIterator::TNaming_NewShapeIterator
1078 (const TopoDS_Shape& aShape,
1079 const Handle(TNaming_UsedShapes)& Shapes)
1082 Standard_Boolean Old = Standard_True;
1083 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1084 myNode = RS->FirstUse();
1085 SelectSameShape(myNode,Old,RS,myTrans);
1088 //=======================================================================
1089 //function : TNaming_NewShapeIterator
1091 //=======================================================================
1093 TNaming_NewShapeIterator::TNaming_NewShapeIterator
1094 (const TopoDS_Shape& aShape,
1095 const TDF_Label& access)
1098 Handle(TNaming_UsedShapes) Shapes;
1099 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1100 Standard_Boolean Old = Standard_True;
1101 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1102 myNode = RS->FirstUse();
1103 SelectSameShape(myNode,Old,RS,myTrans);
1107 //=======================================================================
1108 //function : TNaming_NewShapeIterator
1110 //=======================================================================
1112 TNaming_NewShapeIterator::TNaming_NewShapeIterator(const TNaming_NewShapeIterator& anIterator)
1113 :myTrans(anIterator.myTrans)
1115 Standard_Boolean Old = Standard_True;
1116 myNode = anIterator.myNode;
1117 TNaming_RefShape* RS = myNode->myNew;
1119 myNode = 0L; // No descendant
1121 // il faut repartir de la premiere utilisation.
1122 myNode = RS->FirstUse();
1123 SelectSameShape(myNode,Old,RS,myTrans);
1127 //=======================================================================
1130 //=======================================================================
1132 void TNaming_NewShapeIterator::Next()
1134 Standard_Boolean Old = Standard_True;
1135 TNaming_RefShape* RS = myNode->myOld;
1136 myNode = myNode->NextSameShape(RS);
1137 SelectSameShape(myNode,Old,RS,myTrans);
1140 //=======================================================================
1143 //=======================================================================
1145 TDF_Label TNaming_NewShapeIterator::Label() const
1147 Standard_NoSuchObject_Raise_if(myNode == 0L,
1148 "TNaming_NewShapeIterator::Label");
1149 return myNode->Label();
1152 //=======================================================================
1153 //function : NamedShape
1155 //=======================================================================
1157 Handle(TNaming_NamedShape) TNaming_NewShapeIterator::NamedShape() const
1159 Standard_NoSuchObject_Raise_if(myNode == 0L,
1160 "TNaming_NewShapeIterator::Label");
1161 return myNode->myAtt;
1164 //=======================================================================
1167 //=======================================================================
1169 const TopoDS_Shape& TNaming_NewShapeIterator::Shape() const
1171 Standard_NoSuchObject_Raise_if(myNode == 0L,
1172 "TNaming_NewShapeIterator::Shape");
1173 return myNode->myNew->Shape();
1176 //=======================================================================
1177 //function : IsModification
1179 //=======================================================================
1181 Standard_Boolean TNaming_NewShapeIterator::IsModification() const
1183 Standard_NoSuchObject_Raise_if(myNode == 0L,
1184 "TNaming_NewShapeIterator::IsModification");
1186 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
1187 myNode->myAtt->myEvolution == TNaming_DELETE );
1190 //**********************************************************************
1191 //Methods of the TNaming_OldShapeIterator class
1192 //**********************************************************************
1193 //=======================================================================
1194 //function : TNaming_OldShapeIterator
1196 //=======================================================================
1198 TNaming_OldShapeIterator::TNaming_OldShapeIterator
1199 (const TopoDS_Shape& aShape,
1200 const Standard_Integer Trans,
1201 const Handle(TNaming_UsedShapes)& Shapes)
1204 Standard_Boolean Old = Standard_False;
1205 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1206 myNode = RS->FirstUse();
1207 SelectSameShape(myNode,Old,RS,myTrans);
1210 //=======================================================================
1211 //function : TNaming_OldShapeIterator
1213 //=======================================================================
1215 TNaming_OldShapeIterator::TNaming_OldShapeIterator
1216 (const TopoDS_Shape& aShape,
1217 const Standard_Integer Trans,
1218 const TDF_Label& access)
1221 Handle(TNaming_UsedShapes) Shapes;
1222 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1223 Standard_Boolean Old = Standard_False;
1224 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1225 myNode = RS->FirstUse();
1226 SelectSameShape(myNode,Old,RS,myTrans);
1229 //=======================================================================
1230 //function : TNaming_OldShapeIterator
1232 //=======================================================================
1234 TNaming_OldShapeIterator::TNaming_OldShapeIterator
1235 (const TopoDS_Shape& aShape,
1236 const Handle(TNaming_UsedShapes)& Shapes)
1239 Standard_Boolean Old = Standard_False;
1240 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1241 myNode = RS->FirstUse();
1242 SelectSameShape(myNode,Old,RS,myTrans);
1245 //=======================================================================
1246 //function : TNaming_OldShapeIterator
1248 //=======================================================================
1250 TNaming_OldShapeIterator::TNaming_OldShapeIterator
1251 (const TopoDS_Shape& aShape,
1252 const TDF_Label& access)
1255 Handle(TNaming_UsedShapes) Shapes;
1256 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1257 Standard_Boolean Old = Standard_False;
1258 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1259 myNode = RS->FirstUse();
1260 SelectSameShape(myNode,Old,RS,myTrans);
1264 //=======================================================================
1265 //function : TNaming_OldShapeIterator
1267 //=======================================================================
1269 TNaming_OldShapeIterator::TNaming_OldShapeIterator (const TNaming_Iterator& anIterator)
1270 :myTrans(anIterator.myTrans)
1272 Standard_Boolean Old = Standard_False;
1273 myNode = anIterator.myNode;
1274 TNaming_RefShape* RS = myNode->myNew;
1276 myNode = 0L; // No descendant
1278 // il faut repartir de la premiere utilisation.
1279 myNode = RS->FirstUse();
1280 SelectSameShape(myNode,Old,RS,myTrans);
1284 //=======================================================================
1285 //function : TNaming_OldShapeIterator
1287 //=======================================================================
1289 TNaming_OldShapeIterator::TNaming_OldShapeIterator(const TNaming_OldShapeIterator& anIterator)
1290 :myTrans(anIterator.myTrans)
1292 Standard_Boolean Old = Standard_False;
1293 myNode = anIterator.myNode;
1294 TNaming_RefShape* RS = myNode->myOld;
1296 myNode = 0L; // No descendant
1298 // il faut repartir de la premiere utilisation.
1299 myNode = RS->FirstUse();
1300 SelectSameShape(myNode,Old,RS,myTrans);
1304 //=======================================================================
1307 //=======================================================================
1309 void TNaming_OldShapeIterator::Next()
1311 Standard_Boolean Old = Standard_False;
1312 TNaming_RefShape* RS = myNode->myNew;
1313 myNode = myNode->NextSameShape(RS);
1314 SelectSameShape(myNode,Old,RS,myTrans);
1317 //=======================================================================
1320 //=======================================================================
1322 TDF_Label TNaming_OldShapeIterator::Label() const
1324 if (myNode == 0L) Standard_NoSuchObject::Raise("TNaming_OldShapeIterator::Label");
1325 return myNode->Label();
1329 //=======================================================================
1330 //function : NamedShape
1332 //=======================================================================
1334 Handle(TNaming_NamedShape) TNaming_OldShapeIterator::NamedShape() const
1336 if (myNode == 0L) Standard_NoSuchObject::Raise("TNaming_OldShapeIterator::Label");
1337 return myNode->myAtt;
1339 //=======================================================================
1342 //=======================================================================
1344 const TopoDS_Shape& TNaming_OldShapeIterator::Shape() const
1346 if(myNode == 0L) Standard_NoSuchObject::Raise("TNaming_OldShapeIterator::Shape");
1347 return myNode->myOld->Shape();
1350 //=======================================================================
1351 //function : IsModification
1353 //=======================================================================
1355 Standard_Boolean TNaming_OldShapeIterator::IsModification() const
1357 Standard_NoSuchObject_Raise_if(myNode == 0L,
1358 "TNaming_OldShapeIterator::IsModification");
1359 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
1360 myNode->myAtt->myEvolution == TNaming_DELETE );
1364 //**********************************************************************
1365 //Methods of the SameShapeIterator
1366 //**********************************************************************
1368 //=======================================================================
1371 //=======================================================================
1373 TNaming_SameShapeIterator::TNaming_SameShapeIterator
1374 (const TopoDS_Shape& aShape,
1375 const Handle(TNaming_UsedShapes)& Shapes)
1377 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1378 myNode = RS->FirstUse();
1379 myIsNew = (myNode->myNew == RS);
1383 //=======================================================================
1384 //function : TNaming_SameShapeIterator
1386 //=======================================================================
1388 TNaming_SameShapeIterator::TNaming_SameShapeIterator
1389 (const TopoDS_Shape& aShape,
1390 const TDF_Label& access)
1392 Handle(TNaming_UsedShapes) Shapes;
1393 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1394 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1395 myNode = RS->FirstUse();
1396 myIsNew = (myNode->myNew == RS);
1400 //=======================================================================
1403 //=======================================================================
1405 void TNaming_SameShapeIterator::Next()
1407 TNaming_RefShape* prs;
1408 if (myIsNew) prs = myNode->myNew; else prs = myNode->myOld;
1410 myNode = myNode->NextSameShape(prs);
1411 if (myNode != 0L) myIsNew = (myNode->myNew == prs);
1414 //=======================================================================
1417 //=======================================================================
1419 TDF_Label TNaming_SameShapeIterator::Label() const
1421 Standard_NoSuchObject_Raise_if(myNode == 0L,
1422 "TNaming_SameShapeIterator::Label");
1423 return myNode->Label();
1427 //**********************************************************************
1428 //Methods of the TNaming_RefShape
1429 //**********************************************************************
1430 //=======================================================================
1433 //=======================================================================
1435 TDF_Label TNaming_RefShape::Label() const
1437 return myFirstUse->myAtt->Label();
1440 //=======================================================================
1441 //function : NamedShape
1443 //=======================================================================
1445 Handle(TNaming_NamedShape) TNaming_RefShape::NamedShape() const
1447 return myFirstUse->myAtt;
1451 //**********************************************************************
1452 //Methods of the TNaming_Tool class
1453 //**********************************************************************
1455 //=======================================================================
1456 //function : HasLabel
1458 //=======================================================================
1460 Standard_Boolean TNaming_Tool::HasLabel (const TDF_Label& access,
1461 const TopoDS_Shape& S)
1463 Handle(TNaming_UsedShapes) US;
1464 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US)) {
1465 return (US->Map().IsBound(S));
1467 #ifdef MDTV_DEB_HASL
1468 cout << "##==> Sub-Shape has no Label!" <<endl;
1470 return Standard_False;
1474 //=======================================================================
1477 //=======================================================================
1479 TDF_Label TNaming_Tool::Label(const TDF_Label& access,
1480 const TopoDS_Shape& S,
1481 Standard_Integer& Trans)
1483 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(access,S),"TNaming_Tool::Label");
1484 Handle(TNaming_UsedShapes) US;
1485 access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1486 return TNaming_Tool::Label(US,S,Trans);
1490 //=======================================================================
1491 //function : IsValidInTrans
1492 //purpose : un shape est valid tant que l attribut ou il est cree est valid
1493 //=======================================================================
1495 Standard_Integer TNaming_Tool::ValidUntil (const TDF_Label& access, const TopoDS_Shape& S)
1497 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(access,S),"TNaming_Tool::ValidUntil");
1498 Handle(TNaming_UsedShapes) US;
1499 access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1500 return TNaming_Tool::ValidUntil(S,US);
1504 //=======================================================================
1505 //function : HasLabel
1507 //=======================================================================
1509 Standard_Boolean TNaming_Tool::HasLabel(const Handle(TNaming_UsedShapes)& Shapes,
1510 const TopoDS_Shape& S)
1512 return (Shapes->Map().IsBound(S));
1516 //=======================================================================
1519 //=======================================================================
1521 TDF_Label TNaming_Tool::Label(const Handle(TNaming_UsedShapes)& Shapes,
1522 const TopoDS_Shape& S,
1523 Standard_Integer& Trans)
1525 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(Shapes,S),"TNaming_Tool::Label");
1526 TNaming_RefShape* prs = Shapes->Map().Find(S);
1527 TNaming_Node* pdn = prs->FirstUse();
1529 while (pdn != 0L && !(pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED)){
1530 pdn = pdn->NextSameShape(prs);
1532 if (pdn == 0L) pdn = prs->FirstUse();
1534 TDF_Label L = pdn->Label();
1535 Trans = pdn->myAtt->Transaction();
1538 //=======================================================================
1539 //function : NamedShape
1541 //=======================================================================
1542 Handle(TNaming_NamedShape) TNaming_Tool::NamedShape(const TopoDS_Shape& S,
1543 const TDF_Label& Acces)
1545 Handle(TNaming_UsedShapes) US;
1546 Acces.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1547 Handle(TNaming_NamedShape) NS;
1549 if(!TNaming_Tool::HasLabel(US,S)) {
1553 TNaming_RefShape* prs = US->Map().Find(S);
1554 TNaming_Node* pdn = prs->FirstUse();
1555 TNaming_Node* res = 0L;
1558 if (pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED) {
1560 if (pdn->myAtt->Evolution() != TNaming_GENERATED) {
1561 // Les modifications sont privilegiees par rapport au generation.
1562 // Dans le cas des shapes qui sont a la fois des modifications et des generations
1567 pdn = pdn->NextSameShape(prs);
1570 if (res == 0L) return NS;
1572 // VERUE EN ATTENDANT DE REVOIR ABORT 03/11/98
1573 // Protection pour eviter de renvoyer un attribut backuped
1574 TDF_Label Lab = res->Label();
1575 Lab.FindAttribute(TNaming_NamedShape::GetID(),NS);
1577 // return res->myAtt;
1580 //=======================================================================
1581 //function : IsValidInTrans
1582 //purpose : un shape est valid tant que l attribut ou il est cree est valid
1583 //=======================================================================
1585 Standard_Integer TNaming_Tool::ValidUntil (const TopoDS_Shape& S,
1586 const Handle(TNaming_UsedShapes)& US)
1588 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(US,S),"TNaming_Tool::ValidUntil");
1590 TNaming_RefShape* RS = US->Map().ChangeFind(S);
1591 Standard_Integer Cur;
1592 Standard_Integer Until = 0;
1593 TNaming_Node* Node = RS->FirstUse();
1595 while (Node != 0L) {
1596 if (Node->myNew != 0L && Node->myNew == RS) {
1597 Cur = Node->myAtt->UntilTransaction();
1598 if (Cur > Until) Until = Cur;
1600 Node = Node->NextSameShape(RS);