diff -r 34e37068b6c7 -r 47f4a1712c25 src/backend/plot.cpp
--- src/backend/plot.cpp Thu Apr 17 22:17:56 2014 +0100
+++ src/backend/plot.cpp Thu Apr 24 00:06:18 2014 +0100
@@ -47,118 +47,8 @@
// perform a little "push off" by this fudge factor
const float AXIS_MIN_TOLERANCE=10*sqrtf(std::numeric_limits<float>::epsilon());
-int MGLColourFixer::maxCols=-1;
+const unsigned int MGL_RESERVED_COLOURS=2;
-void MGLColourFixer::reset()
-{
- rs.clear();
- gs.clear();
- bs.clear();
-}
-
-char MGLColourFixer::haveExactColour(float r, float g, float b) const
-{
- ASSERT(rs.size() == gs.size())
- ASSERT(gs.size() == bs.size())
-
- ASSERT(rs.size() <=getMaxColours());
-
- for(unsigned int ui=0; ui<rs.size(); ui++)
- {
- if( fabs(r-rs[ui]) <std::numeric_limits<float>::epsilon()
- && fabs(g-gs[ui]) <std::numeric_limits<float>::epsilon()
- && fabs(b-bs[ui]) <std::numeric_limits<float>::epsilon())
- return mglColorIds[ui+1].id; //Add one to offset to avoid the reserved "k"
- }
-
- return 0;
-}
-
-unsigned int MGLColourFixer::getMaxColours()
-{
- //Used cached value if available
- if(maxCols!=-1)
- return maxCols;
-
- //The array is statically defined in
- //mgl/mgl_main.cpp, and must end with an id of zero.
- //
- //this is not documented at all.
- maxCols=0;
- while(mglColorIds[maxCols].id)
- maxCols++;
-
- return maxCols;
-}
-
-char MGLColourFixer::getNextBestColour(float r, float g, float b)
-{
- ASSERT(rs.size() == gs.size());
- ASSERT(gs.size() == bs.size());
-
-
- //As a special case, mgl has its own black
- if(r == 0.0f && g == 0.0f && b == 0.0f)
- return mglColorIds[0].id;
-
-
- unsigned int best=0;
- if(rs.size() == getMaxColours())
- {
- ASSERT(getMaxColours());
- //Looks like we ran out of palette colours.
- //lets just give up and try to match this against our existing colours
-
- //TODO: let this modify the existing palette
- // to find a better match.
- float distanceSqr=std::numeric_limits<float>::max();
- for(unsigned int ui=0; ui<rs.size(); ui++)
- {
- float distanceTmp;
- if(r <= 0.5)
- {
- //3,4,2 weighted euclidean distance. Weights allow for closer human perception
- distanceTmp= 3.0*(rs[ui] - r )*(rs[ui] - r ) +4.0*(gs[ui] - g )*(gs[ui] - g )
- + 2.0*(bs[ui] - b )*(bs[ui] - b );
- }
- else
- {
- //use alternate weighting for closer colour perception in "non-red" half of colour cube
- distanceTmp= 2.0*(rs[ui] - r )*(rs[ui] - r ) +4.0*(gs[ui] - g )*(gs[ui] - g )
- + 3.0*(bs[ui] - b )*(bs[ui] - b );
- }
-
- if(distanceTmp < distanceSqr)
- {
- distanceSqr = (distanceTmp);
- best=ui+1; //offset by 1 because mathgl colour 0 is special
- }
-
- }
- }
- else
- {
- char exactMatch;
- //Check to see if we don't already have this
- // no use wasting palette positions on existing
- // colours
- exactMatch=haveExactColour(r,g,b);
-
- if(exactMatch)
- return exactMatch;
-
- //Offset zero is special, for black things, like axes
- best=rs.size()+1;
- mglColorIds[best].col = mglColor(r,g,b);
-
- rs.push_back(r);
- gs.push_back(g);
- bs.push_back(b);
- }
-
- ASSERT(mglColorIds[best].id != 'k');
- return mglColorIds[best].id;
-}
//Mathgl uses some internal for(float=...) constructions,
// which are just generally a bad idea, as they often won't terminate
@@ -209,6 +99,18 @@
}
+std::string mglColourCode(float r, float g, float b)
+{
+ ASSERT(r >=0.0f && g >=0.0f && b >=0.0f)
+ ASSERT(r <=255.0f && g <=255.0f && b <=255.0f)
+ std::string s;
+ genColString((unsigned char)(r*255),
+ (unsigned char)(g*255),(unsigned char)(b*255),s);
+ s=s.substr(1);
+
+ return string("{x") + uppercase(s) + string("}");
+}
+
//TODO: Refactor these functions to use a common string map
//-----------
string plotString(unsigned int traceType)
@@ -806,7 +708,6 @@
}
//Un-fudger for mathgl plots
- MGLColourFixer colourFixer;
bool haveMultiTitles=false;
float minX,maxX,minY,maxY;
@@ -994,17 +895,15 @@
if(!curPlot->visible)
continue;
- curPlot->drawRegions(gr,colourFixer,min,max);
- curPlot->drawPlot(gr,colourFixer);
+ curPlot->drawRegions(gr,min,max);
+ curPlot->drawPlot(gr);
if(drawLegend)
{
//Fake an mgl colour code
- char colourCode[2];
- colourCode[0]=colourFixer.getNextBestColour(
- curPlot->r,curPlot->g,curPlot->b);
- colourCode[1]='\0';
- gr->AddLegend(curPlot->title.c_str(),colourCode);
+ std::string mglColStr;
+ mglColStr= mglColourCode(curPlot->r,curPlot->g,curPlot->b);
+ gr->AddLegend(curPlot->title.c_str(),mglColStr.c_str());
}
}
@@ -1017,7 +916,7 @@
vector<pair<size_t,size_t> > overlapId;
vector<pair<float,float> > overlapXCoords;
- char colourCode=colourFixer.getNextBestColour(1.0f,0.0f,0.0f);
+ string colourCode=mglColourCode(1.0f,0.0f,0.0f);
getRegionOverlaps(overlapId,overlapXCoords);
float rMinY,rMaxY;
@@ -1045,10 +944,10 @@
#ifdef USE_MGL2
gr->FaceZ(mglPoint(rMinX,rMinY,-1),rMaxX-rMinX,rMaxY-rMinY,
- &colourCode);
+ colourCode.c_str());
#else
gr->FaceZ(rMinX,rMinY,-1,rMaxX-rMinX,rMaxY-rMinY,
- &colourCode);
+ colourCode.c_str());
#endif
}
@@ -1082,7 +981,7 @@
#endif
}
- overlays.draw(gr,colourFixer,min,max,haveUsedLog);
+ overlays.draw(gr,min,max,haveUsedLog);
}
void PlotWrapper::hideAll()
@@ -1405,7 +1304,7 @@
return xValues.empty();
}
-void Plot1D::drawPlot(mglGraph *gr,MGLColourFixer &fixer) const
+void Plot1D::drawPlot(mglGraph *gr) const
{
bool showErrs;
@@ -1453,9 +1352,8 @@
//Obtain a colour code to use for the plot, based upon
// the actual colour we wish to use
- char colourCode[2];
- colourCode[0]=fixer.getNextBestColour(r,g,b);
- colourCode[1]='\0';
+ string colourCode;
+ colourCode=mglColourCode(r,g,b);
//---
@@ -1467,23 +1365,23 @@
//rather than linear interpolating them back along their paths. I have emailed the author.
//for now, we shall have to put up with missing lines :( Absolute worst case, I may have to draw them myself.
gr->SetCut(true);
-
- gr->Plot(xDat,yDat,colourCode);
+
+ gr->Plot(xDat,yDat,colourCode.c_str());
if(showErrs)
- gr->Error(xDat,yDat,eDat,colourCode);
+ gr->Error(xDat,yDat,eDat,colourCode.c_str());
gr->SetCut(false);
break;
case PLOT_TRACE_BARS:
- gr->Bars(xDat,yDat,colourCode);
+ gr->Bars(xDat,yDat,colourCode.c_str());
break;
case PLOT_TRACE_STEPS:
//Same problem as for line plot.
gr->SetCut(true);
- gr->Step(xDat,yDat,colourCode);
+ gr->Step(xDat,yDat,colourCode.c_str());
gr->SetCut(false);
break;
case PLOT_TRACE_STEM:
- gr->Stem(xDat,yDat,colourCode);
+ gr->Stem(xDat,yDat,colourCode.c_str());
break;
case PLOT_TRACE_POINTS:
@@ -1557,13 +1455,11 @@
regionGroup.clear();
}
-void Plot1D::drawRegions(mglGraph *gr,MGLColourFixer &fixer,
+void Plot1D::drawRegions(mglGraph *gr,
const mglPoint &min,const mglPoint &max) const
{
//Mathgl palette colour name
- char colourCode[2];
- colourCode[1]='\0';
-
+ string colourCode;
for(unsigned int uj=0;uj<regionGroup.regions.size();uj++)
{
@@ -1577,16 +1473,15 @@
//Prevent drawing inverted regionGroup.regions
if(rMaxX > rMinX && rMaxY > rMinY)
{
- colourCode[0] = fixer.getNextBestColour(regionGroup.regions[uj].r,
+ colourCode = mglColourCode(regionGroup.regions[uj].r,
regionGroup.regions[uj].g,
regionGroup.regions[uj].b);
- colourCode[1] = '\0';
#ifdef USE_MGL2
gr->FaceZ(mglPoint(rMinX,rMinY,-1),rMaxX-rMinX,rMaxY-rMinY,
- colourCode);
+ colourCode.c_str());
#else
gr->FaceZ(rMinX,rMinY,-1,rMaxX-rMinX,rMaxY-rMinY,
- colourCode);
+ colourCode.c_str());
#endif
}
@@ -1791,18 +1686,17 @@
}
-void PlotOverlays::draw(mglGraph *gr,MGLColourFixer &fixer,
+void PlotOverlays::draw(mglGraph *gr,
const mglPoint &boundMin, const mglPoint &boundMax,bool logMode ) const
{
if(!isEnabled)
return;
- char colourCode[2];
+ string colourCode;
//Draw the overlays in black
- colourCode[0] = fixer.getNextBestColour(0.0,0.0,0.0);
- colourCode[1]='\0';
+ colourCode = mglColourCode(0.0,0.0,0.0);
for(size_t ui=0;ui<overlayData.size();ui++)
{
@@ -1841,6 +1735,7 @@
}
}
+ //TODO: Deprecate me. Upstream now allows single stems
//Draw stems. can't use stem plot due to mathgl bug whereby single stems
// will not be drawn
for(size_t uj=0;uj<overlayData[ui].coordData.size();uj++)
@@ -1849,7 +1744,7 @@
boundMin.y < bufY[uj])
{
gr->Line (mglPoint(bufX[uj],std::max(0.0f,(float)boundMin.y)),
- mglPoint(bufX[uj],bufY[uj]),colourCode,100);
+ mglPoint(bufX[uj],bufY[uj]),colourCode.c_str(),100);
//Print labels near to the text
const float STANDOFF_FACTOR=1.05;
diff -r 34e37068b6c7 -r 47f4a1712c25 src/backend/plot.h
--- src/backend/plot.h Thu Apr 17 22:17:56 2014 +0100
+++ src/backend/plot.h Thu Apr 24 00:06:18 2014 +0100
@@ -64,26 +64,6 @@
//!Return the error mode type, given the human readable string
unsigned int plotErrmodeID(const std::string &s);
-//!Nasty hack class to change mathgl API from named char palette to rgb specification
-class MGLColourFixer
-{
- private:
- vector<float> rs,gs,bs;
- static int maxCols;
- public:
- //Restore the MGL colour strings
- void reset();
- //Return the exact colour, if there is one
- char haveExactColour(float r, float g, float b) const;
- //Get the best colour that is available
- // returns the char to give to mathgl; may be exact,
- // maybe nearest match, depending upon number of colours used
- // and mgl palette size
- char getNextBestColour(float r, float g, float b);
-
- static unsigned int getMaxColours();
-};
-
//!Data class for holding info about non-overlapping
// interactive rectilinear "zones" overlaid on plots
@@ -199,7 +179,7 @@
//Add a new overlay to the plot
void add(const OVERLAY_DATA &overlay) {overlayData.push_back(overlay);}
//Draw the overlay on the current plot
- void draw(mglGraph *g,MGLColourFixer &fixer,
+ void draw(mglGraph *g,
const mglPoint &boundMin, const mglPoint &boundMax,bool logMode) const;
//Enable the specified overlay
void setEnabled(size_t offset,bool isEnabled)
@@ -262,7 +242,7 @@
virtual bool empty() const=0;
//Draw the plot onto a given MGL graph
- virtual void drawPlot(mglGraph *graph, MGLColourFixer &fixer) const=0;
+ virtual void drawPlot(mglGraph *graph) const=0;
//!Scan for the data bounds.
virtual void getBounds(float &xMin,float &xMax,
@@ -309,11 +289,10 @@
//Draw the plot onto a given MGL graph
- virtual void drawPlot(mglGraph *graph,MGLColourFixer &fixer) const;
+ virtual void drawPlot(mglGraph *graph) const;
//Draw the associated regions
- void drawRegions(mglGraph *graph, MGLColourFixer &fixer,
- const mglPoint &min, const mglPoint &max) const;
+ void drawRegions(mglGraph *graph,const mglPoint &min, const mglPoint &max) const;
//!Retrieve the raw data associated with the currently visible plots.
diff -r 34e37068b6c7 -r 47f4a1712c25 src/common/stringFuncs.cpp
--- src/common/stringFuncs.cpp Thu Apr 17 22:17:56 2014 +0100
+++ src/common/stringFuncs.cpp Thu Apr 24 00:06:18 2014 +0100
@@ -457,6 +457,16 @@
return s;
}
+std::string uppercase(std::string s)
+{
+ for(unsigned int ui=0;ui<s.size();ui++)
+ {
+ if(isascii(s[ui]) && islower(s[ui]))
+ s[ui] = toupper(s[ui]);
+ }
+ return s;
+}
+
//Split strings around a delimiter
void splitStrsRef(const char *cpStr, const char delim,std::vector<string> &v )
{
diff -r 34e37068b6c7 -r 47f4a1712c25 src/common/stringFuncs.h
--- src/common/stringFuncs.h Thu Apr 17 22:17:56 2014 +0100
+++ src/common/stringFuncs.h Thu Apr 24 00:06:18 2014 +0100
@@ -61,6 +61,8 @@
std::string stripChars(const std::string &Str, const char *chars);
//!Return a lowercase version for a given string
std::string lowercase(std::string s);
+//!Return a uppercase version for a given string
+std::string uppercase(std::string s);
//Drop empty entries from a string of vector
void stripZeroEntries(std::vector<std::string> &s);
@@ -71,9 +73,11 @@
unsigned char &r, unsigned char &g, unsigned char &b, unsigned char &a);
//Convert an RGBA 8-bit/channel quadruplet into its hexadecimal colour string
+// format is "#rrggbbaa" such as "#11ee00aa"
void genColString(unsigned char r, unsigned char g,
unsigned char b, unsigned char a, std::string &s);
//Convert an RGB 8-bit/channel quadruplet into its hexadecimal colour string
+// format is "#rrggbb" such as "#11ee00"
void genColString(unsigned char r, unsigned char g,
unsigned char b, std::string &s);
diff -r 34e37068b6c7 -r 47f4a1712c25 src/gui/dialogs/rangeEditDialog.cpp
--- src/gui/dialogs/rangeEditDialog.cpp Thu Apr 17 22:17:56 2014 +0100
+++ src/gui/dialogs/rangeEditDialog.cpp Thu Apr 24 00:06:18 2014 +0100
@@ -288,7 +288,7 @@
EVT_CHECKLISTBOX(ID_LIST_OVERLAY, RangeEditorDialog::OnListOverlayCheck)
EVT_BUTTON(wxID_OK, RangeEditorDialog::OnBtnOK)
EVT_BUTTON(wxID_CANCEL, RangeEditorDialog::OnBtnCancel)
- EVT_SPLITTER_UNSPLIT(ID_SPLIT_LEFTRIGHT, RangeEditorDialog::OnSashVerticalUnsplit)
+ EVT_SPLITTER_DCLICK(ID_SPLIT_LEFTRIGHT, RangeEditorDialog::OnSashVerticalDClick)
// end wxGlade
END_EVENT_TABLE();
@@ -1438,7 +1438,7 @@
plotPanel->Refresh();
}
-void RangeEditorDialog::OnSashVerticalUnsplit(wxSplitterEvent &event)
+void RangeEditorDialog::OnSashVerticalDClick(wxSplitterEvent &event)
{
event.Veto();
}
diff -r 34e37068b6c7 -r 47f4a1712c25 src/gui/dialogs/rangeEditDialog.h
--- src/gui/dialogs/rangeEditDialog.h Thu Apr 17 22:17:56 2014 +0100
+++ src/gui/dialogs/rangeEditDialog.h Thu Apr 24 00:06:18 2014 +0100
@@ -210,7 +210,7 @@
virtual void OnCheckShowOverlay(wxCommandEvent &event); // wxGlade: <event_handler>
virtual void OnBtnOK(wxCommandEvent &event); // wxGlade: <event_handler>
virtual void OnBtnCancel(wxCommandEvent &event); // wxGlade: <event_handler>
- virtual void OnSashVerticalUnsplit(wxSplitterEvent &event); // wxGlade: <event_handler>
+ virtual void OnSashVerticalDClick(wxSplitterEvent &event); // wxGlade: <event_handler>
virtual void OnListOverlayCheck(wxCommandEvent &event);
virtual void OnListOverlayKeyDown(wxListEvent &event);
virtual void OnTextOverlay(wxCommandEvent &event);
diff -r 34e37068b6c7 -r 47f4a1712c25 src/gui/mainFrame.cpp
--- src/gui/mainFrame.cpp Thu Apr 17 22:17:56 2014 +0100
+++ src/gui/mainFrame.cpp Thu Apr 24 00:06:18 2014 +0100
@@ -1143,9 +1143,12 @@
f->setRangeData(rng);
f->setRangeFilename(s.c_str());
- //Get the parent filter pointer
+ //Add the filter, using the seelcted
+ // item as the parent
visControl.addFilter(f,false,filterId);
+ //update the tree control
+ visControl.updateWxTreeCtrl(treeFilters);
}
else
{
@@ -1398,6 +1401,10 @@
}
setSaveStatus();
+
+ //make sure camera is properly centred
+ if(visControl.numCams() == 1)
+ visControl.ensureSceneVisible(3);
}
}