Esempio n. 1
0
        static bool addReferencedModel(string fileName, IfcStore fedModel, int counter, bool informUser, out bool userRespOnInfo)
        {
            userRespOnInfo = true;
            var temporaryReference = new XbimReferencedModelViewModel
            {
                Name             = fileName,
                OrganisationName = "OrganisationName " + counter,
                OrganisationRole = "Undefined"
            };

            var       buildRes  = false;
            Exception exception = null;

            try
            {
                buildRes = temporaryReference.TryBuildAndAddTo(fedModel);
            }
            catch (Exception ex)
            {
                //usually an EsentDatabaseSharingViolationException, user needs to close db first
                exception = ex;
                Console.WriteLine("%Error. Unable to open the .xbim cache file (" + fileName + "). Check source file exists or the cache file is being used or corrupted!");
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        }     //打开一个openfiledialog,并获取选择的文件名

        public static IfcStore FederationFromDialogbox(string[] files)
        {
            IfcStore fedModel = null;

            if (files == null || files.Length == 0)
            {
                return(fedModel);
            }
            else
            {
                //use the first filename it's extension to decide which action should happen
                var s = System.IO.Path.GetExtension(files[0]);
                //if (s == null) return ifcStore;
                var firstExtension = s.ToLower();
                if (firstExtension == ".ifc")
                {
                    // create temp file as a placeholder for the temporory xbim file
                    fedModel = IfcStore.Create(null, XbimSchemaVersion.Ifc2X3, XbimStoreType.InMemoryModel);
                    using (var txn = fedModel.BeginTransaction())
                    {
                        var project = fedModel.Instances.New <Xbim.Ifc2x3.Kernel.IfcProject>();
                        project.Name = "默认项目名称";
                        project.Initialize(ProjectUnits.SIUnitsUK);
                        txn.Commit();
                    }
                    var informUser = true;
                    for (var i = 0; i < files.Length; i++)
                    {
                        var fileName           = files[i];
                        var temporaryReference = new XbimReferencedModelViewModel
                        {
                            Name             = fileName,
                            OrganisationName = "机构 " + i,
                            OrganisationRole = "未定义"
                        };

                        var       buildRes  = false;
                        Exception exception = null;
                        try
                        {
                            buildRes = temporaryReference.TryBuildAndAddTo(fedModel);  //验证所有数据并创建模型。
                        }
                        catch (Exception ex)
                        {
                            //usually an EsentDatabaseSharingViolationException, user needs to close db first
                            exception = ex;
                        }

                        if (buildRes || !informUser)
                        {
                            continue;
                        }
                        var msg = exception == null ? "" : "\r\nMessage: " + exception.Message;
                        var res = MessageBox.Show(fileName + " couldn't be opened." + msg + "\r\nShow this message again?",
                                                  "Failed to open a file", MessageBoxButton.YesNoCancel, MessageBoxImage.Error);
                        if (res == MessageBoxResult.No)
                        {
                            informUser = false;
                        }
                        else if (res == MessageBoxResult.Cancel)
                        {
                            fedModel = null;
                        }
                        //return fedModel;
                    }
                }
            }
            return(fedModel);
        }