Пример #1
0
    public ComponentList <string, string> GetComponents()
    {
        try
        {
            IClient    client    = DXP.GlobalVars.Client;
            IWorkspace workSpace = client.GetDXPWorkspace() as IWorkspace;
            IProject   project   = workSpace.DM_FocusedProject();
            if (project.DM_NeedsCompile())
            {
                project.DM_Compile();
            }

            ComponentList <string, string> Output = new ComponentList <string, string>();

            IDocument document       = project.DM_DocumentFlattened();
            int       componentCount = document.DM_ComponentCount();

            pbProgress.Maximum = componentCount;
            pbProgress.Value   = 0;
            UpdateLabel("Getting Comp List");

            for (int i = 0; i < componentCount; i++)
            {//TODO: what to do when multiple keys
                IComponent component = document.DM_Components(i);
                if (!Output.ContainsKey(component.DM_PhysicalDesignator()))
                {
                    Output.Add(component.DM_PhysicalDesignator(), component.DM_NexusDeviceId());
                }
                pbProgress.Value++;
                UpdateLabel("Getting Comp List");
            }

            return(Output);
        }
        catch (Exception ex)
        {
            ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
            return(null);
        }
    }
Пример #2
0
    private void btnImport_Click(object sender, EventArgs e)
    {
        try
        {
            //TODO: need to support hierarchy
            string Path = txtPath.Text;
            if (Path == "")
            {
                MessageBox.Show("Missing file path.");
                return;
            }

            Var_Type Variants = GetPEData(Path); //Get data from excel.

            if (Variants == null)
            {
                return;
            }

            //Verify data was collected.
            if (Variants.Components.Count == 0)
            {
                MessageBox.Show("There were no PE_FLT or PE_ENG changes detected.");
                return;
            }

            //Disabled for now.
            #region Set Base Design
            //IDXPWorkSpace CurrentWorkspace = DXP.GlobalVars.DXPWorkSpace;
            //IDXPProject CurrentProject;
            //int LogicalDocumentCount;
            //int LoopIterator;
            //IDXPDocument CurrentSheet;
            //CurrentProject = CurrentWorkspace.DM_FocusedProject();
            //LogicalDocumentCount = CurrentProject.DM_LogicalDocumentCount();
            //ISch_ServerInterface SchServer = SCH.GlobalVars.SchServer;
            //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.

            //bool DocOpened = false;
            //for (LoopIterator = 1; LoopIterator <= LogicalDocumentCount; LoopIterator++)
            //{
            //    CurrentSheet = CurrentProject.DM_LogicalDocuments(LoopIterator - 1);
            //    if (CurrentSheet.DM_DocumentKind() == "SCH")
            //    {
            //        DocOpened = false;
            //        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);

            //        ISch_Lib SchDoc;
            //        SchDoc = SchServer.LoadSchDocumentByPath(CurrentSheet.DM_FullPath()) as ISch_Lib;

            //        ISch_Iterator LibraryIterator, PIterator;
            //        ISch_Component Component;
            //        ISch_Parameter Param;
            //        VarParam<string, string> CompVars = new VarParam<string, string>();
            //        if (SchDoc == null)
            //            return;
            //        //Iterate theough all components on the schematic.
            //        LibraryIterator = SchDoc.SchIterator_Create();
            //        LibraryIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eSchComponent));

            //        Component = LibraryIterator.FirstSchObject() as ISch_Component;
            //        while (Component != null)
            //        {
            //            if (Variants.Components.ContainsKey(Component.GetState_DesignItemId()))
            //            {
            //                Component.UpdatePart_PreProcess();
            //                CompVars = Variants.Components[Component.GetState_DesignItemId()];
            //                //Iterate theough all parameters in the component.
            //                PIterator = Component.SchIterator_Create();
            //                PIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eParameter));

            //                Param = PIterator.FirstSchObject() as ISch_Parameter;
            //                while (Param != null)
            //                {
            //                    if (Param.GetState_Name() != null)
            //                        if ("PE_ENG" == Param.GetState_Name() || Param.GetState_Name() == "PE_FLT")
            //                        {

            //                            Param.SetState_Text(CompVars[Param.GetState_Name()]);
            //                        }
            //                    Param = PIterator.NextSchObject() as ISch_Parameter;
            //                }
            //                Component.UpdatePart_PostProcess();
            //            }

            //            Component = LibraryIterator.NextSchObject() as ISch_Component;
            //        }

            //        if (ServerDoc.GetModified())
            //            ServerDoc.DoFileSave("");

            //        if (!DocOpened)
            //            Client.CloseDocument(ServerDoc);

            //        ServerDoc = null;

            //    }

            //}

            //Client.ShowDocument(Client.GetDocumentByPath(ActiveDoc.DM_FullPath()));
            #endregion

            #region Set Var_PE
            IProject            project = DXP.GlobalVars.DXPWorkSpace.DM_FocusedProject() as IProject;
            IProjectVariant     Variant;
            IComponentVariation CompVariant;
            IParameterVariation ParamVariant;

            CheckParams();

            //Stores the library reference value for each refdes.
            ComponentList <string, string> CompList = GetComponents(); //Get list of components in the design.

            //GetComponents() will return null if there is an error.
            if (CompList == null)
            {
                MessageBox.Show("Error getting a list of components. Please check design and try again.", "Component List Error", MessageBoxButtons.OK);
                return;
            }

            string RefDes;
            for (int i = 0; i < project.DM_ProjectVariantCount(); i++)
            {
                Variant = project.DM_ProjectVariants(i);
                //Update Var_PE data only.
                if (project.DM_ProjectVariants(i).DM_Description().ToUpper() == "VAR_PE")
                {
                    pbProgress.Maximum = Variant.DM_VariationCount();
                    pbProgress.Value   = 0;
                    UpdateLabel("Updating Existing Variants");
                    //PCB.IPCB_Component.GetState_ChannelOffset()
                    //EDP.IProject.DM_ChannelDesignatorFormat()
                    //EDP.IProject.DM_ChannelRoomLevelSeperator()
                    //EDP.IPart.DM_ChannelOffset()
                    //EDP.IDocument.DM_ChannelIndex()
                    //EDP.IDocument.DM_ChannelPrefix()

                    for (int j = 0; j < Variant.DM_VariationCount(); j++)
                    {
                        CompVariant = Variant.DM_Variations(j);
                        RefDes      = CompVariant.DM_PhysicalDesignator();
                        //Check that there is data in the Variants list for current refdes.
                        if (CompList.ContainsKey(RefDes))
                        {
                            if (Variants.Components.ContainsKey(CompList[RefDes]))
                            {
                                for (int k = 0; k < CompVariant.DM_VariationCount(); k++)
                                {
                                    if (CompVariant.DM_VariationKind() != TVariationKind.eVariation_NotFitted)
                                    {
                                        ParamVariant = CompVariant.DM_Variations(k);
                                        //Update component variant parameter data.
                                        if ("PE_ENG" == ParamVariant.DM_ParameterName().ToUpper() || ParamVariant.DM_ParameterName().ToUpper() == "PE_FLT") //Verify a parameter we want.
                                        {
                                            if (CompList.ContainsKey(RefDes))
                                            {
                                                if (Variants.Components.ContainsKey(CompList[RefDes]))
                                                {
                                                    if (Variants.Components[CompList[RefDes]].ContainsKey(ParamVariant.DM_ParameterName().ToUpper())) //Make sure the parameter value is in our list of data.

                                                    //if (Variants.Components[CompList[RefDes]][ParamVariant.DM_ParameterName()] != CompVariant.DM_PhysicalDesignator()) //I dont know what this is for.
                                                    //if (Variants.Components[CompList[RefDes]][ParamVariant.DM_ParameterName().ToUpper()] != "x") //Make sure the parameter data is not 'x'
                                                    {
                                                        ParamVariant.DM_SetVariedValue(Variants.Components[CompList[RefDes]][ParamVariant.DM_ParameterName().ToUpper()] + "_$");
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if (CompList.ContainsKey(RefDes))
                                {
                                    CompList.Remove(RefDes);
                                }
                            }
                        }
                        pbProgress.Value = j;
                        UpdateLabel("Updating Existing Variants");
                    }
                    IComponentVariation tmpCompVar;

                    pbProgress.Maximum = CompList.Count;
                    pbProgress.Value   = 0;
                    UpdateLabel("Creating New Variants");
                    project.DM_BeginUpdate();
                    //Create new variants.
                    foreach (string CompRef in CompList.Keys)
                    {
                        if (Variants.Components.ContainsKey(CompList[CompRef]))
                        {
                            tmpCompVar = project.DM_ProjectVariants(i).DM_AddComponentVariation();
                            tmpCompVar.DM_SetVariationKind(TVariationKind.eVariation_None);
                            CreateCompVar(ref tmpCompVar, Variants.Components[CompList[CompRef]], CompRef);
                            Variants.Components[CompList[CompRef]].Saved = true;
                        }
                        pbProgress.Value++;
                        UpdateLabel("Creating New Variants");
                    }
                    project.DM_EndUpdate();
                }
            }
            #endregion

            return;
        }
        catch (Exception ex)
        {
            ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
            return;
        }
        finally
        {
            this.Close();
            MessageBox.Show("Process Complete");
        }
    }