GME  13
MakeKindClosure.cpp
Go to the documentation of this file.
00001 #include "stdafx.h"
00002 #if(0) // this class is not used for smart copy anymore
00003 #include "MakeKindClosure.h"
00004 #include <algorithm>
00005 
00006 
00007 //---------------------------------------------------------------------------
00008 //  C  L  A  S  S   CKindSelectClosure
00009 //                  previous enabler of SmartCopy
00010 //---------------------------------------------------------------------------
00011 bool CKindSelectClosure::isValidSelection()
00012 {
00013         m_peculiarFcos.clear(); // reset to prevent some data left in it
00014         m_iniSelPath = ""; // not used currently in this class, only for the container
00015         m_accKind = "";
00016 
00017         checkMeta( m_selFolds, m_selFcos);// works based on the initially selected objects
00018 
00019         getAccKindsInString( m_accKind);
00020 
00021         return true;
00022 }
00023 
00024 void CKindSelectClosure::procObj( IMgaObject* obj)
00025 {
00026         ASSERT( obj != NULL );
00028         if ( m_iIntoLibraries != LIB_CONT && isInLibrary( obj)) // if no intention to step into libraries and the object is in a library then return
00029                 return;
00030 
00031         objtype_enum objtype;
00032         COMTHROW( obj->get_ObjType( &objtype) );
00033 
00034         switch( objtype)
00035         {
00036         case OBJTYPE_FOLDER:
00037                 {
00038                         if ( m_bFolderContainment)
00039                         {
00040                                 CComObjPtr<IMgaFolder> f;
00041                                 COMTHROW( ::QueryInterface( obj, f) );
00042                                 procFolder( f);
00043                         }
00044                         break;
00045                 }
00046 
00047         case OBJTYPE_MODEL:
00048                 {
00049                         if ( m_bContainment)
00050                         {
00051                                 CComObjPtr<IMgaModel> m;
00052                                 COMTHROW( ::QueryInterface( obj, m) );
00053 
00054                                 procModel( m);
00055                         }
00056                         break;
00057                 }
00058 
00059         case OBJTYPE_REFERENCE:
00060                 {
00061                         if ( m_bRefs)
00062                         {
00063                                 CComObjPtr<IMgaFCO> fco;
00064                                 COMTHROW( ::QueryInterface( obj, fco) );
00065                                 m_peculiarFcos.push_back( fco);
00066                         }
00067                         break;
00068                 }
00069 
00070         case OBJTYPE_CONNECTION:
00071                 {
00072                         if ( m_bConns)
00073                         {
00074                                 CComObjPtr<IMgaFCO> fco;
00075                                 COMTHROW( ::QueryInterface( obj, fco) );
00076                                 m_peculiarFcos.push_back( fco);
00077                         }
00078                         break;
00079                 }
00080 
00081         case OBJTYPE_SET:
00082                 {
00083                         if ( m_bSets)
00084                         {
00085                                 CComObjPtr<IMgaFCO> fco;
00086                                 COMTHROW( ::QueryInterface( obj, fco) );
00087                                 m_peculiarFcos.push_back( fco);
00088                         }
00089                         break;
00090                 }
00091 
00092         default: { }
00093         };
00094 }
00095 
00096 bool CKindSelectClosure::postValidateSelection()
00097 {
00098         return true;
00099 }
00100 
00101 void CKindSelectClosure::preProcess()
00102 {
00103         send2Console("[Smart Copy] Working...");
00104 }
00105 
00106 void CKindSelectClosure::postProcess()
00107 {
00108         // acc kinds already calculated in isValidSelection()
00109         if( m_peculiarFcos.size() > 0)
00110                 send2Console( "[Smart Copy] The following kinds may accept the copied data: " + m_accKind + ".");
00111         else //
00112                 send2Console( "[Smart Copy] No data copied.");
00113 
00114 
00115         std::sort( m_peculiarFcos.begin(), m_peculiarFcos.end(), ConnsLast());
00116 
00117         m_selFcos = m_topFcos = m_peculiarFcos;
00118         ASSERT( m_peculiarFolds.size() == 0);
00119 }
00120 
00121 //---------------------------------------------------------------------------
00122 //  C  L  A  S  S   CContainerSelectSomeKindClosure
00123 //---------------------------------------------------------------------------
00124 bool CContainerSelectSomeKindClosure::isValidSelection()
00125 {
00126         m_peculiarFcos.clear(); // reset to prevent some data left in it
00127         m_iniSelPath = "";
00128 
00129         CComBstrObj kind_name;
00130         ASSERT( m_selFcos.size() + m_selFolds.size() == 1);
00131         if( m_selFcos.size() + m_selFolds.size() != 1) return false;
00132 
00133         for( unsigned int i = 0; i < m_selFcos.size(); ++i)
00134         {
00135                 CComBSTR path;
00136                 COMTHROW( m_selFcos[i]->get_AbsPath( &path));
00137                 CopyTo( path, m_iniSelPath);
00138 
00139                 CComObjPtr<IMgaMetaFCO> k_meta;
00140                 COMTHROW( m_selFcos[i]->get_Meta( PutOut( k_meta)));
00141                 COMTHROW( k_meta->get_Name( PutOut(kind_name)) );
00142         
00143                 ASSERT( i == 0);
00144         }
00145 
00146         if( i == 0)
00147         for( unsigned int j = 0; j < m_selFolds.size(); ++j)
00148         {
00149                 CComBSTR path;
00150                 COMTHROW( m_selFolds[j]->get_AbsPath( &path));
00151                 CopyTo( path, m_iniSelPath);
00152 
00153                 CComObjPtr<IMgaMetaFolder> f_meta;
00154                 COMTHROW( m_selFolds[j]->get_MetaFolder( PutOut( f_meta)));
00155                 COMTHROW( f_meta->get_Name( PutOut(kind_name)) );
00156 
00157                 ASSERT( j == 0);
00158         }
00159 
00160         CopyTo( kind_name, m_accKind);// the acc kind is intended to be similar to the one and only container's kind
00161 
00162         return true;
00163 }
00164 
00165 void CContainerSelectSomeKindClosure::postProcess()
00166 {
00167         // m_accKind already calculated in isValidSelection()
00168         if( m_peculiarFcos.size() > 0)
00169                 send2Console( "[Smart Copy] The following container may accept the copied data: " + m_accKind + ".");
00170         else
00171                 send2Console( "[Smart Copy] The container does not contain the kinds specified. No data copied.");
00172 
00173         std::sort( m_peculiarFcos.begin(), m_peculiarFcos.end(), ConnsLast());
00174 
00175         m_selFcos = m_topFcos = m_peculiarFcos;
00176         ASSERT( m_peculiarFolds.size() == 0);
00177 }
00178 
00179 bool ConnsLast::operator()( const CComObjPtr<IMgaFCO>& p1, const CComObjPtr<IMgaFCO>& p2) const
00180 {
00181         // used for sort. 1st rule: Connections will be put in the back of the vector
00182         // 2nd rule: if the two elements are both connections or none of them is connection then sort on ID
00183         // returns true if p1 precedes p2
00184 
00185         objtype_enum objtype1, objtype2;
00186         COMTHROW( p1->get_ObjType( &objtype1));
00187         COMTHROW( p2->get_ObjType( &objtype2));
00188         bool c1 = objtype1 == OBJTYPE_CONNECTION;
00189         bool c2 = objtype2 == OBJTYPE_CONNECTION;
00190         if( c1 && c2 || !c1 && !c2)
00191         {
00192                 //return true;// the predicate must be a strict weak ordering, so let's compare the IDs
00193                 CComBstrObj bstr1, bstr2;
00194                 COMTHROW( p1->get_ID( PutOut( bstr1)));
00195                 COMTHROW( p2->get_ID( PutOut( bstr2)));
00196                 return bstr1.Compare( bstr2) < 0;
00197         }
00198         else if( c2) // && !c1
00199                 return true;
00200         else // c1
00201                 return false;
00202 }
00203 #endif