Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:05

0001 // Created on: 2000-08-15
0002 // Created by: Andrey BETENEV
0003 // Copyright (c) 2000-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _STEPCAFControl_Reader_HeaderFile
0017 #define _STEPCAFControl_Reader_HeaderFile
0018 
0019 #include <STEPControl_Reader.hxx>
0020 #include <IFSelect_ReturnStatus.hxx>
0021 #include <TDF_LabelSequence.hxx>
0022 #include <TopTools_MapOfShape.hxx>
0023 #include <STEPCAFControl_DataMapOfShapePD.hxx>
0024 #include <STEPCAFControl_DataMapOfPDExternFile.hxx>
0025 #include <XCAFDoc_DataMapOfShapeLabel.hxx>
0026 #include <TColStd_HSequenceOfTransient.hxx>
0027 #include <XCAFDimTolObjects_DatumModifiersSequence.hxx>
0028 #include <XCAFDimTolObjects_DatumModifWithValue.hxx>
0029 
0030 class XSControl_WorkSession;
0031 class TDocStd_Document;
0032 class STEPCAFControl_ExternFile;
0033 class TopoDS_Shape;
0034 class XCAFDoc_ShapeTool;
0035 class StepRepr_RepresentationItem;
0036 class Transfer_TransientProcess;
0037 class StepShape_ConnectedFaceSet;
0038 class StepRepr_NextAssemblyUsageOccurrence;
0039 class STEPConstruct_Tool;
0040 class StepDimTol_Datum;
0041 class StepData_Factors;
0042 
0043 
0044 //! Provides a tool to read STEP file and put it into
0045 //! DECAF document. Besides transfer of shapes (including
0046 //! assemblies) provided by STEPControl, supports also
0047 //! colors and part names
0048 //!
0049 //! This reader supports reading files with external references
0050 //! i.e. multifile reading
0051 //! It behaves as usual Reader (from STEPControl) for the main
0052 //! file (e.g. if it is single file)
0053 //! Results of reading other files can be accessed by name of the
0054 //! file or by iterating on a readers
0055 class STEPCAFControl_Reader 
0056 {
0057 public:
0058 
0059   DEFINE_STANDARD_ALLOC
0060 
0061   
0062   //! Creates a reader with an empty
0063   //! STEP model and sets ColorMode, LayerMode, NameMode and
0064   //! PropsMode to Standard_True.
0065   Standard_EXPORT STEPCAFControl_Reader();
0066   
0067   //! Creates a reader tool and attaches it to an already existing Session
0068   //! Clears the session if it was not yet set for STEP
0069   Standard_EXPORT STEPCAFControl_Reader(const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch = Standard_True);
0070 
0071   //! Destructor.
0072   Standard_EXPORT virtual ~STEPCAFControl_Reader();
0073 
0074   //! Clears the internal data structures and attaches to a new session
0075   //! Clears the session if it was not yet set for STEP
0076   Standard_EXPORT void Init (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch = Standard_True);
0077 
0078   //! Loads a file and returns the read status
0079   //! Provided for use like single-file reader.
0080   //! @param theFileName [in] file to open
0081   //! @return read status
0082   Standard_EXPORT IFSelect_ReturnStatus ReadFile (const Standard_CString theFileName);
0083 
0084   //! Loads a file and returns the read status
0085   //! Provided for use like single-file reader.
0086   //! @param theFileName [in] file to open
0087   //! @param theParams [in] default configuration parameters
0088   //! @return read status
0089   Standard_EXPORT IFSelect_ReturnStatus ReadFile(const Standard_CString theFileName,
0090                                                  const StepData_ConfParameters& theParams);
0091 
0092   //! Loads a file from stream and returns the read status.
0093   //! @param theName [in] auxiliary stream name
0094   //! @param theIStream [in] stream to read from
0095   //! @return read status
0096   Standard_EXPORT IFSelect_ReturnStatus ReadStream (const Standard_CString theName,
0097                                                     std::istream& theIStream);
0098 
0099   //! Returns number of roots recognized for transfer
0100   //! Shortcut for Reader().NbRootsForTransfer()
0101   Standard_EXPORT Standard_Integer NbRootsForTransfer();
0102   
0103   //! Translates currently loaded STEP file into the document
0104   //! Returns True if succeeded, and False in case of fail
0105   //! Provided for use like single-file reader
0106   Standard_EXPORT Standard_Boolean TransferOneRoot (const Standard_Integer num,
0107                                                     const Handle(TDocStd_Document)& doc,
0108                                                     const Message_ProgressRange& theProgress = Message_ProgressRange());
0109   
0110   //! Translates currently loaded STEP file into the document
0111   //! Returns True if succeeded, and False in case of fail
0112   //! Provided for use like single-file reader
0113   Standard_EXPORT Standard_Boolean Transfer (const Handle(TDocStd_Document)& doc,
0114                                              const Message_ProgressRange& theProgress = Message_ProgressRange());
0115   
0116   Standard_EXPORT Standard_Boolean Perform (const TCollection_AsciiString& filename,
0117                                             const Handle(TDocStd_Document)& doc,
0118                                             const Message_ProgressRange& theProgress = Message_ProgressRange());
0119 
0120   Standard_EXPORT Standard_Boolean Perform (const TCollection_AsciiString& filename,
0121                                             const Handle(TDocStd_Document)& doc,
0122                                             const StepData_ConfParameters& theParams,
0123                                             const Message_ProgressRange& theProgress = Message_ProgressRange());
0124  
0125   //! Translate STEP file given by filename into the document
0126   //! Return True if succeeded, and False in case of fail
0127   Standard_EXPORT Standard_Boolean Perform (const Standard_CString filename,
0128                                             const Handle(TDocStd_Document)& doc,
0129                                             const Message_ProgressRange& theProgress = Message_ProgressRange());
0130 
0131   //! Translate STEP file given by filename into the document
0132   //! Return True if succeeded, and False in case of fail
0133   Standard_EXPORT Standard_Boolean Perform (const Standard_CString filename,
0134                                             const Handle(TDocStd_Document)& doc,
0135                                             const StepData_ConfParameters& theParams,
0136                                             const Message_ProgressRange& theProgress = Message_ProgressRange());
0137   
0138   //! Returns data on external files
0139   //! Returns Null handle if no external files are read
0140   Standard_EXPORT const NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> & ExternFiles() const;
0141   
0142   //! Returns data on external file by its name
0143   //! Returns False if no external file with given name is read
0144   Standard_EXPORT Standard_Boolean ExternFile (const Standard_CString name, Handle(STEPCAFControl_ExternFile)& ef) const;
0145   
0146   //! Returns basic reader
0147   Standard_EXPORT STEPControl_Reader& ChangeReader();
0148   
0149   //! Returns basic reader as const
0150   Standard_EXPORT const STEPControl_Reader& Reader() const;
0151   
0152   //! Returns label of instance of an assembly component
0153   //! corresponding to a given NAUO
0154   Standard_EXPORT static TDF_Label FindInstance
0155                 (const Handle(StepRepr_NextAssemblyUsageOccurrence)& NAUO, 
0156                  const Handle(XCAFDoc_ShapeTool)& STool,
0157                  const STEPConstruct_Tool& Tool, 
0158                  const XCAFDoc_DataMapOfShapeLabel& ShapeLabelMap);
0159   
0160   //! Set ColorMode for indicate read Colors or not.
0161   Standard_EXPORT void SetColorMode (const Standard_Boolean colormode);
0162   
0163   Standard_EXPORT Standard_Boolean GetColorMode() const;
0164   
0165   //! Set NameMode for indicate read Name or not.
0166   Standard_EXPORT void SetNameMode (const Standard_Boolean namemode);
0167   
0168   Standard_EXPORT Standard_Boolean GetNameMode() const;
0169 
0170   //! Set LayerMode for indicate read Layers or not.
0171   Standard_EXPORT void SetLayerMode (const Standard_Boolean layermode);
0172   
0173   Standard_EXPORT Standard_Boolean GetLayerMode() const;
0174   
0175   //! PropsMode for indicate read Validation properties or not.
0176   Standard_EXPORT void SetPropsMode (const Standard_Boolean propsmode);
0177   
0178   Standard_EXPORT Standard_Boolean GetPropsMode() const;
0179   
0180   //! Set SHUO mode for indicate write SHUO or not.
0181   Standard_EXPORT void SetSHUOMode (const Standard_Boolean shuomode);
0182   
0183   Standard_EXPORT Standard_Boolean GetSHUOMode() const;
0184   
0185   //! Set GDT mode for indicate write GDT or not.
0186   Standard_EXPORT void SetGDTMode (const Standard_Boolean gdtmode);
0187   
0188   Standard_EXPORT Standard_Boolean GetGDTMode() const;
0189   
0190   //! Set Material mode
0191   Standard_EXPORT void SetMatMode (const Standard_Boolean matmode);
0192   
0193   Standard_EXPORT Standard_Boolean GetMatMode() const;
0194   
0195   //! Set View mode
0196   Standard_EXPORT void SetViewMode(const Standard_Boolean viewmode);
0197 
0198   //! Get View mode
0199   Standard_EXPORT Standard_Boolean GetViewMode() const;
0200 
0201   const XCAFDoc_DataMapOfShapeLabel& GetShapeLabelMap() const { return myMap; }
0202 
0203 protected:
0204 
0205   
0206   //! Translates STEP file already loaded into the reader
0207   //! into the document
0208   //! If num==0, translates all roots, else only root number num
0209   //! Returns True if succeeded, and False in case of fail
0210   //! If asOne is True, in case of multiple results composes
0211   //! them into assembly. Fills sequence of produced labels
0212   Standard_EXPORT Standard_Boolean Transfer (STEPControl_Reader& rd,
0213                                              const Standard_Integer num,
0214                                              const Handle(TDocStd_Document)& doc,
0215                                              TDF_LabelSequence& Lseq,
0216                                              const Standard_Boolean asOne = Standard_False,
0217                                              const Message_ProgressRange& theProgress = Message_ProgressRange());
0218   
0219   //! Add a shape to a document
0220   //! Depending on a case, this shape can be added as one, or
0221   //! as assembly, or (in case if it is associated with external
0222   //! reference) taken as that referred shape
0223   Standard_EXPORT TDF_Label AddShape (const TopoDS_Shape& S, const Handle(XCAFDoc_ShapeTool)& STool, const TopTools_MapOfShape& NewShapesMap, const STEPCAFControl_DataMapOfShapePD& ShapePDMap, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap);
0224   
0225   //! Reads (or if returns already read) extern file with
0226   //! given name
0227   Standard_EXPORT Handle(STEPCAFControl_ExternFile) ReadExternFile (const Standard_CString file,
0228                                                                     const Standard_CString fullpath,
0229                                                                     const Handle(TDocStd_Document)& doc,
0230                                    const Message_ProgressRange& theProgress = Message_ProgressRange());
0231   
0232   //! Reads style assignments from STEP model and sets
0233   //! corresponding color assignments in the DECAF document
0234   Standard_EXPORT Standard_Boolean ReadColors
0235                 (const Handle(XSControl_WorkSession)& WS,
0236                  const Handle(TDocStd_Document)& doc,
0237                  const StepData_Factors& theLocalFactors) const;
0238   
0239   //! Reads names of parts defined in the STEP model and
0240   //! assigns them to corresponding labels in the DECAF document
0241   Standard_EXPORT Standard_Boolean ReadNames (const Handle(XSControl_WorkSession)& WS, const Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const;
0242   
0243   //! Reads validation properties assigned to shapes in the STEP
0244   //! model and assigns them to corresponding labels in the DECAF
0245   //! document
0246   Standard_EXPORT Standard_Boolean ReadValProps (const Handle(XSControl_WorkSession)& WS,
0247                                                  const Handle(TDocStd_Document)& doc,
0248                                                  const STEPCAFControl_DataMapOfPDExternFile& PDFileMap,
0249                                                  const StepData_Factors& theLocalFactors) const;
0250   
0251   //! Reads layers of parts defined in the STEP model and
0252   //! set reference between shape and layers in the DECAF document
0253   Standard_EXPORT Standard_Boolean ReadLayers (const Handle(XSControl_WorkSession)& WS, const Handle(TDocStd_Document)& doc) const;
0254   
0255   //! Reads SHUO for instances defined in the STEP model and
0256   //! set reference between shape instances from different assemblyes
0257   Standard_EXPORT Standard_Boolean ReadSHUOs (const Handle(XSControl_WorkSession)& WS, const Handle(TDocStd_Document)& doc, const STEPCAFControl_DataMapOfPDExternFile& PDFileMap) const;
0258   
0259   //! Reads D&GT for instances defined in the STEP model and
0260   //! set reference between shape instances from different assemblyes
0261   Standard_EXPORT Standard_Boolean ReadGDTs (const Handle(XSControl_WorkSession)& WS,
0262                                              const Handle(TDocStd_Document)& doc,
0263                                              const StepData_Factors& theLocalFactors);
0264   
0265   //! Reads materials for instances defined in the STEP model and
0266   //! set reference between shape instances from different assemblyes
0267   Standard_EXPORT Standard_Boolean ReadMaterials (const Handle(XSControl_WorkSession)& WS,
0268                                                   const Handle(TDocStd_Document)& doc,
0269                                                   const Handle(TColStd_HSequenceOfTransient)& SeqPDS,
0270                                                   const StepData_Factors& theLocalFactors) const;
0271   
0272   //! Reads Views for instances defined in the STEP model
0273   Standard_EXPORT Standard_Boolean ReadViews(const Handle(XSControl_WorkSession)& theWS,
0274                                              const Handle(TDocStd_Document)& theDoc,
0275                                              const StepData_Factors& theLocalFactors) const;
0276 
0277   //! Populates the sub-Label of the passed TDF Label with shape
0278   //! data associated with the given STEP Representation Item,
0279   //! including naming and topological information.
0280   Standard_EXPORT TDF_Label SettleShapeData (const Handle(StepRepr_RepresentationItem)& theItem, const TDF_Label& theLab, const Handle(XCAFDoc_ShapeTool)& theShapeTool, const Handle(Transfer_TransientProcess)& theTP) const;
0281   
0282   //! Given the maps of already translated shapes, this method
0283   //! expands their correspondent Labels in XDE Document so that
0284   //! to have a dedicated sub-Label for each sub-shape coming
0285   //! with associated name in its STEP Representation Item.
0286   Standard_EXPORT void ExpandSubShapes (const Handle(XCAFDoc_ShapeTool)& theShapeTool, const STEPCAFControl_DataMapOfShapePD& theShapePDMap) const;
0287   
0288   //! Expands the topological structure of Manifold Solid BRep
0289   //! STEP entity to OCAF sub-tree. Entities having no names
0290   //! associated via their Representation Items are skipped.
0291   Standard_EXPORT void ExpandManifoldSolidBrep (TDF_Label& theLab, const Handle(StepRepr_RepresentationItem)& theItem, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const;
0292   
0293   //! Expands the topological structure of Shell-Based Surface
0294   //! Model STEP entity to OCAF sub-tree. Entities having no names
0295   //! associated via their Representation Items are skipped.
0296   Standard_EXPORT void ExpandSBSM (TDF_Label& theLab, const Handle(StepRepr_RepresentationItem)& theItem, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const;
0297   
0298   //! Expands STEP Shell structure to OCAF sub-tree. Entities
0299   //! having no names associated via their Representation Items
0300   //! are skipped.
0301   Standard_EXPORT void ExpandShell (const Handle(StepShape_ConnectedFaceSet)& theShell, TDF_Label& theLab, const Handle(Transfer_TransientProcess)& theTP, const Handle(XCAFDoc_ShapeTool)& theShapeTool) const;
0302 
0303   //! Convert name into UNICODE text.
0304   Standard_EXPORT virtual TCollection_ExtendedString convertName (const TCollection_AsciiString& theName) const;
0305 
0306 private:
0307 
0308   //! Internal method. Import all Datum attributes and set them to XCAF object. Set connection of Datum to GeomTolerance (theGDTL).
0309   Standard_Boolean setDatumToXCAF(const Handle(StepDimTol_Datum)& theDat,
0310     const TDF_Label theGDTL,
0311     const Standard_Integer thePositionCounter,
0312     const XCAFDimTolObjects_DatumModifiersSequence& theXCAFModifiers,
0313     const XCAFDimTolObjects_DatumModifWithValue theXCAFModifWithVal,
0314     const Standard_Real theModifValue,
0315     const Handle(TDocStd_Document)& theDoc,
0316     const Handle(XSControl_WorkSession)& theWS,
0317     const StepData_Factors& theLocalFactors);
0318   
0319   //! Internal method. Read Datums, connected to GeomTolerance theGDTL.
0320   Standard_Boolean readDatumsAP242(const Handle(Standard_Transient)& theEnt,
0321     const TDF_Label theGDTL,
0322     const Handle(TDocStd_Document)& theDoc,
0323     const Handle(XSControl_WorkSession)& theWS,
0324     const StepData_Factors& theLocalFactors);
0325 
0326   //! Internal method. Read Dimension or GeomTolerance.
0327   TDF_Label createGDTObjectInXCAF(const Handle(Standard_Transient)& theEnt,
0328     const Handle(TDocStd_Document)& theDoc,
0329     const Handle(XSControl_WorkSession)& theWS,
0330     const StepData_Factors& theLocalFactors);
0331 
0332   //! Prepares units for transfer
0333   void prepareUnits(const Handle(StepData_StepModel)& theModel,
0334                     const Handle(TDocStd_Document)& theDoc,
0335                     StepData_Factors& theLocalFactors) const;
0336 
0337 private:
0338 
0339   STEPControl_Reader myReader;
0340   NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> myFiles;
0341   XCAFDoc_DataMapOfShapeLabel myMap;
0342   Standard_Boolean myColorMode;
0343   Standard_Boolean myNameMode;
0344   Standard_Boolean myLayerMode;
0345   Standard_Boolean myPropsMode;
0346   Standard_Boolean mySHUOMode;
0347   Standard_Boolean myGDTMode;
0348   Standard_Boolean myMatMode;
0349   Standard_Boolean myViewMode;
0350   NCollection_DataMap<Handle(Standard_Transient), TDF_Label> myGDTMap;
0351 
0352 };
0353 
0354 #endif // _STEPCAFControl_Reader_HeaderFile