summaryrefslogtreecommitdiff
path: root/src/MDocStd/MDocStd_DocumentRetrievalDriver.cxx
blob: 7d789640a7eb313514ca21154f9e4486f2b22efc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <MDocStd_DocumentRetrievalDriver.ixx>
#include <CDM_MessageDriver.hxx>
#include <TDocStd_Application.hxx>
#include <TDocStd_Document.hxx>
#include <MDF.hxx>
#include <MDF_RRelocationTable.hxx>
#include <PDocStd_Document.hxx>
#include <TDF_Data.hxx> 
#include <TDocStd_Owner.hxx>

#include <TDF_Tool.hxx>
#include <UTL.hxx>
#include <Resource_Manager.hxx>
#include <Plugin.hxx>

#include <CDF_Application.hxx>
#include <CDF_Session.hxx>


//=======================================================================
//function : MDocStd_DocumentRetrievalDriver
//purpose  : 
//=======================================================================

MDocStd_DocumentRetrievalDriver::MDocStd_DocumentRetrievalDriver () {}


//=======================================================================
//function : CreateDocument
//purpose  : virtuelle
// //=======================================================================

Handle(CDM_Document) MDocStd_DocumentRetrievalDriver::CreateDocument() 
{
   return new TDocStd_Document (PCDM_RetrievalDriver::GetFormat());
}

//=======================================================================
//function : Paste
//purpose  : paste Persistant Document in Transient Document
//=======================================================================

void MDocStd_DocumentRetrievalDriver::Paste (const Handle(PDocStd_Document)& PDOC,
				     const Handle(TDocStd_Document)& TDOC,
				     const Handle(MDF_RRelocationTable)& Reloc)
{
  Handle(PDF_Data) aPDF = PDOC->GetData(); 
  Handle(TDF_Data) aTDF = new TDF_Data();  
  Handle(CDM_MessageDriver) aMsgDriver;
  if (CDF_Session::CurrentSession()->HasCurrentApplication()) 
    aMsgDriver = CDF_Session::CurrentSession()->CurrentApplication()->MessageDriver();
 
  if (myDrivers.IsNull()) myDrivers = AttributeDrivers(aMsgDriver);
  MDF::FromTo (aPDF, aTDF, myDrivers, Reloc); 
  TDOC->SetData(aTDF);  
  TDocStd_Owner::SetDocument(aTDF,TDOC);
}

//=======================================================================
//function : Make
//purpose  : 
//=======================================================================

void MDocStd_DocumentRetrievalDriver::Make (const Handle(PCDM_Document)& aPDocument,
				    const Handle(CDM_Document)& aTDocument) 
{ 
  Handle(PDocStd_Document) PDOC = Handle(PDocStd_Document)::DownCast(aPDocument);
  Handle(TDocStd_Document) TDOC = Handle(TDocStd_Document)::DownCast(aTDocument);
  if (!PDOC.IsNull() && !TDOC.IsNull()) {
    Handle(MDF_RRelocationTable) Reloc = new MDF_RRelocationTable();
    Paste (PDOC,TDOC,Reloc);
  }


//   Handle(PDF_Data) aPDF =  Handle(PDocStd_Document)::DownCast(aPDocument)->GetData();
//   Handle(MDF_RRelocationTable) aReloc = new  MDF_RRelocationTable();
//   Handle(TDF_Data) aTDF = new TDF_Data();
//   if (myDrivers.IsNull()) myDrivers = AttributeDrivers();
//   MDF::FromTo (aPDF, aTDF, myDrivers, aReloc);
//   Handle(TDocStd_Document)::DownCast(aTDocument)->SetData(aTDF);
}


//=======================================================================
//function : SchemaName
//purpose  : 
//=======================================================================

TCollection_ExtendedString MDocStd_DocumentRetrievalDriver::SchemaName() const 
{  
  TCollection_ExtendedString schemaname = PCDM_RetrievalDriver::GetFormat();
  schemaname+="Schema";
  return schemaname;
}

//=======================================================================
//function : AttributeDrivers
//purpose  : 
//=======================================================================

Handle(MDF_ARDriverTable) MDocStd_DocumentRetrievalDriver::AttributeDrivers(const Handle(CDM_MessageDriver)& theMsgDriver)
{ 
  Handle(MDF_ARDriverTable) drivers;
  //
  Handle(CDF_Application) TheApplication;  
  if (CDF_Session::Exists()) {
    Handle(CDF_Session) TheSession = CDF_Session::CurrentSession();   
    if (TheSession->HasCurrentApplication()) {
      TheApplication = TheSession->CurrentApplication();
    } 
  }
  if (!TheApplication.IsNull()) {
    Handle(Resource_Manager) resource = TheApplication->Resources();
    TCollection_ExtendedString pluginNAME;
    pluginNAME = PCDM_RetrievalDriver::GetFormat(); 
    pluginNAME+=".";  
    pluginNAME+="AttributeRetrievalPlugin";  
    TCollection_ExtendedString pluginID;
    Standard_Boolean found = UTL::Find(resource,pluginNAME);
    if(found) { 
      TCollection_ExtendedString value = UTL::Value (resource,pluginNAME);
      Standard_GUID plugin (UTL::GUID(value));
      drivers = Handle(MDF_ARDriverTable)::DownCast(Plugin::Load(plugin));
    } else {
      TCollection_ExtendedString aMsg("Resource not found: ");
      aMsg = aMsg.Cat(pluginNAME).Cat("\0");
      theMsgDriver->Write(aMsg.ToExtString());
    }
  }
  if (drivers.IsNull()) {
    TCollection_ExtendedString aMsg("AttributeDrivers not found ");
    aMsg = aMsg.Cat("\0");
    theMsgDriver->Write(aMsg.ToExtString());
  }
  return drivers;
}