private void CountPrimitivesOfFootprint() { OpenFileDialog openDialog = InitFileOpenDialog("PCBLIB"); if (openDialog == null) { return; } string[] FootprintFiles = openDialog.FileNames; foreach (string FootprintFile in FootprintFiles) { System.Threading.Thread.Sleep(5000); IServerDocument PcbDocuemnt = OpenDocuemnt(FootprintFile, "PCBLIB"); if (PcbDocuemnt == null) { DXP.Utils.ShowMessage("Failed to open " + FootprintFile); return; } IPCB_ServerInterface PcbServer = PCB.GlobalVars.PCBServer; IPCB_Library PcbLib = PcbServer.GetCurrentPCBLibrary(); IPCB_Board currentBoard = PcbServer.GetCurrentPCBBoard(); currentBoard.GraphicalView_ZoomRedraw(); IPCB_LibraryIterator LibIteartor = PcbLib.LibraryIterator_Create(); LibIteartor.AddFilter_ObjectSet(new PCB.TObjectSet(PCB.TObjectId.eComponentObject)); IPCB_LibComponent PcbCmp = LibIteartor.FirstPCBObject() as IPCB_LibComponent; while (PcbCmp != null) { string FootprintDescription = PcbCmp.GetState_Description(); string FootprintName = PcbCmp.GetState_Pattern(); IPCB_GroupIterator PcbObjItera = PcbCmp.GroupIterator_Create(); int count = 0; IPCB_Primitive PcbObj = PcbObjItera.FirstPCBObject(); while (PcbObj != null) { count++; PcbObj = PcbObjItera.NextPCBObject(); } PcbCmp.GroupIterator_Destroy(ref PcbObjItera); System.IO.File.AppendAllText(@"G:\report.txt", FootprintName + "|" + FootprintDescription + "|" + count.ToString() + "\r\n"); PcbCmp = LibIteartor.NextPCBObject() as IPCB_LibComponent; } PcbLib.LibraryIterator_Destroy(ref LibIteartor); CloseDocument(PcbDocuemnt); } }
/// <summary> /// Will show or hide reference designators based on NameOn parameter. /// </summary> /// <param name="NameOn">true = show refdes', false = hide refdes'</param> public void ShowHide(IPCB_Board Board, bool NameOn, bool Discretes = false) { try { IPCB_BoardIterator BoardIterator; IPCB_Component Component; if (Board == null) { return; } //Iterate theough all components on the board. BoardIterator = Board.BoardIterator_Create(); PCB.TObjectSet FilterSet = new PCB.TObjectSet(); //Filter for components only. FilterSet.Add(PCB.TObjectId.eComponentObject); BoardIterator.AddFilter_ObjectSet(FilterSet); BoardIterator.AddFilter_LayerSet(PCBConstant.V6AllLayersSet); //Filter all layers. BoardIterator.AddFilter_Method(TIterationMethod.eProcessAll); Component = (IPCB_Component)BoardIterator.FirstPCBObject(); while (Component != null) { if (!Discretes) { Component.BeginModify(); Component.SetState_NameOn(NameOn); //Show or hide refdes. Component.EndModify(); } else { if (Component.GetState_Name().GetState_Text().StartsWith("R") || Component.GetState_Name().GetState_Text().StartsWith("C")) { Component.BeginModify(); Component.SetState_NameOn(NameOn); //Show or hide refdes. Component.EndModify(); } } Component = (IPCB_Component)BoardIterator.NextPCBObject(); } //Iterator clean-up Board.BoardIterator_Destroy(ref BoardIterator); Board.GraphicalView_ZoomRedraw(); } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); } }
/// <summary> /// Will adjust refdes orientation to match component orientation. /// </summary> public void FixRefDesOrientation() { try { IPCB_BoardIterator BoardIterator; IPCB_Component Component; IPCB_Text RefDes; IPCB_Board Board = Util.GetCurrentPCB(); if (Board == null) { return; } //Iterate theough all components on the board. BoardIterator = Board.BoardIterator_Create(); PCB.TObjectSet FilterSet = new PCB.TObjectSet(); //Filter for components only. FilterSet.Add(PCB.TObjectId.eComponentObject); BoardIterator.AddFilter_ObjectSet(FilterSet); BoardIterator.AddFilter_LayerSet(PCBConstant.V6AllLayersSet); //Filter all layers. BoardIterator.AddFilter_Method(TIterationMethod.eProcessAll); //int cnt = 0; //Component = (IPCB_Component)BoardIterator.FirstPCBObject(); //while (Component != null) //{ // cnt++; // Component = (IPCB_Component)BoardIterator.NextPCBObject(); //} Component = (IPCB_Component)BoardIterator.FirstPCBObject(); //DXP.Utils.PercentInit("Updating RefDes", cnt);//Progressbar init. while (Component != null) { RefDes = Component.GetState_Name(); if (Component.GetState_NameAutoPos() == TTextAutoposition.eAutoPos_CenterCenter) { Component.SetState_NameAutoPos(TTextAutoposition.eAutoPos_Manual); Component.BeginModify(); RefDes.BeginModify(); switch (Convert.ToInt32(Component.GetState_Rotation())) { case 0: //for bottom: 90=270 RefDes.SetState_Rotation(0); break; case 90: if (RefDes.GetState_Layer() == TV6_Layer.eV6_BottomOverlay) { RefDes.SetState_Rotation(270); } else { RefDes.SetState_Rotation(90); } break; case 180: RefDes.SetState_Rotation(0); break; case 270: if (RefDes.GetState_Layer() == TV6_Layer.eV6_BottomOverlay) { RefDes.SetState_Rotation(270); } else { RefDes.SetState_Rotation(90); } break; } //Component.SetState_NameAutoPos(TTextAutoposition.eAutoPos_CenterCenter); Component.ChangeNameAutoposition(TTextAutoposition.eAutoPos_CenterCenter); RefDes.EndModify(); RefDes.GraphicallyInvalidate(); Component.EndModify(); Component.GraphicallyInvalidate(); } //DXP.Utils.PercentUpdate(); Component = (IPCB_Component)BoardIterator.NextPCBObject(); } //Iterator clean-up Board.BoardIterator_Destroy(ref BoardIterator); Board.GraphicalView_ZoomRedraw(); //Board.GraphicallyInvalidate(); //DXP.Utils.PercentFinish(); System.Windows.Forms.MessageBox.Show("Process Complete"); } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); } }
/// <summary> /// Aligns variant component to base component. /// </summary> void AlignSelected() { IPCB_BoardIterator BoardIterator; IPCB_Component Component; string RefDes; IPCB_Board Board = Util.GetCurrentPCB(); if (Board == null) { return; } //Iterate theough all components on the board. BoardIterator = Board.BoardIterator_Create(); PCB.TObjectSet FilterSet = new PCB.TObjectSet(); //Filter for components only. FilterSet.Add(PCB.TObjectId.eComponentObject); BoardIterator.AddFilter_ObjectSet(FilterSet); BoardIterator.AddFilter_LayerSet(PCBConstant.V6AllLayersSet); //Filter all layers. BoardIterator.AddFilter_Method(TIterationMethod.eProcessAll); Component = (IPCB_Component)BoardIterator.FirstPCBObject(); Board.BeginModify(); while (Component != null) { RefDes = Component.GetState_Name().GetState_Text(); if (Component.GetState_SourceUniqueId() != null) { if (!Component.GetState_SourceUniqueId().Contains("@") || RefDes.Contains("EM") || RefDes.Contains("FM")) //Verify component is not a variant. { if (RefDes.Contains("EM")) { RefDes = RefDes.Replace("EM", "FM"); } else if (RefDes.Contains("FM")) { RefDes = RefDes.Replace("FM", "EM"); } if (SelectedRef.Contains(RefDes)) { foreach (IPCB_Component item in SelectedComp) { if (item.GetState_Name().GetState_Text() == RefDes) //Match component { //Copy position, laye and rotation settings from base to variant. item.SetState_Layer(Component.GetState_Layer()); item.SetState_XLocation(Component.GetState_XLocation()); item.SetState_YLocation(Component.GetState_YLocation()); item.SetState_Rotation(Component.GetState_Rotation()); Board.SetState_DocumentHasChanged(); break; } } } } } Component = (IPCB_Component)BoardIterator.NextPCBObject(); } Board.EndModify(); Board.GraphicalView_ZoomRedraw(); Board.GraphicallyInvalidate(); //Iterator clean-up Board.BoardIterator_Destroy(ref BoardIterator); MessageBox.Show("Process Complete"); }