GME
13
|
00001 //############################################################################################################################################### 00002 // 00003 // Object Constraint Language Generic Manager 00004 // GMEViolationDialog.cpp 00005 // 00006 //############################################################################################################################################### 00007 00008 #include "stdafx.h" 00009 #include "GMEViolationDialog.h" 00010 #include "OCLCommonEx.h" 00011 #include "OCLGMECMFacade.h" 00012 00013 #ifdef _DEBUG 00014 #define new DEBUG_NEW 00015 #undef THIS_FILE 00016 static char THIS_FILE[] = __FILE__; 00017 #endif 00018 00019 namespace OclGmeCM { 00020 00021 struct SortStruct 00022 { 00023 CViolationDialog* pDialog; 00024 int iColumn; 00025 }; 00026 00027 00028 00029 //############################################################################################################################################## 00030 // 00031 // C L A S S : CViolationDialog <<< + CDialog 00032 // 00033 //############################################################################################################################################## 00034 00035 CViolationDialog::CViolationDialog( bool bExpanded, CWnd* pParent /*=NULL*/, IMgaProject *project) 00036 : CDialog(CViolationDialog::IDD, pParent), m_bExpanded( bExpanded ), m_bAbort( false ), m_bOK( false ), m_iSelected( 0 ), 00037 m_iSelectedConstraint( 0 ), m_iSelectedError( 0 ), m_iSelectedVariable( 0 ) 00038 { 00039 m_spProject = project; 00040 00041 COMTRY 00042 { 00043 CComBSTR app(L"GME.Application"); 00044 CComPtr<IMgaClient> client; 00045 HRESULT hr = m_spProject->GetClientByName((BSTR)app, &client); 00046 if (FAILED(hr)) 00047 return; 00048 00049 CComPtr<IDispatch> gui; 00050 COMTHROW(client->get_OLEServer(&gui)); 00051 COMTHROW(gui.QueryInterface(&m_oleapp)); 00052 } 00053 catch(hresult_exception &) 00054 { 00055 } 00056 00057 //{{AFX_DATA_INIT(CViolationDialog) 00058 //}}AFX_DATA_INIT 00059 } 00060 00061 void CViolationDialog::DoDataExchange(CDataExchange* pDX) 00062 { 00063 CDialog::DoDataExchange(pDX); 00064 //{{AFX_DATA_MAP(CViolationDialog) 00065 DDX_Control(pDX, CVD_LBLCONSTRAINT, m_lblConstraint); 00066 DDX_Control(pDX, CVD_FRMMESSAGE, m_frmMessage); 00067 DDX_Control(pDX, CVD_BTNPREVIOUS, m_btnPrevious); 00068 DDX_Control(pDX, CVD_BTNNEXT, m_btnNext); 00069 DDX_Control(pDX, CVD_BTNEXPAND, m_btnExpand); 00070 DDX_Control(pDX, CVD_TABCONTEXT, m_tabPages); 00071 DDX_Control(pDX, CVD_LBLGENERALMSG, m_lblGeneralMessage); 00072 DDX_Control(pDX, CVD_LSTOBJECTS, m_lstObjects); 00073 DDX_Control(pDX, CVD_BTNABORT, m_btnAbort); 00074 DDX_Control(pDX, CVD_LSTEXPRESSION, m_lstExpression); 00075 DDX_Control(pDX, CVD_LSTERRORS, m_lstErrors); 00076 DDX_Control(pDX, CVD_LSTCONSTRAINTS, m_lstConstraints); 00077 DDX_Control(pDX, CVD_ICNLARGE, m_imgLarge); 00078 DDX_Control(pDX, CVD_BTNCLOSE, m_btnClose); 00079 //}}AFX_DATA_MAP 00080 } 00081 00082 00083 BEGIN_MESSAGE_MAP(CViolationDialog, CDialog) 00084 //{{AFX_MSG_MAP(CViolationDialog) 00085 ON_BN_CLICKED(CVD_BTNCLOSE, OnClickClose) 00086 ON_NOTIFY(LVN_KEYDOWN, CVD_LSTCONSTRAINTS, OnKeyDownConstraints) 00087 ON_BN_CLICKED(CVD_BTNABORT, OnClickAbort) 00088 ON_NOTIFY(NM_CLICK, CVD_LSTCONSTRAINTS, OnClickConstraints) 00089 ON_NOTIFY(NM_CLICK, CVD_LSTERRORS, OnClickErrors) 00090 ON_NOTIFY(NM_CLICK, CVD_LSTOBJECTS, OnClickVariable) 00091 ON_NOTIFY(LVN_KEYDOWN, CVD_LSTERRORS, OnKeyDownErrors) 00092 ON_NOTIFY(TCN_SELCHANGE, CVD_TABCONTEXT, OnSelectionChangedTab) 00093 ON_BN_CLICKED(CVD_BTNEXPAND, OnClickExpand) 00094 ON_BN_CLICKED(CVD_BTNNEXT, OnClickNext) 00095 ON_BN_CLICKED(CVD_BTNPREVIOUS, OnClickPrevious) 00096 ON_NOTIFY(LVN_COLUMNCLICK, CVD_LSTCONSTRAINTS, OnClickConstraintsColumn) 00097 //}}AFX_MSG_MAP 00098 END_MESSAGE_MAP() 00099 00100 00101 00102 00103 00104 00105 BOOL CViolationDialog::OnInitDialog() 00106 { 00107 CDialog::OnInitDialog(); 00108 00109 // Load ImageLists 00110 00111 m_lstConstraintImages.Create( 16, 16, ILC_COLOR24 | ILC_MASK, 10, 10 ); 00112 CBitmap bmpTemp1; 00113 bmpTemp1.LoadBitmap( IDB_CONSTRAINTICONS ); 00114 m_lstConstraintImages.Add( &bmpTemp1, RGB( 255, 0, 255 ) ); 00115 00116 m_lstErrorImages.Create( 16, 16, ILC_COLOR24 | ILC_MASK, 4, 4 ); 00117 CBitmap bmpTemp2; 00118 bmpTemp2.LoadBitmap( IDB_ERRORICONS ); 00119 m_lstErrorImages.Add( &bmpTemp2, RGB( 255, 0, 255 ) ); 00120 00121 m_lstLineImages.Create( 16, 16, ILC_COLOR24 | ILC_MASK, 2, 2 ); 00122 CBitmap bmpTemp3; 00123 bmpTemp3.LoadBitmap( IDB_LINEICONS ); 00124 m_lstLineImages.Add( &bmpTemp3, RGB( 255, 0, 255 ) ); 00125 00126 // Set required properties of ListControls 00127 00128 m_lstConstraints.SetImageList( &m_lstConstraintImages, LVSIL_SMALL ); 00129 00130 int iLength = 3 * m_lstConstraints.GetStringWidth(_T("Type")) / 2; 00131 m_lstConstraints.InsertColumn( 0, _T("Type"), LVCFMT_LEFT, iLength, -1 ); 00132 iLength = 3 * m_lstConstraints.GetStringWidth(_T("Context")) / 2; 00133 m_lstConstraints.InsertColumn( 1, _T("Context"), LVCFMT_LEFT, iLength, 1 ); 00134 iLength = 3 * m_lstConstraints.GetStringWidth(_T("Name")) / 2; 00135 m_lstConstraints.InsertColumn( 2, _T("Name"), LVCFMT_LEFT, iLength, 2 ); 00136 00137 m_lstConstraints.SetExtendedStyle( LVS_EX_FULLROWSELECT ); 00138 00139 m_lstErrors.SetImageList( &m_lstErrorImages, LVSIL_SMALL ); 00140 00141 iLength = 3 * m_lstErrors.GetStringWidth(_T("Line")) / 2; 00142 m_lstErrors.InsertColumn( 0, _T("Ln."), LVCFMT_LEFT, iLength, -1 ); 00143 /* 00144 // This column is commented out because this features is not implemented yet 00145 // Be careful with uncommenting -> column numbers 00146 00147 iLength = 3 * m_lstErrors.GetStringWidth(_T("Column")) / 2; 00148 m_lstErrors.InsertColumn( 2, _T("Col."), LVCFMT_LEFT, iLength, 1 ); 00149 */ 00150 00151 iLength = 3 * m_lstErrors.GetStringWidth(_T("Message")) / 2; 00152 m_lstErrors.InsertColumn( 1, _T("Message"), LVCFMT_LEFT, iLength, 1 ); 00153 iLength = 3 * m_lstErrors.GetStringWidth(_T("Signature")) / 2; 00154 m_lstErrors.InsertColumn( 2, _T("Signature"), LVCFMT_LEFT, iLength, 2 ); 00155 00156 m_lstErrors.SetExtendedStyle( LVS_EX_FULLROWSELECT ); 00157 00158 m_lstExpression.SetImageList( &m_lstLineImages, LVSIL_SMALL ); 00159 00160 iLength = 3 * m_lstExpression.GetStringWidth(_T("Line")) / 2; 00161 m_lstExpression.InsertColumn( 0, _T("Line"), LVCFMT_RIGHT, iLength, -1 ); 00162 iLength = 3 * m_lstExpression.GetStringWidth(_T("Expression")) / 2; 00163 m_lstExpression.InsertColumn( 1, _T("Expression"), LVCFMT_LEFT, iLength, 1 ); 00164 00165 m_lstExpression.SetExtendedStyle( LVS_EX_FULLROWSELECT ); 00166 00167 m_lstObjects.SetImageList( &m_lstLineImages, LVSIL_SMALL ); 00168 00169 iLength = 3 * m_lstObjects.GetStringWidth(_T("Variable")) / 2; 00170 m_lstObjects.InsertColumn( 0, _T("Variable"), LVCFMT_RIGHT, iLength, -1 ); 00171 iLength = 3 * m_lstObjects.GetStringWidth(_T("Object")) / 2; 00172 m_lstObjects.InsertColumn( 1, _T("Object"), LVCFMT_LEFT, iLength, 1 ); 00173 00174 m_lstObjects.SetExtendedStyle( LVS_EX_FULLROWSELECT ); 00175 00176 // Fill Constraint List 00177 00178 for ( unsigned int i = 0 ; i < m_vecRecords.size() ; i++ ) { 00179 LVITEM lvItem; 00180 lvItem.mask = LVIF_IMAGE | LVIF_PARAM; 00181 if ( i == 0 ) { 00182 lvItem.mask = lvItem.mask | LVIF_STATE; 00183 lvItem.state = LVIS_SELECTED; 00184 lvItem.stateMask = LVIS_SELECTED; 00185 } 00186 lvItem.iItem = m_lstConstraints.GetItemCount(); 00187 lvItem.iSubItem = 0; 00188 lvItem.iImage = m_vecRecords[ i ].spConstraint->GetType(); 00189 lvItem.lParam = i; 00190 m_lstConstraints.InsertItem( &lvItem ); 00191 00192 lvItem.mask = LVIF_TEXT; 00193 lvItem.iSubItem = 1; 00194 CString strText = OclCommonEx::Convert( m_vecRecords[ i ].spConstraint->GetContextType() ); 00195 lvItem.pszText = (TCHAR*)(LPCTSTR)strText; //.GetBuffer( strText.GetLength() ); 00196 m_lstConstraints.SetItem( &lvItem ); 00197 // strText.ReleaseBuffer(); 00198 00199 lvItem.iSubItem = 2; 00200 strText = OclCommonEx::Convert( m_vecRecords[ i ].spConstraint->GetName() ); 00201 lvItem.pszText = (TCHAR*)(LPCTSTR)strText; //.GetBuffer( strText.GetLength() ); 00202 m_lstConstraints.SetItem( &lvItem ); 00203 // strText.ReleaseBuffer(); 00204 } 00205 00206 m_lstConstraints.SetColumnWidth( 0, LVSCW_AUTOSIZE_USEHEADER ); 00207 m_lstConstraints.SetColumnWidth( 1, LVSCW_AUTOSIZE_USEHEADER ); 00208 m_lstConstraints.SetColumnWidth( 2, LVSCW_AUTOSIZE_USEHEADER ); 00209 00210 // Display First Constraint 00211 00212 SortConstraints( 2 ); 00213 SortConstraints( 1 ); 00214 SortConstraints( 0 ); 00215 RefreshWidgets( true ); 00216 00217 // Enable Buttons 00218 00219 m_btnAbort.EnableWindow( m_bAbort ); 00220 m_btnClose.EnableWindow( m_bOK ); 00221 00222 m_tabPages.InsertItem( 0, _T("Expression") ); 00223 m_tabPages.InsertItem( 1, _T("Variables") ); 00224 m_lstObjects.ShowWindow( SW_HIDE ); 00225 00226 // Set Expanded vs Collapsed 00227 00228 if ( ! m_bExpanded ) { 00229 m_bExpanded = true; 00230 OnClickExpand(); 00231 } 00232 00233 return TRUE; 00234 } 00235 00236 void CViolationDialog::OnSelectionChangedTab(NMHDR* pNMHDR, LRESULT* pResult) 00237 { 00238 m_lstObjects.ShowWindow( ( m_tabPages.GetCurSel() == 1 ) ? SW_SHOW : SW_HIDE ); 00239 m_lstExpression.ShowWindow( ( m_tabPages.GetCurSel() == 0 ) ? SW_SHOW : SW_HIDE ); 00240 *pResult = 0; 00241 } 00242 00243 void CViolationDialog::OnClickClose() 00244 { 00245 CDialog::OnOK(); 00246 } 00247 00248 void CViolationDialog::OnClickAbort() 00249 { 00250 CDialog::OnCancel(); 00251 } 00252 00253 void CViolationDialog::OnClickExpand() 00254 { 00255 m_bExpanded = ! m_bExpanded; 00256 00257 m_btnExpand.SetWindowText( ( m_bExpanded ) ? _T("Collapse") : _T("Expand") ); 00258 00259 CRect rectEx; 00260 m_btnExpand.GetWindowRect( rectEx ); 00261 00262 CRect rectObj; 00263 m_lstObjects.GetWindowRect( rectObj ); 00264 00265 CRect rectExp; 00266 m_lstExpression.GetWindowRect( rectExp ); 00267 00268 CRect rectCon; 00269 m_lstConstraints.GetWindowRect( rectCon ); 00270 00271 CRect rectMes; 00272 m_frmMessage.GetWindowRect( rectMes ); 00273 00274 rectObj.TopLeft() = ( m_bExpanded ) ? rectExp.TopLeft() : rectCon.TopLeft(); 00275 if ( m_bExpanded ) 00276 rectObj.BottomRight() = rectExp.BottomRight(); 00277 else { 00278 rectObj.right = rectEx.right; 00279 rectObj.bottom -= rectObj.Height() / 2; 00280 } 00281 00282 m_lstConstraints.ShowWindow( ( m_bExpanded ) ? SW_SHOW : SW_HIDE ); 00283 m_lstErrors.ShowWindow( ( m_bExpanded ) ? SW_SHOW : SW_HIDE ); 00284 m_lstExpression.ShowWindow( ( m_bExpanded && m_tabPages.GetCurSel() == 0 ) ? SW_SHOW : SW_HIDE ); 00285 m_lstObjects.ShowWindow( ( ! m_bExpanded || m_tabPages.GetCurSel() == 1 ) ? SW_SHOW : SW_HIDE ); 00286 m_tabPages.ShowWindow( ( m_bExpanded ) ? SW_SHOW : SW_HIDE ); 00287 00288 int iYGap = rectCon.top - rectMes.bottom; 00289 int iTop = ( m_bExpanded ) ? rectCon.bottom + iYGap : rectObj.bottom + iYGap; 00290 00291 ScreenToClient( rectObj ); 00292 m_lstObjects.MoveWindow( rectObj ); 00293 00294 std::vector< CButton* > vecButtons; 00295 vecButtons.push_back( &m_btnNext ); vecButtons.push_back( &m_btnPrevious ); vecButtons.push_back( &m_btnClose ); vecButtons.push_back( &m_btnAbort ); 00296 for ( unsigned int i = 0 ; i < vecButtons.size() ; i++ ) { 00297 CRect rect; vecButtons[ i ]->GetWindowRect( rect ); 00298 int iHeight = rect.Height(); 00299 rect.top = iTop; 00300 rect.bottom = iTop + iHeight; 00301 ScreenToClient( rect ); 00302 vecButtons[ i ]->MoveWindow( rect ); 00303 } 00304 00305 CRect rectDlg; 00306 GetWindowRect( rectDlg ); 00307 CRect rectBtn; 00308 m_btnPrevious.GetWindowRect( rectBtn ); 00309 rectDlg.bottom = rectBtn.bottom + iYGap; 00310 MoveWindow( rectDlg ); 00311 00312 00313 00314 } 00315 00316 void CViolationDialog::OnClickNext() 00317 { 00318 SelectConstraint( true ); 00319 } 00320 00321 void CViolationDialog::OnClickPrevious() 00322 { 00323 SelectConstraint( false ); 00324 } 00325 00326 void CViolationDialog::OnKeyDownConstraints(NMHDR* pNMHDR, LRESULT* pResult) 00327 { 00328 LV_KEYDOWN* pLVKeyDown = (LV_KEYDOWN*)pNMHDR; 00329 if ( pLVKeyDown->wVKey == VK_UP ) 00330 SelectConstraint( false ); 00331 else 00332 if ( pLVKeyDown->wVKey == VK_DOWN ) 00333 SelectConstraint( true ); 00334 *pResult = 0; 00335 } 00336 00337 void CViolationDialog::OnClickConstraints(NMHDR* pNMHDR, LRESULT* pResult) 00338 { 00339 m_iSelected = min( max( m_lstConstraints.GetSelectionMark(), 0 ), m_lstConstraints.GetItemCount() - 1 ); 00340 RefreshWidgets( true ); 00341 *pResult = 0; 00342 } 00343 00344 void CViolationDialog::OnClickVariable(NMHDR* pNMHDR, LRESULT* pResult) 00345 { 00346 m_iSelectedVariable = min( max( m_lstObjects.GetSelectionMark(), 0 ), m_lstObjects.GetItemCount() - 1 ); 00347 GotoObject(); 00348 } 00349 00350 void CViolationDialog::OnClickErrors(NMHDR* pNMHDR, LRESULT* pResult) 00351 { 00352 m_iSelectedError = min( max( m_lstErrors.GetSelectionMark(), 0 ), m_lstErrors.GetItemCount() - 1 ); 00353 DisplayErrorItem(); 00354 } 00355 00356 void CViolationDialog::OnKeyDownErrors(NMHDR* pNMHDR, LRESULT* pResult) 00357 { 00358 LV_KEYDOWN* pLVKeyDown = (LV_KEYDOWN*)pNMHDR; 00359 if ( pLVKeyDown->wVKey == VK_UP ) 00360 SelectError( false ); 00361 else 00362 if ( pLVKeyDown->wVKey == VK_DOWN ) 00363 SelectError( true ); 00364 *pResult = 0; 00365 } 00366 00367 BOOL CViolationDialog::PreTranslateMessage( MSG* pMsg ) 00368 { 00369 return CDialog::PreTranslateMessage( pMsg ); 00370 } 00371 00372 void CViolationDialog::OnClickConstraintsColumn(NMHDR* pNMHDR, LRESULT* pResult) 00373 { 00374 NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; 00375 SortConstraints( pNMListView->iSubItem ); 00376 *pResult = 0; 00377 } 00378 00379 void CViolationDialog::RefreshWidgets( bool bNewConstraint ) 00380 { 00381 m_btnNext.EnableWindow( m_iSelected != m_lstConstraints.GetItemCount() - 1 ); 00382 m_btnPrevious.EnableWindow( m_iSelected != 0 ); 00383 if ( bNewConstraint ) { 00384 m_iSelectedConstraint = m_lstConstraints.GetItemData( m_iSelected ); 00385 m_lstConstraints.SetItemState( m_iSelected, LVIS_SELECTED, LVIS_SELECTED ); 00386 DisplayConstraintItem(); 00387 } 00388 } 00389 00390 void CViolationDialog::SelectConstraint( bool bNext ) 00391 { 00392 if ( ! bNext ) { 00393 if ( m_iSelected != 0 ) { 00394 m_iSelected--; 00395 RefreshWidgets( true ); 00396 } 00397 } 00398 else { 00399 if ( m_iSelected != m_lstConstraints.GetItemCount() - 1 ) { 00400 m_iSelected++; 00401 RefreshWidgets( true ); 00402 } 00403 } 00404 } 00405 00406 void CViolationDialog::SelectError( bool bNext ) 00407 { 00408 if ( ! bNext ) { 00409 if ( m_iSelectedError != 0 ) { 00410 m_iSelectedError--; 00411 DisplayErrorItem(); 00412 } 00413 } 00414 else { 00415 if ( m_iSelectedError != m_lstErrors.GetItemCount() - 1 ) { 00416 m_iSelectedError++; 00417 DisplayErrorItem(); 00418 } 00419 } 00420 } 00421 00422 bool CViolationDialog::IsExpanded() const 00423 { 00424 return m_bExpanded; 00425 } 00426 00427 void CViolationDialog::AddItem( const EvaluationRecord& item ) 00428 { 00429 m_vecRecords.push_back( item ); 00430 // ?? 00431 COMTRY 00432 { 00433 OclTree::Violation vi = item.vecViolations[ item.vecViolations.size()-1 ]; // which violation ? 00434 CComPtr<IUnknown> logfco = vi.vecObjectsPtr[0]; // self needed 00435 CComPtr<IMgaFCO> fco; 00436 COMTRY 00437 { 00438 COMTHROW(logfco.QueryInterface(&fco)); 00439 CComBSTR bstr, id, nm; 00440 COMTHROW( fco->get_ID( &id)); 00441 COMTHROW( fco->get_Name( &nm)); 00442 COMTHROW(bstr.Append(_T("Constraint Violation: <A HREF=\"mga:"))); 00443 COMTHROW(bstr.AppendBSTR( id)); 00444 COMTHROW(bstr.Append(_T("\">"))); 00445 COMTHROW(bstr.AppendBSTR( nm)); 00446 COMTHROW(bstr.Append(_T("</A>: "))); 00447 COMTHROW(bstr.Append(OclCommonEx::Convert(item.spConstraint.Ptr()->GetMessage()))); 00448 if (m_oleapp) 00449 COMTHROW(m_oleapp->ConsoleMessage(bstr, MSG_ERROR)); 00450 } 00451 catch(hresult_exception &)// in case the constraint is not attached to any fco in the metamodel 00452 { // the constraint becomes project scoped, thus QueryInterface fails 00453 CComBSTR bstr; 00454 bstr.Append(_T("Constraint ")); 00455 bstr.Append(OclCommonEx::Convert(item.spConstraint.Ptr()->GetFullName())); // FIXME suspect 00456 bstr.Append(_T(" Violated! Description: \"")); 00457 bstr.Append(OclCommonEx::Convert(item.spConstraint.Ptr()->GetMessage())); // FIXME suspect 00458 bstr.Append(_T("\".")); 00459 if (m_oleapp) 00460 COMTHROW(m_oleapp->ConsoleMessage(bstr, MSG_ERROR)); 00461 } 00462 } 00463 catch(hresult_exception &) 00464 { 00465 } 00466 } 00467 00468 void CViolationDialog::EnableAbort() 00469 { 00470 m_bAbort = true; 00471 } 00472 00473 void CViolationDialog::EnableOK() 00474 { 00475 m_bOK = true; 00476 } 00477 00478 void CViolationDialog::DisplayErrorItem() 00479 { 00480 // Set Line in Expression 00481 00482 m_lstErrors.SetItemState( m_iSelectedError, LVIS_SELECTED, LVIS_SELECTED ); 00483 00484 OclTree::Violation vi = m_vecRecords[ m_iSelectedConstraint ].vecViolations[ m_iSelectedError ]; 00485 int iLine = vi.position.iLine; 00486 00487 for ( unsigned int i = 0 ; i < (unsigned int) m_lstExpression.GetItemCount() ; i++ ) { 00488 LVITEM lvItem; 00489 DWORD lparam = m_lstExpression.GetItemData(i); 00490 lvItem.mask = LVIF_IMAGE | LVIF_STATE; 00491 lvItem.state = ( lparam + 1 == (unsigned int) iLine ) ? LVIS_SELECTED : 0; 00492 lvItem.stateMask = LVIS_SELECTED; 00493 lvItem.iItem = i; 00494 lvItem.iSubItem = 0; 00495 lvItem.iImage = ( lparam + 1 == (unsigned int) iLine ) ? 1 : 0; 00496 m_lstExpression.SetItem( &lvItem ); 00497 if ( lparam + 1 == (unsigned int) iLine ) 00498 m_lstExpression.EnsureVisible( i, false ); 00499 } 00500 00501 // Add Objects 00502 00503 m_lstObjects.DeleteAllItems(); 00504 00505 for ( unsigned int i = 0 ; i < vi.vecVariables.size() ; i++ ) { 00506 00507 // Add Variable 00508 00509 LVITEM lvItem; 00510 lvItem.mask = /*LVIF_NORECOMPUTE |*/ LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM; 00511 lvItem.iItem = m_lstObjects.GetItemCount(); 00512 lvItem.iSubItem = 0; 00513 lvItem.iImage = 0; 00514 lvItem.lParam = i; 00515 CString strTemp = OclCommonEx::Convert( vi.vecVariables[ i ] ); 00516 lvItem.pszText = (TCHAR*)(LPCTSTR)strTemp;//.GetBuffer( strTemp.GetLength() ); 00517 m_lstObjects.InsertItem( &lvItem ); 00518 00519 // strTemp.ReleaseBuffer(); 00520 strTemp.Empty(); 00521 00522 // Add Object 00523 00524 lvItem.mask = LVIF_TEXT; 00525 lvItem.iSubItem = 1; 00526 strTemp = OclCommonEx::Convert( vi.vecObjects[ i ] ); 00527 lvItem.pszText = (TCHAR*)(LPCTSTR)strTemp; //.GetBuffer( strTemp.GetLength() ); 00528 m_lstObjects.SetItem( &lvItem ); 00529 00530 // strTemp.ReleaseBuffer(); 00531 } 00532 00533 // m_lstObjects.SetColumnWidth( 0, LVSCW_AUTOSIZE_USEHEADER ); 00534 m_lstObjects.SetColumnWidth( 0, 70); 00535 m_lstObjects.SetColumnWidth( 1, LVSCW_AUTOSIZE_USEHEADER ); 00536 m_lstObjects.GetParent()->Invalidate(); 00537 } 00538 00539 void CViolationDialog::addFunctions() 00540 { 00541 CStringArray arrText; 00542 OclGmeCM::FuncDesc::iterator it; 00543 for (it = m_vecRecords[ m_iSelectedConstraint ].calledFunctions.begin(); 00544 it != m_vecRecords[ m_iSelectedConstraint ].calledFunctions.end(); ++it) 00545 { 00546 arrText.RemoveAll(); 00547 int serial = it->second.serial; 00548 CString strExpression = OclCommonEx::Convert(it->second.text); 00549 strExpression.Replace( _T("\r"), _T("") ); 00550 strExpression.Replace( _T("\n"), _T("\r\n") ); 00551 strExpression.Replace( _T("\t"), _T(" ") ); 00552 int iFPos = 0; 00553 do { 00554 iFPos = strExpression.Find( _T("\r\n") ); 00555 if ( iFPos == -1 ) 00556 arrText.Add( strExpression ); 00557 else { 00558 arrText.Add( strExpression.Left( iFPos ) ); 00559 strExpression = strExpression.Right( strExpression.GetLength() - iFPos - 2 ); 00560 } 00561 } while ( iFPos != -1 ); 00562 00563 // Add Expression 00564 00565 LVITEM lvItem; 00566 for ( int i = 0 ; i < arrText.GetSize() ; i++ ) { 00567 00568 // Add Line 00569 00570 lvItem.mask = LVIF_PARAM | LVIF_IMAGE | /*LVIF_NORECOMPUTE |*/ LVIF_TEXT; 00571 lvItem.iItem = m_lstExpression.GetItemCount(); 00572 lvItem.iSubItem = 0; 00573 lvItem.iImage = 0; 00574 lvItem.lParam = it->second.serial*1000 +i; 00575 CString strTemp; 00576 strTemp.Format( _T("%d"), it->second.serial*1000 + i + 1 ); 00577 lvItem.pszText = (TCHAR*)(LPCTSTR)strTemp; //.GetBuffer( strTemp.GetLength() ); 00578 m_lstExpression.InsertItem( &lvItem ); 00579 00580 // strTemp.ReleaseBuffer(); 00581 strTemp.Empty(); 00582 00583 // Add ExpressionPiece 00584 00585 lvItem.mask = LVIF_TEXT; 00586 lvItem.iSubItem = 1; 00587 strTemp = arrText.GetAt( i ); 00588 lvItem.pszText = (TCHAR*)(LPCTSTR)strTemp; //.GetBuffer( strTemp.GetLength() ); 00589 m_lstExpression.SetItem( &lvItem ); 00590 00591 // strTemp.ReleaseBuffer(); 00592 } 00593 } 00594 } 00595 00596 void CViolationDialog::DisplayConstraintItem() 00597 { 00598 // Set Constraint Name 00599 00600 m_lblConstraint.SetWindowText( OclCommonEx::Convert( m_vecRecords[ m_iSelectedConstraint ].spConstraint->GetDefinedName() ) ); 00601 00602 // Set Constraint Text 00603 00604 m_lstExpression.DeleteAllItems(); 00605 00606 CStringArray arrText; 00607 CString strExpression = OclCommonEx::Convert( m_vecRecords[ m_iSelectedConstraint ].spConstraint->GetText() ); 00608 strExpression.Replace( _T("\r"), _T("") ); 00609 strExpression.Replace( _T("\n"), _T("\r\n") ); 00610 strExpression.Replace( _T("\t"), _T(" ") ); 00611 int iFPos = 0; 00612 do { 00613 iFPos = strExpression.Find( _T("\r\n") ); 00614 if ( iFPos == -1 ) 00615 arrText.Add( strExpression ); 00616 else { 00617 arrText.Add( strExpression.Left( iFPos ) ); 00618 strExpression = strExpression.Right( strExpression.GetLength() - iFPos - 2 ); 00619 } 00620 } while ( iFPos != -1 ); 00621 00622 // Add Expression 00623 00624 LVITEM lvItem; 00625 for ( unsigned int i = 0 ; i < (unsigned int) arrText.GetSize() ; i++ ) { 00626 00627 // Add Line 00628 00629 lvItem.mask = LVIF_PARAM | LVIF_IMAGE | /*LVIF_NORECOMPUTE |*/ LVIF_TEXT; 00630 lvItem.iItem = m_lstExpression.GetItemCount(); 00631 lvItem.iSubItem = 0; 00632 lvItem.iImage = 0; 00633 lvItem.lParam = i; 00634 CString strTemp; 00635 strTemp.Format( _T("%d"), i + 1 ); 00636 lvItem.pszText = (TCHAR*)(LPCTSTR)strTemp; // .GetBuffer( strTemp.GetLength() ); 00637 m_lstExpression.InsertItem( &lvItem ); 00638 00639 // strTemp.ReleaseBuffer(); 00640 strTemp.Empty(); 00641 00642 // Add ExpressionPiece 00643 00644 lvItem.mask = LVIF_TEXT; 00645 lvItem.iSubItem = 1; 00646 strTemp = arrText.GetAt( i ); 00647 lvItem.pszText = (TCHAR*)(LPCTSTR)strTemp; // .GetBuffer( strTemp.GetLength() ); 00648 m_lstExpression.SetItem( &lvItem ); 00649 00650 // strTemp.ReleaseBuffer(); 00651 } 00652 00653 addFunctions(); 00654 00655 // m_lstExpression.SetColumnWidth( 0, LVSCW_AUTOSIZE_USEHEADER ); 00656 m_lstExpression.SetColumnWidth( 0, 50); 00657 m_lstExpression.SetColumnWidth( 1, LVSCW_AUTOSIZE_USEHEADER ); 00658 m_lstExpression.SetWindowPos( &wndTop, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE ); 00659 00660 // Add Errors 00661 00662 m_lstErrors.DeleteAllItems(); 00663 00664 OclTree::ViolationVector vecViolations = m_vecRecords[ m_iSelectedConstraint ].vecViolations; 00665 00666 for ( unsigned int i = 0 ; i < vecViolations.size() ; i++ ) { 00667 OclTree::Violation vi = vecViolations[ i ]; 00668 00669 // Add Line 00670 00671 lvItem.mask = LVIF_IMAGE | /*LVIF_NORECOMPUTE |*/ LVIF_TEXT; 00672 if ( i == 0 ) { 00673 lvItem.mask = lvItem.mask | LVIF_STATE; 00674 lvItem.state = LVIS_SELECTED; 00675 } 00676 lvItem.iItem = m_lstErrors.GetItemCount(); 00677 lvItem.iSubItem = 0; 00678 lvItem.iImage = ( vi.bIsException ) ? 2 : 3; 00679 lvItem.lParam = i; 00680 CString strTemp; 00681 if ( vi.position.iLine < 0 ) 00682 strTemp = _T("?"); 00683 else 00684 strTemp.Format( _T("%d"), vi.position.iLine ); 00685 lvItem.pszText = (TCHAR*)(LPCTSTR)strTemp; //.GetBuffer( strTemp.GetLength() ); 00686 m_lstErrors.InsertItem( &lvItem ); 00687 00688 // strTemp.ReleaseBuffer(); 00689 strTemp.Empty(); 00690 00691 // Add Column 00692 00693 /* 00694 // This column is commented out because this features is not implemented yet 00695 // Be careful with uncommenting -> column and subitem numbers 00696 00697 lvItem.mask = LVIF_TEXT; 00698 lvItem.iSubItem = 1; 00699 strTemp.Format( "%d", vi.position.iColumn ); 00700 lvItem.pszText = (TCHAR*)(LPCTSTR)strTemp; //.GetBuffer( strTemp.GetLength() ); 00701 m_lstErrors.SetItem( &lvItem ); 00702 00703 // strTemp.ReleaseBuffer(); 00704 strTemp.Empty(); 00705 */ 00706 00707 // Add Message 00708 00709 lvItem.mask = LVIF_TEXT; 00710 lvItem.iSubItem = 1; 00711 strTemp = OclCommonEx::Convert( vi.strMessage ); 00712 lvItem.pszText = (TCHAR*)(LPCTSTR)strTemp; // .GetBuffer( strTemp.GetLength() ); 00713 m_lstErrors.SetItem( &lvItem ); 00714 00715 // strTemp.ReleaseBuffer(); 00716 strTemp.Empty(); 00717 00718 // Add Signature 00719 00720 lvItem.iSubItem = 2; 00721 strTemp = OclCommonEx::Convert( vi.strSignature ); 00722 lvItem.pszText = (TCHAR*)(LPCTSTR)strTemp; // .GetBuffer( strTemp.GetLength() ); 00723 m_lstErrors.SetItem( &lvItem ); 00724 00725 // strTemp.ReleaseBuffer(); 00726 } 00727 00728 m_lstErrors.SetColumnWidth( 0, LVSCW_AUTOSIZE_USEHEADER ); 00729 m_lstErrors.SetColumnWidth( 1, LVSCW_AUTOSIZE_USEHEADER ); 00730 m_lstErrors.SetColumnWidth( 2, LVSCW_AUTOSIZE_USEHEADER ); 00731 00732 /* 00733 // This column is commented out because this features is not implemented yet 00734 // Be careful with uncommenting -> column numbers 00735 00736 m_lstErrors.SetColumnWidth( 3, LVSCW_AUTOSIZE_USEHEADER ); 00737 */ 00738 00739 // Add Constraint Message 00740 00741 m_lblGeneralMessage.SetWindowText( OclCommonEx::Convert( m_vecRecords[ m_iSelectedConstraint ].spConstraint->GetMessage() ) ); 00742 00743 if ( vecViolations.empty() ) 00744 ASSERT( 0 ); 00745 else { 00746 m_iSelectedError = 0; 00747 DisplayErrorItem(); 00748 } 00749 } 00750 00751 void CViolationDialog::SortConstraints( int iColumn ) 00752 { 00753 SortStruct sortInfo; 00754 sortInfo.pDialog = this; 00755 sortInfo.iColumn = iColumn; 00756 m_lstConstraints.SortItems( CViolationDialog::CompareConstraint, ( LPARAM ) ( &sortInfo ) ); 00757 00758 for ( int i = 0 ; i < m_lstConstraints.GetItemCount() ; i++ ) 00759 if ( m_lstConstraints.GetItemData( i ) == (unsigned int) m_iSelectedConstraint ) { 00760 m_iSelected = i; 00761 RefreshWidgets( false ); 00762 return; 00763 } 00764 } 00765 00766 int CALLBACK CViolationDialog::CompareConstraint( LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort ) 00767 { 00768 SortStruct* pSortInfo = ( SortStruct* ) lParamSort; 00769 00770 OclGme::SpConstraint spConstraint1 = pSortInfo->pDialog->m_vecRecords[ lParam1 ].spConstraint; 00771 OclGme::SpConstraint spConstraint2 = pSortInfo->pDialog->m_vecRecords[ lParam2 ].spConstraint; 00772 00773 if ( pSortInfo->iColumn == 0 ) { 00774 int iType1 = spConstraint1->GetType(); 00775 int iType2 = spConstraint2->GetType(); 00776 return ( iType1 < iType2 ) ? -1 : ( iType1 > iType2 ) ? 1 : 0; 00777 } 00778 CString str1 = OclCommonEx::Convert( ( pSortInfo->iColumn == 1 ) ? spConstraint1->GetContextType() : spConstraint1->GetName() ); 00779 CString str2 = OclCommonEx::Convert( ( pSortInfo->iColumn == 1 ) ? spConstraint2->GetContextType() : spConstraint2->GetName() ); 00780 return _tcscmp( str1, str2 ); 00781 } 00782 00783 void CViolationDialog::GotoObject() 00784 { 00785 DWORD lparam = m_lstObjects.GetItemData(m_iSelectedVariable); 00786 OclTree::Violation vi = m_vecRecords[ m_iSelectedConstraint ].vecViolations[ m_iSelectedError ]; 00787 m_gotopunk = vi.vecObjectsPtr[lparam]; 00788 if (m_gotopunk) 00789 CDialog::OnOK(); 00790 } 00791 00792 00793 }; // namespace OclGmeCM 00794 00795 00796