Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Calculate scale in plotting

Posted on 2001-09-17
3
Medium Priority
?
377 Views
Last Modified: 2013-11-20
Hello,

I'm using a CStatic derived class to represent a diagram on a dialog. Because there are several curves to be displayed in one diagram simultaneously(I'm using MM_ANISOTROPIC mapping mode to fit all of them in the window), I decide not to draw a vertival axis and a set of tic marks for each of these curves, instead, I calculate the scale of each curve while plotting and then display them besides the diagram.

The scale here is defined as actual value (in vertical dir.) in a range of 1cm on the screen. I'm using the code like afterwards, I think it's right and logical, but there's remakable error on the display(around 8%). I don't know where does it come from:

void CDiagram::CalculateScale(CDC *pDC, CSize *scale)
{
     // calculate scales in x(scale.cx) and y(scale.cy) directions
     // logical values in 1cm of length on screen

     CPoint OldViewportOrg = pDC->GetViewportOrg();
     CSize OldViewportExt = pDC->GetViewportExt();
     CPoint OldWindowOrg = pDC->GetWindowOrg();
     CSize OldWindowExt = pDC->GetWindowExt();
     int OldMapMode = pDC->GetMapMode();

     pDC->SetMapMode(MM_LOMETRIC);
     CSize size(100, 100);          // 1cm size under MM_LOMETRIC mode
     pDC->LPtoDP(&size);          // pixels

     pDC->SetMapMode(OldMapMode);
     pDC->SetViewportOrg(OldViewportOrg);
     pDC->SetViewportExt(OldViewportExt);
     pDC->SetWindowOrg(OldWindowOrg);
     pDC->SetWindowExt(OldWindowExt);
     pDC->DPtoLP(&size);          // logical units in 1cm under current mode

     *scale = size;
}
Of course, I have already considered the potential loss of accuracy casting doulbe value to int in MoveTo/LineTo functions, and applied zoom factors to ensure the logical value be no less than, say, 1000.

By the way, in the above segment, if I omit the code saving and restore the stuff such as viewport/window org./ext.(because there's no change in between), their setting will not be kept in subsequent plotting, why?

Thanks in advance.

Max
0
Comment
Question by:min2max
3 Comments
 
LVL 9

Accepted Solution

by:
Pacman earned 400 total points
ID: 6490539
On Windows NT/2000 windows resets the printer DC for each page. You've to set your own values.

0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9532405
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by: Pacman

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question