예제 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter IFC File Name: ");
            string filename = "Resources/sample.ifc"; //Console.ReadLine();

            BSConfig.Register();
            var client = BrightstarService.GetClient(BSConfig.ConnectionString());
            if(client.ListStores().Any(x => x == "ifcRDF"))
            {
                client.DeleteStore("ifcRDF");
            }
            client.CreateStore("ifcRDF");
            BrightstarService.Shutdown();

            var ctx = new Ifc2x3Context(BSConfig.ConnectionString("ifcRDF"));
            var model = new XbimModel();

            if(OpenIfcFile(model, filename))
            {
                ctx.ConvertToRDF(model);
                ctx.SaveChanges();
            }

            PrintOut(BSConfig.ConnectionString("ifcRDF"));

            Console.ReadKey();

        }
예제 #2
0
 public XbimModelHandler(String ModelPath)
 {
     model = new XbimModel();
     model.Open(ModelPath, XbimExtensions.XbimDBAccess.Read);
     //setup a type map
     Init();
 }
예제 #3
0
 /// <summary>
 ///     Builds a placement tree of all ifcLocalPlacements
 /// </summary>
 /// <param name="model"></param>
 /// <param name="adjustWcs">
 ///     If there is a single root displacement, this is removed from the tree and added to the World
 ///     Coordinate System. Useful for models where the site has been located into a geographical context
 /// </param>
 public XbimPlacementTree(XbimModel model, bool adjustWcs = true)
 {
     var rootNodes = new List<XbimPlacementNode>();
     var localPlacements = model.InstancesLocal.OfType<IfcLocalPlacement>(true).ToList();
     Nodes = new Dictionary<int, XbimPlacementNode>();
     foreach (var placement in localPlacements)
         Nodes.Add(placement.EntityLabel, new XbimPlacementNode(placement));
     foreach (var localPlacement in localPlacements)
     {
         if (localPlacement.PlacementRelTo != null) //resolve parent
         {
             var xbimPlacement = Nodes[localPlacement.EntityLabel];
             var xbimPlacementParent = Nodes[localPlacement.PlacementRelTo.EntityLabel];
             xbimPlacement.Parent = xbimPlacementParent;
             xbimPlacementParent.Children.Add(xbimPlacement);
         }
         else
             rootNodes.Add(Nodes[localPlacement.EntityLabel]);
     }
     if (adjustWcs && rootNodes.Count == 1)
     {
         var root = rootNodes[0];
         WorldCoordinateSystem = root.Matrix;
         //make the children parentless
         foreach (var node in Nodes.Values.Where(node => node.Parent == root)) node.Parent = null;
         root.Matrix = new XbimMatrix3D(); //set the matrix to identity
     }
     //muliply out the matrices
     foreach (var node in Nodes.Values) node.ToGlobalMatrix();
 }
예제 #4
0
        public void CopyAllEntitiesTest()
        {
            using (var source = new XbimModel())
            {
                PropertyTranformDelegate propTransform = delegate(IfcMetaProperty prop, object toCopy)
                {              
                    var value = prop.PropertyInfo.GetValue(toCopy, null);
                    return value;
                };



                source.Open("BIM Logo-LetterM.xBIM");
                source.SaveAs("WithGeometry.ifc");
                using (var target = XbimModel.CreateTemporaryModel())
                {
                    target.AutoAddOwnerHistory = false;
                    using (var txn = target.BeginTransaction())
                    {
                        var copied = new XbimInstanceHandleMap(source, target);

                        foreach (var item in source.Instances)
                        {
                            target.InsertCopy(item, copied, txn, propTransform);
                        }
                        txn.Commit();
                    }
                    target.SaveAs("WithoutGeometry.ifc");
                }
                source.Close();
                //the two files should be the same
            }
        }
예제 #5
0
 public void ConvertCoBieLiteToJson()
 {
     using (var m = new XbimModel())
     {
         var IfcTestFile = "2012-03-23-Duplex-Handover.ifc";
         //IfcTestFile = @"D:\Users\steve\My Documents\DPoW\001 NBS Lakeside Restaurant 2014.ifc";
         var XbimTestFile = Path.ChangeExtension(IfcTestFile, "xbim");
         var JsonFile = Path.ChangeExtension(IfcTestFile, "json");
         m.CreateFrom(IfcTestFile, XbimTestFile, null, true, true);
         var helper = new CoBieLiteHelper(m,"UniClass");
         var facilities = helper.GetFacilities();
         foreach (var facilityType in facilities)
         {
             Assert.IsTrue(facilityType.FacilityDefaultLinearUnitSpecified);
             Assert.IsTrue(facilityType.FacilityDefaultAreaUnitSpecified);
             Assert.IsTrue(facilityType.FacilityDefaultVolumeUnitSpecified);
             using (var fs = new StreamWriter(JsonFile))
             {
                 CoBieLiteHelper.WriteJson(fs, facilityType);
                 fs.Close();
             }
             
         }
     }
 }
 public static Facility FacilityFromModel(XbimModel model)
 {
     var facilities = new List<Facility>();
     var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(model, facilities);
     facilities = ifcToCoBieLiteUkExchanger.Convert();
     return facilities.FirstOrDefault();
 }
예제 #7
0
        public Int32 StartComparison(XbimModel baseline, XbimModel revision, string filter = "")
        {
            Baseline = baseline;
            Revision = revision;

            Int32 ret = 0;
            if (filter == "")
            {
                // default behaviour (maintained during code review) is to test only for IfcProducts
                //
                WorkingCopyBaseline = new List<IfcRoot>(Baseline.Instances.OfType<IfcProduct>().Cast<IfcRoot>());
                WorkingCopyDelta = new List<IfcRoot>(Revision.Instances.OfType<IfcProduct>().Cast<IfcRoot>());
                ret += StartProductsComparison();
            }
            else
            {
                IfcType ot = IfcMetaData.IfcType(filter.ToUpper());
                if (ot != null)
                {
                    if (ot.Type.IsSubclassOf(typeof(IfcRoot)))
                    {
                        WorkingCopyBaseline = new List<IfcRoot>(Baseline.Instances.OfType(filter, false).Cast<IfcRoot>());
                        WorkingCopyDelta = new List<IfcRoot>(Revision.Instances.OfType(filter, false).Cast<IfcRoot>());
                        ret += StartProductsComparison();
                    }
                }
            }
            return ret;
        }
        public void ExtrudedCircularProfilesTest()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();
            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\15 - Swept pipes.ifc", null, null, true, true);
                    foreach (
                        var cp in
                            m.Instances.OfType<IfcExtrudedAreaSolid>().Where(e => e.SweptArea is IfcCircleProfileDef))
                    {
                        Assert.IsTrue(cp != null, "No Extruded Solid found");
                        Assert.IsTrue(cp.SweptArea is IfcCircleProfileDef, "Incorrect profiledef found");

                        var solid = xbimGeometryCreator.CreateSolid(cp);
                        Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                        IfcCsgTests.GeneralTest(solid);

                    }

                    //Assert.IsTrue(solid.Faces.Count() == 10, "T Shaped profiles should have 10 faces");
                }
            }
        }
