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 | |
17 | #include <CDF_Session.ixx> | |
18 | #include <TCollection_ExtendedString.hxx> | |
19 | #include <CDF_MetaDataDriverFactory.hxx> | |
b6c0b841 | 20 | #include <CDF_FWOSDriver.hxx> |
7fd59977 | 21 | #include <Plugin.hxx> |
22 | #include <Standard_GUID.hxx> | |
23 | #include <PCDM.hxx> | |
24 | #include <PCDM_Reader.hxx> | |
25 | #include <Standard_ErrorHandler.hxx> | |
26 | #include <Standard_Failure.hxx> | |
27 | ||
28 | static Handle(CDF_Session) CS; | |
29 | ||
30 | //======================================================================= | |
31 | //function : | |
32 | //purpose : | |
33 | //======================================================================= | |
34 | CDF_Session::CDF_Session () : myHasCurrentApplication(Standard_False) | |
35 | { | |
36 | Standard_MultiplyDefined_Raise_if(!CS.IsNull()," a session already exists"); | |
37 | myDirectory = new CDF_Directory(); | |
38 | CS = this; | |
39 | } | |
40 | ||
41 | //======================================================================= | |
42 | //function : Exists | |
43 | //purpose : | |
44 | //======================================================================= | |
45 | Standard_Boolean CDF_Session::Exists() { | |
46 | return !CS.IsNull(); | |
47 | } | |
48 | ||
49 | //======================================================================= | |
50 | //function : Directory | |
51 | //purpose : | |
52 | //======================================================================= | |
53 | Handle(CDF_Directory) CDF_Session::Directory() const { | |
54 | ||
55 | return CS->myDirectory; | |
56 | } | |
57 | ||
58 | //======================================================================= | |
59 | //function : CurrentSession | |
60 | //purpose : | |
61 | //======================================================================= | |
62 | Handle(CDF_Session) CDF_Session::CurrentSession() { | |
63 | Standard_NoSuchObject_Raise_if(CS.IsNull(), "no session has been created"); | |
64 | return CS; | |
65 | } | |
66 | ||
67 | //======================================================================= | |
68 | //function : HasCurrentApplication | |
69 | //purpose : | |
70 | //======================================================================= | |
71 | Standard_Boolean CDF_Session::HasCurrentApplication() const { | |
72 | return myHasCurrentApplication; | |
73 | } | |
74 | ||
75 | //======================================================================= | |
76 | //function : CurrentApplication | |
77 | //purpose : | |
78 | //======================================================================= | |
79 | Handle(CDF_Application) CDF_Session::CurrentApplication() const { | |
80 | Standard_NoSuchObject_Raise_if(!myHasCurrentApplication,"there is no current application in the session"); | |
81 | return myCurrentApplication; | |
82 | } | |
83 | ||
84 | //======================================================================= | |
85 | //function : SetCurrentApplication | |
86 | //purpose : | |
87 | //======================================================================= | |
88 | void CDF_Session::SetCurrentApplication(const Handle(CDF_Application)& anApplication) { | |
89 | myCurrentApplication = anApplication; | |
90 | myHasCurrentApplication = Standard_True; | |
91 | } | |
92 | ||
93 | //======================================================================= | |
94 | //function : UnsetCurrentApplication | |
95 | //purpose : | |
96 | //======================================================================= | |
97 | void CDF_Session::UnsetCurrentApplication() { | |
98 | myHasCurrentApplication = Standard_False; | |
99 | myCurrentApplication.Nullify(); | |
100 | } | |
101 | ||
102 | //======================================================================= | |
103 | //function : MetaDataDriver | |
104 | //purpose : | |
105 | //======================================================================= | |
106 | Handle(CDF_MetaDataDriver) CDF_Session::MetaDataDriver() const { | |
107 | Standard_NoSuchObject_Raise_if(myMetaDataDriver.IsNull(),"no metadatadriver has been provided; this session is not able to store or retrieve files."); | |
108 | return myMetaDataDriver; | |
109 | } | |
110 | ||
111 | //======================================================================= | |
112 | //function : LoadDriver | |
113 | //purpose : | |
114 | //======================================================================= | |
115 | void CDF_Session::LoadDriver() { | |
b6c0b841 RL |
116 | if (myMetaDataDriver.IsNull()) { |
117 | Handle(CDF_MetaDataDriverFactory) aFactory; | |
118 | try { | |
119 | aFactory = Handle(CDF_MetaDataDriverFactory)::DownCast ( | |
120 | Plugin::Load (Standard_GUID ("a148e300-5740-11d1-a904-080036aaa103"), | |
121 | Standard_False /*theVerbose*/)); | |
122 | } catch (const Standard_Failure&) { | |
123 | } | |
124 | if (!aFactory.IsNull()) { | |
125 | myMetaDataDriver = aFactory->Build(); | |
126 | } else { | |
127 | myMetaDataDriver = new CDF_FWOSDriver; | |
128 | } | |
129 | } | |
7fd59977 | 130 | } |