using Eventech.Model;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using WW.Cad.Base;
|
using WW.Cad.Drawing;
|
using WW.Cad.Drawing.GDI;
|
using WW.Cad.IO;
|
using WW.Cad.Model;
|
using WW.Cad.Model.Entities;
|
using WW.Cad.Model.Tables;
|
using WW.Math;
|
|
namespace TProduct.PumpGraph.Dxf
|
{
|
public class FeatChart
|
{
|
protected short _defaultFeatCurveWidth = 40;//默认曲线宽度
|
protected short _defatulCurveLabelHeight = 8;//曲线上文字的高度
|
protected short _equalCurveParaLabelHeight = 8;//等效线文字高度
|
protected short _equalCurveParaLabelHeight_Offset_X = 0;//等效线文字高度 偏置X
|
protected short _equalCurveParaLabelHeight_Offset_Y = 2;//等效线文字高度 偏置Y
|
|
// 第二刻度
|
public Eventech.Model.CoordAxis2 SecondAxisQ { get; set; }
|
|
public Eventech.Model.CoordAxis2 SecondAxisH { get; set; }
|
|
//各种字体
|
protected DxfTextStyle _axisTextFont = null;//坐标默认字体 可空
|
protected DxfTextStyle _frameTextFont = null;//图框默认字体 可空
|
protected DxfTextStyle _curveTextFont = null;//曲线默认字体 可空
|
|
protected DxfModel _dxfFileModel = null;
|
|
protected string _axisTtileContentQ = "流量";
|
protected string _axisTtileContentH = "扬程";
|
protected string _axisTtileContentE = "效率";
|
protected string _axisTtileContentP = "功率";
|
protected string _axisTtileContentNPSH = "NPSH";
|
|
//文件格式
|
protected Eventech.Model.eFileSuffixType _fileSuffixType = Eventech.Model.eFileSuffixType.DWG;
|
public Eventech.Model.eFileSuffixType FileSuffixType
|
{
|
get { return _fileSuffixType; }
|
set { _fileSuffixType = value; }
|
}
|
|
//如果其他格式时,是否保留DWG文件
|
protected bool _isRetainDwgFile = false;
|
public bool IsRetainDwgFile
|
{
|
get { return _isRetainDwgFile; }
|
set { _isRetainDwgFile = value; }
|
}
|
|
//设计员签名
|
protected string _designUserDrawSignal = "";
|
|
public string DesignUserDrawSignal
|
{
|
get { return _designUserDrawSignal; }
|
set { _designUserDrawSignal = value; }
|
}
|
|
//产品型号
|
protected string _productName = null;
|
|
public string ProductName
|
{
|
get { return _productName; }
|
set { _productName = value; }
|
}
|
|
//产品 系列
|
protected string _seriesName = null;
|
|
public string SeriesName
|
{
|
get { return _seriesName; }
|
set { _seriesName = value; }
|
}
|
|
//产品 类型
|
protected string _catalogName = null;
|
|
public string CatalogName
|
{
|
get { return _catalogName; }
|
set { _catalogName = value; }
|
}
|
|
//产品 别名
|
protected string _kindName = null;
|
|
public string KindName
|
{
|
get { return _kindName; }
|
set { _kindName = value; }
|
}
|
|
//曲线号
|
protected string _curveCode = null;
|
|
public string CurveCode
|
{
|
get { return _curveCode; }
|
set { _curveCode = value; }
|
}
|
|
//公司名
|
protected string _corpFullName = null;
|
|
public string CorpFullName
|
{
|
get { return _corpFullName; }
|
set { _corpFullName = value; }
|
}
|
|
protected bool _isDrawWaterMark = false;
|
|
public bool IsDrawWaterMark
|
{
|
get { return _isDrawWaterMark; }
|
set { _isDrawWaterMark = value; }
|
}
|
|
protected string _waterMarkText = null;
|
|
public string WaterMarkText
|
{
|
get { return _waterMarkText; }
|
set { _waterMarkText = value; }
|
}
|
|
//是否黑白显示
|
protected bool _isMonoColor = false;
|
public bool IsMonoColor
|
{
|
get { return _isMonoColor; }
|
set { _isMonoColor = value; }
|
}
|
|
protected virtual string BuildCadText(string content)
|
{
|
return content;
|
}
|
protected string BuildCadText(Eventech.Model.UnitQ unit)
|
{
|
if (unit == Eventech.Model.UnitQ.M3S)
|
return @"m{{\fArial|b0|i0|c0|p34;³}}/s";
|
else if (unit == Eventech.Model.UnitQ.M3H)
|
return @"m{{\fArial|b0|i0|c0|p34;³}}/h";
|
else
|
return Eventech.Common.UnitQHelper.GetEnUnitName(unit);
|
}
|
protected virtual string BuildCadText_Trim0(string content)
|
{
|
if (content == null)
|
return "";
|
if (content.EndsWith(".0"))
|
{
|
return BuildCadText(content.Replace(".0", ""));
|
}
|
return BuildCadText(content);
|
}
|
protected virtual string Trim0(double vvv)
|
{
|
string content = vvv.ToString();
|
if (content == null)
|
return "";
|
if (content.EndsWith(".0"))
|
{
|
return content.Replace(".0", "");
|
}
|
return content;
|
}
|
//其他参数
|
protected Dictionary<string, string> _dwgObjectDict = null;
|
public Dictionary<string, string> DwgObjectDict
|
{
|
get { return _dwgObjectDict; }
|
set { _dwgObjectDict = value; }
|
}
|
|
//文字
|
protected List<Eventech.Model.AnnoAnchorPoint> _labelTextList = null;
|
|
public List<Eventech.Model.AnnoAnchorPoint> LabelTextList
|
{
|
get { return _labelTextList; }
|
set { _labelTextList = value; }
|
}
|
|
public enum eAxisTitlePosiStyle
|
{
|
Center = 0,
|
Top = 1
|
}
|
|
//纵坐标标题的位置 0表示 中间, 1表示刻度的上面
|
protected eAxisTitlePosiStyle _axisTitlePosiStyleY = eAxisTitlePosiStyle.Center;
|
|
public eAxisTitlePosiStyle AxisTitlePosiStyleY
|
{
|
get { return _axisTitlePosiStyleY; }
|
set { _axisTitlePosiStyleY = value; }
|
}
|
|
|
|
protected ChartCurveLabelHelper theCurveLabelHelper = null;
|
|
protected TProduct.Model.RatedParas4Pump _ratedParas = null;
|
|
protected Eventech.Model.PointToleranceParas _toleranceParas = null;
|
|
public void SetRatedParas(
|
TProduct.Model.RatedParas4Pump ratedParas,
|
List<Model.TestGradeJudgeItem> testJudgeItems)
|
{
|
this._ratedParas = ratedParas;
|
if (ratedParas == null)
|
return;
|
|
_toleranceParas = new PointToleranceParas();
|
var flow_min = testJudgeItems.Find(x => x.TargeType == TProduct.Model.eTestJudgeTargetType.流量 && x.ThresholdType == TProduct.Model.TestGradeJudgeItem.eThresholdType.Min);
|
if (flow_min != null)
|
{
|
_toleranceParas.TolRatioMinQ = flow_min.ThresholdValue;
|
}
|
var flow_max = testJudgeItems.Find(x => x.TargeType == TProduct.Model.eTestJudgeTargetType.流量 && x.ThresholdType == TProduct.Model.TestGradeJudgeItem.eThresholdType.Max);
|
if (flow_max != null)
|
{
|
_toleranceParas.TolRatioMaxQ = flow_max.ThresholdValue;
|
}
|
|
var head_min = testJudgeItems.Find(x => x.TargeType == TProduct.Model.eTestJudgeTargetType.扬程 && x.ThresholdType == TProduct.Model.TestGradeJudgeItem.eThresholdType.Min);
|
if (head_min != null)
|
{
|
_toleranceParas.TolRatioMinH = head_min.ThresholdValue;
|
}
|
var head_max = testJudgeItems.Find(x => x.TargeType == TProduct.Model.eTestJudgeTargetType.扬程 && x.ThresholdType == TProduct.Model.TestGradeJudgeItem.eThresholdType.Max);
|
if (head_max != null)
|
{
|
_toleranceParas.TolRatioMaxH = head_max.ThresholdValue;
|
}
|
|
}
|
|
|
//绘制额定点线
|
protected bool _isDrawRatedParasCurve = true;
|
public bool IsDrawRatedParasCurve
|
{
|
get { return _isDrawRatedParasCurve; }
|
set { _isDrawRatedParasCurve = value; }
|
}
|
|
//绘制额定点文字
|
protected bool _isDrawRatedParasText = true;
|
public bool IsDrawRatedParasText
|
{
|
get { return _isDrawRatedParasText; }
|
set { _isDrawRatedParasText = value; }
|
}
|
|
protected double _ratedN = -1;
|
public double RatedN
|
{
|
get { return _ratedN; }
|
set { _ratedN = value; }
|
}
|
|
protected double _originD2 = -1;
|
public double OriginD2
|
{
|
get { return _originD2; }
|
set { _originD2 = value; }
|
}
|
|
protected double _workSpeed = -1;
|
public double WorkSpeed
|
{
|
get { return _workSpeed; }
|
set { _workSpeed = value; }
|
}
|
|
protected string _inletDia = null;
|
public string InletDia
|
{
|
get { return _inletDia; }
|
set { _inletDia = value; }
|
}
|
|
protected string _outletDia = null;
|
public string OutletDia
|
{
|
get { return _outletDia; }
|
set { _outletDia = value; }
|
}
|
|
protected Eventech.Model.CrossPoint _crossPoint = null;
|
public Eventech.Model.CrossPoint CrossPoint
|
{
|
get { return _crossPoint; }
|
set { _crossPoint = value; }
|
}
|
|
protected bool _isDrawDesignPoint = true;
|
public bool IsDrawDesignPoint
|
{
|
get { return _isDrawDesignPoint; }
|
set { _isDrawDesignPoint = value; }
|
}
|
|
|
|
//单位 (设计点)
|
protected Eventech.Model.UnitH _dpUnitH = Eventech.Model.UnitH.M;
|
public Eventech.Model.UnitH DpUnitH
|
{
|
get { return _dpUnitH; }
|
set { _dpUnitH = value; }
|
}
|
protected Eventech.Model.UnitQ _dpUnitQ = Eventech.Model.UnitQ.M3H;
|
public Eventech.Model.UnitQ DpUnitQ
|
{
|
get { return _dpUnitQ; }
|
set { _dpUnitQ = value; }
|
}
|
//单位(图表)
|
protected Eventech.Model.UnitQ _unitQ = Eventech.Model.UnitQ.M3H;
|
protected Eventech.Model.UnitH _unitH = Eventech.Model.UnitH.M;
|
public Eventech.Model.UnitH UnitH
|
{
|
get { return _unitH; }
|
set { _unitH = value; }
|
}
|
|
public Eventech.Model.UnitQ UnitQ
|
{
|
get { return _unitQ; }
|
set { _unitQ = value; }
|
}
|
|
|
|
//设计点显示方式:注意有的模板此设置无效,有的模板已经固华了显示方式
|
protected Eventech.Model.eDesignPointDispType _designPointDispType = Eventech.Model.eDesignPointDispType.Cross;
|
public Eventech.Model.eDesignPointDispType DesignPointDispType
|
{
|
get { return _designPointDispType; }
|
set { _designPointDispType = value; }
|
}
|
|
//电机功率
|
protected string _motorPower = null;
|
public string MotorPower
|
{
|
get { return _motorPower; }
|
set { _motorPower = value; }
|
}
|
|
//
|
protected Eventech.Model.AnnoAnchorPointList _annoAnchorPointList = null;
|
public Eventech.Model.AnnoAnchorPointList AnnoAnchorPointList
|
{
|
get { return _annoAnchorPointList; }
|
set { _annoAnchorPointList = value; }
|
}
|
|
#region 等效线
|
|
protected Eventech.Model.CombineCurveList _equalParaCurveE = null;
|
public Eventech.Model.CombineCurveList EqualParaCurveE
|
{
|
get { return _equalParaCurveE; }
|
set { _equalParaCurveE = value; }
|
}
|
|
//是否显示等效线
|
protected bool isDispEqualParaCurveE = true;
|
|
public bool IsDispEqualParaCurveE
|
{
|
get { return isDispEqualParaCurveE; }
|
set
|
{
|
isDispEqualParaCurveE = value;
|
isDispEqualParaTextE = value;
|
}
|
}
|
|
//是否显示等效线效率值
|
protected bool isDispEqualParaTextE = true;
|
|
public bool IsDispEqualParaTextE
|
{
|
get { return isDispEqualParaTextE; }
|
set { isDispEqualParaTextE = value; }
|
}
|
|
#endregion 等效线
|
|
//
|
protected WW.Cad.Model.Entities.EntityColor _whiteColor;//白色
|
|
protected short _equalParaCurveWidth = 20;
|
protected WW.Cad.Model.Entities.EntityColor _equalParaCurveColor;
|
protected WW.Cad.Model.Entities.EntityColor _gridLineColor;
|
|
protected WW.Cad.Model.Entities.EntityColor _gridSubLineColor;//子刻度
|
protected WW.Cad.Model.Entities.EntityColor _axisTitleColorQ;
|
protected WW.Cad.Model.Entities.EntityColor _axisTitleColorH;
|
protected WW.Cad.Model.Entities.EntityColor _axisTitleColorE;
|
protected WW.Cad.Model.Entities.EntityColor _axisTitleColorP;
|
protected WW.Cad.Model.Entities.EntityColor _axisTitleColorNPSH;
|
protected WW.Cad.Model.Entities.EntityColor _axisLabelColorQ;
|
protected WW.Cad.Model.Entities.EntityColor _axisLabelColorH;
|
protected WW.Cad.Model.Entities.EntityColor _axisLabelColorE;
|
protected WW.Cad.Model.Entities.EntityColor _axisLabelColorP;
|
protected WW.Cad.Model.Entities.EntityColor _axisLabelColorNPSH;
|
protected WW.Cad.Model.Entities.EntityColor _designPointColor;
|
protected WW.Cad.Model.Entities.EntityColor _frameTextColor;
|
|
//语言
|
protected Eventech.Model.eLocalizationType _currentLangugage = Eventech.Model.eLocalizationType.zhCN;
|
|
public Eventech.Model.eLocalizationType CurrentLangugage
|
{
|
get { return _currentLangugage; }
|
set
|
{
|
SetLangugageType(value);
|
}
|
}
|
|
protected virtual void SetLangugageType(Eventech.Model.eLocalizationType currentLangugage)
|
{
|
this._currentLangugage = currentLangugage;
|
if (this._currentLangugage != Eventech.Model.eLocalizationType.zhCN)
|
{
|
_axisTtileContentQ = "Flow";
|
_axisTtileContentH = "Head";
|
_axisTtileContentP = "Power";
|
_axisTtileContentE = "Eta";
|
_axisTtileContentNPSH = "NPSH";
|
}
|
}
|
|
//初始化模版文件
|
protected string _strTemplateFile = null;
|
|
public virtual bool InitialTemplate(string CorpDataFolder, Eventech.Model.eLocalizationType location, string attachInfo)
|
{
|
_currentLangugage = location;
|
return false;
|
}
|
|
//介质
|
protected TProduct.PumpGraph.Dxf.JieZhiFullPara _jieZhiInfo = null;// TProduct.Model.JieZhiFullPara的 toJsonString
|
|
public void SetJieZhiInfo(string jieZhiJsonInfo)
|
{
|
if (string.IsNullOrEmpty(jieZhiJsonInfo))
|
return;
|
|
try
|
{
|
this._jieZhiInfo = new JieZhiFullPara(jieZhiJsonInfo);
|
}
|
catch
|
{
|
_jieZhiInfo = null;
|
}
|
}
|
|
#region 网格线
|
|
//是否显示Y的网格线
|
protected bool _isDispGridLineY = true;
|
|
public bool IsDispGridLineY
|
{
|
get { return _isDispGridLineY; }
|
set { _isDispGridLineY = value; }
|
}
|
|
//是否显示Y的子网格线
|
protected bool _isDispGridSubLineY = false;
|
|
public bool IsDispGridSubLineY
|
{
|
get { return _isDispGridSubLineY; }
|
set { _isDispGridSubLineY = value; }
|
}
|
|
//是否显示扬程曲线X的网格线
|
protected bool _isDispGridLineX = true;
|
|
public bool IsDispGridLineX
|
{
|
get { return _isDispGridLineX; }
|
set { _isDispGridLineX = value; }
|
}
|
|
//是否显示Y的子网格线
|
protected bool _isDispGridSubLineX = false;
|
|
public bool IsDispGridSubLineX
|
{
|
get { return _isDispGridSubLineX; }
|
set { _isDispGridSubLineX = value; }
|
}
|
|
protected short _gridLineWidth = 5;
|
|
public short GridLineWidth
|
{
|
get { return _gridLineWidth; }
|
set { _gridLineWidth = value; }
|
}
|
|
//子网格线数量
|
protected int _subGridLineNumber = 5;
|
|
public int SubGridLineNumber
|
{
|
get { return _subGridLineNumber; }
|
set { _subGridLineNumber = value; }
|
}
|
|
#endregion 网格线
|
|
public virtual bool CreateDxf(string strFile)
|
{
|
return false;
|
}
|
|
public virtual bool CreateDxf(string strFilePath, string strTemplateFile)
|
{
|
this._strTemplateFile = strTemplateFile;
|
|
return true;
|
}
|
|
protected System.Drawing.Color _colorAxisQ = System.Drawing.Color.Yellow;
|
protected System.Drawing.Color _colorAxisH = System.Drawing.Color.Yellow;
|
protected System.Drawing.Color _colorAxisE = System.Drawing.Color.Yellow;
|
protected System.Drawing.Color _colorAxisP = System.Drawing.Color.Yellow;
|
protected System.Drawing.Color _colorAxisNPSH = System.Drawing.Color.Yellow;
|
protected System.Drawing.Color _colorParaCurveE = System.Drawing.Color.White;
|
protected System.Drawing.Color _colorFrameText = System.Drawing.Color.White;
|
protected System.Drawing.Color _colorGridLine = System.Drawing.Color.Gray;
|
protected System.Drawing.Color _colorDeignPoint = System.Drawing.Color.Red;
|
|
//设置默认字体
|
protected virtual void InitialChartColorAndFont()
|
{
|
try
|
{
|
if (this._isMonoColor)
|
{
|
_whiteColor = TProduct.PumpGraph.Dxf.AutoCadHelper.WhiteColor;
|
|
_axisLabelColorQ = _whiteColor;
|
_axisTitleColorQ = _whiteColor;
|
_axisLabelColorH = _whiteColor;
|
_axisTitleColorH = _whiteColor;
|
_axisLabelColorE = _whiteColor;
|
_axisTitleColorE = _whiteColor;
|
_axisLabelColorP = _whiteColor;
|
_axisTitleColorP = _whiteColor;
|
_axisLabelColorNPSH = _whiteColor;
|
_axisTitleColorNPSH = _whiteColor;
|
_equalParaCurveColor = _whiteColor;
|
_frameTextColor = _whiteColor;
|
_gridLineColor = _whiteColor;
|
_designPointColor = _whiteColor;
|
}
|
else
|
{
|
_whiteColor = TProduct.PumpGraph.Dxf.AutoCadHelper.WhiteColor;
|
|
_axisLabelColorQ = TProduct.PumpGraph.Dxf.AutoCadHelper.GetColor(_colorAxisQ);
|
_axisTitleColorQ = TProduct.PumpGraph.Dxf.AutoCadHelper.GetColor(_colorAxisQ);
|
|
_axisLabelColorH = TProduct.PumpGraph.Dxf.AutoCadHelper.GetColor(_colorAxisH);
|
_axisTitleColorH = TProduct.PumpGraph.Dxf.AutoCadHelper.GetColor(_colorAxisH);
|
|
_axisLabelColorE = TProduct.PumpGraph.Dxf.AutoCadHelper.GetColor(_colorAxisE);
|
_axisTitleColorE = TProduct.PumpGraph.Dxf.AutoCadHelper.GetColor(_colorAxisE);
|
|
_axisLabelColorP = TProduct.PumpGraph.Dxf.AutoCadHelper.GetColor(_colorAxisP);
|
_axisTitleColorP = TProduct.PumpGraph.Dxf.AutoCadHelper.GetColor(_colorAxisP);
|
|
_axisLabelColorNPSH = TProduct.PumpGraph.Dxf.AutoCadHelper.GetColor(_colorAxisNPSH);
|
_axisTitleColorNPSH = TProduct.PumpGraph.Dxf.AutoCadHelper.GetColor(_colorAxisNPSH);
|
|
_equalParaCurveColor = TProduct.PumpGraph.Dxf.AutoCadHelper.GetColor(_colorParaCurveE);
|
_frameTextColor = TProduct.PumpGraph.Dxf.AutoCadHelper.GetColor(_colorFrameText);
|
_gridLineColor = TProduct.PumpGraph.Dxf.AutoCadHelper.GetColor(_colorGridLine);
|
_designPointColor = TProduct.PumpGraph.Dxf.AutoCadHelper.GetColor(_colorDeignPoint);
|
}
|
}
|
catch (Exception ex)
|
{
|
throw ex;
|
}
|
|
//_defaultTextFont = new DxfTextStyle("MYSTYLE", "simfang.ttf");//仿宋体 在WINDOWS/FONT下的文件名称
|
//_dxfFileModel.TextStyles.Add(_defaultTextFont);
|
//DxfTextStyle titleType = null;
|
//titleType = new DxfTextStyle("MY", "txt.shx");
|
//// titleType.Name = "MY";
|
//// titleType.FontFilename = "txt.shx";
|
//titleType.BigFontFilename = "bigfont.shx";
|
//_dxfFileModel.TextStyles.Add(titleType);
|
|
//var fs_path = @"D:\WorkData\TProduct\Client\OutAlone\DataCYJX\template\acadiso.dwt";
|
////
|
//if (System.IO.File.Exists(fs_path))
|
//{
|
// _defaultTextFont = new DxfTextStyle("FS", fs_path);//仿宋体 在WINDOWS/FONT下的文件名称
|
// _dxfFileModel.TextStyles.Add(_defaultTextFont);
|
//}
|
|
//if (!string.IsNullOrEmpty(_defaultFontFilePath) && System.IO.File.Exists(_defaultFontFilePath))
|
//{
|
// _defaultTextFont = new DxfTextStyle(_defaultFontName, _defaultFontFilePath);//仿宋体 在WINDOWS/FONT下的文件名称
|
// _dxfFileModel.TextStyles.Add(_defaultTextFont);
|
//}
|
|
//string font_file = System.IO.Path.Combine(TProduct.GlobeParas.DataFolder, "PumpDwgFeatCurveTemplate", "simfang.ttf");
|
//if (System.IO.File.Exists(font_file))
|
//{
|
// lxpChart.DefaultFontFilePath = font_file;//默认字体
|
// lxpChart.DefaultFontName = "simfang";
|
//}
|
//else
|
//{
|
// font_file = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PumpDwgFeatCurveTemplate", "simfang.ttf");
|
// if (System.IO.File.Exists(font_file))
|
// {
|
// lxpChart.DefaultFontFilePath = font_file;//默认字体
|
// lxpChart.DefaultFontName = "simfang";
|
// }
|
//}
|
//protected string _defaultFontName = "simfang";//默认字体
|
//public string DefaultFontName
|
//{
|
// get { return _defaultFontName; }
|
// set { _defaultFontName = value; }
|
//}
|
|
//protected string _defaultFontFilePath = null;//默认字体
|
//public string DefaultFontFilePath
|
//{
|
// get { return _defaultFontFilePath; }
|
// set { _defaultFontFilePath = value; }
|
//}
|
|
//if (!zlpChart.InitialTemplate(TProduct.GlobeParas.DataFolder, TProduct.UserSetting.Localization.Current))
|
//{
|
// zlpChart = new TProduct.PumpGraph.Dxf.ZlpChartCurve1_NewFile();
|
// string font_file = System.IO.Path.Combine(TProduct.GlobeParas.DataFolder, "PumpDwgFeatCurveTemplate", "simfang.ttf");
|
// if (System.IO.File.Exists(font_file))
|
// {
|
// zlpChart.DefaultFontFilePath = font_file;//默认字体
|
// zlpChart.DefaultFontName = "simfang";
|
// }
|
// else
|
// {
|
// font_file = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PumpDwgFeatCurveTemplate", "simfang.ttf");
|
// if (System.IO.File.Exists(font_file))
|
// {
|
// zlpChart.DefaultFontFilePath = font_file;//默认字体
|
// zlpChart.DefaultFontName = "simfang";
|
// }
|
// }
|
//}
|
}
|
|
//产生图框文字
|
protected DxfMText CreateFrameDxfText(string text, double x, double y, double text_height, AttachmentPoint AttachmentPoint = AttachmentPoint.BottomLeft)
|
{
|
if (string.IsNullOrEmpty(text))
|
return null;
|
|
DxfMText txtLabel = new DxfMText(text, new Point3D(x, y, 0d), text_height);
|
|
if (this._frameTextFont != null)
|
txtLabel.Style = this._frameTextFont;
|
txtLabel.Color = this._frameTextColor;
|
txtLabel.AttachmentPoint = AttachmentPoint;
|
txtLabel.Height = text_height;
|
_dxfFileModel.Entities.Add(txtLabel);
|
return txtLabel;
|
}
|
|
protected DxfMText CreateFrameDxfText(string text, double x, double y, double text_height, AttachmentPoint AttachmentPoint, DxfTextStyle style)
|
{
|
if (string.IsNullOrEmpty(text))
|
return null;
|
|
DxfMText txtLabel = new DxfMText(text, new Point3D(x, y, 0d), text_height);
|
if (style != null)
|
txtLabel.Style = style;
|
else if (this._frameTextFont != null)
|
txtLabel.Style = this._frameTextFont;
|
txtLabel.Color = this._frameTextColor;
|
txtLabel.AttachmentPoint = AttachmentPoint;
|
txtLabel.Height = text_height;
|
_dxfFileModel.Entities.Add(txtLabel);
|
return txtLabel;
|
}
|
|
//
|
protected System.Drawing.Printing.PaperKind _printKindSize = System.Drawing.Printing.PaperKind.A4;
|
|
//
|
protected bool SaveFile(string strFilePath)
|
{
|
if (_fileSuffixType == Eventech.Model.eFileSuffixType.DWG || this._isRetainDwgFile)
|
{
|
string file_dwg = string.Format(@"{0}\{1}.{2}",
|
System.IO.Path.GetDirectoryName(strFilePath), System.IO.Path.GetFileNameWithoutExtension(strFilePath), "dwg");
|
|
if (System.IO.File.Exists(file_dwg))
|
{
|
System.IO.File.Delete(file_dwg);
|
}
|
DwgWriter.Write(file_dwg, _dxfFileModel);
|
|
//DwgWriter.Write("DwgWriteExample-ascii.dwg", model);
|
//DxfWriter.Write(strFilePath, _dxfFileModel, false);
|
//DxfWriter.Write("DxfWriteExample-bin.dxf", model, true);
|
}
|
|
//产生 PDF
|
CreatePdfFile(strFilePath);
|
//产生 PNG图片
|
CreatePngFile(strFilePath);
|
|
return true;
|
}
|
|
//产生 PDF
|
protected bool CreatePdfFile(string strFilePath)
|
{
|
try
|
{
|
System.Drawing.Printing.PaperKind pdfPageKind = _printKindSize;
|
if (_fileSuffixType != Eventech.Model.eFileSuffixType.PDF)
|
{
|
return true;
|
}
|
if (_dxfFileModel == null)
|
return false;
|
var model_new_file = new DxfModel(_dxfFileModel);
|
if (this._isMonoColor)
|
{
|
foreach (var m in model_new_file.Entities)
|
{
|
m.Color = _whiteColor;
|
}
|
}
|
string strPdfFile = string.Format(@"{0}\{1}.{2}",
|
System.IO.Path.GetDirectoryName(strFilePath), System.IO.Path.GetFileNameWithoutExtension(strFilePath), "pdf");
|
|
if (System.IO.File.Exists(strPdfFile))
|
{
|
System.IO.File.Delete(strPdfFile);
|
}
|
|
BoundsCalculator boundsCalculator = new BoundsCalculator();
|
boundsCalculator.GetBounds(model_new_file);
|
Bounds3D bounds = boundsCalculator.Bounds;
|
System.Drawing.Printing.PaperSize paperSize = PaperSizes.GetPaperSize(pdfPageKind);
|
// Lengths in inches.
|
float pageWidth = (float)paperSize.Width / 100f;
|
float pageHeight = (float)paperSize.Height / 100f;
|
float margin = 0.5f;
|
// Scale and transform such that its fits max width/height and the top left middle of
|
// the cad drawing will match the top middle of the pdf page. The transform
|
// transforms to pdf pixels.
|
Matrix4D to2DTransform = DxfUtil.GetScaleTransform(
|
bounds.Corner1,
|
bounds.Corner2,
|
new Point3D(bounds.Center.X, bounds.Corner2.Y, 0d),
|
new Point3D(new Vector3D(margin, margin, 0d) * PdfExporter.InchToPixel),
|
new Point3D(new Vector3D(pageWidth - margin, pageHeight - margin, 0d) * PdfExporter.InchToPixel),
|
new Point3D(new Vector3D(pageWidth / 2d, pageHeight - margin, 0d) * PdfExporter.InchToPixel)
|
);
|
// to2DTransform.TransformAngle(90);
|
System.IO.Stream stream_pdf = null;
|
using (stream_pdf = System.IO.File.Create(strPdfFile))
|
{
|
PdfExporter pdfGraphics = new PdfExporter(stream_pdf);
|
pdfGraphics.DrawPage(
|
model_new_file,
|
GraphicsConfig.WhiteBackgroundCorrectForBackColor, //AcadLikeWithWhiteBackground WhiteBackgroundCorrectForBackColor BlackBackgroundCorrectForBackColor
|
to2DTransform,
|
paperSize
|
);
|
pdfGraphics.EndDocument();
|
}
|
}
|
catch // (Exception ex)
|
{
|
return false;
|
}
|
|
return true;
|
}
|
|
//产生 图片
|
protected bool CreatePngFile(string strFilePath)
|
{
|
try
|
{
|
if (_dxfFileModel == null)
|
return false;
|
|
if (_fileSuffixType != Eventech.Model.eFileSuffixType.PNG)
|
return true;
|
int ImageWidth = 2100;
|
int ImageHeight = 2970;
|
if (this._printKindSize == System.Drawing.Printing.PaperKind.A4Rotated)
|
{
|
ImageWidth = 2970;
|
ImageHeight = 2100;
|
}
|
|
var model_new_file = new DxfModel(_dxfFileModel);
|
if (this._isMonoColor)
|
{
|
var blackColor = TProduct.PumpGraph.Dxf.AutoCadHelper.WhiteColor;
|
foreach (var m in model_new_file.Entities)
|
{
|
m.Color = blackColor;
|
}
|
}
|
|
//var bCopy = strFilePath.Replace(".dwg", "_copyB.dwg");
|
//System.IO.File.Copy(strFilePath, bCopy);
|
//DxfModel model_new_file_image = WW.Cad.IO.DwgReader.Read(bCopy);
|
|
string strImgageFile = string.Format(@"{0}\{1}.{2}",
|
System.IO.Path.GetDirectoryName(strFilePath), System.IO.Path.GetFileNameWithoutExtension(strFilePath), "png");
|
|
if (System.IO.File.Exists(strImgageFile))
|
{
|
System.IO.File.Delete(strImgageFile);
|
}
|
|
GDIGraphics3D graphics = new GDIGraphics3D(GraphicsConfig.AcadLikeWithWhiteBackground);//.BlackBackgroundCorrectForBackColor);
|
System.Drawing.Size maxSize = new System.Drawing.Size(ImageWidth, ImageHeight);
|
System.Drawing.Bitmap bitmap =
|
ImageExporter.CreateAutoSizedBitmap(
|
model_new_file,
|
graphics,
|
Matrix4D.Identity,
|
System.Drawing.Color.White,
|
maxSize
|
);
|
|
System.IO.Stream stream_image = null;
|
using (stream_image = System.IO.File.Create(strImgageFile))
|
{
|
ImageExporter.EncodeImageToPng(bitmap, stream_image);
|
}
|
}
|
catch // (Exception ex)
|
{
|
return false;
|
}
|
|
return true;
|
}
|
|
protected WW.Cad.Model.Tables.DxfLayer GetLayerByName(string name)
|
{
|
foreach (var ly in _dxfFileModel.Layers)
|
{
|
if (ly.Name == name)
|
{
|
return ly;
|
}
|
}
|
|
return null;
|
}
|
|
protected void ReplaceDictText(Dictionary<string, string> dictFrameText)
|
{
|
if (dictFrameText == null)
|
return;
|
|
var dxfMTexts = this._dxfFileModel.Entities.Where(t => t is DxfMText).Select(t => t as DxfMText).ToList();
|
|
foreach (var mtext in dxfMTexts)
|
{
|
if (dictFrameText.ContainsKey(mtext.SimplifiedText))
|
{
|
mtext.Text = mtext.Text.Replace(mtext.SimplifiedText, dictFrameText[mtext.SimplifiedText]);
|
}
|
}
|
}
|
|
|
|
protected string GetNumberString(double v)
|
{
|
if ((int)v == v)
|
{
|
return ((int)v).ToString();
|
}
|
else if (v < 3)
|
{
|
return Math.Round(v, 3).ToString();
|
}
|
else if (v < 10)
|
{
|
return Math.Round(v, 2).ToString();
|
}
|
else
|
{
|
return Math.Round(v, 1).ToString();
|
}
|
}
|
}
|
}
|