Test for 0022778: Bug in BRepMesh
[occt.git] / src / BinMFunction / BinMFunction_ScopeDriver.cxx
CommitLineData
b311480e 1// Created on: 2008-05-11
2// Created by: Vlad Romashko
3// Copyright (c) 2008-2012 OPEN CASCADE SAS
4//
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.
9//
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.
12//
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.
19
7fd59977 20
21
22#include <BinMFunction_ScopeDriver.ixx>
23#include <CDM_MessageDriver.hxx>
24#include <TDF_Attribute.hxx>
25#include <TFunction_Scope.hxx>
26#include <BinMDF_ADriver.hxx>
27#include <BinObjMgt_Persistent.hxx>
28#include <BinObjMgt_RRelocationTable.hxx>
29#include <BinObjMgt_SRelocationTable.hxx>
30#include <TColStd_Array1OfInteger.hxx>
31#include <TFunction_DoubleMapIteratorOfDoubleMapOfIntegerLabel.hxx>
32#include <TDF_Label.hxx>
33#include <TDF_Tool.hxx>
34
35//=======================================================================
36//function : BinMFunction_GraphNodeDriver
37//purpose :
38//=======================================================================
39
40BinMFunction_ScopeDriver::BinMFunction_ScopeDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
41: BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TFunction_Scope)->Name())
42{
43}
44
45//=======================================================================
46//function : NewEmpty
47//purpose :
48//=======================================================================
49
50Handle(TDF_Attribute) BinMFunction_ScopeDriver::NewEmpty() const
51{
52 return new TFunction_Scope();
53}
54
55//=======================================================================
56//function : Paste
57//purpose : persistent -> transient (retrieve)
58//=======================================================================
59
60Standard_Boolean BinMFunction_ScopeDriver::Paste(const BinObjMgt_Persistent& theSource,
61 const Handle(TDF_Attribute)& theTarget,
62 BinObjMgt_RRelocationTable& ) const
63{
64 Handle(TFunction_Scope) S = Handle(TFunction_Scope)::DownCast(theTarget);
65
66 Standard_Integer nb;
67 if ( !(theSource >> nb) )
68 return Standard_False;
69 if (!nb)
70 return Standard_True;
71
72 TFunction_DoubleMapOfIntegerLabel& map = S->ChangeFunctions();
73
74 // IDs
75 TColStd_Array1OfInteger IDs(1, nb);
76 theSource.GetIntArray (&IDs(1), nb);
77
78 // Labels
79 Standard_Integer freeID = 0;
80 for (Standard_Integer i = 1; i <= nb; i++)
81 {
82 TCollection_AsciiString entry;
83 if ( !(theSource >> entry) )
84 return Standard_False;
85 TDF_Label L;
86 TDF_Tool::Label(S->Label().Data(), entry, L, Standard_True);
87 if (!L.IsNull())
88 {
89 map.Bind(IDs.Value(i), L);
90 if (IDs.Value(i) > freeID)
91 freeID = IDs.Value(i);
92 }
93 }
94
95 // Free ID
96 freeID++;
97 S->SetFreeID(freeID);
98
99 return Standard_True;
100}
101
102//=======================================================================
103//function : Paste
104//purpose : transient -> persistent (store)
105//=======================================================================
106
107void BinMFunction_ScopeDriver::Paste (const Handle(TDF_Attribute)& theSource,
108 BinObjMgt_Persistent& theTarget,
109 BinObjMgt_SRelocationTable& ) const
110{
111 Handle(TFunction_Scope) S = Handle(TFunction_Scope)::DownCast(theSource);
112 const TFunction_DoubleMapOfIntegerLabel& map = S->GetFunctions();
113 const Standard_Integer nb = map.Extent();
114
115 // Number of functions
116 theTarget << nb;
117 if (!nb)
118 return;
119
120 // IDs
121 {
122 TColStd_Array1OfInteger aSourceArray(1, nb);
123 TFunction_DoubleMapIteratorOfDoubleMapOfIntegerLabel itr(map);
124 for (Standard_Integer i = 1; itr.More(); itr.Next(), i++)
125 {
126 aSourceArray.SetValue(i, itr.Key1());
127 }
128 Standard_Integer *aPtr = (Standard_Integer *) &aSourceArray(1);
129 theTarget.PutIntArray(aPtr, nb);
130 }
131
132 // Labels
133 {
134 TFunction_DoubleMapIteratorOfDoubleMapOfIntegerLabel itr(map);
135 for (; itr.More(); itr.Next())
136 {
137 TDF_Label L = itr.Key2();
138 if (!L.IsNull())
139 {
140 TCollection_AsciiString entry;
141 TDF_Tool::Entry(L, entry);
142 theTarget << entry;
143 }
144 }
145 }
146}
147