3c1f9e5d1a23d4da2dbf3b55d1d17474d1e0a6ae
[occt.git] / src / BinDrivers / BinDrivers_DocumentStorageDriver.cxx
1 // Created on: 2002-10-29
2 // Created by: Michael SAZONOV
3 // Copyright (c) 2002-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 #include <BinDrivers_DocumentStorageDriver.hxx>
17
18 #include <BinDrivers.hxx>
19 #include <BinLDrivers_DocumentSection.hxx>
20 #include <BinMDF_ADriver.hxx>
21 #include <BinMDF_ADriverTable.hxx>
22 #include <BinMNaming_NamedShapeDriver.hxx>
23 #include <Message_Messenger.hxx>
24 #include <Standard_ErrorHandler.hxx>
25 #include <Standard_NotImplemented.hxx>
26 #include <Standard_Type.hxx>
27 #include <TCollection_AsciiString.hxx>
28 #include <TNaming_NamedShape.hxx>
29
30 IMPLEMENT_STANDARD_RTTIEXT(BinDrivers_DocumentStorageDriver,BinLDrivers_DocumentStorageDriver)
31
32 //=======================================================================
33 //function : BinDrivers_DocumentStorageDriver
34 //purpose  : Constructor
35 //=======================================================================
36 BinDrivers_DocumentStorageDriver::BinDrivers_DocumentStorageDriver ()
37 {
38 }
39
40 //=======================================================================
41 //function : AttributeDrivers
42 //purpose  :
43 //=======================================================================
44
45 Handle(BinMDF_ADriverTable) BinDrivers_DocumentStorageDriver::AttributeDrivers
46        (const Handle(Message_Messenger)& theMessageDriver)
47 {
48   return BinDrivers::AttributeDrivers (theMessageDriver);
49 }
50
51 //=======================================================================
52 //function : IsWithTriangles
53 //purpose  :
54 //=======================================================================
55 Standard_Boolean BinDrivers_DocumentStorageDriver::IsWithTriangles() const
56 {
57   if (myDrivers.IsNull())
58   {
59     return Standard_False;
60   }
61
62   Handle(BinMDF_ADriver) aDriver;
63   myDrivers->GetDriver (STANDARD_TYPE(TNaming_NamedShape), aDriver);
64   Handle(BinMNaming_NamedShapeDriver) aShapesDriver = Handle(BinMNaming_NamedShapeDriver)::DownCast(aDriver);
65   return !aShapesDriver.IsNull()
66        && aShapesDriver->IsWithTriangles();
67 }
68
69 //=======================================================================
70 //function : SetWithTriangles
71 //purpose  :
72 //=======================================================================
73 void BinDrivers_DocumentStorageDriver::SetWithTriangles (const Handle(Message_Messenger)& theMessageDriver,
74                                                          const Standard_Boolean theWithTriangulation)
75 {
76   if (myDrivers.IsNull())
77   {
78     myDrivers = AttributeDrivers (theMessageDriver);
79   }
80   if (myDrivers.IsNull())
81   {
82     return;
83   }
84
85   Handle(BinMDF_ADriver) aDriver;
86   myDrivers->GetDriver (STANDARD_TYPE(TNaming_NamedShape), aDriver);
87   Handle(BinMNaming_NamedShapeDriver) aShapesDriver = Handle(BinMNaming_NamedShapeDriver)::DownCast(aDriver);
88   if (aShapesDriver.IsNull())
89   {
90     throw Standard_NotImplemented("Internal Error - TNaming_NamedShape is not found!");
91   }
92
93   aShapesDriver->SetWithTriangles (theWithTriangulation);
94 }
95
96 //=======================================================================
97 //function : WriteShapeSection
98 //purpose  : Implements WriteShapeSection
99 //=======================================================================
100 void BinDrivers_DocumentStorageDriver::WriteShapeSection
101                                (BinLDrivers_DocumentSection&   theSection,
102                                 Standard_OStream&              theOS)
103 {
104   const Standard_Size aShapesSectionOffset = (Standard_Size) theOS.tellp();
105   
106   Handle(BinMDF_ADriver) aDriver;
107   if (myDrivers->GetDriver(STANDARD_TYPE(TNaming_NamedShape), aDriver))
108   {
109     try { 
110       OCC_CATCH_SIGNALS
111       Handle(BinMNaming_NamedShapeDriver) aNamedShapeDriver =
112         Handle(BinMNaming_NamedShapeDriver)::DownCast (aDriver);
113       aNamedShapeDriver->WriteShapeSection (theOS);
114     }
115     catch(Standard_Failure const& anException) {
116       TCollection_ExtendedString anErrorStr ("BinDrivers_DocumentStorageDriver, Shape Section :");
117       myMsgDriver->Send (anErrorStr  + anException.GetMessageString(), Message_Fail);
118     }
119   }
120    
121   // Write the section info in the TOC.
122   theSection.Write (theOS, aShapesSectionOffset);
123 }