10 #include <wx/combobox.h>
11 #include <wx/dcclient.h>
14 #include <wx/stattext.h>
24 : context(
std::move(context)) {}
43 virtual void fill(
const Rgba& color)
override {
48 context->
drawLine(this->transform(p1), this->transform(p2));
87 : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
89 this->Connect(wxEVT_PAINT, wxPaintEventHandler(PaletteCanvas::onPaint));
90 this->SetMinSize(wxSize(320, 100));
99 void onPaint(wxPaintEvent&
UNUSED(evt)) {
102 context.setFontSize(9);
103 Rgba background(dc.GetBackground().GetColour());
112 : wxFrame(parent, wxID_ANY,
"Palette Dialog", wxGetMousePosition(), size)
113 , setPaletteCallback(setPalette) {
115 selected = initial = initialPalette;
117 wxBoxSizer* mainSizer =
new wxBoxSizer(wxVERTICAL);
120 mainSizer->Add(canvas, 0, wxALIGN_CENTER_HORIZONTAL);
122 wxBoxSizer* selectionSizer =
new wxBoxSizer(wxHORIZONTAL);
123 paletteBox =
new ComboBox(
this,
"Select palette ...");
124 selectionSizer->Add(paletteBox);
126 wxButton* loadButton =
new wxButton(
this, wxID_ANY,
"Load");
127 selectionSizer->Add(loadButton);
129 wxButton* resetButton =
new wxButton(
this, wxID_ANY,
"Reset");
130 selectionSizer->Add(resetButton);
132 mainSizer->Add(selectionSizer, 0, wxALIGN_CENTER_HORIZONTAL);
133 mainSizer->AddSpacer(5);
135 wxBoxSizer* rangeSizer =
new wxBoxSizer(wxHORIZONTAL);
137 const Size height = 30;
138 rangeSizer->Add(
new wxStaticText(
this, wxID_ANY,
"From: ", wxDefaultPosition, wxSize(-1, height)));
140 rangeSizer->Add(lowerCtrl);
142 rangeSizer->Add(
new wxStaticText(
this, wxID_ANY,
"To: ", wxDefaultPosition, wxSize(-1, height)));
144 rangeSizer->Add(upperCtrl);
149 if (lower >= value) {
154 setPaletteCallback(selected);
159 if (value >= upper) {
167 setPaletteCallback(selected);
171 mainSizer->Add(rangeSizer, 0, wxALIGN_CENTER_HORIZONTAL);
172 mainSizer->AddSpacer(5);
174 wxBoxSizer* buttonSizer =
new wxBoxSizer(wxHORIZONTAL);
175 wxButton* okButton =
new wxButton(
this, wxID_ANY,
"OK");
176 okButton->Bind(wxEVT_BUTTON, [
this](wxCommandEvent&
UNUSED(evt)) {
177 setPaletteCallback(selected);
180 buttonSizer->Add(okButton);
181 wxButton* cancelButton =
new wxButton(
this, wxID_ANY,
"Cancel");
182 cancelButton->Bind(wxEVT_BUTTON, [
this](wxCommandEvent&
UNUSED(evt)) { this->Close(); });
183 buttonSizer->Add(cancelButton);
185 mainSizer->Add(buttonSizer, 0, wxALIGN_CENTER_HORIZONTAL);
186 mainSizer->AddSpacer(10);
188 this->SetSizerAndFit(mainSizer);
191 paletteBox->Bind(wxEVT_COMBOBOX, [
this](wxCommandEvent&
UNUSED(evt)) { this->update(); });
193 loadButton->Bind(wxEVT_BUTTON, [
this](wxCommandEvent&
UNUSED(evt)) {
200 if (file.extension().native() ==
"csv") {
203 paletteMap.
insert(file.native(), palette);
208 int selectionIdx = 0, idx = 0;
211 if (e.key == path->fileName().native()) {
217 paletteBox->Set(items);
218 paletteBox->SetSelection(selectionIdx);
222 resetButton->Bind(wxEVT_BUTTON, [
this](wxCommandEvent&
UNUSED(evt)) { this->setDefaultPaletteList(); });
224 this->setDefaultPaletteList();
243 { 0.01f,
Rgba(0.4f, 0.106f, 0.38f) },
244 { 0.1f,
Rgba(0.78f, 0.18f, 0.38f) },
245 { 1.f,
Rgba(0.91f, 0.56f, 0.81f) },
246 { 10.f,
Rgba(0.29f, 0.69f, 0.93f) } },
250 { 0.01f,
Rgba(0.5f, 0.5f, 0.5f) },
251 { 0.1f,
Rgba(0.65f, 0.12f, 0.01f) },
252 { 1.f,
Rgba(0.79f, 0.38f, 0.02f) },
253 { 10.f,
Rgba(0.93f, 0.83f, 0.34f) },
254 { 100.f,
Rgba(0.94f, 0.90f, 0.84f) } },
259 void PaletteDialog::setDefaultPaletteList() {
261 {
"(default)", initial },
266 for (
auto& pair : PALETTE_ID_LIST) {
274 paletteBox->Set(items);
275 paletteBox->SetSelection(0);
279 void PaletteDialog::update() {
280 const int idx = paletteBox->GetSelection();
282 selected = (paletteMap.
begin() + idx)->value;
285 setPaletteCallback(selected);
#define NOT_IMPLEMENTED
Helper macro marking missing implementation.
Object converting quantity values of particles into colors.
@ MOVEMENT_DIRECTION
Projected direction of motion.
@ DENSITY_PERTURBATION
Relative difference of density and initial density (rho/rho0 - 1)
@ VELOCITY
Particle velocities.
@ TEMPERATURE
Temperature, computed from internal energy.
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
#define NAMESPACE_SPH_END
@ LOGARITHMIC
Control points are interpolated on logarithmic scale. All points must be positive!
void drawPalette(IRenderContext &context, const Pixel origin, const Pixel size, const Rgba &lineColor, const Palette &palette)
Renderer drawing individual particles as dots.
@ VELOCITY_DIVERGENCE
Velocity divergence.
@ DEVIATORIC_STRESS
Deviatoric stress tensor, always a traceless tensor.
@ DENSITY
Density, always a scalar quantity.
Palette getBlackBodyPalette(const Interval range)
Returns palette with colors for black body emission for given temperature.
Optional< Path > doOpenFileDialog(const std::string &title, Array< FileFormat > &&formats)
Wrapper of an integral value providing functions for reading and modifying individual bits.
Container of key-value pairs.
INLINE TValue & insert(const TKey &key, const TValue &value)
Adds a new element into the map or sets new value of element with the same key.
INLINE Iterator< Element > begin()
Returns the iterator pointing to the first element.
INLINE void clear()
Removes all elements from the map.
virtual void drawBitmap(const Coords, const Bitmap< Rgba > &) override
Draws a bitmap, given the position of its left-top corner.
virtual void drawText(const Coords p, const Flags< TextAlign >, const std::string &s) override
virtual void drawLine(const Coords p1, const Coords p2) override
Draws a line connecting two points.
virtual void drawText(const Coords p, const Flags< TextAlign >, const std::wstring &s) override
virtual void setColor(const Rgba &color, const Flags< ColorFlag > flags) override
Selects the color for one or more drawing modes.
virtual void setFontSize(const int fontSize) override
FlippedRenderContext(AutoPtr< IRenderContext > &&context)
virtual void drawCircle(const Coords center, const float radius) override
Draws a circle, given its center and a radius.
virtual void setThickness(const float thickness) override
Modifies the thickness of the lines.
virtual Pixel size() const override
Returns the size of the canvas associated with the context.
virtual void fill(const Rgba &color) override
Fills the whole canvas with given color.
virtual void drawTriangle(const Coords, const Coords, const Coords) override
Draws a triangle given three points.
Function< bool(double)> onValueChanged
Abstraction of a device used for rendering.
virtual void setFontSize(const int fontSize)=0
virtual void drawCircle(const Coords center, const float radius)=0
Draws a circle, given its center and a radius.
virtual void drawLine(const Coords p1, const Coords p2)=0
Draws a line connecting two points.
virtual void drawText(const Coords p, const Flags< TextAlign > align, const std::string &s)=0
virtual void setColor(const Rgba &color, const Flags< ColorFlag > flags)=0
Selects the color for one or more drawing modes.
virtual void setThickness(const float thickness)=0
Modifies the thickness of the lines.
virtual void fill(const Rgba &color)=0
Fills the whole canvas with given color.
virtual Pixel size() const =0
Returns the size of the canvas associated with the context.
Object representing a 1D interval of real numbers.
INLINE Float lower() const
Returns lower bound of the interval.
INLINE Float upper() const
Returns upper bound of the interval.
Wrapper of type value of which may or may not be present.
PaletteCanvas(wxWindow *parent, const Palette palette)
void setPalette(const Palette newPalette)
PaletteDialog(wxWindow *parent, wxSize size, const Palette palette, Function< void(Palette)> setPalette)
Represents a color palette, used for mapping arbitrary number to a color.
void setInterval(const Interval &newRange)
PaletteScale getScale() const
Returns the scale of the palette.
Outcome loadFromFile(const Path &path)
Loads the palette from given .csv file.
Interval getInterval() const
Returns the interval for which the palette is defined.
Object representing a path on a filesystem.
Palette getPalette(const ExtColorizerId id)
DirectoryAdapter iterateDirectory(const Path &directory)
const Palette GALAXY({ { 0.001f, Rgba(0.f, 0.02f, 0.09f) }, { 0.01f, Rgba(0.4f, 0.106f, 0.38f) }, { 0.1f, Rgba(0.78f, 0.18f, 0.38f) }, { 1.f, Rgba(0.91f, 0.56f, 0.81f) }, { 10.f, Rgba(0.29f, 0.69f, 0.93f) } }, PaletteScale::LOGARITHMIC)
const Palette ACCRETION({ { 0.001f, Rgba(0.43f, 0.70f, 1.f) }, { 0.01f, Rgba(0.5f, 0.5f, 0.5f) }, { 0.1f, Rgba(0.65f, 0.12f, 0.01f) }, { 1.f, Rgba(0.79f, 0.38f, 0.02f) }, { 10.f, Rgba(0.93f, 0.83f, 0.34f) }, { 100.f, Rgba(0.94f, 0.90f, 0.84f) } }, PaletteScale::LOGARITHMIC)
Overload of std::swap for Sph::Array.