예제 #9
0
 public void Importing_From_Missing_Folder_Throws_DirectoryNotFoundException()
 {
     using (XbimModel modelServer = new XbimModel())
     {
         modelServer.CreateFrom("/BadPath/DoesNotExist.ifc");
     }
 }
예제 #10
0
 public void Importing_Missing_File_Throws_FileNotFoundException()
 {
     using (XbimModel modelServer = new XbimModel())
     {
         modelServer.CreateFrom("DoesNotExist.ifc");
     }
 }
        //public ContainedElementsViewModel(IfcSpatialStructureElement container)
        //{
        //    xbimModel = container.ModelOf as XbimModel;
        //    IEnumerable subs = this.Children; //call this once to preload first level of hierarchy          
        //}

        public ContainedElementsViewModel(IfcSpatialStructureElement spatialElem, Type type, IXbimViewModel parent)
        {
            this.spatialContainerLabel = spatialElem.EntityLabel;
            this.type = type;
            this.xbimModel = (XbimModel) spatialElem.ModelOf;
            this.CreatingParent = parent;
        }
예제 #12
0
        public void EscapeHeaderTests()
        {
            const string path = @"x:\path1\path2\filename.ifc";
            const string umlaut = "name with umlaut ü";
            using (var model = XbimModel.CreateTemporaryModel())
            {

                model.Initialise("Creating Author", " Creating Organisation", "This Application", "This Developer", "v1.1");
                using (var txn = model.BeginTransaction())
                {
                    model.IfcProject.Name = "Project Name";
                    txn.Commit();
                }

                model.Header.FileName.Name = path;
                model.Header.FileName.Organization.Add(umlaut); 
                model.SaveAs("testOutput.ifc");
            }
            using (var model = new XbimModel())
            {
                model.CreateFrom("testOutput.ifc", null, null, true);
                Assert.IsTrue(model.Header.FileName.Name == path);
                Assert.IsTrue(model.Header.FileName.Organization.FirstOrDefault() == umlaut);
                model.Close();
            }
        }
예제 #13
0
 public SpatialViewModel(IfcSpatialStructureElement spatialStructure, IXbimViewModel parent)
 {
     xbimModel = spatialStructure.ModelOf as XbimModel;
     this.spatialStructureLabel = Math.Abs(spatialStructure.EntityLabel);
     CreatingParent = parent;
     IEnumerable subs = this.Children; //call this once to preload first level of hierarchy   
 }
예제 #14
0
 public static IfcAxis1Placement MakeAxis1Placement(XbimModel m)
 {
     var p = m.Instances.New<IfcAxis1Placement>();
     p.Axis = m.Instances.New<IfcDirection>(d => d.SetXYZ(1, 0, 0));
     p.Location = m.Instances.New<IfcCartesianPoint>(c => c.SetXYZ(0, 0, 0));
     return p;
 }
예제 #15
0
 public static IfcArbitraryOpenProfileDef MakeArbitraryOpenProfileDef(XbimModel m, IfcBoundedCurve curve)
 {
     var def = m.Instances.New<IfcArbitraryOpenProfileDef>();
     def.Curve = curve;
     def.ProfileType=IfcProfileTypeEnum.CURVE;
     return def;
 }
예제 #16
0
 public XbimModelViewModel(IfcProject project, IXbimViewModel parent)
 {
     xbimModel = project.ModelOf as XbimModel;
     _project = project;
     this.CreatingParent = parent;
     IEnumerable subs = this.Children; //call this once to preload first level of hierarchy   
 }
예제 #17
0
 public COBieXBimEditScope(XbimModel model, IfcOwnerHistory owner)
 {
     Model = model;
     ifcOwnerHistory = Model.OwnerHistoryAddObject;
     Model.OwnerHistoryAddObject = owner;
     
 }
        private void CreateParser(XbimModel model = null)
        {
            if (model != null) _parser = new XbimQueryParser(model);
            else _parser = new XbimQueryParser();

            _parser.Output = _output;
            _parser.OnScriptParsed += delegate
            {
                //fire the event
                ScriptParsed();

                //show output in the output window
                OutputWindow.Text = _output.ToString();
                (OutputWindow.Parent as ScrollViewer).ScrollToEnd();
            };
            _parser.OnModelChanged += delegate(object sender, ModelChangedEventArgs e)
            {
                //fire event
                ModelChangedByScript(e.NewModel);
            };

            //open files just created
            _parser.OnFileReportCreated += delegate(object sender, FileReportCreatedEventArgs args)
            {
                var path = args.FilePath;
                if (path != null)
                    Process.Start(path);
            };
        }
예제 #19
0
 public static void CloseModel()
 {
     if (_model != null)
         _model.Close();
     _model = null;
     _cobieContext = null;
 }
예제 #20
0
 public static void LoadModel(TestContext context)
 {
     if (!File.Exists(SourceFile)) throw new Exception("Cannot find file");
     _model = new XbimModel();
     _model.Open(SourceFile);
     _cobieContext = new COBieContext();
     _cobieContext.Model = _model;
 }
예제 #21
0
 /// <summary>
 /// Constructor which takes a existing model as an argument. 
 /// You can also close and open any model from the script.
 /// </summary>
 /// <param name="model">Model which shuldbe used for the script execution</param>
 public XbimQueryParser(XbimModel model)
 {
     _scanner = new Scanner();
     _parser = new Parser(_scanner, model);
     _parser.OnModelChanged += delegate(object sender, ModelChangedEventArgs e) {
         ModelChanged(e.NewModel);
     };
 }
 public XbimShapeGeometryCursor(XbimModel model, string database, OpenDatabaseGrbit mode)
     : base(model, database, mode)
 {
     Api.JetOpenTable(this.sesid, this.dbId, GeometryTableName, null, 0, mode == OpenDatabaseGrbit.ReadOnly ? OpenTableGrbit.ReadOnly :
                                                                         mode == OpenDatabaseGrbit.Exclusive ? OpenTableGrbit.DenyWrite : OpenTableGrbit.None,
                                                                         out this.table);
     InitColumns();
 }
 internal XbimReadWriteTransaction(XbimModel theModel, XbimLazyDBTransaction txn)
 {
     model = theModel;
     readWriteTransaction = txn;
     inTransaction = true;
     _pulseCount = 0;
     _transactionBatchSize = 100;
 }
예제 #24
0
        public void OpenIfcXmlFile()
        {
            using (var model = new XbimModel())
            {
                model.CreateFrom("4walls1floorSite.ifcxml");
                model.Close();
            }

        }
예제 #25
0
 private static void CreateXbimFile(string fileName)
 {
     string xbimFileName = Path.ChangeExtension(fileName, ".xbim");
     XbimModel model = new XbimModel();
     model.CreateFrom(fileName, xbimFileName, null);
     model.Open(xbimFileName, XbimDBAccess.ReadWrite);
     XbimScene.ConvertGeometry(model.Instances.OfType<IfcProduct>().Where(t => !(t is IfcFeatureElement)),null, false);
     model.Close();
 }
