GME  13
MgaClosure.cpp
Go to the documentation of this file.
00001 #include "stdafx.h"
00002 
00003 #include "MgaClosure.h"
00004 #include "ClosureDlg.h"
00005 #include "ClosureRes.h"
00006 #include "ClosureSmart.h"
00007 #include "MakeClosure.h"
00008 #include "ClosureSimple.h"
00009 #include "MakeSimpleClosure.h"
00010 
00011 const wchar_t* CMgaClosure::m_projLastClosureNode = L"lastClosureId";
00012 
00013 STDMETHODIMP CMgaClosure::GetLastClosureId( IMgaProject* p_project, long* p_pMarkWith)
00014 {
00015         AFX_MANAGE_STATE( AfxGetStaticModuleState());
00016 
00017         COMTRY {
00018                 if( !p_pMarkWith) return E_INVALID_USAGE;
00019                 if( !p_project)   return E_INVALID_USAGE;
00020 
00021                 CComObjPtr<IMgaFolder> rf;
00022                 COMTHROW( p_project->get_RootFolder( PutOut( rf)));
00023 
00024                 CString cst0;
00025                 COMTHROW( rf->get_RegistryValue( CComBSTR( m_projLastClosureNode), PutOut( cst0)));
00026                 
00027                 int t_val = -1;
00028                 if( 1 == _stscanf( (LPCTSTR) cst0, _T("%i"), &t_val))
00029                 {
00030                         *p_pMarkWith = t_val;
00031                 }
00032                 else
00033                 {
00034                         *p_pMarkWith = -1;
00035                 }
00036         }
00037         COMCATCH(;)
00038 }
00039 
00040 STDMETHODIMP CMgaClosure::PutLastClosureId( IMgaProject* p_project, long p_iMarkWith)
00041 {
00042         AFX_MANAGE_STATE( AfxGetStaticModuleState());
00043         COMTRY {
00044                 if( !p_project)  return E_INVALID_USAGE;
00045                 if( p_iMarkWith == -1) return E_INVALID_USAGE;
00046 
00047                 CComObjPtr<IMgaFolder> rf;
00048                 COMTHROW( p_project->get_RootFolder( PutOut( rf)));
00049 
00050                 CString cst;
00051                 cst.Format( _T("%i"), p_iMarkWith);
00052 
00053                 COMTHROW( rf->put_RegistryValue( CComBSTR( m_projLastClosureNode), CComBSTR( cst)));
00054         }
00055         COMCATCH(;)
00056 }
00057 
00058 STDMETHODIMP CMgaClosure::SelectiveClosureDlg
00059         ( VARIANT_BOOL  p_folderContainmentNeeded
00060         , VARIANT_BOOL* p_refersTo           , VARIANT_BOOL* p_referredBy
00061         , VARIANT_BOOL* p_connections        , VARIANT_BOOL* p_connsThroughRefport
00062         , VARIANT_BOOL* p_setMembers         , VARIANT_BOOL* p_memberOfSets
00063         , VARIANT_BOOL* p_modelContainment   , VARIANT_BOOL* p_partOfModels
00064         , VARIANT_BOOL* p_folderContainment  , VARIANT_BOOL* p_partOfFolders
00065         , VARIANT_BOOL* p_baseTypeOf         , VARIANT_BOOL* p_derivedTypesOf
00066         , long* p_libraryElementHandling          // 0: stubs, 1: stop, 2: continue
00067         , long* p_wrappingMode                    // 0: miniproject, 1: automatic, 2: as is
00068         , long* p_kindFilter                      // -1 = all, otherwise calculate the 0b000rsamf mask, where f = Folders, m = Models, a = Atoms, s = Sets, r = References
00069         , long* p_markWith                        // mark all objects in closure
00070         , long* p_options
00071         , VARIANT_BOOL* p_directionDown
00072         , VARIANT_BOOL* p_copyToFile              // file or clipboard
00073         , VARIANT_BOOL* p_okPressed               // how ended the dialog
00074         , BSTR* p_userSelFileName
00075         )
00076 {
00077         AFX_MANAGE_STATE( AfxGetStaticModuleState());
00078 
00079         if 
00080          (  !p_refersTo           || !p_referredBy
00081          || !p_connections        || !p_connsThroughRefport
00082          || !p_setMembers         || !p_memberOfSets
00083          || !p_modelContainment   || !p_partOfModels
00084          || !p_folderContainment  || !p_partOfFolders
00085          || !p_baseTypeOf         || !p_derivedTypesOf
00086          || !p_libraryElementHandling 
00087          || !p_wrappingMode
00088          || !p_kindFilter
00089          || !p_markWith
00090          || !p_options
00091          || !p_directionDown
00092          || !p_copyToFile
00093          || !p_okPressed
00094          || !p_userSelFileName)
00095           return E_INVALID_USAGE;
00096 
00097         CWaitCursor w;
00098         CClosureDlg dlg;
00099         dlg.m_activeFolderContainment = p_folderContainmentNeeded == VARIANT_TRUE;
00100         if( *p_markWith != -1) dlg.m_iMarkVal = *p_markWith;
00101         *p_okPressed = VARIANT_FALSE;
00102 
00103         if ( dlg.DoModal() == IDOK)
00104         {
00105                 *p_refersTo               = dlg.m_bRefersTo           ? VARIANT_TRUE: VARIANT_FALSE;
00106                 *p_referredBy             = dlg.m_bReferredBy         ? VARIANT_TRUE: VARIANT_FALSE;
00107                 *p_connections            = dlg.m_bConnection         ? VARIANT_TRUE: VARIANT_FALSE;
00108                 *p_connsThroughRefport    = dlg.m_bRefPortConnection  ? VARIANT_TRUE: VARIANT_FALSE;
00109                 *p_setMembers             = dlg.m_bSetMember          ? VARIANT_TRUE: VARIANT_FALSE;
00110                 *p_memberOfSets           = dlg.m_bMemberOfSets       ? VARIANT_TRUE: VARIANT_FALSE;
00111                 *p_modelContainment       = dlg.m_bContainment        ? VARIANT_TRUE: VARIANT_FALSE;
00112                 *p_partOfModels           = dlg.m_bPartOfModels       ? VARIANT_TRUE: VARIANT_FALSE;
00113                 *p_folderContainment      = dlg.m_bFolderContainment  ? VARIANT_TRUE: VARIANT_FALSE;
00114                 *p_partOfFolders          = dlg.m_bPartOfFolders      ? VARIANT_TRUE: VARIANT_FALSE;
00115                 *p_baseTypeOf             = dlg.m_bBaseTypes          ? VARIANT_TRUE: VARIANT_FALSE;
00116                 *p_derivedTypesOf         = dlg.m_bDerivedTypes       ? VARIANT_TRUE: VARIANT_FALSE;
00117 
00118                 *p_libraryElementHandling = dlg.m_libraryHandling;
00119                 *p_wrappingMode           = dlg.m_wrappingOption;
00120                 *p_kindFilter             = dlg.calcKindMask();
00121                 *p_markWith               = dlg.m_bMarkObjs ? dlg.m_iMarkVal : -1;
00122                 *p_options                = (dlg.m_libraryHandling == 0)?0x1:0; // in case of "stubs" set the options to 1
00123                 *p_directionDown          = dlg.m_direction    == 1 ? VARIANT_TRUE : VARIANT_FALSE;
00124                 *p_copyToFile             = dlg.m_outputOption == 1 ? VARIANT_TRUE : VARIANT_FALSE;
00125                 *p_okPressed              = VARIANT_TRUE;
00126 
00127                 CComBSTR filename( dlg.m_strOutputFile);
00128                 *p_userSelFileName = filename.Detach();
00129         }
00130         return S_OK;
00131 }
00132 
00133 STDMETHODIMP CMgaClosure::SelectiveClosureCalc
00134         ( IMgaFCOs *p_initSelFcos          , IMgaFolders *p_initSelFolders
00135         , VARIANT_BOOL p_refersTo          , VARIANT_BOOL p_referredBy
00136         , VARIANT_BOOL p_connections       , VARIANT_BOOL p_connsThroughRefport
00137         , VARIANT_BOOL p_setMembers        , VARIANT_BOOL p_memberOfSets
00138         , VARIANT_BOOL p_modelContainment  , VARIANT_BOOL p_partOfModels
00139         , VARIANT_BOOL p_folderContainment , VARIANT_BOOL p_partOfFolders
00140         , VARIANT_BOOL p_baseTypeOf        , VARIANT_BOOL p_derivedTypesOf
00141         , long p_libraryElementHandling          // 0: stubs, 1: stop, 2: continue
00142         , long p_wrapping                        // 0: miniproject, 1: automatic, 2: as is
00143         , long p_kindFilter                      // -1 = all, otherwise calculate the 0b000rsamf mask, where f = Folders, m = Models, a = Atoms, s = Sets, r = References
00144         , long p_markWith                        // mark all objects in closure
00145         , VARIANT_BOOL p_directionDown
00146         , IMgaFCOs** p_selFcos, IMgaFolders** p_selFolders
00147         , IMgaFCOs** p_topFcos, IMgaFolders** p_topFolders
00148         , VARIANT_BOOL* p_topCollectionsFilled
00149         , BSTR* p_accKinds
00150         )
00151 {
00152         if 
00153          (  ! p_selFcos
00154          || ! p_selFolders
00155          || ! p_topFcos
00156          || ! p_topFolders
00157          || ! p_topCollectionsFilled
00158          || ! p_accKinds)
00159           return E_INVALID_USAGE;
00160 
00161         int modcont = p_modelContainment  == VARIANT_TRUE? 1: 0;
00162         int folcont = p_folderContainment == VARIANT_TRUE? 1: 0;
00163         int partmod = p_partOfModels      == VARIANT_TRUE? 1: 0;
00164         int partfol = p_partOfFolders     == VARIANT_TRUE? 1: 0;
00165 
00166         CMakeClosure mc
00167                 ( p_initSelFcos
00168                 , p_initSelFolders
00169                 , p_refersTo            == VARIANT_TRUE? 1 : 0
00170                 , p_referredBy          == VARIANT_TRUE? 1 : 0
00171                 , p_connections         == VARIANT_TRUE? 1 : 0
00172                 , p_connsThroughRefport == VARIANT_TRUE? 1 : 0
00173                 , p_setMembers          == VARIANT_TRUE? 1 : 0
00174                 , p_memberOfSets        == VARIANT_TRUE? 1 : 0 
00175                 // compare the containment options with the direction option
00176                 , p_directionDown  == VARIANT_TRUE  ? modcont:0
00177                 , p_directionDown  == VARIANT_FALSE ? partmod:0
00178                 , p_directionDown  == VARIANT_TRUE  ? folcont:0
00179                 , p_directionDown  == VARIANT_FALSE ? partfol:0
00180                 , p_baseTypeOf     == VARIANT_TRUE  ? 1: 0
00181                 , p_derivedTypesOf == VARIANT_TRUE  ? 1: 0
00182                 , (int) p_libraryElementHandling // == 2 // in case of "continue" ("go on") only
00183                 , (int) p_wrapping
00184                 , p_directionDown  == VARIANT_TRUE  ? 1: 0
00185                 , (int) p_kindFilter
00186                 , (int) p_markWith
00187                 );
00188 
00189         mc.process(); // do the hard job
00190 
00191         // load the results
00192         mc.getFCOs( p_selFcos);
00193         mc.getFolders( p_selFolders);
00194 
00195         bool normal_tops = !mc.noTopObjs();
00196         if ( normal_tops) // the top fcos/folds is calculated and The RootFolder is not among them
00197         {
00198                 mc.getTopFCOs( p_topFcos);
00199                 mc.getTopFolders( p_topFolders);
00200                 
00201                 *p_topCollectionsFilled = VARIANT_TRUE;
00202         }
00203         else
00204                 *p_topCollectionsFilled = VARIANT_FALSE;
00205 
00206         
00207         if( normal_tops &&               // avoid in case of non-normal tops
00208                 p_wrapping > 0 &&            // avoid in case of miniproject
00209                 mc.isAnyAccepting())         // avoid if is no accepting kind/folder
00210         {
00211                 std::string res_str;
00212 
00213                 mc.getAccKindsInString( res_str);
00214 
00215                 CComBSTR acc_kind = res_str.c_str();
00216                 *p_accKinds = acc_kind.Detach();
00217         }
00218 
00219         return S_OK;
00220 }
00221 
00222 
00223 STDMETHODIMP CMgaClosure::SmartCopy(
00224         IMgaFCOs *p_fcosIn, IMgaFolders *p_foldersIn,
00225         IMgaFCOs **p_fcosSelOut, IMgaFolders **p_foldersSelOut,
00226         IMgaFCOs **p_topFcosOut, IMgaFolders **p_topFoldersOut,
00227         int   p_optionsIn, 
00228         long *p_optionsOut,
00229         BSTR *p_accept,
00230         BSTR *p_path
00231         )
00232 {
00233         AFX_MANAGE_STATE( AfxGetStaticModuleState());
00234         ASSERT( p_optionsOut);
00235 
00236         bool res = true;
00237         CWaitCursor w;
00238         CClosureSimple dlg;
00239 
00240         bool any_cont = (p_optionsIn & 1024) == 1024; // is any container
00241         bool any_fold = (p_optionsIn & 16384) == 16384; // is any folder
00242         dlg.m_enableContainChkBox = any_cont;
00243         dlg.m_enableFolderChkBox = any_fold;
00244 
00245         res = dlg.DoModal() == IDOK;
00246 
00247         if( res)
00248         {
00249                 CSimpleSelectClosure mc
00250                         ( p_fcosIn
00251                         , p_foldersIn
00252                         , dlg.m_bCont     // need containment?
00253                         , dlg.m_bFoldCont // need folder containment?
00254                         , dlg.m_bAtom == TRUE // exclude atoms?
00255                         , dlg.m_bConn == TRUE //  -//-   conns?
00256                         , dlg.m_bRef == TRUE  //  -//-   refs?
00257                         , dlg.m_bSet == TRUE  //  -//-   sets?
00258                         );
00259 
00260                 mc.process(); // do the hard job
00261 
00262                 // load the results
00263                 mc.getFCOs( p_fcosSelOut);
00264                 mc.getFolders( p_foldersSelOut);
00265 
00266                 bool normal_tops = !mc.noTopObjs();
00267                 
00268                 if( normal_tops) // the top fcos/folds is calculated and The RootFolder is not among them
00269                 {
00270                         mc.getTopFCOs( p_topFcosOut);
00271                         mc.getTopFolders( p_topFoldersOut);
00272                 }
00273 
00274                 *p_optionsOut = 0;
00275                 //*pOptions = (dlg.m_libraryHandling == 0)?0x1:0; // in case of "stubs" set the options to 1
00276                 *p_optionsOut = (LIB_STUBS == 0)?0x1:0; // in case of "stubs" set the options to 1
00277                 *p_optionsOut = *p_optionsOut | 0x2; // dump the closure2 like attributes
00278                 *p_optionsOut = *p_optionsOut | 0x4; // smart copy signal
00279 
00280                 std::string res_str;
00281                 mc.getAccKindsInString( res_str);
00282 
00283                 CComBSTR acckind = res_str.c_str();
00284                 *p_accept = acckind.Detach();
00285 
00286                 CComBSTR name;
00287                 *p_path = name.Detach();
00288         }
00289 
00290         return S_OK;
00291 }