| 1 | // Created on: 2008-05-11 |
| 2 | // Created by: Vlad Romashko |
| 3 | // Copyright (c) 2008-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 |
| 8 | // under the terms of the GNU Lesser General Public 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 | #include <BinMFunction_GraphNodeDriver.ixx> |
| 17 | #include <CDM_MessageDriver.hxx> |
| 18 | #include <TDF_Attribute.hxx> |
| 19 | #include <TFunction_GraphNode.hxx> |
| 20 | #include <BinMDF_ADriver.hxx> |
| 21 | #include <BinObjMgt_Persistent.hxx> |
| 22 | #include <BinObjMgt_RRelocationTable.hxx> |
| 23 | #include <BinObjMgt_SRelocationTable.hxx> |
| 24 | #include <TColStd_Array1OfInteger.hxx> |
| 25 | #include <TColStd_MapIteratorOfMapOfInteger.hxx> |
| 26 | |
| 27 | //======================================================================= |
| 28 | //function : BinMFunction_GraphNodeDriver |
| 29 | //purpose : |
| 30 | //======================================================================= |
| 31 | |
| 32 | BinMFunction_GraphNodeDriver::BinMFunction_GraphNodeDriver(const Handle(CDM_MessageDriver)& theMsgDriver) |
| 33 | : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TFunction_GraphNode)->Name()) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | //======================================================================= |
| 38 | //function : NewEmpty |
| 39 | //purpose : |
| 40 | //======================================================================= |
| 41 | |
| 42 | Handle(TDF_Attribute) BinMFunction_GraphNodeDriver::NewEmpty() const |
| 43 | { |
| 44 | return new TFunction_GraphNode(); |
| 45 | } |
| 46 | |
| 47 | //======================================================================= |
| 48 | //function : Paste |
| 49 | //purpose : persistent -> transient (retrieve) |
| 50 | //======================================================================= |
| 51 | |
| 52 | Standard_Boolean BinMFunction_GraphNodeDriver::Paste(const BinObjMgt_Persistent& theSource, |
| 53 | const Handle(TDF_Attribute)& theTarget, |
| 54 | BinObjMgt_RRelocationTable& ) const |
| 55 | { |
| 56 | Handle(TFunction_GraphNode) GN = Handle(TFunction_GraphNode)::DownCast(theTarget); |
| 57 | |
| 58 | Standard_Integer intStatus, nb_previous, nb_next; |
| 59 | if (! (theSource >> intStatus >> nb_previous >> nb_next)) |
| 60 | return Standard_False; |
| 61 | |
| 62 | // Execution status |
| 63 | GN->SetStatus((TFunction_ExecutionStatus) intStatus); |
| 64 | |
| 65 | // Previous functions |
| 66 | if (nb_previous) |
| 67 | { |
| 68 | TColStd_Array1OfInteger aTargetArray(1, nb_previous); |
| 69 | theSource.GetIntArray (&aTargetArray(1), nb_previous); |
| 70 | |
| 71 | for (Standard_Integer i = 1; i <= nb_previous; i++) |
| 72 | { |
| 73 | GN->AddPrevious(aTargetArray.Value(i)); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // Next functions |
| 78 | if (nb_next) |
| 79 | { |
| 80 | TColStd_Array1OfInteger aTargetArray(1, nb_next); |
| 81 | theSource.GetIntArray (&aTargetArray(1), nb_next); |
| 82 | |
| 83 | for (Standard_Integer i = 1; i <= nb_next; i++) |
| 84 | { |
| 85 | GN->AddNext(aTargetArray.Value(i)); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | return Standard_True; |
| 90 | } |
| 91 | |
| 92 | //======================================================================= |
| 93 | //function : Paste |
| 94 | //purpose : transient -> persistent (store) |
| 95 | //======================================================================= |
| 96 | |
| 97 | void BinMFunction_GraphNodeDriver::Paste (const Handle(TDF_Attribute)& theSource, |
| 98 | BinObjMgt_Persistent& theTarget, |
| 99 | BinObjMgt_SRelocationTable& ) const |
| 100 | { |
| 101 | Handle(TFunction_GraphNode) GN = Handle(TFunction_GraphNode)::DownCast(theSource); |
| 102 | |
| 103 | // Execution status |
| 104 | theTarget << (Standard_Integer) GN->GetStatus(); |
| 105 | // Number of previous functions |
| 106 | theTarget << GN->GetPrevious().Extent(); |
| 107 | // Number of next functions |
| 108 | theTarget << GN->GetNext().Extent(); |
| 109 | |
| 110 | // Previous functions |
| 111 | Standard_Integer nb = GN->GetPrevious().Extent(); |
| 112 | if (nb) |
| 113 | { |
| 114 | TColStd_Array1OfInteger aSourceArray(1, nb); |
| 115 | TColStd_MapIteratorOfMapOfInteger itr(GN->GetPrevious()); |
| 116 | for (Standard_Integer i = 1; itr.More(); itr.Next(), i++) |
| 117 | { |
| 118 | aSourceArray.SetValue(i, itr.Key()); |
| 119 | } |
| 120 | Standard_Integer *aPtr = (Standard_Integer *) &aSourceArray(1); |
| 121 | theTarget.PutIntArray(aPtr, nb); |
| 122 | } |
| 123 | |
| 124 | // Next functions |
| 125 | nb = GN->GetNext().Extent(); |
| 126 | if (nb) |
| 127 | { |
| 128 | TColStd_Array1OfInteger aSourceArray(1, nb); |
| 129 | TColStd_MapIteratorOfMapOfInteger itr(GN->GetNext()); |
| 130 | for (Standard_Integer i = 1; itr.More(); itr.Next(), i++) |
| 131 | { |
| 132 | aSourceArray.SetValue(i, itr.Key()); |
| 133 | } |
| 134 | Standard_Integer *aPtr = (Standard_Integer *) &aSourceArray(1); |
| 135 | theTarget.PutIntArray(aPtr, nb); |
| 136 | } |
| 137 | } |
| 138 | |