Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sandialabs/InterSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohns committed Aug 12, 2023
2 parents 69b2613 + 19ebf1d commit 9056a36
Show file tree
Hide file tree
Showing 21 changed files with 3,855 additions and 1,250 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ set(sources
src/MoreNuclideInfoDisplay.cpp
src/UndoRedoManager.cpp
src/AppUtils.cpp
src/ExportSpecFile.cpp
js/SpectrumChart.js
js/InterSpec.js
)
Expand Down Expand Up @@ -439,6 +440,7 @@ set(headers
InterSpec/MoreNuclideInfoDisplay.h
InterSpec/UndoRedoManager.h
InterSpec/AppUtils.h
InterSpec/ExportSpecFile.h
)


Expand Down Expand Up @@ -848,6 +850,7 @@ list( APPEND OTHER_InterSpec_SUPPORT_FILES
${CMAKE_CURRENT_SOURCE_DIR}/InterSpec_resources/themes/dark/dark.css
${CMAKE_CURRENT_SOURCE_DIR}/InterSpec_resources/static_text/copyright_and_about.xml
${CMAKE_CURRENT_SOURCE_DIR}/InterSpec_resources/static_text/use_instructions.xml
${CMAKE_CURRENT_SOURCE_DIR}/InterSpec_resources/static_text/spectrum_file_format_descriptions.xml
)

