1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <MDocStd_DocumentRetrievalDriver.ixx>
19 #include <CDM_MessageDriver.hxx>
20 #include <TDocStd_Application.hxx>
21 #include <TDocStd_Document.hxx>
23 #include <MDF_RRelocationTable.hxx>
24 #include <PDocStd_Document.hxx>
25 #include <TDF_Data.hxx>
26 #include <TDocStd_Owner.hxx>
28 #include <TDF_Tool.hxx>
30 #include <Resource_Manager.hxx>
33 #include <CDF_Application.hxx>
34 #include <CDF_Session.hxx>
37 //=======================================================================
38 //function : MDocStd_DocumentRetrievalDriver
40 //=======================================================================
42 MDocStd_DocumentRetrievalDriver::MDocStd_DocumentRetrievalDriver () {}
45 //=======================================================================
46 //function : CreateDocument
48 // //=======================================================================
50 Handle(CDM_Document) MDocStd_DocumentRetrievalDriver::CreateDocument()
52 return new TDocStd_Document (PCDM_RetrievalDriver::GetFormat());
55 //=======================================================================
57 //purpose : paste Persistant Document in Transient Document
58 //=======================================================================
60 void MDocStd_DocumentRetrievalDriver::Paste (const Handle(PDocStd_Document)& PDOC,
61 const Handle(TDocStd_Document)& TDOC,
62 const Handle(MDF_RRelocationTable)& Reloc)
64 Handle(PDF_Data) aPDF = PDOC->GetData();
65 Handle(TDF_Data) aTDF = new TDF_Data();
66 Handle(CDM_MessageDriver) aMsgDriver;
67 if (CDF_Session::CurrentSession()->HasCurrentApplication())
68 aMsgDriver = CDF_Session::CurrentSession()->CurrentApplication()->MessageDriver();
70 if (myDrivers.IsNull()) myDrivers = AttributeDrivers(aMsgDriver);
71 MDF::FromTo (aPDF, aTDF, myDrivers, Reloc);
73 TDocStd_Owner::SetDocument(aTDF,TDOC);
76 //=======================================================================
79 //=======================================================================
81 void MDocStd_DocumentRetrievalDriver::Make (const Handle(PCDM_Document)& aPDocument,
82 const Handle(CDM_Document)& aTDocument)
84 Handle(PDocStd_Document) PDOC = Handle(PDocStd_Document)::DownCast(aPDocument);
85 Handle(TDocStd_Document) TDOC = Handle(TDocStd_Document)::DownCast(aTDocument);
86 if (!PDOC.IsNull() && !TDOC.IsNull()) {
87 Handle(MDF_RRelocationTable) Reloc = new MDF_RRelocationTable();
88 Paste (PDOC,TDOC,Reloc);
92 // Handle(PDF_Data) aPDF = Handle(PDocStd_Document)::DownCast(aPDocument)->GetData();
93 // Handle(MDF_RRelocationTable) aReloc = new MDF_RRelocationTable();
94 // Handle(TDF_Data) aTDF = new TDF_Data();
95 // if (myDrivers.IsNull()) myDrivers = AttributeDrivers();
96 // MDF::FromTo (aPDF, aTDF, myDrivers, aReloc);
97 // Handle(TDocStd_Document)::DownCast(aTDocument)->SetData(aTDF);
101 //=======================================================================
102 //function : SchemaName
104 //=======================================================================
106 TCollection_ExtendedString MDocStd_DocumentRetrievalDriver::SchemaName() const
108 TCollection_ExtendedString schemaname = PCDM_RetrievalDriver::GetFormat();
109 schemaname+="Schema";
113 //=======================================================================
114 //function : AttributeDrivers
116 //=======================================================================
118 Handle(MDF_ARDriverTable) MDocStd_DocumentRetrievalDriver::AttributeDrivers(const Handle(CDM_MessageDriver)& theMsgDriver)
120 Handle(MDF_ARDriverTable) drivers;
122 Handle(CDF_Application) TheApplication;
123 if (CDF_Session::Exists()) {
124 Handle(CDF_Session) TheSession = CDF_Session::CurrentSession();
125 if (TheSession->HasCurrentApplication()) {
126 TheApplication = TheSession->CurrentApplication();
129 if (!TheApplication.IsNull()) {
130 Handle(Resource_Manager) resource = TheApplication->Resources();
131 TCollection_ExtendedString pluginNAME;
132 pluginNAME = PCDM_RetrievalDriver::GetFormat();
134 pluginNAME+="AttributeRetrievalPlugin";
135 TCollection_ExtendedString pluginID;
136 Standard_Boolean found = UTL::Find(resource,pluginNAME);
138 TCollection_ExtendedString value = UTL::Value (resource,pluginNAME);
139 Standard_GUID plugin (UTL::GUID(value));
140 drivers = Handle(MDF_ARDriverTable)::DownCast(Plugin::Load(plugin));
142 TCollection_ExtendedString aMsg("Resource not found: ");
143 aMsg = aMsg.Cat(pluginNAME).Cat("\0");
144 theMsgDriver->Write(aMsg.ToExtString());
147 if (drivers.IsNull()) {
148 TCollection_ExtendedString aMsg("AttributeDrivers not found ");
149 aMsg = aMsg.Cat("\0");
150 theMsgDriver->Write(aMsg.ToExtString());