1 // Created on: 2002-10-29
2 // Created by: Michael SAZONOV
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <BinDrivers_DocumentStorageDriver.hxx>
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>
30 IMPLEMENT_STANDARD_RTTIEXT(BinDrivers_DocumentStorageDriver,BinLDrivers_DocumentStorageDriver)
32 //=======================================================================
33 //function : BinDrivers_DocumentStorageDriver
34 //purpose : Constructor
35 //=======================================================================
36 BinDrivers_DocumentStorageDriver::BinDrivers_DocumentStorageDriver ()
40 //=======================================================================
41 //function : AttributeDrivers
43 //=======================================================================
45 Handle(BinMDF_ADriverTable) BinDrivers_DocumentStorageDriver::AttributeDrivers
46 (const Handle(Message_Messenger)& theMessageDriver)
48 return BinDrivers::AttributeDrivers (theMessageDriver);
51 //=======================================================================
52 //function : IsWithTriangles
54 //=======================================================================
55 Standard_Boolean BinDrivers_DocumentStorageDriver::IsWithTriangles() const
57 if (myDrivers.IsNull())
59 return Standard_False;
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();
69 //=======================================================================
70 //function : SetWithTriangles
72 //=======================================================================
73 void BinDrivers_DocumentStorageDriver::SetWithTriangles (const Handle(Message_Messenger)& theMessageDriver,
74 const Standard_Boolean theWithTriangulation)
76 if (myDrivers.IsNull())
78 myDrivers = AttributeDrivers (theMessageDriver);
80 if (myDrivers.IsNull())
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())
90 throw Standard_NotImplemented("Internal Error - TNaming_NamedShape is not found!");
93 aShapesDriver->SetWithTriangles (theWithTriangulation);
96 //=======================================================================
97 //function : IsWithNormals
99 //=======================================================================
100 Standard_Boolean BinDrivers_DocumentStorageDriver::IsWithNormals() const
102 if (myDrivers.IsNull())
104 return Standard_False;
107 Handle(BinMDF_ADriver) aDriver;
108 myDrivers->GetDriver(STANDARD_TYPE(TNaming_NamedShape), aDriver);
109 Handle(BinMNaming_NamedShapeDriver) aShapesDriver = Handle(BinMNaming_NamedShapeDriver)::DownCast(aDriver);
110 return !aShapesDriver.IsNull()
111 && aShapesDriver->IsWithNormals();
114 //=======================================================================
115 //function : SetWithNormals
117 //=======================================================================
118 void BinDrivers_DocumentStorageDriver::SetWithNormals(const Handle(Message_Messenger)& theMessageDriver,
119 const Standard_Boolean theWithNormals)
121 if (myDrivers.IsNull())
123 myDrivers = AttributeDrivers(theMessageDriver);
125 if (myDrivers.IsNull())
130 Handle(BinMDF_ADriver) aDriver;
131 myDrivers->GetDriver(STANDARD_TYPE(TNaming_NamedShape), aDriver);
132 Handle(BinMNaming_NamedShapeDriver) aShapesDriver = Handle(BinMNaming_NamedShapeDriver)::DownCast(aDriver);
133 if (aShapesDriver.IsNull())
135 throw Standard_NotImplemented("Internal Error - TNaming_NamedShape is not found!");
138 aShapesDriver->SetWithNormals(theWithNormals);
141 //=======================================================================
142 //function : WriteShapeSection
143 //purpose : Implements WriteShapeSection
144 //=======================================================================
145 void BinDrivers_DocumentStorageDriver::WriteShapeSection
146 (BinLDrivers_DocumentSection& theSection,
147 Standard_OStream& theOS,
148 const TDocStd_FormatVersion theDocVer,
149 const Message_ProgressRange& theRange)
151 const Standard_Size aShapesSectionOffset = (Standard_Size) theOS.tellp();
153 Handle(BinMDF_ADriver) aDriver;
154 if (myDrivers->GetDriver(STANDARD_TYPE(TNaming_NamedShape), aDriver))
158 Handle(BinMNaming_NamedShapeDriver) aNamedShapeDriver =
159 Handle(BinMNaming_NamedShapeDriver)::DownCast (aDriver);
160 aNamedShapeDriver->WriteShapeSection (theOS, theDocVer, theRange);
162 catch(Standard_Failure const& anException) {
163 TCollection_ExtendedString anErrorStr ("BinDrivers_DocumentStorageDriver, Shape Section :");
164 myMsgDriver->Send (anErrorStr + anException.GetMessageString(), Message_Fail);
168 // Write the section info in the TOC.
169 theSection.Write (theOS, aShapesSectionOffset, theDocVer);