Updating extents of drawing
Moderators: SDS, support, admin
Updating extents of drawing
Hello
Ñ—How can I update drawing extents (ViewerMainForm.FCADImage.Extents) when I add or delete some entities to the drawing?
Ñ—How can I update drawing extents (ViewerMainForm.FCADImage.Extents) when I add or delete some entities to the drawing?
It seems I cannot edit my previous message.
What I really want to do is to zoom my drawing extents. I know the extents and store them on a dRect structure (in drawing coordinates), but I am not able to do a zoom that shows that dRect adjusted to cadpictbox. The ResetScaling method is not valid because I change the initial extents of drawing.
My question is rather simple Ñ—how can I zoom to a given rectangle? being the rectangle in drawing coordinates
Thanks
What I really want to do is to zoom my drawing extents. I know the extents and store them on a dRect structure (in drawing coordinates), but I am not able to do a zoom that shows that dRect adjusted to cadpictbox. The ResetScaling method is not valid because I change the initial extents of drawing.
My question is rather simple Ñ—how can I zoom to a given rectangle? being the rectangle in drawing coordinates
Thanks
Hello Zebiya,
We will answer you soon.
Sergey.
Please post questions to the forum or write to support@cadsofttools.com
We will answer you soon.
Sergey.
Please post questions to the forum or write to support@cadsofttools.com
Hello Zebiya,
The following code takes entity by entity and zooms within its bounding rectangle. It is based on <b>Viewer</b> demo :
Sergey.
Please post questions to the forum or write to support@cadsofttools.com
The following code takes entity by entity and zooms within its bounding rectangle. It is based on <b>Viewer</b> demo :
Code: Select all
<font color="blue">private float</font id="blue"> SetNewScale(Point topLeft, Point bottomRight)
{
Rectangle entRect = <font color="blue">new</font id="blue"> Rectangle(topLeft.X - 2, topLeft.Y - 2, (bottomRight.X - topLeft.X) + 4, (bottomRight.Y - topLeft.Y) + 4);
<font color="blue">float</font id="blue"> kf1 = (<font color="blue">this</font id="blue">.curClRect.Width * scale) / entRect.Width;
<font color="blue">float</font id="blue">kf2 = (<font color="blue">this</font id="blue">.curClRect.Height * scale) / entRect.Height;
<font color="blue">if</font id="blue">(kf1 > kf2)
kf1 = kf2;
<font color="blue">return</font id="blue"> kf1;
}
<font color="blue">private int</font id="blue"> cnt_ent = 0;
<font color="blue">private void</font id="blue"> btnShowRect_Click(<font color="blue">object</font id="blue"> sender, System.EventArgs e)
{
<font color="blue">this</font id="blue">.cadImage.UseBufMetafile = <font color="blue">false</font id="blue">;
cadPictBox.Invalidate();
<font color="blue">if</font id="blue">(cnt_ent >= <font color="blue">this</font id="blue">.cadImage.Converter.Entities.Count)
cnt_ent = 0;
CADEntity ent = <font color="blue">this</font id="blue">.cadImage.Converter.Entities[cnt_ent];
Point topLeft = <font color="blue">this</font id="blue">.cadImage.GetPoint(ent.Box.TopLeft);
Point bottomRight = <font color="blue">this</font id="blue">.cadImage.GetPoint(ent.Box.BottomRight);
<font color="green">//shift----------</font id="green">
<font color="blue">float</font id="blue"> centerX = <font color="blue">this</font id="blue">.curClRect.Width / 2.0f - (bottomRight.X - topLeft.X) / 2.0f;
<font color="blue">float</font id="blue"> centerY = <font color="blue">this</font id="blue">.curClRect.Height / 2.0f - (bottomRight.Y - topLeft.Y) / 2.0f;
<font color="blue">this</font id="blue">.pos.X = <font color="blue">this</font id="blue">.pos.X - topLeft.X + centerX;
<font color="blue">this</font id="blue">.pos.Y = <font color="blue">this</font id="blue">.pos.Y - topLeft.Y + centerY;
<font color="green">//--------------</font id="green">
old_Pos = <font color="blue">new</font id="blue"> PointF(cadPictBox.ClientRectangle.Width / 2, cadPictBox.ClientRectangle.Height / 2);
<font color="blue">this</font id="blue">.scale = SetNewScale(topLeft, bottomRight);
cadPictBox.Invalidate();
cnt_ent++;
}
Please post questions to the forum or write to support@cadsofttools.com
Hello Zebiya,
Please try the following code:
Sergey
Please post questions to the forum or write to support@cadsofttools.com
Please try the following code:
Code: Select all
<font color="blue">Private Sub</font id="blue"> btnShowRect_Click(<font color="blue">ByVal</font id="blue"> sender <font color="blue">As</font id="blue"> System.Object, <font color="blue">ByVal</font id="blue"> e <font color="blue">As</font id="blue"> System.EventArgs) <font color="blue">Handles</font id="blue"> btnShowRect.Click
<font color="blue">Me</font id="blue">.FCADImage.UseBufMetafile = <font color="blue">False</font id="blue">
cadPictBox.Invalidate()
<font color="blue">If</font id="blue"> (cnt_ent >= <font color="blue">Me</font id="blue">.FCADImage.Converter.Entities.Count) <font color="blue">Then</font id="blue">
cnt_ent = 0
<font color="blue">End If
Dim</font id="blue"> ent <font color="blue">As</font id="blue"> CADEntity = <font color="blue">Me</font id="blue">.FCADImage.Converter.Entities(cnt_ent)
<font color="blue">Dim</font id="blue"> topLeft <font color="blue">As</font id="blue"> Point = <font color="blue">Me</font id="blue">.FCADImage.GetPoint(ent.Box.TopLeft)
<font color="blue">Dim</font id="blue"> bottomRight <font color="blue">As</font id="blue"> Point = <font color="blue">Me</font id="blue">.FCADImage.GetPoint(ent.Box.BottomRight)
<font color="green">'//shift----------</font id="green">
<font color="blue">Dim</font id="blue"> centerX <font color="blue">As Single</font id="blue"> = <font color="blue">Me</font id="blue">.curClRect.Width / 2.0F - (bottomRight.X - topLeft.X) / 2.0F
<font color="blue">Dim</font id="blue"> centerY <font color="blue">As Single</font id="blue"> = <font color="blue">Me</font id="blue">.curClRect.Height / 2.0F - (bottomRight.Y - topLeft.Y) / 2.0F
<font color="blue">Me</font id="blue">.pos.X = <font color="blue">Me</font id="blue">.pos.X - topLeft.X + centerX
<font color="blue">Me</font id="blue">.pos.Y = <font color="blue">Me</font id="blue">.pos.Y - topLeft.Y + centerY
<font color="green">'//--------------</font id="green">
old_Pos = <font color="blue">New</font id="blue"> PointF(cadPictBox.ClientRectangle.Width / 2, cadPictBox.ClientRectangle.Height / 2)
<font color="blue">Me</font id="blue">.scl = SetNewScale(topLeft, bottomRight)
cadPictBox.Invalidate()
cnt_ent = cnt_ent + 1
<font color="blue">End Sub</font id="blue">
<font color="blue">Private Function</font id="blue"> SetNewScale(<font color="blue">ByVal</font id="blue"> topLeft <font color="blue">As</font id="blue"> Point, <font color="blue">ByVal</font id="blue"> bottomRight <font color="blue">As</font id="blue"> Point) <font color="blue">As Single</font id="blue">
<font color="blue">Dim</font id="blue"> entRect <font color="blue">As</font id="blue"> Rectangle = <font color="blue">New</font id="blue"> Rectangle(topLeft.X - 2, topLeft.Y - 2, (bottomRight.X - topLeft.X) + 4, (bottomRight.Y - topLeft.Y) + 4)
<font color="blue">Dim</font id="blue"> kf1 <font color="blue">As Single</font id="blue"> = (<font color="blue">Me</font id="blue">.curClRect.Width * Me.scl) / entRect.Width
<font color="blue">Dim</font id="blue"> kf2 <font color="blue">As Single</font id="blue"> = (<font color="blue">Me</font id="blue">.curClRect.Height * Me.scl) / entRect.Height
<font color="blue">If</font id="blue"> (kf1 > kf2) <font color="blue">Then</font id="blue">
kf1 = kf2
<font color="blue">End If
Return</font id="blue"> kf1
<font color="blue">End Function
Public</font id="blue"> cnt_ent <font color="blue">As</font id="blue"> Integer = 0
Please post questions to the forum or write to support@cadsofttools.com