Esempio n. 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;
        }
    }
Esempio n. 2
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="VariantName"></param>
    /// <returns></returns>
    public Dictionary <string, IComponentVariation> Get_Variants(string VariantName)
    {
        try
        {
            Dictionary <string, IComponentVariation> Output = new Dictionary <string, IComponentVariation>();
            IProject            project = DXP.GlobalVars.DXPWorkSpace.DM_FocusedProject() as IProject;
            IProjectVariant     Variant;
            IComponentVariation CompVariant;
            IParameterVariation ParamVariant;
            //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() == VariantName)
                {
                    for (int j = 0; j < Variant.DM_VariationCount(); j++)
                    {
                        CompVariant = Variant.DM_Variations(j);
                        RefDes      = CompVariant.DM_PhysicalDesignator().ToUpper();

                        //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.");
                            return(null);
                        }
                        ParamVariant = CompVariant.DM_FindParameterVariation("ClassName");
                        if (ParamVariant != null)
                        {
                            if (ParamVariant.DM_VariedValue() != null)
                            {
                                ParamVariant.DM_SetVariedValue("");
                            }
                        }

                        if (CompVariant.DM_VariationKind() == TVariationKind.eVariation_Alternate)
                        {
                            Output.Add(RefDes, CompVariant);
                        }

                        // Parameters = new VarParam<string, string>();
                        ////Iterate through all parameters for current component variant.
                        //for (int k = 0; k < CompVariant.DM_VariationCount(); k++)
                        //{

                        //        //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++;
                    }
                }
            }

            return(Output);
        }
        catch (Exception ex)
        {
            ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
            return(null);
        }
    }
Esempio n. 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;
        }
    }
Esempio n. 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);
        }
    }