1 // Created on: 2008-01-23
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2008-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <TDataStd_DeltaOnModificationOfIntPackedMap.ixx>
22 #include <TDF_DeltaOnModification.hxx>
23 #include <TDF_Label.hxx>
24 #include <TColStd_PackedMapOfInteger.hxx>
25 #include <TColStd_HPackedMapOfInteger.hxx>
26 #include <TColStd_MapIteratorOfPackedMapOfInteger.hxx>
32 //=======================================================================
33 //function : TDataStd_DeltaOnModificationOfIntPackedMap
35 //=======================================================================
37 TDataStd_DeltaOnModificationOfIntPackedMap::TDataStd_DeltaOnModificationOfIntPackedMap(
38 const Handle(TDataStd_IntPackedMap)& OldAtt)
39 : TDF_DeltaOnModification(OldAtt)
41 Handle(TDataStd_IntPackedMap) CurrAtt;
42 if (Label().FindAttribute(OldAtt->ID(),CurrAtt)) {
44 Handle(TColStd_HPackedMapOfInteger) aMap1, aMap2;
45 aMap1 = OldAtt->GetHMap();
46 aMap2 = CurrAtt->GetHMap();
49 cout <<"DeltaOnModificationOfIntPackedMap:: Old Map is Null" <<endl;
51 cout <<"DeltaOnModificationOfIntPackedMap:: Current Map is Null" <<endl;
54 if(aMap1.IsNull() || aMap2.IsNull()) return;
56 if(!aMap1->Map().HasIntersection(aMap2->Map()))
57 return; // no intersection: use full-scale backup
59 if(aMap1->Map().IsSubset(aMap2->Map())) {
60 myDeletion = new TColStd_HPackedMapOfInteger();
61 myDeletion->ChangeMap().Subtraction(aMap2->Map(), aMap1->Map());
62 } else if(aMap2->Map().IsSubset(aMap1->Map())) {
63 myAddition = new TColStd_HPackedMapOfInteger();
64 myAddition->ChangeMap().Subtraction(aMap1->Map(), aMap2->Map());
66 myAddition = new TColStd_HPackedMapOfInteger();
67 myAddition->ChangeMap().Subtraction(aMap1->Map(), aMap2->Map());
68 myDeletion = new TColStd_HPackedMapOfInteger();
69 myDeletion->ChangeMap().Subtraction(aMap2->Map(), aMap1->Map());
75 if(OldAtt->GetHMap().IsNull())
76 cout << "BackUp Arr is Nullified" << endl;
82 //=======================================================================
85 //=======================================================================
87 void TDataStd_DeltaOnModificationOfIntPackedMap::Apply()
90 Handle(TDF_Attribute) aTDFAttribute = Attribute();
91 Handle(TDataStd_IntPackedMap) aBackAtt = (*((Handle(TDataStd_IntPackedMap)*)&aTDFAttribute));
92 if(aBackAtt.IsNull()) {
94 cout << "DeltaOnModificationOfIntPAckedMap::Apply: OldAtt is Null" <<endl;
99 Handle(TDataStd_IntPackedMap) aCurAtt;
100 if (!Label().FindAttribute(aBackAtt->ID(),aCurAtt)) {
102 Label().AddAttribute(aBackAtt);
105 if(aCurAtt.IsNull()) {
107 cout << "DeltaOnModificationOfIntAPckedMAp::Apply: CurAtt is Null" <<endl;
116 Handle(TColStd_HPackedMapOfInteger) IntMap = aCurAtt->GetHMap();
117 if(IntMap.IsNull()) return;
119 if(myDeletion.IsNull() && myAddition.IsNull())
122 if(!myDeletion.IsNull()) {
124 if(myDeletion->Map().Extent())
125 IntMap->ChangeMap().Subtract(myDeletion->Map());
127 if(!myAddition.IsNull()) {
128 if(myAddition->Map().Extent())
129 IntMap->ChangeMap().Unite(myAddition->Map());
134 cout << " << Map Dump after Delta Apply >>" <<endl;
135 Handle(TColStd_HPackedMapOfInteger) aIntMap = aCurAtt->GetHMap();
136 TColStd_MapIteratorOfPackedMapOfInteger it(aIntMap->Map());
137 for (Standard_Integer i=1;it.More() && i <= MAXUP; it.Next(), i++)
138 cout << it.Key() << " ";