public void SetInfos(IPCBIWindow parentPCBI) { if (!parentPCBI.JobIsLoaded) { return; } IStep curStep = parentPCBI.GetCurrentStep(); IMatrix matrix = parentPCBI.GetMatrix(); if (curStep == null || matrix == null) { return; //sollte nicht vorkommen wenn job geladen ist } PCB_Investigator.PCBIWindows.PCBIWorkingDialog working = new PCB_Investigator.PCBIWindows.PCBIWorkingDialog(); working.CanCancel(false); working.SetAnimationStatus(true); working.ShowWorkingDlgAsThread(); richTextBoxMain.Clear(); bool mm = parentPCBI.GetUnit(); richTextBoxMain.Font = new System.Drawing.Font("Verdana", 10); working.SetStatusText("Working on Step Information " + curStep.Name + "..."); float boardArea = curStep.CalculateBoardArea(); if (mm) { boardArea = (float)Math.Round(boardArea * (25.4 * 25.4) / 1000000, 3); } foreach (ILayer activeLayer in curStep.GetActiveLayerList()) { richTextBoxMain.AppendText("Layer " + activeLayer.GetLayerName() + Environment.NewLine); richTextBoxMain.AppendText(Environment.NewLine); working.SetStatusText("Working on Layer " + activeLayer.GetLayerName() + "..."); #region size of layer RectangleF bounds = activeLayer.GetBounds(); richTextBoxMain.AppendText("Bounds: " + Environment.NewLine + "XMin " + (mm ? (IMath.Mils2MM(bounds.Left).ToString("F3") + " mm") : (bounds.Left.ToString("F3") + " mil")) + Environment.NewLine + "YMin " + (mm ? (IMath.Mils2MM(bounds.Top).ToString("F3") + " mm") : (bounds.Top.ToString("F3") + " mil")) + Environment.NewLine + "XMax " + (mm ? (IMath.Mils2MM(bounds.Right).ToString("F3") + " mm") : (bounds.Right.ToString("F3") + " mil")) + Environment.NewLine + "YMax " + (mm ? (IMath.Mils2MM(bounds.Bottom).ToString("F3") + " mm") : (bounds.Bottom.ToString("F3") + " mil")) + Environment.NewLine ); richTextBoxMain.AppendText(Environment.NewLine); richTextBoxMain.AppendText("Width " + (mm ? (IMath.Mils2MM(bounds.Width).ToString("F3") + " mm") : (bounds.Width.ToString("F3") + " mil")) + Environment.NewLine); richTextBoxMain.AppendText("Height " + (mm ? (IMath.Mils2MM(bounds.Height).ToString("F3") + " mm") : (bounds.Height.ToString("F3") + " mil")) + Environment.NewLine); richTextBoxMain.AppendText(Environment.NewLine); #endregion #region area calculation if (activeLayer is IODBLayer) { IODBLayer odbActiveLayer = (IODBLayer)activeLayer; float areaOfLayer = odbActiveLayer.CalculateArea(true); if (mm) { richTextBoxMain.AppendText("Used Area " + (Math.Round(areaOfLayer * (25.4 * 25.4) / 1000000, 3).ToString("F3")) + " of " + boardArea.ToString("F3") + " mm?" + Environment.NewLine); } else { richTextBoxMain.AppendText("Used Area " + Math.Round(areaOfLayer, 2).ToString("F2") + " of " + (boardArea.ToString("F2")) + " mils?" + Environment.NewLine); } } #endregion #region count elements int counterArc = 0; int counterCMPs = 0; int counterLines = 0; int counterSurfaces = 0; int counterText = 0; int counterPads = 0; foreach (IObject obj in activeLayer.GetAllLayerObjects()) //count all elements { if (obj.Type == IObjectType.Arc) { counterArc++; } else if (obj.Type == IObjectType.Component) { counterCMPs++; } else if (obj.Type == IObjectType.Line) { counterLines++; } else if (obj.Type == IObjectType.Pad) { counterPads++; } else if (obj.Type == IObjectType.Surface) { counterSurfaces++; } else if (obj.Type == IObjectType.Text) { counterText++; } } richTextBoxMain.AppendText(Environment.NewLine); if (counterArc > 0) { richTextBoxMain.AppendText("Count Arcs: " + counterArc.ToString("N0") + Environment.NewLine); } if (counterCMPs > 0) { richTextBoxMain.AppendText("Count Components: " + counterCMPs.ToString("N0") + Environment.NewLine); } if (counterLines > 0) { richTextBoxMain.AppendText("Count Lines: " + counterLines.ToString("N0") + Environment.NewLine); } if (counterPads > 0) { richTextBoxMain.AppendText("Count Pads: " + counterPads.ToString("N0") + Environment.NewLine); } if (counterSurfaces > 0) { richTextBoxMain.AppendText("Count Area Fills: " + counterSurfaces.ToString("N0") + Environment.NewLine); } if (counterText > 0) { richTextBoxMain.AppendText("Count Texts: " + counterText.ToString("N0") + Environment.NewLine); } richTextBoxMain.AppendText(Environment.NewLine); #endregion #region matrix infos MatrixLayerContext context = matrix.GetMatrixLayerContext(activeLayer.GetLayerName()); MatrixLayerPolarity polarity = matrix.GetMatrixLayerPolarity(activeLayer.GetLayerName()); MatrixLayerType type = matrix.GetMatrixLayerType(activeLayer.GetLayerName()); int index = matrix.GetRawIndexByName(activeLayer.GetLayerName()); richTextBoxMain.AppendText("Matrix Index " + index + ", Context " + context + ", Polarity " + polarity + ", Type " + type + Environment.NewLine); #endregion richTextBoxMain.AppendText(Environment.NewLine); richTextBoxMain.AppendText(Environment.NewLine); richTextBoxMain.AppendText(Environment.NewLine); } working.DoClose(); }
public void Execute(IPCBIWindow parent) { //set options here: bool onlySelectedComponent = true; bool CalculateTopSide = true; bool CalculateBotSide = true; double TopArea = 0; double BotArea = 0; IStep step = parent.GetCurrentStep(); if (step == null) { return; //no project loaded } List <ICMPObject> allCMPs = step.GetAllCMPObjects(); foreach (ICMPObject cmp in allCMPs) { if (onlySelectedComponent && !cmp.IsSelected) { continue; } PCBI.MathUtils.IPolyClass polygonOfCMP = cmp.GetPolygonOutline(); foreach (PCBI.MathUtils.IEdge edge in polygonOfCMP.GetEdges()) { if (!CalculateTopSide && cmp.PlacedTop) { continue; } if (!CalculateBotSide && !cmp.PlacedTop) { continue; } //work with integrals to calculate the area double extent = 0; if (edge.Type == IEdgeType.Line) { extent = PCBI.MathUtils.IMath.DistancePointToPoint(edge.Begin, edge.End); } else { // Pi * R * winkel /180 double angle = PCBI.MathUtils.IMath.GetAngle(edge.Begin, edge.End, ((PCBI.MathUtils.IArcEdge)edge).Center, ((PCBI.MathUtils.IArcEdge)edge).ClockWise); double radius = PCBI.MathUtils.IMath.DistancePointToPoint(edge.Begin, ((PCBI.MathUtils.IArcEdge)edge).Center); extent = Math.PI * radius * angle / 180; } if (cmp.PlacedTop) { TopArea += extent * cmp.CompHEIGHT; } else { BotArea += extent * cmp.CompHEIGHT; } } } double areaPCB = step.CalculateBoardArea(); if (parent.GetUnit()) //change mils? to cm? { areaPCB = areaPCB / 155000.31; //(1/2.54*2.54) TopArea = TopArea / 155000.31; BotArea = BotArea / 155000.31; } System.Windows.Forms.MessageBox.Show((onlySelectedComponent ? "Selected Component side walls:" : "All side walls of Components:") + Environment.NewLine + (CalculateTopSide ? "Top Side Components: " + TopArea + Environment.NewLine : "") + (CalculateBotSide ? "Bot Side Components: " + BotArea + Environment.NewLine : "") + ((!CalculateBotSide && !CalculateTopSide) ? "No Elements allowed, please run check with other parameters!" : "") + Environment.NewLine + "Board Area " + areaPCB + (parent.GetUnit() ? " cm?":" mils?") , "Result", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); }