Example #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (!ShowEditMessage())
            {
                return;
            }

            if (lbShapes.SelectedIndices.Count == 0)
            {
                return;
            }

            PosShape copy = GetSelected();

            if (copy == null)
            {
                return;
            }
            if (copy.IsBuiltIn)
            {
                return;
            }

            m_Copies.Remove(copy);
            lbShapes.Items.Remove(lbShapes.SelectedItems[0]);
        }
Example #2
0
        private void lbShapes_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbShapes.SelectedIndices.Count == 0)
            {
                gbOptions.Enabled = false;

                btnDelete.Enabled       = false;
                btnRename.Enabled       = false;
                btnDrawShapes.Enabled   = false;
                btnSelectShapes.Enabled = false;
            }
            else
            {
                gbOptions.Enabled = true;

                PosShape copy   = GetSelected();
                bool     enable = (copy != null) && !copy.IsBuiltIn;

                btnDelete.Enabled       = enable;
                btnRename.Enabled       = enable;
                btnDrawShapes.Enabled   = true;
                btnSelectShapes.Enabled = enable;

                udFields.ReadOnly          = !enable;
                txtFormula.ReadOnly        = !enable;
                txtFormulaBending.ReadOnly = !enable;
                udPriority.ReadOnly        = !enable;

                lbShapes.LabelEdit = enable;

                SetShape();
            }
        }
