File indexing completed on 2026-09-15 09:16:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _RWMesh_CafReader_HeaderFile
0016 #define _RWMesh_CafReader_HeaderFile
0017
0018 #include <Message_ProgressRange.hxx>
0019 #include <OSD_OpenFile.hxx>
0020 #include <RWMesh_CoordinateSystemConverter.hxx>
0021 #include <RWMesh_NodeAttributes.hxx>
0022 #include <TCollection_AsciiString.hxx>
0023 #include <NCollection_IndexedDataMap.hxx>
0024 #include <TDF_Label.hxx>
0025 #include <TopoDS_Shape.hxx>
0026 #include <NCollection_Sequence.hxx>
0027
0028 class TDocStd_Document;
0029 class XCAFDoc_ShapeTool;
0030 class XCAFDoc_ColorTool;
0031 class XCAFDoc_VisMaterialTool;
0032
0033
0034 enum RWMesh_CafReaderStatusEx
0035 {
0036 RWMesh_CafReaderStatusEx_NONE = 0,
0037 RWMesh_CafReaderStatusEx_Partial =
0038 0x01,
0039 };
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 class RWMesh_CafReader : public Standard_Transient
0053 {
0054 DEFINE_STANDARD_RTTIEXT(RWMesh_CafReader, Standard_Transient)
0055 public:
0056
0057 struct CafDocumentTools
0058 {
0059 occ::handle<XCAFDoc_ShapeTool> ShapeTool;
0060 occ::handle<XCAFDoc_ColorTool> ColorTool;
0061 occ::handle<XCAFDoc_VisMaterialTool> VisMaterialTool;
0062 NCollection_DataMap<TopoDS_Shape, TDF_Label, TopTools_ShapeMapHasher> ComponentMap;
0063 NCollection_DataMap<TopoDS_Shape, TDF_Label, TopTools_ShapeMapHasher> OriginalShapeMap;
0064 };
0065
0066 public:
0067
0068 Standard_EXPORT RWMesh_CafReader();
0069
0070
0071 Standard_EXPORT ~RWMesh_CafReader() override;
0072
0073
0074 const occ::handle<TDocStd_Document>& Document() const { return myXdeDoc; }
0075
0076
0077
0078 Standard_EXPORT void SetDocument(const occ::handle<TDocStd_Document>& theDoc);
0079
0080
0081 const TCollection_AsciiString& RootPrefix() const { return myRootPrefix; }
0082
0083
0084 void SetRootPrefix(const TCollection_AsciiString& theRootPrefix) { myRootPrefix = theRootPrefix; }
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097 bool ToFillIncompleteDocument() const { return myToFillIncomplete; }
0098
0099
0100 void SetFillIncompleteDocument(bool theToFillIncomplete)
0101 {
0102 myToFillIncomplete = theToFillIncomplete;
0103 }
0104
0105
0106 int MemoryLimitMiB() const { return myMemoryLimitMiB; }
0107
0108
0109 void SetMemoryLimitMiB(int theLimitMiB) { myMemoryLimitMiB = theLimitMiB; }
0110
0111 public:
0112
0113 const RWMesh_CoordinateSystemConverter& CoordinateSystemConverter() const
0114 {
0115 return myCoordSysConverter;
0116 }
0117
0118
0119 void SetCoordinateSystemConverter(const RWMesh_CoordinateSystemConverter& theConverter)
0120 {
0121 myCoordSysConverter = theConverter;
0122 }
0123
0124
0125
0126 double SystemLengthUnit() const { return myCoordSysConverter.OutputLengthUnit(); }
0127
0128
0129
0130 void SetSystemLengthUnit(double theUnits) { myCoordSysConverter.SetOutputLengthUnit(theUnits); }
0131
0132
0133 bool HasSystemCoordinateSystem() const { return myCoordSysConverter.HasOutputCoordinateSystem(); }
0134
0135
0136
0137 const gp_Ax3& SystemCoordinateSystem() const
0138 {
0139 return myCoordSysConverter.OutputCoordinateSystem();
0140 }
0141
0142
0143 void SetSystemCoordinateSystem(const gp_Ax3& theCS)
0144 {
0145 myCoordSysConverter.SetOutputCoordinateSystem(theCS);
0146 }
0147
0148
0149 void SetSystemCoordinateSystem(RWMesh_CoordinateSystem theCS)
0150 {
0151 myCoordSysConverter.SetOutputCoordinateSystem(theCS);
0152 }
0153
0154
0155
0156 double FileLengthUnit() const { return myCoordSysConverter.InputLengthUnit(); }
0157
0158
0159
0160 void SetFileLengthUnit(double theUnits) { myCoordSysConverter.SetInputLengthUnit(theUnits); }
0161
0162
0163 bool HasFileCoordinateSystem() const { return myCoordSysConverter.HasInputCoordinateSystem(); }
0164
0165
0166
0167 const gp_Ax3& FileCoordinateSystem() const { return myCoordSysConverter.InputCoordinateSystem(); }
0168
0169
0170 void SetFileCoordinateSystem(const gp_Ax3& theCS)
0171 {
0172 myCoordSysConverter.SetInputCoordinateSystem(theCS);
0173 }
0174
0175
0176 void SetFileCoordinateSystem(RWMesh_CoordinateSystem theCS)
0177 {
0178 myCoordSysConverter.SetInputCoordinateSystem(theCS);
0179 }
0180
0181 public:
0182
0183
0184 bool Perform(const TCollection_AsciiString& theFile, const Message_ProgressRange& theProgress)
0185 {
0186 std::ifstream aStream;
0187 OSD_OpenStream(aStream, theFile, std::ios_base::in | std::ios_base::binary);
0188 return Perform(aStream, theProgress, theFile);
0189 }
0190
0191
0192 bool Perform(std::istream& theStream,
0193 const Message_ProgressRange& theProgress,
0194 const TCollection_AsciiString& theFile = "")
0195 {
0196 return perform(theStream, theFile, theProgress, false);
0197 }
0198
0199
0200
0201 int ExtraStatus() const { return myExtraStatus; }
0202
0203 public:
0204
0205 Standard_EXPORT TopoDS_Shape SingleShape() const;
0206
0207
0208 const NCollection_IndexedMap<TCollection_AsciiString>& ExternalFiles() const
0209 {
0210 return myExternalFiles;
0211 }
0212
0213
0214 const NCollection_IndexedDataMap<TCollection_AsciiString, TCollection_AsciiString>& Metadata()
0215 const
0216 {
0217 return myMetadata;
0218 }
0219
0220
0221 bool ProbeHeader(const TCollection_AsciiString& theFile,
0222 const Message_ProgressRange& theProgress = Message_ProgressRange())
0223 {
0224 std::ifstream aStream;
0225 OSD_OpenStream(aStream, theFile, std::ios_base::in | std::ios_base::binary);
0226 return ProbeHeader(aStream, theFile, theProgress);
0227 }
0228
0229
0230
0231
0232 bool ProbeHeader(std::istream& theStream,
0233 const TCollection_AsciiString& theFile = "",
0234 const Message_ProgressRange& theProgress = Message_ProgressRange())
0235 {
0236 return perform(theStream, theFile, theProgress, true);
0237 }
0238
0239 protected:
0240
0241
0242
0243
0244
0245 Standard_EXPORT virtual bool perform(const TCollection_AsciiString& theFile,
0246 const Message_ProgressRange& theProgress,
0247 const bool theToProbe);
0248
0249
0250
0251
0252
0253
0254
0255
0256 Standard_EXPORT virtual bool perform(std::istream& theStream,
0257 const TCollection_AsciiString& theFile,
0258 const Message_ProgressRange& theProgress,
0259 const bool theToProbe);
0260
0261
0262 Standard_EXPORT virtual bool performMesh(const TCollection_AsciiString& theFile,
0263 const Message_ProgressRange& theProgress,
0264 const bool theToProbe)
0265 {
0266 std::ifstream aStream;
0267 OSD_OpenStream(aStream, theFile, std::ios_base::in | std::ios_base::binary);
0268 return performMesh(aStream, theFile, theProgress, theToProbe);
0269 }
0270
0271
0272 Standard_EXPORT virtual bool performMesh(std::istream& theStream,
0273 const TCollection_AsciiString& theFile,
0274 const Message_ProgressRange& theProgress,
0275 const bool theToProbe) = 0;
0276
0277
0278 protected:
0279
0280 Standard_EXPORT virtual void fillDocument();
0281
0282
0283 Standard_EXPORT bool addShapeIntoDoc(CafDocumentTools& theTools,
0284 const TopoDS_Shape& theShape,
0285 const TDF_Label& theLabel,
0286 const TCollection_AsciiString& theParentName);
0287
0288
0289 Standard_EXPORT bool addSubShapeIntoDoc(CafDocumentTools& theTools,
0290 const TopoDS_Shape& theShape,
0291 const TDF_Label& theParentLabel);
0292
0293
0294 Standard_EXPORT void setShapeName(const TDF_Label& theLabel,
0295 const TopAbs_ShapeEnum theShapeType,
0296 const TCollection_AsciiString& theName,
0297 const TDF_Label& theParentLabel,
0298 const TCollection_AsciiString& theParentName);
0299
0300
0301 Standard_EXPORT void setShapeStyle(const CafDocumentTools& theTools,
0302 const TDF_Label& theLabel,
0303 const XCAFPrs_Style& theStyle);
0304
0305
0306 Standard_EXPORT void setShapeNamedData(const CafDocumentTools& theTools,
0307 const TDF_Label& theLabel,
0308 const occ::handle<TDataStd_NamedData>& theNameData);
0309
0310
0311 Standard_EXPORT void generateNames(const TCollection_AsciiString& theFile,
0312 const int theRootLower,
0313 const bool theWithSubLabels);
0314
0315
0316
0317 static TCollection_AsciiString shapeTypeToString(TopAbs_ShapeEnum theType)
0318 {
0319 TCollection_AsciiString aString = TopAbs::ShapeTypeToString(theType);
0320 aString.Capitalize();
0321 return aString;
0322 }
0323
0324 protected:
0325 occ::handle<TDocStd_Document> myXdeDoc;
0326
0327 NCollection_IndexedDataMap<TCollection_AsciiString, TCollection_AsciiString>
0328 myMetadata;
0329 NCollection_IndexedMap<TCollection_AsciiString>
0330
0331 myExternalFiles;
0332 TCollection_AsciiString myRootPrefix;
0333 NCollection_Sequence<TopoDS_Shape> myRootShapes;
0334 NCollection_DataMap<TopoDS_Shape, RWMesh_NodeAttributes, TopTools_ShapeMapHasher> myAttribMap;
0335
0336 RWMesh_CoordinateSystemConverter
0337 myCoordSysConverter;
0338 bool myToFillDoc;
0339 bool myToFillIncomplete;
0340
0341 int myMemoryLimitMiB;
0342 int myExtraStatus;
0343 };
0344
0345 #endif