Пример #1
0
    /// <summary>
    /// Get the number of Alternates in the provided variant.
    /// </summary>
    /// <param name="VariantName">Name of variant to check.</param>
    /// <returns>Quantity of Alternates in provided variant.</returns>
    public int Get_VariantAlternates(string VariantName)
    {
        try
        {
            IProject            project = DXP.GlobalVars.DXPWorkSpace.DM_FocusedProject() as IProject;
            IProjectVariant     Variant;
            IComponentVariation CompVariant;

            VarParam <string, string> Parameters = new VarParam <string, string>();
            int cnt = 0;
            for (int i = 0; i < project.DM_ProjectVariantCount(); i++)
            {
                Variant = project.DM_ProjectVariants(i);
                //Find variant with the same name as the one provided.
                if (project.DM_ProjectVariants(i).DM_Description() == VariantName)
                {
                    for (int j = 0; j < Variant.DM_VariationCount(); j++)
                    {
                        CompVariant = Variant.DM_Variations(j);
                        //Count the number of alternates.
                        if (CompVariant.DM_VariationKind() == TVariationKind.eVariation_Alternate)
                        {
                            cnt++;
                        }
                    }
                }
            }
            return(cnt);
        }
        catch (Exception ex)
        {
            ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
            return(-1);
        }
    }
Пример #2
0
    /// <summary>
    /// Create a new component variant.
    /// </summary>
    /// <param name="Dest">Component to create variant for.</param>
    /// <param name="Source">Parameter data.</param>
    /// <param name="RefDes">Refdes of component being modified.</param>
    void CreateCompVar(ref IComponentVariation Dest, VarParam <string, string> Source, string RefDes = "")
    {
        IParameterVariation tmpParam;

        if (RefDes != "")
        {
            Dest.DM_SetPhysicalDesignator(RefDes); //Set refdes
        }
        foreach (string key in Source.Keys)        //Set each parameter
        {
            tmpParam = Dest.DM_AddParameterVariation();
            tmpParam.DM_SetParameterName(key);
            tmpParam.DM_SetVariedValue(Source[key] + "_$");
        }
    }
Пример #3
0
 /// <summary>
 /// Create a new component variant.
 /// </summary>
 /// <param name="Dest">Component to create variant for.</param>
 /// <param name="Source">Parameter data.</param>
 /// <param name="RefDes">Refdes of component being modified.</param>
 void CreateCompVar(ref IComponentVariation Dest, VarParam <string, string> Source, string RefDes)
 {
     try
     {
         IParameterVariation tmpParam;
         Dest.DM_SetPhysicalDesignator(RefDes);
         foreach (string key in Source.Keys)
         {
             tmpParam = Dest.DM_AddParameterVariation();
             tmpParam.DM_SetParameterName(key);
             tmpParam.DM_SetVariedValue(Source[key] + "_$");
         }
     }
     catch (Exception ex)
     {
         ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
         return;
     }
 }
Пример #4
0
 public bool TryGetValue(string key, out VarParam <string, string> value)
 {
     return(((IDictionary <string, VarParam <string, string> >)backingDictionary).TryGetValue(key, out value));
 }
Пример #5
0
 public void Add(string key, VarParam <string, string> value)
 {
     ((IDictionary <string, VarParam <string, string> >)backingDictionary).Add(key, value);
 }
