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; } }
/// <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"); }