00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef TOOL_H
00010 #define TOOL_H
00011
00012
00013
00014 #include <QtGui>
00015 #include "IrisGui.h"
00016 #include "GlobalDefines.h"
00017 #include "ui_Settings.h"
00018
00019
00020
00021 class OutputInformation;
00022 class Slice;
00023 class ToolFlag;
00024 class ToolFlagElement;
00025 class VolumeIndex;
00026 class AliasType;
00027 namespace Iris { class IrisTests; }
00028
00029 class Tool : public QWidget
00030 {
00031 Q_OBJECT
00032
00033 friend IrisGui::~IrisGui();
00034 friend class Iris::IrisTests;
00035
00036 public:
00037 enum ToolType
00038 {
00039 NONE = 0,
00040 IR_FFT,
00041 IR_REFINE_TRANSLATE,
00042 IR_REFINE_GRID,
00043 IR_MOSAIC_OVERRIDE,
00044 IR_ASSEMBLE,
00045 IR_STOS_BRUTE,
00046 IR_STOS_GRID,
00047 IR_ADD_TRANSFORMS,
00048 IR_STOM,
00049 IR_STOS_OVERRIDE,
00050 SNAPSHOT,
00051 IR_BLOB,
00052 IR_CLAHE,
00053 SMART_IMPORT = 20,
00054 IR_ASSEMBLE_TILED = 22,
00055 INVALID_TOOL = 32767
00056 };
00057
00058 public:
00059
00060 Tool( QXmlStreamReader& xml, ToolType type );
00061 ~Tool();
00062
00063 static QString GetToolName( Tool::ToolType type );
00064 static QString GetIconName( Tool::ToolType type );
00065 static QString GetDetails( Tool::ToolType type );
00066
00067 QString GetToolName() { return name; }
00068 QString GetProcessName() { return processName; }
00069 QString GetIconName() { return icon; }
00070 QString GetDetails() { return description; }
00071 QString GetShortDetails() { return shortDescription; }
00072 QString GetFriendlyName() { return friendlyName; }
00073 QString GetSearchName() { return InsertAliasId( searchName ); }
00074 QString GetSaveName() { return InsertAliasId( saveName ); }
00075 QString InsertAliasId( const QString &addTo );
00076 bool GetRunPerImage() { return runPerImage; }
00077 QStringList GetFilterList( const QString &tag = "" ) { return inputFilters[tag]; }
00078 bool RunPerChannel() { return runPerChannel; }
00079 int GetGroupType() { return groupId; }
00080
00081 static bool FileToComboBoxDetails(const QString &fileName, QString &properName, QIcon &icon);
00082 QStringList GetPossibleInputFiles( QList<VolumeIndex*> *slices, const QString &inputTag );
00083 QHash<QString, QStringList> GetAllPossibleInputFiles( QList<VolumeIndex*> *indices );
00084 bool FilenameMatchesSearch( const QString &filename );
00085
00086
00087 void SetIndices( QList<VolumeIndex*> *indices ) { this->activeIndices = indices; }
00088 void QueueOnly( bool queueOnly ) { this->queueOnly = queueOnly; }
00089 void SetUpstreamInput( const QStringList &upstreams ) { this->upstreamArgs = upstreams; }
00090 void ClearUpstreamInput() { this->upstreamArgs.clear(); }
00091 void SetAlias( ToolAlias *alias ) { this->currentAlias = alias; }
00092 void ClearAlias() { this->currentAlias = NULL; }
00093 ToolAlias *GetAlias() { return this->currentAlias; }
00094
00095
00096 Tool::ToolType GetToolType() { return type; }
00097 void SaveCustomArgs( QXmlStreamWriter& xml, bool loadSettings = true );
00098 void LoadCustomArgs( QXmlStreamReader& xml, QHash<QString, ToolFlag *> *newFlags = NULL );
00099
00100 static ToolAlias* LoadNextTool( QXmlStreamReader &xml, int &separator,
00101 bool onlyOverride = false, QHash<QString, ToolFlag *> *newFlags = NULL );
00102
00103 bool RunOnSections() { return runOnSections; }
00104 bool NoOperation() { return runType == 2; }
00105 bool RunInTerminal() { return runType == 3; }
00106
00107 void ToolCompletedSuccessfully( int timeTaken ) { if ( timesFinished == 0 ) totalTime = 0; totalTime += ((float)timeTaken)/ 1000.0f; timesFinished++; }
00108 float TotalRuntime() { return totalTime; }
00109 float AverageRuntime() { return totalTime / (timesFinished == 0 ? 1.0f : (float)timesFinished); }
00110
00111 QHash<QString, ToolFlag *> GetFlags() { return flags; }
00112 void OverrideFlags( QHash<QString, ToolFlag *> *flags ) { overrideFlags = flags; }
00113 void ClearOverride() { overrideFlags = NULL; }
00114 bool CanRunAfter( ToolAlias *before );
00115
00116 static Tool *GetTool( ToolType type ) { return (toolList.contains(type)) ? toolList[type] : NULL; }
00117 static Tool *GetOperable( int idx ) { return (operableTools.contains(idx)) ? operableTools[idx] : NULL; }
00118 static QHash<int, Tool *> &GetOperables() { return operableTools; }
00119 static int ConvertToGroupId( const QString & groupStr );
00120
00121 int QueueProcess( const QString &prog, VolumeIndex *index );
00122 int NumThreads() { return (numThreads == -1) ? QThread::idealThreadCount() : numThreads; }
00123 int SectionsRequired() { return sectionsRequired; }
00124
00125 bool ChecksValid();
00126 QString PrintValidChecks();
00127
00128 public slots:
00129 void Run( bool askUserInput = true, bool userRequest = true, bool runOnAllSlices = false );
00130 void SaveCustomArgs();
00131 bool ExecuteSettingsDialog( QHash<QString, ToolFlag *> &flags, bool askUserInput = true, bool onlyOkButton = false );
00132 void Clean();
00133
00134
00135
00136 protected:
00137 QString name;
00138 QString processName;
00139 QString icon;
00140 QString description;
00141 QString shortDescription;
00142 QString friendlyName;
00143 QString saveName;
00144 QString searchName;
00145 QHash<QString, QStringList> inputFilters;
00146 Tool::ToolType type;
00147
00148 QStringList checkList;
00149 QStringList invalidList;
00150
00151 bool singleRun;
00152 bool runOnSections;
00153 bool useSlicesAsInput;
00154 bool runPerImage;
00155 bool runPerChannel;
00156 int runType;
00157 int numThreads;
00158 int sectionsRequired;
00159 int groupId;
00160
00161 float totalTime;
00162 int timesFinished;
00163 ToolAlias *currentAlias;
00164
00165
00166
00167 protected:
00168 QHash<QString, ToolFlag *> flags;
00169 QHash<QString, ToolFlag *> *overrideFlags;
00170
00171 static QHash<ToolType, Tool*> toolList;
00172 static QHash<int, Tool *> operableTools;
00173
00174 bool queueOnly;
00175 QList<VolumeIndex*> *activeIndices;
00176
00177 QStringList upstreamArgs;
00178 };
00179
00180
00181
00182
00183
00184 typedef unsigned int InnerAliasType;
00185 class AliasType
00186 {
00187 public:
00188 AliasType( Tool::ToolType type, unsigned short id ) { this->type = ((type << 16) | (id & 0xffff)); }
00189
00190 Tool::ToolType Type() const { return (Tool::ToolType)(type >> 16); }
00191 short Id() const { return (short)(type & 0xffff); }
00192 InnerAliasType InnerType() const { return type; }
00193
00194 bool operator==( const AliasType& aliasType ) const { return (type == aliasType.type); }
00195 bool operator<( const AliasType& aliasType ) const { return (Type() < aliasType.Type() || (Type() == aliasType.Type() && Id() < aliasType.Id())); }
00196 bool operator>( const AliasType& aliasType ) const { return (Type() > aliasType.Type() || (Type() == aliasType.Type() && Id() > aliasType.Id())); }
00197
00198 private:
00199 InnerAliasType type;
00200 };
00201
00202
00203
00204
00205 class ToolAlias : public QObject
00206 {
00207 Q_OBJECT
00208
00209 friend QWidget* Pipeline::NewLabel( int type, Tool *tool, ToolAlias *alias );
00210 friend IrisGui::~IrisGui();
00211
00212 public:
00213 static ToolAlias *NewAlias( Tool *tool, int id ) { ToolAlias *alias = new ToolAlias( tool, id ); aliasHash[alias->Type().InnerType()] = alias; return alias; }
00214 static void DeleteAlias( InnerAliasType internalId ) { delete aliasHash[internalId]; aliasHash.remove( internalId ); }
00215 ~ToolAlias();
00216
00217 Tool *BaseTool() const { return baseTool; }
00218 void SetFlags( const QHash<QString, ToolFlag *> &flags ) { this->flags.unite( flags ); }
00219 void OverrideFlags() { baseTool->OverrideFlags( &flags ); }
00220 void ClearOverride() { baseTool->ClearOverride(); }
00221 void RefreshProgress();
00222 QString GetSearchName();
00223 AliasType Type() const { return type; }
00224
00225 void InitializeAction();
00226 void MoveAction( ToolAlias *beforeAlias );
00227 void Edit( bool requireInput = true );
00228 void SetValid( bool validInput ) { this->validInput = validInput; }
00229 bool IsValid() { return this->validInput; }
00230
00231 ToolAlias& operator=(const ToolAlias &rhs);
00232
00233 static ToolAlias *GetAlias( AliasType aliasType ) { InnerAliasType type = aliasType.InnerType(); return (aliasHash.contains(type)) ? aliasHash[type] : NULL; }
00234 static QHash<InnerAliasType, ToolAlias *> GetAllAliases() { return aliasHash; }
00235
00236 public slots:
00237 void Clean( bool allAfter = false );
00238 void CleanAllAfter();
00239 void Run( bool askUserInput = true, bool userRequest = true, bool runOnAllSlices = false );
00240
00241 protected:
00242 bool eventFilter( QObject *object, QEvent *event );
00243
00244 private:
00245 ToolAlias( Tool* baseTool, int id ) : type( baseTool->GetToolType(), id ), action(this), cleanAction(this), cleanAllAction(this) { iconLabel = NULL; progressBar = NULL; arrowLabel = NULL; this->baseTool = baseTool; validInput = false; }
00246
00247 Tool *baseTool;
00248 QHash<QString, ToolFlag *> flags;
00249 QLabel *iconLabel;
00250 QLabel *arrowLabel;
00251 QProgressBar *progressBar;
00252 bool validInput;
00253
00254 static QHash<InnerAliasType, ToolAlias *> aliasHash;
00255 AliasType type;
00256
00257 QAction action;
00258 QAction cleanAction;
00259 QAction cleanAllAction;
00260 };
00261
00262
00263 #endif