0025923: Remove small wires on face read from STEP
[occt.git] / src / MDocStd / MDocStd_DocumentStorageDriver.cxx
CommitLineData
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_DocumentStorageDriver.ixx>
15
16#include <CDM_MessageDriver.hxx>
17#include <TDocStd_Application.hxx>
18#include <TDocStd_Document.hxx>
19#include <MDF.hxx>
20#include <MDF_SRelocationTable.hxx>
21#include <MDF_TypeASDriverMap.hxx>
22#include <PDF_Data.hxx>
23#include <PDocStd_Document.hxx>
24
25#include <TDF_Tool.hxx>
26#include <UTL.hxx>
27#include <Resource_Manager.hxx>
28#include <Plugin.hxx>
29
30
31#include <CDF_Application.hxx>
32#include <CDF_Session.hxx>
33
34
35//=======================================================================
36//function : MDocStd_DocumentStorageDriver
37//purpose :
38//=======================================================================
39
40MDocStd_DocumentStorageDriver::MDocStd_DocumentStorageDriver () {}
41
42
43//=======================================================================
44//function : Paste
45//purpose : paste Transient Document in Persistant Document
46//=======================================================================
47
48void MDocStd_DocumentStorageDriver::Paste (const Handle(TDocStd_Document)& TDOC,
49 const Handle(PDocStd_Document)& PDOC,
50 const Handle(MDF_SRelocationTable)& Reloc)
51{
52 Handle(TDF_Data) aTDF = TDOC->GetData();
53 Handle(PDF_Data) aPDF; // = new PDF_Data(); fait par MDF
54 if (myDrivers.IsNull()) myDrivers = AttributeDrivers(TDOC->Application()->MessageDriver());
55 Standard_Integer DFSchemaVersion = 0;
56 MDF::FromTo(aTDF, aPDF, myDrivers, Reloc,DFSchemaVersion);
57 PDOC->SetData(aPDF);
58}
59
60//=======================================================================
61//function : CreateDocument
62//purpose :
63//=======================================================================
64
65Handle(PCDM_Document) MDocStd_DocumentStorageDriver::CreateDocument() {
66 return new PDocStd_Document ();
67}
68
69//=======================================================================
70//function : Make
71//purpose :
72//=======================================================================
73
74Handle(PCDM_Document) MDocStd_DocumentStorageDriver::Make(const Handle(CDM_Document)& aDocument)
75{
76 Handle(TDocStd_Document) TDOC = Handle(TDocStd_Document)::DownCast(aDocument);
77 Handle(PDocStd_Document) PDOC = Handle(PDocStd_Document)::DownCast(CreateDocument());
78 if (!TDOC.IsNull() && !PDOC.IsNull()) {
79 Handle(MDF_SRelocationTable) Reloc = new MDF_SRelocationTable();
80 Paste (TDOC,PDOC,Reloc);
81 }
82 return PDOC;
83}
84
85//=======================================================================
86//function : SchemaName
87//purpose :
88//=======================================================================
89
90TCollection_ExtendedString MDocStd_DocumentStorageDriver::SchemaName() const
91{
92 TCollection_ExtendedString schemaname = PCDM_StorageDriver::GetFormat();
93 schemaname+="Schema";
94 return schemaname;
95}
96
97//=======================================================================
98//function : AttributeDrivers
99//purpose :
100//=======================================================================
101
102Handle(MDF_ASDriverTable) MDocStd_DocumentStorageDriver::AttributeDrivers(const Handle(CDM_MessageDriver)& theMsgDriver)
103{
104 Handle(MDF_ASDriverTable) drivers;
105 //
106 Handle(CDF_Application) TheApplication;
107 if (CDF_Session::Exists()) {
108 Handle(CDF_Session) TheSession = CDF_Session::CurrentSession();
109 if (TheSession->HasCurrentApplication()) {
110 TheApplication = TheSession->CurrentApplication();
111 }
112 }
113 if (!TheApplication.IsNull()) {
114 Handle(Resource_Manager) resource = TheApplication->Resources();
115 TCollection_ExtendedString pluginNAME;
116 pluginNAME = PCDM_StorageDriver::GetFormat();
117 pluginNAME+=".";
118 pluginNAME+="AttributeStoragePlugin";
119 TCollection_ExtendedString pluginID;
120 Standard_Boolean found = UTL::Find(resource,pluginNAME);
121 if(found) {
122 TCollection_ExtendedString value = UTL::Value (resource,pluginNAME);
123 Standard_GUID plugin (UTL::GUID(value));
124 drivers = Handle(MDF_ASDriverTable)::DownCast(Plugin::Load(plugin));
125 }else {
126 TCollection_ExtendedString aMsg("Resource not found: ");
127 aMsg = aMsg.Cat(pluginNAME).Cat("\0");
128 theMsgDriver->Write(aMsg.ToExtString());
129 }
130 }
131 if (drivers.IsNull()) {
132// cout << "MDocStd_DocumentStorageDriver::AttributeDrivers not found" << endl;
133 TCollection_ExtendedString aMsg("AttributeDrivers not found ");
134 aMsg = aMsg.Cat("\0");
135 theMsgDriver->Write(aMsg.ToExtString());
136 }
137 return drivers;
138}
139
140
141