public ProcessBoard() { _MinCorner = new SharpPoint3D(); _MaxCorner = new SharpPoint3D(); _ALlHoles = new List <DrillHole>(); _Contour = new List <SharpPoint3D>(); }
public DrillHole() { _ToolNumber = 0; _Diameter = 0; _Deep = 0; _HolePlane = ""; _Dir = new SharpPoint3D(); _EntryPoint = new SharpPoint3D(); }
private static ProcessBoard ParsePartFormsProcess(string xmlFile) { ProcessBoard board = new ProcessBoard(); try { XmlDocument doc = null; try { doc = new XmlDocument(); doc.Load(xmlFile); } catch { return(null); } board._MinCorner = new SharpPoint3D(double.MaxValue, double.MaxValue, double.MaxValue); board._MaxCorner = new SharpPoint3D(-1 * double.MaxValue, -1 * double.MaxValue, -1 * double.MaxValue); //工件轮廓信息 XmlNode nodeContour = doc.SelectSingleNode("/part_forms"); if (nodeContour == null) { return(null); } for (int iNode = 0; iNode < nodeContour.ChildNodes.Count; iNode++) { XmlNode node = nodeContour.ChildNodes[iNode]; if (node == null) { continue; } SharpPoint3D pt = new SharpPoint3D(); if (node.Name.Equals("part", StringComparison.InvariantCultureIgnoreCase)) { for (int item = 0; item < node.ChildNodes.Count; item++) { if (node.ChildNodes[item].Name.Equals("curvelist", StringComparison.InvariantCultureIgnoreCase)) { XmlNode nodeLine = node.ChildNodes[item]; for (int iLine = 0; iLine < nodeLine.ChildNodes.Count; iLine++) { if (nodeLine.ChildNodes[iLine].Name.Equals("line", StringComparison.InvariantCultureIgnoreCase)) { SharpPoint3D ptStart = new SharpPoint3D(); SharpPoint3D ptEnd = new SharpPoint3D(); XmlNode nodePoint = nodeLine.ChildNodes[iLine]; for (int iPoint = 0; iPoint < nodePoint.ChildNodes.Count; iPoint++) { if (nodePoint.ChildNodes[iPoint].Name.Equals("startpt", StringComparison.InvariantCultureIgnoreCase)) { XmlNode nodePT = nodePoint.ChildNodes[iPoint]; for (int iPt = 0; iPt < nodePT.ChildNodes.Count; iPt++) { if (nodePT.ChildNodes[iPt].Name.Equals("point", StringComparison.InvariantCultureIgnoreCase)) { if (nodePT.ChildNodes[iPt].Attributes != null) { foreach (XmlAttribute attribute in nodePT.ChildNodes[iPt].Attributes) { if (attribute.Name.Equals("x", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { ptStart.x = Convert.ToDouble(attribute.Value); } } else if (attribute.Name.Equals("y", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { ptStart.y = Convert.ToDouble(attribute.Value); } } else if (attribute.Name.Equals("z", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { ptStart.z = Convert.ToDouble(attribute.Value); } } } } } } } else if (nodePoint.ChildNodes[iPoint].Name.Equals("endpt", StringComparison.InvariantCultureIgnoreCase)) { XmlNode nodePT = nodePoint.ChildNodes[iPoint]; for (int iPt = 0; iPt < nodePT.ChildNodes.Count; iPt++) { if (nodePT.ChildNodes[iPt].Name.Equals("point", StringComparison.InvariantCultureIgnoreCase)) { if (nodePT.ChildNodes[iPt].Attributes != null) { foreach (XmlAttribute attribute in nodePT.ChildNodes[iPt].Attributes) { if (attribute.Name.Equals("x", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { ptEnd.x = Convert.ToDouble(attribute.Value); } } else if (attribute.Name.Equals("y", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { ptEnd.y = Convert.ToDouble(attribute.Value); } } else if (attribute.Name.Equals("z", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { ptEnd.z = Convert.ToDouble(attribute.Value); } } } } } } } } } } } else if (node.ChildNodes[item].Name.Equals("process", StringComparison.InvariantCultureIgnoreCase)) { XmlNode nodeLine = node.ChildNodes[item]; for (int iLine = 0; iLine < nodeLine.ChildNodes.Count; iLine++) { if (nodeLine.ChildNodes[item].Name.Equals("hole", StringComparison.InvariantCultureIgnoreCase)) { XmlNode nodeHole = nodeLine.ChildNodes[item]; DrillHole drillHole = new DrillHole(); drillHole._Dir = new SharpPoint3D(0, 0, 0); drillHole._ToolNumber = 0; drillHole._HolePlane = ""; if (nodeHole.Attributes != null) { foreach (XmlAttribute attribute in nodeHole.Attributes) { if (attribute.Name.Equals("faceid", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { drillHole._HolePlane = attribute.Value; } } else if (attribute.Name.Equals("dir", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { int dr = Convert.ToInt32(attribute.Value); } } else if (attribute.Name.Equals("diameter", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { drillHole._Diameter = Convert.ToDouble(attribute.Value); } } else if (attribute.Name.Equals("deep", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { drillHole._Deep = Convert.ToDouble(attribute.Value); } } } } for (int iHole = 0; iHole < nodeHole.ChildNodes.Count; iHole++) { if (nodeHole.ChildNodes[iHole].Name.Equals("point", StringComparison.InvariantCultureIgnoreCase)) { if (nodeHole.ChildNodes[iHole].Attributes != null) { foreach (XmlAttribute attribute in nodeHole.ChildNodes[iHole].Attributes) { if (attribute.Name.Equals("x", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { drillHole._EntryPoint.x = Convert.ToDouble(attribute.Value); drillHole._EntryPoint.nMask |= 0x80; } } else if (attribute.Name.Equals("y", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { drillHole._EntryPoint.y = Convert.ToDouble(attribute.Value); drillHole._EntryPoint.nMask |= 0x40; } } else if (attribute.Name.Equals("z", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { drillHole._EntryPoint.z = Convert.ToDouble(attribute.Value); drillHole._EntryPoint.nMask |= 0x20; } } } } } } board._ALlHoles.Add(drillHole); } } } } } if (pt.nMask == 0xE0) { board._Contour.Add(pt); } } if (board._Contour.Count == 0) { return(null); } } catch { } return(board); }
private static ProcessBoard ParseProcessContour(string xmlFile) { ProcessBoard board = new ProcessBoard(); try { XmlDocument doc = null; try { doc = new XmlDocument(); doc.Load(xmlFile); } catch { return(null); } board._MinCorner = new SharpPoint3D(double.MaxValue, double.MaxValue, double.MaxValue); board._MaxCorner = new SharpPoint3D(-1 * double.MaxValue, -1 * double.MaxValue, -1 * double.MaxValue); //工件轮廓信息 XmlNode nodeContour = doc.SelectSingleNode("/process/contour"); if (nodeContour == null) { return(null); } for (int iNode = 0; iNode < nodeContour.ChildNodes.Count; iNode++) { XmlNode node = nodeContour.ChildNodes[iNode]; if (node == null) { continue; } SharpPoint3D pt = new SharpPoint3D(); if (node.Name.Equals("point", StringComparison.InvariantCultureIgnoreCase)) { if (node.Attributes != null) { foreach (XmlAttribute attribute in node.Attributes) { if (attribute.Name.Equals("x", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { double value = Convert.ToDouble(attribute.Value); board._MinCorner.x = Math.Min(board._MinCorner.x, value); board._MaxCorner.x = Math.Max(board._MaxCorner.x, value); pt.x = value; pt.nMask |= 0x80; } } else if (attribute.Name.Equals("y", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { double value = Convert.ToDouble(attribute.Value); board._MinCorner.y = Math.Min(board._MinCorner.y, value); board._MaxCorner.y = Math.Max(board._MaxCorner.y, value); pt.y = value; pt.nMask |= 0x40; } } else if (attribute.Name.Equals("z", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { double value = Convert.ToDouble(attribute.Value); board._MinCorner.z = Math.Min(board._MinCorner.z, value); board._MaxCorner.z = Math.Max(board._MaxCorner.z, value); pt.z = value; pt.nMask |= 0x20; } } } } } if (pt.nMask == 0xE0) { board._Contour.Add(pt); } } if (board._Contour.Count == 0) { return(null); } //工件孔位信息 long nToolNumber = -1; string holePlane = ""; SharpPoint3D ptDir = new SharpPoint3D(); XmlNode nodeRoot = doc.SelectSingleNode("/process"); if (nodeRoot == null) { return(null); } for (int iNode = 0; iNode < nodeRoot.ChildNodes.Count; iNode++) { XmlNode nodeSide = nodeRoot.ChildNodes[iNode]; if (nodeSide != null) { if ((nodeSide.Name.Equals("sideHole", StringComparison.InvariantCultureIgnoreCase)) || (nodeSide.Name.Equals("frontHole", StringComparison.InvariantCultureIgnoreCase)) || (nodeSide.Name.Equals("backHole", StringComparison.InvariantCultureIgnoreCase))) { holePlane = nodeSide.Name; if (nodeSide.Attributes != null) { foreach (XmlAttribute attribute in nodeSide.Attributes) { if (attribute.Name.Equals("dirx", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { ptDir.x = Convert.ToDouble(attribute.Value); ptDir.nMask |= 0x80; } } else if (attribute.Name.Equals("diry", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { ptDir.y = Convert.ToDouble(attribute.Value); ptDir.nMask |= 0x40; } } else if (attribute.Name.Equals("dirz", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { ptDir.z = Convert.ToDouble(attribute.Value); ptDir.nMask |= 0x20; } } } } for (int iTool = 0; iTool < nodeSide.ChildNodes.Count; iTool++) { XmlNode nodeTool = nodeSide.ChildNodes[iTool]; if (nodeTool != null) { if (nodeTool.Name.Equals("tool", StringComparison.InvariantCultureIgnoreCase)) { if (nodeTool.Attributes != null) { foreach (XmlAttribute attribute in nodeTool.Attributes) { if (attribute.Name.Equals("toolno", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { nToolNumber = Convert.ToInt32(attribute.Value); } } } } for (int iHole = 0; iHole < nodeTool.ChildNodes.Count; iHole++) { XmlNode nodeHole = nodeTool.ChildNodes[iHole]; if (nodeHole != null) { if (nodeHole.Name.Equals("hole", StringComparison.InvariantCultureIgnoreCase)) { DrillHole drillHole = new DrillHole(); drillHole._Dir = new SharpPoint3D(ptDir.x, ptDir.y, ptDir.z); drillHole._ToolNumber = nToolNumber; drillHole._HolePlane = holePlane; if (nodeHole.Attributes != null) { foreach (XmlAttribute attribute in nodeHole.Attributes) { if (attribute.Name.Equals("x", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { drillHole._EntryPoint.x = Convert.ToDouble(attribute.Value); drillHole._EntryPoint.nMask |= 0x80; } } else if (attribute.Name.Equals("y", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { drillHole._EntryPoint.y = Convert.ToDouble(attribute.Value); drillHole._EntryPoint.nMask |= 0x40; } } else if (attribute.Name.Equals("z", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { drillHole._EntryPoint.z = Convert.ToDouble(attribute.Value); drillHole._EntryPoint.nMask |= 0x20; } } else if (attribute.Name.Equals("diameter", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { drillHole._Diameter = Convert.ToDouble(attribute.Value); } } else if (attribute.Name.Equals("deep", StringComparison.InvariantCultureIgnoreCase)) { if (!String.IsNullOrEmpty(attribute.Value)) { drillHole._Deep = Convert.ToDouble(attribute.Value); } } } } board._ALlHoles.Add(drillHole); } } } } } } } } } } catch { } return(board); }