Пример #6
0
    /// <summary>
    /// Updates base design parameters based on provided data.
    /// </summary>
    /// <param name="VarList">Parameter data</param>
    void SetBaseDesign(Var_Type VarList)
    {
        try
        {
            string        RefDes;
            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.

            Progress.Maximum = LogicalDocumentCount;
            Progress.Value   = 0;
            UpdateLabel("Updating Variants");
            bool DocOpened = false;
            //Iterate through all documents looking for scheatic docs.
            for (LoopIterator = 1; LoopIterator <= LogicalDocumentCount; LoopIterator++)
            {
                CurrentSheet = CurrentProject.DM_LogicalDocuments(LoopIterator - 1);
                if (CurrentSheet.DM_DocumentKind() == "SCH")
                {
                    //Open document if not already open.
                    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)
                    {
                        RefDes = Component.GetState_SchDesignator().GetState_Text();
                        if (VarList.Components.ContainsKey(Component.GetState_SchDesignator().GetState_Text()))
                        {
                            if (VarList.Components[Component.GetState_SchDesignator().GetState_Text()].Saved == false)
                            {
                                Component.UpdatePart_PreProcess();
                                CompVars = VarList.Components[Component.GetState_SchDesignator().GetState_Text()];
                                //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 (Param.GetState_Name().ToUpper() != null)
                                        {
                                            //Set parameter data in component if it is in the provided parameter data.
                                            //Param = null;
                                            if (CompVars.ContainsKey(Param.GetState_Name().ToUpper()))
                                            {
                                                if (Param.GetState_Text() == "x")
                                                {
                                                    Param.SetState_Text(CompVars[Param.GetState_Name().ToUpper()]);
                                                }
                                                else if (OverwriteValue(Param.GetState_Text().ToUpper(), CompVars[Param.GetState_Name().ToUpper()], Component.GetState_SchDesignator().GetState_Text(), Param.GetState_Name().ToUpper()))
                                                {
                                                    Param.SetState_Text(CompVars[Param.GetState_Name().ToUpper()]);
                                                }
                                            }
                                        }
                                    }
                                    Param = PIterator.NextSchObject() as ISch_Parameter;
                                }
                                Component.UpdatePart_PostProcess();
                                VarList.Components[Component.GetState_SchDesignator().GetState_Text()].Saved = true;
                            }
                        }
                        Component = LibraryIterator.NextSchObject() as ISch_Component;
                    }

                    if (ServerDoc.GetModified())
                    {
                        ServerDoc.DoFileSave("");
                    }

                    if (!DocOpened)
                    {
                        Client.CloseDocument(ServerDoc);
                    }

                    ServerDoc = null;
                }
                Progress.Value += 1;
                UpdateLabel("Updating Variants");
            }

            Client.ShowDocument(Client.GetDocumentByPath(ActiveDoc.DM_FullPath()));
            return;
        }
        catch (Exception ex)
        {
            ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
            return;
        }
    }
Пример #7
0
    /// <summary>
    /// Get parameter data from the base design.
    /// </summary>
    /// <param name="VarList">Reference to the class that will store the gathered parameter data.</param>
    public void GetBaseVariants(ref Var_Type VarList)
    {
        try
        {
            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.
            VarParam <string, string> Parameters = new VarParam <string, string>();
            string RefDes;

            bool DocOpened = false;
            Progress.Value   = 0;
            Progress.Maximum = LogicalDocumentCount;
            UpdateLabel("Loading Variants");
            //iterate through project documents.
            for (LoopIterator = 1; LoopIterator <= LogicalDocumentCount; LoopIterator++)
            {
                CurrentSheet = CurrentProject.DM_LogicalDocuments(LoopIterator - 1);
                //Check for schematic documents.
                if (CurrentSheet.DM_DocumentKind() == "SCH")
                {
                    DocOpened = false;
                    //Open documents
                    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;
                    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 (Component.GetState_SchDesignator().GetState_Text().Contains("?"))
                        {
                            MessageBox.Show("Detected and un-annotated refdes. Please Annotate the project and try again.");
                            VarList = null;
                            return;
                        }
                        RefDes     = Component.GetState_SchDesignator().GetState_Text();
                        Parameters = new VarParam <string, string>();

                        //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)
                            {
                                //Store specific parameter data.
                                if ("PE_ENG" == Param.GetState_Name().ToUpper() || Param.GetState_Name().ToUpper() == "PE_FLT")
                                {
                                    if (Param.GetState_Text() != "x")
                                    {
                                        Parameters.Add(Param.GetState_Name().ToUpper(), Param.GetState_CalculatedValueString());
                                    }
                                }
                            }
                            Param = PIterator.NextSchObject() as ISch_Parameter;
                        }
                        //Add stored parameter data to VarList.
                        if (Parameters.Count > 0)
                        {
                            if (!VarList.Components.ContainsKey(RefDes))
                            {
                                VarList.Components.Add(RefDes, Parameters);
                            }
                        }
                        Component = LibraryIterator.NextSchObject() as ISch_Component;
                    }

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

                    //Close opend documents.
                    if (!DocOpened)
                    {
                        Client.CloseDocument(ServerDoc);
                    }

                    ServerDoc = null;
                }
                Progress.Value += 1;
                UpdateLabel("Loading Variants");
            }

            Client.ShowDocument(Client.GetDocumentByPath(ActiveDoc.DM_FullPath()));
            return;
        }
        catch (Exception ex)
        {
            ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
            return;
        }
    }
