1 //#**************************************************************
2 //# filename:             DrawWindow2D.h
3 //#
4 //# author:               Gerstmayr, Dorninger
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 
25 #pragma once
26 #include "resource.h"
27 #include "afxcmn.h"
28 #include "afxwin.h"
29 #include "MyBaseView.h" // base class for View
30 
31 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33 // class CDrawWindow2DView:                                       derived View class for the 2D - PlotWindow ( Control elements )   * 2012-12-12 +
34 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
35 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
36 // derived class for CDrawWindow2DView
37 class CDrawWindow2DView : public CMyBase2DView
38 {
39 	DECLARE_DYNCREATE(CDrawWindow2DView)
40 
41 public:
42 	CDrawWindow2DView(CWnd* pParent = NULL);       // Standardkonstruktor
~CDrawWindow2DView()43 	virtual ~CDrawWindow2DView() {};
44 public:
45 	virtual void Reset();                // initialize with default values ( from EDC or hardcoded )
46 	virtual void ErrorMessage(mystr& msg);
47 
48 // ACCESS // LINKED DIALOGS & OBJECTS
49 private:
50 	class CDrawWindow2DDlg* m_pParent;             // pointer to parent required, DrawElementList is stored in DLG
51 public:
SetParentDlg(class CDrawWindow2DDlg * parent)52 	void SetParentDlg(class CDrawWindow2DDlg* parent) { m_pParent = parent; }
GetParentDlg()53 	class CDrawWindow2DDlg* GetParentDlg() { return m_pParent; }
54 
55 protected:
56 	DECLARE_MESSAGE_MAP()
57 
58 
59 public:
60 // WINDOW PROPERTIES & ADDITIONAL DISPLAY ELEMENTS
61 // CATCH MOUSE directly
62 	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);          // zoom in and out
63 	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);                    // start drag/drop
64 	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);							        // end drag/drop // catch click
65 	afx_msg void OnMouseMove(UINT nFlags, CPoint point);                      // value - tracking
66   afx_msg void OnNcMouseMove(UINT nHitTest, CPoint point);
67 
68 // CATCH OTHER via Msg
69 	void OnKeyPressed(MSG* pMsg);																							// catch key - catching must be done by DLG
70 
71 
72 // DRAG - DROP:
73 	void DragDropAction();																										// drag drop action - move and redraw
74 
75 
76 // THE DRAWING PROCESS
77 public:
78 //	virtual	BOOL RedrawWindow(LPCRECT lpRectUpdate = NULL,	CRgn* prgnUpdate = NULL,UINT flags = RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
79 	virtual void OnDraw(CDC* pDC);                          // this routine is automatically called by the framework (redrawwindow etc.)
80 	virtual void DrawElements(CDC* pDC);										// draw all items to specified CDC
81 
82 	virtual BOOL IsVisible(CDC* pDC, ControlWindowContext_::DrawComponent& elem);
83 	virtual BOOL DrawLine(CDC* pDC, ControlWindowContext_::DrawComponent& elem);
84 	virtual BOOL DrawRectangle(CDC* pDC, ControlWindowContext_::DrawComponent& elem);
85 	virtual BOOL DrawEllipse(CDC* pDC, ControlWindowContext_::DrawComponent& elem);
86 	virtual BOOL DrawText(CDC* pDC, ControlWindowContext_::DrawComponent& elem);
87 
88 // is redraw allowed/prohibited ?
89 	virtual int DoNotRedraw();
90 	virtual void ForbidRedraw();
91 	virtual void AllowRedraw();
92 // StatusBarText
93 	virtual void UpdateStatusBarInfo();
94 	virtual void SetStatusBarText_Main (mystr text);
95 	virtual void SetStatusBarText_X (mystr text);
96 	virtual void SetStatusBarText_Y (mystr text);
97 
98   Box2D initshownrange;
99 	double currentzoomfactor;
100 	virtual double ReComputeZoomFactor();
101 
102 	virtual void SetInitialRange();
103 	virtual void MatchLogicalPoints();
104 	virtual void Rescale();
105 	CRect prevClientRect;
106 
107 // REAL VALUES of COORDINATES
108 	Box2D fullrange;   // full range of all lines to plot (real values)
109 	virtual void ComputeFullRange(int flag_equal = 0); // computes limits of datasets - real values
110   virtual void SetShownRange(double xmin, double xmax, double ymin, double ymax); // sets range of plot
111 
112 	// Catching
113 	virtual int CatchDrawObject( CPoint capture);									// computes the object to be selected
114 	int selected_object_buffer;
115 	virtual int GetDistanceFromComponent(int i, CPoint capture);
116 	virtual int DistFromLine(CPoint p1, CPoint p2, CPoint pmouse); // replace this function with MinDispLP from linalg3d
117 };
118 
119 
120 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
121 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
122 // class CDrawWindow2DDlg:                               this is the dialog that nests the Graph (CMyView object),                  * 2012-12-12 +
123 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
124 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
125 // DrawWindow2DDlg-Dialogfeld
126 
127 class CDrawWindow2DDlg : public MyBaseDialogForView, // provides the View::OnDraw, Zoom, etc.
128 	                       public ControlWindowContext_ // provides the list of Elements to be drawn
129 {
130 	enum { IDD = IDD_DIALOG_2D_VIEW };
131 	DECLARE_DYNAMIC(CDrawWindow2DDlg)
132 
133 public:
134 	CDrawWindow2DDlg(CWnd* pParent = NULL);   // Standardkonstruktor
135 	virtual ~CDrawWindow2DDlg();
136 public:
137 	virtual BOOL OnInitDialog();
138 	virtual BOOL DestroyWindow();
139 
140 protected:
141 	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV-Unterst�tzung
DECLARE_MESSAGE_MAP()142 	DECLARE_MESSAGE_MAP()
143 
144 // ACCESS // LINKED DIALOGS & OBJECTS
145 public:
146 	void SetView(class CDrawWindow2DView* myView) { m_pMyView = (CDrawWindow2DView*) myView; }
GetView()147 	class CDrawWindow2DView* GetView() { return (class CDrawWindow2DView*) m_pMyView; } // we know that the derived dialog also uses a derived view class
148 
149 	WCDInterface* pWCDI;
150 	//CGLDrawWnd* pGLDrawWnd;
SetWCDI(WCDInterface * pWCDI_)151 	void SetWCDI(WCDInterface * pWCDI_) { pWCDI = pWCDI_; }
GetWCDI()152 	WCDInterface * GetWCDI() { return pWCDI; }
153 	//void SetGLDrawWnd(CGLDrawWnd * pGLDrawWnd_) { pGLDrawWnd = pGLDrawWnd_; }
154 
155 
156 // WINDOW PROPERTIES & ADDITIONAL DISPLAY ELEMENTS
157 public:
158 	afx_msg void OnSize(UINT nType, int cx, int cy);
159 	afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpMMI);
160 	afx_msg void OnMove(int x, int y);
161 	afx_msg void OnClose();
162 	afx_msg void OnPaint();
163 	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
164 	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
165 
166 // catch keydown
167 	BOOL PreTranslateMessage(MSG* pMsg);
168 	virtual void ForceUpdate();
169 
170 // placement of the elements ( CMyView object & Dialog ) so the two dialogs stick together
171 	void PlaceElements();
172 
173 	// CONTEXTMENU
174 	afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
175 	afx_msg void OnCMSelectobject();
176 	afx_msg void OnCMZoomToFullRange();
177 	afx_msg void OnCMExportToFile();
178 	afx_msg void OnCMPrintGraph();
179 	afx_msg void OnCMShowStatusInfo();
180 	int m_flag_statusinfo;
181 
182 	// functions to create a new construction node in the middle of the selected connection line
183 	virtual Vector2D ComputeSplitPointPosition(ControlWindowContext_::DrawComponent& elem); // new position in the middle
184 	virtual int ComputeSplitPointListIndex(ControlWindowContext_::DrawComponent& elem);      // list index to insert the new node
185 
186 	// Diagnose functions - Functions that trigger redraw
SetCaller(mystr calleri)187 	void SetCaller(mystr calleri) { GetView()->SetCaller(calleri); }
188 };