Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #9369 Add HistoryView and HistoryItem classes.
- Loading branch information
Samuel Jackson
committed
May 15, 2014
1 parent
fb2e914
commit 9a8f330
Showing
5 changed files
with
291 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#ifndef MANTID_API_HISTORYITEM_H_ | ||
#define MANTID_API_HISTORYITEM_H_ | ||
|
||
//---------------------------------------------------------------------- | ||
// Includes | ||
//---------------------------------------------------------------------- | ||
#include "MantidAPI/DllConfig.h" | ||
#include "MantidAPI/WorkspaceHistory.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace API | ||
{ | ||
|
||
/** @class HistoryView | ||
This class wraps an algorithm history pointer to add additional functionality when creating a HistoryView. | ||
@author Samuel Jackson, ISIS, RAL | ||
@date 21/01/2008 | ||
Copyright © 2007-8 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://github.com/mantidproject/mantid>. | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
|
||
|
||
class MANTID_API_DLL HistoryItem | ||
{ | ||
public: | ||
HistoryItem(AlgorithmHistory_const_sptr algHist); | ||
HistoryItem(const HistoryItem& A); | ||
virtual ~HistoryItem() {}; | ||
|
||
bool isUnrolled() { return m_unrolled; } | ||
void unrolled(bool unrolled) { m_unrolled = unrolled; } | ||
AlgorithmHistory_const_sptr getAlgorithmHistory() { return m_algorithmHistory; } | ||
size_t numberOfChildren() { return m_algorithmHistory->childHistorySize(); } | ||
HistoryItem& operator=(const HistoryItem& A); | ||
|
||
private: | ||
AlgorithmHistory_const_sptr m_algorithmHistory; | ||
bool m_unrolled; | ||
}; | ||
|
||
} // namespace API | ||
} // namespace Mantid | ||
|
||
#endif /*MANTID_API_HISTORYITEM_H_*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#ifndef MANTID_API_HISTORYVIEW_H_ | ||
#define MANTID_API_HISTORYVIEW_H_ | ||
|
||
//---------------------------------------------------------------------- | ||
// Includes | ||
//---------------------------------------------------------------------- | ||
#include "MantidAPI/DllConfig.h" | ||
#include "MantidAPI/HistoryItem.h" | ||
#include "MantidAPI/WorkspaceHistory.h" | ||
|
||
#include <list> | ||
#include <vector> | ||
|
||
namespace Mantid | ||
{ | ||
namespace API | ||
{ | ||
|
||
/** @class HistoryView | ||
This class builds a view of the algorithm history by "unrolling" parent algorithms. | ||
@author Samuel Jackson, ISIS, RAL | ||
@date 21/01/2008 | ||
Copyright © 2007-8 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://github.com/mantidproject/mantid>. | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
|
||
|
||
class MANTID_API_DLL HistoryView | ||
{ | ||
public: | ||
HistoryView(const WorkspaceHistory& wsHist); | ||
virtual ~HistoryView() {}; | ||
|
||
void unroll(size_t index); | ||
void roll(size_t index); | ||
const std::vector<HistoryItem> getAlgorithmsList(); | ||
size_t size() { return m_historyItems.size(); } | ||
|
||
private: | ||
const WorkspaceHistory m_wsHist; | ||
std::list<HistoryItem> m_historyItems; | ||
}; | ||
|
||
} // namespace API | ||
} // namespace Mantid | ||
|
||
#endif /*MANTID_API_HISTORYVIEW_H_*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//---------------------------------------------------------------------- | ||
// Includes | ||
//---------------------------------------------------------------------- | ||
#include "MantidAPI/HistoryItem.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace API | ||
{ | ||
|
||
HistoryItem::HistoryItem(AlgorithmHistory_const_sptr algHist) | ||
: m_algorithmHistory(algHist), m_unrolled(false) | ||
{ | ||
} | ||
|
||
HistoryItem::HistoryItem(const HistoryItem& A) | ||
: m_algorithmHistory(A.m_algorithmHistory), m_unrolled(A.m_unrolled) | ||
{ | ||
} | ||
|
||
HistoryItem& HistoryItem::operator=(const HistoryItem& A) | ||
{ | ||
if( &A != this) | ||
{ | ||
m_algorithmHistory = A.m_algorithmHistory; | ||
m_unrolled = A.m_unrolled; | ||
} | ||
|
||
return *this; | ||
} | ||
|
||
} // namespace API | ||
} // namespace Mantid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
//---------------------------------------------------------------------- | ||
// Includes | ||
//---------------------------------------------------------------------- | ||
#include "MantidAPI/HistoryView.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace API | ||
{ | ||
|
||
HistoryView::HistoryView(const WorkspaceHistory& wsHist) | ||
: m_wsHist(wsHist), m_historyItems() | ||
{ | ||
//add all of the top level algorithms to the view by default | ||
const auto algorithms = wsHist.getAlgorithmHistories(); | ||
AlgorithmHistories::const_iterator iter = algorithms.begin(); | ||
for ( ; iter != algorithms.end(); ++iter) | ||
{ | ||
HistoryItem item(*iter); | ||
m_historyItems.push_back(item); | ||
} | ||
} | ||
|
||
/** | ||
* Unroll an algorithm history to export its child algorithms. | ||
* | ||
* This places each of the child algorithm histories into the | ||
* HistoryView object. The parent is retained as a marker so we can | ||
* "roll" the history back up if we want. This method does nothing if | ||
* the history object has no children | ||
* | ||
* @param index :: index of the history object to unroll | ||
* @throws std::out_of_range if the index is larger than the number of history items. | ||
*/ | ||
void HistoryView::unroll(size_t index) | ||
{ | ||
if( index >= m_historyItems.size() ) | ||
{ | ||
throw std::out_of_range("HistoryView::unroll() - Index out of range"); | ||
} | ||
|
||
//advance to the item at the index | ||
auto it = m_historyItems.begin(); | ||
std::advance (it,index); | ||
|
||
const auto history = it->getAlgorithmHistory(); | ||
const auto childHistories = history->getChildHistories(); | ||
|
||
if (!it->isUnrolled() && childHistories.size() > 0) | ||
{ | ||
//mark this record as being ignored by the script builder | ||
it->unrolled(true); | ||
|
||
++it; //move iterator forward to insertion position | ||
//insert each of the records, in order, at this position | ||
for (auto childIter = childHistories.begin(); childIter != childHistories.end(); ++childIter) | ||
{ | ||
HistoryItem item(*childIter); | ||
m_historyItems.insert(it, item); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Roll an unrolled algorithm history item and remove its children from the view. | ||
* | ||
* This removes each of the child algorithm histories (if any) and marks | ||
* the parent as being "rolled up". Note that this will recursively "roll up" any child | ||
* history objects that are also unrolled. This method does nothing if | ||
* the history object has no children. | ||
* | ||
* @param index :: index of the history object to unroll | ||
* @throws std::out_of_range if the index is larger than the number of history items. | ||
*/ | ||
void HistoryView::roll(size_t index) | ||
{ | ||
if( index >= m_historyItems.size() ) | ||
{ | ||
throw std::out_of_range("HistoryView::roll() - Index out of range"); | ||
} | ||
|
||
//advance to the item at the index | ||
auto it = m_historyItems.begin(); | ||
std::advance (it,index); | ||
|
||
// the number of records after this position | ||
const size_t numChildren = it->numberOfChildren(); | ||
if (it->isUnrolled() && numChildren > 0) | ||
{ | ||
//mark this record as not being ignored by the script builder | ||
it->unrolled(false); | ||
++it; //move to first child | ||
|
||
//remove each of the children from the list | ||
for (size_t i = 0; i < numChildren; ++i) | ||
{ | ||
//check if our children are unrolled and | ||
//roll them back up if so. | ||
if(it->isUnrolled()) | ||
{ | ||
roll(index+1); | ||
} | ||
//Then just remove the item from the list | ||
it = m_historyItems.erase(it); | ||
} | ||
} | ||
} | ||
|
||
const std::vector<HistoryItem> HistoryView::getAlgorithmsList() | ||
{ | ||
std::vector<HistoryItem> histories; | ||
histories.reserve(size()); | ||
std::copy(m_historyItems.cbegin(), m_historyItems.cend(), std::back_inserter( histories )); | ||
return histories; | ||
} | ||
|
||
} // namespace API | ||
} // namespace Mantid |