static public double Area(this IfcCurve curve) { //- IfcConic (abstract) // - IfcCircle (x) // - IfcEllipse (x) //- IfcLine (x) //- IfcOffsetCurve2D (Throw) //- IfcOffsetCurve3D (Throw) //- IfcBoundedCurve (abstract) // - IfcBSplineCurve (abstract) (Throw) // - IfcBezierCurve (Throw) // - IfcRationalBezierCurve (Throw) // - IfcTrimmedCurve (Throw) // - IfcPolyline (x) // - IfcCompositeCurve (Throw) // - Ifc2DCompositeCurve (Throw) if (curve is IfcCircle) { IfcCircle c = curve as IfcCircle; return(Math.PI * Math.Pow(c.Radius, 2)); } else if (curve is IfcEllipse) { IfcEllipse c = curve as IfcEllipse; return(Math.PI * c.SemiAxis1 * c.SemiAxis2); } else if (curve is IfcLine) { return(0); } else if (curve is IfcOffsetCurve2D) { throw new NotImplementedException("Area not implemented for IfcOffsetCurve2D"); } else if (curve is IfcOffsetCurve3D) { throw new NotImplementedException("Area not implemented for IfcOffsetCurve3D"); } else if (curve is IfcBSplineCurve) { throw new NotImplementedException("Area not implemented for IfcBSplineCurve"); } else if (curve is IfcTrimmedCurve) { throw new NotImplementedException("Area not implemented for IfcTrimmedCurve"); } else if (curve is IfcPolyline) { // todo: needs testing IfcPolyline p = curve as IfcPolyline; if (p.Dim != 2) { throw new NotImplementedException("Area not implemented for 3D IfcPolyline"); } // http://stackoverflow.com/questions/2553149/area-of-a-irregular-shape // it assumes that the last point is NOT the same of the first one, but it tolerates the case. double area = 0.0f; int numVertices = p.Points.Count; for (int i = 0; i < numVertices - 1; ++i) { area += p.Points[i].X * p.Points[i + 1].Y - p.Points[i + 1].X * p.Points[i].Y; } area += p.Points[numVertices - 1].X * p.Points[0].Y - p.Points[0].X * p.Points[numVertices - 1].Y; area /= 2.0; return(area); } else if (curve is Ifc2DCompositeCurve) { // these are complicated and should be solved with opencascade or some other lib throw new NotImplementedException("Area not implemented for Ifc2DCompositeCurve"); } else if (curve is IfcCompositeCurve) { // these are complicated and should be solved with opencascade or some other lib throw new NotImplementedException("Area not implemented for IfcCompositeCurve"); } return(double.NaN); }
protected override void GenerateInstance(IfcBuilding building) { DatabaseIfc database = building.Database; double angFactor = database.Factory.Options.AngleUnitsInRadians ? 1 : 180 / Math.PI; building.Comments.Add("These profile curves are intentionally expressed in a more complicated manner than possible to test parameterization"); IfcMaterial material = new IfcMaterial(database, "Steel"); //-IfcBSplineCurve //- IfcCompositeCurve //- IfcCompositeCurveSegment //- IfcIndexedPolyCurve //- IfcTrimmedCurve //- IfcPCurve ? double root2 = Math.Sqrt(2), root2div2 = Math.Sqrt(2) / 2.0, root3 = Math.Sqrt(3), root3div2 = Math.Sqrt(3) / 2.0; List <IfcCompositeCurveSegment> segments = new List <IfcCompositeCurveSegment>(); IfcLine line = new IfcLine(new IfcCartesianPoint(database, -1000, 1000), new IfcVector(new IfcDirection(database, 1, -1), 1000 * Math.Sqrt(2))); IfcTrimmedCurve trimmedCurve = new IfcTrimmedCurve(line, new IfcTrimmingSelect((root2 - 1) / root2), new IfcTrimmingSelect(1 + (1 / root2)), true, IfcTrimmingPreference.PARAMETER); segments.Add(new IfcCompositeCurveSegment(IfcTransitionCode.CONTINUOUS, true, trimmedCurve)); IfcCircle circle = new IfcCircle(database, 1000); trimmedCurve = new IfcTrimmedCurve(circle, new IfcTrimmingSelect(7.0 / 4 * Math.PI * angFactor), new IfcTrimmingSelect(3.0 / 4 * Math.PI * angFactor), true, IfcTrimmingPreference.PARAMETER); segments.Add(new IfcCompositeCurveSegment(IfcTransitionCode.CONTINUOUS, true, trimmedCurve)); string name = "SemiCircle"; IfcArbitraryClosedProfileDef profile = new IfcArbitraryClosedProfileDef(name, new IfcCompositeCurve(segments)); IfcMaterialProfileSet materialProfileSet = new IfcMaterialProfileSet(name, new IfcMaterialProfile(name, material, profile)); IfcColumnType columnType = new IfcColumnType(name, materialProfileSet, IfcColumnTypeEnum.COLUMN); database.Context.AddDeclared(columnType); IfcColumnStandardCase column = new IfcColumnStandardCase(building, new IfcMaterialProfileSetUsage(materialProfileSet, IfcCardinalPointReference.MID), new IfcAxis2Placement3D(new IfcCartesianPoint(database, 0, 0, 0)), 2000) { Name = name, RelatingType = columnType }; //Unique ids assigned to generate constant IfcScript sample files, remove otherwise columnType.GlobalId = "24mq0gwVr7bgEMXPmo$TrF"; column.GlobalId = "0RGc8lepr7BRF_EtHrWJ45"; columnType.ObjectTypeOf.GlobalId = "0devdSRyf3uBEQbSqWTDjo"; columnType.MaterialSelect.Associates.GlobalId = "1gdVo5TjPETPZlW8HSRupM"; column.MaterialSelect.Associates.GlobalId = "35z8gDFbb6gvrCOz$24tUJ"; database.NextObjectRecord = 100; circle = new IfcCircle(new IfcAxis2Placement2D(new IfcCartesianPoint(database, 0, 1000)) { RefDirection = new IfcDirection(database, -1, 0) }, root3 * 1000); segments = new List <IfcCompositeCurveSegment>(); trimmedCurve = new IfcTrimmedCurve(circle, new IfcTrimmingSelect(Math.PI / 3 * angFactor), new IfcTrimmingSelect(2 * Math.PI / 3 * angFactor), true, IfcTrimmingPreference.PARAMETER); segments.Add(new IfcCompositeCurveSegment(IfcTransitionCode.CONTINUOUS, true, trimmedCurve)); circle = new IfcCircle(new IfcAxis2Placement2D(new IfcCartesianPoint(database, -1000 * root3div2, -500)) { RefDirection = new IfcDirection(database, 0, -1) }, root3 * 1000); trimmedCurve = new IfcTrimmedCurve(circle, new IfcTrimmingSelect(Math.PI / 2 * angFactor), new IfcTrimmingSelect(5 * Math.PI / 6 * angFactor), true, IfcTrimmingPreference.PARAMETER); segments.Add(new IfcCompositeCurveSegment(IfcTransitionCode.CONTINUOUS, true, trimmedCurve)); circle = new IfcCircle(new IfcAxis2Placement2D(new IfcCartesianPoint(database, 1000 * root3div2, -500)) { RefDirection = new IfcDirection(database, 0, 1) }, root3 * 1000); trimmedCurve = new IfcTrimmedCurve(circle, new IfcTrimmingSelect(Math.PI / 6 * angFactor), new IfcTrimmingSelect(Math.PI / 2 * angFactor), true, IfcTrimmingPreference.PARAMETER); segments.Add(new IfcCompositeCurveSegment(IfcTransitionCode.CONTINUOUS, true, trimmedCurve)); name = "CurviLinearTriangle"; profile = new IfcArbitraryClosedProfileDef(name, new IfcCompositeCurve(segments)); materialProfileSet = new IfcMaterialProfileSet(name, new IfcMaterialProfile(name, material, profile)); columnType = new IfcColumnType(name, materialProfileSet, IfcColumnTypeEnum.COLUMN); database.Context.AddDeclared(columnType); column = new IfcColumnStandardCase(building, new IfcMaterialProfileSetUsage(materialProfileSet, IfcCardinalPointReference.MID), new IfcAxis2Placement3D(new IfcCartesianPoint(database, 2500, 0, 0)), 2000) { Name = name, RelatingType = columnType }; //Unique ids assigned to generate constant IfcScript sample files, remove otherwise columnType.GlobalId = "3N_qc_BjX1hvEgwfRvVcb_"; column.GlobalId = "0bmIILAwj8$PLHK1jcmad0"; columnType.ObjectTypeOf.GlobalId = "3tGocD1N51oOvSvHbJI_qD"; columnType.MaterialSelect.Associates.GlobalId = "1M5oofzjD3IOM43brXW6wT"; column.MaterialSelect.Associates.GlobalId = "0gnTzVmkbE9hPsJDxOUOL3"; database.NextObjectRecord = 150; IfcEllipse ellipse = new IfcEllipse(new IfcAxis2Placement2D(database), 1000, 500); segments = new List <IfcCompositeCurveSegment>(); trimmedCurve = new IfcTrimmedCurve(ellipse, new IfcTrimmingSelect(0), new IfcTrimmingSelect(Math.PI / 4 * angFactor), true, IfcTrimmingPreference.PARAMETER); segments.Add(new IfcCompositeCurveSegment(IfcTransitionCode.CONTINUOUS, true, trimmedCurve)); double x = root2div2, y = 0.5 * root2div2, len = Math.Sqrt(0.5 + Math.Pow(y, 2)); line = new IfcLine(new IfcCartesianPoint(database, 0, 0), new IfcVector(new IfcDirection(database, x / len, y / len), 1)); trimmedCurve = new IfcTrimmedCurve(line, new IfcTrimmingSelect(0), new IfcTrimmingSelect(len * 1000), false, IfcTrimmingPreference.PARAMETER); segments.Add(new IfcCompositeCurveSegment(IfcTransitionCode.CONTINUOUS, true, trimmedCurve)); line = new IfcLine(new IfcCartesianPoint(database, 0, 0), new IfcVector(new IfcDirection(database, 1, 0), 1)); trimmedCurve = new IfcTrimmedCurve(line, new IfcTrimmingSelect(0), new IfcTrimmingSelect(1000), true, IfcTrimmingPreference.PARAMETER); segments.Add(new IfcCompositeCurveSegment(IfcTransitionCode.CONTINUOUS, true, trimmedCurve)); name = "PartialEllipse"; profile = new IfcArbitraryClosedProfileDef(name, new IfcCompositeCurve(segments)); materialProfileSet = new IfcMaterialProfileSet(name, new IfcMaterialProfile(name, material, profile)); columnType = new IfcColumnType(name, materialProfileSet, IfcColumnTypeEnum.COLUMN); database.Context.AddDeclared(columnType); column = new IfcColumnStandardCase(building, new IfcMaterialProfileSetUsage(materialProfileSet, IfcCardinalPointReference.MID), new IfcAxis2Placement3D(new IfcCartesianPoint(database, 5000, 0, 0)), 2000) { Name = name, RelatingType = columnType }; //Unique ids assigned to generate constant IfcScript sample files, remove otherwise columnType.GlobalId = "0dtemVu1P2682BcO3CPWAy"; column.GlobalId = "1JCvykjKH71R7_uck4n6hN"; columnType.ObjectTypeOf.GlobalId = "0rNx6sqCH2mOt1cWOT6zSU"; columnType.MaterialSelect.Associates.GlobalId = "2OfhB1Dcz2cAdV$CDh9PHV"; column.MaterialSelect.Associates.GlobalId = "3bTNkVsf9099xrALHA6WhF"; }
private static ICurve getICurveFromIfcCurve(IfcCurve ifcCurve, ViewportLayout viewportLayout1 = null, Transformation entityTrs = null) { ICurve result = null; if (ifcCurve is IfcConic) { IfcConic ifcConic = (IfcConic)ifcCurve; Plane pln = getPlaneFromPosition((IfcPlacement)ifcConic.Position); if (ifcConic is IfcCircle) { IfcCircle ifcCircle = (IfcCircle)ifcCurve; Circle circle = new Circle(pln, ifcCircle.Radius); result = circle; } else { IfcEllipse ifcEllipse = (IfcEllipse)ifcConic; Ellipse ellipse = new Ellipse(pln, pln.Origin, ifcEllipse.SemiAxis1, ifcEllipse.SemiAxis2); result = ellipse; } } else if (ifcCurve is IfcPolyline) { IfcPolyline p = (IfcPolyline)ifcCurve; Point3D[] points = new Point3D[p.Points.Count]; for (int i = 0; i < p.Points.Count; i++) { points[i] = getPoint3DFromIfcCartesianPoint(p.Points[i]); } LinearPath lp = new LinearPath(points); result = lp; } else if (ifcCurve is IfcCompositeCurve) // verificare sense e transition { IfcCompositeCurve cc = (IfcCompositeCurve)ifcCurve; result = new CompositeCurve(); foreach (IfcCompositeCurveSegment ccSegment in cc.Segments) { ICurve segment = getICurveFromIfcCurve(ccSegment.ParentCurve, viewportLayout1, entityTrs); if (segment != null) { ((CompositeCurve)result).CurveList.Add(segment); } else { result = null; break; } } } else if (ifcCurve is IfcTrimmedCurve) { IfcTrimmedCurve tc = (IfcTrimmedCurve)ifcCurve; ICurve basisCurve = getICurveFromIfcCurve(tc.BasisCurve, viewportLayout1, entityTrs); if (basisCurve != null) { ICurve trimCurve = null; if (tc.MasterRepresentation == IfcTrimmingPreference.PARAMETER) { double startParam = tc.Trim1.IfcParameterValue * Math.PI / 180; double endParam = tc.Trim2.IfcParameterValue * Math.PI / 180; if (tc.SenseAgreement) { if (startParam > endParam) { startParam = startParam - Math.PI * 2; } basisCurve.SubCurve(startParam, endParam, out trimCurve); } else { if (endParam > startParam) { endParam = endParam - Math.PI * 2; } basisCurve.SubCurve(endParam, startParam, out trimCurve); trimCurve.Reverse(); } result = trimCurve; //new CompositeCurve(trimCurve); } else if (tc.MasterRepresentation == IfcTrimmingPreference.CARTESIAN) { debug += "IfcTrimmed cartesianPoint not supported: \n"; } else { debug += "IfcTrimmed not supported: \n"; } } } else { if (!debug.Contains("IfcCurve not supported: " + ifcCurve.KeyWord)) { debug += "IfcCurve not supported: " + ifcCurve.KeyWord + "\n"; } } return(result); }