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