Exemple #1
0
    /// <summary>
    /// Set parameter data in the provided variant.
    /// </summary>
    /// <param name="VarList">Parameter data.</param>
    /// <param name="VarName">Name of variant to modify.</param>
    /// <param name="Force">Force alternate variants to fitted.</param>
    void SetVariant(Var_Type VarList, string VarName, bool Force)
    {
        try
        {
            IProject            project = DXP.GlobalVars.DXPWorkSpace.DM_FocusedProject() as IProject;
            IProjectVariant     Variant;
            IComponentVariation CompVariant;
            IParameterVariation ParamVariant;
            if (project == null)
            {
                return;
            }
            project.DM_BeginUpdate();

            string RefDes;

            for (int i = 0; i < project.DM_ProjectVariantCount(); i++)
            {
                Variant = project.DM_ProjectVariants(i);
                //Find variant that matches the one provided.
                if (project.DM_ProjectVariants(i).DM_Description().ToUpper() == VarName)
                {
                    Progress.Maximum = (Variant.DM_VariationCount() + VarList.Components.Count);
                    Progress.Value   = 0;
                    UpdateLabel("Updating " + VarName + " Variants");
                    for (int j = 0; j < Variant.DM_VariationCount(); j++)
                    {
                        //Remove alternate variants  if Force is true.
                        if (Variant.DM_Variations(j).DM_VariationKind() == TVariationKind.eVariation_Alternate && Force)
                        {
                            Variant.DM_RemoveComponentVariation(j);
                            j--;
                        }
                        else
                        {
                            CompVariant = Variant.DM_Variations(j);
                            RefDes      = CompVariant.DM_PhysicalDesignator();
                            //Make sure there is parameter data for this component variant.
                            if (VarList.Components.ContainsKey(CompVariant.DM_PhysicalDesignator()))
                            {
                                for (int k = 0; k < CompVariant.DM_VariationCount(); k++)
                                {
                                    if (CompVariant.DM_VariationKind() != TVariationKind.eVariation_NotFitted)
                                    {
                                        ParamVariant = CompVariant.DM_Variations(k);
                                        //Update parameter data.
                                        if ("PE_ENG" == ParamVariant.DM_ParameterName().ToUpper() || ParamVariant.DM_ParameterName().ToUpper() == "PE_FLT")
                                        {
                                            if (VarList.Components[CompVariant.DM_PhysicalDesignator()].ContainsKey(ParamVariant.DM_ParameterName().ToUpper()))
                                            {
                                                if (VarList.Components[CompVariant.DM_PhysicalDesignator()][ParamVariant.DM_ParameterName().ToUpper()] != CompVariant.DM_PhysicalDesignator())
                                                {
                                                    if (OverwriteValue(ParamVariant.DM_VariedValue(), VarList.Components[CompVariant.DM_PhysicalDesignator()][ParamVariant.DM_ParameterName().ToUpper()], CompVariant.DM_PhysicalDesignator(), ParamVariant.DM_ParameterName().ToUpper()))
                                                    {
                                                        ParamVariant.DM_SetVariedValue(VarList.Components[CompVariant.DM_PhysicalDesignator()][ParamVariant.DM_ParameterName().ToUpper()] + "_$");
                                                        VarList.Components[CompVariant.DM_PhysicalDesignator()].Saved = true;
                                                    }
                                                }
                                            }
                                        }
                                        //else
                                        //{
                                        //    ParamVariant.DM_SetVariedValue(VarList.Components[CompVariant.DM_PhysicalDesignator()][ParamVariant.DM_ParameterName().ToUpper()] + "_$");
                                        //    VarList.Components[CompVariant.DM_PhysicalDesignator()].Saved = true;
                                        //}
                                    }
                                }
                                if (!VarList.Components[CompVariant.DM_PhysicalDesignator()].Saved)
                                {
                                    CreateCompVar(ref CompVariant, VarList.Components[CompVariant.DM_PhysicalDesignator()]);
                                    VarList.Components[CompVariant.DM_PhysicalDesignator()].Saved = true;
                                }
                            }
                        }
                        Progress.Value += 1;
                    }
                    IComponentVariation tmpCompVar;
                    foreach (string CompRef in VarList.Components.Keys)
                    {
                        //Add component variants that havent already been modified.
                        if (!VarList.Components[CompRef].Saved)
                        {
                            tmpCompVar = null;
                            tmpCompVar = project.DM_ProjectVariants(i).DM_AddComponentVariation();
                            tmpCompVar.DM_SetVariationKind(TVariationKind.eVariation_None);
                            CreateCompVar(ref tmpCompVar, VarList.Components[CompRef], CompRef);

                            VarList.Components[CompRef].Saved = true;
                        }
                        Progress.Value += 1;
                        UpdateLabel("Updating " + VarName + " Variants");
                    }
                }
            }
            project.DM_EndUpdate();
        }
        catch (Exception ex)
        {
            ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
            return;
        }
    }
Exemple #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");
        }
    }
Exemple #3
0
    /// <summary>
    /// Get parameter data from an existing variant.
    /// </summary>
    /// <param name="VarList">Reference to the class that will store the gathered parameter data.</param>
    public void Get_Variants(ref Var_Type VarList)
    {
        try
        {
            IProject            project = DXP.GlobalVars.DXPWorkSpace.DM_FocusedProject() as IProject;
            IProjectVariant     Variant;
            IComponentVariation CompVariant;
            IParameterVariation ParamVariant;

            VarParam <string, string> Parameters = new VarParam <string, string>();
            string RefDes;
            int    l = 0;

            for (int i = 0; i < project.DM_ProjectVariantCount(); i++)
            {
                l++;
                Variant = project.DM_ProjectVariants(i);

                //Find the variant that matches the one provided.
                if (project.DM_ProjectVariants(i).DM_Description().ToUpper() == VarList.VarName)
                {
                    Progress.Maximum = Variant.DM_VariationCount();
                    Progress.Value   = 0;
                    UpdateLabel("Loading Variants");
                    for (int j = 0; j < Variant.DM_VariationCount(); j++)
                    {
                        CompVariant = Variant.DM_Variations(j);
                        RefDes      = CompVariant.DM_PhysicalDesignator();

                        //checking to make sure all components have a refdes assigned.
                        if (RefDes.Contains("?"))
                        {
                            MessageBox.Show("Detected an un-annotated refdes. Please Annotate the project and try again.");
                            VarList = null;
                            return;
                        }
                        Parameters = new VarParam <string, string>();
                        //Iterate through all parameters for current component variant.
                        for (int k = 0; k < CompVariant.DM_VariationCount(); k++)
                        {
                            if (CompVariant.DM_VariationKind() != TVariationKind.eVariation_NotFitted)
                            {
                                ParamVariant = CompVariant.DM_Variations(k);
                                //Get values of matching parameters.
                                if ("PE_ENG" == ParamVariant.DM_ParameterName().ToUpper() || ParamVariant.DM_ParameterName().ToUpper() == "PE_FLT")
                                {
                                    string tmpVarValue = ParamVariant.DM_VariedValue() == null ? "x" : ParamVariant.DM_VariedValue();
                                    Parameters.Add(ParamVariant.DM_ParameterName().ToUpper(), tmpVarValue);
                                    if (!tmpVarValue.EndsWith("_$"))
                                    {
                                        ParamVariant.DM_SetVariedValue(tmpVarValue + "_$");
                                    }
                                }
                            }
                        }

                        l++;
                        //Save collected data to VarList.
                        if (Parameters.Count > 0)
                        {
                            VarList.Components.Add(RefDes, Parameters);
                        }
                        Progress.Value += 1;
                        UpdateLabel("Loading Variants");
                    }
                }
            }
        }
        catch (Exception ex)
        {
            ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
            return;
        }
    }
