コード例 #1
0
 /// <summary>
 /// Returns a table of duplicate úsages of IfcGUIDs by model source, index label and EXPRESS type.
 /// </summary>
 /// <returns>A matrix of rows holding (IfcGUID, filename, label index and entity type)</returns>
 public object[][] ToDataOfDuplicateUsage()
 {
     return(GuidStore
            .Where(g => g.Value.Count > 1)
            .SelectMany(g => g.Value.Select(v => new object[] { g.Key, IfcModel.GetFilePathName(v.Qualifier), v.InstanceHandle.EntityLabel, v.InstanceHandle.EntityExpressType.ExpressName }))
            .ToArray());
 }
コード例 #2
0
        /// <summary>
        /// Background Worker
        ///
        /// Create xBIM File and Add it to the new DataController.
        /// The xBIM File is therefor stored in a Database
        ///
        /// The ModelId (FilePath) and the ElementList are stored in the ModelInfo Class
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">Value File is the FilePath</param>
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            var filePath = e.Argument.ToString();

            var model = new IfcModel(ModelTypes.IFC, filePath);

            using (model.xModel = IfcStore.Open(filePath))
            {
                // Create context
                model.xModelContext = new Xbim3DModelContext(model.xModel);
                model.xModelContext.CreateContext();

                modelInfo = new ModelInfo();
                foreach (var item in model.xModel.Instances.OfType <IIfcProduct>())
                {
                    modelInfo.elementIds.Add(item.GlobalId.ToString());
                }
                e.Result = modelInfo;
            }

            modelInfo.modelId = model.id.ToString();
            modelController.AddModel(model);
            model.xModel.Close();

            e.Result = model;
        }
コード例 #3
0
        public List <ModelUIElement3D> CreateModelUiElementsDs(IfcModel model, List <IfcGloballyUniqueId> elementIdsList, bool visualizeUnselectedElementsTransparent = true, DiffuseMaterial overrideMaterial = null)
        {
            tempMaterialLibrary = new Dictionary <string, DiffuseMaterial>();
            // Refresh the selected Models
            SelectedModels   = new Dictionary <string, GeometryModel3D>();
            VisualizedModels = new Dictionary <string, ModelUIElement3D>();

            xModel  = model.GetModel();
            context = model.GetModelContext();

            // Loop through Entities and visualze them in the viewport
            var res = new HashSet <IfcGloballyUniqueId>(elementIdsList);

            var elementList = new List <ModelUIElement3D>();

            // GET GEOREFERENCING
            var wcsTransformation = new XbimMatrix3D();
            var myIfcSite         = xModel.Instances.OfType <Xbim.Ifc2x3.ProductExtension.IfcSite>();
            var ifcSites          = myIfcSite as IList <Xbim.Ifc2x3.ProductExtension.IfcSite> ?? myIfcSite.ToList();

            if (ifcSites.Count == 1)
            {
                Xbim.Ifc2x3.ProductExtension.IfcSite mySite = ifcSites.First();
                IfcLocalPlacement relplacement = mySite.ObjectPlacement.ReferencedByPlacements.First();
                wcsTransformation = relplacement.ToMatrix3D();
            }

            foreach (var item in xModel.Instances.OfType <IIfcProduct>())
            {
                if (visualizeUnselectedElementsTransparent == false)
                {
                    if (!res.Contains(item.GlobalId))
                    {
                        continue;
                    }
                }
                // Get the Material
                var mat = new DiffuseMaterial();
                if (overrideMaterial == null)
                {
                    mat = res.Contains(item.GlobalId)
                        ? GeometryHandler.GetStyleFromXbimModel(item, context)
                        : GeometryHandler.GetStyleFromXbimModel(item, context, 0.03);
                }
                else
                {
                    mat = overrideMaterial;
                }

                var m = GeometryHandler.WriteTriangles(item, context, wcsTransformation);
                tempMaterialLibrary.Add(item.GlobalId, mat);
                var element = CreateModelUIElement3D(m, mat);
                element.MouseDown += ElementOnMouseDown;
                elementList.Add(element);
                VisualizedModels.Add(item.GlobalId, element);
            }
            return(elementList);
        }
コード例 #4
0
        public void VisualizeWithWorker(IfcModel model, List <IfcGloballyUniqueId> elementIdsList)
        {
            this.model          = model;
            this.elementIdsList = elementIdsList;
            _worker             = new BackgroundWorker();
            _worker.DoWork     += new DoWorkEventHandler(worker_DoWork);
            // _worker.RunWorkerAsync(file);
            _worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);

            _worker.RunWorkerAsync(10000);
        }
