FOX/ObjCryst++  1.10.X (development)
wxTrackerGraph.cpp
1 /* ObjCryst++ Object-Oriented Crystallographic Library
2  (c) 2005- Vincent Favre-Nicolin vincefn@users.sourceforge.net
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 #include "ObjCryst/wxCryst/wxTrackerGraph.h"
19 
20 namespace ObjCryst
21 {
22 
23 WXTrackerGraph::WXTrackerGraph(wxFrame *frame, MainTracker *tracker):
24 WXMultiGraph(frame),mpMainTracker(tracker)
25 {
26  this->UpdateDisplay();
27 }
28 
29 WXTrackerGraph::~WXTrackerGraph()
30 {
31  if(mpMainTracker!=0) mpMainTracker->WXNotifyDelete();
32 }
33 
35 {
36  VFN_DEBUG_ENTRY("WXTrackerGraph::UpdateDisplay()",4)
37  const std::set<Tracker*> *pList=&(mpMainTracker->GetTrackerList());
38  std::set<Tracker*>::const_iterator pos;
39 
40  // Remove orphan graphs
41  if(mClockGraphList<mpMainTracker->GetClockTrackerList())
42  {
43  std::map<Tracker*,long>::iterator pos1;
44  std::map<Tracker*,long> id=mvId;
45  for(pos1=id.begin();pos1!=id.end();pos1++)
46  if(pList->find(pos1->first)==pList->end())
47  {
48  this->DeleteGraph(pos1->second);
50  }
51  }
52  unsigned long nbxMax=0;
53  // Add new graphs and update data for all
54  if( (mClockGraphList <mpMainTracker->GetClockTrackerList())
55  ||(mClockGraphValues<mpMainTracker->GetClockValues()))
56  {
57  for(pos=pList->begin();pos!=pList->end();pos++)
58  {
59  if(mvId.find(*pos)==mvId.end())
60  {
61  mvId[*pos]=this->AddGraph((*pos)->GetName());
63  }
64  const unsigned long nb=(*pos)->GetValues().size();
65  std::map<long,REAL>::const_iterator pos2;
66  valarray<float> vx(nb),vy(nb);
67  unsigned long i=0;
68  bool allnull=true;
69  for(pos2=(*pos)->GetValues().begin();pos2!=(*pos)->GetValues().end();pos2++)
70  {
71  vx[i]=pos2->first;
72  vy[i]=pos2->second;
73  if(pos2->second!=0) allnull=false;
74  i++;
75  }
76  if(!allnull)
77  {// Only display graph if some values are non-null
78  this->SetGraphData(mvId[*pos],vx,vy);
80  if(nbxMax<vx.size()) nbxMax=vx.size();
81  }
82  }
83  if(nbxMax==1) this->AutoScale(-1);// first drawing, so rescale everything
84  else this->AutoScale(-1,false,true,false,false);//just rescale xmax
85  }
86  this->WXMultiGraph::UpdateDisplay();
87  VFN_DEBUG_EXIT("WXTrackerGraph::UpdateDisplay()",4)
88 }
89 
90 void WXTrackerGraph::DeleteGraph(const unsigned long id)
91 {
92  // remove tracker. Maybe should keep a reverse map.
93  std::map<Tracker*,long>::iterator pos;
94  for(pos=mvId.begin();pos!=mvId.end();pos++)
95  {
96  if((long)id==pos->second)
97  {
98  mvId.erase(pos);
99  break;
100  }
101  }
102  this->WXMultiGraph::DeleteGraph(id);
103 }
104 
105 
106 }//namespace
virtual void DeleteGraph(const unsigned long id)
Remove graph.
void SetGraphData(const unsigned long id, const std::valarray< float > &vx, const std::valarray< float > &vy)
Set data for a given graph.
virtual void UpdateDisplay()
reads new values from the MainTracker, and asks for a repaint.
void Click()
Record an event for this clock (generally, the 'time' an object has been modified, or some computation has been made)
RefinableObjClock mClockGraphValues
Last time values were added to the graph.
virtual void DeleteGraph(const unsigned long id)
Remove graph.
RefinableObjClock mClockGraphList
Last time a tracker was added to the graph.
The namespace which includes all objects (crystallographic and algorithmic) in ObjCryst++.
Definition: Atom.cpp:47
unsigned long AddGraph(const std::string &name)
Add a graph.
void AutoScale(const long id=-1, const bool xmin=true, const bool xmax=true, const bool ymin=true, const bool ymax=true)
Auto-scale graph, i.e.