// from_ifcSQL.cs, this software use IfcSharp (see https://github.com/IfcSharp) class from_ifcSQL { static void Main(string[] args)//####################################################################### { try{ ifc.Model m = ifc.Model.FromSql(ServerName: System.Environment.GetEnvironmentVariable("SqlServer"), DatabaseName: "ifcSQL_Instance", ProjectId: 0);// 0 = current project m.ToHtmlFile(); m.ToStepFile(); }catch (System.Exception e) { System.Console.WriteLine(e.Message); } }
public partial class Model {//========================================================================================== public static Model FromStepFile(string FileName) { //ifc.Repository.CurrentModel. string FileSchema = "-"; Model CurrentModel = new ifc.Model(FileName.Replace(".ifc", "")); StreamReader sr = new StreamReader(FileName); string line = ""; while ((line = sr.ReadLine()) != null && (line.Length > 1) && ((line + ' ')[0] != '#') && (!line.StartsWith("DATA"))) { if (line.StartsWith("FILE_DESCRIPTION")) { CurrentModel.Header.description = line.Split('\'')[1 * 2 - 1]; } if (line.StartsWith("FILE_NAME")) { string[] HeaderLine = line.Split('\''); CurrentModel.Header.name = HeaderLine[1 * 2 - 1]; CurrentModel.Header.time_stamp = HeaderLine[2 * 2 - 1]; CurrentModel.Header.author = HeaderLine[3 * 2 - 1]; CurrentModel.Header.organization = HeaderLine[4 * 2 - 1]; CurrentModel.Header.preprocessor_version = HeaderLine[5 * 2 - 1]; CurrentModel.Header.originating_system = HeaderLine[6 * 2 - 1]; CurrentModel.Header.authorization = HeaderLine[7 * 2 - 1]; } if (line.StartsWith("FILE_SCHEMA")) { FileSchema = line.Split('\'')[1 * 2 - 1]; } } ; if (FileSchema != Specification.SchemaName) { Console.WriteLine("WARNING! Expected schema is '" + Specification.SchemaName + "', detected schema is '" + FileSchema + "'"); } //if (line.Length>1) ENTITY.ParseIfcLine(CurrentModel,line); while ((line = sr.ReadLine()) != null) { if (line.Length > 3) { line = line.TrimStart(' '); //Console.WriteLine(line); if (line.Length > 3) { if (line[0] == '#' || (line[0] == '/' && line[1] == '*')) { ENTITY.ParseIfcLine(CurrentModel, line); } } } } sr.Close(); CurrentModel.AssignEntities(); return(CurrentModel); } // of FromStepFile
public static Model FromSqliteFile(string fullPath) { SQLiteDatabase database = new SQLiteDatabase(); Model CurrentModel = new ifc.Model(fullPath.Replace(".sqlite", "")); DataSet dataSet = database.GetContentAsDataSet(fullPath); #if _DEBUG Console.WriteLine(string.Format("Reading SQLite-File: {0}", NetSystem.IO.Path.GetFileName(fullPath))); Console.WriteLine("======================================================"); #endif foreach (DataTable dt in dataSet.Tables) { #if _DEBUG Console.WriteLine("______________________________________________________"); Console.WriteLine(dt.TableName); foreach (DataColumn c in dt.Columns) { Console.Write(string.Format("{0} ", c.ColumnName)); } Console.Write("\r\n"); #endif foreach (DataRow row in dt.Rows) { Type entityType = Type.GetType("ifc." + dt.TableName); ENTITY entityInstance; if (entityType == typeof(EntityComment)) { EntityComment ec = new EntityComment((string)row["Comment"], (int)row["PreviousEntity"]); entityInstance = ec; } else { object[] ctorArgs = GetEntityConstructorArgs(entityType, row); entityInstance = Activator.CreateInstance(entityType, ctorArgs) as ENTITY; } if (row["Id"] != null) { entityInstance.LocalId = (int)row["Id"]; } CurrentModel.EntityList.Add(entityInstance); #if _DEBUG foreach (DataColumn c in dt.Columns) { Console.Write(string.Format("{0} ", row[c] is DBNull ? "NULL" : row[c].ToString())); } Console.Write("\r\n"); #endif } } Console.WriteLine("======================================================"); // before we assign the entities, we need to order the list according to the Ids CurrentModel.EntityList = CurrentModel.EntityList.OrderBy(e => e.LocalId).ToList(); // then we change the position of all EntityComment´s to match the actual order, // since they are being read sequentially foreach (EntityComment ec in CurrentModel.EntityList.FindAll(e => e.GetType() == typeof(EntityComment))) { int oldIndex = CurrentModel.EntityList.FindIndex(e => e.LocalId == ec.LocalId); int newIndex = CurrentModel.EntityList.FindIndex(e => e.LocalId == ec.PreviousEntityId) + 1; var item = CurrentModel.EntityList[oldIndex]; CurrentModel.EntityList.RemoveAt(oldIndex); if (newIndex > oldIndex) { newIndex--; // the actual index could have shifted due to the removal } CurrentModel.EntityList.Insert(newIndex, item); } CurrentModel.AssignEntities(); return(CurrentModel); }
// hello_pipe.cs, this software use IfcSharp (see https://github.com/IfcSharp) class hello_pipe { static void Main(string[] args) //####################################################################### { #if IFC2X3 System.Console.WriteLine("This example runs only higher than IFC2X3"); #else ifc.Model PipeModel = new ifc.Model(); PipeModel.Header.name = "hello_pipe_short"; PipeModel.Header.description = @"see http://www.team-solutions.de/ifc-examples/"; PipeModel.Header.author = "Bernhard Simon Bock, Friedrich Eder"; PipeModel.Header.organization = @"https://github.com/IfcSharp"; PipeModel.Header.originating_system = "IfcSharp"; PipeModel.Header.documentation = "no docs"; ifc.Repository.CurrentModel = PipeModel; new ifc.EntityComment(CommentLine: "local coords:"); var Origin = new ifc.CartesianPoint(x: 0, y: 0, z: 0, EndOfLineComment: "origin"); var DirX = new ifc.Direction(x: 1, y: 0, z: 0, EndOfLineComment: "X-axis"); new ifc.Direction(x: 0, y: 1, z: 0, EndOfLineComment: "Y-axis (not needed)"); var DirZ = new ifc.Direction(x: 0, y: 0, z: 1, EndOfLineComment: "Z-axis"); var LocalCoords = new ifc.Axis2Placement3D(Location: Origin, Axis: DirZ, RefDirection: DirX, EndOfLineComment: "cartesian coordinate system" ); new ifc.EntityComment(CommentLine: "unit-declaration:"); var LengthUnit = new ifc.SIUnit(UnitType: ifc.UnitEnum.LENGTHUNIT, Name: ifc.SIUnitName.METRE, EndOfLineComment: "e.g. cartesian point coordinates" ); var LengthUnitmm = new ifc.SIUnit(UnitType: ifc.UnitEnum.LENGTHUNIT, Name: ifc.SIUnitName.METRE, Prefix: ifc.SIPrefix.MILLI, EndOfLineComment: "mm, e.g. nominal diameter" ); var PlaneAngleRadUnit = new ifc.SIUnit(UnitType: ifc.UnitEnum.PLANEANGLEUNIT, Name: ifc.SIUnitName.RADIAN, EndOfLineComment: "rotation angles" ); var UnitAssignment = new ifc.UnitAssignment(Units: new ifc.Set1toUnbounded_Unit(new ifc.Unit(LengthUnit), new ifc.Unit(PlaneAngleRadUnit) ) ); new ifc.EntityComment(CommentLine: "ways to display:"); var GeomReprContext3D = new ifc.GeometricRepresentationContext (CoordinateSpaceDimension: (ifc.DimensionCount)(3), WorldCoordinateSystem: new ifc.Axis2Placement(LocalCoords), ContextIdentifier: new ifc.Label("3D body"), ContextType: new ifc.Label("3D-Models VR") ); var SubContextBody = new ifc.GeometricRepresentationSubContext (CoordinateSpaceDimension: (ifc.DimensionCount)(3), WorldCoordinateSystem: new ifc.Axis2Placement(LocalCoords), ParentContext: GeomReprContext3D, TargetView: ifc.GeometricProjectionEnum.MODEL_VIEW ); new ifc.EntityComment(CommentLine: "assign global coords to 3D representation context:"); var Projection = new ifc.ProjectedCRS(Name: new ifc.Label("EPSG:25832"), Description: new ifc.Text("UTM in band 32"), GeodeticDatum: new ifc.Identifier("ETRS89"), VerticalDatum: new ifc.Identifier("DHHN92"), MapProjection: new ifc.Identifier("UTM"), MapZone: new ifc.Identifier("UTM32"), MapUnit: LengthUnit); new ifc.MapConversion(SourceCRS: new ifc.CoordinateReferenceSystemSelect(GeomReprContext3D), TargetCRS: Projection, Eastings: new ifc.LengthMeasure(439949), Northings: new ifc.LengthMeasure(5466152), OrthogonalHeight: new ifc.LengthMeasure(130), XAxisAbscissa: new ifc.Real(1.0), XAxisOrdinate: new ifc.Real(0.0), Scale: new ifc.Real(1.0), EndOfLineComment: "base of local coords"); new ifc.EntityComment(CommentLine: "assign contexts, units to project:"); var Project = new ifc.Project(GlobalId: null, Name: new ifc.Label("hello pipe project"), RepresentationContexts: new ifc.Set1toUnbounded_RepresentationContext(GeomReprContext3D), UnitsInContext: UnitAssignment ); // reinforced concrete pipe DN400 DIN V 1201-DIN EN1916-Typ 2-SB-K 3000 double d1_m = 400 * units.mm2m; double t_m = 75 * units.mm2m; double dg_m = 694 * units.mm2m; double da_m = d1_m + 2 * t_m; double dsp_m = 526 * units.mm2m; double l_m = 3000 * units.mm2m; double lso_m = 100 * units.mm2m; double dso_m = 543.8 * units.mm2m; double ri_m = d1_m / 2; double rg_m = dg_m / 2; double ra_m = da_m / 2; double rsp_m = dsp_m / 2; double rso_m = dso_m / 2; new ifc.EntityComment(CommentLine: "3D-body-context LOD 300:"); var FlowSegmentPoly = new ifc.Polyline(Points: new ifc.List2toUnbounded_CartesianPoint( new ifc.CartesianPoint(0, ri_m, " (1): x=0 , y=ri "), new ifc.CartesianPoint(0, rsp_m, " (2): x=0 , y=rsp"), new ifc.CartesianPoint(lso_m, rsp_m, " (3): x=lso , y=rsp"), // 3*(rg-ra) new ifc.CartesianPoint(lso_m, ra_m, " (4): x=lso , y=ra "), // +l-lso new ifc.CartesianPoint(l_m - 3 * (rg_m - ra_m), ra_m, " (5): x=l-3*(rg-ra), y=ra "), new ifc.CartesianPoint(l_m, rg_m, " (6): x=l , y=rg "), new ifc.CartesianPoint(l_m + lso_m, rg_m, " (7): x=l+lso , y=rg "), new ifc.CartesianPoint(l_m + lso_m, rso_m, " (8): x=l+lso , y=rso"), new ifc.CartesianPoint(l_m, rso_m, " (9): x=l , y=rso"), new ifc.CartesianPoint(l_m, ri_m, "(10): x=l , y=ri "), new ifc.CartesianPoint(0, ri_m, "(11)=(1) ") ) ); var rpd = new ifc.ArbitraryClosedProfileDef(ProfileType: ifc.ProfileTypeEnum.AREA, OuterCurve: FlowSegmentPoly, EndOfLineComment: "declare poly as area" ); var RevolveInsCoords = new ifc.Axis2Placement3D(Location: Origin, Axis: DirZ, RefDirection: DirX, EndOfLineComment: "revolve-plane" ); var RevolvedPoly = new ifc.RevolvedAreaSolid(SweptArea: rpd, Position: RevolveInsCoords, Axis: new ifc.Axis1Placement(Location: Origin, Axis: DirX, EndOfLineComment: "rotation axis" ), Angle: (ifc.PlaneAngleMeasure)(2 * System.Math.PI) ); var FlowSegmentShpRepr1 = new ifc.ShapeRepresentation(ContextOfItems: SubContextBody, Items: new ifc.Set1toUnbounded_RepresentationItem(RevolvedPoly) ); new ifc.EntityComment(CommentLine: "product shape definition, placement and instancing:"); var FlowSegProductDefShp = new ifc.ProductDefinitionShape(Representations: new ifc.List1toUnbounded_Representation(FlowSegmentShpRepr1)); var FlowSegmentPlacement = new ifc.LocalPlacement(RelativePlacement: new ifc.Axis2Placement(LocalCoords)); var FlowSegment = new ifc.FlowSegment(GlobalId: null, Name: (ifc.Label) "pipe", _ObjectPlacement: FlowSegmentPlacement, _Representation: FlowSegProductDefShp ); new ifc.EntityComment(CommentLine: "assign properties to pipe:"); var psv = new ifc.PropertySingleValue(Name: new ifc.Identifier("DN"), NominalValue: new ifc.Value(new ifc.Real(400)), Unit: new ifc.Unit(LengthUnitmm) ); var ps1 = new ifc.PropertySet(Name: new ifc.Label("pipe-properties"), HasProperties: new ifc.Set1toUnbounded_Property(psv) ); new ifc.RelDefinesByProperties(RelatedObjects: new ifc.Set1toUnbounded_ObjectDefinition(FlowSegment), RelatingPropertyDefinition: new ifc.PropertySetDefinitionSelect(ps1) ); new ifc.RelAggregates(RelatingObject: Project, RelatedObjects: new ifc.Set1toUnbounded_ObjectDefinition(FlowSegment), EndOfLineComment: "assign elements to project:" ); PipeModel.ToStepFile(); PipeModel.ToHtmlFile(); //PipeModel.ToSqliteFile(); //PipeModel.ToSql(ServerName: System.Environment.GetEnvironmentVariable("SqlServer"), DatabaseName:"ifcSQL_Instance",WriteMode:ifc.Model.eWriteMode.CreateNewProject); // Sql server connection required #endif }