GME  13
GMEConstraintBrowserDialog.cpp
Go to the documentation of this file.
00001 //###############################################################################################################################################
00002 //
00003 //      Object Constraint Language Generic Manager
00004 //      GMEConstraintBrowserDialog.cpp
00005 //
00006 //###############################################################################################################################################
00007 
00008 #include "stdafx.h"
00009 #include "constraintmanager.h"
00010 #include "GMEConstraintBrowserDialog.h"
00011 #include "OCLGMECMFacade.h"
00012 #include "GMEConstraintPropertiesDialog.h"
00013 #include "GMESmallMessageBox.h"
00014 #include "OCLObjectExGME.h"
00015 
00016 #ifdef _DEBUG
00017 #define new DEBUG_NEW
00018 #undef THIS_FILE
00019 static char THIS_FILE[] = __FILE__;
00020 #endif
00021 
00022 #define NILNAMESPACE ""
00023 namespace OclGmeCM {
00024 
00025 //##############################################################################################################################################
00026 //
00027 //      C L A S S : CConstraintBrowserDialog <<< + CDialog
00028 //
00029 //##############################################################################################################################################
00030 
00031 CConstraintBrowserDialog::CConstraintBrowserDialog( Facade* pFacade, CComPtr<IMgaObject> spObject, CComPtr<IMgaObjects> spObjects, CWnd* pParent )
00032         : CDialog( CConstraintBrowserDialog::IDD, pParent ), m_pFacade( pFacade ), m_spObject( spObject ), m_spObjects( spObjects ), m_eKindActiveTree( CConstraintTreeCtrl::TK_CONSTRAINT ), m_bLoaded( false )
00033 {
00034         //{{AFX_DATA_INIT(CConstraintBrowserDialog)
00035         //}}AFX_DATA_INIT
00036 }
00037 
00038 CConstraintBrowserDialog::~CConstraintBrowserDialog()
00039 {
00040 }
00041 
00042 void CConstraintBrowserDialog::DoDataExchange(CDataExchange* pDX)
00043 {
00044         CDialog::DoDataExchange(pDX);
00045         //{{AFX_DATA_MAP(CConstraintBrowserDialog)
00046         DDX_Control(pDX, BRW_BTNLOAD, m_btnLoad);
00047         DDX_Control(pDX, BRW_BTNAPPLY, m_btnApply);
00048         DDX_Control(pDX, BRW_TABENABLES, m_tabTrees);
00049         DDX_Control(pDX, BRW_BTNREMOVE, m_btnRemove);
00050         DDX_Control(pDX, BRW_BTNOK, m_btnOK);
00051         DDX_Control(pDX, BRW_BTNCHECK, m_btnCheck);
00052         DDX_Control(pDX, BRW_BTNCANCEL, m_btnCancel);
00053         DDX_Control(pDX, BRW_BTNADD, m_btnAdd);
00054         //}}AFX_DATA_MAP
00055 }
00056 
00057 
00058 BEGIN_MESSAGE_MAP(CConstraintBrowserDialog, CDialog)
00059         //{{AFX_MSG_MAP(CConstraintBrowserDialog)
00060         ON_BN_CLICKED(BRW_BTNADD, OnClickAdd)
00061         ON_BN_CLICKED(BRW_BTNCANCEL, OnClickCancel)
00062         ON_BN_CLICKED(BRW_BTNCHECK, OnClickCheck)
00063         ON_BN_CLICKED(BRW_BTNOK, OnClickOK)
00064         ON_BN_CLICKED(BRW_BTNREMOVE, OnClickRemove)
00065         ON_NOTIFY(TCN_SELCHANGE, BRW_TABENABLES, OnSelectionChangedTab)
00066         ON_BN_CLICKED(BRW_BTNAPPLY, OnClickApply)
00067         ON_BN_CLICKED(BRW_BTNLOAD, OnClickLoad)
00068         //}}AFX_MSG_MAP
00069         ON_NOTIFY( TVN_ITEMEXPANDING, BRW_TREEOBJECTS, OnItemExpanding )
00070         ON_NOTIFY( CTVN_CHECKCHANGED, BRW_TREEOBJECTS, OnCheckChanged )
00071         ON_NOTIFY( CTVN_CHECKCHANGEDREC, BRW_TREEOBJECTS, OnCheckChangedRecursive )
00072         ON_NOTIFY( CTVN_SHOWITEM, BRW_TREECONSTRAINTS, OnShowItem )
00073         ON_NOTIFY( TVN_SELCHANGED, BRW_TREECONSTRAINTS, OnSelectionChangedTreeConstraints )
00074         ON_NOTIFY( TVN_SELCHANGED, BRW_TREEOBJECTS, OnSelectionChangedTreeObjects )
00075 END_MESSAGE_MAP()
00076 
00077 
00078 
00079 
00080 
00081 
00082 
00083 BOOL CConstraintBrowserDialog::OnInitDialog()
00084 {
00085         CDialog::OnInitDialog();
00086 
00087         CWaitCursor crsrWait;
00088 
00089         // Fill ImageLists
00090 
00091         m_lstObjectImages.Create( 16, 16, ILC_COLOR24 | ILC_MASK, 28, 28 );
00092         CBitmap bmp;
00093         bmp.LoadBitmap( IDB_TREEICONS );
00094         m_lstObjectImages.Add( &bmp, RGB( 255, 0, 255 ) );
00095 
00096         m_lstStateImages.Create( 16, 16, ILC_COLOR4 | ILC_MASK, 6, 6 );
00097         CBitmap bmp2;
00098         bmp2.LoadBitmap( IDB_CHECKICONS );
00099         m_lstStateImages.Add( &bmp2, RGB( 255, 255, 255 ) );
00100 
00101         m_lstCStateImages.Create( 16, 16, ILC_COLOR4 | ILC_MASK, 6, 6 );
00102         CBitmap bmp3;
00103         bmp3.LoadBitmap( IDB_CONSTRAINTSTATEICONS );
00104         m_lstCStateImages.Add( &bmp3, RGB( 255, 255, 255 ) );
00105 
00106         // Create Tabs
00107 
00108         m_tabTrees.InsertItem(  0, _T("Constraints") );
00109         m_tabTrees.InsertItem(  1, _T("Kinds and Types") );
00110         m_tabTrees.InsertItem(  2, _T("Settings") );
00111 
00112         m_pageSettings.Create( IDD_BROWSER_SETTINGS_PAGE, &m_tabTrees );
00113         PlaceWindow( m_pageSettings );
00114 
00115         // Create Constraint and Object Trees
00116 
00117         DWORD dwStyleTree = WS_VISIBLE | WS_TABSTOP | WS_CHILD | WS_BORDER | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_HASLINES /*TVS_FULLROWSELECT*/ | TVS_DISABLEDRAGDROP | TVS_SHOWSELALWAYS | WS_EX_CLIENTEDGE;
00118         CRect rect;
00119         m_treeConstraints.Create( dwStyleTree, rect, &m_tabTrees, BRW_TREECONSTRAINTS );
00120         m_treeConstraints.SetImageList( &m_lstObjectImages, TVSIL_NORMAL );
00121         m_treeConstraints.SetImageList( &m_lstCStateImages, TVSIL_STATE );
00122         m_treeConstraints.SetKind( CConstraintTreeCtrl::TK_CONSTRAINT );
00123         PlaceWindow( m_treeConstraints, 10 );
00124 
00125         m_treeObjects.Create( dwStyleTree, rect, &m_tabTrees, BRW_TREEOBJECTS );
00126         m_treeObjects.SetImageList( &m_lstObjectImages, TVSIL_NORMAL );
00127         m_treeObjects.SetImageList( &m_lstStateImages, TVSIL_STATE );
00128         m_treeObjects.SetKind( CConstraintTreeCtrl::TK_OBJECT );
00129         PlaceWindow( m_treeObjects, 10 );
00130 
00131         // Set Tab specific things
00132 
00133         SetView( ( ! m_spObject.p && ! m_spObjects.p ) ? CConstraintTreeCtrl::TK_CONSTRAINT : CConstraintTreeCtrl::TK_OBJECT );
00134         m_tabTrees.SetCurSel( ( m_spObject.p || m_spObjects.p ) ? 1 : 0 );
00135 
00136         LoadSettings();
00137         LoadConstraints();
00138         LoadKinds();
00139 
00140         crsrWait.Restore();
00141 
00142         return TRUE;
00143 }
00144 
00145 void CConstraintBrowserDialog::PlaceWindow( CWnd& window, int iGap )
00146 {
00147         CRect rectTab;
00148         m_tabTrees.GetWindowRect( rectTab );
00149         m_tabTrees.ScreenToClient( rectTab );
00150         CRect rectItem;
00151         m_tabTrees.GetItemRect( 0, rectItem );
00152 
00153         CRect rect;
00154         window.GetWindowRect( rect );
00155         m_tabTrees.ScreenToClient( rect );
00156 
00157         int iXGap = ( iGap != -1 ) ? iGap : ( rectTab.Width() - rect.Width() ) / 2;
00158         int iYGap = ( iGap != -1 ) ? iGap : ( rectTab.Height() - rectItem.Height() - rect.Height() ) / 2;
00159 
00160         rect.left = iXGap;
00161         rect.right = rectTab.Width() - iXGap;
00162         rect.top = rectItem.Height() + iYGap;
00163         rect.bottom = rectTab.Height() - iYGap;
00164 
00165         window.MoveWindow( rect );
00166 }
00167 
00168 void CConstraintBrowserDialog::OnClickAdd()
00169 {
00170         CConstraintPropertiesDialog dlgProperties( this, NULL );
00171         if ( dlgProperties.DoModal() == IDOK ) {
00172                 InsertConstraint( dlgProperties.m_spConstraintOut );
00173                 m_btnApply.EnableWindow( true );
00174                 m_treeConstraints.SortItemChildren( TVI_ROOT );
00175         }
00176 }
00177 
00178 void CConstraintBrowserDialog::OnClickCancel()
00179 {
00180         CDialog::OnCancel();
00181 }
00182 
00183 void CConstraintBrowserDialog::OnClickCheck()
00184 {
00185         EvaluationRecordVector vecRecords;
00186 
00187         AfxGetApp()->DoWaitCursor( 1 );
00188 
00189         if ( m_eKindActiveTree == CConstraintTreeCtrl::TK_CONSTRAINT ) {
00190                 for ( HTREEITEM hCItem = m_treeConstraints.GetRootItem(); hCItem != NULL ; hCItem = m_treeConstraints.GetNextSiblingItem( hCItem ) ) {
00191                         BOOL bSelected = m_treeConstraints.GetItemState( hCItem, TVIS_SELECTED ) & TVIS_SELECTED;
00192                         if ( bSelected ) {
00193                                 ConstraintMap::iterator it = m_mapConstraint.find( ( HTREEITEM ) m_treeConstraints.GetItemData( hCItem ) );
00194                                 OclGme::SpConstraint spConstraint = (*it).second;
00195                                 if ( spConstraint->IsValid() ) {
00196                                         OclCommonEx::ObjectVector vecObjects;
00197                                         OclCommonEx::GetKindObjects( m_pFacade->GetProject(), spConstraint->GetContextType().substr( 6 ), vecObjects );
00198                                         for ( unsigned int i = 0 ; i < vecObjects.size() ; i++ ) {
00199                                                 OclGme::Constraint::EnableInfo eInfo = spConstraint->GetEnableInfo( vecObjects[ i ].p );
00200                                                 if ( eInfo > OclGme::Constraint::CE_NONE && eInfo <= OclGme::Constraint::CE_ENABLED_READONLY ) {
00201                                                         EvaluationRecord item;
00202                                                         item.spObject = CREATE_GMEOBJECT( m_pFacade->GetTreeManager()->GetTypeManager(), vecObjects[ i ].p );
00203                                                         item.spConstraint = spConstraint;
00204                                                         vecRecords.push_back( item );
00205                                                 }
00206                                         }
00207                                 }
00208                         }
00209                 }
00210         }
00211         else {
00212                 for ( HandlerSet::iterator it = m_setSelecteds.begin() ; it != m_setSelecteds.end() ; ++it ) {
00213                         EvaluationRecord item;
00214 
00215                         HTREEITEM hParent = m_treeObjects.GetParentItem( *it );
00216                         MapH2ID::iterator idit = m_mapH2ID.find( ( HTREEITEM ) m_treeObjects.GetItemData( hParent ) );
00217                         std::string strOID = (*idit).second;
00218                         CComPtr<IMgaObject> spObject;
00219                         COMTHROW( m_pFacade->GetProject()->GetObjectByID( CComBSTR( OclCommonEx::Convert( (*idit).second ) ), &spObject ) );
00220                         item.spObject = CREATE_GMEOBJECT( m_pFacade->GetTreeManager()->GetTypeManager(), spObject );
00221 
00222                         std::string strCID = OclCommonEx::Convert( m_treeObjects.GetItemText( *it ) );
00223                         for ( ConstraintMap::iterator cit = m_mapConstraint.begin() ; cit != m_mapConstraint.end() ; ++cit ) {
00224                                 if ( (*cit).second->GetFullName() == strCID ) {
00225                                         item.spConstraint = (*cit).second;
00226                                         break;
00227                                 }
00228                         }
00229 
00230                         OclGme::Constraint::EnableInfo eInfo = item.spConstraint->GetEnableInfo( spObject );
00231                         if ( eInfo > OclGme::Constraint::CE_NONE && eInfo <= OclGme::Constraint::CE_ENABLED_READONLY )
00232                                 vecRecords.push_back( item );
00233                 }
00234         }
00235 
00236         AfxGetApp()->DoWaitCursor( -1 );
00237 
00238         m_pFacade->EvaluateConstraints( vecRecords, true,  &m_gotoPunk);
00239          // ?? !! gotoPunk
00240         if (m_gotoPunk)
00241         {
00242                 ApplyChanges();
00243                 CDialog::OnOK();
00244         }
00245 }
00246 
00247 void CConstraintBrowserDialog::OnClickOK()
00248 {
00249         ApplyChanges();
00250         CDialog::OnOK();
00251 }
00252 
00253 void CConstraintBrowserDialog::OnClickApply()
00254 {
00255         ApplyChanges();
00256 
00257         COMTHROW( m_pFacade->GetProject()->CommitTransaction() );
00258         CComPtr<IMgaTerritory> spTerritory;
00259         COMTHROW( m_pFacade->GetProject()->CreateTerritory( NULL, &spTerritory ) );
00260         COMTHROW( m_pFacade->GetProject()->BeginTransaction( spTerritory, TRANSACTION_GENERAL));
00261         m_btnApply.EnableWindow( false );
00262 }
00263 
00264 
00265 void CConstraintBrowserDialog::OnClickRemove()
00266 {
00267         if ( m_eKindActiveTree == CConstraintTreeCtrl::TK_CONSTRAINT ) {
00268                 for ( HTREEITEM hCItem = m_treeConstraints.GetRootItem(); hCItem != NULL ; hCItem = m_treeConstraints.GetNextSiblingItem( hCItem ) ) {
00269                         BOOL bSelected = m_treeConstraints.GetItemState( hCItem, TVIS_SELECTED ) & TVIS_SELECTED;
00270                         if ( bSelected ) {
00271                                 ConstraintMap::iterator it = m_mapConstraint.find( ( HTREEITEM ) m_treeConstraints.GetItemData( hCItem ) );
00272                                 RemoveConstraint( (*it).second );
00273                         }
00274                 }
00275         }
00276 }
00277 
00278 void CConstraintBrowserDialog::OnClickLoad()
00279 {
00280         CWaitCursor crsrWait;
00281 
00282         m_bLoaded = true;
00283         for ( HTREEITEM hKItem = m_treeObjects.GetChildItem( TVI_ROOT ) ; hKItem != NULL ; hKItem = m_treeObjects.GetNextSiblingItem( hKItem ) )
00284                 ExpandKind( OclCommonEx::Convert( m_treeObjects.GetItemText( hKItem ) ), hKItem );
00285         m_btnLoad.EnableWindow( false );
00286 
00287         crsrWait.Restore();
00288 }
00289 
00290 void CConstraintBrowserDialog::OnSelectionChangedTab( NMHDR* pNMHDR, LRESULT* pResult )
00291 {
00292         if ( m_tabTrees.GetCurSel() == 0 )
00293                 SetView( CConstraintTreeCtrl::TK_CONSTRAINT );
00294         else
00295                 if ( m_tabTrees.GetCurSel() == 1 )
00296                         SetView( CConstraintTreeCtrl::TK_OBJECT );
00297                 else
00298                         SetView( CConstraintTreeCtrl::TK_UNKNOWN );
00299         *pResult = 0;
00300 }
00301 
00302 void CConstraintBrowserDialog::OnItemExpanding( NMHDR* pNMHDR, LRESULT* pResult )
00303 {
00304         NM_TREEVIEW* pNMTV = (NM_TREEVIEW*) pNMHDR;
00305         if ( m_eKindActiveTree == CConstraintTreeCtrl::TK_OBJECT ) {
00306                 int iImNum, iImNumS;
00307                 m_treeObjects.GetItemImage( pNMTV->itemNew.hItem, iImNum, iImNum );
00308                 if ( iImNum > 8 ) {
00309                         iImNumS = m_treeObjects.GETSTATE( pNMTV->itemNew.hItem );
00310                         if ( iImNumS == NS_UNKNOWN ) {
00311                                 MapH2ID::iterator it = m_mapH2ID.find( (HTREEITEM) m_treeObjects.GetItemData( pNMTV->itemNew.hItem ) );
00312                                 ExpandKind( (*it).second, (*it).first );
00313                         }
00314                 }
00315         }
00316         *pResult = 0;
00317 }
00318 
00319 void CConstraintBrowserDialog::OnCheckChanged( NMHDR* pNMHDR, LRESULT* pResult )
00320 {
00321         NM_TREEVIEW* pNMTV = (NM_TREEVIEW*)pNMHDR;
00322         if ( m_eKindActiveTree == CConstraintTreeCtrl::TK_OBJECT ) {
00323                 int iImNumS = m_treeObjects.GETSTATE( pNMTV->itemNew.hItem );
00324                 int iImNewS = ( iImNumS == NS_UNCHECKED || iImNumS == NS_UNCHECKED_INHERITED || iImNumS == NS_MISCELLANEOUS ) ? NS_CHECKED : NS_UNCHECKED;
00325                 SetNewState( pNMTV->itemNew.hItem, iImNewS, false );
00326         }
00327         m_btnApply.EnableWindow( true );
00328 }
00329 
00330 void CConstraintBrowserDialog::OnCheckChangedRecursive( NMHDR* pNMHDR, LRESULT* pResult )
00331 {
00332         NM_TREEVIEW* pNMTV = (NM_TREEVIEW*)pNMHDR;
00333         if ( m_eKindActiveTree == CConstraintTreeCtrl::TK_OBJECT ) {
00334                 int iImNumS = m_treeObjects.GETSTATE( pNMTV->itemNew.hItem );
00335                 int iImNewS = ( iImNumS == NS_UNCHECKED || iImNumS == NS_UNCHECKED_INHERITED || iImNumS == NS_MISCELLANEOUS ) ? NS_CHECKED : NS_UNCHECKED;
00336                 SetNewState( pNMTV->itemNew.hItem, iImNewS, true );
00337         }
00338         m_btnApply.EnableWindow( true );
00339 }
00340 
00341 void CConstraintBrowserDialog::OnShowItem( NMHDR* pNMHDR, LRESULT* pResult )
00342 {
00343         NM_TREEVIEW* pNMTV = (NM_TREEVIEW*) pNMHDR;
00344         ConstraintMap::iterator it = m_mapConstraint.find( ( HTREEITEM ) m_treeConstraints.GetItemData( pNMTV->itemNew.hItem ) );
00345         if ( it != m_mapConstraint.end() ) {
00346                 CConstraintPropertiesDialog dlgProperties( this, (*it).second );
00347                 if ( dlgProperties.DoModal() == IDOK && (*it).second->GetLocation() == OclGme::ConstraintBase::CL_PROJECT ) {
00348                         RemoveConstraint( (*it).second, false );
00349                         InsertConstraint( dlgProperties.m_spConstraintOut );
00350                         m_btnApply.EnableWindow( true );
00351                         m_treeConstraints.SortItemChildren( TVI_ROOT );
00352                 }
00353         }
00354 }
00355 
00356 void CConstraintBrowserDialog::OnSelectionChangedTreeConstraints(NMHDR* pNMHDR, LRESULT* pResult)
00357 {
00358         NM_TREEVIEW* pNMTV = (NM_TREEVIEW*) pNMHDR;
00359         if ( m_eKindActiveTree == CConstraintTreeCtrl::TK_CONSTRAINT ) {
00360                 bool bRemoveEnabled = true;
00361                 bool bCheckEnabled = false;
00362                 for ( HTREEITEM hCItem = m_treeConstraints.GetRootItem(); hCItem != NULL ; hCItem = m_treeConstraints.GetNextSiblingItem( hCItem ) ) {
00363                         BOOL bSelected = m_treeConstraints.GetItemState( hCItem, TVIS_SELECTED ) & TVIS_SELECTED;
00364                         int iImNumS = m_treeConstraints.GETSTATE( hCItem );
00365                         if ( bSelected ) {
00366                                 if ( iImNumS == 1 )
00367                                         bCheckEnabled = true;
00368                                 int iImNum;
00369                                 m_treeConstraints.GetItemImage( hCItem, iImNum, iImNum );
00370                                 if ( iImNum == 0 || iImNum == 1 || iImNum == 4 || iImNum == 5 ) {
00371                                         bRemoveEnabled = false;
00372                                         break;
00373                                 }
00374                         }
00375                 }
00376                 m_btnCheck.EnableWindow( bCheckEnabled );
00377                 m_btnRemove.EnableWindow( bRemoveEnabled && bCheckEnabled );
00378         }
00379         *pResult = 0;
00380 }
00381 
00382 void CConstraintBrowserDialog::OnSelectionChangedTreeObjects(NMHDR* pNMHDR, LRESULT* pResult)
00383 {
00384         NM_TREEVIEW* pNMTV = (NM_TREEVIEW*) pNMHDR;
00385         if ( m_eKindActiveTree == CConstraintTreeCtrl::TK_OBJECT ) {
00386                 for ( HandlerSet::iterator it = m_setClicked.begin() ; it != m_setClicked.end() ; ++it ) {
00387                         BOOL bSelected = m_treeObjects.GetItemState( *it, TVIS_SELECTED ) & TVIS_SELECTED;
00388                         if ( ! bSelected ) {
00389                                 SelectItem( *it, false );
00390                                 m_setClicked.erase( *it );
00391                         }
00392                 }
00393                 if ( pNMTV->itemNew.hItem ) {
00394                         BOOL bSelected = m_treeObjects.GetItemState( pNMTV->itemNew.hItem, TVIS_SELECTED ) & TVIS_SELECTED;
00395                         SelectItem( pNMTV->itemNew.hItem, ( bSelected ) ? true : false );
00396                         m_setClicked.insert( pNMTV->itemNew.hItem );
00397                 }
00398                 m_btnCheck.EnableWindow( ! m_setSelecteds.empty() );
00399         }
00400         *pResult = 0;
00401 }
00402 
00403 
00404         void CConstraintBrowserDialog::SelectItem( HTREEITEM hItem, bool bSelect )
00405         {
00406                 int iImNum;
00407                 m_treeObjects.GetItemImage( hItem, iImNum, iImNum );
00408 
00409                 // Object Selection
00410 
00411                 if ( iImNum > 8 ) {
00412                         CString strKind = m_treeObjects.GetItemText( hItem );
00413                         ExpandKind( OclCommonEx::Convert( m_treeObjects.GetItemText( hItem ) ), hItem );
00414                         for ( HTREEITEM hKItem = m_treeObjects.GetRootItem(); hKItem != NULL ; hKItem = m_treeObjects.GetNextSiblingItem( hKItem ) ) {
00415                                 if ( m_treeObjects.GetItemText( hKItem ) == strKind ) {
00416                                         hItem = hKItem;
00417                                         break;
00418                                 }
00419                         }
00420                 }
00421                 if ( iImNum > 5 ) {
00422                         for ( HTREEITEM hCItem = m_treeObjects.GetChildItem( hItem ); hCItem != NULL ; hCItem = m_treeObjects.GetNextSiblingItem( hCItem ) ) {
00423                                 int iImNumC;
00424                                 m_treeObjects.GetItemImage( hCItem, iImNumC, iImNumC );
00425                                 if ( iImNumC < 6 )
00426                                         SelectItem( hCItem, bSelect );
00427                         }
00428                         return;
00429                 }
00430 
00431                 // Constraint Selection
00432 
00433                 HTREEITEM hParent = m_treeObjects.GetParentItem( hItem );
00434                 m_treeObjects.GetItemImage( hParent, iImNum, iImNum );
00435                 if ( iImNum < 9 )
00436                         if ( bSelect )
00437                                 m_setSelecteds.insert( hItem );
00438                         else
00439                                 m_setSelecteds.erase( hItem );
00440                 for ( HTREEITEM hOItem = m_treeObjects.GetChildItem( hParent ); hOItem != NULL ; hOItem = m_treeObjects.GetNextSiblingItem( hOItem ) ) {
00441                         int iImNumO;
00442                         m_treeObjects.GetItemImage( hOItem, iImNumO, iImNumO );
00443                         if ( iImNumO > 5 )
00444                                 SelectItem( FindConstraintNode( hOItem, OclCommonEx::Convert( m_treeObjects.GetItemText( hItem ) ) ), bSelect );
00445                 }
00446         }
00447 
00448         void CConstraintBrowserDialog::ApplyChanges()
00449         {
00450                 m_pFacade->m_vecUserConstraints.clear();
00451                 m_pFacade->m_vecMetaConstraints.clear();
00452 
00453                 for ( ConstraintMap::iterator i = m_mapConstraint.begin() ; i != m_mapConstraint.end() ; ++i ) {
00454                         if ( (*i).second->GetLocation() != OclGme::ConstraintBase::CL_META )
00455                                 m_pFacade->m_vecUserConstraints.push_back( (*i).second );
00456                         else
00457                                 m_pFacade->m_vecMetaConstraints.push_back( (*i).second );
00458                 }
00459 
00460                 EvaluationInfo info;
00461 
00462                 info.bEnabledSCLogical = m_pageSettings.m_chkEnableLogical.GetCheck() == 1;
00463                 info.bEnabledSCIterator = m_pageSettings.m_chkEnableIterator.GetCheck() == 1;
00464                 info.bEnabledTracking = m_pageSettings.m_chkEnableTracking.GetCheck() == 1;
00465 
00466                 if ( ( (CButton*) m_pageSettings.GetDlgItem( BSEP_RDVIOLFIRST ) )->GetCheck() == 1 )
00467                         info.iViolationCount = 1;
00468                 else if ( ( (CButton*) m_pageSettings.GetDlgItem( BSEP_RDLEVELFIRST ) )->GetCheck() == 1 )
00469                         info.iViolationCount = -1;
00470                 else if ( ( (CButton*) m_pageSettings.GetDlgItem( BSEP_RDDEFAULT ) )->GetCheck() == 1 )
00471                         info.iViolationCount = -2;
00472                 else {
00473                         CString strCount;
00474                         m_pageSettings.m_edtViolationCount.GetWindowText( strCount );
00475                         info.iViolationCount = _ttoi( strCount );
00476                 }
00477 
00478                 if ( ( (CButton*) m_pageSettings.GetDlgItem( BSEP_RDZERODEPTH ) )->GetCheck() == 1 )
00479                         info.iModelDepth = 0;
00480                 else if ( ( (CButton*) m_pageSettings.GetDlgItem( BSEP_RDONEDEPTH ) )->GetCheck() == 1 )
00481                         info.iModelDepth = 1;
00482                 else
00483                         info.iModelDepth = -1;
00484 
00485                 m_pFacade->SetEvaluationInfo( info );
00486         }
00487 
00488         void CConstraintBrowserDialog::LoadSettings()
00489         {
00490                 EvaluationInfo info = m_pFacade->GetEvaluationInfo();
00491 
00492                 m_pageSettings.m_chkEnableLogical.SetCheck( info.bEnabledSCLogical );
00493                 m_pageSettings.m_chkEnableIterator.SetCheck( info.bEnabledSCIterator );
00494                 m_pageSettings.m_chkEnableTracking.SetCheck( info.bEnabledTracking );
00495 
00496                 if ( info.iViolationCount > 1 ) {
00497                         ( (CButton*) m_pageSettings.GetDlgItem( BSEP_RDVIOLCOUNT ) )->SetCheck( 1 );
00498                         m_pageSettings.m_edtViolationCount.SetReadOnly( false );
00499                         CString strCount;
00500                         strCount.Format( _T("%d"), info.iViolationCount );
00501                         m_pageSettings.m_edtViolationCount.SetWindowText( strCount );
00502                 }
00503                 else {
00504                         m_pageSettings.m_edtViolationCount.SetWindowText( _T("2") );
00505                         switch( info.iViolationCount ) {
00506                                 case 1 : ( (CButton*) m_pageSettings.GetDlgItem( BSEP_RDVIOLFIRST ) )->SetCheck( 1 ); break;
00507                                 case -1 : ( (CButton*) m_pageSettings.GetDlgItem( BSEP_RDLEVELFIRST ) )->SetCheck( 1 ); break;
00508                                 default : ( (CButton*) m_pageSettings.GetDlgItem( BSEP_RDDEFAULT ) )->SetCheck( 1 ); break;
00509                         }
00510                 }
00511 
00512                 switch ( info.iModelDepth ) {
00513                         case 0 : ( (CButton*) m_pageSettings.GetDlgItem( BSEP_RDZERODEPTH ) )->SetCheck( 1 ); break;
00514                         case 1 : ( (CButton*) m_pageSettings.GetDlgItem( BSEP_RDONEDEPTH ) )->SetCheck( 1 ); break;
00515                         default : ( (CButton*) m_pageSettings.GetDlgItem( BSEP_RDANYDEPTH ) )->SetCheck( 1 ); break;
00516                 }
00517         }
00518 
00519         void CConstraintBrowserDialog::LoadConstraints()
00520         {
00521                 for ( unsigned int i = 0 ; i < m_pFacade->m_vecMetaConstraints.size() ; i++ )
00522                         AddConstraint( m_pFacade->m_vecMetaConstraints[ i ] );
00523                 for ( unsigned int i = 0 ; i < m_pFacade->m_vecUserConstraints.size() ; i++ )
00524                         AddConstraint( m_pFacade->m_vecUserConstraints[ i ] );
00525 
00526                 m_treeConstraints.SortItemChildren( TVI_ROOT );
00527         }
00528 
00529         void CConstraintBrowserDialog::LoadKinds()
00530         {
00531                 OclCommonEx::MetaBaseVector vecMetas;
00532                 OclCommonEx::GetMetaObjects( m_pFacade->GetMetaProject(), "", OBJTYPE_NULL, vecMetas );
00533                 UINT uiMask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE | TVIF_TEXT;
00534                 int iImNumS = NS_UNKNOWN;
00535                 int iImNum;
00536                 CComPtr<IMgaMetaFolder> spRootFolder;
00537                 COMTHROW( m_pFacade->GetMetaProject()->get_RootFolder( &spRootFolder ) );
00538                 for ( unsigned int i = 0 ; i < vecMetas.size() ; i++ ) {
00539                         std::string strKind = OclCommonEx::GetObjectName( vecMetas[ i ].p );
00540                         objtype_enum eType = OclCommonEx::GetObjectType( vecMetas[ i ].p );
00541                         if ( eType == OBJTYPE_FOLDER )
00542                                 iImNum = ( vecMetas[ i ].p == spRootFolder.p ) ? 9 : 10;
00543                         else
00544                                 iImNum = eType + 10;
00545                         HTREEITEM hItem = m_treeObjects.InsertItem( uiMask, OclCommonEx::Convert( strKind ), iImNum, iImNum, iImNumS << 12 , TVIS_STATEIMAGEMASK, NULL, TVI_ROOT, TVI_LAST );
00546                         m_treeObjects.SetItemData( hItem, ( DWORD ) hItem );
00547                         m_mapH2ID.insert( MapH2ID::value_type( hItem, strKind ) );
00548                         m_mapID2H.insert( MapID2H::value_type( strKind, hItem ) );
00549                 }
00550 
00551                 m_treeObjects.SortItemChildren( TVI_ROOT );
00552         }
00553 
00554         void CConstraintBrowserDialog::AddConstraint( OclGme::SpConstraint spConstraint )
00555         {
00556                 // Set State
00557 
00558                 int iImNumS;
00559                 switch ( spConstraint->GetState() ) {
00560                         case Ocl::Constraint::CS_CTX_PARSE_FAILED :
00561                         case Ocl::Constraint::CS_PARSE_FAILED :
00562                                 iImNumS = CSIMG_SYNTAX_ERROR;
00563                                 break;
00564                         case Ocl::Constraint::CS_CTX_CHECK_FAILED :
00565                         case Ocl::Constraint::CS_CHECK_FAILED : {
00566                                 iImNumS = CSIMG_SEMANTIC_ERROR;
00567                                 std::string strType = spConstraint->GetFullName();
00568                                 auto iPos = strType.rfind( ":" );
00569                                 strType = strType.substr( 0, iPos - 1 );
00570                                 try {
00571                                         m_pFacade->GetTreeManager()->GetTypeManager()->GetType( strType, NILNAMESPACE );
00572                                 }
00573                                 catch ( ... ) {
00574                                         iImNumS = CSIMG_CONTEXT_ERROR;
00575                                 }
00576                                 break;
00577                         }
00578                         case Ocl::Constraint::CS_CHECK_DEPENDENCY_FAILED :
00579                                 iImNumS = CSIMG_DEPENDENCY_ERROR;
00580                                 break;
00581                         case Ocl::Constraint::CS_CHECK_DEPENDENCY_SUCCEEDED :
00582                         case Ocl::Constraint::CS_EVAL_FAILED :
00583                         case Ocl::Constraint::CS_EVAL_SUCCEEDED :
00584                                 iImNumS = CSIMG_OK;
00585                                 break;
00586                         default :
00587                                 iImNumS = CSIMG_CONTEXT_ERROR;
00588                 }
00589 
00590                 // Insert Constraint
00591 
00592                 UINT uiMask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE | TVIF_TEXT;
00593                 int iImNum = spConstraint->GetType();
00594                 HTREEITEM hItem = m_treeConstraints.InsertItem( uiMask, OclCommonEx::Convert( spConstraint->GetFullName() ), iImNum, iImNum, iImNumS << 12 , TVIS_STATEIMAGEMASK, NULL, TVI_ROOT, TVI_LAST );
00595                 m_treeConstraints.SetItemData( hItem, ( DWORD ) hItem );
00596                 if ( iImNumS == CSIMG_OK ) {
00597                         ConstraintVectorMap::iterator it = m_mapConstraints.find( spConstraint->GetContextType() );
00598                         if ( it == m_mapConstraints.end() )
00599                                 m_mapConstraints.insert( ConstraintVectorMap::value_type( spConstraint->GetContextType(), OclGme::ConstraintVector( 1, spConstraint ) ) );
00600                         else
00601                                 m_mapConstraints[ (*it).first ].push_back( spConstraint );
00602                 }
00603                 m_mapConstraint.insert( ConstraintMap::value_type( hItem, spConstraint ) );
00604         }
00605 
00606         void CConstraintBrowserDialog::ExpandKind( const std::string& strKind, HTREEITEM hItem )
00607         {
00608                 if ( m_treeObjects.GETSTATE( hItem ) != NS_UNKNOWN )
00609                         return;
00610 
00611                 // Create ConstraintVector
00612 
00613                 int iRootIm;
00614                 m_treeObjects.GetItemImage( hItem, iRootIm, iRootIm );
00615 
00616                 OclGme::ConstraintVector vecConstraints;
00617                 ConstraintVectorMap::iterator it =  m_mapConstraints.find( "meta::" + strKind );
00618                 if ( it != m_mapConstraints.end() )
00619                         vecConstraints = (*it).second;
00620 
00621                 // Add Constraints As Children
00622 
00623                 for ( unsigned int i = 0 ; i < vecConstraints.size() ; i++ ) {
00624                         UINT uiMask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE | TVIF_TEXT;
00625                         int iImNum = vecConstraints[ i ]->GetType();
00626                         int iImNumS = ( vecConstraints[ i ]->GetLocation() != OclGme::ConstraintBase::CL_PROJECT && vecConstraints[ i ]->GetPriority() == 1 ) ? NS_CHECKED_DISABLED : NS_CHECKED;
00627                         HTREEITEM hCItem = m_treeObjects.InsertItem( uiMask, OclCommonEx::Convert( vecConstraints[ i ]->GetFullName() ), iImNum, iImNum, iImNumS << 12 , TVIS_STATEIMAGEMASK, NULL, hItem, TVI_LAST );
00628                         m_treeObjects.SetItemData( hCItem, ( DWORD ) hCItem );
00629                 }
00630                 m_treeObjects.SETSTATE( hItem, (int) ( ( vecConstraints.size() == 0 ) ? NS_UNCHECKED_DISABLED : NS_CHECKED ) );
00631 
00632                 OclCommonEx::ObjectVector vecObjects;
00633                 OclCommonEx::GetKindObjects( m_pFacade->GetProject(), strKind, vecObjects );
00634                 for ( unsigned int i = 0 ; i < vecObjects.size() ; i++ ) {
00635                         CComQIPtr<IMgaFCO> spFCO = vecObjects[ i ].p;
00636                         if ( spFCO.p ) {
00637                                 CComPtr<IMgaFCO> spArche;
00638                                 COMTHROW( spFCO->get_ArcheType( &spArche ) );
00639                                 if ( ! spArche.p )
00640                                         LoadObject( spFCO.p, hItem, vecConstraints );
00641                         }
00642                         else
00643                                 LoadObject( vecObjects[ i ].p, hItem, vecConstraints );
00644                 }
00645                 m_treeObjects.SortItemChildren( hItem );
00646         }
00647 
00648         void CConstraintBrowserDialog::LoadObject( CComPtr<IMgaObject> spObject, HTREEITEM hParent, const OclGme::ConstraintVector& vecConstraints )
00649         {
00650                 // Determine icon
00651 
00652                 std::string strName = OclCommonEx::GetObjectName( spObject );
00653                 CComQIPtr<IMgaFCO> spFCO = spObject;
00654                 CComQIPtr<IMgaFolder> spFolder = spObject;
00655                 int iImNum = 6;
00656                 if ( spFCO.p ) {
00657                         VARIANT_BOOL vbInstance;
00658                         COMTHROW( spFCO->get_IsInstance( &vbInstance ) );
00659                         if ( vbInstance )
00660                                 iImNum = 8;
00661                         else {
00662                                 CComPtr<IMgaFCO> spArche;
00663                                 COMTHROW( spFCO->get_ArcheType( &spArche ) );
00664                                 if ( spArche.p )
00665                                         iImNum = 7;
00666                         }
00667                 }
00668                 else {
00669                         CComPtr<IMgaFolder> spRoot;
00670                         COMTHROW( m_pFacade->GetProject()->get_RootFolder( &spRoot ) );
00671                         iImNum = ( spObject.p == spRoot.p ) ? 9 : 10;
00672                 }
00673 
00674                 // Insert TreeItem
00675 
00676                 CString strID;
00677                 COMTHROW( spObject->get_ID( PutOut( strID ) ) );
00678                 int iImNumS = NS_UNKNOWN;
00679                 UINT uiMask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE | TVIF_TEXT;
00680                 HTREEITEM hItem = m_treeObjects.InsertItem( uiMask, OclCommonEx::Convert( strName ), iImNum, iImNum, iImNumS << 12 , TVIS_STATEIMAGEMASK, NULL, hParent, TVI_LAST );
00681                 m_treeObjects.SetItemData( hItem, ( DWORD ) hItem );
00682                 m_mapH2ID.insert( MapH2ID::value_type( hItem, OclCommonEx::Convert( strID ) ) );
00683                 m_mapID2H.insert( MapID2H::value_type( OclCommonEx::Convert( strID ), hItem ) );
00684 
00685                 for ( unsigned int i = 0 ; i < vecConstraints.size() ; i++ ) {
00686 
00687                         // Add Constraint
00688 
00689                         int iImCNum = vecConstraints[ i ]->GetType();
00690                         int iImCNumS = NS_UNKNOWN;
00691                         HTREEITEM hCItem = m_treeObjects.InsertItem( uiMask, OclCommonEx::Convert( vecConstraints[ i ]->GetFullName() ), iImCNum, iImCNum, iImCNumS << 12 , TVIS_STATEIMAGEMASK, NULL, hItem, TVI_LAST );
00692                         m_treeObjects.SetItemData( hCItem, ( DWORD ) hCItem );
00693 
00694                         // Determine state
00695 
00696                         switch ( vecConstraints[ i ]->GetEnableInfo( spObject ) ) {
00697                                 case OclGme::Constraint::CE_NONE :
00698                                 case OclGme::Constraint::CE_DISABLED_READONLY :
00699                                         iImCNumS = NS_UNCHECKED_DISABLED; break;
00700                                 case OclGme::Constraint::CE_ENABLED_READONLY :
00701                                         iImCNumS = NS_CHECKED_DISABLED; break;
00702                                 case OclGme::Constraint::CE_ENABLED_INHERITED :
00703                                         iImCNumS = NS_CHECKED_INHERITED; break;
00704                                 case OclGme::Constraint::CE_DISABLED_INHERITED :
00705                                         iImCNumS = NS_UNCHECKED_INHERITED; break;
00706                                 case OclGme::Constraint::CE_ENABLED :
00707                                         iImCNumS = NS_CHECKED; break;
00708                                 case OclGme::Constraint::CE_DISABLED :
00709                                         iImCNumS = NS_UNCHECKED; break;
00710                         }
00711 
00712                         // Refreshing Root State and Set This State
00713 
00714                         m_treeObjects.SETSTATE( hCItem, iImCNumS );
00715                 }
00716                 RefreshRootState( hItem );
00717 
00718                 if ( vecConstraints.size() == 0 )
00719                         m_treeObjects.SETSTATE( hItem, NS_UNCHECKED_DISABLED );
00720 
00721                 // Load Derived Objects
00722 
00723                 if ( spFCO.p && iImNum != 8 ) {
00724                         CComPtr<IMgaFCOs> spDeriveds;
00725                         COMTHROW( spFCO->get_DerivedObjects( &spDeriveds ) );
00726                         MGACOLL_ITERATE( IMgaFCO, spDeriveds ) {
00727                                 LoadObject( MGACOLL_ITER.p, hItem, vecConstraints );
00728                         } MGACOLL_ITERATE_END;
00729                 }
00730 
00731                 m_treeObjects.SortItemChildren( hItem );
00732         }
00733 
00734         void CConstraintBrowserDialog::RefreshRootState( HTREEITEM hParent )
00735         {
00736                 int iCount = 0;
00737                 int iChecked = 0;
00738                 int iDisabled = 0;
00739                 for ( HTREEITEM hCItem = m_treeObjects.GetChildItem( hParent ) ; hCItem != NULL ; hCItem = m_treeObjects.GetNextSiblingItem( hCItem ) ) {
00740                         int iImNumC;
00741                         m_treeObjects.GetItemImage( hCItem, iImNumC, iImNumC );
00742                         if ( iImNumC < 6 ) {
00743                                 int iImNumS = m_treeObjects.GETSTATE( hCItem );
00744                                 iCount++;
00745                                 if ( iImNumS == NS_CHECKED || iImNumS == NS_CHECKED_INHERITED || iImNumS == NS_CHECKED_DISABLED )
00746                                         iChecked++;
00747                                 if ( iImNumS == NS_CHECKED_DISABLED || iImNumS == NS_UNCHECKED_DISABLED )
00748                                         iDisabled++;
00749                         }
00750                 }
00751                 if ( iCount == 0 )
00752                         m_treeObjects.SETSTATE( hParent, (int) NS_UNCHECKED_DISABLED );
00753                 else if ( iCount == iDisabled )
00754                         if ( iChecked == 0 )
00755                                 m_treeObjects.SETSTATE( hParent, (int) NS_UNCHECKED_DISABLED );
00756                         else
00757                                 m_treeObjects.SETSTATE( hParent, (int) NS_CHECKED_DISABLED );
00758                 else if ( iCount == iChecked )
00759                         m_treeObjects.SETSTATE( hParent, (int) NS_CHECKED );
00760                 else if ( iChecked == 0 )
00761                         m_treeObjects.SETSTATE( hParent, (int) NS_UNCHECKED );
00762                 else
00763                         m_treeObjects.SETSTATE( hParent, (int) NS_MISCELLANEOUS );
00764         }
00765 
00766         int CConstraintBrowserDialog::GetAncestorState( HTREEITEM hItem, const std::string& strCID )
00767         {
00768                 HTREEITEM hParent = m_treeObjects.GetParentItem( hItem ); // Assume Instance
00769                 hParent = m_treeObjects.GetParentItem( hParent ); // Then Its Type
00770                 if ( ! hParent )
00771                         return NS_ERROR;
00772                 HTREEITEM hCItem = FindConstraintNode( hParent, strCID );
00773                 if ( hCItem )
00774                         return m_treeObjects.GETSTATE( hCItem );
00775                 return NS_ERROR;
00776         }
00777 
00778         void CConstraintBrowserDialog::SetNewState( HTREEITEM hItem, int iNewS, bool bInheritance )
00779         {
00780                 int iImNum;
00781                 m_treeObjects.GetItemImage( hItem, iImNum, iImNum );
00782 
00783                 // If not Constraint TreeNode
00784 
00785                 if ( iImNum > 5 ) {
00786                         for ( HTREEITEM hCItem = m_treeObjects.GetChildItem( hItem ) ; hCItem != NULL ; hCItem = m_treeObjects.GetNextSiblingItem( hCItem ) ) {
00787                                 int iImNumC;
00788                                 m_treeObjects.GetItemImage( hCItem, iImNumC, iImNumC );
00789                                 if ( iImNumC > 0 && iImNumC < 6 )
00790                                         SetNewState( hCItem, iNewS, bInheritance );
00791                                 else
00792                                         if ( bInheritance )
00793                                                 SetNewState( hCItem, iNewS, bInheritance );
00794                         }
00795                         return;
00796                 }
00797 
00798                 // If Constraint TreeNode
00799 
00800                 if ( m_treeObjects.GETSTATE( hItem ) == NS_UNCHECKED_DISABLED || m_treeObjects.GETSTATE( hItem ) == NS_CHECKED_DISABLED )
00801                         return;
00802 
00803                 // Obtain parent
00804 
00805                 HTREEITEM hParent = m_treeObjects.GetParentItem( hItem );
00806                 int iImNumP;
00807                 m_treeObjects.GetItemImage( hParent, iImNumP, iImNumP );
00808 
00809                 // determine the new state
00810 
00811                 CString strCID = m_treeObjects.GetItemText( hItem );
00812                 int iAncestor = GetAncestorState( hItem, OclCommonEx::Convert( strCID ) );
00813                 int iRealNewS;
00814                 if ( iNewS == NS_CHECKED )
00815                         iRealNewS = ( ( iAncestor == NS_CHECKED || iAncestor == NS_CHECKED_INHERITED ) && iImNumP != 6 ) ? NS_CHECKED_INHERITED : NS_CHECKED;
00816                 else
00817                         iRealNewS = ( ( iAncestor == NS_UNCHECKED || iAncestor == NS_UNCHECKED_INHERITED ) && iImNumP != 6 ) ? NS_UNCHECKED_INHERITED : NS_UNCHECKED;
00818 
00819                 // if parent is Object and not kind, perform the change in registry
00820 
00821                 if ( iImNumP > 5 && iImNumP < 9 ) {
00822                         MapH2ID::iterator it = m_mapH2ID.find( (HTREEITEM) m_treeObjects.GetItemData( hParent ) );
00823                         CComPtr<IMgaObject> spObject;
00824                         COMTHROW( m_pFacade->GetProject()->GetObjectByID( CComBSTR( OclCommonEx::Convert( (*it).second ) ), &spObject ) );
00825                         CComQIPtr<IMgaRegNode> spRegNode;
00826                         CComQIPtr<IMgaFCO> spFCO = spObject;
00827                         if ( spFCO.p )
00828                                 COMTHROW( spFCO->get_RegistryNode( CComBSTR( L"ConstraintEnabling/" + strCID ), &spRegNode ) );
00829                         else {
00830                                 CComQIPtr<IMgaFolder> spFolder = spObject;
00831                                 COMTHROW( spFolder->get_RegistryNode( CComBSTR( L"ConstraintEnabling/" + strCID ), &spRegNode ) );
00832                         }
00833                         if ( iRealNewS == NS_CHECKED_INHERITED || iRealNewS == NS_UNCHECKED_INHERITED && iImNumP != 6 )
00834                                 COMTHROW( spRegNode->RemoveTree() );
00835                         else
00836                                 COMTHROW( spRegNode->put_Value( CComBSTR( ( iRealNewS == NS_CHECKED || iRealNewS == NS_CHECKED_INHERITED ) ? "yes" : "no" ) ) );
00837                 }
00838 
00839                 // Refresh Root and Set State in Tree
00840 
00841                 m_treeObjects.SETSTATE( hItem, iRealNewS );
00842                 RefreshRootState( hParent );
00843 
00844                 // Refresh All Inherited
00845 
00846                 for ( HTREEITEM hOItem = m_treeObjects.GetChildItem( hParent ) ; hOItem != NULL ; hOItem = m_treeObjects.GetNextSiblingItem( hOItem ) ) {
00847                         int iImNumO;
00848                         m_treeObjects.GetItemImage( hOItem, iImNumO, iImNumO );
00849                         if ( iImNumO > 5 ) {
00850                                 HTREEITEM hCItem = FindConstraintNode( hOItem, OclCommonEx::Convert( strCID ) );
00851                                 if ( hCItem ) {
00852                                         if ( ! bInheritance ) {
00853                                                 iNewS = m_treeObjects.GETSTATE( hCItem );
00854                                                 if ( iNewS == NS_CHECKED_INHERITED )
00855                                                         iNewS = NS_CHECKED;
00856                                                 else if ( iNewS == NS_UNCHECKED_INHERITED )
00857                                                         iNewS = NS_UNCHECKED;
00858                                         }
00859                                         SetNewState( hCItem, iNewS, bInheritance );
00860                                 }
00861                         }
00862                 }
00863         }
00864 
00865         HTREEITEM CConstraintBrowserDialog::FindConstraintNode( HTREEITEM hItem, const std::string& strCID )
00866         {
00867                 for ( HTREEITEM hCItem = m_treeObjects.GetChildItem( hItem ) ; hCItem != NULL ; hCItem = m_treeObjects.GetNextSiblingItem( hCItem ) ) {
00868                         int iImNumC;
00869                         m_treeObjects.GetItemImage( hCItem, iImNumC, iImNumC );
00870                         if ( iImNumC < 6 ) {
00871                                 CString strID = m_treeObjects.GetItemText( hCItem );
00872                                 if ( strCID == OclCommonEx::Convert( strID ) )
00873                                         return hCItem;
00874                         }
00875                 }
00876                 return NULL;
00877         }
00878 
00879         void CConstraintBrowserDialog::SetView( CConstraintTreeCtrl::Kind eKind )
00880         {
00881                 if ( m_eKindActiveTree == CConstraintTreeCtrl::TK_OBJECT && m_treeObjects.IsWindowVisible() )
00882                         m_treeObjects.ClearSelection();
00883                 if ( m_eKindActiveTree == CConstraintTreeCtrl::TK_CONSTRAINT && m_treeConstraints.IsWindowVisible() )
00884                         m_treeConstraints.ClearSelection();
00885 
00886                 m_eKindActiveTree = eKind;
00887                 m_btnRemove.EnableWindow( false );
00888                 m_btnAdd.EnableWindow( eKind == CConstraintTreeCtrl::TK_CONSTRAINT );
00889 
00890                 m_treeConstraints.ShowWindow( ( eKind == CConstraintTreeCtrl::TK_CONSTRAINT ) ? SW_SHOW : SW_HIDE );
00891                 m_treeObjects.ShowWindow( ( eKind == CConstraintTreeCtrl::TK_OBJECT ) ? SW_SHOW : SW_HIDE );
00892                 m_pageSettings.ShowWindow( ( eKind == CConstraintTreeCtrl::TK_UNKNOWN ) ? SW_SHOW : SW_HIDE );
00893 
00894                 m_btnLoad.EnableWindow( eKind == CConstraintTreeCtrl::TK_OBJECT && ! m_bLoaded );
00895 
00896                 m_btnCheck.EnableWindow( eKind != CConstraintTreeCtrl::TK_UNKNOWN );
00897         }
00898 
00899         void CConstraintBrowserDialog::RefreshKind( const std::string& strKind )
00900         {
00901                 MapID2H::iterator it = m_mapID2H.find( strKind );
00902                 m_treeObjects.DeleteItem( (*it).second );
00903                 m_mapID2H.erase( it );
00904 
00905                 OclCommonEx::MetaBaseVector vecMetas;
00906                 OclCommonEx::GetMetaObjects( m_pFacade->GetMetaProject(), strKind, OBJTYPE_NULL, vecMetas );
00907                 UINT uiMask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE | TVIF_TEXT | TVIF_CHILDREN;
00908                 int iImNumS = NS_UNKNOWN;
00909                 int iImNum;
00910                 CComPtr<IMgaMetaFolder> spRootFolder;
00911                 COMTHROW( m_pFacade->GetMetaProject()->get_RootFolder( &spRootFolder ) );
00912                 objtype_enum eType = OclCommonEx::GetObjectType( vecMetas[ 0 ].p );
00913                 if ( eType == OBJTYPE_FOLDER )
00914                         iImNum = ( vecMetas[ 0 ].p == spRootFolder.p ) ? 9 : 10;
00915                 else
00916                         iImNum = eType + 10;
00917                 HTREEITEM hItem = m_treeObjects.InsertItem( uiMask, OclCommonEx::Convert( strKind ), iImNum, iImNum, iImNumS << 12 , TVIS_STATEIMAGEMASK, NULL, TVI_ROOT, TVI_LAST );
00918                 m_treeObjects.SetItemData( hItem, ( DWORD ) hItem );
00919                 m_mapH2ID.insert( MapH2ID::value_type( hItem, strKind ) );
00920                 m_mapID2H.insert( MapID2H::value_type( strKind, hItem ) );
00921 
00922                 m_treeObjects.SortItemChildren( TVI_ROOT );
00923 
00924                 ExpandKind( strKind, hItem );
00925         }
00926 
00927         void CConstraintBrowserDialog::InsertConstraint( OclGme::SpConstraint spConstraint )
00928         {
00929                 // Add Constraint to Tree, and Context keyed map
00930 
00931                 AddConstraint( spConstraint );
00932 
00933                 // Write it to registry
00934 
00935                 CComPtr<IMgaFolder> spRootFolder;
00936                 COMTHROW( m_pFacade->GetProject()->get_RootFolder( &spRootFolder ) );
00937                 CComPtr<IMgaRegNode> spRegNode;
00938                 COMTHROW( spRootFolder->get_RegistryNode( CComBSTR( L"ConstraintDefinitions/" + OclCommonEx::Convert( spConstraint->GetFullName() ) ), &spRegNode ) );
00939                 spConstraint->Write( spRegNode );
00940 
00941                 // Remove the kind from Object Tree, and refresh it
00942 
00943                 RefreshKind( spConstraint->GetContextType().substr( 6 ) );
00944         }
00945 
00946         void CConstraintBrowserDialog::RemoveConstraint( OclGme::SpConstraint spConstraint, bool bRemoveEnableInfo )
00947         {
00948                 // Remove it from constraint map and constraint tree
00949 
00950                 for ( HTREEITEM hCItem = m_treeConstraints.GetChildItem( TVI_ROOT ) ; hCItem != NULL ; hCItem = m_treeObjects.GetNextSiblingItem( hCItem ) ) {
00951                         CString strCID = m_treeConstraints.GetItemText( hCItem );
00952                         if ( OclCommonEx::Convert( strCID ) == spConstraint->GetFullName() ) {
00953                                 HTREEITEM hRealItem = ( HTREEITEM ) m_treeConstraints.GetItemData( hCItem );
00954                                 m_treeConstraints.DeleteItem( hCItem );
00955                                 m_mapConstraint.erase( hRealItem );
00956                                 break;
00957                         }
00958                 }
00959 
00960                 // Remove it from context map
00961 
00962                 std::string strType;
00963                 if ( spConstraint->IsValid() )
00964                         strType = spConstraint->GetContextType();
00965                 else {
00966                         strType = spConstraint->GetFullName();
00967                         auto iPos = strType.rfind( ":" );
00968                         strType = strType.substr( 0, iPos - 1 );
00969                 }
00970 
00971                 if ( spConstraint->IsValid() ) {
00972                         ConstraintVectorMap::iterator it = m_mapConstraints.find( strType );
00973                         for ( OclGme::ConstraintVector::iterator vit = (*it).second.begin() ; vit != (*it).second.end() ; ++vit ) {
00974                                 if ( (*vit)->GetFullName() == spConstraint->GetFullName() ) {
00975                                         (*it).second.erase( vit );
00976                                         break;
00977                                 }
00978                         }
00979                 }
00980 
00981                 // Remove it from Registry
00982 
00983                 CComPtr<IMgaFolder> spRootFolder;
00984                 COMTHROW( m_pFacade->GetProject()->get_RootFolder( &spRootFolder ) );
00985                 CComPtr<IMgaRegNode> spRegNode;
00986                 COMTHROW( spRootFolder->get_RegistryNode( CComBSTR( L"ConstraintDefinitions/" + OclCommonEx::Convert( spConstraint->GetFullName() ) ), &spRegNode ) );
00987                 COMTHROW( spRegNode->RemoveTree() );
00988 
00989                 // Remove Enabling flags from objects' registry
00990 
00991                 if ( bRemoveEnableInfo ) {
00992                         OclCommonEx::ObjectVector vecObjects;
00993                         OclCommonEx::GetKindObjects( m_pFacade->GetProject(), strType.substr( 6 ), vecObjects );
00994                         for ( unsigned int i = 0 ; i < vecObjects.size() ; i++ ) {
00995                                 if ( OclCommonEx::GetLibraryPath( vecObjects[ i ].p ).empty() ) {
00996                                         CComPtr<IMgaRegNode> spRegNode;
00997                                         CComQIPtr<IMgaFolder> spFolder = vecObjects[ i ].p;
00998                                         if ( spFolder.p )
00999                                                 COMTHROW( spFolder->get_RegistryNode( CComBSTR( OclCommonEx::Convert( "ConstraintEnabling/" + spConstraint->GetFullName() ) ), &spRegNode ) );
01000                                         else {
01001                                                 CComQIPtr<IMgaFCO> spFCO = vecObjects[ i ].p;
01002                                                 COMTHROW( spFCO->get_RegistryNode( CComBSTR( OclCommonEx::Convert( "ConstraintEnabling/" + spConstraint->GetFullName() ) ), &spRegNode ) );
01003                                         }
01004                                         COMTHROW( spRegNode->RemoveTree() );
01005                                 }
01006                         }
01007 
01008                         // Refresh Kind
01009                 }
01010 
01011                 RefreshKind( strType.substr( 6 ) );
01012         }
01013 
01014 //##############################################################################################################################################
01015 //
01016 //      C L A S S : CConstraintBrowserDialog <<< + CDialog
01017 //
01018 //##############################################################################################################################################
01019 
01020 CSettingsPage::CSettingsPage( CWnd* pParent /*=NULL*/ )
01021         : CDialog( CSettingsPage::IDD, pParent )
01022 {
01023         //{{AFX_DATA_INIT(CSettingsPage)
01024                 // NOTE: the ClassWizard will add member initialization here
01025         //}}AFX_DATA_INIT
01026 }
01027 
01028 
01029 void CSettingsPage::DoDataExchange(CDataExchange* pDX)
01030 {
01031         CDialog::DoDataExchange(pDX);
01032         //{{AFX_DATA_MAP(CSettingsPage)
01033         DDX_Control(pDX, BSEP_EDTVIOLCOUNT, m_edtViolationCount);
01034         DDX_Control(pDX, BSEP_CHKTRACKING, m_chkEnableTracking);
01035         DDX_Control(pDX, BSEP_CHKSC_LOGICAL, m_chkEnableLogical);
01036         DDX_Control(pDX, BSEP_CHKSC_ITERATOR, m_chkEnableIterator);
01037         //}}AFX_DATA_MAP
01038 }
01039 
01040 
01041 BEGIN_MESSAGE_MAP(CSettingsPage, CDialog)
01042         //{{AFX_MSG_MAP(CSettingsPage)
01043         ON_BN_CLICKED(BSEP_RDVIOLFIRST, OnRadioButtonClicked)
01044         ON_EN_CHANGE(BSEP_EDTVIOLCOUNT, OnViolationCountChanged)
01045         //}}AFX_MSG_MAP
01046         ON_BN_CLICKED(BSEP_RDVIOLCOUNT, OnRadioButtonClicked)
01047         ON_BN_CLICKED(BSEP_RDLEVELFIRST, OnRadioButtonClicked)
01048         ON_BN_CLICKED(BSEP_RDDEFAULT, OnRadioButtonClicked)
01049 END_MESSAGE_MAP()
01050 
01052 // CSettingsPage message handlers
01053 
01054 BOOL CSettingsPage::PreTranslateMessage(MSG* pMsg)
01055 {
01056         if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE )
01057                 return GetParent()->PreTranslateMessage( pMsg );
01058         return CDialog::PreTranslateMessage( pMsg );
01059 }
01060 
01061 void CSettingsPage::OnRadioButtonClicked()
01062 {
01063         m_edtViolationCount.SetReadOnly( ! ( (CButton*) GetDlgItem( BSEP_RDVIOLCOUNT ) )->GetCheck() );
01064 }
01065 
01066 void CSettingsPage::OnViolationCountChanged()
01067 {
01068         CString strCount;
01069         m_edtViolationCount.GetWindowText( strCount );
01070         if ( strCount.IsEmpty() )
01071                 m_edtViolationCount.SetWindowText( _T("2") );
01072         else {
01073                 int iCount = _ttoi( strCount );
01074                 if ( iCount == 0 )
01075                         m_edtViolationCount.SetWindowText( _T("2") );
01076                 if ( iCount > 999 )
01077                         m_edtViolationCount.SetWindowText( _T("999") );
01078         }
01079 }
01080 
01081 }; // namespace OclGmeCM