Skip to content

Commit 24acbf1

Browse files
committed
Merge branch 'master' of github.com:sandialabs/InterSpec
2 parents 082b4ac + 026414e commit 24acbf1

36 files changed

+794
-390
lines changed

InterSpec/D3SpectrumDisplayDiv.h

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -160,29 +160,32 @@ class D3SpectrumDisplayDiv : public Wt::WContainerWidget
160160
void scheduleUpdateSecondData();
161161

162162

163-
/** Schedules the foreground peaks to be re-loaded to the client during the
164-
next call to #render (which Wt takes care of calling); this function is called by the PeakModel.
165-
*/
166-
void scheduleForegroundPeakRedraw();
167-
168-
/** Schedules peak redraw for the given spectrum.
169-
170-
TODO: As of 20250802, only foreground spectrum has any effect.
163+
/** Schedules the peaks to be re-loaded to the client, for the specified spectrum, during the
164+
next call to #render (which Wt takes care of calling).
171165
*/
172166
void schedulePeakRedraw( const SpecUtils::SpectrumType spectrum_type );
173167

174-
/** Applies the current color theme.
175-
if nullptr, then sets to default colors.
168+
/** Applies the color theme globally to all D3SpectrumDisplayDiv instances in the current app.
169+
Should be called once when the color theme changes, typically from InterSpec::applyColorTheme().
170+
If nullptr, then sets to default colors.
171+
172+
Uses InterSpecApp::setGlobalD3SpectrumCssRule() to track the global CSS rules per app instance.
176173
*/
177-
void applyColorTheme( std::shared_ptr<const ColorTheme> theme );
178-
179-
void setForegroundSpectrumColor( const Wt::WColor &color );
180-
void setBackgroundSpectrumColor( const Wt::WColor &color );
181-
void setSecondarySpectrumColor( const Wt::WColor &color );
182-
void setTextColor( const Wt::WColor &color );
183-
void setAxisLineColor( const Wt::WColor &color );
184-
void setChartMarginColor( const Wt::WColor &color );
185-
void setChartBackgroundColor( const Wt::WColor &color );
174+
static void applyColorTheme( std::shared_ptr<const ColorTheme> theme );
175+
176+
/** Updates the default peak color for this specific instance based on the color theme.
177+
This is needed because peak color is passed in JSON, not via CSS variables.
178+
Also updates peak label size/rotation and log Y-axis min from theme.
179+
*/
180+
void updateDefaultPeakColorForColorTheme( std::shared_ptr<const ColorTheme> theme );
181+
182+
void overrideForegroundSpectrumColor( const Wt::WColor &color );
183+
void overrideBackgroundSpectrumColor( const Wt::WColor &color );
184+
void overrideSecondarySpectrumColor( const Wt::WColor &color );
185+
void overrideTextColor( const Wt::WColor &color );
186+
void overrideAxisLineColor( const Wt::WColor &color );
187+
void overrideChartMarginColor( const Wt::WColor &color );
188+
void overrideChartBackgroundColor( const Wt::WColor &color );
186189
void setDefaultPeakColor( const Wt::WColor &color );
187190

188191
/** Sets the charts font size.
@@ -467,12 +470,6 @@ class D3SpectrumDisplayDiv : public Wt::WContainerWidget
467470
/** Sets the highlight regions to client - currently unimplemented. */
468471
void setHighlightRegionsToClient();
469472

470-
void setForegroundPeaksToClient();
471-
472-
void setSecondaryPeaksToClient();
473-
474-
void setBackgroundPeaksToClient();
475-
476473
void setReferenceLinesToClient();
477474

478475
protected:
@@ -500,7 +497,6 @@ class D3SpectrumDisplayDiv : public Wt::WContainerWidget
500497

501498
UpdateDynamicRefLines = 0x80,
502499

503-
// TODO: Currently background and secondary peaks not loaded to client, so these flags have no effect.
504500
UpdateBackgroundPeaks = 0x0100,
505501
UpdateSecondaryPeaks = 0x0200,
506502
//ToDo: maybe add a few other things to this mechanism.
@@ -694,13 +690,17 @@ class D3SpectrumDisplayDiv : public Wt::WContainerWidget
694690
*/
695691
int m_comptonPeakAngle;
696692

