Exemplo n.º 1
0
        private void ProcessHole(View swView, DrawingHole drwhole, string blkname)
        {
            var mpoint = (MathPoint)(_iSwApp.IGetMathUtility()).CreatePoint(
                new[] { drwhole.Cx, drwhole.Cy, drwhole.Cz });

            if (blkname != "")
            {
                SketchBlockDefinition swSbDef = SwModel.SketchManager.MakeSketchBlockFromFile(mpoint, blkname, false, 1,
                                                                                              0);

                if (swSbDef == null)
                {
                    var swBDefs = (object[])SwModel.SketchManager.GetSketchBlockDefinitions();
                    if (swBDefs != null)
                    {
                        foreach (var swTestSbDef in
                            swBDefs.Cast<SketchBlockDefinition>().Where(swTestSbDef => swTestSbDef.FileName == blkname))
                        {
                            swSbDef = swTestSbDef;
                            break;
                        }
                    }
                }

                if (swSbDef != null)
                {
                    var swBInsts = (object[])swSbDef.GetInstances();
                    if (swBInsts != null)
                    {
                        foreach (object t in swBInsts)
                        {
                            var swSbInst = (SketchBlockInstance)t;
                            if (((Feature)swSbInst.GetSketch()).Name == ((Feature)swView.GetSketch()).Name)
                            {
                                swSbInst.Scale2 = drwhole.Radius * 2 * swView.ScaleDecimal * 1000;
                            }
                        }
                    }
                }
            }
            drwhole.IsProcessed = true;
        }
Exemplo n.º 2
0
        public void AddHolesSymbols()
        {
            try
            {
                View swView;
                if (GetSelectedView(out swView))
                {
                    SwModel.ClearSelection();

                    var swBDefs = (object[])SwModel.SketchManager.GetSketchBlockDefinitions();
                    if (swBDefs != null)
                    {
                        foreach (object t in swBDefs)
                        {
                            var swSbDef = (SketchBlockDefinition)t;
                            var swBInsts = (object[])swSbDef.GetInstances();
                            if (swBInsts != null)
                            {
                                foreach (object t1 in swBInsts)
                                {
                                    var swSbInst = (SketchBlockInstance)t1;
                                    if (((Feature)swSbInst.GetSketch()).Name == ((Feature)swView.GetSketch()).Name)
                                    {
                                        swSbInst.Select(true, null);
                                    }
                                }
                            }
                        }
                    }

                    SwModel.DeleteSelection(false);

                    var drwHoles = new LinkedList<DrawingHole>();

                    object plinfoobj;
                    var edges = (object[])swView.GetPolylines7(0, out plinfoobj);
                    var plinfo = (double[])plinfoobj;
                    int plinfoidx = 0;

                    foreach (object t in edges)
                    {
                        Curve crv = null;
                        Face2 swFace = null;
                        Surface swSurface = null;

                        try
                        {
                            var swEdge = (Edge)t;
                            crv = swEdge.IGetCurve();

                            var faces = (object[])swEdge.GetTwoAdjacentFaces2();
                            swFace = (Face2)faces[0];

                            swSurface = (Surface)swFace.GetSurface();
                            if (!swSurface.IsCylinder())
                            {
                                swFace = (Face2)faces[1];
                                swSurface = (Surface)swFace.GetSurface();
                            }
                        }
                        catch
                        {
                            var swSEdge = (SilhouetteEdge)t;
                            if (swSEdge != null)
                            {
                                crv = swSEdge.GetCurve();
                                swFace = swSEdge.GetFace();
                                swSurface = (Surface)swFace.GetSurface();
                            }
                        }
                        if (swFace != null)
                        {
                            if (crv.IsCircle())
                            {
                                var curveprms = (double[])crv.CircleParams;
                                double holeradius = curveprms[6];

                                if (swSurface.IsCylinder())
                                {
                                    var swFeature = (Feature)swFace.GetFeature();
                                    if (swFeature.GetTypeName2().ToLower() == "cut" ||
                                        swFeature.GetTypeName2().ToLower() == "ice")
                                    {
                                        var swExtrData = (ExtrudeFeatureData2)swFeature.GetDefinition();
                                        double holedepth = swExtrData.GetDepth(true);
                                        var newhole = new DrawingHole(crv, holeradius, holedepth,
                                                                      plinfo[plinfoidx + 2], plinfo[plinfoidx + 3],
                                                                      plinfo[plinfoidx + 4]);
                                        drwHoles.AddLast(newhole);
                                    }
                                }
                            }
                        }
                        plinfoidx += 2 + (int)plinfo[plinfoidx + 1] + 7 +
                                     (int)plinfo[plinfoidx + 2 + (int)plinfo[plinfoidx + 1] + 6] * 3;
                    }
                    if (drwHoles.Count > 0)
                    {
                        var drwHolesArr = new DrawingHole[drwHoles.Count];

                        int holeidx = 0;
                        foreach (DrawingHole drwhole in drwHoles)
                        {
                            drwHolesArr[holeidx] = drwhole;
                            holeidx++;
                        }
                        string holeFileName = DrwPathResult + "holes.txt";
                        var drwHoleBlocks = new LinkedList<DrawingHoleBlock>();

                        if (File.Exists(holeFileName))
                        {
                            var reader = new StreamReader(holeFileName, Encoding.GetEncoding(1251));
                            string line;

                            while ((line = reader.ReadLine()) != null)
                            {
                                string[] linearr = line.Split('\t');

                                try
                                {
                                    drwHoleBlocks.AddLast(
                                        new DrawingHoleBlock(DrwPathResult + linearr[2],
                                                             Convert.ToDouble(linearr[0]) / 2000,
                                                             Convert.ToDouble(linearr[1]) / 1000));
                                }
                                catch
                                {
                                }
                            }
                            reader.Close();
                        }

                        var drwHoleBlocksArr = new DrawingHoleBlock[drwHoleBlocks.Count];
                        drwHoleBlocks.CopyTo(drwHoleBlocksArr, 0);

                        string[] blocknames = Directory.GetFiles(DrwPathResult, "*.SLDBLK");
                        int blockidx = 0;

                        for (int i = 0; i < drwHolesArr.Length; i++)
                        {
                            if (!drwHolesArr[i].IsProcessed)
                            {
                                string blockname = "";

                                foreach (DrawingHoleBlock t in drwHoleBlocksArr)
                                {
                                    if (t.Radius == drwHolesArr[i].Radius &&
                                        t.Depth == drwHolesArr[i].Depth)
                                    {
                                        blockname = t.BlockFileName;
                                        break;
                                    }
                                }
                                if (blockname == "")
                                {
                                    while (blocknames.Length > blockidx)
                                    {
                                        blockname = blocknames[blockidx];
                                        blockidx++;

                                        string blockname1 = blockname;
                                        if (drwHoleBlocksArr.Any(t => t.BlockFileName.ToLower() == blockname1.ToLower()))
                                        {
                                            blockname = "";
                                        }
                                        if (blockname != "")
                                            break;
                                    }
                                }
                                ProcessHole(swView, drwHolesArr[i], blockname);

                                for (int j = i + 1; j < drwHolesArr.Length; j++)
                                {
                                    if (!drwHolesArr[j].IsProcessed && drwHolesArr[i].Radius == drwHolesArr[j].Radius &&
                                        drwHolesArr[i].Depth == drwHolesArr[j].Depth)
                                    {
                                        ProcessHole(swView, drwHolesArr[j], blockname);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, MyTitle, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }