1 // Created on: 2001-08-24
2 // Created by: Alexnder GRIGORIEV
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // modified 13.04.2009 Sergey Zaritchny
18 #include <BinMDataXtd_ConstraintDriver.hxx>
19 #include <BinObjMgt_Persistent.hxx>
20 #include <CDM_MessageDriver.hxx>
21 #include <Standard_Type.hxx>
22 #include <TDataStd_Real.hxx>
23 #include <TDataXtd_Constraint.hxx>
24 #include <TDF_Attribute.hxx>
25 #include <TNaming_NamedShape.hxx>
27 IMPLEMENT_STANDARD_RTTIEXT(BinMDataXtd_ConstraintDriver,BinMDF_ADriver)
29 //=======================================================================
30 //function : BinMDataXtd_ConstraintDriver
31 //purpose : Constructor
32 //=======================================================================
33 BinMDataXtd_ConstraintDriver::BinMDataXtd_ConstraintDriver
34 (const Handle(CDM_MessageDriver)& theMsgDriver)
35 : BinMDF_ADriver (theMsgDriver, NULL)
38 //=======================================================================
41 //=======================================================================
42 Handle(TDF_Attribute) BinMDataXtd_ConstraintDriver::NewEmpty() const
44 return (new TDataXtd_Constraint());
47 //=======================================================================
49 //purpose : persistent -> transient (retrieve)
50 //=======================================================================
52 Standard_Boolean BinMDataXtd_ConstraintDriver::Paste
53 (const BinObjMgt_Persistent& theSource,
54 const Handle(TDF_Attribute)& theTarget,
55 BinObjMgt_RRelocationTable& theRelocTable) const
57 Handle(TDataXtd_Constraint) aC =
58 Handle(TDataXtd_Constraint)::DownCast(theTarget);
63 if (! (theSource >> aNb))
64 return Standard_False;
67 Handle(TDataStd_Real) aTValue;
68 if (theRelocTable.IsBound(aNb))
69 aTValue = Handle(TDataStd_Real)::DownCast(theRelocTable.Find(aNb));
72 aTValue = new TDataStd_Real;
73 theRelocTable.Bind(aNb, aTValue);
75 aC->SetValue(aTValue);
79 Standard_Integer NbGeom;
80 if (! (theSource >> NbGeom))
81 return Standard_False;
82 Standard_Integer iG = 1;
85 if (! (theSource >> aNb))
86 return Standard_False;
89 Handle(TNaming_NamedShape) aG;
90 if (theRelocTable.IsBound(aNb))
91 aG = Handle(TNaming_NamedShape)::DownCast(theRelocTable.Find(aNb));
94 aG = new TNaming_NamedShape;
95 theRelocTable.Bind(aNb, aG);
97 aC->SetGeometry (iG++, aG);
102 if (! (theSource >> aNb))
103 return Standard_False;
106 Handle(TNaming_NamedShape) aTPlane;
107 if (theRelocTable.IsBound(aNb))
108 aTPlane = Handle(TNaming_NamedShape)::DownCast(theRelocTable.Find(aNb));
111 aTPlane = new TNaming_NamedShape;
112 theRelocTable.Bind(aNb, aTPlane);
114 aC->SetPlane(aTPlane);
118 Standard_Integer aType;
119 if (! (theSource >> aType))
120 return Standard_False;
121 aC->SetType( (TDataXtd_ConstraintEnum) aType );
124 Standard_Integer flags;
125 if (! (theSource >> flags))
126 return Standard_False;
127 aC->Verified( flags & 1);
128 aC->Inverted( flags & 2);
129 aC->Reversed( flags & 4);
131 return Standard_True;
134 //=======================================================================
136 //purpose : transient -> persistent (store)
137 //=======================================================================
138 void BinMDataXtd_ConstraintDriver::Paste
139 (const Handle(TDF_Attribute)& theSource,
140 BinObjMgt_Persistent& theTarget,
141 BinObjMgt_SRelocationTable& theRelocTable) const
143 Handle(TDataXtd_Constraint) aC =
144 Handle(TDataXtd_Constraint)::DownCast(theSource);
146 Standard_Integer aNb;
149 Handle(TDataStd_Real) aValue = aC->GetValue();
150 if (!aValue.IsNull())
151 aNb = theRelocTable.Add(aValue); // create and/or get index
157 Standard_Integer NbGeom = aC->NbGeometries();
160 for (iG = 1; iG <= NbGeom; iG++)
162 Handle(TNaming_NamedShape) aG = aC->GetGeometry(iG);
164 aNb = theRelocTable.Add(aG);
171 Handle(TNaming_NamedShape) aTPlane = aC->GetPlane();
172 if (!aTPlane.IsNull())
173 aNb = theRelocTable.Add(aTPlane);
179 theTarget << (Standard_Integer) aC->GetType();
182 Standard_Integer flags = 0;
183 if (aC->Verified()) flags |= 1;
184 if (aC->Inverted()) flags |= 2;
185 if (aC->Reversed()) flags |= 4;