697-
Wt::WColor m_foregroundLineColor;
698-
Wt::WColor m_backgroundLineColor;
699-
Wt::WColor m_secondaryLineColor;
700-
Wt::WColor m_textColor;
701-
Wt::WColor m_axisColor;
702-
Wt::WColor m_chartMarginColor;
703-
Wt::WColor m_chartBackgroundColor;
693+
// Member variables for instance-specific color overrides
694+
// When default (isDefault() == true), the global CSS variable from the theme is used
695+
Wt::WColor m_foregroundLineColorOverride;
696+
Wt::WColor m_backgroundLineColorOverride;
697+
Wt::WColor m_secondaryLineColorOverride;
698+
Wt::WColor m_textColorOverride;
699+
Wt::WColor m_axisColorOverride;
700+
Wt::WColor m_chartMarginColorOverride;
701+
Wt::WColor m_chartBackgroundColorOverride;
702+
703+
// Default peak color - used directly in JSON, not via CSS
704704
Wt::WColor m_defaultPeakColor;
705705

706706
std::string m_peakLabelFontSize;

InterSpec/InterSpec.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,10 @@ class InterSpec : public Wt::WContainerWidget
383383
const SpecUtils::SpectrumType spec_type,
384384
const std::string &ref_line_name = "" );
385385

386-
/** Sets the peaks for the given spectrum. If foreground, you should consider instead to use the PeakModel.
386+
/** Sets the peaks for the given spectrum - taking care of adding a undo/redo step.
387+
388+
If you do not wish to add a undo/redo step, you can call `PeakModel::setPeaks(peaks,SpectrumType).`
389+
(the undo/redo is the only differnce between calling this function and the PeakModel function directly).
387390
388391
@param spectrum Which spectrum to set the peaks for.
389392
@param peaks The peaks to set. Must not be nullptr, or the currently set deque of peaks.

InterSpec/InterSpecApp.h

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "InterSpec_config.h"
2727

28+
#include <map>
2829
#include <set>
2930
#include <mutex>
3031
#include <chrono>
@@ -43,6 +44,7 @@ namespace Wt
4344
class WText;
4445
class WGridLayout;
4546
class WPushButton;
47+
class WCssTextRule;
4648
}//namespace Wt
4749

4850
class PopupDivMenuItem;
@@ -238,7 +240,27 @@ class InterSpec_API InterSpecApp : public Wt::WApplication
238240
the list of the capture group.
239241
*/
240242
static const std::set<std::string> &languagesAvailable();
241-
243+
244+
/** Sets or replaces a global CSS rule for this app instance.
245+
Used by various components to manage global theme colors and styles.
246+
247+
@param rulename Unique name for the CSS rule
248+
@param selector CSS selector (e.g., ":root")
249+
@param declarations CSS declarations (e.g., "--d3spec-fore-line-color: rgb(0,0,0);")
250+
251+
If a rule with the same name already exists, it will be removed before adding the new one.
252+
*/
253+
void setGlobalCssRule( const std::string &rulename,
254+
const std::string &selector,
255+
const std::string &declarations );
256+
257+
/** Removes a global CSS rule for this app instance.
258+
259+
@param rulename Name of the CSS rule to remove
260+
@returns true if the rule was found and removed, false if it didn't exist
261+
*/
262+
bool removeGlobalCssRule( const std::string &rulename );
263+
242264
protected:
243265

244266
//notify(): over-riding WApplication::notify in order to catch any exceptions
@@ -369,7 +391,12 @@ class InterSpec_API InterSpecApp : public Wt::WApplication
369391
/** CSS px values for areas on iPhoneX's like the notch or bottom bar. */
370392
float m_safeAreas[4];
371393
#endif
372-
394+
395+
/** Map of global D3 spectrum CSS rules for this app instance.
396+
Used to manage global theme colors that apply to all D3SpectrumDisplayDiv instances.
397+
*/
398+
std::map<std::string, Wt::WCssTextRule*> m_globalD3SpectrumCssRules;
399+
373400
friend class InterSpec;
374401
#if( INCLUDE_ANALYSIS_TEST_SUITE )
375402
friend class SpectrumViewerTester;

InterSpec/PeakModel.h

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040

4141
class SpecMeas;
4242

43-
namespace SpecUtils{ class Measurement; }
43+
namespace SpecUtils
44+
{
45+
class Measurement;
46+
enum class SpectrumType : int;
47+
}
4448

4549
namespace SandiaDecay
4650
{
@@ -60,6 +64,9 @@ class PeakModel: public Wt::WAbstractItemModel
6064
That is, the row specifies the peak, and the column represents
6165
various peak values, as specified by the 'Columns' enum.
6266
67+
All functions refer to the foreground, except `peaks(SpectrumType)` and `measurement(SpectrumType)` - which just returns what
68+
`setPeakFromSpecMeas(...)` was last called for the type (currently only the main InterSpec class do anything other than for foreground).
69+
6370
Incomplete TODO list:
6471
- add a `replacePeaks(orig,newer)` function to allow updating peak quanitites in one step
6572
- Or allow setting kLowerX/kUpperX columns in setData(...) function
@@ -98,7 +105,8 @@ class PeakModel: public Wt::WAbstractItemModel
98105
// or the displayed sample numbers), then this function should be called to
99106
// update the m_peaks pointer to be from the appropriate SpecMeas object.
100107
void setPeakFromSpecMeas( std::shared_ptr<SpecMeas> meas,
101-
const std::set<int> &samplenums );
108+
const std::set<int> &samplenums,
109+
const SpecUtils::SpectrumType specType );
102110

