Develop and Download Open Source Software

Browse CVS Repository

Contents of /satellite/neuromanager/neuromanager/DataViewProperties.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Sat Feb 4 13:38:16 2006 UTC (18 years, 2 months ago) by orrisroot
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-c++src
moved main application sources to neuromanager directory.

1 /* --------------------------------------------------------------------- */
2 /* NeuroManager - A spike train analysis tool */
3 /* Copyright (c) 2005-2006 RIKEN, Japan. All rights reserved. */
4 /* http://satellite.sourceforge.jp/ */
5 /* --------------------------------------------------------------------- */
6 /* This program is free software; you can redistribute it and/or */
7 /* modify it under the terms of the GNU General Public License */
8 /* as published by the Free Software Foundation; either version 2 */
9 /* of the License, or (at your option) any later version. */
10 /* */
11 /* This program is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU General Public License */
17 /* along with this program; see the file COPYING.txt. If not, write */
18 /* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth */
19 /* Floor, Boston, MA 02110-1301, USA. */
20 /* --------------------------------------------------------------------- */
21
22 /* $Id: DataViewProperties.cpp,v 1.18 2006/01/24 01:59:57 orrisroot Exp $ */
23
24 // DataViewProperties.cpp : implementation of the CDataViewProperties class
25 //
26
27 #include "stdafx.h"
28 #include <atlrx.h>
29
30 #include "NeuroManager.h"
31 #include "NeuroManagerDoc.h"
32
33 #include "DataViewSplitter.h"
34 #include "DataViewContext.h"
35 #include "DataView.h"
36 #include "DataViewProperties.h"
37 #include ".\dataviewproperties.h"
38
39 #include <math.h>
40
41 // CDataViewProperties
42
43 IMPLEMENT_DYNCREATE( CDataViewProperties, CFormView )
44
45 CDataViewProperties::CDataViewProperties()
46 : CFormView( CDataViewProperties::IDD )
47 {
48 EnableActiveAccessibility();
49 m_bInitCtrlList = FALSE;
50 }
51
52 CDataViewProperties::~CDataViewProperties()
53 {}
54
55 void CDataViewProperties::DoDataExchange( CDataExchange *pDX )
56 {
57 CFormView::DoDataExchange( pDX );
58 DDX_Control( pDX, IDC_LIST_CHANNEL, m_ctrlList );
59 }
60
61 BEGIN_MESSAGE_MAP( CDataViewProperties, CFormView )
62 ON_NOTIFY( LVN_ITEMCHANGED, IDC_LIST_CHANNEL, OnLvnItemchangedListChannel )
63 ON_NOTIFY( LVN_BEGINLABELEDIT, IDC_LIST_CHANNEL, OnLvnBeginlabeleditListChannel )
64 ON_NOTIFY( LVN_ENDLABELEDIT, IDC_LIST_CHANNEL, OnLvnEndlabeleditListChannel )
65 ON_UPDATE_COMMAND_UI( ID_EDIT_COPY, OnUpdateNeedSel )
66 ON_UPDATE_COMMAND_UI( ID_EDIT_CUT, OnUpdateNeedSel )
67 ON_UPDATE_COMMAND_UI( ID_EDIT_PASTE, OnUpdateNeedClip )
68 ON_COMMAND( ID_EDIT_COPY, OnEditCopy )
69 ON_COMMAND( ID_EDIT_CUT, OnEditCut )
70 ON_COMMAND( ID_EDIT_PASTE, OnEditPaste )
71 END_MESSAGE_MAP()
72
73
74 // CDataViewProperties diagnostics
75
76 #ifdef _DEBUG
77 void CDataViewProperties::AssertValid() const
78 {
79 CFormView::AssertValid();
80 }
81
82 void CDataViewProperties::Dump( CDumpContext &dc ) const
83 {
84 CFormView::Dump( dc );
85 }
86 #endif //_DEBUG
87
88 BOOL CDataViewProperties::String2Double( CString &str, double &result )
89 {
90 CAtlRegExp<> reDouble;
91 str.Trim();
92 // accept pattern
93 // "0.0001", ".00001", "0.0001e10", ".0001e10",
94 // "0.0001e+10", ".0001e+10", "0.0001e-10", ".0001e-10"
95 REParseError status = reDouble.Parse( _T( "^{(\\-?)((\\z\\.\\z?)|(\\z?\\.\\z))([eE][\\+\\-]?\\z)?}$" ) );
96 if ( REPARSE_ERROR_OK != status )
97 {
98 // Unexpected error
99 return FALSE;
100 }
101 CAtlREMatchContext<> mcDouble;
102 if ( !reDouble.Match( str, &mcDouble ) )
103 {
104 // Unexpected error
105 return FALSE;
106 }
107 // reform of floating point numbered string
108 result = strtod( str, NULL );
109 str.Format( "%f", result );
110 return TRUE;
111 }
112
113 BOOL CDataViewProperties::IsEdit( CWnd* pWnd )
114 {
115 ASSERT( pWnd != NULL );
116 HWND hWnd = pWnd->GetSafeHwnd();
117 if ( hWnd == NULL )
118 return FALSE;
119
120 TCHAR szClassName[ 6 ];
121 return ::GetClassName( hWnd, szClassName, 6 ) && _tcsicmp( szClassName, _T( "Edit" ) ) == 0;
122 }
123
124 CScrollView *CDataViewProperties::GetDataView() const
125 {
126 CDataViewSplitter * wndSplit = ( CDataViewSplitter* ) GetParent();
127 if ( wndSplit == NULL )
128 return NULL;
129 return wndSplit->GetDataViewWindow();
130 }
131
132 void CDataViewProperties::FormatTime( CString &str, double dTime ) const
133 {
134 CString unit( _T( "[sec]" ) );
135 if ( dTime != 0.0 )
136 {
137 double order = floor( log10( dTime ) );
138 if ( order < -6.0 )
139 { // nano sec
140 dTime *= pow( 10.0, -9 );
141 unit = _T( "[nanosec]" );
142 }
143 else if ( order < -3.0 )
144 { // micro sec
145 dTime /= pow( 10.0, -6 );
146 unit = _T( "[microsec]" );
147 }
148 else if ( order < -0.0 )
149 { // mili sec
150 dTime /= pow( 10.0, -3 );
151 unit = _T( "[msec]" );
152 }
153 }
154 str.Format( _T( "%.4f %s" ), dTime, unit );
155 }
156
157 void CDataViewProperties::InitializeDataChannelList()
158 {
159 CNeuroManagerDoc * pDoc = ( CNeuroManagerDoc* ) GetDocument();
160 ASSERT_VALID( pDoc );
161
162 // check for already initialized
163 if ( m_bInitCtrlList == FALSE )
164 {
165 // set control list style
166 DWORD cStyle = m_ctrlList.GetExtendedStyle();
167 m_ctrlList.SetExtendedStyle( cStyle | LVS_EX_HEADERDRAGDROP | LVS_EX_FULLROWSELECT |
168 LVS_EX_GRIDLINES | LVS_EX_CHECKBOXES );
169 // read header width
170 int nCl0 = AfxGetApp() ->GetProfileInt( "LISTCTRL", "Head0", 60 );
171 int nCl1 = AfxGetApp() ->GetProfileInt( "LISTCTRL", "Head1", 150 );
172 int nCl2 = AfxGetApp() ->GetProfileInt( "LISTCTRL", "Head2", 150 );
173 // set header title and width
174 m_ctrlList.InsertColumn( 0, _T( "Channel" ), LVCFMT_RIGHT, nCl0 );
175 m_ctrlList.InsertColumn( 1, _T( "Y Min" ), LVCFMT_LEFT, nCl1 );
176 m_ctrlList.InsertColumn( 2, _T( "Y Max" ), LVCFMT_LEFT, nCl2 );
177
178 // set initilized flag
179 m_bInitCtrlList = TRUE;
180 }
181
182 // set items
183 m_ctrlList.DeleteAllItems();
184 if ( pDoc->IsMapped() )
185 {
186 UINT maxch = pDoc->GetChannelNumber();
187 CString str;
188 for ( UINT ch = 0; ch < maxch; ch++ )
189 {
190 str.Format( "%-3d", ch + 1 );
191 m_ctrlList.InsertItem( ch, str );
192 double d = pDoc->GetYAxisRange( ch );
193 SetDataYAxisRange( ch, -d, d );
194 }
195 SetVisibleDataChannelState( 0, TRUE );
196 }
197 }
198
199 BOOL CDataViewProperties::InitializeDataLength( QWORD len, double dTime )
200 {
201 CEdit * pEdit = ( CEdit* ) GetDlgItem( IDC_STATIC_DATALENGTH );
202 ASSERT_VALID( pEdit );
203 CString lenstr;
204 if ( len != 0 )
205 {
206 CString totalTime;
207 FormatTime( totalTime, dTime );
208 lenstr.Format( _T( "%s (%I64d pt)" ), totalTime, len );
209 }
210 else
211 {
212 lenstr.Format( _T( "0" ) );
213 }
214 pEdit->SetWindowText( lenstr );
215 return TRUE;
216 }
217
218 BOOL CDataViewProperties::OnChangedVisibleDataChannelState( LPNMLISTVIEW pNMLV )
219 {
220 if ( pNMLV->uOldState == 0 && pNMLV->uNewState == 0 )
221 return FALSE; // No change
222
223 // get old check box state
224 BOOL bPrevState = ( BOOL ) ( ( ( pNMLV->uOldState & LVIS_STATEIMAGEMASK ) >> 12 ) - 1 );
225 // On startup there's no previous state
226 if ( bPrevState < 0 )
227 bPrevState = FALSE; // assing as false (unchecked)
228
229 // get new check box state
230 BOOL bNewState = ( BOOL ) ( ( ( pNMLV->uNewState & LVIS_STATEIMAGEMASK ) >> 12 ) - 1 );
231 // non-check box notification
232 if ( bNewState < 0 )
233 bNewState = FALSE;
234
235 if ( bPrevState == bNewState )
236 return FALSE;
237
238 UINT ch = pNMLV->iItem;
239 CDataViewContext::SetVisibleDataChannelState( ch, bNewState );
240 return TRUE;
241 }
242
243 BOOL CDataViewProperties::SetVisibleDataChannelState( UINT ch, BOOL bState )
244 {
245 BOOL bOldState = CDataViewContext::SetVisibleDataChannelState( ch, bState );
246 ListView_SetItemState( m_ctrlList.m_hWnd, ch, UINT( ( int( bState ) + 1 ) << 12 ), LVIS_STATEIMAGEMASK );
247 return bOldState;
248 }
249
250 void CDataViewProperties::SetDataYAxisRange( UINT ch, double ymin, double ymax )
251 {
252 CDataViewContext::SetDataYAxisRange( ch, ymin, ymax );
253 CString str;
254 str.Format( "%f", ymin );
255 m_ctrlList.SetItemText( ch, 1, str );
256 str.Format( "%f", ymax );
257 m_ctrlList.SetItemText( ch, 2, str );
258 }
259
260 void CDataViewProperties::SetDataTime( double dTime )
261 {
262 CNeuroManagerDoc * pDoc = ( CNeuroManagerDoc* ) GetDocument();
263 ASSERT_VALID( pDoc );
264 // data time
265 CEdit *pTime = ( CEdit* ) GetDlgItem( IDC_STATIC_TIME );
266 ASSERT_VALID( pTime );
267 CString str = _T( "0" );
268 if ( pDoc->IsMapped() )
269 {
270 FormatTime( str, dTime );
271 }
272 pTime->SetWindowText( str );
273 }
274
275 // CDataViewProperties message handlers
276 void CDataViewProperties::OnUpdate( CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/ )
277 {
278 CNeuroManagerDoc * pDoc = ( CNeuroManagerDoc* ) GetDocument();
279 ASSERT_VALID( pDoc );
280
281 UINT ch = 0;
282 QWORD len = 0;
283 double dMaxTime = 0.0;
284 if ( pDoc->IsMapped() )
285 {
286 ch = ( int ) pDoc->GetChannelNumber();
287 len = pDoc->GetDataLength();
288 dMaxTime = pDoc->GetPosTime( len );
289 }
290 InitializeContext( ch );
291 InitializeDataLength( len, dMaxTime );
292 InitializeDataChannelList();
293 SetDataTime( 0.0 );
294 }
295
296 void CDataViewProperties::OnLvnItemchangedListChannel( NMHDR *pNMHDR, LRESULT *pResult )
297 {
298 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>( pNMHDR );
299
300 BOOL bVisibleStateChanged = OnChangedVisibleDataChannelState( pNMLV );
301 if ( bVisibleStateChanged )
302 {
303 CDataView * wndDataView = ( CDataView* ) GetDataView();
304 wndDataView->RedrawRequest();
305 }
306 *pResult = 0;
307 }
308
309 void CDataViewProperties::OnLvnBeginlabeleditListChannel( NMHDR *pNMHDR, LRESULT *pResult )
310 {
311 NMLVDISPINFO * pDispInfo = reinterpret_cast<NMLVDISPINFO*>( pNMHDR );
312
313 // pResult - 0: show EditControl, 1: doen't show EditControl
314
315 // stop to show EditControl
316 *pResult = 1;
317 // set current column number to 'pDispInfo->item.iSubItem' from cursor position.
318 if ( ! m_ctrlList.PrepareLabelEdit( pDispInfo ) )
319 return ; // invalid cursor position
320
321 // don't edit label of first column 'Channel'
322 if ( pDispInfo->item.iSubItem == 0 )
323 {
324 return ;
325 }
326 m_ctrlList.BeginLabelEdit( pDispInfo, pResult );
327 }
328
329 void CDataViewProperties::OnLvnEndlabeleditListChannel( NMHDR *pNMHDR, LRESULT *pResult )
330 {
331 NMLVDISPINFO * pDispInfo = reinterpret_cast<NMLVDISPINFO*>( pNMHDR );
332
333 // pResult - 0: changed text does not applies to label.
334 // 1: changed text applies to label.
335
336 CString str = pDispInfo->item.pszText;
337
338 // changed text will apply to label text by myself.
339 *pResult = 0;
340 double result;
341 if ( String2Double( str, result ) == FALSE )
342 {
343 // invalid text string
344 ::MessageBeep( MB_OK );
345 return ;
346 }
347
348 BOOL bChange = FALSE;
349 double ymin, ymax;
350 GetDataYAxisRange( pDispInfo->item.iItem, ymin, ymax );
351 switch ( pDispInfo->item.iSubItem )
352 {
353 case 0:
354 // channel
355 // invalid column number
356 break;
357 case 1:
358 // y axis range min
359 // check value. it has to be less than colums 2.
360 if ( ymax > result )
361 {
362 ymin = result;
363 bChange = TRUE;
364 }
365 break;
366 case 2:
367 // y axis range max
368 // check value. it has to be more than colums 1.
369 if ( ymin < result )
370 {
371 ymax = result;
372 bChange = TRUE;
373 }
374 break;
375 default:
376 break;
377 }
378 if ( bChange == TRUE )
379 {
380 SetDataYAxisRange( pDispInfo->item.iItem, ymin, ymax );
381 BOOL bVisible = GetVisibleDataChannelState( pDispInfo->item.iItem );
382 if ( bVisible == TRUE )
383 {
384 CDataView * wndDataView = ( CDataView* ) GetDataView();
385 wndDataView->RedrawRequest();
386 }
387 }
388 else
389 ::MessageBeep( MB_OK );
390 }
391
392 // UPDATE_COMMAND_UI handler for Edit Copy and Edit Cut which both
393 // require that the current focus is on an edit control that has
394 // text selected.
395 void CDataViewProperties::OnUpdateNeedSel( CCmdUI *pCmdUI )
396 {
397 // get the current focus & determine if its on a CEdit control
398 CWnd * pWnd = GetFocus();
399 if ( NULL == pWnd || !IsEdit( pWnd ) )
400 {
401 pCmdUI->Enable( FALSE );
402 }
403 else
404 {
405 CEdit* pEdit = ( CEdit* ) pWnd;
406 int nBeg, nEnd;
407
408 pEdit->GetSel( nBeg, nEnd );
409 pCmdUI->Enable( nBeg != nEnd );
410 }
411 }
412
413 // UPDATE_COMMAND_UI handlers for Edit Paste requires that focus be
414 // on an edit control and that the clipboard contains text to be
415 // pasted into the control.
416 void CDataViewProperties::OnUpdateNeedClip( CCmdUI* pCmdUI )
417 {
418 // get the current focus & determine if its on a CEdit control
419 // also check to see if the control is read-only.
420 CWnd * pWnd = GetFocus();
421 if ( NULL == pWnd || !IsEdit( pWnd ) || ( pWnd->GetStyle() & ES_READONLY ) != 0 )
422 {
423 pCmdUI->Enable( FALSE );
424 }
425 else
426 pCmdUI->Enable( ::IsClipboardFormatAvailable( CF_TEXT ) );
427 }
428
429 void CDataViewProperties::OnEditCopy()
430 {
431 CEdit * pEdit = ( CEdit* ) GetFocus();
432 ASSERT( IsEdit( pEdit ) );
433 pEdit->Copy();
434 }
435
436 void CDataViewProperties::OnEditCut()
437 {
438 CEdit * pEdit = ( CEdit* ) GetFocus();
439 ASSERT( IsEdit( pEdit ) );
440 pEdit->Cut();
441 }
442
443 void CDataViewProperties::OnEditPaste()
444 {
445 CEdit * pEdit = ( CEdit* ) GetFocus();
446 ASSERT( IsEdit( pEdit ) );
447 ASSERT( ::IsClipboardFormatAvailable( CF_TEXT ) );
448 pEdit->Paste();
449 }
450

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26