1 // Created on: 1997-08-08
2 // Created by: Jean-Louis Frenkel
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <CDF_Application.hxx>
19 #include <CDF_Directory.hxx>
20 #include <CDF_FWOSDriver.hxx>
21 #include <CDF_MetaDataDriver.hxx>
22 #include <CDF_MetaDataDriverFactory.hxx>
23 #include <CDF_Session.hxx>
25 #include <PCDM_Reader.hxx>
27 #include <Standard_ErrorHandler.hxx>
28 #include <Standard_Failure.hxx>
29 #include <Standard_GUID.hxx>
30 #include <Standard_MultiplyDefined.hxx>
31 #include <Standard_NoSuchObject.hxx>
32 #include <Standard_Type.hxx>
33 #include <TCollection_ExtendedString.hxx>
35 IMPLEMENT_STANDARD_RTTIEXT(CDF_Session,Standard_Transient)
37 static Handle(CDF_Session) CS;
39 //=======================================================================
42 //=======================================================================
43 CDF_Session::CDF_Session () : myHasCurrentApplication(Standard_False)
45 Standard_MultiplyDefined_Raise_if(!CS.IsNull()," a session already exists");
46 myDirectory = new CDF_Directory();
50 //=======================================================================
53 //=======================================================================
54 Standard_Boolean CDF_Session::Exists() {
58 //=======================================================================
59 //function : Directory
61 //=======================================================================
62 Handle(CDF_Directory) CDF_Session::Directory() const {
64 return CS->myDirectory;
67 //=======================================================================
68 //function : CurrentSession
70 //=======================================================================
71 Handle(CDF_Session) CDF_Session::CurrentSession() {
72 Standard_NoSuchObject_Raise_if(CS.IsNull(), "no session has been created");
76 //=======================================================================
77 //function : HasCurrentApplication
79 //=======================================================================
80 Standard_Boolean CDF_Session::HasCurrentApplication() const {
81 return myHasCurrentApplication;
84 //=======================================================================
85 //function : CurrentApplication
87 //=======================================================================
88 Handle(CDF_Application) CDF_Session::CurrentApplication() const {
89 Standard_NoSuchObject_Raise_if(!myHasCurrentApplication,"there is no current application in the session");
90 return myCurrentApplication;
93 //=======================================================================
94 //function : SetCurrentApplication
96 //=======================================================================
97 void CDF_Session::SetCurrentApplication(const Handle(CDF_Application)& anApplication) {
98 myCurrentApplication = anApplication;
99 myHasCurrentApplication = Standard_True;
102 //=======================================================================
103 //function : UnsetCurrentApplication
105 //=======================================================================
106 void CDF_Session::UnsetCurrentApplication() {
107 myHasCurrentApplication = Standard_False;
108 myCurrentApplication.Nullify();
111 //=======================================================================
112 //function : MetaDataDriver
114 //=======================================================================
115 Handle(CDF_MetaDataDriver) CDF_Session::MetaDataDriver() const {
116 Standard_NoSuchObject_Raise_if(myMetaDataDriver.IsNull(),"no metadatadriver has been provided; this session is not able to store or retrieve files.");
117 return myMetaDataDriver;
120 //=======================================================================
121 //function : LoadDriver
123 //=======================================================================
124 void CDF_Session::LoadDriver() {
125 if (myMetaDataDriver.IsNull()) {
126 Handle(CDF_MetaDataDriverFactory) aFactory;
128 aFactory = Handle(CDF_MetaDataDriverFactory)::DownCast (
129 Plugin::Load (Standard_GUID ("a148e300-5740-11d1-a904-080036aaa103"),
130 Standard_False /*theVerbose*/));
131 } catch (const Standard_Failure&) {
133 if (!aFactory.IsNull()) {
134 myMetaDataDriver = aFactory->Build();
136 myMetaDataDriver = new CDF_FWOSDriver;