Skip to content

Commit

Permalink
Refactored the dock widget to use the info tree from the ADS. Re #7253
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Jun 21, 2013
1 parent 1c5fb65 commit 9412934
Show file tree
Hide file tree
Showing 26 changed files with 646 additions and 723 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/AnalysisDataService.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ class DLLExport AnalysisDataServiceImpl : public Kernel::DataService<API::Worksp

//@}

/// Create an info tree out of InfoNodes to describe the current state of the ADS.
Workspace::InfoNode *createInfoTree() const;

private:
/// Checks the name is valid, throwing if not
void verifyName(const std::string & name);
Expand Down
4 changes: 4 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/IEventWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ namespace API
bool skipError = false) const = 0;

virtual void clearMRU() const = 0;

protected:
/// Create and return a new InfoNode describing this workspace.
virtual InfoNode *createInfoNode() const;
};

///shared pointer to the matrix workspace base class
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDEventWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ namespace API
virtual void setCoordinateSystem(const Mantid::API::SpecialCoordinateSystem coordinateSystem) = 0;

protected:
/// Create and return a new InfoNode describing this workspace.
virtual InfoNode *createInfoNode() const;
/// Marker set to true when a file-backed workspace needs its back-end file updated (by calling SaveMD(UpdateFileBackEnd=1) )
bool m_fileNeedsUpdating;

Expand Down
4 changes: 4 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/IMDWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ namespace Mantid
/// this is the method to build table workspace from any workspace. It does not have much sence and may be placed here erroneously
virtual ITableWorkspace_sptr makeBoxTable(size_t /*start*/, size_t /* num*/)
{throw Kernel::Exception::NotImplementedError("This method is not generally implemented ");}

protected:
/// Create and return a new InfoNode describing this workspace.
virtual InfoNode *createInfoNode() const;
};

/// Shared pointer to the IMDWorkspace base class
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/ITableWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ class MANTID_API_DLL ITableWorkspace: public API::Workspace

protected:

virtual InfoNode *createInfoNode() const;

/** Resize a column.
@param c :: Pointer to the column
@param size :: New column size
Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/MatrixWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ namespace Mantid
/// Initialises the workspace. Sets the size and lengths of the arrays. Must be overloaded.
virtual void init(const std::size_t &NVectors, const std::size_t &XLength, const std::size_t &YLength) = 0;

/// Create and return a new InfoNode describing this workspace.
virtual InfoNode *createInfoNode() const;

/// A vector of pointers to the axes for this workspace
std::vector<Axis*> m_axes;

Expand Down
50 changes: 50 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/Workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,51 @@ class AnalysisDataServiceImpl;
class MANTID_API_DLL Workspace : public Kernel::DataItem
{
public:

/**
* Holds information about a workspace in a vector of strings.
* InfoNodes can contian other nodes and form a tree.
* The purpose is to be returned by the ADS for displaying in the GUI.
*/
class InfoNode
{
public:
enum IconType {Default = 0, Matrix, Group, MD, Table};
/// Constructor
InfoNode(const Workspace& workspace);
/// Constructor
InfoNode(const AnalysisDataServiceImpl*);
/// Destructor
~InfoNode();
/// Add a new line
void addLine(const std::string& line);
/// Add a new InfoNode object.
void addNode(InfoNode* node);
/// Add experiment info if workspace inherits from ExperimentInfo.
void addExperimentInfo(const Workspace& workspace);
/// Get workspace name
std::string workspaceName() const {return m_workspaceName;}
/// Get memory size
size_t getMemorySize() const {return m_memorySize;}
/// Get the info lines.
const std::vector<std::string>& lines() const {return m_info;}
/// Get the child nodes.
const std::vector<InfoNode*>& nodes() const {return m_nodes;}
/// Get icon type
IconType getIconType() const {return m_icon;}
private:
/// Information about a single workspace. Each string shouldn't be too long.
std::vector<std::string> m_info;
/// Child nodes (eg a WorkspaceGroup will have a child node for each item).
std::vector<InfoNode*> m_nodes;
/// Icon type to use for this workspace
IconType m_icon;
/// Workspace name
std::string m_workspaceName;
/// Memory size taken by the workspace
size_t m_memorySize;
};

Workspace();
Workspace(const Workspace & other);
virtual ~Workspace();
Expand Down Expand Up @@ -84,7 +129,12 @@ class MANTID_API_DLL Workspace : public Kernel::DataItem
WorkspaceHistory& history() { return m_history; }
/// Returns a reference to the WorkspaceHistory const
const WorkspaceHistory& getHistory() const { return m_history; }
/// Add info about this workspace to a parent InfoNode.
void addInfoNodeTo(InfoNode& parentNode) const;

