コード例 #1
0
        private static void Plane(Stack operandStack)
        {
            var operand = (string)operandStack.Pop();

            //remove all spaces
            operand.Replace(" ", "");
            int splitPos = operand.IndexOf("],") + 1;

            //plane equation is n[0]*x + n[1]*y + n[2]*z = d
            double[] normal = ParseArray(operand.Substring(0, splitPos));
            double   d      = Double.Parse(operand.Substring(splitPos + 1, operand.Length - splitPos - 1));

            //find point on plane
            double[] point = new double[] { 0, 0, 0 };
            for (int i = 0; i < 3; ++i)
            {
                if (Math.Abs(normal[i]) > 0)
                {
                    point[i] = d / normal[i];
                    break;
                }
            }
            IfcPlane plane = IfcGeom.CreatePlane(point, normal);

            operandStack.Push(plane);
        }
コード例 #2
0
        public void ExtrudeAndRevolveTest()
        {
            //Set up project hierarchy
            IfcProject project = IfcInit.CreateProject(null, null, null);
            IfcSite    site    = IfcInit.CreateSite(null, null, null);

            project.Aggregate(site, null);
            IfcBuilding building = IfcInit.CreateBuilding(null, null, null, null);

            site.Aggregate(building, null);
            IfcBuildingStorey storey = IfcInit.CreateBuildingStorey(null, null, null, null);

            building.Aggregate(storey, null);

            //Create shape representation
            // -- extruded profile shape
            IfcPolyline outerCurve = IfcGeom.CreatePolyLine(new List <double[]>()
            {
                new double[] { -0.5, -0.5 },
                new double[] { -0.5, 0.5 },
                new double[] { 0.5, 0.5 },
                new double[] { 0.5, -0.5 },
                new double[] { -0.5, -0.5 }
            });
            IfcProfileDef profileDef = new IfcArbitraryClosedProfileDef(IfcProfileTypeEnum.AREA,
                                                                        null,
                                                                        outerCurve);
            IfcRepresentationItem extrudedRepresentation = profileDef.Extrude(1).Rotate(new double[] { 45, 0, 45 }).Translate(new double[] { -2, 0, 0 });

            // -- revolved profile shape
            IfcRepresentationItem revolvedRepresentation = profileDef.Revolve(-45,
                                                                              new IfcAxis1Placement(new IfcCartesianPoint(1, 0, 0),
                                                                                                    new IfcDirection(0, 1, 0)),
                                                                              null);

            //Create product with representation and place in storey
            var contextEnum = project.RepresentationContexts.GetEnumerator();

            contextEnum.MoveNext();
            IfcShapeRepresentation shapeRepresentation =
                new IfcShapeRepresentation(contextEnum.Current,
                                           new IfcLabel("extruded square"),
                                           new IfcLabel("SweptSolid"),
                                           new IfcRepresentationItem[] { extrudedRepresentation, revolvedRepresentation });
            IfcProxy product = IfcInit.CreateProxy(null, null, null, storey.ObjectPlacement, null);

            product.Representation = new IfcProductDefinitionShape(null, null, new IfcRepresentation[] { shapeRepresentation });;
            storey.Contains(product, null);

            //Write to IFC file
            using (FileStream fs = File.Create("./swept_geom_test.ifc"))
            {
                project.SerializeToStep(fs, "IFC2X3", null);
            }
        }
コード例 #3
0
        private static void Polyline2D(Stack operandStack)
        {
            string operand = (string)operandStack.Pop();

            //remove all spaces
            operand.Replace(" ", "");
            if ((operand.Length < 12) || !operand.StartsWith("[[") || !operand.EndsWith("]]"))
            {   //operand should represent a two dimensional array with at least two points
                throw new ArgumentException(string.Format("Invalid operand for POLYLINE2D: {0}", operand), "POLYLINE2D");
            }

            // Parse operand
            int             openParenthesis = 2;
            List <double[]> curve           = new List <double[]>();
            List <double>   currentVector   = new List <double>();
            StringBuilder   stringBuffer    = new StringBuilder();

            for (int i = 2; i < operand.Length; ++i)
            {
                switch (operand[i])
                {
                case '[':
                    openParenthesis++;
                    break;

                case ']':
                    openParenthesis--;
                    if (openParenthesis == 1)
                    {       // closing current vector
                        currentVector.Add(Double.Parse(stringBuffer.ToString()));
                        stringBuffer.Clear();
                        curve.Add(currentVector.ToArray());
                        currentVector = new List <double>();
                    }
                    break;

                case ',':
                    if (openParenthesis == 2)
                    {       // starting new coordinate in vector
                        currentVector.Add(Double.Parse(stringBuffer.ToString()));
                        stringBuffer.Clear();
                    }
                    break;

                default:
                    stringBuffer.Append(operand[i]);
                    break;
                }
            }

            // Construct IFC PolyLine
            operandStack.Push(IfcGeom.CreatePolyLine(curve));
        }