Пример #8
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;
        }
    }
Пример #9
0
    /// <summary>
    /// Get component list with library IDs.
    /// </summary>
    /// <returns></returns>
    public void CheckParams()
    {
        try
        {
            ComponentList <string, string> Output = new ComponentList <string, string>();
            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.

            pbProgress.Maximum = LogicalDocumentCount;
            pbProgress.Value   = 0;
            UpdateLabel("Checking Parameters");

            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());
                    }

                    ISch_Document SchDoc;
                    SchDoc = SchServer.LoadSchDocumentByPath(CurrentSheet.DM_FullPath()) as ISch_Document;

                    ISch_Iterator             LibraryIterator, PIterator;
                    ISch_Component            Component;
                    VarParam <string, string> CompVars = new VarParam <string, string>();
                    ISch_Parameter            Param;
                    bool Flt = false, Eng = false;
                    //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)
                    {
                        //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().ToUpper())
                                {
                                    Eng = true;
                                }
                                else if (Param.GetState_Name().ToUpper() == "PE_FLT")
                                {
                                    Flt = true;
                                }
                            }

                            Param = PIterator.NextSchObject() as ISch_Parameter;
                        }

                        if (!Flt)
                        {
                            Param = Component.AddSchParameter();
                            Param.SetState_Name("PE_FLT");
                            Param.SetState_Text("x");
                        }

                        if (!Eng)
                        {
                            Param = Component.AddSchParameter();
                            Param.SetState_Name("PE_ENG");
                            Param.SetState_Text("x");
                        }
                        Flt       = false;
                        Eng       = false;
                        Component = LibraryIterator.NextSchObject() as ISch_Component;
                    }

                    if (!DocOpened)
                    {
                        Client.CloseDocument(ServerDoc);
                    }

                    ServerDoc = null;
                }
                pbProgress.Value++;
                UpdateLabel("Checking Parameters");
            }

            Client.ShowDocument(Client.GetDocumentByPath(ActiveDoc.DM_FullPath()));

            return;
        }
        catch (Exception ex)
        {
            ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
            return;
        }
    }