Example #3
0
        public bool Init(bool showShapes)
        {
            chkShowShapes.Checked = showShapes;

            List <string> shapes = PosShape.GetAllPosShapes();

            if (shapes.Count == 0)
            {
                return(false);
            }

            try
            {
                foreach (string name in shapes)
                {
                    m_Copies.Add((PosShape)PosShape.GetPosShape(name).Clone());
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message, "RebarPos", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return(false);
            }

            PopulateList();

            return(true);
        }
Example #4
0
        private void lbShapes_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            if (e.Label == null)
            {
                e.CancelEdit = true;
                return;
            }
            if (lbShapes.SelectedIndices.Count == 0)
            {
                e.CancelEdit = true;
                return;
            }
            foreach (ListViewItem item in lbShapes.Items)
            {
                if (item.Index != lbShapes.SelectedIndices[0] && item.Text == e.Label)
                {
                    MessageBox.Show("Bu isim zaten mevcut. Lütfen farklı bir isim seçin.", "RebarPos", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    e.CancelEdit = true;
                    return;
                }
            }
            PosShape copy = m_Copies.Find(p => p.Name == lbShapes.Items[e.Item].Text);

            if (copy == null || copy.IsBuiltIn)
            {
                e.CancelEdit = true;
                return;
            }
            copy.Name = e.Label;
        }
Example #5
0
        public void SetTable()
        {
            ClearItems();

            if (mTable != null)
            {
                mTable.Dispose();
            }

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

            string shape = "GENEL";

            if (PosShape.HasPosShape("00"))
            {
                shape = "00";
            }
            mTable.Items.Add(1, 6, 14, 240, shape, "240", "", "", "", "", "");
            if (PosShape.HasPosShape("11"))
            {
                shape = "11";
            }
            mTable.Items.Add(1, 12, 16, 320, shape, "200", "120", "", "", "", "");

            mTable.Multiplier = 2;
            mTable.Precision  = 2;
            mTable.ColumnDef  = Columns;

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

            mTable.TextStyleId    = TextStyleId;
            mTable.HeadingStyleId = HeadingStyleId;
            mTable.FootingStyleId = FootingStyleId;

            mTable.ResumeUpdate();

            AddItem(mTable);
        }
Example #6
0
        private void txtFormulaBending_Validated(object sender, EventArgs e)
        {
            PosShape copy = GetSelected();

            if (copy == null)
            {
                return;
            }
            if (copy.IsBuiltIn)
            {
                return;
            }
            copy.FormulaBending = txtFormulaBending.Text;
        }
Example #7
0
        private void udFields_ValueChanged(object sender, EventArgs e)
        {
            PosShape copy = GetSelected();

            if (copy == null)
            {
                return;
            }
            if (copy.IsBuiltIn)
            {
                return;
            }
            copy.Fields = (int)udFields.Value;
        }
Example #8
0
        private void udPriority_ValueChanged(object sender, EventArgs e)
        {
            PosShape copy = GetSelected();

            if (copy == null)
            {
                return;
            }
            if (copy.IsBuiltIn)
            {
                return;
            }
            copy.Priority = (int)udPriority.Value;
        }
Example #9
0
        private void SetReplaceShape(string name)
        {
            psvReplace.SetShape(name);

            m_ReplaceShape = name;
            PosShape shape = PosShape.GetPosShape(name);

            if (shape == null)
            {
                return;
            }
            m_ReplaceFields = shape.Fields;

            UpdateUI();
        }
Example #10
0
        private void SetFindShape(string name)
        {
            psvFind.SetShape(name);

            m_FindShape = name;
            PosShape shape = PosShape.GetPosShape(name);

            if (shape == null)
            {
                return;
            }
            m_FindFields = shape.Fields;

            UpdateUI();
        }
Example #11
0
 private void UpdateItemImages()
 {
     for (int i = 0; i < lbShapes.Items.Count; i++)
     {
         ListViewItem lv   = lbShapes.Items[i];
         PosShape     copy = m_Copies.Find(p => p.Name == lv.Text);
         if (copy.IsBuiltIn)
         {
             lv.ImageIndex = 0;
         }
         else
         {
             lv.ImageIndex = 1;
         }
     }
 }
Example #12
0
        public void ReadUserPosShapes()
        {
            string userFolder     = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "RebarPos");
            string userShapesFile = System.IO.Path.Combine(userFolder, "ShapeList.txt");

            try
            {
                if (System.IO.File.Exists(userShapesFile))
                {
                    PosShape.ClearPosShapes();
                    PosShape.ReadPosShapesFromFile(userShapesFile);
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message, "RebarPos", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }
        }
Example #13
0
        void cell_Paint(object sender, PaintEventArgs e)
        {
            if (init && !disposed && !Disposing && !IsDesigner)
            {
                Control cell      = (Control)sender;
                string  shapeName = (string)cell.Tag;
                if (string.IsNullOrEmpty(shapeName))
                {
                    return;
                }
                int           index   = layoutPanel.Controls.IndexOf(cell);
                PosShape      shape   = PosShape.GetPosShape(shapeName);
                List <string> lengths = new List <string>();
                if (pieceLengths.TryGetValue(index, out lengths) && (lengths.Count == 6))
                {
                    shape.SetShapeTexts(lengths[0], lengths[1], lengths[2], lengths[3], lengths[4], lengths[5]);
                }

                using (Bitmap bmp = shape.ToBitmap(device, view, model, CellBackColor, mCellSize.Width, mCellSize.Height))
                {
                    e.Graphics.DrawImageUnscaled(bmp, 0, 0);
                }

                shape.ClearShapeTexts();

                if (ShowShapeNames)
                {
                    using (Brush brush = new SolidBrush(IsDark(CellBackColor) ? Color.White : Color.Black))
                    {
                        e.Graphics.DrawString(shapeName, Font, brush, 4, 6);
                    }
                }

                if (mSelectedShape == shapeName)
                {
                    using (Pen pen = new Pen(mSelectionColor, 2.0f))
                    {
                        Rectangle rec = new Rectangle(0, 0, mCellSize.Width, mCellSize.Height);
                        rec.Inflate(-2, -2);
                        e.Graphics.DrawRectangle(pen, rec);
                    }
                }
            }
        }
Example #14
0
        public void CMD_DumpShapes()
        {
            Autodesk.AutoCAD.EditorInput.Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            PromptPointResult result = ed.GetPoint("Baz noktası: ");

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

            Point3d pt = result.Value;

            foreach (string name in PosShape.GetAllPosShapes())
            {
                DWGUtility.DrawShape(name, pt, 100);

                pt = pt.Add(new Vector3d(0, 120, 0));
            }
        }
Example #15
0
        public void SetShape(string shapeName)
        {
            SuspendUpdate();
            ClearItems();
            mShapeName = shapeName;

            if (!string.IsNullOrEmpty(mShapeName))
            {
                PosShape shape = PosShape.GetPosShape(shapeName);
                if (shape != null)
                {
                    PosShape shapeCopy = shape.Clone() as PosShape;
                    shapeCopy.ClearShapeTexts();
                    AddItem(shapeCopy);
                }
            }

            ResumeUpdate();
        }
Example #16
0
        public void SetShape()
        {
            PosShape copy = GetSelected();

            if (copy == null)
            {
                return;
            }

            udFields.Value         = copy.Fields;
            txtFormula.Text        = copy.Formula;
            txtFormulaBending.Text = copy.FormulaBending;
            udPriority.Value       = Math.Max(0, Math.Min(copy.Priority, 99));

            posShapeView.SuspendUpdate();
            posShapeView.ClearItems();
            posShapeView.AddItem(copy);
            posShapeView.ResumeUpdate();
        }
Example #17
0
        private void ApplyChanges()
        {
            string userFolder     = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "RebarPos");
            string userShapesFile = System.IO.Path.Combine(userFolder, "ShapeList.txt");
            string newShapesFile  = System.IO.Path.Combine(userFolder, "ShapeList.new");

            foreach (PosShape copy in m_Copies)
            {
                if (!copy.IsBuiltIn)
                {
                    if (PosShape.HasPosShape(copy.Name))
                    {
                        PosShape org = PosShape.GetPosShape(copy.Name);
                        org.Fields         = copy.Fields;
                        org.Formula        = copy.Formula;
                        org.FormulaBending = copy.FormulaBending;
                        org.Priority       = copy.Priority;
                        org.Items.Clear();
                        for (int i = 0; i < copy.Items.Count; i++)
                        {
                            org.Items.Add(copy.Items[i].Clone());
                        }
                    }
                    else
                    {
                        PosShape.AddPosShape(copy);
                    }
                }
            }

            try
            {
                PosShape.SavePosShapesToFile(newShapesFile);
                System.IO.File.Delete(userShapesFile);
                System.IO.File.Move(newShapesFile, userShapesFile);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message, "RebarPos", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }

            PosShape.ReadPosShapesFromFile(userShapesFile);
        }
