0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / XmlLDrivers / XmlLDrivers.cxx
1 // Created on: 2001-07-09
2 // Created by: Julia DOROVSKIKH
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16
17 #include <Message_Messenger.hxx>
18 #include <Plugin_Macro.hxx>
19 #include <Standard_GUID.hxx>
20 #include <TDocStd_Application.hxx>
21 #include <TCollection_AsciiString.hxx>
22 #include <XmlLDrivers.hxx>
23 #include <XmlLDrivers_DocumentRetrievalDriver.hxx>
24 #include <XmlLDrivers_DocumentStorageDriver.hxx>
25 #include <XmlMDataStd.hxx>
26 #include <XmlMDF.hxx>
27 #include <XmlMDF_ADriverTable.hxx>
28 #include <XmlMDocStd.hxx>
29 #include <XmlMFunction.hxx>
30
31 #include <locale.h>
32 #include <time.h>
33 static Standard_GUID XmlLStorageDriver  ("13a56820-8269-11d5-aab2-0050044b1af1");
34 static Standard_GUID XmlLRetrievalDriver("13a56822-8269-11d5-aab2-0050044b1af1");
35
36 static int CURRENT_DOCUMENT_VERSION(9);
37
38 //=======================================================================
39 //function : Factory
40 //purpose  : PLUGIN FACTORY
41 //=======================================================================
42 const Handle(Standard_Transient)& XmlLDrivers::Factory(const Standard_GUID& theGUID)
43 {
44   if (theGUID == XmlLStorageDriver)
45   {
46 #ifdef OCCT_DEBUG
47     std::cout << "XmlLDrivers : Storage Plugin" << std::endl;
48 #endif
49     static Handle(Standard_Transient) model_sd =
50       new XmlLDrivers_DocumentStorageDriver
51         ("Copyright: Open Cascade, 2001-2002"); // default copyright
52     return model_sd;
53   }
54
55   if (theGUID == XmlLRetrievalDriver)
56   {
57 #ifdef OCCT_DEBUG
58     std::cout << "XmlLDrivers : Retrieval Plugin" << std::endl;
59 #endif
60     static Handle (Standard_Transient) model_rd =
61       new XmlLDrivers_DocumentRetrievalDriver ();
62     return model_rd;
63   }
64  
65   throw Standard_Failure("XmlLDrivers : unknown GUID");
66 }
67
68 #define SLENGTH 80
69 //=======================================================================
70 //function : CreationDate
71 //purpose  : mm/dd/yy
72 //=======================================================================
73 TCollection_AsciiString XmlLDrivers::CreationDate ()
74 {
75   Standard_Character nowstr[SLENGTH];
76   time_t nowbin;
77   struct tm *nowstruct;
78
79   if (time(&nowbin) == (time_t) - 1)
80   {
81 #ifdef OCCT_DEBUG
82     std::cerr << "Storage ERROR : Could not get time of day from time()" << std::endl;
83 #endif
84   }
85   
86   nowstruct = localtime(&nowbin);
87   
88   if (strftime(nowstr, SLENGTH, "%Y-%m-%d", nowstruct) == (size_t) 0)
89   {
90 #ifdef OCCT_DEBUG
91     std::cerr << "Storage ERROR : Could not get string from strftime()" << std::endl;
92 #endif
93   }
94
95   return nowstr;
96 }
97
98 //=======================================================================
99 //function : DefineFormat
100 //purpose  : 
101 //=======================================================================
102 void XmlLDrivers::DefineFormat (const Handle(TDocStd_Application)& theApp)
103 {
104   theApp->DefineFormat ("XmlLOcaf", "Xml Lite OCAF Document", "xmll",
105                         new XmlLDrivers_DocumentRetrievalDriver, 
106                         new XmlLDrivers_DocumentStorageDriver ("Copyright: Open Cascade, 2001-2002"));
107 }
108
109 //=======================================================================
110 //function : AttributeDrivers
111 //purpose  : 
112 //=======================================================================
113 Handle(XmlMDF_ADriverTable) XmlLDrivers::AttributeDrivers
114                 (const Handle(Message_Messenger)& theMessageDriver)
115 {
116   Handle(XmlMDF_ADriverTable) aTable = new XmlMDF_ADriverTable();
117   //
118   XmlMDF        ::AddDrivers (aTable, theMessageDriver);
119   XmlMDataStd   ::AddDrivers (aTable, theMessageDriver);
120   XmlMFunction  ::AddDrivers (aTable, theMessageDriver);
121   XmlMDocStd    ::AddDrivers (aTable, theMessageDriver); 
122   //
123   return aTable;
124 }
125
126 //=======================================================================
127 //function : StorageVersion
128 //purpose  : Document storage version
129 //=======================================================================
130
131 int XmlLDrivers::StorageVersion()
132 {
133   return CURRENT_DOCUMENT_VERSION;
134 }
135
136 // Declare entry point PLUGINFACTORY
137 PLUGIN(XmlLDrivers)