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 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); } }
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(); }