protected:
/// Create and return a new InfoNode describing this workspace.
virtual InfoNode* createInfoNode() const;

private:
void setName(const std::string&);
Expand Down
12 changes: 11 additions & 1 deletion Code/Mantid/Framework/API/inc/MantidAPI/WorkspaceGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class MANTID_API_DLL WorkspaceGroup : public Workspace
bool areNamesSimilar() const;
/// Inidicates that the workspace group can be treated as multiperiod.
bool isMultiperiod() const;
/// Check if a workspace is included in this group or any nested groups.
bool isInGroup( const Workspace& workspace, size_t level = 0 ) const;
/// Prints the group to the screen using the logger at debug
void print() const;

Expand All @@ -102,7 +104,11 @@ class MANTID_API_DLL WorkspaceGroup : public Workspace
std::vector<std::string> getNames() const;

//@}


protected:
/// Create and return a new InfoNode describing this workspace.
virtual InfoNode *createInfoNode() const;

private:
/// Private, unimplemented copy constructor
WorkspaceGroup(const WorkspaceGroup& ref);
Expand All @@ -112,6 +118,8 @@ class MANTID_API_DLL WorkspaceGroup : public Workspace
void removeByADS(const std::string& name);
/// Turn ADS observations on/off
void observeADSNotifications(const bool observeADS);
/// Check if a workspace is included in any child groups and groups in them.
bool isInChildGroup( const Workspace& workspace ) const;
/// Callback when a delete notification is received
void workspaceDeleteHandle(Mantid::API::WorkspacePostDeleteNotification_ptr notice);
/// Observer for workspace delete notfications
Expand All @@ -128,6 +136,8 @@ class MANTID_API_DLL WorkspaceGroup : public Workspace
mutable Poco::Mutex m_mutex;
/// Static reference to the logger
static Kernel::Logger& g_log;
/// Maximum allowed depth for nested groups.
static size_t g_maximum_depth;

friend class AnalysisDataServiceImpl;
friend class Algorithm;
Expand Down
30 changes: 30 additions & 0 deletions Code/Mantid/Framework/API/src/AnalysisDataService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,36 @@ namespace Mantid
notificationCenter.postNotification(new GroupUpdatedNotification( groupName ));
}

/**
* @return A pointer to the root node of the info tree.
*/
Workspace::InfoNode *AnalysisDataServiceImpl::createInfoTree() const
{
auto workspaces = getObjects();

// collect all groups and put them into temporary rootGroup
WorkspaceGroup rootGroup;
for( auto ws = workspaces.begin(); ws != workspaces.end(); ++ws )
{
WorkspaceGroup_sptr group = boost::dynamic_pointer_cast<WorkspaceGroup>( *ws );
if ( group )
{
rootGroup.addWorkspace( group );
}
}

// build the tree
Workspace::InfoNode *root = new Workspace::InfoNode(this);
for( auto ws = workspaces.begin(); ws != workspaces.end(); ++ws )
{
if ( !rootGroup.isInChildGroup(**ws) )
{
(**ws).addInfoNodeTo( *root );
}
}
return root;
}

//-------------------------------------------------------------------------
// Private methods
//-------------------------------------------------------------------------
Expand Down
39 changes: 35 additions & 4 deletions Code/Mantid/Framework/API/src/IEventWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,41 @@
template MANTID_API_DLL class Mantid::API::workspace_iterator<Mantid::API::LocatedDataRef,Mantid::API::IEventWorkspace>;
template MANTID_API_DLL class Mantid::API::workspace_iterator<const Mantid::API::LocatedDataRef, const Mantid::API::IEventWorkspace>;

namespace Mantid
{

namespace API
{

/**
* @return :: A pointer to the created info node.
*/
API::Workspace::InfoNode *IEventWorkspace::createInfoNode() const
{
auto node = MatrixWorkspace::createInfoNode();
std::string extra("");
switch ( getEventType() )
{
case WEIGHTED:
extra = " (weighted)";
break;
case WEIGHTED_NOTIME:
extra = " (weighted, no times)";
break;
case TOF:
extra = "";
break;
}
node->addLine( "Events: " + boost::lexical_cast<std::string>(getNumberEvents()) + extra );
return node;
}

}

/*
* In order to be able to cast PropertyWithValue classes correctly a definition for the PropertyWithValue<IEventWorkspace> is required
* In order to be able to cast PropertyWithValue classes correctly a definition for the PropertyWithValue<IEventWorkspace> is required
*
*/
namespace Mantid
{
namespace Kernel
{

Expand Down Expand Up @@ -52,7 +81,9 @@ Mantid::API::IEventWorkspace_const_sptr IPropertyManager::getValue<Mantid::API::
}


} // namespace Kernel
}

// namespace Kernel
} // namespace Mantid

