0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / BinMFunction / BinMFunction_GraphNodeDriver.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_GraphNodeDriver.ixx>
23#include <CDM_MessageDriver.hxx>
24#include <TDF_Attribute.hxx>
25#include <TFunction_GraphNode.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 <TColStd_MapIteratorOfMapOfInteger.hxx>
32
33//=======================================================================
34//function : BinMFunction_GraphNodeDriver
35//purpose :
36//=======================================================================
37
38BinMFunction_GraphNodeDriver::BinMFunction_GraphNodeDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
39: BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TFunction_GraphNode)->Name())
40{
41}
42
43//=======================================================================
44//function : NewEmpty
45//purpose :
46//=======================================================================
47
48Handle(TDF_Attribute) BinMFunction_GraphNodeDriver::NewEmpty() const
49{
50 return new TFunction_GraphNode();
51}
52
53//=======================================================================
54//function : Paste
55//purpose : persistent -> transient (retrieve)
56//=======================================================================
57
58Standard_Boolean BinMFunction_GraphNodeDriver::Paste(const BinObjMgt_Persistent& theSource,
59 const Handle(TDF_Attribute)& theTarget,
60 BinObjMgt_RRelocationTable& ) const
61{
62 Handle(TFunction_GraphNode) GN = Handle(TFunction_GraphNode)::DownCast(theTarget);
63
64 Standard_Integer intStatus, nb_previous, nb_next;
65 if (! (theSource >> intStatus >> nb_previous >> nb_next))
66 return Standard_False;
67
68 // Execution status
69 GN->SetStatus((TFunction_ExecutionStatus) intStatus);
70
71 // Previous functions
72 if (nb_previous)
73 {
74 TColStd_Array1OfInteger aTargetArray(1, nb_previous);
75 theSource.GetIntArray (&aTargetArray(1), nb_previous);
76
77 for (Standard_Integer i = 1; i <= nb_previous; i++)
78 {
79 GN->AddPrevious(aTargetArray.Value(i));
80 }
81 }
82
83 // Next functions
84 if (nb_next)
85 {
86 TColStd_Array1OfInteger aTargetArray(1, nb_next);
87 theSource.GetIntArray (&aTargetArray(1), nb_next);
88
89 for (Standard_Integer i = 1; i <= nb_next; i++)
90 {
91 GN->AddNext(aTargetArray.Value(i));
92 }
93 }
94
95 return Standard_True;
96}
97
98//=======================================================================
99//function : Paste
100//purpose : transient -> persistent (store)
101//=======================================================================
102
103void BinMFunction_GraphNodeDriver::Paste (const Handle(TDF_Attribute)& theSource,
104 BinObjMgt_Persistent& theTarget,
105 BinObjMgt_SRelocationTable& ) const
106{
107 Handle(TFunction_GraphNode) GN = Handle(TFunction_GraphNode)::DownCast(theSource);
108
109 // Execution status
110 theTarget << (Standard_Integer) GN->GetStatus();
111 // Number of previous functions
112 theTarget << GN->GetPrevious().Extent();
113 // Number of next functions
114 theTarget << GN->GetNext().Extent();
115
116 // Previous functions
117 Standard_Integer nb = GN->GetPrevious().Extent();
118 if (nb)
119 {
120 TColStd_Array1OfInteger aSourceArray(1, nb);
121 TColStd_MapIteratorOfMapOfInteger itr(GN->GetPrevious());
122 for (Standard_Integer i = 1; itr.More(); itr.Next(), i++)
123 {
124 aSourceArray.SetValue(i, itr.Key());
125 }
126 Standard_Integer *aPtr = (Standard_Integer *) &aSourceArray(1);
127 theTarget.PutIntArray(aPtr, nb);
128 }
129
130 // Next functions
131 nb = GN->GetNext().Extent();
132 if (nb)
133 {
134 TColStd_Array1OfInteger aSourceArray(1, nb);
135 TColStd_MapIteratorOfMapOfInteger itr(GN->GetNext());
136 for (Standard_Integer i = 1; itr.More(); itr.Next(), i++)
137 {
138 aSourceArray.SetValue(i, itr.Key());
139 }
140 Standard_Integer *aPtr = (Standard_Integer *) &aSourceArray(1);
141 theTarget.PutIntArray(aPtr, nb);
142 }
143}
144