0029220: Application Framework - replace CDM_MessageDriver interface by Message_Messe...
[occt.git] / src / BinMDataXtd / BinMDataXtd_ConstraintDriver.cxx
CommitLineData
b311480e 1// Created on: 2001-08-24
2// Created by: Alexnder GRIGORIEV
973c2be1 3// Copyright (c) 2001-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.
b311480e 15
7fd59977 16// modified 13.04.2009 Sergey Zaritchny
17
42cf5bc1 18#include <BinMDataXtd_ConstraintDriver.hxx>
19#include <BinObjMgt_Persistent.hxx>
83ae3591 20#include <Message_Messenger.hxx>
42cf5bc1 21#include <Standard_Type.hxx>
7fd59977 22#include <TDataStd_Real.hxx>
42cf5bc1 23#include <TDataXtd_Constraint.hxx>
24#include <TDF_Attribute.hxx>
7fd59977 25#include <TNaming_NamedShape.hxx>
26
92efcf78 27IMPLEMENT_STANDARD_RTTIEXT(BinMDataXtd_ConstraintDriver,BinMDF_ADriver)
28
7fd59977 29//=======================================================================
30//function : BinMDataXtd_ConstraintDriver
31//purpose : Constructor
32//=======================================================================
33BinMDataXtd_ConstraintDriver::BinMDataXtd_ConstraintDriver
83ae3591 34 (const Handle(Message_Messenger)& theMsgDriver)
7fd59977 35 : BinMDF_ADriver (theMsgDriver, NULL)
36{}
37
38//=======================================================================
39//function : NewEmpty
40//purpose :
41//=======================================================================
42Handle(TDF_Attribute) BinMDataXtd_ConstraintDriver::NewEmpty() const
43{
44 return (new TDataXtd_Constraint());
45}
46
47//=======================================================================
48//function : Paste
49//purpose : persistent -> transient (retrieve)
50//=======================================================================
51
52Standard_Boolean BinMDataXtd_ConstraintDriver::Paste
53 (const BinObjMgt_Persistent& theSource,
54 const Handle(TDF_Attribute)& theTarget,
55 BinObjMgt_RRelocationTable& theRelocTable) const
56{
57 Handle(TDataXtd_Constraint) aC =
58 Handle(TDataXtd_Constraint)::DownCast(theTarget);
59
60 Standard_Integer aNb;
61
62 // value
63 if (! (theSource >> aNb))
64 return Standard_False;
65 if (aNb > 0)
66 {
67 Handle(TDataStd_Real) aTValue;
68 if (theRelocTable.IsBound(aNb))
69 aTValue = Handle(TDataStd_Real)::DownCast(theRelocTable.Find(aNb));
70 else
71 {
72 aTValue = new TDataStd_Real;
73 theRelocTable.Bind(aNb, aTValue);
74 }
75 aC->SetValue(aTValue);
76 }
77
78 // geometries
79 Standard_Integer NbGeom;
80 if (! (theSource >> NbGeom))
81 return Standard_False;
82 Standard_Integer iG = 1;
83 while (iG <= NbGeom)
84 {
85 if (! (theSource >> aNb))
86 return Standard_False;
87 if (aNb > 0)
88 {
89 Handle(TNaming_NamedShape) aG;
90 if (theRelocTable.IsBound(aNb))
91 aG = Handle(TNaming_NamedShape)::DownCast(theRelocTable.Find(aNb));
92 else
93 {
94 aG = new TNaming_NamedShape;
95 theRelocTable.Bind(aNb, aG);
96 }
97 aC->SetGeometry (iG++, aG);
98 }
99 }
100
101 // plane
102 if (! (theSource >> aNb))
103 return Standard_False;
104 if (aNb > 0)
105 {
106 Handle(TNaming_NamedShape) aTPlane;
107 if (theRelocTable.IsBound(aNb))
108 aTPlane = Handle(TNaming_NamedShape)::DownCast(theRelocTable.Find(aNb));
109 else
110 {
111 aTPlane = new TNaming_NamedShape;
112 theRelocTable.Bind(aNb, aTPlane);
113 }
114 aC->SetPlane(aTPlane);
115 }
116
117 // constraint type
118 Standard_Integer aType;
119 if (! (theSource >> aType))
120 return Standard_False;
121 aC->SetType( (TDataXtd_ConstraintEnum) aType );
122
123 // flags
124 Standard_Integer flags;
125 if (! (theSource >> flags))
126 return Standard_False;
dde68833 127 aC->Verified ((flags & 1) != 0);
128 aC->Inverted ((flags & 2) != 0);
129 aC->Reversed ((flags & 4) != 0);
7fd59977 130
131 return Standard_True;
132}
133
134//=======================================================================
135//function : Paste
136//purpose : transient -> persistent (store)
137//=======================================================================
138void BinMDataXtd_ConstraintDriver::Paste
139 (const Handle(TDF_Attribute)& theSource,
140 BinObjMgt_Persistent& theTarget,
141 BinObjMgt_SRelocationTable& theRelocTable) const
142{
143 Handle(TDataXtd_Constraint) aC =
144 Handle(TDataXtd_Constraint)::DownCast(theSource);
145
146 Standard_Integer aNb;
147
148 // value
149 Handle(TDataStd_Real) aValue = aC->GetValue();
150 if (!aValue.IsNull())
151 aNb = theRelocTable.Add(aValue); // create and/or get index
152 else
153 aNb = -1;
154 theTarget << aNb;
155
156 // geometries
157 Standard_Integer NbGeom = aC->NbGeometries();
158 theTarget << NbGeom;
159 Standard_Integer iG;
160 for (iG = 1; iG <= NbGeom; iG++)
161 {
162 Handle(TNaming_NamedShape) aG = aC->GetGeometry(iG);
163 if (!aG.IsNull())
164 aNb = theRelocTable.Add(aG);
165 else
166 aNb = -1;
167 theTarget << aNb;
168 }
169
170 // plane
171 Handle(TNaming_NamedShape) aTPlane = aC->GetPlane();
172 if (!aTPlane.IsNull())
173 aNb = theRelocTable.Add(aTPlane);
174 else
175 aNb = -1;
176 theTarget << aNb;
177
178 // constraint type
179 theTarget << (Standard_Integer) aC->GetType();
180
181 // flags
182 Standard_Integer flags = 0;
183 if (aC->Verified()) flags |= 1;
184 if (aC->Inverted()) flags |= 2;
185 if (aC->Reversed()) flags |= 4;
186 theTarget << flags;
187}