コード例 #5
0
        internal IfcValidationTask(IfcModel ifcModel, Func <IfcValidationTask, IfcValidationResult> taskDelegate)
        {
            if (null == ifcModel)
            {
                throw new ArgumentNullException(nameof(ifcModel));
            }
            if (null == taskDelegate)
            {
                throw new ArgumentNullException(nameof(taskDelegate));
            }

            OnIfcModel   = ifcModel;
            TaskDelegate = taskDelegate;
        }
コード例 #6
0
        /// <summary>
        /// Ingest a complete IFC model by querying it's IfcRoots GUID attributes.
        /// </summary>
        /// <param name="ifcModel">The IFC model</param>
        /// <returns>The modified store</returns>
        public IfcGuidStore Ingest(IfcModel ifcModel)
        {
            var innerModel = ifcModel.XbimModel;

            if (null == innerModel)
            {
                throw new ArgumentNullException(nameof(ifcModel));
            }

            foreach (var instance in innerModel.Instances.OfType <IIfcRoot>())
            {
                Put(ifcModel.Qualifier, instance);
            }

            return(this);
        }
コード例 #7
0
        public static IfcValidationTask NewIfcGuidCheckingTask(IfcGuidStore guidStore, IfcModel ifcModel)
        {
            if (null == ifcModel)
            {
                throw new ArgumentNullException(nameof(ifcModel));
            }
            if (null == guidStore)
            {
                throw new ArgumentNullException(nameof(guidStore));
            }

            return(new IfcValidationTask(ifcModel, (t) =>
            {
                var innerModel = ifcModel.XbimModel;
                if (null == innerModel)
                {
                    throw new NotSupportedException("No internal model available");
                }

                var monitor = t.CreateProgressMonitor(LogReason.Checked);
                monitor.NotifyProgressEstimateUpdate(innerModel.Instances.Count / 50);

                List <IfcValidationMessage> failingMessages = new List <IfcValidationMessage>();
                foreach (var instance in innerModel.Instances.OfType <IIfcRoot>())
                {
                    var message = guidStore.Put(ifcModel.Qualifier, instance);

                    if (monitor.State.Done > 0.90 * monitor.State.TotalEstimate)
                    {
                        monitor.NotifyProgressEstimateUpdate((long)Math.Floor(monitor.State.TotalEstimate * 1.25));
                    }

                    monitor.NotifyOnProgressChange(1, "Checking unique IfcGUID values...");

                    failingMessages.Add(message);
                    if (monitor.State.IsCanceled)
                    {
                        break;
                    }
                }

                monitor.NotifyOnProgressEnd();

                return new IfcGuidCheckResult(guidStore)
                {
                    MessagePipe = failingMessages
                };
            }));
        }
コード例 #8
0
 internal ComponentSceneBuild(IfcModel ifcModel, ILoggerFactory loggerFactory)
 {
     Exporter = new ComponentModelExporter(new XbimTesselationContext(loggerFactory), loggerFactory);
     IfcModel = ifcModel;
 }
