Esempio n. 1
0
        executeCLKS(SelectionSet ss0 = null)
        {
            hLnkAdds = new List <Handle>();
            hLnkFixs = new List <Handle>();
            winResults wResults = FormHandler.fHandler.wResults;

            Application.ShowModelessWindow(wResults);

            ListBox lbxAdd = wResults.lbxAdd;

            lbxAdd.Items.Clear();
            lbxAdd.Height = 220;

            ListBox lbxFix = wResults.lbxFix;

            lbxFix.Items.Clear();
            lbxFix.Height   = 220;
            wResults.Height = 565;

            bool     exists;
            string   nameDict = "";
            ObjectId idDict   = ObjectId.Null;
            ObjectId idPnt    = ObjectId.Null;

            List <ObjectId> ids    = getBlockRefs();
            List <ObjectId> idsPnt = getPoints();
            List <ObjectId> idsLdr = getLeaders();

            Handle hPntX = new Handle();

            if (ids != null && ids.Count > 0)
            {
                wResults.pBar1.Maximum = ids.Count;
                int     i = 0;
                Point3d pnt3dIns;

                ObjectId idGradeTagDict = Dict.getNamedDictionary("GradeTagDict", out exists);
                List <DBDictionaryEntry> entriesGradeTagDict = idGradeTagDict.getEntries();

                ObjectId idFlTagDict = Dict.getNamedDictionary("FlTagDict", out exists);
                List <DBDictionaryEntry> entriesFlTagDict = idFlTagDict.getEntries();
                List <DBDictionaryEntry> entries          = null;

                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    foreach (ObjectId idBlkRef in ids)
                    {
                        ++i;
                        Debug.Print(i.ToString());

                        string nameBlkRef = Blocks.getBlockRefName(idBlkRef).ToUpper();
                        switch (nameBlkRef)
                        {
                        case "GRADETAG":
                            entries  = entriesGradeTagDict;
                            nameDict = "GradeTagDict";
                            idDict   = idGradeTagDict;
                            break;

                        case "FLTAG":
                            entries  = entriesFlTagDict;
                            nameDict = "FlTagDict";
                            idDict   = idFlTagDict;
                            break;
                        }
                        bool fix;

                        bool isValid = utility1.isValidObjInDictionary(idBlkRef, entries, nameDict, idDict, out fix, out hPntX);

                        if (isValid)
                        {
                            if (fix)
                            {
                                hLnkFixs.Add(hPntX);
                            }
                        }
                        else
                        {
                            using (BaseObjs._acadDoc.LockDocument())
                            {
                                try
                                {
                                    BlockReference br = (BlockReference)tr.GetObject(idBlkRef, OpenMode.ForRead);
                                    pnt3dIns = br.Position;
                                    //Debug.Print(string.Format("{0:F3},{1:F3},{2:F3}", pnt3dIns.X, pnt3dIns.Y, pnt3dIns.Z));

                                    ObjectId idLdr = findLeader(pnt3dIns, idsLdr);
                                    if (idLdr == ObjectId.Null)
                                    {
                                        continue;
                                    }

                                    Point3d pnt3dLdrBeg = idLdr.getBegPnt();
                                    Point3d pnt3dPnt    = Point3d.Origin;

                                    bool found = false;

                                    try
                                    {
                                        foreach (ObjectId id in idsPnt)
                                        {
                                            pnt3dPnt = id.getCogoPntCoordinates();

                                            if ((pnt3dPnt - pnt3dLdrBeg) == v3d0)
                                            {
                                                found = true;
                                                idPnt = id;
                                                break;
                                            }
                                            else if (System.Math.Round(pnt3dPnt.getDistance(pnt3dLdrBeg)) < .001)
                                            {
                                                found = true;
                                                idPnt = id;
                                                break;
                                            }
                                        }
                                    }
                                    catch (System.Exception ex)
                                    {
                                        Application.ShowAlertDialog(string.Format("{0} line 149", ex.Message));
                                    }

                                    if (!found)
                                    {
                                        continue;
                                    }

                                    string desc = string.Empty;

                                    try
                                    {
                                        switch (nameBlkRef)
                                        {
                                        case "GRADETAG":
                                            desc = Blocks.getBlockRefAttributeValue(idBlkRef, "TOPTXT");
                                            desc = desc.Replace(")", "");
                                            desc = desc.Replace("(", "");
                                            if (desc == "")
                                            {
                                                idBlkRef.delete();
                                                continue;
                                            }
                                            switch (desc)
                                            {
                                            case "FF":
                                                utility1.checkFF(idBlkRef, pnt3dPnt);
                                                addOrphanToDicts("GradeTagDict", idPnt.getHandle(), idBlkRef.getHandle(), idLdr.getHandle());
                                                //Debug.Print(idPnt.getHandle().ToString());
                                                break;

                                            case "TC":
                                                utility1.checkTC(idBlkRef, pnt3dPnt);
                                                addOrphanToDicts("GradeTagDict", idPnt.getHandle(), idBlkRef.getHandle(), idLdr.getHandle());
                                                //Debug.Print(idPnt.getHandle().ToString());
                                                break;
                                            }
                                            break;

                                        case "FLTAG":
                                            desc = Blocks.getBlockRefAttributeValue(idBlkRef, "BOTTXT");
                                            desc = desc.Replace(")", "");
                                            desc = desc.Replace("(", "");
                                            if (desc == "")
                                            {
                                                idBlkRef.delete();
                                                continue;
                                            }
                                            utility1.checkFL(idBlkRef, pnt3dPnt);
                                            addOrphanToDicts("FlTagDict", idPnt.getHandle(), idBlkRef.getHandle(), idLdr.getHandle());
                                            //Debug.Print(idPnt.getHandle().ToString());

                                            break;
                                        }
                                    }
                                    catch (System.Exception ex)
                                    {
                                        Application.ShowAlertDialog(string.Format("{0} line 198", ex.Message));
                                    }
                                }
                                catch (Autodesk.AutoCAD.Runtime.Exception ex5)
                                {
                                    Autodesk.AutoCAD.ApplicationServices.Core.Application.ShowAlertDialog(string.Format("{0} line 204", ex5.Message));
                                }
                            }
                        }
                        wResults.pBar1.Value = i;
                    }
                    tr.Commit();
                }
            }

            wResults.addControls(wResults, lbxAdd, hLnkAdds);
            wResults.addControls(wResults, lbxFix, hLnkFixs);

            using (BaseObjs._acadDoc.LockDocument())
            {
                Dict.getNamedDictionary("CLKS", out exists);
            }

            wResults.pBar1.Value = 0;
        }
