Пример #1
0
    /// <summary>
    /// Compiles a list of selected components.
    /// </summary>
    void GetSelectedComponents()
    {
        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();

        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 selected component is a variant.
                {
                    RefDes = Component.GetState_Name().GetState_Text();
                    if (Component.GetState_Selected())
                    { //Add to lists.
                        SelectedRef.Add(RefDes);
                        SelectedComp.Add(Component);
                    }
                }
            }

            Component = (IPCB_Component)BoardIterator.NextPCBObject();
        }
        //Iterator clean-up
        Board.BoardIterator_Destroy(ref BoardIterator);
    }
Пример #2
0
    /// <summary>
    /// Will adjust refdes orientation to match component orientation.
    /// </summary>
    public void FixRefDesOrientation()
    {
        try
        {
            IPCB_BoardIterator BoardIterator;
            IPCB_Component     Component;
            IPCB_Text          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);
            //int cnt = 0;
            //Component = (IPCB_Component)BoardIterator.FirstPCBObject();

            //while (Component != null)
            //{
            //    cnt++;
            //    Component = (IPCB_Component)BoardIterator.NextPCBObject();
            //}

            Component = (IPCB_Component)BoardIterator.FirstPCBObject();
            //DXP.Utils.PercentInit("Updating RefDes", cnt);//Progressbar init.
            while (Component != null)
            {
                RefDes = Component.GetState_Name();
                if (Component.GetState_NameAutoPos() == TTextAutoposition.eAutoPos_CenterCenter)
                {
                    Component.SetState_NameAutoPos(TTextAutoposition.eAutoPos_Manual);
                    Component.BeginModify();
                    RefDes.BeginModify();
                    switch (Convert.ToInt32(Component.GetState_Rotation()))
                    {
                    case 0:    //for bottom: 90=270
                        RefDes.SetState_Rotation(0);
                        break;

                    case 90:
                        if (RefDes.GetState_Layer() == TV6_Layer.eV6_BottomOverlay)
                        {
                            RefDes.SetState_Rotation(270);
                        }
                        else
                        {
                            RefDes.SetState_Rotation(90);
                        }
                        break;

                    case 180:
                        RefDes.SetState_Rotation(0);
                        break;

                    case 270:
                        if (RefDes.GetState_Layer() == TV6_Layer.eV6_BottomOverlay)
                        {
                            RefDes.SetState_Rotation(270);
                        }
                        else
                        {
                            RefDes.SetState_Rotation(90);
                        }
                        break;
                    }



                    //Component.SetState_NameAutoPos(TTextAutoposition.eAutoPos_CenterCenter);
                    Component.ChangeNameAutoposition(TTextAutoposition.eAutoPos_CenterCenter);
                    RefDes.EndModify();
                    RefDes.GraphicallyInvalidate();
                    Component.EndModify();
                    Component.GraphicallyInvalidate();
                }
                //DXP.Utils.PercentUpdate();
                Component = (IPCB_Component)BoardIterator.NextPCBObject();
            }
            //Iterator clean-up
            Board.BoardIterator_Destroy(ref BoardIterator);
            Board.GraphicalView_ZoomRedraw();
            //Board.GraphicallyInvalidate();
            //DXP.Utils.PercentFinish();
            System.Windows.Forms.MessageBox.Show("Process Complete");
        }
        catch (Exception ex)
        {
            ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
        }
    }
Пример #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;
        }
    }
Пример #4
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);
        }
    }
Пример #5
0
    /// <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");
    }
Пример #6
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);
        }
    }