public BlockStructureMappingPairModel(Document doc, Window mainWindow, ObservableCollection <BlockTableRecord> blocks, PartsList partsList, ObjectId defPartFam, ObjectId defPartSize, string defBlock = null) { BlockVM = new Controls.SelectBlockUserControl3.ViewModel(doc, mainWindow, blocks, defBlock); StructureVM = new SelectPartSizeViewModel(doc, partsList, PartType.StructJunction, defPartFam, defPartSize); //blockVM.SelectionChanged += FireBlockSelectionChanged;//передать информацию о том, что выбор изменен в ViewModel //structureVM.SelectionChanged += FirePartSizeSelectionChanged; }
public ConfigureNetworkCreationViewModel(Document doc, CivilDocument cdoc, Window thisWindow) { this.doc = doc; this.cdoc = cdoc; this.thisWindow = thisWindow; //команды addBlockStructureMappingPairCommand = new RelayCommand(new Action <object>(AddBlockStructureMappingPair)); selectSurfaceCommand = new RelayCommand(new Action <object>(SelectSurface)); acceptConfigsCommand = new RelayCommand(new Action <object>(AcceptConfigs)); openReferenceDocCommand = new RelayCommand(new Action <object>(OpenReferenceDoc)); openExcelSampleCommand = new RelayCommand(new Action <object>(OpenExcelSample)); createPipeNenworkCommand = new RelayCommand(new Action <object>(CreatePipeNenwork)); //Выбор слоев ObservableCollection <SelectLayerUserControl.Model> layers = SelectLayerUserControl.ViewModel.GetLayers(doc); GridLayerVM = new SelectLayerUserControl.ViewModel(doc, thisWindow, layers, defaultGridLayer); StructuresLayerVM = new SelectLayerUserControl.ViewModel(doc, thisWindow, layers, defaultStructuresLayer); StructureLabelsLayerVM = new SelectLayerUserControl.ViewModel(doc, thisWindow, layers, defaultStructureLabelsLayer); SameDepth = defaultSameDepth; RimElevationCorrection = defaultRimElevationCorrection; //combo box populate //как правильно связать выбранный элемент в combo box и заданный PartsList для SelectPartSizeViewModel (можно через события) //нужно DependencyProperty в классе SelectPartSizeView? Database db = doc.Database; PartsListCollection partListColl = cdoc.Styles.PartsListSet; PartsList startSelection = null; using (Transaction tr = db.TransactionManager.StartTransaction()) { foreach (ObjectId plId in partListColl) { //defaultPartsList PartsList pl = (PartsList)tr.GetObject(plId, OpenMode.ForRead); PartsLists.Add(pl); if (plId.Equals(defaultPartsList)) { startSelection = pl; } } tr.Commit(); } if (startSelection != null) { SelectedPartsListItem = startSelection; } //datagrid populate blocks = SelectBlockUserControl.ViewModel.GetBlocks(doc); BlocksStructuresMappingColl = new ObservableCollection <BlockStructureMappingPairModel>(); if (defaultBlockStructureTable != null) { //есть сохраненная таблица блоков using (Transaction tr = db.TransactionManager.StartTransaction()) { foreach (KeyValuePair <ObjectId, SelectedPartTypeId> kvp in defaultBlockStructureTable) { try { BlockTableRecord btr = tr.GetObject(kvp.Key, OpenMode.ForRead) as BlockTableRecord; if (btr != null) { string blockName = btr.Name; ObjectId famId = ObjectId.Null; ObjectId sizeId = ObjectId.Null; if (kvp.Value != null) { famId = kvp.Value.PartFamId; sizeId = kvp.Value.PartSizeId; } BlockStructureMappingPairModel item = new BlockStructureMappingPairModel(doc, thisWindow, blocks, SelectedPartsList, famId, sizeId, blockName); HandleDataGridItemInput(item); BlocksStructuresMappingColl.Add(item); } } catch (Exception) { BlocksStructuresMappingColl.Clear(); defaultBlockStructureTable = null;//удалить сохраненную таблицу блоков. Пусть создается 1 дефолтная строчка break; } } tr.Commit(); } } if (defaultBlockStructureTable == null) { //нет сохраненной таблицы блоков BlockStructureMappingPairModel defItem = new BlockStructureMappingPairModel(doc, thisWindow, blocks, SelectedPartsList, ObjectId.Null, ObjectId.Null) { BlockVM = new SelectBlockUserControl.ViewModel(doc, thisWindow, blocks, DEFAULT_STRUCTURE_BLOCK) }; HandleDataGridItemInput(defItem);//для каждой строки в datagrid должен добавляться обработчик событий BlocksStructuresMappingColl.Add(defItem); } ObjectId startPipeFam = ObjectId.Null; ObjectId startPipeSize = ObjectId.Null; if (defaultPipeType != null) { startPipeFam = defaultPipeType.PartFamId; startPipeSize = defaultPipeType.PartSizeId; } pipeVM = new SelectPartSizeViewModel(doc, SelectedPartsList, PartType.Pipe //| PartType.Wire | PartType.Channel | PartType.Conduit | PartType.UndefinedPartType , startPipeFam, startPipeSize); communicationDepthVM = new NumericUpDownViewModel(defaultCommunicationDepth, 0.5, 0, 100); wellDepthVM = new NumericUpDownViewModel(defaultWellDepth, 0.5, 0, 100); string initialPath = defaultExcelPath == null?Path.GetDirectoryName(doc.Name) : defaultExcelPath; excelPathVM = new FileNameInputViewModel("Excel Files|*.xls;*.xlsx;", "Укажите путь к файлу Excel") { FileName = initialPath }; communicationLayerVM = new SelectLayerUserControl .ViewModel(doc, thisWindow, layers, defaultCommunicationLayer); if (defaultTinSurface != null) { using (Transaction tr = db.TransactionManager.StartTransaction()) { try { TinSurface tinSurface = tr.GetObject(defaultTinSurface.Value, OpenMode.ForRead) as TinSurface; if (tinSurface != null) { SelectedTinSurface = tinSurface; } } catch { } tr.Commit(); } } //Подпись на события, которые оповещают о том, что пользовательские настройки изменились //(можно было использовать стандартное событие INotifyPropertyChanged вместо специально созданного SelectionChanged) BlocksStructuresMappingColl.CollectionChanged += EnableCreateNetworkBtn; BlocksStructuresMappingColl.CollectionChanged += EnableAcceptBtn; GridLayerVM.SelectionChanged += EnableCreateNetworkBtn; GridLayerVM.SelectionChanged += EnableAcceptBtn; StructuresLayerVM.SelectionChanged += EnableCreateNetworkBtn; StructuresLayerVM.SelectionChanged += EnableAcceptBtn; StructureLabelsLayerVM.SelectionChanged += EnableCreateNetworkBtn; StructureLabelsLayerVM.SelectionChanged += EnableAcceptBtn; PipeVM.SelectionChanged += EnableCreateNetworkBtn; ExcelPathVM.FileNameChanged += EnableCreateNetworkBtn; ExcelPathVM.FileNameChanged += EnableAcceptBtn; CommunicationLayerVM.SelectionChanged += EnableCreateNetworkBtn; CommunicationLayerVM.SelectionChanged += EnableAcceptBtn; OnPropertyChanged(nameof(AcceptBtnIsEnabled)); OnPropertyChanged(nameof(CreateNetworkBtnIsEnabled)); //Сохранить введенные данные в окно при любом закрытии thisWindow.Closing += SaveInput; }