bd0401e0e367a94ffcab90f6e2b5416ba9113a8e
[occt.git] / src / MDataStd / MDataStd_RelationRetrievalDriver.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <MDataStd_RelationRetrievalDriver.ixx>
15 #include <PDataStd_Relation.hxx>
16 #include <TDataStd_Relation.hxx>
17 #include <TCollection_ExtendedString.hxx>
18 #include <PCollection_HExtendedString.hxx>
19 #include <TDF_ListIteratorOfAttributeList.hxx> 
20 #include <PDF_HAttributeArray1.hxx> 
21 #include <Standard_NoSuchObject.hxx>
22 #include <CDM_MessageDriver.hxx>
23
24
25 //=======================================================================
26 //function : MDataStd_RelationRetrievalDriver
27 //purpose  : 
28 //=======================================================================
29
30 MDataStd_RelationRetrievalDriver::MDataStd_RelationRetrievalDriver(const Handle(CDM_MessageDriver)& theMsgDriver):MDF_ARDriver(theMsgDriver)
31 {
32 }
33
34 //=======================================================================
35 //function : VersionNumber
36 //purpose  : 
37 //=======================================================================
38
39 Standard_Integer MDataStd_RelationRetrievalDriver::VersionNumber() const
40 { return 0; }
41
42 //=======================================================================
43 //function : SourceType
44 //purpose  : 
45 //=======================================================================
46
47 Handle(Standard_Type) MDataStd_RelationRetrievalDriver::SourceType() const
48 {
49   return STANDARD_TYPE(PDataStd_Relation); 
50 }
51
52 //=======================================================================
53 //function : NewEmpty
54 //purpose  : 
55 //=======================================================================
56
57 Handle(TDF_Attribute) MDataStd_RelationRetrievalDriver::NewEmpty() const
58 {
59   return new TDataStd_Relation (); 
60 }
61
62 //=======================================================================
63 //function : Paste
64 //purpose  : 
65 //=======================================================================
66
67 void MDataStd_RelationRetrievalDriver::Paste(const Handle(PDF_Attribute)& Source,
68                                              const Handle(TDF_Attribute)& Target,
69                                              const Handle(MDF_RRelocationTable)& RelocTable) const
70 {
71   Handle(PDataStd_Relation) S = Handle(PDataStd_Relation)::DownCast (Source);
72   Handle(TDataStd_Relation) T = Handle(TDataStd_Relation)::DownCast (Target);
73   TCollection_ExtendedString Relation = (S->GetName())->Convert ();
74   T->SetRelation (Relation);
75   
76   Handle(PDF_Attribute) PV; 
77   Handle(TDF_Attribute) TV;
78
79   Handle(PDF_HAttributeArray1) PVARS = S->GetVariables ();
80   if (PVARS.IsNull()) return;
81   for (Standard_Integer i = 1; i <= PVARS->Length (); i++) {
82     PV = PVARS->Value (i);
83     if (!PV.IsNull ()) {
84       if (!RelocTable->HasRelocation (PV, TV)) {
85         Standard_NoSuchObject::Raise("MDataStd_ConstraintRetrievalDriver::Paste");
86       }
87       T->GetVariables().Append(TV);
88     }
89   }
90 }
91