0024275: Cppcheck warnings on uninitialized class members
[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
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
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.
10//
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.
13//
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.
20
7fd59977 21
22
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>
29
30//=======================================================================
31//function : TNaming_DeltaOnModification
32//purpose :
33//=======================================================================
34
35TNaming_DeltaOnModification::TNaming_DeltaOnModification(const Handle(TNaming_NamedShape)& NS)
36: TDF_DeltaOnModification(NS)
37{
38 Standard_Integer NbShapes = 0;
39 for (TNaming_Iterator it(NS); it.More(); it.Next()) { NbShapes++;}
40
41 if (NbShapes == 0) return;
42
43 TNaming_Evolution Evol = NS->Evolution();
44 Standard_Integer i = 1;
45
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());
50 }
51 }
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());
56 }
57 }
58 else {
59 myOld = new TopTools_HArray1OfShape(1,NbShapes);
60 myNew = new TopTools_HArray1OfShape(1,NbShapes);
61
62 for (TNaming_Iterator it2(NS); it2.More(); it2.Next(), i++) {
63 myNew->SetValue(i,it2.NewShape());
64 myOld->SetValue(i,it2.OldShape());
65 }
66 }
67}
68
69//=======================================================================
70//function : LoadNamedShape
71//purpose :
72//=======================================================================
73
74static void LoadNamedShape (TNaming_Builder& B,
75 TNaming_Evolution Evol,
76 const TopoDS_Shape& OS,
77 const TopoDS_Shape& NS)
78{
79 switch (Evol) {
80 case TNaming_PRIMITIVE :
81 {
82 B.Generated(NS);
83 break;
84 }
85 case TNaming_GENERATED :
86 {
87 B.Generated(OS,NS);
88 break;
89 }
90 case TNaming_MODIFY :
91 {
92 B.Modify(OS,NS);
93 break;
94 }
95 case TNaming_DELETE :
96 {
97 B.Delete (OS);
98 break;
99 }
100 case TNaming_SELECTED :
101 {
102 B.Select(NS,OS);
103 break;
104 }
7fd59977 105 }
106}
107
108//=======================================================================
109//function : Apply
110//purpose :
111//=======================================================================
112
113void TNaming_DeltaOnModification::Apply()
114{
115
116 Handle(TDF_Attribute) TDFAttribute = Attribute();
117 Handle(TNaming_NamedShape) NS = (*((Handle(TNaming_NamedShape)*)&TDFAttribute));
118
119
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)) {
125
126 Label().AddAttribute(NS);
127 }
128
129 if (myOld.IsNull() && myNew.IsNull())
130 return;
131 else if (myOld.IsNull()) {
132 //TNaming_Builder B(Ins);
133 TNaming_Builder B(Label());
134 TopoDS_Shape Old;
135 for (Standard_Integer i = 1; i <= myNew->Upper(); i++) {
136 LoadNamedShape (B,NS->Evolution(),Old,myNew->Value(i));
137 }
138 }
139 else if (myNew.IsNull()) {
140 //TNaming_Builder B(Ins);
141 TNaming_Builder B(Label());
142 TopoDS_Shape New;
143 for (Standard_Integer i = 1; i <= myOld->Upper(); i++) {
144 LoadNamedShape (B,NS->Evolution(),myOld->Value(i),New);
145 }
146 }
147 else {
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));
152 }
153 }
154}
155
156