0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / BinMDataStd / BinMDataStd_ExtStringArrayDriver.cxx
1 // Created on: 2004-08-24
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2004-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16
17 #include <BinMDataStd.hxx>
18 #include <BinMDataStd_ExtStringArrayDriver.hxx>
19 #include <BinObjMgt_Persistent.hxx>
20 #include <Message_Messenger.hxx>
21 #include <Standard_Type.hxx>
22 #include <TColStd_Array1OfExtendedString.hxx>
23 #include <TColStd_HArray1OfExtendedString.hxx>
24 #include <TDataStd_ExtStringArray.hxx>
25 #include <TDF_Attribute.hxx>
26
27 IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_ExtStringArrayDriver,BinMDF_ADriver)
28
29 //=======================================================================
30 //function : BinMDataStd_ExtStringArrayDriver
31 //purpose  : Constructor
32 //=======================================================================
33 BinMDataStd_ExtStringArrayDriver::BinMDataStd_ExtStringArrayDriver
34                         (const Handle(Message_Messenger)& theMsgDriver)
35      : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_ExtStringArray)->Name())
36 {
37 }
38
39 //=======================================================================
40 //function : NewEmpty
41 //purpose  : 
42 //=======================================================================
43
44 Handle(TDF_Attribute) BinMDataStd_ExtStringArrayDriver::NewEmpty() const
45 {
46   return new TDataStd_ExtStringArray();
47 }
48
49 //=======================================================================
50 //function : Paste
51 //purpose  : persistent -> transient (retrieve)
52 //=======================================================================
53
54 Standard_Boolean BinMDataStd_ExtStringArrayDriver::Paste
55                                 (const BinObjMgt_Persistent&  theSource,
56                                  const Handle(TDF_Attribute)& theTarget,
57                                  BinObjMgt_RRelocationTable&  theRelocTable) const
58 {
59   Standard_Integer aFirstInd, aLastInd;
60   if (! (theSource >> aFirstInd >> aLastInd))
61     return Standard_False;
62   const Standard_Integer aLength = aLastInd - aFirstInd + 1;
63   if (aLength <= 0)
64     return Standard_False;
65
66   Handle(TDataStd_ExtStringArray) anAtt =
67     Handle(TDataStd_ExtStringArray)::DownCast(theTarget);
68   anAtt->Init(aFirstInd, aLastInd);
69   TColStd_Array1OfExtendedString& aTargetArray = anAtt->Array()->ChangeArray1();
70   Standard_Boolean ok = Standard_True;
71   for (Standard_Integer i = aFirstInd; i <= aLastInd; i ++)
72   {
73     TCollection_ExtendedString aStr;
74     if ( !(theSource >> aStr) )
75     {
76       ok = Standard_False;
77       break;
78     }
79     aTargetArray.SetValue( i, aStr );
80   }
81
82   if(ok) {
83     Standard_Boolean aDelta(Standard_False);
84     if(theRelocTable.GetHeaderData()->StorageVersion().IntegerValue() > 2) {
85       Standard_Byte aDeltaValue;
86       if (! (theSource >> aDeltaValue)) {
87         return Standard_False;
88       }
89       else
90         aDelta = (aDeltaValue != 0);
91     }
92     anAtt->SetDelta(aDelta);
93   }
94
95   BinMDataStd::SetAttributeID(theSource, anAtt, theRelocTable.GetHeaderData()->StorageVersion().IntegerValue());
96   return ok;
97 }
98
99 //=======================================================================
100 //function : Paste
101 //purpose  : transient -> persistent (store)
102 //=======================================================================
103
104 void BinMDataStd_ExtStringArrayDriver::Paste
105                                 (const Handle(TDF_Attribute)& theSource,
106                                  BinObjMgt_Persistent&        theTarget,
107                                  BinObjMgt_SRelocationTable&  ) const
108 {
109   const Handle(TDataStd_ExtStringArray) anAtt =
110     Handle(TDataStd_ExtStringArray)::DownCast(theSource);
111   const TColStd_Array1OfExtendedString& aSourceArray = anAtt->Array()->Array1();
112   const Standard_Integer aFirstInd = aSourceArray.Lower();
113   const Standard_Integer aLastInd  = aSourceArray.Upper();
114   theTarget << aFirstInd << aLastInd;
115   for (Standard_Integer i = aFirstInd; i <= aLastInd; i ++)
116     theTarget << anAtt->Value( i );
117
118   theTarget << (Standard_Byte)(anAtt->GetDelta() ? 1 : 0);
119
120   // process user defined guid
121   if(anAtt->ID() != TDataStd_ExtStringArray::GetID()) 
122     theTarget << anAtt->ID();
123 }