0023258: Missing parenthesis
[occt.git] / src / MDocStd / MDocStd_DocumentRetrievalDriver.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
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.
7 //
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.
10 //
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.
17
18 #include <MDocStd_DocumentRetrievalDriver.ixx>
19 #include <CDM_MessageDriver.hxx>
20 #include <TDocStd_Application.hxx>
21 #include <TDocStd_Document.hxx>
22 #include <MDF.hxx>
23 #include <MDF_RRelocationTable.hxx>
24 #include <PDocStd_Document.hxx>
25 #include <TDF_Data.hxx> 
26 #include <TDocStd_Owner.hxx>
27
28 #include <TDF_Tool.hxx>
29 #include <UTL.hxx>
30 #include <Resource_Manager.hxx>
31 #include <Plugin.hxx>
32
33 #include <CDF_Application.hxx>
34 #include <CDF_Session.hxx>
35
36
37 //=======================================================================
38 //function : MDocStd_DocumentRetrievalDriver
39 //purpose  : 
40 //=======================================================================
41
42 MDocStd_DocumentRetrievalDriver::MDocStd_DocumentRetrievalDriver () {}
43
44
45 //=======================================================================
46 //function : CreateDocument
47 //purpose  : virtuelle
48 // //=======================================================================
49
50 Handle(CDM_Document) MDocStd_DocumentRetrievalDriver::CreateDocument() 
51 {
52    return new TDocStd_Document (PCDM_RetrievalDriver::GetFormat());
53 }
54
55 //=======================================================================
56 //function : Paste
57 //purpose  : paste Persistant Document in Transient Document
58 //=======================================================================
59
60 void MDocStd_DocumentRetrievalDriver::Paste (const Handle(PDocStd_Document)& PDOC,
61                                      const Handle(TDocStd_Document)& TDOC,
62                                      const Handle(MDF_RRelocationTable)& Reloc)
63 {
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();
69  
70   if (myDrivers.IsNull()) myDrivers = AttributeDrivers(aMsgDriver);
71   MDF::FromTo (aPDF, aTDF, myDrivers, Reloc); 
72   TDOC->SetData(aTDF);  
73   TDocStd_Owner::SetDocument(aTDF,TDOC);
74 }
75
76 //=======================================================================
77 //function : Make
78 //purpose  : 
79 //=======================================================================
80
81 void MDocStd_DocumentRetrievalDriver::Make (const Handle(PCDM_Document)& aPDocument,
82                                     const Handle(CDM_Document)& aTDocument) 
83
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);
89   }
90
91
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);
98 }
99
100
101 //=======================================================================
102 //function : SchemaName
103 //purpose  : 
104 //=======================================================================
105
106 TCollection_ExtendedString MDocStd_DocumentRetrievalDriver::SchemaName() const 
107 {  
108   TCollection_ExtendedString schemaname = PCDM_RetrievalDriver::GetFormat();
109   schemaname+="Schema";
110   return schemaname;
111 }
112
113 //=======================================================================
114 //function : AttributeDrivers
115 //purpose  : 
116 //=======================================================================
117
118 Handle(MDF_ARDriverTable) MDocStd_DocumentRetrievalDriver::AttributeDrivers(const Handle(CDM_MessageDriver)& theMsgDriver)
119
120   Handle(MDF_ARDriverTable) drivers;
121   //
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();
127     } 
128   }
129   if (!TheApplication.IsNull()) {
130     Handle(Resource_Manager) resource = TheApplication->Resources();
131     TCollection_ExtendedString pluginNAME;
132     pluginNAME = PCDM_RetrievalDriver::GetFormat(); 
133     pluginNAME+=".";  
134     pluginNAME+="AttributeRetrievalPlugin";  
135     TCollection_ExtendedString pluginID;
136     Standard_Boolean found = UTL::Find(resource,pluginNAME);
137     if(found) { 
138       TCollection_ExtendedString value = UTL::Value (resource,pluginNAME);
139       Standard_GUID plugin (UTL::GUID(value));
140       drivers = Handle(MDF_ARDriverTable)::DownCast(Plugin::Load(plugin));
141     } else {
142       TCollection_ExtendedString aMsg("Resource not found: ");
143       aMsg = aMsg.Cat(pluginNAME).Cat("\0");
144       theMsgDriver->Write(aMsg.ToExtString());
145     }
146   }
147   if (drivers.IsNull()) {
148     TCollection_ExtendedString aMsg("AttributeDrivers not found ");
149     aMsg = aMsg.Cat("\0");
150     theMsgDriver->Write(aMsg.ToExtString());
151   }
152   return drivers;
153 }
154
155
156