Zoom questions
Moderators: SDS, support, admin
Zoom questions
This isn't really a problem I've been having with CADImport.NET, really I'm just looking for some advice.
I have been overlaying a networking model on a transparent panel over the top of my CADImage. I have then been drawing components on that panel.
I have got to the stage in development where I need my overlayed model to zoom and scroll whilst locked in position relative to the CADImage underneath. I have successfully managed to lock my model in position relative to the CADImage, so when I scroll the CADImage with the right mouse button, my model remains in place relative to the image.
I have also managed to zoom my model to the same zoom level as the CADImage, so everything looks to be the same relative size.
My current problem is related to the position of my model when the CADImage has been zoomed. When the CADImage moves with the mouse (when RMB is depressed) I can easily move my model by the same amount that the CADImage is moved. However, when the CADImage is zoomed obviously it moves, but I don't know by how much.
Can anyone suggest how I can find out how much a given point on the CADImage moves in terms of pixels when it is zoomed? If I knew this then I could move my model by the same amount and keep them aligned.
I hope this is explained clearly enough...
I have been overlaying a networking model on a transparent panel over the top of my CADImage. I have then been drawing components on that panel.
I have got to the stage in development where I need my overlayed model to zoom and scroll whilst locked in position relative to the CADImage underneath. I have successfully managed to lock my model in position relative to the CADImage, so when I scroll the CADImage with the right mouse button, my model remains in place relative to the image.
I have also managed to zoom my model to the same zoom level as the CADImage, so everything looks to be the same relative size.
My current problem is related to the position of my model when the CADImage has been zoomed. When the CADImage moves with the mouse (when RMB is depressed) I can easily move my model by the same amount that the CADImage is moved. However, when the CADImage is zoomed obviously it moves, but I don't know by how much.
Can anyone suggest how I can find out how much a given point on the CADImage moves in terms of pixels when it is zoomed? If I knew this then I could move my model by the same amount and keep them aligned.
I hope this is explained clearly enough...
Hello!
The following answer is based on Viewer demo from CAD Import .NET package (it is available at: http://www.cadsofttools.com/download/cadimportnet.zip).
Module <b>ViewerMainForm.cs</b> contains the following method:
This method is responsible on recalculating of parameters for further drawing of the image after zoomming by mouse wheel.
pos.X - defines horizontal offset of the image
pos.Y - defines vertical offset of the image
old_Pos - mouse cursor coordinates
scale - new scale parameter
prev_scale - old scale parameter
Sergey.
Please post questions to the forum or write to support@cadsofttools.com
The following answer is based on Viewer demo from CAD Import .NET package (it is available at: http://www.cadsofttools.com/download/cadimportnet.zip).
Module <b>ViewerMainForm.cs</b> contains the following method:
Code: Select all
<font color="blue">private void</font id="blue"> Shift()
{
pos.X = old_Pos.X - (old_Pos.X - pos.X)*scale / prev_scale;
pos.Y = old_Pos.Y - (old_Pos.Y - pos.Y)*scale / prev_scale;
prev_scale = scale;
}
pos.X - defines horizontal offset of the image
pos.Y - defines vertical offset of the image
old_Pos - mouse cursor coordinates
scale - new scale parameter
prev_scale - old scale parameter
Sergey.
Please post questions to the forum or write to support@cadsofttools.com
Hi Sergey,
Thanks for that, I was already looking at that method.
I don't really think it can help me though. I can use Pos.X and Pos.X before it was zoomed to find out how much the whole image has been offset, but not a given point, as this changes relative to the position of the mouse pointer.
What I really need is a function that gives does the inverse of GetRealPointUsingsgImagePoint(float X, float Y) - i.e. given a Real Point return a pixel point in (x,y).
I think I may need to start over and relate each corner of my model to two intersecting lines on the CADImage. Then I can get the new realpoint of those lines and move my model correspondingly after a zoom event.
Any suggestions?
Thanks for that, I was already looking at that method.
I don't really think it can help me though. I can use Pos.X and Pos.X before it was zoomed to find out how much the whole image has been offset, but not a given point, as this changes relative to the position of the mouse pointer.
What I really need is a function that gives does the inverse of GetRealPointUsingsgImagePoint(float X, float Y) - i.e. given a Real Point return a pixel point in (x,y).
I think I may need to start over and relate each corner of my model to two intersecting lines on the CADImage. Then I can get the new realpoint of those lines and move my model correspondingly after a zoom event.
Any suggestions?
Hello!
It is not really clear what exactly you have to receive. It means we must know what you have on the beginning and how you want to manipulate with the image on the screen.
If you make your own application from the beginning - this is one thing. If you are based on <b>CAD Import .NET</b> - this is another thing.
Sergey.
Please post questions to the forum or write to support@cadsofttools.com
It is not really clear what exactly you have to receive. It means we must know what you have on the beginning and how you want to manipulate with the image on the screen.
If you make your own application from the beginning - this is one thing. If you are based on <b>CAD Import .NET</b> - this is another thing.
Sergey.
Please post questions to the forum or write to support@cadsofttools.com
Hello!
The following code converts drqzing point to the screen equivalent. It is based on <b>Viewer</b> from the <b>CAD Import .NET</b> package:
Sergey.
Please post questions to the forum or write to support@cadsofttools.com
The following code converts drqzing point to the screen equivalent. It is based on <b>Viewer</b> from the <b>CAD Import .NET</b> package:
Code: Select all
<font color="blue">private void</font id="blue"> cadPictBox_MouseUp(<font color="blue">object</font id="blue"> sender, System.Windows.Forms.MouseEventArgs e)
{
<font color="green">//Get offset of the screen respectively to the sought point on the drawing</font id="green">
<font color="green">//In this case input point for GetRealPointUsingsgImagePoint must be ever (0, 0)</font id="green">
DPoint posPoint = <font color="blue">this</font id="blue">.GetRealPointUsingsgImagePoint(0, 0);
<font color="green">//Drawing point which must be converted to the screen equivalent</font id="green">
DPoint tmpPoint = <font color="blue">new</font id="blue"> DPoint(0, 0, 0);
<font color="green">//Taking into account current offset of the drawing point</font id="green">
<font color="green">//respectively to its screen position</font id="green">
tmpPoint.X += posPoint.X;
tmpPoint.Y += posPoint.Y;
tmpPoint.Z += posPoint.Z;
<font color="green">//------------------</font id="green">
<font color="green">//Get screen coordinates of the drawing point</font id="green">
Point res = <font color="blue">this</font id="blue">.cadImage.GetPoint(tmpPoint);
MessageBox.Show(<font color="blue">string</font id="blue">.Format("{0} {1}", res.X, res.Y));
...
}
Please post questions to the forum or write to support@cadsofttools.com