Solved

Calculate scale in plotting

Posted on 2001-09-17
3
371 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 100 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create frequencies of a variable from SAS dataset? 10 137
maxBlock challenge 30 145
Line meaning 9 89
sumHeights  challenge 17 79
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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

713 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