Exemple #1
0
        public void Execute(IPCBIWindow parent)
        {
            IStep step = parent.GetCurrentStep();

            if (step == null)
            {
                return;
            }

            //the symbol diameter selected by user
            float diameterReplacedSymbolsInMils = 1;

            foreach (ILayer activeLayer in step.GetActiveLayerList())
            {
                if (!(activeLayer is IODBLayer)) //component and picture layer irrelevant
                {
                    continue;
                }

                IODBLayer Layer       = (IODBLayer)activeLayer;
                int       symbolIndex = -1;
                IFilter.AddToolDefinitionRound(Layer, diameterReplacedSymbolsInMils);
                foreach (IODBObject obj in Layer.GetAllLayerObjects())
                {
                    if (obj.GetDiameter() == 0) //all elements with diameter 0 replaced by new symbol
                    {
                        if (symbolIndex < 0)
                        {
                            symbolIndex = IFilter.AddToolDefinitionRound(Layer, diameterReplacedSymbolsInMils); //add new symbol only if used
                        }
                        obj.SetSpecifics(obj.GetSpecificsD(), symbolIndex);
                    }
                }
            }
        }
        public void Execute(IPCBIWindow parentPCBI)
        {
            if (parentPCBI == null)
            {
                MessageBox.Show("No license!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return;
            }

            if (!parentPCBI.JobIsLoaded)
            {
                return;
            }
            IStep curStep = parentPCBI.GetCurrentStep();

            if (curStep == null)
            {
                return;                  //no step -> no job -> break;
            }
            IFilter filter = new IFilter(parentPCBI);

            foreach (ILayer layer in curStep.GetActiveLayerList())
            {
                IODBLayer  newLayer    = filter.CreateEmptyODBLayer("newLayerWithCutting_" + layer.GetLayerName(), curStep.Name, false);
                IPolyClass outlinePoly = curStep.GetPCBOutlinePoly();

                if ((!(layer is IODBLayer)) || !CutRectangle(outlinePoly, (IODBLayer)layer, newLayer, filter, parentPCBI))
                {
                    MessageBox.Show("Something is wrong, cutting has not worked!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

            parentPCBI.UpdateView();
            IMatrix matrix = parentPCBI.GetMatrix();

            matrix.UpdateDataAndList();
        }
Exemple #3
0
        public void parent_PCBIActiveLayerChanged(object sender, EventArgs e)
        {
            int   i    = 0;
            IStep step = Parent.GetCurrentStep();

            if (step == null)
            {
                return;
            }
            List <ILayer> activeLayers = step.GetActiveLayerList();

            if (activeLayers.Count != 2)
            {
                return;
            }
            foreach (ILayer layer in activeLayers)
            {
                if (layer.GetType() == typeof(IODBLayer))
                {
                    if (i == 0)
                    {
                        i++;
                        ((IODBLayer)layer).Col = Color.FromArgb(255, 255, 250, 0);
                    }
                    else
                    if (i == 1)
                    {
                        ((IODBLayer)layer).Col = Color.FromArgb(255, 255, 240, 0);
                    }
                }
            }
            Parent.IColorsetting.ColorMix = PCBI.DrawingMode.special;
            Parent.UpdateView();
        }
        public void Execute(IPCBIWindow parent)
        {
            IStep curStep = parent.GetCurrentStep();

            if (curStep == null)
            {
                return;
            }

            foreach (ILayer layer in curStep.GetActiveLayerList())
            {
                if (layer is IODBLayer)
                {
                    ((IODBLayer)layer).PolygonizeLayer(0, false);
                }
            }

            parent.UpdateView();
        }
            internal void doWork(IPCBIWindow parent, bool splitRoutItem, bool activateNewLayer)
            {
                IStep   step   = parent.GetCurrentStep();
                IMatrix matrix = parent.GetMatrix();
                IFilter filter = new IFilter(parent);

                //if true the new layer need to be activated
                activateNewCreatedLayer = activateNewLayer;

                //sets the bool if rout should be used
                withRout = splitRoutItem;

                foreach (string currLayerName in matrix.GetAllDrillLayerNames())
                {
                    Dictionary <string, List <IODBObject> > allNewLayerDict = new Dictionary <string, List <IODBObject> >();

                    drill_ = new List <IODBObject>();

                    drillPlatedNormal    = new List <IODBObject>();
                    drillNonPlatedNormal = new List <IODBObject>();
                    drillViaNormal       = new List <IODBObject>();

                    drillRout          = new List <IODBObject>();
                    drillPlatedRout    = new List <IODBObject>();
                    drillNonPlatedRout = new List <IODBObject>();
                    drillViaRout       = new List <IODBObject>();

                    noAttributesPadsLayerNameCreated    = false;
                    noAttributesNotPadsLayerNameCreated = false;

                    platedLayerNameCreatedRout    = false;
                    nonPlatedLayerNameCreatedRout = false;
                    viaLayerNameCreatedRout       = false;

                    platedLayerNameCreatedNormal    = false;
                    nonPlatedLayerNameCreatedNormal = false;
                    viaLayerNameCreatedNormal       = false;

                    //only activate layer can be splitted
                    if (activateNewCreatedLayer)
                    {
                        if (!step.GetActiveLayerList().Contains(step.GetLayer(currLayerName)))
                        {
                            continue;
                        }
                    }

                    //checks if the layer is a splitted layer
                    if ((currLayerName.Length > 7 && currLayerName.Substring(currLayerName.Length - 7, 7).Equals("_plated")) || (currLayerName.Length > 4 && currLayerName.Substring(currLayerName.Length - 4, 4).Equals("_via")))
                    {
                        continue;
                    }

                    //checks if the new layer wasn't already splitted last time
                    foreach (string allOtherLayerName in matrix.GetAllDrillLayerNames())
                    {
                        if (activateNewCreatedLayer)
                        {
                            string searchedLayerName = currLayerName.ToLower() + "_plated";
                            if (allOtherLayerName.ToLower().Equals(searchedLayerName))
                            {
                                step.GetLayer(searchedLayerName).EnableLayer(true);
                            }
                            searchedLayerName = currLayerName.ToLower() + "_non_plated";
                            if (allOtherLayerName.ToLower().Equals(searchedLayerName))
                            {
                                step.GetLayer(searchedLayerName).EnableLayer(true);
                            }
                            searchedLayerName = currLayerName.ToLower() + "_via";
                            if (allOtherLayerName.ToLower().Equals(searchedLayerName))
                            {
                                step.GetLayer(searchedLayerName).EnableLayer(true);
                            }
                        }
                        if (allOtherLayerName.ToLower().Equals(currLayerName.ToLower() + "_plated") || allOtherLayerName.ToLower().Equals(currLayerName.ToLower() + "_non_plated") || allOtherLayerName.ToLower().Equals(currLayerName.ToLower() + "_via"))
                        {
                            skipLayerWasAlreadySplitted = true;
                            continue;
                        }
                    }

                    //if it was already splitted then skip it
                    if (skipLayerWasAlreadySplitted)
                    {
                        skipLayerWasAlreadySplitted = false;
                        continue;
                    }

                    //checks if layer is a drilllayer
                    if (matrix.GetMatrixLayerType(currLayerName) == MatrixLayerType.Drill)
                    {
                        ILayer         lay     = step.GetLayer(currLayerName);
                        List <IObject> objects = lay.GetAllLayerObjects();
                        foreach (IODBObject currObj in objects)
                        {
                            Dictionary <PCBI.FeatureAttributeEnum, string> objDict = currObj.GetAttributesDictionary();
                            if (objDict.Count != 0)
                            {
                                if (objDict.ContainsKey(PCBI.FeatureAttributeEnum.drill))
                                {
                                    if (currObj.Type == IObjectType.Pad)
                                    {
                                        #region Rout
                                        if (withRout)
                                        {
                                            if (objDict[PCBI.FeatureAttributeEnum.drill] == "non_plated")
                                            {
                                                drillNonPlatedNormal.Add(currObj);
                                                if (!nonPlatedLayerNameCreatedNormal)
                                                {
                                                    allNewLayerDict.Add(currLayerName + "_non_plated", drillNonPlatedNormal);
                                                    nonPlatedLayerNameCreatedNormal = true;
                                                }
                                            }
                                            else if (objDict[PCBI.FeatureAttributeEnum.drill] == "plated")
                                            {
                                                drillPlatedNormal.Add(currObj);
                                                if (!platedLayerNameCreatedNormal)
                                                {
                                                    allNewLayerDict.Add(currLayerName + "_plated", drillPlatedNormal);
                                                    platedLayerNameCreatedNormal = true;
                                                }
                                            }
                                            else if (objDict[PCBI.FeatureAttributeEnum.drill] == "via")
                                            {
                                                drillViaNormal.Add(currObj);
                                                if (!viaLayerNameCreatedNormal)
                                                {
                                                    allNewLayerDict.Add(currLayerName + "_via", drillViaNormal);
                                                    viaLayerNameCreatedNormal = true;
                                                }
                                            }
                                            else
                                            {
                                                drill_.Add(currObj);
                                                if (!noAttributesPadsLayerNameCreated)
                                                {
                                                    allNewLayerDict.Add(currLayerName + "_", drill_);
                                                    noAttributesPadsLayerNameCreated = true;
                                                }
                                            }
                                        }
                                        #endregion
                                        #region Without Rout
                                        else
                                        {
                                            if (objDict[PCBI.FeatureAttributeEnum.drill] == "non_plated")
                                            {
                                                drillNonPlatedRout.Add(currObj);
                                                if (!nonPlatedLayerNameCreatedRout)
                                                {
                                                    allNewLayerDict.Add(currLayerName + "_non_plated_rout", drillNonPlatedRout);
                                                    nonPlatedLayerNameCreatedRout = true;
                                                }
                                            }
                                            else if (objDict[PCBI.FeatureAttributeEnum.drill] == "plated")
                                            {
                                                drillPlatedRout.Add(currObj);
                                                if (!platedLayerNameCreatedRout)
                                                {
                                                    allNewLayerDict.Add(currLayerName + "_plated_rout", drillPlatedRout);
                                                    platedLayerNameCreatedRout = true;
                                                }
                                            }
                                            else if (objDict[PCBI.FeatureAttributeEnum.drill] == "via")
                                            {
                                                drillViaRout.Add(currObj);
                                                if (!viaLayerNameCreatedRout)
                                                {
                                                    allNewLayerDict.Add(currLayerName + "_via_rout", drillViaRout);
                                                    viaLayerNameCreatedRout = true;
                                                }
                                            }
                                            else
                                            {
                                                drill_.Add(currObj);
                                                if (!noAttributesPadsLayerNameCreated)
                                                {
                                                    allNewLayerDict.Add(currLayerName + "_", drill_);
                                                    noAttributesPadsLayerNameCreated = true;
                                                }
                                            }
                                        }
                                        #endregion
                                    }
                                    else if (withRout)
                                    {
                                        #region Line-Arcs-Surfaces-Text + Rout
                                        if (objDict[PCBI.FeatureAttributeEnum.drill] == "non_plated")
                                        {
                                            drillNonPlatedRout.Add(currObj);
                                            if (!nonPlatedLayerNameCreatedRout)
                                            {
                                                allNewLayerDict.Add("rout_" + currLayerName + "_non_plated", drillNonPlatedRout);
                                                nonPlatedLayerNameCreatedRout = true;
                                            }
                                        }
                                        else if (objDict[PCBI.FeatureAttributeEnum.drill] == "plated")
                                        {
                                            drillPlatedRout.Add(currObj);
                                            if (!platedLayerNameCreatedRout)
                                            {
                                                allNewLayerDict.Add("rout_" + currLayerName + "_plated", drillPlatedRout);
                                                platedLayerNameCreatedRout = true;
                                            }
                                        }
                                        else if (objDict[PCBI.FeatureAttributeEnum.drill] == "via")
                                        {
                                            drillViaRout.Add(currObj);
                                            if (!viaLayerNameCreatedRout)
                                            {
                                                allNewLayerDict.Add("rout_" + currLayerName + "_via", drillViaRout);
                                                viaLayerNameCreatedRout = true;
                                            }
                                        }
                                        else
                                        {
                                            drillRout.Add(currObj);
                                            if (!noAttributesNotPadsLayerNameCreated)
                                            {
                                                allNewLayerDict.Add("rout_" + currLayerName, drillRout);
                                                noAttributesNotPadsLayerNameCreated = true;
                                            }
                                        }
                                        #endregion
                                    }
                                }
                            }
                            else
                            {
                                #region No Attributes + Rout
                                if (withRout)
                                {
                                    if (currObj.Type == IObjectType.Pad)
                                    {
                                        drill_.Add(currObj);
                                        if (!noAttributesPadsLayerNameCreated)
                                        {
                                            allNewLayerDict.Add(currLayerName + "_", drill_);
                                            noAttributesPadsLayerNameCreated = true;
                                        }
                                    }
                                    else
                                    {
                                        drillRout.Add(currObj);
                                        if (!noAttributesNotPadsLayerNameCreated)
                                        {
                                            allNewLayerDict.Add("rout_" + currLayerName, drillRout);
                                            noAttributesNotPadsLayerNameCreated = true;
                                        }
                                    }
                                }
                                #endregion
                                #region No Attributes Without Rout
                                else
                                {
                                    if (currObj.Type == IObjectType.Pad)
                                    {
                                        drill_.Add(currObj);
                                        if (!noAttributesPadsLayerNameCreated)
                                        {
                                            allNewLayerDict.Add(currLayerName + "_", drill_);
                                            noAttributesPadsLayerNameCreated = true;
                                        }
                                    }
                                }
                                #endregion
                            }
                        }

                        if (allNewLayerDict.Count > 1) //wenn alle vom gleichen Typ sind muss nicht gesplittet werden!
                        {
                            foreach (string currNewLayerName in allNewLayerDict.Keys)
                            {
                                filter = new IFilter(parent);
                                CreateNewDrillODBLayer(filter, currNewLayerName, parent, allNewLayerDict[currNewLayerName], activateNewCreatedLayer);
                            }
                        }
                    }
                }
                matrix.UpdateDataAndList();
            }
        public void Execute(IPCBIWindow parent)
        {
            IStep   step   = parent.GetCurrentStep();
            IMatrix matrix = parent.GetMatrix();

            if (step == null || matrix == null)
            {
                return;
            }

            IODBLayer IODBLayerOrg = null;
            IODBLayer IODBLayerNew = null;

            foreach (ILayer activeLayer in step.GetActiveLayerList()) //search for the first two active layer to copy from first to second
            {
                if (activeLayer is IODBLayer)
                {
                    if (IODBLayerOrg == null)
                    {
                        IODBLayerOrg = (IODBLayer)activeLayer;
                    }
                    else if (IODBLayerNew == null)
                    {
                        IODBLayerNew = (IODBLayer)activeLayer;
                    }
                    else
                    {
                        break; //only the first two layers...
                    }
                }
            }
            if (IODBLayerOrg == null || IODBLayerNew == null)
            {
                return;
            }

            IFilter filter = new IFilter(parent);

            if (IODBLayerOrg is IODBLayer)
            {
                Dictionary <int, int> ShapeIndexOldNew = new Dictionary <int, int>(); //set new shape index if symbol is created.

                foreach (IODBObject obj in IODBLayerOrg.GetAllLayerObjects())
                {
                    IODBObject        objNew = null;
                    IObjectSpecificsD spec   = obj.GetSpecificsD();
                    switch (obj.Type)
                    {
                    case IObjectType.Arc:
                        objNew = filter.CreateArc(IODBLayerNew);
                        if (!ShapeIndexOldNew.ContainsKey(((IArcSpecificsD)spec).ShapeIndex))
                        {
                            int indexNew = IFilter.AddToolFromODBString(IODBLayerNew, ((IArcSpecificsD)spec).ODBSymbol_String);
                            ShapeIndexOldNew.Add(((IArcSpecificsD)spec).ShapeIndex, indexNew);
                        }
                        ((IArcSpecificsD)spec).ShapeIndex = ShapeIndexOldNew[((IArcSpecificsD)spec).ShapeIndex];
                        break;

                    case IObjectType.Line:
                        objNew = filter.CreateLine(IODBLayerNew);
                        if (!ShapeIndexOldNew.ContainsKey(((ILineSpecificsD)spec).ShapeIndex))
                        {
                            int indexNew = IFilter.AddToolFromODBString(IODBLayerNew, ((ILineSpecificsD)spec).ODBSymbol_String);
                            ShapeIndexOldNew.Add(((ILineSpecificsD)spec).ShapeIndex, indexNew);
                        }
                        ((ILineSpecificsD)spec).ShapeIndex = ShapeIndexOldNew[((ILineSpecificsD)spec).ShapeIndex];
                        break;

                    case IObjectType.Pad:
                        objNew = filter.CreatePad(IODBLayerNew);
                        if (!ShapeIndexOldNew.ContainsKey(((IPadSpecificsD)spec).ShapeIndex))
                        {
                            IFilter.ToolDefinition toolDef = filter.GetSymbolByShapeIndex(((IPadSpecificsD)spec).ShapeIndex, (IODBLayer)IODBLayerOrg);
                            int indexNew = -1;
                            if (toolDef.Type == PCBI.Symbol_Type.special)
                            {
                                indexNew = IFilter.AddToolDefinitionSpecial(IODBLayerNew, (IODBLayer)IODBLayerOrg, toolDef.ShapeIndex);
                            }
                            else
                            {
                                indexNew = IFilter.AddToolFromODBString(IODBLayerNew, ((IPadSpecificsD)spec).ODBSymbol_String);
                            }
                            ShapeIndexOldNew.Add(((IPadSpecificsD)spec).ShapeIndex, indexNew);
                        }
                        ((IPadSpecificsD)spec).ShapeIndex = ShapeIndexOldNew[((IPadSpecificsD)spec).ShapeIndex];
                        break;

                    case IObjectType.Surface:
                        objNew = filter.CreatePolygon(IODBLayerNew);
                        break;

                    case IObjectType.Text:
                        objNew = filter.CreateText(IODBLayerNew);
                        break;

                    default:
                        System.Diagnostics.Debug.WriteLine("Case not possible!");
                        break;
                    }

                    if (objNew != null)
                    {
                        objNew.SetSpecifics(spec);
                    }
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Not implemented for components!");
            }
            parent.UpdateView();
        }
Exemple #7
0
            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();
            }
Exemple #8
0
        public void Execute(IPCBIWindow parent)
        {
            //set all signal layers in one image
            string Rows = Microsoft.VisualBasic.Interaction.InputBox("How many rows do you wish?", "Setup", "2");
            int    rows = 2;

            try
            {
                rows = int.Parse(Rows);
            }
            catch (Exception re)
            {
                MessageBox.Show("Please provide a number\n" + re.ToString());
            }

            string pathForImage = System.IO.Path.GetTempPath() + "imageComplete.png"; //output somewhere

            stopImaging = false;                                                      //internal bool to use cancel button
            float DPI        = 1000;                                                  //in pixel foreach layer
            int   maxWidtBMP = 40000;                                                 //image class is dangerous for big RAM usage!

            int     countImagesEachLine           = rows;                             //maximum of image in one line
            bool    AddDrillsToImage              = true;                             //see where are the connections to other layers
            bool    AddCompToImageAsSeperateLayer = true;                             //see where are the connections to other layers
            IStep   step   = parent.GetCurrentStep();
            IMatrix matrix = parent.GetMatrix();

            if (step == null || matrix == null)
            {
                return;
            }
            PCB_Investigator.PCBIWindows.PCBIWorkingDialog working = null;
            try
            {
                working = new PCB_Investigator.PCBIWindows.PCBIWorkingDialog(); //show waiting dialog, because for some projects it is very slow
                working.CanCancel(true);
                working.CancelPressed += working_CancelPressed;
                working.SetAnimationStatus(false);
                working.ShowWorkingDlgAsThread();
                int curValPercentage = 0;
                working.SetStatusPercent(curValPercentage);

                List <string> allSignalLayerNames = matrix.GetAllSignalLayerNames();
                if (!AddCompToImageAsSeperateLayer)
                {
                    allSignalLayerNames.Insert(0, matrix.GetTopComponentLayer());
                    allSignalLayerNames.Add(matrix.GetBotComponentLayer());
                }
                List <ILayer> activeLayerList = step.GetActiveLayerList(); //remember active layer list to set them later back
                step.TurnOffAllLayer();

                int   maxHeight     = 0;
                int   maxWidth      = 0;
                int   completeWidth = 0;
                int   lines         = 1;
                bool  setBackHatch  = parent.IColorsetting.UseHatchMode;
                Color setBackColor  = parent.IColorsetting.SelectionColor;

                parent.IColorsetting.SelectionColor = Color.White; //highlight selection better with plane color
                parent.IColorsetting.UseHatchMode   = false;

                RectangleF boundsStep = step.GetBounds();
                boundsStep.Inflate(20, 20);

                int height = (int)(boundsStep.Height * DPI / 1000);
                int width  = (int)(boundsStep.Width * DPI / 1000); //set the step bounds with DPI
                if (height > maxHeight)
                {
                    maxHeight = height;
                }

                curValPercentage = 10;
                working.SetStatusPercent(curValPercentage);

                Dictionary <string, System.Drawing.Bitmap> allLayerImages = new Dictionary <string, System.Drawing.Bitmap>();
                int counterLayers = 0;
                foreach (string layername in allSignalLayerNames)
                {
                    if (stopImaging)
                    {
                        break;
                    }
                    counterLayers++;
                    working.SetStatusText("working on " + layername);
                    curValPercentage += 80 / allSignalLayerNames.Count; //we want only the part in the middle of the progress bar...
                    working.SetStatusPercent(curValPercentage);
                    Bitmap resultImage;
                    if (step.GetLayer(layername) is IODBLayer)
                    {
                        IODBLayer signalLayer = (IODBLayer)step.GetLayer(layername);
                        signalLayer.EnableLayer(true);
                        if (AddDrillsToImage)
                        {
                            List <ILayer> drawList = new List <ILayer>();
                            foreach (string layerDrillName in matrix.GetAllDrillLayersForThisLayer(layername))
                            {
                                drawList.Add(step.GetLayer(layerDrillName));
                            }
                            drawList.Add(signalLayer);
                            if (AddCompToImageAsSeperateLayer)
                            {
                                if (matrix.GetTopSignalLayer() == layername)
                                {
                                    ILayer layer = step.GetLayer(matrix.GetTopComponentLayer());
                                    if (layer != null)
                                    {
                                        drawList.Add(layer);
                                    }
                                }
                                if (matrix.GetBotSignalLayer() == layername)
                                {
                                    ILayer layer = step.GetLayer(matrix.GetBotComponentLayer());
                                    if (layer != null)
                                    {
                                        drawList.Add(layer);
                                    }
                                }
                            }
                            resultImage = step.GetBitmap(drawList, boundsStep, width, height, true, false, false, false);
                            // public Bitmap GetBitmap(	List<ILayer> Layers,RectangleF DetailRectangle,	int Width,	int Height,	bool DrawPCBOutline,	bool FillBoardOutline,	bool ShowComponentDetails,	bool IgnoreSelection,	bool DrawOnlySelection,	out RectangleF DrawnRectangle

                            Bitmap copyBitmap = new Bitmap(resultImage); //do copy the image before the old one will be disposed

                            resultImage = copyBitmap;
                        }
                        else
                        {
                            resultImage = step.GetBitmap(new List <ILayer>()
                            {
                                signalLayer
                            }, boundsStep, width, height, true, false, false, false);
                        }
                        if (resultImage != null)
                        {
                            allLayerImages.Add(layername, resultImage); //remember the layer image later
                        }
                        signalLayer.DisableLayer();
                    }
                    else if (!AddCompToImageAsSeperateLayer && step.GetLayer(layername) is ICMPLayer)
                    {
                        ICMPLayer cmpLayer = (ICMPLayer)step.GetLayer(layername);
                        resultImage = step.GetBitmap(new List <ILayer>()
                        {
                            cmpLayer
                        }, boundsStep, width, height, true, false, true, false);

                        allLayerImages.Add(layername, resultImage); //remember the layer image later
                    }

                    if (completeWidth + width > maxWidtBMP || counterLayers > countImagesEachLine) //max image size
                    {
                        lines++;
                        completeWidth = width;
                        counterLayers = 1;
                    }
                    else
                    {
                        completeWidth += width;
                    }

                    if (completeWidth > maxWidth)
                    {
                        maxWidth = completeWidth;
                    }
                }
                working.SetStatusText("built new image...");

                working.SetStatusPercent(85);
                Bitmap bitComplete   = null;
                bool   needDownScale = false;

                try
                {
                    bitComplete = new Bitmap(maxWidth, lines * (maxHeight + 100) + 60); //depending on your design this constructor sometimes throw an exception
                }
                catch
                {
                    bitComplete   = new Bitmap(maxWidth / 10, lines * (maxHeight + 1000) / 10 + 60);
                    needDownScale = true; //depending on your machine settings and RAM it can make problems by creating big images.
                }

                parent.IColorsetting.UseHatchMode   = setBackHatch;
                parent.IColorsetting.SelectionColor = setBackColor;

                Graphics g = Graphics.FromImage(bitComplete);
                g.Clear(Color.Transparent);
                int Xoff = 0;
                int Yoff = 0;
                working.SetStatusText("set images in one... ");

                Font f = new Font("Arial", needDownScale ? 20 : 40); //we need a font to write layernames
                int  counterImagesInLine = 0;
                foreach (string layer in allLayerImages.Keys)
                {
                    counterImagesInLine++;
                    if (needDownScale && (Xoff + allLayerImages[layer].Width / 10 > bitComplete.Width || counterImagesInLine > countImagesEachLine))
                    {
                        Yoff += maxHeight / 10 + 100; //space for text
                        Xoff  = 0;
                        counterImagesInLine = 1;
                    }
                    else if (Xoff + allLayerImages[layer].Width > maxWidtBMP || counterImagesInLine > countImagesEachLine)
                    {
                        Yoff += maxHeight + 100; //space for text
                        Xoff  = 0;
                        counterImagesInLine = 1;
                    }
                    if (needDownScale)
                    {
                        g.DrawImage(allLayerImages[layer], new RectangleF(Xoff, Yoff + 100, width / 10, height / 10), new RectangleF(0, 0, allLayerImages[layer].Width, allLayerImages[layer].Height), GraphicsUnit.Pixel);
                    }
                    else
                    {
                        g.DrawImage(allLayerImages[layer], new Point(Xoff, Yoff + 100));
                    }

                    g.DrawString(layer, f, Brushes.Red, new PointF(Xoff + 50, Yoff + 30)); //name of layer

                    if (needDownScale)
                    {
                        Xoff += allLayerImages[layer].Width / 10;
                    }
                    else
                    {
                        Xoff += allLayerImages[layer].Width;
                    }
                }
                string textForFooter = parent.GetJobName() + " - creation date: " + DateTime.Now.ToString() + "    www.PCB-Investigator.com";

                SizeF size = g.MeasureString(textForFooter, f);

                g.DrawString(textForFooter, f, Brushes.White, new PointF((bitComplete.Width - size.Width) / 2, bitComplete.Height - 60)); //name of layer

                working.SetStatusPercent(91);

                foreach (ILayer layerActive in activeLayerList)
                {
                    layerActive.EnableLayer(true);
                }
                working.SetStatusPercent(95);

                try
                {
                    working.SetStatusText("saving result...");
                    bitComplete.Save(pathForImage, ImageFormat.Png);

                    //open image with standard viewer
                    System.Diagnostics.Process.Start(pathForImage);
                }
                catch
                { }
                working.DoClose();
            }
            catch (Exception ex)
            {
                if (working != null)
                {
                    working.DoClose();
                }

                MessageBox.Show("Can't create image, because " + Environment.NewLine + ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }