Esempio n. 1
0
        private void editButton_Click(object sender, EventArgs e)
        {
            ListViewItem listViewItem = lvGlobalParameters.SelectedItem;

            try
            {
                if (listViewItem != null)
                {
                    SolidEdgeFramework.ApplicationGlobalConstants globalConstant = (SolidEdgeFramework.ApplicationGlobalConstants)listViewItem.Tag;
                    Type   valueType       = listViewItem.SubItems[2].Tag as Type;
                    object globalValue     = null;
                    Type   globalValueType = null;

                    if (typeof(bool).Equals(valueType))
                    {
                        globalValue = booleanToolStripComboBox.SelectedItem;
                    }
                    else if (typeof(string).Equals(valueType))
                    {
                        globalValue = _textToolStripTextBox.Text;
                    }
                    else if (typeof(int).Equals(valueType))
                    {
                        globalValue = int.Parse(_textToolStripTextBox.Text);
                    }

                    if (globalValue != null)
                    {
                        _application.SetGlobalParameter(globalConstant, globalValue);

                        globalValueType = globalValue.GetType();

                        listViewItem.SubItems[1].Text = String.Format("{0}", globalValue);
                        listViewItem.SubItems[1].Tag  = globalValue;
                        listViewItem.SubItems[2].Text = String.Format("{0}", globalValueType);
                        listViewItem.SubItems[2].Tag  = globalValueType;
                    }
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            lvGlobalParameters.SelectedItem = listViewItem;
        }
        /// <summary>
        /// Returns the value of a specified global constant.
        /// </summary>
        /// <typeparam name="T">The type to return.</typeparam>
        public static T GetGlobalParameter <T>(this SolidEdgeFramework.Application application, SolidEdgeFramework.ApplicationGlobalConstants globalConstant)
        {
            object value = null;

            application.GetGlobalParameter(globalConstant, ref value);
            return((T)value);
        }
Esempio n. 3
0
        private void RefreshGlobalParametersListView()
        {
            if (lvGlobalParameters.Items.Count == 0)
            {
                List <ListViewItem> listViewItems = new List <ListViewItem>();
                SolidEdgeFramework.ApplicationGlobalConstants[] appGlobalConstants = GetAllApplicationGlobalConstants();

                foreach (SolidEdgeFramework.ApplicationGlobalConstants appGlobalConstant in appGlobalConstants)
                {
                    string[] itemValues =
                    {
                        appGlobalConstant.ToString(),
                        String.Empty,
                        String.Empty,
                        String.Format("SolidEdgeFramework.ApplicationGlobalConstants.{0}", appGlobalConstant.ToString())
                    };

                    itemValues[0] = itemValues[0].Replace("seApplicationGlobal", String.Empty).CamelCaseToWordString();

                    ListViewItem listViewItem = new ListViewItem(itemValues);
                    listViewItem.ImageIndex = 0;
                    listViewItem.Tag        = appGlobalConstant;
                    listViewItems.Add(listViewItem);
                }

                lvGlobalParameters.Items.AddRange(listViewItems.ToArray());
                lvGlobalParameters.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.ColumnContent);
                lvGlobalParameters.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.ColumnContent);
                lvGlobalParameters.AutoResizeColumn(3, ColumnHeaderAutoResizeStyle.ColumnContent);
            }

            try
            {
                // Register with OLE to handle concurrency issues on the current thread.
                SolidEdgeCommunity.OleMessageFilter.Register();

                if (_application == null)
                {
                    // Connect to Solid Edge.
                    _application = SolidEdgeCommunity.SolidEdgeUtils.Connect(true);

                    // Ensure Solid Edge GUI is visible.
                    _application.Visible = true;
                }

                foreach (ListViewItem listViewItem in lvGlobalParameters.Items)
                {
                    SolidEdgeFramework.ApplicationGlobalConstants appGlobalConstant = (SolidEdgeFramework.ApplicationGlobalConstants)listViewItem.Tag;

                    object globalValue     = null;
                    object globalValueType = null;

                    try
                    {
                        _application.GetGlobalParameter(appGlobalConstant, ref globalValue);
                    }
                    catch (System.Exception ex)
                    {
                        globalValue     = ex;
                        globalValueType = ex.GetType();
                    }

                    if (globalValue != null)
                    {
                        if (globalValueType == null)
                        {
                            globalValueType = globalValue.GetType();
                        }
                    }

                    listViewItem.SubItems[1].Text = String.Format("{0}", globalValue);
                    listViewItem.SubItems[1].Tag  = globalValue;
                    listViewItem.SubItems[2].Text = String.Format("{0}", globalValueType);
                    listViewItem.SubItems[2].Tag  = globalValueType;
                }

                lvGlobalParameters.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.ColumnContent);
            }
            catch
            {
#if DEBUG
                System.Diagnostics.Debugger.Break();
#endif
                throw;
            }
            finally
            {
                SolidEdgeCommunity.OleMessageFilter.Unregister();
            }
        }
Esempio n. 4
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()));
        }