Class TTextNCFile
The main class to use for writing text files. It automatically synchronizes with the postprocessing system and, when debugging via CLDViewer, allows you to see how the contents of the file change right during the writing process. It also implements the functionality of writing to an arbitrary location in the file (at the beginning or middle, and not just at the end).
Also you can set the desired encoding TextEncoding of the output file.
To use TTextNCFile class just create an instance of it and use WriteLine(String) or Write(String) methods to append some text to the file.
In addition, you can create a new class that inherits from this class. This will allow you to declare your members within the class associated with the given output file, for example, the number of the NC program, a set of registers (NCWord) for formatting and filtering the output, methods for writing specific information, etc.
Implements
Inherited Members
Namespace: SprutTechnology.SCPostprocessor
Assembly: SCPostprocessor.dll
Syntax
public class TTextNCFile : TNCFile, INCBlockOwner
Constructors
TTextNCFile()
Initializes a new instance of TTextNCFile object and assigns TNCFilesManager.Singletone.DefaultNCFilesOwner
as an
Owner.
It assigns UTF-8 without BOM as a desired encoding of the output file (TextEncoding).
Declaration
public TTextNCFile()
TTextNCFile(INCFileOwner)
Initializes a new instance of TTextNCFile object and assigns specified object as an Owner.
It assigns new UTF8Encoding(false)
(UTF-8 without BOM) as a desired encoding of the output file (TextEncoding).
Declaration
public TTextNCFile(INCFileOwner Owner)
Parameters
Type | Name | Description |
---|---|---|
INCFileOwner | Owner | The object that is the owner of the output file formed by the postprocessor. Usually the owner is a postprocessor itself. |
TTextNCFile(INCFileOwner, Encoding)
Initializes a new instance of TTextNCFile object and assigns specified object as an Owner. It expects the encoding of the output text file as an input parameter.
Declaration
public TTextNCFile(INCFileOwner Owner, Encoding encoding)
Parameters
Type | Name | Description |
---|---|---|
INCFileOwner | Owner | The object that is the owner of the output file formed by the postprocessor. Usually the owner is a postprocessor itself. |
System.Text.Encoding | encoding | Desired output file encoding. If it is null then default encoding UTF8 without BOM will be used (TextEncoding). |
TTextNCFile(Encoding)
Initializes a new instance of TTextNCFile object and assigns TNCFilesManager.Singletone.DefaultNCFilesOwner
as an
Owner. It expects the encoding of the output text file as an input parameter (TextEncoding).
Declaration
public TTextNCFile(Encoding encoding)
Parameters
Type | Name | Description |
---|---|---|
System.Text.Encoding | encoding | Desired output file encoding. If it is null then default encoding UTF-8 without BOM will be used. |
Properties
DefaultLabel
A label that specifies the position within the output file to which data will be written by default. If DefaultLabel is "null" then data will be written to the end of the file.
Initial value is "null".
Declaration
public INCLabel DefaultLabel { get; set; }
Property Value
Type | Description |
---|---|
INCLabel |
FileEnd
The label that always points to the end position of this file.
Declaration
public INCLabel FileEnd { get; }
Property Value
Type | Description |
---|---|
INCLabel |
FileStart
The label that always points to the start position of this file.
Declaration
public INCLabel FileStart { get; }
Property Value
Type | Description |
---|---|
INCLabel |
OutputFileName
The file name with a full path where this output file should be saved at the finish.
Declaration
public override string OutputFileName { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Overrides
TextEncoding
Desired encoding of the output file. For example, you can use one of the following variants.
Encoding.GetEncoding("windows-1251")
- with specifying any standard textual name of the encoding.Encoding.UTF8
- UTF-8 with BOM (byte order mark bytes at the start of a file)Encoding.Unicode
- UTF-16 using the little endian byte order.Encoding.BigEndianUnicode
- UTF-16 using the big endian byte order.Encoding.Default
- The default encoding for this .NET implementation.new UTF8Encoding(false)
- UTF-8 without BOM will be used.null
- UTF-8 without BOM will be used.
You can assign TextEncoding not only at the initialization of new instance of TTextNCFile but at any time of postprocessing. It will be applied at the finish of whole postprocessing.
Declaration
public Encoding TextEncoding { get; set; }
Property Value
Type | Description |
---|---|
System.Text.Encoding |
Methods
CreateLabel()
Creates a new label that usually points to the end of the file. If "DefaultLabel" property is not "null" then the new label will point to the same position with it.
Declaration
public INCLabel CreateLabel()
Returns
Type | Description |
---|---|
INCLabel | Returns the new INCLabel object. |
CreateLabel(INCLabel, Int32)
Creates a new label that points to the position in file that is shifted by the specified "charOffset" count relative to the "start" label.
Declaration
public INCLabel CreateLabel(INCLabel start, int charOffset)
Parameters
Type | Name | Description |
---|---|---|
INCLabel | start | The original label, relative to which the new one will be created. |
System.Int32 | charOffset | The count of chars to shift the new label relative to the "start" label. |
Returns
Type | Description |
---|---|
INCLabel | Returns the new INCLabel object. |
Flush()
It should write the buffered in memory data for the output file to a hard drive (to a temporary files, not to the final destination). Usually you don't need to call it manually, the postprocessing system calls it as needed.
Declaration
public override void Flush()
Overrides
Output(String)
Writes the specified string to the file with a line break. If the DefaultLabel property is not "null", then the string will be written to the position this label points to. Otherwise, the text will be written to the end of the file.
Declaration
public void Output(string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | The string you want to write. |
Output(String, INCLabel)
Writes the specified string to the file with a line break. If the "label" parameter is not "null", then the string will be written to the position this label points to. Otherwise, the text will be written to the end of the file.
Declaration
public void Output(string s, INCLabel label)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | The string you want to write. |
INCLabel | label | The label determines position in the file to which the string will be written. |
SaveToFile(String)
This method is called by the system automatically at the most final stage of the postprocessor's work. Here the content of the file should be written from a temporary storage (in memory or temporary file) to the destination file specified in the OutputFileName property.
After this saving the OnFinalizeNCFiles(TNCFilesManager) handler of the postprocessor is called where you can implement some additional actions on the output files.
Declaration
public override void SaveToFile(string fileName)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName | The destination file path. |
Overrides
Write(String)
Writes the specified string to a file. No line break is added. If the DefaultLabel property is not "null", then the string will be written to the position this label points to. Otherwise, the text will be written to the end of the file.
Declaration
public void Write(string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | The string you want to write. |
Write(String, INCLabel)
Writes the specified string to a file. No line break is added. If the "label" parameter is not "null", then the string will be written to the position this label points to. Otherwise, the text will be written to the end of the file.
Declaration
public void Write(string s, INCLabel label)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | The string you want to write. |
INCLabel | label | The label determines position in the file to which the string will be written. |
WriteLine()
Writes a line break to the file.
Declaration
public void WriteLine()
WriteLine(String)
Writes the specified string to the file with a line break. If the DefaultLabel property is not "null", then the string will be written to the position this label points to. Otherwise, the text will be written to the end of the file.
Declaration
public void WriteLine(string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | The string you want to write. |
WriteLine(String, INCLabel)
Writes the specified string to the file with a line break. If the "label" parameter is not "null", then the string will be written to the position this label points to. Otherwise, the text will be written to the end of the file.
Declaration
public void WriteLine(string s, INCLabel label)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | The string you want to write. |
INCLabel | label | The label determines position in the file to which the string will be written. |