Scope
ScopeFOVDiagram.cpp
1 #include "stdafx.h"
2 #include "ScopeFOVDiagram.h"
3 #include "parameters\Scope.h"
4 #include "helpers\helpers.h"
5 
6 namespace scope {
7  namespace gui {
8 
9 CScopeFOVDiagram::CScopeFOVDiagram(const uint32_t& _area, const parameters::Scope* _params)
10  : area(_area)
11  , params(_params) {
12  connections.push_back(params->areas[area]->fpuxystage.xpos.ConnectGUI(std::bind(&CScopeFOVDiagram::UpdateDiagram, this)));
13  connections.push_back(params->areas[area]->fpuxystage.ypos.ConnectGUI(std::bind(&CScopeFOVDiagram::UpdateDiagram, this)));
14  connections.push_back(params->areas[area]->micronperpixelx.ConnectGUI(std::bind(&CScopeFOVDiagram::UpdateDiagram, this)));
15  connections.push_back(params->areas[area]->micronperpixely.ConnectGUI(std::bind(&CScopeFOVDiagram::UpdateDiagram, this)));
16  connections.push_back(params->areas[area]->Currentframe().xoffset.ConnectGUI(std::bind(&CScopeFOVDiagram::UpdateDiagram, this)));
17  connections.push_back(params->areas[area]->Currentframe().yoffset.ConnectGUI(std::bind(&CScopeFOVDiagram::UpdateDiagram, this)));
18 }
19 
20 CScopeFOVDiagram::~CScopeFOVDiagram() {
21  for ( auto& c : connections )
22  c.disconnect();
23 }
24 
26  if ( SubclassWindow(hWnd) ) {
27  return true;
28  }
29  return false;
30 }
31 
33  if ( ::IsWindow(m_hWnd) )
34  Invalidate();
35 }
36 
37 void CScopeFOVDiagram::DrawItem(LPDRAWITEMSTRUCT lpdis) {
38  CDCHandle dc = lpdis->hDC;
39 
40  dc.SaveDC();
41 
42  // Paint background black
43  dc.FillSolidRect ( &lpdis->rcItem, RGB(0,0,0) );
44 
45  // total fov for zoom 1
46  const double totalfovx = params->masterfovsizex();
47  const double totalfovy = params->masterfovsizey();
48 
49  for ( uint32_t a = 0 ; a < SCOPE_NAREAS ; a++ ) {
50  // current fov
51  const double zoomedfovx = params->areas[a]->micronperpixelx() * params->areas[a]->Currentframe().xres();
52  const double zoomedfovy = params->areas[a]->micronperpixely() * params->areas[a]->Currentframe().yres();
53 
54  // center of zoomed fov in totalfov, add FPU movement offset and scanner offset
55  const double zoomedx = params->areas[a]->fpuxystage.xpos() + params->areas[a]->XOffsetInMicron();
56  const double zoomedy = params->areas[a]->fpuxystage.ypos() + params->areas[a]->YOffsetInMicron();
57  const double scalerx = (lpdis->rcItem.right-lpdis->rcItem.left)/totalfovx;
58  const double scalery = (lpdis->rcItem.bottom-lpdis->rcItem.top)/totalfovy;
59 
60  // Convert to screen coordinates
61  CPoint topleft(round2i16( (totalfovx/2 + zoomedx - zoomedfovx/2) * scalerx), round2i16( (totalfovy/2 + zoomedy - zoomedfovy/2) * scalery));
62  CPoint bottomright(round2i16( (totalfovx/2 + zoomedx + zoomedfovx/2) * scalerx), round2i16( (totalfovy/2 + zoomedy + zoomedfovy/2) * scalery));
63  CRect rect(topleft, bottomright);
64 
65  // Paint this area's FOV white, the other areas' gray
66  if ( area == a )
67  dc.FillSolidRect(&rect, RGB(255,255,255));
68  else
69  dc.FillSolidRect(&rect, RGB(128,128,128));
70  }
71 
72  dc.RestoreDC(-1);
73 }
74 
75 }
76 }
ScopeNumber< double > masterfovsizey
The same for the y direction.
Definition: Scope.h:273
*bool AttachToDlgItem(HWND hWnd)
()
The master parameters class.
Definition: Scope.h:204
std::array< std::unique_ptr< Area >, SCOPE_NAREAS > areas
holds AreaParameters for all areas.
Definition: Scope.h:231
void DrawItem(LPDRAWITEMSTRUCT lpdis)
Called from COwnerDraw.
This is the include file for standard system include files, or project specific include files that ar...
ScopeNumber< double > masterfovsizex
Size of the maximally reachable field of view.
Definition: Scope.h:270
const uint32_t area
the area of this FPU
std::vector< boost::signals2::connection > connections
Stores connections to ScopeValues that are then disconnected on destruction.
const parameters::Scope *const params
Pointer to the scope parameters to use for calculations.
Various helper functions and classes for Scope.
CScopeFOVDiagram(const uint32_t &_area, const parameters::Scope *_params)
void UpdateDiagram()
Connected to scope parameters, called upon their change.