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_Writer_HeaderFile
0017 #define _STEPCAFControl_Writer_HeaderFile
0018 
0019 #include <MoniTool_DataMapOfShapeTransient.hxx>
0020 #include <NCollection_Vector.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 #include <STEPCAFControl_DataMapOfLabelShape.hxx>
0024 #include <STEPCAFControl_DataMapOfLabelExternFile.hxx>
0025 #include <STEPControl_Writer.hxx>
0026 #include <StepAP242_GeometricItemSpecificUsage.hxx>
0027 #include <StepData_ConfParameters.hxx>
0028 #include <StepDimTol_Datum.hxx>
0029 #include <StepDimTol_GeometricTolerance.hxx>
0030 #include <StepDimTol_HArray1OfDatumSystemOrReference.hxx>
0031 #include <StepRepr_ProductDefinitionShape.hxx>
0032 #include <StepVisual_DraughtingModel.hxx>
0033 #include <StepVisual_HArray1OfPresentationStyleAssignment.hxx>
0034 #include <TDF_LabelSequence.hxx>
0035 #include <TDF_LabelMap.hxx>
0036 #include <XCAFDimTolObjects_GeomToleranceObject.hxx>
0037 
0038 class XSControl_WorkSession;
0039 class TDocStd_Document;
0040 class STEPCAFControl_ExternFile;
0041 class TopoDS_Shape;
0042 class StepData_Factors;
0043 
0044 //! Provides a tool to write DECAF document to the
0045 //! STEP file. Besides transfer of shapes (including
0046 //! assemblies) provided by STEPControl, supports also
0047 //! colors and part names
0048 //!
0049 //! Also supports multifile writing
0050 class STEPCAFControl_Writer
0051 {
0052 public:
0053   DEFINE_STANDARD_ALLOC
0054 
0055 public:
0056 
0057   //! Creates a writer with an empty
0058   //! STEP model and sets ColorMode, LayerMode, NameMode and
0059   //! PropsMode to Standard_True.
0060   Standard_EXPORT STEPCAFControl_Writer();
0061 
0062   //! Creates a reader tool and attaches it to an already existing Session
0063   //! Clears the session if it was not yet set for STEP
0064   //! Clears the internal data structures
0065   Standard_EXPORT STEPCAFControl_Writer(const Handle(XSControl_WorkSession)& theWS,
0066                                         const Standard_Boolean theScratch = Standard_True);
0067 
0068   //! Clears the internal data structures and attaches to a new session
0069   //! Clears the session if it was not yet set for STEP
0070   Standard_EXPORT void Init(const Handle(XSControl_WorkSession)& theWS,
0071                             const Standard_Boolean theScratch = Standard_True);
0072 
0073   //! Writes all the produced models into file
0074   //! In case of multimodel with extern references,
0075   //! filename will be a name of root file, all other files
0076   //! have names of corresponding parts
0077   //! Provided for use like single-file writer
0078   Standard_EXPORT IFSelect_ReturnStatus Write(const Standard_CString theFileName);
0079 
0080   //! Writes all the produced models into the stream.
0081   //! Provided for use like single-file writer
0082   Standard_EXPORT IFSelect_ReturnStatus WriteStream(std::ostream& theStream);
0083 
0084   //! Transfers a document (or single label) to a STEP model
0085   //! The mode of translation of shape is AsIs
0086   //! If multi is not null pointer, it switches to multifile
0087   //! mode (with external refs), and string pointed by <multi>
0088   //! gives prefix for names of extern files (can be empty string)
0089   //! Returns True if translation is OK
0090   Standard_EXPORT Standard_Boolean Transfer(const Handle(TDocStd_Document)& theDoc,
0091                                             const STEPControl_StepModelType theMode = STEPControl_AsIs,
0092                                             const Standard_CString theIsMulti = 0,
0093                                             const Message_ProgressRange& theProgress = Message_ProgressRange());
0094 
0095   //! Transfers a document (or single label) to a STEP model
0096   //! This method uses if need to set parameters avoiding
0097   //! initialization from Interface_Static
0098   //! @param theParams  configuration parameters
0099   //! @param theMode    mode of translation of shape is AsIs
0100   //! @param theIsMulti if multi is not null pointer, it switches to multifile
0101   //!                   mode (with external refs), and string pointed by <multi>
0102   //!                   gives prefix for names of extern files (can be empty string)
0103   //! @param theProgress progress indicator
0104   //! Returns True if translation is OK
0105   Standard_EXPORT Standard_Boolean Transfer(const Handle(TDocStd_Document)& theDoc,
0106                                             const StepData_ConfParameters& theParams,
0107                                             const STEPControl_StepModelType theMode = STEPControl_AsIs,
0108                                             const Standard_CString theIsMulti = 0,
0109                                             const Message_ProgressRange& theProgress = Message_ProgressRange());
0110 
0111   //! Method to transfer part of the document specified by label
0112   Standard_EXPORT Standard_Boolean Transfer(const TDF_Label& theLabel,
0113                                             const STEPControl_StepModelType theMode = STEPControl_AsIs,
0114                                             const Standard_CString theIsMulti = 0,
0115                                             const Message_ProgressRange& theProgress = Message_ProgressRange());
0116 
0117   //! Method to transfer part of the document specified by label
0118   //! This method uses if need to set parameters avoiding
0119   //! initialization from Interface_Static
0120   Standard_EXPORT Standard_Boolean Transfer(const TDF_Label& theLabel,
0121                                             const StepData_ConfParameters& theParams,
0122                                             const STEPControl_StepModelType theMode = STEPControl_AsIs,
0123                                             const Standard_CString theIsMulti = 0,
0124                                             const Message_ProgressRange& theProgress = Message_ProgressRange());
0125 
0126   //! Mehod to writing sequence of root assemblies or part of the file specified by use by one label 
0127   Standard_EXPORT Standard_Boolean Transfer(const TDF_LabelSequence& theLabelSeq,
0128                                             const STEPControl_StepModelType theMode = STEPControl_AsIs,
0129                                             const Standard_CString theIsMulti = 0,
0130                                             const Message_ProgressRange& theProgress = Message_ProgressRange());
0131 
0132   //! Mehod to writing sequence of root assemblies or part of the file specified by use by one label 
0133   //! This method uses if need to set parameters avoiding
0134   //! initialization from Interface_Static
0135   Standard_EXPORT Standard_Boolean Transfer(const TDF_LabelSequence& theLabelSeq,
0136                                             const StepData_ConfParameters& theParams,
0137                                             const STEPControl_StepModelType theMode = STEPControl_AsIs,
0138                                             const Standard_CString theIsMulti = 0,
0139                                             const Message_ProgressRange& theProgress = Message_ProgressRange());
0140 
0141   Standard_EXPORT Standard_Boolean Perform(const Handle(TDocStd_Document)& theDoc,
0142                                            const TCollection_AsciiString& theFileName,
0143                                            const Message_ProgressRange& theProgress = Message_ProgressRange());
0144 
0145   //! Transfers a document and writes it to a STEP file
0146   //! Returns True if translation is OK
0147   Standard_EXPORT Standard_Boolean Perform(const Handle(TDocStd_Document)& theDoc,
0148                                            const Standard_CString theFileName,
0149                                            const Message_ProgressRange& theProgress = Message_ProgressRange());
0150 
0151   //! Transfers a document and writes it to a STEP file
0152   //! This method uses if need to set parameters avoiding
0153   //! initialization from Interface_Static
0154   //! Returns True if translation is OK
0155   Standard_EXPORT Standard_Boolean Perform(const Handle(TDocStd_Document)& theDoc,
0156                                            const Standard_CString theFileName,
0157                                            const StepData_ConfParameters& theParams,
0158                                            const Message_ProgressRange& theProgress = Message_ProgressRange());
0159 
0160   //! Returns data on external files
0161   //! Returns Null handle if no external files are read
0162   const NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>& ExternFiles() const { return myFiles; };
0163 
0164   //! Returns data on external file by its original label
0165   //! Returns False if no external file with given name is read
0166   Standard_EXPORT Standard_Boolean ExternFile(const TDF_Label& theLabel,
0167                                               Handle(STEPCAFControl_ExternFile)& theExtFile) const;
0168 
0169   //! Returns data on external file by its name
0170   //! Returns False if no external file with given name is read
0171   Standard_EXPORT Standard_Boolean ExternFile(const Standard_CString theName,
0172                                               Handle(STEPCAFControl_ExternFile)& theExtFile) const;
0173 
0174   //! Returns basic reader for root file
0175   STEPControl_Writer& ChangeWriter() { return myWriter; }
0176 
0177   //! Returns basic reader as const
0178   const STEPControl_Writer& Writer() const { return myWriter; }
0179 
0180   //! Set ColorMode for indicate write Colors or not.
0181   void SetColorMode(const Standard_Boolean theColorMode) { myColorMode = theColorMode; }
0182 
0183   Standard_Boolean GetColorMode() const { return myColorMode; }
0184 
0185   //! Set NameMode for indicate write Name or not.
0186   void SetNameMode(const Standard_Boolean theNameMode) { myNameMode = theNameMode; }
0187 
0188   Standard_Boolean GetNameMode() const { return myNameMode; }
0189 
0190   //! Set LayerMode for indicate write Layers or not.
0191   void SetLayerMode(const Standard_Boolean theLayerMode) { myLayerMode = theLayerMode; }
0192 
0193   Standard_Boolean GetLayerMode() const { return myLayerMode; }
0194 
0195   //! PropsMode for indicate write Validation properties or not.
0196   void SetPropsMode(const Standard_Boolean thePropsMode) { myPropsMode = thePropsMode; }
0197 
0198   Standard_Boolean GetPropsMode() const { return myPropsMode; }
0199 
0200   //! Set SHUO mode for indicate write SHUO or not.
0201   void SetSHUOMode(const Standard_Boolean theSHUOMode) { mySHUOMode = theSHUOMode; }
0202 
0203   Standard_Boolean GetSHUOMode() const { return mySHUOMode; }
0204 
0205   //! Set dimtolmode for indicate write D&GTs or not.
0206   void SetDimTolMode(const Standard_Boolean theDimTolMode) { myGDTMode = theDimTolMode; };
0207 
0208   Standard_Boolean GetDimTolMode() const { return myGDTMode; }
0209 
0210   //! Set dimtolmode for indicate write D&GTs or not.
0211   void SetMaterialMode(const Standard_Boolean theMaterialMode) { myMatMode = theMaterialMode; }
0212 
0213   Standard_Boolean GetMaterialMode() const { return myMatMode; }
0214 
0215 protected:
0216 
0217   //! Transfers labels to a STEP model
0218   //! Returns True if translation is OK
0219   //! isExternFile setting from transferExternFiles method
0220   Standard_Boolean transfer(STEPControl_Writer& theWriter,
0221                             const TDF_LabelSequence& theLabels,
0222                             const STEPControl_StepModelType theMode = STEPControl_AsIs,
0223                             const Standard_CString theIsMulti = 0,
0224                             const Standard_Boolean isExternFile = Standard_False,
0225                             const Message_ProgressRange& theProgress = Message_ProgressRange());
0226 
0227   //! Parses assembly structure of label L, writes all the simple
0228   //! shapes each to its own file named by name of its label plus
0229   //! prefix
0230   //! Returns shape representing that assembly structure
0231   //! in the form of nested empty compounds (and a sequence of
0232   //! labels which are newly written nodes of this assembly)
0233   TopoDS_Shape transferExternFiles(const TDF_Label& theLabel,
0234                                    const STEPControl_StepModelType theMode,
0235                                    TDF_LabelSequence& theLabelSeq,
0236                                    const StepData_Factors& theLocalFactors,
0237                                    const Standard_CString thePrefix = "",
0238                                    const Message_ProgressRange& theProgress = Message_ProgressRange());
0239 
0240   //! Write external references to STEP
0241   Standard_Boolean writeExternRefs(const Handle(XSControl_WorkSession)& theWS,
0242                                    const TDF_LabelSequence& theLabels) const;
0243 
0244   //! Write colors assigned to specified labels, to STEP model
0245   Standard_Boolean writeColors(const Handle(XSControl_WorkSession)& theWS,
0246                                const TDF_LabelSequence& theLabels);
0247 
0248   //! Write names assigned to specified labels, to STEP model
0249   Standard_Boolean writeNames(const Handle(XSControl_WorkSession)& theWS,
0250                               const TDF_LabelSequence& theLabels) const;
0251 
0252   //! Write D&GTs assigned to specified labels, to STEP model
0253   Standard_Boolean writeDGTs(const Handle(XSControl_WorkSession)& theWS,
0254                              const TDF_LabelSequence& theLabels) const;
0255 
0256   //! Write D&GTs assigned to specified labels, to STEP model, according AP242
0257   Standard_Boolean writeDGTsAP242(const Handle(XSControl_WorkSession)& theWS,
0258                                   const TDF_LabelSequence& theLabels,
0259                                   const StepData_Factors& theLocalFactors);
0260 
0261   //! Write materials assigned to specified labels, to STEP model
0262   Standard_Boolean writeMaterials(const Handle(XSControl_WorkSession)& theWS,
0263                                   const TDF_LabelSequence& theLabels) const;
0264 
0265   //! Write validation properties assigned to specified labels,
0266   //! to STEP model
0267   Standard_Boolean writeValProps(const Handle(XSControl_WorkSession)& theWS,
0268                                  const TDF_LabelSequence& theLabels,
0269                                  const Standard_CString theIsMulti) const;
0270 
0271   //! Write layers assigned to specified labels, to STEP model
0272   Standard_Boolean writeLayers(const Handle(XSControl_WorkSession)& theWS,
0273                                const TDF_LabelSequence& theLabels) const;
0274 
0275   //! Write SHUO assigned to specified component, to STEP model
0276   Standard_Boolean writeSHUOs(const Handle(XSControl_WorkSession)& theWS,
0277                               const TDF_LabelSequence& theLabels);
0278 
0279   //! Finds length units located in root of label
0280   //! If it exists, initializes local length unit from it
0281   //! Else initializes according to Cascade length unit
0282   void prepareUnit(const TDF_Label& theLabel,
0283                    const Handle(StepData_StepModel)& theModel,
0284                    StepData_Factors& theLocalFactors);
0285 
0286   Handle(StepRepr_ShapeAspect) writeShapeAspect(const Handle(XSControl_WorkSession)& theWS,
0287                                                 const TDF_Label theLabel,
0288                                                 const TopoDS_Shape& theShape,
0289                                                 Handle(StepRepr_RepresentationContext)& theRC,
0290                                                 Handle(StepAP242_GeometricItemSpecificUsage)& theGISU);
0291 
0292   void writePresentation(const Handle(XSControl_WorkSession)& theWS,
0293                          const TopoDS_Shape& thePresentation,
0294                          const Handle(TCollection_HAsciiString)& thePrsName,
0295                          const Standard_Boolean theHasSemantic,
0296                          const Standard_Boolean theHasPlane,
0297                          const gp_Ax2& theAnnotationPlane,
0298                          const gp_Pnt& theTextPosition,
0299                          const Handle(Standard_Transient)& theDimension,
0300                          const StepData_Factors& theLocalFactors);
0301 
0302   Handle(StepDimTol_Datum) writeDatumAP242(const Handle(XSControl_WorkSession)& theWS,
0303                                            const TDF_LabelSequence& theShapeL,
0304                                            const TDF_Label& theDatumL,
0305                                            const Standard_Boolean isFirstDTarget,
0306                                            const Handle(StepDimTol_Datum)& theWrittenDatum,
0307                                            const StepData_Factors& theLocalFactors);
0308 
0309   void writeToleranceZone(const Handle(XSControl_WorkSession)& theWS,
0310                           const Handle(XCAFDimTolObjects_GeomToleranceObject)& theObject,
0311                           const Handle(StepDimTol_GeometricTolerance)& theEntity,
0312                           const Handle(StepRepr_RepresentationContext)& theRC);
0313 
0314   void writeGeomTolerance(const Handle(XSControl_WorkSession)& theWS,
0315                           const TDF_LabelSequence& theShapeSeqL,
0316                           const TDF_Label& theGeomTolL,
0317                           const Handle(StepDimTol_HArray1OfDatumSystemOrReference)& theDatumSystem,
0318                           const Handle(StepRepr_RepresentationContext)& theRC,
0319                           const StepData_Factors& theLocalFactors);
0320 
0321 private:
0322 
0323   STEPControl_Writer myWriter;
0324   NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> myFiles;
0325   TDF_LabelMap myRootLabels;
0326   STEPCAFControl_DataMapOfLabelShape myLabels;
0327   STEPCAFControl_DataMapOfLabelExternFile myLabEF;
0328   STEPCAFControl_DataMapOfLabelShape myPureRefLabels;
0329   Standard_Boolean myColorMode;
0330   Standard_Boolean myNameMode;
0331   Standard_Boolean myLayerMode;
0332   Standard_Boolean myPropsMode;
0333   Standard_Boolean mySHUOMode;
0334   MoniTool_DataMapOfShapeTransient myMapCompMDGPR;
0335   Standard_Boolean myGDTMode;
0336   Standard_Boolean myMatMode;
0337   NCollection_Vector<Handle(StepRepr_RepresentationItem)> myGDTAnnotations;
0338   Handle(StepVisual_DraughtingModel) myGDTPresentationDM;
0339   Handle(StepVisual_HArray1OfPresentationStyleAssignment) myGDTPrsCurveStyle;
0340   Handle(StepRepr_ProductDefinitionShape) myGDTCommonPDS;
0341 
0342 };
0343 
0344 #endif // _STEPCAFControl_Writer_HeaderFile