EntitiesCreator

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
yannick
Posts: 18
Joined: 16 Apr 2008, 12:43

EntitiesCreator

Post by yannick » 20 Nov 2008, 16:51

Hello,

I need to allow user to add lines and texts in editor. So i would like to use the class EntitiesCreator.
I read sample EditorDemo and i copy codes in my application but when i click in map nothing appear, i don't get start of line.
So i badly use EntitiesCreator but i don't find what is missing.

I join a simple sample, could you say me what is missing.
Other questions, how can i choose color and thickness of the line, rectangle, polyline, etc..

Best regards, yannick


public partial class frmEditor : Form
{
public frmEditor()
{
InitializeComponent();

Init();

LoadMap();
}

#region VAR
private CADImport.CADImage cadImage;
private System.Drawing.SizeF visibleArea;
private bool useDoubleBuffering;
private CADImport.FaceModule.ClipRect clipRectangle;
private System.Drawing.PointF pos;
protected CADPictureBox cadPictBox = null;
private System.Windows.Forms.PropertyGrid propGrid;
protected EntitiesCreator entCreator;
#endregion VAR


protected void Init()
{
cadPictBox = new CADPictureBox();
cadPictBox.BackColor = Color.Black;
cadPictBox.Dock = DockStyle.Fill;

this.Controls.Add(cadPictBox);

propGrid = new PropertyGrid();
CADImportFace.EntityPropertyGrid = this.propGrid;

this.cadPictBox.MouseDown += new System.Windows.Forms.MouseEventHandler(this.cadPictBox_MouseDown);
this.cadPictBox.Paint += new PaintEventHandler(cadPictureBox_Paint);

this.clipRectangle = new ClipRect(this.cadPictBox);
this.clipRectangle.MultySelect = false;
}

protected void LoadMap()
{
string sCompletMapFileName = @"D:\STARVW\Carte\CONDORCET.dwg";

this.cadImage = CADImage.CreateImageByExtension(sCompletMapFileName);
cadImage.LoadFromFile(sCompletMapFileName);

cadPictBox.Focus();

VisibleAreaSize = cadPictBox.Size;
ResetScaling();

cadImage.SetCurrentLayout(0);
cadImage.DefaultLayoutIndex = 0;

cadPictBox.Enabled = true;

cadImage.UseWinEllipse = false;
cadImage.IsShowLineWeight = false;

useDoubleBuffering = false;
cadImage.UseDoubleBuffering = useDoubleBuffering;

cadImage.DrawMode = CADDrawMode.Normal;

this.cadImage.IsDraw3DAxes = false;
cadImage.SelectionMode = SelectionEntityMode.Enabled;

ObjEntity.cadImage = cadImage;
ObjEntity.propGrid = this.propGrid;

this.entCreator = new EntitiesCreator(this.cadPictBox, Color.White);

this.entCreator.Image = this.cadImage;
cadImage.SelectionMode = SelectionEntityMode.Enabled;

cadImage.UseDoubleBuffering = false;
this.cadPictBox.Invalidate();
}


private void cadPictBox_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
try
{
CreatorType seltp = CreatorType.Line;

this.entCreator.EnableCreator(seltp);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "ERREUR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

void cadPictureBox_Paint(object sender, PaintEventArgs e)
{
if (cadImage == null) return;
DrawCADImage(e.Graphics);
}

public void DrawCADImage(Graphics gr)
{
try
{
Cursor curs = Cursor.Current;
//Shift();
RectangleF tmp = ImageRectangleF;
SetSizePictureBox(new Size((int)tmp.Width, (int)tmp.Height));

cadImage.Draw(gr, tmp);

Cursor.Current = Cursors.Default;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "ERREUR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

protected void ResetScaling()
{
LeftImagePosition = (cadPictBox.ClientRectangle.Width - VisibleAreaSize.Width) / 2.0f;
TopImagePosition = (cadPictBox.ClientRectangle.Height - VisibleAreaSize.Height) / 2.0f;
cadPictBox.Invalidate();
}


/*private void Shift()
{
LeftImagePosition = PreviousPosition.X - (PreviousPosition.X - LeftImagePosition) * ImageScale / ImagePreviousScale;
TopImagePosition = PreviousPosition.Y - (PreviousPosition.Y - TopImagePosition) * ImageScale / ImagePreviousScale;
ImagePreviousScale = ImageScale;
}*/

protected float ImageScale
{
get
{
return 1.0f;
}
}

protected float ImagePreviousScale
{
get
{
return 1.0f;
}
}



public void SetSizePictureBox(Size sz)
{
this.cadPictBox.SetVirtualSizeNoInvalidate(sz);
}

protected RectangleF ImageRectangleF
{
get
{
return new RectangleF(this.LeftImagePosition, this.TopImagePosition,
VisibleAreaSize.Width * ImageScale, VisibleAreaSize.Height * ImageScale);
}
}

protected SizeF VisibleAreaSize
{
get
{
return this.visibleArea;
}
set
{
this.visibleArea = value;
}
}

protected float LeftImagePosition
{
get
{
return this.pos.X;
}
set
{
this.pos.X = value;
}
}

protected float TopImagePosition
{
get
{
return this.pos.Y;
}
set
{
this.pos.Y = value;
}
}


}

Evgeny
Posts: 115
Joined: 16 Mar 2004, 11:04
Location: Russia

Re: EntitiesCreator

Post by Evgeny » 24 Nov 2008, 11:44

Hello Yannick,

Thank you for the post.

If you need to add entities programmatically, we suggest to use AddEntityDemo. It shows how to create lines, texts and other entities. Also you can see there how to set properties: color, layer, etc.

If you wish to customize the way of entities creating which is used in Editor demo please use this demo and change it. It has many methods which should be implemented.

Kind regards,
Evgeny

Post Reply