GME
13
|
00001 // ExpressionChecker.cpp : Implementation of CExpressionChecker 00002 00003 #include "StdAfx.h" 00004 #include "ConstraintManager.h" 00005 #include "ExpressionChecker.h" 00006 #include "GMESyntacticSemanticDialog.h" 00007 #include "GMESmallMessageBox.h" 00008 #include "OCLCommonEx.h" 00009 00010 //############################################################################################################################################## 00011 // 00012 // C L A S S : CExpEventSink 00013 // 00014 //############################################################################################################################################## 00015 00016 STDMETHODIMP CExpEventSink::GlobalEvent( globalevent_enum event ) 00017 { 00018 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00019 return ec->GlobalEvent( event ); 00020 } 00021 00022 STDMETHODIMP CExpEventSink::ObjectEvent( IMgaObject *obj, unsigned long eventmask, VARIANT v ) 00023 { 00024 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00025 return ec->ObjectEvent( obj, eventmask, v ); 00026 } 00027 00028 //############################################################################################################################################## 00029 // 00030 // C L A S S : CExpressionChecker 00031 // 00032 //############################################################################################################################################## 00033 00034 STDMETHODIMP CExpressionChecker::ObjectsInvokeEx( IMgaProject *p, IMgaObject *o, IMgaObjects* os, long k ) 00035 { 00036 HRESULT ret = E_ABORT; 00037 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00038 if ( ! m_Facade.m_bEnabled ) 00039 return S_OK; 00040 00041 //AFX_MANAGE_STATE( AfxGetStaticModuleState() ); 00042 00043 COMTRY { 00044 00045 CWaitCursor crsrWait; 00046 00047 OclGme::ConstraintFunctionVector vecConstraintFunctions; 00048 m_Facade.CheckAllConstraintFunctions( vecConstraintFunctions ); 00049 OclGme::ConstraintVector vecConstraints; 00050 m_Facade.CheckAllConstraints( vecConstraints ); 00051 00052 crsrWait.Restore(); 00053 00054 if ( ! vecConstraints.empty() || ! vecConstraintFunctions.empty() ) { 00055 CSyntacticSemanticDialog dlgErrors( AfxGetApp()->m_pActiveWnd ); 00056 for ( unsigned int i = 0 ; i < vecConstraintFunctions.size() ; i++ ) 00057 dlgErrors.AddItem( vecConstraintFunctions[ i ] ); 00058 for ( unsigned int i = 0 ; i < vecConstraints.size() ; i++ ) 00059 dlgErrors.AddItem( vecConstraints[ i ] ); 00060 dlgErrors.DoModal(); 00061 ret = S_FALSE; 00062 } 00063 else 00064 { 00065 CSmallMessageBox().DoModal(); 00066 ret = S_OK; 00067 } 00068 00069 m_Facade.Finalize(); 00070 00071 return ret; 00072 } COMCATCH( ASSERT( 0 ); ) 00073 } 00074 00075 STDMETHODIMP CExpressionChecker::GlobalEvent( globalevent_enum event ) 00076 { 00077 AFX_MANAGE_STATE( AfxGetStaticModuleState() ); 00078 00079 switch( event ) { 00080 case GLOBALEVENT_CLOSE_PROJECT: { 00081 m_spAddOn = NULL; 00082 break; 00083 } 00084 00085 case GLOBALEVENT_COMMIT_TRANSACTION: 00086 case GLOBALEVENT_ABORT_TRANSACTION: { 00087 m_Facade.m_bEnabledEvents = true; 00088 break; 00089 } 00090 00091 case GLOBALEVENT_NOTIFICATION_READY: { 00092 m_Facade.m_bEnabledEvents = true; 00093 break; 00094 } 00095 00096 case APPEVENT_XML_IMPORT_BEGIN: 00097 //case APPEVENT_XML_IMPORT_FCOS_BEGIN: 00098 //case APPEVENT_XML_IMPORT_SPECIAL_BEGIN: 00099 case APPEVENT_LIB_ATTACH_BEGIN: { 00100 m_Facade.m_bEnabledEvents = false; 00101 break; 00102 } 00103 00104 case APPEVENT_XML_IMPORT_END: 00105 //case APPEVENT_XML_IMPORT_FCOS_END: 00106 //case APPEVENT_XML_IMPORT_SPECIAL_END: 00107 case APPEVENT_LIB_ATTACH_END: { 00108 m_Facade.m_bEnabledEvents = true; 00109 break; 00110 } 00111 } 00112 00113 return S_OK; 00114 } 00115 00116 STDMETHODIMP CExpressionChecker::ObjectEvent( IMgaObject *obj, unsigned long eventmask, VARIANT v ) 00117 { 00118 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00119 00120 if ( ! m_Facade.m_bEnabled || ! m_Facade.m_bEnabledInteractions || ! m_Facade.m_bEnabledEvents ) { 00121 return S_OK; 00122 } 00123 00124 CWnd* pMainWindow = AfxGetApp()->m_pActiveWnd; 00125 00126 COMTRY { 00127 00128 if( ( eventmask & OBJEVENT_ATTR ) || ( eventmask & OBJEVENT_CONNECTED ) ) { 00129 00130 CComQIPtr<IMgaFCO> spFCO = obj; 00131 if( spFCO ) { 00132 std::string strKind = OclCommonEx::GetObjectKind( spFCO.p ); 00133 if ( strKind == "Constraint" ) { 00134 CWaitCursor crsrWait; 00135 OclGme::ConstraintVector vecConstraints; 00136 m_Facade.CheckConstraint( spFCO.p, vecConstraints, false ); 00137 if ( ! vecConstraints.empty() ) { 00138 CSyntacticSemanticDialog dlgErrors( pMainWindow ); 00139 for ( unsigned int i = 0 ; i < vecConstraints.size() ; i++ ) 00140 dlgErrors.AddItem( vecConstraints[ i ] ); 00141 crsrWait.Restore(); 00142 dlgErrors.DoModal(); 00143 } 00144 else 00145 crsrWait.Restore(); 00146 } 00147 else if ( strKind == "ConstraintFunc" ) { 00148 CWaitCursor crsrWait; 00149 OclGme::ConstraintFunctionVector vecConstraintFunctions; 00150 m_Facade.CheckConstraintFunction( spFCO.p, vecConstraintFunctions, false ); 00151 if ( ! vecConstraintFunctions.empty() ) { 00152 CSyntacticSemanticDialog dlgErrors( pMainWindow ); 00153 for ( unsigned int i = 0 ; i < vecConstraintFunctions.size() ; i++ ) 00154 dlgErrors.AddItem( vecConstraintFunctions[ i ] ); 00155 crsrWait.Restore(); 00156 dlgErrors.DoModal(); 00157 } 00158 else 00159 crsrWait.Restore(); 00160 } 00161 m_Facade.Finalize(); 00162 } 00163 } else 00164 ASSERT(false); // Shouldn't get other events because of put_EventMask 00165 00166 } COMCATCH( ASSERT( 0 ); ) 00167 } 00168 00169 STDMETHODIMP CExpressionChecker::Initialize( IMgaProject *p ) 00170 { 00171 AFX_MANAGE_STATE( AfxGetStaticModuleState() ); 00172 00173 m_spProject = p; 00174 00175 CreateComObject( m_spEventSink ); 00176 m_spEventSink->ec = this; 00177 00178 m_spAddOn = NULL; 00179 COMTRY { 00180 COMTHROW( m_spProject->CreateAddOn( m_spEventSink, &m_spAddOn ) ); 00181 COMTHROW(m_spAddOn->put_EventMask(OBJEVENT_ATTR | OBJEVENT_CONNECTED)); 00182 00183 m_Facade.Initialize( p ); 00184 } COMCATCH( ASSERT( 0 ); ) 00185 00186 } 00187 00188 STDMETHODIMP CExpressionChecker::Enable( VARIANT_BOOL enabled ) 00189 { 00190 AFX_MANAGE_STATE( AfxGetStaticModuleState() ); 00191 m_Facade.m_bEnabled = ( enabled != VARIANT_TRUE ) ? true : false; 00192 return S_OK; 00193 } 00194 00195 STDMETHODIMP CExpressionChecker::get_InteractiveMode( VARIANT_BOOL * enabled ) 00196 { 00197 AFX_MANAGE_STATE( AfxGetStaticModuleState() ); 00198 *enabled = ( m_Facade.m_bEnabledInteractions ) ? VARIANT_TRUE : VARIANT_FALSE; 00199 return S_OK; 00200 } 00201 00202 STDMETHODIMP CExpressionChecker::put_InteractiveMode( VARIANT_BOOL enabled ) 00203 { 00204 AFX_MANAGE_STATE( AfxGetStaticModuleState() ); 00205 m_Facade.m_bEnabledInteractions = ( enabled ) ? true : false; 00206 return S_OK; 00207 } 00208 00209 STDMETHODIMP CExpressionChecker::get_ComponentParameter( BSTR name, VARIANT *pVal ) 00210 { 00211 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00212 return S_OK; 00213 } 00214 00215 STDMETHODIMP CExpressionChecker::put_ComponentParameter( BSTR name, VARIANT newVal ) 00216 { 00217 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00218 return S_OK; 00219 } 00220 00221 STDMETHODIMP CExpressionChecker::get_Paradigm( BSTR *pname ) 00222 { 00223 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00224 if( ! pname ) 00225 return E_MGA_OUTPTR_NULL; 00226 if( *pname ) 00227 return E_MGA_OUTPTR_NONEMPTY; 00228 *pname = CComBSTR( EXP_PARADIGM ).Detach(); 00229 return S_OK; 00230 } 00231 00232 STDMETHODIMP CExpressionChecker::get_ComponentName( BSTR *pname ) 00233 { 00234 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00235 if( ! pname ) 00236 return E_MGA_OUTPTR_NULL; 00237 if( *pname ) 00238 return E_MGA_OUTPTR_NONEMPTY; 00239 *pname = CComBSTR( EXP_COMPONENT_NAME ).Detach(); 00240 return S_OK; 00241 00242 } 00243 00244 STDMETHODIMP CExpressionChecker::get_ComponentProgID( BSTR *pname ) 00245 { 00246 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00247 if( ! pname ) 00248 return E_MGA_OUTPTR_NULL; 00249 if( *pname ) 00250 return E_MGA_OUTPTR_NONEMPTY; 00251 *pname = CComBSTR( EXP_COMPONENT_PROGID ).Detach(); 00252 return S_OK; 00253 } 00254 00255 STDMETHODIMP CExpressionChecker::get_ComponentType( componenttype_enum *ct ) 00256 { 00257 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00258 if( ! ct ) 00259 return E_MGA_OUTPTR_NULL; 00260 *ct = EXP_CETYPE; 00261 return S_OK; 00262 } 00263 00264 STDMETHODIMP CExpressionChecker::Invoke( IMgaProject *p, IMgaFCOs *os, long k ) 00265 { 00266 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00267 COMTRY { 00268 CComPtr<IMgaFCO> o; 00269 if(os) { 00270 long l; 00271 COMTHROW(os->get_Count(&l)); 00272 if(l > 0) COMTHROW(os->get_Item(1, &o)); 00273 } 00274 CComPtr<IMgaTerritory> t; 00275 COMTHROW(p->get_ActiveTerritory(&t)); 00276 COMTHROW(p->AbortTransaction()); 00277 HRESULT ret = ObjectsInvokeEx(p, o, NULL, k); 00278 COMTHROW(ret); 00279 COMTHROW(p->BeginTransaction(t, TRANSACTION_GENERAL)); 00280 return ret; 00281 } COMCATCH(;) 00282 } 00283 00284 STDMETHODIMP CExpressionChecker::InvokeEx( IMgaProject *p, IMgaFCO *o, IMgaFCOs *, long k ) 00285 { 00286 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00287 return ObjectsInvokeEx(p, o, NULL, k); 00288 }