103111
/** Normally we keep the peaks added/removed up to date with the #SpecMeas passed into
104112
#setPeakFromSpecMeas (i.e., the #SpecMeas "owns" the peaks), but if you dont want to do
@@ -141,6 +149,26 @@ class PeakModel: public Wt::WAbstractItemModel
141149

142150
const std::deque<std::shared_ptr<const PeakDef>> &sortedPeaks() const;
143151

152+
/** Get the currently set peaks - this requires that `setPeakFromSpecMeas(spec, samples, type)`
153+
has been called to set these - currently the only place that does this for anything besides the foreground is the main InterSpec class.
154+
155+
All other functions in this class refer to foreground peaks, except `peaks(SpectrumType)` and `measurement(SpectrumType)`.
156+
*/
157+
std::shared_ptr<const std::deque<std::shared_ptr<const PeakDef>>> peaks( const SpecUtils::SpectrumType type ) const;
158+
159+
std::weak_ptr<SpecMeas> measurement( const SpecUtils::SpectrumType type );
160+
161+
Wt::Signal<> &backgroundPeaksChanged();
162+
Wt::Signal<> &secondaryPeaksChanged();
163+
164+
165+
/** Get the currently set secondary peaks - this requires that `setPeakFromSpecMeas(back, backSamples, SpectrumType::SecondaryForeground)`
166+
has been called to set these - currently the only place that does this is the main InterSpec class.
167+
168+
All other functions in this class refer to foregorund peaks, except `backgroundPeaks()` and `secondaryPeaks()`.
169+
*/
170+
std::shared_ptr<const std::deque<std::shared_ptr<const PeakDef>>> secondaryPeaks() const;
171+
144172
//definePeakXRangeAndChi2(...): Inorder to save cpu (and mostly memorry access
145173
// time) later on, this function will define the lower and upper energy range
146174
// of peaks that have a polynomial continum defined, and have not already had
@@ -176,6 +204,9 @@ class PeakModel: public Wt::WAbstractItemModel
176204
*/
177205
void setPeaks( std::vector<std::shared_ptr<const PeakDef>> peaks );
178206

207+
208+
void setPeaks( const std::deque<std::shared_ptr<const PeakDef>> &peakdeque, const SpecUtils::SpectrumType type );
209+
179210
//removePeak( size_t ): removes the specified `peakn`, where the peakn refers
180211
// to the peak at position `peakn` when sorted by peak means (similar
181212
// behavior as all other functions which refer to peaks by index).
@@ -439,8 +470,16 @@ class PeakModel: public Wt::WAbstractItemModel
439470

440471
//Peaks are stored sorted according to peak.mean, since some of the algorithms
441472
// that work on the peaks need them to be sorted by mean
442-
std::shared_ptr< std::deque< PeakShrdPtr > > m_peaks;
443-
std::weak_ptr<SpecMeas> m_measurment;
473+
std::shared_ptr< std::deque< std::shared_ptr<const PeakDef> > > m_peaks;
474+
std::weak_ptr<SpecMeas> m_measurment; //Foreground
475+
476+
std::shared_ptr<std::deque<std::shared_ptr<const PeakDef>>> m_background_peaks;
477+
std::weak_ptr<SpecMeas> m_background;
478+
Wt::Signal<> m_backgroundPeaksChanged;
479+
480+
std::shared_ptr<std::deque<std::shared_ptr<const PeakDef>>> m_secondary_peaks;
481+
std::weak_ptr<SpecMeas> m_secondary;
482+
Wt::Signal<> m_secondaryPeaksChanged;
444483

445484
Columns m_sortColumn;
446485
Wt::SortOrder m_sortOrder;

InterSpec_resources/DecayChainChart.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ rect.DecayChartNuc.MousedOver
104104
cursor: pointer;
105105
}
106106

107+
.ShowDecayProductsTxt
108+
{
109+
cursor: pointer;
110+
}
111+
112+
.ShowDecayProductsRect
113+
{
114+
cursor: pointer;
115+
}
116+
107117
.DecayChainDnldBtn
108118
{
109119
position: absolute;

0 commit comments

Comments
 (0)