Exemple #4
0
    /// <summary>
    /// Get parameter data from an existing variant.
    /// </summary>
    /// <param name="VarList">Reference to the class that will store the gathered parameter data.</param>
    bool Get_Variants(string VariantName)
    {
        try
        {
            IProject            project = DXP.GlobalVars.DXPWorkSpace.DM_FocusedProject() as IProject;
            IProjectVariant     Variant;
            IComponentVariation CompVariant;
            IParameterVariation ParamVariant;
            CompData            NewComp;
            //VarParam<string, string> Parameters = new VarParam<string, string>();
            string RefDes;
            int    l = 0;

            for (int i = 0; i < project.DM_ProjectVariantCount(); i++)
            {
                l++;
                Variant = project.DM_ProjectVariants(i);

                //Find the variant that matches the one provided.
                if (project.DM_ProjectVariants(i).DM_Description().ToUpper() == VariantName)
                {
                    for (int j = 0; j < Variant.DM_VariationCount(); j++)
                    {
                        NewComp                 = new CompData("");
                        CompVariant             = Variant.DM_Variations(j);
                        RefDes                  = CompVariant.DM_PhysicalDesignator();
                        NewComp.RefDes          = RefDes;
                        NewComp.Base_Partnumber = RefCompList[RefDes].Base_Partnumber;
                        if (CompVariant.DM_VariationKind() == TVariationKind.eVariation_Alternate)
                        {
                            if (VariantName.ToUpper() == "VAR_ENG")
                            {
                                NewComp.Var_Eng_LibRef = CompVariant.DM_AlternateLibraryLink().DM_DesignItemID();
                            }
                            else if (VariantName.ToUpper() == "VAR_FLT")
                            {
                                NewComp.Var_Flt_LibRef = CompVariant.DM_AlternateLibraryLink().DM_DesignItemID();
                            }
                        }
                        //checking to make sure all components have a refdes assigned.
                        if (RefDes.Contains("?"))
                        {
                            MessageBox.Show("Detected and un-annotated refdes. Please Annotate the project and try again.");
                            return(false);
                        }
                        //Iterate through all parameters for current component variant.
                        for (int k = 0; k < CompVariant.DM_VariationCount(); k++)
                        {
                            if (CompVariant.DM_VariationKind() != TVariationKind.eVariation_NotFitted)
                            {
                                ParamVariant = CompVariant.DM_Variations(k);
                                if (VariantName.ToUpper() != "VAR_PE")
                                {
                                    //Get values of matching parameters.
                                    if ("PARTNUMBER" == ParamVariant.DM_ParameterName().ToUpper())
                                    {
                                        if (VariantName.ToUpper() == "VAR_ENG")
                                        {
                                            NewComp.Var_Eng_Partnumber = ParamVariant.DM_VariedValue();
                                        }
                                        else if (VariantName.ToUpper() == "VAR_FLT")
                                        {
                                            NewComp.Var_Flt_Partnumber = ParamVariant.DM_VariedValue();
                                        }
                                    }
                                }
                                else
                                {
                                    if ("PE_FLT" == ParamVariant.DM_ParameterName().ToUpper())
                                    {
                                        NewComp.PE_FLT_Partnumber = (ParamVariant.DM_VariedValue() == null) ? ParamVariant.DM_VariedValue() : "";
                                    }
                                    else if ("PE_ENG" == ParamVariant.DM_ParameterName().ToUpper())
                                    {
                                        NewComp.PE_ENG_Partnumber = (ParamVariant.DM_VariedValue() == null) ? ParamVariant.DM_VariedValue() : "";
                                    }
                                }
                            }
                        }
                        AddPart(NewComp);
                        l++;
                    }
                }
            }
            return(true);
        }
        catch (Exception ex)
        {
            ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
            return(false);
        }
    }