0025418: Debug output to be limited to OCC development environment
[occt.git] / src / TNaming / TNaming_DeltaOnModification.cxx
CommitLineData
b311480e 1// Created on: 1997-12-03
2// Created by: Yves FRICAUD
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <TNaming_DeltaOnModification.ixx>
18#include <TNaming_Iterator.hxx>
19#include <TNaming_Builder.hxx>
20#include <TNaming_Evolution.hxx>
21#include <TDF_DeltaOnModification.hxx>
22#include <TDF_Label.hxx>
23
24//=======================================================================
25//function : TNaming_DeltaOnModification
26//purpose :
27//=======================================================================
28
29TNaming_DeltaOnModification::TNaming_DeltaOnModification(const Handle(TNaming_NamedShape)& NS)
30: TDF_DeltaOnModification(NS)
31{
32 Standard_Integer NbShapes = 0;
33 for (TNaming_Iterator it(NS); it.More(); it.Next()) { NbShapes++;}
34
35 if (NbShapes == 0) return;
36
37 TNaming_Evolution Evol = NS->Evolution();
38 Standard_Integer i = 1;
39
40 if (Evol == TNaming_PRIMITIVE) {
41 myNew = new TopTools_HArray1OfShape(1,NbShapes);
42 for (TNaming_Iterator it2(NS) ; it2.More(); it2.Next(),i++) {
43 myNew->SetValue(i,it2.NewShape());
44 }
45 }
46 else if (Evol == TNaming_DELETE) {
47 myOld = new TopTools_HArray1OfShape(1,NbShapes);
48 for (TNaming_Iterator it2(NS); it2.More(); it2.Next(),i++) {
49 myOld->SetValue(i,it2.OldShape());
50 }
51 }
52 else {
53 myOld = new TopTools_HArray1OfShape(1,NbShapes);
54 myNew = new TopTools_HArray1OfShape(1,NbShapes);
55
56 for (TNaming_Iterator it2(NS); it2.More(); it2.Next(), i++) {
57 myNew->SetValue(i,it2.NewShape());
58 myOld->SetValue(i,it2.OldShape());
59 }
60 }
61}
62
63//=======================================================================
64//function : LoadNamedShape
65//purpose :
66//=======================================================================
67
68static void LoadNamedShape (TNaming_Builder& B,
69 TNaming_Evolution Evol,
70 const TopoDS_Shape& OS,
71 const TopoDS_Shape& NS)
72{
73 switch (Evol) {
74 case TNaming_PRIMITIVE :
75 {
76 B.Generated(NS);
77 break;
78 }
8cb69787 79 case TNaming_REPLACE: // for compatibility
7fd59977 80 case TNaming_GENERATED :
81 {
82 B.Generated(OS,NS);
83 break;
84 }
85 case TNaming_MODIFY :
86 {
87 B.Modify(OS,NS);
88 break;
89 }
90 case TNaming_DELETE :
91 {
92 B.Delete (OS);
93 break;
94 }
95 case TNaming_SELECTED :
96 {
97 B.Select(NS,OS);
98 break;
99 }
7fd59977 100 }
101}
102
103//=======================================================================
104//function : Apply
105//purpose :
106//=======================================================================
107
108void TNaming_DeltaOnModification::Apply()
109{
110
111 Handle(TDF_Attribute) TDFAttribute = Attribute();
112 Handle(TNaming_NamedShape) NS = (*((Handle(TNaming_NamedShape)*)&TDFAttribute));
113
114
115 // If there is no attribute, reinsert the previous. Otherwise a new one
116 // is created automatically, and all referencing the previous are incorrect! FID 24/12/97
117 Handle(TDF_Attribute) dummyAtt;
118 //if (!Ins.Find(NS->ID(),dummyAtt)) Ins.Add(NS);
119 if (!Label().FindAttribute(NS->ID(),dummyAtt)) {
120
121 Label().AddAttribute(NS);
122 }
123
124 if (myOld.IsNull() && myNew.IsNull())
125 return;
126 else if (myOld.IsNull()) {
127 //TNaming_Builder B(Ins);
128 TNaming_Builder B(Label());
129 TopoDS_Shape Old;
130 for (Standard_Integer i = 1; i <= myNew->Upper(); i++) {
131 LoadNamedShape (B,NS->Evolution(),Old,myNew->Value(i));
132 }
133 }
134 else if (myNew.IsNull()) {
135 //TNaming_Builder B(Ins);
136 TNaming_Builder B(Label());
137 TopoDS_Shape New;
138 for (Standard_Integer i = 1; i <= myOld->Upper(); i++) {
139 LoadNamedShape (B,NS->Evolution(),myOld->Value(i),New);
140 }
141 }
142 else {
143 //TNaming_Builder B(Ins);
144 TNaming_Builder B(Label());
145 for (Standard_Integer i = 1; i <= myOld->Upper(); i++) {
146 LoadNamedShape (B,NS->Evolution(),myOld->Value(i),myNew->Value(i));
147 }
148 }
149}
150
151