Zoom to entities

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
scooper540
Posts: 2
Joined: 01 Jul 2008, 15:51

Zoom to entities

Post by scooper540 » 01 Jul 2008, 16:12

Hello,

I want to zoom on an array of entity.
I have already made an union of each boxes of all entites to get the rectangle to zoom into but i don't know how to put these coordinates to zoom on it.

The best result is with PreviousPosition property :

Code: Select all

        internal static void zoomOnEntity(MyMapDisplay map, CADEntity[] entity)
        {
            if(entity.Length == 0)
                return;
            DRect rect = entity[0].Box;
            RectangleF rectangleF;
            foreach(CADEntity en in entity)
            {
                rectangleF = RectangleF.Union(new RectangleF((float)rect.left, (float)rect.top, (float)rect.Width, (float)rect.Height), new RectangleF((float)en.Box.left, (float)en.Box.top, (float)en.Box.Width, (float)en.Box.Height));
                rect = new DRect(rectangleF.X, rectangleF.Y, 0, rectangleF.Right, rectangleF.Bottom, 0);
            }
    
            Point p = map.CADPicture.cadImage.GetPoint(new DPoint(rect.left + rect.Width / 2, rect.top + rect.Height / 2, 0), map.CADPicture.ImageRectangleF);
            map.CADPicture.PreviousPosition = new PointF((float)p.X, (float)p.Y);
            map.CADPicture.ImageScale = 20.0f;
            map.CADPicture.Refresh();
        }
but the result is not good.

Where to set theses coordinates to do a global zoom of the entities ?

Thank you.

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Re: Zoom to entities

Post by support » 02 Jul 2008, 12:10

Hello!

Thank you for the question. We will answer you soon.

Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

scooper540
Posts: 2
Joined: 01 Jul 2008, 15:51

Re: Zoom to entities

Post by scooper540 » 17 Jul 2008, 11:23

Hello,

Have you find a solution which let's me zoom on a special entity or a technic to zoom to see a list of entities ?

Thank you in advance.

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Re: Zoom to entities

Post by support » 18 Jul 2008, 17:13

Hello,

Please try the following code (it is based on Viewer demo):

Code: Select all

private float SetNewScale(Point topLeft, Point bottomRight)
{
	Rectangle entRect = new Rectangle(topLeft.X - 2, topLeft.Y - 2, (bottomRight.X - topLeft.X) + 4, (bottomRight.Y - topLeft.Y) + 4);               
	float kf1 = (this.curClRect.Width * scale) / entRect.Width;
	float kf2 = (this.curClRect.Height * scale) / entRect.Height;     
	if(kf1 > kf2)
		kf1 = kf2;                                   
	return kf1;
}

private int cnt_ent = 0;

private void btnShowRect_Click(object sender, System.EventArgs e)
{     
	this.cadImage.UseDoubleBuffering = false;
	cadPictBox.Invalidate();			

	if(cnt_ent >= this.cadImage.Converter.Entities.Count)
		cnt_ent = 0;
	CADEntity ent = this.cadImage.Converter.Entities[cnt_ent];
	Point topLeft = this.cadImage.GetPoint(ent.Box.TopLeft);               
	Point bottomRight = this.cadImage.GetPoint(ent.Box.BottomRight);          
	//shift----------               
	float centerX = this.curClRect.Width / 2.0f - (bottomRight.X - topLeft.X) / 2.0f;
	float centerY = this.curClRect.Height / 2.0f - (bottomRight.Y - topLeft.Y) / 2.0f;                                                                 
	this.pos.X = this.pos.X - topLeft.X + centerX;          
	this.pos.Y = this.pos.Y - topLeft.Y + centerY;                                        
	//--------------     
	old_Pos = new PointF(cadPictBox.ClientRectangle.Width / 2, cadPictBox.ClientRectangle.Height / 2);
	this.scale = SetNewScale(topLeft, bottomRight);               
	cadPictBox.Invalidate();               
	cnt_ent++;                              
}
Sergey.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply