b311480e |
1 | // Created on: 2008-01-23 |
2 | // Created by: Sergey ZARITCHNY |
973c2be1 |
3 | // Copyright (c) 2008-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
bc73b006 |
16 | #include <TDataStd_DeltaOnModificationOfIntPackedMap.hxx> |
42cf5bc1 |
17 | |
18 | #include <Standard_Type.hxx> |
7fd59977 |
19 | #include <TColStd_HPackedMapOfInteger.hxx> |
20 | #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx> |
42cf5bc1 |
21 | #include <TColStd_PackedMapOfInteger.hxx> |
42cf5bc1 |
22 | #include <TDataStd_IntPackedMap.hxx> |
23 | #include <TDF_DeltaOnModification.hxx> |
24 | #include <TDF_Label.hxx> |
7fd59977 |
25 | |
92efcf78 |
26 | IMPLEMENT_STANDARD_RTTIEXT(TDataStd_DeltaOnModificationOfIntPackedMap,TDF_DeltaOnModification) |
27 | |
0797d9d3 |
28 | #ifdef OCCT_DEBUG |
7fd59977 |
29 | #define MAXUP 1000 |
30 | #endif |
31 | |
32 | //======================================================================= |
33 | //function : TDataStd_DeltaOnModificationOfIntPackedMap |
34 | //purpose : |
35 | //======================================================================= |
36 | |
37 | TDataStd_DeltaOnModificationOfIntPackedMap::TDataStd_DeltaOnModificationOfIntPackedMap( |
38 | const Handle(TDataStd_IntPackedMap)& OldAtt) |
39 | : TDF_DeltaOnModification(OldAtt) |
40 | { |
41 | Handle(TDataStd_IntPackedMap) CurrAtt; |
6d1dc3e8 |
42 | if (Label().FindAttribute(OldAtt->ID(), CurrAtt)) |
43 | { |
44 | Handle(TColStd_HPackedMapOfInteger) aMap1, aMap2; |
45 | aMap1 = OldAtt->GetHMap(); |
46 | aMap2 = CurrAtt->GetHMap(); |
0797d9d3 |
47 | #ifdef OCCT_DEBUG_disable |
6d1dc3e8 |
48 | if (aMap1.IsNull()) |
04232180 |
49 | std::cout <<"DeltaOnModificationOfIntPackedMap:: Old Map is Null" <<std::endl; |
6d1dc3e8 |
50 | if (aMap2.IsNull()) |
04232180 |
51 | std::cout <<"DeltaOnModificationOfIntPackedMap:: Current Map is Null" <<std::endl; |
7fd59977 |
52 | #endif |
53 | |
6d1dc3e8 |
54 | if (aMap1.IsNull() || aMap2.IsNull()) return; |
55 | if (aMap1 != aMap2) { |
56 | const TColStd_PackedMapOfInteger& map1 = aMap1->Map(); |
57 | const TColStd_PackedMapOfInteger& map2 = aMap2->Map(); |
58 | if (map1.IsSubset(map2)) { |
59 | myDeletion = new TColStd_HPackedMapOfInteger(); |
60 | myDeletion->ChangeMap().Subtraction(map2, map1); |
61 | } else if (map2.IsSubset(map1)) { |
62 | myAddition = new TColStd_HPackedMapOfInteger(); |
63 | myAddition->ChangeMap().Subtraction(map1, map2); |
64 | } else if (map1.HasIntersection(map2)) { |
65 | myAddition = new TColStd_HPackedMapOfInteger(); |
66 | myAddition->ChangeMap().Subtraction(map1, map2); |
67 | myDeletion = new TColStd_HPackedMapOfInteger(); |
68 | myDeletion->ChangeMap().Subtraction(map2, map1); |
69 | } else { |
70 | myAddition = new TColStd_HPackedMapOfInteger(map1); |
71 | myDeletion = new TColStd_HPackedMapOfInteger(map2); |
7fd59977 |
72 | } |
73 | } |
7fd59977 |
74 | } |
75 | } |
76 | |
77 | |
78 | //======================================================================= |
79 | //function : Apply |
80 | //purpose : |
81 | //======================================================================= |
82 | |
83 | void TDataStd_DeltaOnModificationOfIntPackedMap::Apply() |
84 | { |
85 | |
86 | Handle(TDF_Attribute) aTDFAttribute = Attribute(); |
c5f3a425 |
87 | Handle(TDataStd_IntPackedMap) aBackAtt = Handle(TDataStd_IntPackedMap)::DownCast (aTDFAttribute); |
7fd59977 |
88 | if(aBackAtt.IsNull()) { |
0797d9d3 |
89 | #ifdef OCCT_DEBUG |
04232180 |
90 | std::cout << "DeltaOnModificationOfIntPAckedMap::Apply: OldAtt is Null" <<std::endl; |
7fd59977 |
91 | #endif |
92 | return; |
93 | } |
94 | |
95 | Handle(TDataStd_IntPackedMap) aCurAtt; |
96 | if (!Label().FindAttribute(aBackAtt->ID(),aCurAtt)) { |
97 | |
98 | Label().AddAttribute(aBackAtt); |
99 | } |
100 | |
101 | if(aCurAtt.IsNull()) { |
0797d9d3 |
102 | #ifdef OCCT_DEBUG |
04232180 |
103 | std::cout << "DeltaOnModificationOfIntAPckedMAp::Apply: CurAtt is Null" <<std::endl; |
7fd59977 |
104 | #endif |
105 | return; |
106 | } |
107 | else |
108 | aCurAtt->Backup(); |
109 | |
110 | |
111 | |
112 | Handle(TColStd_HPackedMapOfInteger) IntMap = aCurAtt->GetHMap(); |
6d1dc3e8 |
113 | if (IntMap.IsNull()) return; |
7fd59977 |
114 | |
6d1dc3e8 |
115 | if (myDeletion.IsNull() && myAddition.IsNull()) |
7fd59977 |
116 | return; |
6d1dc3e8 |
117 | |
118 | if (!myDeletion.IsNull()) { |
119 | if (myDeletion->Map().Extent()) |
120 | IntMap->ChangeMap().Subtract(myDeletion->Map()); |
121 | } |
122 | if (!myAddition.IsNull()) { |
123 | if (myAddition->Map().Extent()) |
124 | IntMap->ChangeMap().Unite(myAddition->Map()); |
7fd59977 |
125 | } |
126 | |
0797d9d3 |
127 | #ifdef OCCT_DEBUG_disable |
04232180 |
128 | std::cout << " << Map Dump after Delta Apply >>" <<std::endl; |
7fd59977 |
129 | Handle(TColStd_HPackedMapOfInteger) aIntMap = aCurAtt->GetHMap(); |
130 | TColStd_MapIteratorOfPackedMapOfInteger it(aIntMap->Map()); |
131 | for (Standard_Integer i=1;it.More() && i <= MAXUP; it.Next(), i++) |
04232180 |
132 | std::cout << it.Key() << " "; |
133 | std::cout <<std::endl; |
7fd59977 |
134 | #endif |
135 | } |