Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Calculate scale in plotting

Posted on 2001-09-17
3
370 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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