c# 2D Cad Cizim Yardım

Başlatan 61rev, 07 Şubat 2016, 23:21:41

61rev




Merhaba resimdeki gibi c# ile pvc cizim programı için cizim yapmak istiyorum ancak nasıl bir yol izleyecegimi bulamıyorum. ne internette nede kitaplarda yeterli dökümanı bulamadım yardımlarınızı bekliyorum.

61rev

çok mu zor bi konu kimse tek kelime etmiyor.

kamilsorhan

Eğer sadece pencerenin şeklini  nasıl çizebileceğini soruyorsan , C# ta bulunan GDI sınıfı ile çizebilirsin.

atomx

Bircok yolu var ama hadi dedimmi anlatikacak birsey yok. Önce vektör tabanli mi cizim olacak yoksa bitmap tababli mi? Vektör tabanli cizimler icin Directx opengl pixelshader bu arayuzlerin programlamasini bilmelisiniz. C# directx kolay yolu xna game studiodur. Gerisi alogoritma hocam, senin hayl gücün.
Hüseyin TECER

61rev

bitmap olsa click olayı eklemek daha zor olur galiba. pencere veya cam a tıklandıgında ilgili diyalogu acmak lazim . amac dogramayı cizmek ve cizilen dogramada ilgili bölümleri düzenleyebilme click eklemek. dediklerinizi araştırmaya başlıyorum.

Tesla.25

Ben konuyu anlamadım. Sıfırdan bir CAD programı mı yazmak amaç?
Durum buysa, ha dedin mi kimse yardım edemez. Basit bir konu değil. Uzmanlık alanı.

z

Bir ara forumdan bir arkadaş bir şeyler yapmıştı.
Bana e^st de diyebilirsiniz.   www.cncdesigner.com

tunayk

2D düzeyde okadar zor değil.  Bir formun üzerindeki nesnelerin nasıl görüntülendiğini be mouse ve klavye olaylarının nasıl yakalandığını öğrenirsiniz (mekanizma olarak) dediğiniz işler zor değil.  Önce Pencere diye bir class tanımlarını. Buna cam kanat kasa vb. Alt nesneleri eklerseniz. Her alt nesnenin nasıl çizileceğini ve şeklin tam koordinatları iç alanlarını belirlersin.
Sonrasında paint olayında sırayla alttan üste doğru sırasıyla bu nesneleri çizersin.  PictureBox click olayından mouse pozisyonu alıp kendi nesnelerinizin iç alanlarında olup olmadığını kontrol edersin. Buna göre de işlem yaparsınız.
Gibi gibi.

61rev

Alıntı yapılan: Tesla.25 - 09 Şubat 2016, 22:19:52
Ben konuyu anlamadım. Sıfırdan bir CAD programı mı yazmak amaç?
Durum buysa, ha dedin mi kimse yardım edemez. Basit bir konu değil. Uzmanlık alanı.

Cad cizimden kastım solid maya autocad değil daha okadar uçmadık mesele 2d pvc cizim yapmak  ;)

61rev

Alıntı yapılan: z - 09 Şubat 2016, 22:24:34
Bir ara forumdan bir arkadaş bir şeyler yapmıştı.

bir tane buldum ama o paint gibi birşey yapmış bizim ki son kullanıcıya cizim yaptırmakyacak girilen degerlere resim cizecek

61rev

Alıntı yapılan: tunayk - 09 Şubat 2016, 22:31:56
2D düzeyde okadar zor değil.  Bir formun üzerindeki nesnelerin nasıl görüntülendiğini be mouse ve klavye olaylarının nasıl yakalandığını öğrenirsiniz (mekanizma olarak) dediğiniz işler zor değil.  Önce Pencere diye bir class tanımlarını. Buna cam kanat kasa vb. Alt nesneleri eklerseniz. Her alt nesnenin nasıl çizileceğini ve şeklin tam koordinatları iç alanlarını belirlersin.
Sonrasında paint olayında sırayla alttan üste doğru sırasıyla bu nesneleri çizersin.  PictureBox click olayından mouse pozisyonu alıp kendi nesnelerinizin iç alanlarında olup olmadığını kontrol edersin. Buna göre de işlem yaparsınız.
Gibi gibi.
sonuc olarak tek resim olacak belirlediğimiz kordinatları aynı sıralama ile denetleyecez. sanırım nesneleri ayrı ayrı picturebox'a aktaramayız.ve bu cizimler icin drawing kütüphesine yeterli olur. yoksa dgı+ yada directx e ihtiyac duymuyoruz.birde bu drumumda drawing de her değişiklikte tüm nesneyi yeniden cizmemiz gerekiyor.ve her fare hareketınde nerde oludugunu ogrenmek için yorucu bir kod blogu calıstıracaz sanırım.