コード例 #4
0
        public void RotationTest()
        {
            // ==== Rotate IfcSweptAreaSolid
            var         operandStack = new Stack();
            IfcPolyline outerCurve   = IfcGeom.CreatePolyLine(new List <double[]>()
            {
                new double[] { -1, -1 },
                new double[] { -1, 1 },
                new double[] { 1, 1 },
                new double[] { 1, -1 },
                new double[] { -1, -1 }
            });
            IfcProfileDef profileDef = new IfcArbitraryClosedProfileDef(IfcProfileTypeEnum.AREA,
                                                                        null,
                                                                        outerCurve);

            operandStack.Push(profileDef.Extrude(1));
            operandStack.Push("[-90,0,90]");
            ConstructionOperations.ExecuteOperation(OperationName.ROTATION, operandStack);
            Assert.Single(operandStack);
            var response = operandStack.Pop();

            Assert.IsAssignableFrom <IfcSweptAreaSolid>(response);
            Assert.Equal(0, ((IfcSweptAreaSolid)response).Position.RefDirection.DirectionRatios[0].Value, 10);
            Assert.Equal(0, ((IfcSweptAreaSolid)response).Position.RefDirection.DirectionRatios[1].Value, 10);
            Assert.Equal(-1, ((IfcSweptAreaSolid)response).Position.RefDirection.DirectionRatios[2].Value, 10);

            // ==== Rotate IfcBooleanResult
            operandStack.Clear();
            IfcCsgPrimitive3D union_first = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(0, 0, 0), null, null),
                                                         new IfcPositiveLengthMeasure(1),
                                                         new IfcPositiveLengthMeasure(1),
                                                         new IfcPositiveLengthMeasure(1));
            IfcCsgPrimitive3D union_second = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(0.5, 0.5, 0.5), null, null),
                                                          new IfcPositiveLengthMeasure(1),
                                                          new IfcPositiveLengthMeasure(1),
                                                          new IfcPositiveLengthMeasure(1));

            operandStack.Push(union_first.Union(union_second));
            operandStack.Push("[-90,0,90]");
            ConstructionOperations.ExecuteOperation(OperationName.ROTATION, operandStack);
            Assert.Single(operandStack);
            response = operandStack.Pop();
            Assert.IsAssignableFrom <IfcBooleanResult>(response);
            Assert.Equal(0, ((IfcCsgPrimitive3D)((IfcBooleanResult)response).FirstOperand).Position.RefDirection.DirectionRatios[0].Value, 10);
            Assert.Equal(0, ((IfcCsgPrimitive3D)((IfcBooleanResult)response).FirstOperand).Position.RefDirection.DirectionRatios[1].Value, 10);
            Assert.Equal(-1, ((IfcCsgPrimitive3D)((IfcBooleanResult)response).FirstOperand).Position.RefDirection.DirectionRatios[2].Value, 10);
            Assert.Equal(0, ((IfcCsgPrimitive3D)((IfcBooleanResult)response).SecondOperand).Position.RefDirection.DirectionRatios[0].Value, 10);
            Assert.Equal(0, ((IfcCsgPrimitive3D)((IfcBooleanResult)response).SecondOperand).Position.RefDirection.DirectionRatios[1].Value, 10);
            Assert.Equal(-1, ((IfcCsgPrimitive3D)((IfcBooleanResult)response).SecondOperand).Position.RefDirection.DirectionRatios[2].Value, 10);
        }
