public int Select(string[] guids /*,out string[] notFindedGuid*/) { try { var _notFindedGuid = new List <string>(); try { if (Model != null) { //if (guids.Length ==1) { Xbim.Presentation.EntitySelection sel = new Xbim.Presentation.EntitySelection(false); var project = Model.Instances.FirstOrDefault <IIfcProject>(); if (project is Xbim.Ifc2x3.Kernel.IfcProject) { var globalIds = guids.Select(g => new Xbim.Ifc2x3.UtilityResource.IfcGloballyUniqueId(g)).ToList(); var selected = Model.Instances.OfType <Xbim.Ifc2x3.Interfaces.IIfcRoot>().Join(globalIds, a => a.GlobalId, b => b, (a, b) => a).ToArray(); _notFindedGuid = guids.Except(selected.Select(x => x.GlobalId.Value.ToString())).ToList(); sel.AddRange(selected); } else if (project is Xbim.Ifc4.Kernel.IfcProject) { var globalIds = guids.Select(g => new Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId(g)).ToList(); var selected = Model.Instances.OfType <Xbim.Ifc4.Interfaces.IIfcRoot>().Join(globalIds, a => a.GlobalId, b => b, (a, b) => a).ToArray(); // selected[0].ExpressType.Type _notFindedGuid = guids.Except(selected.Select(x => x.GlobalId.Value.ToString())).ToList(); sel.AddRange(selected); } else { throw new Exception("Undefined project"); } if (!_notFindedGuid.Any()) { Canvas.SetSelection(sel); } else { return(1); } //DrawingControl.ReloadModel(Xbim.Presentation.DrawingControl3D.ModelRefreshOptions.ViewPreserveCameraPosition); //DrawingControl.ReloadModel(); return(0); } } } catch (Exception ex) { log(ex.ToString()); } // if some errors occurs return 1; return(1); //notFindedGuid = _notFindedGuid.ToArray(); // TODO: comment for the first time } catch { return(1); } }
public int SelectTheSame(string guid) { try { log("Model: " + (Model != null)); if (Model != null) { IPersistEntity selected = null; Xbim.Presentation.EntitySelection sel = new Xbim.Presentation.EntitySelection(false); var project = Model.Instances.FirstOrDefault <IIfcProject>(); if (project is Xbim.Ifc2x3.Kernel.IfcProject) { var globalIds = new Xbim.Ifc2x3.UtilityResource.IfcGloballyUniqueId(guid); selected = Model.Instances.OfType <Xbim.Ifc2x3.Interfaces.IIfcRoot>().FirstOrDefault(a => a.GlobalId == globalIds); } else if (project is Xbim.Ifc4.Kernel.IfcProject) { var globalIds = new Xbim.Ifc4.UtilityResource.IfcGloballyUniqueId(guid); selected = Model.Instances.OfType <Xbim.Ifc4.Interfaces.IIfcRoot>().FirstOrDefault(a => a.GlobalId == globalIds); } else { throw new Exception("Undefined project"); } //System.Timers.Timer t = new System.Timers.Timer(); //t.Start(); if (selected != null) { var test = getExpressType(Model); selectTheSameElements(selected, test); log("Set selection"); } else { return(1); } //t.Stop(); //Console.WriteLine( t.Interval.ToString()); log("return 0"); return(0); } } catch (Exception ex) { log("Не удалось выделить " + ex.ToString()); } log("SelectTheSame return 0"); return(0); }
Xbim.Presentation.EntitySelection getTheSameElements(IPersistEntity selectedItem, HashSet <ExpressType> types) { Xbim.Presentation.EntitySelection sel = new Xbim.Presentation.EntitySelection(false); var obType = getPropertyValue(selectedItem, types); if (0 != obType) { // get all objects with the same objectType var project = Model.Instances.FirstOrDefault <IIfcProject>(); if (project is Xbim.Ifc2x3.Kernel.IfcProject) { var selected = new List <Xbim.Ifc2x3.Interfaces.IIfcRoot>(); foreach (var item in Model.Instances.OfType <Xbim.Ifc2x3.Interfaces.IIfcRoot>()) { if (getPropertyValue(item, types, obType)) { selected.Add(item); } } if (selected.Any()) { sel.AddRange(selected); } } else if (project is Xbim.Ifc4.Kernel.IfcProject) { var selected = Model.Instances.OfType <Xbim.Ifc4.Interfaces.IIfcRoot>() .Where(x => getPropertyValue(x, types, obType) ).ToList(); if (selected != null) { sel.AddRange(selected); } } else { throw new Exception("Undefined project"); } } return(sel); }