private bool SingleViaReplace() { if (PCBServer == null) { return(false); } IPCB_BoardIterator BoardIterator; IPCB_Via Via; Board = Util.GetCurrentPCB(); if (Board == null) { return(false); } BoardIterator = Board.BoardIterator_Create(); //Iterate theough all components on the board. PCB.TObjectSet FilterSet = new PCB.TObjectSet(); //Filter for components only. FilterSet.Add(PCB.TObjectId.eViaObject); BoardIterator.AddFilter_ObjectSet(FilterSet); BoardIterator.AddFilter_LayerSet(PCBConstant.V6AllLayersSet); //Filter all layers. BoardIterator.AddFilter_Method(TIterationMethod.eProcessAll); IPCB_DrillLayerPair OldPair = null, DrillPair = null; List <IPCB_DrillLayerPair> NewPairs = new List <IPCB_DrillLayerPair>(); for (int i = 0; i < Board.GetState_DrillLayerPairsCount(); i++) { DrillPair = Board.GetState_LayerPair(i); if (lstBefore.SelectedItem.ToString() == DrillPair.GetState_Description()) { OldPair = DrillPair; } if (lstAfter.SelectedItems.Contains(DrillPair.GetState_Description())) { NewPairs.Add(DrillPair); } } Via = BoardIterator.FirstPCBObject() as IPCB_Via; Board.BeginModify(); while (Via != null) { if (Via.GetState_StartLayer() == OldPair.GetState_StartLayer() && Via.GetState_StopLayer() == OldPair.GetState_StopLayer()) { if (SelectedOnly) { if (Via.GetState_Selected()) { ReplaceVia(Via, NewPairs); } } else { ReplaceVia(Via, NewPairs); } } Via = BoardIterator.NextPCBObject() as IPCB_Via; } Board.EndModify(); Board.BoardIterator_Destroy(ref BoardIterator); return(true); }
private bool MultiBeforeViaReplace() { //if (PCBServer == null) // return false; IPCB_BoardIterator BoardIterator; List <IPCB_Via> BoardVias = new List <IPCB_Via>(); IPCB_Via Via; Board = Util.GetCurrentPCB(); if (Board == null) { return(false); } BoardIterator = Board.BoardIterator_Create(); //Iterate theough all components on the board. PCB.TObjectSet FilterSet = new PCB.TObjectSet(); //Filter for components only. FilterSet.Add(PCB.TObjectId.eViaObject); BoardIterator.AddFilter_ObjectSet(FilterSet); BoardIterator.AddFilter_LayerSet(PCBConstant.V6AllLayersSet); //Filter all layers. BoardIterator.AddFilter_Method(TIterationMethod.eProcessAll); IPCB_DrillLayerPair DrillPair = null; List <IPCB_DrillLayerPair> OldPairs = new List <IPCB_DrillLayerPair>(); List <IPCB_DrillLayerPair> NewPairs = new List <IPCB_DrillLayerPair>(); for (int i = 0; i < Board.GetState_DrillLayerPairsCount(); i++) { DrillPair = Board.GetState_LayerPair(i); if (lstBefore.SelectedItems.Contains(DrillPair.GetState_Description())) { OldPairs.Add(DrillPair); } if (lstAfter.SelectedItems.Contains(DrillPair.GetState_Description())) { NewPairs.Add(DrillPair); } } //Collect board vias that meet requirements Via = BoardIterator.FirstPCBObject() as IPCB_Via; while (Via != null) { foreach (IPCB_DrillLayerPair OldPair in OldPairs) { if (Via.GetState_StartLayer() == OldPair.GetState_StartLayer() && Via.GetState_StopLayer() == OldPair.GetState_StopLayer()) { if (SelectedOnly) { if (Via.GetState_Selected()) { BoardVias.Add(Via); break; } } else { BoardVias.Add(Via); break; } } } Via = BoardIterator.NextPCBObject() as IPCB_Via; } Board.BoardIterator_Destroy(ref BoardIterator); DXP.Utils.PercentInit("Replacing Vias", BoardVias.Count);//Progressbar init. //Replace vias Board.BeginModify(); IPCB_Net Net = null; int X, Y; List <IPCB_Via> Replaced = new List <IPCB_Via>(); while (BoardVias.Count > 0) { X = BoardVias[0].GetState_XLocation(); Y = BoardVias[0].GetState_YLocation(); Net = BoardVias[0].GetState_Net(); Replaced.Add(BoardVias[0]); for (int i = 1; i < BoardVias.Count; i++) { foreach (IPCB_DrillLayerPair OldPair in OldPairs) { if (BoardVias[i].GetState_Net() == Net) { if (BoardVias[i].GetState_XLocation() == X) { if (BoardVias[i].GetState_YLocation() == Y) { if (BoardVias[i].GetState_StartLayer() == OldPair.GetState_StartLayer()) { if (BoardVias[i].GetState_StopLayer() == OldPair.GetState_StopLayer()) { if (SelectedOnly) { if (BoardVias[i].GetState_Selected()) { Replaced.Add(BoardVias[i]); } } else { Replaced.Add(BoardVias[i]); } } } } } } } } if (Replaced.Count == lstBefore.SelectedItems.Count) { ReplaceVia(Replaced[0], NewPairs, false); } //Remove replaced vias from BoardVias (clean up) foreach (IPCB_Via OldVia in Replaced) { DXP.Utils.PercentUpdate(); BoardVias.Remove(OldVia); if (Replaced.Count == lstBefore.SelectedItems.Count) { Board.RemovePCBObject(OldVia); } } Replaced.Clear(); } Board.EndModify(); DXP.Utils.PercentFinish(); return(true); }