コード例 #5
0
        public void CompositeCurve2DTest()
        {
            var operandStack = new Stack();

            operandStack.Push('{');
            operandStack.Push(IfcGeom.CreatePolyLine(new List <double[]>()
            {
                new double[] { -0.5, -0.5 },
                new double[] { 0, 0 }
            }));
            operandStack.Push(IfcGeom.CreatePolyLine(new List <double[]>()
            {
                new double[] { 0, 0 },
                new double[] { 0.5, 0.5 }
            }));
            var operation = OperationName.COMPOSITE_CURVE2D;

            ConstructionOperations.ExecuteOperation(operation, operandStack);
            Assert.Single(operandStack);
            var response = operandStack.Pop();

            Assert.IsType <IfcCompositeCurve>(response);
            IfcCompositeCurve curve = (IfcCompositeCurve)response;

            Assert.Equal(2, curve.Segments.Count);
            IfcCompositeCurveSegment curve0 = curve.Segments[0];

            Assert.Equal(IfcTransitionCode.CONTINUOUS, curve0.Transition);
            Assert.True(curve0.SameSense.Value);
            Assert.Equal(-0.5, ((IfcPolyline)curve0.ParentCurve).Points[0].Coordinates[0].Value);
            Assert.Equal(-0.5, ((IfcPolyline)curve0.ParentCurve).Points[0].Coordinates[1].Value);
            Assert.Equal(0, ((IfcPolyline)curve0.ParentCurve).Points[1].Coordinates[0].Value);
            Assert.Equal(0, ((IfcPolyline)curve0.ParentCurve).Points[1].Coordinates[1].Value);
            IfcCompositeCurveSegment curve1 = curve.Segments[1];

            Assert.Equal(IfcTransitionCode.CONTINUOUS, curve1.Transition);
            Assert.True(curve1.SameSense.Value);
            Assert.Equal(0, ((IfcPolyline)curve1.ParentCurve).Points[0].Coordinates[0].Value);
            Assert.Equal(0, ((IfcPolyline)curve1.ParentCurve).Points[0].Coordinates[1].Value);
            Assert.Equal(0.5, ((IfcPolyline)curve1.ParentCurve).Points[1].Coordinates[0].Value);
            Assert.Equal(0.5, ((IfcPolyline)curve1.ParentCurve).Points[1].Coordinates[1].Value);
        }
コード例 #6
0
        public void CutByPlaneTest()
        {
            // === Cut IfcSweptAreaSolid
            var         operandStack = new Stack();
            IfcPolyline outerCurve   = IfcGeom.CreatePolyLine(new List <double[]>()
            {
                new double[] { 6, 0 },
                new double[] { 6, 1 },
                new double[] { 7, 1 },
                new double[] { 7, 0 },
                new double[] { 6, 0 }
            });
            IfcProfileDef profileDef = new IfcArbitraryClosedProfileDef(IfcProfileTypeEnum.AREA,
                                                                        null,
                                                                        outerCurve);

            operandStack.Push(profileDef.Extrude(1));
            operandStack.Push(IfcGeom.CreatePlane(new double[] { 6.5, 0.5, 0 },
                                                  new double[] { 1, 1, 0 }));
            ConstructionOperations.ExecuteOperation(OperationName.CUT_BY_PLANE, operandStack);
            Assert.Single(operandStack);
            var response = operandStack.Pop();

            Assert.IsAssignableFrom <IfcBooleanClippingResult>(response);
            Assert.IsType <IfcExtrudedAreaSolid>(((IfcBooleanClippingResult)response).FirstOperand);
            Assert.IsType <IfcPlane>(((IfcHalfSpaceSolid)((IfcBooleanClippingResult)response).SecondOperand).BaseSurface);

            // === Cut IfcSweptAreaSolid
            operandStack.Push(response);
            operandStack.Push(IfcGeom.CreatePlane(new double[] { 6.5, 0.5, 0 },
                                                  new double[] { 1, 1, 0 }));
            ConstructionOperations.ExecuteOperation(OperationName.CUT_BY_PLANE, operandStack);
            Assert.Single(operandStack);
            response = operandStack.Pop();
            Assert.IsAssignableFrom <IfcBooleanClippingResult>(response);
            Assert.IsType <IfcBooleanClippingResult>(((IfcBooleanClippingResult)response).FirstOperand);
            Assert.IsType <IfcPlane>(((IfcHalfSpaceSolid)((IfcBooleanClippingResult)response).SecondOperand).BaseSurface);
        }
コード例 #7
0
        public void RevolveTest()
        {
            var         operandStack = new Stack();
            IfcPolyline outerCurve   = IfcGeom.CreatePolyLine(new List <double[]>()
            {
                new double[] { -0.5, -0.5 },
                new double[] { -0.5, 0.5 },
                new double[] { 0.5, 0.5 },
                new double[] { 0.5, -0.5 },
                new double[] { -0.5, -0.5 }
            });
            IfcProfileDef profileDef = new IfcArbitraryClosedProfileDef(IfcProfileTypeEnum.AREA,
                                                                        null,
                                                                        outerCurve);

            operandStack.Push(profileDef);
            operandStack.Push("70.77");
            ConstructionOperations.ExecuteOperation(OperationName.REVOLVE, operandStack);
            Assert.Single(operandStack);
            var response = operandStack.Pop();

            Assert.IsType <IfcRevolvedAreaSolid>(response);
            Assert.Equal(70.77, ((IfcRevolvedAreaSolid)response).Angle.Value);
        }
コード例 #8
0
        public void BooleanOperatorTest()
        {
            //Set up project hierarchy
            IfcProject project = IfcInit.CreateProject(null, null, null);
            IfcSite    site    = IfcInit.CreateSite(null, null, null);

            project.Aggregate(site, null);
            IfcBuilding building = IfcInit.CreateBuilding(null, null, null, null);

            site.Aggregate(building, null);
            IfcBuildingStorey storey = IfcInit.CreateBuildingStorey(null, null, null, null);

            building.Aggregate(storey, null);

            //Create shape representation
            IfcCsgPrimitive3D union_first = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(0, 0, 0), null, null),
                                                         new IfcPositiveLengthMeasure(1),
                                                         new IfcPositiveLengthMeasure(1),
                                                         new IfcPositiveLengthMeasure(1));
            IfcCsgPrimitive3D union_second = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(0.5, 0.5, 0.5), null, null),
                                                          new IfcPositiveLengthMeasure(1),
                                                          new IfcPositiveLengthMeasure(1),
                                                          new IfcPositiveLengthMeasure(1));
            IfcRepresentationItem unionRepresentation = union_first.Union(union_second);

            IfcCsgPrimitive3D diff_first = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(2, 0, 0), null, null),
                                                        new IfcPositiveLengthMeasure(1),
                                                        new IfcPositiveLengthMeasure(1),
                                                        new IfcPositiveLengthMeasure(1));
            IfcCsgPrimitive3D diff_second = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(2.5, 0.5, 0.5), null, null),
                                                         new IfcPositiveLengthMeasure(1),
                                                         new IfcPositiveLengthMeasure(1),
                                                         new IfcPositiveLengthMeasure(1));
            IfcRepresentationItem diffRepresentation = diff_first.Difference(diff_second);

            IfcCsgPrimitive3D inter_first = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(4, 0, 0), null, null),
                                                         new IfcPositiveLengthMeasure(1),
                                                         new IfcPositiveLengthMeasure(1),
                                                         new IfcPositiveLengthMeasure(1));
            IfcCsgPrimitive3D inter_second = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(4.5, 0.5, 0.5), null, null),
                                                          new IfcPositiveLengthMeasure(1),
                                                          new IfcPositiveLengthMeasure(1),
                                                          new IfcPositiveLengthMeasure(1));
            IfcRepresentationItem interRepresentation = inter_first.Intersection(inter_second);
            IfcPolyline           outerCurve          = IfcGeom.CreatePolyLine(new List <double[]>()
            {
                new double[] { 6, 0 },
                new double[] { 6, 1 },
                new double[] { 7, 1 },
                new double[] { 7, 0 },
                new double[] { 6, 0 }
            });
            IfcProfileDef profileDef = new IfcArbitraryClosedProfileDef(IfcProfileTypeEnum.AREA,
                                                                        null,
                                                                        outerCurve);
            IfcSweptAreaSolid cut_reference = profileDef.Extrude(1);
            IfcPlane          plane         = IfcGeom.CreatePlane(new double[] { 6.5, 0.5, 0 },
                                                                  new double[] { 1, 1, 0 });
            IfcRepresentationItem cutRepresentation = cut_reference.ClipByPlane(plane);

            //Create product with representation and place in storey
            var contextEnum = project.RepresentationContexts.GetEnumerator();

            contextEnum.MoveNext();
            IfcShapeRepresentation shapeRepresentation =
                new IfcShapeRepresentation(contextEnum.Current,
                                           new IfcLabel("union shape"),
                                           new IfcLabel("BooleanResult"),
                                           new IfcRepresentationItem[] { unionRepresentation, diffRepresentation, interRepresentation, cutRepresentation });
            IfcProxy product = IfcInit.CreateProxy(null, null, null, storey.ObjectPlacement, null);

            product.Representation = new IfcProductDefinitionShape(null, null, new IfcRepresentation[] { shapeRepresentation });
            storey.Contains(product, null);

            //Write to IFC file
            using (FileStream fs = File.Create("./constructive_geom_test.ifc"))
            {
                project.SerializeToStep(fs, "IFC2X3", null);
            }
        }
コード例 #9
0
        public void Shape()
        {
            var         operandStack = new Stack();
            IfcPolyline outerCurve   = IfcGeom.CreatePolyLine(new List <double[]>()
            {
                new double[] { -0.5, -0.5 },
                new double[] { -0.5, 0.5 },
                new double[] { 0.5, 0.5 },
                new double[] { 0.5, -0.5 },
                new double[] { -0.5, -0.5 }
            });

            operandStack.Push('{');
            operandStack.Push(outerCurve);
            var operation = OperationName.SHAPE;

            ConstructionOperations.ExecuteOperation(operation, operandStack);
            Assert.Single(operandStack);
            var response = operandStack.Pop();

            Assert.IsType <IfcArbitraryClosedProfileDef>(response);
            Assert.Collection(((IfcPolyline)((IfcArbitraryClosedProfileDef)response).OuterCurve).Points,
                              p0 => { Assert.Equal(-0.5, p0.Coordinates[0].Value);
                                      Assert.Equal(-0.5, p0.Coordinates[1].Value); },
                              p1 => { Assert.Equal(-0.5, p1.Coordinates[0].Value);
                                      Assert.Equal(0.5, p1.Coordinates[1].Value); },
                              p2 => { Assert.Equal(0.5, p2.Coordinates[0].Value);
                                      Assert.Equal(0.5, p2.Coordinates[1].Value); },
                              p3 => { Assert.Equal(0.5, p3.Coordinates[0].Value);
                                      Assert.Equal(-0.5, p3.Coordinates[1].Value); },
                              p4 => { Assert.Equal(-0.5, p4.Coordinates[0].Value);
                                      Assert.Equal(-0.5, p4.Coordinates[1].Value); });

            IfcPolyline innerCurve = IfcGeom.CreatePolyLine(new List <double[]>()
            {
                new double[] { -0.25, -0.25 },
                new double[] { -0.25, 0.25 },
                new double[] { 0.25, 0.25 },
                new double[] { 0.25, -0.25 },
                new double[] { -0.25, -0.25 }
            });

            operandStack.Push('{');
            operandStack.Push(outerCurve);
            operandStack.Push(innerCurve);
            ConstructionOperations.ExecuteOperation(operation, operandStack);
            Assert.Single(operandStack);
            response = operandStack.Pop();
            Assert.IsType <IfcArbitraryProfileDefWithVoids>(response);
            Assert.Collection(((IfcPolyline)((IfcArbitraryProfileDefWithVoids)response).OuterCurve).Points,
                              p0 => { Assert.Equal(-0.5, p0.Coordinates[0].Value);
                                      Assert.Equal(-0.5, p0.Coordinates[1].Value); },
                              p1 => { Assert.Equal(-0.5, p1.Coordinates[0].Value);
                                      Assert.Equal(0.5, p1.Coordinates[1].Value); },
                              p2 => { Assert.Equal(0.5, p2.Coordinates[0].Value);
                                      Assert.Equal(0.5, p2.Coordinates[1].Value); },
                              p3 => { Assert.Equal(0.5, p3.Coordinates[0].Value);
                                      Assert.Equal(-0.5, p3.Coordinates[1].Value); },
                              p4 => { Assert.Equal(-0.5, p4.Coordinates[0].Value);
                                      Assert.Equal(-0.5, p4.Coordinates[1].Value); });
            Assert.Single(((IfcArbitraryProfileDefWithVoids)response).InnerCurves);
            var innerCurveEnumerator = ((IfcArbitraryProfileDefWithVoids)response).InnerCurves.GetEnumerator();

            innerCurveEnumerator.MoveNext();
            Assert.Collection(((IfcPolyline)innerCurveEnumerator.Current).Points,
                              p0 => { Assert.Equal(-0.25, p0.Coordinates[0].Value);
                                      Assert.Equal(-0.25, p0.Coordinates[1].Value); },
                              p1 => { Assert.Equal(-0.25, p1.Coordinates[0].Value);
                                      Assert.Equal(0.25, p1.Coordinates[1].Value); },
                              p2 => { Assert.Equal(0.25, p2.Coordinates[0].Value);
                                      Assert.Equal(0.25, p2.Coordinates[1].Value); },
                              p3 => { Assert.Equal(0.25, p3.Coordinates[0].Value);
                                      Assert.Equal(-0.25, p3.Coordinates[1].Value); },
                              p4 => { Assert.Equal(-0.25, p4.Coordinates[0].Value);
                                      Assert.Equal(-0.25, p4.Coordinates[1].Value); });
        }