Move to CADEntity
Posted: 08 Aug 2018, 18:29
Does anyone have any sample code that can center a CAD Image over a given CADEntity? I dont want to change the current scale I would just like to move the view so the selected CADEnitiy is centeral.
Below is my current none working attempt. What I am trying to do here is convert the coordinate system of the CADEntity into the coordinate system of the view.
Below is my current none working attempt. What I am trying to do here is convert the coordinate system of the CADEntity into the coordinate system of the view.
Code: Select all
public void GotoCadEntity(CADEntity entity)
{
if(entity != null)
{
DPoint p = entity.Box.Center;
DRect cadExtents = cadImage.Extents;
RectangleF screenExtents = new RectangleF(0, 0, (float)cadImage.AbsWidth, (float)cadImage.AbsHeight);
//float x = (float) RangeConvert(cadExtents.left, cadExtents.right, screenExtents.Left, screenExtents.Right, p.X);
//float y = (float) RangeConvert(cadExtents.top, cadExtents.bottom, screenExtents.Top, screenExtents.Bottom, p.Y);
float x = (float)RangeConvert(cadExtents.left, cadExtents.right, screenExtents.Right, screenExtents.Left, p.X);
float y = (float)RangeConvert(cadExtents.top, cadExtents.bottom, screenExtents.Bottom, screenExtents.Top, p.Y);
float dx = x * (float) ImageScale;
float dy = y * (float) ImageScale;
CenterImagePosition = new PointF(dx, dy);
}
}
//------------------------------------------------------------------------------
public static double RangeConvert(double oldmin, double oldmax, double newmin, double newmax, double value)
{
return (value - oldmin) / (oldmax - oldmin) * (newmax - newmin) + newmin;
}