/// <summary> /// 方法,向模型空间添加一个图案填充 /// </summary> /// <param name="_model">模型空间</param> /// <param name="_hatchName">填充名称</param> /// <param name="_startX">起点X坐标</param> /// <param name="_startY">起点Y坐标</param> /// <param name="_endX">终点X坐标</param> /// <param name="_endY">终点Y坐标</param> /// <returns></returns> public DxfHatch AddRecHatch(string _hatchName, double _startX, double _startY, double _endX, double _endY) { DxfHatch hatch = new DxfHatch(); DxfHatch.BoundaryPath boundary = new DxfHatch.BoundaryPath(); boundary.Type = BoundaryPathType.Polyline; hatch.BoundaryPaths.Add(boundary); DxfHatch.BoundaryPath.Polyline.Vertex[] vertexs = new DxfHatch.BoundaryPath.Polyline.Vertex[4] { new DxfHatch.BoundaryPath.Polyline.Vertex(_startX, _startY), new DxfHatch.BoundaryPath.Polyline.Vertex(_endX, _startY), new DxfHatch.BoundaryPath.Polyline.Vertex(_endX, _endY), new DxfHatch.BoundaryPath.Polyline.Vertex(_startX, _endY) }; boundary.PolylineData = new DxfHatch.BoundaryPath.Polyline(vertexs); boundary.PolylineData.Closed = true; DxfPatternStore.Add(PatternReader.ReadPatterns("acad.pat")); hatch.Pattern = DxfPatternStore.GetPatternWithName(_hatchName); hatch.Scale = 0.5; Model.Entities.Add(hatch); return(hatch); }
/// <summary> /// 根据花纹库编号将相应的花纹插入到图表中 /// </summary> public DxfHatch getPatternHatch(double X1, double X2, double startDeep, double endDeep) { string path = AppDomain.CurrentDomain.BaseDirectory + "Drill\\patternLibrary\\"; DirectoryInfo directoryInfo = new DirectoryInfo(path); FileInfo[] fileInfo = directoryInfo.GetFiles("*.pat"); //获得pat文档的个数 int fileLength = fileInfo.Length; //遍历所有的已经存在的pat文件 foreach (FileInfo file in fileInfo) { //解决中文乱码问题 StreamReader str = new StreamReader(path + file, Encoding.Default); char[] s = { ',' }; //定义分隔符为逗号 StringBuilder rockName = new StringBuilder(); //存储岩石名称的数组 string readLine = str.ReadLine(); //读取一行数据 while (!string.IsNullOrEmpty(readLine)) //如果数据不为空) { string[] record = readLine.Split(s); rockName.Append(record[1]); string strRockName = rockName.ToString().Trim(); //strRockName = strRockName.Replace(" ", ""); if (string.Equals(strRockName, mrockName))//找到名字相同的花纹 { //读取花纹库 DxfModel model = new DxfModel(); DxfPatternStore.Add(PatternReader.ReadPatterns(path + file)); DxfHatch hatch = new DxfHatch(); hatch.Pattern = DxfPatternStore.GetPatternWithName("" + Path.GetFileNameWithoutExtension(file.Name)); DxfHatch.BoundaryPath boundaryPath = new DxfHatch.BoundaryPath(); boundaryPath.Type = BoundaryPathType.Polyline; hatch.BoundaryPaths.Add(boundaryPath); boundaryPath.PolylineData = new DxfHatch.BoundaryPath.Polyline( new DxfHatch.BoundaryPath.Polyline.Vertex[] { new DxfHatch.BoundaryPath.Polyline.Vertex(X1, -23d - startDeep), new DxfHatch.BoundaryPath.Polyline.Vertex(X2, -23d - startDeep), new DxfHatch.BoundaryPath.Polyline.Vertex(X2, -23d - endDeep), new DxfHatch.BoundaryPath.Polyline.Vertex(X1, -23d - endDeep) } ); boundaryPath.PolylineData.Closed = true; return(hatch); } break; } } return(null); }