GME  13
MgaModel.cpp
Go to the documentation of this file.
00001 // MgaModel.cpp : Implementation of CMgaModel
00002 #include "stdafx.h"
00003 #include "MgaFCO.h"
00004 #include "MgaFilter.h"
00005 
00006 
00008 // CMgaModel
00009 
00010 HRESULT FCO::CreateChildObject(IMgaMetaRole *metar, IMgaFCO **newobj)
00011 {
00012         COMTRY_IN_TRANSACTION_MAYBE { // FIXME: with _MAYBE, e.g. GMEView doesn't get notification that the object was created
00013                 CheckWrite();
00014                 CHECK_INPTRPAR(metar);
00015                 CHECK_OUTPTRPAR(newobj);
00016                 if((long)self[ATTRID_PERMISSIONS] & ~EXEMPT_FLAG) COMTHROW(E_MGA_NOT_CHANGEABLE);
00017                 CoreObj  nobj;
00018                 CComPtr<IMgaMetaFCO> meta;
00019                 metaref_type rr;
00020                 COMTHROW(metar->get_MetaRef(&rr));
00021                 COMTHROW(metar->get_Kind(&meta));
00022 
00023                 COMTHROW(ContainerCreateFCO(meta, nobj));
00024 
00025                 nobj[ATTRID_ROLEMETA]=rr;
00026                 auto nfco = ObjForCore(nobj);
00027                 nfco->initialname();
00028 
00029                 setcheck(mgaproject, nobj, CHK_NEW);
00030 
00031                 int targetlevel = 0;
00032                 CoreObj rootp;
00033 
00034                 GetRootOfDeriv(self, rootp, &targetlevel);
00035                 if(targetlevel >= 0) ReDeriveNewObj(mgaproject, nobj, targetlevel+1);
00036                 docheck(mgaproject);
00037 
00038                 nfco->SelfMark(OBJEVENT_CREATED);
00039                 SelfMark(OBJEVENT_NEWCHILD);
00040                 nfco->getinterface(newobj);
00041         }
00042         COMCATCH_IN_TRANSACTION_MAYBE(;);       
00043 
00044 }
00045 
00046 
00047 HRESULT FCO::get_AspectParts(IMgaMetaAspect * asp, unsigned int filter, IMgaParts **pVal) {
00048                         COMTRY {
00049                                 CHECK_OUTPTRPAR(pVal);
00050                                 CHECK_INPTRPAR(asp);
00051 
00052                                 CComPtr<IMgaMetaModel> pmm;
00053                                 COMTHROW(asp->get_ParentModel(&pmm));
00054                                 CComPtr<IMgaMetaFCO> mm;
00055                                 COMTHROW(get_Meta(&mm));
00056                                 if(!mm.IsEqualObject(pmm)) return E_META_INVALIDASPECT;
00057 
00058 
00059 #ifdef OWN_META                         
00060                                 CComPtr<IMgaMetaRoles> metars;  
00061                                 COMTHROW(asp->get_Roles(filter, &metars));
00062                                 std::set<metaref_type> mrefs;
00063                                 MGACOLL_ITERATE(IMgaMetaRole, metars) {
00064                                                 metaref_type r;                                         
00065                                                 COMTHROW(MGACOLL_ITER->get_MetaRef(&r));
00066                                                 mrefs.insert(r);
00067                                 }
00068                                 MGACOLL_ITERATE_END;
00069 #else
00070                                 CComPtr<IMgaMetaParts> metaps;  
00071                                 COMTHROW(asp->get_Parts(&metaps));
00072 #pragma warning(push,3)
00073                                 std::set<metaref_type> mrefs;
00074 #pragma warning(pop)
00075                                 MGACOLL_ITERATE(IMgaMetaPart, metaps) {
00076                                                 metaref_type r;                                         
00077                                                 CComPtr<IMgaMetaRole> rr;
00078                                                 COMTHROW(MGACOLL_ITER->get_Role(&rr));
00079                                                 COMTHROW(rr->get_MetaRef(&r));
00080                                                 mrefs.insert(r);
00081                                 }
00082                                 MGACOLL_ITERATE_END;
00083 #endif
00084 
00085                                 CComPtr<IMgaFCOs> children;                                     
00086                                 COMTHROW(get_ChildFCOs(&children));
00087 
00088                                 CREATECOLLECTION_FOR(IMgaPart,q);
00089                                 MGACOLL_ITERATE(IMgaFCO, children) {
00090                                                 CComPtr<IMgaMetaRole> r;
00091                                                 COMTHROW(MGACOLL_ITER->get_MetaRole(&r));
00092                                                 metaref_type mref;                                      
00093                                                 COMTHROW(r->get_MetaRef(&mref));
00094 
00095                                             if(mrefs.find(mref) != mrefs.end()) {
00096                                                   CComPtr<IMgaPart> pp;
00097                                                   COMTHROW(MGACOLL_ITER->get_Part(asp, &pp));
00098                                                   q->Add(pp);
00099                                                 }
00100                                 }
00101                                 MGACOLL_ITERATE_END;
00102                                 *pVal = q.Detach();
00103 
00104                         } COMCATCH(;);
00105 }
00106 
00107 
00108 
00109 
00110 HRESULT FCO::GetDescendantFCOs(struct IMgaFilter *filter,struct IMgaFCOs **fcos) {
00111         COMTRY {
00112                 CHECK_OUTPTRPAR(fcos);
00113                 CHECK_INPTRPAR(filter);  // checks project in the following lines
00114                 CComPtr<IMgaProject> p;
00115                 COMTHROW(filter->get_Project(&p));
00116                 if(!COM_EQUAL(p, (IMgaProject *)mgaproject)) COMTHROW(E_MGA_FOREIGN_PROJECT);
00117 
00118                 CREATEEXCOLLECTION_FOR(MgaFCO, q);
00119                 reinterpret_cast<CMgaFilter *>(filter)->searchFCOs(self, q);
00120                 *fcos = q.Detach();
00121     }
00122     COMCATCH(;);
00123 }
00124 
00125 
00126 
00127 
00128 HRESULT FCO::AddInternalConnections(struct IMgaFCOs *ins, struct IMgaFCOs **objs) {
00129   COMTRY {
00130         bool sameobj = false;
00131         CHECK_MYINPTRSPAR(ins);
00132         if(objs && *objs && COM_EQUAL(CComPtr<IMgaFCOs>(ins), *objs)) sameobj = true;
00133         else CHECK_OUTPTRPAR(objs);
00134 
00135         CREATEEXCOLLECTION_FOR(MgaFCO, q); 
00136 
00137         typedef std::set<FCO*> colltype;
00138         colltype coll;
00139         {
00140                 MGACOLL_ITERATE(IMgaFCO, ins) {
00141                         coll.insert(ObjFor(MGACOLL_ITER));
00142                         q->Add(MGACOLL_ITER);
00143                 }
00144                 MGACOLL_ITERATE_END;
00145         }
00146         CComPtr<IMgaFCOs> childfcos;
00147         get_ChildFCOs(&childfcos);
00148         MGACOLL_ITERATE(IMgaFCO, childfcos) {
00149                 objtype_enum t;
00150                 COMTHROW(MGACOLL_ITER->get_ObjType(&t));
00151                 if(t == OBJTYPE_CONNECTION) {
00152                         bool skip =false;
00153                         if(coll.find(ObjFor(MGACOLL_ITER)) != coll.end()) skip = true; 
00154                         else {
00155                                 CComQIPtr<IMgaSimpleConnection> conn = MGACOLL_ITER;
00156                                 ASSERT(conn);
00157                                 {
00158                                         CComPtr<IMgaFCOs> ff;
00159                                         COMTHROW(conn->get_SrcReferences(&ff));
00160                                         long ll;
00161                                         COMTHROW(ff->get_Count(&ll));
00162                                         CComPtr<IMgaFCO> ntgt;
00163                                         if(ll == 0) { COMTHROW(conn->get_Src(&ntgt)); }
00164                                         else { COMTHROW(ff->get_Item(1, &ntgt)); }
00165                                         colltype::iterator colli, collb = coll.begin(), colle = coll.end();
00166                                         for(colli = collb; colli != colle; ++colli) {
00167                                                 CComPtr<IMgaFCO> pp;
00168                                                 (*colli)->getinterface(&pp);
00169                                                 if(ObjFor(ntgt)->IsDescendantOf(pp)) {
00170                                                         break;
00171                                                 }
00172                                         }
00173                                         if(colli == colle) skip = true;
00174                                 }
00175                                 if(!skip) {
00176                                         CComPtr<IMgaFCOs> ff;
00177                                         COMTHROW(conn->get_DstReferences(&ff));
00178                                         long ll;
00179                                         COMTHROW(ff->get_Count(&ll));
00180                                         CComPtr<IMgaFCO> ntgt;
00181                                         if(ll == 0) { COMTHROW(conn->get_Dst(&ntgt)); }
00182                                         else { COMTHROW(ff->get_Item(1, &ntgt)); }
00183                                         colltype::iterator colli, collb = coll.begin(), colle = coll.end();
00184                                         for(colli = collb; colli != colle; ++colli) {
00185                                                 CComPtr<IMgaFCO> pp;
00186                                                 (*colli)->getinterface(&pp);
00187                                                 if(ObjFor(ntgt)->IsDescendantOf(pp)) {
00188                                                         break;
00189                                                 }
00190                                         }
00191                                         if(colli == colle) skip = true;
00192                                 }
00193                         }
00194                         if(!skip) q->Add(MGACOLL_ITER);
00195                 }
00196         }
00197         MGACOLL_ITERATE_END;
00198         if(!sameobj) *objs = q.Detach();
00199   }COMCATCH(;);
00200 }
00201 
00202