コード例 #9
0
        public static IfcModel BySourceAndTransform(IfcModel source, IfcTransform transform, string nameAddon, object objFilterMask)
        {
            if (null == source)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (null == transform)
            {
                throw new ArgumentNullException(nameof(transform));
            }

            if (null == nameAddon)
            {
                nameAddon = transform.Mark;
            }

            LogReason filterMask = DynamicArgumentDelegation.TryCastEnumOrDefault(objFilterMask, LogReason.Any);

            if (null == transform.CancellationSource)
            {
                transform.CancellationSource = new CancellationTokenSource();
            }

            return(IfcStore.ByTransform(source, (model, node) =>
            {
                log.LogInformation("Starting '{1}' ({0}) on {2} ...", node.GetHashCode(), transform.transformDelegate.Name, node.Name);
                try
                {
                    using (var task = transform.transformDelegate.Run(model, node.CreateProgressMonitor(LogReason.Transformed)))
                    {
                        task.Wait(transform.TimeOutMillis, transform.CancellationSource.Token);

                        log.LogInformation("Finalized '{1}' ({0}) on {2}.", node.GetHashCode(), transform.transformDelegate.Name, node.Name);

                        if (task.IsCompleted)
                        {
                            if (node is ProgressingTask np)
                            {
                                np.OnProgressEnded(LogReason.Changed, false);
                            }

                            using (var result = task.Result)
                            {
                                switch (result.ResultCode)
                                {
                                case TransformResult.Code.Finished:
                                    var name = $"{transform.transformDelegate.Name}({node.Name})";
                                    node.OnActionLogged(TransformLogToMessage(name, result.Log, filterMask).ToArray());
                                    return result.Target;

                                case TransformResult.Code.Canceled:
                                    node.OnActionLogged(LogMessage.BySeverityAndMessage(
                                                            node.Name, LogSeverity.Error, LogReason.Any, "Canceled by user request ({0}).", node.Name));
                                    break;

                                case TransformResult.Code.ExitWithError:
                                    node.OnActionLogged(LogMessage.BySeverityAndMessage(
                                                            node.Name, LogSeverity.Error, LogReason.Any, "Caught error ({0}): {1}", node.Name, result.Cause));
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (node is ProgressingTask np)
                            {
                                np.OnProgressEnded(LogReason.Changed, true);
                            }

                            node.OnActionLogged(LogMessage.BySeverityAndMessage(
                                                    node.Name, LogSeverity.Error, LogReason.Changed, $"Task incompletely terminated (Status {task.Status})."));
                        }
                        return null;
                    }
                }
                catch (Exception thrownOnExec)
                {
                    log.LogError("{0} '{1}'\n{2}", thrownOnExec, thrownOnExec.Message, thrownOnExec.StackTrace);
                    throw new Exception("Exception while executing task");
                }
            }, nameAddon));
        }
コード例 #10
0
        public override void Calculate()
        {
            ifcViewerControl.InitViewPort();

            if (InputPorts[0].Data == null)
            {
                return;
            }

            if (InputPorts[0].Data.GetType() == typeof(ModelInfo))
            {
                var modelInfo = InputPorts[0].Data as ModelInfo;
                if (modelInfo == null)
                {
                    return;
                }

                model = _controller.GetModel(modelInfo.modelId) as IfcModel;
                if (model == null)
                {
                    return;
                }

                var idList = new List <IfcGloballyUniqueId>();
                foreach (var id in modelInfo.elementIds)
                {
                    var guid = new Guid();
                    if (Guid.TryParse(id, out guid))
                    {
                        idList.Add(IfcGuid.ToIfcGuid(Guid.Parse(id)));
                    }
                    else
                    {
                        idList.Add(new IfcGloballyUniqueId(id));
                    }
                }

                ifcViewerControl.Visualize(ifcViewerControl.CreateModelUiElementsDs(model, idList));
            }
            else if (InputPorts[0].Data.GetType() == typeof(ModelInfo))
            {
                var modelInfo = InputPorts[0].Data as ModelInfo;
                if (modelInfo == null)
                {
                    return;
                }

                model = ModelController.Instance.GetModel(modelInfo.modelId) as IfcModel;

                if (model == null)
                {
                    return;
                }

                var idList = new List <IfcGloballyUniqueId>();

                foreach (var id in modelInfo.elementIds)
                {
                    idList.Add(new IfcGloballyUniqueId(id));
                }

                ifcViewerControl.Visualize(ifcViewerControl.CreateModelUiElementsDs(model, idList));
            }

            else if (InputPorts[0].Data.GetType() == typeof(Relation))
            {
                var relation = InputPorts[0].Data as Relation;

                if (relation == null)
                {
                    return;
                }
                var elements1 = new List <IfcGloballyUniqueId>();
                var elements2 = new List <IfcGloballyUniqueId>();
                foreach (var item in relation.Collection)
                {
                    var item_Tuple = item as Tuple <Guid, Guid>;
                    elements1.Add(IfcGuid.ToIfcGuid(item_Tuple.Item1));
                    elements2.Add(IfcGuid.ToIfcGuid(item_Tuple.Item2));
                }

                var material1 = new DiffuseMaterial {
                    Brush = new SolidColorBrush(Colors.Blue)
                    {
                        Opacity = 0.3
                    }
                };

                var material2 = new DiffuseMaterial {
                    Brush = new SolidColorBrush(Colors.Red)
                    {
                        Opacity = 0.3
                    }
                };

                // Get the model
                model = ModelController.Instance.GetModel(relation.ModelId.ToString()) as IfcModel;
                ifcViewerControl.Visualize(ifcViewerControl.CreateModelUiElementsDs(model, elements1, false, material1));
                ifcViewerControl.Visualize(ifcViewerControl.CreateModelUiElementsDs(model, elements2, false, material2), false);
            }

            ifcViewerControl.Viewport3D.ZoomExtents();
        }