예제 #26
0
        public static string GeomInfoBoundBox(XbimModel model, int iEntLabel)
        {
            XbimGeometryData geomdata = model.GetGeometryData(iEntLabel, XbimGeometryType.BoundingBox).FirstOrDefault();
            if (geomdata == null)
                return "<not found>";

            XbimRect3D r3d = XbimRect3D.FromArray(geomdata.ShapeData);
            return string.Format("Bounding box (position, size): {0}", r3d.ToString());
        }
예제 #27
0
 public void QueryingNestedPropFunction()
 {
     // DirectoryInfo d = new DirectoryInfo("."); // to find folder location
     XbimModel model = new XbimModel();
     model.Open(SourceModelFileName, XbimDBAccess.Read);
     var chkCnt = model.Query("select @12275.Representation.Representations");
     Assert.AreEqual(3, ((IEnumerable<object>)chkCnt).Count());
     model.Close();
 }
 public XbimMeshLayer<WpfMeshGeometry3D, WpfMaterial> GetLayer(
     string layerKey, 
     XbimModel model,
     XbimScene<WpfMeshGeometry3D, WpfMaterial> scene
     )
 {
     XbimColour colour = _colours[layerKey];
     return new XbimMeshLayer<WpfMeshGeometry3D, WpfMaterial>(model, colour) { Name = layerKey };
 }
예제 #29
0
 public xBimQueryLanguage()
     : base(caseSensitive: false)
 {
     _model = new XbimModel();
     #if debug
     _model.Open(@"F:\dev\Codeplex\xBIM\XbimFramework\Head\Xbim.Querying\Querying\Test\Duplex-Handover.xBIM");
     #endif
     InitGrammar();
 }
 public IModel OpenIfcModel()
 {
     IModel model = new XbimModel();
     string xbimName = Path.ChangeExtension(TestSourceFileIfc, "xbim");
     model.CreateFrom(TestSourceFileIfc, xbimName);
     model.Close();
     model = new XbimModel();
     model.Open(xbimName);
     return model;
 }
예제 #31
0
        public void ConvertSolidToTriangulatedFacetedSolidPlanarTest()
        {
            using (var m = XbimModel.CreateTemporaryModel())
            {
                using (var txn = m.BeginTransaction())
                {
                    var profile      = IfcModelBuilder.MakeRectangleHollowProfileDef(m, 20, 10, 1);
                    var extrude      = IfcModelBuilder.MakeExtrudedAreaSolid(m, profile, 40);
                    var solid        = XbimGeometryCreator.CreateSolid(extrude);
                    var triangulated = XbimGeometryCreator.CreateTriangulatedSolid(solid, m.ModelFactors.Precision,
                                                                                   m.ModelFactors.DeflectionTolerance);

                    Assert.IsTrue(solid.Shells.Count == triangulated.Shells.Count, "Shell count differs");
                    Assert.IsTrue(triangulated.Faces.Count == 32, "Face count differs");
                    Assert.IsTrue(solid.Edges.Count * 2 == triangulated.Edges.Count, "Edge count differs");
                    Assert.IsTrue(solid.Vertices.Count == triangulated.Vertices.Count, "Vertex count differs");
                    Assert.IsTrue(Math.Abs(solid.Volume - triangulated.Volume) < 0.001, "Volume differs");
                }
            }
        }
예제 #32
0
 public void ReadWriteTriangulationOfNonPlanarFacetedSolidTest()
 {
     using (var m = XbimModel.CreateTemporaryModel())
     {
         using (var txn = m.BeginTransaction())
         {
             var profile = IfcModelBuilder.MakeCircleHollowProfileDef(m, 20, 1);
             var extrude = IfcModelBuilder.MakeExtrudedAreaSolid(m, profile, 40);
             var solid   = XbimGeometryCreator.CreateSolid(extrude);
             solid = XbimGeometryCreator.CreateFacetedSolid(solid, m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance, 0.5);
             TextWriter tw = new StringWriter();
             XbimGeometryCreator.WriteTriangulation(tw, solid, m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance, 0.5);
             TextReader          tr   = new StringReader(tw.ToString());
             IXbimGeometryObject geom = XbimGeometryCreator.ReadTriangulation(tr);
             var triangulatedSold     = geom as IXbimSolid;
             Assert.IsNotNull(triangulatedSold, "Invalid solid returned");
             Assert.IsTrue(Math.Abs(solid.Volume - triangulatedSold.Volume) < 5, "Volume differs too much");
         }
     }
 }
예제 #33
0
        public void IfcSurfaceCurveSweptAreaSolid()
        {
            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\11- IfcSurfaceCurveSweptAreaSolid.ifc", null, null, true, true);
                    var ss = m.Instances.OfType <IfcSurfaceCurveSweptAreaSolid>().FirstOrDefault();
                    Assert.IsTrue(ss != null, "No Swept Disk found");


                    var solid = _xbimGeometryCreator.CreateSolid(ss);

                    Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);
                    Assert.IsTrue(solid.Faces.Count() == 6, "This IfcSurfaceCurveSweptAreaSolid with hollow circular profile def should have 6 faces");
                }
            }
        }
예제 #34
0
        public static IfcCompositeCurve MakeCompositeCurve(XbimModel m)
        {
            var c  = m.Instances.New <IfcCompositeCurve>();
            var sc = MakeSemiCircle(m, 10);
            var l  = MakeLine(m, new XbimPoint3D(5, 0, 0), new XbimVector3D(1, 0, 0), 5);
            var s1 = m.Instances.New <IfcCompositeCurveSegment>();

            s1.ParentCurve = sc;
            s1.SameSense   = true;
            s1.Transition  = IfcTransitionCode.CONTINUOUS;
            c.Segments.Add(s1);
            var s2 = m.Instances.New <IfcCompositeCurveSegment>();

            s2.ParentCurve = l;
            s2.SameSense   = true;
            s2.Transition  = IfcTransitionCode.CONTINUOUS;
            c.Segments.Add(s2);
            c.SelfIntersect = false;
            return(c);
        }
