1 // Created on: 1997-12-03
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1997-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.
23 #include <TNaming_DeltaOnModification.ixx>
24 #include <TNaming_Iterator.hxx>
25 #include <TNaming_Builder.hxx>
26 #include <TNaming_Evolution.hxx>
27 #include <TDF_DeltaOnModification.hxx>
28 #include <TDF_Label.hxx>
30 //=======================================================================
31 //function : TNaming_DeltaOnModification
33 //=======================================================================
35 TNaming_DeltaOnModification::TNaming_DeltaOnModification(const Handle(TNaming_NamedShape)& NS)
36 : TDF_DeltaOnModification(NS)
38 Standard_Integer NbShapes = 0;
39 for (TNaming_Iterator it(NS); it.More(); it.Next()) { NbShapes++;}
41 if (NbShapes == 0) return;
43 TNaming_Evolution Evol = NS->Evolution();
44 Standard_Integer i = 1;
46 if (Evol == TNaming_PRIMITIVE) {
47 myNew = new TopTools_HArray1OfShape(1,NbShapes);
48 for (TNaming_Iterator it2(NS) ; it2.More(); it2.Next(),i++) {
49 myNew->SetValue(i,it2.NewShape());
52 else if (Evol == TNaming_DELETE) {
53 myOld = new TopTools_HArray1OfShape(1,NbShapes);
54 for (TNaming_Iterator it2(NS); it2.More(); it2.Next(),i++) {
55 myOld->SetValue(i,it2.OldShape());
59 myOld = new TopTools_HArray1OfShape(1,NbShapes);
60 myNew = new TopTools_HArray1OfShape(1,NbShapes);
62 for (TNaming_Iterator it2(NS); it2.More(); it2.Next(), i++) {
63 myNew->SetValue(i,it2.NewShape());
64 myOld->SetValue(i,it2.OldShape());
69 //=======================================================================
70 //function : LoadNamedShape
72 //=======================================================================
74 static void LoadNamedShape (TNaming_Builder& B,
75 TNaming_Evolution Evol,
76 const TopoDS_Shape& OS,
77 const TopoDS_Shape& NS)
80 case TNaming_PRIMITIVE :
85 case TNaming_GENERATED :
100 case TNaming_SELECTED :
108 //=======================================================================
111 //=======================================================================
113 void TNaming_DeltaOnModification::Apply()
116 Handle(TDF_Attribute) TDFAttribute = Attribute();
117 Handle(TNaming_NamedShape) NS = (*((Handle(TNaming_NamedShape)*)&TDFAttribute));
120 // If there is no attribute, reinsert the previous. Otherwise a new one
121 // is created automatically, and all referencing the previous are incorrect! FID 24/12/97
122 Handle(TDF_Attribute) dummyAtt;
123 //if (!Ins.Find(NS->ID(),dummyAtt)) Ins.Add(NS);
124 if (!Label().FindAttribute(NS->ID(),dummyAtt)) {
126 Label().AddAttribute(NS);
129 if (myOld.IsNull() && myNew.IsNull())
131 else if (myOld.IsNull()) {
132 //TNaming_Builder B(Ins);
133 TNaming_Builder B(Label());
135 for (Standard_Integer i = 1; i <= myNew->Upper(); i++) {
136 LoadNamedShape (B,NS->Evolution(),Old,myNew->Value(i));
139 else if (myNew.IsNull()) {
140 //TNaming_Builder B(Ins);
141 TNaming_Builder B(Label());
143 for (Standard_Integer i = 1; i <= myOld->Upper(); i++) {
144 LoadNamedShape (B,NS->Evolution(),myOld->Value(i),New);
148 //TNaming_Builder B(Ins);
149 TNaming_Builder B(Label());
150 for (Standard_Integer i = 1; i <= myOld->Upper(); i++) {
151 LoadNamedShape (B,NS->Evolution(),myOld->Value(i),myNew->Value(i));