Esempio n. 1
0
 private void comboBoxRecipient_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (null != comboBoxSource.SelectedItem && null != comboBoxRecipient.SelectedItem)
     {
         ModelInfo sModelInfo = (ModelInfo)comboBoxSource.SelectedItem;
         ModelInfo rModelInfo = (ModelInfo)comboBoxRecipient.SelectedItem;
         if (sModelInfo.ModelId == rModelInfo.ModelId)
         {
             labelSameModel.Visibility = System.Windows.Visibility.Visible;
         }
         else
         {
             labelSameModel.Visibility = System.Windows.Visibility.Hidden;
             if (selectedViewType == ViewType.ThreeD)
             {
                 DisplayCameraView(sModelInfo, rModelInfo);
             }
             else
             {
                 DisplayPlanView(sModelInfo, rModelInfo, selectedViewType);
             }
             //map info will be stored in the recipient document
             viewConfig = ViewConfigDataStorageUtil.GetViewConfiguration(rModelInfo.ModelDoc);
         }
     }
 }
Esempio n. 2
0
        private void buttonConfiguration_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (null != comboBoxSource.SelectedItem && null != comboBoxRecipient.SelectedItem)
                {
                    ModelInfo sModelInfo = (ModelInfo)comboBoxSource.SelectedItem;
                    ModelInfo rModelInfo = (ModelInfo)comboBoxRecipient.SelectedItem;

                    if (sModelInfo.ModelId == rModelInfo.ModelId)
                    {
                        labelSameModel.Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        ViewConfigurationWindow configWindow = new ViewConfigurationWindow(sModelInfo, rModelInfo, viewConfig);
                        if (configWindow.ShowDialog() == true)
                        {
                            viewConfig = configWindow.ViewConfig;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to display configuration settings.\n" + ex.Message, "Configuration ", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        public static ViewConfiguration GetViewConfiguration(Document doc)
        {
            var viewConfig = new ViewConfiguration();

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

                if (null != m_schema)
                {
                    var savedStorage = GetViewConfigurationStorage(doc, m_schema);
                    if (savedStorage.Count > 0)
                    {
                        var storage = savedStorage.First();
                        var entity  = storage.GetEntity(m_schema);
                        viewConfig.ApplyWorksetVisibility = entity.Get <bool>(m_schema.GetField(s_WorksetVisibility));

                        var mapItems    = new List <MapItemInfo>();
                        var subEntities = entity.Get <IList <Entity> >(m_schema.GetField(s_MapItems));
                        foreach (var subE in subEntities)
                        {
                            var mapItem = new MapItemInfo();
                            mapItem.SourceModelId     = subE.Get <string>(subSchema.GetField(s_SourceModelId));
                            mapItem.RecipientModelId  = subE.Get <string>(subSchema.GetField(s_RecipientModelId));
                            mapItem.MapItemType       = (MapType)Enum.Parse(typeof(MapType), subE.Get <string>(subSchema.GetField(s_MapItemType)));
                            mapItem.SourceItemId      = subE.Get <int>(subSchema.GetField(s_SourceItemId));
                            mapItem.RecipientItemId   = subE.Get <int>(subSchema.GetField(s_RecipientItemId));
                            mapItem.SourceItemName    = subE.Get <string>(subSchema.GetField(s_SourceItemName));
                            mapItem.RecipientItemName = subE.Get <string>(subSchema.GetField(s_RecipientItemName));

                            mapItems.Add(mapItem);
                        }
                        viewConfig.MapItems = mapItems;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get view configuration.\n" + ex.Message, "Get View Configuration", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(viewConfig);
        }
        public ViewConfigurationWindow(ModelInfo source, ModelInfo recipient, ViewConfiguration vc)
        {
            sModelInfo = source;
            rModelInfo = recipient;
            ViewConfig = vc;

            InitializeComponent();
            labelSource.Content = sModelInfo.ModelName;
            labelTarget.Content = rModelInfo.ModelName;

            checkBoxWorkset.IsChecked = vc.ApplyWorksetVisibility;
            GetItems();
            //remove non-existing mapping items
            for (var i = ViewConfig.MapItems.Count - 1; i > -1; i--)
            {
                var mapItemInfo = ViewConfig.MapItems[i];
                if (!sourceItems.ContainsKey(mapItemInfo.SourceItemId) || !recipientItems.ContainsKey(mapItemInfo.RecipientItemId))
                {
                    ViewConfig.MapItems.RemoveAt(i);
                }
            }

            radioButtonLevel.IsChecked = true;
        }
        public static bool StoreViewConfiguration(Document doc, ViewConfiguration vc)
        {
            var stored = false;

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

                if (null != m_schema)
                {
                    var savedStorage = GetViewConfigurationStorage(doc, m_schema);
                    if (savedStorage.Count > 0)
                    {
                        using (var trans = new Transaction(doc))
                        {
                            trans.Start("Delete Storage");
                            try
                            {
                                foreach (var storage in savedStorage)
                                {
                                    doc.Delete(storage.Id);
                                }
                                trans.Commit();
                            }
                            catch (Exception ex)
                            {
                                trans.RollBack();
                                MessageBox.Show("Failed to delete data storage for mapping items.\n" + ex.Message, "Delete Data Storage", MessageBoxButton.OK, MessageBoxImage.Warning);
                            }
                        }
                    }

                    using (var trans = new Transaction(doc))
                    {
                        trans.Start("Save Storage");
                        try
                        {
                            var storage = DataStorage.Create(doc);
                            var entity  = new Entity(schemaId);
                            entity.Set <bool>(s_WorksetVisibility, vc.ApplyWorksetVisibility);

                            var subEntities = new List <Entity>();
                            foreach (var mapItemInfo in vc.MapItems)
                            {
                                var subEntity = new Entity(subSchemaId);
                                subEntity.Set <string>(s_SourceModelId, mapItemInfo.SourceModelId);
                                subEntity.Set <string>(s_RecipientModelId, mapItemInfo.RecipientModelId);
                                subEntity.Set <string>(s_MapItemType, mapItemInfo.MapItemType.ToString());
                                subEntity.Set <int>(s_SourceItemId, mapItemInfo.SourceItemId);
                                subEntity.Set <int>(s_RecipientItemId, mapItemInfo.RecipientItemId);
                                subEntity.Set <string>(s_SourceItemName, mapItemInfo.SourceItemName);
                                subEntity.Set <string>(s_RecipientItemName, mapItemInfo.RecipientItemName);
                                subEntities.Add(subEntity);
                            }

                            entity.Set <IList <Entity> >(s_MapItems, subEntities);
                            storage.SetEntity(entity);
                            trans.Commit();
                            stored = true;
                        }
                        catch (Exception ex)
                        {
                            trans.RollBack();
                            MessageBox.Show("Failed to save mapping items.\n" + ex.Message, "Store Mapping Information", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to store model Id.\n" + ex.Message, "Store Model Id", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(stored);
        }