예제 #35
0
        /// <summary>
        ///     Builds a placement tree of all ifcLocalPlacements
        /// </summary>
        /// <param name="model"></param>
        /// <param name="adjustWcs">
        ///     If there is a single root displacement, this is removed from the tree and added to the World
        ///     Coordinate System. Useful for models where the site has been located into a geographical context
        /// </param>
        public XbimPlacementTree(XbimModel model, bool adjustWcs = true)
        {
            var rootNodes       = new List <XbimPlacementNode>();
            var localPlacements = model.InstancesLocal.OfType <IfcLocalPlacement>(true).ToList();

            Nodes = new Dictionary <int, XbimPlacementNode>();
            foreach (var placement in localPlacements)
            {
                Nodes.Add(placement.EntityLabel, new XbimPlacementNode(placement));
            }
            foreach (var localPlacement in localPlacements)
            {
                if (localPlacement.PlacementRelTo != null) //resolve parent
                {
                    var xbimPlacement       = Nodes[localPlacement.EntityLabel];
                    var xbimPlacementParent = Nodes[localPlacement.PlacementRelTo.EntityLabel];
                    xbimPlacement.Parent = xbimPlacementParent;
                    xbimPlacementParent.Children.Add(xbimPlacement);
                }
                else
                {
                    rootNodes.Add(Nodes[localPlacement.EntityLabel]);
                }
            }
            if (adjustWcs && rootNodes.Count == 1)
            {
                var root = rootNodes[0];
                WorldCoordinateSystem = root.Matrix;
                //make the children parentless
                foreach (var node in Nodes.Values.Where(node => node.Parent == root))
                {
                    node.Parent = null;
                }
                root.Matrix = new XbimMatrix3D(); //set the matrix to identity
            }
            //muliply out the matrices
            foreach (var node in Nodes.Values)
            {
                node.ToGlobalMatrix();
            }
        }
예제 #36
0
        /// <summary>
        /// Role Merge
        /// </summary>
        /// <param name="model"></param>
        /// <param name="fileRoles">bit fields enumeration to hold all the roles in one place using bitwise AND, OR, EXCLUSIVE OR</param>
        public void ValidateRoles(XbimModel model, COBieMergeRoles fileRoles)
        {
#if DEBUG
            Stopwatch timer = new Stopwatch();
            timer.Start();
#endif
            if (fileRoles != COBieMergeRoles.Unknown) //if role is a single value of unknown then do no merging
            {
                var           sheet         = this[Constants.WORKSHEET_COMPONENT];
                List <string> typeGlobalIds = sheet.ValidateComponentMerge(model, fileRoles);

                sheet = this[Constants.WORKSHEET_TYPE];
                int remNo = sheet.ValidateTypeMerge(typeGlobalIds);

                sheet = this[Constants.WORKSHEET_COMPONENT];
                List <string> keyList  = new List <string>();
                List <string> nameList = new List <string>();
                if (sheet.RemovedRows != null)
                {
                    foreach (var item in sheet.RemovedRows)
                    {
                        string      sheetName = "Component";
                        COBieColumn colName   = item.ParentSheet.Columns.Where(c => c.Value.ColumnName == "Name").Select(c => c.Value).FirstOrDefault();
                        var         name      = item[colName.ColumnOrder].CellValue;
                        nameList.Add(name);
                        keyList.Add(sheetName + name);
                    }

                    sheet = this[Constants.WORKSHEET_ATTRIBUTE];
                    int attRemNo = sheet.ValidateAttributeMerge(keyList);

                    sheet = this[Constants.WORKSHEET_SYSTEM];
                    int systemRemNo = sheet.ValidateSystemMerge(nameList);
                }
            }

#if DEBUG
            timer.Stop();
            Console.WriteLine(String.Format("Time to generate Role Merge data = {0} seconds", timer.Elapsed.TotalSeconds.ToString("F3")));
#endif
        }
예제 #37
0
        private static IfcIShapeProfileDef AssignIProfile(XbimModel model, HndzStructuralElement genericProducthndz,
                                                          IfcProduct genericProductIfc, IfcBuildingElementType elementType, HndzISectionProfile gnericProfileHndz)
        {
            #region Type & Material &Tags

            string typeText = genericProducthndz.ToString() + "I beam (flange " + gnericProfileHndz.I_Section.b_f + " x " + gnericProfileHndz.I_Section.t_fTop + " and web "
                              + gnericProfileHndz.I_Section.d + " x " + gnericProfileHndz.I_Section.t_w + " mm";


            elementType.Tag  = typeText;
            elementType.Name = typeText;
            IfcLabel columnLabel = new IfcLabel(typeText);
            elementType.ElementType          = columnLabel;
            elementType.ApplicableOccurrence = columnLabel;



            //genericProductIfc.Tag = typeText;
            genericProductIfc.Name        = typeText;
            genericProductIfc.Description = typeText;
            genericProductIfc.SetDefiningType(elementType, model);

            #endregion

            IfcIShapeProfileDef ifcGenericProfile = model.Instances.New <IfcIShapeProfileDef>();
            ifcGenericProfile.FlangeThickness = gnericProfileHndz.I_Section.tf;
            ifcGenericProfile.WebThickness    = gnericProfileHndz.I_Section.t_w;
            ifcGenericProfile.OverallWidth    = gnericProfileHndz.I_Section.b_f;
            ifcGenericProfile.OverallDepth    = gnericProfileHndz.I_Section.d;
            ifcGenericProfile.FilletRadius    = 10;//ToDo:make it zero after explore ISection

            ifcGenericProfile.ProfileType           = IfcProfileTypeEnum.AREA;
            ifcGenericProfile.Position              = model.Instances.New <IfcAxis2Placement2D>();
            ifcGenericProfile.Position.RefDirection = model.Instances.New <IfcDirection>();
            ifcGenericProfile.Position.RefDirection.SetXY(gnericProfileHndz.OrientationInPlane.X, gnericProfileHndz.OrientationInPlane.Y);
            ifcGenericProfile.Position.Location = model.Instances.New <IfcCartesianPoint>();
            ifcGenericProfile.Position.Location.SetXY(0, 0);
            //ifcGenericProfile.Position.Location.SetXY(genericProducthndz.ExtrusionLine.baseNode.Point.X,
            //     genericProducthndz.ExtrusionLine.baseNode.Point.Y);
            return(ifcGenericProfile);
        }
예제 #38
0
        static void Main(string[] args)
        {
            var          pow = PlanOfWork.OpenJson("013-Lakeside_Restaurant.dpow");
            const string dir = "..\\..\\COBieLiteUK";

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            string msg;

            foreach (var stage in pow.ProjectStages)
            {
                var json = Path.Combine(dir, stage.Name + ".cobie.json");
                var xlsx = Path.Combine(dir, stage.Name + ".xlsx");
                var ifc  = Path.Combine(dir, stage.Name + ".ifc");

                var facility       = new Xbim.COBieLiteUK.Facility();
                var cobieExchanger = new DPoWToCOBieLiteUKExchanger(pow, facility, stage);
                cobieExchanger.Convert();

                facility.WriteJson(json, true);
                facility.WriteCobie(xlsx, out msg);


                using (var ifcModel = XbimModel.CreateTemporaryModel())
                {
                    ifcModel.Initialise("Xbim Tester", "XbimTeam", "Xbim.Exchanger", "Xbim Development Team", "3.0");
                    ifcModel.Header.FileName.Name = stage.Name;
                    ifcModel.ReloadModelFactors();
                    using (var txn = ifcModel.BeginTransaction("Conversion from COBie"))
                    {
                        var ifcExchanger = new XbimExchanger.COBieLiteUkToIfc.CoBieLiteUkToIfcExchanger(facility, ifcModel);
                        ifcExchanger.Convert();
                        txn.Commit();
                    }
                    ifcModel.SaveAs(ifc, XbimStorageType.IFC);
                    ifcModel.Close();
                }
            }
        }
