public override void Calculate() { // Check values ... if (InputPorts[0].Data == null) return; // ModelInfo if (InputPorts[0].Data.GetType() != typeof(ModelInfo)) return; // Loop through all the elements _modelInfo = InputPorts[0].Data as ModelInfo; if (_modelInfo == null) return; _elements = new List<DtObject>(); if (_modelInfo.ModelType == ModelType.BimPlusModel) { // Get the corresponding model var model = _controller.BimPlusModels[Guid.Parse(_modelInfo.ModelId)]; if (model == null) return; _elements = model.Objects as List<DtObject>; } if (_elements == null) return; foreach (var elem in _elements.Where(elem => _filterListBox.Items.Contains(elem.Type) == false)) { _filterListBox.Items.Add(elem.Type); } }
private void FilterListBoxOnSelectionChanged(object sender, SelectionChangedEventArgs selectionChangedEventArgs) { // Filter for types var filteredElements = new List<DtObject>(); foreach (var type in _filterListBox.SelectedItems) { if (_elements == null) continue; filteredElements.AddRange(_elements.Where(elem => elem != null && elem.Type == type.ToString())); } // Set the ModelInfo Output var output = new ModelInfo(_modelInfo.ProjectId, _modelInfo.ModelId, filteredElements.Select(item => item.Id).ToList(), ModelType.BimPlusModel); OutputPorts[0].Data = output; }
private void WorkerOnRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs runWorkerCompletedEventArgs) { if (_elements != null) { Dispatcher.BeginInvoke((Action)delegate () { _control.LoadingGrid.Visibility = Visibility.Collapsed; _control.statusLabel.Content = "Status: " +_elements.Count+ " Elements loaded!"; }); } // Store the data in the dataController if (_elements != null) { var guid = Guid.NewGuid(); _model = new DtoModel {Objects = _elements.ToList()}; _controller.BimPlusModels.Add(guid, _model); var output = new ModelInfo(projectId.ToString(), guid.ToString(), _elements.Select(item => item.Id).ToList(), ModelType.BimPlusModel); OutputPorts[0].Data = output; } }
private List<TriangleMesh> CreateTriangleMeshes(ModelInfo modelInfo) { var elements1 = modelInfo.GetCurrentElements(); var resList = new List<TriangleMesh>(); foreach (var item in elements1) { var jObject = item.AttributeGroups["geometry"]["threejs"] as JObject; if (jObject == null) continue; // var vertices = jObject.SelectToken("vertices").ToList().Select(value => value.Value<double>()).ToArray(); // Transformation var vertices = jObject.SelectToken("vertices").ToList().Select(value => value.Value<double>()).ToArray(); var indices = jObject.SelectToken("faces").ToList().Select(value => value.Value<int>()).ToArray(); // var faceSet = new IndexedFaceSet(item.Id.ToString(), indices, vertices); var faceSet = new IndexedFaceSet(item.Id.ToString(), indices, vertices); resList.Add(faceSet.CreateMesh()); } return resList; }
/// <summary> /// OnElementMouseDown: Click Event for each geometric element /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <param name="watch3DNode"></param> private void OnElementMouseDown(object sender, MouseButtonEventArgs e, Watch3DNode watch3DNode) { // 1-CLick event if (e.LeftButton != MouseButtonState.Pressed) return; // Get sender var element = sender as ModelUIElement3D; var geometryModel3D = element?.Model as GeometryModel3D; if (geometryModel3D == null) return; // Check Type // If it is already selected ... Deselect if (SelectedModels.Contains(geometryModel3D)) { // var geo = geometryModel3D.Clone(); // geo.Material = geometryModel3D.BackMaterial; geometryModel3D.Material = geometryModel3D.BackMaterial; SelectedModels.Remove(geometryModel3D); } // If not ... Select! else { SelectedModels.Add(geometryModel3D); // var geo = geometryModel3D.Clone(); // geo.Material = _selectionMaterial; geometryModel3D.Material = _selectionMaterial; } // Get the id of the selected model var reslist = new List<Guid>(); if (SelectedModels != null && SelectedModels.Count > 0) { foreach (var item in _fallBackGeometry) { foreach (var item_2 in SelectedModels) { if (Equals(item_2.Geometry, item.Model3D.Geometry)) reslist.Add(item.Id); } } } string modelId = null; string projectId = null; if (InputPorts[0].Data.GetType() == typeof(ModelInfo)) { var input = InputPorts[0].Data as ModelInfo; if (input != null) { modelId = input.ModelId; projectId = input.ProjectId; } } else if (InputPorts[0].Data.GetType() == typeof(BaseRelation)) { var input = InputPorts[0].Data as BaseRelation; if (input != null) { modelId = input.ModelId.ToString(); projectId = input.ProjectId.ToString(); } } else { return; } var res = new ModelInfo(projectId, modelId, reslist, ModelType.BimPlusModel); OutputPorts[0].Data = res; // Set selected models to Output ... e.Handled = true; }
private void WorkerOnDoWork(object sender, DoWorkEventArgs doWorkEventArgs) { if (InputPorts[0].Data == null) return; Dispatcher.BeginInvoke((Action)delegate () { ProgressBar.Visibility = Visibility.Visible; ProgressLabel.Visibility = Visibility.Visible; }); if (InputPorts[0].Data.GetType() == typeof(ModelInfo)) { modelInfo = InputPorts[0].Data as ModelInfo; if (modelInfo != null && modelInfo.ModelType == ModelType.BimPlusModel) { // Get the corresponding model var model = _controller.BimPlusModels[Guid.Parse(modelInfo.ModelId)]; if (model == null) return; var list = model.Objects.Where(item => modelInfo.ElementIds.Contains(item.Id)).ToList(); doWorkEventArgs.Result = VisualizeBimPlusDataAsGenericElements(list, sender); } } else if (InputPorts[0].Data.GetType() == typeof(List<DtObject>)) { doWorkEventArgs.Result = VisualizeBimPlusDataAsGenericElements(InputPorts[0].Data as List<DtObject>, sender); } else if (InputPorts[0].Data.GetType() == typeof(List<DbGeometry>)) { // .Result = VisualizeBimPlusData(InputPorts[0].Data as List<GenericElement>, sender); } else if (InputPorts[0].Data.GetType() == typeof(Relation)) { var input = InputPorts[0].Data as Relation; if (input == null) return; // Get Model var model = _controller.BimPlusModels[input.ModelId]; // To be visualized elements var visElements1 = new List<DtObject>(); var visElements2 = new List<DtObject>(); // var visElements3 = new List<DtObject>(); // ID Lists from the relation var listGuids1 = new List<Guid>(); var listGuids2 = new List<Guid>(); var collection = input.Collection as ObservableCollection<Tuple<Guid, Guid>>; if (collection != null) foreach (var item in collection) { listGuids1.Add(item.Item1); listGuids2.Add(item.Item2); } // Setup the visualizing element list foreach (var elem in model.Objects) { if (listGuids1.Contains(elem.Id)) { if(!visElements1.Contains(elem)) visElements1.Add(elem); } if (listGuids2.Contains(elem.Id)) { if (!visElements2.Contains(elem)) visElements2.Add(elem); } // else // { // visElements3.Add(elem); // } } var list = new List<MeshIdandGeometry>(); list.AddRange(VisualizeBimPlusDataAsGenericElements(visElements1, sender, Colors.Red, 0.6)); list.AddRange(VisualizeBimPlusDataAsGenericElements(visElements2, sender, Colors.Blue, 0.6)); // list.AddRange(VisualizeBimPlusDataAsGenericElements(visElements3, sender, default(Color), 0.95)); doWorkEventArgs.Result = list; } else if (InputPorts[0].Data.GetType() == typeof(Relation3)) { var input = InputPorts[0].Data as Relation3; if (input == null) return; // Get Model var model = _controller.BimPlusModels[input.ModelId]; // To be visualized elements var visElements1 = new List<DtObject>(); var visElements2 = new List<DtObject>(); var visElements3 = new List<DtObject>(); // ID Lists from the relation var listGuids1 = new List<Guid>(); var listGuids2 = new List<Guid>(); var listGuids3 = new List<Guid>(); var collection = input.Collection as ObservableCollection<Tuple<Guid, Guid, Guid>>; if (collection != null) foreach (var item in collection) { listGuids1.Add(item.Item1); listGuids2.Add(item.Item2); listGuids3.Add(item.Item3); } // Setup the visualizing element list foreach (var elem in model.Objects) { if (listGuids1.Contains(elem.Id)) { if (!visElements1.Contains(elem)) visElements1.Add(elem); } if (listGuids2.Contains(elem.Id)) { if (!visElements2.Contains(elem)) visElements2.Add(elem); } if (listGuids3.Contains(elem.Id)) { if (!visElements3.Contains(elem)) visElements3.Add(elem); } } var list = new List<MeshIdandGeometry>(); list.AddRange(VisualizeBimPlusDataAsGenericElements(visElements1, sender, Colors.Red, 0.6)); list.AddRange(VisualizeBimPlusDataAsGenericElements(visElements2, sender, Colors.Blue, 0.6)); list.AddRange(VisualizeBimPlusDataAsGenericElements(visElements3, sender, Colors.BlueViolet, 0.6)); doWorkEventArgs.Result = list; } else { var s = InputPorts[0].Data as string; if (s != null) doWorkEventArgs.Result = ReadFileData(s); } }