Exemplo n.º 1
0
        private void buttonAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (null != dataGridHost.SelectedItem && null != dataGridMass.SelectedItem)
                {
                    ParameterInfo hostParam = (ParameterInfo)dataGridHost.SelectedItem;
                    ParameterInfo massParam = (ParameterInfo)dataGridMass.SelectedItem;

                    if (hostParam.ParamType == massParam.ParamType)
                    {
                        ParameterMapInfo mapInfo = new ParameterMapInfo(hostParam, massParam);
                        mapInfoList.Add(mapInfo);

                        DisplayParameterMapInfo();
                        DisplayParameterInfo();
                    }
                    else
                    {
                        MessageBox.Show("Parameter type does not match.\nPlease select a mass parameter of which type is same as the host parameter.", "Parameter Type Mismatch", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to add link.\n" + ex.Message, "Add Link", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        public static MassConfiguration GetMassConfiguration(Document doc, SourceType massSource)
        {
            MassConfiguration massConfig = new MassConfiguration();

            try
            {
                if (null == m_schema)
                {
                    m_schema = CreateSchema();
                }

                if (null != m_schema)
                {
                    IList <DataStorage> savedStorage = GetMassConfigurationStorage(doc, m_schema);
                    if (savedStorage.Count > 0)
                    {
                        foreach (DataStorage storage in savedStorage)
                        {
                            Entity entity       = storage.GetEntity(m_schema);
                            string hostCategory = entity.Get <string>(m_schema.GetField(s_HostCategory));
                            if (hostCategory == massSource.ToString())
                            {
                                massConfig.MassSourceType   = massSource;
                                massConfig.HostCategory     = hostCategory;
                                massConfig.MassCategory     = entity.Get <string>(m_schema.GetField(s_MassCategory));
                                massConfig.UpdateType       = (ParameterUpdateType)Enum.Parse(typeof(ParameterUpdateType), entity.Get <string>(m_schema.GetField(s_ParameterUpdateType)));
                                massConfig.UserHeight       = entity.Get <double>(m_schema.GetField(s_UserHeight), DisplayUnitType.DUT_DECIMAL_FEET);
                                massConfig.SetDefaultHeight = entity.Get <bool>(m_schema.GetField(s_SetDefaultHeight));

                                List <ParameterMapInfo> massParameters = new List <ParameterMapInfo>();
                                IList <Entity>          subEntities    = entity.Get <IList <Entity> >(m_schema.GetField(s_ParameterMaps));
                                foreach (Entity subE in subEntities)
                                {
                                    string        hostParamName = subE.Get <string>(subSchema.GetField(s_HostParameterName));
                                    ParameterInfo hostParamInfo = GetParameterInfo(doc, massConfig.HostCategory, hostParamName);

                                    string        massParamName = subE.Get <string>(subSchema.GetField(s_MassParameterName));
                                    ParameterInfo massParamInfo = GetParameterInfo(doc, massConfig.MassCategory, massParamName);

                                    if (null != hostParamInfo && null != massParamInfo)
                                    {
                                        ParameterMapInfo mapInfo = new ParameterMapInfo(hostParamInfo, massParamInfo);
                                        massParameters.Add(mapInfo);
                                    }
                                }
                                massConfig.MassParameters = massParameters;
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get mass configuration.\n" + ex.Message, "Get Mass Configuration", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(massConfig);
        }
Exemplo n.º 3
0
 private void buttonRemove_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (null != dataGridMap.SelectedItem)
         {
             ParameterMapInfo mapInfo = (ParameterMapInfo)dataGridMap.SelectedItem;
             int mapIndex             = mapInfoList.FindIndex(o => o.HostParamInfo.ParameterName == mapInfo.HostParamInfo.ParameterName &&
                                                              o.MassParamInfo.ParameterName == mapInfo.MassParamInfo.ParameterName);
             if (mapIndex > -1)
             {
                 mapInfoList.RemoveAt(mapIndex);
             }
             DisplayParameterMapInfo();
             DisplayParameterInfo();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to remove link.\n" + ex.Message, "Remove Link", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }