Skip to content

Commit

Permalink
Re 6687 MantidEV menubar, show UB
Browse files Browse the repository at this point in the history
Implemented the menubar item View->ShowUB.
The UB matrix is displayed using g_log.notice(),
both in the internal "Mantid" format and in the
external "ISAW" format, along with the lattice
parameters.

Refs #6687
  • Loading branch information
DennisMikkelson committed Mar 20, 2013
1 parent 8acda94 commit 469e29d
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ private slots:

/// Slot to load a peaks workspace to the current MantidEV named workspace
void loadIsawPeaks_slot();

/// Slot to show the UB matrix
void showUB_slot();

//
// The following slots just take care of enabling and disabling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1069,115 +1069,6 @@
</property>
</widget>
</widget>
<widget class="QWidget" name="ChangeHKL">
<attribute name="title">
<string>Change HKL</string>
</attribute>
<widget class="QPushButton" name="ApplyChangeHKL_btn">
<property name="geometry">
<rect>
<x>430</x>
<y>520</y>
<width>115</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>Apply</string>
</property>
</widget>
<widget class="QLabel" name="HKL_Transfrom_lbl">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>431</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>Specify 3x3 Matrix to Apply to HKL</string>
</property>
</widget>
<widget class="QLabel" name="HKL_Tran_Row_1_lbl">
<property name="geometry">
<rect>
<x>50</x>
<y>70</y>
<width>291</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>HKL Transformation, Row 1</string>
</property>
</widget>
<widget class="QLineEdit" name="HKL_tran_row_1_ledt">
<property name="geometry">
<rect>
<x>350</x>
<y>70</y>
<width>291</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>1, 0, 0</string>
</property>
</widget>
<widget class="QLabel" name="HKL_Tran_Row_2_lbl">
<property name="geometry">
<rect>
<x>50</x>
<y>100</y>
<width>291</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>HKL Transformation, Row 2</string>
</property>
</widget>
<widget class="QLineEdit" name="HKL_tran_row_2_ledt">
<property name="geometry">
<rect>
<x>350</x>
<y>100</y>
<width>291</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>0, 1, 0</string>
</property>
</widget>
<widget class="QLabel" name="HKL_Tran_Row_3_lbl">
<property name="geometry">
<rect>
<x>50</x>
<y>130</y>
<width>291</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>HKL Transformation, Row 3</string>
</property>
</widget>
<widget class="QLineEdit" name="HKL_tran_row_3_ledt">
<property name="geometry">
<rect>
<x>350</x>
<y>130</y>
<width>291</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>0, 0, 1</string>
</property>
</widget>
</widget>
<widget class="QWidget" name="Integrate">
<attribute name="title">
<string>Integrate</string>
Expand Down Expand Up @@ -1508,6 +1399,115 @@
</property>
</widget>
</widget>
<widget class="QWidget" name="ChangeHKL">
<attribute name="title">
<string>Change HKL</string>
</attribute>
<widget class="QPushButton" name="ApplyChangeHKL_btn">
<property name="geometry">
<rect>
<x>430</x>
<y>520</y>
<width>115</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>Apply</string>
</property>
</widget>
<widget class="QLabel" name="HKL_Transfrom_lbl">
<property name="geometry">
<rect>
<x>20</x>
<y>30</y>
<width>431</width>
<height>18</height>
</rect>
</property>
<property name="text">
<string>Specify 3x3 Matrix to Apply to HKL</string>
</property>
</widget>
<widget class="QLabel" name="HKL_Tran_Row_1_lbl">
<property name="geometry">
<rect>
<x>50</x>
<y>70</y>
<width>291</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>HKL Transformation, Row 1</string>
</property>
</widget>
<widget class="QLineEdit" name="HKL_tran_row_1_ledt">
<property name="geometry">
<rect>
<x>350</x>
<y>70</y>
<width>291</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>1, 0, 0</string>
</property>
</widget>
<widget class="QLabel" name="HKL_Tran_Row_2_lbl">
<property name="geometry">
<rect>
<x>50</x>
<y>100</y>
<width>291</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>HKL Transformation, Row 2</string>
</property>
</widget>
<widget class="QLineEdit" name="HKL_tran_row_2_ledt">
<property name="geometry">
<rect>
<x>350</x>
<y>100</y>
<width>291</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>0, 1, 0</string>
</property>
</widget>
<widget class="QLabel" name="HKL_Tran_Row_3_lbl">
<property name="geometry">
<rect>
<x>50</x>
<y>130</y>
<width>291</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>HKL Transformation, Row 3</string>
</property>
</widget>
<widget class="QLineEdit" name="HKL_tran_row_3_ledt">
<property name="geometry">
<rect>
<x>350</x>
<y>130</y>
<width>291</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>0, 0, 1</string>
</property>
</widget>
</widget>
</widget>
</item>
</layout>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

#include <MantidKernel/System.h>
#include "MantidKernel/Logger.h"