Example #18
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            PosShape org = GetSelected();

            int i = 1;

            while (m_Copies.Exists(p => p.Name.ToUpperInvariant() == "SHAPE" + i.ToString()))
            {
                i++;
            }

            PosShape copy = new PosShape();

            copy.Name = "Shape" + i.ToString();

            copy.Fields         = org != null ? org.Fields : 1;
            copy.Formula        = org != null ? org.Formula : "A";
            copy.FormulaBending = org != null ? org.FormulaBending : "A";
            copy.Priority       = org != null ? org.Priority : 0;

            if (org != null)
            {
                for (int k = 0; k < org.Items.Count; k++)
                {
                    PosShape.Shape draw = org.Items[k];
                    copy.Items.Add(draw.Clone());
                }
            }

            m_Copies.Add(copy);

            ListViewItem lv = new ListViewItem(copy.Name);

            lv.SubItems.Add(copy.Fields.ToString());
            lv.SubItems.Add(copy.Formula);
            lv.SubItems.Add(copy.FormulaBending);
            lv.ImageIndex = 1;
            lbShapes.Items.Add(lv);
            lbShapes.SelectedIndices.Clear();
            lbShapes.SelectedIndices.Add(lbShapes.Items.Count - 1);
            lv.BeginEdit();
        }
Example #19
0
        private void btnRename_Click(object sender, EventArgs e)
        {
            if (lbShapes.SelectedIndices.Count == 0)
            {
                return;
            }
            PosShape copy = GetSelected();

            if (copy.IsBuiltIn)
            {
                return;
            }

            if (!ShowEditMessage())
            {
                return;
            }

            lbShapes.SelectedItems[0].BeginEdit();
        }
Example #20
0
 public void SetShapes(string current)
 {
     SetShapes(current, PosShape.GetAllPosShapes());
 }
Example #21
0
        private bool SetShape()
        {
            if (chkShowPieceLengths.Checked)
            {
                posShapeView.SetShape(m_Shape, txtA.Text, txtB.Text, txtC.Text, txtD.Text, txtE.Text, txtF.Text);
            }
            else
            {
                posShapeView.SetShape(m_Shape);
            }

            PosShape shape = PosShape.GetPosShape(m_Shape);

            if (shape == null)
            {
                return(false);
            }

            if (m_Bending)
            {
                m_Formula = shape.FormulaBending;
            }
            else
            {
                m_Formula = shape.Formula;
            }

            m_Fields     = shape.Fields;
            txtA.Enabled = btnSelectA.Enabled = btnMeasureA.Enabled = (m_Fields >= 1);
            txtB.Enabled = btnSelectB.Enabled = btnMeasureB.Enabled = (m_Fields >= 2);
            txtC.Enabled = btnSelectC.Enabled = btnMeasureC.Enabled = (m_Fields >= 3);
            txtD.Enabled = btnSelectD.Enabled = btnMeasureD.Enabled = (m_Fields >= 4);
            txtE.Enabled = btnSelectE.Enabled = btnMeasureE.Enabled = (m_Fields >= 5);
            txtF.Enabled = btnSelectF.Enabled = btnMeasureF.Enabled = (m_Fields >= 6);

            if (!txtA.Enabled)
            {
                txtA.Text = "";
            }
            if (!txtB.Enabled)
            {
                txtB.Text = "";
            }
            if (!txtC.Enabled)
            {
                txtC.Text = "";
            }
            if (!txtD.Enabled)
            {
                txtD.Text = "";
            }
            if (!txtE.Enabled)
            {
                txtE.Text = "";
            }
            if (!txtF.Enabled)
            {
                txtF.Text = "";
            }

            lblPosShape.Text = m_Shape;

            return(true);
        }
