Пример #1
0
        private void CreateBox()
        {
#if DEBUG
            double a = 80, b = 4.2, c = 2.6, d = 0.8;//dx  dy dz chamfer

            List <Point3D> pts = new List <Point3D>();
            pts.Add(new Point3D(0, -d, 0));
            pts.Add(new Point3D(0, b + d, 0));
            pts.Add(new Point3D(0, b, d));
            pts.Add(new Point3D(0, b, c));
            pts.Add(new Point3D(0, 0, c));
            pts.Add(new Point3D(0, 0, d));
            pts.Add(new Point3D(0, -d, 0));

            LinearPath lp  = new LinearPath(pts);
            Region     r   = new Region(lp);
            Mesh       box = r.ExtrudeAsMesh(new Vector3D(a, 0, 0), 0.01, Mesh.natureType.Plain);

            Transformation trans = new Transformation();
            trans.Translation(new Vector3D(-a / 2, -0.1, -0.1));
            box.TransformBy(trans);

            eyeshot.Entities.Add(box, 0, Color.Red);


            eyeshot.Invalidate();
            eyeshot.SetView(viewType.Left);
            eyeshot.ZoomFit();

            WriteSTL wStl = new WriteSTL(eyeshot, "d:/ChamferBox.stl");
            wStl.DoWork();
#endif
        }
Пример #2
0
        private void exportButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            string theFilter = "STandard for the Exchange of Product (*.step)|*.step|" + "Initial Graphics Exchange Specification (*.iges)|*.iges";

            saveFileDialog1.Filter = theFilter;

            saveFileDialog1.AddExtension    = true;
            saveFileDialog1.CheckPathExists = true;

            var result = saveFileDialog1.ShowDialog();

            if (result.Value)
            {
                WriteFileAsync wfa        = null;
                WriteParams    dataParams = null;
                switch (saveFileDialog1.FilterIndex)
                {
                case 1:
                    dataParams = new WriteParamsWithMaterials(model1);
                    wfa        = new WriteOBJ((WriteParamsWithMaterials)dataParams, saveFileDialog1.FileName);
                    break;

                case 2:
                    dataParams = new WriteParams(model1);
                    wfa        = new WriteSTL(dataParams, saveFileDialog1.FileName);
                    break;

                case 3:
                    dataParams = null;
                    wfa        = new WriteLAS(model1.Entities.Where(x => x is FastPointCloud).FirstOrDefault() as FastPointCloud, saveFileDialog1.FileName);
                    break;

                case 4:
                    dataParams = new WriteParamsWithMaterials(model1);
                    wfa        = new WriteWebGL((WriteParamsWithMaterials)dataParams, model1.DefaultMaterial, saveFileDialog1.FileName);
                    break;

#if NURBS
                case 5:
                    dataParams = new WriteParamsWithUnits(model1);
                    wfa        = new WriteSTEP((WriteParamsWithUnits)dataParams, saveFileDialog1.FileName);
                    break;

                case 6:
                    dataParams = new WriteParamsWithUnits(model1);
                    wfa        = new WriteIGES((WriteParamsWithUnits)dataParams, saveFileDialog1.FileName);
                    break;
#endif
                }

                model1.StartWork(wfa);

                openButton.IsEnabled   = false;
                saveButton.IsEnabled   = false;
                importButton.IsEnabled = false;
                exportButton.IsEnabled = false;
            }
        }
        private void btnExport_Click(object sender, RoutedEventArgs e)
        {
            //pgBar.IsEnabled=true;
            //pgBar.Value = 90;

            string         objFile        = "Test.Step";
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            var            writeSTL       = new WriteSTEP(new WriteParamsWithUnits(model1), objFile);
            var            RS             = new WriteParamsWithMaterials(model1);

            writeSTL.DoWork();
            saveFileDialog.Title = "Exported Model";
            if (saveFileDialog.ShowDialog() == true)
            {
                saveFileDialog.CheckFileExists = true;
                saveFileDialog.AddExtension    = true;
                saveFileDialog.FileName        = writeSTL.ToString();
                saveFileDialog.Filter          = "Object files (*.STL)|*.STL|All files (*.*)|*.*";
                //saveFileDialog.FileOk(writeSTL);
            }

            string   stlFile = "chair.stl";
            WriteSTL ws      = new WriteSTL(new WriteParams(model1), stlFile, true);

            ws.DoWork();

            string fullPath = String.Format(@"{0}\{1}", System.Environment.CurrentDirectory, stlFile);

            MessageBox.Show(String.Format("File saved in {0}", fullPath));
            WriteSTEP wrStep = new WriteSTEP(new WriteParamsWithUnits(model1), "wing.stp");

            wrStep.DoWork();
            MessageBox.Show("File 'wing.stp' successfully written.");
        }
Пример #4
0
        private void exportStlButton_Click(object sender, RoutedEventArgs e)
        {
            string   stlFile = "chair.stl";
            WriteSTL ws      = new WriteSTL(new WriteParams(model1), stlFile, true);

            ws.DoWork();

            string fullPath = String.Format(@"{0}\{1}", System.Environment.CurrentDirectory, stlFile);

            MessageBox.Show(String.Format("File saved in {0}", fullPath));
        }
Пример #5
0
        //导出
        private void exportButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            string theFilter = "WaveFront OBJ (*.obj)|*.obj|" + "Stereolithography (*.stl)|*.stl|" + "Laser LAS (*.las)|*.las|" + "WebGL (*.html)|*.html";

            theFilter += "|STandard for the Exchange of Product (*.step)|*.step|" + "Initial Graphics Exchange Specification (*.iges)|*.iges";

            saveFileDialog1.Filter          = theFilter;
            saveFileDialog1.AddExtension    = true;
            saveFileDialog1.CheckPathExists = true;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                WriteFileAsync wfa = null;
                WriteParams    dataParams;

                switch (saveFileDialog1.FilterIndex)
                {
                case 1:
                    dataParams = new WriteParamsWithMaterials(model);
                    wfa        = new WriteOBJ((WriteParamsWithMaterials)dataParams, saveFileDialog1.FileName);
                    break;

                case 2:
                    dataParams = new WriteParams(model);
                    wfa        = new WriteSTL(dataParams, saveFileDialog1.FileName);
                    break;

                case 3:
                    dataParams = null;
                    wfa        = new WriteLAS(model.Entities.Where(x => x is FastPointCloud).FirstOrDefault() as FastPointCloud, saveFileDialog1.FileName);
                    break;

                case 4:
                    dataParams = new WriteParamsWithMaterials(model);
                    wfa        = new WriteWebGL((WriteParamsWithMaterials)dataParams, model.DefaultMaterial, saveFileDialog1.FileName);
                    break;

                case 5:
                    dataParams = new WriteParamsWithUnits(model);
                    wfa        = new WriteSTEP((WriteParamsWithUnits)dataParams, saveFileDialog1.FileName);
                    break;

                case 6:
                    dataParams = new WriteParamsWithUnits(model);
                    wfa        = new WriteIGES((WriteParamsWithUnits)dataParams, saveFileDialog1.FileName);
                    break;
                }

                model.StartWork(wfa);
            }
        }
Пример #6
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);
        }
Пример #7
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);
            }
        }