ve yorumunuz faydalı oldu şimdiden sayenizde sistemi kafamda tasarımlıyorum yavastan yavastan



atomx

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private Rectangle areaRect = new Rectangle(100, 100, 300, 300);
        private Rectangle oldRect;
        private int dragHandle = 0;
        private Point dragPoint;

        public Form1()
        {
            InitializeComponent();
            this.DoubleBuffered = true;
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            for (int i = 1; i < 9; i++)
            {
                if (GetHandleRect(i).Contains(e.Location))
                {
                    dragHandle = i;
                    oldRect = areaRect;
                    dragPoint = GetHandlePoint(i);
                }
            }
            base.OnMouseDown(e);
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (dragHandle == 1)
            {
                int diffX = dragPoint.X - e.Location.X;
                int diffY = dragPoint.Y - e.Location.Y;
                areaRect = new Rectangle(oldRect.Left - diffX, oldRect.Top - diffY , oldRect.Width + diffX, oldRect.Height +diffY);
            }
            else if (dragHandle == 2)
            {
                int diff = dragPoint.X - e.Location.X;
                areaRect = new Rectangle(oldRect.Left - diff, oldRect.Top, oldRect.Width + diff, oldRect.Height);
            }
            else if (dragHandle == 3)
            {
                int diffX = dragPoint.X - e.Location.X;
                int diffY = dragPoint.Y - e.Location.Y;
                areaRect = new Rectangle(oldRect.Left - diffX, oldRect.Top, oldRect.Width + diffX, oldRect.Height - diffY);
            }
            else if (dragHandle == 4)
            {
                int diffX = dragPoint.X - e.Location.X;
                int diffY = dragPoint.Y - e.Location.Y;
                areaRect = new Rectangle(oldRect.Left, oldRect.Top - diffY, oldRect.Width, oldRect.Height + diffY);
            }
            else if (dragHandle == 5)
            {
                int diffX = dragPoint.X - e.Location.X;
                int diffY = dragPoint.Y - e.Location.Y;
                areaRect = new Rectangle(oldRect.Left, oldRect.Top, oldRect.Width, oldRect.Height - diffY);
            }
            else if (dragHandle == 6)
            {
                int diffX = dragPoint.X - e.Location.X;
                int diffY = dragPoint.Y - e.Location.Y;
                areaRect = new Rectangle(oldRect.Left, oldRect.Top - diffY, oldRect.Width - diffX, oldRect.Height + diffY);
            }
            else if (dragHandle == 7)
            {
                int diff = dragPoint.X - e.Location.X;
                areaRect = new Rectangle(oldRect.Left, oldRect.Top, oldRect.Width - diff, oldRect.Height);
            }
            else if (dragHandle == 8)
            {
                int diffX = dragPoint.X - e.Location.X;
                int diffY = dragPoint.Y - e.Location.Y;
                areaRect = new Rectangle(oldRect.Left, oldRect.Top, oldRect.Width - diffX, oldRect.Height - diffY);
            }

            if (dragHandle > 0)
                this.Invalidate();

            base.OnMouseMove(e);
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            dragHandle = 0;
            base.OnMouseUp(e);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.DrawRectangle(Pens.Red, areaRect);
            for (int i = 1; i < 9; i++)
            {
                e.Graphics.FillRectangle(Brushes.DarkRed, GetHandleRect(i));
            }
            base.OnPaint(e);
        }

        private Point GetHandlePoint(int value)
        {
            Point result = Point.Empty;

            if (value == 1)
                result = new Point(areaRect.Left, areaRect.Top);
            else if (value == 2)
                result = new Point(areaRect.Left, areaRect.Top + (areaRect.Height / 2));
            else if (value == 3)
                result = new Point(areaRect.Left, areaRect.Bottom);
            else if (value == 4)
                result = new Point(areaRect.Left + (areaRect.Width / 2), areaRect.Top);
            else if (value == 5)
                result = new Point(areaRect.Left + (areaRect.Width / 2), areaRect.Bottom);
            else if (value == 6)
                result = new Point(areaRect.Right, areaRect.Top);
            else if (value == 7)
                result = new Point(areaRect.Right, areaRect.Top + (areaRect.Height / 2));
            else if (value == 8)
                result = new Point(areaRect.Right, areaRect.Bottom);

            return result;
        }

        private Rectangle GetHandleRect(int value)
        {
            Point p = GetHandlePoint(value);
            p.Offset(-2, -2);
            return new Rectangle(p, new Size(5, 5));
        }
    }
}