Esempio n. 2
0
        public void addControls(winResults wResults, ListBox lbx, List <Handle> hLnk)
        {
            int n = hLnk.Count;

            if (n > 0)
            {
                System.Math.DivRem(n, 2, out rem);
                half = n / 2;
                if (rem == 1)
                {
                    half++;
                }

                if (half > 10)
                {
                    lbx.Height      += (1 + half - 10) * (btnH + buf);
                    wResults.Height += (half - 10) * (btnH + buf);
                }
                else
                {
                    half = 10;
                }

                if (lbx.Name == "lbxAdd")
                {
                    halfAdd = half;
                }
                if (lbx.Name == "lbxFix")
                {
                    halfFix = half;
                }

                col = -1;
                int colX = 0;
                int rowY = 0;
                for (itm = 0; itm < n; itm += half)
                {
                    col++;
                    colX = buf + itm / half * btnW;
                    for (row = 0; row < half; row++)
                    {
                        if ((itm + row) == n)
                        {
                            break;
                        }
                        rowY = row * (btnH + buf);

                        string h = hLnk[col * half + row].ToString();
                        //Debug.Print(h.ToString());

                        Button btn = new Button();
                        btn.Name    = h;
                        btn.Content = h;
                        btn.Height  = btnH;
                        btn.Width   = btnW;
                        //btn.Location = new System.Drawing.Point(colX, rowY);

                        btn.MouseDown += btn_MouseDown;
                        lbx.Items.Add(btn);
                    }
                }

                switch (lbx.Name)
                {
                case "lbxAdd":
                    lblCountAdd.Text = n.ToString();
                    break;

                case "lbxFix":
                    lblCountFix.Text = n.ToString();
                    break;
                }
            }
            return;
        }
Esempio n. 3
0
 private FormHandler()
 {
     wResults = new winResults();
 }