Skip to content

Commit f44aab6

Browse files
committed
Merge branch 'master' of github.com:sandialabs/InterSpec
2 parents aa6394d + 8ada7a7 commit f44aab6

34 files changed

+2531
-1005
lines changed

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ set(sources
266266
src/SpectrumChart.cpp
267267
src/SpectrumDataModel.cpp
268268
src/HelpSystem.cpp
269+
src/InjaLogDialog.cpp
269270
src/InterSpec.cpp
270271
src/InterSpecServer.cpp
271272
src/PopupDiv.cpp
@@ -379,6 +380,7 @@ set(headers
379380
InterSpec/SpectrumChart.h
380381
InterSpec/SpectrumDataModel.h
381382
InterSpec/HelpSystem.h
383+
InterSpec/InjaLogDialog.h
382384
InterSpec/InterSpec.h
383385
InterSpec/InterSpecServer.h
384386
InterSpec/PopupDiv.h
@@ -556,6 +558,7 @@ if( USE_REL_ACT_TOOL )
556558
src/RelActAutoGuiFreePeak.cpp
557559
src/RelActAutoReport.cpp
558560
src/RelActAutoDev.cpp
561+
src/ShieldingSourceFitPlot.cpp
559562
)
560563

561564
list( APPEND headers
@@ -570,6 +573,7 @@ if( USE_REL_ACT_TOOL )
570573
InterSpec/RelActTxtResults.h
571574
InterSpec/RelEffChart.h
572575
InterSpec/RelEffShieldWidget.h
576+
InterSpec/ShieldingSourceFitPlot.h
573577
InterSpec/RelActAutoGuiRelEffOptions.h
574578
InterSpec/RelActAutoGuiEnergyRange.h
575579
InterSpec/RelActAutoGuiNuclide.h
@@ -632,7 +636,11 @@ deploy_js_resource("${CMAKE_CURRENT_SOURCE_DIR}/external_libs/SpecUtils/d3_resou
632636

633637

634638

635-
list( APPEND OTHER_InterSpec_SUPPORT_FILES ${CMAKE_CURRENT_SOURCE_DIR}/InterSpec_resources/D3TimeChart.js )
639+
list( APPEND OTHER_InterSpec_SUPPORT_FILES
640+
${CMAKE_CURRENT_SOURCE_DIR}/InterSpec_resources/D3TimeChart.js
641+
${CMAKE_CURRENT_SOURCE_DIR}/InterSpec_resources/ShieldingSourceFitPlot.js
642+
${CMAKE_CURRENT_SOURCE_DIR}/InterSpec_resources/ShieldingSourceFitPlot.css
643+
)
636644

637645
deploy_js_resource("${CMAKE_CURRENT_SOURCE_DIR}/external_libs/SpecUtils/d3_resources/SpectrumChartD3.js"
638646
"${CMAKE_CURRENT_BINARY_DIR}/InterSpec_resources/SpectrumChartD3.js"

InterSpec/BatchInfoLog.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ namespace BatchPeak
6363
namespace SpecUtils
6464
{
6565
class Measurement;
66+
class EnergyCalibration;
6667
}
6768

6869
namespace BatchActivity
@@ -83,17 +84,31 @@ namespace BatchInfoLog
8384
*/
8485
std::string template_include_dir( const BatchPeak::BatchPeakFitOptions &options );
8586

86-
/** Returns the default inja environment, with include directory, options, and callbacks set, as well as default templates loaded. */
87-
inja::Environment get_default_inja_env( const BatchPeak::BatchPeakFitOptions &options );
87+
/** Returns the default inja environment, with include directory, options, and callbacks set, as well as default templates loaded.
88+
89+
@param tmplt_dir The template include directory to use. Should include trailing path separator (as required by inja).
90+
If empty string, then no custom template directory will be used.
91+
To get the directory from options, use `template_include_dir(options)`.
92+
*/
93+
inja::Environment get_default_inja_env( const std::string &tmplt_dir );
8894

8995
/** Returns key-value pairs of of the file contents of the JS and CSS files needed for SpectrumChar. Specifically returns:
9096
9197
"D3_JS": contents of `InterSpec_resources/d3.v3.min.js`
9298
"SpectrumChart_JS": contents of `InterSpec_resources/SpectrumChartD3.js`
9399
"SpectrumChart_CSS": contents of `InterSpec_resources/SpectrumChartD3.css`
94-
100+
95101
*/
96102
std::vector<std::pair<std::string,std::string>> load_spectrum_chart_js_and_css();
103+
104+
/** Returns key-value pairs of the file contents of the JS and CSS files needed for ShieldingSourceFitPlot. Specifically returns:
105+
106+
"D3_JS": contents of `InterSpec_resources/d3.v3.min.js`
107+
"ShieldingSourceFitPlot_JS": contents of `InterSpec_resources/ShieldingSourceFitPlot.js`
108+
"ShieldingSourceFitPlot_CSS": contents of `InterSpec_resources/ShieldingSourceFitPlot.css`
109+
110+
*/
111+
std::vector<std::pair<std::string,std::string>> load_shielding_fit_plot_js_and_css();
97112

98113
/** An enum to provide context of what default templates names "csv", "txt", and "html" refer to for `render_template(...)` */
99114
enum class TemplateRenderType : int

InterSpec/InjaLogDialog.h

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#ifndef InjaLogDialog_h
2+
#define InjaLogDialog_h
3+
/* InterSpec: an application to analyze spectral gamma radiation data.
4+
5+
Copyright 2018 National Technology & Engineering Solutions of Sandia, LLC
6+
(NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
7+
Government retains certain rights in this software.
8+
For questions contact William Johnson via email at [email protected], or
9+
alternative emails of [email protected].
10+
11+
This library is free software; you can redistribute it and/or
12+
modify it under the terms of the GNU Lesser General Public
13+
License as published by the Free Software Foundation; either
14+
version 2.1 of the License, or (at your option) any later version.
15+
16+
This library is distributed in the hope that it will be useful,
17+
but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19+
Lesser General Public License for more details.
20+
21+
You should have received a copy of the GNU Lesser General Public
22+
License along with this library; if not, write to the Free Software
23+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24+
*/
25+
26+
#include "InterSpec_config.h"
27+
28+
#include <tuple>
29+
#include <vector>
30+
#include <string>
31+
#include <utility>
32+
#include <functional>
33+
34+
#include <Wt/WString>
35+
36+
#include <nlohmann/json.hpp>
37+
38+
#include "external_libs/SpecUtils/3rdparty/inja/inja.hpp"
39+
40+
#include "InterSpec/SimpleDialog.h"
41+
42+
43+
// Forward declarations
44+
namespace Wt
45+
{
46+
class WText;
47+
class WComboBox;
48+
class WResource;
49+
class WPushButton;
50+
class WContainerWidget;
51+
}// namespace Wt
52+
53+
54+
/** A reusable dialog for displaying content rendered from inja templates.
55+
56+
This dialog allows displaying HTML content generated from JSON data using inja templates.
57+
It supports multiple template options (selected via a combo box), displays the content in
58+
an iframe for isolation, and provides download functionality.
59+
60+
Originally extracted from BatchGuiAnaWidget to be reusable across the application.
61+
*/
62+
class InjaLogDialog : public SimpleDialog
63+
{
64+
public:
65+
/** Enum to specify the type of log content. */
66+
enum class LogType
67+
{
68+
Html, ///< HTML content that will be displayed directly in iframe
69+
Text ///< Plain text content that will be HTML-escaped and wrapped for display
70+
};
71+
72+
/** HTML wrapper tags for text log templates.
73+
Use these to wrap plain text content in HTML for display,
74+
so this way they can be stripped off when downloading the text version.
75+
*/
76+
static const char * const sm_txt_log_pre_wrapper;
77+
static const char * const sm_txt_log_post_wrapper;
78+
79+
/** Constructor for InjaLogDialog.
80+
81+
@param title The dialog title
82+
@param data The JSON data to be passed to inja templates
83+
@param template_options A vector of template options. Each entry contains a tuple:
84+
- get<0>: Display name for the template (shown in combo box)
85+
- get<1>: Filename suffix to append to spectrum filename for downloads (e.g., "_act_fit.html" or "_std_fit_log.txt")
86+
- get<2>: LogType enum indicating whether content is Html or Text
87+
- get<3>: Function that takes inja::Environment and JSON data,
88+
and returns rendered content string
89+
- For Html type: content must be a valid HTML page, as it will be displayed in an iframe
90+
- For Text type: content will be HTML-escaped and wrapped in <pre> tags for display
91+
92+
If template_options contains only one entry, no combo box is shown.
93+
If template_options is empty, an error is displayed.
94+
*/
95+
InjaLogDialog( const Wt::WString &title,
96+
const nlohmann::json &data,
97+
std::vector<std::tuple<Wt::WString, std::string, LogType, std::function<std::string(inja::Environment&, const nlohmann::json&)>>> template_options );
98+
99+
virtual ~InjaLogDialog();
100+
101+
const std::string &current_content() const;
102+
const std::string current_suggested_name() const;
103+
104+
/** Show or hide the toolbar containing the template selector and download button.
105+
@param show If true, toolbar is shown; if false, toolbar is hidden
106+
*/
107+
void setToolbarVisible( const bool show );
108+
109+
protected:
110+
/** Update the displayed content using the currently selected template. */
111+
void updateDisplay();
112+
113+
/** Handle template selection change from combo box. */
114+
void handleTemplateChange();
115+
116+
private:
117+
Wt::WResource *m_download_resource;
118+
119+
120+
// Member variables
121+
nlohmann::json m_data;
122+
std::vector<std::tuple<Wt::WString, std::string, LogType, std::function<std::string(inja::Environment&, const nlohmann::json&)>>> m_template_options;
123+
124+
Wt::WContainerWidget *m_toolbar;
125+
Wt::WComboBox *m_template_selector;
126+
Wt::WPushButton *m_download_button;
127+
Wt::WText *m_iframe_holder;
128+
Wt::WResource *m_current_resource;
129+
std::string m_current_content;
130+
};//class InjaLogDialog
131+
132+
133+
#endif // InjaLogDialog_h

InterSpec/ShieldingSourceDisplay.h

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,29 @@
2626
#include "InterSpec_config.h"
2727

2828
#include <map>
29-
#include <tuple>
3029
#include <mutex>
3130
#include <utility>
3231

3332
#if( INCLUDE_ANALYSIS_TEST_SUITE )
33+
#include <tuple>
34+
3435
#include <boost/optional.hpp>
3536
#endif
3637

37-
#include <Wt/WRectF>
38-
#include <Wt/WColor>
39-
#include <Wt/WPainter>
4038
#include <Wt/WModelIndex>
41-
#include <Wt/WGridLayout>
4239
#include <Wt/WContainerWidget>
4340
#include <Wt/WAbstractItemModel>
44-
#include <Wt/Chart/WCartesianChart>
4541

46-
#include "InterSpec/DetectorPeakResponse.h" //DetectorPeakResponse::EffGeometryType
42+
#include "InterSpec/DetectorPeakResponse.h"
43+
#include "InterSpec/ShieldingSourceFitPlot.h"
4744
#include "InterSpec/ShieldingSourceFitCalc.h"
4845

4946
//Forward declarations
5047
class PeakDef;
5148
struct Material;
5249
class PeakModel;
5350
class AuxWindow;
51+
class InjaLogDialog;
5452
class MaterialDB;
5553
class ColorTheme;
5654
class PopupDivMenu;
@@ -87,8 +85,6 @@ namespace Wt
8785
{
8886
class WText;
8987
class WLabel;
90-
class WAnchor;
91-
class WSvgImage;
9288
class WCheckBox;
9389
class WLineEdit;
9490
class WTreeView;
@@ -97,11 +93,6 @@ namespace Wt
9793
class WFileUpload;
9894
class WSelectionBox;
9995
class WSuggestionPopup;
100-
class WStandardItemModel;
101-
// namespace Chart
102-
// {
103-
// class WCartesianChart;
104-
// }//namespace Chart
10596
}//namespace Wt
10697

10798

@@ -355,9 +346,6 @@ class ShieldingSourceDisplay : public Wt::WContainerWidget
355346

356347
/** Returns <num values specified, num fit values, is valid> */
357348
std::tuple<int,int,bool> numTruthValuesForFitValues();
358-
359-
/** Renders the Chi2Chart to a SVG image */
360-
void renderChi2Chart( Wt::WSvgImage &image );
361349

362350
/** Tests the current values, for all quantities being fit for, against truth-level values.
363351
@@ -489,8 +477,11 @@ class ShieldingSourceDisplay : public Wt::WContainerWidget
489477
void handleShieldingChange();
490478

491479
void handleDetectorChanged( std::shared_ptr<DetectorPeakResponse> new_det );
492-
480+
493481
void updateChi2Chart();
482+
483+
/** Callback for when the user toggles between Chi and Mult display modes in the chart */
484+
void handleChi2ChartDisplayModeChanged( bool showChi );
494485

495486
void showCalcLog();
496487
void closeCalcLogWindow();
@@ -690,8 +681,7 @@ class ShieldingSourceDisplay : public Wt::WContainerWidget
690681
Wt::WText *m_fixedGeometryTxt;
691682

692683
Wt::WText *m_showChi2Text;
693-
Wt::WStandardItemModel *m_chi2Model;
694-
Chi2Graphic *m_chi2Graphic;
684+
ShieldingSourceFitPlot *m_chi2Plot;
695685

696686

697687
Wt::WCheckBox *m_multiIsoPerPeak;
@@ -707,10 +697,11 @@ class ShieldingSourceDisplay : public Wt::WContainerWidget
707697
bool m_multithread_computation;
708698

709699
PopupDivMenuItem *m_showLog;
710-
711-
AuxWindow *m_logDiv;
700+
701+
InjaLogDialog *m_logDiv;
712702
std::vector<std::string> m_calcLog;
713703
std::unique_ptr<const std::vector<GammaInteractionCalc::PeakDetail>> m_peakCalcLogInfo;
704+
std::shared_ptr<ShieldingSourceFitCalc::ModelFitResults> m_lastFitResults;
714705

715706
AuxWindow *m_modelUploadWindow;
716707
#if( USE_DB_TO_STORE_SPECTRA )
@@ -730,30 +721,6 @@ class ShieldingSourceDisplay : public Wt::WContainerWidget
730721
std::shared_ptr<GammaInteractionCalc::ShieldingSourceChi2Fcn> m_currentFitFcn;
731722

732723
//A class to draw the chi2 distribution of the fit to activity/shielding.
733-
// We have to overide the Paint(...) method to draw some text on chart
734-
// indicating the chi2
735-
class Chi2Graphic : public Wt::Chart::WCartesianChart
736-
{
737-
public:
738-
Chi2Graphic( Wt::WContainerWidget *parent = 0 );
739-
virtual ~Chi2Graphic();
740-
virtual void paint( Wt::WPainter &painter,
741-
const Wt::WRectF &rectangle = Wt::WRectF() ) const;
742-
virtual void paintEvent( Wt::WPaintDevice *paintDevice );
743-
void setNumFitForParams( unsigned int npar );
744-
745-
void setShowChiOnChart( const bool show_chi );
746-
void setTextPenColor( const Wt::WColor &color );
747-
void setColorsFromTheme( std::shared_ptr<const ColorTheme> theme );
748-
protected:
749-
void calcAndSetAxisRanges();
750-
void calcAndSetAxisPadding( double yHeightPx );
751-
752-
int m_nFitForPar;
753-
bool m_showChi;
754-
Wt::WColor m_textPenColor;
755-
};//class WCartesianChart
756-
757724
static const int sm_xmlSerializationMajorVersion;
758725
static const int sm_xmlSerializationMinorVersion;
759726

0 commit comments

Comments
 (0)