0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[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
42cf5bc1 17
18#include <Standard_Type.hxx>
7fd59977 19#include <TDF_DeltaOnModification.hxx>
20#include <TDF_Label.hxx>
42cf5bc1 21#include <TNaming_Builder.hxx>
22#include <TNaming_DeltaOnModification.hxx>
23#include <TNaming_Evolution.hxx>
24#include <TNaming_Iterator.hxx>
25#include <TNaming_NamedShape.hxx>
7fd59977 26
92efcf78 27IMPLEMENT_STANDARD_RTTIEXT(TNaming_DeltaOnModification,TDF_DeltaOnModification)
28
7fd59977 29//=======================================================================
30//function : TNaming_DeltaOnModification
31//purpose :
32//=======================================================================
7fd59977 33TNaming_DeltaOnModification::TNaming_DeltaOnModification(const Handle(TNaming_NamedShape)& NS)
34: TDF_DeltaOnModification(NS)
35{
36 Standard_Integer NbShapes = 0;
37 for (TNaming_Iterator it(NS); it.More(); it.Next()) { NbShapes++;}
38
39 if (NbShapes == 0) return;
40
41 TNaming_Evolution Evol = NS->Evolution();
42 Standard_Integer i = 1;
43
44 if (Evol == TNaming_PRIMITIVE) {
45 myNew = new TopTools_HArray1OfShape(1,NbShapes);
46 for (TNaming_Iterator it2(NS) ; it2.More(); it2.Next(),i++) {
47 myNew->SetValue(i,it2.NewShape());
48 }
49 }
50 else if (Evol == TNaming_DELETE) {
51 myOld = new TopTools_HArray1OfShape(1,NbShapes);
52 for (TNaming_Iterator it2(NS); it2.More(); it2.Next(),i++) {
53 myOld->SetValue(i,it2.OldShape());
54 }
55 }
56 else {
57 myOld = new TopTools_HArray1OfShape(1,NbShapes);
58 myNew = new TopTools_HArray1OfShape(1,NbShapes);
59
60 for (TNaming_Iterator it2(NS); it2.More(); it2.Next(), i++) {
61 myNew->SetValue(i,it2.NewShape());
62 myOld->SetValue(i,it2.OldShape());
63 }
64 }
65}
66
67//=======================================================================
68//function : LoadNamedShape
69//purpose :
70//=======================================================================
71
72static void LoadNamedShape (TNaming_Builder& B,
73 TNaming_Evolution Evol,
74 const TopoDS_Shape& OS,
75 const TopoDS_Shape& NS)
76{
77 switch (Evol) {
78 case TNaming_PRIMITIVE :
79 {
80 B.Generated(NS);
81 break;
82 }
8cb69787 83 case TNaming_REPLACE: // for compatibility
7fd59977 84 case TNaming_GENERATED :
85 {
86 B.Generated(OS,NS);
87 break;
88 }
89 case TNaming_MODIFY :
90 {
91 B.Modify(OS,NS);
92 break;
93 }
94 case TNaming_DELETE :
95 {
96 B.Delete (OS);
97 break;
98 }
99 case TNaming_SELECTED :
100 {
101 B.Select(NS,OS);
102 break;
103 }
7fd59977 104 }
105}
106
107//=======================================================================
108//function : Apply
109//purpose :
110//=======================================================================
111
112void TNaming_DeltaOnModification::Apply()
113{
114
115 Handle(TDF_Attribute) TDFAttribute = Attribute();
c5f3a425 116 Handle(TNaming_NamedShape) NS = Handle(TNaming_NamedShape)::DownCast (TDFAttribute);
7fd59977 117
118
119 // If there is no attribute, reinsert the previous. Otherwise a new one
120 // is created automatically, and all referencing the previous are incorrect! FID 24/12/97
121 Handle(TDF_Attribute) dummyAtt;
122 //if (!Ins.Find(NS->ID(),dummyAtt)) Ins.Add(NS);
123 if (!Label().FindAttribute(NS->ID(),dummyAtt)) {
124
125 Label().AddAttribute(NS);
126 }
127
128 if (myOld.IsNull() && myNew.IsNull())
129 return;
130 else if (myOld.IsNull()) {
131 //TNaming_Builder B(Ins);
132 TNaming_Builder B(Label());
133 TopoDS_Shape Old;
134 for (Standard_Integer i = 1; i <= myNew->Upper(); i++) {
135 LoadNamedShape (B,NS->Evolution(),Old,myNew->Value(i));
136 }
137 }
138 else if (myNew.IsNull()) {
139 //TNaming_Builder B(Ins);
140 TNaming_Builder B(Label());
141 TopoDS_Shape New;
142 for (Standard_Integer i = 1; i <= myOld->Upper(); i++) {
143 LoadNamedShape (B,NS->Evolution(),myOld->Value(i),New);
144 }
145 }
146 else {
147 //TNaming_Builder B(Ins);
148 TNaming_Builder B(Label());
149 for (Standard_Integer i = 1; i <= myOld->Upper(); i++) {
150 LoadNamedShape (B,NS->Evolution(),myOld->Value(i),myNew->Value(i));
151 }
152 }
153}
154
155