##// END OF EJS Templates
added quick fileName generation for data export, and fixed wrong date reading...
jeandet -
r10:63067c6877ba default
parent child
Show More
@@ -1,302 +1,306
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the QLop Software
2 -- This file is a part of the QLop Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "cassinidatafile.h"
22 #include "cassinidatafile.h"
23 #include <QFile>
23 #include <QFile>
24 #include <stdio.h>
24 #include <stdio.h>
25 #include <QDateTime>
25 #include <QDateTime>
26 #include <QVector>
26 #include <QVector>
27 #include <QProgressDialog>
27 #include <QProgressDialog>
28 #include <omp.h>
28 #include <omp.h>
29 #include <QTimer>
29 #include <QTimer>
30 #include <QElapsedTimer>
30 #include <QElapsedTimer>
31 #include <sys/time.h>
31 #include <sys/time.h>
32
32
33 CassiniDataFile::CassiniDataFile(QObject *parent) : AbstractFileLoader(parent)
33 CassiniDataFile::CassiniDataFile(QObject *parent) : AbstractFileLoader(parent)
34 {
34 {
35
35
36 }
36 }
37
37
38 CassiniDataFile::~CassiniDataFile()
38 CassiniDataFile::~CassiniDataFile()
39 {
39 {
40
40
41 }
41 }
42
42
43 void CassiniDataFile::parseFile(const QString &fileName)
43 void CassiniDataFile::parseFile(const QString &fileName)
44 {
44 {
45 this->fileName = fileName;
45 this->fileName = fileName;
46 m_Write = false;
46 m_Write = false;
47 this->start();
47 this->start();
48 }
48 }
49
49
50 void CassiniDataFile::saveFile(const QString &fileName, QLopDataList data)
50 void CassiniDataFile::saveFile(const QString &fileName, QLopDataList data)
51 {
51 {
52 this->fileName = fileName;
52 this->fileName = fileName;
53 m_Write = true;
53 m_Write = true;
54 m_data = data;
54 m_data = data;
55 this->start();
55 this->start();
56 }
56 }
57
57
58 inline double __decodeVal(int ofset,unsigned char* data)
58 inline double __decodeVal(int ofset,unsigned char* data)
59 {
59 {
60 if(data[ofset]=='-')
60 if(data[ofset]=='-')
61 return -0.001 * (double)(
61 return -0.001 * (double)(
62 (10000 * (int)(data[ofset+1] & 0x0F))
62 (10000 * (int)(data[ofset+1] & 0x0F))
63 + (1000 * (int)(data[ofset+2] & 0x0F))
63 + (1000 * (int)(data[ofset+2] & 0x0F))
64 + (100 * (int)(data[ofset+4] & 0x0F))
64 + (100 * (int)(data[ofset+4] & 0x0F))
65 + (10 * (int)(data[ofset+5] & 0x0F))
65 + (10 * (int)(data[ofset+5] & 0x0F))
66 + ( (int)(data[ofset+6] & 0x0F))
66 + ( (int)(data[ofset+6] & 0x0F))
67 );
67 );
68 else
68 else
69 {
69 {
70 if(data[ofset+1]=='-')
70 if(data[ofset+1]=='-')
71 {
71 {
72 return -0.001 * (double)(
72 return -0.001 * (double)(
73 (1000 * (int)(data[ofset+2] & 0x0F))
73 (1000 * (int)(data[ofset+2] & 0x0F))
74 + (100 * (int)(data[ofset+4] & 0x0F))
74 + (100 * (int)(data[ofset+4] & 0x0F))
75 + (10 * (int)(data[ofset+5] & 0x0F))
75 + (10 * (int)(data[ofset+5] & 0x0F))
76 + ( (int)(data[ofset+6] & 0x0F))
76 + ( (int)(data[ofset+6] & 0x0F))
77 );
77 );
78 }
78 }
79 else
79 else
80 {
80 {
81 return 0.001 * (double)(
81 return 0.001 * (double)(
82 (10000 * (int)(data[ofset+1] & 0x0F))
82 (10000 * (int)(data[ofset+1] & 0x0F))
83 + (1000 * (int)(data[ofset+2] & 0x0F))
83 + (1000 * (int)(data[ofset+2] & 0x0F))
84 + (100 * (int)(data[ofset+4] & 0x0F))
84 + (100 * (int)(data[ofset+4] & 0x0F))
85 + (10 * (int)(data[ofset+5] & 0x0F))
85 + (10 * (int)(data[ofset+5] & 0x0F))
86 + ( (int)(data[ofset+6] & 0x0F))
86 + ( (int)(data[ofset+6] & 0x0F))
87 );
87 );
88 }
88 }
89 }
89 }
90 }
90 }
91
91
92 inline QDate __decodeDate(int ofset,unsigned char* data)
92 inline QDate __decodeDate(int ofset,unsigned char* data)
93 {
93 {
94 int y=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + (1*(data[ofset+3] & 0x0F));
94 int y=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + (1*(data[ofset+3] & 0x0F));
95 int m=(10*(data[ofset+5] & 0x0F)) + (1*(data[ofset+6] & 0x0F));
95 int m=(10*(data[ofset+5] & 0x0F)) + (1*(data[ofset+6] & 0x0F));
96 int d=(10*(data[ofset+8] & 0x0F)) + (1*(data[ofset+9] & 0x0F));
96 int d=(10*(data[ofset+8] & 0x0F)) + (1*(data[ofset+9] & 0x0F));
97 return QDate(y,m,d);
97 return QDate(y,m,d);
98 }
98 }
99
99
100 inline QTime __decodeTime(int ofset,unsigned char* data)
100 inline QTime __decodeTime(int ofset,unsigned char* data)
101 {
101 {
102 int h=(10*(data[ofset] & 0x0F)) + (1*(data[ofset+1] & 0x0F));
102 int h=(10*(data[ofset] & 0x0F)) + (1*(data[ofset+1] & 0x0F));
103 int m=(10*(data[ofset+3] & 0x0F)) + (1*(data[ofset+4] & 0x0F));
103 int m=(10*(data[ofset+3] & 0x0F)) + (1*(data[ofset+4] & 0x0F));
104 int s=(10*(data[ofset+6] & 0x0F)) + (1*(data[ofset+7] & 0x0F));
104 int s=(10*(data[ofset+6] & 0x0F)) + (1*(data[ofset+7] & 0x0F));
105 int ms=(100*(data[ofset+9] & 0x0F)) + (10*(data[ofset+10] & 0x0F)) + (1*(data[ofset+11] & 0x0F));
105 int ms=(100*(data[ofset+9] & 0x0F)) + (10*(data[ofset+10] & 0x0F)) + (1*(data[ofset+11] & 0x0F));
106 return QTime(h,m,s,ms);
106 return QTime(h,m,s,ms);
107 }
107 }
108
108
109 double __decodeTimeFromEpochMs(int ofset,unsigned char* data)
109 double __decodeTimeFromEpochMs(int ofset,unsigned char* data)
110 {
110 {
111 struct tm t;
111 struct tm t;
112 time_t t_of_day;
112 time_t t_of_day;
113 t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900;
113 t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900;
114 t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F));
114 t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F));
115 t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F));
115 t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F));
116 t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F));
116 t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F));
117 t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F));
117 t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F));
118 t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F));
118 t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F));
119 int ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F));
119 int ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F));
120 t_of_day = mktime(&t);
120 t_of_day = mktime(&t);
121 return (t_of_day*1000.0)+ms;
121 return (t_of_day*1000.0)+ms;
122 }
122 }
123
123
124 double __decodeTimeFromEpoch(int ofset,unsigned char* data)
124 double __decodeTimeFromEpoch(int ofset,unsigned char* data)
125 {
125 {
126 struct tm t;
126 struct tm t;
127 time_t t_of_day;
127 time_t t_of_day;
128 t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900;
128 t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900;
129 t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F));
129 t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F));
130 t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F));
130 t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F));
131 t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F));
131 t.tm_hour=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F));
132 t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F));
132 t.tm_min=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F));
133 t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F));
133 t.tm_sec=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F));
134 double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F));
134 double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F));
135 t_of_day = mktime(&t);
135 t_of_day = mktime(&t);
136 return (double)t_of_day+((double)ms*(double)0.001);
136 return (double)t_of_day+((double)ms*(double)0.001);
137 }
137 }
138
138
139 double __decodeTimeHMSmS(int ofset,unsigned char* data)
139 double __decodeTimeHMSmS(int ofset,unsigned char* data)
140 {
140 {
141 int h,m,s;
141 int h,m,s;
142 h=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F));
142 h=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F));
143 m=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F));
143 m=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F));
144 s=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F));
144 s=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F));
145 double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F));
145 double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F));
146 return (double)((h*3600)+(m*60)+s) + (ms*0.001);
146 return (double)((h*3600)+(m*60)+s) + (ms*0.001);
147 }
147 }
148
148
149 double __decodeTimeDHMSmS(int ofset,unsigned char* data)
149 double __decodeTimeDHMSmS(int ofset,unsigned char* data)
150 {
150 {
151 int d,h,m,s;
151 int d,h,m,s;
152 d=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F));
152 d=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F));
153 h=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F));
153 h=(10*(data[ofset+11] & 0x0F)) + ((data[ofset+12] & 0x0F));
154 m=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F));
154 m=(10*(data[ofset+14] & 0x0F)) + ((data[ofset+15] & 0x0F));
155 s=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F));
155 s=(10*(data[ofset+17] & 0x0F)) + ((data[ofset+18] & 0x0F));
156 double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F));
156 double ms=(100*(data[ofset+20] & 0x0F)) + (10*(data[ofset+21] & 0x0F)) + ((data[ofset+22] & 0x0F));
157 return (double)((d*3600*24)+(h*3600)+(m*60)+s) + (ms*0.001);
157 return (double)((d*3600*24)+(h*3600)+(m*60)+s) + (ms*0.001);
158 }
158 }
159
159
160 double __decodeTimeFromEpochDayOnly(int ofset,unsigned char* data)
160 double __decodeTimeFromEpochDayOnly(int ofset,unsigned char* data)
161 {
161 {
162 struct tm t;
162 struct tm t;
163 time_t t_of_day;
163 time_t t_of_day;
164 t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900;
164 // t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F)) -1900;
165 t.tm_year=(1000*(data[ofset] & 0x0F)) + (100*(data[ofset+1] & 0x0F)) + (10*(data[ofset+2] & 0x0F)) + ((data[ofset+3] & 0x0F));
165 t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F));
166 t.tm_mon=(10*(data[ofset+5] & 0x0F)) + ((data[ofset+6] & 0x0F));
166 t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F));
167 t.tm_mday=(10*(data[ofset+8] & 0x0F)) + ((data[ofset+9] & 0x0F));
167 t.tm_hour=0;
168 t.tm_hour=0;
168 t.tm_min=0;
169 t.tm_min=0;
169 t.tm_sec=0;
170 t.tm_sec=0;
170 t_of_day = mktime(&t);
171 // t_of_day = mktime(&t);
171 return (double)t_of_day;
172 // return (double)t_of_day;
173 QDateTime date(QDate(t.tm_year,t.tm_mon,1),QTime(0,0));
174 // date.setDate();
175 return (double)((date.toMSecsSinceEpoch()/1000.0)-(24*3600));
172 }
176 }
173
177
174 void CassiniDataFile::run()
178 void CassiniDataFile::run()
175 {
179 {
176 if(!m_Write)
180 if(!m_Write)
177 {
181 {
178 readFile();
182 readFile();
179 }
183 }
180 else
184 else
181 {
185 {
182 writeFile();
186 writeFile();
183 }
187 }
184 }
188 }
185
189
186 void CassiniDataFile::readFile()
190 void CassiniDataFile::readFile()
187 {
191 {
188 FILE* dataFile;
192 FILE* dataFile;
189 dataFile = fopen(fileName.toStdString().c_str(),"r");
193 dataFile = fopen(fileName.toStdString().c_str(),"r");
190
194
191 if(dataFile != NULL)
195 if(dataFile != NULL)
192 {
196 {
193 fseek(dataFile, 0L, SEEK_END);
197 fseek(dataFile, 0L, SEEK_END);
194 int FileSize=ftell(dataFile);
198 int FileSize=ftell(dataFile);
195 int lineCnt = FileSize/58;
199 int lineCnt = FileSize/58;
196 int curLine=0;
200 int curLine=0;
197 int lastLineUpdate=0;
201 int lastLineUpdate=0;
198 QVector<QCPData> *ch1=new QVector<QCPData>(lineCnt);
202 QVector<QCPData> *ch1=new QVector<QCPData>(lineCnt);
199 QVector<QCPData> *ch2=new QVector<QCPData>(lineCnt);
203 QVector<QCPData> *ch2=new QVector<QCPData>(lineCnt);
200 QVector<QCPData> *ch3=new QVector<QCPData>(lineCnt);
204 QVector<QCPData> *ch3=new QVector<QCPData>(lineCnt);
201 QLopDataList data;
205 QLopDataList data;
202 QLopData* ch1V=new QLopData();
206 QLopData* ch1V=new QLopData();
203 QLopData* ch2V=new QLopData();
207 QLopData* ch2V=new QLopData();
204 QLopData* ch3V=new QLopData();
208 QLopData* ch3V=new QLopData();
205 ch1V->data=ch1;
209 ch1V->data=ch1;
206 ch2V->data=ch2;
210 ch2V->data=ch2;
207 ch3V->data=ch3;
211 ch3V->data=ch3;
208 ch1V->name="r";
212 ch1V->name="r";
209 ch2V->name="theta";
213 ch2V->name="theta";
210 ch3V->name="phi";
214 ch3V->name="phi";
211 ch1V->unit="nT";
215 ch1V->unit="nT";
212 ch2V->unit="nT";
216 ch2V->unit="nT";
213 ch3V->unit="nT";
217 ch3V->unit="nT";
214 data.append(ch1V);
218 data.append(ch1V);
215 data.append(ch2V);
219 data.append(ch2V);
216 data.append(ch3V);
220 data.append(ch3V);
217 QElapsedTimer timr;
221 QElapsedTimer timr;
218
222
219 double _x=0.0,day=0.0;
223 double _x=0.0,day=0.0;
220 char* line;
224 char* line;
221 QCPData data1,data2,data3;
225 QCPData data1,data2,data3;
222 char* fileContent=(char*)malloc(FileSize);
226 char* fileContent=(char*)malloc(FileSize);
223 if(Q_UNLIKELY(fileContent==NULL))return;
227 if(Q_UNLIKELY(fileContent==NULL))return;
224 int threadIndex,numThreads=omp_get_num_threads();
228 int threadIndex,numThreads=omp_get_num_threads();
225 int updateTriger=(lineCnt/100)/numThreads;
229 int updateTriger=(lineCnt/100)/numThreads;
226 fseek(dataFile, 0L, SEEK_SET);
230 fseek(dataFile, 0L, SEEK_SET);
227 char* svglocale=NULL;
231 char* svglocale=NULL;
228 setlocale(LC_NUMERIC,svglocale);
232 setlocale(LC_NUMERIC,svglocale);
229 setlocale(LC_NUMERIC, "en_US");
233 setlocale(LC_NUMERIC, "en_US");
230 if(fread(fileContent,1,FileSize,dataFile))
234 if(fread(fileContent,1,FileSize,dataFile))
231 {
235 {
232 line = fileContent;
236 line = fileContent;
233 QDateTime date;
237 QDateTime date;
234 timr.start();
238 timr.start();
235 day=__decodeTimeFromEpochDayOnly(0,(unsigned char*)line);
239 day=__decodeTimeFromEpochDayOnly(0,(unsigned char*)line);
236 //#pragma omp parallel if ((FileSize > 10000000)) private(date,data1,data2,data3,_x,threadIndex,lastLineUpdate) shared(ch1,ch2,ch3,lineCnt)
240 //#pragma omp parallel if ((FileSize > 10000000)) private(date,data1,data2,data3,_x,threadIndex,lastLineUpdate) shared(ch1,ch2,ch3,lineCnt)
237 // {
241 // {
238 #pragma omp parallel for if ((FileSize > 1024*1024*10)) private(date,data1,data2,data3,_x,threadIndex,lastLineUpdate,curLine) shared(ch1,ch2,ch3,lineCnt,updateTriger)
242 #pragma omp parallel for if ((FileSize > 1024*1024*10)) private(date,data1,data2,data3,_x,threadIndex,lastLineUpdate,curLine) shared(ch1,ch2,ch3,lineCnt,updateTriger)
239 for(int i=0;i<lineCnt;i++)
243 for(int i=0;i<lineCnt;i++)
240 {
244 {
241 // _x= i;
245 // _x= i;
242 _x= day + __decodeTimeDHMSmS((i*58),(unsigned char*)line);
246 _x= day + __decodeTimeDHMSmS((i*58),(unsigned char*)line);
243 // _x=__decodeTimeFromEpoch((i*58),(unsigned char*)line);
247 // _x=__decodeTimeFromEpoch((i*58),(unsigned char*)line);
244 data1.key=_x;
248 data1.key=_x;
245 data2.key=_x;
249 data2.key=_x;
246 data3.key=_x;
250 data3.key=_x;
247 data1.value=__decodeVal(((i*58)+27),(unsigned char*)line);
251 data1.value=__decodeVal(((i*58)+27),(unsigned char*)line);
248 data2.value=__decodeVal(((i*58)+38),(unsigned char*)line);
252 data2.value=__decodeVal(((i*58)+38),(unsigned char*)line);
249 data3.value=__decodeVal(((i*58)+49),(unsigned char*)line);
253 data3.value=__decodeVal(((i*58)+49),(unsigned char*)line);
250 (*ch1)[i]=data1;
254 (*ch1)[i]=data1;
251 (*ch2)[i]=data2;
255 (*ch2)[i]=data2;
252 (*ch3)[i]=data3;
256 (*ch3)[i]=data3;
253 curLine++;
257 curLine++;
254 if(Q_UNLIKELY(lastLineUpdate++>updateTriger))
258 if(Q_UNLIKELY(lastLineUpdate++>updateTriger))
255 {
259 {
256 lastLineUpdate=0;
260 lastLineUpdate=0;
257 int test=((curLine*numThreads *100)/ (lineCnt));
261 int test=((curLine*numThreads *100)/ (lineCnt));
258 emit updateProgress(omp_get_thread_num(),test);
262 emit updateProgress(omp_get_thread_num(),test);
259 }
263 }
260 }
264 }
261 }
265 }
262 //#pragma omp barrier
266 //#pragma omp barrier
263 free(fileContent);
267 free(fileContent);
264 // }
268 // }
265 qDebug()<< lineCnt <<" Points loade in "<< timr.elapsed()<<"ms";
269 qDebug()<< lineCnt <<" Points loade in "<< timr.elapsed()<<"ms";
266 setlocale(LC_NUMERIC,svglocale);
270 setlocale(LC_NUMERIC,svglocale);
267 emit dataReady(data);
271 emit dataReady(data);
268 }
272 }
269 }
273 }
270
274
271 void CassiniDataFile::writeFile()
275 void CassiniDataFile::writeFile()
272 {
276 {
273 QFile dataFile(fileName);
277 QFile dataFile(fileName);
274 dataFile.open(QIODevice::WriteOnly);
278 dataFile.open(QIODevice::WriteOnly);
275 QTextStream out(&dataFile);
279 QTextStream out(&dataFile);
276 if(dataFile.isOpen())
280 if(dataFile.isOpen())
277 {
281 {
278 if(m_data.count()==3)
282 if(m_data.count()==3)
279 {
283 {
280 QLopData* ch1V=m_data.at(0);
284 QLopData* ch1V=m_data.at(0);
281 QLopData* ch2V=m_data.at(1);
285 QLopData* ch2V=m_data.at(1);
282 QLopData* ch3V=m_data.at(2);
286 QLopData* ch3V=m_data.at(2);
283 if(ch1V->data->count()==ch2V->data->count() && ch1V->data->count()==ch3V->data->count())
287 if(ch1V->data->count()==ch2V->data->count() && ch1V->data->count()==ch3V->data->count())
284 {
288 {
285 for(int i=0;i<ch1V->data->count();i++)
289 for(int i=0;i<ch1V->data->count();i++)
286 {
290 {
287 double key = ch1V->data->at(i).key;
291 double key = ch1V->data->at(i).key;
288 QDateTime date = QDateTime::fromMSecsSinceEpoch(key*1000);
292 QDateTime date = QDateTime::fromMSecsSinceEpoch(key*1000);
289 out << date.toString(Qt::ISODate)+QString(".%1").arg(date.time().msec(),3);
293 out << date.toString(Qt::ISODate)+QString(".%1").arg(date.time().msec(),3);
290 out << QString("%1%2%3").arg(ch1V->data->at(i).value, 11, 'f', 3).arg(ch2V->data->at(i).value, 11, 'f', 3).arg(ch3V->data->at(i).value, 11, 'f', 3);
294 out << QString("%1%2%3").arg(ch1V->data->at(i).value, 11, 'f', 3).arg(ch2V->data->at(i).value, 11, 'f', 3).arg(ch3V->data->at(i).value, 11, 'f', 3);
291 out << "\r\n";
295 out << "\r\n";
292 }
296 }
293 }
297 }
294 dataFile.flush();
298 dataFile.flush();
295 m_data.clear();
299 m_data.clear();
296 delete ch1V;
300 delete ch1V;
297 delete ch2V;
301 delete ch2V;
298 delete ch3V;
302 delete ch3V;
299 }
303 }
300 }
304 }
301 }
305 }
302
306
@@ -1,248 +1,277
1 #include "cassinitools.h"
1 #include "cassinitools.h"
2 #include <qlopplots.h>
2 #include <qlopplots.h>
3 #include <QPen>
3 #include <QPen>
4 #include <QAction>
4 #include <QAction>
5 #include <fftw3.h>
5 #include <fftw3.h>
6
6
7 CassiniTools* CassiniTools::_self=NULL;
7 CassiniTools* CassiniTools::_self=NULL;
8 QDockWidget* CassiniTools::m_gui=NULL;
8 QDockWidget* CassiniTools::m_gui=NULL;
9 CassiniToolsGUI* CassiniTools::m_CassiniToolsGUI=NULL;
9 CassiniToolsGUI* CassiniTools::m_CassiniToolsGUI=NULL;
10 CassiniDataFile* CassiniTools::m_dataFile=NULL;
10 CassiniDataFile* CassiniTools::m_dataFile=NULL;
11 int CassiniTools::m_defaultPlot=-1;
11 int CassiniTools::m_defaultPlot=-1;
12 int CassiniTools::m_fftPlot=-1;
12 int CassiniTools::m_fftPlot=-1;
13 SocExplorerPlotActions* CassiniTools::ExportAction=NULL;
13
14
14 Qt::GlobalColor QLopColours[]= {Qt::black,
15 Qt::GlobalColor QLopColours[]= {Qt::black,
15 Qt::red,
16 Qt::red,
16 Qt::blue,
17 Qt::blue,
17 Qt::green,
18 Qt::green,
18 Qt::darkGreen,
19 Qt::darkGreen,
19 Qt::cyan,
20 Qt::cyan,
20 Qt::darkRed,
21 Qt::darkRed,
21 Qt::gray,
22 Qt::gray,
22 Qt::yellow,
23 Qt::yellow,
23 Qt::darkBlue,
24 Qt::darkBlue,
24 Qt::darkCyan,
25 Qt::darkCyan,
25 Qt::magenta,
26 Qt::magenta,
26 Qt::darkMagenta,
27 Qt::darkMagenta,
27 Qt::darkYellow,
28 Qt::darkYellow,
28 Qt::darkGray,
29 Qt::darkGray,
29 Qt::lightGray};
30 Qt::lightGray};
30
31
31 int QLopColoursCount=16;
32 int QLopColoursCount=16;
32
33
33 #define _INIT() if(Q_UNLIKELY(_self==NULL)){init();}
34 #define _INIT() if(Q_UNLIKELY(_self==NULL)){init();}
34
35
35 CassiniTools::CassiniTools(bool noGUI,QObject *parent) : QLopService(parent)
36 CassiniTools::CassiniTools(bool noGUI,QObject *parent) : QLopService(parent)
36 {
37 {
37 m_dataFile = new CassiniDataFile();
38 m_dataFile = new CassiniDataFile();
38 connect(m_dataFile,SIGNAL(dataReady(QLopDataList)),this,SLOT(dataReady(QLopDataList)));
39 connect(m_dataFile,SIGNAL(dataReady(QLopDataList)),this,SLOT(dataReady(QLopDataList)));
39 m_serviceName="CassiniTools";
40 m_serviceName="CassiniTools";
40 m_noGui=noGUI;
41 m_noGui=noGUI;
41 }
42 }
42
43
43 CassiniTools::~CassiniTools()
44 CassiniTools::~CassiniTools()
44 {
45 {
45 delete m_dataFile;
46 delete m_dataFile;
46 delete m_CassiniToolsGUI;
47 delete m_CassiniToolsGUI;
47 delete m_gui;
48 delete m_gui;
48 }
49 }
49
50
50 void CassiniTools::makePlot()
51 void CassiniTools::makePlot()
51 {
52 {
52 m_defaultPlot = QLopPlots::addPlot();
53 m_defaultPlot = QLopPlots::addPlot();
53 m_fftPlot = QLopPlots::addPlot();
54 m_fftPlot = QLopPlots::addPlot();
54 SocExplorerPlot* plot=QLopPlots::getPlot(m_defaultPlot);
55 SocExplorerPlot* plot=QLopPlots::getPlot(m_defaultPlot);
55 if(plot)
56 if(plot)
56 {
57 {
57 plot->setTitle(_self->m_serviceName + " plot");
58 plot->setTitle(_self->m_serviceName + " plot");
58 plot->setXaxisTickLabelType(QCPAxis::ltDateTime);
59 plot->setXaxisTickLabelType(QCPAxis::ltDateTime);
59 plot->setXaxisDateTimeFormat("hh:mm:ss.zzz");
60 plot->setXaxisDateTimeFormat("hh:mm:ss.zzz");
60 plot->setContextMenuPolicy(Qt::ActionsContextMenu);
61 plot->setContextMenuPolicy(Qt::ActionsContextMenu);
61 SocExplorerPlotActions* action=new SocExplorerPlotActions("export view",plot->PID(),_self);
62 SocExplorerPlotActions* action=new SocExplorerPlotActions("export view",plot->PID(),_self);
62 plot->addAction(action);
63 plot->addAction(action);
63 QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(export_view(int)));
64 QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(export_view(int)));
65 ExportAction=new SocExplorerPlotActions("export view to "+QString(plot->title()).replace(".TAB","-part.TAB"),plot->PID(),_self);
66 plot->addAction(ExportAction);
67 QObject::connect(ExportAction,SIGNAL(triggered(int)),_self,SLOT(export_view_Predefined_FileName(int)));
64 action=new SocExplorerPlotActions("FFT of the current view",plot->PID(),_self);
68 action=new SocExplorerPlotActions("FFT of the current view",plot->PID(),_self);
65 plot->addAction(action);
69 plot->addAction(action);
66 QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(compute_fft_on_view(int)));
70 QObject::connect(action,SIGNAL(triggered(int)),_self,SLOT(compute_fft_on_view(int)));
67 }
71 }
68 }
72 }
69
73
70 void CassiniTools::init(bool noGUI, QObject *parent)
74 void CassiniTools::init(bool noGUI, QObject *parent)
71 {
75 {
72 if(Q_UNLIKELY(_self==NULL))
76 if(Q_UNLIKELY(_self==NULL))
73 {
77 {
74 _self=new CassiniTools(noGUI,parent);
78 _self=new CassiniTools(noGUI,parent);
75 }
79 }
76 }
80 }
77
81
78 CassiniTools *CassiniTools::self()
82 CassiniTools *CassiniTools::self()
79 {
83 {
80 _INIT();
84 _INIT();
81 return _self;
85 return _self;
82 }
86 }
83
87
84 void CassiniTools::decodeFGMData(const QString &file)
88 void CassiniTools::decodeFGMData(const QString &file)
85 {
89 {
86 _INIT();
90 _INIT();
87 m_dataFile->parseFile(file);
91 m_dataFile->parseFile(file);
88 }
92 }
89
93
90 void CassiniTools::plotFile(const QString &File)
94 void CassiniTools::plotFile(const QString &File)
91 {
95 {
92 if(!m_dataFile->isRunning())
96 if(!m_dataFile->isRunning())
93 {
97 {
94 m_dataFile->parseFile(File);
98 m_dataFile->parseFile(File);
95 // TODO fixme
99 // TODO fixme
96 SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot);
100 SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot);
97 if(plot==NULL)
101 if(plot==NULL)
98 {
102 {
99 makePlot();
103 makePlot();
100 plot = QLopPlots::getPlot(m_defaultPlot);
104 plot = QLopPlots::getPlot(m_defaultPlot);
101 }
105 }
102 if(plot)
106 if(plot)
107 {
103 plot->setTitle(File);
108 plot->setTitle(File);
109 ExportAction->setText("export view to "+QString(File).replace(".TAB","-part.TAB"));
110 }
104 }
111 }
105 }
112 }
106
113
107 void CassiniTools::plot_TAB_File(const QString &fileName)
114 void CassiniTools::plot_TAB_File(const QString &fileName)
108 {
115 {
109 //TODO fix: accent not accepted
116 //TODO fix: accent not accepted
110 plotFile(fileName);
117 plotFile(fileName);
111 }
118 }
112
119
113 void CassiniTools::export_view(int PID)
120 void CassiniTools::export_view(int PID)
114 {
121 {
115 SocExplorerPlot* plot = QLopPlots::getPlot(PID);
122 SocExplorerPlot* plot = QLopPlots::getPlot(PID);
116 if(plot==NULL)
123 if(plot==NULL)
117 return;
124 return;
118 {
125 {
119 QString fileName = QFileDialog::getSaveFileName();
126 QString fileName = plot->title();
127 fileName = QFileDialog::getSaveFileName(0,tr("Set filename"),fileName.replace(".TAB","-part.TAB"));
128 if(fileName!="")
129 {
130 QLopDataList vectors;
131 for(int i=0;i<plot->graphCount();i++)
132 {
133 QLopData* vect = new QLopData();
134 vect->data = plot->getVisibleData(i);
135 vectors.append(vect);
136 }
137 m_dataFile->saveFile(fileName,vectors);
138 }
139 }
140 }
141
142 void CassiniTools::export_view_Predefined_FileName(int PID)
143 {
144 SocExplorerPlot* plot = QLopPlots::getPlot(PID);
145 if(plot==NULL)
146 return;
147 {
148 QString fileName = QString(plot->title()).replace(".TAB","-part.TAB");
120 if(fileName!="")
149 if(fileName!="")
121 {
150 {
122 QLopDataList vectors;
151 QLopDataList vectors;
123 for(int i=0;i<plot->graphCount();i++)
152 for(int i=0;i<plot->graphCount();i++)
124 {
153 {
125 QLopData* vect = new QLopData();
154 QLopData* vect = new QLopData();
126 vect->data = plot->getVisibleData(i);
155 vect->data = plot->getVisibleData(i);
127 vectors.append(vect);
156 vectors.append(vect);
128 }
157 }
129 m_dataFile->saveFile(fileName,vectors);
158 m_dataFile->saveFile(fileName,vectors);
130 }
159 }
131 }
160 }
132 }
161 }
133
162
134 void CassiniTools::compute_fft_on_view(int PID)
163 void CassiniTools::compute_fft_on_view(int PID)
135 {
164 {
136 SocExplorerPlot* plot = QLopPlots::getPlot(PID);
165 SocExplorerPlot* plot = QLopPlots::getPlot(PID);
137 if(plot==NULL)
166 if(plot==NULL)
138 return;
167 return;
139 {
168 {
140 QLopDataList vectors;
169 QLopDataList vectors;
141 for(int i=0;i<plot->graphCount();i++)
170 for(int i=0;i<plot->graphCount();i++)
142 {
171 {
143 QLopData* vect = new QLopData();
172 QLopData* vect = new QLopData();
144 vect->data = plot->getVisibleData(i);
173 vect->data = plot->getVisibleData(i);
145 vectors.append(vect);
174 vectors.append(vect);
146 }
175 }
147 if(vectors.count()==3)
176 if(vectors.count()==3)
148 {
177 {
149 QLopData* ch1V=vectors.at(0);
178 QLopData* ch1V=vectors.at(0);
150 QLopData* ch2V=vectors.at(1);
179 QLopData* ch2V=vectors.at(1);
151 QLopData* ch3V=vectors.at(2);
180 QLopData* ch3V=vectors.at(2);
152 QLopData* FFTout=new QLopData();
181 QLopData* FFTout=new QLopData();
153 if(ch1V->data->count()==ch2V->data->count() && ch1V->data->count()==ch3V->data->count())
182 if(ch1V->data->count()==ch2V->data->count() && ch1V->data->count()==ch3V->data->count())
154 {
183 {
155
184
156 double* in;
185 double* in;
157 fftw_complex *out;
186 fftw_complex *out;
158 fftw_plan p;
187 fftw_plan p;
159 FFTout->data = new QVector<QCPData>(ch1V->data->count()/2);
188 FFTout->data = new QVector<QCPData>(ch1V->data->count()/2);
160 in = (double*) fftw_malloc(sizeof(double) * ch1V->data->count());
189 in = (double*) fftw_malloc(sizeof(double) * ch1V->data->count());
161 out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * ch1V->data->count());
190 out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * ch1V->data->count());
162 double av=0;
191 double av=0;
163 for(int i=0;i<ch1V->data->count();i++)
192 for(int i=0;i<ch1V->data->count();i++)
164 {
193 {
165 in[i]=sqrt((ch1V->data->at(i).value*ch1V->data->at(i).value) + (ch2V->data->at(i).value*ch2V->data->at(i).value) + (ch3V->data->at(i).value*ch3V->data->at(i).value));
194 in[i]=sqrt((ch1V->data->at(i).value*ch1V->data->at(i).value) + (ch2V->data->at(i).value*ch2V->data->at(i).value) + (ch3V->data->at(i).value*ch3V->data->at(i).value));
166 av = av+in[i];
195 av = av+in[i];
167 }
196 }
168 av/=ch1V->data->count();
197 av/=ch1V->data->count();
169 for(int i=0;i<ch1V->data->count();i++)
198 for(int i=0;i<ch1V->data->count();i++)
170 {
199 {
171 in[i]=in[i]-av;
200 in[i]=in[i]-av;
172 }
201 }
173 p = fftw_plan_dft_r2c_1d(ch1V->data->count(),in, out,FFTW_ESTIMATE);
202 p = fftw_plan_dft_r2c_1d(ch1V->data->count(),in, out,FFTW_ESTIMATE);
174 fftw_execute(p); /* repeat as needed */
203 fftw_execute(p); /* repeat as needed */
175 fftw_destroy_plan(p);
204 fftw_destroy_plan(p);
176 fftw_free(in);
205 fftw_free(in);
177 for(int i=0;i<ch1V->data->count()/2;i++)
206 for(int i=0;i<ch1V->data->count()/2;i++)
178 {
207 {
179 // (*FFTout->data)[i].value=sqrt((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/ch1V->data->count();
208 // (*FFTout->data)[i].value=sqrt((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/ch1V->data->count();
180 (*FFTout->data)[i].value=((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/(ch1V->data->count());
209 (*FFTout->data)[i].value=((out[i][0] * out[i][0]) + (out[i][1] * out[i][1]))/(ch1V->data->count());
181 (*FFTout->data)[i].key = i;
210 (*FFTout->data)[i].key = i;
182 }
211 }
183 fftw_free(out);
212 fftw_free(out);
184 SocExplorerPlot* plot = QLopPlots::getPlot(m_fftPlot);
213 SocExplorerPlot* plot = QLopPlots::getPlot(m_fftPlot);
185 if(plot==NULL)
214 if(plot==NULL)
186 return;
215 return;
187 plot->removeAllGraphs();
216 plot->removeAllGraphs();
188 plot->addGraph();
217 plot->addGraph();
189 plot->setXaxisLog();
218 plot->setXaxisLog();
190 plot->setYaxisLog();
219 plot->setYaxisLog();
191 plot->setAdaptativeSampling(0,true);
220 plot->setAdaptativeSampling(0,true);
192 QPen pen = plot->getGraphPen(0);
221 QPen pen = plot->getGraphPen(0);
193 pen.setColor(QLopColours[0%QLopColoursCount]);
222 pen.setColor(QLopColours[0%QLopColoursCount]);
194 plot->setGraphPen(0,pen);
223 plot->setGraphPen(0,pen);
195 plot->setGraphData(0,FFTout->data,false);
224 plot->setGraphData(0,FFTout->data,false);
196 plot->rescaleAxis();
225 plot->rescaleAxis();
197 plot->replot();
226 plot->replot();
198
227
199 }
228 }
200 }
229 }
201 }
230 }
202 }
231 }
203
232
204 QDockWidget *CassiniTools::getGUI()
233 QDockWidget *CassiniTools::getGUI()
205 {
234 {
206 if(!m_noGui && (m_gui==NULL))
235 if(!m_noGui && (m_gui==NULL))
207 {
236 {
208 m_gui=new QDockWidget("Cassini Tools");
237 m_gui=new QDockWidget("Cassini Tools");
209 m_CassiniToolsGUI = new CassiniToolsGUI();
238 m_CassiniToolsGUI = new CassiniToolsGUI();
210 m_gui->setWidget(m_CassiniToolsGUI);
239 m_gui->setWidget(m_CassiniToolsGUI);
211 m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
240 m_gui->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
212 }
241 }
213 return m_gui;
242 return m_gui;
214 }
243 }
215
244
216 const QString &CassiniTools::serviceName()
245 const QString &CassiniTools::serviceName()
217 {
246 {
218 _INIT();
247 _INIT();
219 return m_serviceName;
248 return m_serviceName;
220 }
249 }
221
250
222 void CassiniTools::dataReady(QLopDataList data)
251 void CassiniTools::dataReady(QLopDataList data)
223 {
252 {
224 SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot);
253 SocExplorerPlot* plot = QLopPlots::getPlot(m_defaultPlot);
225 if(plot==NULL)
254 if(plot==NULL)
226 {
255 {
227 makePlot();
256 makePlot();
228 plot = QLopPlots::getPlot(m_defaultPlot);
257 plot = QLopPlots::getPlot(m_defaultPlot);
229 }
258 }
230 if(plot)
259 if(plot)
231 {
260 {
232 plot->removeAllGraphs();
261 plot->removeAllGraphs();
233 for(int i=0;i<data.count();i++)
262 for(int i=0;i<data.count();i++)
234 {
263 {
235 plot->addGraph();
264 plot->addGraph();
236 plot->setAdaptativeSampling(i,true);
265 plot->setAdaptativeSampling(i,true);
237 plot->setUseFastVector(i,true);
266 plot->setUseFastVector(i,true);
238 QPen pen = plot->getGraphPen(i);
267 QPen pen = plot->getGraphPen(i);
239 pen.setColor(QLopColours[i%QLopColoursCount]);
268 pen.setColor(QLopColours[i%QLopColoursCount]);
240 plot->setGraphPen(i,pen);
269 plot->setGraphPen(i,pen);
241 plot->setGraphName(i,data.at(i)->name+"("+data.at(i)->unit+")");
270 plot->setGraphName(i,data.at(i)->name+"("+data.at(i)->unit+")");
242 plot->setGraphData(i,data.at(i)->data,false);
271 plot->setGraphData(i,data.at(i)->data,false);
243 }
272 }
244 plot->rescaleAxis();
273 plot->rescaleAxis();
245 plot->replot();
274 plot->replot();
246 }
275 }
247 }
276 }
248
277
@@ -1,41 +1,43
1 #ifndef CASSINITOOLS_H
1 #ifndef CASSINITOOLS_H
2 #define CASSINITOOLS_H
2 #define CASSINITOOLS_H
3
3
4 #include <QObject>
4 #include <QObject>
5 #include <QWidget>
5 #include <QWidget>
6 #include <qlopservice.h>
6 #include <qlopservice.h>
7 #include <cassinitoolsgui.h>
7 #include <cassinitoolsgui.h>
8 #include <cassinidatafile.h>
8 #include <cassinidatafile.h>
9 #include <qlopdata.h>
9 #include <qlopdata.h>
10 #include <SocExplorerPlot.h>
10 #include <SocExplorerPlot.h>
11
11
12 class CassiniTools: public QLopService
12 class CassiniTools: public QLopService
13 {
13 {
14 Q_OBJECT
14 Q_OBJECT
15 private:
15 private:
16 static CassiniTools* _self;
16 static CassiniTools* _self;
17 static QDockWidget* m_gui;
17 static QDockWidget* m_gui;
18 static CassiniToolsGUI* m_CassiniToolsGUI;
18 static CassiniToolsGUI* m_CassiniToolsGUI;
19 static CassiniDataFile* m_dataFile;
19 static CassiniDataFile* m_dataFile;
20 static int m_defaultPlot,m_fftPlot;
20 static int m_defaultPlot,m_fftPlot;
21 static SocExplorerPlotActions* ExportAction;
21 CassiniTools(bool noGUI=false, QObject *parent=0);
22 CassiniTools(bool noGUI=false, QObject *parent=0);
22 ~CassiniTools();
23 ~CassiniTools();
23 static void makePlot();
24 static void makePlot();
24 public:
25 public:
25 static void init(bool noGUI=false,QObject *parent = 0);
26 static void init(bool noGUI=false,QObject *parent = 0);
26 static CassiniTools *self();
27 static CassiniTools *self();
27 static void decodeFGMData(const QString& file);
28 static void decodeFGMData(const QString& file);
28 // QLopService methodes
29 // QLopService methodes
29 QDockWidget* getGUI();
30 QDockWidget* getGUI();
30 const QString& serviceName();
31 const QString& serviceName();
31 static void plotFile(const QString &File);
32 static void plotFile(const QString &File);
32 public slots:
33 public slots:
33 void plot_TAB_File(const QString& fileName);
34 void plot_TAB_File(const QString& fileName);
34 void export_view(int PID);
35 void export_view(int PID);
36 void export_view_Predefined_FileName(int PID);
35 void compute_fft_on_view(int PID);
37 void compute_fft_on_view(int PID);
36 private slots:
38 private slots:
37 void dataReady(QLopDataList data);
39 void dataReady(QLopDataList data);
38 };
40 };
39
41
40 #endif // CASSINITOOLS_H
42 #endif // CASSINITOOLS_H
41
43
@@ -1,654 +1,669
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the QLop Software
2 -- This file is a part of the QLop Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "SocExplorerPlot.h"
22 #include "SocExplorerPlot.h"
23 #include <QSvgGenerator>
23 #include <QSvgGenerator>
24 #include <qcpdocumentobject.h>
24 #include <qcpdocumentobject.h>
25 #include <QPdfWriter>
25 #include <QPdfWriter>
26 #include <QPrinter>
26 #include <QPrinter>
27
27
28 SocExplorerPlot::SocExplorerPlot(QWidget *parent) :
28 SocExplorerPlot::SocExplorerPlot(QWidget *parent) :
29 QWidget(parent), mRubberBand(new QRubberBand(QRubberBand::Rectangle, this))
29 QWidget(parent), mRubberBand(new QRubberBand(QRubberBand::Rectangle, this))
30 {
30 {
31 this->m_plot = new QCustomPlotVect(this);
31 this->m_plot = new QCustomPlotVect(this);
32 this->m_plot->setInteractions(QCP::iRangeDrag | QCP::iSelectAxes |
32 this->m_plot->setInteractions(QCP::iRangeDrag | QCP::iSelectAxes |
33 QCP::iSelectLegend | QCP::iSelectPlottables);
33 QCP::iSelectLegend | QCP::iSelectPlottables);
34 this->m_plot->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical);
34 this->m_plot->axisRect()->setRangeDrag(Qt::Horizontal|Qt::Vertical);
35 this->m_plot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical);
35 this->m_plot->axisRect()->setRangeZoom(Qt::Horizontal|Qt::Vertical);
36 this->m_mainlayout = new QGridLayout(this);
36 this->m_mainlayout = new QGridLayout(this);
37 this->setLayout(this->m_mainlayout);
37 this->setLayout(this->m_mainlayout);
38 this->m_mainlayout->addWidget(this->m_plot);
38 this->m_mainlayout->addWidget(this->m_plot);
39 this->setMinimumSize(400,300);
39 this->setMinimumSize(400,300);
40 this->setFocusPolicy(Qt::WheelFocus);
40 this->setFocusPolicy(Qt::WheelFocus);
41 this->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents);
41 this->m_plot->setAttribute(Qt::WA_TransparentForMouseEvents);
42 this->ctrl_hold = false;
42 this->ctrl_hold = false;
43 this->shift_hold = false;
43 this->shift_hold = false;
44 this->mouse_hold = false;
44 this->mouse_hold = false;
45 this->m_plot->setNoAntialiasingOnDrag(true);
45 this->m_plot->setNoAntialiasingOnDrag(true);
46 this->show();
46 this->show();
47 this->m_plot->legend->setVisible(true);
47 this->m_plot->legend->setVisible(true);
48 }
48 }
49
49
50 SocExplorerPlot::~SocExplorerPlot()
50 SocExplorerPlot::~SocExplorerPlot()
51 {
51 {
52 delete mRubberBand;
52 delete mRubberBand;
53 }
53 }
54
54
55 void SocExplorerPlot::show()
55 void SocExplorerPlot::show()
56 {
56 {
57 QWidget::show();
57 QWidget::show();
58 }
58 }
59
59
60 void SocExplorerPlot::replot()
60 void SocExplorerPlot::replot()
61 {
61 {
62 this->m_plot->replot();
62 this->m_plot->replot();
63 }
63 }
64
64
65 void SocExplorerPlot::exportToSVG(const QString &fileName)
65 void SocExplorerPlot::exportToSVG(const QString &fileName)
66 {
66 {
67 QSvgGenerator printer;
67 QSvgGenerator printer;
68 printer.setFileName(fileName);
68 printer.setFileName(fileName);
69 QCPPainter qcpPainter;
69 QCPPainter qcpPainter;
70 qcpPainter.begin(&printer);
70 qcpPainter.begin(&printer);
71 m_plot->toPainter(&qcpPainter, m_plot->width(), m_plot->height());
71 m_plot->toPainter(&qcpPainter, m_plot->width(), m_plot->height());
72 qcpPainter.end();
72 qcpPainter.end();
73 }
73 }
74
74
75 void SocExplorerPlot::exportToPDF(const QString &fileName)
75 void SocExplorerPlot::exportToPDF(const QString &fileName)
76 {
76 {
77 QPrinter printer(QPrinter::HighResolution);
77 QPrinter printer(QPrinter::HighResolution);
78 printer.setOutputFormat(QPrinter::PdfFormat);
78 printer.setOutputFormat(QPrinter::PdfFormat);
79 printer.setOrientation(QPrinter::Landscape);
79 printer.setOrientation(QPrinter::Landscape);
80 printer.setOutputFileName(fileName);
80 printer.setOutputFileName(fileName);
81 printer.setFullPage(true);
81 printer.setFullPage(true);
82 QCPPainter qcpPainter;
82 QCPPainter qcpPainter;
83 qcpPainter.begin(&printer);
83 qcpPainter.begin(&printer);
84 m_plot->toPainter(&qcpPainter, printer.width(), printer.height());
84 m_plot->toPainter(&qcpPainter, printer.width(), printer.height());
85 qcpPainter.end();
85 qcpPainter.end();
86 }
86 }
87
87
88 void SocExplorerPlot::addAction(SocExplorerPlotActions *action)
88 void SocExplorerPlot::addAction(SocExplorerPlotActions *action)
89 {
89 {
90 this->m_actions.append(action);
90 this->m_actions.append(action);
91 QWidget::addAction((QAction*)action);
91 QWidget::addAction((QAction*)action);
92 }
92 }
93
93
94 QVector<QCPData> *SocExplorerPlot::getVisibleData(int graphIndex)
94 QVector<QCPData> *SocExplorerPlot::getVisibleData(int graphIndex)
95 {
95 {
96 QVector<QCPData> *visibleData=((QCPGraphVect*)m_plot->graph(graphIndex))->getVisibleData();
96 QVector<QCPData> *visibleData=((QCPGraphVect*)m_plot->graph(graphIndex))->getVisibleData();
97 return visibleData;
97 return visibleData;
98 }
98 }
99
99
100 void SocExplorerPlot::setTitle(QString title)
100 void SocExplorerPlot::setTitle(QString title)
101 {
101 {
102 Q_UNUSED(title)
102 Q_UNUSED(title)
103 //this->m_plot->setTitle(title);
103 //this->m_plot->setTitle(title);
104 /*!
104 /*!
105 @todo Function borcken fixe this!
105 @todo Function borcken fixe this!
106 */
106 */
107 this->m_Title = title;
107 emit titleChanged(title);
108 emit titleChanged(title);
108 this->repaint();
109 this->repaint();
109 }
110 }
110
111
112 const QString &SocExplorerPlot::title()
113 {
114 return m_Title;
115 }
116
111 void SocExplorerPlot::setXaxisLabel(QString label)
117 void SocExplorerPlot::setXaxisLabel(QString label)
112 {
118 {
113 this->m_plot->xAxis->setLabel(label);
119 this->m_plot->xAxis->setLabel(label);
114 this->repaint();
120 this->repaint();
115 }
121 }
116
122
117 void SocExplorerPlot::setXaxisLog()
123 void SocExplorerPlot::setXaxisLog()
118 {
124 {
119 this->m_plot->xAxis->setScaleType(QCPAxis::stLogarithmic);
125 this->m_plot->xAxis->setScaleType(QCPAxis::stLogarithmic);
120 }
126 }
121
127
122 void SocExplorerPlot::setYaxisLabel(QString label)
128 void SocExplorerPlot::setYaxisLabel(QString label)
123 {
129 {
124 this->m_plot->yAxis->setLabel(label);
130 this->m_plot->yAxis->setLabel(label);
125 this->repaint();
131 this->repaint();
126 }
132 }
127
133
128 void SocExplorerPlot::setYaxisLog()
134 void SocExplorerPlot::setYaxisLog()
129 {
135 {
130 this->m_plot->yAxis->setScaleType(QCPAxis::stLogarithmic);
136 this->m_plot->yAxis->setScaleType(QCPAxis::stLogarithmic);
131 }
137 }
132
138
133 void SocExplorerPlot::setXaxisRange(double lower, double upper)
139 void SocExplorerPlot::setXaxisRange(double lower, double upper)
134 {
140 {
135 this->m_plot->xAxis->setRange(lower,upper);
141 this->m_plot->xAxis->setRange(lower,upper);
136 }
142 }
137
143
138 void SocExplorerPlot::setYaxisRange(double lower, double upper)
144 void SocExplorerPlot::setYaxisRange(double lower, double upper)
139 {
145 {
140 this->m_plot->yAxis->setRange(lower,upper);
146 this->m_plot->yAxis->setRange(lower,upper);
141 }
147 }
142
148
143
149
144 void SocExplorerPlot::rescaleAxis()
150 void SocExplorerPlot::rescaleAxis()
145 {
151 {
146 this->m_plot->rescaleAxes();
152 this->m_plot->rescaleAxes();
147 this->m_plot->replot();
153 this->m_plot->replot();
148 }
154 }
149
155
150 void SocExplorerPlot::setLegendFont(QFont font)
156 void SocExplorerPlot::setLegendFont(QFont font)
151 {
157 {
152 this->m_plot->legend->setFont(font);
158 this->m_plot->legend->setFont(font);
153 this->repaint();
159 this->repaint();
154 }
160 }
155
161
156 void SocExplorerPlot::setLegendSelectedFont(QFont font)
162 void SocExplorerPlot::setLegendSelectedFont(QFont font)
157 {
163 {
158 this->m_plot->legend->setSelectedFont(font);
164 this->m_plot->legend->setSelectedFont(font);
159 this->repaint();
165 this->repaint();
160 }
166 }
161
167
162 void SocExplorerPlot::setAdaptativeSampling(int graphIndex, bool enable)
168 void SocExplorerPlot::setAdaptativeSampling(int graphIndex, bool enable)
163 {
169 {
164 this->m_plot->graph(graphIndex)->setAdaptiveSampling(enable);
170 this->m_plot->graph(graphIndex)->setAdaptiveSampling(enable);
165 }
171 }
166
172
167 void SocExplorerPlot::setUseFastVector(int graphIndex, bool enable)
173 void SocExplorerPlot::setUseFastVector(int graphIndex, bool enable)
168 {
174 {
169 // TODO deprecated
175 // TODO deprecated
170 // this->m_plot->graph(graphIndex)->setUseFastVectors(enable);
176 // this->m_plot->graph(graphIndex)->setUseFastVectors(enable);
171 }
177 }
172
178
173 int SocExplorerPlot::addGraph()
179 int SocExplorerPlot::addGraph()
174 {
180 {
175 this->m_plot->addGraph();
181 this->m_plot->addGraph();
176 return this->m_plot->graphCount() -1;
182 return this->m_plot->graphCount() -1;
177 }
183 }
178
184
179 bool SocExplorerPlot::removeGraph(int graphIndex)
185 bool SocExplorerPlot::removeGraph(int graphIndex)
180 {
186 {
181 return this->m_plot->removeGraph(graphIndex);
187 return this->m_plot->removeGraph(graphIndex);
182 }
188 }
183
189
184 int SocExplorerPlot::graphCount()
190 int SocExplorerPlot::graphCount()
185 {
191 {
186 return m_plot->graphCount();
192 return m_plot->graphCount();
187 }
193 }
188
194
189 void SocExplorerPlot::removeAllGraphs()
195 void SocExplorerPlot::removeAllGraphs()
190 {
196 {
191 int graphCount=this->m_plot->graphCount();
197 int graphCount=this->m_plot->graphCount();
192 for(int i=0;i<graphCount;i++)
198 for(int i=0;i<graphCount;i++)
193 {
199 {
194 this->m_plot->removeGraph(0);
200 this->m_plot->removeGraph(0);
195 }
201 }
196 }
202 }
197
203
198
204
199 void SocExplorerPlot::setGraphName(int graphIndex,QString name)
205 void SocExplorerPlot::setGraphName(int graphIndex,QString name)
200 {
206 {
201 if(graphIndex<this->m_plot->graphCount())
207 if(graphIndex<this->m_plot->graphCount())
202 {
208 {
203 this->m_plot->graph(graphIndex)->setName(name);
209 this->m_plot->graph(graphIndex)->setName(name);
210 }
211 }
212
213 const QString &SocExplorerPlot::graphName(int graphIndex)
214 {
215 if(graphIndex<this->m_plot->graphCount())
216 {
217 return this->m_plot->graph(graphIndex)->name();
204 }
218 }
219 return "";
205 }
220 }
206
221
207
222
208 void SocExplorerPlot::setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y)
223 void SocExplorerPlot::setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y)
209 {
224 {
210 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::Double))
225 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::Double))
211 {
226 {
212 QVector<double> _x(x.count()), _y(y.count());
227 QVector<double> _x(x.count()), _y(y.count());
213 for(int i=0;i<x.count();i++)
228 for(int i=0;i<x.count();i++)
214 {
229 {
215 /*_x[i] = x.at(i).value<double>();
230 /*_x[i] = x.at(i).value<double>();
216 _y[i] = y.at(i).value<double>();*/
231 _y[i] = y.at(i).value<double>();*/
217 _x[i] = x.at(i).toDouble();
232 _x[i] = x.at(i).toDouble();
218 _y[i] = y.at(i).toDouble();
233 _y[i] = y.at(i).toDouble();
219 }
234 }
220 this->m_plot->graph(graphIndex)->setData(_x,_y);
235 this->m_plot->graph(graphIndex)->setData(_x,_y);
221 }
236 }
222 else
237 else
223 {
238 {
224 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::DateTime))
239 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()) && (x.at(0).type()==QVariant::DateTime))
225 {
240 {
226 QVector<double> _x(x.count()), _y(y.count());
241 QVector<double> _x(x.count()), _y(y.count());
227 for(int i=0;i<x.count();i++)
242 for(int i=0;i<x.count();i++)
228 {
243 {
229 /*_x[i] = x.at(i).value<double>();
244 /*_x[i] = x.at(i).value<double>();
230 _y[i] = y.at(i).value<double>();*/
245 _y[i] = y.at(i).value<double>();*/
231 _x[i] = x.at(i).toDateTime().toMSecsSinceEpoch();
246 _x[i] = x.at(i).toDateTime().toMSecsSinceEpoch();
232 _y[i] = y.at(i).toDouble();
247 _y[i] = y.at(i).toDouble();
233 }
248 }
234 this->m_plot->graph(graphIndex)->setData(_x,_y);
249 this->m_plot->graph(graphIndex)->setData(_x,_y);
235 this->m_plot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
250 this->m_plot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
236 this->m_plot->xAxis->setDateTimeFormat("hh:mm:ss.zzz");
251 this->m_plot->xAxis->setDateTimeFormat("hh:mm:ss.zzz");
237
252
238 }
253 }
239 }
254 }
240 this->m_plot->replot();
255 this->m_plot->replot();
241 }
256 }
242
257
243 void SocExplorerPlot::setGraphData(int graphIndex, QCPDataMap *data, bool copy, bool replot)
258 void SocExplorerPlot::setGraphData(int graphIndex, QCPDataMap *data, bool copy, bool replot)
244 {
259 {
245 if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double))
260 if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double))
246 {
261 {
247 this->m_plot->graph(graphIndex)->setData(data,copy);
262 this->m_plot->graph(graphIndex)->setData(data,copy);
248 }
263 }
249 if(replot)
264 if(replot)
250 this->m_plot->replot();
265 this->m_plot->replot();
251 }
266 }
252
267
253 void SocExplorerPlot::setGraphData(int graphIndex,QVector<QCPData> *data, bool replot)
268 void SocExplorerPlot::setGraphData(int graphIndex,QVector<QCPData> *data, bool replot)
254 {
269 {
255 if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double))
270 if((graphIndex<this->m_plot->graphCount()))// && (x.at(0).type()==QVariant::Double))
256 {
271 {
257 ((QCPGraphVect*)this->m_plot->graph(graphIndex))->setData(data);
272 ((QCPGraphVect*)this->m_plot->graph(graphIndex))->setData(data);
258 }
273 }
259 if(replot)
274 if(replot)
260 this->m_plot->replot();
275 this->m_plot->replot();
261 }
276 }
262
277
263 void SocExplorerPlot::addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y)
278 void SocExplorerPlot::addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y)
264 {
279 {
265 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double))
280 if((graphIndex<this->m_plot->graphCount()) && (x.count()==y.count()))// && (x.at(0).type()==QVariant::Double))
266 {
281 {
267 QVector<double> _x(x.count()), _y(y.count());
282 QVector<double> _x(x.count()), _y(y.count());
268 for(int i=0;i<x.count();i++)
283 for(int i=0;i<x.count();i++)
269 {
284 {
270 /*_x[i] = x.at(i).value<double>();
285 /*_x[i] = x.at(i).value<double>();
271 _y[i] = y.at(i).value<double>();*/
286 _y[i] = y.at(i).value<double>();*/
272 _x[i] = x.at(i).toDouble();
287 _x[i] = x.at(i).toDouble();
273 _y[i] = y.at(i).toDouble();
288 _y[i] = y.at(i).toDouble();
274 }
289 }
275 this->m_plot->graph(graphIndex)->addData(_x,_y);
290 this->m_plot->graph(graphIndex)->addData(_x,_y);
276 }
291 }
277 this->m_plot->replot();
292 this->m_plot->replot();
278 }
293 }
279
294
280 void SocExplorerPlot::addGraphData(int graphIndex, QVariant x, QVariant y)
295 void SocExplorerPlot::addGraphData(int graphIndex, QVariant x, QVariant y)
281 {
296 {
282 if(graphIndex<this->m_plot->graphCount())// && (x.at(0).type()==QVariant::Double))
297 if(graphIndex<this->m_plot->graphCount())// && (x.at(0).type()==QVariant::Double))
283 {
298 {
284 this->m_plot->graph(graphIndex)->addData(x.toDouble(),y.toDouble());
299 this->m_plot->graph(graphIndex)->addData(x.toDouble(),y.toDouble());
285 }
300 }
286 this->m_plot->replot();
301 this->m_plot->replot();
287 }
302 }
288
303
289 void SocExplorerPlot::setGraphPen(int graphIndex,QPen pen)
304 void SocExplorerPlot::setGraphPen(int graphIndex,QPen pen)
290 {
305 {
291 if(graphIndex<this->m_plot->graphCount())
306 if(graphIndex<this->m_plot->graphCount())
292 {
307 {
293 this->m_plot->graph(graphIndex)->setPen(pen);
308 this->m_plot->graph(graphIndex)->setPen(pen);
294 }
309 }
295 }
310 }
296
311
297 QPen SocExplorerPlot::getGraphPen(int graphIndex)
312 QPen SocExplorerPlot::getGraphPen(int graphIndex)
298 {
313 {
299 if(graphIndex<this->m_plot->graphCount())
314 if(graphIndex<this->m_plot->graphCount())
300 {
315 {
301 return this->m_plot->graph(graphIndex)->pen();
316 return this->m_plot->graph(graphIndex)->pen();
302 }
317 }
303 return this->m_plot->graph()->pen();
318 return this->m_plot->graph()->pen();
304 }
319 }
305
320
306
321
307
322
308 void SocExplorerPlot::setGraphLineStyle(int graphIndex,QString lineStyle)
323 void SocExplorerPlot::setGraphLineStyle(int graphIndex,QString lineStyle)
309 {
324 {
310 if(graphIndex<this->m_plot->graphCount())
325 if(graphIndex<this->m_plot->graphCount())
311 {
326 {
312 if(!lineStyle.compare("none"))
327 if(!lineStyle.compare("none"))
313 {
328 {
314 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsNone);
329 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsNone);
315 return;
330 return;
316 }
331 }
317 if(!lineStyle.compare("line"))
332 if(!lineStyle.compare("line"))
318 {
333 {
319 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsLine);
334 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsLine);
320 return;
335 return;
321 }
336 }
322 if(!lineStyle.compare("stepleft"))
337 if(!lineStyle.compare("stepleft"))
323 {
338 {
324 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepLeft);
339 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepLeft);
325 return;
340 return;
326 }
341 }
327 if(!lineStyle.compare("stepright"))
342 if(!lineStyle.compare("stepright"))
328 {
343 {
329 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepRight);
344 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepRight);
330 return;
345 return;
331 }
346 }
332 if(!lineStyle.compare("stepcenter"))
347 if(!lineStyle.compare("stepcenter"))
333 {
348 {
334 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepCenter);
349 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsStepCenter);
335 return;
350 return;
336 }
351 }
337 if(!lineStyle.compare("impulse"))
352 if(!lineStyle.compare("impulse"))
338 {
353 {
339 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsImpulse);
354 this->m_plot->graph(graphIndex)->setLineStyle(QCPGraph::lsImpulse);
340 return;
355 return;
341 }
356 }
342
357
343
358
344 }
359 }
345 }
360 }
346
361
347 void SocExplorerPlot::setGraphScatterStyle(int graphIndex,QString scatterStyle)
362 void SocExplorerPlot::setGraphScatterStyle(int graphIndex,QString scatterStyle)
348 {
363 {
349 if(graphIndex<this->m_plot->graphCount())
364 if(graphIndex<this->m_plot->graphCount())
350 {
365 {
351 if(!scatterStyle.compare("none"))
366 if(!scatterStyle.compare("none"))
352 {
367 {
353 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssNone);
368 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssNone);
354 return;
369 return;
355 }
370 }
356 if(!scatterStyle.compare("dot"))
371 if(!scatterStyle.compare("dot"))
357 {
372 {
358 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDot);
373 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDot);
359 return;
374 return;
360 }
375 }
361 if(!scatterStyle.compare("cross"))
376 if(!scatterStyle.compare("cross"))
362 {
377 {
363 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCross);
378 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCross);
364 return;
379 return;
365 }
380 }
366 if(!scatterStyle.compare("plus"))
381 if(!scatterStyle.compare("plus"))
367 {
382 {
368 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlus);
383 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlus);
369 return;
384 return;
370 }
385 }
371 if(!scatterStyle.compare("circle"))
386 if(!scatterStyle.compare("circle"))
372 {
387 {
373 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCircle);
388 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCircle);
374 return;
389 return;
375 }
390 }
376 if(!scatterStyle.compare("disc"))
391 if(!scatterStyle.compare("disc"))
377 {
392 {
378 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDisc);
393 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDisc);
379 return;
394 return;
380 }
395 }
381 if(!scatterStyle.compare("square"))
396 if(!scatterStyle.compare("square"))
382 {
397 {
383 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssSquare);
398 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssSquare);
384 return;
399 return;
385 }
400 }
386 if(!scatterStyle.compare("diamond"))
401 if(!scatterStyle.compare("diamond"))
387 {
402 {
388 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDiamond);
403 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssDiamond);
389 return;
404 return;
390 }
405 }
391 if(!scatterStyle.compare("star"))
406 if(!scatterStyle.compare("star"))
392 {
407 {
393 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssStar);
408 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssStar);
394 return;
409 return;
395 }
410 }
396 if(!scatterStyle.compare("triangle"))
411 if(!scatterStyle.compare("triangle"))
397 {
412 {
398 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangle);
413 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangle);
399 return;
414 return;
400 }
415 }
401 if(!scatterStyle.compare("invertedtriangle"))
416 if(!scatterStyle.compare("invertedtriangle"))
402 {
417 {
403 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangleInverted);
418 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssTriangleInverted);
404 return;
419 return;
405 }
420 }
406 if(!scatterStyle.compare("crosssquare"))
421 if(!scatterStyle.compare("crosssquare"))
407 {
422 {
408 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossSquare);
423 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossSquare);
409 return;
424 return;
410 }
425 }
411 if(!scatterStyle.compare("plussquare"))
426 if(!scatterStyle.compare("plussquare"))
412 {
427 {
413 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusSquare);
428 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusSquare);
414 return;
429 return;
415 }
430 }
416 if(!scatterStyle.compare("crosscircle"))
431 if(!scatterStyle.compare("crosscircle"))
417 {
432 {
418 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossCircle);
433 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssCrossCircle);
419 return;
434 return;
420 }
435 }
421 if(!scatterStyle.compare("pluscircle"))
436 if(!scatterStyle.compare("pluscircle"))
422 {
437 {
423 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusCircle);
438 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPlusCircle);
424 return;
439 return;
425 }
440 }
426 if(!scatterStyle.compare("peace"))
441 if(!scatterStyle.compare("peace"))
427 {
442 {
428 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPeace);
443 this->m_plot->graph(graphIndex)->setScatterStyle(QCPScatterStyle::ssPeace);
429 return;
444 return;
430 }
445 }
431
446
432 }
447 }
433 }
448 }
434
449
435 void SocExplorerPlot::setXaxisTickLabelType(QCPAxis::LabelType type)
450 void SocExplorerPlot::setXaxisTickLabelType(QCPAxis::LabelType type)
436 {
451 {
437 this->m_plot->xAxis->setTickLabelType(type);
452 this->m_plot->xAxis->setTickLabelType(type);
438 }
453 }
439
454
440 void SocExplorerPlot::setXaxisDateTimeFormat(const QString &format)
455 void SocExplorerPlot::setXaxisDateTimeFormat(const QString &format)
441 {
456 {
442 this->m_plot->xAxis->setDateTimeFormat(format);
457 this->m_plot->xAxis->setDateTimeFormat(format);
443 }
458 }
444
459
445
460
446
461
447
462
448
463
449 void SocExplorerPlot::keyPressEvent(QKeyEvent * event)
464 void SocExplorerPlot::keyPressEvent(QKeyEvent * event)
450 {
465 {
451 switch(event->key())
466 switch(event->key())
452 {
467 {
453 case Qt::Key_Control:
468 case Qt::Key_Control:
454 this->ctrl_hold = true;
469 this->ctrl_hold = true;
455 setCursor(Qt::CrossCursor);
470 setCursor(Qt::CrossCursor);
456 break;
471 break;
457 case Qt::Key_Shift:
472 case Qt::Key_Shift:
458 this->shift_hold = true;
473 this->shift_hold = true;
459 break;
474 break;
460 case Qt::Key_M:
475 case Qt::Key_M:
461 this->rescaleAxis();
476 this->rescaleAxis();
462 break;
477 break;
463 case Qt::Key_Left:
478 case Qt::Key_Left:
464 if(!ctrl_hold)
479 if(!ctrl_hold)
465 {
480 {
466 move(-0.1,Qt::Horizontal);
481 move(-0.1,Qt::Horizontal);
467 }
482 }
468 else
483 else
469 {
484 {
470 zoom(2,this->width()/2,Qt::Horizontal);
485 zoom(2,this->width()/2,Qt::Horizontal);
471 }
486 }
472 break;
487 break;
473 case Qt::Key_Right:
488 case Qt::Key_Right:
474 if(!ctrl_hold)
489 if(!ctrl_hold)
475 {
490 {
476 move(0.1,Qt::Horizontal);
491 move(0.1,Qt::Horizontal);
477 }
492 }
478 else
493 else
479 {
494 {
480 zoom(0.5,this->width()/2,Qt::Horizontal);
495 zoom(0.5,this->width()/2,Qt::Horizontal);
481 }
496 }
482 break;
497 break;
483 case Qt::Key_Up:
498 case Qt::Key_Up:
484 if(!ctrl_hold)
499 if(!ctrl_hold)
485 {
500 {
486 move(0.1,Qt::Vertical);
501 move(0.1,Qt::Vertical);
487 }
502 }
488 else
503 else
489 {
504 {
490 zoom(0.5,this->height()/2,Qt::Vertical);
505 zoom(0.5,this->height()/2,Qt::Vertical);
491 }
506 }
492 break;
507 break;
493 case Qt::Key_Down:
508 case Qt::Key_Down:
494 if(!ctrl_hold)
509 if(!ctrl_hold)
495 {
510 {
496 move(-0.1,Qt::Vertical);
511 move(-0.1,Qt::Vertical);
497 }
512 }
498 else
513 else
499 {
514 {
500 zoom(2,this->height()/2,Qt::Vertical);
515 zoom(2,this->height()/2,Qt::Vertical);
501 }
516 }
502 break;
517 break;
503 default:
518 default:
504 QWidget::keyPressEvent(event);
519 QWidget::keyPressEvent(event);
505 break;
520 break;
506 }
521 }
507 }
522 }
508
523
509 void SocExplorerPlot::keyReleaseEvent(QKeyEvent * event)
524 void SocExplorerPlot::keyReleaseEvent(QKeyEvent * event)
510 {
525 {
511 switch(event->key())
526 switch(event->key())
512 {
527 {
513 case Qt::Key_Control:
528 case Qt::Key_Control:
514 event->accept();
529 event->accept();
515 this->ctrl_hold = false;
530 this->ctrl_hold = false;
516 break;
531 break;
517 case Qt::Key_Shift:
532 case Qt::Key_Shift:
518 event->accept();
533 event->accept();
519 this->shift_hold = false;
534 this->shift_hold = false;
520 break;
535 break;
521 default:
536 default:
522 QWidget::keyReleaseEvent(event);
537 QWidget::keyReleaseEvent(event);
523 break;
538 break;
524 }
539 }
525 setCursor(Qt::ArrowCursor);
540 setCursor(Qt::ArrowCursor);
526 }
541 }
527
542
528 void SocExplorerPlot::wheelEvent(QWheelEvent * event)
543 void SocExplorerPlot::wheelEvent(QWheelEvent * event)
529 {
544 {
530 double factor;
545 double factor;
531 double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually
546 double wheelSteps = event->delta()/120.0; // a single step delta is +/-120 usually
532 if(ctrl_hold)
547 if(ctrl_hold)
533 {
548 {
534 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
549 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
535 {
550 {
536 setCursor(Qt::SizeVerCursor);
551 setCursor(Qt::SizeVerCursor);
537 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps);
552 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Vertical), wheelSteps);
538 zoom(factor,event->pos().y(),Qt::Vertical);
553 zoom(factor,event->pos().y(),Qt::Vertical);
539 }
554 }
540 QWidget::wheelEvent(event);
555 QWidget::wheelEvent(event);
541 return;
556 return;
542 }
557 }
543 if(shift_hold)
558 if(shift_hold)
544 {
559 {
545 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
560 if (event->orientation()==Qt::Vertical)//mRangeZoom.testFlag(Qt::Vertical))
546 {
561 {
547 setCursor(Qt::SizeHorCursor);
562 setCursor(Qt::SizeHorCursor);
548 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps);
563 factor = pow(this->m_plot->axisRect()->rangeZoomFactor(Qt::Horizontal), wheelSteps);
549 zoom(factor,event->pos().x(),Qt::Horizontal);
564 zoom(factor,event->pos().x(),Qt::Horizontal);
550 }
565 }
551 QWidget::wheelEvent(event);
566 QWidget::wheelEvent(event);
552 return;
567 return;
553 }
568 }
554 move(wheelSteps/10,Qt::Horizontal);
569 move(wheelSteps/10,Qt::Horizontal);
555 QWidget::wheelEvent(event);
570 QWidget::wheelEvent(event);
556 }
571 }
557
572
558
573
559
574
560
575
561 void SocExplorerPlot::mousePressEvent(QMouseEvent *event)
576 void SocExplorerPlot::mousePressEvent(QMouseEvent *event)
562 {
577 {
563 if(event->button()==Qt::LeftButton)
578 if(event->button()==Qt::LeftButton)
564 {
579 {
565 if(ctrl_hold)
580 if(ctrl_hold)
566 {
581 {
567 setCursor(Qt::CrossCursor);
582 setCursor(Qt::CrossCursor);
568 mOrigin = event->pos();
583 mOrigin = event->pos();
569 mRubberBand->setGeometry(QRect(mOrigin, QSize()));
584 mRubberBand->setGeometry(QRect(mOrigin, QSize()));
570 mRubberBand->show();
585 mRubberBand->show();
571 }
586 }
572 else
587 else
573 {
588 {
574 setCursor(Qt::ClosedHandCursor);
589 setCursor(Qt::ClosedHandCursor);
575 mDragStart = event->pos();
590 mDragStart = event->pos();
576 this->mouse_hold = true;
591 this->mouse_hold = true;
577 DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range();
592 DragStartHorzRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal)->range();
578 DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range();
593 DragStartVertRange = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical)->range();
579 }
594 }
580 }
595 }
581 QWidget::mousePressEvent(event);
596 QWidget::mousePressEvent(event);
582 }
597 }
583
598
584 void SocExplorerPlot::mouseReleaseEvent(QMouseEvent *event)
599 void SocExplorerPlot::mouseReleaseEvent(QMouseEvent *event)
585 {
600 {
586 if(event->button()==Qt::LeftButton)
601 if(event->button()==Qt::LeftButton)
587 {
602 {
588 this->mouse_hold = false;
603 this->mouse_hold = false;
589 }
604 }
590 if (mRubberBand->isVisible())
605 if (mRubberBand->isVisible())
591 {
606 {
592 const QRect & zoomRect = mRubberBand->geometry();
607 const QRect & zoomRect = mRubberBand->geometry();
593 int xp1, yp1, xp2, yp2;
608 int xp1, yp1, xp2, yp2;
594 zoomRect.getCoords(&xp1, &yp1, &xp2, &yp2);
609 zoomRect.getCoords(&xp1, &yp1, &xp2, &yp2);
595 double x1 = this->m_plot->xAxis->pixelToCoord(xp1);
610 double x1 = this->m_plot->xAxis->pixelToCoord(xp1);
596 double x2 = this->m_plot->xAxis->pixelToCoord(xp2);
611 double x2 = this->m_plot->xAxis->pixelToCoord(xp2);
597 double y1 = this->m_plot->yAxis->pixelToCoord(yp1);
612 double y1 = this->m_plot->yAxis->pixelToCoord(yp1);
598 double y2 = this->m_plot->yAxis->pixelToCoord(yp2);
613 double y2 = this->m_plot->yAxis->pixelToCoord(yp2);
599
614
600 this->m_plot->xAxis->setRange(x1, x2);
615 this->m_plot->xAxis->setRange(x1, x2);
601 this->m_plot->yAxis->setRange(y1, y2);
616 this->m_plot->yAxis->setRange(y1, y2);
602
617
603 mRubberBand->hide();
618 mRubberBand->hide();
604 this->m_plot->replot();
619 this->m_plot->replot();
605 }
620 }
606 setCursor(Qt::ArrowCursor);
621 setCursor(Qt::ArrowCursor);
607 QWidget::mouseReleaseEvent(event);
622 QWidget::mouseReleaseEvent(event);
608 }
623 }
609
624
610 void SocExplorerPlot::zoom(double factor, int center, Qt::Orientation orientation)
625 void SocExplorerPlot::zoom(double factor, int center, Qt::Orientation orientation)
611 {
626 {
612 QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(orientation);
627 QCPAxis* axis = this->m_plot->axisRect()->rangeZoomAxis(orientation);
613 axis->scaleRange(factor, axis->pixelToCoord(center));
628 axis->scaleRange(factor, axis->pixelToCoord(center));
614 this->m_plot->replot();
629 this->m_plot->replot();
615 }
630 }
616
631
617 void SocExplorerPlot::move(double factor, Qt::Orientation orientation)
632 void SocExplorerPlot::move(double factor, Qt::Orientation orientation)
618 {
633 {
619 QCPAxis* axis = this->m_plot->axisRect()->rangeDragAxis(orientation);
634 QCPAxis* axis = this->m_plot->axisRect()->rangeDragAxis(orientation);
620 double rg = (axis->range().upper - axis->range().lower)*(factor);
635 double rg = (axis->range().upper - axis->range().lower)*(factor);
621 axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg));
636 axis->setRange(axis->range().lower+(rg), axis->range().upper+(rg));
622 this->m_plot->replot();
637 this->m_plot->replot();
623 }
638 }
624
639
625
640
626 void SocExplorerPlot::mouseMoveEvent(QMouseEvent *event)
641 void SocExplorerPlot::mouseMoveEvent(QMouseEvent *event)
627 {
642 {
628 if(mouse_hold)
643 if(mouse_hold)
629 {
644 {
630 QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal);
645 QCPAxis* Haxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Horizontal);
631 QCPAxis* Vaxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical);
646 QCPAxis* Vaxis = this->m_plot->axisRect()->rangeDragAxis(Qt::Vertical);
632 double diff = Haxis->pixelToCoord(mDragStart.x()) - Haxis->pixelToCoord(event->pos().x());
647 double diff = Haxis->pixelToCoord(mDragStart.x()) - Haxis->pixelToCoord(event->pos().x());
633 Haxis->setRange(DragStartHorzRange.lower+diff, DragStartHorzRange.upper+diff);
648 Haxis->setRange(DragStartHorzRange.lower+diff, DragStartHorzRange.upper+diff);
634 diff = Vaxis->pixelToCoord(mDragStart.y()) - Vaxis->pixelToCoord(event->pos().y());
649 diff = Vaxis->pixelToCoord(mDragStart.y()) - Vaxis->pixelToCoord(event->pos().y());
635 Vaxis->setRange(DragStartVertRange.lower+diff, DragStartVertRange.upper+diff);
650 Vaxis->setRange(DragStartVertRange.lower+diff, DragStartVertRange.upper+diff);
636 this->m_plot->replot();
651 this->m_plot->replot();
637 }
652 }
638 if (mRubberBand->isVisible())
653 if (mRubberBand->isVisible())
639 {
654 {
640 mRubberBand->setGeometry(QRect(mOrigin, event->pos()).normalized());
655 mRubberBand->setGeometry(QRect(mOrigin, event->pos()).normalized());
641 }
656 }
642 QWidget::mouseMoveEvent(event);
657 QWidget::mouseMoveEvent(event);
643 }
658 }
644
659
645
660
646
661
647
662
648
663
649
664
650
665
651
666
652
667
653
668
654
669
@@ -1,131 +1,134
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the QLop Software
2 -- This file is a part of the QLop Software
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@member.fsf.org
20 -- Mail : alexis.jeandet@member.fsf.org
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #ifndef SOCEXPLORERPLOT_H
22 #ifndef SOCEXPLORERPLOT_H
23 #define SOCEXPLORERPLOT_H
23 #define SOCEXPLORERPLOT_H
24
24
25 #include <QWidget>
25 #include <QWidget>
26 #include <QGridLayout>
26 #include <QGridLayout>
27 #include <qcustomplot.h>
27 #include <qcustomplot.h>
28 #include <qcustomplotvect.h>
28 #include <qcustomplotvect.h>
29 #include <QRubberBand>
29 #include <QRubberBand>
30 #include <QPoint>
30 #include <QPoint>
31
31
32 class SocExplorerPlotActions : public QAction
32 class SocExplorerPlotActions : public QAction
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35 public:
35 public:
36 SocExplorerPlotActions(const QString &text,int PID,QObject* parent=0)
36 SocExplorerPlotActions(const QString &text,int PID,QObject* parent=0)
37 :QAction(text,parent)
37 :QAction(text,parent)
38 {
38 {
39 setPID(PID);
39 setPID(PID);
40 connect(this,SIGNAL(triggered()),this,SLOT(trigger()));
40 connect(this,SIGNAL(triggered()),this,SLOT(trigger()));
41 }
41 }
42 SocExplorerPlotActions(const QIcon &icon, const QString &text,int PID, QObject* parent)
42 SocExplorerPlotActions(const QIcon &icon, const QString &text,int PID, QObject* parent)
43 :QAction(icon,text,parent)
43 :QAction(icon,text,parent)
44 {
44 {
45 setPID(PID);
45 setPID(PID);
46 connect(this,SIGNAL(triggered()),this,SLOT(trigger()));
46 connect(this,SIGNAL(triggered()),this,SLOT(trigger()));
47 }
47 }
48 ~SocExplorerPlotActions(){}
48 ~SocExplorerPlotActions(){}
49 void setPID(int PID){this->m_PID=PID;}
49 void setPID(int PID){this->m_PID=PID;}
50 int PID(){return m_PID;}
50 int PID(){return m_PID;}
51 private slots:
51 private slots:
52 void trigger(){emit triggered(m_PID);}
52 void trigger(){emit triggered(m_PID);}
53 signals:
53 signals:
54 void triggered(int PID);
54 void triggered(int PID);
55 private:
55 private:
56 int m_PID;
56 int m_PID;
57 };
57 };
58
58
59 class SocExplorerPlot : public QWidget
59 class SocExplorerPlot : public QWidget
60 {
60 {
61 Q_OBJECT
61 Q_OBJECT
62 public:
62 public:
63 explicit SocExplorerPlot(QWidget *parent = 0);
63 explicit SocExplorerPlot(QWidget *parent = 0);
64 ~SocExplorerPlot();
64 ~SocExplorerPlot();
65 void setTitle(QString title);
65 void setTitle(QString title);
66 const QString& title();
66 void setXaxisLabel(QString label);
67 void setXaxisLabel(QString label);
67 void setXaxisLog();
68 void setXaxisLog();
68 void setXaxisRange(double lower, double upper);
69 void setXaxisRange(double lower, double upper);
69 void setYaxisLabel(QString label);
70 void setYaxisLabel(QString label);
70 void setYaxisLog();
71 void setYaxisLog();
71 void setYaxisRange(double lower, double upper);
72 void setYaxisRange(double lower, double upper);
72 void rescaleAxis();
73 void rescaleAxis();
73 void setLegendFont(QFont font);
74 void setLegendFont(QFont font);
74 void setLegendSelectedFont(QFont font);
75 void setLegendSelectedFont(QFont font);
75 void setAdaptativeSampling(int graphIndex,bool enable);
76 void setAdaptativeSampling(int graphIndex,bool enable);
76 void setUseFastVector(int graphIndex,bool enable);
77 void setUseFastVector(int graphIndex,bool enable);
77 int addGraph();
78 int addGraph();
78 bool removeGraph(int graphIndex);
79 bool removeGraph(int graphIndex);
79 int graphCount();
80 int graphCount();
80 void removeAllGraphs();
81 void removeAllGraphs();
81 void setGraphName(int graphIndex,QString name);
82 void setGraphName(int graphIndex,QString name);
83 const QString& graphName(int graphIndex);
82 void setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y);
84 void setGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y);
83 void setGraphData(int graphIndex, QCPDataMap* data,bool copy = true,bool replot=true);
85 void setGraphData(int graphIndex, QCPDataMap* data,bool copy = true,bool replot=true);
84 void setGraphData(int graphIndex, QVector<QCPData> *data, bool replot);
86 void setGraphData(int graphIndex, QVector<QCPData> *data, bool replot);
85 void addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y);
87 void addGraphData(int graphIndex, QList<QVariant> x, QList<QVariant> y);
86 void addGraphData(int graphIndex, QVariant x, QVariant y);
88 void addGraphData(int graphIndex, QVariant x, QVariant y);
87 void setGraphPen(int graphIndex,QPen pen);
89 void setGraphPen(int graphIndex,QPen pen);
88 QPen getGraphPen(int graphIndex);
90 QPen getGraphPen(int graphIndex);
89 void setGraphLineStyle(int graphIndex,QString lineStyle);
91 void setGraphLineStyle(int graphIndex,QString lineStyle);
90 void setGraphScatterStyle(int graphIndex,QString scatterStyle);
92 void setGraphScatterStyle(int graphIndex,QString scatterStyle);
91 void setXaxisTickLabelType(QCPAxis::LabelType type);
93 void setXaxisTickLabelType(QCPAxis::LabelType type);
92 void setXaxisDateTimeFormat(const QString &format);
94 void setXaxisDateTimeFormat(const QString &format);
93 void show();
95 void show();
94 void replot();
96 void replot();
95 void exportToSVG(const QString& fileName);
97 void exportToSVG(const QString& fileName);
96 void exportToPDF(const QString& fileName);
98 void exportToPDF(const QString& fileName);
97 void addAction(SocExplorerPlotActions* action);
99 void addAction(SocExplorerPlotActions* action);
98 int PID(){return m_PID;}
100 int PID(){return m_PID;}
99 void setPID(int PID){m_PID = PID;}
101 void setPID(int PID){m_PID = PID;}
100 QVector<QCPData>* getVisibleData(int graphIndex);
102 QVector<QCPData>* getVisibleData(int graphIndex);
101 signals:
103 signals:
102 void titleChanged(const QString& newTitle);
104 void titleChanged(const QString& newTitle);
103 public slots:
105 public slots:
104
106
105 protected:
107 protected:
106 void keyPressEvent(QKeyEvent *);
108 void keyPressEvent(QKeyEvent *);
107 void keyReleaseEvent(QKeyEvent *);
109 void keyReleaseEvent(QKeyEvent *);
108 void wheelEvent(QWheelEvent *);
110 void wheelEvent(QWheelEvent *);
109 void mousePressEvent(QMouseEvent *);
111 void mousePressEvent(QMouseEvent *);
110 void mouseMoveEvent(QMouseEvent *);
112 void mouseMoveEvent(QMouseEvent *);
111 void mouseReleaseEvent(QMouseEvent *);
113 void mouseReleaseEvent(QMouseEvent *);
112
114
113 private:
115 private:
114 void zoom(double factor, int center, Qt::Orientation orientation);
116 void zoom(double factor, int center, Qt::Orientation orientation);
115 void move(double factor, Qt::Orientation orientation);
117 void move(double factor, Qt::Orientation orientation);
116 QCustomPlotVect* m_plot;
118 QCustomPlotVect* m_plot;
117 QGridLayout* m_mainlayout;
119 QGridLayout* m_mainlayout;
118 bool ctrl_hold;
120 bool ctrl_hold;
119 bool shift_hold;
121 bool shift_hold;
120 bool mouse_hold;
122 bool mouse_hold;
121 QCPRange DragStartHorzRange;
123 QCPRange DragStartHorzRange;
122 QCPRange DragStartVertRange;
124 QCPRange DragStartVertRange;
123 QPoint mDragStart;
125 QPoint mDragStart;
124 bool mZoomMode;
126 bool mZoomMode;
125 QRubberBand * mRubberBand;
127 QRubberBand * mRubberBand;
126 QPoint mOrigin;
128 QPoint mOrigin;
127 QList<SocExplorerPlotActions*> m_actions;
129 QList<SocExplorerPlotActions*> m_actions;
130 QString m_Title;
128 int m_PID;
131 int m_PID;
129 };
132 };
130
133
131 #endif // SOCEXPLORERPLOT_H
134 #endif // SOCEXPLORERPLOT_H
General Comments 0
You need to be logged in to leave comments. Login now