public IXbimSolid CreateSolid(IfcHalfSpaceSolid ifcSolid)
 {
     return(_engine.CreateSolid(ifcSolid));
 }
示例#2
0
        private static Solid getSolidFromIfcBooleanClippingResult(IfcBooleanClippingResult bcr)
        {
            Solid op1 = null, op2 = null;
            Solid mmm = null;

            Entity e;

            if (bcr.FirstOperand is IfcBooleanClippingResult)
            {
                op1 = getSolidFromIfcBooleanClippingResult((IfcBooleanClippingResult)bcr.FirstOperand);
            }
            else
            {
                e = getEntityFromIfcRepresentationItem((IfcRepresentationItem)bcr.FirstOperand);

                if (e != null)// && (e is Solid || e is Mesh))
                {
                    if (e is Mesh)
                    {
                        op1 = ((Mesh)e).ConvertToSolid();
                    }
                    else
                    {
                        op1 = (Solid)e;
                    }
                }
            }

            //m = getMeshFromIfcRepresentationItem((IfcRepresentationItem)bcr.SecondOperand);

            //if (m != null)
            //    op2 = m.ConvertToSolid();

            if (bcr.SecondOperand is IfcPolygonalBoundedHalfSpace)
            {
                IfcPolygonalBoundedHalfSpace polB = (IfcPolygonalBoundedHalfSpace)bcr.SecondOperand;

                IfcPlane baseSurface = (IfcPlane)polB.BaseSurface;

                Plane cutPln = Conversion.getPlaneFromPosition(baseSurface.Position);


                devDept.Eyeshot.Entities.Region r = new RectangularRegion(cutPln, 100, 100, true);
                mmm = r.ExtrudeAsSolid(cutPln.AxisZ * 0.1, 0.1);


                Plane boundaryPlane = Conversion.getPlaneFromPosition(polB.Position);

                Align3D align = new Align3D(Plane.XY, boundaryPlane);

                ICurve boundary = getICurveFromIfcCurve(polB.PolygonalBoundary);

                if (boundary != null)
                {
                    devDept.Eyeshot.Entities.Region region = new devDept.Eyeshot.Entities.Region(boundary);

                    region.TransformBy(align);

                    Vector3D extDir = boundaryPlane.AxisZ;

                    op2 = region.ExtrudeAsSolid(extDir * 20, 0.1); // 0.1 tolerance must be computed according to object size

                    if (!polB.AgreementFlag)
                    {
                        cutPln.Flip();
                    }

                    op2.CutBy(cutPln);
                }
            }
            else if (bcr.SecondOperand is IfcHalfSpaceSolid)
            {
                IfcHalfSpaceSolid hs = (IfcHalfSpaceSolid)bcr.SecondOperand;

                IfcPlane ip = (IfcPlane)hs.BaseSurface;

                Plane pln = Conversion.getPlaneFromPosition(ip.Position);

                if (!hs.AgreementFlag)
                {
                    pln.Flip();
                }

                if (op1 != null)
                {
                    op1.CutBy(pln);
                }
                return(op1);
            }

            if (op1 == null || op2 == null)
            {
                return(null);
            }

            //op1.TransformBy(trs);
            //op2.TransformBy(trs);

            //viewportLayout1.Entities.Add(op1, testLayer, Color.Red);
            //viewportLayout1.Entities.Add(op2, testLayer, Color.Blue);
            //return null;

            Solid[] result;

            double tolerance = 0.01;

            switch (bcr.Operator)
            {
            case IfcBooleanOperator.DIFFERENCE:
                result = Solid.Difference(op1, op2, tolerance);        //su dll nuova e' possibile inserire parametro di tolleranza
                break;

            case IfcBooleanOperator.UNION:
                result = Solid.Union(op1, op2, tolerance);
                break;

            case IfcBooleanOperator.INTERSECTION:
                result = Solid.Intersection(op1, op2, tolerance);
                break;

            default:
                return(null);
            }

            //WriteSTL ws = new WriteSTL(new Entity[] { op1, op2, mmm }, new Layer[] { new Layer("Default") }, new Dictionary<string, Block>(), @"c:\devdept\booleanError\gino" + count + ".stl", 0.01, true);
            //count++;
            //ws.DoWork();

            if (result != null)
            {
                return(result[0]);
            }
            else
            {
                WriteSTL ws = new WriteSTL(new Entity[] { op1, op2 }, new Layer[] { new Layer("Default") }, new Dictionary <string, Block>(), @"c:\devdept\booleanError\gino" + bcr.Index + ".stl", 0.01, true);
                count++;
                ws.DoWork();
                debug += "Error in boolean operation\n";
                return(op1);
            }
        }