GME
13
|
00001 //############################################################################################################################################### 00002 // 00003 // Object Constraint Language Generic Manager 00004 // GMESyntacticSemanticDialog.cp 00005 // 00006 //############################################################################################################################################### 00007 00008 #include "StdAfx.h" 00009 #include "GMESyntacticSemanticDialog.h" 00010 #include "OCLCommonEx.h" 00011 00012 #ifdef _DEBUG 00013 #define new DEBUG_NEW 00014 #undef THIS_FILE 00015 static char THIS_FILE[] = __FILE__; 00016 #endif 00017 00018 struct SortStruct 00019 { 00020 CSyntacticSemanticDialog* pDialog; 00021 int iColumn; 00022 }; 00023 00024 //############################################################################################################################################## 00025 // 00026 // C L A S S : CSyntacticSemanticDialog <<< + CDialog 00027 // 00028 //############################################################################################################################################## 00029 00030 CSyntacticSemanticDialog::CSyntacticSemanticDialog(CWnd* pParent /*=NULL*/) 00031 : CDialog(CSyntacticSemanticDialog::IDD, pParent), m_iSelected( 0 ), m_iSelectedError( 0 ) 00032 { 00033 //{{AFX_DATA_INIT(CSyntacticSemanticDialog) 00034 //}}AFX_DATA_INIT 00035 } 00036 00037 void CSyntacticSemanticDialog::DoDataExchange(CDataExchange* pDX) 00038 { 00039 CDialog::DoDataExchange(pDX); 00040 //{{AFX_DATA_MAP(CSyntacticSemanticDialog) 00041 DDX_Control(pDX, SSD_LSTERRORS, m_lstErrors); 00042 DDX_Control(pDX, SSD_LSTCONSTRAINTS, m_lstConstraints); 00043 DDX_Control(pDX, SSD_LSTEXPRESSION, m_lstExpression); 00044 DDX_Control(pDX, SSD_LBLGENERALMSG, m_lblGeneralMessage); 00045 DDX_Control(pDX, SSD_ICNLARGE, m_imgLarge); 00046 DDX_Control(pDX, SSD_BTNCLOSE, m_btnClose); 00047 //}}AFX_DATA_MAP 00048 } 00049 00050 BEGIN_MESSAGE_MAP(CSyntacticSemanticDialog, CDialog) 00051 //{{AFX_MSG_MAP(CSyntacticSemanticDialog) 00052 ON_BN_CLICKED(SSD_BTNCLOSE, OnClickClose) 00053 ON_NOTIFY(LVN_KEYDOWN, SSD_LSTCONSTRAINTS, OnKeyDownConstraints) 00054 ON_NOTIFY(LVN_KEYDOWN, SSD_LSTERRORS, OnKeyDownErrors) 00055 ON_NOTIFY(NM_CLICK, SSD_LSTERRORS, OnClickErrors) 00056 ON_NOTIFY(LVN_COLUMNCLICK, SSD_LSTCONSTRAINTS, OnClickConstraintsColumn) 00057 ON_NOTIFY(NM_CLICK, SSD_LSTCONSTRAINTS, OnClickConstraints) 00058 //}}AFX_MSG_MAP 00059 END_MESSAGE_MAP() 00060 00061 00062 00063 00064 00065 BOOL CSyntacticSemanticDialog::OnInitDialog() 00066 { 00067 CDialog::OnInitDialog(); 00068 00069 // Load ImageLists 00070 00071 m_lstConstraintImages.Create( 16, 16, ILC_COLOR24 | ILC_MASK, 10, 10 ); 00072 CBitmap bmpTemp1; 00073 bmpTemp1.LoadBitmap( IDB_CONSTRAINTICONS ); 00074 m_lstConstraintImages.Add( &bmpTemp1, RGB( 255, 0, 255 ) ); 00075 00076 m_lstErrorImages.Create( 16, 16, ILC_COLOR24 | ILC_MASK, 4, 4 ); 00077 CBitmap bmpTemp2; 00078 bmpTemp2.LoadBitmap( IDB_ERRORICONS ); 00079 m_lstErrorImages.Add( &bmpTemp2, RGB( 255, 0, 255 ) ); 00080 00081 m_lstLineImages.Create( 16, 16, ILC_COLOR24 | ILC_MASK, 2, 2 ); 00082 CBitmap bmpTemp3; 00083 bmpTemp3.LoadBitmap( IDB_LINEICONS ); 00084 m_lstLineImages.Add( &bmpTemp3, RGB( 255, 0, 255 ) ); 00085 00086 // Set required properties of ListControls 00087 00088 m_lstConstraints.SetImageList( &m_lstConstraintImages, LVSIL_SMALL ); 00089 00090 int iLength = 3 * m_lstConstraints.GetStringWidth(_T("Type")) / 2; 00091 m_lstConstraints.InsertColumn( 0, _T("Type"), LVCFMT_LEFT, iLength, -1 ); 00092 iLength = 3 * m_lstConstraints.GetStringWidth(_T("Context")) / 2; 00093 m_lstConstraints.InsertColumn( 1, _T("Context"), LVCFMT_LEFT, iLength, 1 ); 00094 iLength = 3 * m_lstConstraints.GetStringWidth(_T("Constraint(Definition)")) / 2; 00095 m_lstConstraints.InsertColumn( 2, _T("Name"), LVCFMT_LEFT, iLength, 2 ); 00096 00097 m_lstConstraints.SetExtendedStyle( LVS_EX_FULLROWSELECT ); 00098 00099 m_lstErrors.SetImageList( &m_lstErrorImages, LVSIL_SMALL ); 00100 00101 iLength = 3 * m_lstErrors.GetStringWidth(_T("Code")) / 2; 00102 m_lstErrors.InsertColumn( 0, _T("Code"), LVCFMT_LEFT, iLength, -1 ); 00103 iLength = 3 * m_lstErrors.GetStringWidth(_T("Line")) / 2; 00104 m_lstErrors.InsertColumn( 1, _T("Ln."), LVCFMT_LEFT, iLength, 1 ); 00105 /* 00106 // This column is commented out because this features is not implemented yet 00107 // Be careful with uncommenting -> column numbers 00108 00109 iLength = 3 * m_lstErrors.GetStringWidth(_T("Column")) / 2; 00110 m_lstErrors.InsertColumn( 2, _T("Col."), LVCFMT_LEFT, iLength, 2 ); 00111 */ 00112 00113 iLength = 3 * m_lstErrors.GetStringWidth(_T("Message")) / 2; 00114 m_lstErrors.InsertColumn( 2, _T("Message"), LVCFMT_LEFT, iLength, 2 ); 00115 00116 m_lstErrors.SetExtendedStyle( LVS_EX_FULLROWSELECT ); 00117 00118 m_lstExpression.SetImageList( &m_lstLineImages, LVSIL_SMALL ); 00119 00120 iLength = 3 * m_lstExpression.GetStringWidth(_T("Line")) / 2; 00121 m_lstExpression.InsertColumn( 0, _T("Line"), LVCFMT_RIGHT, iLength, -1 ); 00122 iLength = 3 * m_lstExpression.GetStringWidth(_T("Expression")) / 2; 00123 m_lstExpression.InsertColumn( 1, _T("Expression"), LVCFMT_LEFT, iLength, 1 ); 00124 00125 m_lstExpression.SetExtendedStyle( LVS_EX_FULLROWSELECT ); 00126 00127 // Fill Constraint List 00128 00129 int iFunctions = m_vecConstraintFunctions.size(); 00130 for ( int i = 0 ; i < iFunctions ; i++ ) 00131 AddConstraintRow( i ); 00132 00133 for ( unsigned int i = 0 ; i < (int) m_vecConstraints.size() ; i++ ) 00134 AddConstraintRow( i + iFunctions ); 00135 00136 m_lstConstraints.SetColumnWidth( 0, LVSCW_AUTOSIZE_USEHEADER ); 00137 m_lstConstraints.SetColumnWidth( 1, LVSCW_AUTOSIZE_USEHEADER ); 00138 m_lstConstraints.SetColumnWidth( 2, LVSCW_AUTOSIZE_USEHEADER ); 00139 00140 // Display First Constraint 00141 00142 SortConstraints( 2 ); 00143 SortConstraints( 1 ); 00144 SortConstraints( 0 ); 00145 DisplayConstraintItem(); 00146 00147 return TRUE; 00148 } 00149 00150 void CSyntacticSemanticDialog::OnClickClose() 00151 { 00152 CDialog::OnOK(); 00153 } 00154 00155 void CSyntacticSemanticDialog::OnClickConstraints(NMHDR* pNMHDR, LRESULT* pResult) 00156 { 00157 m_iSelected = min( max( m_lstConstraints.GetSelectionMark(), 0 ), m_lstConstraints.GetItemCount() - 1 ); 00158 DisplayConstraintItem(); 00159 *pResult = 0; 00160 } 00161 00162 void CSyntacticSemanticDialog::OnKeyDownConstraints(NMHDR* pNMHDR, LRESULT* pResult) 00163 { 00164 LV_KEYDOWN* pLVKeyDown = (LV_KEYDOWN*)pNMHDR; 00165 if ( pLVKeyDown->wVKey == VK_UP ) 00166 SelectConstraint( false ); 00167 else 00168 if ( pLVKeyDown->wVKey == VK_DOWN ) 00169 SelectConstraint( true ); 00170 *pResult = 0; 00171 } 00172 00173 void CSyntacticSemanticDialog::OnClickErrors(NMHDR* pNMHDR, LRESULT* pResult) 00174 { 00175 m_iSelectedError = min( max( m_lstErrors.GetSelectionMark(), 0 ), m_lstErrors.GetItemCount() - 1 ); 00176 DisplayErrorItem(); 00177 *pResult = 0; 00178 } 00179 00180 00181 void CSyntacticSemanticDialog::OnKeyDownErrors(NMHDR* pNMHDR, LRESULT* pResult) 00182 { 00183 LV_KEYDOWN* pLVKeyDown = (LV_KEYDOWN*)pNMHDR; 00184 if ( pLVKeyDown->wVKey == VK_UP ) 00185 SelectError( false ); 00186 else 00187 if ( pLVKeyDown->wVKey == VK_DOWN ) 00188 SelectError( true ); 00189 *pResult = 0; 00190 } 00191 00192 void CSyntacticSemanticDialog::OnClickConstraintsColumn( NMHDR* pNMHDR, LRESULT* pResult ) 00193 { 00194 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; 00195 SortConstraints( pNMListView->iSubItem ); 00196 *pResult = 0; 00197 } 00198 00199 void CSyntacticSemanticDialog::AddItem( const OclGme::SpConstraint& item ) 00200 { 00201 m_vecConstraints.push_back( item ); 00202 } 00203 00204 void CSyntacticSemanticDialog::AddItem( const OclGme::SpConstraintFunction& item ) 00205 { 00206 m_vecConstraintFunctions.push_back( item ); 00207 } 00208 00209 void CSyntacticSemanticDialog::SelectConstraint( bool bNext ) 00210 { 00211 if ( ! bNext ) { 00212 if ( m_iSelected != 0 ) { 00213 m_iSelected--; 00214 DisplayConstraintItem(); 00215 } 00216 } 00217 else { 00218 if ( m_iSelected != m_lstConstraints.GetItemCount() - 1 ) { 00219 m_iSelected++; 00220 DisplayConstraintItem(); 00221 } 00222 } 00223 } 00224 00225 void CSyntacticSemanticDialog::SelectError( bool bNext ) 00226 { 00227 if ( ! bNext ) { 00228 if ( m_iSelectedError != 0 ) { 00229 m_iSelectedError--; 00230 DisplayErrorItem(); 00231 } 00232 } 00233 else { 00234 if ( m_iSelectedError != m_lstErrors.GetItemCount() - 1 ) { 00235 m_iSelectedError++; 00236 DisplayErrorItem(); 00237 } 00238 } 00239 } 00240 00241 void CSyntacticSemanticDialog::AddConstraintRow( int iPos ) 00242 { 00243 CString strContext, strName; int eType; 00244 GetConstraintRow( iPos, eType, strContext, strName ); 00245 00246 LVITEM lvItem; 00247 lvItem.mask = LVIF_IMAGE | LVIF_PARAM;; 00248 if ( iPos == 0 ) { 00249 lvItem.mask = lvItem.mask | LVIF_STATE; 00250 lvItem.state = LVIS_SELECTED; 00251 lvItem.stateMask = LVIS_SELECTED; 00252 } 00253 lvItem.iItem = m_lstConstraints.GetItemCount(); 00254 lvItem.iSubItem = 0; 00255 lvItem.iImage = eType; 00256 lvItem.lParam = iPos; 00257 m_lstConstraints.InsertItem( &lvItem ); 00258 00259 lvItem.mask = LVIF_TEXT; 00260 lvItem.iSubItem = 1; 00261 lvItem.pszText = strContext.GetBuffer( strContext.GetLength() ); 00262 m_lstConstraints.SetItem( &lvItem ); 00263 strContext.ReleaseBuffer(); 00264 00265 lvItem.mask = LVIF_TEXT; 00266 lvItem.iSubItem = 2; 00267 lvItem.pszText = strName.GetBuffer( strName.GetLength() ); 00268 m_lstConstraints.SetItem( &lvItem ); 00269 strName.ReleaseBuffer(); 00270 } 00271 00272 void CSyntacticSemanticDialog::GetConstraintRow( int iPos, int& eType, CString& strContext, CString& strName ) 00273 { 00274 int iFunctions = m_vecConstraintFunctions.size(); 00275 eType = ( iPos >= iFunctions ) ? m_vecConstraints[ iPos - iFunctions ]->GetType() : m_vecConstraintFunctions[ iPos ]->GetType(); 00276 std::string strContextT, strNameT; 00277 if ( iPos >= iFunctions ) 00278 m_vecConstraints[ iPos - iFunctions ]->GetContextAndName( strContextT, strNameT ); 00279 else 00280 m_vecConstraintFunctions[ iPos ]->GetContextAndName( strContextT, strNameT ); 00281 strContext = OclCommonEx::Convert( strContextT ); 00282 strName = OclCommonEx::Convert( strNameT ); 00283 } 00284 00285 void CSyntacticSemanticDialog::DisplayErrorItem() 00286 { 00287 int iCPos = m_lstConstraints.GetItemData( m_iSelected ); 00288 int iFunctions = m_vecConstraintFunctions.size(); 00289 m_lstErrors.SetItemState( m_iSelectedError, LVIS_SELECTED, LVIS_SELECTED ); 00290 00291 OclCommon::ExceptionPool poolExceptions = ( iCPos >= iFunctions ) ? m_vecConstraints[ iCPos - iFunctions ]->GetExceptions() : m_vecConstraintFunctions[ iCPos ]->GetExceptions(); 00292 int iLine = poolExceptions.GetAt( m_iSelectedError ).GetLine(); 00293 for ( int i = 0 ; i < m_lstExpression.GetItemCount() ; i++ ) { 00294 LVITEM lvItem; 00295 lvItem.mask = LVIF_IMAGE | LVIF_STATE; 00296 lvItem.state = ( i + 1== iLine ) ? LVIS_SELECTED : 0; 00297 lvItem.stateMask = LVIS_SELECTED; 00298 lvItem.iItem = i; 00299 lvItem.iSubItem = 0; 00300 lvItem.iImage = ( i + 1== iLine ) ? 1 : 0; 00301 m_lstExpression.SetItem( &lvItem ); 00302 if ( i + 1== iLine ) 00303 m_lstExpression.EnsureVisible( i, false ); 00304 } 00305 } 00306 00307 void CSyntacticSemanticDialog::DisplayConstraintItem() 00308 { 00309 int iPos = m_lstConstraints.GetItemData( m_iSelected ); 00310 int iFunctions = m_vecConstraintFunctions.size(); 00311 m_lstConstraints.SetItemState( m_iSelected, LVIS_SELECTED, LVIS_SELECTED ); 00312 00313 // Set Constraint Text 00314 00315 m_lstExpression.DeleteAllItems(); 00316 00317 CStringArray arrText; 00318 CString strExpression = OclCommonEx::Convert( ( iPos >= iFunctions ) ? m_vecConstraints[ iPos - iFunctions ]->GetText() : m_vecConstraintFunctions[ iPos ]->GetText() ); 00319 strExpression.Replace( _T("\r"), _T("") ); 00320 strExpression.Replace( _T("\n"), _T("\r\n") ); 00321 strExpression.Replace( _T("\t"), _T(" ") ); 00322 int iFPos = 0; 00323 do { 00324 iFPos = strExpression.Find( _T("\r\n") ); 00325 if ( iFPos == -1 ) 00326 arrText.Add( strExpression ); 00327 else { 00328 arrText.Add( strExpression.Left( iFPos ) ); 00329 strExpression = strExpression.Right( strExpression.GetLength() - iFPos - 2 ); 00330 } 00331 } while ( iFPos != -1 ); 00332 00333 LVITEM lvItem; 00334 for ( int i = 0 ; i < arrText.GetSize() ; i++ ) { 00335 00336 // Add Line 00337 00338 lvItem.mask = LVIF_IMAGE | LVIF_NORECOMPUTE | LVIF_TEXT; 00339 lvItem.iItem = m_lstExpression.GetItemCount(); 00340 lvItem.iSubItem = 0; 00341 lvItem.iImage = 0; 00342 lvItem.lParam = i; 00343 CString strTemp; 00344 strTemp.Format( _T("%d"), i + 1 ); 00345 lvItem.pszText = strTemp.GetBuffer( strTemp.GetLength() ); 00346 m_lstExpression.InsertItem( &lvItem ); 00347 00348 strTemp.ReleaseBuffer(); 00349 strTemp.Empty(); 00350 00351 // Add ExpressionPiece 00352 00353 lvItem.mask = LVIF_TEXT; 00354 lvItem.iSubItem = 1; 00355 strTemp = arrText.GetAt( i ); 00356 lvItem.pszText = strTemp.GetBuffer( strTemp.GetLength() ); 00357 m_lstExpression.SetItem( &lvItem ); 00358 00359 strTemp.ReleaseBuffer(); 00360 } 00361 00362 m_lstExpression.SetColumnWidth( 0, LVSCW_AUTOSIZE_USEHEADER ); 00363 m_lstExpression.SetColumnWidth( 1, LVSCW_AUTOSIZE_USEHEADER ); 00364 00365 // Add Errors 00366 00367 m_lstErrors.DeleteAllItems(); 00368 00369 OclCommon::ExceptionPool poolExceptions = ( iPos >= iFunctions ) ? m_vecConstraints[ iPos - iFunctions ]->GetExceptions() : m_vecConstraintFunctions[ iPos ]->GetExceptions(); 00370 for ( int i = 0 ; i < poolExceptions.Size() ; i++ ) { 00371 OclCommon::Exception ex = poolExceptions.GetAt( i ); 00372 00373 // Add Code 00374 00375 lvItem.mask = LVIF_IMAGE | LVIF_NORECOMPUTE | LVIF_TEXT; 00376 if ( i == 0 ) { 00377 lvItem.mask = lvItem.mask | LVIF_STATE; 00378 lvItem.state = LVIS_SELECTED; 00379 } 00380 lvItem.iItem = m_lstErrors.GetItemCount(); 00381 lvItem.iSubItem = 0; 00382 lvItem.iImage = ex.GetType(); 00383 lvItem.lParam = i; 00384 CString strTemp; 00385 if ( ex.GetCode() == -1 ) 00386 strTemp = _T("None"); 00387 else 00388 strTemp.Format( _T("%d"), ex.GetCode() ); 00389 lvItem.pszText = strTemp.GetBuffer( strTemp.GetLength() ); 00390 m_lstErrors.InsertItem( &lvItem ); 00391 00392 strTemp.ReleaseBuffer(); 00393 strTemp.Empty(); 00394 00395 // Add Line 00396 00397 lvItem.mask = LVIF_TEXT; 00398 lvItem.iSubItem = 1; 00399 if ( ex.GetLine() < 0 ) 00400 strTemp = _T("?"); 00401 else 00402 strTemp.Format( _T("%d"), ex.GetLine() ); 00403 lvItem.pszText = strTemp.GetBuffer( strTemp.GetLength() ); 00404 m_lstErrors.SetItem( &lvItem ); 00405 00406 strTemp.ReleaseBuffer(); 00407 strTemp.Empty(); 00408 00409 // Add Column 00410 00411 /* 00412 // This column is commented out because this features is not implemented yet 00413 // Be careful with uncommenting -> column and subitem numbers 00414 00415 lvItem.iSubItem = 2; 00416 strTemp.Format( _T("%d"), ex.GetColumn() ); 00417 lvItem.pszText = strTemp.GetBuffer( strTemp.GetLength() ); 00418 m_lstErrors.SetItem( &lvItem ); 00419 00420 strTemp.ReleaseBuffer(); 00421 strTemp.Empty(); 00422 */ 00423 00424 // Add Message 00425 00426 lvItem.iSubItem = 2; 00427 strTemp = OclCommonEx::Convert( ex.GGetMessage() ); 00428 lvItem.pszText = strTemp.GetBuffer( strTemp.GetLength() ); 00429 m_lstErrors.SetItem( &lvItem ); 00430 00431 strTemp.ReleaseBuffer(); 00432 } 00433 00434 m_lstErrors.SetColumnWidth( 0, LVSCW_AUTOSIZE_USEHEADER ); 00435 m_lstErrors.SetColumnWidth( 1, LVSCW_AUTOSIZE_USEHEADER ); 00436 m_lstErrors.SetColumnWidth( 2, LVSCW_AUTOSIZE_USEHEADER ); 00437 00438 /* 00439 // This column is commented out because this features is not implemented yet 00440 // Be careful with uncommenting -> column numbers 00441 00442 m_lstErrors.SetColumnWidth( 3, LVSCW_AUTOSIZE_USEHEADER ); 00443 */ 00444 00445 if ( poolExceptions.IsEmpty() ) 00446 ASSERT( 0 ); 00447 else { 00448 m_iSelectedError = 0; 00449 DisplayErrorItem(); 00450 } 00451 } 00452 00453 void CSyntacticSemanticDialog::SortConstraints( int iColumn ) 00454 { 00455 SortStruct sortInfo; 00456 sortInfo.pDialog = this; 00457 sortInfo.iColumn = iColumn; 00458 m_lstConstraints.SortItems( CSyntacticSemanticDialog::CompareConstraint, ( LPARAM ) ( &sortInfo ) ); 00459 00460 m_iSelected = min( max( m_lstConstraints.GetSelectionMark(), 0 ), m_lstConstraints.GetItemCount() - 1 ); 00461 } 00462 00463 int CALLBACK CSyntacticSemanticDialog::CompareConstraint( LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort ) 00464 { 00465 SortStruct* pSortInfo = ( SortStruct* ) lParamSort; 00466 00467 CString strCtx1, strName1; int eType1; 00468 pSortInfo->pDialog->GetConstraintRow( lParam1, eType1, strCtx1, strName1 ); 00469 00470 CString strCtx2, strName2; int eType2; 00471 pSortInfo->pDialog->GetConstraintRow( lParam2, eType2, strCtx2, strName2 ); 00472 00473 if ( pSortInfo->iColumn == 0 ) { 00474 if ( eType1 < 4 ) 00475 eType1 += 10; 00476 if ( eType2 < 4 ) 00477 eType2 += 10; 00478 return ( eType1 < eType2 ) ? -1 : ( eType1 > eType2 ) ? 1 : 0; 00479 } 00480 if ( pSortInfo->iColumn == 1 ) 00481 return _tcscmp( strCtx1, strCtx2 ); 00482 return _tcscmp( strName1, strName2 ); 00483 }