第三部分要介绍的是绘图相关的通用Utility库
1、Constants类定义了绘图相关的很多常数,比如曲线类型(折线、点状线、杆状线、散点、左填充等等)、图道类型、深度单位、图形单位、岩性类型、布局方式类型等等。
代码如下:
public class Constants
{
public const string PREFIX_WC_CLI1 = "8207"; //硫化氢1
public const string PREFIX_WC_CLI2 = "8212"; //甲烷
public const string PREFIX_WC_DPMI1 = "8433";//检查大钩高度
public const string PREFIX_WC_DPMI2 = "8436";//检查钻压
public const string LSS = "LSS";//测井地面系统(logging surface system)
public const string CLI = "CLI";//综合录井仪(comprehensive logging instrument)
public const string DPMI = "DPMI";//钻参仪(drilling parameters monitoring instrument)
public const string DE = "DE";//柴油机( diesel engine)
public const string MWD = "MWD";//MWD
public const string LWD = "LWD";//LWD
public const string CLI_WISCODES = "80_81_82";//综合录井仪集合
public const string DPMI_WISCODES = "70_71_72_84";//钻参仪
public const string MWD_WISCODES = "79";//MWD
public const string LWD_WISCODES = "83";//LWD
public const string DE_WISCODES = "60_61_64_67";//柴油机( diesel engine)
public const int MAX_VIEW_SCALE = 500;
public const int MIN_VIEW_SCALE = 25;
public const int HSCROLL_DEFAULT_WIDTH = 17;//像素
public const float DEPTH_AXIS_SCALE_DEFAULT = 20f;
public const float POINT_HEIGHT = 3f;
public const float POINT_WIDTH = 3f;
public const int MIN_HEIGHT_SHOW_AXIS_LABLE = 60;//像素
public const int POINTER_DEVIATION_SECONDS = 3;//时间曲线鼠标读数误差秒数
public static readonly float MinLaneWidth = PixelUtility.ConvertLogicalSizeToPixel(2.0f, EShapeUnit.Centimeter, true);
public static readonly float MinLaneHeaderHeight = PixelUtility.ConvertLogicalSizeToPixel(1.0f, EShapeUnit.Centimeter, false);
public static readonly float MaxCurveBottomHeight = PixelUtility.ConvertLogicalSizeToPixel(10f, EShapeUnit.Centimeter, false);
public static readonly float TimeAxisScaleDefault = (float)(PixelUtility.Dpi.Y * 10 / 25.4 / 60);
// 无效的曲线值
public const float INVALID_VALUE = -999.25F; //有相应曲线,但采集值无效
public const float INVALID_VALUE1 = -9999.25F; //没有相应曲线
public const float DASHBOARD_MIN_PIERANGELENGTH = 15;
public const float DASHBOARD_MIN_SIZE = 151.1811f;//像素(4厘米)
public const float DIGITBOARD_MIN_WIDTH = 188.9764f;//像素(5厘米)
public const float DIGITBOARD_MIN_HEIGHT = 75.5906f;//像素(2厘米)
public static string AppDataPath
{
get { return CoreUtility.APP_START_PATH + @"Data"; }
}
}
public enum ECanvasRole
{
Single,
Header,
Body,
Footer,
}
/// <summary>
/// Canva Category:
/// 0 - Normal
/// 1 - WireLogging
/// 2 - Time
/// </summary>
public enum ECanvaCategory
{
Blank,
Depth,
Time,
TimeMixture,
}
public enum EActionState
{
None,
Selected, // group selection is active
Moving, // object(s) are moves
ResizingE, // resize east
ResizingW, // resize west
ResizingS, // resize south
ResizingN, // resize north
ResizingNe, // resize east-north
ResizingSe, // resize east-south
ResizingNw, // resize west-north
ResizingSw, // resize west-south
}
public enum EActionMode
{
None,
Select, // group selection is active
Move, // object(s) are moves
Resize,
}
public enum EDirection
{
None = -1,
All = 0,
East,
West,
North,
South,
Ne,
Nw,
Se,
Sw,
Ew,
Sn,
}
public enum EEntityState
{
Unknown = 0,
New,
Modified,
Deleted,
Unchanged,
}
public enum EDrawToolType
{
Pointer,
Rectangle,
Ellipse,
Line,
Polygon,
NumberOfDrawTools
}
public enum ECoordinates
{
None = 0,
Linear,
Logarithm,
}
public enum EDataProvideMethod
{
Online,
Offline,
}
public enum EWatcherMode
{
Monitoring,
Playback
}
public enum ELaneCategroy
{
None = 0,
DepthLane,
TimeLane,
CurveLane,
LithologyLane, //岩性道
TextLane,//文本道
ImageLane, //图片道
AxisLane, //用于坐标刻度标签
}
/// <summary>
/// 图形单位
/// </summary>
public enum EShapeUnit
{
Millimeter, //毫米
Centimeter, //厘米
Pixel, //像素
Inch, //英寸
}
/// <summary>
/// 深度单位
/// </summary>
public enum EDepthUnit
{
Meter, //米
Foot //英尺
}
public enum EAxisLayout
{
LeftOrBelow,
RightOrAbove,
Both
}
/// <summary>
/// 图道插入类别
/// </summary>
public enum ELaneAddMethod
{
PreviousAdd,
BehindAdd,
LastAdd,
FirstAdd,
}
/// <summary>
/// 曲线展示类型
/// </summary>
public enum ECurveStyle
{
/// <summary>
/// 曲线
/// </summary>
[Description("曲线")]
Line,
/// <summary>
/// 阶梯图
/// </summary>
[Description("阶梯图")]
Ladder,
/// <summary>
/// 散点
/// </summary>
[Description("散点")]
Point,
/// <summary>
/// 杆状图
/// </summary>
[Description("杆状图")]
StickPlot,
/// <summary>
/// 散点曲线
/// </summary>
[Description("散点曲线")]
PointLine,
/// <summary>
/// 杆状曲线图
/// </summary>
[Description("杆状曲线")]
StickPlotLine,
/// <summary>
/// 左填充
/// </summary>
[Description("左填充")]
LeftFill,
/// <summary>
/// 右填充
/// </summary>
[Description("右填充")]
RightFill,
/// <summary>
/// 裁剪
/// </summary>
[Description("线间填充")]
ClipFill
}
/// <summary>
/// 曲线超出图道范围后的表现方式
/// </summary>
public enum EOverflowDrawType
{
/// <summary>
/// 图道外展示
/// </summary>
[Description("直绘")]
Visible,
/// <summary>
/// 截取图道区域内内容,只在本图道内显示
/// </summary>
[Description("截峰")]
Hidden,
/// <summary>
/// 截取图道区域内内容,移到图道内显示
/// </summary>
[Description("移峰")]
Move,
/// <summary>
/// 截取图道区域内内容,镜像折合到图道内显示
/// </summary>
[Description("折峰")]
Mirror,
/// <summary>
/// 截取图道区域内内容,增加不同比例显示
/// </summary>
[Description("变比例")]
ChangeScale,
/// <summary>
/// 其它方式
/// </summary>
[Description("其它")]
Other
}
/// <summary>
/// 曲线填充类型
/// </summary>
public enum EFillType
{
/// <summary>
/// 左填充
/// </summary>
Left,
/// <summary>
/// 右填充
/// </summary>
Right,
/// <summary>
/// 线间填充
/// </summary>
Curve,
/// <summary>
/// 默认不填充
/// </summary>
None
}
/// <summary>
/// 曲线展示类型
/// </summary>
public enum EFillBrushType
{
/// <summary>
/// 曲线
/// </summary>
[Description("空白")]
Blank,
/// <summary>
/// 泥岩
/// </summary>
[Description("泥岩")]
Mudstone,
/// <summary>
/// 砂质泥岩
/// </summary>
[Description("砂质泥岩")]
ConglomeraticMudstone,
/// <summary>
/// 砂岩
/// </summary>
[Description("砂岩")]
Gritstone,
/// <summary>
/// 石灰岩
/// </summary>
[Description("石灰岩")]
Limestone,
/// <summary>
/// 泥质灰岩
/// </summary>
[Description("泥质灰岩")]
ChalkyClay ,
/// <summary>
/// 云灰岩
/// </summary>
[Description("云灰岩")]
LimeMudstone,
/// <summary>
/// 白云岩
/// </summary>
[Description("白云岩")]
Dolostone,
/// <summary>
/// 泥质云岩
/// </summary>
[Description("泥质云岩")]
ArgillaceousDolomite,
/// <summary>
/// 油
/// </summary>
[Description("油")]
Oil,
/// <summary>
/// 气
/// </summary>
[Description("气")]
Gas,
/// <summary>
/// 水
/// </summary>
[Description("水")]
Water,
/// <summary>
/// 煤
/// </summary>
[Description("煤")]
Coal
}
/// <summary>
/// 数字表盘数字显示风格
/// </summary>
public enum EDigitStyle
{
[Description("系统默认")]
System,
[Description("LED数字")]
Led,
[Description("自定义风格")]
Custom,
}
/// <summary>
/// 数字表盘排列结构
/// </summary>
public enum EDigitStructure
{
[Description("上下")]
UpDown,
[Description("左右")]
LeftRight,
}
/// <summary>
/// 仪表盘3d指针颜色
/// </summary>
public enum EHandColorStyle
{
[Description("灰色")]
Gray = 0,
[Description("红色")]
Red = 1,
[Description("绿色")]
Green = 2,
[Description("蓝色")]
Blue = 3,
[Description("黄色")]
Yellow = 4,
[Description("紫红色")]
Violet = 5,
[Description("蓝紫色")]
Magenta = 6
};
/// <summary>
/// 仪表盘指针样式类型
/// </summary>
public enum EHandType
{
/// <summary>
/// 3d
/// </summary>
Needle3D,
/// <summary>
/// 普通样式
/// </summary>
Needle2D
}
/// <summary>
/// 容器布局类型
/// </summary>
public enum EContainerLayoutStyle
{
Float,
Flow,
Stack
}
2、Coordinate类主要是定义了图道绘制刻度尺和对数类型坐标系坐标线的方法。
public class LogCoordinate
{
public LogCoordinate(RectangleF axisRectangle, float startFreq, float endFreq)
: this(axisRectangle.Left, axisRectangle.Right, axisRectangle.Top, axisRectangle.Bottom)
{
_startFreq = startFreq;
_endFreq = endFreq;
}
public LogCoordinate(RectangleF axisRectangle)
: this(axisRectangle.Left, axisRectangle.Right, axisRectangle.Top, axisRectangle.Bottom)
{
}
}
3、DrawerUtility类定义了绘制转换相关方法。
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
namespace RST.CGM.Utility
{
public class DrawerUtility
{
public static string FontSizeToNo(float ptSize)
{
public static Brush LoadFillBrush(EFillBrushType brushType)
{
if (brushType == EFillBrushType.Oil)
{
return Brushes.Red;
}
if (brushType == EFillBrushType.Gas)
{
return Brushes.Yellow;
}
return Brushes.White;
}
}
}
4、PixelUtility像素和物理单位转换的方法
public class PixelUtility
{
public static int GetMaxWatcherTimeScope(float axisScale)
{
return ConvertPixelToSeconds(CoreUtility.DGI_MAX_SIZE, axisScale);
}
public static float GetMaxWatcherDepthScope(float axisScale)
{
return ConvertPixelToLogicalSize(CoreUtility.DGI_MAX_SIZE, EShapeUnit.Centimeter, false) * axisScale/100;
}
private static PointF _dpi= PointF.Empty;
public static PointF Dpi
{
get
{
if (_dpi.IsEmpty)
_dpi = GetScreenDpi1();
return _dpi;
}
}
/// <summary>
/// Get screen dpi according to Graphics Object
/// </summary>
/// <returns></returns>
private static PointF GetScreenDpi1()
{
var dpiPonit = PointF.Empty;
using (var graphics = Graphics.FromHwnd(IntPtr.Zero))
{
dpiPonit.X = graphics.DpiX;
dpiPonit.Y = graphics.DpiY;
}
return dpiPonit;
}
/// <summary>
/// Get screen dpi according to Win32_DesktopMonitor
/// </summary>
/// <returns></returns>
public static PointF GetScreenDpi2()
{
***
}
/// <summary>
/// 单位换算,时间单位换算为像素
/// </summary>
/// <returns></returns>
public static int ConvertTimeToPixel(int seconds, float axisScale)
{
return (int)(seconds * axisScale);
}
/// <summary>
/// 单位换算,时间单位换算为像素(浮点)
/// </summary>
/// <returns></returns>
public static float ConvertTimeToPixelF(double seconds,float axisScale)
{
return (float)(seconds * axisScale);
}
/// <summary>
/// 单位换算,深度单位换算为像素
/// </summary>
/// <returns></returns>
public static int ConvertDepthToPixel(double depth, EDepthUnit unit, float axisScale)
{
if (unit == EDepthUnit.Meter)
{
return (int)(depth * 39.3700787 * Dpi.Y / axisScale);
}
return (int)(depth * 12 * Dpi.Y / axisScale);
}
/// <summary>
/// 单位换算,深度单位换算为像素(浮点数)
/// </summary>
/// <returns></returns>
public static float ConvertDepthToPixelF(float depth, EDepthUnit unit, float axisScale)
{
if (unit == EDepthUnit.Meter)
{
return (float)(depth * 39.3700787 * Dpi.Y / axisScale);
}
return depth * 12 * Dpi.Y / axisScale;
}
/// <summary>
/// 单位换算,深度单位换算为像素(高精度)
/// </summary>
/// <returns></returns>
public static int ConvertDepthToPixelD(float depth, EDepthUnit unit, float axisScale)
{
if (unit == EDepthUnit.Meter)
{
return (int)(depth * 39.3700787 * Dpi.Y / axisScale);
}
return (int)(depth * 12 * Dpi.Y / axisScale);
}
/// <summary>
/// 获取2条直线交点位置坐标
/// </summary>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <param name="p3"></param>
/// <param name="p4"></param>
/// <returns></returns>
public static PointF FindCrossPoint(PointF p1, PointF p2, PointF p3, PointF p4)
{
***
}
/// <summary>
/// 单位换算,像素换算为时间单位
/// </summary>
/// <returns></returns>
public static int ConvertPixelToSeconds(float pixels, float axisScale)
{
return (int)Math.Round(pixels / (double)axisScale);
}
/// <summary>
/// 单位换算,像素 换算为 物理长度
/// </summary>
/// <param name="pixels">像素</param>
/// <param name="unit">物理长度单位</param>
/// <param name="isWidth">是否屏幕宽度</param>
/// <returns></returns>
public static float ConvertPixelToLogicalSize(float pixels, EShapeUnit unit, bool isWidth)
{
***
}
/// <summary>
/// 单位换算,物理长度 换算为 像素
/// </summary>
/// <returns></returns>
public static float ConvertLogicalSizeToPixel(float phyLength, EShapeUnit unit, bool isWidth)
{
}
}
}