b311480e |
1 | // Created on: 2002-10-29 |
2 | // Created by: Michael SAZONOV |
973c2be1 |
3 | // Copyright (c) 2002-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
f1fb0901 |
16 | #include <BinDrivers_DocumentStorageDriver.hxx> |
42cf5bc1 |
17 | |
7fd59977 |
18 | #include <BinDrivers.hxx> |
42cf5bc1 |
19 | #include <BinLDrivers_DocumentSection.hxx> |
7fd59977 |
20 | #include <BinMDF_ADriver.hxx> |
42cf5bc1 |
21 | #include <BinMDF_ADriverTable.hxx> |
7fd59977 |
22 | #include <BinMNaming_NamedShapeDriver.hxx> |
83ae3591 |
23 | #include <Message_Messenger.hxx> |
42cf5bc1 |
24 | #include <Standard_ErrorHandler.hxx> |
f1fb0901 |
25 | #include <Standard_NotImplemented.hxx> |
42cf5bc1 |
26 | #include <Standard_Type.hxx> |
27 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
28 | #include <TNaming_NamedShape.hxx> |
42cf5bc1 |
29 | |
92efcf78 |
30 | IMPLEMENT_STANDARD_RTTIEXT(BinDrivers_DocumentStorageDriver,BinLDrivers_DocumentStorageDriver) |
31 | |
7fd59977 |
32 | //======================================================================= |
33 | //function : BinDrivers_DocumentStorageDriver |
34 | //purpose : Constructor |
35 | //======================================================================= |
7fd59977 |
36 | BinDrivers_DocumentStorageDriver::BinDrivers_DocumentStorageDriver () |
37 | { |
38 | } |
39 | |
40 | //======================================================================= |
41 | //function : AttributeDrivers |
42 | //purpose : |
43 | //======================================================================= |
44 | |
45 | Handle(BinMDF_ADriverTable) BinDrivers_DocumentStorageDriver::AttributeDrivers |
83ae3591 |
46 | (const Handle(Message_Messenger)& theMessageDriver) |
7fd59977 |
47 | { |
48 | return BinDrivers::AttributeDrivers (theMessageDriver); |
49 | } |
50 | |
f1fb0901 |
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 | //======================================================================= |
83ae3591 |
73 | void BinDrivers_DocumentStorageDriver::SetWithTriangles (const Handle(Message_Messenger)& theMessageDriver, |
f1fb0901 |
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 | { |
9775fa61 |
90 | throw Standard_NotImplemented("Internal Error - TNaming_NamedShape is not found!"); |
f1fb0901 |
91 | } |
92 | |
93 | aShapesDriver->SetWithTriangles (theWithTriangulation); |
94 | } |
95 | |
9f45d35b |
96 | //======================================================================= |
97 | //function : IsWithNormals |
98 | //purpose : |
99 | //======================================================================= |
100 | Standard_Boolean BinDrivers_DocumentStorageDriver::IsWithNormals() const |
101 | { |
102 | if (myDrivers.IsNull()) |
103 | { |
104 | return Standard_False; |
105 | } |
106 | |
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(); |
112 | } |
113 | |
114 | //======================================================================= |
115 | //function : SetWithNormals |
116 | //purpose : |
117 | //======================================================================= |
118 | void BinDrivers_DocumentStorageDriver::SetWithNormals(const Handle(Message_Messenger)& theMessageDriver, |
119 | const Standard_Boolean theWithNormals) |
120 | { |
121 | if (myDrivers.IsNull()) |
122 | { |
123 | myDrivers = AttributeDrivers(theMessageDriver); |
124 | } |
125 | if (myDrivers.IsNull()) |
126 | { |
127 | return; |
128 | } |
129 | |
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()) |
134 | { |
135 | throw Standard_NotImplemented("Internal Error - TNaming_NamedShape is not found!"); |
136 | } |
137 | |
138 | aShapesDriver->SetWithNormals(theWithNormals); |
139 | } |
140 | |
7fd59977 |
141 | //======================================================================= |
142 | //function : WriteShapeSection |
143 | //purpose : Implements WriteShapeSection |
144 | //======================================================================= |
145 | void BinDrivers_DocumentStorageDriver::WriteShapeSection |
146 | (BinLDrivers_DocumentSection& theSection, |
6d8f9f4a |
147 | Standard_OStream& theOS, |
9f45d35b |
148 | const TDocStd_FormatVersion theDocVer, |
7e785937 |
149 | const Message_ProgressRange& theRange) |
7fd59977 |
150 | { |
7fd59977 |
151 | const Standard_Size aShapesSectionOffset = (Standard_Size) theOS.tellp(); |
152 | |
aa00364d |
153 | Handle(BinMDF_ADriver) aDriver; |
154 | if (myDrivers->GetDriver(STANDARD_TYPE(TNaming_NamedShape), aDriver)) |
155 | { |
7fd59977 |
156 | try { |
aa00364d |
157 | OCC_CATCH_SIGNALS |
158 | Handle(BinMNaming_NamedShapeDriver) aNamedShapeDriver = |
159 | Handle(BinMNaming_NamedShapeDriver)::DownCast (aDriver); |
9f45d35b |
160 | aNamedShapeDriver->WriteShapeSection (theOS, theDocVer, theRange); |
7fd59977 |
161 | } |
9775fa61 |
162 | catch(Standard_Failure const& anException) { |
83ae3591 |
163 | TCollection_ExtendedString anErrorStr ("BinDrivers_DocumentStorageDriver, Shape Section :"); |
164 | myMsgDriver->Send (anErrorStr + anException.GetMessageString(), Message_Fail); |
7fd59977 |
165 | } |
166 | } |
167 | |
168 | // Write the section info in the TOC. |
716cf4d9 |
169 | theSection.Write (theOS, aShapesSectionOffset, theDocVer); |
7fd59977 |
170 | } |