private void LoadLists() { PCBServer = PCB.GlobalVars.PCBServer; if (PCBServer == null) { MessageBox.Show("Error opening PCB."); return; } Board = Util.GetCurrentPCB(); if (Board == null) { MessageBox.Show("Invalid Board"); } IPCB_DrillLayerPair DrillPair = null; lstBefore.Items.Clear(); lstAfter.Items.Clear(); for (int i = 0; i < Board.GetState_DrillLayerPairsCount(); i++) { DrillPair = Board.GetState_LayerPair(i); lstBefore.Items.Add(DrillPair.GetState_Description()); lstAfter.Items.Add(DrillPair.GetState_Description()); } }
/// <summary> /// Toggle rule on/off. /// </summary> /// <param name="RuleName">Name of rule to toggle</param> public void ToggleDesignRule(string RuleName) { try { IPCB_Rule Rule; IPCB_Board Board = Util.GetCurrentPCB(); if (Board == null) { return; } Rule = GetRule(RuleName); if (Rule == null) { MessageBox.Show("No rule found that matches '" + RuleName + "'."); return; } PCBServer.PreProcess(); Rule.BeginModify(); // {Rule has to be prepared for modification} Rule.SetState_DRCEnabled(!Rule.GetState_DRCEnabled()); // Toggle rule state. Rule.EndModify(); // {Let script know we are done modifying the rule} Rule = null; PCBServer.PostProcess(); //{Dispatch message to system now that processing is complete} Board.DispatchMessage(SCH.SCHConstant.FromSystem, SCH.SCHConstant.BroadCast, SCH.SCHConstant.SCHMYieldToRobots, SCH.SCHConstant.NoEventData); } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); } }
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); } }
private void btnSelect_Click(object sender, EventArgs e) { if (PCBServer == null) { return; } IPCB_BoardIterator BoardIterator; IPCB_Via Via; Board = Util.GetCurrentPCB(); if (Board == null) { return; } 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; } } Via = BoardIterator.FirstPCBObject() as IPCB_Via; Board.BeginModify(); while (Via != null) { if (Via.GetState_StartLayer() == OldPair.GetState_StartLayer() && Via.GetState_StopLayer() == OldPair.GetState_StopLayer()) { Via.SetState_Selected(true); } Via = BoardIterator.NextPCBObject() as IPCB_Via; } Board.EndModify(); Board.BoardIterator_Destroy(ref BoardIterator); }
private void AddCenterMark() { IPCB_ServerInterface PcbServer = PCB.GlobalVars.PCBServer; if (PcbServer == null) { return; } IPCB_Library PcbLib = PcbServer.GetCurrentPCBLibrary(); if (PcbLib == null) { return; } 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) { IPCB_Board currentBoard = PcbServer.GetCurrentPCBBoard(); int Origin_X = currentBoard.GetState_XOrigin(); int Origin_Y = currentBoard.GetState_YOrigin(); int LineWidth = EDP.Utils.MMsToCoord((double)0.1); int HalfLineLegnth = EDP.Utils.MMsToCoord((double)0.5); V7_Layer MechLayer15 = new V7_Layer().Mechanical15(); PcbServer.PreProcess(); IPCB_Track vLine = PcbServer.PCBObjectFactory(PCB.TObjectId.eTrackObject, TDimensionKind.eNoDimension, PCB.TObjectCreationMode.eCreate_Default) as IPCB_Track; SetTrackLocaton(vLine, Origin_X - HalfLineLegnth, Origin_Y, Origin_X + HalfLineLegnth, Origin_Y); vLine.SetState_Layer((int)MechLayer15.ID); vLine.SetState_Width(LineWidth); IPCB_Track hLine = PcbServer.PCBObjectFactory(PCB.TObjectId.eTrackObject, TDimensionKind.eNoDimension, PCB.TObjectCreationMode.eCreate_Default) as IPCB_Track; SetTrackLocaton(hLine, Origin_X, Origin_Y + HalfLineLegnth, Origin_X, Origin_Y - HalfLineLegnth); hLine.SetState_Layer((int)MechLayer15.ID); hLine.SetState_Width(LineWidth); currentBoard.AddPCBObject(vLine); currentBoard.AddPCBObject(hLine); PcbServer.PostProcess(); DXP.Utils.RunCommand("PCB:Zoom", "Action=Redraw"); PcbCmp = LibIteartor.NextPCBObject() as IPCB_LibComponent; } PcbLib.LibraryIterator_Destroy(ref LibIteartor); }
/// <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); } }
//void GetNets() //{ // try // { // IPCB_Board Board; // IPCB_BoardIterator BoardIterator; // IPCB_ServerInterface PCBServer = PCB.GlobalVars.PCBServer; // IPCB_Net Net; // Board = Util.GetCurrentPCB(); // if (Board == null) // return; // //Iterate theough all nets on the board. // BoardIterator = Board.BoardIterator_Create(); // PCB.TObjectSet FilterSet = new PCB.TObjectSet(); // //Filter for nets only. // FilterSet.Add(PCB.TObjectId.eNetObject); // BoardIterator.AddFilter_ObjectSet(FilterSet); // BoardIterator.AddFilter_LayerSet(PCBConstant.V6AllLayersSet); //Filter all layers. // BoardIterator.AddFilter_Method(TIterationMethod.eProcessAll); // cboNets.Items.Clear(); // Net = (IPCB_Net)BoardIterator.FirstPCBObject(); // while (Net != null) // { // //Net.GetState_ReliefConductorWidth() // // Net.GetState_LayerUsed // //Net.GetState_ReliefEntries() // string netname = Net.GetState_Name(); // int cnt = 0; // cboNets.Items.Add(Net.GetState_Name()); // foreach (TV6_Layer layer in PCBConstant.V6InternalPlanes) // { // if (Net.GetState_LayerUsed(layer)) // cnt++; // } // Net = (IPCB_Net)BoardIterator.NextPCBObject(); // } // //Iterator clean-up // Board.BoardIterator_Destroy(ref BoardIterator); // } // catch (Exception ex) // { // ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); // } //} void LoadData() { IPCB_Board Board = Util.GetCurrentPCB(); if (Board == null) { return; } try { //PCB.IPCB_BoardHelper.GetState_InternalPlaneNetName(this PCB.IPCB_Board, PCB.V7_LayerBase) IPCB_LayerStack_V7 tmpLayerstack = Board.GetState_LayerStack_V7(); IPCB_LayerObject_V7 objLayer; objLayer = tmpLayerstack.FirstLayer(); IPCB_InternalPlane IPlane; while (objLayer != null) { if (objLayer.LayerID().ToString().Contains("InternalPlane")) { IPlane = (IPCB_InternalPlane)objLayer; //if (IPlane.GetState_NetName() == "(Multiple Nets)") //{ //} //else //{ if (!Nets.ContainsKey(IPlane.GetState_NetName())) { Nets.Add(IPlane.GetState_NetName(), new LayerValues(1, EDP.Utils.CoordToMils(objLayer.GetState_CopperThickness()))); } else { cboNets.Items.Add(IPlane.GetState_NetName()); Nets[IPlane.GetState_NetName()].Thickness += EDP.Utils.CoordToMils(objLayer.GetState_CopperThickness()); Nets[IPlane.GetState_NetName()].Count++; } //} } objLayer = tmpLayerstack.NextLayer(objLayer); } } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); } }
/// <summary> /// Will get the user layername based on the layer ID. /// </summary> /// <param name="Board">Board to get the layer name from.</param> /// <param name="LayerID">Layer data</param> /// <returns>User created name for provided layer.</returns> public static string GetLayerName(IPCB_Board Board, V7_LayerBase LayerID) { IPCB_LayerStack_V7 tmpLayerstack = Board.GetState_LayerStack_V7(); IPCB_LayerObject_V7 objLayer; objLayer = tmpLayerstack.FirstLayer(); while (objLayer != null) { if (LayerID.ID == objLayer.V7_LayerID().ID) { return(objLayer.GetState_LayerName()); } objLayer = tmpLayerstack.NextLayer(objLayer); } return(""); }
/// <summary> /// Gets a list of all layers for the provided board file. /// </summary> /// <param name="Board">Current board</param> /// <returns>List of layers.</returns> public static List <TV6_Layer> GetV6Layers(IPCB_Board Board) { List <TV6_Layer> tempList = new List <TV6_Layer>(); IPCB_LayerIterator LayerIterator = Board.LayerIterator(); //LayerIterator.AddFilter_ElectricalLayers(); LayerIterator.First(); TV6_Layer tmpLayer; do { tmpLayer = (TV6_Layer)LayerIterator.Layer().GetDEBUGV6LAYER(); tempList.Add(tmpLayer); } while (LayerIterator.Next()); return(tempList); }
/// <summary> /// Compiles a list of selected components. /// </summary> void GetSelectedComponents() { 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(); 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 selected component is a variant. { RefDes = Component.GetState_Name().GetState_Text(); if (Component.GetState_Selected()) { //Add to lists. SelectedRef.Add(RefDes); SelectedComp.Add(Component); } } } Component = (IPCB_Component)BoardIterator.NextPCBObject(); } //Iterator clean-up Board.BoardIterator_Destroy(ref BoardIterator); }
public void BoundingBoxTest() { IPCB_BoardIterator BoardIterator; IPCB_Component Component; string RefDes;//, Varriant, Footprint, CompID; IPCB_Board Board = Util.GetCurrentPCB(); if (Board == null) { return; } double OriginX = EDP.Utils.CoordToMils(Board.GetState_XOrigin()); double OriginY = EDP.Utils.CoordToMils(Board.GetState_YOrigin()); //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) { RefDes = Component.GetState_Name().GetState_Text(); //Determines if component is a variant. if (RefDes == "U7") { while (true) { MessageBox.Show("X: " + Math.Abs((EDP.Utils.CoordToMils(Component.BoundingRectangleNoNameCommentForSignals().Right) - OriginX) - (EDP.Utils.CoordToMils(Component.BoundingRectangleNoNameCommentForSignals().Left) - OriginX)) + " Y: " + Math.Abs((EDP.Utils.CoordToMils(Component.BoundingRectangleNoNameCommentForSignals().Top) - OriginX) - (EDP.Utils.CoordToMils(Component.BoundingRectangleNoNameCommentForSignals().Bottom) - OriginX))); //MessageBox.Show("X: " + (EDP.Utils.CoordToMils(Component.BoundingRectangle().Lx) - OriginX) + " Y: " + (EDP.Utils.CoordToMils(Component.BoundingRectangle().Ly) - OriginY)); //MessageBox.Show("X: " + (EDP.Utils.CoordToMils(Component.BoundingRectangleNoNameCommentForSignals().Lx) - OriginX) + " Y: " + (EDP.Utils.CoordToMils(Component.BoundingRectangleNoNameCommentForSignals().Ly) - OriginY)); } } Component = (IPCB_Component)BoardIterator.NextPCBObject(); } //Iterator clean-up Board.BoardIterator_Destroy(ref BoardIterator); }
//Autogenerated code. End of implementation [GetState_Viagrid] //Autogenerated code. Begin of implementation [Command_Viagrid] public void Command_Viagrid(IServerDocumentView view, ref string parameters) { IPCB_ServerInterface pcbServer = PCB.GlobalVars.PCBServer; if (pcbServer == null) { return; } IPCB_Board pcbBoard = pcbServer.GetCurrentPCBBoard(); if (pcbBoard == null) { return; } DXP.Utils.RunCommand("PCB:DeSelect", "Scope=All"); var boundingRect = pcbBoard.GetState_BoardOutline().BoundingRectangle(); var gridSize = (int)pcbBoard.GetState_ComponentGridSize(); var delta = EDP.Utils.MMsToCoord(0.001); IPCB_BoardIterator iterator = pcbBoard.BoardIterator_Create(); iterator.AddFilter_ObjectSet(new PCB.TObjectSet(PCB.TObjectId.eViaObject)); iterator.AddFilter_LayerSet(PCBConstant.V6AllLayersSet); iterator.AddFilter_Area(boundingRect.Left, boundingRect.Bottom, boundingRect.Right, boundingRect.Top); IPCB_Primitive pcbObject = iterator.FirstPCBObject(); while (pcbObject != null) { if (pcbObject is IPCB_Via via && (via.GetState_XLocation() % gridSize > delta || via.GetState_XLocation() % gridSize > delta)) { via.SetState_Selected(true); } pcbObject = iterator.NextPCBObject(); } pcbBoard.BoardIterator_Destroy(ref iterator); DXP.Utils.RunCommand("PCB:RunQuery", "Apply=True|Expr=IsSelected|Mask=True|Select=True"); }
/// <summary> /// Gets a list of signal layers for the provided board file. /// </summary> /// <param name="Board">Current board</param> /// <returns>List of layers.</returns> public static List <TV6_Layer> GetV6SigLayers(IPCB_Board Board) { List <TV6_Layer> tempList = new List <TV6_Layer>(); IPCB_LayerIterator LayerIterator = Board.LayerIterator(); LayerIterator.AddFilter_SignalLayers(); LayerIterator.First(); TV6_Layer tmpLayer; //tmpLayer = new V7_Layer( LayerIterator.Layer().Data); do { tmpLayer = (TV6_Layer)LayerIterator.Layer().GetDEBUGV6LAYER(); //if (EDP.Utils.LayerToString(tmpLayer).Contains("Mid")) tempList.Add(tmpLayer); } while (LayerIterator.Next()); return(tempList); }
/// <summary> /// Gets a list of electrical layers for the provided board file. /// </summary> /// <param name="Board">Current board</param> /// <returns>List of layers.</returns> public static List <V7_Layer> GetV7ElectLayers(IPCB_Board Board) { List <V7_Layer> tempList = new List <V7_Layer>(); IPCB_LayerIterator LayerIterator = Board.LayerIterator(); LayerIterator.AddFilter_ElectricalLayers(); LayerIterator.First(); V7_Layer tmpLayer; //tmpLayer = new V7_Layer( LayerIterator.Layer().Data); do { tmpLayer = new V7_Layer(LayerIterator.Layer().Data); //if (EDP.Utils.LayerToString(tmpLayer).Contains("Mid")) tempList.Add(tmpLayer); } while (LayerIterator.Next()); return(tempList); }
//Autogenerated code. End of implementation [GetState_SetActiveLayer] //Autogenerated code. Begin of implementation [Command_SetActiveLayer] public void Command_SetActiveLayer(IServerDocumentView view, ref string parameters) { IPCB_Primitive obj = null; IPCB_Board board = Util.GetCurrentPCB(); try { //If a object is already selected, Use it. If not, then get the object under the cursor. if (board.GetState_SelectecObjectCount() != 1) { obj = (IPCB_Primitive)board.GetObjectAtXYAskUserIfAmbiguous(board.GetState_XCursor(), board.GetState_YCursor(), Util.PCBAllObject, PCBConstant.V6AllLayersSet, TEditingAction.eEditAction_Focus); } if (obj == null) { obj = (IPCB_Primitive)board.GetLastClickedObject(Util.PCBAllObject, TEditingAction.eEditAction_Select); } else { obj = (IPCB_Primitive)board.GetState_SelectecObject(0); } if (obj == null) { return; } //Set the active layer to that of the selected object layer. Doesnt update the selected layer tab. board.SetState_CurrentLayerV7(obj.GetState_V7Layer()); //Switch to the next layer and back so that the propper layer tab is selected. DXP.Utils.RunCommand("PCB:SetCurrentLayer", "LayerName = Next"); DXP.Utils.RunCommand("PCB:SetCurrentLayer", "LayerName = Previous"); //Switch to single layer mode. //DXP.Utils.RunCommand("PCB:SetupPreferences", "SingleLayerMode=ON"); } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); } }
public void GetNets() { IPCB_BoardIterator BoardIterator; IPCB_Net Net; BoardNets = new Dictionary <string, IPCB_Net>(); 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(); FilterSet.Add(TObjectId.eNetObject); BoardIterator.AddFilter_ObjectSet(FilterSet); BoardIterator.AddFilter_LayerSet(PCBConstant.V6AllLayersSet); //Filter all layers. BoardIterator.AddFilter_Method(TIterationMethod.eProcessAll); Net = BoardIterator.FirstPCBObject() as IPCB_Net; while (Net != null) { if (!BoardNets.ContainsKey(Net.GetState_Name())) { BoardNets.Add(Net.GetState_Name(), Net); } Net = BoardIterator.NextPCBObject() as IPCB_Net; } Board.BoardIterator_Destroy(ref BoardIterator); }
/// <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> /// Adds a new track to the PCB /// </summary> /// <param name="Offset"></param> /// <param name="argWidth"></param> private void AddTrack(structPos Offset, int argWidth)//, V7_Layer argLayer) { PCBServer = PCB.GlobalVars.PCBServer; if (Offset.x == null) { Offset.x = 0; } if (Offset.y == null) { Offset.y = 0; } int xL, yL, xO, yO; IPCB_Board pcbBoard = Util.GetCurrentPCB(); if (pcbBoard == null) { return; } System.Diagnostics.Debug.WriteLine(pcbBoard.GetState_DisplayUnit().ToString()); TV6_Layer ActiveLayer = pcbBoard.GetState_CurrentLayer(); int OriginX = pcbBoard.GetState_XOrigin(); int OriginY = pcbBoard.GetState_YOrigin(); PCBServer.PreProcess(); // Set the value of J to point to the "next" vertex; this is normally // I + 1, but needs to be set to 0 instead for the very last vertex // that is processed by this loop. IPCB_Primitive primitive = PCBServer.PCBObjectFactory(TObjectId.eTrackObject, TDimensionKind.eNoDimension, TObjectCreationMode.eCreate_Default); if (primitive == null) { return; } IPCB_Track track = primitive as IPCB_Track; if (pcbBoard.GetState_DisplayUnit() == TUnit.eImperial) { xL = EDP.Utils.MilsToCoord((double)LastPos.x); yL = EDP.Utils.MilsToCoord((double)LastPos.y); xO = EDP.Utils.MilsToCoord((double)Offset.x); yO = EDP.Utils.MilsToCoord((double)Offset.y); argWidth = EDP.Utils.MilsToCoord((double)argWidth); } else { xL = EDP.Utils.MMsToCoord((double)LastPos.x); yL = EDP.Utils.MMsToCoord((double)LastPos.y); xO = EDP.Utils.MMsToCoord((double)Offset.x); yO = EDP.Utils.MMsToCoord((double)Offset.y); argWidth = EDP.Utils.MMsToCoord((double)argWidth); } if (Offset.absolute) { track.SetState_X1(OriginX + xL); track.SetState_Y1(OriginY + yL); track.SetState_X2(OriginX + xO); track.SetState_Y2(OriginY + yO); LastPos = Offset; } else { track.SetState_X1(OriginX + xL); track.SetState_Y1(OriginY + yL); track.SetState_X2(OriginX + (xL + xO)); track.SetState_Y2(OriginY + (yL + yO)); LastPos.x = LastPos.x + Offset.x; LastPos.y = LastPos.y + Offset.y; } track.SetState_Layer(ActiveLayer); track.SetState_Width(argWidth); pcbBoard.AddPCBObject(primitive); PCBServer.PostProcess(); // Refresh PCB workspace. //DXP.Utils.RunCommand("PCB:Zoom", "Action=Redraw"); }
public void AssignNet() { IClient tmpClient = DXP.GlobalVars.Client; IPCB_Primitive FirstObj = null; IPCB_Primitive SecondObj = null; IPCB_Board board = Util.GetCurrentPCB(); int NewX = 0, NewY = 0; try { //If a object is already selected, Use it. If not, then get the object under the cursor. if (board.GetState_SelectecObjectCount() != 1) { FirstObj = (IPCB_Primitive)board.GetObjectAtXYAskUserIfAmbiguous(board.GetState_XCursor(), board.GetState_YCursor(), Util.PCBAllObject, PCBConstant.V6AllLayersSet, TEditingAction.eEditAction_Focus); } if (FirstObj == null) { FirstObj = (IPCB_Primitive)board.GetLastClickedObject(Util.PCBAllObject, TEditingAction.eEditAction_Select); } else { FirstObj = (IPCB_Primitive)board.GetState_SelectecObject(0); } if (FirstObj == null) { return; } board.ChooseLocation(ref NewX, ref NewY, "Select desired net."); if (NewX > 0 & NewY > 0) { SecondObj = (IPCB_Primitive)board.GetObjectAtXYAskUserIfAmbiguous(NewX, NewY, Util.PCBAllObject, PCBConstant.V6AllLayersSet, TEditingAction.eEditAction_Select); } if (SecondObj == null) { return; } if (SecondObj.GetState_Net() != null) { #if DEBUG MessageBox.Show(SecondObj.GetState_Net().GetState_Name()); #endif FirstObj.BeginModify(); FirstObj.SetState_Net(SecondObj.GetState_Net()); FirstObj.EndModify(); } if (FirstObj.GetState_ObjectID() == TObjectId.eSplitPlaneObject) { DXP.Utils.RunCommand("PCB:EditInternalPlanes", "RebuildPlane=All"); } //PCB:EditInternalPlanes //RebuildPlane=All } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); } }
/// <summary> /// /// </summary> /// <param name="report"></param> void ScanDocuments(ref Dictionary <string, Heights> report) { try { IDXPWorkSpace CurrentWorkspace = DXP.GlobalVars.DXPWorkSpace; IDXPProject CurrentProject; int LogicalDocumentCount; int LoopIterator; IDXPDocument CurrentSheet; CurrentProject = CurrentWorkspace.DM_FocusedProject(); LogicalDocumentCount = CurrentProject.DM_LogicalDocumentCount(); ISch_Document SchDoc; IClient Client = DXP.GlobalVars.Client; IServerDocument ServerDoc; IDXPDocument ActiveDoc = DXP.GlobalVars.DXPWorkSpace.DM_FocusedDocument(); //Save current open document so it can be reopened after process is done. int BoardCount = 0; string BoardName = ""; DialogResult dlgResult; DXP.Utils.PercentInit("Scanning Documents", LogicalDocumentCount); bool DocOpened = false; for (LoopIterator = 1; LoopIterator <= LogicalDocumentCount; LoopIterator++) { CurrentSheet = CurrentProject.DM_LogicalDocuments(LoopIterator - 1); if (CurrentSheet.DM_DocumentKind() == "PCB") { if (BoardCount == 0) { BoardCount += 1; BoardName = CurrentSheet.DM_FileName(); } else { dlgResult = MessageBox.Show("There are multiple boards in this project. PCB outjobs will only run on the first board :" + BoardName + "\n Do you wish to continue?", "Multiple PCBs", MessageBoxButtons.YesNo); if (dlgResult == DialogResult.No) { report = null; return; } } } if (CurrentSheet.DM_DocumentKind() == "SCH") { DocOpened = false; SchDoc = CurrentSheet as ISch_Document; if (Client.IsDocumentOpen(CurrentSheet.DM_FullPath())) { ServerDoc = Client.GetDocumentByPath(CurrentSheet.DM_FullPath()); DocOpened = true; } else { ServerDoc = Client.OpenDocument("SCH", CurrentSheet.DM_FullPath()); } Client.ShowDocument(ServerDoc); GetParamHeights(ref report); if (!DocOpened) { Client.CloseDocument(ServerDoc); } ServerDoc = null; if (report == null) { return; } } DocOpened = false; DXP.Utils.PercentUpdate(); } DXP.Utils.PercentFinish(); DXP.Utils.PercentInit("Scanning Documents", LogicalDocumentCount); for (LoopIterator = 1; LoopIterator <= LogicalDocumentCount; LoopIterator++) { CurrentSheet = CurrentProject.DM_LogicalDocuments(LoopIterator - 1); if (CurrentSheet.DM_DocumentKind() == "PCB") { if (BoardName == CurrentSheet.DM_FileName()) { DocOpened = false; IPCB_Board PCBDoc = CurrentSheet as IPCB_Board; if (Client.IsDocumentOpen(CurrentSheet.DM_FullPath())) { ServerDoc = Client.GetDocumentByPath(CurrentSheet.DM_FullPath()); DocOpened = true; } else { ServerDoc = Client.OpenDocument("PCB", CurrentSheet.DM_FullPath()); } Client.ShowDocument(ServerDoc); GetBodyHeights(ref report); if (!DocOpened) { Client.CloseDocument(ServerDoc); } ServerDoc = null; } } DXP.Utils.PercentUpdate(); } Client.ShowDocument(Client.GetDocumentByPath(ActiveDoc.DM_FullPath())); DXP.Utils.PercentFinish(); return; } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); return; } }
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); }
/// <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"); }
private void AddCourtyard() { IPCB_ServerInterface PcbServer = PCB.GlobalVars.PCBServer; if (PcbServer == null) { return; } IPCB_Library PcbLib = PcbServer.GetCurrentPCBLibrary(); if (PcbLib == null) { return; } IPCB_LibraryIterator LibIteartor = PcbLib.LibraryIterator_Create(); LibIteartor.AddFilter_ObjectSet(new PCB.TObjectSet(PCB.TObjectId.eComponentObject)); IPCB_Component PcbCmp = LibIteartor.FirstPCBObject() as IPCB_Component; while (PcbCmp != null) { IPCB_Board currentBoard = PcbServer.GetCurrentPCBBoard(); IPCB_GroupIterator PcbObjItera = PcbCmp.GroupIterator_Create(); TV6_LayerSet layers = new TV6_LayerSet(TV6_Layer.eV6_BottomLayer, TV6_Layer.eV6_BottomOverlay, TV6_Layer.eV6_Mechanical13, TV6_Layer.eV6_TopLayer, TV6_Layer.eV6_TopOverlay); PcbObjItera.AddFilter_LayerSet(layers); IPCB_Primitive PcbObj = PcbObjItera.FirstPCBObject(); List <PrimitiveArea> Areas = new List <PrimitiveArea>(); while (PcbObj != null) { PrimitiveArea ObjArea = new PrimitiveArea(); switch (PcbObj.GetState_ObjectID()) { case PCB.TObjectId.ePadObject: ObjArea = CalPadArea(PcbObj as IPCB_Pad); Areas.Add(ObjArea); break; case PCB.TObjectId.eTrackObject: ObjArea = CalTrackArea(PcbObj as IPCB_Track); Areas.Add(ObjArea); break; case PCB.TObjectId.eArcObject: break; } PcbObj = PcbObjItera.NextPCBObject(); } PrimitiveArea ComponentArea = CalComponentArea(Areas); DrawAreaAsCourtyard(ComponentArea, PcbServer, currentBoard); PcbCmp.GroupIterator_Destroy(ref PcbObjItera); PcbCmp = LibIteartor.NextPCBObject() as IPCB_Component; } PcbLib.LibraryIterator_Destroy(ref LibIteartor); }
private void DrawAreaAsCourtyard(PrimitiveArea Area, IPCB_ServerInterface ArgPcbServer, IPCB_Board ArgPcbBoard) { int CourtyardClearnce_IPC_L = EDP.Utils.MMsToCoord((double)0.1); int lineWidth = EDP.Utils.MMsToCoord((double)0.05); V7_Layer MechLayer15 = new V7_Layer().Mechanical15(); ArgPcbServer.PreProcess(); IPCB_Track trackLeft = ArgPcbServer.PCBObjectFactory(PCB.TObjectId.eTrackObject, TDimensionKind.eNoDimension, PCB.TObjectCreationMode.eCreate_GlobalCopy) as IPCB_Track; SetTrackLocaton(trackLeft, Area.BottomLeft.X - CourtyardClearnce_IPC_L, Area.BottomLeft.Y - CourtyardClearnce_IPC_L, Area.TopLeft.X - CourtyardClearnce_IPC_L, Area.TopLeft.Y + CourtyardClearnce_IPC_L); trackLeft.SetState_Width(lineWidth); trackLeft.SetState_Layer((int)MechLayer15.ID); IPCB_Track trackRight = ArgPcbServer.PCBObjectFactory(PCB.TObjectId.eTrackObject, TDimensionKind.eNoDimension, PCB.TObjectCreationMode.eCreate_GlobalCopy) as IPCB_Track; SetTrackLocaton(trackRight, Area.BottomRight.X + CourtyardClearnce_IPC_L, Area.BottomRight.Y - CourtyardClearnce_IPC_L, Area.TopRight.X + CourtyardClearnce_IPC_L, Area.TopRight.Y + CourtyardClearnce_IPC_L); trackRight.SetState_Width(lineWidth); trackRight.SetState_Layer((int)MechLayer15.ID); IPCB_Track trackTop = ArgPcbServer.PCBObjectFactory(PCB.TObjectId.eTrackObject, TDimensionKind.eNoDimension, PCB.TObjectCreationMode.eCreate_GlobalCopy) as IPCB_Track; SetTrackLocaton(trackTop, Area.TopLeft.X - CourtyardClearnce_IPC_L, Area.TopLeft.Y + CourtyardClearnce_IPC_L, Area.TopRight.X + CourtyardClearnce_IPC_L, Area.TopRight.Y + CourtyardClearnce_IPC_L); trackTop.SetState_Width(lineWidth); trackTop.SetState_Layer((int)MechLayer15.ID); IPCB_Track trackBottom = ArgPcbServer.PCBObjectFactory(PCB.TObjectId.eTrackObject, TDimensionKind.eNoDimension, PCB.TObjectCreationMode.eCreate_GlobalCopy) as IPCB_Track; SetTrackLocaton(trackBottom, Area.BottomLeft.X - CourtyardClearnce_IPC_L, Area.BottomLeft.Y - CourtyardClearnce_IPC_L, Area.BottomRight.X + CourtyardClearnce_IPC_L, Area.BottomRight.Y - CourtyardClearnce_IPC_L); trackBottom.SetState_Width(lineWidth); trackBottom.SetState_Layer((int)MechLayer15.ID); ArgPcbBoard.AddPCBObject(trackBottom); ArgPcbBoard.AddPCBObject(trackLeft); ArgPcbBoard.AddPCBObject(trackRight); ArgPcbBoard.AddPCBObject(trackTop); ArgPcbServer.PostProcess(); DXP.Utils.RunCommand("PCB:Zoom", "Action=Redraw"); }
public void PrimPrimTest() { IPCB_BoardIterator BoardIterator; IPCB_Pad Pad, Selected1 = null, Selected2 = null; IPCB_Board Board = Util.GetCurrentPCB(); if (Board == null) { return; } double OriginX = EDP.Utils.CoordToMils(Board.GetState_XOrigin()); double OriginY = EDP.Utils.CoordToMils(Board.GetState_YOrigin()); //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.ePadObject); BoardIterator.AddFilter_ObjectSet(FilterSet); BoardIterator.AddFilter_LayerSet(PCBConstant.V6AllLayersSet); //Filter all layers. BoardIterator.AddFilter_Method(TIterationMethod.eProcessAll); Pad = (IPCB_Pad)BoardIterator.FirstPCBObject(); while (Pad != null) { //RefDes = Component.GetState_Name().GetState_Text(); //Determines if component is a variant. if (Selected1 == null && Pad.GetState_Selected() == true) { Selected1 = Pad; } else if (Pad.GetState_Selected() == true) { Selected2 = Pad; } if (Selected1 != null && Selected2 != null) { break; } Pad = (IPCB_Pad)BoardIterator.NextPCBObject(); } if (Selected1 == null || Selected2 == null) { return; } bool bot = false, top = false; if (Selected1.GetState_Layer() == TV6_Layer.eV6_BottomLayer) { Selected1.SetState_Layer(TV6_Layer.eV6_TopLayer); top = true; } if (Selected2.GetState_Layer() == TV6_Layer.eV6_BottomLayer) { Selected2.SetState_Layer(TV6_Layer.eV6_TopLayer); bot = true; } MessageBox.Show(EDP.Utils.CoordToMMs(Board.PrimPrimDistance(Selected1, Selected2)).ToString()); if (top) { Selected1.SetState_Layer(TV6_Layer.eV6_BottomLayer); } if (bot) { Selected2.SetState_Layer(TV6_Layer.eV6_BottomLayer); } //Iterator clean-up Board.BoardIterator_Destroy(ref BoardIterator); }
public void PlaceLayerStackTable() { PCBServer = PCB.GlobalVars.PCBServer; List <IPCB_Primitive> lstLayerStackPrims = new List <IPCB_Primitive>(); //DXP.Utils.RunCommand("PCB:ManageLayerSets", "SetIndex=0"); IPCB_Board pcbBoard = Util.GetCurrentPCB(); if (pcbBoard == null) { return; } if (!pcbBoard.ChooseLocation(ref OffsetX, ref OffsetY, "Select placement location")) { return; } IPCB_MasterLayerStack LStack = pcbBoard.GetState_MasterStack(); //IPCB_Text test = pcbBoard.SelectedObjectsCount ActiveLayer = TV6_Layer.eV6_DrillDrawing; IPCB_LayerObject tmp; tmp = LStack.First(TLayerClassID.eLayerClass_Electrical); do { Layers.Add(tmp as IPCB_ElectricalLayer); //GetState_CopperThickness //GetState_LayerName tmp = LStack.Next(TLayerClassID.eLayerClass_Electrical, tmp); } while (tmp != null); // [Page Number, Layer Num, Ext, Name, POS/NEG, Weight] List <TableData> TableText = new List <TableData>(); string CopperWeight; TableText.Add(new TableData(new string[6] { "1", null, "GD1", "FABRICATION DRAWING", "POS", null }, TV6_Layer.eV6_DrillDrawing)); TableText.Add(new TableData(new string[6] { "2", null, "GTO", "Top Overlay", "POS", null }, TV6_Layer.eV6_TopOverlay)); TableText.Add(new TableData(new string[6] { "3", null, "GTS", "Top Solder", "NEG", null }, TV6_Layer.eV6_TopSolder)); int i = 4; int Sig = 1, Plane = 1; string Ext; foreach (IPCB_ElectricalLayer item in Layers) { System.Diagnostics.Debug.WriteLine(item.GetState_CopperThickness()); System.Diagnostics.Debug.WriteLine(item.GetState_LayerDisplayName(0)); System.Diagnostics.Debug.WriteLine(item.GetState_LayerDisplayName(1)); System.Diagnostics.Debug.WriteLine(item.GetState_LayerDisplayName(2)); //14000 //7000 switch (item.GetState_CopperThickness()) { case 7090: CopperWeight = ".5 oz"; break; case 7000: CopperWeight = ".5 oz"; break; case 7087: CopperWeight = ".5 oz"; break; case 13780: CopperWeight = "1 oz"; break; case 14000: CopperWeight = "1 oz"; break; case 13779: CopperWeight = "1 oz"; break; case 28000: CopperWeight = "2 oz"; break; case 27560: CopperWeight = "2 oz"; break; default: CopperWeight = EDP.Utils.CoordToMils(item.GetState_CopperThickness()).ToString() + "mils"; break; } if (item.GetState_LayerDisplayName(0).Contains("P")) { Ext = "GP" + Plane.ToString(); Plane++; } else if (item.GetState_LayerDisplayName(0).Contains("T")) { Ext = "G" + item.GetState_LayerDisplayName(0); } else if (item.GetState_LayerDisplayName(0).Contains("B")) { Ext = "G" + item.GetState_LayerDisplayName(0); } else { Ext = "G" + Sig.ToString(); Sig++; } //TV6_Layer tempLayer = (TV6_Layer)item; TableText.Add(new TableData(new string[6] { i.ToString(), (i - 3).ToString(), Ext, item.GetState_LayerName(), item.GetState_LayerDisplayName(0).Contains("P") ?"NEG":"POS", CopperWeight }, item.V6_LayerID())); i++; } TableText.Add(new TableData(new string[6] { (LStack.Count_1(3) + 4).ToString(), null, "GBS", "Bottom Solder", "NEG", null }, TV6_Layer.eV6_BottomSolder)); TableText.Add(new TableData(new string[6] { (LStack.Count_1(3) + 5).ToString(), null, "GBO", "Bottom Overlay", "POS", null }, TV6_Layer.eV6_BottomOverlay)); TableText.Add(new TableData(new string[6] { "", null, "TXT", "NC DRILL FILE", null, null }, TV6_Layer.eV6_DrillDrawing)); double pos = -815; foreach (TableData item in TableText) {// [Page Number, Layer Num, Ext, Name, POS/NEG, Weight] if (item.Text[0] != "") { lstLayerStackPrims.Add(CreateString(161, pos, item.Text[0], ActiveLayer)); //Page Number } if (item.Text[1] != "") { lstLayerStackPrims.Add(CreateString(661, pos, item.Text[1], ActiveLayer)); //Layer Num } if (item.Text[2] != "") { lstLayerStackPrims.Add(CreateString(1061, pos, item.Text[2], ActiveLayer)); //Ext } if (item.Text[3] != "") { lstLayerStackPrims.Add(CreateString(1516, pos, item.Text[3], ActiveLayer)); //Name } if (item.Text[4] != "") { lstLayerStackPrims.Add(CreateString(3361, pos, item.Text[4], ActiveLayer)); //POS/NEG } if (item.Text[5] != "") { lstLayerStackPrims.Add(CreateString(3861, pos, item.Text[5], ActiveLayer)); //Weight } if (item.Text[0] != "1") { if (item.Text[0] != "") { lstLayerStackPrims.Add(CreateString(4485, pos, ".Layer_Name", item.CurrentLayer)); //Layer name } if (item.Text[0] != "") { lstLayerStackPrims.Add(CreateString(5985, pos, item.Text[0], item.CurrentLayer)); //Page Number } } pos -= 200; } tmp = LStack.First(TLayerClassID.eLayerClass_Dielectric); double thickness; pos = -1515; do { System.Diagnostics.Debug.WriteLine((tmp as IPCB_DielectricLayer).GetState_DielectricType()); if ((tmp as IPCB_DielectricLayer).GetState_DielectricType() != TDielectricType.eSurfaceMaterial) { thickness = EDP.Utils.CoordToMils((tmp as IPCB_DielectricLayer).GetState_DielectricHeight()) / 1000; thickness = Math.Round(thickness, 4); lstLayerStackPrims.Add(CreateString(-737, pos, thickness.ToString() + "\"", ActiveLayer)); lstLayerStackPrims.Add(CreateTrack(-238, pos + 50, -50, pos + 50, ActiveLayer)); pos -= 200; } tmp = LStack.Next(TLayerClassID.eLayerClass_Dielectric, tmp); } while (tmp != null); PCBServer.PreProcess(); lstLayerStackPrims.AddRange(CreateTemplate(LStack.Count_1(3))); //tmpPrim = PCBServer.PCBObjectFactory(TObjectId.eTrackObject, TDimensionKind.eNoDimension, TObjectCreationMode.eCreate_Default); //if (tmpPrim == null) // return; //IPCB_Track track = tmpPrim as IPCB_Track; foreach (IPCB_Primitive prim in lstLayerStackPrims) { if (prim != null) { pcbBoard.AddPCBObject(prim); } } PCBServer.PostProcess(); }
private void CleanUpSamtecFootprints() { IPCB_ServerInterface PcbServer = PCB.GlobalVars.PCBServer; if (PcbServer == null) { return; } IPCB_Library PcbLib = PcbServer.GetCurrentPCBLibrary(); if (PcbLib == null) { return; } IPCB_LibraryIterator LibIteartor = PcbLib.LibraryIterator_Create(); LibIteartor.AddFilter_ObjectSet(new PCB.TObjectSet(PCB.TObjectId.eComponentObject)); IPCB_LibComponent PcbCmp = LibIteartor.FirstPCBObject() as IPCB_LibComponent; PcbServer.PreProcess(); while (PcbCmp != null) { IPCB_Board currentBoard = PcbServer.GetCurrentPCBBoard(); // heads up, PCB Ojbect can be added only by IPCB_Board, not IPCB_Component IPCB_GroupIterator PcbObjItera = PcbCmp.GroupIterator_Create(); IPCB_Primitive PcbObj = PcbObjItera.FirstPCBObject(); while (PcbObj != null) { switch (PcbObj.GetState_ObjectID()) { case PCB.TObjectId.eTrackObject: if ((int)PcbObj.GetState_V7Layer().ID != (int)new V7_Layer().Mechanical1().ID) { PcbObj = PcbObjItera.NextPCBObject(); continue; } IPCB_Track TrackObj = PcbObj as IPCB_Track; TrackObj.SetState_Width(EDP.Utils.MMsToCoord((double)0.1)); TrackObj.SetState_Layer((int)new V7_Layer().Mechanical13().ID); break; case PCB.TObjectId.eArcObject: if ((int)PcbObj.GetState_V7Layer().ID != (int)new V7_Layer().Mechanical1().ID) { PcbObj = PcbObjItera.NextPCBObject(); continue; } IPCB_Arc ArcObj = PcbObj as IPCB_Arc; ArcObj.SetState_LineWidth(EDP.Utils.MMsToCoord((double)0.1)); ArcObj.SetState_Layer((int)new V7_Layer().Mechanical13().ID); break; case PCB.TObjectId.eComponentBodyObject: IPCB_ComponentBody BodyObj = PcbObj as IPCB_ComponentBody; BodyObj.SetState_Layer((int)new V7_Layer().Mechanical13().ID); break; case PCB.TObjectId.eTextObject: PcbCmp.RemovePCBObject(PcbObj); break; } PcbObj = PcbObjItera.NextPCBObject(); } PcbServer.PostProcess(); DXP.Utils.RunCommand("PCB:Zoom", "Action=Redraw"); PcbCmp.GroupIterator_Destroy(ref PcbObjItera); PcbCmp = LibIteartor.NextPCBObject() as IPCB_LibComponent; } PcbLib.LibraryIterator_Destroy(ref LibIteartor); }
private void btnPlace_Click(object sender, EventArgs e) { try { clsSelectedObjects NewPlacement = new clsSelectedObjects(); Dictionary <string, string> NetCompare = GetNetDiff(); IPCB_Board brd = Util.GetCurrentPCB(); brd.SelectedObjects_Clear(); IPCB_Primitive temp; IPCB_ServerInterface PCBServer = PCB.GlobalVars.PCBServer; PCBServer.PreProcess(); int OffsetX = 0, OffsetY = 0; if (!brd.ChooseLocation(ref OffsetX, ref OffsetY, "Select placement location")) { return; } try { OffsetX = OffsetX - PR.selectedSourceObjects.componentObjects[0].GetState_XLocation(); OffsetY = OffsetY - PR.selectedSourceObjects.componentObjects[0].GetState_YLocation(); } catch (Exception ex) { if (ex.HResult == -2147467259) { MessageBox.Show("Source and destination data is corrupted due to board file being closed. Please restart the process."); lstDest.Items.Clear(); lstSource.Items.Clear(); lstMatched.Items.Clear(); return; } throw; } PR.GetNets(); brd.BeginModify(); foreach (IPCB_Primitive item in PR.selectedSourceObjects.arcObjects) { temp = item.Replicate(); brd.AddPCBObject(temp); temp.BeginModify(); temp.MoveByXY(OffsetX, OffsetY); if (temp.GetState_Net() != null) { if (NetCompare.ContainsKey(temp.GetState_Net().GetState_Name())) { if (PR.BoardNets.ContainsKey(NetCompare[temp.GetState_Net().GetState_Name()])) { temp.SetState_Net(PR.BoardNets[NetCompare[temp.GetState_Net().GetState_Name()]]); } } else { //temp.SetState_Net(PCBServer.PCBObjectFactory(TObjectId.eNetObject, TDimensionKind.eNoDimension, TObjectCreationMode.eCreate_Default) as IPCB_Net); temp.SetState_Net(null); } } temp.EndModify(); NewPlacement.arcObjects.Add(temp as IPCB_Arc); } foreach (IPCB_Primitive item in PR.selectedSourceObjects.padObjects) { temp = item.Replicate(); brd.AddPCBObject(temp); temp.BeginModify(); temp.MoveByXY(OffsetX, OffsetY); if (temp.GetState_Net() != null) { if (NetCompare.ContainsKey(temp.GetState_Net().GetState_Name())) { if (PR.BoardNets.ContainsKey(NetCompare[temp.GetState_Net().GetState_Name()])) { temp.SetState_Net(PR.BoardNets[NetCompare[temp.GetState_Net().GetState_Name()]]); } else { temp.SetState_Net(null); } } else { temp.SetState_Net(null); } } temp.EndModify(); NewPlacement.padObjects.Add(temp as IPCB_Pad); } foreach (IPCB_Primitive item in PR.selectedSourceObjects.ViaObjects) { temp = item.Replicate(); brd.AddPCBObject(temp); temp.BeginModify(); temp.MoveByXY(OffsetX, OffsetY); if (temp.GetState_Net() != null) { if (NetCompare.ContainsKey(temp.GetState_Net().GetState_Name())) { if (PR.BoardNets.ContainsKey(NetCompare[temp.GetState_Net().GetState_Name()])) { temp.SetState_Net(PR.BoardNets[NetCompare[temp.GetState_Net().GetState_Name()]]); } else { temp.SetState_Net(null); } } else { temp.SetState_Net(null); } } temp.EndModify(); NewPlacement.ViaObjects.Add(temp as IPCB_Via); } foreach (IPCB_Primitive item in PR.selectedSourceObjects.trackObjects) { temp = item.Replicate(); brd.AddPCBObject(temp); temp.BeginModify(); temp.MoveByXY(OffsetX, OffsetY); if (temp.GetState_Net() != null) { if (NetCompare.ContainsKey(temp.GetState_Net().GetState_Name())) { if (PR.BoardNets.ContainsKey(NetCompare[temp.GetState_Net().GetState_Name()])) { temp.SetState_Net(PR.BoardNets[NetCompare[temp.GetState_Net().GetState_Name()]]); } else { temp.SetState_Net(null); } } else { temp.SetState_Net(null); } } temp.EndModify(); NewPlacement.trackObjects.Add(temp as IPCB_Track); } foreach (IPCB_Primitive item in PR.selectedSourceObjects.textObjects) { temp = item.Replicate(); brd.AddPCBObject(temp); temp.BeginModify(); temp.MoveByXY(OffsetX, OffsetY); if (temp.GetState_Net() != null) { if (NetCompare.ContainsKey(temp.GetState_Net().GetState_Name())) { if (PR.BoardNets.ContainsKey(NetCompare[temp.GetState_Net().GetState_Name()])) { temp.SetState_Net(PR.BoardNets[NetCompare[temp.GetState_Net().GetState_Name()]]); } else { temp.SetState_Net(null); } } else { temp.SetState_Net(null); } } temp.EndModify(); NewPlacement.textObjects.Add(temp as IPCB_Text); } foreach (IPCB_Primitive item in PR.selectedSourceObjects.fillObjects) { temp = item.Replicate(); brd.AddPCBObject(temp); temp.BeginModify(); temp.MoveByXY(OffsetX, OffsetY); if (temp.GetState_Net() != null) { if (NetCompare.ContainsKey(temp.GetState_Net().GetState_Name())) { if (PR.BoardNets.ContainsKey(NetCompare[temp.GetState_Net().GetState_Name()])) { temp.SetState_Net(PR.BoardNets[NetCompare[temp.GetState_Net().GetState_Name()]]); } else { temp.SetState_Net(null); } } else { temp.SetState_Net(null); } } temp.EndModify(); NewPlacement.fillObjects.Add(temp as IPCB_Fill); } foreach (IPCB_Primitive item in PR.selectedSourceObjects.polygonObjects) { temp = item.Replicate(); brd.AddPCBObject(temp); temp.BeginModify(); temp.MoveByXY(OffsetX, OffsetY); if (temp.GetState_Net() != null) { if (NetCompare.ContainsKey(temp.GetState_Net().GetState_Name())) { if (PR.BoardNets.ContainsKey(NetCompare[temp.GetState_Net().GetState_Name()])) { temp.SetState_Net(PR.BoardNets[NetCompare[temp.GetState_Net().GetState_Name()]]); } else { temp.SetState_Net(null); } } else { temp.SetState_Net(null); } } temp.EndModify(); NewPlacement.polygonObjects.Add(temp as IPCB_Polygon); } foreach (IPCB_Primitive item in PR.selectedSourceObjects.primitiveObjects) { temp = item.Replicate(); brd.AddPCBObject(temp); temp.BeginModify(); temp.MoveByXY(OffsetX, OffsetY); if (temp.GetState_Net() != null) { if (NetCompare.ContainsKey(temp.GetState_Net().GetState_Name())) { if (PR.BoardNets.ContainsKey(NetCompare[temp.GetState_Net().GetState_Name()])) { temp.SetState_Net(PR.BoardNets[NetCompare[temp.GetState_Net().GetState_Name()]]); } else { temp.SetState_Net(null); } } else { temp.SetState_Net(null); } } temp.EndModify(); NewPlacement.primitiveObjects.Add(temp); } foreach (IPCB_Primitive item in PR.selectedSourceObjects.regionObjects) { temp = item.Replicate(); brd.AddPCBObject(temp); temp.BeginModify(); temp.MoveByXY(OffsetX, OffsetY); if (temp.GetState_Net() != null) { if (NetCompare.ContainsKey(temp.GetState_Net().GetState_Name())) { if (PR.BoardNets.ContainsKey(NetCompare[temp.GetState_Net().GetState_Name()])) { temp.SetState_Net(PR.BoardNets[NetCompare[temp.GetState_Net().GetState_Name()]]); } else { temp.SetState_Net(null); } } else { temp.SetState_Net(null); } } temp.EndModify(); NewPlacement.regionObjects.Add(temp as IPCB_Region); } string srcRef, dstRef; IPCB_Component srcComp, dstComp; foreach (string item in lstMatched.Items) { srcRef = item.Split('>')[0]; dstRef = item.Split('>')[1]; srcComp = PR.selectedSourceObjects.GetComponent(srcRef); dstComp = PR.selectedDestinationObjects.GetComponent(dstRef); dstComp.BeginModify(); if (srcComp.GetState_Layer() != dstComp.GetState_Layer()) { dstComp.FlipComponent(); } dstComp.SetState_Rotation(srcComp.GetState_Rotation()); dstComp.MoveToXY(OffsetX + srcComp.GetState_XLocation(), OffsetY + srcComp.GetState_YLocation()); //dstComp.Rebuild(); dstComp.EndModify(); } brd.EndModify(); PCBServer.PostProcess(); brd.GraphicallyInvalidate(); //brd.Update_PCBGraphicalView(true, true); //DXP.Utils.RunCommand("PCB:Zoom", "Action=Redraw"); //string process = "PCB:MoveObject"; //string parameters = "Object= Selection"; //DXP.Utils.RunCommand(process, parameters); RemoveMatched("Placed"); } catch (Exception ex) { ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex); return; } }
public void NetConnect() { #if DEBUG Stopwatch stopwatch; stopwatch = new Stopwatch(); stopwatch.Start(); #endif IPCB_BoardIterator BoardIterator; IPCB_GroupIterator CompIterator; IPCB_Primitive CompItem; IPCB_Board Board = Util.GetCurrentPCB(); IPCB_Component Comp; 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); FilterSet.Add(PCB.TObjectId.ePadObject); FilterSet.Add(PCB.TObjectId.eTrackObject); BoardIterator.AddFilter_ObjectSet(FilterSet); BoardIterator.AddFilter_LayerSet(PCBConstant.V6AllLayersSet); //Filter all layers. BoardIterator.AddFilter_Method(TIterationMethod.eProcessAll); CompItem = BoardIterator.FirstPCBObject(); //Comp = (IPCB_Component)BoardIterator.FirstPCBObject(); while (CompItem != null) { if (CompItem.GetState_Selected()) { if (CompItem.GetState_ObjectIDString() == "Pad" || CompItem.GetState_ObjectIDString() == "Track") { if (CompItem.GetState_InNet()) { CompItem.GetState_Net().ShowNetConnects(); } } else { Comp = (IPCB_Component)CompItem; CompIterator = Comp.GroupIterator_Create(); CompIterator.AddFilter_LayerSet_2(PCBConstant.V7AllLayersSet); CompItem = CompIterator.FirstPCBObject(); while (CompItem != null) { if (CompItem.GetState_InNet()) { CompItem.GetState_Net().ShowNetConnects(); } CompItem = CompIterator.NextPCBObject(); } } } CompItem = BoardIterator.NextPCBObject(); } #if DEBUG stopwatch.Stop(); Debug.WriteLine(stopwatch.ElapsedMilliseconds); #endif }
private void btnRemoveDupe_Click(object sender, EventArgs e) { DXP.Utils.StatusBarSetState(2, "Removing Vias"); //if (PCBServer == null) // return false; IPCB_BoardIterator BoardIterator; List <IPCB_Via> BoardVias = new List <IPCB_Via>(); List <IPCB_Via> clnBoardVias = new List <IPCB_Via>(); IPCB_Via Via; Board = Util.GetCurrentPCB(); if (Board == null) { MessageBox.Show("Unable to complete. Error occured."); return; } 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>(); for (int i = 0; i < Board.GetState_DrillLayerPairsCount(); i++) { DrillPair = Board.GetState_LayerPair(i); if (lstBefore.SelectedItems.Contains(DrillPair.GetState_Description())) { OldPairs.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()) { BoardVias.Add(Via); break; } } Via = BoardIterator.NextPCBObject() as IPCB_Via; } Board.BoardIterator_Destroy(ref BoardIterator); DXP.Utils.PercentInit("Removing Vias", BoardVias.Count * OldPairs.Count);//Progressbar init. //Replace vias Board.BeginModify(); IPCB_Net Net = null; int X, Y; List <IPCB_Via> Replaced = new List <IPCB_Via>(); foreach (IPCB_DrillLayerPair OldPair in OldPairs) { clnBoardVias.AddRange(BoardVias); while (clnBoardVias.Count > 0) { X = clnBoardVias[0].GetState_XLocation(); Y = clnBoardVias[0].GetState_YLocation(); Net = clnBoardVias[0].GetState_Net(); Replaced.Add(clnBoardVias[0]); for (int i = 1; i < clnBoardVias.Count; i++) { if (clnBoardVias[i].GetState_Net() == Net) { if (clnBoardVias[i].GetState_XLocation() == X) { if (clnBoardVias[i].GetState_YLocation() == Y) { if (clnBoardVias[i].GetState_StartLayer() == OldPair.GetState_StartLayer()) { if (clnBoardVias[i].GetState_StopLayer() == OldPair.GetState_StopLayer()) { Replaced.Add(clnBoardVias[i]); } } } } } } if (Replaced.Count > 1) { //Remove replaced vias from BoardVias (clean up) for (int i = 1; i < Replaced.Count; i++) { clnBoardVias.Remove(Replaced[i]); Board.RemovePCBObject(Replaced[i]); DXP.Utils.PercentUpdate(); } } clnBoardVias.Remove(Replaced[0]); DXP.Utils.PercentUpdate(); Replaced.Clear(); } } Board.EndModify(); DXP.Utils.PercentFinish(); MessageBox.Show("Process Complete"); }