1 //#**************************************************************
2 //# filename:             MyBaseView.h
3 //#
4 //# author:               Gerstmayr, Vetyukov
5 //#
6 //# generated:
7 //# description:
8 //# comments:
9 //#
10 //# Copyright (c) 2003-2013 Johannes Gerstmayr, Linz Center of Mechatronics GmbH, Austrian
11 //# Center of Competence in Mechatronics GmbH, Institute of Technical Mechanics at the
12 //# Johannes Kepler Universitaet Linz, Austria. All rights reserved.
13 //#
14 //# This file is part of HotInt.
15 //# HotInt is free software: you can redistribute it and/or modify it under the terms of
16 //# the HOTINT license. See folder 'licenses' for more details.
17 //#
18 //# bug reports are welcome!!!
19 //# WWW:		www.hotint.org
20 //# email:	bug_reports@hotint.org or support@hotint.org
21 //#***************************************************************************************
22 
23 
24 #pragma once
25 #include "resource.h"
26 #include "afxcmn.h"
27 #include "afxwin.h"
28 #ifndef MFEMATH__H
29   #include "..\MBSKernelLib\femath.h"
30 #endif
31 //#include "PlotToolDlg.h"
32 
33 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
35 // class CMyMemoryDC:       derived View class - base class
36 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
37 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
38 // Memory device context
39 
40 class CMyMemDC : public CDC
41 {
42 public:
CDC()43 	CMyMemDC(CDC* pDC, const CRect* pRect = NULL) : CDC()
44 	{
45 		ASSERT(pDC!=NULL);
46 
47 		m_pDC = pDC;
48 		m_BMPold = NULL;
49 		_isMemDC = !(pDC->IsPrinting());
50 		if(pRect==NULL) { pDC->GetClipBox(&m_DrawRectLogical); }
51 		else { m_DrawRectLogical = *pRect;	}
52 
53 		if(_isMemDC)
54 		{
55 			CreateCompatibleDC(pDC);
56 
57 			// create Bitmap
58 			CRect m_DrawRectPixels = m_DrawRectLogical;
59 			pDC->LPtoDP(&m_DrawRectPixels);							// convert logical -> pixel coordinates for the bitmap
60 			m_BMPoffscreen.CreateCompatibleBitmap(pDC, m_DrawRectPixels.Width(), m_DrawRectPixels.Height());
61 			m_BMPold = SelectObject(&m_BMPoffscreen);
62 
63 			// properties of original DC
64 			SetMapMode(pDC->GetMapMode());
65 			SetWindowExt(pDC->GetWindowExt());
66 			SetViewportExt(pDC->GetViewportExt());
67 			SetWindowOrg(m_DrawRectLogical.left, m_DrawRectLogical.top);
68 		}
69 		else
70 		{
71 			m_bPrinting = pDC->m_bPrinting;
72 			m_hDC       = pDC->m_hDC;
73 			m_hAttribDC	= pDC->m_hAttribDC;
74 		}
75 		FillSolidRect(m_DrawRectLogical, pDC->GetBkColor());
76 	}
77 
~CMyMemDC()78 	~CMyMemDC()
79 	{
80 		if(_isMemDC)
81 		{
82 			//copy the Bitmap to the screen
83 			m_pDC->BitBlt(m_DrawRectLogical.left,    m_DrawRectLogical.top,
84 				            m_DrawRectLogical.Width(), m_DrawRectLogical.Height(),
85 										this, m_DrawRectLogical.left,    m_DrawRectLogical.top, SRCCOPY);
86 			SelectObject(m_BMPold);
87 		}
88 	}
89 
90 
91 
92 private:
93 	CBitmap m_BMPoffscreen;                   // offscreen bitmap
94 	CBitmap* m_BMPold;                        // previous bitmap
95 	CDC* m_pDC;                               // valid pDC
96 	CRect m_DrawRectLogical;                  // drawing area
97 	int _isMemDC;                             // true if drawing, false if printing
98 };
99 
100 
101 
102 
103 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
104 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
105 // class CMyBase2DView:       derived View class - base class
106 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
107 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
108 // functionality in base Class:
109 // * Zoom (both axes at once) & Move via drag drop
110 // * Draw (Lines, Rectangle, Arrow, CheckVisibility, grid?)
111 // * Text placement
112 
113 class CMyBase2DView : public CView
114 {
115 	DECLARE_DYNCREATE(CMyBase2DView)
116 
117 public:
118 	CMyBase2DView(CWnd* pParent = NULL);       // Standardkonstruktor
~CMyBase2DView()119 	virtual ~CMyBase2DView() {};
120 public:
121 	virtual void Reset();                // initialize with default values ( from EDC or hardcoded )
ErrorMessage(mystr & msg)122 	virtual void ErrorMessage(mystr& msg) {};
123 
124 protected:
125 	DECLARE_MESSAGE_MAP()
126 
127 public:
128 // COORDINATE SYSTEM CONVERSION   pixels <--> logical
129 	CPoint GetPixelsFromLogical(CPoint logical, mystr& caller = mystr());
130 	CPoint GetLogicalFromPixels(CPoint pixels, mystr& caller = mystr());
131 // COORDINATE SYSTEM CONVERSION   real <--> logical
132 	virtual CPoint ValuesToLogical(double x, double y);     // map values to logical coordinates
133 	virtual double XofLogical(CPoint& logical);
134 	virtual double YofLogical(CPoint& logical);
135 
136 
137 public:
138 // WINDOW PROPERTIES & ADDITIONAL DISPLAY ELEMENTS
139 // CATCH MOUSE
140 	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);          // zoom in and out
141 	virtual void ReComputeShownRange_Zooming(UINT nFlags, short zDelta, CPoint pt); // Zooming centered around current mouse position
142 	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);                    // start drag/drop
143 	afx_msg void OnLButtonUp(UINT nFlags, CPoint point); // center view       // end drag/drop
144 	afx_msg void OnMouseMove(UINT nFlags, CPoint point);                      // value - tracking
145 	int m_mouseisinclient;
146 
147 public:
148 // DRAG - DROP:
149 	virtual void DragDropAction();																						// drag drop action - move and redraw
150 	CRect prevdragrect;
151 		CPoint dragdrop_start_device;
152 	CPoint dragdrop_final_device;
153 	CPoint mouse_pos;
DragDropStart()154 	CPoint& DragDropStart() { return dragdrop_start_device; }
DragDropFinal()155 	CPoint& DragDropFinal() { return dragdrop_final_device; }
MousePosition()156 	CPoint& MousePosition() { return mouse_pos; }
157 	int skipdrawduringmove;
158 
159 public:
160 // LOGICAL COORDINATES - A plot window with border
161                     /* Zero-----+----------------------------------+-----+ */
162                     /* |                                                 | */
163   int pts_y_top;    /* 400: Title                                        |
164                     /* |                    *TITLE*                      | */
165                     /* +        +----------------------------------+     | */
166                     /* |        |                           legend?|     | */
167                     /* |        |                                  |     | */
168  	int pts_y_plot;   /* 2000:Plot|       * THE PLOT *               |     | */
169                     /* |        |                                  |     | */
170                     /* |        |                                  |     | */
171                     /* +        Origin-----------------------------+     | */
172                     /* |         (0,0)      *axis*                       | */
173   int pts_y_bottom; /* 300: Axis                                         | */
174                     /* |                                                 | */
175                     /* +--------+----------------------------------+-----+ */
176                     /*  300:Axis                 3000: Plot          200   */
177                   	int pts_x_left;     	int pts_x_plot;       int pts_x_right;
178 
179 public:
180 	// coordinates of "zero" in respect to "origin"
GetWindowOrigin(CPoint & zero)181 	virtual void GetWindowOrigin(CPoint& zero) { zero.SetPoint(-pts_x_left,pts_y_top+pts_y_plot);	}
182 	// coordinates of rectangle for "the plot" in respect to "origin"
GetPlotRect(CRect & rect)183 	virtual void GetPlotRect(CRect& rect) { rect.left = 0; rect.bottom = 0;	rect.right = pts_x_plot; rect.top = pts_y_plot;	}
GetXAxisRect(CRect & rect)184 	virtual void GetXAxisRect(CRect& rect) { rect.left = 0;	rect.bottom = -pts_y_bottom; rect.right = pts_x_plot;	rect.top = 0;	}
GetYAxisRect(CRect & rect)185 	virtual void GetYAxisRect(CRect& rect) { rect.left = -pts_x_left; rect.bottom = 0; rect.right = 0; rect.top = pts_y_plot;	}
GetTitleRect(CRect & rect)186 	virtual void GetTitleRect(CRect& rect) { rect.left = 0; rect.bottom = pts_y_plot;	rect.right = pts_x_plot; rect.top = pts_y_plot+pts_y_top;	}
GetViewRect(CRect & viewrect)187 	virtual void GetViewRect(CRect& viewrect)	{	viewrect.left = -pts_x_left; viewrect.bottom = -pts_y_bottom; viewrect.right = pts_x_plot+pts_x_right; viewrect.top = pts_y_plot+pts_y_top; }
188 
189 public:
190 // THE DRAWING PROCESS
OnDraw(CDC * pDC)191 	virtual void OnDraw(CDC* pDC) {;}														// this routine is automatically called by the framework (redrawwindow etc.)
192 	int _is_executing_ondraw;
193 
194 // Diagnose functions
195 	mystr caller;																								// this string contains the caller function for all redraws - default "system", changed right before all RedrawWindow calls
SetCaller(mystr calleri)196 	virtual void SetCaller(mystr calleri) { caller = calleri; }
GetCaller()197 	virtual mystr& GetCaller() { return caller; }
198 
199 // TEXT PLACEMENT
200 	virtual void SelectDefaultFont(CDC* pDC, int size = 12, const char* name = "Arial"); // a default font ( Arial )
201 	virtual CFont* GetDefaultFont(CDC* pDC, int size = 12, const char* name = "Arial"); // a default font ( Arial )
202 	virtual void DrawTextAtPoint(CDC* pDC, const CString str, CPoint point, double angle_deg); 	// plot text at a given posiiton (this position is center of textbox)
203 	virtual void DrawTextInRect(CDC* pDC, const CString str, CRect rect, double angle_deg, TTextAllign allign = TTextAllign (HCenter+VCenter), UINT nOptions = 0);	// plot text at in given rectangle (text mayhave allignment)
204 	virtual void DrawTextAt(CDC* pDC, const CString str, CPoint center, CPoint vector_center2origin, double angle_deg, UINT nOptions = 0);	// this function actually writes the text
205 // VISIBILITY
206 	virtual int IsPointInRect(CPoint& point, CRect& rect); // computes if point is within rectangle (!including borders which CRect.PtInRect does not)
207 	virtual int IsPointOnRectBorder(CPoint& point, CRect& rect); // computes if point is exactly on the rectangles border
208 
209 public:
210 // FUNCTIONS THAT PREPARE THE DRAWING DEVICE CONTENTS
OnFilePrint()211 	virtual void OnFilePrint() {	CView::OnFilePrint(); }
212 	virtual void OnPrepareDC(CDC* pDC, CPrintInfo* pInfo = NULL);
213 	virtual void PrepareDC_Screen(CDC* pDC, CPrintInfo* pInfo = NULL);              // client is actual CView
214 //	virtual void PrepareDC_Memory(CDC* pDC, CPrintInfo* pInfo = NULL);              // client is Rect with Pixels as output BMP - only in derived
215 	virtual void PrepareDC_Printer(CDC* pDC, CPrintInfo* pInfo = NULL);             // client is determined by Printer device
216 	virtual void PrepareDC_inRect(CDC* pDC, CPrintInfo* pInfo, CRect& clientRect);  // scales DC
217 
218 public:
219 // FUNCTIONS FOR PRINTING
220 	virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
221 	virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
222 	virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
223 
224 public:
225 // FILE EXPORT FUNCTIONS
226 	virtual void SaveAsBitmapGraphic(CString& path_and_filename_noext, int resX, int resY, int flag_jpg, int flag_png, int flag_bmp); // jpg, png, bmp
227   virtual void SaveAsVectorGraphic(CString& path_and_filename_noext, int flag_emf); // emf
228 
229 public:
230 // ranges
Get_XRange_logical()231 	int Get_XRange_logical() { return pts_x_plot; }
Get_YRange_logical()232 	int Get_YRange_logical() { return pts_y_plot; }
233 // range of values that is shown in viewport
234 	Box2D shownrange;         // must be double values
Get_XMin()235 	double Get_XMin() { return shownrange.PMin().X(); } //returns lower x limit of view port
Get_XMax()236 	double Get_XMax() { return shownrange.PMax().X(); } //returns upper x limit of view port
Get_YMin()237 	double Get_YMin() { return shownrange.PMin().Y(); } //returns lower y limit of view port
Get_YMax()238 	double Get_YMax() { return shownrange.PMax().Y(); } //returns upper y limit of view port
239 };
240 
241 
242 
243 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
244 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
245 // class MyBaseDialogForView:       derived View class - base class for 2D Views                                                    * 29.11.2012 +
246 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
247 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
248 // MyBaseDialogForView-Dialogfeld
249 class MyBaseDialogForView : public CDialog
250 {
251 public:
252 	CWnd* CreateNewView(CCreateContext* pContext, CWnd *pParent, CRect& rect, int wID);
253 
254 	enum { IDD = IDD_DIALOG_2D_VIEW };
255 	DECLARE_DYNAMIC(MyBaseDialogForView)
256 
257 public:
258 	MyBaseDialogForView(CWnd* pParent = NULL);   // Standardkonstruktor
259 	virtual ~MyBaseDialogForView();
260 public:
261 	virtual BOOL OnInitDialog();
262 	virtual BOOL DestroyWindow();
263 
264 protected:
265 	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV-Unterst�tzung
266 	DECLARE_MESSAGE_MAP()
267 
268 	// ACCESS // LINKED DIALOGS & OBJECTS
269 protected:
270 	class CMyBase2DView* m_pMyView; // must be derived from CView
271 	class CWCDriver3DDlg* m_wcdd;   // owning WCDriver3Dlg instance
272 public:
SetView(CMyBase2DView * myView)273 	void SetView(CMyBase2DView* myView) { m_pMyView = myView ; }
SetWCDDlg(CWCDriver3DDlg * wcdd)274 	void SetWCDDlg(CWCDriver3DDlg* wcdd) {m_wcdd = wcdd; }
GetView()275 	CMyBase2DView* GetView() { return m_pMyView; }
GetWCDDlg()276 	CWCDriver3DDlg* GetWCDDlg() { return m_wcdd; }
277 
278 // WINDOW PROPERTIES & ADDITIONAL DISPLAY ELEMENTS
279 public:
280 	afx_msg void OnSize(UINT nType, int cx, int cy);
281 	afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI);        // defines the minimum size for the dialog - important to not encounter negative extensions for the nested view
282 	afx_msg void OnMove(int x, int y);
283 	afx_msg void OnClose();
284 	afx_msg void OnPaint();
285 	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
286 	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
287 
288 	BOOL PreTranslateMessage(MSG* pMsg);
289 
290 	int m_init_done;     // sometimes reqired during initializaiton when Statusbar is involved
291 	int slow_zoom;
292 	int _isclosing;
293 
294 // actively prohibit redraw
295 private:
296 	int flag_no_redraw;
297 public:
DoNotRedraw()298 	int DoNotRedraw() { return flag_no_redraw; }
ForbidRedraw()299 	void ForbidRedraw() { flag_no_redraw = 1; }
AllowRedraw()300 	void AllowRedraw() { flag_no_redraw = 0; }
301 
302 // placement of the elements ( CMyView object & Dialog ) so the two dialogs stick together
303 	virtual void PlaceElements();
304 
305 	virtual CRect PlaceView(CRect& viewrect); // places the View Rect in the Popup Dialog
306 	virtual void CheckScreenLocation();       // ensure that dialog is in visible range
GetViewRect(CRect & viewrect)307 	virtual void GetViewRect(CRect& viewrect) { GetClientRect(viewrect); if (m_flag_use_statusbar) { viewrect.bottom = viewrect.bottom - statusbar_height; } }
GetStatusRect(CRect & statusrect)308 	virtual void GetStatusRect(CRect& statusrect) { GetClientRect(statusrect); statusrect.top = statusrect.bottom - statusbar_height; }
309 
310 // status bar at the bottom of the graph with a slot for each line (shows last value)
311 	CStatusBarCtrl m_StatusBar;
312 	mystr statusbartextbuffer;
313 	//virtual void SetStatusBarText( mystr text, int slot) { m_StatusBar.SetText(text,slot,0); }
314 	//virtual void SetStatusBarText_Main (mystr text) {;}
315 	//virtual void SetStatusBarText_X (mystr text) {;}
316 	//virtual void SetStatusBarText_Y (mystr text) {;}
317 	int m_flag_use_statusbar;
318 	static const int statusbar_height = 25;
SetStatusBar(int flag_use)319 	virtual int& SetStatusBar(int flag_use) { return m_flag_use_statusbar; }
320 
321 // name displayed in the window title bar
322 	CString def_name;
SetDefaultName(CString & defaultname)323 	void SetDefaultName(CString& defaultname) { def_name = defaultname; }
GetDefaultName()324 	CString& GetDefaultName() { return def_name; }
ReadDefaultName(CString & defaultname)325 	void ReadDefaultName(CString& defaultname) { defaultname = def_name; }
SetDisplayName(CString & displayname)326 	void SetDisplayName(CString& displayname) { this->SetWindowTextA(displayname); }
ReadDisplayname(CString & displayname)327 	void ReadDisplayname(CString& displayname) { this->GetWindowText(displayname); }
328 
329 // FUNCTIONS FOR PRINTING
OnBeginPrinting(CDC * pDC,CPrintInfo * pInfo)330 	void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo) { return; }
331 	void OnPrint(CDC* pDC, CPrintInfo* pInfo);
OnEndPrinting(CDC * pDC,CPrintInfo * pInfo)332 	void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo) { return; }
333 	void Print();
334 
SetCaller(mystr calleri)335 	virtual void SetCaller(mystr calleri) { GetView()->caller = calleri; }
336 };
337