0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / PCDM / PCDM.cxx
1 // Created on: 1997-11-05
2 // Created by: Jean-Louis Frenkel
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <CDM_Application.hxx>
19 #include <CDM_Document.hxx>
20 #include <FSD_BinaryFile.hxx>
21 #include <FSD_CmpFile.hxx>
22 #include <FSD_File.hxx>
23 #include <PCDM.hxx>
24 #include <PCDM_StorageDriver.hxx>
25 #include <Plugin.hxx>
26 #include <Resource_Manager.hxx>
27 #include <Standard_GUID.hxx>
28 #include <Standard_NoSuchObject.hxx>
29 #include <Standard_SStream.hxx>
30 #include <Storage_Schema.hxx>
31 #include <TCollection_AsciiString.hxx>
32 #include <TCollection_ExtendedString.hxx>
33 #include <UTL.hxx>
34
35 //=======================================================================
36 //function : FileDriverType
37 //purpose  : 
38 //=======================================================================
39
40 PCDM_TypeOfFileDriver PCDM::FileDriverType(const TCollection_AsciiString& aFileName, Handle(Storage_BaseDriver)& aBaseDriver)
41 {
42   if(FSD_CmpFile::IsGoodFileType(aFileName) == Storage_VSOk) {
43     aBaseDriver=new FSD_CmpFile;
44     return PCDM_TOFD_CmpFile;
45   }
46   else if(FSD_File::IsGoodFileType(aFileName) == Storage_VSOk) {
47     aBaseDriver=new FSD_File;
48     return PCDM_TOFD_File;
49   }
50   else if(FSD_BinaryFile::IsGoodFileType(aFileName) == Storage_VSOk) {
51     aBaseDriver=new FSD_BinaryFile;
52     return PCDM_TOFD_File;
53   }
54   else {
55     aBaseDriver=NULL;
56     return PCDM_TOFD_Unknown;
57   }
58 }
59
60 //=======================================================================
61 //function : FileDriverType
62 //purpose  : 
63 //=======================================================================
64
65 PCDM_TypeOfFileDriver PCDM::FileDriverType (Standard_IStream& theIStream, Handle(Storage_BaseDriver)& theBaseDriver)
66 {
67   TCollection_AsciiString aReadMagicNumber;
68
69   // read magic number from the file
70   if (theIStream.good())
71   {
72     aReadMagicNumber = Storage_BaseDriver::ReadMagicNumber (theIStream);
73   }
74
75   if(aReadMagicNumber == FSD_CmpFile::MagicNumber())
76   {
77     theBaseDriver = new FSD_CmpFile;
78     return PCDM_TOFD_CmpFile;
79   }
80   else if (aReadMagicNumber == FSD_File::MagicNumber())
81   {
82     theBaseDriver = new FSD_File;
83     return PCDM_TOFD_File;
84   }
85   else if (aReadMagicNumber == FSD_BinaryFile::MagicNumber())
86   {
87     theBaseDriver = new FSD_BinaryFile;
88     return PCDM_TOFD_File;
89   }
90   else if (aReadMagicNumber.Search ("<?xml") != -1)
91   {
92     // skip xml declaration
93     char aChar = ' ';
94     while (theIStream.good() && !theIStream.eof() && aChar != '>')
95     {
96       theIStream.get(aChar);
97     }
98
99     return PCDM_TOFD_XmlFile;
100   }
101
102   theBaseDriver = NULL;
103   return PCDM_TOFD_Unknown;
104 }
105