Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1997-08-08 |
2 | // Created by: Jean-Louis Frenkel | |
3 | // Copyright (c) 1997-1999 Matra Datavision | |
973c2be1 | 4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 5 | // |
973c2be1 | 6 | // This file is part of Open CASCADE Technology software library. |
b311480e | 7 | // |
d5f74e42 | 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 | |
973c2be1 | 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. | |
b311480e | 13 | // |
973c2be1 | 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. | |
7fd59977 | 16 | |
42cf5bc1 | 17 | |
18 | #include <CDF_Application.hxx> | |
19 | #include <CDF_Directory.hxx> | |
b6c0b841 | 20 | #include <CDF_FWOSDriver.hxx> |
42cf5bc1 | 21 | #include <CDF_MetaDataDriver.hxx> |
22 | #include <CDF_MetaDataDriverFactory.hxx> | |
23 | #include <CDF_Session.hxx> | |
7fd59977 | 24 | #include <PCDM.hxx> |
25 | #include <PCDM_Reader.hxx> | |
42cf5bc1 | 26 | #include <Plugin.hxx> |
7fd59977 | 27 | #include <Standard_ErrorHandler.hxx> |
28 | #include <Standard_Failure.hxx> | |
42cf5bc1 | 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> | |
7fd59977 | 34 | |
35 | static Handle(CDF_Session) CS; | |
36 | ||
37 | //======================================================================= | |
38 | //function : | |
39 | //purpose : | |
40 | //======================================================================= | |
41 | CDF_Session::CDF_Session () : myHasCurrentApplication(Standard_False) | |
42 | { | |
43 | Standard_MultiplyDefined_Raise_if(!CS.IsNull()," a session already exists"); | |
44 | myDirectory = new CDF_Directory(); | |
45 | CS = this; | |
46 | } | |
47 | ||
48 | //======================================================================= | |
49 | //function : Exists | |
50 | //purpose : | |
51 | //======================================================================= | |
52 | Standard_Boolean CDF_Session::Exists() { | |
53 | return !CS.IsNull(); | |
54 | } | |
55 | ||
56 | //======================================================================= | |
57 | //function : Directory | |
58 | //purpose : | |
59 | //======================================================================= | |
60 | Handle(CDF_Directory) CDF_Session::Directory() const { | |
61 | ||
62 | return CS->myDirectory; | |
63 | } | |
64 | ||
65 | //======================================================================= | |
66 | //function : CurrentSession | |
67 | //purpose : | |
68 | //======================================================================= | |
69 | Handle(CDF_Session) CDF_Session::CurrentSession() { | |
70 | Standard_NoSuchObject_Raise_if(CS.IsNull(), "no session has been created"); | |
71 | return CS; | |
72 | } | |
73 | ||
74 | //======================================================================= | |
75 | //function : HasCurrentApplication | |
76 | //purpose : | |
77 | //======================================================================= | |
78 | Standard_Boolean CDF_Session::HasCurrentApplication() const { | |
79 | return myHasCurrentApplication; | |
80 | } | |
81 | ||
82 | //======================================================================= | |
83 | //function : CurrentApplication | |
84 | //purpose : | |
85 | //======================================================================= | |
86 | Handle(CDF_Application) CDF_Session::CurrentApplication() const { | |
87 | Standard_NoSuchObject_Raise_if(!myHasCurrentApplication,"there is no current application in the session"); | |
88 | return myCurrentApplication; | |
89 | } | |
90 | ||
91 | //======================================================================= | |
92 | //function : SetCurrentApplication | |
93 | //purpose : | |
94 | //======================================================================= | |
95 | void CDF_Session::SetCurrentApplication(const Handle(CDF_Application)& anApplication) { | |
96 | myCurrentApplication = anApplication; | |
97 | myHasCurrentApplication = Standard_True; | |
98 | } | |
99 | ||
100 | //======================================================================= | |
101 | //function : UnsetCurrentApplication | |
102 | //purpose : | |
103 | //======================================================================= | |
104 | void CDF_Session::UnsetCurrentApplication() { | |
105 | myHasCurrentApplication = Standard_False; | |
106 | myCurrentApplication.Nullify(); | |
107 | } | |
108 | ||
109 | //======================================================================= | |
110 | //function : MetaDataDriver | |
111 | //purpose : | |
112 | //======================================================================= | |
113 | Handle(CDF_MetaDataDriver) CDF_Session::MetaDataDriver() const { | |
114 | Standard_NoSuchObject_Raise_if(myMetaDataDriver.IsNull(),"no metadatadriver has been provided; this session is not able to store or retrieve files."); | |
115 | return myMetaDataDriver; | |
116 | } | |
117 | ||
118 | //======================================================================= | |
119 | //function : LoadDriver | |
120 | //purpose : | |
121 | //======================================================================= | |
122 | void CDF_Session::LoadDriver() { | |
b6c0b841 RL |
123 | if (myMetaDataDriver.IsNull()) { |
124 | Handle(CDF_MetaDataDriverFactory) aFactory; | |
125 | try { | |
126 | aFactory = Handle(CDF_MetaDataDriverFactory)::DownCast ( | |
127 | Plugin::Load (Standard_GUID ("a148e300-5740-11d1-a904-080036aaa103"), | |
128 | Standard_False /*theVerbose*/)); | |
129 | } catch (const Standard_Failure&) { | |
130 | } | |
131 | if (!aFactory.IsNull()) { | |
132 | myMetaDataDriver = aFactory->Build(); | |
133 | } else { | |
134 | myMetaDataDriver = new CDF_FWOSDriver; | |
135 | } | |
136 | } | |
7fd59977 | 137 | } |