Exemple #1
0
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            if ((_pApplication == null) || (_pApplication.IsInvalid))
            {
                return(new PropertyDescriptorCollection(new PropertyDescriptor[] { }));
            }

            List <GlobalParameterPropertyDescriptor> list = new List <GlobalParameterPropertyDescriptor>();

            try
            {
                ComTypeLibrary comTypeLibrary = ComTypeManager.Instance.ComTypeLibraries.Where(x => x.Name.Equals("SolidEdgeFramework")).FirstOrDefault();

                if (comTypeLibrary != null)
                {
                    ComEnumInfo enumInfo = comTypeLibrary.Enums.Where(x => x.Name.Equals("ApplicationGlobalConstants")).FirstOrDefault();

                    foreach (ComVariableInfo variableInfo in enumInfo.Variables)
                    {
                        if (String.IsNullOrEmpty(_filter) == false)
                        {
                            if (variableInfo.Name.IndexOf(_filter, StringComparison.OrdinalIgnoreCase) == -1)
                            {
                                continue;
                            }
                        }

                        SolidEdgeFramework.ApplicationGlobalConstants globalConst = (SolidEdgeFramework.ApplicationGlobalConstants)variableInfo.ConstantValue;

                        // There is a known bug where seApplicationGlobalOpenAsReadOnly3DFile causes SE to display the read-only icon on
                        // files after GetGlobalParameter() is called.
                        if (globalConst.Equals(SolidEdgeFramework.ApplicationGlobalConstants.seApplicationGlobalOpenAsReadOnly3DFile))
                        {
                            continue;
                        }

                        try
                        {
                            object[] args        = new object[] { globalConst, new VariantWrapper(null) };
                            object   returnValue = null;

                            if (MarshalEx.Succeeded(_pApplication.TryInvokeMethod("GetGlobalParameter", args, out returnValue)))
                            {
                                if (args[1] != null)
                                {
                                    Type propertyType = args[1].GetType();

                                    string        name        = variableInfo.Name.Replace("seApplicationGlobal", string.Empty);
                                    StringBuilder description = new StringBuilder();
                                    description.AppendLine(variableInfo.Description);
                                    description.AppendLine(String.Format("Application.GetGlobalParameter({0}.{1}, out value)", enumInfo.FullName, variableInfo.Name));

                                    GlobalParameterProperty property = new GlobalParameterProperty(name, description.ToString(), args[1], propertyType, true);

                                    list.Add(new GlobalParameterPropertyDescriptor(ref property, attributes));

                                    try
                                    {
                                        if (_colorGlobalConstants.Contains(globalConst))
                                        {
                                            var color = Color.Empty;

                                            if (args[1] is int)
                                            {
                                                byte[] rgb = BitConverter.GetBytes((int)args[1]);
                                                color = Color.FromArgb(255, rgb[0], rgb[1], rgb[2]);
                                            }
                                            else if (args[1] is uint)
                                            {
                                                byte[] rgb = BitConverter.GetBytes((uint)args[1]);
                                                color = Color.FromArgb(255, rgb[0], rgb[1], rgb[2]);
                                            }
                                            else
                                            {
#if DEBUG
                                                //System.Diagnostics.Debugger.Break();
#endif
                                            }

                                            if (color.IsEmpty == false)
                                            {
                                                description = new StringBuilder();
                                                description.AppendLine(property.Description);
                                                description.AppendLine("byte[] rgb = BitConverter.GetBytes((int)value)");
                                                description.AppendLine("Color color = Color.FromArgb(255, rgb[0], rgb[1], rgb[2]");

                                                property = new GlobalParameterProperty(String.Format("{0} (converted to color)", property.Name), description.ToString(), color, color.GetType(), true);

                                                list.Add(new GlobalParameterPropertyDescriptor(ref property, attributes));
                                            }
                                        }
                                    }
                                    catch
                                    {
                                    }
                                }
                            }
                        }
                        catch
                        {
                            GlobalExceptionHandler.HandleException();
                        }
                    }
                }
            }
            catch
            {
                GlobalExceptionHandler.HandleException();
            }

            return(new PropertyDescriptorCollection(list.ToArray()));
        }
Exemple #2
0
        private ComTreeNode[] GetChildren(ComPtr comPtr)
        {
            if (comPtr == null) return new ComTreeNode[] { };

            ComTypeInfo comTypeInfo = comPtr.TryGetComTypeInfo();

            if (comTypeInfo == null) return new ComTreeNode[] { };

            List<ComTreeNode> childNodes = new List<ComTreeNode>();

            try
            {
                foreach (ComPropertyInfo comPropertyInfo in comTypeInfo.Properties)
                {
                    // Special case. MailSession is a PITA property that causes modal dialog.
                    if (comPropertyInfo.Name.Equals("MailSession"))
                    {
                        continue;
                    }

                    ComTreeNode comTreeNode = GetChild(comPtr, comPropertyInfo);

                    if (comTreeNode != null)
                    {
                        if ((comTreeNode is ComPropertyTreeNode) && (_showProperties == false))
                        {
                            continue;
                        }

                        childNodes.Add(comTreeNode);
                    }
                }

                if (comPtr.TryIsCollection())
                {
                    int count = comPtr.TryGetItemCount();

                    try
                    {
                        ComFunctionInfo comFunctionInfo = comTypeInfo.Methods.Where(x => x.Name.Equals("Item", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                        if (comFunctionInfo != null)
                        {
                            // Solid Edge is supposed to be 1 based index but some collections are 0 based.
                            // Application->Customization->RibbonBarThemes seems to be 0 based.
                            for (int i = 0; i <= count; i++)
                            {
                                object returnValue = null;
                                if (MarshalEx.Succeeded(comPtr.TryInvokeMethod("Item", new object[] { i }, out returnValue)))
                                {
                                    ComPtr pItem = returnValue as ComPtr;
                                    if ((pItem != null) && (pItem.IsInvalid == false))
                                    {
                                        ComPtrItemTreeNode comPtrItemTreeNode = new ComPtrItemTreeNode((ComPtr)returnValue, comFunctionInfo);
                                        comPtrItemTreeNode.Caption = String.Format("{0}({1})", comFunctionInfo.Name, i);
                                        comPtrItemTreeNode.Nodes.Add("...");
                                        childNodes.Add(comPtrItemTreeNode);
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                        GlobalExceptionHandler.HandleException();
                    }
                }

                if (_showMethods)
                {
                    foreach (ComFunctionInfo comFunctionInfo in comTypeInfo.GetMethods(true))
                    {
                        if (comFunctionInfo.IsRestricted) continue;

                        ComMethodTreeNode comMethodTreeNode = new ComMethodTreeNode(comFunctionInfo);
                        childNodes.Add(comMethodTreeNode);
                    }
                }
            }
            catch
            {
                GlobalExceptionHandler.HandleException();
            }

            return childNodes.ToArray();
        }
Exemple #3
0
        private ComTreeNode[] GetChildren(ComPtr comPtr)
        {
            if (comPtr == null)
            {
                return new ComTreeNode[] { }
            }
            ;

            ComTypeInfo comTypeInfo = comPtr.TryGetComTypeInfo();

            if (comTypeInfo == null)
            {
                return new ComTreeNode[] { }
            }
            ;

            List <ComTreeNode> childNodes = new List <ComTreeNode>();

            try
            {
                foreach (ComPropertyInfo comPropertyInfo in comTypeInfo.Properties)
                {
                    // Special case. MailSession is a PITA property that causes modal dialog.
                    if (comPropertyInfo.Name.Equals("MailSession"))
                    {
                        continue;
                    }

                    ComTreeNode comTreeNode = GetChild(comPtr, comPropertyInfo);

                    if (comTreeNode != null)
                    {
                        if ((comTreeNode is ComPropertyTreeNode) && (_showProperties == false))
                        {
                            continue;
                        }

                        childNodes.Add(comTreeNode);
                    }
                }

                if (comPtr.TryIsCollection())
                {
                    List <ComTreeNode> collectionChildNodes = new List <ComTreeNode>();
                    int count      = comPtr.TryGetItemCount();
                    int foundCount = 0;

                    try
                    {
                        ComFunctionInfo comFunctionInfo = comTypeInfo.Methods.Where(x => x.Name.Equals("Item", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                        if (comFunctionInfo != null)
                        {
                            object returnValue = null;

                            // Solid Edge is supposed to be 1 based index.
                            for (int i = 1; i <= count; i++)
                            {
                                returnValue = null;
                                if (MarshalEx.Succeeded(comPtr.TryInvokeMethod("Item", new object[] { i }, out returnValue)))
                                {
                                    ComPtr pItem = returnValue as ComPtr;
                                    if ((pItem != null) && (pItem.IsInvalid == false))
                                    {
                                        ComPtrItemTreeNode comPtrItemTreeNode = new ComPtrItemTreeNode((ComPtr)returnValue, comFunctionInfo);
                                        comPtrItemTreeNode.Caption = String.Format("{0}({1})", comFunctionInfo.Name, i);
                                        comPtrItemTreeNode.Nodes.Add("...");
                                        collectionChildNodes.Add(comPtrItemTreeNode);
                                        foundCount++;
                                    }
                                }
                            }

                            try
                            {
                                // Some collections are 0 based.
                                // Application->Customization->RibbonBarThemes seems to be 0 based.
                                if (foundCount == (count - 1))
                                {
                                    returnValue = null;
                                    if (MarshalEx.Succeeded(comPtr.TryInvokeMethod("Item", new object[] { 0 }, out returnValue)))
                                    {
                                        ComPtr pItem = returnValue as ComPtr;
                                        if ((pItem != null) && (pItem.IsInvalid == false))
                                        {
                                            ComPtrItemTreeNode comPtrItemTreeNode = new ComPtrItemTreeNode((ComPtr)returnValue, comFunctionInfo);
                                            comPtrItemTreeNode.Caption = String.Format("{0}({1})", comFunctionInfo.Name, 0);
                                            comPtrItemTreeNode.Nodes.Add("...");
                                            collectionChildNodes.Insert(0, comPtrItemTreeNode);
                                        }
                                    }
                                }
                            }
                            catch
                            {
                            }
                        }
                    }
                    catch
                    {
                        GlobalExceptionHandler.HandleException();
                    }

                    childNodes.AddRange(collectionChildNodes.ToArray());
                }

                if (_showMethods)
                {
                    foreach (ComFunctionInfo comFunctionInfo in comTypeInfo.GetMethods(true))
                    {
                        if (comFunctionInfo.IsRestricted)
                        {
                            continue;
                        }

                        ComMethodTreeNode comMethodTreeNode = new ComMethodTreeNode(comFunctionInfo);
                        childNodes.Add(comMethodTreeNode);
                    }
                }
            }
            catch
            {
                GlobalExceptionHandler.HandleException();
            }

            return(childNodes.ToArray());
        }