GME
13
|
00001 // ConstraintMgr.cpp : Implementation of CConstraintMgr 00002 #include "StdAfx.h" 00003 #include "ConstraintManager.h" 00004 #include "ConstraintMgr.h" 00005 #include "GMESyntacticSemanticDialog.h" 00006 #include "GMEConstraintBrowserDialog.h" 00007 #include "OCLCommonEx.h" 00008 #include "Gme.h" 00009 00010 //############################################################################################################################################## 00011 // 00012 // C L A S S : CMgrEventSink 00013 // 00014 //############################################################################################################################################## 00015 00016 STDMETHODIMP CMgrEventSink::GlobalEvent( globalevent_enum event ) 00017 { 00018 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00019 return cm->GlobalEvent(event); 00020 } 00021 00022 STDMETHODIMP CMgrEventSink::ObjectEvent(IMgaObject *obj, unsigned long eventmask, VARIANT v) 00023 { 00024 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00025 return cm->ObjectEvent( obj, eventmask, v ); 00026 } 00027 00028 //############################################################################################################################################## 00029 // 00030 // C L A S S : CConstraintMgr 00031 // 00032 //############################################################################################################################################## 00033 void CConstraintMgr::GotoViolatorObject(CComPtr<IUnknown> &gotoPunk) 00034 { 00035 if (!gotoPunk) 00036 return; 00037 00038 COMTRY 00039 { 00040 CComBSTR app("GME.Application"); 00041 CComPtr<IMgaClient> client; 00042 COMTHROW(m_spProject->GetClientByName((BSTR)app, &client)); 00043 00044 CComPtr<IDispatch> gui; 00045 COMTHROW(client->get_OLEServer(&gui)); 00046 CComPtr<IGMEOLEApp> oleapp; 00047 COMTHROW(gui.QueryInterface(&oleapp)); 00048 /* COleDispatchDriver dispdrv(gui); 00049 00050 const BYTE BASED_CODE partypes[] = VTS_UNKNOWN; 00051 try 00052 { 00053 dispdrv.InvokeHelper(33, DISPATCH_METHOD, VT_EMPTY, NULL, partypes, (IUnknown*)gotoPunk); 00054 } 00055 */ 00056 try 00057 { 00058 CComPtr<IMgaFCO> fco; 00059 COMTHROW(gotoPunk.QueryInterface(&fco)); 00060 COMTHROW(oleapp->ShowFCO(fco, FALSE)); 00061 } 00062 catch (CException*) 00063 { 00064 } 00065 00066 } 00067 catch(hresult_exception &) 00068 { 00069 return ; 00070 } 00071 } 00072 00073 STDMETHODIMP CConstraintMgr::ObjectsInvokeEx( IMgaProject *p, IMgaObject *o, IMgaObjects* os, long k ) 00074 { 00075 AFX_MANAGE_STATE( AfxGetStaticModuleState() ); 00076 00077 if ( ! m_Facade.m_bEnabled ) 00078 return S_OK; 00079 00080 CComPtr<IUnknown> gotoPunk; 00081 COMTRY { 00082 00083 // Show ConstraintBrowser Dialog 00084 00085 if ( k == CONSTMGR_SHOW_CONSTRAINTS ) { 00086 00087 m_Facade.m_bEnabledEvents = false; 00088 00089 CComPtr<IMgaTerritory> spTerritory; 00090 COMTHROW( m_spProject->CreateTerritory( NULL, &spTerritory ) ); 00091 COMTHROW( m_spProject->BeginTransaction( spTerritory, TRANSACTION_GENERAL)); 00092 00093 OclGmeCM::CConstraintBrowserDialog dlgConstraints( &m_Facade, NULL, NULL, NULL ); 00094 if ( dlgConstraints.DoModal() == IDOK ) 00095 COMTHROW( m_spProject->CommitTransaction() ); 00096 else 00097 COMTHROW( m_spProject->AbortTransaction() ); 00098 00099 m_Facade.m_bEnabledEvents = true; 00100 00101 dlgConstraints.GetGotoPunk(&gotoPunk); 00102 GotoViolatorObject(gotoPunk); 00103 return S_OK; 00104 } 00105 00106 // Evaluate All Constraints 00107 00108 CComPtr<IMgaTerritory> spTerritory; 00109 COMTHROW( m_spProject->CreateTerritory( NULL, &spTerritory ) ); 00110 COMTHROW( m_spProject->BeginTransaction( spTerritory, TRANSACTION_READ_ONLY ) ); 00111 00112 try { 00113 00114 if ( ! o && ! os ) 00115 m_Facade.EvaluateAll(&gotoPunk); 00116 else if ( o ) { 00117 CComPtr<IMgaObject> spObject; 00118 COMTHROW( spTerritory->OpenObj( o, &spObject ) ); 00119 m_Facade.Evaluate( spObject, &gotoPunk ); 00120 } 00121 if ( os ) { 00122 OclCommonEx::ObjectVector vecObjects; 00123 MGACOLL_ITERATE( IMgaObject, os ) { 00124 CComPtr<IMgaObject> spObject; 00125 COMTHROW( spTerritory->OpenObj( MGACOLL_ITER, &spObject ) ); 00126 vecObjects.push_back( spObject.p ); 00127 } MGACOLL_ITERATE_END; 00128 m_Facade.Evaluate( vecObjects, &gotoPunk ); 00129 } 00130 COMTHROW( p->AbortTransaction() ); 00131 // ?? !! gotoPunk 00132 GotoViolatorObject(gotoPunk); 00133 00134 00135 } catch ( hresult_exception hEx ) { 00136 COMTHROW( p->AbortTransaction() ); 00137 throw hEx; 00138 } 00139 00140 } COMCATCH( ; ) 00141 00142 } 00143 00144 STDMETHODIMP CConstraintMgr::GlobalEvent( globalevent_enum event ) 00145 { 00146 AFX_MANAGE_STATE( AfxGetStaticModuleState() ); 00147 00148 switch( event ) { 00149 case GLOBALEVENT_CLOSE_PROJECT: { 00150 m_spAddOn = NULL; 00151 break; 00152 } 00153 00154 case GLOBALEVENT_COMMIT_TRANSACTION: 00155 case GLOBALEVENT_ABORT_TRANSACTION: { 00156 break; 00157 } 00158 00159 case GLOBALEVENT_NOTIFICATION_READY: { 00160 break; 00161 } 00162 } 00163 00164 return S_OK; 00165 } 00166 00167 STDMETHODIMP CConstraintMgr::ObjectEvent( IMgaObject* obj, unsigned long eventmask, VARIANT v ) 00168 { 00169 AFX_MANAGE_STATE( AfxGetStaticModuleState() ); 00170 00171 if ( ! m_Facade.m_bEnabled || ! m_Facade.m_bEnabledInteractions || ! m_Facade.m_bEnabledEvents ) { 00172 return S_OK; 00173 } 00174 ASSERT(!(eventmask & OBJEVENT_MOUSEOVER)); // shouldn't receive these events because of put_EventMask 00175 ASSERT(!(eventmask & OBJEVENT_PRE_DESTROYED)); 00176 00177 COMTRY { 00178 return m_Facade.Evaluate( obj, eventmask); 00179 } COMCATCH( ; ) 00180 } 00181 00182 STDMETHODIMP CConstraintMgr::Initialize( IMgaProject *p ) 00183 { 00184 AFX_MANAGE_STATE( AfxGetStaticModuleState() ); 00185 00186 m_spProject = p; 00187 00188 CreateComObject( m_spEventSink ); 00189 m_spEventSink->cm = this; 00190 00191 m_spAddOn = NULL; 00192 00193 COMTRY { 00194 COMTHROW( m_spProject->CreateAddOn( m_spEventSink, &m_spAddOn ) ); 00195 COMTHROW( m_spAddOn->put_EventMask( ~(OBJEVENT_MOUSEOVER | OBJEVENT_PRE_DESTROYED) ) ); 00196 00197 CComPtr<IMgaTerritory> spTerritory; 00198 COMTHROW( m_spProject->CreateTerritory( NULL, &spTerritory ) ); 00199 COMTHROW( m_spProject->BeginTransaction( spTerritory, TRANSACTION_READ_ONLY ) ); 00200 00201 m_Facade.Initialize( p ); 00202 00203 CWaitCursor crsrWait; 00204 00205 OclGme::ConstraintFunctionVector vecConstraintFunctions; 00206 m_Facade.LoadMetaConstraintFunctions( vecConstraintFunctions ); 00207 OclGme::ConstraintVector vecConstraints; 00208 m_Facade.LoadMetaConstraints( vecConstraints ); 00209 m_Facade.LoadUserConstraints( vecConstraints ); 00210 00211 crsrWait.Restore(); 00212 00213 if ( ! vecConstraints.empty() || ! vecConstraintFunctions.empty() ) { 00214 CSyntacticSemanticDialog dlgErrors; 00215 for ( unsigned int i = 0 ; i < vecConstraintFunctions.size() ; i++ ) 00216 dlgErrors.AddItem( vecConstraintFunctions[ i ] ); 00217 for ( unsigned int i = 0 ; i < vecConstraints.size() ; i++ ) 00218 dlgErrors.AddItem( vecConstraints[ i ] ); 00219 dlgErrors.DoModal(); 00220 } 00221 00222 COMTHROW( m_spProject->CommitTransaction() ); 00223 00224 return S_OK; 00225 00226 } COMCATCH( ; ) 00227 } 00228 00229 STDMETHODIMP CConstraintMgr::Enable( VARIANT_BOOL enabled ) 00230 { 00231 AFX_MANAGE_STATE(AfxGetStaticModuleState()) 00232 00233 m_Facade.m_bEnabled = ( enabled ) ? true : false; 00234 return S_OK; 00235 } 00236 00237 STDMETHODIMP CConstraintMgr::get_InteractiveMode( VARIANT_BOOL* enabled ) 00238 { 00239 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00240 *enabled = ( m_Facade.m_bEnabledInteractions ) ? VARIANT_TRUE : VARIANT_FALSE; 00241 return S_OK; 00242 } 00243 00244 STDMETHODIMP CConstraintMgr::put_InteractiveMode( VARIANT_BOOL enabled ) 00245 { 00246 AFX_MANAGE_STATE(AfxGetStaticModuleState()) 00247 00248 m_Facade.m_bEnabledInteractions = ( enabled ) ? true : false; 00249 return S_OK; 00250 } 00251 00252 STDMETHODIMP CConstraintMgr::get_ComponentParameter( BSTR name, VARIANT *pVal ) 00253 { 00254 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00255 return S_OK; 00256 } 00257 00258 STDMETHODIMP CConstraintMgr::put_ComponentParameter(BSTR name, VARIANT newVal) 00259 { 00260 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00261 return S_OK; 00262 } 00263 00264 STDMETHODIMP CConstraintMgr::get_Paradigm( BSTR *pname ) 00265 { 00266 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00267 if( ! pname ) 00268 return E_MGA_OUTPTR_NULL; 00269 if( *pname ) 00270 return E_MGA_OUTPTR_NONEMPTY; 00271 *pname = CComBSTR( MGR_PARADIGM ).Detach(); 00272 return S_OK; 00273 } 00274 00275 STDMETHODIMP CConstraintMgr::get_ComponentName( BSTR *pname ) 00276 { 00277 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00278 if( ! pname ) 00279 return E_MGA_OUTPTR_NULL; 00280 if( *pname ) 00281 return E_MGA_OUTPTR_NONEMPTY; 00282 *pname = CComBSTR( MGR_COMPONENT_NAME ).Detach(); 00283 return S_OK; 00284 } 00285 00286 STDMETHODIMP CConstraintMgr::get_ComponentProgID( BSTR *pname ) 00287 { 00288 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00289 if( !pname ) 00290 return E_MGA_OUTPTR_NULL; 00291 if( *pname ) 00292 return E_MGA_OUTPTR_NONEMPTY; 00293 *pname = CComBSTR( MGR_COMPONENT_PROGID ).Detach(); 00294 return S_OK; 00295 } 00296 00297 STDMETHODIMP CConstraintMgr::get_ComponentType( componenttype_enum *ct ) 00298 { 00299 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00300 if( ! ct ) 00301 return E_MGA_OUTPTR_NULL; 00302 *ct = MGR_CETYPE; 00303 return S_OK; 00304 } 00305 00306 STDMETHODIMP CConstraintMgr::Invoke(IMgaProject *p, IMgaFCOs *os, long k) { 00307 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00308 COMTRY { 00309 CComPtr<IMgaFCO> o; 00310 if(os) { 00311 long l; 00312 COMTHROW(os->get_Count(&l)); 00313 if(l > 0) COMTHROW(os->get_Item(1, &o)); 00314 } 00315 CComPtr<IMgaTerritory> t; 00316 COMTHROW(p->get_ActiveTerritory(&t)); 00317 COMTHROW(p->AbortTransaction()); 00318 COMTHROW(ObjectsInvokeEx(p, o, NULL, k)); 00319 COMTHROW(p->BeginTransaction(t, TRANSACTION_GENERAL)); 00320 } COMCATCH(;) 00321 } 00322 00323 STDMETHODIMP CConstraintMgr::InvokeEx(IMgaProject *p, IMgaFCO *o, IMgaFCOs *, long k) 00324 { 00325 AFX_MANAGE_STATE( AfxGetStaticModuleState());//z 00326 return ObjectsInvokeEx( p, o, NULL, k ); 00327 }