///\endcond TEMPLATE
20 changes: 19 additions & 1 deletion Code/Mantid/Framework/API/src/IMDEventWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,25 @@ namespace API
*/
bool IMDEventWorkspace::threadSafe() const
{
return !this->isFileBacked();
return !this->isFileBacked();
}

//-----------------------------------------------------------------------------------------------
/**
* @return :: A pointer to the created info node.
*/
Workspace::InfoNode *IMDEventWorkspace::createInfoNode() const
{
auto node = IMDWorkspace::createInfoNode();
// Now box controller details
std::vector<std::string> stats = getBoxControllerStats();
for (size_t i=0; i < stats.size(); i++)
{
node->addLine( stats[i] );
}

node->addLine("Events: " + boost::lexical_cast<std::string>(getNPoints()) );
return node;
}


Expand Down
29 changes: 28 additions & 1 deletion Code/Mantid/Framework/API/src/IMDWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "MantidKernel/IPropertyManager.h"
#include "MantidKernel/VMD.h"

#include <sstream>

using Mantid::Kernel::VMD;

namespace Mantid
Expand Down Expand Up @@ -57,7 +59,32 @@ namespace Mantid
signal_t IMDWorkspace::getSignalAtVMD(const Mantid::Kernel::VMD & coords,
const Mantid::API::MDNormalization & normalization) const
{
return this->getSignalAtCoord(coords.getBareArray(), normalization);
return this->getSignalAtCoord(coords.getBareArray(), normalization);
}

//-----------------------------------------------------------------------------------------------
/**
* @return :: A pointer to the created info node.
*/
Workspace::InfoNode *IMDWorkspace::createInfoNode() const
{
auto node = new InfoNode(*this);
node->addLine( "Title: " + getTitle() );
for (size_t i=0; i < getNumDims(); i++)
{
std::ostringstream mess;
Geometry::IMDDimension_const_sptr dim = getDimension(i);
mess << "Dim " << i << ": (" << dim->getName() << ") " << dim->getMinimum() << " to " << dim->getMaximum() << " in " << dim->getNBins() << " bins";
// Also show the dimension ID string, if different than name
if (dim->getDimensionId() != dim->getName())
mess << ". Id=" << dim->getDimensionId();
node->addLine( mess.str() );
}
if ( hasOriginalWorkspace() )
{
node->addLine("Binned from '" + getOriginalWorkspace()->getName() + "'");
}
return node;
}

//-----------------------------------------------------------------------------------------------
Expand Down
16 changes: 15 additions & 1 deletion Code/Mantid/Framework/API/src/ITableWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,21 @@ void ITableWorkspace::modified()
ITableWorkspace_sptr tws = boost::dynamic_pointer_cast<ITableWorkspace>(ws);
if (!tws) return;
AnalysisDataService::Instance().notificationCenter.postNotification(
new Kernel::DataService<API::Workspace>::AfterReplaceNotification(this->getName(),tws));
new Kernel::DataService<API::Workspace>::AfterReplaceNotification(this->getName(),tws));
}

/**
* Implement Workspace's virtual method to fill the info node with info
* descriding this table workspace.
*
* @return :: A pointer to the created node.
*/
Workspace::InfoNode *ITableWorkspace::createInfoNode() const
{
auto node = new InfoNode(*this);
node->addLine("Columns: " + boost::lexical_cast<std::string>(columnCount()));
node->addLine("Rows: " + boost::lexical_cast<std::string>(rowCount()));
return node;
}


Expand Down
33 changes: 33 additions & 0 deletions Code/Mantid/Framework/API/src/MatrixWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,39 @@ namespace Mantid
return Mantid::API::None;
}

/**
* @return :: A pointer to the created node.
*/
Workspace::InfoNode *MatrixWorkspace::createInfoNode() const
{
auto node = new InfoNode(*this);
node->addLine( "Title: " + getTitle() );
node->addLine( "Histograms: " + boost::lexical_cast<std::string>(getNumberHistograms()) );
node->addLine( "Bins: " + boost::lexical_cast<std::string>(blocksize()) );
if ( isHistogramData() )
{
node->addLine( "Histogram" );
}
else
{
node->addLine( "Data points" );
}
std::string s = "X axis: ";
if (axes() > 0 )
{
Axis *ax = getAxis(0);
if ( ax && ax->unit() ) s += ax->unit()->caption() + " / " + ax->unit()->label();
else s += "Not set";
}
else
{
s += "N/A";
}
node->addLine( s );
node->addLine( "Y axis: " + YUnitLabel() );
node->addExperimentInfo(*this);
return node;
}

} // namespace API
} // Namespace Mantid
Expand Down

0 comments on commit 9412934

Please sign in to comment.