diff --git a/Code/Mantid/Build/CMake/CommonSetup.cmake b/Code/Mantid/Build/CMake/CommonSetup.cmake index c2c00011930d67206567244689e9166a42cbe6a7..7d2bbc56221a2fa07182a6abf05a853ca7d65501 100644 --- a/Code/Mantid/Build/CMake/CommonSetup.cmake +++ b/Code/Mantid/Build/CMake/CommonSetup.cmake @@ -156,9 +156,115 @@ if ( CMAKE_COMPILER_IS_GNUCXX ) endif () ########################################################################### -# The inital stuff for cppcheck +# Setup cppcheck ########################################################################### find_package ( Cppcheck ) +if ( CPPCHECK_EXECUTABLE ) + set ( CPPCHECK_SOURCE_DIRS + Framework + MantidPlot + MantidQt + Vates + ) + + set ( CPPCHECK_USE_INCLUDE_DIRS OFF CACHE BOOL "Use specified include directories. WARNING: cppcheck will run significantly slower." ) + + set ( CPPCHECK_INCLUDE_DIRS + Framework/Algorithms/inc + Framework/GPUAlgorithms/inc + Framework/PythonInterface/inc + Framework/NexusCPP/inc + Framework/Nexus/inc + Framework/MPIAlgorithms/inc + Framework/MDAlgorithms/inc + Framework/DataHandling/inc + Framework/WorkflowAlgorithms/inc + Framework/MDEvents/inc + Framework/DataObjects/inc + Framework/Geometry/inc + Framework/ICat/inc + Framework/CurveFitting/inc + Framework/API/inc + Framework/TestHelpers/inc + Framework/Crystal/inc + Framework/PythonAPI/inc + Framework/Kernel/inc + Vates/VatesAPI/inc + Vates/VatesSimpleGui/ViewWidgets/inc + Vates/VatesSimpleGui/StandAloneExec/inc + Vates/VatesSimpleGui/QtWidgets/inc + MantidQt/MantidWidgets/inc + MantidQt/CustomDialogs/inc + MantidQt/DesignerPlugins/inc + MantidQt/CustomInterfaces/inc + MantidQt/API/inc + MantidQt/Factory/inc + MantidQt/SliceViewer/inc + ) + + set ( CPPCHECK_EXCLUDES + Framework/ICat/inc/MantidICat/GSoapGenerated/ + Framework/ICat/src/GSoapGenerated/ + Framework/ICat/src/GSoapGenerated.cpp + Framework/Kernel/src/ANN/ + Framework/Kernel/src/ANN_complete.cpp + ) + + # setup the standard arguments + set (_cppcheck_args) + list ( APPEND _cppcheck_args ${CPPCHECK_TEMPLATE_ARG} ${CPPCHECK_ARGS} ) + if ( CPPCHECK_NUM_THREADS GREATER 0) + list ( APPEND _cppcheck_args -j ${CPPCHECK_NUM_THREADS} ) + endif ( CPPCHECK_NUM_THREADS GREATER 0) + + # process list of include/exclude directories + set (_cppcheck_source_dirs) + foreach (_dir ${CPPCHECK_SOURCE_DIRS} ) + set ( _tmpdir "${CMAKE_SOURCE_DIR}/${_dir}" ) + if ( EXISTS ${_tmpdir} ) + list ( APPEND _cppcheck_source_dirs ${_tmpdir} ) + endif () + endforeach() + + set (_cppcheck_includes) + foreach( _dir ${CPPCHECK_INCLUDE_DIRS} ) + set ( _tmpdir "${CMAKE_SOURCE_DIR}/${_dir}" ) + if ( EXISTS ${_tmpdir} ) + list ( APPEND _cppcheck_includes -I ${_tmpdir} ) + endif () + endforeach() + if (CPPCHECK_USE_INCLUDE_DIRS) + list ( APPEND _cppcheck_args ${_cppcheck_includes} ) + endif (CPPCHECK_USE_INCLUDE_DIRS) + + set (_cppcheck_excludes) + foreach( _file ${CPPCHECK_EXCLUDES} ) + set ( _tmp "${CMAKE_SOURCE_DIR}/${_file}" ) + if ( EXISTS ${_tmp} ) + list ( APPEND _cppcheck_excludes -i ${_tmp} ) + endif () + endforeach() + list ( APPEND _cppcheck_args ${_cppcheck_excludes} ) + + # put the finishing bits on the final command call + set (_cppcheck_xml_args) + if (CPPCHECK_GENERATE_XML) + list( APPEND _cppcheck_xml_args --xml --xml-version=2 ${_cppcheck_source_dirs} 2> ${CMAKE_BINARY_DIR}/cppcheck.xml ) + else (CPPCHECK_GENERATE_XML) + list( APPEND _cppcheck_xml_args ${_cppcheck_source_dirs} ) + endif (CPPCHECK_GENERATE_XML) + + # generate the target + if (NOT TARGET cppcheck) + add_custom_target ( cppcheck + COMMAND ${CPPCHECK_EXECUTABLE} ${_cppcheck_args} ${_cppcheck_xml_args} + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMENT "Running cppcheck" + ) + set_target_properties(cppcheck PROPERTIES EXCLUDE_FROM_ALL TRUE) + endif() +endif ( CPPCHECK_EXECUTABLE ) + ########################################################################### # Set up the unit tests target diff --git a/Code/Mantid/Build/CMake/FindCppcheck.cmake b/Code/Mantid/Build/CMake/FindCppcheck.cmake index ce9c0b543046c0b39d791dd2379b908494e47e53..ec5e07b50674c591e27668810f5c82b616721f40 100644 --- a/Code/Mantid/Build/CMake/FindCppcheck.cmake +++ b/Code/Mantid/Build/CMake/FindCppcheck.cmake @@ -46,22 +46,23 @@ if(CPPCHECK_EXECUTABLE OR CPPCHECK_MARK_AS_ADVANCED) mark_as_advanced(CPPCHECK_ROOT_DIR) endif() -if(CPPCHECK_EXECUTABLE) - if(NOT TARGET cppcheck) - add_custom_target(cppcheck) - set_target_properties(cppcheck PROPERTIES EXCLUDE_FROM_ALL TRUE) - endif() - execute_process ( COMMAND ${CPPCHECK_EXECUTABLE} --version - OUTPUT_VARIABLE CPPCHECK_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE ) - string ( TOUPPER ${CPPCHECK_VERSION} CPPCHECK_VERSION ) - string ( REPLACE "CPPCHECK" "" CPPCHECK_VERSION ${CPPCHECK_VERSION} ) - string ( STRIP ${CPPCHECK_VERSION} CPPCHECK_VERSION ) - message ( STATUS "cppcheck version: ${CPPCHECK_VERSION}" ) -endif() +#if(CPPCHECK_EXECUTABLE) +# if(NOT TARGET cppcheck) +# add_custom_target(cppcheck) +# set_target_properties(cppcheck PROPERTIES EXCLUDE_FROM_ALL TRUE) +# endif() +# execute_process ( COMMAND ${CPPCHECK_EXECUTABLE} --version +# OUTPUT_VARIABLE CPPCHECK_VERSION +# OUTPUT_STRIP_TRAILING_WHITESPACE ) +# string ( TOUPPER ${CPPCHECK_VERSION} CPPCHECK_VERSION ) +# string ( REPLACE "CPPCHECK" "" CPPCHECK_VERSION ${CPPCHECK_VERSION} ) +# string ( STRIP ${CPPCHECK_VERSION} CPPCHECK_VERSION ) +# message ( STATUS "cppcheck version: ${CPPCHECK_VERSION}" ) +#endif() mark_as_advanced(CPPCHECK_EXECUTABLE) set ( CPPCHECK_ARGS "--enable=all" CACHE STRING "Arguments for running cppcheck" ) +set ( CPPCHECK_NUM_THREADS 0 CACHE STRING "Number of threads to use when running cppcheck" ) set ( CPPCHECK_GENERATE_XML OFF CACHE BOOL "Generate xml output files from cppcheck" ) function(add_cppcheck _name) # additional arguments are files to ignore diff --git a/Code/Mantid/Framework/API/CMakeLists.txt b/Code/Mantid/Framework/API/CMakeLists.txt index 4e2899753b74318aa261250b599812e2188fa3f0..881e5bde9260366f8e19ddf1116cac9e798129d7 100644 --- a/Code/Mantid/Framework/API/CMakeLists.txt +++ b/Code/Mantid/Framework/API/CMakeLists.txt @@ -272,7 +272,6 @@ endif () ADD_PRECOMPILED_HEADER( inc/MantidAPI/PrecompiledHeader.h MantidAPI src/PrecompiledHeader.cpp SRC_FILES INC_FILES ) # Add the target for this directory add_library ( API ${SRC_FILES} ${INC_FILES}) -add_cppcheck ( API ) # Set the name of the generated library set_target_properties ( API PROPERTIES OUTPUT_NAME MantidAPI COMPILE_DEFINITIONS IN_MANTID_API ) diff --git a/Code/Mantid/Framework/Algorithms/CMakeLists.txt b/Code/Mantid/Framework/Algorithms/CMakeLists.txt index 591857693ac511ff83a2481b4e92f3364aed7134..49ba3fa39fa6724b6aa7b6908b592d2d2bb24353 100644 --- a/Code/Mantid/Framework/Algorithms/CMakeLists.txt +++ b/Code/Mantid/Framework/Algorithms/CMakeLists.txt @@ -540,7 +540,6 @@ endif(UNITY_BUILD) ADD_PRECOMPILED_HEADER( inc/MantidAlgorithms/PrecompiledHeader.h MantidAlgorithms src/PrecompiledHeader.cpp SRC_FILES INC_FILES ) # Add the target for this directory add_library ( Algorithms ${SRC_FILES} ${INC_FILES}) -add_cppcheck ( Algorithms ) # Set the name of the generated library set_target_properties ( Algorithms PROPERTIES OUTPUT_NAME MantidAlgorithms ) # Add to the 'Framework' group in VS diff --git a/Code/Mantid/Framework/Algorithms/src/CalMuonDeadTime.cpp b/Code/Mantid/Framework/Algorithms/src/CalMuonDeadTime.cpp index 7459453c0ed2b93970c76f62594812c00e77e558..6b4fcfd54ae548f94b6f0c725c29716e223ef523 100644 --- a/Code/Mantid/Framework/Algorithms/src/CalMuonDeadTime.cpp +++ b/Code/Mantid/Framework/Algorithms/src/CalMuonDeadTime.cpp @@ -60,6 +60,14 @@ void CalMuonDeadTime::exec() const double lastgooddata = getProperty("LastGoodData"); + // Seem to have to do this to avoid MantidPlot to crash when + // running this algorithm where the "DataFitted" WS already exists + + std::string dataFittedName = getPropertyValue("DataFitted"); + if (API::AnalysisDataService::Instance().doesExist(dataFittedName)) + API::AnalysisDataService::Instance().remove(dataFittedName); + + // Get number of good frames from Run object. This also serves as // a test to see if valid input workspace has been provided @@ -84,7 +92,8 @@ void CalMuonDeadTime::exec() // Start created a temperary workspace with data we are going to fit - // against. First step is to crop to only include data from firstgooddata + // against. First step is to crop to only include data between firstgooddata + // and lastgooddata std::string wsName = "TempForMuonCalDeadTime"; API::IAlgorithm_sptr cropWS; @@ -95,6 +104,8 @@ void CalMuonDeadTime::exec() cropWS->setProperty("XMax", lastgooddata); cropWS->executeAsSubAlg(); + // get cropped input workspace + boost::shared_ptr<API::MatrixWorkspace> wsCrop = cropWS->getProperty("OutputWorkspace"); @@ -111,6 +122,8 @@ void CalMuonDeadTime::exec() convertToPW->setPropertyValue("OutputWorkspace", wsName); convertToPW->executeAsSubAlg(); + // get pointworkspace + boost::shared_ptr<API::MatrixWorkspace> wsFitAgainst = convertToPW->getProperty("OutputWorkspace"); @@ -122,11 +135,26 @@ void CalMuonDeadTime::exec() { const double time = wsFitAgainst->dataX(i)[t]; // mid-point time value because point WS const double decayFac = exp(time/muonDecay); - wsFitAgainst->dataY(i)[t] = wsCrop->dataY(i)[t]*decayFac; - wsFitAgainst->dataX(i)[t] = wsCrop->dataY(i)[t]; - wsFitAgainst->dataE(i)[t] = wsCrop->dataE(i)[t]*decayFac; + if ( wsCrop->dataY(i)[t] > 0 ) + { + wsFitAgainst->dataY(i)[t] = wsCrop->dataY(i)[t]*decayFac; + wsFitAgainst->dataX(i)[t] = wsCrop->dataY(i)[t]; + wsFitAgainst->dataE(i)[t] = wsCrop->dataE(i)[t]*decayFac; + } + else + { + // For the Muon data which I have looked at when zero counts + // the errors are zero which is likely nonsense. Hence to get + // around this problem treat such counts to be 0.1 with standard + // of one........ + + wsFitAgainst->dataY(i)[t] = 0.1*decayFac; + wsFitAgainst->dataX(i)[t] = 0.1; + wsFitAgainst->dataE(i)[t] = decayFac; + } } + } diff --git a/Code/Mantid/Framework/Algorithms/src/CreateCalFileByNames.cpp b/Code/Mantid/Framework/Algorithms/src/CreateCalFileByNames.cpp index 5f1e7696b7e332e14933eba7b99360b602b0a9f3..ae6a9724d734db143f852f6d0d3651f9f2dc3180 100644 --- a/Code/Mantid/Framework/Algorithms/src/CreateCalFileByNames.cpp +++ b/Code/Mantid/Framework/Algorithms/src/CreateCalFileByNames.cpp @@ -119,8 +119,11 @@ namespace Mantid // Assign incremental number to each group std::map<std::string,int> group_map; int index=0; - for (std::vector<std::string>::const_iterator it=vgroups.begin();it!=vgroups.end();++it) + for (std::vector<std::string>::iterator it=vgroups.begin();it!=vgroups.end();++it) + { + boost::trim(*it); group_map[(*it)]=++index; + } // Not needed anymore vgroups.clear(); diff --git a/Code/Mantid/Framework/Algorithms/src/CreateGroupingWorkspace.cpp b/Code/Mantid/Framework/Algorithms/src/CreateGroupingWorkspace.cpp index ced8cb2b36aafa9ed257470e59c92c884e58b8d8..131a5077bbd208893b328c014175db55f1d36a30 100644 --- a/Code/Mantid/Framework/Algorithms/src/CreateGroupingWorkspace.cpp +++ b/Code/Mantid/Framework/Algorithms/src/CreateGroupingWorkspace.cpp @@ -138,11 +138,14 @@ namespace Algorithms std::vector<std::string> vgroups; boost::split( vgroups, GroupNames, boost::algorithm::detail::is_any_ofF<char>(",/*")); - // Assign incremental number to each group + // Trim and assign incremental number to each group std::map<std::string,int> group_map; int index=0; - for (std::vector<std::string>::const_iterator it=vgroups.begin();it!=vgroups.end();++it) + for (std::vector<std::string>::iterator it=vgroups.begin();it!=vgroups.end();++it) + { + boost::trim(*it); group_map[(*it)]=++index; + } // Find Detectors that belong to groups if (!group_map.empty()) diff --git a/Code/Mantid/Framework/Algorithms/src/Plus.cpp b/Code/Mantid/Framework/Algorithms/src/Plus.cpp index a3b9b8508d2d3e8db404b688e201c9274e46aaed..388c416136bf34fa0aeb5f027cc235394031533d 100644 --- a/Code/Mantid/Framework/Algorithms/src/Plus.cpp +++ b/Code/Mantid/Framework/Algorithms/src/Plus.cpp @@ -128,6 +128,11 @@ namespace Mantid // either or both workspace are "other" // Use the default behaviour BinaryOperation::checkRequirements(); + + // Except that commutation is possible + // If LHS is smaller, e.g. single-value, flip sides to put it on the right + m_flipSides = (m_lhs->size() < m_rhs->size()); + } } diff --git a/Code/Mantid/Framework/Algorithms/test/CreateCalFileByNamesTest.h b/Code/Mantid/Framework/Algorithms/test/CreateCalFileByNamesTest.h index 68fc70ddc11fdec36cd98b1905fd37731854bdbc..56206fd2e4c68bcb4f6e2946a41afec3af20a611 100644 --- a/Code/Mantid/Framework/Algorithms/test/CreateCalFileByNamesTest.h +++ b/Code/Mantid/Framework/Algorithms/test/CreateCalFileByNamesTest.h @@ -55,7 +55,7 @@ public: outputFile = "./INES_CreateCalFileByNamesTest.cal"; testerCAL.setPropertyValue("GroupingFileName", outputFile); outputFile = testerCAL.getPropertyValue("GroupingFileName"); - testerCAL.setPropertyValue("GroupNames", "bank1A,bank2B,bank3C,bank4D,bank5E,bank6F,bank7G,bank8H,bank9I"); + TS_ASSERT_THROWS_NOTHING(testerCAL.setPropertyValue("GroupNames", "bank1A, bank2B,bank3C, bank4D,bank5E,bank6F, bank7G,bank8H,bank9I")); TS_ASSERT_THROWS_NOTHING(testerCAL.execute()); TS_ASSERT_THROWS_NOTHING(testerCAL.isExecuted()); diff --git a/Code/Mantid/Framework/Algorithms/test/CreateGroupingWorkspaceTest.h b/Code/Mantid/Framework/Algorithms/test/CreateGroupingWorkspaceTest.h index 979e90d5dce5e2e80ffbd16264667942fba38534..7a8a29abd17fd686e42b58af69c7c59f19fe5620 100644 --- a/Code/Mantid/Framework/Algorithms/test/CreateGroupingWorkspaceTest.h +++ b/Code/Mantid/Framework/Algorithms/test/CreateGroupingWorkspaceTest.h @@ -86,7 +86,7 @@ public: TS_ASSERT_THROWS_NOTHING( alg.initialize() ) TS_ASSERT( alg.isInitialized() ) TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("InstrumentFilename", "CNCS_Definition.xml") ); - TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("GroupNames", "bank1,bank2,bank3,bank4") ); + TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("GroupNames", "bank1,bank2, bank3,bank4") ); TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("OutputWorkspace", outWSName) ); TS_ASSERT_THROWS_NOTHING( alg.execute(); ); TS_ASSERT( alg.isExecuted() ); diff --git a/Code/Mantid/Framework/Algorithms/test/PlusMinusTest.in.h b/Code/Mantid/Framework/Algorithms/test/PlusMinusTest.in.h index 44e5295a7949e97d14da1fbb23ff6b51bc9283b0..6ab83def16adfcca510d08db47edacf86bf36f1e 100644 --- a/Code/Mantid/Framework/Algorithms/test/PlusMinusTest.in.h +++ b/Code/Mantid/Framework/Algorithms/test/PlusMinusTest.in.h @@ -210,7 +210,11 @@ public: MatrixWorkspace_sptr work_in1 = WorkspaceCreationHelper::Create2DWorkspace123(1,nBins); MatrixWorkspace_sptr work_in2 = WorkspaceCreationHelper::Create2DWorkspace154(nHist,nBins); if (DO_PLUS) - performTest(work_in1,work_in2); + { + performTest(work_in1,work_in2, + false /*in place*/, false /*not event*/, + -1,-1, false, true /*algorithmWillCommute*/); + } else performTest_fails(work_in1,work_in2); } @@ -252,7 +256,11 @@ public: MatrixWorkspace_sptr work_in1 = WorkspaceCreationHelper::CreateWorkspaceSingleValue(2.2); MatrixWorkspace_sptr work_in2 = WorkspaceCreationHelper::Create1DWorkspaceFib(nBins); if (DO_PLUS) - performTest(work_in1,work_in2); + { + MatrixWorkspace_sptr out = performTest(work_in1,work_in2, + false /*in place*/, false /*not event*/, + -1,-1, false, true /*algorithmWillCommute*/); + } else performTest_fails(work_in1,work_in2); } @@ -280,7 +288,13 @@ public: MatrixWorkspace_sptr work_in1 = WorkspaceCreationHelper::CreateWorkspaceSingleValue(4.455); MatrixWorkspace_sptr work_in2 = WorkspaceCreationHelper::Create2DWorkspaceBinned(nHist,nBins); if (DO_PLUS) - performTest(work_in1,work_in2); + { + MatrixWorkspace_sptr out = performTest(work_in1,work_in2, + false /*in place*/, false /*not event*/, + -1,-1, false, true /*algorithmWillCommute*/); + TS_ASSERT_EQUALS( out->getNumberHistograms(), nHist); + TS_ASSERT_EQUALS( out->blocksize(), nBins); + } else performTest_fails(work_in1,work_in2); } @@ -321,7 +335,13 @@ public: MatrixWorkspace_sptr work_in2 = WorkspaceCreationHelper::CreateEventWorkspace(nHist,nBins,100,0.0,1.0,2); // Become a WS2D if (DO_PLUS) - performTest(work_in1, work_in2, false, false /*output is NOT event*/ ); + { + MatrixWorkspace_sptr out = performTest(work_in1,work_in2, + false /*in place*/, false /*not event*/, + -1,-1, false, true /*algorithmWillCommute*/); + TS_ASSERT_EQUALS( out->getNumberHistograms(), nHist); + TS_ASSERT_EQUALS( out->blocksize(), nBins); + } else performTest_fails(work_in1,work_in2); @@ -398,7 +418,14 @@ public: MatrixWorkspace_sptr work_in1 = WorkspaceCreationHelper::Create2DWorkspace(1, nBins); MatrixWorkspace_sptr work_in2 = WorkspaceCreationHelper::CreateEventWorkspace(nHist,nBins,100,0.0,1.0,2); if (DO_PLUS) - performTest(work_in1,work_in2, inplace!=0, false /*not event*/, 4.0, 2.0); // Commutes if doing it with event workspace + { + // Commutes unless doing it inplace, inplace = fails + if (inplace!=0) + performTest_fails(work_in1,work_in2, inplace!=0); + else + performTest(work_in1,work_in2, inplace!=0, false /*not event*/, 4.0, 2.0, + false, true /*algorithmWillCommute*/); + } else performTest_fails(work_in1,work_in2, inplace!=0); } @@ -612,7 +639,7 @@ public: * @param expectedValue * @param expectedError * @param allWorkspacesSameName :: do A = A + A - * @return + * @return the created workspace */ MatrixWorkspace_sptr performTest(const MatrixWorkspace_sptr work_in1, const MatrixWorkspace_sptr work_in2, bool doInPlace = false, bool outputIsEvent = false, double expectedValue=-1.0, double expectedError=-1.0, @@ -689,9 +716,13 @@ public: } if (algorithmWillCommute) + { checkData(work_in2, work_in1, work_out1, 0, expectedValue, expectedError); + } else + { checkData(work_in1, work_in2, work_out1, 0, expectedValue, expectedError); + } AnalysisDataService::Instance().remove(wsNameOut); } @@ -759,6 +790,9 @@ public: TSM_ASSERT_LESS_THAN( message, 0, work_out1->getNumberHistograms()); TSM_ASSERT_LESS_THAN( message, 0, work_out1->blocksize()); TSM_ASSERT_EQUALS( message, work_in1->getNumberHistograms(), work_out1->getNumberHistograms()); + // Number of histograms/bins is unchanged (relative to LHS argument) + TSM_ASSERT_EQUALS( message, work_out1->getNumberHistograms(), work_in1->getNumberHistograms()); + TSM_ASSERT_EQUALS( message, work_out1->blocksize(), work_in1->blocksize()); if (expectedValue == -1.0 && expectedError == -1.0) { diff --git a/Code/Mantid/Framework/Crystal/CMakeLists.txt b/Code/Mantid/Framework/Crystal/CMakeLists.txt index cd690b4874ecd14fa1e1aa08299644afb823de05..ec19adbd5ae892c6b6d41e375eed9b19fd173168 100644 --- a/Code/Mantid/Framework/Crystal/CMakeLists.txt +++ b/Code/Mantid/Framework/Crystal/CMakeLists.txt @@ -86,7 +86,6 @@ endif(UNITY_BUILD) # Add the target for this directory add_library ( Crystal ${SRC_FILES} ${INC_FILES}) -add_cppcheck( Crystal ) # Set the name of the generated library set_target_properties ( Crystal PROPERTIES OUTPUT_NAME MantidCrystal ) # Add to the 'Framework' group in VS diff --git a/Code/Mantid/Framework/CurveFitting/CMakeLists.txt b/Code/Mantid/Framework/CurveFitting/CMakeLists.txt index 62c14191daf664a8bc2ceb7fc5c1254033c46a1d..a23c3ff030a1a3d32890f428eeb045dbd916f872 100644 --- a/Code/Mantid/Framework/CurveFitting/CMakeLists.txt +++ b/Code/Mantid/Framework/CurveFitting/CMakeLists.txt @@ -131,7 +131,6 @@ endif(UNITY_BUILD) ADD_PRECOMPILED_HEADER( inc/MantidCurveFitting/PrecompiledHeader.h MantidCurveFitting src/PrecompiledHeader.cpp SRC_FILES INC_FILES ) # Add the target for this directory add_library ( CurveFitting ${SRC_FILES} ${INC_FILES}) -add_cppcheck( CurveFitting ) # Set the name of the generated library set_target_properties ( CurveFitting PROPERTIES OUTPUT_NAME MantidCurveFitting ) # Add to the 'Framework' group in VS diff --git a/Code/Mantid/Framework/DataHandling/CMakeLists.txt b/Code/Mantid/Framework/DataHandling/CMakeLists.txt index 23782d1c3a4322e8b732cf5dd6790634cceabf21..2c6e691c71067d4c379d84450f46eae84118850d 100644 --- a/Code/Mantid/Framework/DataHandling/CMakeLists.txt +++ b/Code/Mantid/Framework/DataHandling/CMakeLists.txt @@ -312,7 +312,6 @@ endif(UNITY_BUILD) ADD_PRECOMPILED_HEADER( inc/MantidDataHandling/PrecompiledHeader.h MantidDataHandling src/PrecompiledHeader.cpp SRC_FILES INC_FILES ) # Add the target for this directory add_library ( DataHandling ${SRC_FILES} ${INC_FILES}) -add_cppcheck( DataHandling ) # Set the name of the generated library set_target_properties ( DataHandling PROPERTIES OUTPUT_NAME MantidDataHandling ) # Add to the 'Framework' group in VS diff --git a/Code/Mantid/Framework/DataObjects/CMakeLists.txt b/Code/Mantid/Framework/DataObjects/CMakeLists.txt index df1c2ca90e7e26cf7c9018c6f5b94232bf8d6a40..404d2fdba897c2767c060f42c4e21d3ba49d6435 100644 --- a/Code/Mantid/Framework/DataObjects/CMakeLists.txt +++ b/Code/Mantid/Framework/DataObjects/CMakeLists.txt @@ -95,7 +95,6 @@ endif(UNITY_BUILD) ADD_PRECOMPILED_HEADER( inc/MantidDataObjects/PrecompiledHeader.h MantidDataObjects src/PrecompiledHeader.cpp SRC_FILES INC_FILES ) # Add the target for this directory add_library ( DataObjects ${SRC_FILES} ${INC_FILES}) -add_cppcheck( DataObjects ) # Set the name of the generated library set_target_properties ( DataObjects PROPERTIES OUTPUT_NAME MantidDataObjects COMPILE_DEFINITIONS IN_MANTID_DATA_OBJECTS ) diff --git a/Code/Mantid/Framework/GPUAlgorithms/CMakeLists.txt b/Code/Mantid/Framework/GPUAlgorithms/CMakeLists.txt index 2d2d7badbafd636746712beb52c02fb7d6125cc9..3bbf129d9375b0b4a3f248e7637a6b30190a2835 100644 --- a/Code/Mantid/Framework/GPUAlgorithms/CMakeLists.txt +++ b/Code/Mantid/Framework/GPUAlgorithms/CMakeLists.txt @@ -23,7 +23,6 @@ set ( KERNEL_FILES # Add the target for this directory add_library ( GPUAlgorithms ${SRC_FILES} ${INC_FILES} ) -add_cppcheck( GPUAlgorithms ) # Set the name of the generated library set_target_properties ( GPUAlgorithms PROPERTIES OUTPUT_NAME MantidGPUAlgorithms ) # Add to the 'Framework' group in VS diff --git a/Code/Mantid/Framework/Geometry/CMakeLists.txt b/Code/Mantid/Framework/Geometry/CMakeLists.txt index 843e60f6dda1c5c0665e97cfd08bee49e1a41cc3..d857425f561ead221b0f9d76ee529b2e65e49992 100644 --- a/Code/Mantid/Framework/Geometry/CMakeLists.txt +++ b/Code/Mantid/Framework/Geometry/CMakeLists.txt @@ -1,6 +1,7 @@ set ( SRC_FILES src/ComponentParser.cpp src/Crystal/IndexingUtils.cpp + src/Crystal/ReducedCell.cpp src/Crystal/OrientedLattice.cpp src/Crystal/ReflectionCondition.cpp src/Crystal/UnitCell.cpp @@ -89,6 +90,7 @@ set ( SRC_UNITY_IGNORE_FILES src/Instrument/CompAssembly.cpp set ( INC_FILES inc/MantidGeometry/ComponentParser.h inc/MantidGeometry/Crystal/IndexingUtils.h + inc/MantidGeometry/Crystal/ReducedCell.h inc/MantidGeometry/Crystal/OrientedLattice.h inc/MantidGeometry/Crystal/ReflectionCondition.h inc/MantidGeometry/Crystal/UnitCell.h @@ -190,6 +192,7 @@ set ( TEST_FILES test/IMDDimensionFactoryTest.h test/IMDDimensionTest.h test/IndexingUtilsTest.h + test/ReducedCellTest.h test/InstrumentDefinitionParserTest.h test/InstrumentRayTracerTest.h test/InstrumentTest.h @@ -279,7 +282,6 @@ endif () ADD_PRECOMPILED_HEADER( inc/MantidGeometry/PrecompiledHeader.h MantidGeometry src/PrecompiledHeader.cpp SRC_FILES INC_FILES ) # Add the target for this directory add_library ( Geometry ${SRC_FILES} ${INC_FILES} ) -add_cppcheck( Geometry ) # Set the name of the generated library set_target_properties ( Geometry PROPERTIES OUTPUT_NAME MantidGeometry COMPILE_DEFINITIONS IN_MANTID_GEOMETRY ) diff --git a/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Crystal/ReducedCell.h b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Crystal/ReducedCell.h new file mode 100644 index 0000000000000000000000000000000000000000..622ada9b996b2019bf0299af7a82f80289a095f6 --- /dev/null +++ b/Code/Mantid/Framework/Geometry/inc/MantidGeometry/Crystal/ReducedCell.h @@ -0,0 +1,112 @@ +#ifndef MANTID_GEOMETRY_REDUCED_CELL_H_ +#define MANTID_GEOMETRY_REDUCED_CELL_H_ + +#include "MantidGeometry/DllConfig.h" +#include "MantidKernel/Matrix.h" + +namespace Mantid +{ +namespace Geometry +{ +/** + @class ReducedCell + + Instances of this class represent information about reduced cell types + including the transformation required to transform the reduced cell to + a conventional cell. Essentially, each instance of this class represents + one row of information from Table 2 in the paper: + "Lattice Symmetry and Identification -- The Fundamental Role of Reduced + Cells in Materials Characterization", Alan D. Mighell, Vol. 106, Number 6, + Nov-Dec 2001, Journal of Research of the National Institute of Standards + and Technology. This class is a direct port of the ISAW class + ReducedCellInfo. + + @author Dennis Mikkelson + @date 2012-01-02 + + Copyright © 2012 ORNL, STFC Rutherford Appleton Laboratories + + 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://svn.mantidproject.org/mantid/trunk/Code/Mantid> + + Code Documentation is available at + <http://doxygen.mantidproject.org> + */ + + class MANTID_GEOMETRY_DLL ReducedCell + { + public: + // Construct a ReducedCell for the specified form and lattice parameters + ReducedCell( size_t form_num = 0, + double a = 1, double b = 1, double c = 1, + double alpha = 90, double beta = 90, double gamma = 90 ); + + size_t GetFormNum(); + std::string GetCellType(); + std::string GetCentering(); + + // Get the "distance" between the scalars for this form and another form + double WeightedDistance( const ReducedCell & other ); + + // Get transformation between the Niggli cell and the conventional cell + Kernel::DblMatrix GetTransformation(); + + // String constants for cell types + static const std::string NONE; + static const std::string CUBIC; + static const std::string HEXAGONAL; + static const std::string RHOMBOHEDRAL; + static const std::string TETRAGONAL; + static const std::string ORTHORHOMBIC; + static const std::string MONOCLINIC; + static const std::string TRICLINIC; + + // String constants for centerings + static const std::string F_CENTERED; + static const std::string I_CENTERED; + static const std::string C_CENTERED; + static const std::string P_CENTERED; + static const std::string R_CENTERED; + + enum { NUM_CELL_TYPES = 44 }; + + private: + void init( size_t form_num, + double a_a, double b_b, double c_c, + double b_c, double a_c, double a_b ); + void foot_note_b( double a_a, double a_c ); + void foot_note_c( double b_b, double b_c ); + void foot_note_d( double c_c, double b_c ); + void foot_note_e( double a_a, double c_c, double a_c ); + void foot_note_f( double b_b, double c_c, double a_c ); + void premultiply( size_t index ); + std::vector<double> norm_vals( const ReducedCell &info ); + + size_t form_num; + double scalars[6]; + Kernel::DblMatrix transform; + std::string cell_type; + std::string centering; + }; + +} // namespace Mantid +} // namespace Geometry + +#endif /* MANTID_GEOMETRY_REDUCED_CELL_H_ */ + + diff --git a/Code/Mantid/Framework/Geometry/src/Crystal/ReducedCell.cpp b/Code/Mantid/Framework/Geometry/src/Crystal/ReducedCell.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e24ed4dbc69bb70153c2e8d8c989334da3b99dbe --- /dev/null +++ b/Code/Mantid/Framework/Geometry/src/Crystal/ReducedCell.cpp @@ -0,0 +1,758 @@ +/* File: ReducedCell.cpp */ + +#include "MantidGeometry/Crystal/ReducedCell.h" +#include "MantidKernel/V3D.h" +#include <stdexcept> + +namespace Mantid +{ +namespace Geometry +{ + using Mantid::Kernel::V3D; + using Mantid::Kernel::DblMatrix; + + /** + * Strings representing the cell types. + */ + const std::string ReducedCell::NONE = "None"; + const std::string ReducedCell::CUBIC = "Cubic"; + const std::string ReducedCell::HEXAGONAL = "Hexagonal"; + const std::string ReducedCell::RHOMBOHEDRAL = "Rhombohedral"; + const std::string ReducedCell::TETRAGONAL = "Tetragonal"; + const std::string ReducedCell::ORTHORHOMBIC = "Orthorhombic"; + const std::string ReducedCell::MONOCLINIC = "Monoclinic"; + const std::string ReducedCell::TRICLINIC = "Triclinic"; + + /** + * Strings representing the centering types. + */ + const std::string ReducedCell::F_CENTERED = "F"; + const std::string ReducedCell::I_CENTERED = "I"; + const std::string ReducedCell::C_CENTERED = "C"; + const std::string ReducedCell::P_CENTERED = "P"; + const std::string ReducedCell::R_CENTERED = "R"; + + /** + * Array of basic transformations from reduced cell to conventional cell + * for rows 1 to 44 of Table 2. This array is indexed by the row number + * 1 to 44. Entry 0 is the identity matrix. + */ + static double transforms[ReducedCell::NUM_CELL_TYPES + 1][3][3] = // row + { { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }, // 0 + + { { 1, -1, 1 }, { 1, 1, -1 }, { -1, 1, 1 } }, // 1 + { { 1, -1, 0 }, { -1, 0, 1 }, { -1, -1, -1 } }, // 2 + { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }, // 3 + { { 1, -1, 0 }, { -1, 0, 1 }, { -1, -1, -1 } }, // 4 + { { 1, 0, 1 }, { 1, 1, 0 }, { 0, 1, 1 } }, // 5 + + { { 0, 1, 1 }, { 1, 0, 1 }, { 1, 1, 0 } }, // 6 + { { 1, 0, 1 }, { 1, 1, 0 }, { 0, 1, 1 } }, // 7 + { { -1, -1, 0 }, { -1, 0, -1 }, { 0, -1, -1 } }, // 8 + { { 1, 0, 0 }, { -1, 1, 0 }, { -1, -1, 3 } }, // 9 + { { 1, 1, 0 }, { 1, -1, 0 }, { 0, 0, -1 } }, // 10 + + { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }, // 11 + { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }, // 12 + { { 1, 1, 0 }, { -1, 1, 0 }, { 0, 0, 1 } }, // 13 + { { 1, 1, 0 }, { -1, 1, 0 }, { 0, 0, 1 } }, // 14 + { { 1, 0, 0 }, { 0, 1, 0 }, { 1, 1, 2 } }, // 15 + + { { -1, -1, 0 }, { 1, -1, 0 }, { 1, 1, 2 } }, // 16 + { { -1, 0, -1 }, { -1, -1, 0 }, { 0, 1, 1 } }, // 17 + { { 0, -1, 1 }, { 1, -1, -1 }, { 1, 0, 0 } }, // 18 + { { -1, 0, 0 }, { 0, -1, 1 }, { -1, 1, 1 } }, // 19 + { { 0, 1, 1 }, { 0, 1, -1 }, { -1, 0, 0 } }, // 20 + + { { 0, 1, 0 }, { 0, 0, 1 }, { 1, 0, 0 } }, // 21 + { { 0, 1, 0 }, { 0, 0, 1 }, { 1, 0, 0 } }, // 22 + { { 0, 1, 1 }, { 0, -1, 1 }, { 1, 0, 0 } }, // 23 + { { 1, 2, 1 }, { 0, -1, 1 }, { 1, 0, 0 } }, // 24 + { { 0, 1, 1 }, { 0, -1, 1 }, { 1, 0, 0 } }, // 25 + + { { 1, 0, 0 }, { -1, 2, 0 }, { -1, 0, 2 } }, // 26 + { { 0, -1, 1 }, { -1, 0, 0 }, { 1, -1, -1 } }, // 27 + { { -1, 0, 0 }, { -1, 0, 2 }, { 0, 1, 0 } }, // 28 + { { 1, 0, 0 }, { 1, -2, 0 }, { 0, 0, -1 } }, // 29 + { { 0, 1, 0 }, { 0, 1, -2 }, { -1, 0, 0 } }, // 30 + + { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }, // 31 + { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }, // 32 + { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }, // 33 + { { -1, 0, 0 }, { 0, 0, -1 }, { 0, -1, 0 } }, // 34 + { { 0, -1, 0 }, { -1, 0, 0 }, { 0, 0, -1 } }, // 35 + + { { 1, 0, 0 }, { -1, 0, -2 }, { 0, 1, 0 } }, // 36 + { { 1, 0, 2 }, { 1, 0, 0 }, { 0, 1, 0 } }, // 37 + { { -1, 0, 0 }, { 1, 2, 0 }, { 0, 0, -1 } }, // 38 + { { -1, -2, 0 }, { -1, 0, 0 }, { 0, 0, -1 } }, // 39 + { { 0, -1, 0 }, { 0, 1, 2 }, { -1, 0, 0 } }, // 40 + + { { 0, -1, -2 }, { 0, -1, 0 }, { -1, 0, 0 } }, // 41 + { { -1, 0, 0 }, { 0, -1, 0 }, { 1, 1, 2 } }, // 42 + { { -1, 0, 0 }, { -1, -1, -2 }, { 0, -1, 0 } }, // 43 + { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } } }; // 44 + + /** + * These transforms pre-multiply the basic transforms in certain cases, + * as listed in the footnotes to Table 2. + */ + static double transform_modifier[2][3][3] = + { { { 0, 0, -1 }, { 0, 1, 0 }, { 1, 0, 1 } }, // 0 + { { -1, 0, -1 }, { 0, 1, 0 }, { 1, 0, 0 } } }; // 1 + + /** + * Array of Strings specifying the cell type for reduced cells for rows + * 1 to 44 of Table 2. This array is indexed by the row number 1 to 44. + * Entry 0 is the String "None". + */ + static std::string lattice_types[ReducedCell::NUM_CELL_TYPES + 1] = + { ReducedCell::NONE, // 0 + + ReducedCell::CUBIC, // 1 + ReducedCell::RHOMBOHEDRAL, // 2 + ReducedCell::CUBIC, // 3 + ReducedCell::RHOMBOHEDRAL, // 4 + ReducedCell::CUBIC, // 5 + + ReducedCell::TETRAGONAL, // 6 + ReducedCell::TETRAGONAL, // 7 + ReducedCell::ORTHORHOMBIC, // 8 + ReducedCell::RHOMBOHEDRAL, // 9 + ReducedCell::MONOCLINIC, // 10 + + ReducedCell::TETRAGONAL, // 11 + ReducedCell::HEXAGONAL, // 12 + ReducedCell::ORTHORHOMBIC, // 13 + ReducedCell::MONOCLINIC, // 14 + ReducedCell::TETRAGONAL, // 15 + + ReducedCell::ORTHORHOMBIC, // 16 + ReducedCell::MONOCLINIC, // 17 + ReducedCell::TETRAGONAL, // 18 + ReducedCell::ORTHORHOMBIC, // 19 + ReducedCell::MONOCLINIC, // 20 + + ReducedCell::TETRAGONAL, // 21 + ReducedCell::HEXAGONAL, // 22 + ReducedCell::ORTHORHOMBIC, // 23 + ReducedCell::RHOMBOHEDRAL, // 24 + ReducedCell::MONOCLINIC, // 25 + + ReducedCell::ORTHORHOMBIC, // 26 + ReducedCell::MONOCLINIC, // 27 + ReducedCell::MONOCLINIC, // 28 + ReducedCell::MONOCLINIC, // 29 + ReducedCell::MONOCLINIC, // 30 + + ReducedCell::TRICLINIC, // 31 + ReducedCell::ORTHORHOMBIC, // 32 + ReducedCell::MONOCLINIC, // 33 + ReducedCell::MONOCLINIC, // 34 + ReducedCell::MONOCLINIC, // 35 + + ReducedCell::ORTHORHOMBIC, // 36 + ReducedCell::MONOCLINIC, // 37 + ReducedCell::ORTHORHOMBIC, // 38 + ReducedCell::MONOCLINIC, // 39 + ReducedCell::ORTHORHOMBIC, // 40 + + ReducedCell::MONOCLINIC, // 41 + ReducedCell::ORTHORHOMBIC, // 42 + ReducedCell::MONOCLINIC, // 43 + ReducedCell::TRICLINIC }; // 44 + + /** + * Array of Strings specifying the centering for reduced cells for rows + * 1 to 44 of Table 2. This array is indexed by the row number 1 to 44. + * Entry 0 is the String "None". + */ + static std::string center_types[ReducedCell::NUM_CELL_TYPES + 1] = + { ReducedCell::NONE, // 0 + + ReducedCell::F_CENTERED, // 1 + ReducedCell::R_CENTERED, // 2 + ReducedCell::P_CENTERED, // 3 + ReducedCell::R_CENTERED, // 4 + ReducedCell::I_CENTERED, // 5 + + ReducedCell::I_CENTERED, // 6 + ReducedCell::I_CENTERED, // 7 + ReducedCell::I_CENTERED, // 8 + ReducedCell::R_CENTERED, // 9 + ReducedCell::C_CENTERED, // 10 + + ReducedCell::P_CENTERED, // 11 + ReducedCell::P_CENTERED, // 12 + ReducedCell::C_CENTERED, // 13 + ReducedCell::C_CENTERED, // 14 + ReducedCell::I_CENTERED, // 15 + + ReducedCell::F_CENTERED, // 16 + ReducedCell::I_CENTERED, // 17 + ReducedCell::I_CENTERED, // 18 + ReducedCell::I_CENTERED, // 19 + ReducedCell::C_CENTERED, // 20 + + ReducedCell::P_CENTERED, // 21 + ReducedCell::P_CENTERED, // 22 + ReducedCell::C_CENTERED, // 23 + ReducedCell::R_CENTERED, // 24 + ReducedCell::C_CENTERED, // 25 + + ReducedCell::F_CENTERED, // 26 + ReducedCell::I_CENTERED, // 27 + ReducedCell::C_CENTERED, // 28 + ReducedCell::C_CENTERED, // 29 + ReducedCell::C_CENTERED, // 30 + + ReducedCell::P_CENTERED, // 31 + ReducedCell::P_CENTERED, // 32 + ReducedCell::P_CENTERED, // 33 + ReducedCell::P_CENTERED, // 34 + ReducedCell::P_CENTERED, // 35 + + ReducedCell::C_CENTERED, // 36 + ReducedCell::C_CENTERED, // 37 + ReducedCell::C_CENTERED, // 38 + ReducedCell::C_CENTERED, // 39 + ReducedCell::C_CENTERED, // 40 + + ReducedCell::C_CENTERED, // 41 + ReducedCell::I_CENTERED, // 42 + ReducedCell::I_CENTERED, // 43 + ReducedCell::P_CENTERED }; // 44 + + /** + * Construct a ReducedCellInfo object representing the specified row of + * Table 2 for a reduced cell with the specified lattice parameters, + * if the form number is between 1 and 44 exclusive. If the form number + * is specified to be zero, the scalar values will be calculated according + * to the column headers for Table 2, for comparison purposes. + * + * @param form_num The row number from Table 2, that specifies the + * reduced form number. + * @param a Real space unit cell length "a". + * @param b Real space unit cell length "b". + * @param c Real space unit cell length "c". + * @param alpha Resl space unit cell angle "alpha", in degrees. + * @param beta Resl space unit cell angle "beta", in degrees. + * @param gamma Resl space unit cell angle "gamma", in degrees. + */ + ReducedCell::ReducedCell( size_t form_num, + double a, double b, double c, + double alpha, double beta, double gamma ) + { + if ( a <= 0 || b <= 0 || c <= 0 ) + { + throw std::invalid_argument("ReducedCell(): a, b, c, must be positive"); + } + if ( alpha <= 0 || alpha >= 180 || + beta <= 0 || beta >= 180 || + gamma <= 0 || gamma >= 180 ) + { + throw std::invalid_argument("ReducedCell(): alpha, beta, gamma, must be between 0 and 180 degrees"); + } + + alpha = alpha * M_PI / 180; + beta = beta * M_PI / 180; + gamma = gamma * M_PI / 180; + + init( form_num, + a*a, b*b, c*c, + b*c*cos(alpha), a*c*cos(beta), a*b*cos(gamma) ); + } + + /** + * Initialize all private data to represent one row of Table 2, for the + * row specified by the form number and for the given lattice parameters. + * The form number must be between 1 and 44 to represent an actual row of + * the table and must be 0 to represent the column header scalars, for + * comparison purposes. + */ + void ReducedCell::init( size_t f_num, + double a_a, double b_b, double c_c, + double b_c, double a_c, double a_b ) + { + if ( f_num > NUM_CELL_TYPES ) + { + throw std::invalid_argument( + "Reduced form number must be no more than 44" ); + } + // The mixed dot products should be > 0 for + cell + // types and always appear inside absolute value + // for - cell types, therefore we can deal with + // the absolute value for all rows in the table. + if ( f_num > 0 ) + { + b_c = fabs( b_c ); + a_c = fabs( a_c ); + a_b = fabs( a_b ); + } + + form_num = f_num; + + transform = DblMatrix(3,3,false); + for ( size_t row = 0; row < 3; row++ ) + for ( size_t col = 0; col <3; col++ ) + { + transform[row][col] = transforms[f_num][row][col]; + } + cell_type = lattice_types[ form_num ]; + centering = center_types[ form_num ]; + + if ( form_num == 0 ) + { + scalars[0] = a_a; + scalars[1] = b_b; + scalars[2] = c_c; + } + else if ( form_num <= 8 ) + { + scalars[0] = a_a; + scalars[1] = a_a; + scalars[2] = a_a; + } + else if ( form_num <= 17 ) + { + scalars[0] = a_a; + scalars[1] = a_a; + scalars[2] = c_c; + } + else if ( form_num <= 25 ) + { + scalars[0] = a_a; + scalars[1] = b_b; + scalars[2] = b_b; + } + else + { + scalars[0] = a_a; + scalars[1] = b_b; + scalars[2] = c_c; + } + + double value; + switch( form_num ) + { + case 0: + scalars[3] = b_c; + scalars[4] = a_c; + scalars[5] = a_b; + break; + case 1: + scalars[3] = a_a/2; + scalars[4] = a_a/2; + scalars[5] = a_a/2; + break; + case 2: + scalars[3] = b_c; + scalars[4] = b_c; + scalars[5] = b_c; + break; + case 3: + scalars[3] = 0; + scalars[4] = 0; + scalars[5] = 0; + break; + case 4: + value = -fabs(b_c); + scalars[3] = value; + scalars[4] = value; + scalars[5] = value; + break; + case 5: + scalars[3] = -a_a/3; + scalars[4] = -a_a/3; + scalars[5] = -a_a/3; + break; + case 6: + value = (-a_a + fabs(a_b))/2; + scalars[3] = value; + scalars[4] = value; + scalars[5] = -fabs(a_b);; + break; + case 7: + value = (-a_a + fabs(b_c))/2; + scalars[3] = -fabs(b_c); + scalars[4] = value; + scalars[5] = value; + break; + case 8: + scalars[3] = -fabs(b_c); + scalars[4] = -fabs(a_c); + scalars[5] = -(fabs(a_a) - fabs(b_c) - fabs(a_c)); + break; + case 9: + scalars[3] = a_a/2; + scalars[4] = a_a/2; + scalars[5] = a_a/2; + break; + case 10: + scalars[3] = b_c; + scalars[4] = b_c; + scalars[5] = a_b; + foot_note_d( c_c, b_c ); + break; + case 11: + scalars[3] = 0; + scalars[4] = 0; + scalars[5] = 0; + break; + case 12: + scalars[3] = 0; + scalars[4] = 0; + scalars[5] = -a_a/2; + break; + case 13: + scalars[3] = 0; + scalars[4] = 0; + scalars[5] = -fabs(a_b); + break; + case 14: + value = -fabs(b_c); + scalars[3] = value; + scalars[4] = value; + scalars[5] = -fabs(a_b); + foot_note_d( c_c, b_c ); + break; + case 15: + scalars[3] = -a_a/2; + scalars[4] = -a_a/2; + scalars[5] = 0; + break; + case 16: + value = -fabs(b_c); + scalars[3] = value; + scalars[4] = value; + scalars[5] = -(a_a - 2*fabs(b_c) ); + break; + case 17: + scalars[3] = -fabs(b_c); + scalars[4] = -fabs(a_c); + scalars[5] = -(a_a - fabs(b_c) - fabs(a_c)); + foot_note_e( a_a, c_c, a_c ); + break; + case 18: + scalars[3] = a_a/4; + scalars[4] = a_a/2; + scalars[5] = a_a/2; + break; + case 19: + scalars[3] = b_c; + scalars[4] = a_a/2; + scalars[5] = a_a/2; + break; + case 20: + scalars[3] = b_c; + scalars[4] = a_c; + scalars[5] = a_c; + foot_note_b( a_a, a_c ); + break; + case 21: + scalars[3] = 0; + scalars[4] = 0; + scalars[5] = 0; + break; + case 22: + scalars[3] = -b_b/2; + scalars[4] = 0; + scalars[5] = 0; + break; + case 23: + scalars[3] = -fabs(b_c); + scalars[4] = 0; + scalars[5] = 0; + break; + case 24: + scalars[3] = -(b_b - a_a/3)/2; + scalars[4] = -a_a/3; + scalars[5] = -a_a/3; + break; + case 25: + value = -fabs(a_c); + scalars[3] = -fabs(b_c); + scalars[4] = value; + scalars[5] = value; + foot_note_b( a_a, a_c ); + break; + case 26: + scalars[3] = a_a/4; + scalars[4] = a_a/2; + scalars[5] = a_a/2; + break; + case 27: + scalars[3] = b_c; + scalars[4] = a_a/2; + scalars[5] = a_a/2; + foot_note_f( b_b, c_c, b_c ); + break; + case 28: + scalars[3] = a_b/2; + scalars[4] = a_a/2; + scalars[5] = a_b; + break; + case 29: + scalars[3] = a_c/2; + scalars[4] = a_c; + scalars[5] = a_a/2; + break; + case 30: + scalars[3] = b_b/2; + scalars[4] = a_b/2; + scalars[5] = a_b; + break; + case 31: + scalars[3] = b_c; + scalars[4] = a_c; + scalars[5] = a_b; + break; + case 32: + scalars[3] = 0; + scalars[4] = 0; + scalars[5] = 0; + break; + case 33: + scalars[3] = 0; + scalars[4] = -fabs(a_c); + scalars[5] = 0; + break; + case 34: + scalars[3] = 0; + scalars[4] = 0; + scalars[5] = -fabs(a_b); + break; + case 35: + scalars[3] = -fabs(b_c); + scalars[4] = 0; + scalars[5] = 0; + break; + case 36: + scalars[3] = 0; + scalars[4] = -a_a/2; + scalars[5] = 0; + break; + case 37: + scalars[3] = -fabs(b_c); + scalars[4] = -a_a/2; + scalars[5] = 0; + foot_note_c( b_b, b_c ); + break; + case 38: + scalars[3] = 0; + scalars[4] = 0; + scalars[5] = -a_a/2; + break; + case 39: + scalars[3] = -fabs(b_c); + scalars[4] = 0; + scalars[5] = -a_a/2; + foot_note_d( c_c, b_c ); + break; + case 40: + scalars[3] = -b_b/2; + scalars[4] = 0; + scalars[5] = 0; + break; + case 41: + scalars[3] = -b_b/2; + scalars[4] = -fabs(a_c); + scalars[5] = 0; + foot_note_b( a_a, a_c ); + break; + case 42: + scalars[3] = -b_b/2; + scalars[4] = -a_a/2; + scalars[5] = 0; + break; + case 43: + scalars[3] = -(b_b - fabs(a_b))/2; + scalars[4] = -(a_a - fabs(a_b))/2; + scalars[5] = -fabs(a_b); + break; + case 44: + scalars[3] = -fabs(b_c); + scalars[4] = -fabs(a_c); + scalars[5] = -fabs(a_b); + break; + } + } + + /** + * Adjust tranform and centering according to foot note b of the paper + */ + void ReducedCell::foot_note_b( double a_a, double a_c ) + { + if ( a_a < 4 * fabs(a_c) ) // foot note b + { + premultiply(0); // use matrix modification 0 + centering = I_CENTERED; + } + } + + + /** + * Adjust tranform and centering according to foot note c of the paper + */ + void ReducedCell::foot_note_c( double b_b, double b_c ) + { + if ( b_b < 4 * fabs(b_c) ) // foot note c + { + premultiply(0); // use matrix modification 0 + centering = I_CENTERED; + } + } + + + /** + * Adjust tranform and centering according to foot note d of the paper + */ + void ReducedCell::foot_note_d( double c_c, double b_c ) + { + if ( c_c < 4 * fabs(b_c) ) // foot note d + { + premultiply(0); // use matrix modification 0 + centering = I_CENTERED; + } + } + + + /** + * Adjust tranform and centering according to foot note e of the paper + */ + void ReducedCell::foot_note_e( double a_a, double c_c, double a_c ) + { + if ( 3 * a_a < c_c + 2 * fabs(a_c) ) // foot note e + { + premultiply(1); // use matrix modification 1 + centering = C_CENTERED; + } + } + + + /** + * Adjust tranform and centering according to foot note f of the paper + */ + void ReducedCell::foot_note_f( double b_b, double c_c, double b_c ) + { + if ( 3 * b_b < c_c + 2 * fabs(b_c) ) // foot note f + { + premultiply(1); // use matrix modification 1 + centering = C_CENTERED; + } + } + + + /** + * Adjust the tranformation for this reduced cell by premultiplying + * by modification transform 0 or 1. + */ + void ReducedCell::premultiply( size_t index ) + { + DblMatrix modifier = DblMatrix(3,3,false); + for ( size_t row = 0; row < 3; row++ ) + for ( size_t col = 0; col <3; col++ ) + { + modifier[row][col] = transform_modifier[index][row][col]; + } + transform = modifier * transform; + } + + + /** + * Get the form number used to construct this form + */ + size_t ReducedCell::GetFormNum() + { + return form_num; + } + + /** + * Get the cell type of this form + */ + std::string ReducedCell::GetCellType() + { + return cell_type; + } + + /** + * Get centering assigned to this form. NOTE: This might be different + * from the requested cell type, since sometimes the centering is + * changed. See the foot notes to Table 2 in the paper for details. + */ + std::string ReducedCell::GetCentering() + { + return centering; + } + + /** + * Get the maximum absolute weighted difference between the scalars + * for the specifed ReducedCellInfo object and this ReducedCellInfo. + * A fairly complicated weighting is used to make the effect of a + * difference in cell edge length on lattice corner positions is + * comparable to the effect of a difference in the angles. + * + * @param other The ReducedCellInfo object to compare with the current + * object. + * + * @return The maximum absolute difference between the scalars. + */ + double ReducedCell::WeightedDistance( const ReducedCell & other ) + { + std::vector<double> vals_1 = norm_vals( *this ); + std::vector<double> vals_2 = norm_vals( other ); + + double max = 0; + + for ( size_t i = 0; i < vals_1.size(); i++ ) + { + double difference = fabs( vals_1[i] - vals_2[i] ); + if ( difference > max ) + max = difference; + } + return max; + } + + /** + * Get list of six values, related to the six scalars, but adjusted so + * that changes in these values represent changes of positions of the + * lattice corners of approximately the same magnitude. This is useful + * when comparing how close the lattice for one cell is to the lattice + * for another cell. + */ + std::vector<double> ReducedCell::norm_vals( const ReducedCell &info ) + { + std::vector<double> vals; + vals.resize(6); + + double a = sqrt( info.scalars[0] ); + double b = sqrt( info.scalars[1] ); + double c = sqrt( info.scalars[2] ); + + // Use the side lengths themselves, instead of squares of sides + // so errors correspond to errors in lattice positions + vals[0] = a; + vals[1] = b; + vals[2] = c; + // Use law of cosines to interpret errors in dot products + // interms of errors in lattice positions. + vals[3] = sqrt( ( b*b + c*c - 2 * info.scalars[3] ) ); + vals[4] = sqrt( ( a*a + c*c - 2 * info.scalars[4] ) ); + vals[5] = sqrt( ( a*a + b*b - 2 * info.scalars[5] ) ); + return vals; + } + + /** + * Return the transformation to map the reduced cell to the conventional + * cell, as listed in Table 2, if the form number is between 1 and 44. + * If the form number is 0, this returns the identity transformation. + * + * @return The transformation. + */ + Kernel::DblMatrix ReducedCell::GetTransformation() + { + return transform; + } + +} // namespace Mantid +} // namespace Geometry diff --git a/Code/Mantid/Framework/Geometry/test/ReducedCellTest.h b/Code/Mantid/Framework/Geometry/test/ReducedCellTest.h new file mode 100644 index 0000000000000000000000000000000000000000..c81752de051246dc2ce9b4b6288cb704102b3acb --- /dev/null +++ b/Code/Mantid/Framework/Geometry/test/ReducedCellTest.h @@ -0,0 +1,81 @@ +#ifndef MANTID_GEOMETRY_REDUCED_CELL_TEST_H_ +#define MANTID_GEOMETRY_REDUCED_CELL_TEST_H_ + +#include <cxxtest/TestSuite.h> +#include <MantidKernel/Timer.h> +#include <MantidKernel/System.h> +#include <iostream> +#include <iomanip> +#include <MantidKernel/V3D.h> +#include <MantidKernel/Matrix.h> + +#include <MantidGeometry/Crystal/ReducedCell.h> + +using namespace Mantid::Geometry; +using Mantid::Kernel::Matrix; + +class ReducedCellTest : public CxxTest::TestSuite +{ +public: + void test_WeightedDistance() + { + double quartz_err[45] = { 0.00000, 3.58705, 1.55740, 1.55740, 1.55740, + 0.70989, 0.50000, 1.19527, 1.31295, 3.58705, + 3.58705, 1.55740, 0.00000, 0.00000, 0.00000, + 1.55740, 1.31295, 1.31295, 3.58705, 3.58705, + 1.55740, 1.55740, 1.55740, 1.55740, 0.70989, + 1.55740, 3.58705, 3.58705, 3.58705, 3.58705, + 3.58705, 3.58705, 1.55740, 1.55740, 0.00000, + 1.55740, 1.55740, 1.55740, 0.00000, 0.00000, + 1.55740, 1.55740, 1.55740, 0.78133, 0.00000 }; + + double oxalic_err[45] = { 0.00000, 8.46773, 5.94102, 5.94102, 5.94102, + 5.80000, 5.80000, 5.80000, 5.80000, 2.66773, + 2.50000, 2.50000, 3.48243, 2.50000, 2.50000, + 2.50000, 5.11692, 3.66129,10.96773,10.96773, + 10.47244, 8.30000, 8.30000, 8.30000, 8.30000, + 8.30000, 3.48308, 3.48308, 2.66773, 3.48308, + 1.19537, 2.50865, 1.19537, 0.00000, 1.19537, + 1.19537, 0.13023, 0.13023, 2.26465, 2.26465, + 1.19537, 0.51072, 0.51072, 0.51072, 0.00000 }; + + double silicon_err[45] = { 0.00000, 0.00000, 0.00000, 1.59472, 2.81840, + 2.43702, 2.81840, 2.81840, 2.81840, 0.00000, + 0.00000, 1.59472, 2.81840, 2.81840, 2.81840, + 2.81840, 2.81840, 2.81840, 0.86527, 0.00000, + 0.00000, 1.59472, 2.81840, 2.81840, 2.43702, + 2.81840, 0.86527, 0.00000, 0.86527, 0.86527, + 0.86527, 0.00000, 1.59472, 2.81840, 2.81840, + 2.81840, 2.81840, 2.81840, 2.81840, 2.81840, + 2.81840, 2.81840, 2.81840, 2.81840, 2.81840 }; + double distance; + ReducedCell form_0( 0, 4.9, 4.9, 5.4, 90, 90, 120 ); + + for ( size_t i = 1; i <= 44; i++ ) + { + ReducedCell form_i( i, 4.9, 4.9, 5.4, 90, 90, 120 ); + distance = form_0.WeightedDistance( form_i ); + TS_ASSERT_DELTA( distance, quartz_err[i], 1e-5 ); + } + + form_0 = ReducedCell( 0, 6.1, 3.6, 11.9, 90, 103.3, 90 ); + for ( size_t i = 1; i <= 44; i++ ) + { + ReducedCell form_i( i, 6.1, 3.6, 11.9, 90, 103.3, 90 ); + distance = form_0.WeightedDistance( form_i ); + TS_ASSERT_DELTA( distance, oxalic_err[i], 1e-5 ); + } + + form_0 = ReducedCell( 0, 3.85, 3.85, 3.85, 60, 60, 60 ); + for ( size_t i = 1; i <= 44; i++ ) + { + ReducedCell form_i( i, 3.85, 3.85, 3.85, 60, 60, 60 ); + distance = form_0.WeightedDistance( form_i ); + TS_ASSERT_DELTA( distance, silicon_err[i], 1e-5 ); + } + } + +}; + +#endif /* MANTID_GEOMETRY_REDUCED_CELL_TEST_H_ */ + diff --git a/Code/Mantid/Framework/ICat/CMakeLists.txt b/Code/Mantid/Framework/ICat/CMakeLists.txt index 7ad5ccc60547a69ebcef675714209d32b271bb7b..29bc0baf01a3e2961e090296968393149ace66ce 100644 --- a/Code/Mantid/Framework/ICat/CMakeLists.txt +++ b/Code/Mantid/Framework/ICat/CMakeLists.txt @@ -65,13 +65,6 @@ add_definitions ( -DWITH_OPENSSL -DWITH_NONAMESPACES ) ADD_PRECOMPILED_HEADER( inc/MantidICat/PrecompiledHeader.h MantidICat src/PrecompiledHeader.cpp SRC_FILES INC_FILES ) # Add the target for this directory add_library ( ICat ${SRC_FILES} ${INC_FILES}) -add_cppcheck( ICat - inc/MantidICat/GSoapGenerated/soapH.h - inc/MantidICat/GSoapGenerated/soapICATPortBindingProxy.h - inc/MantidICat/GSoapGenerated/soapStub.h - src/GSoapGenerated.cpp - src/GSoapGenerated/soapC.cpp - src/GSoapGenerated/soapICATPortBindingProxy.cpp ) # Set the name of the generated library set_target_properties ( ICat PROPERTIES OUTPUT_NAME MantidICat COMPILE_DEFINITIONS IN_MANTID_ICAT ) diff --git a/Code/Mantid/Framework/Kernel/CMakeLists.txt b/Code/Mantid/Framework/Kernel/CMakeLists.txt index c4b44e5b53b948873c184bf8348583f0ce995ef9..598d07a11f8a4e46e28c7610ee61af12f44f6c2a 100644 --- a/Code/Mantid/Framework/Kernel/CMakeLists.txt +++ b/Code/Mantid/Framework/Kernel/CMakeLists.txt @@ -278,7 +278,6 @@ endif(UNITY_BUILD) ADD_PRECOMPILED_HEADER ( inc/MantidKernel/PrecompiledHeader.h MantidKernel src/PrecompiledHeader.cpp SRC_FILES INC_FILES ) # Add the target for this directory add_library ( Kernel ${SRC_FILES} ${INC_FILES} ) -add_cppcheck( Kernel ) # Set the name of the generated library set_target_properties ( Kernel PROPERTIES OUTPUT_NAME MantidKernel COMPILE_DEFINITIONS "IN_MANTID_KERNEL;PSAPI_VERSION=1" ) diff --git a/Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt b/Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt index a4ffcbfd3672886251a89a85df0d68ff368ba19c..01290e8b7a65a468d0fc72428ecf4913c20b68c6 100644 --- a/Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt +++ b/Code/Mantid/Framework/MDAlgorithms/CMakeLists.txt @@ -131,7 +131,6 @@ endif(UNITY_BUILD) ADD_PRECOMPILED_HEADER( inc/MantidMDAlgorithms/PrecompiledHeader.h MantidMDAlgorithms src/PrecompiledHeader.cpp SRC_FILES INC_FILES ) # Add the target for this directory add_library ( MDAlgorithms ${SRC_FILES} ${INC_FILES}) -add_cppcheck( MDAlgorithms ) # Set the name of the generated library set_target_properties ( MDAlgorithms PROPERTIES OUTPUT_NAME MantidMDAlgorithms COMPILE_DEFINITIONS IN_MANTID_MDALGORITHMS ) diff --git a/Code/Mantid/Framework/MDAlgorithms/src/UnaryOperationMD.cpp b/Code/Mantid/Framework/MDAlgorithms/src/UnaryOperationMD.cpp index 71afdba1d0c393e650efaff844ea0e31d6fe843e..c9007fe8f1fdf80a8d2ffc185c6c31e1374b8c06 100644 --- a/Code/Mantid/Framework/MDAlgorithms/src/UnaryOperationMD.cpp +++ b/Code/Mantid/Framework/MDAlgorithms/src/UnaryOperationMD.cpp @@ -67,9 +67,27 @@ namespace Mantid m_in = getProperty( inputPropName() ); m_out = getProperty( outputPropName() ); - // Can't do log(123) + // For MatrixWorkspace's ... if (boost::dynamic_pointer_cast<MatrixWorkspace>(m_in)) - throw std::invalid_argument("UnaryOperationMD: can't have a MatrixWorkspace (e.g. WorkspaceSingleValue) as the argument of " + this->name() + "."); + { + // Pass-through to the same function without "MD" + std::string matrixAlg = this->name(); + matrixAlg = matrixAlg.substr(0, matrixAlg.size()-2); + IAlgorithm_sptr alg = this->createSubAlgorithm(matrixAlg); + // Copy all properties from THIS to the non-MD version + std::vector< Property*> props = this->getProperties(); + for (size_t i=0; i<props.size(); i++) + { + Property* prop = props[i]; + alg->setPropertyValue(prop->name(), prop->value()); + } + alg->execute(); + // Copy the output too + MatrixWorkspace_sptr outMW = alg->getProperty("OutputWorkspace"); + IMDWorkspace_sptr out = boost::dynamic_pointer_cast<IMDWorkspace>(outMW); + setProperty("OutputWorkspace", out); + return; + } // Check for validity m_in_event = boost::dynamic_pointer_cast<IMDEventWorkspace>(m_in); diff --git a/Code/Mantid/Framework/MDEvents/CMakeLists.txt b/Code/Mantid/Framework/MDEvents/CMakeLists.txt index d9b21a549becaa8bac0b82ca1734bf34abf85aa7..bb8f27472284582400caa0f9fa0bd3dd9c1c45fc 100644 --- a/Code/Mantid/Framework/MDEvents/CMakeLists.txt +++ b/Code/Mantid/Framework/MDEvents/CMakeLists.txt @@ -143,7 +143,6 @@ endif(UNITY_BUILD) ADD_PRECOMPILED_HEADER( inc/MantidMDEvents/PrecompiledHeader.h MantidMDEvents src/PrecompiledHeader.cpp SRC_FILES INC_FILES ) # Add the target for this directory add_library ( MDEvents ${SRC_FILES} ${INC_FILES}) -add_cppcheck( MDEvents ) # Set the name of the generated library set_target_properties ( MDEvents PROPERTIES OUTPUT_NAME MantidMDEvents COMPILE_DEFINITIONS IN_MANTID_MDEVENT ) diff --git a/Code/Mantid/Framework/MPIAlgorithms/CMakeLists.txt b/Code/Mantid/Framework/MPIAlgorithms/CMakeLists.txt index bb2bd0834559b65b35129e8ea5e388f026db9ce8..87d3d652cc5fdd1eac125aede5a6b23cc3750e81 100644 --- a/Code/Mantid/Framework/MPIAlgorithms/CMakeLists.txt +++ b/Code/Mantid/Framework/MPIAlgorithms/CMakeLists.txt @@ -12,7 +12,6 @@ set ( TEST_FILES test/BroadcastWorkspaceTest.h # Add the target for this directory add_library ( MPIAlgorithms ${SRC_FILES} ${INC_FILES} ) -add_cppcheck( MPIAlgorithms ) # Set the name of the generated library set_target_properties ( MPIAlgorithms PROPERTIES OUTPUT_NAME MantidMPIAlgorithms ) # Add to the 'Framework' group in VS diff --git a/Code/Mantid/Framework/MatlabAPI/CMakeLists.txt b/Code/Mantid/Framework/MatlabAPI/CMakeLists.txt index 18e51efcb2a079a682ab742467d528ea6a7b2173..2923171c59a1538de1eb77b9d212182b525e9af0 100644 --- a/Code/Mantid/Framework/MatlabAPI/CMakeLists.txt +++ b/Code/Mantid/Framework/MatlabAPI/CMakeLists.txt @@ -9,7 +9,6 @@ add_definitions ( -DIN_MANTID_MATLAB_API -DMATLAB_MEX_FILE=1 ) include_directories ( inc ) include_directories ( ${MATLAB_INCLUDE_DIR} ${MATLAB_EXTERN_SRC} ) add_library ( MatlabAPI ${SRC_FILES} ${INC_FILES}) -add_cppcheck( MatlabAPI ) # Set the name of the generated library set_target_properties ( MatlabAPI PROPERTIES OUTPUT_NAME MantidMatlabAPI ) # Add to the 'Framework' group in VS diff --git a/Code/Mantid/Framework/Nexus/CMakeLists.txt b/Code/Mantid/Framework/Nexus/CMakeLists.txt index 2d1fcb5567b85a17d008ea19098ffb46af865a05..4ae945710347d2996d181fcc1ee3138aa18c0fb4 100644 --- a/Code/Mantid/Framework/Nexus/CMakeLists.txt +++ b/Code/Mantid/Framework/Nexus/CMakeLists.txt @@ -19,7 +19,6 @@ add_definitions ( -DIN_NEXUS_CPP_LIBRARY ) # Add the target for this directory add_library ( Nexus ${SRC_FILES} ${INC_FILES}) -add_cppcheck( Nexus ) # Set the name of the generated library set_target_properties ( Nexus PROPERTIES OUTPUT_NAME MantidNexus COMPILE_DEFINITIONS IN_MANTID_NEXUS ) diff --git a/Code/Mantid/Framework/NexusCPP/CMakeLists.txt b/Code/Mantid/Framework/NexusCPP/CMakeLists.txt index 3bd48f684220d98045cd9f963107b90af5e40c36..8c5b57925bcb6bc5e5be28c35f41f270dd3ccfee 100644 --- a/Code/Mantid/Framework/NexusCPP/CMakeLists.txt +++ b/Code/Mantid/Framework/NexusCPP/CMakeLists.txt @@ -17,7 +17,6 @@ add_definitions ( -DIN_NEXUS_CPP_LIBRARY ) # Add the target for this directory add_library ( NexusCPP ${SRC_FILES} ${INC_FILES}) -add_cppcheck( NexusCPP ) # Set the name of the generated library set_target_properties ( NexusCPP PROPERTIES OUTPUT_NAME MantidNexusCPP COMPILE_DEFINITIONS IN_MANTID_NEXUSCPP ) diff --git a/Code/Mantid/Framework/PythonAPI/CMakeLists.txt b/Code/Mantid/Framework/PythonAPI/CMakeLists.txt index 42d826a6df91dfbeba4a55eb69207796f91d8bb8..808f2d1fc10de16cce2ce85c24a9aeb37e995268 100644 --- a/Code/Mantid/Framework/PythonAPI/CMakeLists.txt +++ b/Code/Mantid/Framework/PythonAPI/CMakeLists.txt @@ -90,11 +90,9 @@ endforeach ( PYFILE ) ########################################################################### add_library ( PythonAPI ${SRC_FILES} ${INC_FILES} ${BOOST_SRC} ${PYTHON_INSTALL_FILES} ) -add_cppcheck( PythonAPI ) if ( UNIX ) set ( DLOPEN_SRC src/dlopen.c ) add_library ( dlopen ${DLOPEN_SRC} ) - add_cppcheck( dlopen ) if ( APPLE ) # and in .so on the Mac # Need to remove OpenMP diff --git a/Code/Mantid/Framework/PythonAPI/MantidFramework.py b/Code/Mantid/Framework/PythonAPI/MantidFramework.py index 6c2dc107ace56a1c756929fb54e020aeda273866..9d98a1b811c352ad54cc7f5ac6efff1fc1521b5e 100644 --- a/Code/Mantid/Framework/PythonAPI/MantidFramework.py +++ b/Code/Mantid/Framework/PythonAPI/MantidFramework.py @@ -481,6 +481,8 @@ class ProxyObject(object): self.__obj = obj + + # Prefix for temporary objects within workspace binary operations _binary_op_prefix = '__binary_tmp' # A list of temporary workspaces created by algebraic operations @@ -685,16 +687,27 @@ class WorkspaceProxy(ProxyObject): return self.__do_operation('Xor', rhs, inplace=False, reverse=False, lhs_vars=lhs) - + + def __pow__(self, y): + """ Raise a workspace to a power. Equivalent of x**y. + + Args: + x :: workspace or other type. + y :: exponent + """ + lhs = lhs_info() + return self.__do_unary_operation("PowerMD", lhs, Exponent=y) - def __do_unary_operation(self, op, lhs_vars): + def __do_unary_operation(self, op, lhs_vars, **kwargs): """ Perform the unary operation - @param op :: name of the algorithm to run - @param lhs_vars :: is expected to be a tuple containing the number of lhs variables and + Args: + op :: name of the algorithm to run + lhs_vars :: is expected to be a tuple containing the number of lhs variables and their names as the first and second element respectively + kwargs :: additional properties to give to algorithm """ global _binary_op_tmps @@ -713,6 +726,8 @@ class WorkspaceProxy(ProxyObject): alg = mtd.createAlgorithm(op) alg.setPropertyValue("InputWorkspace", self.getName()) alg.setPropertyValue("OutputWorkspace", output_name) + for (key,value) in kwargs.items(): + alg.setPropertyValue(key,str(value)) alg.execute() resultws = alg.workspace() @@ -823,7 +838,7 @@ class RunProxy(ProxyObject): raise TypeError("Not working for %s" % str(type(value))) prop = self._getHeldObject().getProperty(key) self.__properties[key] = prop - + #------------------------------------------------------------------------------- diff --git a/Code/Mantid/Framework/PythonAPI/mantidsimple.py b/Code/Mantid/Framework/PythonAPI/mantidsimple.py index 6908498a8d384ea8629ad4580f3bbd3d75a9966c..cff1f38cef4536fb4f8dc5e3093fd4155cb35243 100755 --- a/Code/Mantid/Framework/PythonAPI/mantidsimple.py +++ b/Code/Mantid/Framework/PythonAPI/mantidsimple.py @@ -268,4 +268,5 @@ def translate(): translate() - + + diff --git a/Code/Mantid/Framework/PythonAPI/test/MatrixWorkspaceTest.py b/Code/Mantid/Framework/PythonAPI/test/MatrixWorkspaceTest.py index 47f2c73ed0732deedfcc05f071a29b3c740dea92..6c1fd744d7b3becf09a98dfe9377ba22b79066b3 100644 --- a/Code/Mantid/Framework/PythonAPI/test/MatrixWorkspaceTest.py +++ b/Code/Mantid/Framework/PythonAPI/test/MatrixWorkspaceTest.py @@ -10,6 +10,10 @@ class MatrixWorkspaceTest(unittest.TestCase): """ def setUp(self): + mtd.clear() + pass + + def tearDown(self): pass def test_equals_matches_same_data(self): @@ -64,6 +68,22 @@ class MatrixWorkspaceTest(unittest.TestCase): C = B * A C = B + A + def test_plus(self): + CreateWorkspace('A', DataX=[1,2,3], DataY=[2,3], DataE=[2,3]) + A = mtd['A'] + C = A + 5.5 + D = 5.5 + A + # TODO: Re-enable these when we figure out why it fails in system tests + #self.assertAlmostEqual(C.dataY(0)[0], 7.5, 2) + #self.assertAlmostEqual(C.dataY(0)[1], 8.5, 2) + + def test_pow(self): + CreateWorkspace('A', DataX=[1,2,3], DataY=[2,3], DataE=[2,3]) + A = mtd['A'] + C = A ** 2.0 + self.assertEqual(C.getName(), "C") + self.assertAlmostEqual(C.dataY(0)[0], 4.0, 2) + self.assertAlmostEqual(C.dataY(0)[1], 9.0, 2) if __name__ == '__main__': diff --git a/Code/Mantid/Framework/PythonInterface/mantid/api/CMakeLists.txt b/Code/Mantid/Framework/PythonInterface/mantid/api/CMakeLists.txt index eff8223b6763912efebde9dcac61d18f93135b70..501c7258084325cdb930d9043be7bc4119909f2f 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/api/CMakeLists.txt +++ b/Code/Mantid/Framework/PythonInterface/mantid/api/CMakeLists.txt @@ -81,7 +81,6 @@ endforeach ( PYFILE ) ############################################################################################# add_library ( PythonAPIModule ${SRC_FILES} ${INC_FILES} ${PYTHON_INSTALL_FILES} ) -add_cppcheck( PythonAPIModule ) set_python_properties( PythonAPIModule _api ) set_target_output_directory ( PythonAPIModule ${OUTPUT_DIR} .pyd ) diff --git a/Code/Mantid/Framework/PythonInterface/mantid/geometry/CMakeLists.txt b/Code/Mantid/Framework/PythonInterface/mantid/geometry/CMakeLists.txt index 20211daecce845486f6361f0b5275d686825cfca..cc179b41421b3a39215efb46c620fb4adc21c513 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/geometry/CMakeLists.txt +++ b/Code/Mantid/Framework/PythonInterface/mantid/geometry/CMakeLists.txt @@ -58,7 +58,6 @@ endforeach ( PYFILE ) ############################################################################################# add_library ( PythonGeometryModule ${SRC_FILES} ${INC_FILES} ${PYTHON_INSTALL_FILES} ) -add_cppcheck( PythonGeometryModule ) set_python_properties( PythonGeometryModule _geometry ) set_target_output_directory ( PythonGeometryModule ${OUTPUT_DIR} .pyd ) # Add the required dependencies diff --git a/Code/Mantid/Framework/PythonInterface/mantid/kernel/CMakeLists.txt b/Code/Mantid/Framework/PythonInterface/mantid/kernel/CMakeLists.txt index 9e4657cf9b20bcdc4aadb0c32a9a9cf52d706212..8f82865900f2d73db971a7909e05287ae0fe4123 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/kernel/CMakeLists.txt +++ b/Code/Mantid/Framework/PythonInterface/mantid/kernel/CMakeLists.txt @@ -79,7 +79,6 @@ endforeach ( PYFILE ) ############################################################################################# add_library ( PythonKernelModule ${SRC_FILES} ${BOOST_PYTHON_SRC} ${INC_FILES} ${PYTHON_INSTALL_FILES} ) -add_cppcheck( PythonKernelModule ) set_python_properties( PythonKernelModule _kernel ) set_target_output_directory ( PythonKernelModule ${OUTPUT_DIR} .pyd ) # Add the required dependencies diff --git a/Code/Mantid/Framework/WorkflowAlgorithms/CMakeLists.txt b/Code/Mantid/Framework/WorkflowAlgorithms/CMakeLists.txt index d3e09704fcf98bfa7496889c6c08b8d8acda9be5..ecc0d18b4dd4aca64e37c95723dc7fc3c5c181f7 100644 --- a/Code/Mantid/Framework/WorkflowAlgorithms/CMakeLists.txt +++ b/Code/Mantid/Framework/WorkflowAlgorithms/CMakeLists.txt @@ -46,7 +46,6 @@ set ( TEST_PY_FILES test/EQSANSQ2DTest.py test/EQSANSSensitivityCorrectionTest.p ADD_PRECOMPILED_HEADER( inc/MantidWorkflowAlgorithms/PrecompiledHeader.h MantidWorkflowAlgorithms src/PrecompiledHeader.cpp SRC_FILES INC_FILES ) # Add the target for this directory add_library ( WorkflowAlgorithms ${SRC_FILES} ${INC_FILES}) -add_cppcheck( WorkflowAlgorithms ) # Set the name of the generated library set_target_properties ( WorkflowAlgorithms PROPERTIES OUTPUT_NAME MantidWorkflowAlgorithms ) # Add to the 'Framework' group in VS diff --git a/Code/Mantid/MantidPlot/CMakeLists.txt b/Code/Mantid/MantidPlot/CMakeLists.txt index 46872a589b3f7f17d36438f204f9a1fd3f455cc6..4389b883e3b17288b2efb02c9d88795deff3499a 100644 --- a/Code/Mantid/MantidPlot/CMakeLists.txt +++ b/Code/Mantid/MantidPlot/CMakeLists.txt @@ -762,7 +762,6 @@ add_executable ( MantidPlot ${WIN_CONSOLE} MACOSX_BUNDLE ${ALL_SRC} src/main.cpp ${INC_FILES} ${QTIPLOT_C_SRC} ${UI_HDRS} ${RES_FILES} ${MANTID_RC_FILE} ) -add_cppcheck ( MantidPlot ) # Library dependencies target_link_libraries ( MantidPlot diff --git a/Code/Mantid/MantidPlot/src/PythonScripting.cpp b/Code/Mantid/MantidPlot/src/PythonScripting.cpp index 49e684a04f0d1fcd7616f1c761fe83dea8ce72a3..46e7e167ddd405a6a1d48d4898b32eb232f7c30e 100644 --- a/Code/Mantid/MantidPlot/src/PythonScripting.cpp +++ b/Code/Mantid/MantidPlot/src/PythonScripting.cpp @@ -97,10 +97,10 @@ PythonScripting::PythonScripting(ApplicationWindow *parent) #endif // Observe ADS updates - observeAdd(); - observeAfterReplace(); - observeDelete(); - observeADSClear(); + //observeAdd(); + //observeAfterReplace(); + //observeDelete(); + //observeADSClear(); } PythonScripting::~PythonScripting() diff --git a/Code/Mantid/MantidQt/API/CMakeLists.txt b/Code/Mantid/MantidQt/API/CMakeLists.txt index 74b855adc175895ab2a400b28f52fc3f3c0935fe..cd7eddff88ca5b8dbb8d5693253c4e08cb268ade 100644 --- a/Code/Mantid/MantidQt/API/CMakeLists.txt +++ b/Code/Mantid/MantidQt/API/CMakeLists.txt @@ -74,7 +74,6 @@ add_definitions ( -DIN_MANTIDQT_API ) # Use a precompiled header where they are supported ADD_PRECOMPILED_HEADER( inc/MantidQtAPI/PrecompiledHeader.h MantidQtAPI src/PrecompiledHeader.cpp ALL_SRC INC_FILES ) add_library ( MantidQtAPI ${ALL_SRC} ${INC_FILES} ${UI_HDRS} ) -add_cppcheck( MantidQtAPI ) target_link_libraries ( MantidQtAPI ${CORE_MANTIDLIBS} ${QT_LIBRARIES} ${QWT_LIBRARIES} ) diff --git a/Code/Mantid/MantidQt/CMakeLists.txt b/Code/Mantid/MantidQt/CMakeLists.txt index 571700dc406afaef8912d05ce65b617e24cf1275..d51fd061fbeab5cea7fc38d8cb494f73c882c1b5 100644 --- a/Code/Mantid/MantidQt/CMakeLists.txt +++ b/Code/Mantid/MantidQt/CMakeLists.txt @@ -107,7 +107,6 @@ include_directories ( ${CMAKE_CURRENT_BINARY_DIR}/SliceViewer ) # to find the ui # This creates the target library, just for python bindings add_library ( mantidqtpython MODULE ${SIP_SRC} ) -add_cppcheck( mantidqtpython ) if(WIN32) # Windows: Python library name needs to end in .pyd for Windows diff --git a/Code/Mantid/MantidQt/CustomDialogs/CMakeLists.txt b/Code/Mantid/MantidQt/CustomDialogs/CMakeLists.txt index c0ab1f8d352cc6f90047c312df83290fa0de4b80..dd60f1f11ba19523ce38f6cec9e1d677268250ce 100644 --- a/Code/Mantid/MantidQt/CustomDialogs/CMakeLists.txt +++ b/Code/Mantid/MantidQt/CustomDialogs/CMakeLists.txt @@ -64,7 +64,6 @@ endif(UNITY_BUILD) # Use a precompiled header where they are supported ADD_PRECOMPILED_HEADER( inc/MantidQtCustomDialogs/PrecompiledHeader.h MantidQtCustomDialogs src/PrecompiledHeader.cpp ALL_SRC INC_FILES ) add_library ( CustomDialogs ${ALL_SRC} ${INC_FILES} ${UI_HDRS} ) -add_cppcheck( CustomDialogs ) # Set the name of the generated library set_target_properties ( CustomDialogs PROPERTIES OUTPUT_NAME MantidQtCustomDialogs ) diff --git a/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt b/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt index 1621366f901332c689c64a5a722d7ed2d2400098..955d65a1392b89bf850cc71117c060f8595a82d1 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt +++ b/Code/Mantid/MantidQt/CustomInterfaces/CMakeLists.txt @@ -19,6 +19,7 @@ set ( SRC_FILES src/background.cpp src/deltaECalc.cpp src/WorkspaceInADS.cpp + src/WorkspaceMemento.cpp src/WorkspaceOnDisk.cpp ) @@ -104,7 +105,6 @@ endif(UNITY_BUILD) # Use a precompiled header where they are supported ADD_PRECOMPILED_HEADER( inc/MantidQtCustomInterfaces/PrecompiledHeader.h MantidQtCustomInterfaces src/PrecompiledHeader.cpp ALL_SRC INC_FILES ) add_library ( CustomInterfaces ${ALL_SRC} ${INC_FILES} ${UI_HDRS} ) -add_cppcheck( CustomInterfaces ) # Set the name of the generated library set_target_properties ( CustomInterfaces PROPERTIES OUTPUT_NAME MantidQtCustomInterfaces ) diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/CreateMDWorkspace.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/CreateMDWorkspace.h index 9fa1013a89cceb9a93346c06c7ac893704241762..16ef8d018699200e88c06db1370b222a556d9376 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/CreateMDWorkspace.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/CreateMDWorkspace.h @@ -47,8 +47,14 @@ namespace MantidQt void addFileClicked(); + void setUBMatrixClicked(); + void removeSelectedClicked(); + void findUBMatrixClicked(); + + void createMDWorkspaceClicked(); + private: Ui::CreateMDWorkspace m_uiForm; WorkspaceMementoCollection m_data; diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/CreateMDWorkspace.ui b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/CreateMDWorkspace.ui index 49229de869400137455b0ec51495e4f298bcf6c2..efc89abfa37de4eb18e770dc88d784283ed12b3e 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/CreateMDWorkspace.ui +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/CreateMDWorkspace.ui @@ -37,6 +37,9 @@ <verstretch>0</verstretch> </sizepolicy> </property> + <property name="toolTip"> + <string>Add a raw file</string> + </property> <property name="text"> <string>Add Raw File</string> </property> @@ -52,6 +55,9 @@ <verstretch>0</verstretch> </sizepolicy> </property> + <property name="toolTip"> + <string>Remove any workspace once it is highlighted</string> + </property> <property name="text"> <string>Remove Selected</string> </property> @@ -93,7 +99,7 @@ </sizepolicy> </property> <property name="selectionMode"> - <enum>QAbstractItemView::MultiSelection</enum> + <enum>QAbstractItemView::SingleSelection</enum> </property> <property name="selectionBehavior"> <enum>QAbstractItemView::SelectRows</enum> @@ -141,7 +147,22 @@ <property name="title"> <string>UB Matrix</string> </property> - <layout class="QHBoxLayout" name="horizontalLayout_5"/> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QPushButton" name="btn_set_ub_matrix"> + <property name="text"> + <string>Set UB Matrix</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="btn_find_ub_matrix"> + <property name="text"> + <string>Find UB Matrix</string> + </property> + </widget> + </item> + </layout> </widget> </item> </layout> @@ -159,7 +180,6 @@ <property name="title"> <string>Goniometer Settings</string> </property> - <zorder>tableView</zorder> </widget> </item> </layout> diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/WorkspaceInADS.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/WorkspaceInADS.h index 3c164fbaa225a9f319e80eec3d472a36921d8b90..07f37fe595b026da887ab642bd44383a5876eee0 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/WorkspaceInADS.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/WorkspaceInADS.h @@ -57,15 +57,18 @@ namespace MantidQt */ virtual Mantid::API::MatrixWorkspace_sptr fetchIt() const; - virtual std::string statusReport() const; + /* + Do nothing clean-up method. + */ + virtual void cleanUp() + { + } /// Destructor virtual ~WorkspaceInADS(); private: /// Id/name of the workspace in the ADS std::string m_wsName; - /// Status report message. - std::string m_statusReportMessage; }; } diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/WorkspaceMemento.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/WorkspaceMemento.h index 7d94cd0ce8cd1a8357e32a2d35ea719980fa2f4e..347f90bfccf1b1bc0311e91339aa93fe201d58f5 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/WorkspaceMemento.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/WorkspaceMemento.h @@ -42,6 +42,11 @@ namespace MantidQt class DLLExport WorkspaceMemento { public: + //Status enumeration type. + enum Status{NoOrientedLattice=0, Ready}; + + /// Constructor for the workspace memento. + WorkspaceMemento(); /** Getter for the id of the workspace @return the id of the workspace @@ -66,7 +71,15 @@ namespace MantidQt /** Generates a status report based on the workspace state. */ - virtual std::string statusReport() const = 0; + std::string statusReport() + { + return m_statusReport; + } + /// Perform any clean up operations of the underlying workspace + virtual void cleanUp() = 0; + /// Sets the status report overrideing it with the provided message. + void setReport(const Status status); + /// Destructor virtual ~WorkspaceMemento(){}; @@ -76,19 +89,15 @@ namespace MantidQt Common implementation of report generation. @param ws : workspace to report on. */ - std::string generateReport(Mantid::API::MatrixWorkspace_sptr ws) - { - std::string msg; - if(!ws->sample().hasOrientedLattice()) - { - msg = "Has no Oriented Lattice"; - } - else - { - msg = "Ready!"; - } - return msg; - } + void generateReport(Mantid::API::MatrixWorkspace_sptr ws); + + private: + + /// Extract a friendly status. + void interpretStatus(const Status arg); + + /// Status report. + std::string m_statusReport; }; diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/WorkspaceOnDisk.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/WorkspaceOnDisk.h index 5074f361ca0317415a766d80df2f587c7fc2c705..bae83b1b86414b9afc9397d0b64c97f247621d86 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/WorkspaceOnDisk.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/WorkspaceOnDisk.h @@ -58,9 +58,8 @@ namespace MantidQt @throw if workspace has been moved since instantiation. */ virtual Mantid::API::MatrixWorkspace_sptr fetchIt() const; - - virtual std::string statusReport() const; - + ///Clean-up operations + virtual void cleanUp(); /// Destructor virtual ~WorkspaceOnDisk(); private: @@ -68,8 +67,8 @@ namespace MantidQt void dumpIt(const std::string& name); /// Path + name of file containing workspace to use. std::string m_fileName; - /// Status report message. - std::string m_statusReportMessage; + // Id of the workspace in the ADS. + std::string m_adsID; }; } diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/CreateMDWorkspace.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/CreateMDWorkspace.cpp index 165ff4140c1ec4cfd978a1901e24d6ab262f6781..46bf56f8492d0a6a9989cfd161930f4737354380 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/CreateMDWorkspace.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/CreateMDWorkspace.cpp @@ -49,7 +49,7 @@ namespace CustomInterfaces { //Add this class to the list of specialised dialogs in this namespace -//DECLARE_SUBWINDOW(CreateMDWorkspace); //TODO: Enable this to use it via mantid plot. Not ready for this yet! +DECLARE_SUBWINDOW(CreateMDWorkspace); //TODO: Enable this to use it via mantid plot. Not ready for this yet! /** Helper type to perform comparisons between WorkspaceMementos @@ -64,7 +64,7 @@ namespace CustomInterfaces { std::vector<std::string> strs; std::string id = m_benchmark->getId(); - boost::split(strs, id, boost::is_any_of("/")); + boost::split(strs, id, boost::is_any_of("/,\\")); std::stringstream streamPattern; streamPattern << "(" << strs.back() << ")$"; @@ -94,10 +94,58 @@ void CreateMDWorkspace::initLayout() connect(m_uiForm.btn_add_workspace, SIGNAL(clicked()), this, SLOT(addWorkspaceClicked())); connect(m_uiForm.btn_add_file, SIGNAL(clicked()), this, SLOT(addFileClicked())); connect(m_uiForm.btn_remove_workspace, SIGNAL(clicked()), this, SLOT(removeSelectedClicked())); + connect(m_uiForm.btn_set_ub_matrix, SIGNAL(clicked()), this, SLOT(setUBMatrixClicked())); + connect(m_uiForm.btn_find_ub_matrix, SIGNAL(clicked()), this, SLOT(findUBMatrixClicked())); + connect(m_uiForm.btn_create, SIGNAL(clicked()), this, SLOT(createMDWorkspaceClicked())); //Set MVC Model m_uiForm.tableView->setModel(m_model); } +void CreateMDWorkspace::findUBMatrixClicked() +{ + runConfirmation("Not yet implemented!"); +} + +/* +Event handler for setting the UB Matrix +*/ +void CreateMDWorkspace::setUBMatrixClicked() +{ + QTableView* view = m_uiForm.tableView; + QModelIndexList indexes = view->selectionModel()->selection().indexes(); + if(indexes.size() > 0) + { + int index = indexes.front().row(); + WorkspaceMemento_sptr memento = m_data[index]; + Mantid::API::MatrixWorkspace_sptr ws = memento->fetchIt(); + std::string id = memento->getId(); + std::string command = "SetUBDialog(Workspace='" + id + "')"; + + QString pyInput = + "from mantidsimple import *\n" + "import sys\n" + "try:\n" + " SetUBDialog(Workspace='%1')\n" + " print 1\n" + "except:\n" + " print 0\n"; + + pyInput = pyInput.arg(QString(id.c_str())); + QString pyOutput = runPythonCode(pyInput).trimmed(); + + if ( pyOutput == "1" ) + { + memento->setReport(WorkspaceMemento::Ready); + memento->cleanUp(); + m_model->update(); + } + } + else + { + runConfirmation("Nothing selected"); + } +} + /* Add a workspace from the ADS */ @@ -143,8 +191,15 @@ void CreateMDWorkspace::addFileClicked() std::string name = fileName.toStdString(); if(!name.empty()) { - WorkspaceMemento_sptr candidate(new WorkspaceOnDisk(name)); - addUniqueMemento(candidate); + try + { + WorkspaceMemento_sptr candidate(new WorkspaceOnDisk(name)); + addUniqueMemento(candidate); + } + catch(std::invalid_argument& arg) + { + this->runConfirmation(arg.what()); + } } } @@ -195,6 +250,11 @@ int CreateMDWorkspace::runConfirmation(const std::string& message) return msgBox.exec(); } +void CreateMDWorkspace::createMDWorkspaceClicked() +{ + //Launch dialog +} + /// Destructor CreateMDWorkspace::~CreateMDWorkspace() diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/QtWorkspaceMementoModel.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/QtWorkspaceMementoModel.cpp index 1eebf9e2dab87f19b52b4fb3bd914100bfe79ff6..628af1e2cf0bbabeeea41da7bb4efd1950f03b34 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/QtWorkspaceMementoModel.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/QtWorkspaceMementoModel.cpp @@ -87,4 +87,4 @@ namespace CustomInterfaces } } -} +} \ No newline at end of file diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceInADS.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceInADS.cpp index ddbefca5698245e7f1bf8283d2f240ceab3ca9cf..cdfab402afd1418ec3bb704de2d2b6341ad18677 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceInADS.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceInADS.cpp @@ -22,10 +22,10 @@ namespace MantidQt { throw std::invalid_argument("WorkspaceInADS:: Workspace is not a matrix workspace : " + wsName ); } - //Generate an initial report. - m_statusReportMessage = generateReport(ws); + generateReport(ws); } + /** Getter for the id of the workspace @return the id of the workspace @@ -53,15 +53,6 @@ namespace MantidQt return Mantid::API::AnalysisDataService::Instance().doesExist(m_wsName); } - /** - Gets a friendly status report on the state of the workspace memento. - @return a formatted string containing the report. - */ - std::string WorkspaceInADS::statusReport() const - { - return m_statusReportMessage; - } - /** Getter for the workspace itself @returns the matrix workspace diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceMemento.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceMemento.cpp new file mode 100644 index 0000000000000000000000000000000000000000..16289558a51ed737ea7384cb23bcd0e880d0776c --- /dev/null +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceMemento.cpp @@ -0,0 +1,57 @@ +#include "MantidQtCustomInterfaces/WorkspaceMemento.h" + +namespace MantidQt +{ + namespace CustomInterfaces + { + /// Constructor + WorkspaceMemento::WorkspaceMemento() + { + } + + /** + Common implementation of report generation. + @param ws : workspace to report on. + */ + void WorkspaceMemento::generateReport(Mantid::API::MatrixWorkspace_sptr ws) + { + Status status; + if(!ws->sample().hasOrientedLattice()) + { + status = NoOrientedLattice; + } + else + { + status = Ready; + } + interpretStatus(status); + } + + /* + Setter for the status report. + */ + void WorkspaceMemento::setReport(const Status status) + { + interpretStatus(status); + } + + /* + Helper method for extracting friendly messages from status enum. + Single point for providing messages. + */ + void WorkspaceMemento::interpretStatus(const Status status) + { + std::string msg; + if(status == NoOrientedLattice) + { + msg = "Has no Oriented Lattice"; + } + else + { + msg = "Ready!"; + } + m_statusReport = msg; + } + + } +} \ No newline at end of file diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceOnDisk.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceOnDisk.cpp index 2357ee65027d7214c80af06bdaa516375b1b8739..6185d9412c997d683b6f6564b86903dcde88b72a 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceOnDisk.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/WorkspaceOnDisk.cpp @@ -21,15 +21,24 @@ namespace MantidQt std::string msg = "WorkspaceOnDisk:: Unknown File extension on: " + fileName; throw std::invalid_argument(msg); } + if(!checkStillThere()) { throw std::runtime_error("WorkspaceOnDisk:: File doesn't exist"); } + std::vector<std::string> strs; + boost::split(strs, m_fileName, boost::is_any_of("/,\\")); + m_adsID = strs.back(); + m_adsID = m_adsID.substr(0, m_adsID.find('.')); + //Generate an initial report. Mantid::API::MatrixWorkspace_sptr ws = fetchIt(); - m_statusReportMessage = generateReport(ws); - dumpIt(ws->name()); + Mantid::API::Sample sample = ws->mutableSample(); + + generateReport(ws); + + cleanUp(); } /** @@ -61,15 +70,6 @@ namespace MantidQt return !ifile.fail(); } - /** - Gets a friendly status report on the state of the workspace memento. - @return a formatted string containing the report. - */ - std::string WorkspaceOnDisk::statusReport() const - { - return m_statusReportMessage; - } - /** Getter for the workspace itself @returns the matrix workspace @@ -79,13 +79,23 @@ namespace MantidQt { using namespace Mantid::API; + checkStillThere(); + IAlgorithm_sptr alg = Mantid::API::AlgorithmManager::Instance().create("LoadRaw"); alg->initialize(); + alg->setRethrows(true); alg->setProperty("Filename", m_fileName); - alg->setProperty("OutputWorkspace", "_tmp"); + alg->setPropertyValue("OutputWorkspace", m_adsID); alg->execute(); - return boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve("_tmp")); + Mantid::API::Workspace_sptr ws = AnalysisDataService::Instance().retrieve(m_adsID); + + Mantid::API::WorkspaceGroup_sptr gws = boost::dynamic_pointer_cast<WorkspaceGroup>(ws); + if(gws != NULL) + { + throw std::invalid_argument("This raw file corresponds to a WorkspaceGroup. Cannot process groups like this. Import via MantidPlot instead."); + } + return boost::dynamic_pointer_cast<MatrixWorkspace>(ws); } /** @@ -106,5 +116,11 @@ namespace MantidQt { } + /// Clean up. + void WorkspaceOnDisk::cleanUp() + { + dumpIt(m_adsID); + } + } } \ No newline at end of file diff --git a/Code/Mantid/MantidQt/DesignerPlugins/CMakeLists.txt b/Code/Mantid/MantidQt/DesignerPlugins/CMakeLists.txt index d57eb10cb059b78324046d9499fbcb0b37ed6ea8..41de695240487229477e2df641c9ab6197ae1d68 100644 --- a/Code/Mantid/MantidQt/DesignerPlugins/CMakeLists.txt +++ b/Code/Mantid/MantidQt/DesignerPlugins/CMakeLists.txt @@ -36,7 +36,6 @@ if(UNITY_BUILD) endif(UNITY_BUILD) add_library ( DesignerPlugins ${SRC_FILES} ${INC_FILES} ${MOCCED_FILES} ) -add_cppcheck( DesignerPlugins ) # Change the destination of the target as Qt expects this in a directory called "designer" SET_TARGET_OUTPUT_DIRECTORY( DesignerPlugins ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/designer ) diff --git a/Code/Mantid/MantidQt/Factory/CMakeLists.txt b/Code/Mantid/MantidQt/Factory/CMakeLists.txt index a8550a41d0906e3d086f6c2d27fdb0bb3f16f95e..1545e3877071b1ad3d0aa2fee7bf5e4d6a120bbd 100644 --- a/Code/Mantid/MantidQt/Factory/CMakeLists.txt +++ b/Code/Mantid/MantidQt/Factory/CMakeLists.txt @@ -38,7 +38,6 @@ add_definitions ( -DIN_MANTIDQT_FACTORY ) # This creates the target library add_library ( MantidQtFactory ${ALL_SRC} ${INC_FILES} ${UI_HDRS} ) -add_cppcheck( MantidQtFactory ) # ... and links to other required libs target_link_libraries ( MantidQtFactory MantidQtAPI QtPropertyBrowser MantidQtSliceViewer ${QT_LIBRARIES} ${QWT_LIBRARIES} ) diff --git a/Code/Mantid/MantidQt/MantidWidgets/CMakeLists.txt b/Code/Mantid/MantidQt/MantidWidgets/CMakeLists.txt index a014b1815cbee0042a3ea3dfcecbf6d2452c794e..bc9918532a70bbb374b34b425bfc30a782713ff2 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/CMakeLists.txt +++ b/Code/Mantid/MantidQt/MantidWidgets/CMakeLists.txt @@ -99,7 +99,6 @@ add_definitions ( -DIN_MANTIDQT_MANTIDWIDGETS ) # Use a precompiled header where they are supported ADD_PRECOMPILED_HEADER( inc/MantidQtMantidWidgets/PrecompiledHeader.h MantidQtMantidWidgets src/PrecompiledHeader.cpp ALL_SRC INC_FILES ) add_library ( MantidWidgets ${ALL_SRC} ${INC_FILES} ${UI_HDRS} ) -add_cppcheck( MantidWidgets ) target_link_libraries ( MantidWidgets MantidQtAPI QtPropertyBrowser ${QT_LIBRARIES} ${QWT_LIBRARIES} ) diff --git a/Code/Mantid/MantidQt/SliceViewer/CMakeLists.txt b/Code/Mantid/MantidQt/SliceViewer/CMakeLists.txt index 8cd502480ebbecee02f377857cfc9cf491d55615..8e5c746aa47d2575548600fd8ed46609071ad297 100644 --- a/Code/Mantid/MantidQt/SliceViewer/CMakeLists.txt +++ b/Code/Mantid/MantidQt/SliceViewer/CMakeLists.txt @@ -80,7 +80,6 @@ add_definitions ( -DIN_MANTIDQT_SLICEVIEWER ) # This creates the target library add_library ( MantidQtSliceViewer ${ALL_SRC} ${INC_FILES} ${UI_HDRS} ) -add_cppcheck( MantidQtSliceViewer ) # ... and links to other required libs target_link_libraries ( MantidQtSliceViewer MantidQtAPI QtPropertyBrowser ${QT_LIBRARIES} ${QWT_LIBRARIES} ) diff --git a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/CMakeLists.txt b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/CMakeLists.txt index c430b2b08210ab773453ee2f4455e3feaffe8ba9..9224f28ca8a9769e6f6afdfceaa9829c0152b45c 100644 --- a/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/CMakeLists.txt +++ b/Code/Mantid/Vates/ParaviewPlugins/ParaViewWidgets/QtWidgets/CMakeLists.txt @@ -27,7 +27,6 @@ qt4_wrap_cpp( MOCCED_FILES ${HDR_FILES} ) project( MantidParaViewQtWidgets ) add_library( MantidParaViewQtWidgets ${SRC_FILES} ${MOCCED_FILES} ${INC_FILES} ) -add_cppcheck( MantidParaViewQtWidgets ) # Add to the 'Vates' group in VS set_property( TARGET MantidParaViewQtWidgets PROPERTY FOLDER "MantidVates" ) target_link_libraries( MantidParaViewQtWidgets ${QT_LIBRARIES} diff --git a/Code/Mantid/Vates/VatesAPI/CMakeLists.txt b/Code/Mantid/Vates/VatesAPI/CMakeLists.txt index 04aaabf36676afc3aff046e280707df1f794cc7e..42bc5493ad5132604c422498f02279de58f94686 100644 --- a/Code/Mantid/Vates/VatesAPI/CMakeLists.txt +++ b/Code/Mantid/Vates/VatesAPI/CMakeLists.txt @@ -160,7 +160,6 @@ add_definitions( -DIN_MANTID_VATESAPI ) ADD_PRECOMPILED_HEADER( inc/MantidVatesAPI/PrecompiledHeader.h MantidVatesAPI src/PrecompiledHeader.cpp SRC_FILES INC_FILES ) # Add the target for this directory add_library( VatesAPI ${SRC_FILES} ${INC_FILES} ) -add_cppcheck( VatesAPI ) # Set the name of the generated library set_target_properties( VatesAPI PROPERTIES OUTPUT_NAME MantidVatesAPI ) # Add to the 'Framework' group in VS diff --git a/Code/Mantid/Vates/VatesSimpleGui/QtWidgets/CMakeLists.txt b/Code/Mantid/Vates/VatesSimpleGui/QtWidgets/CMakeLists.txt index acd784040e994c6cb509ed9efaddb5001a6d6ff7..395c2ef3bda150981c5510e1848c689a928fd7a0 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/QtWidgets/CMakeLists.txt +++ b/Code/Mantid/Vates/VatesSimpleGui/QtWidgets/CMakeLists.txt @@ -60,7 +60,6 @@ ${RES_FILES} add_definitions( -DIN_MANTID_VATES_SIMPLEGUI_QTWIDGETS ) # Add the target for this directory add_library( VatesSimpleGuiQtWidgets ${ALL_FILES} ) -add_cppcheck( VatesSimpleGuiQtWidgets ) # Set the name of the generated library set_target_properties( VatesSimpleGuiQtWidgets PROPERTIES OUTPUT_NAME MantidVatesSimpleGuiQtWidgets ) # Add to the 'VatesSimpleGui' group in VS diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt index 87eeec937f50abf7ac087ab57e082e953a4ad5d9..51324714fbb4b5b0857dca64667187dbc963d690 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt @@ -76,7 +76,6 @@ ${RES_FILES} add_definitions( -DIN_MANTID_VATES_SIMPLEGUI_VIEWWIDGETS ) # Add the target for this directory add_library( VatesSimpleGuiViewWidgets ${ALL_FILES} ) -add_cppcheck( VatesSimpleGuiViewWidgets ) # Set the name of the generated library set_target_properties( VatesSimpleGuiViewWidgets PROPERTIES OUTPUT_NAME MantidVatesSimpleGuiViewWidgets ) # Add to the 'VatesSimpleGui' group in VS diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/MultisliceView.h b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/MultisliceView.h index 1814d759c4729f0124dec2e23c712ca180da0fca..6919dc7b12fae8e02228368d4f392d4ee35fc421 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/MultisliceView.h +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/MultisliceView.h @@ -65,6 +65,8 @@ public: /// Default constructor. virtual ~MultiSliceView(); + /// ViewBase::closeSubWindows + void closeSubWindows(); /** * ViewBase::destroyView */ diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h index 9e3b7c8fdde6e03b851a40f8470e1331eafa0b13..4fedaf5c37ead29e219c892852a50711006e7ded 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h @@ -64,6 +64,8 @@ public: /// Poll the view to set status for mode control buttons. virtual void checkView(); + /// Close view generated sub-windows. + virtual void closeSubWindows(); /** * Function used to correct post-accept visibility issues. Most * views won't need to do anything. diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp index d9d790e784e3cf5bbed107d3b785b8bf0b4b4a8f..7be90f83cb7421984c4562dc3b997f3dbb0e723c 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp @@ -387,6 +387,7 @@ void MdViewerWidget::checkForUpdates() void MdViewerWidget::switchViews(ModeControlWidget::Views v) { + this->currentView->closeSubWindows(); this->removeProxyTabWidgetConnections(); this->hiddenView = this->setMainViewWidget(this->ui.viewWidget, v); this->hiddenView->hide(); @@ -530,6 +531,6 @@ void MdViewerWidget::onRotationPoint() this->rotPointDialog->activateWindow(); } -} -} -} +} // namespace SimpleGui +} // namespace Vates +} // namespace Mantid diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/MultisliceView.cpp b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/MultisliceView.cpp index 9a50dc884a2343baaa97b945463d85864609113b..479a3c4773ca1f95cf7e0e7765600918a16cf3c9 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/MultisliceView.cpp +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/MultisliceView.cpp @@ -581,9 +581,6 @@ void MultiSliceView::showCutInSliceViewer(const QString &name) src1 = smModel->getItemAtIndex<pqPipelineSource *>(0); } - this->printProxyProps(src1); - - // Get the current dataset characteristics const char *inGeomXML = vtkSMPropertyHelper(src1->getProxy(), "InputGeometryXML").GetAsString(); @@ -615,8 +612,7 @@ void MultiSliceView::showCutInSliceViewer(const QString &name) MDImplicitFunction_sptr impplane(new MDPlaneImplicitFunction(3, orient, origin)); - rks.setImplicitFunction(impplane); - //std::cout << rks.createXMLString() << std::endl; + rks.setImplicitFunction(impplane);; QString titleAddition = name; // Use the WidgetFactory to create the slice viewer window @@ -624,10 +620,18 @@ void MultiSliceView::showCutInSliceViewer(const QString &name) // Set the slice points, etc, using the XML definition of the plane function w->getSlicer()->openFromXML( QString::fromStdString(rks.createXMLString()) ); w->show(); - - //TODO: Connect to application windows shutdown signal to close the slice viewer with the window. } +/** + * This function closes user requested SliceViewer windows when the view is + * closed. The function is a no-op (except for factory creation) when no + * SliceViewer windows were requested. + */ +void MultiSliceView::closeSubWindows() +{ + MantidQt::Factory::WidgetFactory::Instance()->closeAllSliceViewerWindows(); } -} -} + +} // namespace SimpleGui +} // namespace Vates +} // namespace Mantid diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp index e47dde8ab1f7abd7da5b7151c5e9677331219e85..26809565e934abcdc43a692e7c6596de76897644 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp @@ -388,6 +388,14 @@ double ViewBase::getCurrentTimeStep() return scene->getAnimationTime(); } +/** + * This function will close view generated sub-windows. Most views will not + * reimplement this function, so the default is to do nothing. + */ +void ViewBase::closeSubWindows() +{ +} + } // namespace SimpleGui } // namespace Vates } // namespace Mantid