Example #22
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 #23
0
        public static void DrawShape(PosShape shape, Point3d inspt, double height)
        {
            Extents3d?bounds = shape.Bounds;

            if (!bounds.HasValue)
            {
                return;
            }
            Point3d  p1    = bounds.Value.MinPoint;
            Point3d  p2    = bounds.Value.MaxPoint;
            double   scale = height / (p2.Y - p1.Y);
            Matrix3d trans = Matrix3d.AlignCoordinateSystem(p1, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis,
                                                            inspt, Vector3d.XAxis * scale, Vector3d.YAxis * scale, Vector3d.ZAxis * scale);

            Database db = HostApplicationServices.WorkingDatabase;

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

                    Point3dCollection vertices = new Point3dCollection(new Point3d[] {
                        new Point3d(p1.X, p1.Y, 0),
                        new Point3d(p2.X, p1.Y, 0),
                        new Point3d(p2.X, p2.Y, 0),
                        new Point3d(p1.X, p2.Y, 0),
                    });
                    Polyline2d rec = new Polyline2d(Poly2dType.SimplePoly, vertices, 0, true, 0, 0, null);
                    rec.TransformBy(trans);
                    btr.AppendEntity(rec);
                    tr.AddNewlyCreatedDBObject(rec, true);

                    ObjectId hiddenLayer = PosUtility.DefpointsLayer;

                    foreach (PosShape.Shape item in shape.Items)
                    {
                        Entity en = null;

                        if (item is PosShape.ShapeLine)
                        {
                            PosShape.ShapeLine line = (PosShape.ShapeLine)item;
                            en = new Line(new Point3d(line.X1, line.Y1, 0), new Point3d(line.X2, line.Y2, 0));
                        }
                        else if (item is PosShape.ShapeArc)
                        {
                            PosShape.ShapeArc arc = (PosShape.ShapeArc)item;
                            en = new Arc(new Point3d(arc.X, arc.Y, 0), arc.R, arc.StartAngle, arc.EndAngle);
                        }
                        else if (item is PosShape.ShapeCircle)
                        {
                            PosShape.ShapeCircle circle = (PosShape.ShapeCircle)item;
                            en = new Circle(new Point3d(circle.X, circle.Y, 0), Vector3d.ZAxis, circle.R);
                        }
                        else if (item is PosShape.ShapeText)
                        {
                            PosShape.ShapeText text  = (PosShape.ShapeText)item;
                            DBText             dbobj = new DBText();
                            dbobj.TextString     = text.Text;
                            dbobj.Position       = new Point3d(text.X, text.Y, 0);
                            dbobj.TextStyleId    = PosUtility.CreateTextStyle("ShapeDump_" + shape.Name, text.Font, text.Width);
                            dbobj.Height         = text.Height;
                            dbobj.WidthFactor    = text.Width;
                            dbobj.HorizontalMode = text.HorizontalAlignment;
                            if (text.VerticalAlignment == TextVerticalMode.TextBottom)
                            {
                                dbobj.VerticalMode = TextVerticalMode.TextBase;
                            }
                            else
                            {
                                dbobj.VerticalMode = text.VerticalAlignment;
                            }

                            if (dbobj.HorizontalMode != TextHorizontalMode.TextLeft || dbobj.VerticalMode != TextVerticalMode.TextBase)
                            {
                                dbobj.AlignmentPoint = new Point3d(text.X, text.Y, 0);
                            }
                            en = dbobj;
                        }

                        if (en != null)
                        {
                            en.Color = item.Color;
                            if (!item.Visible)
                            {
                                en.LayerId = hiddenLayer;
                            }
                            en.TransformBy(trans);

                            btr.AppendEntity(en);
                            tr.AddNewlyCreatedDBObject(en, true);
                        }
                    }

                    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 #24
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 #25
0
 public static void DrawShape(string name, Point3d inspt, double height)
 {
     DrawShape(PosShape.GetPosShape(name), inspt, height);
 }
Example #26
0
        public static void DrawShape(PosShape shape, Point3d inspt, double height)
        {
            Extents3d? bounds = shape.Bounds;
            if (!bounds.HasValue) return;
            Point3d p1 = bounds.Value.MinPoint;
            Point3d p2 = bounds.Value.MaxPoint;
            double scale = height / (p2.Y - p1.Y);
            Matrix3d trans = Matrix3d.AlignCoordinateSystem(p1, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis,
                inspt, Vector3d.XAxis * scale, Vector3d.YAxis * scale, Vector3d.ZAxis * scale);

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

                    Point3dCollection vertices = new Point3dCollection(new Point3d[]{
                            new Point3d(p1.X, p1.Y, 0),
                            new Point3d(p2.X, p1.Y, 0),
                            new Point3d(p2.X, p2.Y, 0),
                            new Point3d(p1.X, p2.Y, 0),
                        });
                    Polyline2d rec = new Polyline2d(Poly2dType.SimplePoly, vertices, 0, true, 0, 0, null);
                    rec.TransformBy(trans);
                    btr.AppendEntity(rec);
                    tr.AddNewlyCreatedDBObject(rec, true);

                    ObjectId hiddenLayer = PosUtility.DefpointsLayer;

                    foreach (PosShape.Shape item in shape.Items)
                    {
                        Entity en = null;

                        if (item is PosShape.ShapeLine)
                        {
                            PosShape.ShapeLine line = (PosShape.ShapeLine)item;
                            en = new Line(new Point3d(line.X1, line.Y1, 0), new Point3d(line.X2, line.Y2, 0));
                        }
                        else if (item is PosShape.ShapeArc)
                        {
                            PosShape.ShapeArc arc = (PosShape.ShapeArc)item;
                            en = new Arc(new Point3d(arc.X, arc.Y, 0), arc.R, arc.StartAngle, arc.EndAngle);
                        }
                        else if (item is PosShape.ShapeCircle)
                        {
                            PosShape.ShapeCircle circle = (PosShape.ShapeCircle)item;
                            en = new Circle(new Point3d(circle.X, circle.Y, 0), Vector3d.ZAxis, circle.R);
                        }
                        else if (item is PosShape.ShapeText)
                        {
                            PosShape.ShapeText text = (PosShape.ShapeText)item;
                            DBText dbobj = new DBText();
                            dbobj.TextString = text.Text;
                            dbobj.Position = new Point3d(text.X, text.Y, 0);
                            dbobj.TextStyleId = PosUtility.CreateTextStyle("ShapeDump_" + shape.Name, text.Font, text.Width);
                            dbobj.Height = text.Height;
                            dbobj.WidthFactor = text.Width;
                            dbobj.HorizontalMode = text.HorizontalAlignment;
                            if (text.VerticalAlignment == TextVerticalMode.TextBottom)
                                dbobj.VerticalMode = TextVerticalMode.TextBase;
                            else
                                dbobj.VerticalMode = text.VerticalAlignment;

                            if (dbobj.HorizontalMode != TextHorizontalMode.TextLeft || dbobj.VerticalMode != TextVerticalMode.TextBase)
                            {
                                dbobj.AlignmentPoint = new Point3d(text.X, text.Y, 0);
                            }
                            en = dbobj;
                        }

                        if (en != null)
                        {
                            en.Color = item.Color;
                            if (!item.Visible) en.LayerId = hiddenLayer;
                            en.TransformBy(trans);

                            btr.AppendEntity(en);
                            tr.AddNewlyCreatedDBObject(en, true);
                        }
                    }

                    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 #27
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            PosShape org = GetSelected();

            int i = 1;
            while (m_Copies.Exists(p => p.Name.ToUpperInvariant() == "SHAPE" + i.ToString()))
            {
                i++;
            }

            PosShape copy = new PosShape();

            copy.Name = "Shape" + i.ToString();

            copy.Fields = org != null ? org.Fields : 1;
            copy.Formula = org != null ? org.Formula : "A";
            copy.FormulaBending = org != null ? org.FormulaBending : "A";
            copy.Priority = org != null ? org.Priority : 0;

            if (org != null)
            {
                for (int k = 0; k < org.Items.Count; k++)
                {
                    PosShape.Shape draw = org.Items[k];
                    copy.Items.Add(draw.Clone());
                }
            }

            m_Copies.Add(copy);

            ListViewItem lv = new ListViewItem(copy.Name);
            lv.SubItems.Add(copy.Fields.ToString());
            lv.SubItems.Add(copy.Formula);
            lv.SubItems.Add(copy.FormulaBending);
            lv.ImageIndex = 1;
            lbShapes.Items.Add(lv);
            lbShapes.SelectedIndices.Clear();
            lbShapes.SelectedIndices.Add(lbShapes.Items.Count - 1);
            lv.BeginEdit();
        }
Example #28
0
        private void btnSelectShapes_Click(object sender, EventArgs e)
        {
            PosShape copy = GetSelected();

            if (copy == null || copy.IsBuiltIn)
            {
                return;
            }

            // Select shapes
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

            using (EditorUserInteraction UI = ed.StartUserInteraction(this))
            {
                TypedValue[] tvs = new TypedValue[] {
                    new TypedValue((int)DxfCode.Operator, "<OR"),
                    new TypedValue((int)DxfCode.Start, "LINE"),
                    new TypedValue((int)DxfCode.Start, "ARC"),
                    new TypedValue((int)DxfCode.Start, "CIRCLE"),
                    new TypedValue((int)DxfCode.Start, "TEXT"),
                    new TypedValue((int)DxfCode.Operator, "OR>")
                };
                SelectionFilter       filter = new SelectionFilter(tvs);
                PromptSelectionResult result = ed.GetSelection(filter);

                if (result.Status != PromptStatus.OK || result.Value.Count == 0)
                {
                    return;
                }

                int fieldCount = 1;
                copy.Items.Clear();
                Database db = HostApplicationServices.WorkingDatabase;
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    try
                    {
                        foreach (SelectedObject sel in result.Value)
                        {
                            DBObject obj = tr.GetObject(sel.ObjectId, OpenMode.ForRead);

                            bool   visible = true;
                            Entity en      = obj as Entity;
                            if (en != null)
                            {
                                LayerTableRecord ltr = (LayerTableRecord)tr.GetObject(en.LayerId, OpenMode.ForRead);

                                if (ltr != null)
                                {
                                    visible = ltr.IsPlottable;
                                }
                            }

                            if (obj is Line)
                            {
                                Line line = obj as Line;

                                copy.Items.Add(new PosShape.ShapeLine(line.Color, line.StartPoint.X, line.StartPoint.Y, line.EndPoint.X, line.EndPoint.Y, visible));
                            }
                            else if (obj is Arc)
                            {
                                Arc arc = obj as Arc;
                                copy.Items.Add(new PosShape.ShapeArc(arc.Color, arc.Center.X, arc.Center.Y, arc.Radius, arc.StartAngle, arc.EndAngle, visible));
                            }
                            else if (obj is Circle)
                            {
                                Circle circle = obj as Circle;
                                copy.Items.Add(new PosShape.ShapeCircle(circle.Color, circle.Center.X, circle.Center.Y, circle.Radius, visible));
                            }
                            else if (obj is DBText)
                            {
                                DBText text = obj as DBText;
                                if (text.TextString == "A" && fieldCount < 1)
                                {
                                    fieldCount = 1;
                                }
                                if (text.TextString == "B" && fieldCount < 2)
                                {
                                    fieldCount = 2;
                                }
                                if (text.TextString == "C" && fieldCount < 3)
                                {
                                    fieldCount = 3;
                                }
                                if (text.TextString == "D" && fieldCount < 4)
                                {
                                    fieldCount = 4;
                                }
                                if (text.TextString == "E" && fieldCount < 5)
                                {
                                    fieldCount = 5;
                                }
                                if (text.TextString == "F" && fieldCount < 6)
                                {
                                    fieldCount = 6;
                                }
                                double x = text.Position.X;
                                double y = text.Position.Y;
                                if (text.AlignmentPoint.X != 0.0 || text.AlignmentPoint.Y != 0.0)
                                {
                                    x = text.AlignmentPoint.X;
                                    y = text.AlignmentPoint.Y;
                                }
                                copy.Items.Add(new PosShape.ShapeText(text.Color, x, y, text.Height, text.WidthFactor, text.TextString, "romans.shx", text.HorizontalMode, text.VerticalMode, visible));
                            }
                        }
                    }
                    catch (System.Exception ex)
                    {
                        System.Windows.Forms.MessageBox.Show("Error: " + ex.Message, "RebarPos", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    }
                }

                udFields.Value = fieldCount;
            }

            SetShape();
        }