📄 tlmbase.cs
字号:
//#define Test
using System;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
// Creation date: 05.11.2002
// Checked: 30.05.2003
// Author: Otto Mayer (mot@root.ch)
// Version: 1.01
// Report.NET copyright 2002-2004 root-software ag, B黵glen Switzerland - O. Mayer, S. Spirig, R. Gartenmann, all rights reserved
// This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation, version 2.1 of the License.
// This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You
// should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA www.opensource.org/licenses/lgpl-license.html
namespace Root.Reports {
/// <summary>Table Layout Manager Base Class</summary>
/// <remarks>
/// </remarks>
public abstract class TlmBase : LayoutManager, IDisposable {
//----------------------------------------------------------------------------------------------------x
#region TlmBase
//----------------------------------------------------------------------------------------------------x
/// <summary>Report of this table layout manager</summary>
public readonly Report report;
/// <summary>Definition of the default properties of a cell of this table</summary>
public readonly CellDef cellDef;
/// <summary>Definition of the default properties of a cell of this table (VB version)</summary>
public CellDef _cellDef {
get { return cellDef; }
}
/// <summary>Definition of the default properties of a column of this table</summary>
public readonly ColumnDef columnDef;
/// <summary>Definition of the default properties of a column of this table (VB version)</summary>
public ColumnDef _columnDef {
get { return columnDef; }
}
/// <summary>Definition of the default properties of a row of this table</summary>
public readonly RowDef rowDef;
/// <summary>Definition of the default properties of a row of this table (VB version)</summary>
public RowDef _rowDef {
get { return rowDef; }
}
/// <summary>Lines will be shortened by this value.</summary>
/// <remarks>Lines in PDF are sometimes too long.</remarks>
private const Double rLineDelta = 0.0;
/// <summary>Tolerance for comparing coordinates.</summary>
internal const Double rTol = 0.01;
#if (Test)
private const Double rTest = 3;
private PenProp pp_Test;
#else
private const Double rTest = 0;
#endif
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/// <summary>Status of the layout manager</summary>
private enum Status {
/// <summary>Initialization mode</summary>
Init,
/// <summary>Table open</summary>
Open,
/// <summary>Container closed</summary>
Closed
}
/// <summary>Status of the layout manager</summary>
private Status status = Status.Init;
//----------------------------------------------------------------------------------------------------x
/// <summary>Creates a new table layout manager.</summary>
/// <param name="report">Report of this table layout manager</param>
internal TlmBase(Report report) {
this.report = report;
cellDef = new CellDef();
columnDef = new ColumnDef();
rowDef = new RowDef();
#if (Test)
pp_Test = new PenPropMM(report, 0.1, Color.Orange);
#endif
}
//----------------------------------------------------------------------------------------------------x
/// <summary>Checks whether the layout manager status is 'Init'.</summary>
/// <exception cref="ReportException">The layout manager status is not 'Init'</exception>
internal void CheckStatus_Init(String sMsg) {
if (status != Status.Init) {
throw new ReportException("The layout manager must be in initialization mode; " + sMsg);
}
}
//----------------------------------------------------------------------------------------------------x
/// <summary>Checks whether the layout manager is opened.</summary>
/// <exception cref="ReportException">The layout manager status is not 'ContainerOpen'</exception>
internal void CheckStatus_Open(String sMsg) {
if (status != Status.Open) {
throw new ReportException("The layout manager must be opened; " + sMsg);
}
}
#endregion
//----------------------------------------------------------------------------------------------------x
#region Initialization / Definition
//----------------------------------------------------------------------------------------------------x
/// <summary>Array of Column Definition Objects</summary>
internal class AL_TlmColumn : ArrayList {
/// <summary>Creates the array of column definition objects.</summary>
internal AL_TlmColumn() : base(20) {
}
/// <summary>Gets the column definition with the specified index.</summary>
internal new TlmColumn this[Int32 iIndex] {
get { return (TlmColumn)base[iIndex]; }
}
}
/// <summary>Column definition</summary>
internal AL_TlmColumn al_TlmColumn = new AL_TlmColumn();
//----------------------------------------------------------------------------------------------------x
/// <summary>Scales the current width of the columns to the specified width.</summary>
/// <param name="rWidthNew">New width (points, 1/72 inch)</param>
/// <exception cref="ReportException">The layout manager status is not 'Init'</exception>
public void ScaleWidth(Double rWidthNew) {
CheckStatus_Init("the width of the columns cannot be scaled.");
Double rWidthCur = 0;
foreach (TlmColumn col in al_TlmColumn) {
rWidthCur += col.rWidth;
}
Double rScale = rWidthNew / rWidthCur;
foreach (TlmColumn col in al_TlmColumn) {
col.rWidth *= rScale;
}
}
//----------------------------------------------------------------------------------------------------x
/// <summary>Scales the current width of the columns to the specified width (metric version).</summary>
/// <param name="rWidthNewMM">New width (mm)</param>
/// <exception cref="ReportException">The layout manager status is not 'Init'</exception>
public void ScaleWidthMM(Double rWidthNewMM) {
ScaleWidth(RT.rPointFromMM(rWidthNewMM));
}
#endregion
//----------------------------------------------------------------------------------------------------x
#region Table
//----------------------------------------------------------------------------------------------------x
private Double _rWidth = Double.NaN;
/// <summary>Width of the table (points, 1/72 inch)</summary>
public Double rWidth {
get {
if (Double.IsNaN(_rWidth)) {
Double r = 0;
foreach (TlmColumn col in al_TlmColumn) {
r += col.rWidth;
}
return r;
}
return _rWidth;
}
}
/// <summary>Width of the table (mm)</summary>
public Double rWidthMM {
get { return RT.rMMFromPoint(rWidth); }
}
//----------------------------------------------------------------------------------------------------x
/// <summary>The layout manager will be opened.</summary>
public void Open() {
if (status == Status.Open) {
throw new ReportException("The layout manager has been opened already; " +
"it must be in initialization mode or it must have been closed.");
}
if (status == Status.Init) {
// Set position of the columns
aCellCreateType_New = new TlmBase.CellCreateType[al_TlmColumn.Count];
_rWidth = 0;
foreach (TlmColumn col in al_TlmColumn) {
col._rPosX = rWidth;
_rWidth += col.rWidth;
aCellCreateType_New[col.iIndex] = TlmBase.CellCreateType.New;
}
}
Debug.Assert(aTlmRow.iCount == 0);
Debug.Assert(tlmRow_Committed == null);
foreach (TlmColumn col in al_TlmColumn) {
Debug.Assert(col.iRepObjCommitted == 0);
}
status = Status.Open;
CreateNewContainer();
}
//----------------------------------------------------------------------------------------------------x
/// <summary>The layout manager will be closed.</summary>
public void Close() {
if (status == Status.Init || status == Status.Closed) {
return;
}
if (aTlmRow.iCount > 0) {
WriteAll();
}
Debug.Assert(aTlmRow.iCount == 0);
Debug.Assert(tlmRow_Committed == null);
foreach (TlmColumn col in al_TlmColumn) {
Debug.Assert(col.iRepObjCommitted == 0);
}
status = Status.Closed;
}
//----------------------------------------------------------------------------------------------------x
/// <summary>The layout manager will be closed.</summary>
public void Dispose() {
Close();
}
#endregion
//----------------------------------------------------------------------------------------------------x
#region ArrayTlmRow
//----------------------------------------------------------------------------------------------------x
/// <summary>Array of TlmRows</summary>
internal class ArrayTlmRow {
internal ArrayList _al_TlmRow = new ArrayList(20);
internal ArrayList al_TlmRow {
get {
#if (Checked)
DebugTools.CheckMethodCall(new DebugTools.Method[] {
new DebugTools.Method(typeof(TlmBase), "InsertRow"),
new DebugTools.Method(typeof(TlmBase), "RemoveCommittedRowsAndRepObjs"),
new DebugTools.Method(typeof(TlmRow), "get_iIndex"),
new DebugTools.Method(typeof(TlmRow), "set_iIndex")
});
#endif
return _al_TlmRow;
}
}
internal ArrayTlmRow() {
}
internal TlmRow this[Int32 iIndex] {
get { return (TlmRow)_al_TlmRow[iIndex]; }
}
internal Int32 iCount {
get { return _al_TlmRow.Count; }
}
}
/// <summary>Lines will be shortened by this value.</summary>
/// <remarks>Lines in PDF are sometimes too long.</remarks>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -