public void Polyline2DExceptionsTest(string operand) { var operandStack = new Stack(); operandStack.Push(operand); var operation = OperationName.POLYLINE2D; Assert.Throws <ArgumentException>( () => ConstructionOperations.ExecuteOperation(operation, operandStack)); }
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); }
public void PlaneTest() { var operandStack = new Stack(); operandStack.Push("[0,0,2],-2"); ConstructionOperations.ExecuteOperation(OperationName.PLANE, operandStack); Assert.Single(operandStack); var response = operandStack.Pop(); Assert.IsAssignableFrom <IfcPlane>(response); Assert.Equal(0, ((IfcPlane)response).Position.Axis.DirectionRatios[0].Value); Assert.Equal(0, ((IfcPlane)response).Position.Axis.DirectionRatios[1].Value); Assert.Equal(2, ((IfcPlane)response).Position.Axis.DirectionRatios[2].Value); Assert.Equal(0, ((IfcPlane)response).Position.Location.Coordinates[0].Value); Assert.Equal(0, ((IfcPlane)response).Position.Location.Coordinates[1].Value); Assert.Equal(-1, ((IfcPlane)response).Position.Location.Coordinates[2].Value); }
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); }
public void Polyline2DTest() { var operandStack = new Stack(); operandStack.Push("[[0,0],[1.0,1.0],[1,0]]"); var operation = OperationName.POLYLINE2D; ConstructionOperations.ExecuteOperation(operation, operandStack); Assert.Single(operandStack); var response = operandStack.Pop(); Assert.IsType <IfcPolyline>(response); Assert.Collection(((IfcPolyline)response).Points, p0 => { Assert.Equal(0, p0.Coordinates[0].Value); Assert.Equal(0, p0.Coordinates[1].Value); }, p1 => { Assert.Equal(1, p1.Coordinates[0].Value); Assert.Equal(1, p1.Coordinates[1].Value); }, p2 => { Assert.Equal(1, p2.Coordinates[0].Value); Assert.Equal(0, p2.Coordinates[1].Value); }); }
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); }
public void IntersectionTest() { var operandStack = new Stack(); IfcCsgPrimitive3D first = new IfcBlock(new IfcAxis2Placement3D(new IfcCartesianPoint(0, 0, 0), null, null), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1), new IfcPositiveLengthMeasure(1)); IfcCsgPrimitive3D 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(first); operandStack.Push(second); ConstructionOperations.ExecuteOperation(OperationName.INTERSECTION, operandStack); Assert.Single(operandStack); var response = operandStack.Pop(); Assert.IsType <IfcBooleanResult>(response); Assert.Equal(IfcBooleanOperator.INTERSECTION, ((IfcBooleanResult)response).Operator); Assert.Equal(0, ((IfcBlock)((IfcBooleanResult)response).FirstOperand).Position.Location.Coordinates[0].Value); Assert.Equal(0.5, ((IfcBlock)((IfcBooleanResult)response).SecondOperand).Position.Location.Coordinates[0].Value); }
public void Circleline2DTest() { var operandStack = new Stack(); operandStack.Push("[0.5, -0.5]"); // center operandStack.Push("1.5"); // radius operandStack.Push("180"); // start parameter operandStack.Push("90"); // end parameter var operation = OperationName.CIRCLELINE2D; ConstructionOperations.ExecuteOperation(operation, operandStack); Assert.Single(operandStack); var response = operandStack.Pop(); Assert.IsType <IfcTrimmedCurve>(response); IfcTrimmedCurve curve = (IfcTrimmedCurve)response; Assert.IsType <IfcCircle>(curve.BasisCurve); IfcCircle circle = (IfcCircle)curve.BasisCurve; Assert.Equal(0.5, ((IfcAxis2Placement2D)circle.Position).Location.Coordinates[0].Value); Assert.Equal(-0.5, ((IfcAxis2Placement2D)circle.Position).Location.Coordinates[1].Value); Assert.Equal(1, ((IfcAxis2Placement2D)circle.Position).RefDirection.DirectionRatios[0].Value); Assert.Equal(0, ((IfcAxis2Placement2D)circle.Position).RefDirection.DirectionRatios[1].Value); Assert.Equal(1.5, circle.Radius.Value.Value); var trim1Enumerator = curve.Trim1.GetEnumerator(); trim1Enumerator.MoveNext(); Assert.Equal(180, ((IfcParameterValue)trim1Enumerator.Current).Value); var trim2Enumerator = curve.Trim2.GetEnumerator(); trim2Enumerator.MoveNext(); Assert.Equal(90, ((IfcParameterValue)trim2Enumerator.Current).Value); Assert.True(curve.SenseAgreement.Value); Assert.Equal(IfcTrimmingPreference.PARAMETER, curve.MasterRepresentation); }
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); }
public static IfcRepresentationItem ParseConstructionString(string expression) { Stack <OperationName> operationStack = new Stack <OperationName>(); Stack operandStack = new Stack(); StringBuilder stringBuffer = new StringBuilder(); for (int i = 0; i < expression.Length; ++i) { switch (expression[i]) { case '(': // parenthesis are opened after operation operationStack.Push((OperationName)Enum.Parse(typeof(OperationName), stringBuffer.ToString())); stringBuffer.Clear(); break; case ')': // parenthesis are closed after operand if (stringBuffer.Length > 0) { //stringBuffer could be empty if argument was a function closed with a ')' operandStack.Push(stringBuffer.ToString()); } stringBuffer.Clear(); ConstructionOperations.ExecuteOperation(operationStack.Pop(), operandStack); break; case ' ': // Remove spaces break; case '\n': // Remove newlines break; case '\t': //remove tabs break; case '{': //braces are opened at the start of an array operandStack.Push('{'); //braces are added to the operand stack to mark the end of the array stringBuffer.Clear(); break; case '}': //braces are closed at the end of an array if (stringBuffer.Length > 0) { //stringBuffer could be empty if argument was a function closed with a ')' operandStack.Push(stringBuffer.ToString()); } stringBuffer.Clear(); break; case ';': //marks separation between arguments if (stringBuffer.Length > 0) { //stringBuffer could be empty if argument was a function closed with a ')' operandStack.Push(stringBuffer.ToString()); } stringBuffer.Clear(); break; case '.': // nor an operation, nor an operand starts with a dot if (stringBuffer.Length > 0) { stringBuffer.Append(expression[i]); } break; default: stringBuffer.Append(expression[i]); break; } } if (operandStack.Count != 1) { // operand stack should contain the result throw new ArgumentException(string.Format("Could not parse geometric representation expression: {0}", expression)); } return((IfcRepresentationItem)operandStack.Pop()); }
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); }); }