fikir edinmeniz için.
Hüseyin TECER

61rev

#12
Alıntı yapılan: atomx - 10 Şubat 2016, 00:35:47
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private Rectangle areaRect = new Rectangle(100, 100, 300, 300);
        private Rectangle oldRect;
        private int dragHandle = 0;
        private Point dragPoint;

        public Form1()
        {
            InitializeComponent();
            this.DoubleBuffered = true;
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            for (int i = 1; i < 9; i++)
            {
                if (GetHandleRect(i).Contains(e.Location))
                {
                    dragHandle = i;
                    oldRect = areaRect;
                    dragPoint = GetHandlePoint(i);
                }
            }
            base.OnMouseDown(e);
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (dragHandle == 1)
            {
                int diffX = dragPoint.X - e.Location.X;
                int diffY = dragPoint.Y - e.Location.Y;
                areaRect = new Rectangle(oldRect.Left - diffX, oldRect.Top - diffY , oldRect.Width + diffX, oldRect.Height +diffY);
            }
            else if (dragHandle == 2)
            {
                int diff = dragPoint.X - e.Location.X;
                areaRect = new Rectangle(oldRect.Left - diff, oldRect.Top, oldRect.Width + diff, oldRect.Height);
            }
            else if (dragHandle == 3)
            {
                int diffX = dragPoint.X - e.Location.X;
                int diffY = dragPoint.Y - e.Location.Y;
                areaRect = new Rectangle(oldRect.Left - diffX, oldRect.Top, oldRect.Width + diffX, oldRect.Height - diffY);
            }
            else if (dragHandle == 4)
            {
                int diffX = dragPoint.X - e.Location.X;
                int diffY = dragPoint.Y - e.Location.Y;
                areaRect = new Rectangle(oldRect.Left, oldRect.Top - diffY, oldRect.Width, oldRect.Height + diffY);
            }
            else if (dragHandle == 5)
            {
                int diffX = dragPoint.X - e.Location.X;
                int diffY = dragPoint.Y - e.Location.Y;
                areaRect = new Rectangle(oldRect.Left, oldRect.Top, oldRect.Width, oldRect.Height - diffY);
            }
            else if (dragHandle == 6)
            {
                int diffX = dragPoint.X - e.Location.X;
                int diffY = dragPoint.Y - e.Location.Y;
                areaRect = new Rectangle(oldRect.Left, oldRect.Top - diffY, oldRect.Width - diffX, oldRect.Height + diffY);
            }
            else if (dragHandle == 7)
            {
                int diff = dragPoint.X - e.Location.X;
                areaRect = new Rectangle(oldRect.Left, oldRect.Top, oldRect.Width - diff, oldRect.Height);
            }
            else if (dragHandle == 8)
            {
                int diffX = dragPoint.X - e.Location.X;
                int diffY = dragPoint.Y - e.Location.Y;
                areaRect = new Rectangle(oldRect.Left, oldRect.Top, oldRect.Width - diffX, oldRect.Height - diffY);
            }

            if (dragHandle > 0)
                this.Invalidate();

            base.OnMouseMove(e);
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            dragHandle = 0;
            base.OnMouseUp(e);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.DrawRectangle(Pens.Red, areaRect);
            for (int i = 1; i < 9; i++)
            {
                e.Graphics.FillRectangle(Brushes.DarkRed, GetHandleRect(i));
            }
            base.OnPaint(e);
        }

        private Point GetHandlePoint(int value)
        {
            Point result = Point.Empty;

            if (value == 1)
                result = new Point(areaRect.Left, areaRect.Top);
            else if (value == 2)
                result = new Point(areaRect.Left, areaRect.Top + (areaRect.Height / 2));
            else if (value == 3)
                result = new Point(areaRect.Left, areaRect.Bottom);
            else if (value == 4)
                result = new Point(areaRect.Left + (areaRect.Width / 2), areaRect.Top);
            else if (value == 5)
                result = new Point(areaRect.Left + (areaRect.Width / 2), areaRect.Bottom);
            else if (value == 6)
                result = new Point(areaRect.Right, areaRect.Top);
            else if (value == 7)
                result = new Point(areaRect.Right, areaRect.Top + (areaRect.Height / 2));
            else if (value == 8)
                result = new Point(areaRect.Right, areaRect.Bottom);

            return result;
        }

        private Rectangle GetHandleRect(int value)
        {
            Point p = GetHandlePoint(value);
            p.Offset(-2, -2);
            return new Rectangle(p, new Size(5, 5));
        }
    }
}



fikir edinmeniz için.


yapmak istediğimizle alakasını bulamadım ama mouse kullanımına güzel örnek teşekkurler.