Beispiel #1
0
        public static string ResolveCommandId(SolidEdgeFramework.Application application, int theCommandID)
        {
            ComVariableInfo variableInfo = null;

            if (_environmentConstantsMap.Count == 0)
            {
                Initialize();
            }

            try
            {
                ComEnumInfo enumInfo = null;
                SolidEdgeFramework.Environment environment = application.GetActiveEnvironment();
                Guid environmentGuid = environment.GetGuid();

                if (_environmentConstantsMap.TryGetValue(environmentGuid, out enumInfo))
                {
                    variableInfo = enumInfo.Variables.Where(x => x.ConstantValue != null).Where(x => x.ConstantValue.Equals(theCommandID)).FirstOrDefault();

                    if (variableInfo != null)
                    {
                        return(String.Format("{0} [{1}.{2}]", theCommandID, variableInfo.ComTypeInfo.Name, variableInfo.Name));
                    }
                }
            }
            catch
            {
                GlobalExceptionHandler.HandleException();
            }

            return(String.Format("{0} [Undefined]", theCommandID));
        }
Beispiel #2
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()));
        }