|
Isis 3.0 Application Source Code Reference |
Home |
00001 #include "Isis.h" 00002 00003 #include <sstream> 00004 00005 #include "FileList.h" 00006 #include "ControlNet.h" 00007 #include "Progress.h" 00008 #include "iTime.h" 00009 00010 using namespace std; 00011 using namespace Isis; 00012 00013 // Main program 00014 void IsisMain() { 00015 // Get user parameters 00016 UserInterface &ui = Application::GetUserInterface(); 00017 FileList filelist; 00018 if( ui.GetString("INPUTTYPE") == "LIST" ) { 00019 filelist = ui.GetFilename("FROMLIST"); 00020 } 00021 else if ( ui.GetString("INPUTTYPE") == "CNETS" ) { 00022 filelist.push_back( ui.GetFilename("FROM1") ); 00023 filelist.push_back( ui.GetFilename("FROM2") ); 00024 } 00025 Filename outfile( ui.GetFilename("TO") ); 00026 00027 //Creates a Progress 00028 Progress progress; 00029 progress.SetMaximumSteps( filelist.size() ); 00030 progress.CheckStatus(); 00031 00032 //Set up the output ControlNet with the first Control Net in the list 00033 ControlNet cnet( Filename(filelist[0]).Expanded() ); 00034 cnet.SetNetworkId( ui.GetString("ID") ); 00035 cnet.SetUserName( Isis::Application::UserName() ); 00036 cnet.SetCreatedDate( Isis::Application::DateTime() ); 00037 cnet.SetModifiedDate( Isis::iTime::CurrentLocalTime() ); 00038 cnet.SetDescription( ui.GetString("DESCRIPTION") ); 00039 00040 progress.CheckStatus(); 00041 00042 ofstream ss; 00043 if( ui.WasEntered("REPORT") ) { 00044 string report = ui.GetFilename("REPORT"); 00045 ss.open(report.c_str(),ios::out); 00046 } 00047 00048 for ( int f = 1; f < (int)filelist.size(); f ++ ) { 00049 00050 ControlNet currentnet( Filename(filelist[f]).Expanded() ); 00051 00052 //Checks to make sure the ControlNets are valid to merge 00053 if ( cnet.Target() != currentnet.Target() ) { 00054 string msg = "Input [" + currentnet.NetworkId() + "] does not target the "; 00055 msg += "same target as other Control Nets."; 00056 throw iException::Message(iException::User,msg,_FILEINFO_); 00057 } 00058 /*else if( cnet.NetworkId() == currentnet.NetworkId() ) { 00059 string msg = "Inputs have the same Network Id of ["; 00060 msg += cnet.NetworkId() + "] They are likely the same file."; 00061 throw iException::Message(iException::User,msg,_FILEINFO_); 00062 }*/ 00063 00064 //ERROR Merge 00065 if ( ui.GetString("DUPLICATEPOINTS") == "ERROR" ) { 00066 00067 //Throws an error if there is a duplicate Control Point 00068 for ( int cp=0; cp<currentnet.Size(); cp++ ) { 00069 if ( cnet.Exists(currentnet[cp]) ) { 00070 string msg = "Inputs contain the same ControlPoint. [Id="; 00071 msg += currentnet[cp].Id() + "] Set DUPLICATEPOINTS=RENAME to force the"; 00072 msg += " merge. Or, set DUPLICATEPOINTS=REPLACE to replace duplicate"; 00073 msg += " Control Points."; 00074 throw iException::Message(iException::User,msg,_FILEINFO_); 00075 } 00076 //Adds the point to the output ControlNet 00077 cnet.Add( currentnet[cp] ); 00078 } 00079 00080 } 00081 //RENAME Merge 00082 else if ( ui.GetString("DUPLICATEPOINTS") == "RENAME" ) { 00083 00084 //Adds the Control Net and gets the number of duplicate Control 00085 // Points to Log 00086 for ( int cp=0; cp<currentnet.Size(); cp++ ) { 00087 try { 00088 cnet.Find( currentnet[cp].Id() ); //This is the failing line 00089 if( ui.WasEntered("REPORT") ) { 00090 ss << "Control Point " << currentnet[cp].Id() << " from "; 00091 ss << currentnet.NetworkId() << " was renamed "; 00092 ss << currentnet.NetworkId() << currentnet[cp].Id() << endl; 00093 } 00094 currentnet[cp].SetId( currentnet.NetworkId() + currentnet[cp].Id() ); 00095 } catch ( ... ) { 00096 //then currentnet[i] was not found and no renaming took place 00097 } 00098 //Adds the point to the output ControlNet 00099 cnet.Add( currentnet[cp] ); 00100 } 00101 00102 } 00103 //REPLACE Merge 00104 else if ( ui.GetString("DUPLICATEPOINTS") == "REPLACE" ) { 00105 00106 //Adds currentnet to the ControlNet if it does not exist in cnet 00107 for ( int cp=0; cp<currentnet.Size(); cp++ ) { 00108 try { 00109 cnet.Find( currentnet[cp].Id() ); //This is the failing line 00110 if( ui.WasEntered("REPORT") ) { 00111 ss << "Control Point " << currentnet[cp].Id() << " was replaced from "; 00112 ss << currentnet.NetworkId() << endl; 00113 } 00114 cnet.Delete( currentnet[cp].Id() ); 00115 } catch ( ... ) { 00116 //then currentnet[i] was not found as was not deleted 00117 } 00118 //Adds the point to the output ControlNet 00119 cnet.Add( currentnet[cp] ); 00120 } 00121 00122 } 00123 00124 progress.CheckStatus(); 00125 } 00126 00127 //Writes out the final Control Net 00128 cnet.Write( outfile.Expanded() ); 00129 00130 }