Solved

Calculate scale in plotting

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now