Пример #10
0
    /// <summary>
    /// Load parameter data from excel doc.
    /// </summary>
    /// <param name="Path">Path to excel doc.</param>
    /// <returns></returns>
    Var_Type GetPEData(string Path)
    {
        pbProgress.Value = 0;
        UpdateLabel("Opening Excel Doc");
        Excel.Application xlApp;
        Excel.Workbook    xlWorkBook = null;
        Excel.Worksheet   xlWorkSheet;
        object            misValue = System.Reflection.Missing.Value;

        if (Path == "")
        {
            return(null);
        }

        xlApp       = new Excel.Application();
        xlWorkBook  = xlApp.Workbooks.Open(Path, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
        xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

        Var_Type Output = new Var_Type();
        VarParam <string, string> tmpParams;
        string PE_Flt, PE_Eng, LibRef;

        try
        {
            Output.VarName = "ModBOM";

            pbProgress.Maximum = 3;
            UpdateLabel("Getting Column Headers");

            //Get column letters for specific column names.
            PE_Eng = GetColumn("PE_ENG", ref xlWorkSheet);

            pbProgress.Value = 1;
            UpdateLabel("Getting Column Headers");

            PE_Flt = GetColumn("PE_FLT", ref xlWorkSheet);

            pbProgress.Value = 2;
            UpdateLabel("Getting Column Headers");

            LibRef = GetColumn("LIBREF", ref xlWorkSheet);

            pbProgress.Value = 3;
            UpdateLabel("Getting Column Headers");

            if (PE_Eng == "" || PE_Flt == "" || LibRef == "")
            {
                MessageBox.Show("One or more parameters are missing from the BOM. Please try again with a different BOM.");
                xlWorkBook.Close(false, misValue, misValue);
                xlApp.Quit();


                releaseObject(xlWorkSheet);
                releaseObject(xlWorkBook);
                releaseObject(xlApp);
                return(null);
            }

            int Row = 2;
            int cnt = 0;
            while (xlWorkSheet.Range[LibRef + Row].Value2 != null)
            {
                Row++;
                cnt++;
            }
            pbProgress.Maximum = cnt;

            pbProgress.Value = 0;
            UpdateLabel("Reading Data");

            Row = 2;
            //Read parameter data.
            while (xlWorkSheet.Range[LibRef + Row].Value2 != null)
            {
                //if (xlWorkSheet.Range[PE_Flt + Row].Value2.ToString() != "x" || xlWorkSheet.Range[PE_Eng + Row].Value2.ToString() != "x")
                //{
                if (Output.Components.ContainsKey(xlWorkSheet.Range[LibRef + Row].Value2.ToString()))
                {
                    MessageBox.Show("Multiple library references for " + xlWorkSheet.Range[LibRef + Row].Value2.ToString() + " in this BOM. First instance is used.");
                }
                else
                {
                    if (xlWorkSheet.Range[PE_Flt + Row].Value2 == null)
                    {
                        xlWorkSheet.Range[PE_Flt + Row].Value2 = "x";
                    }
                    if (xlWorkSheet.Range[PE_Eng + Row].Value2 == null)
                    {
                        xlWorkSheet.Range[PE_Eng + Row].Value2 = "x";
                    }

                    if (xlWorkSheet.Range[PE_Flt + Row].Value2.ToString() == "x")
                    {
                        xlWorkSheet.Range[PE_Flt + Row].Value2 = "z";
                    }
                    if (xlWorkSheet.Range[PE_Eng + Row].Value2.ToString() == "x")
                    {
                        xlWorkSheet.Range[PE_Eng + Row].Value2 = "z";
                    }
                    tmpParams = new VarParam <string, string>();
                    tmpParams.Add(new KeyValuePair <string, string>("PE_ENG", xlWorkSheet.Range[PE_Eng + Row].Value2.ToString().Replace("'", "")));
                    tmpParams.Add(new KeyValuePair <string, string>("PE_FLT", xlWorkSheet.Range[PE_Flt + Row].Value2.ToString().Replace("'", "")));
                    Output.Components.Add(new KeyValuePair <string, VarParam <string, string> >(xlWorkSheet.Range[LibRef + Row].Value2.ToString(), tmpParams));
                }
                //}
                Row++;
                pbProgress.Value++;
                UpdateLabel("Reading Data");
            }
            //xlWorkBook.Close(false, misValue, misValue);
            //xlApp.Quit();


            //releaseObject(xlWorkSheet);
            //releaseObject(xlWorkBook);
            //releaseObject(xlApp);


            //return Output;
        }
        catch (Exception ex)
        {
            ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
            Output = null;
        }

        xlWorkBook.Close(false, misValue, misValue);
        xlApp.Quit();


        releaseObject(xlWorkSheet);
        releaseObject(xlWorkBook);
        releaseObject(xlApp);
        return(Output);
    }
Пример #11
0
    /// <summary>
    /// Get parameter data from the base design.
    /// </summary>
    /// <param name="VarList">Reference to the class that will store the gathered parameter data.</param>
    public void GetBaseVariants()
    {
        try
        {
            IDXPWorkSpace CurrentWorkspace = DXP.GlobalVars.DXPWorkSpace;
            IDXPProject   CurrentProject;
            int           LogicalDocumentCount;
            int           LoopIterator;
            Dictionary <string, IComponentVariation> FltCompVar, EngCompVar;
            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.
            VarParam <string, string> Parameters = new VarParam <string, string>();
            string RefDes;

            IParameterVariation TempVar;
            int  Matches;
            bool DocOpened = false;

            FltCompVar = Get_Variants("VAR_FLT");
            EngCompVar = Get_Variants("VAR_ENG");

            if (FltCompVar == null || EngCompVar == null)
            {
                return;
            }

            //iterate through project documents.
            for (LoopIterator = 1; LoopIterator <= LogicalDocumentCount; LoopIterator++)
            {
                CurrentSheet = CurrentProject.DM_LogicalDocuments(LoopIterator - 1);
                //Check for schematic documents.
                if (CurrentSheet.DM_DocumentKind() == "SCH")
                {
                    DocOpened = false;
                    //Open documents
                    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       SchIterator, PIterator;
                    ISch_Component      Component;
                    ISch_Implementation Footprint;
                    ISch_Parameter      Param;
                    if (SchDoc == null)
                    {
                        return;
                    }
                    //Iterate theough all components on the schematic.
                    SchIterator = SchDoc.SchIterator_Create();
                    SchIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eSchComponent));

                    Component = SchIterator.FirstSchObject() as ISch_Component;



                    while (Component != null)
                    {
                        Matches = 0;
                        if (Component.GetState_SchDesignator().GetState_Text().Contains("?"))
                        {
                            MessageBox.Show("Detected and un-annotated refdes. Please Annotate the project and try again.");
                            return;
                        }
                        RefDes = Component.GetState_SchDesignator().GetState_Text();



                        //Iterate theough all parameters in the component.
                        PIterator = Component.SchIterator_Create();
                        PIterator.AddFilter_ObjectSet(new SCH.TObjectSet(SCH.TObjectId.eImplementation));

                        Footprint = PIterator.FirstSchObject() as ISch_Implementation;
                        if (FltCompVar.ContainsKey(RefDes))
                        {
                            if (FltCompVar[RefDes].DM_AlternateLibraryLink().DM_Footprint() != Footprint.GetState_ModelName())
                            {
                                TempVar = FltCompVar[RefDes].DM_FindParameterVariation("ClassName");
                                if (TempVar != null)
                                {
                                    TempVar.DM_SetVariedValue("Stencil_Flt");
                                }
                                Matches++;
                            }
                        }

                        if (EngCompVar.ContainsKey(RefDes))
                        {
                            if (EngCompVar[RefDes].DM_AlternateLibraryLink().DM_Footprint() != Footprint.GetState_ModelName())
                            {
                                TempVar = EngCompVar[RefDes].DM_FindParameterVariation("ClassName");
                                if (TempVar != null)
                                {
                                    TempVar.DM_SetVariedValue("Stencil_Eng");
                                }
                                Matches++;
                            }
                        }

                        //?Param.GetState_ModelName()
                        //"FIDUCIAL_SMD"

                        //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() == "ClassName")
                            {
                                if (Matches == 2)
                                {
                                    Param.SetState_Text("Stencil_Base");
                                }
                                else
                                {
                                    Param.SetState_Text("");
                                }

                                Component.UpdatePart_PostProcess();
                                break;
                            }
                            Param = PIterator.NextSchObject() as ISch_Parameter;
                        }

                        Component = SchIterator.NextSchObject() as ISch_Component;
                    }

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

                    //Close opend documents.
                    if (!DocOpened)
                    {
                        Client.CloseDocument(ServerDoc);
                    }

                    ServerDoc = null;
                }
            }

            Client.ShowDocument(Client.GetDocumentByPath(ActiveDoc.DM_FullPath()));
            return;
        }
        catch (Exception ex)
        {
            ErrorMail.LogError("Error in " + System.Reflection.MethodBase.GetCurrentMethod().Name + ".", ex);
            return;
        }
    }