#ifndef INTERFACES_MANTID_EV_WORKER_H
#define INTERFACES_MANTID_EV_WORKER_H
Expand Down Expand Up @@ -148,9 +150,16 @@ class DLLExport MantidEVWorker
double inner_size,
double outer_size );

/// Display UB and lattice parameters in MantidPlot
bool showUB( const std::string & peaks_ws_name );

private:

/// Utility to get workspace ID from ADS, blank if none
std::string workspaceType( const std::string & ws_name );

/// Reference to a logger
static Mantid::Kernel::Logger & g_log;
};

} // namespace CustomInterfaces
Expand Down
18 changes: 18 additions & 0 deletions Code/Mantid/MantidQt/CustomInterfaces/src/MantidEV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ void MantidEV::initLayout()
QObject::connect( m_uiForm.actionLoad_Isaw_Peaks, SIGNAL(triggered()),
this, SLOT(loadIsawPeaks_slot()) );

QObject::connect( m_uiForm.actionShow_UB, SIGNAL(triggered()),
this, SLOT(showUB_slot()) );

// connect the slots for enabling and disabling
// various subsets of widgets
QObject::connect( m_uiForm.LoadEventFile_rbtn, SIGNAL(toggled(bool)),
Expand Down Expand Up @@ -1065,6 +1068,21 @@ void MantidEV::loadIsawPeaks_slot()
}


void MantidEV::showUB_slot()
{
std::cout << "showUB_slot called..." << std::endl;
std::string peaks_ws_name = m_uiForm.PeaksWorkspace_ledt->text().toStdString();
if ( peaks_ws_name.length() == 0 )
{
errorMessage("Specify a peaks workspace name on the Find Peaks tab.");
return;
}

if ( !worker->showUB( peaks_ws_name ) )
errorMessage("The specified workspace does not have a UB matrix");
}


void MantidEV::setEnabledLoadEventFileParams_slot( bool on )
{
m_uiForm.EventFileName_lbl->setEnabled( on );
Expand Down
61 changes: 61 additions & 0 deletions Code/Mantid/MantidQt/CustomInterfaces/src/MantidEVWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "MantidAPI/IEventWorkspace.h"
#include "MantidAPI/IMDWorkspace.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidGeometry/Crystal/OrientedLattice.h"


namespace MantidQt
{
Expand All @@ -16,6 +19,9 @@ namespace CustomInterfaces
using namespace Mantid::Kernel;
using namespace Mantid::API;

// Initialize the logger
Logger& MantidEVWorker::g_log = Logger::get("MantidEV");


MantidEVWorker::MantidEVWorker()
{
Expand Down Expand Up @@ -603,5 +609,60 @@ bool MantidEVWorker::ellipsoidIntegrate( const std::string & peaks_ws_name,
return false;
}


bool MantidEVWorker::showUB( const std::string & peaks_ws_name )
{
if ( !isPeaksWorkspace( peaks_ws_name ) )
{
return false;
}

const auto& ADS = AnalysisDataService::Instance();
IPeaksWorkspace_sptr peaks_ws = ADS.retrieveWS<IPeaksWorkspace>(peaks_ws_name);

try
{
char logInfo[200];

Mantid::Geometry::OrientedLattice o_lattice = peaks_ws->mutableSample().getOrientedLattice();
Matrix<double> UB = o_lattice.getUB();

g_log.notice() << std::endl;
g_log.notice() << "Mantid UB = " << std::endl;
sprintf( logInfo,
std::string(" %12.8f %12.8f %12.8f\n %12.8f %12.8f %12.8f\n %12.8f %12.8f %12.8f\n").c_str(),
UB[0][0], UB[0][1], UB[0][2],
UB[1][0], UB[1][1], UB[1][2],
UB[2][0], UB[2][1], UB[2][2] );
g_log.notice( std::string(logInfo) );

g_log.notice() << "ISAW UB = " << std::endl;
sprintf( logInfo,
std::string(" %12.8f %12.8f %12.8f\n %12.8f %12.8f %12.8f\n %12.8f %12.8f %12.8f\n").c_str(),
UB[2][0], UB[0][0], UB[1][0],
UB[2][1], UB[0][1], UB[1][1],
UB[2][2], UB[0][2], UB[1][2] );
g_log.notice( std::string(logInfo) );

double calc_a = o_lattice.a();
double calc_b = o_lattice.b();
double calc_c = o_lattice.c();
double calc_alpha = o_lattice.alpha();
double calc_beta = o_lattice.beta();
double calc_gamma = o_lattice.gamma();
// Show the modified lattice parameters
sprintf( logInfo,
std::string("Lattice Parameters: %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f").c_str(),
calc_a, calc_b, calc_c, calc_alpha, calc_beta, calc_gamma);
g_log.notice( std::string(logInfo) );
}
catch(...)
{
return false;
}

return true;
}

} // namespace CustomInterfaces
} // namespace MantidQt

0 comments on commit 469e29d

Please sign in to comment.