Пример #1
0
        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); }
        }
Пример #2
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);
        }