예제 #39
0
        public void ConverIfcToWexBim()
        {
            const string ifcFileFullName = @"Lakeside_Restaurant.ifc";

            var fileName = Path.GetFileName(ifcFileFullName);
            var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
            var workingDir     = Directory.GetCurrentDirectory();
            var coreFileName   = Path.Combine(workingDir, fileNameWithoutExtension);
            var wexBimFileName = Path.ChangeExtension(coreFileName, "wexbim");
            var xbimFile       = Path.ChangeExtension(coreFileName, "xbim");

            try
            {
                using (var wexBimFile = new FileStream(wexBimFileName, FileMode.Create))
                {
                    using (var binaryWriter = new BinaryWriter(wexBimFile))
                    {
                        using (var model = new XbimModel())
                        {
                            try
                            {
                                model.CreateFrom(ifcFileFullName, xbimFile, null, true);
                                var geomContext = new Xbim3DModelContext(model);
                                geomContext.CreateContext(XbimGeometryType.PolyhedronBinary);
                                geomContext.Write(binaryWriter);
                            }
                            finally
                            {
                                model.Close();
                                binaryWriter.Flush();
                                wexBimFile.Close();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Assert.Fail("Failed to process " + ifcFileFullName + " - " + e.Message);
            }
        }
예제 #40
0
        public ModelGeometry.Scene.XbimMeshLayer <WpfMeshGeometry3D, WpfMaterial> GetLayer(
            string layerKey,
            XbimModel model,
            XbimScene <WpfMeshGeometry3D, WpfMaterial> scene
            )
        {
            int    iLab;
            string LayerName    = layerKey;
            bool   conversionok = Int32.TryParse(layerKey, out iLab);

            if (conversionok)
            {
                layerKey = model.Instances[iLab].GetType().Name;
            }
            XbimColour colour = scene.LayerColourMap[layerKey];

            return(new XbimMeshLayer <WpfMeshGeometry3D, WpfMaterial>(model, colour)
            {
                Name = LayerName
            });
        }
 public void IfcRevolvedArea_To_Sphere()
 {
     using (var eventTrace = LoggerFactory.CreateEventTrace())
     {
         using (var m = new XbimModel())
         {
             m.CreateFrom(@"SolidTestFiles\BIM Logo-Coordination View 2 - No M.ifc", null, null, true, true);
             var ss = m.Instances.OfType <IfcRevolvedAreaSolid>().FirstOrDefault(e => e.EntityLabel == 290);
             Assert.IsTrue(ss != null, "No Revolved Area found");
             //  m.ModelFactors.DeflectionAngle = 0.1;
             //  m.ModelFactors.DeflectionTolerance = 0.1;
             var solid = _xbimGeometryCreator.CreateSolid(ss);
             Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call
             var facetedSphere     = _xbimGeometryCreator.CreateFacetedBrep(m, solid);
             var shell             = _xbimGeometryCreator.CreateShell(facetedSphere.Outer);
             var xbimFacetedSphere = _xbimGeometryCreator.CreateSolidSet(facetedSphere);
             Assert.IsTrue(xbimFacetedSphere.Count == 1);
             //_xbimGeometryCreator.WriteTriangulation(Console.Out,solid, 0.001,0.5);
         }
     }
 }
        public void IfcFacetedBRepWithMultipleSolids()
        {
            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\12 - Multiple FacetedBrep.ifc", null, null, true, true);
                    var fbr = m.Instances[25] as IfcFacetedBrep;
                    Assert.IsTrue(fbr != null, "No IfcFacetedBRep found");
                    int faceCount = fbr.Outer.CfsFaces.Count;

                    var solids = _xbimGeometryCreator.CreateSolidSet(fbr);

                    Assert.IsTrue(solids.Count == 11, "Expected 11 solids");
                    foreach (var solid in solids)
                    {
                        IfcCsgTests.GeneralTest(solid, true);
                    }
                }
            }
        }
예제 #43
0
        public void IfcRightCircularConeTest()
        {
            using (var m = XbimModel.CreateTemporaryModel())
            {
                using (var txn = m.BeginTransaction())
                {
                    var cylinder = m.Instances.New <IfcRightCircularCone>();
                    var p        = m.Instances.New <IfcAxis2Placement3D>();
                    p.Axis                = m.Instances.New <IfcDirection>(d => d.SetXYZ(1, 0, 0));
                    p.Location            = m.Instances.New <IfcCartesianPoint>(c => c.SetXYZ(10, 10, 0));
                    cylinder.Position     = p;
                    cylinder.BottomRadius = 10;
                    cylinder.Height       = 20;

                    var solid = _xbimGeometryCreator.CreateSolid(cylinder);

                    Assert.IsTrue(solid.Faces.Count == 2, "2 faces are required of a cone");
                    Assert.IsTrue(solid.Vertices.Count == 2, "2 vertices are required of a cone");
                }
            }
        }
예제 #44
0
        public void ZShapeProfileDefTest()
        {
            using (var m = XbimModel.CreateTemporaryModel())
            {
                using (var txn = m.BeginTransaction())
                {
                    var    prof = IfcModelBuilder.MakeZShapeProfileDef(m, 150, 90, 13, 20, 6, 3);
                    var    face = _xbimGeometryCreator.CreateFace(prof);
                    double area = face.Area;
                    Assert.IsTrue(face.Area > 0);
                    m.ModelFactors.ProfileDefLevelOfDetail = 1;
                    face = _xbimGeometryCreator.CreateFace(prof);
                    //var w = new XbimOccWriter();
                    //w.Write(face, "d:\\xbim\\f");

                    Assert.IsTrue(face.Area > 0);
                    Assert.IsTrue(face.OuterBound.Edges.Count == 12, "Incorrect edge count");
                    Assert.IsTrue(face.Area > area, "Detailed profile should be bigger than normal profile");
                }
            }
        }
예제 #45
0
        public void IfcSweptDisk_With_IfcComposite()
        {
            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\6- IfcSweptDiskSolid_With_BooleanResult.ifc", null, null, true, true);
                    var ss = m.Instances.OfType <IfcSweptDiskSolid>().FirstOrDefault(e => e.Directrix is IfcCompositeCurve);
                    Assert.IsTrue(ss != null, "No Swept Disk found");
                    Assert.IsTrue(ss.Directrix is IfcCompositeCurve, "Incorrect sweep found");


                    var solid = _xbimGeometryCreator.CreateSolid(ss);

                    Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);
                    Assert.IsTrue(solid.Faces.Count() == 4, "Swept disk solids along a this composite curve should have 4 faces");
                }
            }
        }
        void XplorerMainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var model = XbimModel.CreateTemporaryModel();

            model.Initialise();
            ModelProvider.ObjectInstance = model;
            ModelProvider.Refresh();

            // logging information warnings
            appender = new EventAppender {
                Tag = "MainWindow"
            };
            appender.Logged += appender_Logged;

            var hier = LogManager.GetRepository() as Hierarchy;

            if (hier != null)
            {
                hier.Root.AddAppender(appender);
            }
        }
예제 #47
0
        /// <summary>
        /// Works only on models version 1.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private static XbimRegion GetLargestRegion(XbimModel model)
        {
            //get the region data should only be one
            var project   = model.IfcProject;
            var projectId = 0;

            if (project != null)
            {
                projectId = project.EntityLabel;
            }
            // in version 1.0 there should be only 1 record in the database for the project (storing multiple regions).
            var regionData = model.GetGeometryData(projectId, XbimGeometryType.Region).FirstOrDefault();

            if (regionData == null)
            {
                return(null);
            }
            var regions = XbimRegionCollection.FromArray(regionData.ShapeData);

            return(regions.MostPopulated()); // this then returns
        }
예제 #48
0
 public void ConvertXbimSolidFromXbimFacetedSolidCurvedTest()
 {
     using (var m = XbimModel.CreateTemporaryModel())
     {
         using (var txn = m.BeginTransaction())
         {
             var profile = IfcModelBuilder.MakeCircleHollowProfileDef(m, 20, 2);
             var extrude = IfcModelBuilder.MakeExtrudedAreaSolid(m, profile, 40);
             var solid   = XbimGeometryCreator.CreateSolid(extrude);
             var faceted = XbimGeometryCreator.CreateFacetedSolid(solid, m.ModelFactors.Precision,
                                                                  m.ModelFactors.DeflectionTolerance * 10, 1);
             var solid2 = XbimGeometryCreator.CreateSolid(faceted);
             Assert.IsTrue(solid2.Shells.Count == faceted.Shells.Count, "Shell count differs");
             Assert.IsTrue(solid2.Faces.Count == faceted.Faces.Count, "Face count differs");
             Assert.IsTrue(solid2.Edges.Count == faceted.Edges.Count, "Edge count differs");
             Assert.IsTrue(solid2.Vertices.Count == faceted.Vertices.Count, "Vertex count differs");
             Assert.IsTrue(Math.Abs(faceted.Volume - solid2.Volume) < 0.001, "Volume differs");
             Assert.IsTrue(Math.Abs(solid.Volume - solid2.Volume) < 30, "Volume differs");
         }
     }
 }
        public void CompositeProfileDefTest()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();

            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\IfcCompositeProfileDefTest.ifc", null, null, true, true);
                    var eas = m.Instances.OfType <IfcExtrudedAreaSolid>().FirstOrDefault(e => e.SweptArea.GetType() == typeof(IfcCompositeProfileDef));
                    Assert.IsTrue(eas != null, "No Extruded Solid found");
                    Assert.IsTrue(eas.SweptArea is IfcCompositeProfileDef, "Incorrect profiledef found");

                    var solid = xbimGeometryCreator.CreateSolid(eas);
                    Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);
                    Assert.IsTrue(solid.Faces.Count() == 40, "IfcCompositeProfileDef profile should have six faces");
                }
            }
        }
예제 #50
0
        public void BooleanPerformanceTest()
        {
            using (var m = XbimModel.CreateTemporaryModel())
            {
                using (var txn = m.BeginTransaction())
                {
                    var ifcBlock1 = IfcModelBuilder.MakeBlock(m, 1000, 2000, 3000);
                    var ifcBlock2 = IfcModelBuilder.MakeBlock(m, 200, 200, 3000);
                    //var ifcBlock1 = IfcModelBuilder.MakeRightCircularCylinder(m, 2000, 3000);
                    //var ifcBlock2 = IfcModelBuilder.MakeRightCircularCylinder(m, 2000, 3000);
                    //var ifcBlock1 = IfcModelBuilder.MakeExtrudedAreaSolid(m, IfcModelBuilder.MakeRectangleHollowProfileDef(m, 2000, 3000, 500), 4000);
                    //var ifcBlock2 = IfcModelBuilder.MakeExtrudedAreaSolid(m, IfcModelBuilder.MakeRectangleHollowProfileDef(m, 2000, 3000, 500), 4000);

                    ifcBlock2.Position.Location.X -= 180;
                    ifcBlock2.Position.Location.Y += 200;

                    var solid1   = XbimGeometryCreator.CreateSolid(ifcBlock1);
                    var solid2   = XbimGeometryCreator.CreateSolid(ifcBlock2);
                    var faceted1 = XbimGeometryCreator.CreateFacetedSolid(XbimGeometryCreator.CreateSolid(ifcBlock1), m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance, 1);
                    var faceted2 = XbimGeometryCreator.CreateFacetedSolid(XbimGeometryCreator.CreateSolid(ifcBlock2), m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance, 1);
                    var solid3   = solid1.Cut(solid2, m.ModelFactors.Precision);
                    solid3 = faceted1.Cut(faceted2, m.ModelFactors.Precision);

                    var sw = new Stopwatch();
                    sw.Start();
                    for (int i = 0; i < 10; i++)
                    {
                        solid3 = solid1.Cut(solid2, m.ModelFactors.Precision);
                    }
                    double time1 = sw.ElapsedMilliseconds;
                    sw.Restart();
                    for (int i = 0; i < 10; i++)
                    {
                        solid3 = faceted1.Cut(faceted2, m.ModelFactors.Precision);
                    }
                    double time2 = sw.ElapsedMilliseconds;
                    Assert.IsTrue(time2 < time1, "Performance error");
                }
            }
        }
예제 #51
0
        public void Dpow2CobieLite2Ifc()
        {
            var          pow = PlanOfWork.OpenJson("NewtownHighSchool.new.dpow");
            const string dir = "..\\..\\Export";

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            foreach (var stage in pow.ProjectStages)
            {
                var facility = new FacilityType();
                var d2C      = new DPoWToCOBieLiteExchanger(pow, facility, stage);
                d2C.Convert();

                var outputIfc       = Path.Combine(dir, stage.Name + ".DPoW.ifc");
                var outputCobieJson = Path.Combine(dir, stage.Name + ".DPoW.json");
                var outputCobieXml  = Path.Combine(dir, stage.Name + ".DPoW.xml");
                facility.WriteJson(outputCobieJson);
                facility.WriteXml(outputCobieXml);

                using (var model = XbimModel.CreateTemporaryModel())
                {
                    model.Initialise("Xbim Tester", "XbimTeam", "Xbim.Exchanger", "Xbim Development Team", "3.0");
                    model.ReloadModelFactors();
                    using (var txn = model.BeginTransaction("Convert from COBieLite"))
                    {
                        var c2Ifc = new CoBieLiteToIfcExchanger(facility, model);
                        c2Ifc.Convert();
                        txn.Commit();
                    }
                    model.SaveAs(outputIfc, XbimStorageType.IFC);

                    if (facility.AssetTypes != null)
                    {
                        Assert.AreEqual(facility.AssetTypes.Count(), model.Instances.OfType <IfcTypeObject>().Count());
                    }
                }
            }
        }
