973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | #include <MDocStd_DocumentRetrievalDriver.ixx> |
15 | #include <CDM_MessageDriver.hxx> |
16 | #include <TDocStd_Application.hxx> |
17 | #include <TDocStd_Document.hxx> |
18 | #include <MDF.hxx> |
19 | #include <MDF_RRelocationTable.hxx> |
20 | #include <PDocStd_Document.hxx> |
21 | #include <TDF_Data.hxx> |
22 | #include <TDocStd_Owner.hxx> |
23 | |
24 | #include <TDF_Tool.hxx> |
25 | #include <UTL.hxx> |
26 | #include <Resource_Manager.hxx> |
27 | #include <Plugin.hxx> |
28 | |
29 | #include <CDF_Application.hxx> |
30 | #include <CDF_Session.hxx> |
31 | |
32 | |
33 | //======================================================================= |
34 | //function : MDocStd_DocumentRetrievalDriver |
35 | //purpose : |
36 | //======================================================================= |
37 | |
38 | MDocStd_DocumentRetrievalDriver::MDocStd_DocumentRetrievalDriver () {} |
39 | |
40 | |
41 | //======================================================================= |
42 | //function : CreateDocument |
43 | //purpose : virtuelle |
44 | // //======================================================================= |
45 | |
46 | Handle(CDM_Document) MDocStd_DocumentRetrievalDriver::CreateDocument() |
47 | { |
48 | return new TDocStd_Document (PCDM_RetrievalDriver::GetFormat()); |
49 | } |
50 | |
51 | //======================================================================= |
52 | //function : Paste |
53 | //purpose : paste Persistant Document in Transient Document |
54 | //======================================================================= |
55 | |
56 | void MDocStd_DocumentRetrievalDriver::Paste (const Handle(PDocStd_Document)& PDOC, |
57 | const Handle(TDocStd_Document)& TDOC, |
58 | const Handle(MDF_RRelocationTable)& Reloc) |
59 | { |
60 | Handle(PDF_Data) aPDF = PDOC->GetData(); |
61 | Handle(TDF_Data) aTDF = new TDF_Data(); |
62 | Handle(CDM_MessageDriver) aMsgDriver; |
63 | if (CDF_Session::CurrentSession()->HasCurrentApplication()) |
64 | aMsgDriver = CDF_Session::CurrentSession()->CurrentApplication()->MessageDriver(); |
65 | |
66 | if (myDrivers.IsNull()) myDrivers = AttributeDrivers(aMsgDriver); |
67 | MDF::FromTo (aPDF, aTDF, myDrivers, Reloc); |
68 | TDOC->SetData(aTDF); |
69 | TDocStd_Owner::SetDocument(aTDF,TDOC); |
70 | } |
71 | |
72 | //======================================================================= |
73 | //function : Make |
74 | //purpose : |
75 | //======================================================================= |
76 | |
77 | void MDocStd_DocumentRetrievalDriver::Make (const Handle(PCDM_Document)& aPDocument, |
78 | const Handle(CDM_Document)& aTDocument) |
79 | { |
80 | Handle(PDocStd_Document) PDOC = Handle(PDocStd_Document)::DownCast(aPDocument); |
81 | Handle(TDocStd_Document) TDOC = Handle(TDocStd_Document)::DownCast(aTDocument); |
82 | if (!PDOC.IsNull() && !TDOC.IsNull()) { |
83 | Handle(MDF_RRelocationTable) Reloc = new MDF_RRelocationTable(); |
84 | Paste (PDOC,TDOC,Reloc); |
85 | } |
86 | |
87 | |
88 | // Handle(PDF_Data) aPDF = Handle(PDocStd_Document)::DownCast(aPDocument)->GetData(); |
89 | // Handle(MDF_RRelocationTable) aReloc = new MDF_RRelocationTable(); |
90 | // Handle(TDF_Data) aTDF = new TDF_Data(); |
91 | // if (myDrivers.IsNull()) myDrivers = AttributeDrivers(); |
92 | // MDF::FromTo (aPDF, aTDF, myDrivers, aReloc); |
93 | // Handle(TDocStd_Document)::DownCast(aTDocument)->SetData(aTDF); |
94 | } |
95 | |
96 | |
97 | //======================================================================= |
98 | //function : SchemaName |
99 | //purpose : |
100 | //======================================================================= |
101 | |
102 | TCollection_ExtendedString MDocStd_DocumentRetrievalDriver::SchemaName() const |
103 | { |
104 | TCollection_ExtendedString schemaname = PCDM_RetrievalDriver::GetFormat(); |
105 | schemaname+="Schema"; |
106 | return schemaname; |
107 | } |
108 | |
109 | //======================================================================= |
110 | //function : AttributeDrivers |
111 | //purpose : |
112 | //======================================================================= |
113 | |
114 | Handle(MDF_ARDriverTable) MDocStd_DocumentRetrievalDriver::AttributeDrivers(const Handle(CDM_MessageDriver)& theMsgDriver) |
115 | { |
116 | Handle(MDF_ARDriverTable) drivers; |
117 | // |
118 | Handle(CDF_Application) TheApplication; |
119 | if (CDF_Session::Exists()) { |
120 | Handle(CDF_Session) TheSession = CDF_Session::CurrentSession(); |
121 | if (TheSession->HasCurrentApplication()) { |
122 | TheApplication = TheSession->CurrentApplication(); |
123 | } |
124 | } |
125 | if (!TheApplication.IsNull()) { |
126 | Handle(Resource_Manager) resource = TheApplication->Resources(); |
127 | TCollection_ExtendedString pluginNAME; |
128 | pluginNAME = PCDM_RetrievalDriver::GetFormat(); |
129 | pluginNAME+="."; |
130 | pluginNAME+="AttributeRetrievalPlugin"; |
131 | TCollection_ExtendedString pluginID; |
132 | Standard_Boolean found = UTL::Find(resource,pluginNAME); |
133 | if(found) { |
134 | TCollection_ExtendedString value = UTL::Value (resource,pluginNAME); |
135 | Standard_GUID plugin (UTL::GUID(value)); |
136 | drivers = Handle(MDF_ARDriverTable)::DownCast(Plugin::Load(plugin)); |
137 | } else { |
138 | TCollection_ExtendedString aMsg("Resource not found: "); |
139 | aMsg = aMsg.Cat(pluginNAME).Cat("\0"); |
140 | theMsgDriver->Write(aMsg.ToExtString()); |
141 | } |
142 | } |
143 | if (drivers.IsNull()) { |
144 | TCollection_ExtendedString aMsg("AttributeDrivers not found "); |
145 | aMsg = aMsg.Cat("\0"); |
146 | theMsgDriver->Write(aMsg.ToExtString()); |
147 | } |
148 | return drivers; |
149 | } |
150 | |
151 | |
152 | |