private void ShowPosLength(IEnumerable <ObjectId> list, bool show)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    foreach (ObjectId id in list)
                    {
                        RebarPos pos = tr.GetObject(id, OpenMode.ForWrite) as RebarPos;
                        if (pos != null && !pos.Detached && pos.Display != RebarPos.DisplayStyle.MarkerOnly)
                        {
                            if (show)
                            {
                                pos.Display = RebarPos.DisplayStyle.All;
                            }
                            else
                            {
                                pos.Display = RebarPos.DisplayStyle.WithoutLength;
                            }
                        }
                    }

                    tr.Commit();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #2
0
        public bool Init(ObjectId id, Point3d pt)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    m_Pos = id;

                    RebarPos pos = tr.GetObject(m_Pos, OpenMode.ForRead) as RebarPos;
                    if (pos == null)
                    {
                        return(false);
                    }


                    txtPosMarker.Text = pos.Pos;

                    hit = pos.HitTest(pt);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }

            return(true);
        }
Example #3
0
        private int GetLastPosNumber(IEnumerable <ObjectId> list)
        {
            int      num = -1;
            Database db  = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    foreach (ObjectId id in list)
                    {
                        RebarPos pos = tr.GetObject(id, OpenMode.ForRead) as RebarPos;
                        if (pos != null)
                        {
                            int i = -1;
                            if (int.TryParse(pos.Pos, out i))
                            {
                                num = Math.Max(i, num);
                            }
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            return(num);
        }
Example #4
0
        private void EmptyBalloons()
        {
            PromptSelectionResult result = DWGUtility.SelectAllPosUser(true);

            if (result.Status == PromptStatus.OK)
            {
                Database db = HostApplicationServices.WorkingDatabase;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    try
                    {
                        foreach (SelectedObject sel in result.Value)
                        {
                            RebarPos pos = tr.GetObject(sel.ObjectId, OpenMode.ForWrite) as RebarPos;
                            if (pos != null)
                            {
                                pos.Pos = "";
                            }
                        }
                        tr.Commit();
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Example #5
0
        public static ObjectId[] GetPosWithShape(string shape)
        {
            List <ObjectId> list = new List <ObjectId>();
            Database        db   = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
                    using (BlockTableRecordEnumerator it = btr.GetEnumerator())
                    {
                        while (it.MoveNext())
                        {
                            RebarPos pos = tr.GetObject(it.Current, OpenMode.ForRead) as RebarPos;
                            if (pos != null)
                            {
                                if (pos.Shape == shape)
                                {
                                    list.Add(it.Current);
                                }
                            }
                        }
                    }
                }
                catch (System.Exception)
                {
                    ;
                }
            }
            return(list.ToArray());
        }
Example #6
0
        private void IcludePosinBOQ(IEnumerable <ObjectId> list, bool include)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    foreach (ObjectId id in list)
                    {
                        RebarPos pos = tr.GetObject(id, OpenMode.ForWrite) as RebarPos;
                        if (pos != null && !pos.Detached)
                        {
                            pos.IncludeInBOQ = include;
                        }
                    }

                    tr.Commit();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #7
0
        private void ApplyNumbers()
        {
            int count         = 0;
            int poscount      = 0;
            int detachedcount = 0;

            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    foreach (PosCopy copy in m_PosList)
                    {
                        string num = copy.newpos;
                        if (copy.existing && !string.IsNullOrEmpty(num))
                        {
                            foreach (ObjectId id in copy.list)
                            {
                                RebarPos pos = tr.GetObject(id, OpenMode.ForWrite) as RebarPos;
                                if (pos != null)
                                {
                                    pos.Pos = num;
                                }
                                poscount++;
                            }
                            if (m_DetachedPosList.ContainsKey(copy.pos))
                            {
                                foreach (ObjectId id in m_DetachedPosList[copy.pos])
                                {
                                    RebarPos pos = tr.GetObject(id, OpenMode.ForWrite) as RebarPos;
                                    if (pos != null)
                                    {
                                        pos.Pos = num;
                                    }
                                    detachedcount++;
                                }
                            }

                            count++;
                        }
                    }

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

            MessageBox.Show(
                count.ToString() + " adet farklı numara verildi.\n" +
                (poscount + detachedcount).ToString() + " adet poz nesnesi numaralandırıldı.",
                "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Example #8
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);
            }
        }
Example #9
0
        private bool PosEdit(ObjectId id, Point3d pt)
        {
            bool detached = false;

            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    RebarPos pos = tr.GetObject(id, OpenMode.ForRead) as RebarPos;
                    if (pos == null)
                    {
                        return(false);
                    }

                    detached = pos.Detached;
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }

            if (detached)
            {
                using (EditDetachedPosForm form = new EditDetachedPosForm())
                {
                    if (form.Init(id, pt))
                    {
                        if (Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(null, form, false) == System.Windows.Forms.DialogResult.OK)
                        {
                            return(true);
                        }
                    }
                }
            }
            else
            {
                using (EditPosForm form = new EditPosForm())
                {
                    if (form.Init(id, pt))
                    {
                        if (Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(null, form, false) == System.Windows.Forms.DialogResult.OK)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Example #10
0
        public override bool IsApplicable(RXObject overruledSubject)
        {
            // Shade current group only
            RebarPos pos = overruledSubject as RebarPos;

            if (pos == null)
            {
                return(false);
            }
            return(!pos.IncludeInBOQ || pos.Detached);
        }
Example #11
0
        private void NewPos()
        {
            Autodesk.AutoCAD.EditorInput.Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            PromptPointResult result = ed.GetPoint("Baz noktası: ");

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

                        Point3d  pt  = result.Value;
                        RebarPos pos = new RebarPos();
                        pos.TransformBy(Matrix3d.Displacement(pt.GetAsVector()));
                        pos.TransformBy(Matrix3d.Scaling(25.0, pt));

                        pos.Pos      = "";
                        pos.Count    = "1";
                        pos.Diameter = "12";
                        pos.Spacing  = "";
                        pos.Shape    = "GENEL";
                        pos.A        = "1000";
                        pos.Note     = "";

#if DEBUG
                        pos.Pos      = "1";
                        pos.Count    = "2x3";
                        pos.Diameter = "12";
                        pos.Spacing  = "200";
                        pos.Shape    = "00";
                        pos.A        = "1000";
                        pos.Note     = "";
#endif

                        pos.SetDatabaseDefaults(db);

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

                        tr.Commit();
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Example #12
0
        private void NewPos()
        {
            Autodesk.AutoCAD.EditorInput.Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            PromptPointResult result = ed.GetPoint("Baz noktası: ");
            if (result.Status == PromptStatus.OK)
            {
                Database db = HostApplicationServices.WorkingDatabase;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    try
                    {
                        BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);

                        Point3d pt = result.Value;
                        RebarPos pos = new RebarPos();
                        pos.TransformBy(Matrix3d.Displacement(pt.GetAsVector()));
                        pos.TransformBy(Matrix3d.Scaling(25.0, pt));

                        pos.Pos = "";
                        pos.Count = "1";
                        pos.Diameter = "12";
                        pos.Spacing = "";
                        pos.Shape = "GENEL";
                        pos.A = "1000";
                        pos.Note = "";

            #if DEBUG
                        pos.Pos = "1";
                        pos.Count = "2x3";
                        pos.Diameter = "12";
                        pos.Spacing = "200";
                        pos.Shape = "00";
                        pos.A = "1000";
                        pos.Note = "";
            #endif

                        pos.SetDatabaseDefaults(db);

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

                        tr.Commit();
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Example #13
0
 public void SetFrom(RebarPos pos)
 {
     SetField(ref Count, pos.Count);
     SetField(ref Diameter, pos.Diameter);
     SetField(ref Spacing, pos.Spacing);
     SetField(ref Note, pos.Note);
     SetField(ref Multiplier, pos.Multiplier.ToString());
     SetField(ref Shape, pos.Shape);
     SetField(ref A, pos.A);
     SetField(ref B, pos.B);
     SetField(ref C, pos.C);
     SetField(ref D, pos.D);
     SetField(ref E, pos.E);
     SetField(ref F, pos.F);
 }
Example #14
0
        public override bool IsApplicable(RXObject overruledSubject)
        {
            RebarPos pos = overruledSubject as RebarPos;

            if (pos == null)
            {
                return(false);
            }
            Database db = pos.Database;

            if (db == null)
            {
                return(false);
            }
            return(mIds.ContainsKey(db.FingerprintGuid));
        }
Example #15
0
        private void btnDetach_Click(object sender, EventArgs e)
        {
            bool haserror = false;

            if (!CheckPosMarker())
            {
                haserror = true;
            }

            if (haserror)
            {
                MessageBox.Show("Lütfen hatalı değerleri düzeltin.", "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    RebarPos pos = tr.GetObject(m_Pos, OpenMode.ForWrite) as RebarPos;
                    if (pos == null)
                    {
                        return;
                    }

                    pos.Pos  = txtPosMarker.Text;
                    pos.Note = txtPosNote.Text;

                    pos.Detached = true;

                    tr.Commit();

                    DialogResult = DialogResult.OK;
                    Close();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #16
0
        public override bool WorldDraw(Drawable drawable, WorldDraw wd)
        {
            if (wd.RegenAbort || wd.IsDragging)
            {
                return(base.WorldDraw(drawable, wd));
            }

            RebarPos pos = drawable as RebarPos;

            if (pos == null || (pos.IncludeInBOQ && !pos.Detached))
            {
                return(base.WorldDraw(drawable, wd));
            }

            // Get geometry
            Point3d minpt;
            Point3d maxpt;

            pos.TextBox(out minpt, out maxpt);
            minpt = minpt.DivideBy(pos.Scale);
            maxpt = maxpt.DivideBy(pos.Scale);

            using (Solid solid = new Solid())
            {
                solid.SetPointAt(0, new Point3d(minpt.X - 0.15, minpt.Y - 0.15, 0));
                solid.SetPointAt(1, new Point3d(maxpt.X + 0.15, minpt.Y - 0.15, 0));
                solid.SetPointAt(2, new Point3d(minpt.X - 0.15, maxpt.Y + 0.15, 0));
                solid.SetPointAt(3, new Point3d(maxpt.X + 0.15, maxpt.Y + 0.15, 0));
                solid.Color   = mColor;
                solid.LayerId = PosUtility.DefpointsLayer;

                Matrix3d trans = Matrix3d.AlignCoordinateSystem(
                    Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis,
                    pos.BasePoint, pos.DirectionVector, pos.UpVector, pos.NormalVector);

                solid.TransformBy(trans);
                wd.Geometry.Draw(solid);
            }

            // Draw the entity over shading
            return(base.WorldDraw(drawable, wd));
        }
Example #17
0
        private void AlignPos(Point3d pt, Vector3d direction, Vector3d up, Vector3d normal)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    RebarPos pos = (RebarPos)tr.GetObject(m_Pos, OpenMode.ForWrite);

                    pos.TransformBy(Matrix3d.Displacement(pt - (pos.BasePoint + pos.Width / 2 * pos.DirectionVector / pos.DirectionVector.Length)));
                    pos.TransformBy(Matrix3d.Rotation(pos.DirectionVector.GetAngleTo(direction, normal), normal, pt));

                    tr.Commit();
                }
                catch (System.Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("Error: " + ex.Message, "RebarPos", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                }
            }
        }
Example #18
0
        // Refreshes given items
        public static void RefreshPos(IEnumerable <ObjectId> ids)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    foreach (ObjectId posid in ids)
                    {
                        RebarPos pos = tr.GetObject(posid, OpenMode.ForWrite) as RebarPos;
                        pos.Update();
                        pos.Draw();
                    }

                    tr.Commit();
                }
                catch
                {
                    ;
                }
            }
        }
Example #19
0
        private void btnReplace_Click(object sender, EventArgs e)
        {
            if (m_Selection == null || m_Selection.Length == 0)
            {
                return;
            }

            bool haserror = false;

            if (rbReplaceCount.Checked && !CheckPosCount())
            {
                haserror = true;
            }
            if (rbReplaceSpacing.Checked && !CheckPosSpacing())
            {
                haserror = true;
            }
            if (rbReplaceMultiplier.Checked && !CheckPosMultiplier())
            {
                haserror = true;
            }
            if (rbFindShape.Checked)
            {
                if (m_FindFields >= 1)
                {
                    if (!CheckPosLength(txtFindA))
                    {
                        haserror = true;
                    }
                }
                if (m_FindFields >= 2)
                {
                    if (!CheckPosLength(txtFindB))
                    {
                        haserror = true;
                    }
                }
                if (m_FindFields >= 3)
                {
                    if (!CheckPosLength(txtFindC))
                    {
                        haserror = true;
                    }
                }
                if (m_FindFields >= 4)
                {
                    if (!CheckPosLength(txtFindD))
                    {
                        haserror = true;
                    }
                }
                if (m_FindFields >= 5)
                {
                    if (!CheckPosLength(txtFindE))
                    {
                        haserror = true;
                    }
                }
                if (m_FindFields >= 6)
                {
                    if (!CheckPosLength(txtFindF))
                    {
                        haserror = true;
                    }
                }
            }
            if (rbReplaceShape.Checked)
            {
                if (m_ReplaceFields >= 1)
                {
                    if (!CheckPosLength(txtReplaceA))
                    {
                        haserror = true;
                    }
                }
                if (m_ReplaceFields >= 2)
                {
                    if (!CheckPosLength(txtReplaceB))
                    {
                        haserror = true;
                    }
                }
                if (m_ReplaceFields >= 3)
                {
                    if (!CheckPosLength(txtReplaceC))
                    {
                        haserror = true;
                    }
                }
                if (m_ReplaceFields >= 4)
                {
                    if (!CheckPosLength(txtReplaceD))
                    {
                        haserror = true;
                    }
                }
                if (m_ReplaceFields >= 5)
                {
                    if (!CheckPosLength(txtReplaceE))
                    {
                        haserror = true;
                    }
                }
                if (m_ReplaceFields >= 6)
                {
                    if (!CheckPosLength(txtReplaceF))
                    {
                        haserror = true;
                    }
                }
            }

            if (haserror)
            {
                MessageBox.Show("Lütfen hatalı değerleri düzeltin.", "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    // Filter selection
                    List <ObjectId> list = new List <ObjectId>();
                    foreach (ObjectId id in m_Selection)
                    {
                        RebarPos pos = tr.GetObject(id, OpenMode.ForRead) as RebarPos;
                        if (pos == null)
                        {
                            continue;
                        }

                        if (rbFindPosNumber.Checked && cbFindPosNumber.SelectedIndex != -1 && (string)cbFindPosNumber.SelectedItem != pos.Pos)
                        {
                            continue;
                        }
                        if (rbFindCount.Checked && cbFindCount.SelectedIndex != -1 && (string)cbFindCount.SelectedItem != pos.Count)
                        {
                            continue;
                        }
                        if (rbFindDiameter.Checked && cbFindDiameter.SelectedIndex != -1 && (string)cbFindDiameter.SelectedItem != pos.Diameter)
                        {
                            continue;
                        }
                        if (rbFindSpacing.Checked && cbFindSpacing.SelectedIndex != -1 && (string)cbFindSpacing.SelectedItem != pos.Spacing)
                        {
                            continue;
                        }
                        if (rbFindNote.Checked && cbFindNote.SelectedIndex != -1 && (string)cbFindNote.SelectedItem != pos.Note)
                        {
                            continue;
                        }
                        if (rbFindMultiplier.Checked && cbFindMultiplier.SelectedIndex != -1 && (string)cbFindMultiplier.SelectedItem != pos.Multiplier.ToString())
                        {
                            continue;
                        }
                        if (rbFindShape.Checked && m_FindShape != pos.Shape)
                        {
                            continue;
                        }
                        if (rbFindShape.Checked && !string.IsNullOrEmpty(txtFindA.Text) && txtFindA.Text != pos.A)
                        {
                            continue;
                        }
                        if (rbFindShape.Checked && !string.IsNullOrEmpty(txtFindB.Text) && txtFindA.Text != pos.B)
                        {
                            continue;
                        }
                        if (rbFindShape.Checked && !string.IsNullOrEmpty(txtFindC.Text) && txtFindA.Text != pos.C)
                        {
                            continue;
                        }
                        if (rbFindShape.Checked && !string.IsNullOrEmpty(txtFindD.Text) && txtFindA.Text != pos.D)
                        {
                            continue;
                        }
                        if (rbFindShape.Checked && !string.IsNullOrEmpty(txtFindE.Text) && txtFindA.Text != pos.E)
                        {
                            continue;
                        }
                        if (rbFindShape.Checked && !string.IsNullOrEmpty(txtFindF.Text) && txtFindA.Text != pos.F)
                        {
                            continue;
                        }

                        list.Add(id);
                    }

                    // Apply changes
                    foreach (ObjectId id in list)
                    {
                        RebarPos pos = tr.GetObject(id, OpenMode.ForWrite) as RebarPos;
                        if (pos == null)
                        {
                            continue;
                        }
                        if (pos.Detached)
                        {
                            continue;
                        }

                        if (rbReplaceCount.Checked)
                        {
                            pos.Count = txtReplaceCount.Text;
                        }
                        if (rbReplaceDiameter.Checked)
                        {
                            pos.Diameter = (string)cbReplaceDiameter.SelectedItem;
                        }
                        if (rbReplaceSpacing.Checked)
                        {
                            pos.Spacing = txtReplaceSpacing.Text;
                        }
                        if (rbReplaceNote.Checked)
                        {
                            pos.Note = txtReplaceNote.Text;
                        }
                        if (rbReplaceMultiplier.Checked)
                        {
                            pos.Multiplier = int.Parse(txtReplaceMultiplier.Text);
                        }
                        if (rbReplaceShape.Checked && !string.IsNullOrEmpty(m_ReplaceShape))
                        {
                            pos.Shape = m_ReplaceShape;
                        }
                        if (rbReplaceShape.Checked && !string.IsNullOrEmpty(txtReplaceA.Text))
                        {
                            pos.A = txtReplaceA.Text;
                        }
                        if (rbReplaceShape.Checked && !string.IsNullOrEmpty(txtReplaceB.Text))
                        {
                            pos.B = txtReplaceB.Text;
                        }
                        if (rbReplaceShape.Checked && !string.IsNullOrEmpty(txtReplaceC.Text))
                        {
                            pos.C = txtReplaceC.Text;
                        }
                        if (rbReplaceShape.Checked && !string.IsNullOrEmpty(txtReplaceD.Text))
                        {
                            pos.D = txtReplaceD.Text;
                        }
                        if (rbReplaceShape.Checked && !string.IsNullOrEmpty(txtReplaceE.Text))
                        {
                            pos.E = txtReplaceE.Text;
                        }
                        if (rbReplaceShape.Checked && !string.IsNullOrEmpty(txtReplaceF.Text))
                        {
                            pos.F = txtReplaceF.Text;
                        }
                    }

                    tr.Commit();

                    DialogResult = DialogResult.OK;
                    Close();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #20
0
        public override bool WorldDraw(Drawable drawable, WorldDraw wd)
        {
            if (wd.RegenAbort || wd.IsDragging)
            {
                return(base.WorldDraw(drawable, wd));
            }

            RebarPos pos = drawable as RebarPos;

            if (pos == null)
            {
                return(base.WorldDraw(drawable, wd));
            }

            PosShape  shape    = PosShape.GetPosShape(pos.Shape);
            Extents3d?shapeExt = shape.Bounds;

            if (!shapeExt.HasValue)
            {
                return(base.WorldDraw(drawable, wd));
            }
            Extents3d ext = shapeExt.Value;

            WorldGeometry   g     = wd.Geometry;
            SubEntityTraits s     = wd.SubEntityTraits;
            TextStyle       style = new TextStyle();

            // Get geometry
            Point3d  pt   = pos.BasePoint;
            Vector3d dir  = pos.DirectionVector;
            Vector3d up   = pos.UpVector;
            Vector3d norm = pos.NormalVector;

            double w = pos.Width / dir.Length;
            double h = pos.Height / dir.Length;

            // Draw bound dimension lines
            foreach (RebarPos.BoundDimension dim in pos.GetBoundDimensions())
            {
                Line line = new Line(dim.TextPosition, pos.BasePoint);
                g.Draw(line);
            }

            // Draw shape
            double xmin = ext.MinPoint.X, ymin = ext.MinPoint.Y, xmax = ext.MaxPoint.X, ymax = ext.MaxPoint.Y;

            // Scale
            double scale = 0.025;
            // Client offsets
            double xoff = (w - scale * (xmax - xmin)) / 2.0;
            double yoff = 2.0 * h;//(h - scale * (ymax - ymin)) / 2.0;

            // Transform
            Matrix3d trans = Matrix3d.AlignCoordinateSystem(new Point3d(xmin, ymin, 0), Vector3d.XAxis / scale, Vector3d.YAxis / scale, Vector3d.ZAxis / scale, pt + dir * xoff + up * yoff, dir, up, norm);

            g.PushModelTransform(trans);

            // Draw shapes
            shape.SetShapeTexts(pos.A, pos.B, pos.C, pos.D, pos.E, pos.F);
            g.Draw(shape);
            shape.ClearShapeTexts();

            // Reset transform
            g.PopModelTransform();

            return(base.WorldDraw(drawable, wd));
        }
Example #21
0
        private void btnFind_Click(object sender, EventArgs e)
        {
            if (m_Selection == null || m_Selection.Length == 0)
            {
                return;
            }

            bool haserror = false;

            if (rbFindShape.Checked)
            {
                if (m_FindFields >= 1)
                {
                    if (!CheckPosLength(txtFindA))
                    {
                        haserror = true;
                    }
                }
                if (m_FindFields >= 2)
                {
                    if (!CheckPosLength(txtFindB))
                    {
                        haserror = true;
                    }
                }
                if (m_FindFields >= 3)
                {
                    if (!CheckPosLength(txtFindC))
                    {
                        haserror = true;
                    }
                }
                if (m_FindFields >= 4)
                {
                    if (!CheckPosLength(txtFindD))
                    {
                        haserror = true;
                    }
                }
                if (m_FindFields >= 5)
                {
                    if (!CheckPosLength(txtFindE))
                    {
                        haserror = true;
                    }
                }
                if (m_FindFields >= 6)
                {
                    if (!CheckPosLength(txtFindF))
                    {
                        haserror = true;
                    }
                }
            }

            if (haserror)
            {
                MessageBox.Show("Lütfen hatalı değerleri düzeltin.", "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    // Filter selection
                    List <ObjectId> list = new List <ObjectId>();
                    foreach (ObjectId id in m_Selection)
                    {
                        RebarPos pos = tr.GetObject(id, OpenMode.ForRead) as RebarPos;
                        if (pos == null)
                        {
                            continue;
                        }

                        if (rbFindPosNumber.Checked && cbFindPosNumber.SelectedIndex != -1 && (string)cbFindPosNumber.SelectedItem != pos.Pos)
                        {
                            continue;
                        }
                        if (rbFindCount.Checked && cbFindCount.SelectedIndex != -1 && (string)cbFindCount.SelectedItem != pos.Count)
                        {
                            continue;
                        }
                        if (rbFindDiameter.Checked && cbFindDiameter.SelectedIndex != -1 && (string)cbFindDiameter.SelectedItem != pos.Diameter)
                        {
                            continue;
                        }
                        if (rbFindSpacing.Checked && cbFindSpacing.SelectedIndex != -1 && (string)cbFindSpacing.SelectedItem != pos.Spacing)
                        {
                            continue;
                        }
                        if (rbFindNote.Checked && cbFindNote.SelectedIndex != -1 && (string)cbFindNote.SelectedItem != pos.Note)
                        {
                            continue;
                        }
                        if (rbFindMultiplier.Checked && cbFindMultiplier.SelectedIndex != -1 && (string)cbFindMultiplier.SelectedItem != pos.Multiplier.ToString())
                        {
                            continue;
                        }
                        if (rbFindShape.Checked && m_FindShape != pos.Shape)
                        {
                            continue;
                        }
                        if (rbFindShape.Checked && !string.IsNullOrEmpty(txtFindA.Text) && txtFindA.Text != pos.A)
                        {
                            continue;
                        }
                        if (rbFindShape.Checked && !string.IsNullOrEmpty(txtFindB.Text) && txtFindA.Text != pos.B)
                        {
                            continue;
                        }
                        if (rbFindShape.Checked && !string.IsNullOrEmpty(txtFindC.Text) && txtFindA.Text != pos.C)
                        {
                            continue;
                        }
                        if (rbFindShape.Checked && !string.IsNullOrEmpty(txtFindD.Text) && txtFindA.Text != pos.D)
                        {
                            continue;
                        }
                        if (rbFindShape.Checked && !string.IsNullOrEmpty(txtFindE.Text) && txtFindA.Text != pos.E)
                        {
                            continue;
                        }
                        if (rbFindShape.Checked && !string.IsNullOrEmpty(txtFindF.Text) && txtFindA.Text != pos.F)
                        {
                            continue;
                        }

                        list.Add(id);
                    }

                    // Select
                    Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.SetImpliedSelection(list.ToArray());

                    DialogResult = DialogResult.OK;
                    Close();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #22
0
        private void PosUpgrade()
        {
            TypedValue[] tvs = new TypedValue[] {
                new TypedValue((int)DxfCode.Start, "INSERT")
            };
            PromptSelectionResult res = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetSelection(new SelectionFilter(tvs));

            if (res.Status != PromptStatus.OK)
            {
                return;
            }

            string blockName = "POZ_*";

            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    // Filter pos blocks
                    List <ObjectId> list = new List <ObjectId>();
                    foreach (ObjectId id in res.Value.GetObjectIds())
                    {
                        if (id.ObjectClass == Autodesk.AutoCAD.Runtime.RXObject.GetClass(typeof(BlockReference)))
                        {
                            BlockReference blockRef = tr.GetObject(id, OpenMode.ForRead) as BlockReference;

                            BlockTableRecord block = null;
                            if (blockRef.IsDynamicBlock)
                            {
                                block = tr.GetObject(blockRef.DynamicBlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
                            }
                            else
                            {
                                block = tr.GetObject(blockRef.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
                            }

                            if (block != null)
                            {
                                if (WCMatch(block.Name, blockName))
                                {
                                    list.Add(id);
                                }
                            }
                        }
                    }

                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    foreach (ObjectId id in list)
                    {
                        // Read pos block
                        OldPos oldPos = new OldPos(tr, id);

                        // Insert new pos
                        RebarPos pos = new RebarPos();

                        pos.SuspendUpdate();

                        pos.TransformBy(Matrix3d.Displacement(oldPos.insPoint.GetAsVector()));
                        pos.TransformBy(Matrix3d.Scaling(oldPos.scale, oldPos.insPoint));
                        pos.TransformBy(Matrix3d.Rotation(oldPos.rotation, Vector3d.ZAxis, oldPos.insPoint));

                        pos.Pos        = oldPos.pos;
                        pos.Count      = oldPos.count;
                        pos.Diameter   = oldPos.diameter;
                        pos.Spacing    = oldPos.spacing;
                        pos.Shape      = oldPos.shapeName;
                        pos.A          = oldPos.a;
                        pos.B          = oldPos.b;
                        pos.C          = oldPos.c;
                        pos.D          = oldPos.d;
                        pos.E          = oldPos.e;
                        pos.F          = oldPos.f;
                        pos.Multiplier = oldPos.multiplier;
                        pos.Note       = oldPos.note;

                        // Align note text
                        if (oldPos.noteInText)
                        {
                            pos.NoteAlignment = RebarPos.SubTextAlignment.Right;
                        }
                        else if (!oldPos.noteId.IsNull)
                        {
                            pos.NoteGrip = oldPos.notePt;
                        }

                        // Align length text
                        if (oldPos.lengthInText)
                        {
                            pos.LengthAlignment = RebarPos.SubTextAlignment.Right;
                        }
                        else if (!oldPos.lengthId.IsNull)
                        {
                            pos.LengthGrip = oldPos.lengthPt;
                        }

                        pos.Detached = oldPos.detached;
                        if (!oldPos.detached && !oldPos.showLength)
                        {
                            pos.Display = RebarPos.DisplayStyle.WithoutLength;
                        }

                        pos.ResumeUpdate();

                        pos.SetDatabaseDefaults(db);

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

                        // Erase old pos block
                        BlockReference bref = tr.GetObject(id, OpenMode.ForWrite) as BlockReference;
                        bref.Erase();
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                tr.Commit();
            }
        }
Example #23
0
        private void ReadSelection()
        {
            m_PosList        = new SortedDictionary <string, List <ObjectId> >();
            m_CountList      = new SortedDictionary <string, List <ObjectId> >();
            m_DiameterList   = new SortedDictionary <string, List <ObjectId> >();
            m_SpacingList    = new SortedDictionary <string, List <ObjectId> >();
            m_NoteList       = new SortedDictionary <string, List <ObjectId> >();
            m_MultiplierList = new SortedDictionary <int, List <ObjectId> >();
            m_ShapeList      = new SortedDictionary <string, List <ObjectId> >();

            m_PosProperties = new Dictionary <string, SelectedPos>();

            cbFindPosNumber.Items.Clear();
            cbFindCount.Items.Clear();
            cbFindDiameter.Items.Clear();
            cbFindSpacing.Items.Clear();
            cbFindNote.Items.Clear();
            cbFindMultiplier.Items.Clear();

            if (m_Selection == null || m_Selection.Length == 0)
            {
                return;
            }

            // Read all pos properties in selection
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    foreach (ObjectId id in m_Selection)
                    {
                        RebarPos pos = tr.GetObject(id, OpenMode.ForRead) as RebarPos;
                        if (pos != null)
                        {
                            List <ObjectId> list = null;
                            if (m_PosList.TryGetValue(pos.Pos, out list))
                            {
                                list.Add(id);
                            }
                            else
                            {
                                m_PosList.Add(pos.Pos, new List <ObjectId>()
                                {
                                    id
                                });
                            }
                            if (pos.Detached)
                            {
                                continue;
                            }

                            if (m_CountList.TryGetValue(pos.Count, out list))
                            {
                                list.Add(id);
                            }
                            else
                            {
                                m_CountList.Add(pos.Count, new List <ObjectId>()
                                {
                                    id
                                });
                            }
                            if (m_DiameterList.TryGetValue(pos.Diameter, out list))
                            {
                                list.Add(id);
                            }
                            else
                            {
                                m_DiameterList.Add(pos.Diameter, new List <ObjectId>()
                                {
                                    id
                                });
                            }
                            if (m_SpacingList.TryGetValue(pos.Spacing, out list))
                            {
                                list.Add(id);
                            }
                            else
                            {
                                m_SpacingList.Add(pos.Spacing, new List <ObjectId>()
                                {
                                    id
                                });
                            }
                            if (m_NoteList.TryGetValue(pos.Note, out list))
                            {
                                list.Add(id);
                            }
                            else
                            {
                                m_NoteList.Add(pos.Note, new List <ObjectId>()
                                {
                                    id
                                });
                            }
                            if (m_MultiplierList.TryGetValue(pos.Multiplier, out list))
                            {
                                list.Add(id);
                            }
                            else
                            {
                                m_MultiplierList.Add(pos.Multiplier, new List <ObjectId>()
                                {
                                    id
                                });
                            }
                            if (m_ShapeList.TryGetValue(pos.Shape, out list))
                            {
                                list.Add(id);
                            }
                            else
                            {
                                m_ShapeList.Add(pos.Shape, new List <ObjectId>()
                                {
                                    id
                                });
                            }

                            SelectedPos copy = null;
                            if (!m_PosProperties.TryGetValue(pos.Pos, out copy))
                            {
                                copy = new SelectedPos();
                                m_PosProperties.Add(pos.Pos, copy);
                            }
                            copy.SetFrom(pos);
                        }
                    }
                }
                catch (System.Exception)
                {
                    ;
                }
            }

            // Populate list boxes
            foreach (string name in m_PosList.Keys)
            {
                cbFindPosNumber.Items.Add(name);
            }
            foreach (string name in m_CountList.Keys)
            {
                cbFindCount.Items.Add(name);
            }
            foreach (string name in m_DiameterList.Keys)
            {
                cbFindDiameter.Items.Add(name);
            }
            foreach (string name in m_SpacingList.Keys)
            {
                cbFindSpacing.Items.Add(name);
            }
            foreach (string name in m_NoteList.Keys)
            {
                cbFindNote.Items.Add(name);
            }
            foreach (int mult in m_MultiplierList.Keys)
            {
                cbFindMultiplier.Items.Add(mult.ToString());
            }

            cbReplaceDiameter.Items.Clear();
            foreach (int d in DWGUtility.GetStandardDiameters())
            {
                cbReplaceDiameter.Items.Add(d.ToString());
            }

            if (cbReplaceDiameter.Items.Count > 0)
            {
                cbReplaceDiameter.SelectedIndex = 0;
            }

            if (m_ShapeList.Count > 0)
            {
                foreach (string name in m_ShapeList.Keys)
                {
                    SetFindShape(name);
                    SetReplaceShape(name);
                    break;
                }
            }

            if (cbFindPosNumber.Items.Count > 0)
            {
                cbFindPosNumber.SelectedIndex = 0;
            }
            if (cbFindCount.Items.Count > 0)
            {
                cbFindCount.SelectedIndex = 0;
            }
            if (cbFindDiameter.Items.Count > 0)
            {
                cbFindDiameter.SelectedIndex = 0;
            }
            if (cbFindSpacing.Items.Count > 0)
            {
                cbFindSpacing.SelectedIndex = 0;
            }
            if (cbFindNote.Items.Count > 0)
            {
                cbFindNote.SelectedIndex = 0;
            }
            if (cbFindMultiplier.Items.Count > 0)
            {
                cbFindMultiplier.SelectedIndex = 0;
            }
        }
Example #24
0
        private UpdateLengthResult UpdateLength()
        {
            // Get lengths
            double minLengthMM = 0;
            double maxLengthMM = 0;
            bool   isVarLength = false;
            bool   check       = false;

            try
            {
                check = RebarPos.GetTotalLengths(m_Formula, m_Fields, m_DrawingUnits, txtA.Text, txtB.Text, txtC.Text, txtD.Text, txtE.Text, txtF.Text, cbPosDiameter.Text, out minLengthMM, out maxLengthMM, out isVarLength);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(UpdateLengthResult.SystemError);
            }

            if (check && (minLengthMM > double.Epsilon) && (maxLengthMM > double.Epsilon))
            {
                string unitPrefix = "mm";
                switch (m_DrawingUnits)
                {
                case PosGroup.DrawingUnits.Millimeter:
                    unitPrefix = "mm";
                    break;

                case PosGroup.DrawingUnits.Centimeter:
                    unitPrefix = "cm";
                    break;
                }

                // Scale from MM to drawing units
                double scale     = RebarPos.ConvertLength(1.0, PosGroup.DrawingUnits.Millimeter, m_DrawingUnits);
                double minLength = minLengthMM * scale;
                double maxLength = maxLengthMM * scale;

                if (isVarLength)
                {
                    lblTotalLength.Text = minLength.ToString("F" + m_Precision.ToString()) + "~" + maxLength.ToString("F" + m_Precision.ToString()) + " " + unitPrefix +
                                          " (" + (minLengthMM / 1000.0).ToString("F2") + " m ~ " + (maxLengthMM / 1000.0).ToString("F2") + " m)";
                    lblAverageLength.Text = ((minLength + maxLength) / 2.0).ToString("F" + m_Precision.ToString()) + " " + unitPrefix +
                                            " (" + ((minLengthMM + maxLengthMM) / 2.0 / 1000.0).ToString("F2") + " m)";

                    lblAverageLengthCaption.Visible = true;
                    lblAverageLength.Visible        = true;
                }
                else
                {
                    lblTotalLength.Text = minLength.ToString("F" + m_Precision.ToString()) + " " + unitPrefix +
                                          " (" + (minLengthMM / 1000.0).ToString("F2") + " m)";

                    lblAverageLengthCaption.Visible = false;
                    lblAverageLength.Visible        = false;
                }

                if (minLengthMM > m_MaxLength * 1000.0 || maxLengthMM > m_MaxLength * 1000.0)
                {
                    lblAverageLength.ForeColor = Color.Red;
                    lblTotalLength.ForeColor   = Color.Red;

                    return(UpdateLengthResult.ExceedsMaximum);
                }
                else
                {
                    lblAverageLength.ForeColor = SystemColors.ControlText;
                    lblTotalLength.ForeColor   = SystemColors.ControlText;

                    return(UpdateLengthResult.OK);
                }
            }
            else
            {
                lblTotalLength.Text      = "Hatalı Boy!";
                lblTotalLength.ForeColor = Color.Red;

                lblAverageLengthCaption.Visible = false;
                lblAverageLength.Visible        = false;

                return(UpdateLengthResult.InvalidLength);
            }
        }
Example #25
0
        private void PosUpgrade()
        {
            TypedValue[] tvs = new TypedValue[] {
                new TypedValue((int)DxfCode.Start, "INSERT")
            };
            PromptSelectionResult res = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetSelection(new SelectionFilter(tvs));
            if (res.Status != PromptStatus.OK)
            {
                return;
            }

            string blockName = "POZ_*";

            Database db = HostApplicationServices.WorkingDatabase;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    // Filter pos blocks
                    List<ObjectId> list = new List<ObjectId>();
                    foreach (ObjectId id in res.Value.GetObjectIds())
                    {
                        if (id.ObjectClass == Autodesk.AutoCAD.Runtime.RXObject.GetClass(typeof(BlockReference)))
                        {
                            BlockReference blockRef = tr.GetObject(id, OpenMode.ForRead) as BlockReference;

                            BlockTableRecord block = null;
                            if (blockRef.IsDynamicBlock)
                            {
                                block = tr.GetObject(blockRef.DynamicBlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
                            }
                            else
                            {
                                block = tr.GetObject(blockRef.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
                            }

                            if (block != null)
                            {
                                if (WCMatch(block.Name, blockName)) list.Add(id);
                            }
                        }
                    }

                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    foreach (ObjectId id in list)
                    {
                        // Read pos block
                        OldPos oldPos = new OldPos(tr, id);

                        // Insert new pos
                        RebarPos pos = new RebarPos();

                        pos.SuspendUpdate();

                        pos.TransformBy(Matrix3d.Displacement(oldPos.insPoint.GetAsVector()));
                        pos.TransformBy(Matrix3d.Scaling(oldPos.scale, oldPos.insPoint));
                        pos.TransformBy(Matrix3d.Rotation(oldPos.rotation, Vector3d.ZAxis, oldPos.insPoint));

                        pos.Pos = oldPos.pos;
                        pos.Count = oldPos.count;
                        pos.Diameter = oldPos.diameter;
                        pos.Spacing = oldPos.spacing;
                        pos.Shape = oldPos.shapeName;
                        pos.A = oldPos.a;
                        pos.B = oldPos.b;
                        pos.C = oldPos.c;
                        pos.D = oldPos.d;
                        pos.E = oldPos.e;
                        pos.F = oldPos.f;
                        pos.Multiplier = oldPos.multiplier;
                        pos.Note = oldPos.note;

                        // Align note text
                        if (oldPos.noteInText)
                        {
                            pos.NoteAlignment = RebarPos.SubTextAlignment.Right;
                        }
                        else if (!oldPos.noteId.IsNull)
                        {
                            pos.NoteGrip = oldPos.notePt;
                        }

                        // Align length text
                        if (oldPos.lengthInText)
                        {
                            pos.LengthAlignment = RebarPos.SubTextAlignment.Right;
                        }
                        else if (!oldPos.lengthId.IsNull)
                        {
                            pos.LengthGrip = oldPos.lengthPt;
                        }

                        pos.Detached = oldPos.detached;
                        if (!oldPos.detached && !oldPos.showLength) pos.Display = RebarPos.DisplayStyle.WithoutLength;

                        pos.ResumeUpdate();

                        pos.SetDatabaseDefaults(db);

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

                        // Erase old pos block
                        BlockReference bref = tr.GetObject(id, OpenMode.ForWrite) as BlockReference;
                        bref.Erase();
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                tr.Commit();
            }
        }
Example #26
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);
        }
Example #27
0
        private void CopyPosDetail()
        {
            PromptEntityOptions opts = new PromptEntityOptions("Select source object: ");

            opts.AllowNone = false;
            PromptEntityResult result = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetEntity(opts);

            if (result.Status != PromptStatus.OK)
            {
                return;
            }

            PromptEntityOptions destopts = new PromptEntityOptions("Select destination object: ");

            destopts.AllowNone = false;
            PromptEntityResult destresult = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetEntity(destopts);

            if (destresult.Status != PromptStatus.OK)
            {
                return;
            }
            if (result.ObjectId == destresult.ObjectId)
            {
                return;
            }

            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    RebarPos source = tr.GetObject(result.ObjectId, OpenMode.ForRead) as RebarPos;
                    if (source == null)
                    {
                        return;
                    }
                    if (source.Detached)
                    {
                        return;
                    }

                    RebarPos dest = tr.GetObject(destresult.ObjectId, OpenMode.ForWrite) as RebarPos;
                    if (dest != null)
                    {
                        dest.Pos          = source.Pos;
                        dest.Count        = source.Count;
                        dest.Diameter     = source.Diameter;
                        dest.Spacing      = source.Spacing;
                        dest.Shape        = source.Shape;
                        dest.A            = source.A;
                        dest.B            = source.B;
                        dest.C            = source.C;
                        dest.D            = source.D;
                        dest.E            = source.E;
                        dest.F            = source.F;
                        dest.Display      = RebarPos.DisplayStyle.WithoutLength;
                        dest.Note         = "";
                        dest.IncludeInBOQ = false;
                        dest.Multiplier   = 0;
                    }

                    tr.Commit();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #28
0
        private void btnAlign_Click(object sender, EventArgs e)
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            using (EditorUserInteraction UI = ed.StartUserInteraction(this))
            {
                PromptEntityOptions opts = new PromptEntityOptions("\nSelect entity: ");
                opts.AllowNone = false;
                opts.SetRejectMessage("\nSelect a LINE, ARC or POLYLINE entity.");
                opts.AddAllowedClass(typeof(Curve), false);
                PromptEntityResult per = ed.GetEntity(opts);
                if (per.Status == PromptStatus.OK)
                {
                    Point3d  pt = per.PickedPoint;
                    ObjectId id = per.ObjectId;

                    bool     posUp = false;
                    Vector3d dir = new Vector3d(), up = new Vector3d(), normal = new Vector3d();
                    Database db = HostApplicationServices.WorkingDatabase;
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        try
                        {
                            RebarPos pos = (RebarPos)tr.GetObject(m_Pos, OpenMode.ForRead);

                            Curve curve = (Curve)tr.GetObject(id, OpenMode.ForRead);
                            pt     = curve.GetClosestPointTo(pt, curve.GetPlane().Normal, false);
                            dir    = curve.GetFirstDerivative(pt);
                            dir    = dir * pos.DirectionVector.Length / dir.Length;
                            normal = pos.NormalVector;
                            normal = normal * pos.DirectionVector.Length / normal.Length;
                            up     = dir.CrossProduct(normal);
                            up     = up * pos.DirectionVector.Length / up.Length;

                            posUp = (dir.DotProduct(pos.UpVector) > 0);
                        }
                        catch (System.Exception ex)
                        {
                            System.Windows.Forms.MessageBox.Show("Error: " + ex.Message, "RebarPos", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        }
                    }

                    double offset = 0.0;
                    double offset1 = -0.75, offset2 = 1.75;
                    if (posUp)
                    {
                        AlignPos(pt + offset1 * up, dir, up, normal);
                        offset = offset2;
                    }
                    else
                    {
                        AlignPos(pt + offset2 * up, dir, up, normal);
                        offset = offset1;
                    }

                    PromptKeywordOptions kopts = new PromptKeywordOptions("\nDiğer tarafa yerleştirilsin mi? [Evet/Hayır] <Hayir>: ", "Yes No");
                    kopts.AllowNone = true;
                    PromptResult kres = ed.GetKeywords(kopts);
                    if (kres.Status == PromptStatus.None || kres.StringResult == "Yes")
                    {
                        AlignPos(pt + offset * up, dir, up, normal);
                        ed.UpdateScreen();
                    }
                }
            }
        }
Example #29
0
        private void CopyPosNumber()
        {
            PromptEntityOptions opts = new PromptEntityOptions("Select source object: ");

            opts.AllowNone = false;
            PromptEntityResult result = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetEntity(opts);

            if (result.Status != PromptStatus.OK)
            {
                return;
            }

            PromptEntityOptions destopts = new PromptEntityOptions("Select destination object: ");

            destopts.AllowNone = false;
            PromptEntityResult destresult = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.GetEntity(destopts);

            if (destresult.Status != PromptStatus.OK)
            {
                return;
            }
            if (result.ObjectId == destresult.ObjectId)
            {
                return;
            }

            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    RebarPos source = tr.GetObject(result.ObjectId, OpenMode.ForRead) as RebarPos;
                    if (source == null)
                    {
                        return;
                    }
                    if (source.Detached)
                    {
                        return;
                    }

                    RebarPos dest = tr.GetObject(destresult.ObjectId, OpenMode.ForWrite) as RebarPos;
                    if (dest != null)
                    {
                        dest.Pos      = source.Pos;
                        dest.Detached = true;
                    }

                    DBText text = tr.GetObject(destresult.ObjectId, OpenMode.ForWrite) as DBText;
                    if (text != null)
                    {
                        text.TextString = source.Pos;
                    }
                    MText mtext = tr.GetObject(destresult.ObjectId, OpenMode.ForWrite) as MText;
                    if (mtext != null)
                    {
                        mtext.Contents = source.Pos;
                    }

                    tr.Commit();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #30
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            bool haserror = false;

            if (!CheckPosMarker())
            {
                haserror = true;
            }
            if (!CheckPosCount())
            {
                haserror = true;
            }
            if (!CheckPosDiameter())
            {
                haserror = true;
            }
            if (!CheckPosSpacing())
            {
                haserror = true;
            }
            if (!CheckPosMultiplier())
            {
                haserror = true;
            }
            if (m_Fields >= 1)
            {
                if (!CheckPosLength(txtA))
                {
                    haserror = true;
                }
            }
            if (m_Fields >= 2)
            {
                if (!CheckPosLength(txtB))
                {
                    haserror = true;
                }
            }
            if (m_Fields >= 3)
            {
                if (!CheckPosLength(txtC))
                {
                    haserror = true;
                }
            }
            if (m_Fields >= 4)
            {
                if (!CheckPosLength(txtD))
                {
                    haserror = true;
                }
            }
            if (m_Fields >= 5)
            {
                if (!CheckPosLength(txtE))
                {
                    haserror = true;
                }
            }
            if (m_Fields >= 6)
            {
                if (!CheckPosLength(txtF))
                {
                    haserror = true;
                }
            }

            if (haserror)
            {
                MessageBox.Show("Lütfen hatalı değerleri düzeltin.", "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    RebarPos pos = tr.GetObject(m_Pos, OpenMode.ForWrite) as RebarPos;
                    if (pos == null)
                    {
                        return;
                    }

                    pos.SuspendUpdate();

                    pos.Pos          = txtPosMarker.Text;
                    pos.Count        = txtPosCount.Text;
                    pos.Diameter     = cbPosDiameter.Text;
                    pos.Spacing      = txtPosSpacing.Text;
                    pos.IncludeInBOQ = chkIncludePos.Checked && (int.Parse(txtPosMultiplier.Text) > 0);
                    pos.Multiplier   = int.Parse(txtPosMultiplier.Text);
                    pos.Note         = txtPosNote.Text;
                    pos.Shape        = m_Shape;

                    if (chkShowLength.Checked)
                    {
                        pos.Display = RebarPos.DisplayStyle.All;
                    }
                    else
                    {
                        pos.Display = RebarPos.DisplayStyle.WithoutLength;
                    }

                    pos.A = txtA.Text;
                    pos.B = txtB.Text;
                    pos.C = txtC.Text;
                    pos.D = txtD.Text;
                    pos.E = txtE.Text;
                    pos.F = txtF.Text;

                    // Note text alignment
                    if (rbAlignNoteTop.Checked)
                    {
                        pos.NoteAlignment = RebarPos.SubTextAlignment.Top;
                    }
                    else if (rbAlignNoteBottom.Checked)
                    {
                        pos.NoteAlignment = RebarPos.SubTextAlignment.Bottom;
                    }
                    else if (rbAlignNoteRight.Checked)
                    {
                        pos.NoteAlignment = RebarPos.SubTextAlignment.Right;
                    }
                    else
                    {
                        pos.NoteAlignment = RebarPos.SubTextAlignment.Free;
                    }

                    // Length text alignment
                    if (rbAlignLengthTop.Checked)
                    {
                        pos.LengthAlignment = RebarPos.SubTextAlignment.Top;
                    }
                    else if (rbAlignLengthBottom.Checked)
                    {
                        pos.LengthAlignment = RebarPos.SubTextAlignment.Bottom;
                    }
                    else if (rbAlignLengthRight.Checked)
                    {
                        pos.LengthAlignment = RebarPos.SubTextAlignment.Right;
                    }
                    else
                    {
                        pos.LengthAlignment = RebarPos.SubTextAlignment.Free;
                    }

                    pos.SetBoundDimensions(boundDimensions);

                    pos.ResumeUpdate();

                    tr.Commit();

                    DialogResult = DialogResult.OK;
                    Close();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #31
0
 public void SetFrom(RebarPos pos)
 {
     SetField(ref Count, pos.Count);
     SetField(ref Diameter, pos.Diameter);
     SetField(ref Spacing, pos.Spacing);
     SetField(ref Note, pos.Note);
     SetField(ref Multiplier, pos.Multiplier.ToString());
     SetField(ref Shape, pos.Shape);
     SetField(ref A, pos.A);
     SetField(ref B, pos.B);
     SetField(ref C, pos.C);
     SetField(ref D, pos.D);
     SetField(ref E, pos.E);
     SetField(ref F, pos.F);
 }
Example #32
0
        public bool Init(ObjectId id, Point3d pt)
        {
            Database db = HostApplicationServices.WorkingDatabase;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {
                    m_Pos = id;

                    RebarPos pos = tr.GetObject(m_Pos, OpenMode.ForRead) as RebarPos;
                    if (pos == null)
                    {
                        return(false);
                    }

                    m_Shape = pos.Shape;

                    txtPosMarker.Text        = pos.Pos;
                    txtPosCount.Text         = pos.Count;
                    cbPosDiameter.Text       = pos.Diameter;
                    txtPosSpacing.Text       = pos.Spacing;
                    txtPosMultiplier.Text    = pos.Multiplier.ToString();
                    chkIncludePos.Checked    = pos.IncludeInBOQ;
                    txtPosMultiplier.Enabled = pos.IncludeInBOQ;
                    txtPosNote.Text          = pos.Note;

                    txtA.Text = pos.A;
                    txtB.Text = pos.B;
                    txtC.Text = pos.C;
                    txtD.Text = pos.D;
                    txtE.Text = pos.E;
                    txtF.Text = pos.F;

                    chkShowLength.Checked = (pos.Display == RebarPos.DisplayStyle.All);

                    // Note text alignment
                    rbAlignNoteTop.Checked    = (pos.NoteAlignment == RebarPos.SubTextAlignment.Top);
                    rbAlignNoteBottom.Checked = (pos.NoteAlignment == RebarPos.SubTextAlignment.Bottom);
                    rbAlignNoteRight.Checked  = (pos.NoteAlignment == RebarPos.SubTextAlignment.Right);

                    // Length text alignment
                    rbAlignLengthTop.Checked    = (pos.LengthAlignment == RebarPos.SubTextAlignment.Top);
                    rbAlignLengthBottom.Checked = (pos.LengthAlignment == RebarPos.SubTextAlignment.Bottom);
                    rbAlignLengthRight.Checked  = (pos.LengthAlignment == RebarPos.SubTextAlignment.Right);

                    boundDimensions = pos.GetBoundDimensions().Select(p => p.Id).ToList();

                    if (!SetGroup())
                    {
                        return(false);
                    }
                    if (!SetShape())
                    {
                        return(false);
                    }

                    UpdateLength();

                    hit = pos.HitTest(pt);
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Error: " + ex.Message, "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }

            return(true);
        }