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 <TDF_Tool.hxx>
38 #include <TNaming_Builder.hxx>
39 #include <TNaming_CopyShape.hxx>
40 #include <TNaming_DeltaOnModification.hxx>
41 #include <TNaming_DeltaOnRemoval.hxx>
42 #include <TNaming_Iterator.hxx>
43 #include <TNaming_NamedShape.hxx>
44 #include <TNaming_NewShapeIterator.hxx>
45 #include <TNaming_OldShapeIterator.hxx>
46 #include <TNaming_PtrNode.hxx>
47 #include <TNaming_PtrRefShape.hxx>
48 #include <TNaming_RefShape.hxx>
49 #include <TNaming_SameShapeIterator.hxx>
50 #include <TNaming_Tool.hxx>
51 #include <TNaming_UsedShapes.hxx>
52 #include <TopoDS_Shape.hxx>
53 #include <TopoDS_Vertex.hxx>
55 IMPLEMENT_STANDARD_RTTIEXT(TNaming_NamedShape,TDF_Attribute)
57 // Defines the nodes classes
58 //#define MDTV_DEB_HASL
59 //=======================================================================
62 //=======================================================================
63 const Standard_GUID& TNaming_NamedShape::GetID()
65 static Standard_GUID TNaming_NamedShapeID("c4ef4200-568f-11d1-8940-080009dc3333");
66 return TNaming_NamedShapeID;
69 //=======================================================================
71 //=======================================================================
75 TNaming_Node(TNaming_PtrRefShape Old,
76 TNaming_PtrRefShape New)
77 : myOld(Old),myNew(New),
79 nextSameAttribute(0L), nextSameOld(0L),nextSameNew(0L)
82 //Label : Donne le Label
86 TNaming_Node* NextSameShape(TNaming_RefShape* prs);
88 // Test si l evolution est valide dans la transaction Trans
89 // ie : Trans n est pas anterieure a sa creation
90 // et Trans n est pas posterieure a son BackUp
91 Standard_Boolean IsValidInTrans(Standard_Integer Trans);
93 //! Dumps the content of me into the stream
94 Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
99 TNaming_PtrRefShape myOld;
100 TNaming_PtrRefShape myNew;
101 TNaming_NamedShape* myAtt;
102 TNaming_PtrNode nextSameAttribute;
103 TNaming_PtrNode nextSameOld;
104 TNaming_PtrNode nextSameNew;
107 //=======================================================================
108 //function : NextSameShape
110 //=======================================================================
112 TNaming_Node* TNaming_Node::NextSameShape(TNaming_RefShape* prs)
114 if (myOld == prs) return nextSameOld;
115 if (myNew == prs) return nextSameNew;
119 //=======================================================================
122 //=======================================================================
124 TDF_Label TNaming_Node::Label()
126 return myAtt->Label();
129 //=======================================================================
130 //function : IsValidInTrans
132 //=======================================================================
134 Standard_Boolean TNaming_Node::IsValidInTrans(Standard_Integer Trans)
136 if (myAtt->Transaction() <= Trans && Trans <= myAtt->UntilTransaction()) {
142 //=======================================================================
143 //function : DumpJson
145 //=======================================================================
146 void TNaming_Node::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
148 OCCT_DUMP_CLASS_BEGIN (theOStream, TNaming_Node)
150 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myOld)
151 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myNew)
152 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myAtt)
154 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, nextSameAttribute)
155 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, nextSameOld)
156 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, nextSameNew)
159 //**********************************************************************
160 // Methods of TNaming_NamedShape
161 //**********************************************************************
163 //=======================================================================
164 //function : TNaming_NamedShape
166 //=======================================================================
168 TNaming_NamedShape::TNaming_NamedShape()
172 myEvolution = TNaming_PRIMITIVE;
175 //=======================================================================
178 //=======================================================================
180 Standard_Boolean TNaming_NamedShape::IsEmpty () const
182 TNaming_Iterator it (this);
187 //=======================================================================
190 //=======================================================================
192 TopoDS_Shape TNaming_NamedShape::Get () const
194 return TNaming_Tool::GetShape (this);
200 //=======================================================================
201 //function : RemoveNode
203 //=======================================================================
205 static void RemoveNode(Standard_Boolean MapExist ,
206 TNaming_DataMapOfShapePtrRefShape& M,
209 TNaming_RefShape* pos = N->myOld;
211 if (pos->FirstUse() == N) {
212 TNaming_Node* nextOld = N->nextSameOld;
214 pos->FirstUse(nextOld);
216 // le shape disparait
218 M.UnBind(pos->Shape());
228 TNaming_Node* pdn = pos->FirstUse();
231 if (pdn->NextSameShape(pos) == N) {
232 if (pdn->myOld == pos) pdn->nextSameOld = N->nextSameOld;
233 else pdn->nextSameNew = N->nextSameOld;
236 pdn = pdn->NextSameShape(pos);
241 TNaming_RefShape* pns = N->myNew;
243 if (pns->FirstUse() == N) {
244 TNaming_Node* nextNew = N->nextSameNew;
246 pns->FirstUse(nextNew);
249 // le shape disparait
251 M.UnBind(pns->Shape());
262 TNaming_Node* pdn = pns->FirstUse();
264 if (pdn->NextSameShape(pns) == N) {
265 if (pdn->myOld == pns) pdn->nextSameOld = N->nextSameNew;
266 else pdn->nextSameNew = N->nextSameNew;
269 pdn = pdn->NextSameShape(pns);
275 //=======================================================================
278 //=======================================================================
280 void TNaming_NamedShape::Clear()
282 if (Label().IsNull()) {
283 #ifdef OCCT_DEBUG_BUILDER
284 std::cout << "attention etat fantomatique" << std::endl;
289 Handle(TNaming_UsedShapes) US;
291 TNaming_DataMapOfShapePtrRefShape* M=NULL;
293 // Recuperation de la map si celle-ci n est pas deja detruite.
294 //Standard_Boolean MapExist = Ins.FindInRoot(TNaming_UsedShapes::GetID(),US);
296 Standard_Boolean MapExist = Label().Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
297 if (MapExist) M = &(US->Map());
299 TNaming_Node* p = myNode;
301 RemoveNode (MapExist,*M,p);
302 p = p->nextSameAttribute;
309 p = p->nextSameAttribute;
320 //=======================================================================
321 //function : BeforeRemoval
323 //=======================================================================
325 void TNaming_NamedShape::BeforeRemoval()
331 //=======================================================================
332 //function : BeforeUndo
333 //purpose : before application of a TDF_Delta.
334 //=======================================================================
336 Standard_Boolean TNaming_NamedShape::BeforeUndo
337 (const Handle(TDF_AttributeDelta)& /*anAttDelta*/,
338 const Standard_Boolean /*forceIt*/)
340 // if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) {
341 // anAttDelta->Attribute()->BeforeRemoval();
343 return Standard_True;
346 //=======================================================================
347 //function : AfterUndo
348 //purpose : After application of a TDF_Delta.
349 //=======================================================================
351 Standard_Boolean TNaming_NamedShape::AfterUndo
352 (const Handle(TDF_AttributeDelta)& anAttDelta,
353 const Standard_Boolean /*forceIt*/)
355 if (anAttDelta->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) {
356 Handle(TNaming_UsedShapes) US;
358 TNaming_DataMapOfShapePtrRefShape* M=NULL;
360 // Recuperation de la map si celle-ci n est pas deja detruite.
361 //Standard_Boolean MapExist = Ins.FindInRoot(TNaming_UsedShapes::GetID(),US);
363 Standard_Boolean MapExist = anAttDelta->Label().Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
365 if (MapExist) M = &(US->Map());
367 TNaming_Node* p = myNode;
369 RemoveNode (MapExist,*M,p);
370 p = p->nextSameAttribute;
377 p = p->nextSameAttribute;
387 return Standard_True;
391 //=======================================================================
392 //function : BackupCopy
394 //=======================================================================
396 Handle(TDF_Attribute) TNaming_NamedShape::BackupCopy() const
398 // Remarque dans le copy il est important de reporter le noeud de l attribut
399 // pour ne pas casser le chemin nextSameShape.
401 Handle(TNaming_NamedShape) Cop = new TNaming_NamedShape();
402 Cop->myNode = myNode;
403 Cop->myEvolution = myEvolution;
404 Cop->myVersion = myVersion;
406 // Mise a jour de myAtt sur les noeuds dans l attribut.
407 TNaming_Node* CN = Cop->myNode;
409 Handle(TNaming_NamedShape) A = this;
413 CN->myAtt = Cop.operator->();
414 CN = CN->nextSameAttribute;
420 //=======================================================================
423 //=======================================================================
425 void TNaming_NamedShape::Restore(const Handle(TDF_Attribute)& anAttribute)
429 TNaming_NamedShape* PAtt = (TNaming_NamedShape*)anAttribute.operator->();
430 myNode = PAtt->myNode;
431 myEvolution = PAtt->myEvolution;
432 myVersion = PAtt->myVersion;
434 // Mise a jour de myAtt sur les noeuds dans l attribut.
435 TNaming_Node* CN = myNode;
438 CN = CN->nextSameAttribute;
440 PAtt->myNode = 0L; //un noeud est dans un seul attribut.
444 //=======================================================================
445 //function : DeltaOnModification
447 //=======================================================================
449 Handle(TDF_DeltaOnModification) TNaming_NamedShape::DeltaOnModification
450 (const Handle(TDF_Attribute)& anOldAttribute) const
453 return new TNaming_DeltaOnModification(Handle(TNaming_NamedShape)::DownCast (anOldAttribute));
456 //=======================================================================
457 //function : DeltaOnModification
459 //=======================================================================
461 void TNaming_NamedShape::DeltaOnModification(const Handle(TDF_DeltaOnModification)& aDelta)
466 //=======================================================================
467 //function : DeltaOnRemoval
469 //=======================================================================
471 Handle(TDF_DeltaOnRemoval) TNaming_NamedShape::DeltaOnRemoval() const
473 return new TNaming_DeltaOnRemoval(this);
476 //=======================================================================
477 //function : NewEmpty
479 //=======================================================================
481 Handle(TDF_Attribute) TNaming_NamedShape::NewEmpty () const
483 return new TNaming_NamedShape();
486 //=======================================================================
489 //=======================================================================
491 void TNaming_NamedShape::Paste(const Handle(TDF_Attribute)& into,
492 const Handle(TDF_RelocationTable)& Tab)
495 TDF_Label Lab = into->Label();
497 throw Standard_NullObject("TNaming_NamedShape::Paste");
499 TNaming_Builder B(Lab);
501 TNaming_Iterator It (this);
502 for ( ;It.More() ; It.Next()) {
503 const TopoDS_Shape& OS = It.OldShape();
504 const TopoDS_Shape& NS = It.NewShape();
505 TNaming_Evolution aStatus = It.Evolution();
507 // Modification_1 24.06.99 (szy)
508 TopoDS_Shape copOS, copNS;
509 if(aStatus != TNaming_PRIMITIVE)
510 TNaming_CopyShape::CopyTool(OS, Tab->TransientTable(), copOS);
511 else copOS.Nullify();
512 if(aStatus != TNaming_DELETE )
513 TNaming_CopyShape::CopyTool(NS, Tab->TransientTable(), copNS);
514 else copNS.Nullify();
517 case TNaming_PRIMITIVE :
522 case TNaming_GENERATED :
524 B.Generated(copOS, copNS);
527 case TNaming_MODIFY :
529 B.Modify(copOS, copNS);
532 case TNaming_DELETE :
537 case TNaming_SELECTED :
539 B.Select(copNS,copOS);
549 //=======================================================================
550 //function : References
552 //=======================================================================
554 void TNaming_NamedShape::References(const Handle(TDF_DataSet)& aDataSet) const
556 // Recherche des dependances.
557 // Pour chaque OldShape de l attribut on ajoute au dataSet son label d origine.
558 TNaming_Node* Current = myNode;
559 while (Current != NULL) {
560 if (Current->myOld != NULL) {
561 TNaming_RefShape* prs = Current->myOld;
562 TNaming_Node* pdn = prs->FirstUse();
564 while (pdn != NULL) {
565 if (pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED) {
566 aDataSet->AddLabel(pdn->Label());
568 pdn = pdn->NextSameShape(prs);
571 Current = Current->nextSameAttribute;
576 //=======================================================================
579 //=======================================================================
581 void TNaming_NamedShape::Add(TNaming_Node*& pdn )
585 pdn->nextSameAttribute = myNode;
590 //=======================================================================
593 //=======================================================================
595 Standard_OStream& TNaming_NamedShape::Dump(Standard_OStream& anOS) const
600 //***************************************
601 // Fin Class Named_Shape.
602 //***************************************
605 //**********************************************************************
606 // Methods of the TNaming_Builder class
607 //**********************************************************************
609 ///=======================================================================
610 //function : TNaming_Builder
612 //=======================================================================
614 TNaming_Builder::TNaming_Builder (const TDF_Label& L)
616 // Find or Build Map;
617 const TDF_Label& root = L.Root();
618 if (!root.FindAttribute(TNaming_UsedShapes::GetID(),myShapes)) {
619 myShapes = new TNaming_UsedShapes();
620 root.AddAttribute (myShapes);
623 //Find Or Build Attribute in LIns.
624 if (!L.FindAttribute(TNaming_NamedShape::GetID(),myAtt)) {
625 myAtt = new TNaming_NamedShape();
626 L.AddAttribute(myAtt);
635 //=======================================================================
636 //function : TNaming_Builder
638 //=======================================================================
640 Handle(TNaming_NamedShape) TNaming_Builder::NamedShape() const
645 //=======================================================================
646 //function : UpdateNextSameShape
648 //=======================================================================
650 static void UpdateFirstUseOrNextSameShape(TNaming_RefShape*& prs,
653 TNaming_Node* ldn = prs->FirstUse();
658 TNaming_Node* cdn = ldn;
661 cdn = cdn->NextSameShape(prs);
663 throw Standard_ConstructionError("UpdateFirstUseOrNextSameShape");
667 // boucle interdite et inutile.
669 if (ldn->myOld == prs) ldn->nextSameOld = pdn;
670 if (ldn->myNew == prs) ldn->nextSameNew = pdn;
675 //=======================================================================
676 //function : Generate
678 //=======================================================================
680 void TNaming_Builder::Generated(const TopoDS_Shape& newShape)
682 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_PRIMITIVE;
684 if (myAtt->myEvolution != TNaming_PRIMITIVE)
685 throw Standard_ConstructionError("TNaming_Builder : not same evolution");
688 TNaming_RefShape* pos = 0L;
689 TNaming_RefShape* pns;
691 if (myShapes->myMap.IsBound(newShape)) {
692 #ifdef OCCT_DEBUG_BUILDER
693 std::cout <<"TNaming_Builder::Generate : the shape is already in the attribute"<<std::endl;
695 pns = myShapes->myMap.ChangeFind(newShape);
696 if (pns->FirstUse()->myAtt == myAtt.operator->()) {
697 throw Standard_ConstructionError("TNaming_Builder::Generate");
699 TNaming_Node* pdn = new TNaming_Node(pos,pns);
701 UpdateFirstUseOrNextSameShape (pns,pdn);
704 pns = new TNaming_RefShape(newShape);
705 TNaming_Node* pdn = new TNaming_Node(pos,pns);
707 myShapes->myMap.Bind (newShape , pns);
714 //=======================================================================
717 //=======================================================================
719 void TNaming_Builder::Delete(const TopoDS_Shape& oldShape)
721 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_DELETE;
723 if (myAtt->myEvolution != TNaming_DELETE)
724 throw Standard_ConstructionError("TNaming_Builder : not same evolution");
727 TNaming_RefShape* pns;
728 TNaming_RefShape* pos;
730 if (myShapes->myMap.IsBound(oldShape))
731 pos = myShapes->myMap.ChangeFind(oldShape);
733 #ifdef OCCT_DEBUG_BUILDER
734 std::cout <<"TNaming_Builder::Delete : the shape is not in the data"<<std::endl;
736 pos = new TNaming_RefShape(oldShape);
737 myShapes->myMap.Bind(oldShape, pos);
740 TopoDS_Shape nullShape;
741 pns = new TNaming_RefShape(nullShape);
742 myShapes->myMap.Bind(nullShape, pns);
744 TNaming_Node* pdn = new TNaming_Node(pos,pns);
746 UpdateFirstUseOrNextSameShape (pos,pdn);
747 UpdateFirstUseOrNextSameShape (pns,pdn);
750 //=======================================================================
751 //function : Generate
753 //=======================================================================
755 void TNaming_Builder::Generated(const TopoDS_Shape& oldShape,
756 const TopoDS_Shape& newShape)
758 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_GENERATED;
760 if (myAtt->myEvolution != TNaming_GENERATED)
761 throw Standard_ConstructionError("TNaming_Builder : not same evolution");
764 if (oldShape.IsSame(newShape)) {
765 #ifdef OCCT_DEBUG_BUILDER
766 std::cout <<"TNaming_Builder::Generate : oldShape IsSame newShape"<<std::endl;
770 TNaming_RefShape* pos;
771 if (!myShapes->myMap.IsBound(oldShape)) {
772 pos = new TNaming_RefShape(oldShape);
773 myShapes->myMap.Bind(oldShape,pos);
776 pos = myShapes->myMap.ChangeFind(oldShape);
778 TNaming_RefShape* pns;
779 if (!myShapes->myMap.IsBound(newShape)) {
780 pns = new TNaming_RefShape(newShape);
781 myShapes->myMap.Bind(newShape,pns);
784 pns = myShapes->myMap.ChangeFind(newShape);
786 TNaming_Node* pdn = new TNaming_Node(pos,pns);
788 UpdateFirstUseOrNextSameShape (pos,pdn);
789 UpdateFirstUseOrNextSameShape (pns,pdn);
793 //=======================================================================
796 //=======================================================================
798 void TNaming_Builder::Modify(const TopoDS_Shape& oldShape,
799 const TopoDS_Shape& newShape)
801 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_MODIFY;
803 if (myAtt->myEvolution != TNaming_MODIFY)
804 throw Standard_ConstructionError("TNaming_Builder : not same evolution");
807 if (oldShape.IsSame(newShape)) {
808 #ifdef OCCT_DEBUG_BUILDER
809 std::cout <<"TNaming_Builder::Modify : oldShape IsSame newShape"<<std::endl;
813 TNaming_RefShape* pos;
814 if (!myShapes->myMap.IsBound(oldShape)) {
815 pos = new TNaming_RefShape(oldShape);
816 myShapes->myMap.Bind(oldShape,pos);
819 pos = myShapes->myMap.ChangeFind(oldShape);
821 TNaming_RefShape* pns;
822 if (!myShapes->myMap.IsBound(newShape)) {
823 pns = new TNaming_RefShape(newShape);
824 myShapes->myMap.Bind(newShape,pns);
827 pns = myShapes->myMap.ChangeFind(newShape);
829 TNaming_Node* pdn = new TNaming_Node(pos,pns);
831 UpdateFirstUseOrNextSameShape (pos,pdn);
832 UpdateFirstUseOrNextSameShape (pns,pdn);
836 //=======================================================================
839 //=======================================================================
840 void TNaming_Builder::Select (const TopoDS_Shape& S,
841 const TopoDS_Shape& InS)
843 if (myAtt->myNode == 0L) myAtt->myEvolution = TNaming_SELECTED;
845 if (myAtt->myEvolution != TNaming_SELECTED)
846 throw Standard_ConstructionError("TNaming_Builder : not same evolution");
849 TNaming_RefShape* pos;
850 if (!myShapes->myMap.IsBound(InS)) {
851 pos = new TNaming_RefShape(InS);
852 myShapes->myMap.Bind(InS,pos);
855 pos = myShapes->myMap.ChangeFind(InS);
857 TNaming_RefShape* pns;
858 if (!myShapes->myMap.IsBound(S)) {
859 pns = new TNaming_RefShape(S);
860 myShapes->myMap.Bind(S,pns);
863 pns = myShapes->myMap.ChangeFind(S);
865 TNaming_Node* pdn = new TNaming_Node(pos,pns);
867 UpdateFirstUseOrNextSameShape (pos,pdn);
868 UpdateFirstUseOrNextSameShape (pns,pdn);
871 //**********************************************************************
872 //Methods of the TNaming_Iterator class
873 //**********************************************************************
875 //=======================================================================
876 //function : TNaming_Iterator
878 //=======================================================================
880 TNaming_Iterator::TNaming_Iterator(const Handle(TNaming_NamedShape)& Att)
883 myNode = Att->myNode;
886 //=======================================================================
887 //function : TNaming_Iterator
889 //=======================================================================
891 TNaming_Iterator::TNaming_Iterator(const TDF_Label& Lab)
894 Handle(TNaming_NamedShape) Att;
895 if (Lab.FindAttribute(TNaming_NamedShape::GetID(),Att)) {
896 myNode = Att->myNode;
903 //=====================================================================
904 //function : TNaming_Iterator
906 //=======================================================================
908 TNaming_Iterator::TNaming_Iterator(const TDF_Label& Lab,
909 const Standard_Integer Trans)
912 Handle(TDF_Attribute) Att;
913 if (Lab.FindAttribute(TNaming_NamedShape::GetID(),Trans,Att)) {
914 myNode = Handle(TNaming_NamedShape)::DownCast (Att)->myNode;
919 std::cout <<"TNaming_Iterator : No Shape for this label"<<std::endl;
924 //=======================================================================
927 //=======================================================================
929 void TNaming_Iterator::Next()
931 Standard_NoMoreObject_Raise_if(myNode == 0L,
932 "TNaming_Iterator::Next");
933 myNode = myNode->nextSameAttribute;
936 //=======================================================================
937 //function : OldShape
939 //=======================================================================
941 const TopoDS_Shape& TNaming_Iterator::OldShape() const
943 Standard_NoSuchObject_Raise_if(myNode == 0L,
944 "TNaming_Iterator::OldShape");
945 if (myNode->myOld == 0L) {
946 static TopoDS_Shape NullShape;
949 return myNode->myOld->Shape();
952 //=======================================================================
953 //function : NewShape
955 //=======================================================================
957 const TopoDS_Shape& TNaming_Iterator::NewShape() const
959 Standard_NoSuchObject_Raise_if(myNode == 0L,
960 "TNaming_Iterator::NewShape");
961 if (myNode->myNew == 0L) {
962 static TopoDS_Shape NullShape;
965 return myNode->myNew->Shape();
969 //=======================================================================
970 //function : IsModification
972 //=======================================================================
974 Standard_Boolean TNaming_Iterator::IsModification() const
976 Standard_NoSuchObject_Raise_if(myNode == 0L,
977 "TNaming_Iterator::IsModification");
978 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
979 myNode->myAtt->myEvolution == TNaming_DELETE );
982 //=======================================================================
983 //function : Evolution
985 //=======================================================================
987 TNaming_Evolution TNaming_Iterator::Evolution() const
989 Standard_NoSuchObject_Raise_if(myNode == 0L,
990 "TNaming_Iterator::IsModification");
991 return myNode->myAtt->myEvolution;
996 //**********************************************************************
997 //Methods of the TNaming_NewShapeIterator class
998 //**********************************************************************
1000 //=======================================================================
1001 //function : SelectSameShape
1002 //purpose : Selectionne le prochain noeud ou le shape est le meme que celui
1003 // de RS. Old = 0 si il doit etre new dans le noeud a chercher.
1004 // selection dans la transaction valide.
1005 // On saute aussi les noeud ou OS = NS;
1006 //=======================================================================
1008 static void SelectSameShape (TNaming_Node*& myNode,
1009 Standard_Boolean Old,
1010 TNaming_RefShape*& RS,
1011 const Standard_Integer& Trans)
1013 TNaming_Node* pdn = myNode;
1016 Standard_Boolean Valid;
1017 if (Trans < 0) Valid = pdn->myAtt->IsValid();
1018 else Valid = pdn->IsValidInTrans(Trans);
1023 if( pdn->myOld == RS && pdn->myNew != 0L && pdn->myNew != RS) {
1028 if( pdn->myNew == RS && pdn->myOld != 0L && pdn->myOld != RS) {
1033 pdn = pdn->NextSameShape(RS);
1038 //=======================================================================
1039 //function : TNaming_NewShapeIterator
1041 //=======================================================================
1043 TNaming_NewShapeIterator::TNaming_NewShapeIterator
1044 (const TopoDS_Shape& aShape,
1045 const Standard_Integer Trans,
1046 const Handle(TNaming_UsedShapes)& Shapes)
1049 Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape),
1050 "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");
1051 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1052 myNode = RS->FirstUse();
1053 Standard_Boolean Old(Standard_True);
1054 SelectSameShape(myNode,Old,RS,myTrans);
1057 //=======================================================================
1058 //function : TNaming_NewShapeIterator
1060 //=======================================================================
1062 TNaming_NewShapeIterator::TNaming_NewShapeIterator
1063 (const TopoDS_Shape& aShape,
1064 const Standard_Integer Trans,
1065 const TDF_Label& access)
1068 Handle(TNaming_UsedShapes) Shapes;
1069 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1070 Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape),
1071 "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");
1072 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1073 myNode = RS->FirstUse();
1074 Standard_Boolean Old(Standard_True);
1075 SelectSameShape(myNode,Old,RS,myTrans);
1079 //=======================================================================
1080 //function : TNaming_NewShapeIterator
1082 //=======================================================================
1084 TNaming_NewShapeIterator::TNaming_NewShapeIterator (const TNaming_Iterator& anIterator)
1085 :myTrans(anIterator.myTrans)
1087 Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
1088 "TNaming_NewShapeIterator::TNaming_NewShapeIterator");
1089 myNode = anIterator.myNode;
1090 TNaming_RefShape* RS = myNode->myNew;
1092 myNode = 0L; // No descendant
1094 // il faut repartir de la premiere utilisation.
1095 myNode = RS->FirstUse();
1096 Standard_Boolean Old(Standard_True);
1097 SelectSameShape(myNode,Old,RS,myTrans);
1101 //=======================================================================
1102 //function : TNaming_NewShapeIterator
1104 //=======================================================================
1106 TNaming_NewShapeIterator::TNaming_NewShapeIterator
1107 (const TopoDS_Shape& aShape,
1108 const Handle(TNaming_UsedShapes)& Shapes)
1111 Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape),
1112 "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");
1113 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1114 myNode = RS->FirstUse();
1115 Standard_Boolean Old(Standard_True);
1116 SelectSameShape(myNode,Old,RS,myTrans);
1119 //=======================================================================
1120 //function : TNaming_NewShapeIterator
1122 //=======================================================================
1124 TNaming_NewShapeIterator::TNaming_NewShapeIterator
1125 (const TopoDS_Shape& aShape,
1126 const TDF_Label& access)
1129 Handle(TNaming_UsedShapes) Shapes;
1130 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1131 Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape),
1132 "TNaming_NewShapeIterator::TNaming_NewShapeIterator aShape");
1133 Standard_Boolean Old(Standard_True);
1134 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1135 myNode = RS->FirstUse();
1136 SelectSameShape(myNode,Old,RS,myTrans);
1140 //=======================================================================
1141 //function : TNaming_NewShapeIterator
1143 //=======================================================================
1145 TNaming_NewShapeIterator::TNaming_NewShapeIterator(const TNaming_NewShapeIterator& anIterator)
1146 :myTrans(anIterator.myTrans)
1148 Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
1149 "TNaming_NewShapeIterator::TNaming_NewShapeIterator");
1150 myNode = anIterator.myNode;
1151 TNaming_RefShape* RS = myNode->myNew;
1153 myNode = 0L; // No descendant
1155 // il faut repartir de la premiere utilisation.
1156 myNode = RS->FirstUse();
1157 Standard_Boolean Old(Standard_True);
1158 SelectSameShape(myNode,Old,RS,myTrans);
1162 //=======================================================================
1165 //=======================================================================
1167 void TNaming_NewShapeIterator::Next()
1169 TNaming_RefShape* RS = myNode->myOld;
1170 myNode = myNode->NextSameShape(RS);
1171 Standard_Boolean Old(Standard_True);
1172 SelectSameShape(myNode,Old,RS,myTrans);
1175 //=======================================================================
1178 //=======================================================================
1180 TDF_Label TNaming_NewShapeIterator::Label() const
1182 Standard_NoSuchObject_Raise_if(myNode == 0L,
1183 "TNaming_NewShapeIterator::Label");
1184 return myNode->Label();
1187 //=======================================================================
1188 //function : NamedShape
1190 //=======================================================================
1192 Handle(TNaming_NamedShape) TNaming_NewShapeIterator::NamedShape() const
1194 Standard_NoSuchObject_Raise_if(myNode == 0L,
1195 "TNaming_NewShapeIterator::Label");
1196 return myNode->myAtt;
1199 //=======================================================================
1202 //=======================================================================
1204 const TopoDS_Shape& TNaming_NewShapeIterator::Shape() const
1206 Standard_NoSuchObject_Raise_if(myNode == 0L,
1207 "TNaming_NewShapeIterator::Shape");
1208 return myNode->myNew->Shape();
1211 //=======================================================================
1212 //function : IsModification
1214 //=======================================================================
1216 Standard_Boolean TNaming_NewShapeIterator::IsModification() const
1218 Standard_NoSuchObject_Raise_if(myNode == 0L,
1219 "TNaming_NewShapeIterator::IsModification");
1221 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
1222 myNode->myAtt->myEvolution == TNaming_DELETE );
1225 //**********************************************************************
1226 //Methods of the TNaming_OldShapeIterator class
1227 //**********************************************************************
1228 //=======================================================================
1229 //function : TNaming_OldShapeIterator
1231 //=======================================================================
1233 TNaming_OldShapeIterator::TNaming_OldShapeIterator
1234 (const TopoDS_Shape& aShape,
1235 const Standard_Integer Trans,
1236 const Handle(TNaming_UsedShapes)& Shapes)
1239 Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape),
1240 "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape");
1241 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1242 myNode = RS->FirstUse();
1243 Standard_Boolean Old(Standard_False);
1244 SelectSameShape(myNode,Old,RS,myTrans);
1247 //=======================================================================
1248 //function : TNaming_OldShapeIterator
1250 //=======================================================================
1252 TNaming_OldShapeIterator::TNaming_OldShapeIterator
1253 (const TopoDS_Shape& aShape,
1254 const Standard_Integer Trans,
1255 const TDF_Label& access)
1258 Handle(TNaming_UsedShapes) Shapes;
1259 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1260 Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape),
1261 "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape");
1262 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1263 myNode = RS->FirstUse();
1264 Standard_Boolean Old(Standard_False);
1265 SelectSameShape(myNode,Old,RS,myTrans);
1268 //=======================================================================
1269 //function : TNaming_OldShapeIterator
1271 //=======================================================================
1273 TNaming_OldShapeIterator::TNaming_OldShapeIterator
1274 (const TopoDS_Shape& aShape,
1275 const Handle(TNaming_UsedShapes)& Shapes)
1278 Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape),
1279 "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape");
1280 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1281 myNode = RS->FirstUse();
1282 Standard_Boolean Old(Standard_False);
1283 SelectSameShape(myNode,Old,RS,myTrans);
1286 //=======================================================================
1287 //function : TNaming_OldShapeIterator
1289 //=======================================================================
1291 TNaming_OldShapeIterator::TNaming_OldShapeIterator
1292 (const TopoDS_Shape& aShape,
1293 const TDF_Label& access)
1296 Handle(TNaming_UsedShapes) Shapes;
1297 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1298 Standard_NoSuchObject_Raise_if(!Shapes->Map().IsBound(aShape),
1299 "TNaming_OldShapeIterator::TNaming_OldShapeIterator aShape");
1300 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1301 myNode = RS->FirstUse();
1302 Standard_Boolean Old(Standard_False);
1303 SelectSameShape(myNode,Old,RS,myTrans);
1307 //=======================================================================
1308 //function : TNaming_OldShapeIterator
1310 //=======================================================================
1312 TNaming_OldShapeIterator::TNaming_OldShapeIterator (const TNaming_Iterator& anIterator)
1313 :myTrans(anIterator.myTrans)
1315 Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
1316 "TNaming_OldShapeIterator::TNaming_OldShapeIterator");
1317 myNode = anIterator.myNode;
1318 TNaming_RefShape* RS = myNode->myNew;
1320 myNode = 0L; // No descendant
1322 // il faut repartir de la premiere utilisation.
1323 myNode = RS->FirstUse();
1324 Standard_Boolean Old(Standard_False);
1325 SelectSameShape(myNode,Old,RS,myTrans);
1329 //=======================================================================
1330 //function : TNaming_OldShapeIterator
1332 //=======================================================================
1334 TNaming_OldShapeIterator::TNaming_OldShapeIterator(const TNaming_OldShapeIterator& anIterator)
1335 :myTrans(anIterator.myTrans)
1337 Standard_NoSuchObject_Raise_if(anIterator.myNode == 0L,
1338 "TNaming_OldShapeIterator::TNaming_OldShapeIterator");
1339 myNode = anIterator.myNode;
1340 TNaming_RefShape* RS = myNode->myOld;
1342 myNode = 0L; // No descendant
1344 // il faut repartir de la premiere utilisation.
1345 myNode = RS->FirstUse();
1346 Standard_Boolean Old(Standard_False);
1347 SelectSameShape(myNode,Old,RS,myTrans);
1351 //=======================================================================
1354 //=======================================================================
1356 void TNaming_OldShapeIterator::Next()
1358 Standard_Boolean Old = Standard_False;
1359 TNaming_RefShape* RS = myNode->myNew;
1360 myNode = myNode->NextSameShape(RS);
1361 SelectSameShape(myNode,Old,RS,myTrans);
1364 //=======================================================================
1367 //=======================================================================
1369 TDF_Label TNaming_OldShapeIterator::Label() const
1371 if (myNode == 0L) throw Standard_NoSuchObject("TNaming_OldShapeIterator::Label");
1372 return myNode->Label();
1376 //=======================================================================
1377 //function : NamedShape
1379 //=======================================================================
1381 Handle(TNaming_NamedShape) TNaming_OldShapeIterator::NamedShape() const
1383 if (myNode == 0L) throw Standard_NoSuchObject("TNaming_OldShapeIterator::Label");
1384 return myNode->myAtt;
1386 //=======================================================================
1389 //=======================================================================
1391 const TopoDS_Shape& TNaming_OldShapeIterator::Shape() const
1393 if(myNode == 0L) throw Standard_NoSuchObject("TNaming_OldShapeIterator::Shape");
1394 return myNode->myOld->Shape();
1397 //=======================================================================
1398 //function : IsModification
1400 //=======================================================================
1402 Standard_Boolean TNaming_OldShapeIterator::IsModification() const
1404 Standard_NoSuchObject_Raise_if(myNode == 0L,
1405 "TNaming_OldShapeIterator::IsModification");
1406 return (myNode->myAtt->myEvolution == TNaming_MODIFY ||
1407 myNode->myAtt->myEvolution == TNaming_DELETE );
1411 //**********************************************************************
1412 //Methods of the SameShapeIterator
1413 //**********************************************************************
1415 //=======================================================================
1418 //=======================================================================
1420 TNaming_SameShapeIterator::TNaming_SameShapeIterator
1421 (const TopoDS_Shape& aShape,
1422 const Handle(TNaming_UsedShapes)& Shapes)
1424 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1425 myNode = RS->FirstUse();
1426 myIsNew = (myNode->myNew == RS);
1430 //=======================================================================
1431 //function : TNaming_SameShapeIterator
1433 //=======================================================================
1435 TNaming_SameShapeIterator::TNaming_SameShapeIterator
1436 (const TopoDS_Shape& aShape,
1437 const TDF_Label& access)
1439 Handle(TNaming_UsedShapes) Shapes;
1440 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),Shapes)) {
1441 TNaming_RefShape* RS = Shapes->Map().ChangeFind(aShape);
1442 myNode = RS->FirstUse();
1443 myIsNew = (myNode->myNew == RS);
1447 //=======================================================================
1450 //=======================================================================
1452 void TNaming_SameShapeIterator::Next()
1454 TNaming_RefShape* prs;
1455 if (myIsNew) prs = myNode->myNew; else prs = myNode->myOld;
1457 myNode = myNode->NextSameShape(prs);
1458 if (myNode != 0L) myIsNew = (myNode->myNew == prs);
1461 //=======================================================================
1464 //=======================================================================
1466 TDF_Label TNaming_SameShapeIterator::Label() const
1468 Standard_NoSuchObject_Raise_if(myNode == 0L,
1469 "TNaming_SameShapeIterator::Label");
1470 return myNode->Label();
1474 //**********************************************************************
1475 //Methods of the TNaming_RefShape
1476 //**********************************************************************
1477 //=======================================================================
1480 //=======================================================================
1482 TDF_Label TNaming_RefShape::Label() const
1484 return myFirstUse->myAtt->Label();
1487 //=======================================================================
1488 //function : NamedShape
1490 //=======================================================================
1492 Handle(TNaming_NamedShape) TNaming_RefShape::NamedShape() const
1494 return myFirstUse->myAtt;
1497 //=======================================================================
1498 //function : DumpJson
1500 //=======================================================================
1501 void TNaming_RefShape::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
1503 OCCT_DUMP_CLASS_BEGIN (theOStream, TNaming_NamedShape);
1505 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myShape);
1506 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, myFirstUse);
1509 //**********************************************************************
1510 //Methods of the TNaming_Tool class
1511 //**********************************************************************
1513 //=======================================================================
1514 //function : HasLabel
1516 //=======================================================================
1518 Standard_Boolean TNaming_Tool::HasLabel (const TDF_Label& access,
1519 const TopoDS_Shape& S)
1521 Handle(TNaming_UsedShapes) US;
1522 if (access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US)) {
1523 return (US->Map().IsBound(S));
1525 #ifdef OCCT_DEBUG_HASL
1526 std::cout << "##==> Sub-Shape has no Label!" <<std::endl;
1528 return Standard_False;
1532 //=======================================================================
1535 //=======================================================================
1537 TDF_Label TNaming_Tool::Label(const TDF_Label& access,
1538 const TopoDS_Shape& S,
1539 Standard_Integer& Trans)
1541 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(access,S),"TNaming_Tool::Label");
1542 Handle(TNaming_UsedShapes) US;
1543 access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1544 return TNaming_Tool::Label(US,S,Trans);
1548 //=======================================================================
1549 //function : IsValidInTrans
1550 //purpose : un shape est valid tant que l attribut ou il est cree est valid
1551 //=======================================================================
1553 Standard_Integer TNaming_Tool::ValidUntil (const TDF_Label& access, const TopoDS_Shape& S)
1555 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(access,S),"TNaming_Tool::ValidUntil");
1556 Handle(TNaming_UsedShapes) US;
1557 access.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1558 return TNaming_Tool::ValidUntil(S,US);
1562 //=======================================================================
1563 //function : HasLabel
1565 //=======================================================================
1567 Standard_Boolean TNaming_Tool::HasLabel(const Handle(TNaming_UsedShapes)& Shapes,
1568 const TopoDS_Shape& S)
1570 return (Shapes->Map().IsBound(S));
1574 //=======================================================================
1577 //=======================================================================
1579 TDF_Label TNaming_Tool::Label(const Handle(TNaming_UsedShapes)& Shapes,
1580 const TopoDS_Shape& S,
1581 Standard_Integer& Trans)
1583 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(Shapes,S),"TNaming_Tool::Label");
1584 TNaming_RefShape* prs = Shapes->Map().Find(S);
1585 TNaming_Node* pdn = prs->FirstUse();
1587 while (pdn != 0L && !(pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED)){
1588 pdn = pdn->NextSameShape(prs);
1590 if (pdn == 0L) pdn = prs->FirstUse();
1592 TDF_Label L = pdn->Label();
1593 Trans = pdn->myAtt->Transaction();
1596 //=======================================================================
1597 //function : NamedShape
1599 //=======================================================================
1600 Handle(TNaming_NamedShape) TNaming_Tool::NamedShape(const TopoDS_Shape& S,
1601 const TDF_Label& Acces)
1603 Handle(TNaming_UsedShapes) US;
1604 Acces.Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
1605 Handle(TNaming_NamedShape) NS;
1607 if(!TNaming_Tool::HasLabel(US,S)) {
1611 TNaming_RefShape* prs = US->Map().Find(S);
1612 TNaming_Node* pdn = prs->FirstUse();
1613 TNaming_Node* res = 0L;
1616 if (pdn->myNew == prs && pdn->myAtt->Evolution() != TNaming_SELECTED) {
1618 if (pdn->myAtt->Evolution() != TNaming_GENERATED) {
1619 // Les modifications sont privilegiees par rapport au generation.
1620 // Dans le cas des shapes qui sont a la fois des modifications et des generations
1625 pdn = pdn->NextSameShape(prs);
1628 if (res == 0L) return NS;
1630 // VERUE EN ATTENDANT DE REVOIR ABORT 03/11/98
1631 // Protection pour eviter de renvoyer un attribut backuped
1632 TDF_Label Lab = res->Label();
1633 Lab.FindAttribute(TNaming_NamedShape::GetID(),NS);
1635 // return res->myAtt;
1638 //=======================================================================
1639 //function : IsValidInTrans
1640 //purpose : un shape est valid tant que l attribut ou il est cree est valid
1641 //=======================================================================
1643 Standard_Integer TNaming_Tool::ValidUntil (const TopoDS_Shape& S,
1644 const Handle(TNaming_UsedShapes)& US)
1646 Standard_NoSuchObject_Raise_if(!TNaming_Tool::HasLabel(US,S),"TNaming_Tool::ValidUntil");
1648 TNaming_RefShape* RS = US->Map().ChangeFind(S);
1649 Standard_Integer Cur;
1650 Standard_Integer Until = 0;
1651 TNaming_Node* Node = RS->FirstUse();
1653 while (Node != 0L) {
1654 if (Node->myNew != 0L && Node->myNew == RS) {
1655 Cur = Node->myAtt->UntilTransaction();
1656 if (Cur > Until) Until = Cur;
1658 Node = Node->NextSameShape(RS);
1663 //=======================================================================
1664 //function : DumpJson
1666 //=======================================================================
1667 void TNaming_NamedShape::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
1669 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
1671 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
1673 TNaming_Node* p = myNode;
1676 TCollection_AsciiString aLabel;
1677 TDF_Tool::Entry (myNode->Label(), aLabel);
1678 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aLabel)
1680 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myEvolution)
1681 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myVersion)