1 // Created on: 2000-08-15
2 // Created by: Andrey BETENEV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _STEPCAFControl_Writer_HeaderFile
17 #define _STEPCAFControl_Writer_HeaderFile
19 #include <MoniTool_DataMapOfShapeTransient.hxx>
20 #include <NCollection_Vector.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23 #include <STEPCAFControl_DataMapOfLabelShape.hxx>
24 #include <STEPCAFControl_DataMapOfLabelExternFile.hxx>
25 #include <STEPControl_Writer.hxx>
26 #include <StepAP242_GeometricItemSpecificUsage.hxx>
27 #include <StepDimTol_Datum.hxx>
28 #include <StepDimTol_GeometricTolerance.hxx>
29 #include <StepDimTol_HArray1OfDatumSystemOrReference.hxx>
30 #include <StepRepr_ProductDefinitionShape.hxx>
31 #include <StepVisual_DraughtingModel.hxx>
32 #include <StepVisual_HArray1OfPresentationStyleAssignment.hxx>
33 #include <TDF_LabelSequence.hxx>
34 #include <XCAFDimTolObjects_GeomToleranceObject.hxx>
36 class XSControl_WorkSession;
37 class TDocStd_Document;
38 class STEPCAFControl_ExternFile;
41 //! Provides a tool to write DECAF document to the
42 //! STEP file. Besides transfer of shapes (including
43 //! assemblies) provided by STEPControl, supports also
44 //! colors and part names
46 //! Also supports multifile writing
47 class STEPCAFControl_Writer
54 //! Creates a writer with an empty
55 //! STEP model and sets ColorMode, LayerMode, NameMode and
56 //! PropsMode to Standard_True.
57 Standard_EXPORT STEPCAFControl_Writer();
59 //! Creates a reader tool and attaches it to an already existing Session
60 //! Clears the session if it was not yet set for STEP
61 //! Clears the internal data structures
62 Standard_EXPORT STEPCAFControl_Writer(const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch = Standard_True);
64 //! Clears the internal data structures and attaches to a new session
65 //! Clears the session if it was not yet set for STEP
66 Standard_EXPORT void Init (const Handle(XSControl_WorkSession)& WS, const Standard_Boolean scratch = Standard_True);
68 //! Writes all the produced models into file
69 //! In case of multimodel with extern references,
70 //! filename will be a name of root file, all other files
71 //! have names of corresponding parts
72 //! Provided for use like single-file writer
73 Standard_EXPORT IFSelect_ReturnStatus Write (const Standard_CString theFileName);
75 //! Writes all the produced models into the stream.
76 //! Provided for use like single-file writer
77 Standard_EXPORT IFSelect_ReturnStatus WriteStream (std::ostream& theStream);
79 //! Transfers a document (or single label) to a STEP model
80 //! The mode of translation of shape is AsIs
81 //! If multi is not null pointer, it switches to multifile
82 //! mode (with external refs), and string pointed by <multi>
83 //! gives prefix for names of extern files (can be empty string)
84 //! Returns True if translation is OK
85 Standard_EXPORT Standard_Boolean Transfer (const Handle(TDocStd_Document)& doc,
86 const STEPControl_StepModelType mode = STEPControl_AsIs,
87 const Standard_CString multi = 0,
88 const Message_ProgressRange& theProgress = Message_ProgressRange());
90 //! Method to transfer part of the document specified by label
91 Standard_EXPORT Standard_Boolean Transfer (const TDF_Label& L,
92 const STEPControl_StepModelType mode = STEPControl_AsIs,
93 const Standard_CString multi = 0,
94 const Message_ProgressRange& theProgress = Message_ProgressRange());
96 //! Mehod to writing sequence of root assemblies or part of the file specified by use by one label
97 Standard_EXPORT Standard_Boolean Transfer (const TDF_LabelSequence& L,
98 const STEPControl_StepModelType mode = STEPControl_AsIs,
99 const Standard_CString multi = 0,
100 const Message_ProgressRange& theProgress = Message_ProgressRange());
102 Standard_EXPORT Standard_Boolean Perform (const Handle(TDocStd_Document)& doc,
103 const TCollection_AsciiString& filename,
104 const Message_ProgressRange& theProgress = Message_ProgressRange());
106 //! Transfers a document and writes it to a STEP file
107 //! Returns True if translation is OK
108 Standard_EXPORT Standard_Boolean Perform (const Handle(TDocStd_Document)& doc,
109 const Standard_CString filename,
110 const Message_ProgressRange& theProgress = Message_ProgressRange());
112 //! Returns data on external files
113 //! Returns Null handle if no external files are read
114 Standard_EXPORT const NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)>& ExternFiles() const;
116 //! Returns data on external file by its original label
117 //! Returns False if no external file with given name is read
118 Standard_EXPORT Standard_Boolean ExternFile (const TDF_Label& L, Handle(STEPCAFControl_ExternFile)& ef) const;
120 //! Returns data on external file by its name
121 //! Returns False if no external file with given name is read
122 Standard_EXPORT Standard_Boolean ExternFile (const Standard_CString name, Handle(STEPCAFControl_ExternFile)& ef) const;
124 //! Returns basic reader for root file
125 Standard_EXPORT STEPControl_Writer& ChangeWriter();
127 //! Returns basic reader as const
128 Standard_EXPORT const STEPControl_Writer& Writer() const;
130 //! Set ColorMode for indicate write Colors or not.
131 Standard_EXPORT void SetColorMode (const Standard_Boolean colormode);
133 Standard_EXPORT Standard_Boolean GetColorMode() const;
135 //! Set NameMode for indicate write Name or not.
136 Standard_EXPORT void SetNameMode (const Standard_Boolean namemode);
138 Standard_EXPORT Standard_Boolean GetNameMode() const;
140 //! Set LayerMode for indicate write Layers or not.
141 Standard_EXPORT void SetLayerMode (const Standard_Boolean layermode);
143 Standard_EXPORT Standard_Boolean GetLayerMode() const;
145 //! PropsMode for indicate write Validation properties or not.
146 Standard_EXPORT void SetPropsMode (const Standard_Boolean propsmode);
148 Standard_EXPORT Standard_Boolean GetPropsMode() const;
150 //! Set SHUO mode for indicate write SHUO or not.
151 Standard_EXPORT void SetSHUOMode (const Standard_Boolean shuomode);
153 Standard_EXPORT Standard_Boolean GetSHUOMode() const;
155 //! Set dimtolmode for indicate write D>s or not.
156 Standard_EXPORT void SetDimTolMode (const Standard_Boolean dimtolmode);
158 Standard_EXPORT Standard_Boolean GetDimTolMode() const;
160 //! Set dimtolmode for indicate write D>s or not.
161 Standard_EXPORT void SetMaterialMode (const Standard_Boolean matmode);
163 Standard_EXPORT Standard_Boolean GetMaterialMode() const;
167 //! Transfers labels to a STEP model
168 //! Returns True if translation is OK
169 //! isExternFile setting from TransferExternFiles method
170 Standard_EXPORT Standard_Boolean Transfer (STEPControl_Writer& wr,
171 const TDF_LabelSequence& labels,
172 const STEPControl_StepModelType mode = STEPControl_AsIs,
173 const Standard_CString multi = 0,
174 const Standard_Boolean isExternFile = Standard_False,
175 const Message_ProgressRange& theProgress = Message_ProgressRange()) ;
177 //! Parses assembly structure of label L, writes all the simple
178 //! shapes each to its own file named by name of its label plus
180 //! Returns shape representing that assembly structure
181 //! in the form of nested empty compounds (and a sequence of
182 //! labels which are newly written nodes of this assembly)
183 Standard_EXPORT TopoDS_Shape TransferExternFiles (const TDF_Label& L,
184 const STEPControl_StepModelType mode,
185 TDF_LabelSequence& Lseq,
186 const Standard_CString prefix = "",
187 const Message_ProgressRange& theProgress = Message_ProgressRange());
189 //! Write external references to STEP
190 Standard_EXPORT Standard_Boolean WriteExternRefs (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels) const;
192 //! Write colors assigned to specified labels, to STEP model
193 Standard_EXPORT Standard_Boolean WriteColors (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels);
195 //! Write names assigned to specified labels, to STEP model
196 Standard_EXPORT Standard_Boolean WriteNames (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels) const;
198 //! Write D>s assigned to specified labels, to STEP model
199 Standard_EXPORT Standard_Boolean WriteDGTs (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels) const;
201 //! Write D>s assigned to specified labels, to STEP model, according AP242
202 Standard_EXPORT Standard_Boolean WriteDGTsAP242 (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels);
204 //! Write materials assigned to specified labels, to STEP model
205 Standard_EXPORT Standard_Boolean WriteMaterials (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels) const;
207 //! Write validation properties assigned to specified labels,
209 Standard_EXPORT Standard_Boolean WriteValProps (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels, const Standard_CString multi) const;
211 //! Write layers assigned to specified labels, to STEP model
212 Standard_EXPORT Standard_Boolean WriteLayers (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels) const;
214 //! Write SHUO assigned to specified component, to STEP model
215 Standard_EXPORT Standard_Boolean WriteSHUOs (const Handle(XSControl_WorkSession)& WS, const TDF_LabelSequence& labels);
217 //! Finds length units located in root of label
218 //! If it exists, initializes local length unit from it
219 //! Else initializes according to Cascade length unit
220 Standard_EXPORT void prepareUnit(const TDF_Label& theLabel,
221 const Handle(StepData_StepModel)& theModel);
225 Standard_EXPORT Handle(StepRepr_ShapeAspect) WriteShapeAspect(const Handle(XSControl_WorkSession) &WS,
226 const TDF_Label theLabel, const TopoDS_Shape theShape, Handle(StepRepr_RepresentationContext)& theRC,
227 Handle(StepAP242_GeometricItemSpecificUsage)& theGISU);
229 Standard_EXPORT void WritePresentation(const Handle(XSControl_WorkSession)& WS,
230 const TopoDS_Shape& thePresentation,
231 const Handle(TCollection_HAsciiString)& thePrsName,
232 const Standard_Boolean hasSemantic,
233 const Standard_Boolean hasPlane,
234 const gp_Ax2& theAnnotationPlane,
235 const gp_Pnt& theTextPosition,
236 const Handle(Standard_Transient) theDimension);
238 Standard_EXPORT Handle(StepDimTol_Datum) WriteDatumAP242(const Handle(XSControl_WorkSession)& WS,
239 const TDF_LabelSequence& theShapeL,
240 const TDF_Label& theDatumL,
241 const Standard_Boolean isFirstDTarget,
242 const Handle(StepDimTol_Datum) theWrittenDatum);
244 Standard_EXPORT void WriteToleranceZone(const Handle(XSControl_WorkSession) &WS, const Handle(XCAFDimTolObjects_GeomToleranceObject)& theObject,
245 const Handle(StepDimTol_GeometricTolerance)& theEntity, const Handle(StepRepr_RepresentationContext)& theRC);
247 Standard_EXPORT void WriteGeomTolerance(const Handle(XSControl_WorkSession)& WS,
248 const TDF_LabelSequence& theShapeSeqL,
249 const TDF_Label& theGeomTolL,
250 const Handle(StepDimTol_HArray1OfDatumSystemOrReference)& theDatumSystem,
251 const Handle(StepRepr_RepresentationContext)& theRC);
256 STEPControl_Writer myWriter;
257 NCollection_DataMap<TCollection_AsciiString, Handle(STEPCAFControl_ExternFile)> myFiles;
258 STEPCAFControl_DataMapOfLabelShape myLabels;
259 STEPCAFControl_DataMapOfLabelExternFile myLabEF;
260 Standard_Boolean myColorMode;
261 Standard_Boolean myNameMode;
262 Standard_Boolean myLayerMode;
263 Standard_Boolean myPropsMode;
264 Standard_Boolean mySHUOMode;
265 MoniTool_DataMapOfShapeTransient myMapCompMDGPR;
266 Standard_Boolean myGDTMode;
267 Standard_Boolean myMatMode;
268 NCollection_Vector<Handle(StepRepr_RepresentationItem)> myGDTAnnotations;
269 Handle(StepVisual_DraughtingModel) myGDTPresentationDM;
270 Handle(StepVisual_HArray1OfPresentationStyleAssignment) myGDTPrsCurveStyle;
271 Handle(StepRepr_ProductDefinitionShape) myGDTCommonPDS;
278 #endif // _STEPCAFControl_Writer_HeaderFile