예제 #52
0
        private static IfcColumn CreateColumn(XbimModel model, HndzStructuralElement genericProducthndz)
        {
            using (XbimReadWriteTransaction txn = model.BeginTransaction("Create" + genericProducthndz.ToString()))
            {
                IfcColumn     genericProductIfc = model.Instances.New <IfcColumn>();
                IfcColumnType elementType       = model.Instances.New <IfcColumnType>();
                elementType.PredefinedType = IfcColumnTypeEnum.COLUMN;
                IfcExtrudedAreaSolid body = model.Instances.New <IfcExtrudedAreaSolid>();

                if (genericProducthndz.Profile is HndzRectangularProfile)
                {
                    HndzRectangularProfile genericProfilehndz = genericProducthndz.Profile as HndzRectangularProfile;

                    IfcRectangleProfileDef ifcGenericProfile = AssignRectangularProfile(model, genericProducthndz, genericProductIfc, elementType, genericProfilehndz);

                    //model as a swept area solid
                    body.SweptArea = ifcGenericProfile;
                }
                if (genericProducthndz.Profile is HndzISectionProfile)
                {
                    HndzISectionProfile genericProfilehndz = genericProducthndz.Profile as HndzISectionProfile;

                    IfcIShapeProfileDef ifcGenericProfile = AssignIProfile(model, genericProducthndz, genericProductIfc, elementType, genericProfilehndz);


                    //model as a swept area solid
                    body.SweptArea = ifcGenericProfile;
                }
                AdjustExtrusion(model, body, genericProducthndz, genericProductIfc);


                if (model.Validate(txn.Modified(), Console.Out) == 0)
                {
                    txn.Commit();
                    return(genericProductIfc);
                }
                return(null);
            }
        }
예제 #53
0
        private static IfcCShapeProfileDef AssignCsectionProfile(XbimModel model, HndzStructuralElement genericProducthndz,
                                                                 IfcProduct genericProductIfc, IfcBuildingElementType elementType, HndzCSectionProfile genericProfilehndz)
        {
            #region Type & Material &Tags

            string typeText = genericProducthndz.ToString() + " C-Chanel (flange " + genericProfilehndz.C_Section.b_f + " x " + genericProfilehndz.C_Section.t_f + " and web "
                              + genericProfilehndz.C_Section.d + " x " + genericProfilehndz.C_Section.t_w + " mm";


            elementType.Tag  = typeText;
            elementType.Name = typeText;
            IfcLabel columnLabel = new IfcLabel(typeText);
            elementType.ElementType          = columnLabel;
            elementType.ApplicableOccurrence = columnLabel;


            //genericProductIfc.Tag = typeText;
            genericProductIfc.Name        = typeText;
            genericProductIfc.Description = typeText;
            genericProductIfc.SetDefiningType(elementType, model);

            #endregion

            IfcCShapeProfileDef ifcGenericProfile = model.Instances.New <IfcCShapeProfileDef>();
            ifcGenericProfile.ProfileType   = IfcProfileTypeEnum.AREA;
            ifcGenericProfile.WallThickness = genericProfilehndz.C_Section.t_f;
            //MyColumnPofile.WebThickness = Iprofile.C_Section.t_w; //ToDo:purlin web and flange thickness are the same!!!!
            ifcGenericProfile.Width = genericProfilehndz.C_Section.b_f;
            ifcGenericProfile.Depth = genericProfilehndz.C_Section.d;
            ifcGenericProfile.Girth = 5;//ToDo:What's that
            ifcGenericProfile.InternalFilletRadius = 10;

            ifcGenericProfile.Position = model.Instances.New <IfcAxis2Placement2D>();
            ifcGenericProfile.Position.RefDirection = model.Instances.New <IfcDirection>();
            ifcGenericProfile.Position.RefDirection.SetXY(genericProfilehndz.OrientationInPlane.X, genericProfilehndz.OrientationInPlane.Y);
            ifcGenericProfile.Position.Location = model.Instances.New <IfcCartesianPoint>();
            ifcGenericProfile.Position.Location.SetXY(0, 0);
            return(ifcGenericProfile);
        }
        private static Facility GetValidated(string requirementFile)
        {
            const string ifcTestFile = @"Lakeside_Restaurant_fabric_only.ifczip";
            Facility     sub         = null;

            //create validation file from IFC
            using (var m = new XbimModel())
            {
                var xbimTestFile = Path.ChangeExtension(ifcTestFile, "xbim");
                m.CreateFrom(ifcTestFile, xbimTestFile, null, true, true);
                var facilities = new List <Facility>();
                var ifcToCoBieLiteUkExchanger = new IfcToCOBieLiteUkExchanger(m, facilities);
                facilities = ifcToCoBieLiteUkExchanger.Convert();
                sub        = facilities.FirstOrDefault();
            }
            Assert.IsTrue(sub != null);
            var vd        = new FacilityValidator();
            var req       = Facility.ReadJson(requirementFile);
            var validated = vd.Validate(req, sub);

            return(validated);
        }
예제 #55
0
        //public static string GeomInfoMesh(XbimModel model, int iEntLabel)
        //{
        //    StringBuilder sb = new StringBuilder();

        //    var geomdata = model.GetGeometryData(iEntLabel, XbimGeometryType.TriangulatedMesh);
        //    foreach (var geom in geomdata)
        //    {
        //        sb.Append("RawData:");
        //        sb.AppendLine(BitConverter.ToString(geom.ShapeData));
        //    }
        //    return sb.ToString();
        //}

        internal static string GeomLayers(XbimModel Model, int item, List <Xbim.ModelGeometry.Scene.XbimScene <Xbim.Presentation.WpfMeshGeometry3D, Xbim.Presentation.WpfMaterial> > scenes)
        {
            StringBuilder sb = new StringBuilder();

            // XbimMeshGeometry3D geometry = new XbimMeshGeometry3D();
            // IModel m = entity.ModelOf;
            foreach (var scene in scenes)
            {
                foreach (var layer in scene.SubLayers)
                {
                    // an entity model could be spread across many layers (e.g. in case of different materials)
                    if (layer.Model == Model)
                    {
                        foreach (var mi in layer.GetMeshInfo(item))
                        {
                            sb.AppendLine(mi.ToString());
                        }
                    }
                }
            }
            return(sb.ToString());
        }
