Exemple #1
0
        private void btnIncrementNumber_Click(object sender, EventArgs e)
        {
            int i = -1;
            int n = lbItems.Items.Count;

            if (lbItems.SelectedIndices.Count != 0)
            {
                i = lbItems.SelectedIndices[0];
            }
            if (i == -1)
            {
                return;
            }

            PosCopy old = m_PosList[i];
            string  num = (int.Parse(old.newpos) + 1).ToString();

            old.newpos = num;
            PosCopy swold = m_PosList[i - 1];
            string  swnum = (int.Parse(swold.newpos) - 1).ToString();

            swold.newpos = swnum;

            AddMissing();
            SortDisplayList();
            PopulateList();

            i = m_PosList.FindIndex(p => p.newpos == num);
            if (i != -1)
            {
                lbItems.SelectedIndices.Add(i);
            }
        }
        private List <PosCopy> AddMissing(List <PosCopy> list)
        {
            list = RemoveEmpty(list);

            int lastpos = 0;

            foreach (PosCopy copy in list)
            {
                int posno;
                if (int.TryParse(copy.pos, out posno))
                {
                    lastpos = Math.Max(lastpos, posno);
                }
            }
            for (int i = 1; i <= lastpos; i++)
            {
                if (!list.Exists(p => p.pos == i.ToString()))
                {
                    PosCopy copy = new PosCopy();
                    copy.pos = i.ToString();
                    list.Add(copy);
                }
            }

            return(SortList(list));
        }
