00001
00002
00003
00004
00005
00006
00007 #ifndef SECTION_H
00008 #define SECTION_H
00009
00010
00011
00012 #include "Volume.h"
00013 #include "Tool.h"
00014
00015
00016
00017 class Slice;
00018 class Section;
00019 namespace Iris { class IrisTests; }
00020
00021 struct ToolInfo
00022 {
00023 ToolInfo() : aliasType( Tool::NONE, 0 ) {}
00024 AliasType aliasType;
00025 QStringList channels;
00026 QHash<QString, QStringList> outputPaths;
00027 bool isSection;
00028
00029 bool operator==( const ToolInfo& info ) const { return ( aliasType == info.aliasType ); }
00030 bool operator<( const ToolInfo& info ) const { return ( aliasType < info.aliasType ); }
00031 bool operator>( const ToolInfo& info ) const { return ( aliasType > info.aliasType ); }
00032 };
00033
00034 class VolumeIndex
00035 {
00036 friend class Volume;
00037 friend class VolumeImporter;
00038 friend class Iris::IrisTests;
00039
00040 public:
00041 enum IndexType
00042 {
00043 SECTION,
00044 SLICE,
00045 IMAGE
00046 };
00047
00048 VolumeIndex( IndexType type );
00049 static void StaticInitialize();
00050
00051 void SaveBasic( QXmlStreamWriter &xmlWriter );
00052 void SaveDetails();
00053 void SaveToolPaths( QXmlStreamWriter &xmlWriter );
00054 IndexType Type() const { return type; }
00055 Section *GetSection();
00056 const Section *GetSection() const;
00057 Slice *GetSlice( bool first = true );
00058
00059 static QList<VolumeIndex *> ConvertToVolumeIndexList(const QList<Section *> &list);
00060 static QList<VolumeIndex *> ConvertToVolumeIndexList(const QList<Slice *> &list);
00061 static void Merge( QStringList &a, const QStringList &b );
00062 void AddToLists( const QString &channel, const QStringList &downsamples );
00063
00064 QStringList GetOutputFiles( const AliasType &type, const QString &channel, bool absolutePaths = true, bool allOfThisType = false );
00065 QStringList GetInputFiles( const QString &filter, const QString &channel, bool absolutePaths = true );
00066 QStringList GetFilesFromDisk( const QString &filter, const QString &channel, bool absolutePaths = true );
00067 bool HasFilesOnDisk( const QString &filter, const QString &channel );
00068 QStringList GetIdentifierEntryList( const QDir &dir, const QString &identifier, const QString &filter ) const;
00069
00070 QString ReplacePlaceholderDirectory( const QString &str, const QString &channel = "", bool first = true );
00071 bool GetPlaceholderDirectory( QDir &result, QString &flag, QString &dirFlag, const QString &str, const QString &channel = "", bool first = true );
00072 static bool GetPlaceholderTag( QString &winner, const QString &str );
00073 static bool TagsCompatible( const QString &left, const QString &right );
00074 static bool ComparePathsWithTags( const QString &left, const QStringList &fileList );
00075 static QString XmlToTag( const QString &xml );
00076
00077 Tool::ToolType ToolType( const QStringList &channels );
00078 bool HasRun( AliasType type, const QString &channel );
00079 QList<ToolInfo> GetAllToolsRun() { return toolsRun; }
00080
00081 QString Name() const { return name; }
00082 virtual QString ControlName() const { return ""; }
00083 virtual VolumeIndex* ControlSection() const { return NULL; }
00084 virtual void ToolFinished( const ReadiedProcess &finishedProcess );
00085 virtual void ImportListOfToolsRun( const QStringList &channels );
00086
00087 bool operator > (const VolumeIndex &rhs);
00088 bool operator < (const VolumeIndex &rhs);
00089 bool operator == (const VolumeIndex &rhs);
00090
00091 void TakeSnapshot( const QDir &path, bool reverse = false );
00092 void RestoreSnapshot( const QDir &path );
00093
00094 bool IsValid() const;
00095 bool IsValid( const QString &channel, const QString &downsample );
00096 void Invalidate();
00097 QDir StosDir();
00098 QDir MosaicDir();
00099 QDir ImageDir();
00100 QDir ImageDir( const QString &channel );
00101
00102 bool IsHardLinkedToData() { return hardLinkData; }
00103 bool MosaicDirExists() { return mosaicDir.exists(); }
00104
00105 private:
00106 void LoadToolRun( QXmlStreamReader &xml );
00107 void LoadValidDirectory( QXmlStreamReader &xml );
00108 void LoadToolPaths();
00109 int IndexOf( AliasType type ) const;
00110 QList<int> EveryIndexOf( AliasType type ) const;
00111
00112 protected:
00113 void AddTool( AliasType type, const QStringList &channels, const QHash<QString, QStringList> &outputPaths );
00114 bool AddTool( const ToolInfo &info );
00115 bool RemoveTool( const ToolInfo &info );
00116 void VerifyToolPaths();
00117
00118 protected:
00119 QList<ToolInfo> toolsRun;
00120 QHash<QString, QStringList> validChannels;
00121 bool hardLinkData;
00122 QString name;
00123 QString savePath;
00124
00125 QDir mosaicDir;
00126 QDir sliceDir;
00127
00128 bool valid;
00129
00130 private:
00131 IndexType type;
00132 bool toolPathsLoaded;
00133 static QStringList placeholders;
00134 };
00135
00136 class Section : public VolumeIndex
00137 {
00138 friend void Volume::DeleteSlice( Slice *slice, bool trueDelete );
00139 friend Slice *Volume::AddSlice( Section *section, const QString &requestedName );
00140 friend void Volume::AddSlice( Section *section, Slice *slice, int idx );
00141 friend void Volume::AddSection( Section *section, const QString &parentSection, int idx );
00142 friend void Volume::MoveSlice( Section *oldSection, int oldRow, Section *newSection, int newRow );
00143 friend void Volume::RefreshImages();
00144 friend class Iris::IrisTests;
00145
00146 public:
00147 Section( const QString &name );
00148 ~Section();
00149
00150 void Save( QXmlStreamWriter &xmlWriter );
00151
00152 QList<Slice *> GetAllSlices() { return slices; }
00153 Slice* GetSlice( int row ) { return slices[row]; }
00154 int IndexOf( Slice *slice ) { return slices.indexOf( slice ); }
00155 int NumSlices() { return slices.count(); }
00156 QString ControlName() { return (!controlName.isEmpty()) ? controlName : "None"; }
00157 VolumeIndex* ControlSection() const { return controlSection; }
00158 void SetControlSection( VolumeIndex *control ) { controlSection = control; controlName = (control != NULL) ? control->Name() : ""; }
00159
00160 void AddSlice( const QString &requestedName );
00161 void AddSlice( Slice *slice );
00162 void MoveSlice( int oldRow, Section *newSection, int newRow );
00163 void AddToolToSlice( const ToolInfo &type, Slice *slice );
00164 void RemoveToolFromSlice( const ToolInfo &info, Slice *slice );
00165 private:
00166 void CheckChildrenTools( Tool::ToolType type = Tool::NONE );
00167
00168 private:
00169 QList<Slice *> slices;
00170 QHash<InnerAliasType, int> sliceToolCount;
00171 int IndexOf( const QString &sliceName );
00172 QString controlName;
00173 VolumeIndex *controlSection;
00174
00175 };
00176
00177 class Image : public VolumeIndex
00178 {
00179 public:
00180 Image( Slice *slice, const QString &name );
00181
00182 QString ImagePath();
00183 Slice* GetSlice() { return slice; }
00184 void Move( Slice *slice, const QString &name ) { this->slice = slice; this->name = name; }
00185
00186 private:
00187 Slice *slice;
00188
00189 };
00190 std::ostream& operator<<(std::ostream &str, const Slice &s);
00191
00192 #endif