Ejemplo n.º 1
0
        public static Entity getEntityFromIfcRepresentation(IfcRepresentation rep, ViewportLayout viewportLayout1, Transformation entityTrs = null)
        {
            List <Entity> entityList = new List <Entity>();

            if (viewportLayout1.Blocks.ContainsKey("Representation " + rep.Index.ToString()))
            {
                return(new IfcBlockReference("Representation " + rep.Index.ToString()));
            }

            foreach (IfcRepresentationItem item in rep.Items)
            {
                Entity entity = getEntityFromIfcRepresentationItem(item, viewportLayout1, entityTrs);

                if (entity != null)
                {
                    entityList.Add(entity);
                }
            }
            if (entityList.Count > 1)
            {
                Block b = new Block();

                foreach (Entity e in entityList)
                {
                    b.Entities.Add(e);
                }

                viewportLayout1.Blocks.Add("Representation " + rep.Index.ToString(), b);

                BlockReference br = new IfcBlockReference("Representation " + rep.Index.ToString());

                br.ColorMethod = colorMethodType.byParent;

                return(br);
                //return new IfcBlockReference("Representation " + rep.Index.ToString());
            }
            else if (entityList.Count == 0)
            {
                return(null);
            }

            return(entityList[0]);
        }
Ejemplo n.º 2
0
        public static Entity getEntityFromIfcRepresentationItem(IfcRepresentationItem reprItem, ViewportLayout viewportLayout1 = null, Transformation entityTrs = null)
        {
            Entity result = null;

            if (reprItem is IfcBooleanClippingResult)
            {
                IfcBooleanClippingResult bcr = (IfcBooleanClippingResult)reprItem;

                result = getSolidFromIfcBooleanClippingResult(bcr);
            }
            else if (reprItem is IfcCurve)
            {
                result = (Entity)getICurveFromIfcCurve((IfcCurve)reprItem, viewportLayout1, entityTrs);
            }
            else if (reprItem is IfcExtrudedAreaSolid)
            {
                IfcExtrudedAreaSolid extrAreaSolid = (IfcExtrudedAreaSolid)reprItem;

                // if (!viewportLayout1.Blocks.ContainsKey(extrAreaSolid.Index.ToString()))
                {
                    Plane pln = Conversion.getPlaneFromPosition(extrAreaSolid.Position);

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

                    IfcDirection dir = extrAreaSolid.ExtrudedDirection;

                    Vector3D extDir = new Vector3D(dir.DirectionRatioX, dir.DirectionRatioY, dir.DirectionRatioZ);

                    //extDir.TransformBy(trs * align2);
                    extDir.TransformBy(align);

                    devDept.Eyeshot.Entities.Region region = getRegionFromIfcProfileDef(extrAreaSolid.SweptArea, viewportLayout1);

                    if (region != null)
                    {
                        //region.TransformBy(trs * align2);
                        region.TransformBy(align);

                        result = region.ExtrudeAsMesh(extDir * extrAreaSolid.Depth, 0.1, Mesh.natureType.Plain); // 0.1 tolerance must be computed according to object size

                        //viewportLayout1.Entities.Add(result, 1);
                        //Block b = new Block();
                        //b.Entities.Add(m);
                        //viewportLayout1.Blocks.Add(extrAreaSolid.Index.ToString(), b);
                    }
                }
                // BlockReference br = new IfcBlockReference(trs, extrAreaSolid.Index.ToString());
                // viewportLayout1.Entities.Add(br, 0, Color.Gray);
            }
            else if (reprItem is IfcFaceBasedSurfaceModel)
            {
                IfcFaceBasedSurfaceModel fbs = (IfcFaceBasedSurfaceModel)reprItem;

                result = new Mesh(0, 0, Mesh.natureType.Plain);

                foreach (IfcConnectedFaceSet cfs in fbs.FbsmFaces)
                {
                    Mesh global = new Mesh(0, 0, Mesh.natureType.Plain);

                    foreach (IfcFace face in cfs.CfsFaces)
                    {
                        Point3D[] outerPoints = null;

                        List <Point3D[]> innerPointsList = new List <Point3D[]>();

                        foreach (IfcFaceBound fb in face.Bounds)        // al massimo 2 ? profilo esterno e interno
                        {
                            // bool sense = ifb.mOrientation;

                            if (fb is IfcFaceOuterBound)
                            {
                                IfcFaceOuterBound ifob = (IfcFaceOuterBound)fb;

                                IfcPolyloop pl = (IfcPolyloop)fb.Bound;

                                List <Point3D> pLIst = new List <Point3D>();

                                for (int i = 0; i < pl.Polygon.Count; i++)
                                {
                                    Point3D p = getPoint3DFromIfcCartesianPoint(pl.Polygon[i]);

                                    if (!pLIst.Contains(p))                     // non copio punti uguali !!
                                    {
                                        pLIst.Add(p);
                                    }
                                }

                                outerPoints = pLIst.ToArray();

                                if (!outerPoints[0].Equals(outerPoints[outerPoints.Length - 1]))
                                {
                                    Array.Resize(ref outerPoints, outerPoints.Length + 1);

                                    outerPoints[outerPoints.Length - 1] = (Point3D)outerPoints[0].Clone();
                                }
                                Array.Reverse(outerPoints);
                            }
                            else
                            {
                                IfcFaceBound ifb = (IfcFaceBound)fb;

                                IfcPolyloop inPl = (IfcPolyloop)ifb.Bound;

                                List <Point3D> pLIst = new List <Point3D>();

                                for (int i = 0; i < inPl.Polygon.Count; i++)
                                {
                                    Point3D p = getPoint3DFromIfcCartesianPoint(inPl.Polygon[i]);

                                    if (!pLIst.Contains(p))                     // non copio punti uguali !!
                                    {
                                        pLIst.Add(p);
                                    }
                                }

                                Point3D[] innerPoints = pLIst.ToArray();

                                if (!innerPoints[0].Equals(innerPoints[innerPoints.Length - 1]))
                                {
                                    Array.Resize(ref innerPoints, innerPoints.Length + 1);

                                    innerPoints[innerPoints.Length - 1] = (Point3D)innerPoints[0].Clone();
                                }
                                Array.Reverse(innerPoints);

                                innerPointsList.Add(innerPoints);
                            }
                        }
                        if (outerPoints.Length > 3)
                        {
                            Mesh local;

                            List <LinearPath> boundLp = new List <LinearPath>();

                            boundLp.Add(new LinearPath(outerPoints));

                            foreach (Point3D[] innerPoints in innerPointsList)
                            {
                                boundLp.Add(new LinearPath(innerPoints));
                            }

                            local = new devDept.Eyeshot.Entities.Region(boundLp.ToArray()).ConvertToMesh(0, Mesh.natureType.Plain);

                            global.MergeWith(local, true); // fonde i vertici, sarebbe meglio farla una volta sola alla fine
                        }
                    }
                    ((Mesh)result).MergeWith(global, true);
                }
            }
            else if (reprItem is IfcFacetedBrep)  //controllare
            {
                IfcFacetedBrep facBrep = (IfcFacetedBrep)reprItem;

                IfcClosedShell cs = facBrep.Outer;

                Mesh global = new Mesh(0, 0, Mesh.natureType.Plain);

                foreach (IfcFace face in cs.CfsFaces)
                {
                    Point3D[] outerPoints = null;

                    List <Point3D[]> innerPointsList = new List <Point3D[]>();

                    foreach (IfcFaceBound fb in face.Bounds)
                    {
                        // bool sense = ifb.mOrientation;

                        if (fb is IfcFaceOuterBound)
                        {
                            IfcFaceOuterBound ifob = (IfcFaceOuterBound)fb;

                            IfcPolyloop pl = (IfcPolyloop)fb.Bound;

                            List <Point3D> pLIst = new List <Point3D>();

                            for (int i = 0; i < pl.Polygon.Count; i++)
                            {
                                Point3D p = getPoint3DFromIfcCartesianPoint(pl.Polygon[i]);

                                if (!pLIst.Contains(p))                     // non copio punti uguali !!
                                {
                                    pLIst.Add(p);
                                }
                            }

                            outerPoints = pLIst.ToArray();

                            if (!outerPoints[0].Equals(outerPoints[outerPoints.Length - 1]))
                            {
                                Array.Resize(ref outerPoints, outerPoints.Length + 1);

                                outerPoints[outerPoints.Length - 1] = (Point3D)outerPoints[0].Clone();
                            }
                            Array.Reverse(outerPoints);
                        }
                        else
                        {
                            IfcFaceBound ifb = (IfcFaceBound)fb;

                            IfcPolyloop inPl = (IfcPolyloop)ifb.Bound;

                            List <Point3D> pLIst = new List <Point3D>();

                            for (int i = 0; i < inPl.Polygon.Count; i++)
                            {
                                Point3D p = getPoint3DFromIfcCartesianPoint(inPl.Polygon[i]);

                                if (!pLIst.Contains(p))                     // non copio punti uguali !!
                                {
                                    pLIst.Add(p);
                                }
                            }

                            Point3D[] innerPoints = pLIst.ToArray();

                            if (!innerPoints[0].Equals(innerPoints[innerPoints.Length - 1]))
                            {
                                Array.Resize(ref innerPoints, innerPoints.Length + 1);

                                innerPoints[innerPoints.Length - 1] = (Point3D)innerPoints[0].Clone();
                            }
                            Array.Reverse(innerPoints);

                            innerPointsList.Add(innerPoints);
                        }
                    }
                    if (outerPoints.Length > 3)
                    {
                        Mesh local;

                        List <LinearPath> boundLp = new List <LinearPath>();

                        boundLp.Add(new LinearPath(outerPoints));

                        foreach (Point3D[] innerPoints in innerPointsList)
                        {
                            boundLp.Add(new LinearPath(innerPoints));
                        }
                        local = new devDept.Eyeshot.Entities.Region(boundLp.ToArray()).ConvertToMesh(0, Mesh.natureType.Plain);

                        global.MergeWith(local, true); // fonde i vertici, sarebbe meglio farla una volta sola alla fine
                    }
                }

                result = global;
            }
            //else if (repItem is IfcBoundingBox)
            //{
            //    IfcBoundingBox bBox = (IfcBoundingBox)iRep.Items[0];
            //    m = Mesh.CreateBox(bBox.XDim, bBox.YDim, bBox.ZDim);
            //    m.Translate(bBox.Corner.Coordinates.Item1, bBox.Corner.Coordinates.Item1, bBox.Corner.Coordinates.Item1);
            //}
            else if (reprItem is IfcMappedItem)
            {
                IfcMappedItem mapItem = (IfcMappedItem)reprItem;

                if (!viewportLayout1.Blocks.ContainsKey("MappingSource " + mapItem.MappingSource.Index.ToString()))
                {
                    IfcRepresentationMap reprMapSource = mapItem.MappingSource;

                    Entity mapSource = getEntityFromIfcRepresentation(reprMapSource.MappedRepresentation, viewportLayout1, entityTrs);

                    Block b = new Block();

                    if (mapSource != null)
                    {
                        Plane pln = getPlaneFromPosition((IfcPlacement)reprMapSource.MappingOrigin);

                        Align3D algn = new Align3D(Plane.XY, pln);

                        mapSource.TransformBy(algn);

                        b.Entities.Add(mapSource);
                    }

                    viewportLayout1.Blocks.Add("MappingSource " + mapItem.MappingSource.Index.ToString(), b);
                }

                IfcCartesianTransformationOperator3D iTrs = (IfcCartesianTransformationOperator3D)mapItem.MappingTarget;

                Point3D org = new Point3D(iTrs.LocalOrigin.Coordinates.Item1, iTrs.LocalOrigin.Coordinates.Item2, iTrs.LocalOrigin.Coordinates.Item3);

                Vector3D vectorX;

                if (iTrs.Axis1 != null)
                {
                    vectorX = new Vector3D(iTrs.Axis1.DirectionRatioX, iTrs.Axis1.DirectionRatioY, iTrs.Axis1.DirectionRatioZ);
                }
                else
                {
                    vectorX = new Vector3D(1, 0, 0);
                }
                vectorX = vectorX * iTrs.Scale;

                Vector3D vectorY;

                if (iTrs.Axis2 != null)
                {
                    vectorY = new Vector3D(iTrs.Axis2.DirectionRatioX, iTrs.Axis2.DirectionRatioY, iTrs.Axis2.DirectionRatioZ);
                }
                else
                {
                    vectorY = new Vector3D(0, 1, 0);
                }

                Vector3D vectorZ;

                if (iTrs.Axis1 != null)
                {
                    vectorZ = new Vector3D(iTrs.Axis3.DirectionRatioX, iTrs.Axis3.DirectionRatioY, iTrs.Axis3.DirectionRatioZ);
                }
                else
                {
                    vectorZ = new Vector3D(0, 0, 1);
                }

                if (iTrs is IfcCartesianTransformationOperator3DnonUniform)
                {
                    IfcCartesianTransformationOperator3DnonUniform nut = (IfcCartesianTransformationOperator3DnonUniform)iTrs;

                    vectorY = vectorY * nut.Scale2;

                    vectorZ = vectorZ * nut.Scale3;
                }


                Transformation targetTrs = new Transformation(org, vectorX, vectorY, vectorZ);

                result = new IfcBlockReference(targetTrs, "MappingSource " + mapItem.MappingSource.Index.ToString());
            }
            else if (reprItem is IfcShellBasedSurfaceModel)
            {
                IfcShellBasedSurfaceModel sbs = (IfcShellBasedSurfaceModel)reprItem;

                result = new Mesh(0, 0, Mesh.natureType.Plain);

                foreach (IfcShell cfs in sbs.SbsmBoundary)
                {
                    Mesh global = new Mesh(0, 0, Mesh.natureType.Plain);

                    foreach (IfcFace face in cfs.CfsFaces)
                    {
                        Point3D[] outerPoints = null;

                        List <Point3D[]> innerPointsList = new List <Point3D[]>();

                        foreach (IfcFaceBound fb in face.Bounds)        // al massimo 2 ? profilo esterno e interno
                        {
                            // bool sense = ifb.mOrientation;

                            if (fb is IfcFaceOuterBound)
                            {
                                IfcFaceOuterBound ifob = (IfcFaceOuterBound)fb;

                                IfcPolyloop pl = (IfcPolyloop)fb.Bound;

                                List <Point3D> pLIst = new List <Point3D>();

                                for (int i = 0; i < pl.Polygon.Count; i++)
                                {
                                    Point3D p = getPoint3DFromIfcCartesianPoint(pl.Polygon[i]);

                                    if (!pLIst.Contains(p))                     // non copio punti uguali !!
                                    {
                                        pLIst.Add(p);
                                    }
                                }

                                outerPoints = pLIst.ToArray();

                                if (!outerPoints[0].Equals(outerPoints[outerPoints.Length - 1]))
                                {
                                    Array.Resize(ref outerPoints, outerPoints.Length + 1);

                                    outerPoints[outerPoints.Length - 1] = (Point3D)outerPoints[0].Clone();
                                }
                                Array.Reverse(outerPoints);
                            }
                            else
                            {
                                IfcFaceBound ifb = (IfcFaceBound)fb;

                                IfcPolyloop inPl = (IfcPolyloop)ifb.Bound;

                                List <Point3D> pLIst = new List <Point3D>();

                                for (int i = 0; i < inPl.Polygon.Count; i++)
                                {
                                    Point3D p = getPoint3DFromIfcCartesianPoint(inPl.Polygon[i]);

                                    if (!pLIst.Contains(p))                     // non copio punti uguali !!
                                    {
                                        pLIst.Add(p);
                                    }
                                }

                                Point3D[] innerPoints = pLIst.ToArray();

                                if (!innerPoints[0].Equals(innerPoints[innerPoints.Length - 1]))
                                {
                                    Array.Resize(ref innerPoints, innerPoints.Length + 1);

                                    innerPoints[innerPoints.Length - 1] = (Point3D)innerPoints[0].Clone();
                                }
                                Array.Reverse(innerPoints);

                                innerPointsList.Add(innerPoints);
                            }
                        }
                        if (outerPoints.Length > 3)
                        {
                            Mesh local;

                            List <LinearPath> boundLp = new List <LinearPath>();

                            boundLp.Add(new LinearPath(outerPoints));

                            foreach (Point3D[] innerPoints in innerPointsList)
                            {
                                boundLp.Add(new LinearPath(innerPoints));
                            }

                            //devDept.Eyeshot.Entities.Region localRegion = new devDept.Eyeshot.Entities.Region(boundLp.ToArray());

                            //localRegion.TransformBy(entityTrs);

                            //viewportLayout1.Entities.Add(localRegion, 1);



                            local = new devDept.Eyeshot.Entities.Region(boundLp.ToArray()).ConvertToMesh(0, Mesh.natureType.Plain);



                            global.MergeWith(local, true); // fonde i vertici, sarebbe meglio farla una volta sola alla fine
                        }
                    }
                    ((Mesh)result).MergeWith(global, true);
                }
            }
            else
            {
                if (!debug.Contains("IfcRepresentationItem not supported: " + reprItem.KeyWord))
                {
                    debug += "IfcRepresentationItem not supported: " + reprItem.KeyWord + "\n";
                }
            }

            if (result != null)
            {
                Color color;
                if (tryGetColorFromIfcRepresentationItem(reprItem, out color))
                {
                    result.ColorMethod = colorMethodType.byEntity;

                    result.Color = color;
                }
                else
                {
                    result.ColorMethod = colorMethodType.byParent;
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        private static Entity createOpenings(Entity eyeElement, IfcElement ifcElement, ViewportLayout viewportLayout1)
        {
            if (eyeElement is BlockReference)
            {
                BlockReference brElement = (BlockReference)eyeElement;

                Block blockElement;

                viewportLayout1.Blocks.TryGetValue(brElement.BlockName, out blockElement);

                for (int i = 0; i < blockElement.Entities.Count; i++)
                {
                    blockElement.Entities[i] = createOpenings(blockElement.Entities[i], ifcElement, viewportLayout1);
                }
                return(eyeElement);
            }
            else if (eyeElement is Mesh)
            {
                Mesh m = (Mesh)eyeElement;

                Mesh[] splittedMesh;

                splittedMesh = m.SplitDisjoint();

                if (splittedMesh.Length > 1)
                {
                    debug += "splittedMesh.length > 1\n";
                }

                foreach (IfcRelVoidsElement relVE in ifcElement.HasOpenings)
                {
                    Entity openingEntity = Conversion.getEntityFromIfcProductRepresentation(relVE.RelatedOpeningElement.Representation, viewportLayout1);

                    //viewportLayout1.Entities.Add((Entity)openingEntity.Clone(), 2);

                    if (openingEntity != null && (openingEntity is Mesh || openingEntity is Solid))  //gestire se openingEntity is BlockReference
                    {
                        Transformation opTrs = Conversion.getPlacementTransformtion(relVE.RelatedOpeningElement.Placement);

                        openingEntity.TransformBy(opTrs);

                        Solid openingSolid;

                        if (openingEntity is Mesh)
                        {
                            openingSolid = ((Mesh)openingEntity).ConvertToSolid();
                        }
                        else
                        {
                            openingSolid = (Solid)openingEntity;
                        }

                        for (int i = 0; i < splittedMesh.Length; i++)
                        {
                            //verificare collision? bound box?
                            Solid[] result;

                            Solid entitySolid = splittedMesh[i].ConvertToSolid();

                            //viewportLayout1.Entities.Add((Entity)openingSolid.Clone(), 1, Color.Green);

                            if (Utility.DoOverlap(entitySolid.BoxMin, entitySolid.BoxMax, openingSolid.BoxMin, openingSolid.BoxMax))
                            {
                                result = Solid.Difference(entitySolid, openingSolid, 0.001);

                                if (result != null)
                                {
                                    splittedMesh[i] = result[0].ConvertToMesh();

                                    break;
                                }
                                else
                                {
                                    WriteSTL ws = new WriteSTL(new Entity[] { entitySolid, openingSolid }, new Layer[] { new Layer("Default") }, new Dictionary <string, Block>(), @"c:\devdept\booleanError\" + count + " " + ifcElement.GlobalId + ".stl", 0.01, true);
                                    count++;
                                    ws.DoWork();
                                    debug += "Error in opening boolean operation\n";
                                }
                            }
                        }
                    }
                }
                if (splittedMesh.Length > 1)
                {
                    Block b = new Block();

                    foreach (Mesh mesh in splittedMesh)
                    {
                        b.Entities.Add(mesh);
                    }
                    viewportLayout1.Blocks.Add(ifcElement.GlobalId, b);

                    eyeElement = new IfcBlockReference(ifcElement.GlobalId);
                }
                else
                {
                    eyeElement = splittedMesh[0];
                }
            }
            else
            {
                Solid entitySolid = (Solid)eyeElement;

                foreach (IfcRelVoidsElement relVE in ifcElement.HasOpenings)
                {
                    Entity openingEntity = Conversion.getEntityFromIfcProductRepresentation(relVE.RelatedOpeningElement.Representation, viewportLayout1);

                    if (openingEntity != null && (openingEntity is Mesh || openingEntity is Solid))
                    {
                        Transformation opTrs = Conversion.getPlacementTransformtion(relVE.RelatedOpeningElement.Placement);

                        openingEntity.TransformBy(opTrs);

                        Solid openingSolid;

                        if (openingEntity is Mesh)
                        {
                            openingSolid = ((Mesh)openingEntity).ConvertToSolid();
                        }
                        else
                        {
                            openingSolid = (Solid)openingEntity;
                        }


                        Solid[] result;

                        //viewportLayout1.Entities.Add((Entity)openingSolid.Clone(), 1, Color.Green);

                        result = Solid.Difference(entitySolid, openingSolid, 0.001);

                        if (result != null)
                        {
                            entitySolid = result[0];
                        }
                        else
                        {
                            WriteSTL ws = new WriteSTL(new Entity[] { entitySolid, openingSolid }, new Layer[] { new Layer("Default") }, new Dictionary <string, Block>(), @"c:\devdept\booleanError\" + count + " " + ifcElement.GlobalId + ".stl", 0.01, true);
                            count++;
                            ws.DoWork();
                            debug += "Error in opening boolean operation\n";
                        }
                    }
                }
                eyeElement = entitySolid;
            }
            return(eyeElement);
        }
Ejemplo n.º 4
0
        public static Entity getEntityFromIfcElement(IfcElement ifcElement, ViewportLayout viewportLayout1)
        {
            Entity eyeElement = null;

            Transformation elementTrs = new Transformation(1);

            if (ifcElement.Placement != null)
            {
                elementTrs = Conversion.getPlacementTransformtion(ifcElement.Placement);
            }
            if (ifcElement.Representation != null)
            {
                eyeElement = Conversion.getEntityFromIfcProductRepresentation(ifcElement.Representation, viewportLayout1, elementTrs);
            }
            if (eyeElement != null)
            {
                eyeElement.TransformBy(elementTrs);
            }
            if (ifcElement.IsDecomposedBy.Count > 0)
            {
                Block b = new Block();

                foreach (IfcRelAggregates relAg in ifcElement.IsDecomposedBy)
                {
                    foreach (IfcElement el in relAg.RelatedObjects)
                    {
                        Entity entity = getEntityFromIfcElement(el, viewportLayout1);

                        if (entity != null)
                        {
                            b.Entities.Add(entity);
                        }
                    }
                }
                if (eyeElement != null)
                {
                    b.Entities.Add(eyeElement);
                }

                viewportLayout1.Blocks.Add(ifcElement.GlobalId, b);

                eyeElement = new IfcBlockReference(ifcElement.GlobalId);
            }
            if (eyeElement != null)
            {
                if (ifcElement.HasOpenings.Count > 0)
                {
                    eyeElement = createOpenings(eyeElement, ifcElement, viewportLayout1);
                }
                if (eyeElement is BlockReference)
                {
                    UtilityIfc.loadProperties((IfcBlockReference)eyeElement, ifcElement);
                }
                else
                {
                    IfcMesh ifcMesh;

                    Mesh eyeElementMesh;

                    if (eyeElement is Solid)
                    {
                        Solid eyeElementSolid = (Solid)eyeElement;

                        eyeElementMesh = eyeElementSolid.ConvertToMesh();
                    }
                    else
                    {
                        eyeElementMesh = (Mesh)eyeElement;
                    }
                    Color           color = eyeElementMesh.Color;
                    colorMethodType cmt   = eyeElementMesh.ColorMethod;

                    ifcMesh = new IfcMesh(eyeElementMesh.Vertices, eyeElementMesh.Triangles);

                    ifcMesh.Color       = color;
                    ifcMesh.ColorMethod = cmt;

                    UtilityIfc.loadProperties(ifcMesh, ifcElement);

                    eyeElement = ifcMesh;
                }
            }
            return(eyeElement);
        }