FILE(GLOB CSS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/InterSpec_resources/*.css )
Expand Down
2 changes: 1 addition & 1 deletion InterSpec/CompactFileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class CompactFileManager : public Wt::WContainerWidget

private:
Wt::WComboBox *m_selects[3];
Wt::WText *m_displayedPreTexts[3];
Wt::WText *m_displayedPreTexts[3]; //Doesnt look to be used anymore
Wt::WText *m_displayedPostTexts[3];
Wt::WContainerWidget *m_sampleDivs[3];
Wt::WLineEdit *m_displaySampleNumEdits[3];
Expand Down
258 changes: 258 additions & 0 deletions InterSpec/ExportSpecFile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
#ifndef ExportSpecFile_h
#define ExportSpecFile_h
/* InterSpec: an application to analyze spectral gamma radiation data.
Copyright 2018 National Technology & Engineering Solutions of Sandia, LLC
(NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
Government retains certain rights in this software.
For questions contact William Johnson via email at wcjohns@sandia.gov, or
alternative emails of interspec@sandia.gov.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "InterSpec_config.h"

#include <set>
#include <string>
#include <vector>
#include <memory>
#include <cstdint>

#include <Wt/WContainerWidget>

#include "InterSpec/SimpleDialog.h"

class SpecMeas;
class InterSpec;


namespace Wt
{
class WText;
class WMenu;
class WCheckBox;
class WLineEdit;
}//namespace Wt

namespace SpecUtils
{
enum class SpectrumType : int;
enum class SaveSpectrumAsType : int;
}

namespace ExportSpecFileTool_imp
{
class DownloadSpectrumResource;
}

/**
TODO:
- Add a checkbox for excluding serial number, or other sensitive info
- Fix up displaying for undersized displays
- Peaks aren't re-fit if background subtracted is selected - skeleton code is in there for this.
*/

class ExportSpecFileTool : public Wt::WContainerWidget
{
public:
/** Constructor to create tool to select from any currently loaded spectrum files. */
ExportSpecFileTool( InterSpec *viewer, Wt::WContainerWidget *parent );

/** Constructor to create tool to export only the spectrum file passed in.
@param spectrum The spectrum file to allow exporting.
@param samples The samples to use for the export; if empty, and there are multiple, then user will be given option to select samples.
@param detectors The detectors to use for the export; if empty, and there are multiple, then user will be given option to select samples.
*/
ExportSpecFileTool( const std::shared_ptr<const SpecMeas> &spectrum,
const std::set<int> &samples,
const std::vector<std::string> &detectors,
InterSpec *viewer,
Wt::WContainerWidget *parent );

Wt::Signal<bool> &done();

void emitDone( const bool exported );

/** Returns the currently selected file - as held in memory; i.e., the full file, not just selected samples or whatever. */
std::shared_ptr<const SpecMeas> currentlySelectedFile() const;

/** Returns sample numbers from `currentlySelectedFile()` that will be placed in the output. */
std::set<int> currentlySelectedSamples() const;

/** Returns detector names from `currentlySelectedFile()` that will be placed in the output. */
std::vector<std::string> currentlySelectedDetectors() const;

/** Returns the currently selected save-as file type.
If QR-codes are enabled, returns SpecUtils::SaveSpectrumAsType::NumTypes for it.
*/
SpecUtils::SaveSpectrumAsType currentSaveType() const;


/** Returns 1 (ex., SPE, CHN, etc), 2 (QR-code), or `numeric_limits<uint16_t>::max()` (N42, PCF, etc),
depending on the currently selected save-as type.
@param spec The spectrum file to be saved; optional (but saves a call to `currentlySelectedFile`),
and only used for QR-code format to determine one or two spectra
*/
uint16_t maxRecordsInCurrentSaveType( std::shared_ptr<const SpecMeas> spec ) const;

/** Returns if this option is selected in the GUI; the `generateFileToSave()` function will have removed
most info, but if we are saving to N42, then we'll be a bit more careful and remove more at export time.
*/
bool removeInterSpecInfo() const;

/** Generates the final spectrums file, ready to be given to the user.
E.g., if user selected, all detectors will be summed, or samples numbers, etc.
Throws exception if there is issue generating the file.
*/
std::shared_ptr<const SpecMeas> generateFileToSave();


/** Handles receiving a "deep-link" url starting with "interspec://specsum/...".
Example URIs:
- "interspec://specsum?V=1&LOW=180&HIGH=190"
@param query_str The query portion of the URI. So for example, if the URI has a value of
"interspec://specexport?V=1&FORMAT=N42-2012&Samples=1,2&...", then this string would be "V=1&FORMAT=N42-2012&Samples=1,2&...".
Assumes the string passed in has alaready been url-decoded.
If not a valid query_str, throws exception.
*/
void handleAppUrl( std::string query_str );

/** Encodes current tool state to app-url format. Returned string does not include the
"interspec://" protocol, or "specexport" path; so will look something like "V=1&FORMAT=N42-2012&Samples=1,2&..",
and it will not be url-encoded.
*/
std::string encodeStateToUrl() const;


/** Converts texts ranges like "1-5,8-9,11,12" into the numerical sample numbers. */
static std::pair<std::set<int>,std::string> sampleNumbersFromTxtRange( std::string txt,
std::shared_ptr<const SpecMeas> meas,
const bool quiet );

protected:
void init();
void updateExportEnabled();
void handleFileSelectionChanged();
void updateInfoAboutSelectedFile();
void refreshSampleAndDetectorOptions();
void selectDisplayedFile( const SpecUtils::SpectrumType type );
void handleAllSampleChanged();
void handleCustomSampleChanged();
void handleCustomSampleTxtChanged();
void handleDisplaySampleChanged( const SpecUtils::SpectrumType type );
void handleSamplesChanged();
void handleFormatChange();
void handleForePlusBackChanged();
void handleFilterDetectorCbChanged();

void handleSumToSingleRecordChanged();
void handleSumTypeToSingleRecordChanged();
void handleBackSubForeChanged();
void handleSumDetPerSampleChanged();
void handleIncludeInterSpecInfoChanged();

#if( USE_QR_CODES )
void handleGenerateQrCode();
#endif


InterSpec *m_interspec;

/** Wether or not the dialog is for a specific file, or any loaded file. */
const bool m_is_specific_file;

std::shared_ptr<const SpecMeas> m_specific_spectrum;
std::set<int> m_specific_samples;
std::vector<std::string> m_specific_detectors;

std::weak_ptr<const SpecMeas> m_current_file;

Wt::Signal<bool> m_done;

Wt::WComboBox *m_fileSelect;
Wt::WCheckBox *m_forePlusBack;

Wt::WText *m_fileInfo;

Wt::WMenu *m_formatMenu;

Wt::WContainerWidget *m_samplesHolder;
Wt::WCheckBox *m_dispForeSamples;
Wt::WCheckBox *m_dispBackSamples;
Wt::WCheckBox *m_dispSecondSamples;
Wt::WCheckBox *m_allSamples;
Wt::WCheckBox *m_customSamples;
Wt::WLineEdit *m_customSamplesEdit;
Wt::WCheckBox *m_filterDetector;
/** A <div /> that will only contain WCheckBox's, where the label of each CB will be the detectors name. */
Wt::WContainerWidget *m_detectorFilterCbs;

Wt::WContainerWidget *m_optionsHolder;
Wt::WCheckBox *m_sumAllToSingleRecord;
Wt::WCheckBox *m_sumForeToSingleRecord;
Wt::WCheckBox *m_sumBackToSingleRecord;
Wt::WCheckBox *m_sumSecoToSingleRecord;
Wt::WCheckBox *m_backSubFore;
Wt::WCheckBox *m_sumDetsPerSample;
Wt::WCheckBox *m_excludeInterSpecInfo;
Wt::WCheckBox *m_excludeGpsInfo;

Wt::WText *m_sampleSelectNotAppTxt;
Wt::WText *m_optionsNotAppTxt;

Wt::WText *m_msg;

ExportSpecFileTool_imp::DownloadSpectrumResource *m_resource;
Wt::WPushButton *m_export_btn;
#if( USE_QR_CODES )
Wt::WPushButton *m_show_qr_btn;
#endif
};//class ExportSpecFileTool


class ExportSpecFileWindow : public SimpleDialog
{
public:
ExportSpecFileWindow( InterSpec *viewer );

ExportSpecFileWindow( const std::shared_ptr<const SpecMeas> &spectrum,
const std::set<int> &samples,
const std::vector<std::string> &detectors,
InterSpec *viewer );

void setSpecificSpectrum( const std::shared_ptr<const SpecMeas> &spectrum,
const std::set<int> &samples,
const std::vector<std::string> &detectors,
InterSpec *viewer );

void handleAppUrl( const std::string &query_str );
std::string encodeStateToUrl() const;

void scheduleDelete();
protected:

ExportSpecFileTool *m_tool;
};//class MoreNuclideInfoWindow


#endif //ExportSpecFile_h
39 changes: 21 additions & 18 deletions InterSpec/InterSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class UnitsConverterTool;
class FeatureMarkerWindow;
class D3SpectrumDisplayDiv;
class DetectorPeakResponse;
class ExportSpecFileWindow;
class IsotopeSearchByEnergy;
class ShieldingSourceDisplay;
class EnergyCalPreserveWindow;
Expand Down Expand Up @@ -377,9 +378,6 @@ class InterSpec : public Wt::WContainerWidget
std::set<int> sampleNumbersForTypeFromForegroundFile(
const SpecUtils::SpectrumType spec_type ) const;

#if( IOS )
void exportSpecFile();
#endif

#if( USE_DB_TO_STORE_SPECTRA )
//measurmentFromDb(...): returns the measurment that has been, or will be
Expand Down Expand Up @@ -805,11 +803,8 @@ class InterSpec : public Wt::WContainerWidget
*/
void showLicenseAndDisclaimersWindow();

/** Brings up a dialog asking the user to confirm starting a new session, and if they select so, will start new session. */
void startClearSession();

/** Deletes disclaimer, license, and statment window and sets m_licenseWindow
to nullptr;
to nullptr;
*/
void deleteLicenseAndDisclaimersWindow();

Expand All @@ -833,6 +828,22 @@ class InterSpec : public Wt::WContainerWidget
// showing), and sets m_preserveCalibWindow to null
void deleteEnergyCalPreserveWindow();

/** Shows the spectrum file export dialog.
Sets the `m_exportSpecFileWindow` member variable to the created window.
*/
ExportSpecFileWindow *createExportSpectrumFileDialog();

/** Deletes the spectrum file export dialog.
Sets the `m_exportSpecFileWindow` member variable to nullptr.
*/
void handleExportSpectrumFileDialogClose();

/** Brings up a dialog asking the user to confirm starting a new session, and if they select so, will start new session. */
void startClearSession();


//showIEWarningDialog(): returns NULL if user previously specified to not show
// again, otherwise it returns the AuxWIndow it is displaying. The dialog
// is by default shown visible, and will deleted when user is done with it.
Expand Down Expand Up @@ -1371,17 +1382,9 @@ class InterSpec : public Wt::WContainerWidget
PopupDivMenu *m_rightClickChangeContinuumMenu;

Wt::WMenuItem *m_showPeakManager;

#if( !IOS && !ANDROID )
#define USE_SAVEAS_FROM_MENU 1
//m_downloadMenu:
PopupDivMenu *m_downloadMenu;
//m_downloadMenus: menu items that allow user to download current showing
// spectrums (SpecUtils::SpectrumType::Foreground, SpecUtils::SpectrumType::SecondForeground, SpecUtils::SpectrumType::Background)
PopupDivMenu *m_downloadMenus[3];
#else
#define USE_SAVEAS_FROM_MENU 0
#endif

PopupDivMenuItem *m_exportSpecFileMenu;
ExportSpecFileWindow *m_exportSpecFileWindow;

//If I ever get the preference tracking stuff working better, I could probably
// eliminate the following variables
Expand Down
6 changes: 6 additions & 0 deletions InterSpec/InterSpecApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ class InterSpecApp : public Wt::WApplication
// other not-super-fast actions.
static std::string tempDirectory();


/** Returns a int, representing compile date.
For example, will return value 20120122 if you compile on Jan 22nd, 2012.
*/
static uint32_t compileDateAsInt();

#if( !BUILD_FOR_WEB_DEPLOYMENT )
/** Returns the token passed as part of url using parameter 'externalid' or 'apptoken'.
e.g., if url looked like "localhost:8080?externalid=blah", then this function would return "blah"
Expand Down
Loading

0 comments on commit 9056a36

Please sign in to comment.