Exemple #3
0
        private void btnAutoNumber_Click(object sender, EventArgs e)
        {
            bool keepcurrent     = rbKeepExisting.Checked;
            bool numberVarLength = rbNumberVarLength.Checked;

            int startnum = 0;

            if (keepcurrent)
            {
                foreach (PosCopy copy in m_PosList)
                {
                    int num = 0;
                    if (int.TryParse(copy.pos.Trim(), out num))
                    {
                        startnum = Math.Max(startnum, num);
                    }
                }
                startnum++;
            }
            else
            {
                startnum = int.Parse(txtStartNum.Text);
            }

            if (!keepcurrent && (startnum <= 0))
            {
                MessageBox.Show("Lütfen başlangıç numarasını girin.", "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            RemoveEmpty();
            SortList();

            foreach (PosCopy copy in m_PosList)
            {
                if (!keepcurrent || string.IsNullOrEmpty(copy.pos.Trim()))
                {
                    PosCopy original = m_PosList.Find(p => !string.IsNullOrEmpty(p.pos) && p.key == copy.key);
                    if (original == null || (numberVarLength && copy.isVarLength))
                    {
                        // Add a new number
                        copy.newpos = startnum.ToString();
                        startnum++;
                    }
                    else
                    {
                        // Use existing number
                        copy.newpos = original.pos;
                    }
                }
            }

            AddMissing();
            SortDisplayList();
            PopulateList();
        }
Exemple #4
0
        private void ReadPos()
        {
            try
            {
                if (rbGroupVarLength.Checked)
                {
                    m_PosList = PosCopy.ReadAllInSelection(sourceItems, false, PosCopy.PosGrouping.PosKeyDifferentMarker);
                }
                else
                {
                    m_PosList = PosCopy.ReadAllInSelection(sourceItems, false, PosCopy.PosGrouping.PosKeyDifferentMarkerVarLength);
                }

                m_DetachedPosList = new Dictionary <string, List <ObjectId> >();
                Database db = HostApplicationServices.WorkingDatabase;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    foreach (ObjectId id in sourceItems)
                    {
                        RebarPos pos = tr.GetObject(id, OpenMode.ForRead) as RebarPos;
                        if (pos == null)
                        {
                            continue;
                        }
                        if (!pos.Detached)
                        {
                            continue;
                        }
                        if (string.IsNullOrEmpty(pos.Pos))
                        {
                            continue;
                        }

                        if (m_DetachedPosList.ContainsKey(pos.Pos))
                        {
                            m_DetachedPosList[pos.Pos].Add(id);
                        }
                        else
                        {
                            m_DetachedPosList.Add(pos.Pos, new List <ObjectId>()
                            {
                                id
                            });
                        }
                    }
                }

                AddMissing();
                SortDisplayList();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #5
0
        private void btnApplyNumber_Click(object sender, EventArgs e)
        {
            int i = -1;
            int n = lbItems.Items.Count;

            if (lbItems.SelectedIndices.Count != 0)
            {
                i = lbItems.SelectedIndices[0];
            }
            if (i == -1)
            {
                return;
            }

            string num  = txtNumber.Text;
            int    numi = 0;

            if (!int.TryParse(num, out numi) || numi <= 0)
            {
                MessageBox.Show("Lütfen yeni poz numarasını girin.", "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            PosCopy old   = m_PosList[i];
            int     swsel = m_PosList.FindIndex(p => p.newpos == num);
            string  swnum = old.newpos;

            old.newpos = num;

            if (swsel != -1)
            {
                PosCopy swold = m_PosList[swsel];
                swold.newpos = swnum;
            }

            AddMissing();
            SortDisplayList();
            PopulateList();

            i = m_PosList.FindIndex(p => p.newpos == num);
            if (i != -1)
            {
                lbItems.SelectedIndices.Add(i);
            }
        }
Exemple #6
0
        private void AddMissing()
        {
            RemoveEmpty();

            int lastpos = 0;

            foreach (PosCopy copy in m_PosList)
            {
                int posno;
                if (int.TryParse(copy.newpos, out posno))
                {
                    lastpos = Math.Max(lastpos, posno);
                }
            }
            for (int i = 1; i <= lastpos; i++)
            {
                if (!m_PosList.Exists(p => p.newpos == i.ToString()))
                {
                    PosCopy copy = new PosCopy();
                    copy.newpos = i.ToString();
                    m_PosList.Add(copy);
                }
            }
        }
        private bool DrawBOQ()
        {
            using (DrawBOQForm form = new DrawBOQForm())
            {
                // Pos error check
                PromptSelectionResult sel = DWGUtility.SelectAllPosUser();
                if (sel.Status != PromptStatus.OK)
                {
                    return(false);
                }
                ObjectId[] items = sel.Value.GetObjectIds();

                List <PosCheckResult> errors   = PosCheckResult.CheckAllInSelection(items, true, false);
                List <PosCheckResult> warnings = PosCheckResult.CheckAllInSelection(items, false, true);

                if (errors.Count != 0)
                {
                    PosCheckResult.ConsoleOut(errors);
                }
                if (warnings.Count != 0)
                {
                    PosCheckResult.ConsoleOut(warnings);
                }

                if (errors.Count != 0)
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.DisplayTextScreen = true;
                    return(false);
                }

                // Pos similarity check
                if (warnings.Count != 0)
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.DisplayTextScreen = true;
                    PromptKeywordOptions opts = new PromptKeywordOptions("\nMetraja devam edilsin mi? [Evet/Hayir]", "Yes No");
                    PromptResult         res  = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetKeywords(opts);
                    if (res.Status != PromptStatus.OK || res.StringResult == "No")
                    {
                        return(true);
                    }
                }

                if (!form.Init())
                {
                    return(false);
                }

                if (Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(null, form, false) != System.Windows.Forms.DialogResult.OK)
                {
                    return(true);
                }

                List <PosCopy> posList = new List <PosCopy>();
                try
                {
                    posList = PosCopy.ReadAllInSelection(items, true, PosCopy.PosGrouping.PosMarker);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                if (posList.Count == 0)
                {
                    MessageBox.Show("Seçilen grupta poz mevcut değil.", "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return(false);
                }

                posList = RemoveEmpty(posList);
                if (!form.HideMissing)
                {
                    posList = AddMissing(posList);
                }
                posList = SortList(posList);

                PromptPointResult result = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetPoint("Baz noktası: ");
                if (result.Status != PromptStatus.OK)
                {
                    return(true);
                }

                Database db = HostApplicationServices.WorkingDatabase;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    try
                    {
                        BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);

                        BOQTable table = new BOQTable();
                        table.SuspendUpdate();

                        Point3d pt = result.Value;
                        table.TransformBy(Matrix3d.Displacement(pt.GetAsVector()));
                        table.TransformBy(Matrix3d.Scaling(form.TextHeight, pt));
                        table.Note    = form.TableNote;
                        table.Heading = form.TableHeader;
                        table.Footing = form.TableFooter;

                        table.DisplayUnit = form.DisplayUnit;
                        table.Precision   = form.Precision;

                        table.Multiplier = form.Multiplier;

                        BOQStyle style = form.TableStyle;
                        table.ColumnDef = style.Columns;

                        table.TextStyleId    = style.TextStyleId;
                        table.HeadingStyleId = style.HeadingStyleId;
                        table.FootingStyleId = style.FootingStyleId;

                        table.PosLabel               = style.PosLabel;
                        table.CountLabel             = style.CountLabel;
                        table.DiameterLabel          = style.DiameterLabel;
                        table.LengthLabel            = style.LengthLabel;
                        table.ShapeLabel             = style.ShapeLabel;
                        table.TotalLengthLabel       = style.TotalLengthLabel;
                        table.DiameterListLabel      = style.DiameterListLabel;
                        table.DiameterLengthLabel    = style.DiameterLengthLabel;
                        table.UnitWeightLabel        = style.UnitWeightLabel;
                        table.WeightLabel            = style.WeightLabel;
                        table.GrossWeightLabel       = style.GrossWeightLabel;
                        table.MultiplierHeadingLabel = style.MultiplierHeadingLabel;

                        table.MaxRows      = form.TableRows;
                        table.TableSpacing = form.TableMargin;

                        double lengthScale = 1.0;
                        switch (table.DisplayUnit)
                        {
                        case BOQTable.DrawingUnits.Millimeter:
                            lengthScale = 1.0;
                            break;

                        case BOQTable.DrawingUnits.Centimeter:
                            lengthScale = 0.1;
                            break;

                        case BOQTable.DrawingUnits.Decimeter:
                            lengthScale = 0.01;
                            break;

                        case BOQTable.DrawingUnits.Meter:
                            lengthScale = 0.001;
                            break;
                        }

                        // Add rows
                        foreach (PosCopy copy in posList)
                        {
                            if (copy.existing)
                            {
                                string a = string.Empty;
                                string b = string.Empty;
                                string c = string.Empty;
                                string d = string.Empty;
                                string e = string.Empty;
                                string f = string.Empty;

                                if (copy.isVarA)
                                {
                                    a = (copy.minA * lengthScale).ToString("F0") + "~" + (copy.maxA * lengthScale).ToString("F0");
                                }
                                else
                                {
                                    a = (copy.minA * lengthScale).ToString("F0");
                                }
                                if (copy.isVarB)
                                {
                                    b = (copy.minB * lengthScale).ToString("F0") + "~" + (copy.maxB * lengthScale).ToString("F0");
                                }
                                else
                                {
                                    b = (copy.minB * lengthScale).ToString("F0");
                                }
                                if (copy.isVarC)
                                {
                                    c = (copy.minC * lengthScale).ToString("F0") + "~" + (copy.maxC * lengthScale).ToString("F0");
                                }
                                else
                                {
                                    c = (copy.minC * lengthScale).ToString("F0");
                                }
                                if (copy.isVarD)
                                {
                                    d = (copy.minD * lengthScale).ToString("F0") + "~" + (copy.maxD * lengthScale).ToString("F0");
                                }
                                else
                                {
                                    d = (copy.minD * lengthScale).ToString("F0");
                                }
                                if (copy.isVarE)
                                {
                                    e = (copy.minE * lengthScale).ToString("F0") + "~" + (copy.maxE * lengthScale).ToString("F0");
                                }
                                else
                                {
                                    e = (copy.minE * lengthScale).ToString("F0");
                                }
                                if (copy.isVarF)
                                {
                                    f = (copy.minF * lengthScale).ToString("F0") + "~" + (copy.maxF * lengthScale).ToString("F0");
                                }
                                else
                                {
                                    f = (copy.minF * lengthScale).ToString("F0");
                                }

                                table.Items.Add(int.Parse(copy.pos), copy.count, double.Parse(copy.diameter), copy.length1, copy.length2, copy.isVarLength, copy.shapename, a, b, c, d, e, f);
                            }
                            else
                            {
                                table.Items.Add(int.Parse(copy.pos));
                            }
                        }

                        table.ResumeUpdate();

                        table.SetDatabaseDefaults(db);

                        btr.AppendEntity(table);
                        tr.AddNewlyCreatedDBObject(table, true);

                        tr.Commit();
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }

            return(true);
        }
Exemple #8
0
        public static List <PosCopy> ReadAllInSelection(IEnumerable <ObjectId> items, bool skipEmpty, PosGrouping grouping)
        {
            List <PosCopy> poslist = new List <PosCopy>();

            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId id in items)
                {
                    RebarPos pos = tr.GetObject(id, OpenMode.ForRead) as RebarPos;
                    if (pos != null)
                    {
                        // Skip empty pos numbers
                        if (skipEmpty && string.IsNullOrEmpty(pos.Pos))
                        {
                            continue;
                        }
                        // Skip detached pos
                        if (pos.Detached)
                        {
                            continue;
                        }

                        PosCopy copy = null;
                        if (grouping == PosGrouping.PosKey)
                        {
                            copy = poslist.Find(p => p.key == pos.PosKey);
                        }
                        else if (grouping == PosGrouping.PosKeyVarLength && !pos.CalcProperties.IsVarLength)
                        {
                            copy = poslist.Find(p => p.key == pos.PosKey);
                        }
                        else if (grouping == PosGrouping.PosMarker)
                        {
                            copy = poslist.Find(p => p.pos == pos.Pos);
                        }
                        else if (grouping == PosGrouping.PosKeyDifferentMarker)
                        {
                            copy = poslist.Find(p => p.key == pos.PosKey && p.pos == pos.Pos);
                        }
                        else if (grouping == PosGrouping.PosKeyDifferentMarkerVarLength && !pos.CalcProperties.IsVarLength)
                        {
                            copy = poslist.Find(p => p.key == pos.PosKey && p.pos == pos.Pos);
                        }

                        if (copy != null)
                        {
                            copy.list.Add(id);
                            if (pos.IncludeInBOQ)
                            {
                                copy.count += pos.CalcProperties.Count * pos.Multiplier;
                            }
                            copy.scale = Math.Max(copy.scale, pos.Scale);
                            copy.x     = Math.Min(copy.x, pos.BasePoint.X);
                            copy.y     = Math.Min(copy.y, pos.BasePoint.Y);
                        }
                        else
                        {
                            copy     = new PosCopy();
                            copy.key = pos.PosKey;
                            copy.list.Add(id);
                            copy.pos      = pos.Pos;
                            copy.newpos   = pos.Pos;
                            copy.existing = true;
                            if (pos.IncludeInBOQ)
                            {
                                copy.count = pos.CalcProperties.Count * pos.Multiplier;
                            }
                            copy.diameter = pos.Diameter;
                            copy.length   = pos.Length;

                            copy.a = pos.A;
                            copy.b = pos.B;
                            copy.c = pos.C;
                            copy.d = pos.D;
                            copy.e = pos.E;
                            copy.f = pos.F;

                            RebarPos.CalculatedProperties calc = pos.CalcProperties;
                            copy.fieldCount = calc.FieldCount;
                            copy.minA       = calc.MinA;
                            copy.minB       = calc.MinB;
                            copy.minC       = calc.MinC;
                            copy.minD       = calc.MinD;
                            copy.minE       = calc.MinE;
                            copy.minF       = calc.MinF;
                            copy.maxA       = calc.MaxA;
                            copy.maxB       = calc.MaxB;
                            copy.maxC       = calc.MaxC;
                            copy.maxD       = calc.MaxD;
                            copy.maxE       = calc.MaxE;
                            copy.maxF       = calc.MaxF;
                            copy.isVarA     = calc.IsVarA;
                            copy.isVarB     = calc.IsVarB;
                            copy.isVarC     = calc.IsVarC;
                            copy.isVarD     = calc.IsVarD;
                            copy.isVarE     = calc.IsVarE;
                            copy.isVarF     = calc.IsVarF;

                            copy.scale     = pos.Scale;
                            copy.x         = pos.BasePoint.X;
                            copy.y         = pos.BasePoint.Y;
                            copy.shapename = pos.Shape;
                            PosShape shape = PosShape.GetPosShape(copy.shapename);
                            if (shape != null)
                            {
                                copy.priority = shape.Priority;
                            }
                            copy.length1     = pos.CalcProperties.MinLength;
                            copy.length2     = pos.CalcProperties.MaxLength;
                            copy.isVarLength = pos.CalcProperties.IsVarLength;
                            poslist.Add(copy);
                        }
                    }
                }
            }

            return(poslist);
        }
Exemple #9
0
        public static List<PosCopy> ReadAllInSelection(IEnumerable<ObjectId> items, bool skipEmpty, PosGrouping grouping)
        {
            List<PosCopy> poslist = new List<PosCopy>();

            Database db = HostApplicationServices.WorkingDatabase;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                foreach (ObjectId id in items)
                {
                    RebarPos pos = tr.GetObject(id, OpenMode.ForRead) as RebarPos;
                    if (pos != null)
                    {
                        // Skip empty pos numbers
                        if (skipEmpty && string.IsNullOrEmpty(pos.Pos)) continue;
                        // Skip detached pos
                        if (pos.Detached) continue;

                        PosCopy copy = null;
                        if (grouping == PosGrouping.PosKey)
                        {
                            copy = poslist.Find(p => p.key == pos.PosKey);
                        }
                        else if (grouping == PosGrouping.PosKeyVarLength && !pos.CalcProperties.IsVarLength)
                        {
                            copy = poslist.Find(p => p.key == pos.PosKey);
                        }
                        else if (grouping == PosGrouping.PosMarker)
                        {
                            copy = poslist.Find(p => p.pos == pos.Pos);
                        }
                        else if (grouping == PosGrouping.PosKeyDifferentMarker)
                        {
                            copy = poslist.Find(p => p.key == pos.PosKey && p.pos == pos.Pos);
                        }
                        else if (grouping == PosGrouping.PosKeyDifferentMarkerVarLength && !pos.CalcProperties.IsVarLength)
                        {
                            copy = poslist.Find(p => p.key == pos.PosKey && p.pos == pos.Pos);
                        }

                        if (copy != null)
                        {
                            copy.list.Add(id);
                            if (pos.IncludeInBOQ)
                            {
                                copy.count += pos.CalcProperties.Count * pos.Multiplier;
                            }
                            copy.scale = Math.Max(copy.scale, pos.Scale);
                            copy.x = Math.Min(copy.x, pos.BasePoint.X);
                            copy.y = Math.Min(copy.y, pos.BasePoint.Y);
                        }
                        else
                        {
                            copy = new PosCopy();
                            copy.key = pos.PosKey;
                            copy.list.Add(id);
                            copy.pos = pos.Pos;
                            copy.newpos = pos.Pos;
                            copy.existing = true;
                            if (pos.IncludeInBOQ)
                            {
                                copy.count = pos.CalcProperties.Count * pos.Multiplier;
                            }
                            copy.diameter = pos.Diameter;
                            copy.length = pos.Length;

                            copy.a = pos.A;
                            copy.b = pos.B;
                            copy.c = pos.C;
                            copy.d = pos.D;
                            copy.e = pos.E;
                            copy.f = pos.F;

                            RebarPos.CalculatedProperties calc = pos.CalcProperties;
                            copy.fieldCount = calc.FieldCount;
                            copy.minA = calc.MinA;
                            copy.minB = calc.MinB;
                            copy.minC = calc.MinC;
                            copy.minD = calc.MinD;
                            copy.minE = calc.MinE;
                            copy.minF = calc.MinF;
                            copy.maxA = calc.MaxA;
                            copy.maxB = calc.MaxB;
                            copy.maxC = calc.MaxC;
                            copy.maxD = calc.MaxD;
                            copy.maxE = calc.MaxE;
                            copy.maxF = calc.MaxF;
                            copy.isVarA = calc.IsVarA;
                            copy.isVarB = calc.IsVarB;
                            copy.isVarC = calc.IsVarC;
                            copy.isVarD = calc.IsVarD;
                            copy.isVarE = calc.IsVarE;
                            copy.isVarF = calc.IsVarF;

                            copy.scale = pos.Scale;
                            copy.x = pos.BasePoint.X;
                            copy.y = pos.BasePoint.Y;
                            copy.shapename = pos.Shape;
                            PosShape shape = PosShape.GetPosShape(copy.shapename);
                            if (shape != null)
                            {
                                copy.priority = shape.Priority;
                            }
                            copy.length1 = pos.CalcProperties.MinLength;
                            copy.length2 = pos.CalcProperties.MaxLength;
                            copy.isVarLength = pos.CalcProperties.IsVarLength;
                            poslist.Add(copy);
                        }
                    }
                }
            }

            return poslist;
        }