예제 #56
0
        static private XbimModel CreateandInitModel(HndzProject hndzProject)
        {
            //IfcRelAggregates
            //Crashes here.....Fixed in this update :D

            XbimModel model = XbimModel.CreateModel(hndzProject.Name + "No." + hndzProject.GlobalId + ".xBIM", Xbim.XbimExtensions.XbimDBAccess.ReadWrite); //create an empty model

            if (model != null)
            {
                //Begin a transaction as all changes to a model are transacted
                using (XbimReadWriteTransaction txn = model.BeginTransaction("Initialize Model"))
                {
                    //do once only initialization of model application and editor values
                    model.DefaultOwningUser.ThePerson.GivenName              = hndzProject.Owner.Name;
                    model.DefaultOwningUser.ThePerson.FamilyName             = hndzProject.Owner.LastName;
                    model.DefaultOwningUser.TheOrganization.Name             = hndzProject.Owner.Organization;
                    model.DefaultOwningApplication.ApplicationIdentifier     = IFCFileResources.ApplicationIdentifier;
                    model.DefaultOwningApplication.ApplicationDeveloper.Name = IFCFileResources.ApplicationDevelopers;
                    model.DefaultOwningApplication.ApplicationFullName       = IFCFileResources.ApplicationFullName;
                    model.DefaultOwningApplication.Version = IFCFileResources.CurrentApplicationVersion;

                    //set up a project and initialize the defaults

                    var project = model.Instances.New <IfcProject>();
                    project.Initialize(ProjectUnits.SIUnitsUK);
                    project.Name = hndzProject.Name;
                    project.OwnerHistory.OwningUser        = model.DefaultOwningUser;
                    project.OwnerHistory.OwningApplication = model.DefaultOwningApplication;

                    //validate and commit changes
                    if (model.Validate(txn.Modified(), Console.Out) == 0)
                    {
                        txn.Commit();
                        return(model);
                    }
                }
            }
            return(null); //failed so return nothing
        }
        /// <summary>
        /// Validates all data and creates model.
        /// Provide a "XbimModel model = DataContext as XbimModel;"
        /// </summary>
        /// <returns>Returns XbimReferencedModel == null </returns>
        public bool TryBuild(XbimModel model)
        {
            //it's already build, so no need to recreate it
            if (ReferencedModel != null)
            {
                return(true);
            }

            if (string.IsNullOrWhiteSpace(Name))
            {
                return(false);
            }
            else
            {
                string ext = System.IO.Path.GetExtension(Name).ToLowerInvariant();
                using (XbimModel refM = new XbimModel())
                {
                    if (ext != ".xbim")
                    {
                        refM.CreateFrom(Name, null, null, true);
                        var m3D = new Xbim3DModelContext(refM);
                        m3D.CreateContext();
                        Name = System.IO.Path.ChangeExtension(Name, "xbim");
                    }
                }

                _xbimReferencedModel = model.AddModelReference(Name, OrganisationName, OrganisationRole);
            }

            if (_xbimReferencedModel != null)
            {
                //refresh all
                OnPropertyChanged("Identifier");
                OnPropertyChanged("Name");
                OnPropertyChanged("OrganisationName");
                OnPropertyChanged("OrganisationRole");
            }
            return(ReferencedModel != null);
        }
예제 #58
0
 public void TransformFacetedSolidRectangularProfileDef()
 {
     using (var m = XbimModel.CreateTemporaryModel())
     {
         using (var txn = m.BeginTransaction())
         {
             var profile = IfcModelBuilder.MakeRectangleHollowProfileDef(m, 20, 10, 1);
             var extrude = IfcModelBuilder.MakeExtrudedAreaSolid(m, profile, 40);
             var solid   = XbimGeometryCreator.CreateSolid(extrude);
             solid = XbimGeometryCreator.CreateFacetedSolid(solid, m.ModelFactors.Precision, m.ModelFactors.DeflectionTolerance, 0.5);
             var transform = new XbimMatrix3D(); //test first with identity
             var solid2    = solid.Transform(transform);
             var s1Verts   = solid.Vertices.ToList();
             var s2Verts   = solid2.Vertices.ToList();
             for (int i = 0; i < s1Verts.Count; i++)
             {
                 XbimVector3D v = s1Verts[i].VertexGeometry - s2Verts[i].VertexGeometry;
                 Assert.IsTrue(v.Length < m.ModelFactors.Precision, "vertices not the same");
             }
             transform.RotateAroundXAxis(Math.PI / 2);
             transform.RotateAroundYAxis(Math.PI / 4);
             transform.RotateAroundZAxis(Math.PI);
             transform.OffsetX += 100;
             transform.OffsetY += 200;
             transform.OffsetZ += 300;
             solid2             = solid.Transform(transform);
             Assert.IsTrue(Math.Abs(solid.Volume - solid2.Volume) < 0.001, "Volume differs");
             transform.Invert();
             solid2  = solid2.Transform(transform);
             s1Verts = solid.Vertices.ToList();
             s2Verts = solid2.Vertices.ToList();
             for (int i = 0; i < s1Verts.Count; i++)
             {
                 XbimVector3D v = s1Verts[i].VertexGeometry - s2Verts[i].VertexGeometry;
                 Assert.IsTrue(v.Length < m.ModelFactors.Precision, "vertices not the same");
             }
         }
     }
 }
        public void IfcExtrudedArea_With_IfcArbritraryProfileDefWithVoids()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();

            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\18 - IfcArbritaryClosedProfileDefWithVoids.ifc", null, null, true, true);
                    var eas = m.Instances.OfType <IfcExtrudedAreaSolid>().FirstOrDefault(e => e.SweptArea is IfcArbitraryProfileDefWithVoids);
                    Assert.IsTrue(eas != null);
                    Assert.IsTrue(eas.SweptArea is IfcArbitraryProfileDefWithVoids, "Incorrect profile definition");

                    var solid = xbimGeometryCreator.CreateSolid(eas);
                    Assert.IsTrue(eventTrace.Events.Count == 0, "Warnings or errors raised in geometry conversion"); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);

                    //Assert.IsTrue(solid.Faces.Count() == 6, "IfcPolyline  profiles should have (number of polyline egdes + 2) faces");
                }
            }
        }
        public void TestDerivedProfileDefWithLShapedParent()
        {
            var xbimGeometryCreator = new XbimGeometryEngine();

            using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                using (var m = new XbimModel())
                {
                    m.CreateFrom("SolidTestFiles\\1- IfcExtrudedAreaSolid-IfcProfileDef-Parameterised.ifc", null, null, true, true);
                    var eas = m.Instances.OfType <IfcExtrudedAreaSolid>().FirstOrDefault(e => e.SweptArea is IfcDerivedProfileDef && ((IfcDerivedProfileDef)e.SweptArea).ParentProfile is IfcLShapeProfileDef);
                    Assert.IsTrue(eas != null, "No Extruded Solid found");
                    Assert.IsTrue(eas.SweptArea is IfcDerivedProfileDef, "Incorrect profiledef found");
                    Assert.IsTrue(((IfcDerivedProfileDef)eas.SweptArea).ParentProfile is IfcLShapeProfileDef, "Incorrect parent profiledef found");

                    var solid = xbimGeometryCreator.CreateSolid(eas);
                    Assert.IsTrue(eventTrace.Events.Count == 0); //no events should have been raised from this call

                    IfcCsgTests.GeneralTest(solid);
                    Assert.IsTrue(solid.Faces.Count() == 8, "L Shaped profiles should have 8 faces");
                }
            }
        }