Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Calculate scale in plotting

Posted on 2001-09-17
3
Medium Priority
?
375 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
[X]
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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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…
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

715 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