Changeset 15 in flair-src for trunk/tools/FlairGCS
- Timestamp:
- Apr 8, 2016, 3:40:57 PM (9 years ago)
- Location:
- trunk/tools/FlairGCS/src
- Files:
-
- 63 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/FlairGCS/src/CheckBox.cpp
r10 r15 8 8 #include <QFormLayout> 9 9 10 CheckBox::CheckBox(Layout * parent,int row, int col,QString name,bool value): FormLayout(parent,row,col,name,"CheckBox")11 {12 13 10 CheckBox::CheckBox(Layout *parent, int row, int col, QString name, bool value) 11 : FormLayout(parent, row, col, name, "CheckBox") { 12 checkbox = new QCheckBox(); 13 checkbox->setChecked(value); 14 14 15 checkbox_value=value;15 checkbox_value = value; 16 16 17 object_layout->addRow(name,checkbox);17 object_layout->addRow(name, checkbox); 18 18 19 connect(checkbox,SIGNAL(toggled(bool)),this, SLOT(valuechanged(bool)));19 connect(checkbox, SIGNAL(toggled(bool)), this, SLOT(valuechanged(bool))); 20 20 21 if(checkbox_value==true) 22 { 23 SetValue("1"); 24 } 25 else 26 { 27 SetValue("0"); 28 } 21 if (checkbox_value == true) { 22 SetValue("1"); 23 } else { 24 SetValue("0"); 25 } 29 26 } 30 27 31 CheckBox::~CheckBox() 32 { 33 delete checkbox; 28 CheckBox::~CheckBox() { delete checkbox; } 29 30 void CheckBox::SetUptodate(void) { 31 ui_to_var(); 32 ui_to_xml(); 33 visible_widget->setPalette(black_pal); 34 34 } 35 35 36 void CheckBox::SetUptodate(void) 37 { 38 ui_to_var(); 39 ui_to_xml(); 40 visible_widget->setPalette(black_pal); 36 void CheckBox::ui_to_var(void) { checkbox_value = checkbox->isChecked(); } 37 38 void CheckBox::ui_to_xml(void) { 39 if (checkbox->isChecked() == true) { 40 SetValue("1"); 41 } else { 42 SetValue("0"); 43 } 41 44 } 42 45 43 void CheckBox::ui_to_var(void) 44 { 45 checkbox_value=checkbox->isChecked(); 46 void CheckBox::Reset(void) { checkbox->setChecked(checkbox_value); } 47 48 void CheckBox::LoadEvent(QDomElement dom) { 49 if (checkbox->isEnabled() == true) { 50 if (dom.attribute("value") == QString("1")) { 51 checkbox->setChecked(true); 52 } else { 53 checkbox->setChecked(false); 54 } 55 } 46 56 } 47 57 48 void CheckBox::ui_to_xml(void) 49 { 50 if(checkbox->isChecked()==true) 51 { 52 SetValue("1"); 53 } 54 else 55 { 56 SetValue("0"); 57 } 58 void CheckBox::valuechanged(bool value) { 59 if (value != checkbox_value) { 60 visible_widget->setPalette(red_pal); 61 } else { 62 visible_widget->setPalette(black_pal); 63 } 58 64 } 59 60 void CheckBox::Reset(void)61 {62 checkbox->setChecked(checkbox_value);63 }64 65 void CheckBox::LoadEvent(QDomElement dom)66 {67 if(checkbox->isEnabled()==true)68 {69 if(dom.attribute("value")==QString("1"))70 {71 checkbox->setChecked(true);72 }73 else74 {75 checkbox->setChecked(false);76 }77 }78 }79 80 void CheckBox::valuechanged(bool value)81 {82 if(value!=checkbox_value)83 {84 visible_widget->setPalette(red_pal);85 }86 else87 {88 visible_widget->setPalette(black_pal);89 }90 } -
trunk/tools/FlairGCS/src/CheckBox.h
r10 r15 11 11 class QCheckBox; 12 12 13 class CheckBox: public FormLayout 14 { 15 Q_OBJECT 13 class CheckBox : public FormLayout { 14 Q_OBJECT 16 15 17 18 CheckBox(Layout* parent,int row, int col,QString name,bool value);19 16 public: 17 CheckBox(Layout *parent, int row, int col, QString name, bool value); 18 ~CheckBox(); 20 19 20 private: 21 QCheckBox *checkbox; 22 bool checkbox_value; 23 void SetUptodate(void); 24 void Reset(void); 25 void LoadEvent(QDomElement dom); 21 26 22 private: 23 QCheckBox* checkbox; 24 bool checkbox_value; 25 void SetUptodate(void); 26 void Reset(void); 27 void LoadEvent(QDomElement dom); 27 void ui_to_var(void); 28 void ui_to_xml(void); 28 29 29 void ui_to_var(void); 30 void ui_to_xml(void); 31 32 private slots: 33 void valuechanged(bool value); 30 private slots: 31 void valuechanged(bool value); 34 32 }; 35 33 -
trunk/tools/FlairGCS/src/ComboBox.cpp
r10 r15 8 8 #include <QFormLayout> 9 9 10 ComboBox::ComboBox(Layout * parent,int row, int col,QString name,int value): FormLayout(parent,row,col,name,"ComboBox")11 {12 13 10 ComboBox::ComboBox(Layout *parent, int row, int col, QString name, int value) 11 : FormLayout(parent, row, col, name, "ComboBox") { 12 combobox = new QComboBox(); 13 combobox->setCurrentIndex(value); 14 14 15 combobox_value=value;15 combobox_value = value; 16 16 17 object_layout->addRow(name,combobox);17 object_layout->addRow(name, combobox); 18 18 19 connect(combobox,SIGNAL(currentIndexChanged(int)),this, SLOT(valuechanged(int))); 19 connect(combobox, SIGNAL(currentIndexChanged(int)), this, 20 SLOT(valuechanged(int))); 20 21 21 22 SetValue(QString::number(combobox_value)); 22 23 23 //pour ne pas faire de doublons qd on ajoute des items24 24 // pour ne pas faire de doublons qd on ajoute des items 25 SetIsExpandable(true); 25 26 } 26 27 27 ComboBox::~ComboBox() 28 { 29 delete combobox; 28 ComboBox::~ComboBox() { delete combobox; } 29 30 void ComboBox::XmlEvent(QDomElement dom) { 31 if (dom.attribute("item") != "") { 32 QString item = dom.attribute("item"); 33 combobox->addItem(item); 34 combobox->setCurrentIndex(combobox_value); 35 } 30 36 } 31 37 32 void ComboBox::XmlEvent(QDomElement dom) 33 { 34 if(dom.attribute("item")!="") { 35 QString item=dom.attribute("item"); 36 combobox->addItem(item); 37 combobox->setCurrentIndex(combobox_value); 38 } 38 void ComboBox::SetUptodate(void) { 39 ui_to_var(); 40 ui_to_xml(); 41 visible_widget->setPalette(black_pal); 39 42 } 40 43 41 void ComboBox::SetUptodate(void) 42 { 43 ui_to_var(); 44 ui_to_xml(); 45 visible_widget->setPalette(black_pal); 44 void ComboBox::ui_to_var(void) { combobox_value = combobox->currentIndex(); } 46 45 46 void ComboBox::ui_to_xml(void) { 47 SetValue(QString::number(combobox->currentIndex())); 47 48 } 48 49 49 void ComboBox::ui_to_var(void) 50 { 51 combobox_value=combobox->currentIndex(); 50 void ComboBox::Reset(void) { combobox->setCurrentIndex(combobox_value); } 51 52 void ComboBox::LoadEvent(QDomElement dom) { 53 if (combobox->isEnabled() == true) { 54 combobox->setCurrentIndex((dom.attribute("value")).toInt()); 55 } 52 56 } 53 57 54 void ComboBox::ui_to_xml(void) 55 { 56 SetValue(QString::number(combobox->currentIndex())); 58 void ComboBox::valuechanged(int value) { 59 if (value != combobox_value) { 60 visible_widget->setPalette(red_pal); 61 } else { 62 visible_widget->setPalette(black_pal); 63 } 57 64 } 58 59 void ComboBox::Reset(void)60 {61 combobox->setCurrentIndex(combobox_value);62 }63 64 void ComboBox::LoadEvent(QDomElement dom)65 {66 if(combobox->isEnabled()==true)67 {68 combobox->setCurrentIndex((dom.attribute("value")).toInt());69 }70 }71 72 void ComboBox::valuechanged(int value)73 {74 if(value!=combobox_value)75 {76 visible_widget->setPalette(red_pal);77 }78 else79 {80 visible_widget->setPalette(black_pal);81 }82 } -
trunk/tools/FlairGCS/src/ComboBox.h
r10 r15 11 11 class Layout; 12 12 13 class ComboBox: public FormLayout 14 { 15 Q_OBJECT 13 class ComboBox : public FormLayout { 14 Q_OBJECT 16 15 17 18 ComboBox(Layout* parent,int row, int col,QString name,int value);19 16 public: 17 ComboBox(Layout *parent, int row, int col, QString name, int value); 18 ~ComboBox(); 20 19 21 22 QComboBox*combobox;23 24 25 26 27 20 private: 21 QComboBox *combobox; 22 int combobox_value; 23 void XmlEvent(QDomElement dom); 24 void SetUptodate(void); 25 void Reset(void); 26 void LoadEvent(QDomElement dom); 28 27 29 30 28 void ui_to_var(void); 29 void ui_to_xml(void); 31 30 32 33 31 private slots: 32 void valuechanged(int value); 34 33 }; 35 34 -
trunk/tools/FlairGCS/src/ConnectionLayout.cpp
r10 r15 13 13 #define COMPRESS_CHUNK 1024 14 14 15 16 ConnectionLayout::ConnectionLayout(UdtSocket* socket,QString name): Layout(NULL,name,"root") {17 isRemoteNameDefined=false;18 this->socket=socket;15 ConnectionLayout::ConnectionLayout(UdtSocket *socket, QString name) 16 : Layout(NULL, name, "root") { 17 isRemoteNameDefined = false; 18 this->socket = socket; 19 19 } 20 20 21 ConnectionLayout::~ConnectionLayout() { 22 } 21 ConnectionLayout::~ConnectionLayout() {} 23 22 24 void ConnectionLayout::receive(char * buf,int size) {25 //printf("trame %x\n",buf[0]);26 //for(int i=0; i<size;i++) printf("%x ",buf[i]);27 //printf("\n");28 switch(buf[0]) {29 30 31 char*uncompressbuf;32 uncompressBuffer(buf,size,&uncompressbuf,&out_size);33 handleUncompressedFrame(uncompressbuf,out_size);34 35 36 37 38 handleUncompressedFrame(buf,size);39 40 23 void ConnectionLayout::receive(char *buf, int size) { 24 // printf("trame %x\n",buf[0]); 25 // for(int i=0; i<size;i++) printf("%x ",buf[i]); 26 // printf("\n"); 27 switch (buf[0]) { 28 case ZLIB_HEADER: { 29 ssize_t out_size; 30 char *uncompressbuf; 31 uncompressBuffer(buf, size, &uncompressbuf, &out_size); 32 handleUncompressedFrame(uncompressbuf, out_size); 33 free(uncompressbuf); 34 break; 35 } 36 default: 37 handleUncompressedFrame(buf, size); 38 } 39 free(buf); 41 40 } 42 41 43 42 void ConnectionLayout::XmlToSend(QDomDocument doc) { 44 //printf("xml to send\n%s\n",doc.toString().toLocal8Bit().constData()); 45 //xml to send a mettre dans le manager 46 QMetaObject::invokeMethod(socket, 47 "write", 48 Qt::BlockingQueuedConnection, 49 Q_ARG(const char*,doc.toString().toLocal8Bit().constData()), 50 Q_ARG(qint64,doc.toString().toLocal8Bit().length())); 51 43 // printf("xml to send\n%s\n",doc.toString().toLocal8Bit().constData()); 44 // xml to send a mettre dans le manager 45 QMetaObject::invokeMethod( 46 socket, "write", Qt::BlockingQueuedConnection, 47 Q_ARG(const char *, doc.toString().toLocal8Bit().constData()), 48 Q_ARG(qint64, doc.toString().toLocal8Bit().length())); 52 49 } 53 50 54 51 void ConnectionLayout::LoadXml(QDomDocument to_parse) { 55 if(!isRemoteNameDefined) { 56 printf("load xml: name not defined!\n"); 57 return; 52 if (!isRemoteNameDefined) { 53 printf("load xml: name not defined!\n"); 54 return; 55 } 56 57 QDomElement tmp = to_parse.firstChildElement("root"); 58 while (tmp.attribute("name") != remoteName && !tmp.isNull()) 59 tmp = to_parse.nextSiblingElement("root"); 60 61 if (!tmp.isNull()) { 62 XmlWidget::LoadXml(tmp); 63 } else { 64 printf("%s not found in xml file \n", remoteName.toLocal8Bit().constData()); 65 } 66 } 67 68 void ConnectionLayout::handleUncompressedFrame(char *buf, ssize_t size) { 69 switch ((unsigned char)buf[0]) { 70 case XML_HEADER: { 71 QString xml; 72 QDomDocument doc; 73 xml = QString((char *)buf); 74 xml.resize(size); 75 76 // printf("recu %i\n%s\n",size,xml.toLocal8Bit().constData()); 77 if (!doc.setContent(xml)) { 78 printf("prob setContent fichier\n"); 58 79 } 59 80 60 QDomElement tmp=to_parse.firstChildElement("root"); 61 while(tmp.attribute("name")!=remoteName && !tmp.isNull()) tmp=to_parse.nextSiblingElement("root"); 81 if (!isRemoteNameDefined) { 82 isRemoteNameDefined = true; 83 remoteName = doc.firstChildElement("root").attribute("name"); 84 setRemoteName(remoteName); 85 SetAttribute("name", remoteName); 86 } 62 87 63 if(!tmp.isNull()) { 64 XmlWidget::LoadXml(tmp); 65 } else { 66 printf("%s not found in xml file \n",remoteName.toLocal8Bit().constData()); 67 } 88 ParseXml(doc.firstChildElement("root").firstChildElement()); 89 break; 90 } 91 case DATAS_BIG_ENDIAN: { 92 // for(int i=0;i<size;i++) printf("%x ",buf[i]); 93 // printf("\n"); 94 uint16_t period; 95 memcpy(&period, &buf[1], sizeof(uint16_t)); 96 period = qFromBigEndian(period); 97 drawDatas(&buf[3], size - 3, period, true); 98 break; 99 } 100 case DATAS_LITTLE_ENDIAN: { 101 // for(int i=0;i<size;i++) printf("%x ",buf[i]); 102 // printf("\n"); 103 uint16_t period; 104 memcpy(&period, &buf[1], sizeof(uint16_t)); 105 // printf("recu %i period %i\n",size,period); 106 drawDatas(&buf[3], size - 3, period); 107 break; 108 } 109 default: 110 printf("trame non supportée %x\n", buf[0]); 111 } 68 112 } 69 113 70 void ConnectionLayout::handleUncompressedFrame(char *buf,ssize_t size) { 71 switch((unsigned char)buf[0]) { 72 case XML_HEADER: { 73 QString xml; 74 QDomDocument doc; 75 xml=QString((char*)buf); 76 xml.resize(size); 77 78 //printf("recu %i\n%s\n",size,xml.toLocal8Bit().constData()); 79 if(!doc.setContent(xml)) { 80 printf("prob setContent fichier\n"); 81 } 82 83 if(!isRemoteNameDefined) { 84 isRemoteNameDefined=true; 85 remoteName=doc.firstChildElement("root").attribute("name"); 86 setRemoteName(remoteName); 87 SetAttribute("name",remoteName); 88 } 89 90 ParseXml(doc.firstChildElement("root").firstChildElement()); 91 break; 92 } 93 case DATAS_BIG_ENDIAN: { 94 //for(int i=0;i<size;i++) printf("%x ",buf[i]); 95 //printf("\n"); 96 uint16_t period; 97 memcpy(&period,&buf[1],sizeof(uint16_t)); 98 period=qFromBigEndian(period); 99 drawDatas(&buf[3],size-3,period,true); 100 break; 101 } 102 case DATAS_LITTLE_ENDIAN: { 103 //for(int i=0;i<size;i++) printf("%x ",buf[i]); 104 //printf("\n"); 105 uint16_t period; 106 memcpy(&period,&buf[1],sizeof(uint16_t)); 107 //printf("recu %i period %i\n",size,period); 108 drawDatas(&buf[3],size-3,period); 109 break; 110 } 111 default: 112 printf("trame non supportée %x\n",buf[0]); 113 } 114 void ConnectionLayout::removeDataRemote(DataRemote *data) { 115 dataremotes.removeOne(data); 114 116 } 115 117 116 void ConnectionLayout:: removeDataRemote(DataRemote*data) {117 dataremotes.removeOne(data);118 void ConnectionLayout::addDataRemote(DataRemote *data) { 119 dataremotes.append(data); 118 120 } 119 121 120 void ConnectionLayout::addDataRemote(DataRemote* data) { 121 dataremotes.append(data); 122 QString ConnectionLayout::getRemoteName() { return remoteName; } 123 void ConnectionLayout::drawDatas(char *buf, int buf_size, uint16_t period, 124 bool big_endian) { 125 for (int i = 0; i < dataremotes.count(); i++) { 126 dataremotes.at(i)->BufEvent(&buf, &buf_size, period, big_endian); 127 } 122 128 } 123 129 124 QString ConnectionLayout::getRemoteName() { 125 return remoteName; 130 int ConnectionLayout::uncompressBuffer(char *in, ssize_t in_size, char **out, 131 ssize_t *out_size) { 132 int ret; 133 unsigned have; 134 z_stream strm; 135 136 // allocate inflate state 137 strm.zalloc = Z_NULL; 138 strm.zfree = Z_NULL; 139 strm.opaque = Z_NULL; 140 strm.avail_in = 0; 141 strm.next_in = Z_NULL; 142 ret = inflateInit(&strm); 143 if (ret != Z_OK) 144 return ret; 145 146 *out = (char *)malloc(COMPRESS_CHUNK); 147 if (!(*out)) 148 return Z_BUF_ERROR; 149 150 strm.avail_in = in_size; 151 strm.next_in = (unsigned char *)in; 152 strm.avail_out = COMPRESS_CHUNK; 153 strm.next_out = (unsigned char *)*out; 154 155 ret = inflate(&strm, Z_NO_FLUSH); 156 assert(ret != Z_STREAM_ERROR); // state not clobbered 157 switch (ret) { 158 case Z_NEED_DICT: 159 ret = Z_DATA_ERROR; // and fall through 160 case Z_DATA_ERROR: 161 case Z_MEM_ERROR: 162 (void)inflateEnd(&strm); 163 return ret; 164 } 165 have = COMPRESS_CHUNK - strm.avail_out; 166 *out_size = have; 167 168 // printf("%i -> %i\n",in_size,have); 169 // printf("%s\n",*out); 170 // clean up and return 171 (void)inflateEnd(&strm); 172 return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR; 126 173 } 127 void ConnectionLayout::drawDatas(char* buf,int buf_size,uint16_t period,bool big_endian) {128 for(int i=0;i<dataremotes.count();i++) {129 dataremotes.at(i)->BufEvent(&buf,&buf_size,period,big_endian);130 }131 }132 133 int ConnectionLayout::uncompressBuffer(char *in, ssize_t in_size,char **out,ssize_t *out_size) {134 int ret;135 unsigned have;136 z_stream strm;137 138 // allocate inflate state139 strm.zalloc = Z_NULL;140 strm.zfree = Z_NULL;141 strm.opaque = Z_NULL;142 strm.avail_in = 0;143 strm.next_in = Z_NULL;144 ret = inflateInit(&strm);145 if (ret != Z_OK)146 return ret;147 148 *out=(char*)malloc(COMPRESS_CHUNK);149 if(!(*out))150 return Z_BUF_ERROR;151 152 strm.avail_in = in_size;153 strm.next_in = (unsigned char*)in;154 strm.avail_out = COMPRESS_CHUNK;155 strm.next_out = (unsigned char*)*out;156 157 ret = inflate(&strm, Z_NO_FLUSH);158 assert(ret != Z_STREAM_ERROR); // state not clobbered159 switch (ret) {160 case Z_NEED_DICT:161 ret = Z_DATA_ERROR; // and fall through162 case Z_DATA_ERROR:163 case Z_MEM_ERROR:164 (void)inflateEnd(&strm);165 return ret;166 }167 have = COMPRESS_CHUNK- strm.avail_out;168 *out_size=have;169 170 //printf("%i -> %i\n",in_size,have);171 //printf("%s\n",*out);172 // clean up and return173 (void)inflateEnd(&strm);174 return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;175 } -
trunk/tools/FlairGCS/src/ConnectionLayout.h
r10 r15 11 11 class DataRemote; 12 12 13 class ConnectionLayout: public Layout 14 { 15 Q_OBJECT 13 class ConnectionLayout : public Layout { 14 Q_OBJECT 16 15 17 18 ConnectionLayout(UdtSocket* socket,QString name);19 20 21 void addDataRemote(DataRemote*data);22 void removeDataRemote(DataRemote*data);23 24 16 public: 17 ConnectionLayout(UdtSocket *socket, QString name); 18 ~ConnectionLayout(); 19 void XmlToSend(QDomDocument doc); 20 void addDataRemote(DataRemote *data); 21 void removeDataRemote(DataRemote *data); 22 void LoadXml(QDomDocument to_parse); 23 QString getRemoteName(); 25 24 26 private: 27 static int uncompressBuffer(char *in, ssize_t in_size,char **out,ssize_t *out_size); 28 void handleUncompressedFrame(char *buf,ssize_t size); 29 void drawDatas(char* buf,int buf_size,uint16_t period,bool big_endian=false); 30 bool isRemoteNameDefined; 31 QString remoteName; 32 UdtSocket* socket; 33 QList<DataRemote*> dataremotes; 25 private: 26 static int uncompressBuffer(char *in, ssize_t in_size, char **out, 27 ssize_t *out_size); 28 void handleUncompressedFrame(char *buf, ssize_t size); 29 void drawDatas(char *buf, int buf_size, uint16_t period, 30 bool big_endian = false); 31 bool isRemoteNameDefined; 32 QString remoteName; 33 UdtSocket *socket; 34 QList<DataRemote *> dataremotes; 34 35 35 36 void receive(char* buf,intsize);36 private slots: 37 void receive(char *buf, int size); 37 38 38 39 39 signals: 40 void setRemoteName(QString name); 40 41 }; 41 42 -
trunk/tools/FlairGCS/src/DataPlot1D.cpp
r10 r15 10 10 #include <qendian.h> 11 11 12 DataPlot1D::DataPlot1D(Layout* parent,int row, int col,QString title,float ymin, float ymax,bool enabled,int period): 13 ScopeFixedStep(title,ymin,ymax,period/1000.),DataRemote(title,"DataPlot1D",parent,enabled,period) { 12 DataPlot1D::DataPlot1D(Layout *parent, int row, int col, QString title, 13 float ymin, float ymax, bool enabled, int period) 14 : ScopeFixedStep(title, ymin, ymax, period / 1000.), 15 DataRemote(title, "DataPlot1D", parent, enabled, period) { 14 16 15 16 parent->addWidget(this,row,col);17 visible_widget=this;17 setEnabled(enabled); 18 parent->addWidget(this, row, col); 19 visible_widget = this; 18 20 } 19 21 20 22 DataPlot1D::~DataPlot1D() { 21 visible_widget=NULL;//because otherwise xmlwidget will delete it23 visible_widget = NULL; // because otherwise xmlwidget will delete it 22 24 } 23 25 24 26 void DataPlot1D::XmlEvent(QDomElement dom) { 25 if(dom.attribute("curve")!="") { 26 QString type=dom.attribute("type"); 27 int r=dom.attribute("r").toInt(); 28 int g=dom.attribute("g").toInt(); 29 int b=dom.attribute("b").toInt(); 30 QString name=dom.attribute("curve"); 31 addCurve(QPen(QColor(r,g,b,255)),name); 32 datas_type.append(type); 33 if(type=="float") { 34 receivesize+=sizeof(float); 35 } else if(type=="int8_t") { 36 receivesize+=sizeof(int8_t); 37 } else if(type=="int16_t") { 38 receivesize+=sizeof(int16_t); 39 } else { 40 printf("MyDataPlot1D::addCurve unknown type %s\n",type.toLocal8Bit().constData()); 41 } 27 if (dom.attribute("curve") != "") { 28 QString type = dom.attribute("type"); 29 int r = dom.attribute("r").toInt(); 30 int g = dom.attribute("g").toInt(); 31 int b = dom.attribute("b").toInt(); 32 QString name = dom.attribute("curve"); 33 addCurve(QPen(QColor(r, g, b, 255)), name); 34 datas_type.append(type); 35 if (type == "float") { 36 receivesize += sizeof(float); 37 } else if (type == "int8_t") { 38 receivesize += sizeof(int8_t); 39 } else if (type == "int16_t") { 40 receivesize += sizeof(int16_t); 42 41 } else { 43 XmlSetup(dom); 42 printf("MyDataPlot1D::addCurve unknown type %s\n", 43 type.toLocal8Bit().constData()); 44 44 } 45 } else { 46 XmlSetup(dom); 47 } 45 48 } 46 49 47 50 bool DataPlot1D::eventFilter(QObject *o, QEvent *e) { 48 if ( o == canvas() ) { 49 switch(e->type()) { 50 case QEvent::Resize: { 51 //resolution bug taille widgets: 52 setMaximumHeight(parentWidget()->height()/((QGridLayout*)(parentWidget()->layout()))->rowCount()); 53 break; 54 } 55 case QEvent::MouseButtonPress: { 56 return mouseEvent((QMouseEvent*)e); 57 } 51 if (o == canvas()) { 52 switch (e->type()) { 53 case QEvent::Resize: { 54 // resolution bug taille widgets: 55 setMaximumHeight(parentWidget()->height() / 56 ((QGridLayout *)(parentWidget()->layout()))->rowCount()); 57 break; 58 } 59 case QEvent::MouseButtonPress: { 60 return mouseEvent((QMouseEvent *)e); 61 } 58 62 59 default: 60 break; 61 } 63 default: 64 break; 62 65 } 63 return Scope::eventFilter(o, e); 66 } 67 return Scope::eventFilter(o, e); 64 68 } 65 69 66 void DataPlot1D::BufEvent(char **buf,int *buf_size,uint16_t period,bool big_endian) 67 { 68 setEnabled(IsEnabled()); 69 if(IsEnabled()==false || RefreshRate_ms()!=period) return; 70 double* datas=(double*)malloc(datas_type.count()*sizeof(double)); 70 void DataPlot1D::BufEvent(char **buf, int *buf_size, uint16_t period, 71 bool big_endian) { 72 setEnabled(IsEnabled()); 73 if (IsEnabled() == false || RefreshRate_ms() != period) 74 return; 75 double *datas = (double *)malloc(datas_type.count() * sizeof(double)); 71 76 72 for(int i=0;i<datas_type.count();i++) { 73 if(datas_type.at(i)=="float") { 74 uint32_t data_raw; 75 float* data=(float*)&data_raw; 76 memcpy((void*)&data_raw,*buf,sizeof(uint32_t)); 77 *buf+=sizeof(uint32_t); 78 if(big_endian==true) data_raw=qFromBigEndian(data_raw); 79 datas[i]=*data; 80 } else if(datas_type.at(i)=="int8_t") { 81 int8_t data; 82 memcpy((void*)&data,*buf,sizeof(data)); 83 *buf+=sizeof(data); 84 datas[i]=data; 85 } else if(datas_type.at(i)=="int16_t") { 86 int16_t data; 87 memcpy((void*)&data,*buf,sizeof(data)); 88 *buf+=sizeof(data); 89 if(big_endian==true) data=qFromBigEndian(data); 90 datas[i]=data; 91 } else { 92 printf("DataPlot1D::BufEvent unknown type %s\n",datas_type.at(i).toLocal8Bit().constData()); 93 } 77 for (int i = 0; i < datas_type.count(); i++) { 78 if (datas_type.at(i) == "float") { 79 uint32_t data_raw; 80 float *data = (float *)&data_raw; 81 memcpy((void *)&data_raw, *buf, sizeof(uint32_t)); 82 *buf += sizeof(uint32_t); 83 if (big_endian == true) 84 data_raw = qFromBigEndian(data_raw); 85 datas[i] = *data; 86 } else if (datas_type.at(i) == "int8_t") { 87 int8_t data; 88 memcpy((void *)&data, *buf, sizeof(data)); 89 *buf += sizeof(data); 90 datas[i] = data; 91 } else if (datas_type.at(i) == "int16_t") { 92 int16_t data; 93 memcpy((void *)&data, *buf, sizeof(data)); 94 *buf += sizeof(data); 95 if (big_endian == true) 96 data = qFromBigEndian(data); 97 datas[i] = data; 98 } else { 99 printf("DataPlot1D::BufEvent unknown type %s\n", 100 datas_type.at(i).toLocal8Bit().constData()); 94 101 } 102 } 95 103 96 step_s=period/1000.;97 104 step_s = period / 1000.; 105 plot(datas); 98 106 } 99 107 100 // context menu108 // context menu 101 109 bool DataPlot1D::mouseEvent(QMouseEvent *event) { 102 103 QMenu *menu = new QMenu("nom", (QwtPlot*)this);104 QAction *a,*b,*z;110 if (event->button() == Qt::RightButton) { 111 QMenu *menu = new QMenu("nom", (QwtPlot *)this); 112 QAction *a, *b, *z; 105 113 106 a=menu->addAction("reset time view");107 b=menu->addAction("reset y view");108 114 a = menu->addAction("reset time view"); 115 b = menu->addAction("reset y view"); 116 menu->addSeparator(); 109 117 110 111 z=execmenu((QwtPlot*)this,menu,event->globalPos());112 118 appendmenu(menu); 119 z = execmenu((QwtPlot *)this, menu, event->globalPos()); 120 delete menu; 113 121 114 if(z==a) resetXView(); 115 if(z==b) resetYView(); 122 if (z == a) 123 resetXView(); 124 if (z == b) 125 resetYView(); 116 126 117 118 119 127 return true; 128 } 129 return false; 120 130 } -
trunk/tools/FlairGCS/src/DataPlot1D.h
r10 r15 9 9 #include "DataRemote.h" 10 10 11 12 11 class Layout; 13 12 class QMouseEvent; 14 13 15 class DataPlot1D : public ScopeFixedStep,public DataRemote16 { 17 public:18 DataPlot1D(Layout* parent,int row, int col,QString title,float ymin, float ymax,bool enabled,int period);19 14 class DataPlot1D : public ScopeFixedStep, public DataRemote { 15 public: 16 DataPlot1D(Layout *parent, int row, int col, QString title, float ymin, 17 float ymax, bool enabled, int period); 18 ~DataPlot1D(); 20 19 21 private: 22 void XmlEvent(QDomElement dom); 23 bool eventFilter(QObject *, QEvent *); 24 void BufEvent(char** buf,int *buf_size,uint16_t period,bool big_endian); 25 bool mouseEvent(QMouseEvent *event); 26 QList<QString> datas_type; 27 20 private: 21 void XmlEvent(QDomElement dom); 22 bool eventFilter(QObject *, QEvent *); 23 void BufEvent(char **buf, int *buf_size, uint16_t period, bool big_endian); 24 bool mouseEvent(QMouseEvent *event); 25 QList<QString> datas_type; 28 26 }; 29 27 30 31 28 #endif // DATAPLOT1D_H_INCLUDED -
trunk/tools/FlairGCS/src/DataPlot2D.cpp
r10 r15 20 20 #include <qendian.h> 21 21 22 DataPlot2D::DataPlot2D(Layout* parent,int row, int col,QString plot_name,QString x_name,QString y_name,float xmin, float xmax,float ymin, float ymax,bool enabled,int period): 23 DataRemote(plot_name,"DataPlot2D",parent,enabled,period) 24 { 25 plot=new QwtPlot(NULL); 26 plot->setEnabled(enabled); 27 28 parent->addWidget(plot,row,col); 29 visible_widget=plot; 30 31 view_size=20;//default 20s 32 /* 33 // Disable polygon clipping 34 QwtPainter::setDeviceClipping(false); 35 36 // We don't need the cache here 37 plot->canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false); 38 plot->canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false); 39 */ 22 DataPlot2D::DataPlot2D(Layout *parent, int row, int col, QString plot_name, 23 QString x_name, QString y_name, float xmin, float xmax, 24 float ymin, float ymax, bool enabled, int period) 25 : DataRemote(plot_name, "DataPlot2D", parent, enabled, period) { 26 plot = new QwtPlot(NULL); 27 plot->setEnabled(enabled); 28 29 parent->addWidget(plot, row, col); 30 visible_widget = plot; 31 32 view_size = 20; // default 20s 33 /* 34 // Disable polygon clipping 35 QwtPainter::setDeviceClipping(false); 36 37 // We don't need the cache here 38 plot->canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false); 39 plot->canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false); 40 */ 40 41 #if QT_VERSION >= 0x040000 41 42 #ifdef Q_WS_X11 42 43 44 45 46 43 /* 44 Qt::WA_PaintOnScreen is only supported for X11, but leads 45 to substantial bugs with Qt 4.2.x/Windows 46 */ 47 plot->canvas()->setAttribute(Qt::WA_PaintOnScreen, true); 47 48 #endif 48 49 #endif 49 50 50 alignScales(); 51 52 //d_x=new QList<double*>; 53 //d_y=new QList<double*>; 54 datas=new QList<QwtPlotCurve*>; 55 datas_type=new QList<QString>; 56 57 // Assign a title 58 plot->setTitle(plot_name); 59 60 // Axis 61 plot->setAxisTitle(QwtPlot::xBottom, x_name); 62 setXAxisScale(xmin,xmax); 63 64 plot->setAxisTitle(QwtPlot::yLeft, y_name); 65 setYAxisScale(ymin,ymax); 66 67 QwtPlotRescaler* rescaler = new QwtPlotRescaler( plot->canvas() ); 68 rescaler->setRescalePolicy( QwtPlotRescaler::Fixed );/* 69 rescaler->setReferenceAxis(QwtPlot::xBottom); 70 rescaler->setAspectRatio(QwtPlot::yLeft, 1.0);*/ 71 72 // grid 73 QwtPlotGrid *grid = new QwtPlotGrid; 74 //grid->enableXMin(false); 75 grid->setPen(QPen(Qt::black, 0, Qt::DotLine)); 76 //grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); 77 grid->attach(plot); 78 79 //zoomer 80 QwtPlotMagnifier * zoomer = new QwtPlotMagnifier(plot->canvas()); 81 zoomer->setMouseButton(Qt::RightButton,Qt::ControlModifier); 82 83 //scroller 84 QwtPlotPanner *scroller =new QwtPlotPanner(plot->canvas()); 85 86 //legend 87 QwtLegend* new_legend=new QwtLegend(); 88 new_legend->setDefaultItemMode(QwtLegendData::Checkable); 89 plot->insertLegend(new_legend, QwtPlot::BottomLegend); 90 91 connect( new_legend, SIGNAL( checked( const QVariant &, bool, int ) ), SLOT( legendChecked( const QVariant &, bool ) ) ); 92 93 plot->canvas()->installEventFilter(this); 94 } 95 96 DataPlot2D::~DataPlot2D() 97 { 98 for(int i=0;i<d_x.count();i++) 99 { 100 free(d_x.at(i)); 101 free(d_y.at(i)); 102 } 103 104 delete datas; 105 delete datas_type; 106 } 107 108 void DataPlot2D::XmlEvent(QDomElement dom) 109 { 110 if(dom.attribute("curve")!="") { 111 QString type=dom.attribute("type"); 112 int r=dom.attribute("r").toInt(); 113 int g=dom.attribute("g").toInt(); 114 int b=dom.attribute("b").toInt(); 115 QString name=dom.attribute("curve"); 116 addCurve(QPen(QColor(r,g,b,255)),name,type); 117 } else { 118 XmlSetup(dom); 119 } 120 } 121 122 bool DataPlot2D::eventFilter(QObject *o, QEvent *e) 123 { 124 if ( o == plot->canvas() ) 125 { 126 switch(e->type()) 127 { 128 case QEvent::MouseButtonPress: 129 { 130 mousePressEvent((QMouseEvent*)e); 131 break; 132 } 133 134 default: 135 break; 136 } 137 } 138 return plot->eventFilter(o, e); 139 } 140 141 void DataPlot2D::legendChecked( const QVariant &itemInfo, bool on ) 142 { 143 QwtPlotItem *plotItem = plot->infoToItem( itemInfo ); 144 if ( plotItem ) 145 showCurve( plotItem, on ); 146 } 147 148 void DataPlot2D::showCurve(QwtPlotItem *item, bool on) 149 { 150 item->setVisible(on); 151 152 QwtLegend *lgd = qobject_cast<QwtLegend *>( plot->legend() ); 153 154 QList<QWidget *> legendWidgets = 155 lgd->legendWidgets( plot->itemToInfo( item ) ); 156 157 if ( legendWidgets.size() == 1 ) 158 { 159 QwtLegendLabel *legendLabel = 160 qobject_cast<QwtLegendLabel *>( legendWidgets[0] ); 161 162 if ( legendLabel ) 163 legendLabel->setChecked( on ); 164 } 165 166 plot->replot(); 167 } 168 169 void DataPlot2D::addCurve(QPen pen,QString legend,QString type) 170 { 171 double* new_dx; 172 new_dx=(double*)malloc(view_size/refresh_rate*sizeof(double)); 173 d_x.append(new_dx); 174 double* new_dy; 175 new_dy=(double*)malloc(view_size/refresh_rate*sizeof(double)); 176 d_y.append(new_dy); 177 178 // Initialize data 179 for (int i = 0; i< view_size/refresh_rate; i++) new_dx[i] = 0; 180 for (int i = 0; i< view_size/refresh_rate; i++) new_dy[i] = 0; 181 182 // Insert new curve 183 QwtPlotCurve* new_data; 184 185 new_data = new QwtPlotCurve(legend); 186 new_data->attach(plot); 187 new_data->setPen(pen); 188 datas->append(new_data); 189 190 showCurve(new_data, true); 191 192 datas_type->append(type); 193 bool tmp=true; 194 datas_first_update.append(tmp); 195 196 // Attach (don't copy) data. Both curves use the same x array. 197 new_data->setRawSamples(new_dx, new_dy, view_size/refresh_rate); 198 199 if(type=="float") 200 { 201 receivesize+=sizeof(float); 202 } 203 else if(type=="int8_t") 204 { 205 receivesize+=sizeof(int8_t); 206 } 207 else if(type=="int16_t") 208 { 209 receivesize+=sizeof(int16_t); 210 } 211 else 212 { 213 printf("DataPlot2D::addCurve unknown type %s\n",type.toLocal8Bit().constData()); 214 } 215 216 } 217 218 void DataPlot2D::setXAxisScale(float xmin,float xmax) 219 { 220 xmin_orig=xmin; 221 xmax_orig=xmax; 222 plot->setAxisScale(QwtPlot::xBottom, xmin_orig, xmax_orig); 223 224 } 225 226 void DataPlot2D::setYAxisScale(float ymin,float ymax) 227 { 228 ymin_orig=ymin; 229 ymax_orig=ymax; 230 plot->setAxisScale(QwtPlot::yLeft, ymin_orig, ymax_orig); 51 alignScales(); 52 53 // d_x=new QList<double*>; 54 // d_y=new QList<double*>; 55 datas = new QList<QwtPlotCurve *>; 56 datas_type = new QList<QString>; 57 58 // Assign a title 59 plot->setTitle(plot_name); 60 61 // Axis 62 plot->setAxisTitle(QwtPlot::xBottom, x_name); 63 setXAxisScale(xmin, xmax); 64 65 plot->setAxisTitle(QwtPlot::yLeft, y_name); 66 setYAxisScale(ymin, ymax); 67 68 QwtPlotRescaler *rescaler = new QwtPlotRescaler(plot->canvas()); 69 rescaler->setRescalePolicy(QwtPlotRescaler::Fixed); /* 70 rescaler->setReferenceAxis(QwtPlot::xBottom); 71 rescaler->setAspectRatio(QwtPlot::yLeft, 1.0);*/ 72 73 // grid 74 QwtPlotGrid *grid = new QwtPlotGrid; 75 // grid->enableXMin(false); 76 grid->setPen(QPen(Qt::black, 0, Qt::DotLine)); 77 // grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine)); 78 grid->attach(plot); 79 80 // zoomer 81 QwtPlotMagnifier *zoomer = new QwtPlotMagnifier(plot->canvas()); 82 zoomer->setMouseButton(Qt::RightButton, Qt::ControlModifier); 83 84 // scroller 85 QwtPlotPanner *scroller = new QwtPlotPanner(plot->canvas()); 86 87 // legend 88 QwtLegend *new_legend = new QwtLegend(); 89 new_legend->setDefaultItemMode(QwtLegendData::Checkable); 90 plot->insertLegend(new_legend, QwtPlot::BottomLegend); 91 92 connect(new_legend, SIGNAL(checked(const QVariant &, bool, int)), 93 SLOT(legendChecked(const QVariant &, bool))); 94 95 plot->canvas()->installEventFilter(this); 96 } 97 98 DataPlot2D::~DataPlot2D() { 99 for (int i = 0; i < d_x.count(); i++) { 100 free(d_x.at(i)); 101 free(d_y.at(i)); 102 } 103 104 delete datas; 105 delete datas_type; 106 } 107 108 void DataPlot2D::XmlEvent(QDomElement dom) { 109 if (dom.attribute("curve") != "") { 110 QString type = dom.attribute("type"); 111 int r = dom.attribute("r").toInt(); 112 int g = dom.attribute("g").toInt(); 113 int b = dom.attribute("b").toInt(); 114 QString name = dom.attribute("curve"); 115 addCurve(QPen(QColor(r, g, b, 255)), name, type); 116 } else { 117 XmlSetup(dom); 118 } 119 } 120 121 bool DataPlot2D::eventFilter(QObject *o, QEvent *e) { 122 if (o == plot->canvas()) { 123 switch (e->type()) { 124 case QEvent::MouseButtonPress: { 125 mousePressEvent((QMouseEvent *)e); 126 break; 127 } 128 129 default: 130 break; 131 } 132 } 133 return plot->eventFilter(o, e); 134 } 135 136 void DataPlot2D::legendChecked(const QVariant &itemInfo, bool on) { 137 QwtPlotItem *plotItem = plot->infoToItem(itemInfo); 138 if (plotItem) 139 showCurve(plotItem, on); 140 } 141 142 void DataPlot2D::showCurve(QwtPlotItem *item, bool on) { 143 item->setVisible(on); 144 145 QwtLegend *lgd = qobject_cast<QwtLegend *>(plot->legend()); 146 147 QList<QWidget *> legendWidgets = lgd->legendWidgets(plot->itemToInfo(item)); 148 149 if (legendWidgets.size() == 1) { 150 QwtLegendLabel *legendLabel = 151 qobject_cast<QwtLegendLabel *>(legendWidgets[0]); 152 153 if (legendLabel) 154 legendLabel->setChecked(on); 155 } 156 157 plot->replot(); 158 } 159 160 void DataPlot2D::addCurve(QPen pen, QString legend, QString type) { 161 double *new_dx; 162 new_dx = (double *)malloc(view_size / refresh_rate * sizeof(double)); 163 d_x.append(new_dx); 164 double *new_dy; 165 new_dy = (double *)malloc(view_size / refresh_rate * sizeof(double)); 166 d_y.append(new_dy); 167 168 // Initialize data 169 for (int i = 0; i < view_size / refresh_rate; i++) 170 new_dx[i] = 0; 171 for (int i = 0; i < view_size / refresh_rate; i++) 172 new_dy[i] = 0; 173 174 // Insert new curve 175 QwtPlotCurve *new_data; 176 177 new_data = new QwtPlotCurve(legend); 178 new_data->attach(plot); 179 new_data->setPen(pen); 180 datas->append(new_data); 181 182 showCurve(new_data, true); 183 184 datas_type->append(type); 185 bool tmp = true; 186 datas_first_update.append(tmp); 187 188 // Attach (don't copy) data. Both curves use the same x array. 189 new_data->setRawSamples(new_dx, new_dy, view_size / refresh_rate); 190 191 if (type == "float") { 192 receivesize += sizeof(float); 193 } else if (type == "int8_t") { 194 receivesize += sizeof(int8_t); 195 } else if (type == "int16_t") { 196 receivesize += sizeof(int16_t); 197 } else { 198 printf("DataPlot2D::addCurve unknown type %s\n", 199 type.toLocal8Bit().constData()); 200 } 201 } 202 203 void DataPlot2D::setXAxisScale(float xmin, float xmax) { 204 xmin_orig = xmin; 205 xmax_orig = xmax; 206 plot->setAxisScale(QwtPlot::xBottom, xmin_orig, xmax_orig); 207 } 208 209 void DataPlot2D::setYAxisScale(float ymin, float ymax) { 210 ymin_orig = ymin; 211 ymax_orig = ymax; 212 plot->setAxisScale(QwtPlot::yLeft, ymin_orig, ymax_orig); 231 213 } 232 214 … … 234 216 // Set a plain canvas frame and align the scales to it 235 217 // 236 void DataPlot2D::alignScales(void) 237 { 238 // The code below shows how to align the scales to 239 // the canvas frame, but is also a good example demonstrating 240 // why the spreaded API needs polishing. 241 /* 242 plot->canvas()->setFrameStyle(QFrame::Box | QFrame::Plain ); 243 plot->canvas()->setLineWidth(1); 244 */ 245 for ( int i = 0; i < QwtPlot::axisCnt; i++ ) 246 { 247 QwtScaleWidget *scaleWidget = (QwtScaleWidget *)plot->axisWidget(i); 248 if ( scaleWidget ) 249 scaleWidget->setMargin(0); 250 251 QwtScaleDraw *scaleDraw = (QwtScaleDraw *)plot->axisScaleDraw(i); 252 if ( scaleDraw ) 253 scaleDraw->enableComponent(QwtAbstractScaleDraw::Backbone, false); 254 } 255 } 256 257 void DataPlot2D::BufEvent(char **buf,int *buf_size,uint16_t period,bool big_endian) 258 { 259 plot->setEnabled(IsEnabled()); 260 if(IsEnabled()==false || RefreshRate_ms()!=period) return; 261 262 for(int i=0;i<datas->count();i++) 263 { 264 if(datas_type->at(i)=="float") 265 { 266 uint32_t data1_raw; 267 float* data1=(float*)&data1_raw; 268 uint32_t data2_raw; 269 float* data2=(float*)&data2_raw; 270 271 memcpy((void*)&data1_raw,*buf,sizeof(uint32_t)); 272 *buf+=sizeof(uint32_t); 273 memcpy((void*)&data2_raw,*buf,sizeof(uint32_t)); 274 *buf+=sizeof(uint32_t); 275 if(big_endian==true) data1_raw=qFromBigEndian(data1_raw); 276 if(big_endian==true) data2_raw=qFromBigEndian(data2_raw); 277 plot_data(*data1,*data2,i); 218 void DataPlot2D::alignScales(void) { 219 // The code below shows how to align the scales to 220 // the canvas frame, but is also a good example demonstrating 221 // why the spreaded API needs polishing. 222 /* 223 plot->canvas()->setFrameStyle(QFrame::Box | QFrame::Plain ); 224 plot->canvas()->setLineWidth(1); 225 */ 226 for (int i = 0; i < QwtPlot::axisCnt; i++) { 227 QwtScaleWidget *scaleWidget = (QwtScaleWidget *)plot->axisWidget(i); 228 if (scaleWidget) 229 scaleWidget->setMargin(0); 230 231 QwtScaleDraw *scaleDraw = (QwtScaleDraw *)plot->axisScaleDraw(i); 232 if (scaleDraw) 233 scaleDraw->enableComponent(QwtAbstractScaleDraw::Backbone, false); 234 } 235 } 236 237 void DataPlot2D::BufEvent(char **buf, int *buf_size, uint16_t period, 238 bool big_endian) { 239 plot->setEnabled(IsEnabled()); 240 if (IsEnabled() == false || RefreshRate_ms() != period) 241 return; 242 243 for (int i = 0; i < datas->count(); i++) { 244 if (datas_type->at(i) == "float") { 245 uint32_t data1_raw; 246 float *data1 = (float *)&data1_raw; 247 uint32_t data2_raw; 248 float *data2 = (float *)&data2_raw; 249 250 memcpy((void *)&data1_raw, *buf, sizeof(uint32_t)); 251 *buf += sizeof(uint32_t); 252 memcpy((void *)&data2_raw, *buf, sizeof(uint32_t)); 253 *buf += sizeof(uint32_t); 254 if (big_endian == true) 255 data1_raw = qFromBigEndian(data1_raw); 256 if (big_endian == true) 257 data2_raw = qFromBigEndian(data2_raw); 258 plot_data(*data1, *data2, i); 259 } else if (datas_type->at(i) == "int8_t") { 260 int8_t data1, data2; 261 memcpy((void *)&data1, *buf, sizeof(data1)); 262 *buf += sizeof(data1); 263 memcpy((void *)&data2, *buf, sizeof(data2)); 264 *buf += sizeof(data2); 265 plot_data(data1, data2, i); 266 } else if (datas_type->at(i) == "int16_t") { 267 int16_t data1, data2; 268 memcpy((void *)&data1, *buf, sizeof(data1)); 269 *buf += sizeof(data1); 270 memcpy((void *)&data2, *buf, sizeof(data2)); 271 *buf += sizeof(data2); 272 plot_data(data1, data2, i); 273 } else { 274 printf("DataPlot1D::DrawDatas type non connu\n"); 275 } 276 } 277 278 plot->replot(); 279 } 280 281 void DataPlot2D::plot_data(double data_x, double data_y, int index) { 282 if (index < d_y.count()) { 283 if (datas_first_update.at(index) == false) { 284 // Shift y array left and assign new value to y[view_size/refresh_rate - 285 // 1]. 286 for (int j = 0; j < view_size / refresh_rate - 1; j++) 287 d_y.at(index)[j] = d_y.at(index)[j + 1]; 288 for (int j = 0; j < view_size / refresh_rate - 1; j++) 289 d_x.at(index)[j] = d_x.at(index)[j + 1]; 290 d_y.at(index)[(int)(view_size / refresh_rate) - 1] = data_y; 291 d_x.at(index)[(int)(view_size / refresh_rate) - 1] = data_x; 292 } else { 293 for (int j = 0; j <= view_size / refresh_rate - 1; j++) 294 d_y.at(index)[j] = data_y; 295 for (int j = 0; j <= view_size / refresh_rate - 1; j++) 296 d_x.at(index)[j] = data_x; 297 datas_first_update[index] = false; 298 } 299 } 300 } 301 302 // context menu 303 void DataPlot2D::mousePressEvent(QMouseEvent *event) { 304 if (event->button() == Qt::RightButton) { 305 306 QMenu *menu = new QMenu("nom", plot); 307 // ajout des actions 308 QAction *a, *z, *d; 309 310 a = menu->addAction("reset zoom"); 311 menu->addSeparator(); 312 313 d = menu->addAction(QString("set view size (%1s)").arg(view_size)); 314 315 appendmenu(menu); 316 z = execmenu(plot, menu, event->globalPos()); 317 delete menu; 318 319 if (z == a) { 320 // zoom to original size 321 plot->setAxisScale(QwtPlot::yLeft, ymin_orig, ymax_orig); 322 plot->setAxisScale(QwtPlot::xBottom, xmin_orig, xmax_orig); 323 } 324 325 if (z == d) { 326 bool ok; 327 float time = QInputDialog::getInt( 328 plot, QString("Set view size (%1)").arg(plot->title().text()), 329 tr("Value (s):"), view_size, 1, 65535, 10, &ok); 330 if (ok == true) { 331 for (int i = 0; i < datas->count(); i++) { 332 if (time > view_size) { 333 double *buf = 334 (double *)malloc(time / refresh_rate * sizeof(double)); 335 d_x[i] = (double *)realloc(d_x.at(i), 336 time / refresh_rate * sizeof(double)); 337 memcpy(buf, d_x[i], (view_size / refresh_rate) * sizeof(double)); 338 memcpy(&d_x[i][(int)(time / refresh_rate) - 339 (int)(view_size / refresh_rate)], 340 buf, (view_size / refresh_rate) * sizeof(double)); 341 d_y[i] = (double *)realloc(d_y.at(i), 342 time / refresh_rate * sizeof(double)); 343 memcpy(buf, d_y[i], (view_size / refresh_rate) * sizeof(double)); 344 memcpy(&d_y[i][(int)(time / refresh_rate) - 345 (int)(view_size / refresh_rate)], 346 buf, (view_size / refresh_rate) * sizeof(double)); 347 free(buf); 348 for (int j = 0; j < (int)(time / refresh_rate) - 349 (int)(view_size / refresh_rate); 350 j++) { 351 d_x.at(i)[j] = d_x.at(i)[(int)(time / refresh_rate) - 352 (int)(view_size / refresh_rate) + 1]; 353 d_y.at(i)[j] = d_y.at(i)[(int)(time / refresh_rate) - 354 (int)(view_size / refresh_rate) + 1]; 355 } 356 } else { 357 double *buf = 358 (double *)malloc(time / refresh_rate * sizeof(double)); 359 memcpy(buf, &d_x[i][(int)(view_size / refresh_rate) - 360 (int)(time / refresh_rate)], 361 (time / refresh_rate) * sizeof(double)); 362 d_x[i] = (double *)realloc(d_x.at(i), 363 time / refresh_rate * sizeof(double)); 364 memcpy(d_x[i], buf, (time / refresh_rate) * sizeof(double)); 365 memcpy(buf, &d_y[i][(int)(view_size / refresh_rate) - 366 (int)(time / refresh_rate)], 367 (time / refresh_rate) * sizeof(double)); 368 d_y[i] = (double *)realloc(d_y.at(i), 369 time / refresh_rate * sizeof(double)); 370 memcpy(d_y[i], buf, (time / refresh_rate) * sizeof(double)); 371 free(buf); 372 } 373 datas->at(i) 374 ->setRawSamples(d_x.at(i), d_y.at(i), time / refresh_rate); 278 375 } 279 else if(datas_type->at(i)=="int8_t") 280 { 281 int8_t data1,data2; 282 memcpy((void*)&data1,*buf,sizeof(data1)); 283 *buf+=sizeof(data1); 284 memcpy((void*)&data2,*buf,sizeof(data2)); 285 *buf+=sizeof(data2); 286 plot_data(data1,data2,i); 287 } 288 else if(datas_type->at(i)=="int16_t") 289 { 290 int16_t data1,data2; 291 memcpy((void*)&data1,*buf,sizeof(data1)); 292 *buf+=sizeof(data1); 293 memcpy((void*)&data2,*buf,sizeof(data2)); 294 *buf+=sizeof(data2); 295 plot_data(data1,data2,i); 296 } 297 else 298 { 299 printf("DataPlot1D::DrawDatas type non connu\n"); 300 } 301 } 302 303 plot->replot(); 304 } 305 306 void DataPlot2D::plot_data(double data_x,double data_y,int index) 307 { 308 if(index<d_y.count()) 309 { 310 if(datas_first_update.at(index)==false) 311 { 312 // Shift y array left and assign new value to y[view_size/refresh_rate - 1]. 313 for ( int j = 0; j < view_size/refresh_rate - 1; j++ ) d_y.at(index)[j] = d_y.at(index)[j+1] ; 314 for ( int j = 0; j < view_size/refresh_rate - 1; j++ ) d_x.at(index)[j] = d_x.at(index)[j+1] ; 315 d_y.at(index)[(int)(view_size/refresh_rate) - 1] = data_y; 316 d_x.at(index)[(int)(view_size/refresh_rate) - 1] = data_x; 317 } 318 else 319 { 320 for ( int j = 0; j <= view_size/refresh_rate - 1; j++ ) d_y.at(index)[j] = data_y; 321 for ( int j = 0; j <= view_size/refresh_rate - 1; j++ ) d_x.at(index)[j] = data_x; 322 datas_first_update[index]=false; 323 } 324 } 325 } 326 327 328 //context menu 329 void DataPlot2D::mousePressEvent(QMouseEvent *event) 330 { 331 if (event->button() == Qt::RightButton) 332 { 333 334 QMenu * menu = new QMenu("nom", plot); 335 // ajout des actions 336 QAction *a,*z,*d; 337 338 a=menu->addAction("reset zoom"); 339 menu->addSeparator(); 340 341 d=menu->addAction(QString("set view size (%1s)").arg(view_size)); 342 343 appendmenu(menu); 344 z=execmenu(plot,menu,event->globalPos()); 345 delete menu; 346 347 if(z==a) 348 { 349 //zoom to original size 350 plot->setAxisScale(QwtPlot::yLeft, ymin_orig, ymax_orig); 351 plot->setAxisScale(QwtPlot::xBottom, xmin_orig, xmax_orig); 352 } 353 354 if(z==d) 355 { 356 bool ok; 357 float time = QInputDialog::getInt(plot, QString("Set view size (%1)").arg(plot->title().text()),tr("Value (s):"), view_size, 1, 65535, 10, &ok); 358 if(ok==true) 359 { 360 for(int i=0;i<datas->count();i++) 361 { 362 if(time>view_size) 363 { 364 double* buf=(double*)malloc(time/refresh_rate*sizeof(double)); 365 d_x[i]=(double*)realloc(d_x.at(i),time/refresh_rate*sizeof(double)); 366 memcpy(buf,d_x[i],(view_size/refresh_rate)*sizeof(double)); 367 memcpy(&d_x[i][(int)(time/refresh_rate)-(int)(view_size/refresh_rate)],buf,(view_size/refresh_rate)*sizeof(double)); 368 d_y[i]=(double*)realloc(d_y.at(i),time/refresh_rate*sizeof(double)); 369 memcpy(buf,d_y[i],(view_size/refresh_rate)*sizeof(double)); 370 memcpy(&d_y[i][(int)(time/refresh_rate)-(int)(view_size/refresh_rate)],buf,(view_size/refresh_rate)*sizeof(double)); 371 free(buf); 372 for(int j=0;j<(int)(time/refresh_rate)-(int)(view_size/refresh_rate);j++) 373 { 374 d_x.at(i)[j]=d_x.at(i)[(int)(time/refresh_rate)-(int)(view_size/refresh_rate)+1]; 375 d_y.at(i)[j]=d_y.at(i)[(int)(time/refresh_rate)-(int)(view_size/refresh_rate)+1]; 376 } 377 } 378 else 379 { 380 double* buf=(double*)malloc(time/refresh_rate*sizeof(double)); 381 memcpy(buf,&d_x[i][(int)(view_size/refresh_rate)-(int)(time/refresh_rate)],(time/refresh_rate)*sizeof(double)); 382 d_x[i]=(double*)realloc(d_x.at(i),time/refresh_rate*sizeof(double)); 383 memcpy(d_x[i],buf,(time/refresh_rate)*sizeof(double)); 384 memcpy(buf,&d_y[i][(int)(view_size/refresh_rate)-(int)(time/refresh_rate)],(time/refresh_rate)*sizeof(double)); 385 d_y[i]=(double*)realloc(d_y.at(i),time/refresh_rate*sizeof(double)); 386 memcpy(d_y[i],buf,(time/refresh_rate)*sizeof(double)); 387 free(buf); 388 } 389 datas->at(i)->setRawSamples(d_x.at(i), d_y.at(i), time/refresh_rate); 390 391 } 392 view_size=time; 393 394 } 395 } 396 } 397 } 376 view_size = time; 377 } 378 } 379 } 380 } -
trunk/tools/FlairGCS/src/DataPlot2D.h
r10 r15 16 16 class QMouseEvent; 17 17 18 class DataPlot2D : public DataRemote 19 { 20 Q_OBJECT 18 class DataPlot2D : public DataRemote { 19 Q_OBJECT 21 20 22 public: 23 DataPlot2D(Layout* parent,int row, int col,QString plot_name,QString x_name,QString y_name,float xmin, float xmax,float ymin, float ymax,bool enabled,int period); 24 ~DataPlot2D(); 25 void addCurve(QPen pen,QString legend,QString type); 21 public: 22 DataPlot2D(Layout *parent, int row, int col, QString plot_name, 23 QString x_name, QString y_name, float xmin, float xmax, float ymin, 24 float ymax, bool enabled, int period); 25 ~DataPlot2D(); 26 void addCurve(QPen pen, QString legend, QString type); 26 27 27 28 28 protected: 29 void mousePressEvent(QMouseEvent *event); 29 30 30 31 QwtPlot*plot;32 33 34 void plot_data(double data_x,double data_y,int index);35 float xmin_orig,xmax_orig,ymin_orig,ymax_orig;31 private: 32 QwtPlot *plot; 33 void XmlEvent(QDomElement dom); 34 void alignScales(void); 35 void plot_data(double data_x, double data_y, int index); 36 float xmin_orig, xmax_orig, ymin_orig, ymax_orig; 36 37 37 QList<QwtPlotCurve*> *datas;38 39 40 QList<double*> d_x;41 QList<double*> d_y;42 double view_size;//en s38 QList<QwtPlotCurve *> *datas; 39 QList<QString> *datas_type; 40 QList<bool> datas_first_update; 41 QList<double *> d_x; 42 QList<double *> d_y; 43 double view_size; // en s 43 44 44 45 void setYAxisScale(float ymin,float ymax);46 void setXAxisScale(float xmin,float xmax);47 void BufEvent(char** buf,int *buf_size,uint16_t period,bool big_endian);48 45 bool eventFilter(QObject *, QEvent *); 46 void setYAxisScale(float ymin, float ymax); 47 void setXAxisScale(float xmin, float xmax); 48 void BufEvent(char **buf, int *buf_size, uint16_t period, bool big_endian); 49 void showCurve(QwtPlotItem *item, bool on); 49 50 50 51 void legendChecked( const QVariant &itemInfo, bool on);51 private slots: 52 void legendChecked(const QVariant &itemInfo, bool on); 52 53 }; 53 54 54 55 55 #endif // DATAPLOT2D_H_INCLUDED -
trunk/tools/FlairGCS/src/DataRemote.cpp
r10 r15 10 10 #include "ConnectionLayout.h" 11 11 12 DataRemote::DataRemote(QString name,QString type,XmlWidget* parent,bool enabled,int period):XmlWidget(name,type,parent) { 13 auto_refresh=enabled; 14 is_logging=true; 15 receivesize=0; 16 refresh_rate=(double)period/1000.; 12 DataRemote::DataRemote(QString name, QString type, XmlWidget *parent, 13 bool enabled, int period) 14 : XmlWidget(name, type, parent) { 15 auto_refresh = enabled; 16 is_logging = true; 17 receivesize = 0; 18 refresh_rate = (double)period / 1000.; 17 19 18 20 connectionLayout()->addDataRemote(this); 19 21 20 //pour ne pas faire de doublons qd on change la periode21 22 // pour ne pas faire de doublons qd on change la periode 23 SetIsExpandable(true); 22 24 } 23 25 24 DataRemote::~DataRemote() { 25 connectionLayout()->removeDataRemote(this); 26 DataRemote::~DataRemote() { connectionLayout()->removeDataRemote(this); } 27 28 void DataRemote::appendmenu(QMenu *menu) { 29 menu->addSeparator(); 30 31 b = menu->addAction("auto refresh"); 32 b->setCheckable(true); 33 b->setChecked(auto_refresh); 34 35 c = menu->addAction(QString("set refresh rate (%1ms)") 36 .arg((uint16_t)(qRound(refresh_rate * 1000)))); 37 c->setEnabled(auto_refresh); 38 menu->addSeparator(); 39 40 d = menu->addAction("log"); 41 d->setCheckable(true); 42 d->setChecked(is_logging); 26 43 } 27 44 28 void DataRemote::appendmenu(QMenu * menu) {29 menu->addSeparator();45 QAction *DataRemote::execmenu(QWidget *parent, QMenu *menu, QPoint point) { 46 QAction *z; 30 47 31 b=menu->addAction("auto refresh"); 32 b->setCheckable(true); 33 b->setChecked(auto_refresh); 48 z = menu->exec(point); 34 49 35 c=menu->addAction(QString("set refresh rate (%1ms)").arg((uint16_t)(qRound(refresh_rate*1000)))); 36 c->setEnabled(auto_refresh); 37 menu->addSeparator(); 50 // auto_refresh=b->isChecked(); 38 51 39 d=menu->addAction("log"); 40 d->setCheckable(true); 41 d->setChecked(is_logging); 42 } 52 if (z == b) { 53 SendPeriod(RefreshRate_ms(), b->isChecked()); 54 } 43 55 44 QAction* DataRemote::execmenu(QWidget* parent,QMenu * menu,QPoint point) { 45 QAction *z; 56 if (z == c) { 57 bool ok; 58 // uint16_t time = QInputDialog::getInt(this, QString("Set refresh rate 59 // (%1)").arg(title().text()),tr("Value (ms):"), 60 // (uint16_t)(qRound(refresh_rate*1000)), 1, 65535, 10, &ok); 61 uint16_t time = QInputDialog::getInt( 62 parent, "Set refresh rate ", "Value (ms):", 63 (uint16_t)(qRound(refresh_rate * 1000)), 1, 65535, 10, &ok); 64 if (ok == true && time != qRound(refresh_rate * 1000)) { 65 // refresh_rate=time/1000.; 66 SendPeriod(time, b->isChecked()); 67 } 68 } 46 69 47 z=menu->exec(point); 48 49 //auto_refresh=b->isChecked(); 50 51 if(z==b) { 52 SendPeriod(RefreshRate_ms(),b->isChecked()); 53 } 54 55 if(z==c) { 56 bool ok; 57 //uint16_t time = QInputDialog::getInt(this, QString("Set refresh rate (%1)").arg(title().text()),tr("Value (ms):"), (uint16_t)(qRound(refresh_rate*1000)), 1, 65535, 10, &ok); 58 uint16_t time = QInputDialog::getInt(parent, "Set refresh rate ","Value (ms):", (uint16_t)(qRound(refresh_rate*1000)), 1, 65535, 10, &ok); 59 if(ok==true && time!=qRound(refresh_rate*1000)) { 60 //refresh_rate=time/1000.; 61 SendPeriod(time,b->isChecked()); 62 } 63 } 64 65 return z; 70 return z; 66 71 } 67 72 68 73 uint16_t DataRemote::RefreshRate_ms(void) { 69 return (uint16_t)(qRound(refresh_rate*1000.));74 return (uint16_t)(qRound(refresh_rate * 1000.)); 70 75 } 71 76 72 bool DataRemote::IsEnabled(void) { 73 return auto_refresh; 77 bool DataRemote::IsEnabled(void) { return auto_refresh; } 78 79 void DataRemote::SendPeriod(int period, bool auto_refresh) { 80 SetAttribute("period", period); 81 SetAttribute("enabled", auto_refresh); 82 83 connectionLayout()->XmlToSend(XmlDoc()); 84 85 RemoveAttribute("period"); 86 RemoveAttribute("enabled"); 74 87 } 75 88 76 void DataRemote::SendPeriod(int period,bool auto_refresh) { 77 SetAttribute("period", period); 78 SetAttribute("enabled", auto_refresh); 79 80 connectionLayout()->XmlToSend(XmlDoc()); 81 82 RemoveAttribute("period"); 83 RemoveAttribute("enabled"); 84 } 85 86 int DataRemote::ReceiveSize(void) { 87 return receivesize; 88 } 89 int DataRemote::ReceiveSize(void) { return receivesize; } 89 90 90 91 void DataRemote::XmlSetup(QDomElement dom) { 91 refresh_rate=dom.attribute("period").toInt()/1000.;92 if(dom.attribute("enabled")=="1")93 auto_refresh=true;94 95 auto_refresh=false;92 refresh_rate = dom.attribute("period").toInt() / 1000.; 93 if (dom.attribute("enabled") == "1") 94 auto_refresh = true; 95 else 96 auto_refresh = false; 96 97 } -
trunk/tools/FlairGCS/src/DataRemote.h
r10 r15 13 13 class QAction; 14 14 15 class DataRemote: public XmlWidget 16 { 17 public: 18 DataRemote(QString name,QString type,XmlWidget* parent,bool enabled,int period); 19 ~DataRemote(); 20 uint16_t RefreshRate_ms(void); 21 bool IsEnabled(void); 22 int ReceiveSize(void); 23 virtual void BufEvent(char** buf,int *buf_size,uint16_t period,bool big_endian)=0; 24 void appendmenu(QMenu * menu); 25 QAction* execmenu(QWidget* parent,QMenu * menu,QPoint point); 15 class DataRemote : public XmlWidget { 16 public: 17 DataRemote(QString name, QString type, XmlWidget *parent, bool enabled, 18 int period); 19 ~DataRemote(); 20 uint16_t RefreshRate_ms(void); 21 bool IsEnabled(void); 22 int ReceiveSize(void); 23 virtual void BufEvent(char **buf, int *buf_size, uint16_t period, 24 bool big_endian) = 0; 25 void appendmenu(QMenu *menu); 26 QAction *execmenu(QWidget *parent, QMenu *menu, QPoint point); 26 27 27 28 29 30 double refresh_rate;//en s31 28 protected: 29 bool auto_refresh; 30 bool is_logging; 31 double refresh_rate; // en s 32 int receivesize; 32 33 33 34 void XmlSetup(QDomElement dom); 34 35 35 36 void SendPeriod(int period,bool auto_refresh);37 QAction *b,*c,*d;36 private: 37 void SendPeriod(int period, bool auto_refresh); 38 QAction *b, *c, *d; 38 39 }; 39 40 -
trunk/tools/FlairGCS/src/DoubleSpinBox.cpp
r10 r15 11 11 #include <QFormLayout> 12 12 13 DoubleSpinBox::DoubleSpinBox(Layout* parent,int row, int col,QString name,QString suffix,QString value,float min,float max,float step,int decimals): FormLayout(parent,row,col,name,"DoubleSpinBox") 14 { 15 doublespinbox = new QDoubleSpinBox(); 13 DoubleSpinBox::DoubleSpinBox(Layout *parent, int row, int col, QString name, 14 QString suffix, QString value, float min, 15 float max, float step, int decimals) 16 : FormLayout(parent, row, col, name, "DoubleSpinBox") { 17 doublespinbox = new QDoubleSpinBox(); 16 18 17 doublespinbox->setRange(min,max); 18 doublespinbox->setSingleStep(step); 19 doublespinbox->setDecimals(decimals); 20 if(suffix!="") doublespinbox->setSuffix(suffix); 21 adjust_decimals(value); 22 doublespinbox->setValue(value.toDouble()); 23 doublespinbox_value=doublespinbox->cleanText(); 19 doublespinbox->setRange(min, max); 20 doublespinbox->setSingleStep(step); 21 doublespinbox->setDecimals(decimals); 22 if (suffix != "") 23 doublespinbox->setSuffix(suffix); 24 adjust_decimals(value); 25 doublespinbox->setValue(value.toDouble()); 26 doublespinbox_value = doublespinbox->cleanText(); 24 27 25 //event filter for qdoublespinbox and its child (qlinedit and incremnt qbuttons)26 doublespinbox->installEventFilter(this);27 QObjectList o_list = doublespinbox->children();28 for(int i = 0; i < o_list.length(); i++)29 30 QLineEdit *cast = qobject_cast<QLineEdit*>(o_list[i]);31 if(cast)32 33 28 // event filter for qdoublespinbox and its child (qlinedit and incremnt 29 // qbuttons) 30 doublespinbox->installEventFilter(this); 31 QObjectList o_list = doublespinbox->children(); 32 for (int i = 0; i < o_list.length(); i++) { 33 QLineEdit *cast = qobject_cast<QLineEdit *>(o_list[i]); 34 if (cast) 35 cast->installEventFilter(this); 36 } 34 37 35 object_layout->addRow(name,doublespinbox);38 object_layout->addRow(name, doublespinbox); 36 39 37 connect(doublespinbox,SIGNAL(valueChanged(const QString &)),this, SLOT(valuechanged(const QString &))); 40 connect(doublespinbox, SIGNAL(valueChanged(const QString &)), this, 41 SLOT(valuechanged(const QString &))); 38 42 39 43 SetValue(value); 40 44 } 41 45 42 DoubleSpinBox::~DoubleSpinBox() 43 { 44 delete doublespinbox; 46 DoubleSpinBox::~DoubleSpinBox() { delete doublespinbox; } 47 48 void DoubleSpinBox::adjust_decimals(QString value) { 49 // auto adjust decimals 50 QLocale locale; 51 value.remove(locale.groupSeparator()); 52 53 QStringList parts = value.split(locale.decimalPoint()); 54 if (parts.count() == 2) { 55 doublespinbox->setDecimals(parts[1].size()); 56 } 45 57 } 46 58 47 void DoubleSpinBox::adjust_decimals(QString value) 48 {49 //auto adjust decimals50 QLocale locale;51 value.remove(locale.groupSeparator());59 bool DoubleSpinBox::eventFilter(QObject *object, QEvent *event) { 60 if (object == doublespinbox && event->type() == QEvent::MouseButtonPress) { 61 if (((QMouseEvent *)event)->button() == Qt::RightButton) { 62 QMenu *menu = new QMenu("menu", doublespinbox); 63 QAction *a, *b, *c, *z; 52 64 53 QStringList parts = value.split(locale.decimalPoint()); 54 if(parts.count() == 2) 55 { 56 doublespinbox->setDecimals(parts[1].size()); 65 a = menu->addAction("add decimal"); 66 b = menu->addAction("remove decimal"); 67 68 if (doublespinbox->decimals() == 0) 69 b->setEnabled(false); 70 z = menu->exec(((QMouseEvent *)event)->globalPos()); 71 72 if (z == a) 73 doublespinbox->setDecimals(doublespinbox->decimals() + 1); 74 if (z == b) 75 doublespinbox->setDecimals(doublespinbox->decimals() - 1); 76 delete menu; 77 return true; 57 78 } 79 } 80 81 return object->eventFilter(object, event); 58 82 } 59 83 60 bool DoubleSpinBox::eventFilter(QObject *object, QEvent *event) 61 { 62 if(object==doublespinbox && event->type()==QEvent::MouseButtonPress) 63 { 64 if (((QMouseEvent*)event)->button() == Qt::RightButton) 65 { 66 QMenu * menu = new QMenu("menu", doublespinbox); 67 QAction *a,*b,*c,*z; 68 69 a=menu->addAction("add decimal"); 70 b=menu->addAction("remove decimal"); 71 72 if(doublespinbox->decimals()==0) b->setEnabled(false); 73 z=menu->exec(((QMouseEvent*)event)->globalPos()); 74 75 if(z==a) doublespinbox->setDecimals(doublespinbox->decimals()+1); 76 if(z==b) doublespinbox->setDecimals(doublespinbox->decimals()-1); 77 delete menu; 78 return true; 79 } 80 } 81 82 return object->eventFilter(object, event); 84 void DoubleSpinBox::SetUptodate(void) { 85 ui_to_var(); 86 ui_to_xml(); 87 visible_widget->setPalette(black_pal); 83 88 } 84 89 85 void DoubleSpinBox::SetUptodate(void) 86 { 87 ui_to_var(); 88 ui_to_xml(); 89 visible_widget->setPalette(black_pal); 90 void DoubleSpinBox::ui_to_var(void) { 91 doublespinbox_value = doublespinbox->cleanText(); 90 92 } 91 93 92 void DoubleSpinBox::ui_to_var(void) 93 { 94 doublespinbox_value=doublespinbox->cleanText(); 94 void DoubleSpinBox::ui_to_xml(void) { SetValue(doublespinbox->cleanText()); } 95 96 void DoubleSpinBox::Reset(void) { 97 // le setvalue fait un arrondi pour l'affichage, la variable n'est donc plus 98 // egale 99 // on reprend la valeur de la boite et on force la couleur a noir 100 adjust_decimals(doublespinbox_value); 101 doublespinbox->setValue(doublespinbox_value.toDouble()); 102 doublespinbox_value = doublespinbox->cleanText(); 103 visible_widget->setPalette(black_pal); 95 104 } 96 105 97 void DoubleSpinBox::ui_to_xml(void) 98 { 99 SetValue(doublespinbox->cleanText()); 106 void DoubleSpinBox::LoadEvent(QDomElement dom) { 107 if (doublespinbox->isEnabled() == true) { 108 doublespinbox->setValue((dom.attribute("value")).toDouble()); 109 } 100 110 } 101 111 102 void DoubleSpinBox::Reset(void) 103 { 104 //le setvalue fait un arrondi pour l'affichage, la variable n'est donc plus egale 105 //on reprend la valeur de la boite et on force la couleur a noir 106 adjust_decimals(doublespinbox_value); 107 doublespinbox->setValue(doublespinbox_value.toDouble()); 108 doublespinbox_value= doublespinbox->cleanText(); 112 void DoubleSpinBox::valuechanged(const QString &value) { 113 if (value != doublespinbox_value) { 114 visible_widget->setPalette(red_pal); 115 } else { 109 116 visible_widget->setPalette(black_pal); 110 117 } 111 118 } 112 113 void DoubleSpinBox::LoadEvent(QDomElement dom)114 {115 if(doublespinbox->isEnabled()==true)116 {117 doublespinbox->setValue((dom.attribute("value")).toDouble());118 }119 }120 121 void DoubleSpinBox::valuechanged(const QString &value)122 {123 if(value!=doublespinbox_value)124 {125 visible_widget->setPalette(red_pal);126 }127 else128 {129 visible_widget->setPalette(black_pal);130 }131 } -
trunk/tools/FlairGCS/src/DoubleSpinBox.h
r10 r15 11 11 class QDoubleSpinBox; 12 12 13 class DoubleSpinBox: public FormLayout 14 { 15 Q_OBJECT 13 class DoubleSpinBox : public FormLayout { 14 Q_OBJECT 16 15 17 public: 18 //handle value as string, becouse double value are not exact 19 DoubleSpinBox(Layout* parent,int row, int col,QString name,QString suffix,QString value,float min,float max,float step,int decimals); 20 ~DoubleSpinBox(); 16 public: 17 // handle value as string, becouse double value are not exact 18 DoubleSpinBox(Layout *parent, int row, int col, QString name, QString suffix, 19 QString value, float min, float max, float step, int decimals); 20 ~DoubleSpinBox(); 21 21 22 23 QDoubleSpinBox*doublespinbox;24 25 26 27 28 29 30 31 22 private: 23 QDoubleSpinBox *doublespinbox; 24 QString doublespinbox_value; 25 void SetUptodate(void); 26 void Reset(void); 27 void LoadEvent(QDomElement dom); 28 void ui_to_var(void); 29 void ui_to_xml(void); 30 bool eventFilter(QObject *o, QEvent *e); 31 void adjust_decimals(QString value); 32 32 33 34 33 private slots: 34 void valuechanged(const QString &value); 35 35 }; 36 36 -
trunk/tools/FlairGCS/src/FormLayout.cpp
r10 r15 9 9 #include <QEvent> 10 10 11 FormLayout::FormLayout(Layout* parent,int row, int col,QString name,QString type):XmlWidget(name,type,parent) 12 { 13 visible_widget=new QWidget(); 11 FormLayout::FormLayout(Layout *parent, int row, int col, QString name, 12 QString type) 13 : XmlWidget(name, type, parent) { 14 visible_widget = new QWidget(); 14 15 15 //create a grid to put label and object16 16 // create a grid to put label and object 17 visible_widget->setObjectName(name); 17 18 18 parent->addWidget(visible_widget,row,col);19 20 21 22 object_layout->setContentsMargins (2,2,2,2);19 parent->addWidget(visible_widget, row, col); 20 object_layout = new QFormLayout(visible_widget); 21 object_layout->setHorizontalSpacing(2); 22 object_layout->setVerticalSpacing(2); 23 object_layout->setContentsMargins(2, 2, 2, 2); 23 24 24 25 visible_widget->installEventFilter(this); 25 26 } 26 27 27 FormLayout::~FormLayout() 28 { 28 FormLayout::~FormLayout() {} 29 30 bool FormLayout::IsUptodate(void) { 31 // si le widget n'est pas enabled, sa palette est differente de rouge (greyed) 32 // donc on renvoit true 33 // permet de ne pas envoyer les modifs d'un widget disabled 34 // if(label->palette()==red_pal) return false; 35 if (visible_widget->palette() == red_pal) 36 return false; 37 return true; 29 38 } 30 39 31 bool FormLayout::IsUptodate(void) 32 { 33 //si le widget n'est pas enabled, sa palette est differente de rouge (greyed) donc on renvoit true 34 //permet de ne pas envoyer les modifs d'un widget disabled 35 //if(label->palette()==red_pal) return false; 36 if(visible_widget->palette()==red_pal) return false; 37 return true; 40 bool FormLayout::eventFilter(QObject *o, QEvent *e) { 41 if (o == visible_widget) { 42 switch (e->type()) { 43 case QEvent::EnabledChange: { 44 QPalette palette = visible_widget->palette(); 45 QPalette result; 46 47 if (palette == red_pal) 48 result = red_pal_greyed; 49 if (palette == red_pal_greyed) 50 result = red_pal; 51 if (palette == black_pal) 52 result = black_pal_greyed; 53 if (palette == black_pal_greyed) 54 result = black_pal; 55 56 visible_widget->setPalette(result); 57 } 58 59 default: 60 break; 61 } 62 } 63 return QObject::eventFilter(o, e); 38 64 } 39 40 bool FormLayout::eventFilter(QObject *o, QEvent *e)41 {42 if ( o == visible_widget )43 {44 switch(e->type())45 {46 case QEvent::EnabledChange:47 {48 QPalette palette=visible_widget->palette();49 QPalette result;50 51 if(palette==red_pal) result=red_pal_greyed;52 if(palette==red_pal_greyed) result=red_pal;53 if(palette==black_pal) result=black_pal_greyed;54 if(palette==black_pal_greyed) result=black_pal;55 56 visible_widget->setPalette(result);57 }58 59 default:60 break;61 }62 63 }64 return QObject::eventFilter(o, e);65 } -
trunk/tools/FlairGCS/src/FormLayout.h
r10 r15 11 11 class Layout; 12 12 13 class FormLayout: public XmlWidget 14 { 13 class FormLayout : public XmlWidget { 15 14 16 17 FormLayout(Layout* parent,int row, int col,QString name,QString type);18 15 public: 16 FormLayout(Layout *parent, int row, int col, QString name, QString type); 17 ~FormLayout(); 19 18 20 21 22 virtual void SetUptodate(void)=0;23 19 private: 20 bool IsUptodate(void); 21 virtual void SetUptodate(void) = 0; 22 bool eventFilter(QObject *o, QEvent *e); 24 23 25 26 QFormLayout*object_layout;24 protected: 25 QFormLayout *object_layout; 27 26 }; 28 27 -
trunk/tools/FlairGCS/src/GridLayout.cpp
r10 r15 7 7 #include <QGridLayout> 8 8 9 GridLayout::GridLayout(Layout * parent,int row, int col,QString name): Layout(parent,name,"GridLayout")10 {11 12 9 GridLayout::GridLayout(Layout *parent, int row, int col, QString name) 10 : Layout(parent, name, "GridLayout") { 11 widget = new QWidget(); 12 widget->setObjectName(name); 13 13 14 visible_widget=widget;14 visible_widget = widget; 15 15 16 parent->addWidget(widget,row,col);16 parent->addWidget(widget, row, col); 17 17 18 18 widget->setLayout(getQGridLayout()); 19 19 } 20 20 21 22 GridLayout::~GridLayout() 23 { 24 widget->setParent(NULL); 25 } 21 GridLayout::~GridLayout() { widget->setParent(NULL); } -
trunk/tools/FlairGCS/src/GridLayout.h
r10 r15 8 8 #include "Layout.h" 9 9 10 class GridLayout: public Layout 11 { 10 class GridLayout : public Layout { 12 11 13 14 GridLayout(Layout* parent,int row, int col,QString name);15 12 public: 13 GridLayout(Layout *parent, int row, int col, QString name); 14 ~GridLayout(); 16 15 17 18 QWidget*widget;16 private: 17 QWidget *widget; 19 18 }; 20 19 -
trunk/tools/FlairGCS/src/GroupBox.cpp
r10 r15 7 7 #include <QGridLayout> 8 8 9 GroupBox::GroupBox(Layout * parent,int row, int col,QString name): Layout(parent,name,"GroupBox")10 {11 //creation et ajout QGroupBox12 13 9 GroupBox::GroupBox(Layout *parent, int row, int col, QString name) 10 : Layout(parent, name, "GroupBox") { 11 // creation et ajout QGroupBox 12 box = new QGroupBox(name); 13 box->setObjectName(name); 14 14 15 visible_widget=box;15 visible_widget = box; 16 16 17 parent->addWidget(box,row,col);18 //parent->splitter->addWidget(box);17 parent->addWidget(box, row, col); 18 // parent->splitter->addWidget(box); 19 19 20 20 box->setLayout(getQGridLayout()); 21 21 } 22 22 23 GroupBox::~GroupBox() { 24 // layout->removeItem(this);//ne semble pas necessaire 23 25 24 GroupBox::~GroupBox() 25 { 26 //layout->removeItem(this);//ne semble pas necessaire 27 28 box->setParent(NULL);//sinon le delete layout detruit aussi this 29 //delete layout; 30 //delete box; 26 box->setParent(NULL); // sinon le delete layout detruit aussi this 27 // delete layout; 28 // delete box; 31 29 } -
trunk/tools/FlairGCS/src/GroupBox.h
r10 r15 10 10 class QGroupBox; 11 11 12 class GroupBox: public Layout 13 { 12 class GroupBox : public Layout { 14 13 15 16 GroupBox(Layout* parent,int row, int col,QString name);17 14 public: 15 GroupBox(Layout *parent, int row, int col, QString name); 16 ~GroupBox(); 18 17 19 20 QGroupBox*box;18 private: 19 QGroupBox *box; 21 20 }; 22 21 -
trunk/tools/FlairGCS/src/Label.cpp
r10 r15 7 7 #include <QLabel> 8 8 9 Label::Label(Layout * parent,int row, int col,QString name):XmlWidget(name,"Label",parent)10 {9 Label::Label(Layout *parent, int row, int col, QString name) 10 : XmlWidget(name, "Label", parent) { 11 11 12 13 14 visible_widget=label;12 label = new QLabel(); 13 label->setObjectName(name); 14 visible_widget = label; 15 15 16 parent->addWidget(label,row,col);16 parent->addWidget(label, row, col); 17 17 18 //pour ne pas faire de doublons qd on change le texte19 18 // pour ne pas faire de doublons qd on change le texte 19 SetIsExpandable(true); 20 20 } 21 21 22 Label::~Label() 23 { 22 Label::~Label() {} 24 23 24 void Label::XmlEvent(QDomElement dom) { 25 label->setText(dom.attribute("value")); 25 26 } 26 27 void Label::XmlEvent(QDomElement dom)28 {29 label->setText(dom.attribute("value"));30 } -
trunk/tools/FlairGCS/src/Label.h
r10 r15 11 11 class QLabel; 12 12 13 class Label: public XmlWidget 14 { 15 public: 16 Label(Layout* parent,int row, int col,QString name); 17 ~Label(); 13 class Label : public XmlWidget { 14 public: 15 Label(Layout *parent, int row, int col, QString name); 16 ~Label(); 18 17 19 private: 20 void XmlEvent(QDomElement dom); 21 QLabel *label; 22 23 18 private: 19 void XmlEvent(QDomElement dom); 20 QLabel *label; 24 21 }; 25 22 -
trunk/tools/FlairGCS/src/Landmark.cpp
r10 r15 11 11 using namespace QtMobility; 12 12 13 Landmark::Landmark(QGraphicsGeoMap *geoMap, const QGeoCoordinate &coordinate, QString name,QString type)14 {15 16 this->geoMap=geoMap;17 18 13 Landmark::Landmark(QGraphicsGeoMap *geoMap, const QGeoCoordinate &coordinate, 14 QString name, QString type) { 15 geoMap->addMapObject(this); 16 this->geoMap = geoMap; 17 pixmap = new QGeoMapPixmapObject(); 18 pixmap->setCoordinate(coordinate); 19 19 20 if(type=="cross") 21 { 22 pixmap->setOffset(QPoint(-16, -16)); 23 pixmap->setPixmap(QPixmap(":cross.png")); 24 } 25 else 26 { 27 pixmap->setOffset(QPoint(-2, -30)); 28 pixmap->setPixmap(QPixmap(":landmark.png")); 29 } 30 addChildObject(pixmap); 20 if (type == "cross") { 21 pixmap->setOffset(QPoint(-16, -16)); 22 pixmap->setPixmap(QPixmap(":cross.png")); 23 } else { 24 pixmap->setOffset(QPoint(-2, -30)); 25 pixmap->setPixmap(QPixmap(":landmark.png")); 26 } 27 addChildObject(pixmap); 31 28 32 33 34 text = new QGeoMapTextObject(coordinate,name, font, QPoint(0, 10));35 36 37 29 QFont font; 30 font.setWeight(QFont::Bold); 31 text = new QGeoMapTextObject(coordinate, name, font, QPoint(0, 10)); 32 text->setPen(QPen(Qt::NoPen)); 33 text->setBrush(QBrush(Qt::red)); 34 addChildObject(text); 38 35 } 39 36 40 Landmark::~Landmark() 41 { 42 geoMap->removeMapObject(this); 43 clearChildObjects(); 37 Landmark::~Landmark() { 38 geoMap->removeMapObject(this); 39 clearChildObjects(); 44 40 } 45 41 46 void Landmark::setText(QString string) 47 { 48 text->setText(string); 42 void Landmark::setText(QString string) { text->setText(string); } 43 44 void Landmark::setColor(Qt::GlobalColor color) { 45 text->setBrush(QBrush(color)); 49 46 } 50 47 51 void Landmark::setCo lor(Qt::GlobalColor color)52 { 53 text->setBrush(QBrush(color));48 void Landmark::setCoordinate(const QGeoCoordinate &coordinate) { 49 pixmap->setCoordinate(coordinate); 50 text->setCoordinate(coordinate); 54 51 } 55 52 56 void Landmark::setCoordinate(const QGeoCoordinate &coordinate) 57 { 58 pixmap->setCoordinate(coordinate); 59 text->setCoordinate(coordinate); 53 QGeoCoordinate Landmark::coordinate(void) { return pixmap->coordinate(); } 54 55 void Landmark::RemoveLandmark(void) { geoMap->removeMapObject(this); } 56 57 void Landmark::AddLandmark(QGraphicsGeoMap *geoMap) { 58 geoMap->addMapObject(this); 59 this->geoMap = geoMap; 60 60 } 61 62 QGeoCoordinate Landmark::coordinate(void)63 {64 return pixmap->coordinate();65 }66 67 void Landmark::RemoveLandmark(void)68 {69 geoMap->removeMapObject(this);70 }71 72 void Landmark::AddLandmark(QGraphicsGeoMap *geoMap)73 {74 geoMap->addMapObject(this);75 this->geoMap=geoMap;76 } -
trunk/tools/FlairGCS/src/Landmark.h
r10 r15 10 10 11 11 namespace QtMobility { 12 13 14 12 class QGraphicsGeoMap; 13 class QGeoMapTextObject; 14 class QGeoMapPixmapObject; 15 15 } 16 16 17 18 class Landmark : public QtMobility::QGeoMapGroupObject 19 { 17 class Landmark : public QtMobility::QGeoMapGroupObject { 20 18 21 19 public: 22 Landmark(QtMobility::QGraphicsGeoMap *geoMap,const QtMobility::QGeoCoordinate &coordinate,QString name,QString type="landmark"); 23 ~Landmark(); 20 Landmark(QtMobility::QGraphicsGeoMap *geoMap, 21 const QtMobility::QGeoCoordinate &coordinate, QString name, 22 QString type = "landmark"); 23 ~Landmark(); 24 24 25 26 27 28 29 30 25 QtMobility::QGeoCoordinate coordinate(void); 26 void setCoordinate(const QtMobility::QGeoCoordinate &coordinate); 27 void setText(QString string); 28 void setColor(Qt::GlobalColor color); 29 void RemoveLandmark(void); 30 void AddLandmark(QtMobility::QGraphicsGeoMap *geoMap); 31 31 32 32 private: 33 QtMobility::QGeoMapTextObject*text;34 QtMobility::QGeoMapPixmapObject*pixmap;35 33 QtMobility::QGeoMapTextObject *text; 34 QtMobility::QGeoMapPixmapObject *pixmap; 35 QtMobility::QGraphicsGeoMap *geoMap; 36 36 }; 37 37 -
trunk/tools/FlairGCS/src/Layout.cpp
r10 r15 23 23 #include <QGridLayout> 24 24 25 26 Layout::Layout(QWidget* parent,XmlWidget* xml,QString name,QString type): XmlWidget(name,type,xml) { 27 qgridlayout=new QGridLayout(parent); 28 Constructor(name); 29 } 30 31 Layout::Layout(Layout* parent,QString name,QString type): XmlWidget(name,type,parent) { 32 qgridlayout=new QGridLayout(new QWidget()); 33 Constructor(name); 25 Layout::Layout(QWidget *parent, XmlWidget *xml, QString name, QString type) 26 : XmlWidget(name, type, xml) { 27 qgridlayout = new QGridLayout(parent); 28 Constructor(name); 29 } 30 31 Layout::Layout(Layout *parent, QString name, QString type) 32 : XmlWidget(name, type, parent) { 33 qgridlayout = new QGridLayout(new QWidget()); 34 Constructor(name); 34 35 } 35 36 36 37 void Layout::Constructor(QString name) { 37 visible_widget=qgridlayout->parentWidget(); 38 //if(visible_widget==NULL) printf("null\n"); 39 qgridlayout->setObjectName(name); 40 //printf("layout\n%s\n",XmlDoc().toString().toLocal8Bit().constData()); 41 SetIsContainer(true); 42 SetIsExpandable(true); 43 44 qgridlayout->setHorizontalSpacing(2); 45 qgridlayout->setVerticalSpacing(2); 46 qgridlayout->setContentsMargins (2,2,2,2); 47 48 //splitter = new QSplitter(); 49 //addWidget(splitter); 50 /* 51 QWidget *widget = new QWidget(); 52 //QHBoxLayout *parentLayout = new QHBoxLayout(); 53 widget->setLayout(this); 54 parent->addWidget(widget); 55 //QTabWidget *tabWidget = new QTabWidget(); 56 //parentLayout->addWidget(tabWidget);*/ 57 } 58 59 Layout::~Layout() { 60 delete qgridlayout; 61 } 38 visible_widget = qgridlayout->parentWidget(); 39 // if(visible_widget==NULL) printf("null\n"); 40 qgridlayout->setObjectName(name); 41 // printf("layout\n%s\n",XmlDoc().toString().toLocal8Bit().constData()); 42 SetIsContainer(true); 43 SetIsExpandable(true); 44 45 qgridlayout->setHorizontalSpacing(2); 46 qgridlayout->setVerticalSpacing(2); 47 qgridlayout->setContentsMargins(2, 2, 2, 2); 48 49 // splitter = new QSplitter(); 50 // addWidget(splitter); 51 /* 52 QWidget *widget = new QWidget(); 53 //QHBoxLayout *parentLayout = new QHBoxLayout(); 54 widget->setLayout(this); 55 parent->addWidget(widget); 56 //QTabWidget *tabWidget = new QTabWidget(); 57 //parentLayout->addWidget(tabWidget);*/ 58 } 59 60 Layout::~Layout() { delete qgridlayout; } 62 61 63 62 void Layout::addWidget(QWidget *widget, int row, int column) { 64 qgridlayout->addWidget(widget,row,column); 65 } 66 67 QGridLayout* Layout::getQGridLayout() { 68 return qgridlayout; 69 } 63 qgridlayout->addWidget(widget, row, column); 64 } 65 66 QGridLayout *Layout::getQGridLayout() { return qgridlayout; } 70 67 71 68 void Layout::XmlEvent(QDomElement dom) { 72 XmlWidget* widget=NULL; 73 QString type=dom.tagName(); 74 QString name=dom.attribute("name"); 75 QString old_name=dom.attribute("old_name"); 76 int row=dom.attribute("row").toInt(); 77 int col=dom.attribute("col").toInt(); 78 79 //initially rowCount()=1 and columnCount()=1 but count()=0 ! 80 //new row 81 if(row==-1 && col==-1) { 82 row=qgridlayout->rowCount(); 83 if(qgridlayout->count()==0) row=0; 84 col=0; 85 } 86 //last row last col 87 if(row==-1 && col==0) { 88 row=qgridlayout->rowCount()-1; 89 int i; 90 for(i=0;i<=qgridlayout->columnCount();i++) { 91 if(qgridlayout->itemAtPosition(row,i)==NULL) break; 92 } 93 col=i; 94 } 95 //if an item already exists at this position, put it on a new row 96 if(qgridlayout->itemAtPosition(row,col)!=NULL) { 97 printf("existe %s\n",name.toLocal8Bit().constData()); 98 row=qgridlayout->rowCount(); 99 } 100 101 if(type=="TabWidget") { 102 int position=dom.attribute("position").toInt(); 103 widget = new TabWidget(this,row,col,name,(QTabWidget::TabPosition)position); 104 } 105 if(type=="GroupBox") { 106 widget = new GroupBox(this,row,col,name); 107 } 108 if(type=="GridLayout") { 109 widget = new GridLayout(this,row,col,name); 110 } 111 if(type=="SpinBox") { 112 int value=dom.attribute("value").toInt(); 113 QString suffix=dom.attribute("suffix"); 114 int min=dom.attribute("min").toInt(); 115 int max=dom.attribute("max").toInt(); 116 int step=dom.attribute("step").toInt(); 117 widget= new SpinBox(this,row,col,name,suffix,value,min,max,step); 118 } 119 if(type=="DoubleSpinBox") { 120 QString value=dom.attribute("value"); 121 QString suffix=dom.attribute("suffix"); 122 double min=dom.attribute("min").toDouble(); 123 double max=dom.attribute("max").toDouble(); 124 double step=dom.attribute("step").toDouble(); 125 int decimals=dom.attribute("decimals").toInt(); 126 widget= new DoubleSpinBox(this,row,col,name,suffix,value,min,max,step,decimals); 127 } 128 if(type=="Vector3DSpinBox") { 129 QString value[3]; 130 value[0]=dom.attribute("value_x"); 131 value[1]=dom.attribute("value_y"); 132 value[2]=dom.attribute("value_z"); 133 double min=dom.attribute("min").toDouble(); 134 double max=dom.attribute("max").toDouble(); 135 double step=dom.attribute("step").toDouble(); 136 int decimals=dom.attribute("decimals").toInt(); 137 widget= new Vector3DSpinBox(this,row,col,name,value,min,max,step,decimals); 138 } 139 if(type=="CheckBox") { 140 int value=dom.attribute("value").toInt(); 141 widget= new CheckBox(this,row,col,name,value); 142 } 143 if(type=="ComboBox") { 144 int value=dom.attribute("value").toInt(); 145 widget= new ComboBox(this,row,col,name,value); 146 } 147 if(type=="PushButton") { 148 widget= new PushButton(this,row,col,name); 149 } 150 if(type=="DataPlot1D") { 151 float ymin=dom.attribute("min").toFloat(); 152 float ymax=dom.attribute("max").toFloat(); 153 int enabled=dom.attribute("enabled").toInt(); 154 int period=dom.attribute("period").toInt(); 155 if(enabled==1) { 156 widget = new DataPlot1D(this,row,col,name,ymin,ymax,true,period); 157 } else { 158 widget = new DataPlot1D(this,row,col,name,ymin,ymax,false,100); 159 } 160 } 161 if(type=="DataPlot2D") { 162 float xmin=dom.attribute("xmin").toFloat(); 163 float xmax=dom.attribute("xmax").toFloat(); 164 float ymin=dom.attribute("ymin").toFloat(); 165 float ymax=dom.attribute("ymax").toFloat(); 166 QString x_name=dom.attribute("x_name"); 167 QString y_name=dom.attribute("y_name"); 168 int enabled=dom.attribute("enabled").toInt(); 169 int period=dom.attribute("period").toInt(); 170 if(enabled==1) { 171 widget = new DataPlot2D(this,row,col,name,x_name,y_name,xmin,xmax,ymin,ymax,true,period); 172 } else { 173 widget = new DataPlot2D(this,row,col,name,x_name,y_name,xmin,xmax,ymin,ymax,false,100); 174 } 175 } 176 if(type=="RangeFinderPlot") { 177 float xmin=dom.attribute("xmin").toFloat(); 178 float xmax=dom.attribute("xmax").toFloat(); 179 float ymin=dom.attribute("ymin").toFloat(); 180 float ymax=dom.attribute("ymax").toFloat(); 181 QString x_name=dom.attribute("x_name"); 182 QString y_name=dom.attribute("y_name"); 183 QString data_type=dom.attribute("type"); 184 float start_angle=dom.attribute("start_angle").toFloat(); 185 float end_angle=dom.attribute("end_angle").toFloat(); 186 uint32_t nb_samples=dom.attribute("nb_samples").toUInt(); 187 int enabled=dom.attribute("enabled").toInt(); 188 int period=dom.attribute("period").toInt(); 189 int invert_axis=dom.attribute("invert_axis").toInt(); 190 bool invert_axis_bool; 191 if(invert_axis==0) { 192 invert_axis_bool=false; 193 }else { 194 invert_axis_bool=true; 195 } 196 if(enabled==1) { 197 widget = new RangeFinderPlot(this,row,col,name,x_name,y_name,xmin,xmax,ymin,ymax,start_angle,end_angle,nb_samples,data_type,invert_axis,true,period); 198 } else { 199 widget = new RangeFinderPlot(this,row,col,name,x_name,y_name,xmin,xmax,ymin,ymax,start_angle,end_angle,nb_samples,data_type,invert_axis,false,100); 200 } 201 } 202 if(type=="Picture") { 203 int width=dom.attribute("width").toInt(); 204 int height=dom.attribute("height").toInt(); 205 int enabled=dom.attribute("enabled").toInt(); 206 int period=dom.attribute("period").toInt(); 207 if(enabled==1) { 208 widget = new Picture(this,row,col,name,width,height,true,period); 209 } else { 210 widget = new Picture(this,row,col,name,width,height,false,period); 211 } 212 } 213 if(type=="Map") { 214 int period=dom.attribute("period").toInt(); 215 int enabled=dom.attribute("enabled").toInt(); 216 int i=0; 217 QList<QtMobility::QGeoCoordinate> coordinates; 218 while(dom.hasAttribute("lat" +QString::number(i))) { 219 double latitude=dom.attribute("lat"+QString::number(i)).toDouble(); 220 double longitude=dom.attribute("long"+QString::number(i)).toDouble(); 221 double alt=dom.attribute("alt"+QString::number(i)).toDouble(); 222 QtMobility::QGeoCoordinate coordinate=QtMobility::QGeoCoordinate(latitude,longitude,alt); 223 coordinates.append(coordinate); 224 i++; 225 } 226 227 if(enabled==1) { 228 widget = new Map(this,row,col,name,coordinates,true,period); 229 } else { 230 widget = new Map(this,row,col,name,coordinates,false,period); 231 } 232 } 233 if(type=="TextEdit") { 234 widget= new TextEdit(this,row,col,name); 235 } 236 if(type=="Label") { 237 widget= new Label(this,row,col,name); 238 } 239 240 if(widget!=NULL) { 241 if(old_name!="") { 242 widget->RenamedFrom(old_name); 243 } 244 } 69 XmlWidget *widget = NULL; 70 QString type = dom.tagName(); 71 QString name = dom.attribute("name"); 72 QString old_name = dom.attribute("old_name"); 73 int row = dom.attribute("row").toInt(); 74 int col = dom.attribute("col").toInt(); 75 76 // initially rowCount()=1 and columnCount()=1 but count()=0 ! 77 // new row 78 if (row == -1 && col == -1) { 79 row = qgridlayout->rowCount(); 80 if (qgridlayout->count() == 0) 81 row = 0; 82 col = 0; 83 } 84 // last row last col 85 if (row == -1 && col == 0) { 86 row = qgridlayout->rowCount() - 1; 87 int i; 88 for (i = 0; i <= qgridlayout->columnCount(); i++) { 89 if (qgridlayout->itemAtPosition(row, i) == NULL) 90 break; 91 } 92 col = i; 93 } 94 // if an item already exists at this position, put it on a new row 95 if (qgridlayout->itemAtPosition(row, col) != NULL) { 96 printf("existe %s\n", name.toLocal8Bit().constData()); 97 row = qgridlayout->rowCount(); 98 } 99 100 if (type == "TabWidget") { 101 int position = dom.attribute("position").toInt(); 102 widget = 103 new TabWidget(this, row, col, name, (QTabWidget::TabPosition)position); 104 } 105 if (type == "GroupBox") { 106 widget = new GroupBox(this, row, col, name); 107 } 108 if (type == "GridLayout") { 109 widget = new GridLayout(this, row, col, name); 110 } 111 if (type == "SpinBox") { 112 int value = dom.attribute("value").toInt(); 113 QString suffix = dom.attribute("suffix"); 114 int min = dom.attribute("min").toInt(); 115 int max = dom.attribute("max").toInt(); 116 int step = dom.attribute("step").toInt(); 117 widget = new SpinBox(this, row, col, name, suffix, value, min, max, step); 118 } 119 if (type == "DoubleSpinBox") { 120 QString value = dom.attribute("value"); 121 QString suffix = dom.attribute("suffix"); 122 double min = dom.attribute("min").toDouble(); 123 double max = dom.attribute("max").toDouble(); 124 double step = dom.attribute("step").toDouble(); 125 int decimals = dom.attribute("decimals").toInt(); 126 widget = new DoubleSpinBox(this, row, col, name, suffix, value, min, max, 127 step, decimals); 128 } 129 if (type == "Vector3DSpinBox") { 130 QString value[3]; 131 value[0] = dom.attribute("value_x"); 132 value[1] = dom.attribute("value_y"); 133 value[2] = dom.attribute("value_z"); 134 double min = dom.attribute("min").toDouble(); 135 double max = dom.attribute("max").toDouble(); 136 double step = dom.attribute("step").toDouble(); 137 int decimals = dom.attribute("decimals").toInt(); 138 widget = new Vector3DSpinBox(this, row, col, name, value, min, max, step, 139 decimals); 140 } 141 if (type == "CheckBox") { 142 int value = dom.attribute("value").toInt(); 143 widget = new CheckBox(this, row, col, name, value); 144 } 145 if (type == "ComboBox") { 146 int value = dom.attribute("value").toInt(); 147 widget = new ComboBox(this, row, col, name, value); 148 } 149 if (type == "PushButton") { 150 widget = new PushButton(this, row, col, name); 151 } 152 if (type == "DataPlot1D") { 153 float ymin = dom.attribute("min").toFloat(); 154 float ymax = dom.attribute("max").toFloat(); 155 int enabled = dom.attribute("enabled").toInt(); 156 int period = dom.attribute("period").toInt(); 157 if (enabled == 1) { 158 widget = new DataPlot1D(this, row, col, name, ymin, ymax, true, period); 159 } else { 160 widget = new DataPlot1D(this, row, col, name, ymin, ymax, false, 100); 161 } 162 } 163 if (type == "DataPlot2D") { 164 float xmin = dom.attribute("xmin").toFloat(); 165 float xmax = dom.attribute("xmax").toFloat(); 166 float ymin = dom.attribute("ymin").toFloat(); 167 float ymax = dom.attribute("ymax").toFloat(); 168 QString x_name = dom.attribute("x_name"); 169 QString y_name = dom.attribute("y_name"); 170 int enabled = dom.attribute("enabled").toInt(); 171 int period = dom.attribute("period").toInt(); 172 if (enabled == 1) { 173 widget = new DataPlot2D(this, row, col, name, x_name, y_name, xmin, xmax, 174 ymin, ymax, true, period); 175 } else { 176 widget = new DataPlot2D(this, row, col, name, x_name, y_name, xmin, xmax, 177 ymin, ymax, false, 100); 178 } 179 } 180 if (type == "RangeFinderPlot") { 181 float xmin = dom.attribute("xmin").toFloat(); 182 float xmax = dom.attribute("xmax").toFloat(); 183 float ymin = dom.attribute("ymin").toFloat(); 184 float ymax = dom.attribute("ymax").toFloat(); 185 QString x_name = dom.attribute("x_name"); 186 QString y_name = dom.attribute("y_name"); 187 QString data_type = dom.attribute("type"); 188 float start_angle = dom.attribute("start_angle").toFloat(); 189 float end_angle = dom.attribute("end_angle").toFloat(); 190 uint32_t nb_samples = dom.attribute("nb_samples").toUInt(); 191 int enabled = dom.attribute("enabled").toInt(); 192 int period = dom.attribute("period").toInt(); 193 int invert_axis = dom.attribute("invert_axis").toInt(); 194 bool invert_axis_bool; 195 if (invert_axis == 0) { 196 invert_axis_bool = false; 197 } else { 198 invert_axis_bool = true; 199 } 200 if (enabled == 1) { 201 widget = 202 new RangeFinderPlot(this, row, col, name, x_name, y_name, xmin, xmax, 203 ymin, ymax, start_angle, end_angle, nb_samples, 204 data_type, invert_axis, true, period); 205 } else { 206 widget = 207 new RangeFinderPlot(this, row, col, name, x_name, y_name, xmin, xmax, 208 ymin, ymax, start_angle, end_angle, nb_samples, 209 data_type, invert_axis, false, 100); 210 } 211 } 212 if (type == "Picture") { 213 int width = dom.attribute("width").toInt(); 214 int height = dom.attribute("height").toInt(); 215 int enabled = dom.attribute("enabled").toInt(); 216 int period = dom.attribute("period").toInt(); 217 if (enabled == 1) { 218 widget = new Picture(this, row, col, name, width, height, true, period); 219 } else { 220 widget = new Picture(this, row, col, name, width, height, false, period); 221 } 222 } 223 if (type == "Map") { 224 int period = dom.attribute("period").toInt(); 225 int enabled = dom.attribute("enabled").toInt(); 226 int i = 0; 227 QList<QtMobility::QGeoCoordinate> coordinates; 228 while (dom.hasAttribute("lat" + QString::number(i))) { 229 double latitude = dom.attribute("lat" + QString::number(i)).toDouble(); 230 double longitude = dom.attribute("long" + QString::number(i)).toDouble(); 231 double alt = dom.attribute("alt" + QString::number(i)).toDouble(); 232 QtMobility::QGeoCoordinate coordinate = 233 QtMobility::QGeoCoordinate(latitude, longitude, alt); 234 coordinates.append(coordinate); 235 i++; 236 } 237 238 if (enabled == 1) { 239 widget = new Map(this, row, col, name, coordinates, true, period); 240 } else { 241 widget = new Map(this, row, col, name, coordinates, false, period); 242 } 243 } 244 if (type == "TextEdit") { 245 widget = new TextEdit(this, row, col, name); 246 } 247 if (type == "Label") { 248 widget = new Label(this, row, col, name); 249 } 250 251 if (widget != NULL) { 252 if (old_name != "") { 253 widget->RenamedFrom(old_name); 254 } 255 } 245 256 } 246 257 247 258 bool Layout::IsUptodate(void) { 248 for(int i=0;i<childs->count();i++) { 249 if(childs->at(i)->IsUptodate()==false) return false; 250 } 251 return true; 252 } 259 for (int i = 0; i < childs->count(); i++) { 260 if (childs->at(i)->IsUptodate() == false) 261 return false; 262 } 263 return true; 264 } -
trunk/tools/FlairGCS/src/Layout.h
r10 r15 11 11 class QGridLayout; 12 12 13 class Layout: public XmlWidget 14 { 15 public: 16 Layout(QWidget* parent,XmlWidget* xml,QString name,QString type); 17 Layout(Layout* parent,QString name,QString type); 18 ~Layout(); 19 bool IsUptodate(void); 20 void addWidget(QWidget *, int row, int column); 21 QGridLayout* getQGridLayout(); 13 class Layout : public XmlWidget { 14 public: 15 Layout(QWidget *parent, XmlWidget *xml, QString name, QString type); 16 Layout(Layout *parent, QString name, QString type); 17 ~Layout(); 18 bool IsUptodate(void); 19 void addWidget(QWidget *, int row, int column); 20 QGridLayout *getQGridLayout(); 22 21 23 //QSplitter *splitter;24 25 26 27 QGridLayout*qgridlayout;22 // QSplitter *splitter; 23 private: 24 void Constructor(QString name); 25 void XmlEvent(QDomElement dom); 26 QGridLayout *qgridlayout; 28 27 }; 29 28 -
trunk/tools/FlairGCS/src/Manager.cpp
r10 r15 25 25 26 26 #ifndef WIN32 27 27 #include <arpa/inet.h> 28 28 #else 29 30 29 #include <winsock2.h> 30 #include <ws2tcpip.h> 31 31 #endif 32 32 33 33 using namespace std; 34 34 35 Manager::Manager(QString name,int port):QWidget() { 36 qRegisterMetaType<QModelIndex>("QModelIndex");//pour le file ui?? 37 this->name=name; 38 39 setWindowTitle(name); 40 41 //manager layout 42 managerLayout = new QVBoxLayout; 43 setLayout(managerLayout); 44 45 //tab bar for multiple connections 46 tabBar=new QTabBar(); 47 managerLayout->addWidget(tabBar); 48 connect(tabBar, SIGNAL(currentChanged(int)),this, SLOT(tabBarCurrentChanged(int))); 49 currentTab=0; 50 51 //layout boutons 52 button_layout = new QGridLayout(); 53 managerLayout->addLayout(button_layout); 54 55 //boutons du button_Layout 56 send_button = new QPushButton("apply all"); 57 reset_button = new QPushButton("reset all"); 58 load_button = new QPushButton("load all locally"); 59 save_button = new QPushButton("save all locally"); 60 button_layout->addWidget(send_button,0,0); 61 button_layout->addWidget(reset_button,0,1); 62 button_layout->addWidget(load_button,0,2); 63 button_layout->addWidget(save_button,0,3); 64 65 connect(send_button, SIGNAL(clicked(bool)),this, SLOT(send())); 66 connect(reset_button, SIGNAL(clicked(bool)),this, SLOT(reset())); 67 connect(load_button, SIGNAL(clicked(bool)),this, SLOT(load())); 68 connect(save_button, SIGNAL(clicked(bool)),this, SLOT(save())); 69 70 UDT::startup(); 71 serv = UDT::socket(AF_INET, SOCK_DGRAM, 0); 72 73 //for non blocking accept 74 bool blocking = false; 75 UDT::setsockopt(serv, 0, UDT_RCVSYN, &blocking, sizeof(bool)); 76 77 sockaddr_in my_addr; 78 my_addr.sin_family = AF_INET; 79 my_addr.sin_port = htons(port); 80 my_addr.sin_addr.s_addr = INADDR_ANY; 81 memset(&(my_addr.sin_zero), '\0', 8); 82 83 if (UDT::ERROR == UDT::bind(serv, (sockaddr*)&my_addr, sizeof(my_addr))) { 84 printf("bind error, %s\n",UDT::getlasterror().getErrorMessage()); 85 } 86 87 if (UDT::ERROR == UDT::listen(serv, 1)) { 88 printf("listen error, %s\n",UDT::getlasterror().getErrorMessage()); 89 } 90 91 QTimer *timer = new QTimer(this); 92 connect(timer, SIGNAL(timeout()), this, SLOT(acceptConnections())); 93 timer->start(20); 35 Manager::Manager(QString name, int port) : QWidget() { 36 qRegisterMetaType<QModelIndex>("QModelIndex"); // pour le file ui?? 37 this->name = name; 38 39 setWindowTitle(name); 40 41 // manager layout 42 managerLayout = new QVBoxLayout; 43 setLayout(managerLayout); 44 45 // tab bar for multiple connections 46 tabBar = new QTabBar(); 47 managerLayout->addWidget(tabBar); 48 connect(tabBar, SIGNAL(currentChanged(int)), this, 49 SLOT(tabBarCurrentChanged(int))); 50 currentTab = 0; 51 52 // layout boutons 53 button_layout = new QGridLayout(); 54 managerLayout->addLayout(button_layout); 55 56 // boutons du button_Layout 57 send_button = new QPushButton("apply all"); 58 reset_button = new QPushButton("reset all"); 59 load_button = new QPushButton("load all locally"); 60 save_button = new QPushButton("save all locally"); 61 button_layout->addWidget(send_button, 0, 0); 62 button_layout->addWidget(reset_button, 0, 1); 63 button_layout->addWidget(load_button, 0, 2); 64 button_layout->addWidget(save_button, 0, 3); 65 66 connect(send_button, SIGNAL(clicked(bool)), this, SLOT(send())); 67 connect(reset_button, SIGNAL(clicked(bool)), this, SLOT(reset())); 68 connect(load_button, SIGNAL(clicked(bool)), this, SLOT(load())); 69 connect(save_button, SIGNAL(clicked(bool)), this, SLOT(save())); 70 71 UDT::startup(); 72 serv = UDT::socket(AF_INET, SOCK_DGRAM, 0); 73 74 // for non blocking accept 75 bool blocking = false; 76 UDT::setsockopt(serv, 0, UDT_RCVSYN, &blocking, sizeof(bool)); 77 78 sockaddr_in my_addr; 79 my_addr.sin_family = AF_INET; 80 my_addr.sin_port = htons(port); 81 my_addr.sin_addr.s_addr = INADDR_ANY; 82 memset(&(my_addr.sin_zero), '\0', 8); 83 84 if (UDT::ERROR == UDT::bind(serv, (sockaddr *)&my_addr, sizeof(my_addr))) { 85 printf("bind error, %s\n", UDT::getlasterror().getErrorMessage()); 86 } 87 88 if (UDT::ERROR == UDT::listen(serv, 1)) { 89 printf("listen error, %s\n", UDT::getlasterror().getErrorMessage()); 90 } 91 92 QTimer *timer = new QTimer(this); 93 connect(timer, SIGNAL(timeout()), this, SLOT(acceptConnections())); 94 timer->start(20); 94 95 } 95 96 96 97 Manager::~Manager() { 97 98 99 //delete main_layout;100 98 emit killUdtSockets(); 99 100 // delete main_layout; 101 UDT::cleanup(); 101 102 } 102 103 103 104 void Manager::acceptConnections(void) { 104 static UDTSOCKET first_socket=0; 105 UDTSOCKET socket; 106 107 sockaddr_in their_addr; 108 int namelen = sizeof(their_addr); 109 110 if (UDT::INVALID_SOCK == (socket = UDT::accept(serv, (sockaddr*)&their_addr, &namelen))) { 111 if(UDT::getlasterror().getErrorCode()!=6002) printf("accept: %s, code %i\n",UDT::getlasterror().getErrorMessage(),UDT::getlasterror().getErrorCode()); 112 return; 105 static UDTSOCKET first_socket = 0; 106 UDTSOCKET socket; 107 108 sockaddr_in their_addr; 109 int namelen = sizeof(their_addr); 110 111 if (UDT::INVALID_SOCK == 112 (socket = UDT::accept(serv, (sockaddr *)&their_addr, &namelen))) { 113 if (UDT::getlasterror().getErrorCode() != 6002) 114 printf("accept: %s, code %i\n", UDT::getlasterror().getErrorMessage(), 115 UDT::getlasterror().getErrorCode()); 116 return; 117 } else { 118 printf("connected to %s:%i\n", inet_ntoa(their_addr.sin_addr), 119 their_addr.sin_port); 120 121 if (!first_socket) { 122 first_socket = socket; 123 return; 113 124 } else { 114 printf("connected to %s:%i\n",inet_ntoa(their_addr.sin_addr),their_addr.sin_port); 115 116 if(!first_socket) { 117 first_socket=socket; 118 return; 119 } else { 120 QThread* thread = new QThread(this); 121 UdtSocket* new_udt=new UdtSocket(first_socket,socket,name); 122 new_udt->moveToThread(thread); 123 124 newConnection(new_udt); 125 126 connect(this, SIGNAL(killUdtSockets()),thread, SLOT(quit())); 127 connect(this, SIGNAL(killUdtSockets()),new_udt, SLOT(kill()),Qt::BlockingQueuedConnection); 128 129 connect(thread, SIGNAL(started()), new_udt, SLOT(handleConnections())); 130 131 thread->start(); 132 first_socket=0; 133 } 134 } 135 } 136 137 void Manager::newConnection(UdtSocket* socket) { 138 139 //no tabs to 2 tabs 140 if(connectionsLayout.count()==1) { 141 tabBar->addTab(hiddenTabName); 142 currentTab=0; 143 connectionsWidget.at(0)->show(); 144 } 145 146 //layout utilisateur 147 ConnectionLayout* newLayout = new ConnectionLayout(socket,"interface"); 148 connectionsLayout.append(newLayout); 149 connect(newLayout, SIGNAL(setRemoteName(QString)),this, SLOT(tabName(QString))); 150 connect(socket, SIGNAL(dataReady(char*,int)),newLayout, SLOT(receive(char*,int))); 151 connect(newLayout, SIGNAL(destroyed(QObject*)),this, SLOT(layoutDestroyed(QObject*))); 152 connect(socket, SIGNAL(destroyed()),newLayout, SLOT(deleteLater())); 153 154 //widget 155 QWidget* newWidget=new QWidget(); 156 connectionsWidget.append(newWidget); 157 newWidget->setLayout(newLayout->getQGridLayout()); 158 managerLayout->insertWidget(1,newWidget); 159 newWidget->hide(); 160 161 if(connectionsLayout.count()==1) {//first connection 162 newWidget->show(); 163 } else {//add a tab for the new connection 164 tabBar->addTab("unknown"); 165 } 125 QThread *thread = new QThread(this); 126 UdtSocket *new_udt = new UdtSocket(first_socket, socket, name); 127 new_udt->moveToThread(thread); 128 129 newConnection(new_udt); 130 131 connect(this, SIGNAL(killUdtSockets()), thread, SLOT(quit())); 132 connect(this, SIGNAL(killUdtSockets()), new_udt, SLOT(kill()), 133 Qt::BlockingQueuedConnection); 134 135 connect(thread, SIGNAL(started()), new_udt, SLOT(handleConnections())); 136 137 thread->start(); 138 first_socket = 0; 139 } 140 } 141 } 142 143 void Manager::newConnection(UdtSocket *socket) { 144 145 // no tabs to 2 tabs 146 if (connectionsLayout.count() == 1) { 147 tabBar->addTab(hiddenTabName); 148 currentTab = 0; 149 connectionsWidget.at(0)->show(); 150 } 151 152 // layout utilisateur 153 ConnectionLayout *newLayout = new ConnectionLayout(socket, "interface"); 154 connectionsLayout.append(newLayout); 155 connect(newLayout, SIGNAL(setRemoteName(QString)), this, 156 SLOT(tabName(QString))); 157 connect(socket, SIGNAL(dataReady(char *, int)), newLayout, 158 SLOT(receive(char *, int))); 159 connect(newLayout, SIGNAL(destroyed(QObject *)), this, 160 SLOT(layoutDestroyed(QObject *))); 161 connect(socket, SIGNAL(destroyed()), newLayout, SLOT(deleteLater())); 162 163 // widget 164 QWidget *newWidget = new QWidget(); 165 connectionsWidget.append(newWidget); 166 newWidget->setLayout(newLayout->getQGridLayout()); 167 managerLayout->insertWidget(1, newWidget); 168 newWidget->hide(); 169 170 if (connectionsLayout.count() == 1) { // first connection 171 newWidget->show(); 172 } else { // add a tab for the new connection 173 tabBar->addTab("unknown"); 174 } 166 175 } 167 176 168 177 void Manager::tabBarCurrentChanged(int index) { 169 if(index>=0) {170 171 172 currentTab=index;173 174 currentTab=0;175 176 178 if (index >= 0) { 179 connectionsWidget.at(currentTab)->hide(); 180 connectionsWidget.at(index)->show(); 181 currentTab = index; 182 } else { 183 currentTab = 0; 184 connectionsWidget.at(0)->show(); 185 } 177 186 } 178 187 179 188 void Manager::tabName(QString name) { 180 int index=connectionsLayout.indexOf((ConnectionLayout*)sender());181 if(tabBar->count()==0) {182 hiddenTabName=name;183 184 tabBar->setTabText(index,name);185 186 } 187 188 void Manager::layoutDestroyed(QObject *obj) {189 int index=connectionsLayout.indexOf((ConnectionLayout*)obj);190 191 if(tabBar->count()>1) {192 193 194 195 196 197 connectionsLayout.removeOne((ConnectionLayout*)obj);198 199 if(connectionsLayout.count()==1) {200 hiddenTabName=tabBar->tabText(0);201 202 189 int index = connectionsLayout.indexOf((ConnectionLayout *)sender()); 190 if (tabBar->count() == 0) { 191 hiddenTabName = name; 192 } else { 193 tabBar->setTabText(index, name); 194 } 195 } 196 197 void Manager::layoutDestroyed(QObject *obj) { 198 int index = connectionsLayout.indexOf((ConnectionLayout *)obj); 199 200 if (tabBar->count() > 1) { 201 tabBar->removeTab(index); 202 } 203 204 delete connectionsWidget.at(index); 205 connectionsWidget.removeAt(index); 206 connectionsLayout.removeOne((ConnectionLayout *)obj); 207 208 if (connectionsLayout.count() == 1) { 209 hiddenTabName = tabBar->tabText(0); 210 tabBar->removeTab(0); 211 } 203 212 } 204 213 205 214 void Manager::load(void) { 206 QString dir_name= QFileDialog::getExistingDirectory(this, "Select a directory",0,0); 207 208 if(dir_name!="") { 209 for(int i=0;i<connectionsLayout.count();i++) { 210 QFile* file; 211 file = new QFile(dir_name+"/"+connectionsLayout.at(i)->getRemoteName()+".xml"); 212 if(!file->open(QIODevice::ReadOnly | QIODevice::Text)) { 213 QMessageBox::warning(this,"Warning","Enable to load "+connectionsLayout.at(i)->getRemoteName()+".xml"); 214 continue; 215 } 216 217 QDomDocument doc; 218 QString errorMsg; 219 int errorLine; 220 int errorColumn; 221 if(!doc.setContent(file,&errorMsg,&errorLine,&errorColumn)) { 222 QMessageBox::critical(this,"Error","unable to read " +connectionsLayout.at(i)->getRemoteName()+".xml" 223 +" ("+errorMsg + " at " +QString::number(errorLine) +","+QString::number(errorColumn)+")"); 224 } else { 225 connectionsLayout.at(i)->LoadXml(doc); 226 } 227 delete file; 228 } 229 } 215 QString dir_name = 216 QFileDialog::getExistingDirectory(this, "Select a directory", 0, 0); 217 218 if (dir_name != "") { 219 for (int i = 0; i < connectionsLayout.count(); i++) { 220 QFile *file; 221 file = new QFile(dir_name + "/" + 222 connectionsLayout.at(i)->getRemoteName() + ".xml"); 223 if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) { 224 QMessageBox::warning(this, "Warning", 225 "Enable to load " + 226 connectionsLayout.at(i)->getRemoteName() + 227 ".xml"); 228 continue; 229 } 230 231 QDomDocument doc; 232 QString errorMsg; 233 int errorLine; 234 int errorColumn; 235 if (!doc.setContent(file, &errorMsg, &errorLine, &errorColumn)) { 236 QMessageBox::critical( 237 this, "Error", 238 "unable to read " + connectionsLayout.at(i)->getRemoteName() + 239 ".xml" + " (" + errorMsg + " at " + QString::number(errorLine) + 240 "," + QString::number(errorColumn) + ")"); 241 } else { 242 connectionsLayout.at(i)->LoadXml(doc); 243 } 244 delete file; 245 } 246 } 230 247 } 231 248 232 249 void Manager::save(void) { 233 bool isUptodate=true; 234 235 for(int i=0;i<connectionsLayout.count();i++) { 236 if(!connectionsLayout.at(i)->IsUptodate()) { 237 isUptodate=false; 238 break; 239 } 240 } 241 242 if(!isUptodate) { 243 QMessageBox msgBox; 244 msgBox.setText("There are pending modifications"); 245 msgBox.setInformativeText("Apply and save?"); 246 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel); 247 msgBox.setDefaultButton(QMessageBox::Yes); 248 int ret = msgBox.exec(); 249 250 switch (ret) { 251 case QMessageBox::Yes: 252 send(); 253 break; 254 case QMessageBox::Cancel: 255 return; 256 break; 257 default: 258 // should never be reached 259 break; 260 } 261 } 262 263 //create dirctory for storage 264 QDateTime dateTime = QDateTime::currentDateTime(); 265 QString dir_name = "configs_"+dateTime.toString("yyyyMMdd_hhmm")+ "_" + name; 266 if(QDir().exists(dir_name)==true) { 267 dir_name = "configs_"+dateTime.toString("yyyyMMdd_hhmm_ss")+ "_" + name; 268 } 269 QDir().mkdir(dir_name); 270 271 for(int i=0;i<connectionsLayout.count();i++) { 272 QDomDocument* xml=new QDomDocument("remote_ui_xml"); 273 274 connectionsLayout.at(i)->GetFullXml((QDomElement*)xml); 275 276 QFile fichier(dir_name+"/"+connectionsLayout.at(i)->getRemoteName()+".xml"); 277 QString write_doc = (xml->ownerDocument()).toString(); 278 279 if(!fichier.open(QIODevice::WriteOnly)) { 280 fichier.close(); 281 QMessageBox::critical(this,"Error","Enable to write XML"); 282 continue; 283 } 284 QTextStream stream(&fichier); 285 stream << write_doc; // On utilise l'opérateur << pour écrire write_doc dans le document XML. 286 fichier.close(); 287 288 delete xml; 289 } 290 291 QMessageBox::information(this,"save all","saved to ./"+ dir_name); 250 bool isUptodate = true; 251 252 for (int i = 0; i < connectionsLayout.count(); i++) { 253 if (!connectionsLayout.at(i)->IsUptodate()) { 254 isUptodate = false; 255 break; 256 } 257 } 258 259 if (!isUptodate) { 260 QMessageBox msgBox; 261 msgBox.setText("There are pending modifications"); 262 msgBox.setInformativeText("Apply and save?"); 263 msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel); 264 msgBox.setDefaultButton(QMessageBox::Yes); 265 int ret = msgBox.exec(); 266 267 switch (ret) { 268 case QMessageBox::Yes: 269 send(); 270 break; 271 case QMessageBox::Cancel: 272 return; 273 break; 274 default: 275 // should never be reached 276 break; 277 } 278 } 279 280 // create dirctory for storage 281 QDateTime dateTime = QDateTime::currentDateTime(); 282 QString dir_name = 283 "configs_" + dateTime.toString("yyyyMMdd_hhmm") + "_" + name; 284 if (QDir().exists(dir_name) == true) { 285 dir_name = "configs_" + dateTime.toString("yyyyMMdd_hhmm_ss") + "_" + name; 286 } 287 QDir().mkdir(dir_name); 288 289 for (int i = 0; i < connectionsLayout.count(); i++) { 290 QDomDocument *xml = new QDomDocument("remote_ui_xml"); 291 292 connectionsLayout.at(i)->GetFullXml((QDomElement *)xml); 293 294 QFile fichier(dir_name + "/" + connectionsLayout.at(i)->getRemoteName() + 295 ".xml"); 296 QString write_doc = (xml->ownerDocument()).toString(); 297 298 if (!fichier.open(QIODevice::WriteOnly)) { 299 fichier.close(); 300 QMessageBox::critical(this, "Error", "Enable to write XML"); 301 continue; 302 } 303 QTextStream stream(&fichier); 304 stream << write_doc; // On utilise l'opérateur << pour écrire write_doc dans 305 // le document XML. 306 fichier.close(); 307 308 delete xml; 309 } 310 311 QMessageBox::information(this, "save all", "saved to ./" + dir_name); 292 312 } 293 313 294 314 void Manager::send(void) { 295 for(int i=0;i<connectionsLayout.count();i++) {296 297 connectionsLayout.at(i)->GetUpdateXml((QDomElement*)&doc);298 //printf("merge\n%s\n",doc.toString().toLocal8Bit().constData());299 300 301 315 for (int i = 0; i < connectionsLayout.count(); i++) { 316 QDomDocument doc("remote_ui_xml"); 317 connectionsLayout.at(i)->GetUpdateXml((QDomElement *)&doc); 318 // printf("merge\n%s\n",doc.toString().toLocal8Bit().constData()); 319 320 connectionsLayout.at(i)->XmlToSend(doc); 321 } 302 322 } 303 323 304 324 void Manager::reset() { 305 for(int i=0;i<connectionsLayout.count();i++) connectionsLayout.at(i)->ResetAllChilds(); 306 } 325 for (int i = 0; i < connectionsLayout.count(); i++) 326 connectionsLayout.at(i)->ResetAllChilds(); 327 } -
trunk/tools/FlairGCS/src/Manager.h
r10 r15 17 17 class QGridLayout; 18 18 19 class Manager : public QWidget 20 { 21 Q_OBJECT 19 class Manager : public QWidget { 20 Q_OBJECT 22 21 23 24 Manager(QString name,int port);25 22 public: 23 Manager(QString name, int port); 24 ~Manager(); 26 25 27 28 UDTSOCKET serv;29 30 QList<ConnectionLayout*> connectionsLayout;31 QList<QWidget*> connectionsWidget;32 QTabBar*tabBar;33 QString name,hiddenTabName;34 26 private: 27 UDTSOCKET serv; 28 QVBoxLayout *managerLayout; 29 QList<ConnectionLayout *> connectionsLayout; 30 QList<QWidget *> connectionsWidget; 31 QTabBar *tabBar; 32 QString name, hiddenTabName; 33 int currentTab; 35 34 36 37 38 39 40 35 QPushButton *send_button; 36 QPushButton *reset_button; 37 QPushButton *load_button; 38 QPushButton *save_button; 39 QGridLayout *button_layout; 41 40 42 void newConnection(UdtSocket* socket);41 void newConnection(UdtSocket *socket); 43 42 44 45 46 47 48 49 50 void layoutDestroyed(QObject*obj);51 52 43 private slots: 44 void acceptConnections(void); 45 void load(void); 46 void send(void); 47 void save(void); 48 void reset(void); 49 void layoutDestroyed(QObject *obj); 50 void tabBarCurrentChanged(int index); 51 void tabName(QString name); 53 52 54 55 53 signals: 54 void killUdtSockets(void); 56 55 57 protected: 58 56 protected: 59 57 }; 60 58 61 #endif //MANAGER_H 62 59 #endif // MANAGER_H -
trunk/tools/FlairGCS/src/Map.cpp
r10 r15 21 21 using namespace QtMobility; 22 22 23 Map::Map(Layout* parent,int row, int col,QString name,QList<QGeoCoordinate> coordinates,bool enabled,int period): 24 DataRemote(name,"Map",parent,enabled,period) 25 { 26 visible_widget=new QWidget(); 27 visible_widget->setObjectName(name); 28 centeredpoint=0; 29 30 mapTypes[QGraphicsGeoMap::StreetMap] = tr("Street map"); 31 mapTypes[QGraphicsGeoMap::SatelliteMapDay] = tr("Satellite map (day)"); 32 mapTypes[QGraphicsGeoMap::SatelliteMapNight] = tr("Satellite map (night)"); 33 mapTypes[QGraphicsGeoMap::TerrainMap] = tr("Terrain map"); 34 35 mapWidget = new MapWidget(this,visible_widget); 36 geoMap = 0; 37 38 39 QVBoxLayout *map_layout = new QVBoxLayout(); 40 parent->getQGridLayout()->addLayout(map_layout,row,col); 41 QHBoxLayout *tool_layout = new QHBoxLayout(); 42 map_layout->addLayout(tool_layout,0); 43 44 QFormLayout* servicelayout = new QFormLayout(); 45 serviceCombo = new QComboBox(visible_widget); 46 servicelayout->addRow("service: ",serviceCombo); 47 QFormLayout* maplayout = new QFormLayout(); 48 mapTypeCombo = new QComboBox(visible_widget); 49 maplayout->addRow("map type: ",mapTypeCombo); 50 QFormLayout* proxylayout = new QFormLayout(); 51 proxyCombo = new QComboBox(visible_widget); 52 proxylayout->addRow("proxy: ",proxyCombo); 53 54 if(findServices()) 55 { 56 tool_layout->addLayout(servicelayout,0); 57 tool_layout->addLayout(maplayout,1); 58 tool_layout->addLayout(proxylayout,2); 59 60 zoomin=new QToolButton(visible_widget); 61 zoomout=new QToolButton(visible_widget); 62 zoomInAction = new QAction(QIcon(QPixmap(":zoomin.png")), tr("Zoom &In"),zoomin); 63 zoomOutAction = new QAction(QIcon(QPixmap(":zoomout.png")), tr("Zoom &Out"),zoomout); 64 zoomin->setDefaultAction(zoomInAction); 65 zoomout->setDefaultAction(zoomOutAction); 66 tool_layout->addWidget(zoomin,3); 67 tool_layout->addWidget(zoomout,4); 68 connect(zoomInAction, SIGNAL(triggered()), this, SLOT(zoomIn())); 69 connect(zoomOutAction, SIGNAL(triggered()), this, SLOT(zoomOut())); 70 71 selectService(0); 72 73 findproxy(); 74 75 connect(serviceCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(selectService(int))); 76 connect(mapTypeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changeMapType(int))); 77 connect(proxyCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(changeproxy(int))); 78 } 79 else 80 { 81 printf("Error, no services!\n"); 82 mapWidget->setEnabled(false); 83 } 84 85 map_layout->addWidget(mapWidget,1); 86 for(int i=0;i<coordinates.size();i++) { 87 mapWidget->AddLandmark((QGeoCoordinate &)coordinates.at(i)); 88 } 89 } 90 91 Map::~Map() 92 { 93 } 94 95 bool Map::findServices(void) 96 { 97 QCoreApplication::addLibraryPath(qgetenv("OECORE_HOST_SYSROOT") + "/usr/lib/qt4/"); 98 99 QStringList services = QGeoServiceProvider::availableServiceProviders(); 100 101 if (services.isEmpty()) 102 { 103 QGraphicsTextItem *item = mapWidget->scene()->addText( 104 tr("Failed to find any map services. Please ensure that " 105 "the location services plugins for Qt Mobility are " 106 "installed and, if necessary, set the IGEP_ROOT " 107 "environment variable to the good location.")); 108 109 item->setTextWidth(300); 110 111 return false; 112 } 113 114 QMap<QString, QVariant> parameters; 115 116 foreach (QString name, services) 117 { 118 119 parameters["mapping.cache.directory"] = name; 120 parameters["mapping.cache.size"] = QString("500000000"); 121 122 QGeoServiceProvider *service = new QGeoServiceProvider(name,parameters); 123 124 if (service->error() != QGeoServiceProvider::NoError) { 125 delete service; 126 continue; 127 } 128 129 QGeoMappingManager *manager = service->mappingManager(); 130 131 if (manager) 132 { 133 serviceCombo->addItem(name); 134 managers.append(manager); 135 } 136 } 137 23 Map::Map(Layout *parent, int row, int col, QString name, 24 QList<QGeoCoordinate> coordinates, bool enabled, int period) 25 : DataRemote(name, "Map", parent, enabled, period) { 26 visible_widget = new QWidget(); 27 visible_widget->setObjectName(name); 28 centeredpoint = 0; 29 30 mapTypes[QGraphicsGeoMap::StreetMap] = tr("Street map"); 31 mapTypes[QGraphicsGeoMap::SatelliteMapDay] = tr("Satellite map (day)"); 32 mapTypes[QGraphicsGeoMap::SatelliteMapNight] = tr("Satellite map (night)"); 33 mapTypes[QGraphicsGeoMap::TerrainMap] = tr("Terrain map"); 34 35 mapWidget = new MapWidget(this, visible_widget); 36 geoMap = 0; 37 38 QVBoxLayout *map_layout = new QVBoxLayout(); 39 parent->getQGridLayout()->addLayout(map_layout, row, col); 40 QHBoxLayout *tool_layout = new QHBoxLayout(); 41 map_layout->addLayout(tool_layout, 0); 42 43 QFormLayout *servicelayout = new QFormLayout(); 44 serviceCombo = new QComboBox(visible_widget); 45 servicelayout->addRow("service: ", serviceCombo); 46 QFormLayout *maplayout = new QFormLayout(); 47 mapTypeCombo = new QComboBox(visible_widget); 48 maplayout->addRow("map type: ", mapTypeCombo); 49 QFormLayout *proxylayout = new QFormLayout(); 50 proxyCombo = new QComboBox(visible_widget); 51 proxylayout->addRow("proxy: ", proxyCombo); 52 53 if (findServices()) { 54 tool_layout->addLayout(servicelayout, 0); 55 tool_layout->addLayout(maplayout, 1); 56 tool_layout->addLayout(proxylayout, 2); 57 58 zoomin = new QToolButton(visible_widget); 59 zoomout = new QToolButton(visible_widget); 60 zoomInAction = 61 new QAction(QIcon(QPixmap(":zoomin.png")), tr("Zoom &In"), zoomin); 62 zoomOutAction = 63 new QAction(QIcon(QPixmap(":zoomout.png")), tr("Zoom &Out"), zoomout); 64 zoomin->setDefaultAction(zoomInAction); 65 zoomout->setDefaultAction(zoomOutAction); 66 tool_layout->addWidget(zoomin, 3); 67 tool_layout->addWidget(zoomout, 4); 68 connect(zoomInAction, SIGNAL(triggered()), this, SLOT(zoomIn())); 69 connect(zoomOutAction, SIGNAL(triggered()), this, SLOT(zoomOut())); 70 71 selectService(0); 72 73 findproxy(); 74 75 connect(serviceCombo, SIGNAL(currentIndexChanged(int)), this, 76 SLOT(selectService(int))); 77 connect(mapTypeCombo, SIGNAL(currentIndexChanged(int)), this, 78 SLOT(changeMapType(int))); 79 connect(proxyCombo, SIGNAL(currentIndexChanged(int)), this, 80 SLOT(changeproxy(int))); 81 } else { 82 printf("Error, no services!\n"); 83 mapWidget->setEnabled(false); 84 } 85 86 map_layout->addWidget(mapWidget, 1); 87 for (int i = 0; i < coordinates.size(); i++) { 88 mapWidget->AddLandmark((QGeoCoordinate &)coordinates.at(i)); 89 } 90 } 91 92 Map::~Map() {} 93 94 bool Map::findServices(void) { 95 QCoreApplication::addLibraryPath(qgetenv("OECORE_HOST_SYSROOT") + 96 "/usr/lib/qt4/"); 97 98 QStringList services = QGeoServiceProvider::availableServiceProviders(); 99 100 if (services.isEmpty()) { 101 QGraphicsTextItem *item = mapWidget->scene()->addText( 102 tr("Failed to find any map services. Please ensure that " 103 "the location services plugins for Qt Mobility are " 104 "installed and, if necessary, set the IGEP_ROOT " 105 "environment variable to the good location.")); 106 107 item->setTextWidth(300); 108 109 return false; 110 } 111 112 QMap<QString, QVariant> parameters; 113 114 foreach (QString name, services) { 115 116 parameters["mapping.cache.directory"] = name; 117 parameters["mapping.cache.size"] = QString("500000000"); 118 119 QGeoServiceProvider *service = new QGeoServiceProvider(name, parameters); 120 121 if (service->error() != QGeoServiceProvider::NoError) { 122 delete service; 123 continue; 124 } 125 126 QGeoMappingManager *manager = service->mappingManager(); 127 128 if (manager) { 129 serviceCombo->addItem(name); 130 managers.append(manager); 131 } 132 } 133 134 return true; 135 } 136 137 void Map::selectService(int item) { 138 QString name = serviceCombo->currentText(); 139 140 QGeoCoordinate coordinate = QGeoCoordinate(0, 0); 141 QGraphicsGeoMap::MapType mapType = QGraphicsGeoMap::StreetMap; 142 int zoomLevel = 1; 143 144 if (geoMap) { 145 coordinate = geoMap->center(); 146 mapType = geoMap->mapType(); 147 zoomLevel = geoMap->zoomLevel(); 148 149 mapWidget->RemoveLandmarks(); 150 RemovePoints(); 151 geoMap->deleteLater(); 152 } 153 154 manager = managers[item]; 155 geoMap = new QGraphicsGeoMap(manager); 156 157 mapWidget->AddLandmarks(geoMap); 158 AddPoints(geoMap); 159 geoMap->setCenter(coordinate); 160 geoMap->setMapType(mapType); 161 162 populateMapTypeCombo(); 163 updateZoom(zoomLevel); 164 165 mapWidget->setMap(geoMap); 166 connect(geoMap, SIGNAL(zoomLevelChanged(qreal)), this, 167 SLOT(updateZoom(qreal))); 168 } 169 170 void Map::changeMapType(int index) { 171 geoMap->setMapType( 172 QGraphicsGeoMap::MapType(mapTypeCombo->itemData(index).toInt())); 173 } 174 175 void Map::populateMapTypeCombo(void) { 176 mapTypeCombo->clear(); 177 178 foreach (QGraphicsGeoMap::MapType mapType, geoMap->supportedMapTypes()) { 179 if (mapTypes.contains(mapType)) 180 mapTypeCombo->addItem(mapTypes[mapType], QVariant(mapType)); 181 } 182 183 if (mapTypeCombo->count() > 0) 184 geoMap->setMapType( 185 QGraphicsGeoMap::MapType(mapTypeCombo->itemData(0).toInt())); 186 } 187 188 void Map::zoomIn(void) { updateZoom(geoMap->zoomLevel() + 1); } 189 190 void Map::zoomOut(void) { updateZoom(geoMap->zoomLevel() - 1); } 191 192 void Map::updateZoom(qreal value) { 193 value = 194 qBound(manager->minimumZoomLevel(), value, manager->maximumZoomLevel()); 195 196 geoMap->setZoomLevel(value); 197 zoomin->setEnabled(geoMap->zoomLevel() < manager->maximumZoomLevel()); 198 zoomout->setEnabled(geoMap->zoomLevel() > manager->minimumZoomLevel()); 199 } 200 201 void Map::findproxy(void) { 202 proxyCombo->addItem("none"); 203 proxyCombo->addItem("new"); 204 proxyCombo->addItem("proxyweb.utc.fr:3128"); 205 } 206 207 void Map::changeproxy(int index) { 208 if (index == 0) { 209 QNetworkProxy proxy; 210 proxy.setType(QNetworkProxy::NoProxy); 211 QNetworkProxy::setApplicationProxy(proxy); 212 } else if (index == 1) { 213 bool ok; 214 QString text = 215 QInputDialog::getText(visible_widget, tr("New proxy:"), tr("proxy: "), 216 QLineEdit::Normal, "adress:port", &ok); 217 if (ok == true) { 218 proxyCombo->addItem(text); 219 proxyCombo->setCurrentIndex(proxyCombo->count() - 1); 220 } 221 } else { 222 QStringList string = proxyCombo->itemText(index).split(":"); 223 QNetworkProxy proxy; 224 proxy.setType(QNetworkProxy::HttpProxy); 225 proxy.setHostName(string.at(0)); 226 proxy.setPort(string.at(1).toInt()); 227 QNetworkProxy::setApplicationProxy(proxy); 228 updateZoom(geoMap->zoomLevel()); // refresh 229 } 230 } 231 232 void Map::SetUptodate(void) { 233 QList<Landmark *> *landmarks = mapWidget->Landmarks(); 234 for (int i = 0; i < landmarks->count(); i++) { 235 RemoveAttribute("lat" + QString::number(i)); 236 RemoveAttribute("long" + QString::number(i)); 237 238 if (mapWidget->LandmarkToSend(i)) { 239 SetAttribute("lat" + QString::number(i), 240 landmarks->at(i)->coordinate().latitude()); 241 SetAttribute("long" + QString::number(i), 242 landmarks->at(i)->coordinate().longitude()); 243 } 244 } 245 246 mapWidget->SetUptodate(); 247 } 248 249 bool Map::IsUptodate(void) { return mapWidget->IsUptodate(); } 250 251 void Map::Reset(void) { mapWidget->Reset(); } 252 253 void Map::setCenteredPoint(int i) { 254 centeredpoint = i; 255 if (isCentered()) 256 geoMap->setCenter(points.at(i)->coordinate()); 257 } 258 259 int Map::centeredPoint(void) { return centeredpoint; } 260 261 bool Map::isCentered(void) { 262 if (centeredpoint != -1) { 138 263 return true; 139 } 140 141 void Map::selectService(int item) 142 { 143 QString name = serviceCombo-> currentText (); 144 145 QGeoCoordinate coordinate = QGeoCoordinate(0, 0); 146 QGraphicsGeoMap::MapType mapType = QGraphicsGeoMap::StreetMap; 147 int zoomLevel = 1; 148 149 if (geoMap) { 150 coordinate = geoMap->center(); 151 mapType = geoMap->mapType(); 152 zoomLevel = geoMap->zoomLevel(); 153 154 mapWidget->RemoveLandmarks(); 155 RemovePoints(); 156 geoMap->deleteLater(); 157 } 158 159 manager = managers[item]; 160 geoMap = new QGraphicsGeoMap(manager); 161 162 mapWidget->AddLandmarks(geoMap); 163 AddPoints(geoMap); 164 geoMap->setCenter(coordinate); 165 geoMap->setMapType(mapType); 166 167 populateMapTypeCombo(); 168 updateZoom(zoomLevel); 169 170 mapWidget->setMap(geoMap); 171 connect(geoMap, SIGNAL(zoomLevelChanged(qreal)), this, SLOT(updateZoom(qreal))); 172 } 173 174 void Map::changeMapType(int index) 175 { 176 geoMap->setMapType(QGraphicsGeoMap::MapType(mapTypeCombo->itemData(index).toInt())); 177 } 178 179 void Map::populateMapTypeCombo(void) 180 { 181 mapTypeCombo->clear(); 182 183 foreach (QGraphicsGeoMap::MapType mapType, geoMap->supportedMapTypes()) { 184 if (mapTypes.contains(mapType)) 185 mapTypeCombo->addItem(mapTypes[mapType], QVariant(mapType)); 186 } 187 188 if (mapTypeCombo->count() > 0) 189 geoMap->setMapType(QGraphicsGeoMap::MapType(mapTypeCombo->itemData(0).toInt())); 190 } 191 192 void Map::zoomIn(void) 193 { 194 updateZoom(geoMap->zoomLevel() + 1); 195 } 196 197 void Map::zoomOut(void) 198 { 199 updateZoom(geoMap->zoomLevel() - 1); 200 } 201 202 void Map::updateZoom(qreal value) 203 { 204 value = qBound(manager->minimumZoomLevel(), value, manager->maximumZoomLevel()); 205 206 geoMap->setZoomLevel(value); 207 zoomin->setEnabled(geoMap->zoomLevel() < manager->maximumZoomLevel()); 208 zoomout->setEnabled(geoMap->zoomLevel() > manager->minimumZoomLevel()); 209 } 210 211 void Map::findproxy(void) 212 { 213 proxyCombo->addItem("none"); 214 proxyCombo->addItem("new"); 215 proxyCombo->addItem("proxyweb.utc.fr:3128"); 216 } 217 218 void Map::changeproxy(int index) 219 { 220 if(index==0) 221 { 222 QNetworkProxy proxy; 223 proxy.setType(QNetworkProxy::NoProxy); 224 QNetworkProxy::setApplicationProxy(proxy); 225 } 226 else if(index==1) 227 { 228 bool ok; 229 QString text = QInputDialog::getText(visible_widget, tr("New proxy:"), 230 tr("proxy: "), QLineEdit::Normal, 231 "adress:port", &ok); 232 if(ok==true) 233 { 234 proxyCombo->addItem(text); 235 proxyCombo->setCurrentIndex(proxyCombo->count()-1); 236 } 237 } 238 else 239 { 240 QStringList string=proxyCombo->itemText(index).split(":"); 241 QNetworkProxy proxy; 242 proxy.setType(QNetworkProxy::HttpProxy); 243 proxy.setHostName(string.at(0)); 244 proxy.setPort(string.at(1).toInt()); 245 QNetworkProxy::setApplicationProxy(proxy); 246 updateZoom(geoMap->zoomLevel());//refresh 247 } 248 } 249 250 void Map::SetUptodate(void) { 251 QList<Landmark*> *landmarks=mapWidget->Landmarks(); 252 for(int i=0;i<landmarks->count();i++) { 253 RemoveAttribute("lat" +QString::number(i)); 254 RemoveAttribute("long" +QString::number(i)); 255 256 if(mapWidget->LandmarkToSend(i)) { 257 SetAttribute("lat" +QString::number( i ) ,landmarks->at(i)->coordinate().latitude()); 258 SetAttribute("long" +QString::number( i ) ,landmarks->at(i)->coordinate().longitude()); 259 } 260 } 261 262 mapWidget->SetUptodate(); 263 } 264 265 bool Map::IsUptodate(void) 266 { 267 return mapWidget->IsUptodate(); 268 } 269 270 void Map::Reset(void) 271 { 272 mapWidget->Reset(); 273 } 274 275 void Map::setCenteredPoint(int i) { 276 centeredpoint=i; 277 if(isCentered()) geoMap->setCenter(points.at(i)->coordinate()); 278 } 279 280 int Map::centeredPoint(void) { 281 return centeredpoint; 282 } 283 284 bool Map::isCentered(void) { 285 if(centeredpoint!=-1) { 286 return true; 287 } else { 288 return false; 289 } 264 } else { 265 return false; 266 } 290 267 } 291 268 292 269 void Map::XmlEvent(QDomElement dom) { 293 if(dom.attribute("point")!="") { 294 receivesize+=3*sizeof(double); 295 if(mapWidget->isEnabled()) { 296 Landmark* landmark=new Landmark(geoMap,QGeoCoordinate(0,0,0),dom.attribute("point"),"cross"); 297 landmark->setColor(Qt::black); 298 points.append(landmark); 299 mapWidget->AddPoint(dom.attribute("point")); 300 } 301 } else { 302 XmlSetup(dom); 303 } 304 } 305 306 void Map::BufEvent(char** buf,int *buf_size,uint16_t period,bool big_endian) { 307 if(IsEnabled()==false || RefreshRate_ms()!=period) return; 308 309 for(int i=0;i<points.count();i++) { 310 qint64 lat_raw; 311 double* lat=(double*)&lat_raw; 312 qint64 longitude_raw; 313 double* longitude=(double*)&longitude_raw; 314 qint64 alt_raw; 315 double* alt=(double*)&alt_raw; 316 317 memcpy(&lat_raw,*buf,sizeof(qint64)); 318 *buf+=sizeof(qint64); 319 memcpy(&longitude_raw,*buf,sizeof(qint64)); 320 *buf+=sizeof(qint64); 321 memcpy(&alt_raw,*buf,sizeof(qint64)); 322 *buf+=sizeof(qint64); 323 if(big_endian==true) lat_raw=qFromBigEndian(lat_raw); 324 if(big_endian==true) longitude_raw=qFromBigEndian(longitude_raw); 325 if(big_endian==true) alt_raw=qFromBigEndian(alt_raw); 326 points.at(i)->setCoordinate(QGeoCoordinate(*lat,*longitude,*alt)); 327 328 if(i==centeredpoint) geoMap->setCenter(points.at(i)->coordinate()); 329 } 270 if (dom.attribute("point") != "") { 271 receivesize += 3 * sizeof(double); 272 if (mapWidget->isEnabled()) { 273 Landmark *landmark = new Landmark(geoMap, QGeoCoordinate(0, 0, 0), 274 dom.attribute("point"), "cross"); 275 landmark->setColor(Qt::black); 276 points.append(landmark); 277 mapWidget->AddPoint(dom.attribute("point")); 278 } 279 } else { 280 XmlSetup(dom); 281 } 282 } 283 284 void Map::BufEvent(char **buf, int *buf_size, uint16_t period, 285 bool big_endian) { 286 if (IsEnabled() == false || RefreshRate_ms() != period) 287 return; 288 289 for (int i = 0; i < points.count(); i++) { 290 qint64 lat_raw; 291 double *lat = (double *)&lat_raw; 292 qint64 longitude_raw; 293 double *longitude = (double *)&longitude_raw; 294 qint64 alt_raw; 295 double *alt = (double *)&alt_raw; 296 297 memcpy(&lat_raw, *buf, sizeof(qint64)); 298 *buf += sizeof(qint64); 299 memcpy(&longitude_raw, *buf, sizeof(qint64)); 300 *buf += sizeof(qint64); 301 memcpy(&alt_raw, *buf, sizeof(qint64)); 302 *buf += sizeof(qint64); 303 if (big_endian == true) 304 lat_raw = qFromBigEndian(lat_raw); 305 if (big_endian == true) 306 longitude_raw = qFromBigEndian(longitude_raw); 307 if (big_endian == true) 308 alt_raw = qFromBigEndian(alt_raw); 309 points.at(i)->setCoordinate(QGeoCoordinate(*lat, *longitude, *alt)); 310 311 if (i == centeredpoint) 312 geoMap->setCenter(points.at(i)->coordinate()); 313 } 330 314 } 331 315 332 316 void Map::RemovePoints(void) { 333 for(int i=0;i<points.count();i++) {334 335 317 for (int i = 0; i < points.count(); i++) { 318 points.at(i)->RemoveLandmark(); 319 } 336 320 } 337 321 338 322 void Map::AddPoints(QGraphicsGeoMap *geoMap) { 339 for(int i=0;i<points.count();i++) {340 341 342 } 323 for (int i = 0; i < points.count(); i++) { 324 points.at(i)->AddLandmark(geoMap); 325 } 326 } -
trunk/tools/FlairGCS/src/Map.h
r10 r15 18 18 19 19 namespace QtMobility { 20 21 22 20 class QGeoMappingManager; 21 class QGraphicsGeoMap; 22 class QGeoServiceProvider; 23 23 } 24 24 25 class Map: public DataRemote 26 { 27 Q_OBJECT 25 class Map : public DataRemote { 26 Q_OBJECT 28 27 29 public: 30 Map(Layout* parent,int row, int col,QString name,QList<QtMobility::QGeoCoordinate> coordinates,bool enabled,int period); 31 ~Map(); 32 void setCenteredPoint(int i); 33 int centeredPoint(void); 34 bool isCentered(void); 28 public: 29 Map(Layout *parent, int row, int col, QString name, 30 QList<QtMobility::QGeoCoordinate> coordinates, bool enabled, int period); 31 ~Map(); 32 void setCenteredPoint(int i); 33 int centeredPoint(void); 34 bool isCentered(void); 35 35 36 37 38 39 40 41 42 QComboBox *mapTypeCombo,*serviceCombo,*proxyCombo;43 44 QToolButton *zoomin,*zoomout;45 46 47 QList<Landmark*> points;48 36 private: 37 MapWidget *mapWidget; 38 QtMobility::QGeoMappingManager *manager; 39 QList<QtMobility::QGeoMappingManager *> managers; 40 QtMobility::QGraphicsGeoMap *geoMap; 41 QtMobility::QGeoServiceProvider *service; 42 QComboBox *mapTypeCombo, *serviceCombo, *proxyCombo; 43 QHash<QtMobility::QGraphicsGeoMap::MapType, QString> mapTypes; 44 QToolButton *zoomin, *zoomout; 45 QAction *zoomInAction; 46 QAction *zoomOutAction; 47 QList<Landmark *> points; 48 int centeredpoint; 49 49 50 51 52 53 54 55 56 57 void BufEvent(char** buf,int *buf_size,uint16_t period,bool big_endian);50 bool findServices(void); 51 void findproxy(void); 52 void populateMapTypeCombo(); 53 bool IsUptodate(void); 54 void SetUptodate(void); 55 void Reset(void); 56 void XmlEvent(QDomElement dom); 57 void BufEvent(char **buf, int *buf_size, uint16_t period, bool big_endian); 58 58 59 60 59 void RemovePoints(void); 60 void AddPoints(QtMobility::QGraphicsGeoMap *geoMap); 61 61 62 private slots: 63 void changeMapType(int index); 64 void selectService(int index); 65 void changeproxy(int index); 66 void updateZoom(qreal value); 67 void zoomIn(void); 68 void zoomOut(void); 69 62 private slots: 63 void changeMapType(int index); 64 void selectService(int index); 65 void changeproxy(int index); 66 void updateZoom(qreal value); 67 void zoomIn(void); 68 void zoomOut(void); 70 69 }; 71 70 -
trunk/tools/FlairGCS/src/Picture.cpp
r10 r15 12 12 #include <QVBoxLayout> 13 13 14 Picture::Picture(Layout* parent,int row, int col,QString name,uint16_t width, uint16_t height,bool enabled,int period):DataRemote(name,"Picture",parent,enabled,period) 15 { 16 box = new QGroupBox(name); 17 box->setObjectName(name); 14 Picture::Picture(Layout *parent, int row, int col, QString name, uint16_t width, 15 uint16_t height, bool enabled, int period) 16 : DataRemote(name, "Picture", parent, enabled, period) { 17 box = new QGroupBox(name); 18 box->setObjectName(name); 18 19 19 parent->addWidget(box,row,col);20 parent->addWidget(box, row, col); 20 21 21 label=new QLabel();22 label = new QLabel(); 22 23 23 24 25 24 layout = new QVBoxLayout; 25 layout->addWidget(label); 26 box->setLayout(layout); 26 27 27 visible_widget=box;28 visible_widget = box; 28 29 29 30 label->setAlignment(Qt::AlignCenter); 30 31 31 im_width=width;32 im_height=height;33 label->setMinimumSize(width,height);34 label->setMaximumSize(width,height);35 receivesize=width*height;32 im_width = width; 33 im_height = height; 34 label->setMinimumSize(width, height); 35 label->setMaximumSize(width, height); 36 receivesize = width * height; 36 37 37 for(int i=0;i<256;i++) 38 { 39 color_table.append(qRgb(i,i,i)); 38 for (int i = 0; i < 256; i++) { 39 color_table.append(qRgb(i, i, i)); 40 } 41 42 label->installEventFilter(this); 43 } 44 45 Picture::~Picture() { delete layout; } 46 47 void Picture::BufEvent(char **buf, int *buf_size, uint16_t period, 48 bool big_endian) { 49 if (big_endian) 50 printf("Picture::BufEvent, big endian not handled\n"); 51 52 if (IsEnabled() == false || RefreshRate_ms() != period) 53 return; 54 55 if ((*buf_size) >= im_width * im_height) { 56 QImage image = QImage((const uchar *)*buf, im_width, im_height, 57 QImage::Format_Indexed8); // Format_RGB888); 58 *buf += im_width *im_height; 59 image.setColorTable(color_table); 60 61 label->setPixmap(QPixmap::fromImage(image)); 62 } else 63 printf("buffer trop petit\n"); 64 } 65 66 bool Picture::eventFilter(QObject *o, QEvent *e) { 67 if (o == label) { 68 switch (e->type()) { 69 case QEvent::MouseButtonPress: { 70 mousePressEvent((QMouseEvent *)e); 71 break; 40 72 } 41 73 42 label->installEventFilter(this); 74 default: 75 break; 76 } 77 } 78 return label->eventFilter(o, e); 43 79 } 44 80 81 void Picture::mousePressEvent(QMouseEvent *event) { 45 82 46 Picture::~Picture() 47 { 48 delete layout; 83 if (event->x() > 0 && event->x() < label->width() && event->y() > 0 && 84 event->y() < label->height() && event->button() == Qt::RightButton) { 85 86 QMenu *menu = new QMenu("nom", label); 87 // ajout des actions 88 QAction *a, *z; 89 90 a = menu->addAction("get frame"); 91 a->setEnabled(!auto_refresh); 92 93 appendmenu(menu); 94 z = execmenu(label, menu, event->globalPos()); 95 delete menu; 96 } 49 97 } 50 98 51 void Picture::BufEvent(char** buf,int *buf_size,uint16_t period,bool big_endian) 52 { 53 if(big_endian) printf("Picture::BufEvent, big endian not handled\n"); 54 55 if(IsEnabled()==false || RefreshRate_ms()!=period) return; 56 57 if((*buf_size)>=im_width*im_height) 58 { 59 QImage image= QImage((const uchar*)*buf,im_width,im_height,QImage::Format_Indexed8);//Format_RGB888); 60 *buf+=im_width*im_height; 61 image.setColorTable(color_table); 62 63 label->setPixmap(QPixmap::fromImage(image)); 64 } 65 else 66 printf("buffer trop petit\n"); 67 } 68 69 bool Picture::eventFilter(QObject *o, QEvent *e) 70 { 71 if ( o == label ) 72 { 73 switch(e->type()) 74 { 75 case QEvent::MouseButtonPress: 76 { 77 mousePressEvent((QMouseEvent*)e); 78 break; 79 } 80 81 default: 82 break; 83 } 84 } 85 return label->eventFilter(o, e); 86 } 87 88 void Picture::mousePressEvent(QMouseEvent * event) 89 { 90 91 if(event->x() > 0 && event->x() < label->width() && 92 event->y() > 0 && event->y() < label->height() && 93 event->button() == Qt::RightButton) 94 { 95 96 QMenu * menu = new QMenu("nom", label); 97 // ajout des actions 98 QAction *a,*z; 99 100 a=menu->addAction("get frame"); 101 a->setEnabled(!auto_refresh); 102 103 appendmenu(menu); 104 z=execmenu(label,menu,event->globalPos()); 105 delete menu; 106 107 } 108 } 109 110 void Picture::XmlEvent(QDomElement dom) 111 { 112 XmlSetup(dom); 113 } 99 void Picture::XmlEvent(QDomElement dom) { XmlSetup(dom); } -
trunk/tools/FlairGCS/src/Picture.h
r10 r15 17 17 class QVBoxLayout; 18 18 19 class Picture: public DataRemote 20 { 21 Q_OBJECT 19 class Picture : public DataRemote { 20 Q_OBJECT 22 21 23 public: 24 Picture(Layout* parent,int row, int col,QString name,uint16_t width, uint16_t height,bool enabled,int period); 25 ~Picture(); 22 public: 23 Picture(Layout *parent, int row, int col, QString name, uint16_t width, 24 uint16_t height, bool enabled, int period); 25 ~Picture(); 26 26 27 28 27 protected: 28 void mousePressEvent(QMouseEvent *event); 29 29 30 31 QGroupBox*box;32 33 34 35 36 30 private: 31 QGroupBox *box; 32 QLabel *label; 33 QVBoxLayout *layout; 34 QVector<QRgb> color_table; 35 uint16_t im_width; 36 uint16_t im_height; 37 37 38 bool eventFilter(QObject *, QEvent *); 39 void BufEvent(char** buf,int *buf_size,uint16_t period,bool big_endian); 40 void XmlEvent(QDomElement dom); 41 42 38 bool eventFilter(QObject *, QEvent *); 39 void BufEvent(char **buf, int *buf_size, uint16_t period, bool big_endian); 40 void XmlEvent(QDomElement dom); 43 41 }; 44 42 -
trunk/tools/FlairGCS/src/PushButton.cpp
r10 r15 7 7 #include <QPushButton> 8 8 9 PushButton::PushButton(Layout * parent,int row, int col,QString name):XmlWidget(name,"PushButton",parent)10 {11 button=new QPushButton(name);12 parent->addWidget(button,row,col);9 PushButton::PushButton(Layout *parent, int row, int col, QString name) 10 : XmlWidget(name, "PushButton", parent) { 11 button = new QPushButton(name); 12 parent->addWidget(button, row, col); 13 13 14 14 SetValue("0"); 15 15 16 connect(button, SIGNAL(clicked(bool)),this, SLOT(button_clicked(bool)));16 connect(button, SIGNAL(clicked(bool)), this, SLOT(button_clicked(bool))); 17 17 } 18 18 19 PushButton::~PushButton() 20 { 21 delete button; 19 PushButton::~PushButton() { delete button; } 20 21 void PushButton::button_clicked(bool state) { 22 SetValue("1"); 23 connectionLayout()->XmlToSend(XmlDoc()); 24 SetValue("0"); 22 25 } 23 24 void PushButton::button_clicked(bool state)25 {26 SetValue("1");27 connectionLayout()->XmlToSend(XmlDoc());28 SetValue("0");29 } -
trunk/tools/FlairGCS/src/PushButton.h
r10 r15 11 11 class Layout; 12 12 13 class PushButton: public XmlWidget 14 { 15 Q_OBJECT 13 class PushButton : public XmlWidget { 14 Q_OBJECT 16 15 17 18 PushButton(Layout* parent,int row, int col,QString name);19 16 public: 17 PushButton(Layout *parent, int row, int col, QString name); 18 ~PushButton(); 20 19 21 22 20 private: 21 QPushButton *button; 23 22 24 private slots: 25 void button_clicked(bool state); 26 23 private slots: 24 void button_clicked(bool state); 27 25 }; 28 26 -
trunk/tools/FlairGCS/src/RangeFinderPlot.cpp
r10 r15 18 18 #include <qmath.h> 19 19 20 RangeFinderPlot::RangeFinderPlot(Layout* parent,int row, int col,QString name, 21 QString x_name,QString y_name, 22 float xmin, float xmax,float ymin, float ymax, 23 float start_angle,float end_angle,uint32_t nb_samples,QString data_type, 24 bool invert_axis,bool enabled,int period): 25 DataRemote(name,"RangeFinderPlot",parent,enabled,period) 26 { 27 invert_axis=true; 28 this->start_angle=start_angle; 29 this->end_angle=end_angle; 30 this->nb_samples=nb_samples; 31 this->data_type=data_type; 32 this->invert_axis=invert_axis; 33 34 if(data_type=="float") 35 { 36 receivesize=nb_samples*sizeof(float); 37 } 38 else if(data_type=="int8_t") 39 { 40 receivesize=nb_samples*sizeof(int8_t); 41 } 42 else if(data_type=="int16_t") 43 { 44 receivesize=nb_samples*sizeof(int16_t); 45 } 46 else 47 { 48 printf("RangeFinderPlot::RangeFinderPlot unknown type %s\n",data_type.toLocal8Bit().constData()); 49 } 50 51 52 plot=new QwtPlot(NULL); 53 plot->setEnabled(enabled); 54 //plot->setAutoReplot( false ); 55 56 parent->addWidget(plot,row,col); 57 visible_widget=plot; 58 59 plot->setTitle(name); 60 61 // grid 62 QwtPlotGrid *grid = new QwtPlotGrid; 63 grid->setPen(QPen(Qt::black, 0, Qt::DotLine)); 64 grid->attach(plot); 65 66 plot->updateAxes(); 67 68 //zoomer 69 QwtPlotMagnifier * zoomer = new QwtPlotMagnifier(plot->canvas()); 70 zoomer->setMouseButton(Qt::RightButton,Qt::ControlModifier); 71 72 //scroller 73 QwtPlotPanner *scroller =new QwtPlotPanner(plot->canvas()); 74 75 // Axis 76 if(!invert_axis) { 77 plot->setAxisTitle(QwtPlot::xBottom, x_name); 78 setXAxisScale(xmin,xmax); 79 80 plot->setAxisTitle(QwtPlot::yLeft, y_name); 81 setYAxisScale(ymin,ymax); 82 } else { 83 plot->setAxisTitle(QwtPlot::xBottom, y_name); 84 setXAxisScale(ymin,ymax); 85 86 plot->setAxisTitle(QwtPlot::yLeft, x_name); 87 setYAxisScale(xmin,xmax); 88 } 89 90 QwtPlotRescaler* rescaler = new QwtPlotRescaler( plot->canvas() ); 91 rescaler->setRescalePolicy( QwtPlotRescaler::Fixed ); 92 93 //( void ) new QwtPlotMagnifier( plot->canvas() ); 94 95 plot->canvas()->installEventFilter(this); 96 97 for(uint32_t i=0;i<nb_samples;i++) 98 { 99 addTriangle(start_angle+i*(end_angle-start_angle+1)/nb_samples,start_angle+(i+1)*(end_angle-start_angle+1)/nb_samples); 100 } 101 } 102 103 RangeFinderPlot::~RangeFinderPlot() 104 { 105 delete plot; 106 } 107 108 void RangeFinderPlot::XmlEvent(QDomElement dom) 109 { 110 XmlSetup(dom); 111 } 112 113 bool RangeFinderPlot::eventFilter(QObject *o, QEvent *e) 114 { 115 if (o==plot->canvas()) 116 { 117 switch(e->type()) 118 { 119 case QEvent::MouseButtonPress: 120 { 121 mousePressEvent((QMouseEvent*)e); 122 break; 123 } 124 125 default: 126 break; 127 } 128 } 129 return plot->eventFilter(o, e); 130 } 131 20 RangeFinderPlot::RangeFinderPlot(Layout *parent, int row, int col, QString name, 21 QString x_name, QString y_name, float xmin, 22 float xmax, float ymin, float ymax, 23 float start_angle, float end_angle, 24 uint32_t nb_samples, QString data_type, 25 bool invert_axis, bool enabled, int period) 26 : DataRemote(name, "RangeFinderPlot", parent, enabled, period) { 27 invert_axis = true; 28 this->start_angle = start_angle; 29 this->end_angle = end_angle; 30 this->nb_samples = nb_samples; 31 this->data_type = data_type; 32 this->invert_axis = invert_axis; 33 34 if (data_type == "float") { 35 receivesize = nb_samples * sizeof(float); 36 } else if (data_type == "int8_t") { 37 receivesize = nb_samples * sizeof(int8_t); 38 } else if (data_type == "int16_t") { 39 receivesize = nb_samples * sizeof(int16_t); 40 } else { 41 printf("RangeFinderPlot::RangeFinderPlot unknown type %s\n", 42 data_type.toLocal8Bit().constData()); 43 } 44 45 plot = new QwtPlot(NULL); 46 plot->setEnabled(enabled); 47 // plot->setAutoReplot( false ); 48 49 parent->addWidget(plot, row, col); 50 visible_widget = plot; 51 52 plot->setTitle(name); 53 54 // grid 55 QwtPlotGrid *grid = new QwtPlotGrid; 56 grid->setPen(QPen(Qt::black, 0, Qt::DotLine)); 57 grid->attach(plot); 58 59 plot->updateAxes(); 60 61 // zoomer 62 QwtPlotMagnifier *zoomer = new QwtPlotMagnifier(plot->canvas()); 63 zoomer->setMouseButton(Qt::RightButton, Qt::ControlModifier); 64 65 // scroller 66 QwtPlotPanner *scroller = new QwtPlotPanner(plot->canvas()); 67 68 // Axis 69 if (!invert_axis) { 70 plot->setAxisTitle(QwtPlot::xBottom, x_name); 71 setXAxisScale(xmin, xmax); 72 73 plot->setAxisTitle(QwtPlot::yLeft, y_name); 74 setYAxisScale(ymin, ymax); 75 } else { 76 plot->setAxisTitle(QwtPlot::xBottom, y_name); 77 setXAxisScale(ymin, ymax); 78 79 plot->setAxisTitle(QwtPlot::yLeft, x_name); 80 setYAxisScale(xmin, xmax); 81 } 82 83 QwtPlotRescaler *rescaler = new QwtPlotRescaler(plot->canvas()); 84 rescaler->setRescalePolicy(QwtPlotRescaler::Fixed); 85 86 //( void ) new QwtPlotMagnifier( plot->canvas() ); 87 88 plot->canvas()->installEventFilter(this); 89 90 for (uint32_t i = 0; i < nb_samples; i++) { 91 addTriangle(start_angle + i * (end_angle - start_angle + 1) / nb_samples, 92 start_angle + 93 (i + 1) * (end_angle - start_angle + 1) / nb_samples); 94 } 95 } 96 97 RangeFinderPlot::~RangeFinderPlot() { delete plot; } 98 99 void RangeFinderPlot::XmlEvent(QDomElement dom) { XmlSetup(dom); } 100 101 bool RangeFinderPlot::eventFilter(QObject *o, QEvent *e) { 102 if (o == plot->canvas()) { 103 switch (e->type()) { 104 case QEvent::MouseButtonPress: { 105 mousePressEvent((QMouseEvent *)e); 106 break; 107 } 108 109 default: 110 break; 111 } 112 } 113 return plot->eventFilter(o, e); 114 } 132 115 133 116 // 134 117 // Set a plain canvas frame and align the scales to it 135 118 // 136 void RangeFinderPlot::alignScales(void) 137 { 138 // The code below shows how to align the scales to 139 // the canvas frame, but is also a good example demonstrating 140 // why the spreaded API needs polishing. 141 /* 142 plot->canvas()->setFrameStyle(QFrame::Box | QFrame::Plain ); 143 plot->canvas()->setLineWidth(1); 144 */ 145 for ( int i = 0; i < QwtPlot::axisCnt; i++ ) 146 { 147 QwtScaleWidget *scaleWidget = (QwtScaleWidget *)plot->axisWidget(i); 148 if ( scaleWidget ) 149 scaleWidget->setMargin(0); 150 151 QwtScaleDraw *scaleDraw = (QwtScaleDraw *)plot->axisScaleDraw(i); 152 if ( scaleDraw ) 153 scaleDraw->enableComponent(QwtAbstractScaleDraw::Backbone, false); 154 } 155 } 156 157 void RangeFinderPlot::setXAxisScale(float xmin,float xmax) 158 { 159 xmin_orig=xmin; 160 xmax_orig=xmax; 161 plot->setAxisScale(QwtPlot::xBottom, xmin_orig, xmax_orig); 162 163 } 164 165 void RangeFinderPlot::setYAxisScale(float ymin,float ymax) 166 { 167 ymin_orig=ymin; 168 ymax_orig=ymax; 169 plot->setAxisScale(QwtPlot::yLeft, ymin_orig, ymax_orig); 170 } 171 172 void RangeFinderPlot::BufEvent(char **buf,int *buf_size,uint16_t period,bool big_endian) 173 { 174 plot->setEnabled(IsEnabled()); 175 if(IsEnabled()==false || RefreshRate_ms()!=period) return; 176 177 for(uint32_t i=0;i<nb_samples;i++) 178 { 179 if(data_type=="float") 180 { 181 uint32_t data_raw; 182 float* data=(float*)&data_raw; 183 184 memcpy((void*)&data_raw,*buf,sizeof(uint32_t)); 185 *buf+=sizeof(uint32_t); 186 if(big_endian==true) data_raw=qFromBigEndian(data_raw); 187 SetTriangle(i,*data); 188 } 189 else if(data_type=="int8_t") 190 { 191 int8_t data; 192 memcpy((void*)&data,*buf,sizeof(data)); 193 *buf+=sizeof(data); 194 SetTriangle(i,data); 195 } 196 else if(data_type=="int16_t") 197 { 198 int16_t data; 199 memcpy((void*)&data,*buf,sizeof(data)); 200 *buf+=sizeof(data); 201 if(big_endian==true) data=qFromBigEndian(data); 202 SetTriangle(i,data); 203 } 204 else 205 { 206 printf("RangeFinderPlot::BufEvent unknown type %s\n",data_type.toLocal8Bit().constData()); 207 } 208 } 209 210 plot->replot(); 211 } 212 213 void RangeFinderPlot::addTriangle(float angle_min, float angle_max) 214 { 215 QwtPlotShapeItem *item = new QwtPlotShapeItem(); 216 217 item->setRenderHint( QwtPlotItem::RenderAntialiased, true ); 218 item->attach(plot); 219 triangles.append(item); 220 221 } 222 223 void RangeFinderPlot::SetTriangle(uint32_t id,float length) 224 { 225 QPainterPath path; 226 QPolygonF triangle; 227 float angle_min=start_angle+id*(end_angle-start_angle+1)/nb_samples; 228 float angle_max=start_angle+(id+1)*(end_angle-start_angle+1)/nb_samples; 229 230 if(invert_axis) { 231 angle_min=90-angle_min; 232 angle_max=90-angle_max; 233 } 234 235 triangle += QPointF( 0,0 ); 236 triangle += QPointF( length*cos(angle_min*M_PI/180.),length*sin(angle_min*M_PI/180.) ); 237 triangle += QPointF( length*cos(angle_max*M_PI/180.),length*sin(angle_max*M_PI/180.) ); 238 239 path.addPolygon( triangle ); 240 241 path.closeSubpath(); 242 triangles.at(id)->setShape(path); 243 244 QColor fillColor = "SandyBrown"; 245 fillColor.setAlpha( 200 ); 246 247 QPen pen( QColor("SandyBrown"), 1 ); 248 pen.setJoinStyle( Qt::MiterJoin ); 249 triangles.at(id)->setPen( pen ); 250 triangles.at(id)->setBrush( fillColor ); 251 } 252 253 //context menu 254 void RangeFinderPlot::mousePressEvent(QMouseEvent *event) 255 { 256 if (event->button() == Qt::RightButton) 257 { 258 QMenu *menu = new QMenu("nom", plot); 259 // ajout des actions 260 QAction *a,*z; 261 262 a=menu->addAction("reset y zoom"); 263 264 appendmenu(menu); 265 z=execmenu(plot,menu,event->globalPos()); 266 delete menu; 267 268 if(z==a) 269 { 270 //zoom to original size 271 if(!invert_axis) { 272 plot->setAxisScale(QwtPlot::yLeft, ymin_orig, ymax_orig); 273 } else { 274 plot->setAxisScale(QwtPlot::yLeft, xmin_orig, xmax_orig); 275 } 276 plot->replot(); 277 } 278 } 279 } 280 281 119 void RangeFinderPlot::alignScales(void) { 120 // The code below shows how to align the scales to 121 // the canvas frame, but is also a good example demonstrating 122 // why the spreaded API needs polishing. 123 /* 124 plot->canvas()->setFrameStyle(QFrame::Box | QFrame::Plain ); 125 plot->canvas()->setLineWidth(1); 126 */ 127 for (int i = 0; i < QwtPlot::axisCnt; i++) { 128 QwtScaleWidget *scaleWidget = (QwtScaleWidget *)plot->axisWidget(i); 129 if (scaleWidget) 130 scaleWidget->setMargin(0); 131 132 QwtScaleDraw *scaleDraw = (QwtScaleDraw *)plot->axisScaleDraw(i); 133 if (scaleDraw) 134 scaleDraw->enableComponent(QwtAbstractScaleDraw::Backbone, false); 135 } 136 } 137 138 void RangeFinderPlot::setXAxisScale(float xmin, float xmax) { 139 xmin_orig = xmin; 140 xmax_orig = xmax; 141 plot->setAxisScale(QwtPlot::xBottom, xmin_orig, xmax_orig); 142 } 143 144 void RangeFinderPlot::setYAxisScale(float ymin, float ymax) { 145 ymin_orig = ymin; 146 ymax_orig = ymax; 147 plot->setAxisScale(QwtPlot::yLeft, ymin_orig, ymax_orig); 148 } 149 150 void RangeFinderPlot::BufEvent(char **buf, int *buf_size, uint16_t period, 151 bool big_endian) { 152 plot->setEnabled(IsEnabled()); 153 if (IsEnabled() == false || RefreshRate_ms() != period) 154 return; 155 156 for (uint32_t i = 0; i < nb_samples; i++) { 157 if (data_type == "float") { 158 uint32_t data_raw; 159 float *data = (float *)&data_raw; 160 161 memcpy((void *)&data_raw, *buf, sizeof(uint32_t)); 162 *buf += sizeof(uint32_t); 163 if (big_endian == true) 164 data_raw = qFromBigEndian(data_raw); 165 SetTriangle(i, *data); 166 } else if (data_type == "int8_t") { 167 int8_t data; 168 memcpy((void *)&data, *buf, sizeof(data)); 169 *buf += sizeof(data); 170 SetTriangle(i, data); 171 } else if (data_type == "int16_t") { 172 int16_t data; 173 memcpy((void *)&data, *buf, sizeof(data)); 174 *buf += sizeof(data); 175 if (big_endian == true) 176 data = qFromBigEndian(data); 177 SetTriangle(i, data); 178 } else { 179 printf("RangeFinderPlot::BufEvent unknown type %s\n", 180 data_type.toLocal8Bit().constData()); 181 } 182 } 183 184 plot->replot(); 185 } 186 187 void RangeFinderPlot::addTriangle(float angle_min, float angle_max) { 188 QwtPlotShapeItem *item = new QwtPlotShapeItem(); 189 190 item->setRenderHint(QwtPlotItem::RenderAntialiased, true); 191 item->attach(plot); 192 triangles.append(item); 193 } 194 195 void RangeFinderPlot::SetTriangle(uint32_t id, float length) { 196 QPainterPath path; 197 QPolygonF triangle; 198 float angle_min = 199 start_angle + id * (end_angle - start_angle + 1) / nb_samples; 200 float angle_max = 201 start_angle + (id + 1) * (end_angle - start_angle + 1) / nb_samples; 202 203 if (invert_axis) { 204 angle_min = 90 - angle_min; 205 angle_max = 90 - angle_max; 206 } 207 208 triangle += QPointF(0, 0); 209 triangle += QPointF(length * cos(angle_min * M_PI / 180.), 210 length * sin(angle_min * M_PI / 180.)); 211 triangle += QPointF(length * cos(angle_max * M_PI / 180.), 212 length * sin(angle_max * M_PI / 180.)); 213 214 path.addPolygon(triangle); 215 216 path.closeSubpath(); 217 triangles.at(id)->setShape(path); 218 219 QColor fillColor = "SandyBrown"; 220 fillColor.setAlpha(200); 221 222 QPen pen(QColor("SandyBrown"), 1); 223 pen.setJoinStyle(Qt::MiterJoin); 224 triangles.at(id)->setPen(pen); 225 triangles.at(id)->setBrush(fillColor); 226 } 227 228 // context menu 229 void RangeFinderPlot::mousePressEvent(QMouseEvent *event) { 230 if (event->button() == Qt::RightButton) { 231 QMenu *menu = new QMenu("nom", plot); 232 // ajout des actions 233 QAction *a, *z; 234 235 a = menu->addAction("reset y zoom"); 236 237 appendmenu(menu); 238 z = execmenu(plot, menu, event->globalPos()); 239 delete menu; 240 241 if (z == a) { 242 // zoom to original size 243 if (!invert_axis) { 244 plot->setAxisScale(QwtPlot::yLeft, ymin_orig, ymax_orig); 245 } else { 246 plot->setAxisScale(QwtPlot::yLeft, xmin_orig, xmax_orig); 247 } 248 plot->replot(); 249 } 250 } 251 } -
trunk/tools/FlairGCS/src/RangeFinderPlot.h
r10 r15 14 14 class QMouseEvent; 15 15 16 class RangeFinderPlot : public DataRemote 17 { 18 Q_OBJECT 16 class RangeFinderPlot : public DataRemote { 17 Q_OBJECT 19 18 20 public: 21 RangeFinderPlot(Layout* parent,int row, int col,QString name,QString x_name,QString y_name, 22 float xmin, float xmax,float ymin, float ymax, 23 float start_angle,float end_angle,uint32_t nb_samples,QString data_type, 24 bool invert_axis,bool enabled,int period); 25 ~RangeFinderPlot(); 19 public: 20 RangeFinderPlot(Layout *parent, int row, int col, QString name, 21 QString x_name, QString y_name, float xmin, float xmax, 22 float ymin, float ymax, float start_angle, float end_angle, 23 uint32_t nb_samples, QString data_type, bool invert_axis, 24 bool enabled, int period); 25 ~RangeFinderPlot(); 26 26 27 28 27 protected: 28 void mousePressEvent(QMouseEvent *event); 29 29 30 31 void setYAxisScale(float ymin,float ymax);32 void setXAxisScale(float xmin,float xmax);33 34 void SetTriangle(uint32_t id,float length);35 QwtPlot*plot;36 37 38 float xmin_orig,xmax_orig,ymin_orig,ymax_orig;39 float start_angle,end_angle;40 41 42 QList<QwtPlotShapeItem*> triangles;43 30 private: 31 void setYAxisScale(float ymin, float ymax); 32 void setXAxisScale(float xmin, float xmax); 33 void addTriangle(float angle_min, float angle_max); 34 void SetTriangle(uint32_t id, float length); 35 QwtPlot *plot; 36 void XmlEvent(QDomElement dom); 37 void alignScales(void); 38 float xmin_orig, xmax_orig, ymin_orig, ymax_orig; 39 float start_angle, end_angle; 40 uint32_t nb_samples; 41 QString data_type; 42 QList<QwtPlotShapeItem *> triangles; 43 bool invert_axis; 44 44 45 46 void BufEvent(char** buf,int *buf_size,uint16_t period,bool big_endian);45 bool eventFilter(QObject *, QEvent *); 46 void BufEvent(char **buf, int *buf_size, uint16_t period, bool big_endian); 47 47 }; 48 48 49 50 49 #endif // RANGEFINDERPLOT_H_INCLUDED -
trunk/tools/FlairGCS/src/Scope.cpp
r10 r15 21 21 #define WHEEL_DIVIDOR 30 22 22 23 Scope::Scope(QString title,float ymin,float ymax,float view_size_s,unsigned int refresh_rate_ms,unsigned int history_size): QwtPlot() { 24 this->ymin=ymin; 25 this->ymax=ymax; 26 this->history_size=history_size; 27 this->view_size_s=view_size_s; 28 orig_view_size_s=view_size_s; 29 30 //scroll bar 31 scrollbar=new ScrollBar(Qt::Horizontal,canvas()); 32 connect(scrollbar,SIGNAL(valueChanged(Qt::Orientation,float,float)),this,SLOT(scrollBarMoved(Qt::Orientation,float,float))); 33 scrolling=true; 34 35 //minimum size; sinon widget trop grand 36 setMinimumHeight(10); 37 setMinimumWidth(1); 38 39 alignScales();//is it necessary? 40 41 // Initialize data 42 elapsed_time_s=0; 43 44 // Assign a title 45 setTitle(title); 46 47 // Axis 48 setAxisTitle(QwtPlot::xBottom, "Time (s)"); 49 setAxisScale(QwtPlot::xBottom,0, view_size_s); 50 51 setAxisTitle(QwtPlot::yLeft, "Values"); 52 setAxisScale(QwtPlot::yLeft, ymin, ymax); 53 54 // grid 55 QwtPlotGrid *grid = new QwtPlotGrid; 56 grid->setPen(QPen(Qt::black, 0, Qt::DotLine)); 57 grid->attach(this); 58 59 //zoomer 60 QwtPlotMagnifier * zoomer = new QwtPlotMagnifier(canvas()); 61 zoomer->setWheelModifiers( Qt::ControlModifier ); 62 zoomer->setMouseButton(Qt::NoButton); 63 zoomer->setAxisEnabled(xBottom,0); 64 65 //scroller 66 QwtPlotPanner *scroller =new QwtPlotPanner(canvas()); 67 scroller->setAxisEnabled(xBottom,0); 68 69 //legend 70 QwtLegend* new_legend=new QwtLegend(); 71 new_legend->setDefaultItemMode(QwtLegendData::Checkable); 72 insertLegend(new_legend, QwtPlot::BottomLegend); 73 74 connect( new_legend, SIGNAL( checked( const QVariant &, bool, int ) ), SLOT( legendChecked( const QVariant &, bool ) ) ); 75 76 QTimer *timer = new QTimer(this); 77 connect(timer, SIGNAL(timeout()), this, SLOT(replot())); 78 timer->start(refresh_rate_ms); 23 Scope::Scope(QString title, float ymin, float ymax, float view_size_s, 24 unsigned int refresh_rate_ms, unsigned int history_size) 25 : QwtPlot() { 26 this->ymin = ymin; 27 this->ymax = ymax; 28 this->history_size = history_size; 29 this->view_size_s = view_size_s; 30 orig_view_size_s = view_size_s; 31 32 // scroll bar 33 scrollbar = new ScrollBar(Qt::Horizontal, canvas()); 34 connect(scrollbar, SIGNAL(valueChanged(Qt::Orientation, float, float)), this, 35 SLOT(scrollBarMoved(Qt::Orientation, float, float))); 36 scrolling = true; 37 38 // minimum size; sinon widget trop grand 39 setMinimumHeight(10); 40 setMinimumWidth(1); 41 42 alignScales(); // is it necessary? 43 44 // Initialize data 45 elapsed_time_s = 0; 46 47 // Assign a title 48 setTitle(title); 49 50 // Axis 51 setAxisTitle(QwtPlot::xBottom, "Time (s)"); 52 setAxisScale(QwtPlot::xBottom, 0, view_size_s); 53 54 setAxisTitle(QwtPlot::yLeft, "Values"); 55 setAxisScale(QwtPlot::yLeft, ymin, ymax); 56 57 // grid 58 QwtPlotGrid *grid = new QwtPlotGrid; 59 grid->setPen(QPen(Qt::black, 0, Qt::DotLine)); 60 grid->attach(this); 61 62 // zoomer 63 QwtPlotMagnifier *zoomer = new QwtPlotMagnifier(canvas()); 64 zoomer->setWheelModifiers(Qt::ControlModifier); 65 zoomer->setMouseButton(Qt::NoButton); 66 zoomer->setAxisEnabled(xBottom, 0); 67 68 // scroller 69 QwtPlotPanner *scroller = new QwtPlotPanner(canvas()); 70 scroller->setAxisEnabled(xBottom, 0); 71 72 // legend 73 QwtLegend *new_legend = new QwtLegend(); 74 new_legend->setDefaultItemMode(QwtLegendData::Checkable); 75 insertLegend(new_legend, QwtPlot::BottomLegend); 76 77 connect(new_legend, SIGNAL(checked(const QVariant &, bool, int)), 78 SLOT(legendChecked(const QVariant &, bool))); 79 80 QTimer *timer = new QTimer(this); 81 connect(timer, SIGNAL(timeout()), this, SLOT(replot())); 82 timer->start(refresh_rate_ms); 79 83 } 80 84 81 85 Scope::~Scope() { 82 for(int i=0;i<curves.count();i++) {83 84 85 86 87 86 for (int i = 0; i < curves.count(); i++) { 87 free(curves.at(i)->data_x); 88 free(curves.at(i)->data_y); 89 delete curves.at(i)->plot; 90 free(curves.at(i)); 91 } 88 92 } 89 93 90 94 void Scope::resetXView(void) { 91 //setAxisScale(QwtPlot::xBottom,0, orig_view_size_s); 92 changeViewSize(orig_view_size_s); 93 } 94 95 void Scope::resetYView(void) { 96 setAxisScale(QwtPlot::yLeft, ymin, ymax); 97 } 95 // setAxisScale(QwtPlot::xBottom,0, orig_view_size_s); 96 changeViewSize(orig_view_size_s); 97 } 98 99 void Scope::resetYView(void) { setAxisScale(QwtPlot::yLeft, ymin, ymax); } 98 100 99 101 bool Scope::eventFilter(QObject *o, QEvent *e) { 100 switch(e->type()) { 101 case QEvent::Resize: { 102 const int fw = ((QwtPlotCanvas *)canvas())->frameWidth(); 103 104 QRect rect; 105 rect.setSize(((QResizeEvent *)e)->size()); 106 rect.setRect(rect.x() + fw, rect.y() + fw, 107 rect.width() - 2 * fw, rect.height() - 2 * fw); 108 109 scrollbar->setGeometry(0, 0, rect.width(), 10); 110 return true; 111 } 112 case QEvent::Wheel: { 113 //ctrl+wheel is already handled for y zoom 114 if(!(QApplication::keyboardModifiers() & Qt::ControlModifier)) { 115 QWheelEvent *wheelevent = static_cast<QWheelEvent *> (e); 116 if(view_size_s+wheelevent->delta()/WHEEL_DIVIDOR>0) changeViewSize(view_size_s+wheelevent->delta()/WHEEL_DIVIDOR); 117 } 118 return true; 119 } 120 default: 121 break; 122 } 123 return QwtPlot::eventFilter(o, e); 102 switch (e->type()) { 103 case QEvent::Resize: { 104 const int fw = ((QwtPlotCanvas *)canvas())->frameWidth(); 105 106 QRect rect; 107 rect.setSize(((QResizeEvent *)e)->size()); 108 rect.setRect(rect.x() + fw, rect.y() + fw, rect.width() - 2 * fw, 109 rect.height() - 2 * fw); 110 111 scrollbar->setGeometry(0, 0, rect.width(), 10); 112 return true; 113 } 114 case QEvent::Wheel: { 115 // ctrl+wheel is already handled for y zoom 116 if (!(QApplication::keyboardModifiers() & Qt::ControlModifier)) { 117 QWheelEvent *wheelevent = static_cast<QWheelEvent *>(e); 118 if (view_size_s + wheelevent->delta() / WHEEL_DIVIDOR > 0) 119 changeViewSize(view_size_s + wheelevent->delta() / WHEEL_DIVIDOR); 120 } 121 return true; 122 } 123 default: 124 break; 125 } 126 return QwtPlot::eventFilter(o, e); 124 127 } 125 128 126 129 void Scope::changeViewSize(float new_view_size_s) { 127 view_size_s=new_view_size_s; 128 129 if(scrolling==false) { 130 //4 cas: on utilise le temps au milieu de la vue actuelle 131 132 //le temps total est plus petit que le view_size_s, on affiche tout: 133 if(elapsed_time_s<view_size_s) { 134 scrolling=true; 135 } else { 136 double min=(min_scroll+max_scroll)/2-view_size_s/2; 137 double max=(min_scroll+max_scroll)/2+view_size_s/2; 138 //on va du debut jusqu'a view size 139 if( min<0) { 140 min=0; 141 max=view_size_s; 142 } 143 //on va de fin-viewsize jusqu'a la fin 144 if(max>elapsed_time_s) { 145 min=elapsed_time_s-view_size_s; 146 max=elapsed_time_s; 147 } 148 scrollbar->moveSlider(min,max);//move slider coupe le signal, on fait aussi le scrollbar 149 scrollBarMoved(Qt::Horizontal,min,max); 150 } 151 } 152 } 153 154 void Scope::legendChecked( const QVariant &itemInfo, bool on ) { 155 QwtPlotItem *plotItem=infoToItem(itemInfo); 156 if(plotItem) showCurve( plotItem, on ); 130 view_size_s = new_view_size_s; 131 132 if (scrolling == false) { 133 // 4 cas: on utilise le temps au milieu de la vue actuelle 134 135 // le temps total est plus petit que le view_size_s, on affiche tout: 136 if (elapsed_time_s < view_size_s) { 137 scrolling = true; 138 } else { 139 double min = (min_scroll + max_scroll) / 2 - view_size_s / 2; 140 double max = (min_scroll + max_scroll) / 2 + view_size_s / 2; 141 // on va du debut jusqu'a view size 142 if (min < 0) { 143 min = 0; 144 max = view_size_s; 145 } 146 // on va de fin-viewsize jusqu'a la fin 147 if (max > elapsed_time_s) { 148 min = elapsed_time_s - view_size_s; 149 max = elapsed_time_s; 150 } 151 scrollbar->moveSlider( 152 min, max); // move slider coupe le signal, on fait aussi le scrollbar 153 scrollBarMoved(Qt::Horizontal, min, max); 154 } 155 } 156 } 157 158 void Scope::legendChecked(const QVariant &itemInfo, bool on) { 159 QwtPlotItem *plotItem = infoToItem(itemInfo); 160 if (plotItem) 161 showCurve(plotItem, on); 157 162 } 158 163 159 164 void Scope::showCurve(QwtPlotItem *item, bool on) { 160 item->setVisible(on); 161 162 QwtLegend *lgd=qobject_cast<QwtLegend*>(legend()); 163 164 QList<QWidget*> legendWidgets=lgd->legendWidgets(itemToInfo(item)); 165 166 if(legendWidgets.size()==1) { 167 QwtLegendLabel *legendLabel=qobject_cast<QwtLegendLabel*>(legendWidgets[0]); 168 169 if(legendLabel) legendLabel->setChecked( on ); 170 } 171 } 172 173 int Scope::addCurve(QPen pen,QString legend) { 174 Curve* curve=(Curve*)malloc(sizeof(Curve)); 175 curve->data_x=(double*)calloc(history_size,sizeof(double)); 176 curve->data_y=(double*)calloc(history_size,sizeof(double)); 177 curve->index=0; 178 curve->min_index=0; 179 curve->max_index=0; 180 181 // Insert new curve 182 curve->plot=new QwtPlotCurve(legend); 183 curve->plot->attach(this); 184 curve->plot->setPen(pen); 185 curves.append(curve); 186 187 showCurve(curve->plot, true); 188 189 return curves.count()-1; 190 } 191 192 void Scope::updateCurve(Curve* curve) { 193 if(scrolling==true) { 194 curve->plot->setRawSamples(&curve->data_x[curve->min_index], &curve->data_y[curve->min_index], curve->max_index-curve->min_index); 195 } 196 197 if(curve->index==history_size) { 198 //printf("a revoir qd on arrive a la fin, il faudrait faire un realloc pour rien perdre\n"); 199 //attention le setrawdata s'attend a ce que l'adresse change pas, ce qui n'est pas le cas avec lerealloc 200 //il faudra refaire un setrawdata ici 201 curve->index=0; 202 curve->min_index=0; 203 scrolling=true; 204 } 205 206 //determine les index pour la visualisation 207 if(scrolling==true) { 208 curve->max_index=curve->index; 209 computeMinIndex(curve,elapsed_time_s-view_size_s); 210 } 211 212 scrollbar->setBase(0,elapsed_time_s); 213 if(scrolling==true) { 214 scrollbar->moveSlider(elapsed_time_s-view_size_s,elapsed_time_s); 215 216 if(elapsed_time_s<view_size_s) { 217 setAxisScale(QwtPlot::xBottom,0, view_size_s); 218 } else { 219 setAxisScale(QwtPlot::xBottom,elapsed_time_s-view_size_s, elapsed_time_s); 220 } 165 item->setVisible(on); 166 167 QwtLegend *lgd = qobject_cast<QwtLegend *>(legend()); 168 169 QList<QWidget *> legendWidgets = lgd->legendWidgets(itemToInfo(item)); 170 171 if (legendWidgets.size() == 1) { 172 QwtLegendLabel *legendLabel = 173 qobject_cast<QwtLegendLabel *>(legendWidgets[0]); 174 175 if (legendLabel) 176 legendLabel->setChecked(on); 177 } 178 } 179 180 int Scope::addCurve(QPen pen, QString legend) { 181 Curve *curve = (Curve *)malloc(sizeof(Curve)); 182 curve->data_x = (double *)calloc(history_size, sizeof(double)); 183 curve->data_y = (double *)calloc(history_size, sizeof(double)); 184 curve->index = 0; 185 curve->min_index = 0; 186 curve->max_index = 0; 187 188 // Insert new curve 189 curve->plot = new QwtPlotCurve(legend); 190 curve->plot->attach(this); 191 curve->plot->setPen(pen); 192 curves.append(curve); 193 194 showCurve(curve->plot, true); 195 196 return curves.count() - 1; 197 } 198 199 void Scope::updateCurve(Curve *curve) { 200 if (scrolling == true) { 201 curve->plot->setRawSamples(&curve->data_x[curve->min_index], 202 &curve->data_y[curve->min_index], 203 curve->max_index - curve->min_index); 204 } 205 206 if (curve->index == history_size) { 207 // printf("a revoir qd on arrive a la fin, il faudrait faire un realloc pour 208 // rien perdre\n"); 209 // attention le setrawdata s'attend a ce que l'adresse change pas, ce qui 210 // n'est pas le cas avec lerealloc 211 // il faudra refaire un setrawdata ici 212 curve->index = 0; 213 curve->min_index = 0; 214 scrolling = true; 215 } 216 217 // determine les index pour la visualisation 218 if (scrolling == true) { 219 curve->max_index = curve->index; 220 computeMinIndex(curve, elapsed_time_s - view_size_s); 221 } 222 223 scrollbar->setBase(0, elapsed_time_s); 224 if (scrolling == true) { 225 scrollbar->moveSlider(elapsed_time_s - view_size_s, elapsed_time_s); 226 227 if (elapsed_time_s < view_size_s) { 228 setAxisScale(QwtPlot::xBottom, 0, view_size_s); 221 229 } else { 222 scrollbar->moveSlider(min_scroll,max_scroll); 223 } 230 setAxisScale(QwtPlot::xBottom, elapsed_time_s - view_size_s, 231 elapsed_time_s); 232 } 233 } else { 234 scrollbar->moveSlider(min_scroll, max_scroll); 235 } 224 236 } 225 237 226 238 void Scope::alignScales(void) { 227 // The code below shows how to align the scales to 228 // the canvas frame, but is also a good example demonstrating 229 // why the spreaded API needs polishing. 230 /* 231 plot->canvas()->setFrameStyle(QFrame::Box | QFrame::Plain ); 232 plot->canvas()->setLineWidth(1); 233 */ 234 for(int i = 0;i<QwtPlot::axisCnt;i++) { 235 QwtScaleWidget *scaleWidget = (QwtScaleWidget *)axisWidget(i); 236 if(scaleWidget) scaleWidget->setMargin(0); 237 238 QwtScaleDraw *scaleDraw=(QwtScaleDraw *)axisScaleDraw(i); 239 if(scaleDraw) scaleDraw->enableComponent(QwtAbstractScaleDraw::Backbone, false); 240 } 241 } 242 243 void Scope::scrollBarMoved(Qt::Orientation o, float min, float max) 244 { 245 min_scroll=min; 246 max_scroll=max; 247 248 if(max==scrollbar->maxBaseValue()) { 249 scrolling=true; 239 // The code below shows how to align the scales to 240 // the canvas frame, but is also a good example demonstrating 241 // why the spreaded API needs polishing. 242 /* 243 plot->canvas()->setFrameStyle(QFrame::Box | QFrame::Plain ); 244 plot->canvas()->setLineWidth(1); 245 */ 246 for (int i = 0; i < QwtPlot::axisCnt; i++) { 247 QwtScaleWidget *scaleWidget = (QwtScaleWidget *)axisWidget(i); 248 if (scaleWidget) 249 scaleWidget->setMargin(0); 250 251 QwtScaleDraw *scaleDraw = (QwtScaleDraw *)axisScaleDraw(i); 252 if (scaleDraw) 253 scaleDraw->enableComponent(QwtAbstractScaleDraw::Backbone, false); 254 } 255 } 256 257 void Scope::scrollBarMoved(Qt::Orientation o, float min, float max) { 258 min_scroll = min; 259 max_scroll = max; 260 261 if (max == scrollbar->maxBaseValue()) { 262 scrolling = true; 263 } else { 264 scrolling = false; 265 setAxisScale(QwtPlot::xBottom, min, max); 266 267 // determine les index pour la visualisation 268 for (int i = 0; i < curves.count(); i++) { 269 computeMinIndex(curves.at(i), min); 270 computeMaxIndex(curves.at(i), max); 271 curves.at(i)->plot->setRawSamples( 272 &curves.at(i)->data_x[curves.at(i)->min_index], 273 &curves.at(i)->data_y[curves.at(i)->min_index], 274 curves.at(i)->max_index - curves.at(i)->min_index); 275 } 276 } 277 } 278 279 // TODO: faire une dichotomie 280 void Scope::computeMinIndex(Curve *curve, float displayed_min_time) { 281 if (curve->data_x[curve->index] > displayed_min_time) { 282 if (curve->data_x[curve->min_index] < displayed_min_time) { 283 while (curve->data_x[curve->min_index] < displayed_min_time && 284 curve->min_index != curve->index) 285 curve->min_index++; 250 286 } else { 251 scrolling=false; 252 setAxisScale(QwtPlot::xBottom,min,max); 253 254 //determine les index pour la visualisation 255 for(int i=0;i<curves.count();i++) { 256 computeMinIndex(curves.at(i),min); 257 computeMaxIndex(curves.at(i),max); 258 curves.at(i)->plot->setRawSamples(&curves.at(i)->data_x[curves.at(i)->min_index], &curves.at(i)->data_y[curves.at(i)->min_index], curves.at(i)->max_index-curves.at(i)->min_index); 259 } 260 } 261 } 262 263 //TODO: faire une dichotomie 264 void Scope::computeMinIndex(Curve* curve,float displayed_min_time) { 265 if(curve->data_x[curve->index]>displayed_min_time) { 266 if(curve->data_x[curve->min_index]<displayed_min_time) { 267 while(curve->data_x[curve->min_index]<displayed_min_time && curve->min_index!=curve->index) curve->min_index++; 268 } else { 269 while(curve->data_x[curve->min_index]>displayed_min_time && curve->min_index!=0) curve->min_index--; 270 } 271 } 272 } 273 274 void Scope::computeMaxIndex(Curve* curve,float displayed_max_time) { 275 if(curve->data_x[curve->max_index]<displayed_max_time) { 276 while(curve->data_x[curve->max_index]<displayed_max_time && curve->max_index!=curve->index) curve->max_index++; 277 } else { 278 while(curve->data_x[curve->max_index]>displayed_max_time) curve->max_index--; 279 } 280 } 287 while (curve->data_x[curve->min_index] > displayed_min_time && 288 curve->min_index != 0) 289 curve->min_index--; 290 } 291 } 292 } 293 294 void Scope::computeMaxIndex(Curve *curve, float displayed_max_time) { 295 if (curve->data_x[curve->max_index] < displayed_max_time) { 296 while (curve->data_x[curve->max_index] < displayed_max_time && 297 curve->max_index != curve->index) 298 curve->max_index++; 299 } else { 300 while (curve->data_x[curve->max_index] > displayed_max_time) 301 curve->max_index--; 302 } 303 } -
trunk/tools/FlairGCS/src/Scope.h
r10 r15 14 14 class QMouseEvent; 15 15 16 class Scope : public QwtPlot {17 16 class Scope : public QwtPlot { 17 Q_OBJECT 18 18 19 public: 20 Scope(QString title,float ymin, float ymax,float view_size_s=20,unsigned int refresh_rate_ms=40,unsigned int history_size=20000); 21 ~Scope(); 22 int addCurve(QPen pen,QString legend); 23 void resetXView(void); 24 void resetYView(void); 19 public: 20 Scope(QString title, float ymin, float ymax, float view_size_s = 20, 21 unsigned int refresh_rate_ms = 40, unsigned int history_size = 20000); 22 ~Scope(); 23 int addCurve(QPen pen, QString legend); 24 void resetXView(void); 25 void resetYView(void); 25 26 26 27 28 QwtPlotCurve*plot;29 double*data_x;30 double*data_y;31 32 33 34 35 QList<Curve*> curves;36 27 protected: 28 struct Curve { 29 QwtPlotCurve *plot; 30 double *data_x; 31 double *data_y; 32 unsigned int index; 33 unsigned int min_index; 34 unsigned int max_index; 35 }; 36 QList<Curve *> curves; 37 float elapsed_time_s; 37 38 38 void updateCurve(Curve*curve);39 39 void updateCurve(Curve *curve); 40 bool eventFilter(QObject *, QEvent *); 40 41 41 42 float ymin,ymax;43 float view_size_s,orig_view_size_s;44 45 ScrollBar*scrollbar;46 47 float min_scroll,max_scroll;42 private: 43 float ymin, ymax; 44 float view_size_s, orig_view_size_s; 45 unsigned int history_size; 46 ScrollBar *scrollbar; 47 bool scrolling; 48 float min_scroll, max_scroll; 48 49 49 50 51 void computeMinIndex(Curve* curve,float displayed_min_time);52 void computeMaxIndex(Curve* curve,float displayed_max_time);53 50 void alignScales(void); 51 void showCurve(QwtPlotItem *item, bool on); 52 void computeMinIndex(Curve *curve, float displayed_min_time); 53 void computeMaxIndex(Curve *curve, float displayed_max_time); 54 void changeViewSize(float new_view_size_s); 54 55 55 56 void legendChecked(const QVariant &itemInfo, bool on);57 56 private slots: 57 void legendChecked(const QVariant &itemInfo, bool on); 58 void scrollBarMoved(Qt::Orientation o, float min, float max); 58 59 }; 59 60 60 61 61 #endif // SCOPE_H_INCLUDED -
trunk/tools/FlairGCS/src/ScopeFixedStep.cpp
r10 r15 7 7 #include <qwt_plot_curve.h> 8 8 9 ScopeFixedStep::ScopeFixedStep(QString title,float ymin,float ymax,float step_s,float view_size_s,unsigned int refresh_rate_ms,unsigned int history_size): Scope(title,ymin,ymax,view_size_s,refresh_rate_ms,history_size) { 10 this->step_s=step_s; 9 ScopeFixedStep::ScopeFixedStep(QString title, float ymin, float ymax, 10 float step_s, float view_size_s, 11 unsigned int refresh_rate_ms, 12 unsigned int history_size) 13 : Scope(title, ymin, ymax, view_size_s, refresh_rate_ms, history_size) { 14 this->step_s = step_s; 11 15 } 12 16 13 ScopeFixedStep::~ScopeFixedStep() { 17 ScopeFixedStep::~ScopeFixedStep() {} 14 18 19 void ScopeFixedStep::plot(double *value) { 20 elapsed_time_s += step_s; 21 for (int i = 0; i < curves.count(); i++) { 22 Curve *curve = curves.at(i); 23 24 curve->data_x[curve->index] = elapsed_time_s; 25 curve->data_y[curve->index] = value[i]; 26 curve->index++; 27 28 updateCurve(curve); 29 } 15 30 } 16 17 void ScopeFixedStep::plot(double* value) {18 elapsed_time_s+=step_s;19 for(int i=0;i<curves.count();i++) {20 Curve* curve=curves.at(i);21 22 curve->data_x[curve->index]=elapsed_time_s;23 curve->data_y[curve->index]=value[i];24 curve->index++;25 26 updateCurve(curve);27 }28 } -
trunk/tools/FlairGCS/src/ScopeFixedStep.h
r10 r15 8 8 #include <Scope.h> 9 9 10 class ScopeFixedStep : public Scope { 11 public: 12 ScopeFixedStep(QString title, float ymin, float ymax, float step_s, 13 float view_size_s = 20, unsigned int refresh_rate_ms = 40, 14 unsigned int history_size = 20000); 15 ~ScopeFixedStep(); 16 void plot(double *value); 10 17 11 class ScopeFixedStep: public Scope { 12 public: 13 ScopeFixedStep(QString title,float ymin, float ymax,float step_s,float view_size_s=20,unsigned int refresh_rate_ms=40,unsigned int history_size=20000); 14 ~ScopeFixedStep(); 15 void plot(double* value); 16 17 protected: 18 float step_s; 18 protected: 19 float step_s; 19 20 }; 20 21 21 22 22 #endif // SCOPEFIXEDSTEP_H_INCLUDED -
trunk/tools/FlairGCS/src/ScopeVariableStep.cpp
r10 r15 8 8 #include <qwt_plot_curve.h> 9 9 10 ScopeVariableStep::ScopeVariableStep(QString title,float ymin,float ymax,float view_size_s,unsigned int refresh_rate_ms,unsigned int history_size): Scope(title,ymin,ymax,view_size_s,refresh_rate_ms,history_size) { 10 ScopeVariableStep::ScopeVariableStep(QString title, float ymin, float ymax, 11 float view_size_s, 12 unsigned int refresh_rate_ms, 13 unsigned int history_size) 14 : Scope(title, ymin, ymax, view_size_s, refresh_rate_ms, history_size) {} 11 15 16 ScopeVariableStep::~ScopeVariableStep() {} 17 18 void ScopeVariableStep::plot(double value, QTime time, 19 unsigned int curve_index) { 20 static QTime start_time = QTime::currentTime(); 21 Curve *curve = curves.at(curve_index); 22 23 elapsed_time_s = start_time.msecsTo(time) / 1000.; 24 curve->data_x[curve->index] = elapsed_time_s; 25 curve->data_y[curve->index] = value; 26 curve->index++; 27 28 updateCurve(curve); 12 29 } 13 14 ScopeVariableStep::~ScopeVariableStep() {15 16 }17 18 void ScopeVariableStep::plot(double value,QTime time,unsigned int curve_index) {19 static QTime start_time=QTime::currentTime();20 Curve* curve=curves.at(curve_index);21 22 elapsed_time_s=start_time.msecsTo(time)/1000.;23 curve->data_x[curve->index]=elapsed_time_s;24 curve->data_y[curve->index]=value;25 curve->index++;26 27 updateCurve(curve);28 } -
trunk/tools/FlairGCS/src/ScopeVariableStep.h
r10 r15 8 8 #include <Scope.h> 9 9 10 class ScopeVariableStep: public Scope { 11 public: 12 ScopeVariableStep(QString title,float ymin, float ymax,float view_size_s=20,unsigned int refresh_rate_ms=40,unsigned int history_size=20000); 13 ~ScopeVariableStep(); 14 void plot(double value,QTime time,unsigned int curve_index=0); 10 class ScopeVariableStep : public Scope { 11 public: 12 ScopeVariableStep(QString title, float ymin, float ymax, 13 float view_size_s = 20, unsigned int refresh_rate_ms = 40, 14 unsigned int history_size = 20000); 15 ~ScopeVariableStep(); 16 void plot(double value, QTime time, unsigned int curve_index = 0); 15 17 16 private: 17 18 private: 18 19 }; 19 20 20 21 21 #endif // SCOPEVARIABLESTEP_H_INCLUDED -
trunk/tools/FlairGCS/src/Scrollbar.cpp
r10 r15 7 7 #include "Scrollbar.h" 8 8 9 ScrollBar::ScrollBar(QWidget * parent): 10 QScrollBar(parent) 11 { 12 init(); 9 ScrollBar::ScrollBar(QWidget *parent) : QScrollBar(parent) { init(); } 10 11 ScrollBar::ScrollBar(Qt::Orientation o, QWidget *parent) 12 : QScrollBar(o, parent) { 13 init(); 13 14 } 14 15 15 ScrollBar::ScrollBar(Qt::Orientation o, 16 QWidget *parent): 17 QScrollBar(o, parent) 18 { 19 init(); 16 ScrollBar::ScrollBar(float minBase, float maxBase, Qt::Orientation o, 17 QWidget *parent) 18 : QScrollBar(o, parent) { 19 init(); 20 setBase(minBase, maxBase); 21 moveSlider(minBase, maxBase); 20 22 } 21 23 22 ScrollBar::ScrollBar(float minBase, float maxBase, 23 Qt::Orientation o, QWidget *parent): 24 QScrollBar(o, parent) 25 { 26 init(); 27 setBase(minBase, maxBase); 28 moveSlider(minBase, maxBase); 24 void ScrollBar::init(void) { 25 d_inverted = orientation() == Qt::Vertical; 26 d_baseTicks = 1000000; 27 d_minBase = 0.0; 28 d_maxBase = 1.0; 29 moveSlider(d_minBase, d_maxBase); 30 31 connect(this, SIGNAL(sliderMoved(int)), SLOT(catchSliderMoved(int))); 32 connect(this, SIGNAL(valueChanged(int)), SLOT(catchValueChanged(int))); 29 33 } 30 34 31 void ScrollBar::init(void) 32 { 33 d_inverted = orientation() == Qt::Vertical; 34 d_baseTicks = 1000000; 35 d_minBase = 0.0; 36 d_maxBase = 1.0; 37 moveSlider(d_minBase, d_maxBase); 38 39 connect(this, SIGNAL(sliderMoved(int)), SLOT(catchSliderMoved(int))); 40 connect(this, SIGNAL(valueChanged(int)), SLOT(catchValueChanged(int))); 35 void ScrollBar::setInverted(bool inverted) { 36 if (d_inverted != inverted) { 37 d_inverted = inverted; 38 moveSlider(minSliderValue(), maxSliderValue()); 39 } 41 40 } 42 41 43 void ScrollBar::setInverted(bool inverted) 44 { 45 if ( d_inverted != inverted ) 46 { 47 d_inverted = inverted; 48 moveSlider(minSliderValue(), maxSliderValue()); 49 } 42 bool ScrollBar::isInverted(void) const { return d_inverted; } 43 44 void ScrollBar::setBase(float min, float max) { 45 if (min != d_minBase || max != d_maxBase) { 46 d_minBase = min; 47 d_maxBase = max; 48 49 moveSlider(minSliderValue(), maxSliderValue()); 50 } 50 51 } 51 52 52 bool ScrollBar::isInverted(void) const 53 { 54 return d_inverted; 53 void ScrollBar::moveSlider(float min, float max) { 54 const int sliderTicks = 55 qRound((max - min) / (d_maxBase - d_minBase) * d_baseTicks); 56 57 // setRange initiates a valueChanged of the scrollbars 58 // in some situations. So we block 59 // and unblock the signals. 60 61 blockSignals(true); 62 63 setRange(sliderTicks / 2, d_baseTicks - sliderTicks / 2); 64 int steps = sliderTicks / 200; 65 if (steps <= 0) 66 steps = 1; 67 68 setSingleStep(steps); 69 setPageStep(sliderTicks); 70 71 int tick = mapToTick(min + (max - min) / 2); 72 if (isInverted()) 73 tick = d_baseTicks - tick; 74 75 setSliderPosition(tick); 76 blockSignals(false); 55 77 } 56 78 57 void ScrollBar::setBase(float min, float max) 58 { 59 if ( min != d_minBase || max != d_maxBase ) 60 { 61 d_minBase = min; 62 d_maxBase = max; 79 float ScrollBar::minBaseValue(void) const { return d_minBase; } 63 80 64 moveSlider(minSliderValue(), maxSliderValue()); 65 } 81 float ScrollBar::maxBaseValue(void) const { return d_maxBase; } 82 83 void ScrollBar::sliderRange(int value, float &min, float &max) const { 84 if (isInverted()) 85 value = d_baseTicks - value; 86 87 const int visibleTicks = pageStep(); 88 89 min = mapFromTick(value - visibleTicks / 2); 90 max = mapFromTick(value + visibleTicks / 2); 66 91 } 67 92 68 void ScrollBar::moveSlider(float min, float max) 69 { 70 const int sliderTicks = qRound((max - min) / 71 (d_maxBase - d_minBase) * d_baseTicks); 93 float ScrollBar::minSliderValue(void) const { 94 float min, dummy; 95 sliderRange(value(), min, dummy); 72 96 73 // setRange initiates a valueChanged of the scrollbars 74 // in some situations. So we block 75 // and unblock the signals. 76 77 blockSignals(true); 78 79 setRange(sliderTicks / 2, d_baseTicks - sliderTicks / 2); 80 int steps = sliderTicks / 200; 81 if ( steps <= 0 ) 82 steps = 1; 83 84 setSingleStep(steps); 85 setPageStep(sliderTicks); 86 87 int tick = mapToTick(min + (max - min) / 2); 88 if ( isInverted() ) 89 tick = d_baseTicks - tick; 90 91 setSliderPosition(tick); 92 blockSignals(false); 97 return min; 93 98 } 94 99 95 float ScrollBar::minBaseValue(void) const 96 { 97 return d_minBase; 100 float ScrollBar::maxSliderValue(void) const { 101 float max, dummy; 102 sliderRange(value(), dummy, max); 103 104 return max; 98 105 } 99 106 100 float ScrollBar::maxBaseValue(void) const 101 { 102 return d_maxBase; 107 int ScrollBar::mapToTick(float v) const { 108 return (int)((v - d_minBase) / (d_maxBase - d_minBase) * d_baseTicks); 103 109 } 104 110 105 void ScrollBar::sliderRange(int value, float &min, float &max) const 106 { 107 if ( isInverted() ) 108 value = d_baseTicks - value; 109 110 const int visibleTicks = pageStep(); 111 112 min = mapFromTick(value - visibleTicks / 2); 113 max = mapFromTick(value + visibleTicks / 2); 111 float ScrollBar::mapFromTick(int tick) const { 112 return d_minBase + (d_maxBase - d_minBase) * tick / d_baseTicks; 114 113 } 115 114 116 float ScrollBar::minSliderValue(void) const 117 { 118 float min, dummy; 119 sliderRange(value(), min, dummy); 120 121 return min; 115 void ScrollBar::catchValueChanged(int value) { 116 float min, max; 117 sliderRange(value, min, max); 118 Q_EMIT valueChanged(orientation(), min, max); 122 119 } 123 120 124 float ScrollBar::maxSliderValue(void) const 125 { 126 float max, dummy; 127 sliderRange(value(), dummy, max); 128 129 return max; 121 void ScrollBar::catchSliderMoved(int value) { 122 float min, max; 123 sliderRange(value, min, max); 124 Q_EMIT sliderMoved(orientation(), min, max); 130 125 } 131 126 132 int ScrollBar::mapToTick(float v) const 133 { 134 return (int) ( ( v - d_minBase) / (d_maxBase - d_minBase ) * d_baseTicks ); 127 int ScrollBar::extent(void) const { 128 QStyleOptionSlider opt; 129 opt.init(this); 130 opt.subControls = QStyle::SC_None; 131 opt.activeSubControls = QStyle::SC_None; 132 opt.orientation = orientation(); 133 opt.minimum = minimum(); 134 opt.maximum = maximum(); 135 opt.sliderPosition = sliderPosition(); 136 opt.sliderValue = value(); 137 opt.singleStep = singleStep(); 138 opt.pageStep = pageStep(); 139 opt.upsideDown = invertedAppearance(); 140 if (orientation() == Qt::Horizontal) 141 opt.state |= QStyle::State_Horizontal; 142 return style()->pixelMetric(QStyle::PM_ScrollBarExtent, &opt, this); 135 143 } 136 137 float ScrollBar::mapFromTick(int tick) const138 {139 return d_minBase + ( d_maxBase - d_minBase ) * tick / d_baseTicks;140 }141 142 void ScrollBar::catchValueChanged(int value)143 {144 float min, max;145 sliderRange(value, min, max);146 Q_EMIT valueChanged(orientation(), min, max);147 }148 149 void ScrollBar::catchSliderMoved(int value)150 {151 float min, max;152 sliderRange(value, min, max);153 Q_EMIT sliderMoved(orientation(), min, max);154 }155 156 int ScrollBar::extent(void) const157 {158 QStyleOptionSlider opt;159 opt.init(this);160 opt.subControls = QStyle::SC_None;161 opt.activeSubControls = QStyle::SC_None;162 opt.orientation = orientation();163 opt.minimum = minimum();164 opt.maximum = maximum();165 opt.sliderPosition = sliderPosition();166 opt.sliderValue = value();167 opt.singleStep = singleStep();168 opt.pageStep = pageStep();169 opt.upsideDown = invertedAppearance();170 if (orientation() == Qt::Horizontal)171 opt.state |= QStyle::State_Horizontal;172 return style()->pixelMetric(QStyle::PM_ScrollBarExtent, &opt, this);173 } -
trunk/tools/FlairGCS/src/Scrollbar.h
r10 r15 8 8 #include <qscrollbar.h> 9 9 10 class ScrollBar: public QScrollBar 11 { 12 Q_OBJECT 10 class ScrollBar : public QScrollBar { 11 Q_OBJECT 13 12 14 13 public: 15 16 17 ScrollBar(float minBase, float maxBase,18 Qt::Orientation o,QWidget *parent = NULL);14 ScrollBar(QWidget *parent = NULL); 15 ScrollBar(Qt::Orientation, QWidget *parent = NULL); 16 ScrollBar(float minBase, float maxBase, Qt::Orientation o, 17 QWidget *parent = NULL); 19 18 20 21 19 void setInverted(bool); 20 bool isInverted(void) const; 22 21 23 24 22 float minBaseValue(void) const; 23 float maxBaseValue(void) const; 25 24 26 27 25 float minSliderValue(void) const; 26 float maxSliderValue(void) const; 28 27 29 28 int extent(void) const; 30 29 31 30 Q_SIGNALS: 32 33 31 void sliderMoved(Qt::Orientation, float, float); 32 void valueChanged(Qt::Orientation, float, float); 34 33 35 34 public Q_SLOTS: 36 37 35 virtual void setBase(float min, float max); 36 virtual void moveSlider(float min, float max); 38 37 39 38 protected: 40 41 42 39 void sliderRange(int value, float &min, float &max) const; 40 int mapToTick(float) const; 41 float mapFromTick(int) const; 43 42 44 43 private Q_SLOTS: 45 46 44 void catchValueChanged(int value); 45 void catchSliderMoved(int value); 47 46 48 47 private: 49 48 void init(void); 50 49 51 52 53 54 50 bool d_inverted; 51 float d_minBase; 52 float d_maxBase; 53 int d_baseTicks; 55 54 }; 56 55 -
trunk/tools/FlairGCS/src/SpinBox.cpp
r10 r15 8 8 #include <QSpinBox> 9 9 10 SpinBox::SpinBox(Layout* parent,int row, int col,QString name,QString suffix,int value,int min,int max,int step): FormLayout(parent,row,col,name,"SpinBox") 11 { 12 spinbox = new QSpinBox(); 10 SpinBox::SpinBox(Layout *parent, int row, int col, QString name, QString suffix, 11 int value, int min, int max, int step) 12 : FormLayout(parent, row, col, name, "SpinBox") { 13 spinbox = new QSpinBox(); 13 14 14 spinbox->setRange(min,max);15 16 17 18 spinbox_value=value;15 spinbox->setRange(min, max); 16 spinbox->setSingleStep(step); 17 spinbox->setValue(value); 18 spinbox->setSuffix(suffix); 19 spinbox_value = value; 19 20 20 object_layout->addRow(name,spinbox);21 object_layout->addRow(name, spinbox); 21 22 22 connect(spinbox,SIGNAL(valueChanged(int)),this, SLOT(valuechanged(int)));23 connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(valuechanged(int))); 23 24 24 25 SetValue(QString::number(spinbox_value)); 25 26 } 26 27 27 SpinBox::~SpinBox() 28 { 29 delete spinbox; 28 SpinBox::~SpinBox() { delete spinbox; } 29 30 void SpinBox::SetUptodate(void) { 31 ui_to_var(); 32 ui_to_xml(); 33 visible_widget->setPalette(black_pal); 30 34 } 31 35 32 void SpinBox::SetUptodate(void) 33 { 34 ui_to_var(); 35 ui_to_xml(); 36 visible_widget->setPalette(black_pal); 36 void SpinBox::ui_to_var(void) { spinbox_value = spinbox->value(); } 37 37 38 void SpinBox::ui_to_xml(void) { SetValue(QString::number(spinbox->value())); } 39 40 void SpinBox::Reset(void) { spinbox->setValue(spinbox_value); } 41 42 void SpinBox::LoadEvent(QDomElement dom) { 43 if (spinbox->isEnabled() == true) { 44 spinbox->setValue((dom.attribute("value")).toInt()); 45 } 38 46 } 39 47 40 void SpinBox::ui_to_var(void) 41 { 42 spinbox_value=spinbox->value(); 48 void SpinBox::valuechanged(int value) { 49 if (value != spinbox_value) { 50 visible_widget->setPalette(red_pal); 51 } else { 52 visible_widget->setPalette(black_pal); 53 } 43 54 } 44 45 void SpinBox::ui_to_xml(void)46 {47 SetValue(QString::number(spinbox->value()));48 }49 50 void SpinBox::Reset(void)51 {52 spinbox->setValue(spinbox_value);53 }54 55 void SpinBox::LoadEvent(QDomElement dom)56 {57 if(spinbox->isEnabled()==true)58 {59 spinbox->setValue((dom.attribute("value")).toInt());60 }61 }62 63 void SpinBox::valuechanged(int value)64 {65 if(value!=spinbox_value)66 {67 visible_widget->setPalette(red_pal);68 }69 else70 {71 visible_widget->setPalette(black_pal);72 }73 } -
trunk/tools/FlairGCS/src/SpinBox.h
r10 r15 11 11 class QSpinBox; 12 12 13 class SpinBox: public FormLayout 14 { 15 Q_OBJECT 13 class SpinBox : public FormLayout { 14 Q_OBJECT 16 15 17 public: 18 SpinBox(Layout* parent,int row, int col,QString name,QString suffix,int value,int min,int max,int step); 19 ~SpinBox(); 16 public: 17 SpinBox(Layout *parent, int row, int col, QString name, QString suffix, 18 int value, int min, int max, int step); 19 ~SpinBox(); 20 20 21 22 QSpinBox*spinbox;23 24 25 26 21 private: 22 QSpinBox *spinbox; 23 int spinbox_value; 24 void SetUptodate(void); 25 void Reset(void); 26 void LoadEvent(QDomElement dom); 27 27 28 29 28 void ui_to_var(void); 29 void ui_to_xml(void); 30 30 31 32 31 private slots: 32 void valuechanged(int value); 33 33 }; 34 34 -
trunk/tools/FlairGCS/src/Tab.cpp
r10 r15 7 7 #include <QGridLayout> 8 8 9 Tab::Tab(TabWidget* parent,QString name,int position): Layout(new QWidget(),parent,name,"Tab") { 10 parent_tab=parent; 11 onglet = getQGridLayout()->parentWidget(); 12 onglet->setObjectName(name); 13 if(position==-1) { 14 parent->tab->addTab(onglet, name); 15 } else { 16 parent->tab->insertTab(position,onglet, name); 17 } 9 Tab::Tab(TabWidget *parent, QString name, int position) 10 : Layout(new QWidget(), parent, name, "Tab") { 11 parent_tab = parent; 12 onglet = getQGridLayout()->parentWidget(); 13 onglet->setObjectName(name); 14 if (position == -1) { 15 parent->tab->addTab(onglet, name); 16 } else { 17 parent->tab->insertTab(position, onglet, name); 18 } 18 19 } 19 20 20 Tab::~Tab() { 21 parent_tab->tab->removeTab(parent_tab->tab->indexOf(onglet)); 22 } 21 Tab::~Tab() { parent_tab->tab->removeTab(parent_tab->tab->indexOf(onglet)); } -
trunk/tools/FlairGCS/src/Tab.h
r10 r15 10 10 class TabWidget; 11 11 12 class Tab: public Layout 13 { 12 class Tab : public Layout { 14 13 15 16 Tab(TabWidget* parent,QString name,int position);17 14 public: 15 Tab(TabWidget *parent, QString name, int position); 16 ~Tab(); 18 17 19 private: 20 TabWidget *parent_tab; 21 QWidget* onglet; 22 18 private: 19 TabWidget *parent_tab; 20 QWidget *onglet; 23 21 }; 24 22 -
trunk/tools/FlairGCS/src/TabWidget.cpp
r10 r15 10 10 //#include "qledindicator.h" 11 11 12 TabWidget::TabWidget(Layout* parent,int row,int col,QString name,QTabWidget::TabPosition position):XmlWidget(name,"TabWidget",parent) 13 { 14 tab=new QTabWidget(); 15 //tab->setTabShape(QTabWidget::Triangular); 16 //tab->setDocumentMode(true); 17 parent->addWidget(tab,row,col); 18 tab->setTabPosition(position); 19 SetIsContainer(true); 20 SetIsExpandable(true); 21 visible_widget=tab; 12 TabWidget::TabWidget(Layout *parent, int row, int col, QString name, 13 QTabWidget::TabPosition position) 14 : XmlWidget(name, "TabWidget", parent) { 15 tab = new QTabWidget(); 16 // tab->setTabShape(QTabWidget::Triangular); 17 // tab->setDocumentMode(true); 18 parent->addWidget(tab, row, col); 19 tab->setTabPosition(position); 20 SetIsContainer(true); 21 SetIsExpandable(true); 22 visible_widget = tab; 22 23 23 //QLedIndicator* led=new QLedIndicator(tab);24 //tab->setCornerWidget(led,Qt::TopLeftCorner);24 // QLedIndicator* led=new QLedIndicator(tab); 25 // tab->setCornerWidget(led,Qt::TopLeftCorner); 25 26 } 26 27 27 TabWidget::~TabWidget() 28 { 28 TabWidget::~TabWidget() {} 29 30 void TabWidget::XmlEvent(QDomElement dom) { 31 QString type = dom.tagName(); 32 QString name = dom.attribute("name"); 33 int position = dom.attribute("position").toInt(); 34 35 if (type == "Tab") { 36 Tab *layout = new Tab(this, name, position); 37 } 29 38 } 30 39 31 void TabWidget::XmlEvent(QDomElement dom) 32 { 33 QString type=dom.tagName(); 34 QString name=dom.attribute("name"); 35 int position=dom.attribute("position").toInt(); 36 37 if(type=="Tab") 38 { 39 Tab* layout = new Tab(this,name,position); 40 } 40 bool TabWidget::IsUptodate(void) { 41 for (int i = 0; i < childs->count(); i++) { 42 if (childs->at(i)->IsUptodate() == false) 43 return false; 44 } 45 return true; 41 46 } 42 43 bool TabWidget::IsUptodate(void)44 {45 for(int i=0;i<childs->count();i++)46 {47 if(childs->at(i)->IsUptodate()==false) return false;48 }49 return true;50 } -
trunk/tools/FlairGCS/src/TabWidget.h
r10 r15 11 11 class Layout; 12 12 13 class TabWidget: public XmlWidget 14 { 15 friend class Tab; 13 class TabWidget : public XmlWidget { 14 friend class Tab; 16 15 17 public: 18 TabWidget(Layout* parent,int row,int col,QString name,QTabWidget::TabPosition position); 19 ~TabWidget(); 20 bool IsUptodate(void); 16 public: 17 TabWidget(Layout *parent, int row, int col, QString name, 18 QTabWidget::TabPosition position); 19 ~TabWidget(); 20 bool IsUptodate(void); 21 21 22 private: 23 QTabWidget* tab; 24 void XmlEvent(QDomElement dom); 25 26 22 private: 23 QTabWidget *tab; 24 void XmlEvent(QDomElement dom); 27 25 }; 28 26 -
trunk/tools/FlairGCS/src/TextEdit.cpp
r10 r15 9 9 #include <QTextEdit> 10 10 11 TextEdit::TextEdit(Layout * parent,int row, int col,QString name):XmlWidget(name,"TextEdit",parent)12 {11 TextEdit::TextEdit(Layout *parent, int row, int col, QString name) 12 : XmlWidget(name, "TextEdit", parent) { 13 13 14 15 14 visible_widget = new QWidget(); 15 visible_widget->setObjectName(name); 16 16 17 18 clear= new QPushButton("Effacer");19 text=new QTextEdit();17 layout = new QGridLayout(visible_widget); 18 clear = new QPushButton("Effacer"); 19 text = new QTextEdit(); 20 20 21 layout->addWidget(text,0,0);22 layout->addWidget(clear,1,0);21 layout->addWidget(text, 0, 0); 22 layout->addWidget(clear, 1, 0); 23 23 24 connect(clear, SIGNAL(clicked(bool)),text, SLOT(clear()));24 connect(clear, SIGNAL(clicked(bool)), text, SLOT(clear())); 25 25 26 parent->addWidget(visible_widget,row,col);26 parent->addWidget(visible_widget, row, col); 27 27 } 28 28 29 TextEdit::~TextEdit() 30 { 29 TextEdit::~TextEdit() {} 31 30 31 void TextEdit::XmlEvent(QDomElement dom) { 32 text->append(dom.attribute("value")); 32 33 } 33 34 void TextEdit::XmlEvent(QDomElement dom)35 {36 text->append(dom.attribute("value"));37 } -
trunk/tools/FlairGCS/src/TextEdit.h
r10 r15 13 13 class Layout; 14 14 15 class TextEdit: public XmlWidget 16 { 17 public: 18 TextEdit(Layout* parent,int row, int col,QString name); 19 ~TextEdit(); 15 class TextEdit : public XmlWidget { 16 public: 17 TextEdit(Layout *parent, int row, int col, QString name); 18 ~TextEdit(); 20 19 21 22 23 24 25 20 private: 21 QGridLayout *layout; 22 QPushButton *clear; 23 QTextEdit *text; 24 void XmlEvent(QDomElement dom); 26 25 }; 27 26 -
trunk/tools/FlairGCS/src/UdtSocket.cpp
r10 r15 14 14 15 15 #ifndef WIN32 16 16 #include <arpa/inet.h> 17 17 #else 18 19 18 #include <winsock2.h> 19 #include <ws2tcpip.h> 20 20 #endif 21 21 22 22 using namespace std; 23 23 24 UdtSocket::UdtSocket(UDTSOCKET file_socket,UDTSOCKET com_socket,QString name): QObject() { 25 this->file_socket=file_socket; 26 this->com_socket=com_socket; 27 this->name=name; 28 stop=false; 29 file_dialog=new file_ui(); 30 31 bool blocking = true; 32 UDT::setsockopt(file_socket, 0, UDT_RCVSYN, &blocking, sizeof(bool)); 33 34 heartbeat_timer = new QTimer(this); 35 connect(heartbeat_timer, SIGNAL(timeout()), this, SLOT(heartbeat())); 36 heartbeat_timer->start(200); 24 UdtSocket::UdtSocket(UDTSOCKET file_socket, UDTSOCKET com_socket, QString name) 25 : QObject() { 26 this->file_socket = file_socket; 27 this->com_socket = com_socket; 28 this->name = name; 29 stop = false; 30 file_dialog = new file_ui(); 31 32 bool blocking = true; 33 UDT::setsockopt(file_socket, 0, UDT_RCVSYN, &blocking, sizeof(bool)); 34 35 heartbeat_timer = new QTimer(this); 36 connect(heartbeat_timer, SIGNAL(timeout()), this, SLOT(heartbeat())); 37 heartbeat_timer->start(200); 37 38 } 38 39 39 40 UdtSocket::~UdtSocket() { 40 heartbeat_timer->stop(); 41 42 UDT::close(file_socket); 43 UDT::close(com_socket); 44 45 file_dialog->deleteLater(); 46 } 47 48 //send signal to uav, to check connectivity through a watchdog 49 //this is necessary because we use udt (udp based), and we cannot check disconnection of ground station 41 heartbeat_timer->stop(); 42 43 UDT::close(file_socket); 44 UDT::close(com_socket); 45 46 file_dialog->deleteLater(); 47 } 48 49 // send signal to uav, to check connectivity through a watchdog 50 // this is necessary because we use udt (udp based), and we cannot check 51 // disconnection of ground station 50 52 void UdtSocket::heartbeat(void) { 51 char data=WATCHDOG_HEADER;52 write(&data,1);53 char data = WATCHDOG_HEADER; 54 write(&data, 1); 53 55 } 54 56 55 57 void UdtSocket::kill(void) { 56 57 stop=true;58 58 printf("disconnected\n"); 59 stop = true; 60 deleteLater(); 59 61 } 60 62 61 63 void UdtSocket::handleConnections(void) { 62 while(!stop) { 63 int eid = UDT::epoll_create(); 64 if(eid<0) { 65 printf("epoll_create error: %s\n",UDT::getlasterror().getErrorMessage()); 66 } 67 68 if(UDT::epoll_add_usock(eid,file_socket)<0) { 69 if(UDT::getlasterror().getErrorCode()==5004) { 70 printf("epoll_add_usock\n"); 71 break; 72 } else { 73 printf("epoll_add_usock error: %s\n",UDT::getlasterror().getErrorMessage()); 74 } 75 } 76 if(UDT::epoll_add_usock(eid,com_socket)<0) { 77 if(UDT::getlasterror().getErrorCode()==5004) { 78 printf("epoll_add_usock\n"); 79 break; 80 } else { 81 printf("epoll_add_usock error: %s\n",UDT::getlasterror().getErrorMessage()); 82 } 83 } 84 85 set<UDTSOCKET> readfds; 86 87 int rv=UDT::epoll_wait(eid, &readfds,NULL, 10) ; 88 89 if(rv == -1) { 90 if(UDT::getlasterror().getErrorCode()!=6003) printf("prob %i\n",UDT::getlasterror().getErrorCode()); 91 //printf("wait\n"); 92 } else if(rv == 0) { 93 printf("timeout\n"); // a timeout occured 94 } else { 95 /* 96 if(UDT::getlasterror().getErrorCode()==2001) { 97 UDT::epoll_release(eid); 98 }*/ 99 for (set<UDTSOCKET>::iterator i = readfds.begin(); i != readfds.end(); i++) { 100 //printf("a\n"); 101 if(*i==file_socket) receiveFile(); 102 if(*i==com_socket) receiveData(); 103 } 104 } 105 106 UDT::epoll_remove_usock(eid,file_socket); 107 UDT::epoll_remove_usock(eid,com_socket); 108 UDT::epoll_release(eid); 109 110 QCoreApplication::processEvents(); 111 } 112 kill(); 64 while (!stop) { 65 int eid = UDT::epoll_create(); 66 if (eid < 0) { 67 printf("epoll_create error: %s\n", UDT::getlasterror().getErrorMessage()); 68 } 69 70 if (UDT::epoll_add_usock(eid, file_socket) < 0) { 71 if (UDT::getlasterror().getErrorCode() == 5004) { 72 printf("epoll_add_usock\n"); 73 break; 74 } else { 75 printf("epoll_add_usock error: %s\n", 76 UDT::getlasterror().getErrorMessage()); 77 } 78 } 79 if (UDT::epoll_add_usock(eid, com_socket) < 0) { 80 if (UDT::getlasterror().getErrorCode() == 5004) { 81 printf("epoll_add_usock\n"); 82 break; 83 } else { 84 printf("epoll_add_usock error: %s\n", 85 UDT::getlasterror().getErrorMessage()); 86 } 87 } 88 89 set<UDTSOCKET> readfds; 90 91 int rv = UDT::epoll_wait(eid, &readfds, NULL, 10); 92 93 if (rv == -1) { 94 if (UDT::getlasterror().getErrorCode() != 6003) 95 printf("prob %i\n", UDT::getlasterror().getErrorCode()); 96 // printf("wait\n"); 97 } else if (rv == 0) { 98 printf("timeout\n"); // a timeout occured 99 } else { 100 /* 101 if(UDT::getlasterror().getErrorCode()==2001) { 102 UDT::epoll_release(eid); 103 }*/ 104 for (set<UDTSOCKET>::iterator i = readfds.begin(); i != readfds.end(); 105 i++) { 106 // printf("a\n"); 107 if (*i == file_socket) 108 receiveFile(); 109 if (*i == com_socket) 110 receiveData(); 111 } 112 } 113 114 UDT::epoll_remove_usock(eid, file_socket); 115 UDT::epoll_remove_usock(eid, com_socket); 116 UDT::epoll_release(eid); 117 118 QCoreApplication::processEvents(); 119 } 120 kill(); 113 121 } 114 122 115 123 void UdtSocket::receiveFile(void) { 116 char* recv_buf; 117 int bytesRead; 118 static bool flag_new_seq=true; 119 static QString folder_name; 120 121 //receive file info 122 recv_buf= (char*)malloc(1024); 123 bytesRead = UDT::recvmsg(file_socket,recv_buf,1024); 124 125 if(bytesRead<=0) { 124 char *recv_buf; 125 int bytesRead; 126 static bool flag_new_seq = true; 127 static QString folder_name; 128 129 // receive file info 130 recv_buf = (char *)malloc(1024); 131 bytesRead = UDT::recvmsg(file_socket, recv_buf, 1024); 132 133 if (bytesRead <= 0) { 134 free(recv_buf); 135 return; 136 } 137 138 int size; 139 memcpy(&size, &recv_buf[1], sizeof(int)); 140 if (recv_buf[0] == FILE_INFO_BIG_ENDIAN) 141 size = qFromBigEndian(size); 142 143 // printf("file_ui recu %i %x\n",bytesRead,recv_buf[0]); 144 if ((recv_buf[0] == FILE_INFO_LITTLE_ENDIAN || 145 recv_buf[0] == FILE_INFO_BIG_ENDIAN) && 146 size > 0) { 147 if (flag_new_seq == true) { 148 // create directory for storage 149 QDateTime dateTime = QDateTime::currentDateTime(); 150 folder_name = dateTime.toString("yyyyMMdd_hhmm") + "_" + name; 151 if (QDir().exists(folder_name) == true) { 152 folder_name = dateTime.toString("yyyyMMdd_hhmm_ss") + "_" + name; 153 } 154 QDir().mkdir(folder_name); 155 156 flag_new_seq = false; 157 file_dialog->log("Creating directory " + folder_name); 158 } 159 160 QString file_name = 161 QString::fromAscii((const char *)&recv_buf[5], bytesRead - 5); 162 QString file_path = folder_name + "/" + file_name; 163 file_dialog->log( 164 QString("receiving %1 (%2 bytes)").arg(file_name).arg(size)); 165 QFile fichier(file_path); 166 167 if (!fichier.open(QIODevice::WriteOnly)) { 168 file_dialog->log(" could not write to file!"); 169 } else { 170 // receive file 171 recv_buf = (char *)realloc((void *)recv_buf, size); 172 bytesRead = UDT::recvmsg(file_socket, recv_buf, size); 173 if (bytesRead != size) { 174 file_dialog->log(QString(" error receiving file! (%1/%2)") 175 .arg(bytesRead) 176 .arg(size)); 126 177 free(recv_buf); 127 178 return; 128 } 129 179 } else { 180 file_dialog->log(" ok"); 181 } 182 183 QDataStream stream(&fichier); 184 stream.writeRawData(recv_buf, size); 185 fichier.close(); 186 187 file_dialog->addFile(file_path); 188 } 189 190 free(recv_buf); 191 } else if (recv_buf[0] == END) { 192 file_dialog->endOfFiles(); 193 flag_new_seq = true; 194 } 195 } 196 197 void UdtSocket::receiveData(void) { 198 while (1) { 199 int buf_size; 200 int opt_size; 201 UDT::getsockopt(com_socket, 0, UDT_RCVBUF, &buf_size, &opt_size); 202 203 char *buf = (char *)malloc(buf_size); 130 204 int size; 131 memcpy(&size,&recv_buf[1],sizeof(int)); 132 if(recv_buf[0]==FILE_INFO_BIG_ENDIAN) size=qFromBigEndian(size); 133 134 //printf("file_ui recu %i %x\n",bytesRead,recv_buf[0]); 135 if((recv_buf[0]==FILE_INFO_LITTLE_ENDIAN || recv_buf[0]==FILE_INFO_BIG_ENDIAN) && size>0) { 136 if(flag_new_seq==true) { 137 //create directory for storage 138 QDateTime dateTime = QDateTime::currentDateTime(); 139 folder_name = dateTime.toString("yyyyMMdd_hhmm")+ "_" + name; 140 if(QDir().exists(folder_name)==true) { 141 folder_name = dateTime.toString("yyyyMMdd_hhmm_ss")+ "_" + name; 142 } 143 QDir().mkdir(folder_name); 144 145 flag_new_seq=false; 146 file_dialog->log("Creating directory " +folder_name); 147 } 148 149 QString file_name= QString::fromAscii((const char*)&recv_buf[5],bytesRead-5); 150 QString file_path=folder_name + "/" + file_name; 151 file_dialog->log(QString("receiving %1 (%2 bytes)").arg(file_name).arg(size)); 152 QFile fichier(file_path); 153 154 if(!fichier.open(QIODevice::WriteOnly)) { 155 file_dialog->log(" could not write to file!"); 156 } else { 157 //receive file 158 recv_buf= (char*)realloc((void*)recv_buf,size); 159 bytesRead = UDT::recvmsg(file_socket,recv_buf,size); 160 if(bytesRead!=size) { 161 file_dialog->log(QString(" error receiving file! (%1/%2)").arg(bytesRead).arg(size)); 162 free(recv_buf); 163 return; 164 } else { 165 file_dialog->log(" ok"); 166 } 167 168 QDataStream stream(&fichier); 169 stream.writeRawData(recv_buf,size); 170 fichier.close(); 171 172 file_dialog->addFile(file_path); 173 } 174 175 free(recv_buf); 176 } else if(recv_buf[0]==END) { 177 file_dialog->endOfFiles(); 178 flag_new_seq=true; 179 } 180 } 181 182 void UdtSocket::receiveData(void) { 183 while(1) { 184 int buf_size; 185 int opt_size; 186 UDT::getsockopt(com_socket,0,UDT_RCVBUF,&buf_size,&opt_size); 187 188 char* buf=(char*)malloc(buf_size); 189 int size; 190 size = UDT::recvmsg(com_socket,buf, buf_size); 191 buf=(char*)realloc(buf,size+1); 192 193 if(size>0) { 194 buf[size]=0; 195 emit dataReady(buf,size+1); 196 } else { 197 //if(UDT::getlasterror().getErrorCode()!=6002) printf("udt socket: %s\n",UDT::getlasterror().getErrorMessage()); 198 free(buf); 199 break; 200 } 201 } 202 } 203 204 void UdtSocket::write(const char* buf, qint64 size) { 205 //printf("write\n%s\n",buf); 206 qint64 sent=UDT::sendmsg(com_socket,buf,size, -1, true); 207 if(sent!=size) { 208 printf("erreur envoi: %s\n",UDT::getlasterror().getErrorMessage()); 209 if(UDT::getlasterror().getErrorCode()==2001) { 210 stop=true; 211 } 212 } 213 } 205 size = UDT::recvmsg(com_socket, buf, buf_size); 206 buf = (char *)realloc(buf, size + 1); 207 208 if (size > 0) { 209 buf[size] = 0; 210 emit dataReady(buf, size + 1); 211 } else { 212 // if(UDT::getlasterror().getErrorCode()!=6002) printf("udt socket: 213 // %s\n",UDT::getlasterror().getErrorMessage()); 214 free(buf); 215 break; 216 } 217 } 218 } 219 220 void UdtSocket::write(const char *buf, qint64 size) { 221 // printf("write\n%s\n",buf); 222 qint64 sent = UDT::sendmsg(com_socket, buf, size, -1, true); 223 if (sent != size) { 224 printf("erreur envoi: %s\n", UDT::getlasterror().getErrorMessage()); 225 if (UDT::getlasterror().getErrorCode() == 2001) { 226 stop = true; 227 } 228 } 229 } -
trunk/tools/FlairGCS/src/UdtSocket.h
r10 r15 12 12 class file_ui; 13 13 14 class UdtSocket : public QObject 15 { 16 Q_OBJECT 14 class UdtSocket : public QObject { 15 Q_OBJECT 17 16 18 19 UdtSocket(UDTSOCKET file_socket,UDTSOCKET com_socket,QString name);20 17 public: 18 UdtSocket(UDTSOCKET file_socket, UDTSOCKET com_socket, QString name); 19 ~UdtSocket(); 21 20 22 23 UDTSOCKET file_socket,com_socket;24 file_ui*file_dialog;25 26 27 28 29 21 private: 22 UDTSOCKET file_socket, com_socket; 23 file_ui *file_dialog; 24 bool stop; 25 QString name; 26 QTimer *heartbeat_timer; 27 void receiveData(void); 28 void receiveFile(void); 30 29 31 32 void dataReady(char*,int size);30 signals: 31 void dataReady(char *, int size); 33 32 34 35 36 37 void write(const char*buf, qint64 size);38 39 33 public slots: 34 void handleConnections(void); 35 void kill(void); 36 void write(const char *buf, qint64 size); 37 private slots: 38 void heartbeat(void); 40 39 }; 41 40 -
trunk/tools/FlairGCS/src/Vector3DSpinBox.cpp
r10 r15 12 12 #include "Layout.h" 13 13 14 Vector3DSpinBox::Vector3DSpinBox(Layout *parent, int row, int col, QString name, 15 QString value[3], float min, float max, 16 float step, int decimals) 17 : XmlWidget(name, "Vector3DSpinBox", parent) { 18 for (int i = 0; i < 3; i++) { 19 doublespinbox[i].setRange(min, max); 20 doublespinbox[i].setSingleStep(step); 21 doublespinbox[i].setDecimals(decimals); 22 } 14 23 15 Vector3DSpinBox::Vector3DSpinBox(Layout* parent,int row, int col,QString name,QString value[3],float min,float max,float step,int decimals): XmlWidget(name,"Vector3DSpinBox",parent) { 16 for(int i=0;i<3;i++) { 17 doublespinbox[i].setRange(min,max); 18 doublespinbox[i].setSingleStep(step); 19 doublespinbox[i].setDecimals(decimals); 24 adjust_decimals(value); 25 26 for (int i = 0; i < 3; i++) { 27 doublespinbox[i].setValue(value[i].toDouble()); 28 doublespinbox_value[i] = doublespinbox[i].cleanText(); 29 30 // event filter for qdoublespinbox and its child (qlinedit and incremnt 31 // qbuttons) 32 doublespinbox[i].installEventFilter(this); 33 QObjectList o_list = doublespinbox[i].children(); 34 for (int j = 0; j < o_list.length(); j++) { 35 QLineEdit *cast = qobject_cast<QLineEdit *>(o_list[j]); 36 if (cast) 37 cast->installEventFilter(this); 20 38 } 21 39 22 adjust_decimals(value); 40 connect(&doublespinbox[i], SIGNAL(valueChanged(const QString &)), this, 41 SLOT(valuechanged(const QString &))); 42 } 23 43 24 for(int i=0;i<3;i++) { 25 doublespinbox[i].setValue(value[i].toDouble()); 26 doublespinbox_value[i]=doublespinbox[i].cleanText(); 44 SetValues(value); 27 45 28 //event filter for qdoublespinbox and its child (qlinedit and incremnt qbuttons) 29 doublespinbox[i].installEventFilter(this); 30 QObjectList o_list = doublespinbox[i].children(); 31 for(int j = 0; j < o_list.length(); j++) { 32 QLineEdit *cast = qobject_cast<QLineEdit*>(o_list[j]); 33 if(cast) 34 cast->installEventFilter(this); 35 } 46 // creation et ajout QGroupBox 47 box = new QGroupBox(name); 48 box->setObjectName(name); 49 visible_widget = box; 50 parent->addWidget(box, row, col); 51 qgridlayout = new QGridLayout(new QWidget()); 52 box->setLayout(qgridlayout); 36 53 37 connect(&doublespinbox[i],SIGNAL(valueChanged(const QString &)),this, SLOT(valuechanged(const QString &))); 38 } 39 40 SetValues(value); 41 42 //creation et ajout QGroupBox 43 box = new QGroupBox(name); 44 box->setObjectName(name); 45 visible_widget=box; 46 parent->addWidget(box,row,col); 47 qgridlayout=new QGridLayout(new QWidget()); 48 box->setLayout(qgridlayout); 49 50 AddElement("x:",0); 51 AddElement("y:",1); 52 AddElement("z:",2); 54 AddElement("x:", 0); 55 AddElement("y:", 1); 56 AddElement("z:", 2); 53 57 } 54 58 55 Vector3DSpinBox::~Vector3DSpinBox() { 59 Vector3DSpinBox::~Vector3DSpinBox() {} 60 61 void Vector3DSpinBox::SetValues(QString value[3]) { 62 SetAttribute("value_x", value[0]); 63 SetAttribute("value_y", value[1]); 64 SetAttribute("value_z", value[2]); 56 65 } 57 66 58 void Vector3DSpinBox::SetValues(QString value[3]) { 59 SetAttribute("value_x",value[0]); 60 SetAttribute("value_y",value[1]); 61 SetAttribute("value_z",value[2]); 62 } 67 void Vector3DSpinBox::AddElement(QString name, int index) { 68 QWidget *widget = new QWidget(); 69 QFormLayout *object_layout = new QFormLayout(widget); 70 object_layout->setHorizontalSpacing(2); 71 object_layout->setVerticalSpacing(2); 72 object_layout->setContentsMargins(2, 2, 2, 2); 63 73 64 void Vector3DSpinBox::AddElement(QString name,int index) { 65 QWidget* widget=new QWidget(); 66 QFormLayout* object_layout = new QFormLayout(widget); 67 object_layout->setHorizontalSpacing(2); 68 object_layout->setVerticalSpacing(2); 69 object_layout->setContentsMargins (2,2,2,2); 74 object_layout->addRow(name, &doublespinbox[index]); 70 75 71 object_layout->addRow(name,&doublespinbox[index]); 72 73 qgridlayout->addWidget(widget,index,0); 76 qgridlayout->addWidget(widget, index, 0); 74 77 } 75 78 76 79 void Vector3DSpinBox::adjust_decimals(QString value[3]) { 77 for(int i=0;i<3;i++) {78 //auto adjust decimals79 80 80 for (int i = 0; i < 3; i++) { 81 // auto adjust decimals 82 QLocale locale; 83 value[i].remove(locale.groupSeparator()); 81 84 82 QStringList parts = value[i].split(locale.decimalPoint()); 83 if(parts.count() == 2) { 84 doublespinbox[i].setDecimals(parts[1].size()); 85 } 85 QStringList parts = value[i].split(locale.decimalPoint()); 86 if (parts.count() == 2) { 87 doublespinbox[i].setDecimals(parts[1].size()); 86 88 } 89 } 87 90 } 88 91 89 92 bool Vector3DSpinBox::eventFilter(QObject *object, QEvent *event) { 90 for(int i=0;i<3;i++) { 91 if(object==&doublespinbox[i] && event->type()==QEvent::MouseButtonPress) { 92 if (((QMouseEvent*)event)->button() == Qt::RightButton) { 93 QMenu * menu = new QMenu("menu", doublespinbox); 94 QAction *a,*b,*c,*z; 93 for (int i = 0; i < 3; i++) { 94 if (object == &doublespinbox[i] && 95 event->type() == QEvent::MouseButtonPress) { 96 if (((QMouseEvent *)event)->button() == Qt::RightButton) { 97 QMenu *menu = new QMenu("menu", doublespinbox); 98 QAction *a, *b, *c, *z; 95 99 96 a=menu->addAction("add decimal");97 b=menu->addAction("remove decimal");100 a = menu->addAction("add decimal"); 101 b = menu->addAction("remove decimal"); 98 102 99 if(doublespinbox[i].decimals()==0) b->setEnabled(false); 100 z=menu->exec(((QMouseEvent*)event)->globalPos()); 103 if (doublespinbox[i].decimals() == 0) 104 b->setEnabled(false); 105 z = menu->exec(((QMouseEvent *)event)->globalPos()); 101 106 102 if(z==a) doublespinbox[i].setDecimals(doublespinbox[i].decimals()+1); 103 if(z==b) doublespinbox[i].setDecimals(doublespinbox[i].decimals()-1); 104 delete menu; 105 return true; 106 } 107 } 107 if (z == a) 108 doublespinbox[i].setDecimals(doublespinbox[i].decimals() + 1); 109 if (z == b) 110 doublespinbox[i].setDecimals(doublespinbox[i].decimals() - 1); 111 delete menu; 112 return true; 113 } 108 114 } 109 return object->eventFilter(object, event); 115 } 116 return object->eventFilter(object, event); 110 117 } 111 118 112 119 void Vector3DSpinBox::SetUptodate(void) { 113 114 115 120 ui_to_var(); 121 ui_to_xml(); 122 visible_widget->setPalette(black_pal); 116 123 } 117 124 118 125 void Vector3DSpinBox::ui_to_var(void) { 119 for(int i=0;i<3;i++) {120 doublespinbox_value[i]=doublespinbox[i].cleanText();121 126 for (int i = 0; i < 3; i++) { 127 doublespinbox_value[i] = doublespinbox[i].cleanText(); 128 } 122 129 } 123 130 124 131 void Vector3DSpinBox::ui_to_xml(void) { 125 SetAttribute("value_x",doublespinbox[0].cleanText());126 SetAttribute("value_y",doublespinbox[1].cleanText());127 SetAttribute("value_z",doublespinbox[2].cleanText());132 SetAttribute("value_x", doublespinbox[0].cleanText()); 133 SetAttribute("value_y", doublespinbox[1].cleanText()); 134 SetAttribute("value_z", doublespinbox[2].cleanText()); 128 135 } 129 136 130 137 void Vector3DSpinBox::Reset(void) { 131 //le setvalue fait un arrondi pour l'affichage, la variable n'est donc plus egale 132 //on reprend la valeur de la boite et on force la couleur a noir 133 adjust_decimals(doublespinbox_value); 134 for(int i=0;i<3;i++) { 135 doublespinbox[i].setValue(doublespinbox_value[i].toDouble()); 136 doublespinbox_value[i]= doublespinbox[i].cleanText(); 137 } 138 visible_widget->setPalette(black_pal); 138 // le setvalue fait un arrondi pour l'affichage, la variable n'est donc plus 139 // egale 140 // on reprend la valeur de la boite et on force la couleur a noir 141 adjust_decimals(doublespinbox_value); 142 for (int i = 0; i < 3; i++) { 143 doublespinbox[i].setValue(doublespinbox_value[i].toDouble()); 144 doublespinbox_value[i] = doublespinbox[i].cleanText(); 145 } 146 visible_widget->setPalette(black_pal); 139 147 } 140 148 141 149 void Vector3DSpinBox::LoadEvent(QDomElement dom) { 142 if(doublespinbox[0].isEnabled()) {143 144 145 if(doublespinbox[1].isEnabled()) {146 147 148 if(doublespinbox[2].isEnabled()) {149 150 150 if (doublespinbox[0].isEnabled()) { 151 doublespinbox[0].setValue((dom.attribute("value_x")).toDouble()); 152 } 153 if (doublespinbox[1].isEnabled()) { 154 doublespinbox[1].setValue((dom.attribute("value_y")).toDouble()); 155 } 156 if (doublespinbox[2].isEnabled()) { 157 doublespinbox[2].setValue((dom.attribute("value_z")).toDouble()); 158 } 151 159 } 152 160 153 161 void Vector3DSpinBox::valuechanged(const QString &value) { 154 for(int i=0;i<3;i++) {155 if((QDoubleSpinBox*)sender()==&doublespinbox[i] && value!=doublespinbox_value[i]) {156 visible_widget->setPalette(red_pal);157 return;158 }162 for (int i = 0; i < 3; i++) { 163 if ((QDoubleSpinBox *)sender() == &doublespinbox[i] && 164 value != doublespinbox_value[i]) { 165 visible_widget->setPalette(red_pal); 166 return; 159 167 } 160 visible_widget->setPalette(black_pal); 168 } 169 visible_widget->setPalette(black_pal); 161 170 } 162 171 163 172 bool Vector3DSpinBox::IsUptodate(void) { 164 //si le widget n'est pas enabled, sa palette est differente de rouge (greyed) donc on renvoit true 165 //permet de ne pas envoyer les modifs d'un widget disabled 166 //if(label->palette()==red_pal) return false; 167 if(visible_widget->palette()==red_pal) return false; 168 return true; 173 // si le widget n'est pas enabled, sa palette est differente de rouge (greyed) 174 // donc on renvoit true 175 // permet de ne pas envoyer les modifs d'un widget disabled 176 // if(label->palette()==red_pal) return false; 177 if (visible_widget->palette() == red_pal) 178 return false; 179 return true; 169 180 } 170 -
trunk/tools/FlairGCS/src/Vector3DSpinBox.h
r10 r15 13 13 class QGridLayout; 14 14 15 class Vector3DSpinBox: public XmlWidget 16 { 17 Q_OBJECT 15 class Vector3DSpinBox : public XmlWidget { 16 Q_OBJECT 18 17 19 public: 20 //handle value as string, becouse double value are not exact 21 Vector3DSpinBox(Layout* parent,int row, int col,QString name,QString value[3],float min,float max,float step,int decimals); 22 ~Vector3DSpinBox(); 18 public: 19 // handle value as string, becouse double value are not exact 20 Vector3DSpinBox(Layout *parent, int row, int col, QString name, 21 QString value[3], float min, float max, float step, 22 int decimals); 23 ~Vector3DSpinBox(); 23 24 24 25 QGridLayout*qgridlayout;26 QGroupBox*box;27 28 29 void AddElement(QString name,int index);30 31 32 33 34 35 36 37 38 25 private: 26 QGridLayout *qgridlayout; 27 QGroupBox *box; 28 QDoubleSpinBox doublespinbox[3]; 29 QString doublespinbox_value[3]; 30 void AddElement(QString name, int index); 31 void SetUptodate(void); 32 void SetValues(QString value[3]); 33 void Reset(void); 34 void LoadEvent(QDomElement dom); 35 void ui_to_var(void); 36 void ui_to_xml(void); 37 bool eventFilter(QObject *o, QEvent *e); 38 void adjust_decimals(QString value[3]); 39 bool IsUptodate(void); 39 40 40 41 41 private slots: 42 void valuechanged(const QString &value); 42 43 }; 43 44 -
trunk/tools/FlairGCS/src/XmlWidget.cpp
r10 r15 8 8 #include <stdio.h> 9 9 10 XmlWidget::XmlWidget(QString name,QString type,XmlWidget* parent):QObject() 11 { 12 childs=new QList<XmlWidget*>; 13 isContainer=false; 14 isExpandable=false; 15 visible_widget=NULL; 16 parent_widget=parent; 17 18 red_pal.setColor( QPalette::Text, QColor(255,0,0) ); 19 red_pal.setColor( QPalette::Foreground, QColor(255,0,0) ); 20 red_pal_greyed.setColor( QPalette::Text, QColor(128,0,0) ); 21 red_pal_greyed.setColor( QPalette::Foreground, QColor(128,0,0) ); 22 23 black_pal.setColor( QPalette::Text, QColor(0,0,0) ); 24 black_pal.setColor( QPalette::Foreground, QColor(0,0,0) ); 25 black_pal_greyed.setColor( QPalette::Text, QColor(128,128,128) ); 26 black_pal_greyed.setColor( QPalette::Foreground, QColor(128,128,128) ); 27 28 setObjectName(name); 29 30 if(parent!=NULL) 31 { 32 parent->childs->append(this); 33 34 document=parent->document.cloneNode(true).toDocument(); 35 36 write_elem = QDomElement(document.createElement(type)); 37 write_elem.setAttribute("name", name); 38 //recupere le node le plus profond 39 QDomNode node=document.firstChild(); 40 while(node.firstChild().isNull()==false) 41 { 42 node=node.firstChild(); 10 XmlWidget::XmlWidget(QString name, QString type, XmlWidget *parent) 11 : QObject() { 12 childs = new QList<XmlWidget *>; 13 isContainer = false; 14 isExpandable = false; 15 visible_widget = NULL; 16 parent_widget = parent; 17 18 red_pal.setColor(QPalette::Text, QColor(255, 0, 0)); 19 red_pal.setColor(QPalette::Foreground, QColor(255, 0, 0)); 20 red_pal_greyed.setColor(QPalette::Text, QColor(128, 0, 0)); 21 red_pal_greyed.setColor(QPalette::Foreground, QColor(128, 0, 0)); 22 23 black_pal.setColor(QPalette::Text, QColor(0, 0, 0)); 24 black_pal.setColor(QPalette::Foreground, QColor(0, 0, 0)); 25 black_pal_greyed.setColor(QPalette::Text, QColor(128, 128, 128)); 26 black_pal_greyed.setColor(QPalette::Foreground, QColor(128, 128, 128)); 27 28 setObjectName(name); 29 30 if (parent != NULL) { 31 parent->childs->append(this); 32 33 document = parent->document.cloneNode(true).toDocument(); 34 35 write_elem = QDomElement(document.createElement(type)); 36 write_elem.setAttribute("name", name); 37 // recupere le node le plus profond 38 QDomNode node = document.firstChild(); 39 while (node.firstChild().isNull() == false) { 40 node = node.firstChild(); 41 } 42 node.appendChild(write_elem); 43 } else { 44 document = QDomDocument("remote_ui_xml"); 45 write_elem = QDomElement(document.createElement(type)); 46 write_elem.setAttribute("name", name); 47 document.appendChild(write_elem); 48 } 49 } 50 51 XmlWidget::~XmlWidget() { 52 if (parent_widget != NULL) 53 parent_widget->childs->removeOne(this); 54 55 // on efface les widgets enfants 56 // dans le delete child on modifie le child du parent, donc on se refere 57 // toujours au premier 58 while (childs->count() != 0) { 59 delete childs->first(); 60 } 61 62 delete childs; 63 if (visible_widget != NULL) { 64 delete visible_widget; 65 } 66 } 67 68 QString XmlWidget::Name(void) { return write_elem.attribute("name"); } 69 70 void XmlWidget::SetIsContainer(bool status) { isContainer = status; } 71 72 void XmlWidget::SetIsExpandable(bool status) { isExpandable = status; } 73 74 XmlWidget *XmlWidget::GetXmlWidget(QString name, QString type) { 75 // printf("recherche %s 76 // %s\n",name.toLocal8Bit().constData(),type.toLocal8Bit().constData()); 77 78 for (int i = 0; i < childs->count(); i++) { 79 // printf("child name 80 // %s\n",childs->at(i)->write_elem.attribute("name").toLocal8Bit().constData()); 81 // printf("child tag 82 // %s\n",childs->at(i)->write_elem.tagName().toLocal8Bit().constData()); 83 if (childs->at(i)->write_elem.attribute("name") == name && 84 childs->at(i)->write_elem.tagName() == type) 85 return childs->at(i); 86 } 87 return NULL; 88 } 89 90 void XmlWidget::ParseXml(QDomElement to_parse) { 91 92 if (to_parse.isNull()) 93 return; 94 95 QString type = to_parse.tagName(); 96 QString name = to_parse.attribute("name"); 97 98 // printf("parse %s 99 // %s\n",type.toLocal8Bit().constData(),name.toLocal8Bit().constData()); 100 XmlWidget *match; 101 match = GetXmlWidget(name, type); 102 103 if (match == NULL) { 104 // printf("not match\n"); 105 XmlEvent(to_parse); 106 } else { 107 // printf("match\n"); 108 // si on a une balise IsEnabled, on ne traite que ca 109 if (match->visible_widget != NULL) { 110 if (to_parse.attribute("IsEnabled") == "0") { 111 match->visible_widget->setEnabled(false); 112 return; 113 } 114 if (to_parse.attribute("IsEnabled") == "1") { 115 match->visible_widget->setEnabled(true); 116 return; 117 } 118 } 119 120 // si on a une balise delete, on ne traite que ca 121 if (to_parse.attribute("Delete") == "1") { 122 // printf("delete flag\n"); 123 if (match->isContainer == true && match->childs->count() != 0) { 124 // printf("non vide 125 // %s\n",match->objectName().toLocal8Bit().constData()); 126 return; 127 } 128 129 delete match; 130 return; 131 } 132 133 if (to_parse.firstChild().isNull() == true && 134 match->isExpandable == false) { 135 QString new_name; 136 printf("possible doublon\n"); 137 for (int i = 0; i < 65535; i++) { 138 new_name = QString("%1_%2").arg(name).arg(i); 139 bool continuer = false; 140 for (int i = 0; i < childs->count(); i++) { 141 if (childs->at(i)->write_elem.attribute("name") == new_name) { 142 continuer = true; 143 break; 144 } 43 145 } 44 node.appendChild(write_elem); 45 } 46 else 47 { 48 document=QDomDocument("remote_ui_xml"); 49 write_elem = QDomElement(document.createElement(type)); 50 write_elem.setAttribute("name", name); 51 document.appendChild(write_elem); 52 } 53 } 54 55 XmlWidget::~XmlWidget() 56 { 57 if(parent_widget!=NULL) parent_widget->childs->removeOne(this); 58 59 //on efface les widgets enfants 60 //dans le delete child on modifie le child du parent, donc on se refere toujours au premier 61 while(childs->count()!=0) { 62 delete childs->first(); 63 } 64 65 delete childs; 66 if(visible_widget!=NULL) { 67 delete visible_widget; 68 } 69 } 70 71 QString XmlWidget::Name(void) 72 { 73 return write_elem.attribute("name"); 74 } 75 76 void XmlWidget::SetIsContainer(bool status) { 77 isContainer=status; 78 } 79 80 void XmlWidget::SetIsExpandable(bool status) { 81 isExpandable=status; 82 } 83 84 XmlWidget* XmlWidget::GetXmlWidget(QString name,QString type) 85 { 86 //printf("recherche %s %s\n",name.toLocal8Bit().constData(),type.toLocal8Bit().constData()); 87 88 for(int i=0;i<childs->count();i++) 89 { 90 //printf("child name %s\n",childs->at(i)->write_elem.attribute("name").toLocal8Bit().constData()); 91 //printf("child tag %s\n",childs->at(i)->write_elem.tagName().toLocal8Bit().constData()); 92 if(childs->at(i)->write_elem.attribute("name")==name && childs->at(i)->write_elem.tagName()==type) return childs->at(i); 93 94 } 95 return NULL; 96 } 97 98 99 void XmlWidget::ParseXml(QDomElement to_parse) { 100 101 if(to_parse.isNull()) return; 102 103 QString type=to_parse.tagName(); 104 QString name=to_parse.attribute("name"); 105 106 //printf("parse %s %s\n",type.toLocal8Bit().constData(),name.toLocal8Bit().constData()); 107 XmlWidget* match; 108 match=GetXmlWidget(name,type); 109 110 if(match==NULL) { 111 //printf("not match\n"); 112 XmlEvent(to_parse); 146 if (continuer == false) 147 break; 148 } 149 printf("new_name %s\n", new_name.toLocal8Bit().constData()); 150 to_parse.setAttribute("name", new_name); 151 to_parse.setAttribute("old_name", name); 152 153 XmlEvent(to_parse); 154 155 // return -1;//ou retourner le xml a renvoyer pour chager de nom 113 156 } else { 114 //printf("match\n"); 115 //si on a une balise IsEnabled, on ne traite que ca 116 if(match->visible_widget!=NULL) { 117 if(to_parse.attribute("IsEnabled")=="0") { 118 match->visible_widget->setEnabled(false); 119 return; 120 } 121 if(to_parse.attribute("IsEnabled")=="1") { 122 match->visible_widget->setEnabled(true); 123 return; 124 } 125 } 126 127 //si on a une balise delete, on ne traite que ca 128 if(to_parse.attribute("Delete")=="1") { 129 //printf("delete flag\n"); 130 if(match->isContainer==true && match->childs->count()!=0) { 131 //printf("non vide %s\n",match->objectName().toLocal8Bit().constData()); 132 return; 133 } 134 135 delete match; 136 return; 137 } 138 139 if(to_parse.firstChild().isNull()==true && match->isExpandable==false) { 140 QString new_name; 141 printf("possible doublon\n"); 142 for(int i=0;i<65535;i++) { 143 new_name=QString("%1_%2").arg(name).arg(i); 144 bool continuer=false; 145 for(int i=0;i<childs->count();i++) { 146 if(childs->at(i)->write_elem.attribute("name")==new_name) { 147 continuer=true; 148 break; 149 } 150 } 151 if(continuer==false) break; 152 } 153 printf("new_name %s\n",new_name.toLocal8Bit().constData()); 154 to_parse.setAttribute("name",new_name); 155 to_parse.setAttribute("old_name",name); 156 157 XmlEvent(to_parse); 158 159 //return -1;//ou retourner le xml a renvoyer pour chager de nom 160 } else { 161 if(to_parse.firstChild().toElement().isNull()) { 162 match->XmlEvent(to_parse); 163 return; 164 } else { 165 match->ParseXml(to_parse.firstChild().toElement()); 166 } 167 } 168 } 157 if (to_parse.firstChild().toElement().isNull()) { 158 match->XmlEvent(to_parse); 159 return; 160 } else { 161 match->ParseXml(to_parse.firstChild().toElement()); 162 } 163 } 164 } 169 165 } 170 166 171 167 void XmlWidget::LoadXml(QDomElement to_parse) { 172 if(to_parse.isNull()) return; 173 174 LoadEvent(to_parse); 175 176 QDomElement elem=to_parse.firstChild().toElement(); 177 178 while(!elem.isNull()) { 179 180 QString type=elem.tagName(); 181 QString name=elem.attribute("name"); 182 //printf("%s %s\n",type.toLocal8Bit().constData(),name.toLocal8Bit().constData()); 183 XmlWidget* match; 184 match=GetXmlWidget(name,type); 185 186 if(match!=NULL) { 187 //printf("match\n"); 188 match->LoadXml(elem); 189 } 190 elem=elem.nextSibling().toElement(); 191 } 192 } 193 194 void XmlWidget::GetFullXml(QDomElement* doc) { 195 QDomDocument tmp_doc=XmlDoc(); 196 merge((QDomElement*)&tmp_doc,doc); 197 198 for(int i=0;i<childs->count();i++) { 199 childs->at(i)->GetFullXml(doc); 200 } 201 } 202 203 void XmlWidget::GetUpdateXml(QDomElement* doc) { 204 if(IsUptodate()==false && isContainer==false) { 205 SetUptodate(); 206 QDomDocument tmp_doc=XmlDoc(); 207 merge((QDomElement*)&tmp_doc,doc); 208 } 209 210 for(int i=0;i<childs->count();i++) { 211 childs->at(i)->GetUpdateXml(doc); 212 } 213 } 214 215 void XmlWidget::ResetAllChilds(void) 216 { 217 Reset(); 218 for(int i=0;i<childs->count();i++) 219 { 220 childs->at(i)->ResetAllChilds(); 221 } 222 } 223 224 void XmlWidget::merge(QDomElement* from,QDomElement* into) 225 { 226 QDomElement tmp_into,tmp_from; 227 tmp_from=from->firstChildElement(); 228 229 while(tmp_from.isNull()==false) 230 { 231 //search corresponding child 232 bool match=false; 233 tmp_into=into->firstChildElement(tmp_from.tagName()); 234 while(tmp_into.isNull()==false) 235 { 236 if(tmp_into.attribute("name")==tmp_from.attribute("name")) 237 { 238 merge(&tmp_from,&tmp_into); 239 match=true; 240 break; 241 } 242 tmp_into=tmp_into.nextSiblingElement(tmp_from.tagName()); 243 } 244 245 if(match==false) 246 { 247 into->appendChild(tmp_from.cloneNode()); 248 } 249 250 tmp_from=tmp_from.nextSiblingElement(); 251 } 252 } 253 254 QDomDocument XmlWidget::XmlDoc(void) 255 { 256 return document.cloneNode(true).toDocument(); 257 } 258 259 QDomElement* XmlWidget::AddXmlChild(QString type) 260 { 261 QDomElement* elem; 262 263 elem = new QDomElement(document.createElement(type)); 264 write_elem.appendChild(*elem); 265 266 return elem; 267 } 268 269 void XmlWidget::RemoveXmlChild(QDomElement* element) 270 { 271 write_elem.removeChild(*element); 272 delete element; 273 } 274 275 void XmlWidget::ClearDoc(void) 276 { 277 document.clear(); 278 } 279 280 void XmlWidget::SetValue(QString value) 281 { 282 write_elem.setAttribute("value",value); 283 } 284 285 void XmlWidget::SetAttribute(const QString& name, const QString& value) 286 { 287 write_elem.setAttribute(name,value); 288 } 289 290 void XmlWidget::SetAttribute(const QString& name, qlonglong value) 291 { 292 write_elem.setAttribute(name,value); 293 } 294 295 void XmlWidget::SetAttribute(const QString& name, qulonglong value) 296 { 297 write_elem.setAttribute(name,value); 298 } 299 300 void XmlWidget::SetAttribute(const QString& name, float value) 301 { 302 write_elem.setAttribute(name,value); 303 } 304 305 void XmlWidget::SetAttribute(const QString& name, double value) 306 { 307 write_elem.setAttribute(name,value); 308 } 309 310 void XmlWidget::RemoveAttribute(const QString& name) { 311 write_elem.removeAttribute(name); 312 } 313 314 void XmlWidget::RenamedFrom(QString old_name) 315 { 316 QString name=write_elem.attribute("name"); 317 SetAttribute("name",old_name); 318 SetAttribute("new_name",name); 319 connectionLayout()->XmlToSend(XmlDoc()); 320 SetAttribute("name",name); 321 write_elem.removeAttribute("new_name"); 322 323 } 324 325 ConnectionLayout* XmlWidget::connectionLayout(void) 326 { 327 if(parent_widget!=NULL) { 328 return (ConnectionLayout*)(parent_widget->connectionLayout()); 329 } else { 330 return (ConnectionLayout*)this; 331 } 332 } 333 168 if (to_parse.isNull()) 169 return; 170 171 LoadEvent(to_parse); 172 173 QDomElement elem = to_parse.firstChild().toElement(); 174 175 while (!elem.isNull()) { 176 177 QString type = elem.tagName(); 178 QString name = elem.attribute("name"); 179 // printf("%s 180 // %s\n",type.toLocal8Bit().constData(),name.toLocal8Bit().constData()); 181 XmlWidget *match; 182 match = GetXmlWidget(name, type); 183 184 if (match != NULL) { 185 // printf("match\n"); 186 match->LoadXml(elem); 187 } 188 elem = elem.nextSibling().toElement(); 189 } 190 } 191 192 void XmlWidget::GetFullXml(QDomElement *doc) { 193 QDomDocument tmp_doc = XmlDoc(); 194 merge((QDomElement *)&tmp_doc, doc); 195 196 for (int i = 0; i < childs->count(); i++) { 197 childs->at(i)->GetFullXml(doc); 198 } 199 } 200 201 void XmlWidget::GetUpdateXml(QDomElement *doc) { 202 if (IsUptodate() == false && isContainer == false) { 203 SetUptodate(); 204 QDomDocument tmp_doc = XmlDoc(); 205 merge((QDomElement *)&tmp_doc, doc); 206 } 207 208 for (int i = 0; i < childs->count(); i++) { 209 childs->at(i)->GetUpdateXml(doc); 210 } 211 } 212 213 void XmlWidget::ResetAllChilds(void) { 214 Reset(); 215 for (int i = 0; i < childs->count(); i++) { 216 childs->at(i)->ResetAllChilds(); 217 } 218 } 219 220 void XmlWidget::merge(QDomElement *from, QDomElement *into) { 221 QDomElement tmp_into, tmp_from; 222 tmp_from = from->firstChildElement(); 223 224 while (tmp_from.isNull() == false) { 225 // search corresponding child 226 bool match = false; 227 tmp_into = into->firstChildElement(tmp_from.tagName()); 228 while (tmp_into.isNull() == false) { 229 if (tmp_into.attribute("name") == tmp_from.attribute("name")) { 230 merge(&tmp_from, &tmp_into); 231 match = true; 232 break; 233 } 234 tmp_into = tmp_into.nextSiblingElement(tmp_from.tagName()); 235 } 236 237 if (match == false) { 238 into->appendChild(tmp_from.cloneNode()); 239 } 240 241 tmp_from = tmp_from.nextSiblingElement(); 242 } 243 } 244 245 QDomDocument XmlWidget::XmlDoc(void) { 246 return document.cloneNode(true).toDocument(); 247 } 248 249 QDomElement *XmlWidget::AddXmlChild(QString type) { 250 QDomElement *elem; 251 252 elem = new QDomElement(document.createElement(type)); 253 write_elem.appendChild(*elem); 254 255 return elem; 256 } 257 258 void XmlWidget::RemoveXmlChild(QDomElement *element) { 259 write_elem.removeChild(*element); 260 delete element; 261 } 262 263 void XmlWidget::ClearDoc(void) { document.clear(); } 264 265 void XmlWidget::SetValue(QString value) { 266 write_elem.setAttribute("value", value); 267 } 268 269 void XmlWidget::SetAttribute(const QString &name, const QString &value) { 270 write_elem.setAttribute(name, value); 271 } 272 273 void XmlWidget::SetAttribute(const QString &name, qlonglong value) { 274 write_elem.setAttribute(name, value); 275 } 276 277 void XmlWidget::SetAttribute(const QString &name, qulonglong value) { 278 write_elem.setAttribute(name, value); 279 } 280 281 void XmlWidget::SetAttribute(const QString &name, float value) { 282 write_elem.setAttribute(name, value); 283 } 284 285 void XmlWidget::SetAttribute(const QString &name, double value) { 286 write_elem.setAttribute(name, value); 287 } 288 289 void XmlWidget::RemoveAttribute(const QString &name) { 290 write_elem.removeAttribute(name); 291 } 292 293 void XmlWidget::RenamedFrom(QString old_name) { 294 QString name = write_elem.attribute("name"); 295 SetAttribute("name", old_name); 296 SetAttribute("new_name", name); 297 connectionLayout()->XmlToSend(XmlDoc()); 298 SetAttribute("name", name); 299 write_elem.removeAttribute("new_name"); 300 } 301 302 ConnectionLayout *XmlWidget::connectionLayout(void) { 303 if (parent_widget != NULL) { 304 return (ConnectionLayout *)(parent_widget->connectionLayout()); 305 } else { 306 return (ConnectionLayout *)this; 307 } 308 } -
trunk/tools/FlairGCS/src/XmlWidget.h
r10 r15 14 14 class ConnectionLayout; 15 15 16 class XmlWidget:public QObject 17 { 18 Q_OBJECT 16 class XmlWidget : public QObject { 17 Q_OBJECT 19 18 20 21 XmlWidget(QString name,QString type,XmlWidget*parent);22 23 24 25 void GetFullXml(QDomElement*doc);26 void GetUpdateXml(QDomElement*doc);27 28 virtual bool IsUptodate(void){return true;};29 30 31 19 public: 20 XmlWidget(QString name, QString type, XmlWidget *parent); 21 ~XmlWidget(); 22 QDomDocument XmlDoc(void); 23 void ParseXml(QDomElement to_parse); 24 void GetFullXml(QDomElement *doc); 25 void GetUpdateXml(QDomElement *doc); 26 void ResetAllChilds(void); 27 virtual bool IsUptodate(void) { return true; }; 28 void LoadXml(QDomElement to_parse); 29 void RenamedFrom(QString old_name); 30 QString Name(void); 32 31 33 private: 34 QDomDocument document; 35 QDomElement write_elem; 36 XmlWidget* GetXmlWidget(QString name,QString type); 37 static void merge(QDomElement* from,QDomElement* into); 38 bool isExpandable;//true if we can receive extra frame for this widget (ex combobox, plots, layout) 39 bool isContainer;//true if it can contain other widget (ex layout), isExpandable is also true in this case 40 virtual void SetUptodate(void){}; 41 virtual void Reset(void){}; 42 XmlWidget* parent_widget; 32 private: 33 QDomDocument document; 34 QDomElement write_elem; 35 XmlWidget *GetXmlWidget(QString name, QString type); 36 static void merge(QDomElement *from, QDomElement *into); 37 bool isExpandable; // true if we can receive extra frame for this widget (ex 38 // combobox, plots, layout) 39 bool isContainer; // true if it can contain other widget (ex layout), 40 // isExpandable is also true in this case 41 virtual void SetUptodate(void){}; 42 virtual void Reset(void){}; 43 XmlWidget *parent_widget; 43 44 44 protected: 45 QList<XmlWidget*> *childs; 46 ConnectionLayout* connectionLayout(void); 47 QWidget* visible_widget; 48 QPalette red_pal,red_pal_greyed; 49 QPalette black_pal,black_pal_greyed; 50 void SetIsContainer(bool status); 51 void SetIsExpandable(bool status); 52 virtual void XmlEvent(QDomElement dom){}; 53 virtual void LoadEvent(QDomElement dom){}; 54 QDomElement* AddXmlChild(QString type); 55 void RemoveXmlChild(QDomElement* element); 56 void ClearDoc(void); 57 void SetValue(QString value); 58 void SetAttribute(const QString& name, const QString& value); 59 void SetAttribute(const QString& name, qlonglong value); 60 void SetAttribute(const QString& name, qulonglong value); 61 inline void SetAttribute(const QString& name, int value) 62 { SetAttribute(name, qlonglong(value)); } 63 inline void SetAttribute(const QString& name, uint value) 64 { SetAttribute(name, qulonglong(value)); } 65 void SetAttribute(const QString& name, float value); 66 void SetAttribute(const QString& name, double value); 67 void RemoveAttribute(const QString& name); 45 protected: 46 QList<XmlWidget *> *childs; 47 ConnectionLayout *connectionLayout(void); 48 QWidget *visible_widget; 49 QPalette red_pal, red_pal_greyed; 50 QPalette black_pal, black_pal_greyed; 51 void SetIsContainer(bool status); 52 void SetIsExpandable(bool status); 53 virtual void XmlEvent(QDomElement dom){}; 54 virtual void LoadEvent(QDomElement dom){}; 55 QDomElement *AddXmlChild(QString type); 56 void RemoveXmlChild(QDomElement *element); 57 void ClearDoc(void); 58 void SetValue(QString value); 59 void SetAttribute(const QString &name, const QString &value); 60 void SetAttribute(const QString &name, qlonglong value); 61 void SetAttribute(const QString &name, qulonglong value); 62 inline void SetAttribute(const QString &name, int value) { 63 SetAttribute(name, qlonglong(value)); 64 } 65 inline void SetAttribute(const QString &name, uint value) { 66 SetAttribute(name, qulonglong(value)); 67 } 68 void SetAttribute(const QString &name, float value); 69 void SetAttribute(const QString &name, double value); 70 void RemoveAttribute(const QString &name); 68 71 }; 69 72 -
trunk/tools/FlairGCS/src/file_ui.cpp
r10 r15 24 24 25 25 #ifndef WIN32 26 26 #include <arpa/inet.h> 27 27 #else 28 29 28 #include <winsock2.h> 29 #include <ws2tcpip.h> 30 30 #endif 31 31 32 33 32 using namespace std; 34 33 35 file_ui::file_ui() 36 { 37 dialog=new QDialog(); 38 dialog->setWindowTitle("log files"); 39 QGridLayout *main_layout = new QGridLayout(dialog); 40 ok_button= new QPushButton("Ok",dialog); 41 log_text=new QTextEdit(dialog); 42 log_text->setReadOnly(true); 43 input_text=new QTextEdit(dialog); 44 input_text->setText("add your log comment here"); 45 input_cleared=false; 46 47 ok_button->setEnabled(false); 48 49 main_layout->addWidget(log_text,0,0); 50 main_layout->addWidget(input_text,1,0); 51 52 QWidget *widget=new QWidget(dialog); 53 QFormLayout *formLayout = new QFormLayout(widget); 54 csv_combo = new QComboBox(widget); 55 formLayout->addRow(tr("save all log with following base time"), csv_combo); 56 csv_combo->addItem("(no base time)"); 57 main_layout->addWidget(widget,2,0); 58 main_layout->addWidget(ok_button,3,0); 59 60 connect(ok_button, SIGNAL(clicked()),this, SLOT(save()), Qt::QueuedConnection); 61 connect(this, SIGNAL(showDialog()),dialog, SLOT(show()), Qt::QueuedConnection); 62 connect(this, SIGNAL(appendToLog(QString)),log_text, SLOT(append(QString)), Qt::QueuedConnection); 63 connect(input_text, SIGNAL(cursorPositionChanged()),this, SLOT(clearInputText()), Qt::QueuedConnection); 64 65 file_names=new QStringList(); 66 } 67 68 file_ui::~file_ui() 69 { 70 delete dialog; 71 } 72 73 void file_ui::log(QString text) { 74 appendToLog(text); 75 } 34 file_ui::file_ui() { 35 dialog = new QDialog(); 36 dialog->setWindowTitle("log files"); 37 QGridLayout *main_layout = new QGridLayout(dialog); 38 ok_button = new QPushButton("Ok", dialog); 39 log_text = new QTextEdit(dialog); 40 log_text->setReadOnly(true); 41 input_text = new QTextEdit(dialog); 42 input_text->setText("add your log comment here"); 43 input_cleared = false; 44 45 ok_button->setEnabled(false); 46 47 main_layout->addWidget(log_text, 0, 0); 48 main_layout->addWidget(input_text, 1, 0); 49 50 QWidget *widget = new QWidget(dialog); 51 QFormLayout *formLayout = new QFormLayout(widget); 52 csv_combo = new QComboBox(widget); 53 formLayout->addRow(tr("save all log with following base time"), csv_combo); 54 csv_combo->addItem("(no base time)"); 55 main_layout->addWidget(widget, 2, 0); 56 main_layout->addWidget(ok_button, 3, 0); 57 58 connect(ok_button, SIGNAL(clicked()), this, SLOT(save()), 59 Qt::QueuedConnection); 60 connect(this, SIGNAL(showDialog()), dialog, SLOT(show()), 61 Qt::QueuedConnection); 62 connect(this, SIGNAL(appendToLog(QString)), log_text, SLOT(append(QString)), 63 Qt::QueuedConnection); 64 connect(input_text, SIGNAL(cursorPositionChanged()), this, 65 SLOT(clearInputText()), Qt::QueuedConnection); 66 67 file_names = new QStringList(); 68 } 69 70 file_ui::~file_ui() { delete dialog; } 71 72 void file_ui::log(QString text) { appendToLog(text); } 76 73 77 74 void file_ui::addFile(QString file_path) { 78 //framework sends dbt file then txt file 79 //when we receive txt, we have both files 80 //and we can convert it to .csv 81 if(file_path.endsWith(".dbt")==true) { 82 QString name=file_path.section('/', -1);//remove path for displaying on combobox 83 csv_combo->addItem(name.replace(QString(".dbt"), QString(".csv"))); 84 file_names->append(file_path.replace(QString(".dbt"), QString(".csv"))); 85 } 86 87 if(file_path.endsWith(".txt")==true) { 88 dbt2csv(file_path.replace(QString(".txt"), QString(".dbt"))); 89 } 90 91 if(file_names->size()==1) { 92 input_cleared=false; 93 showDialog(); 94 } 75 // framework sends dbt file then txt file 76 // when we receive txt, we have both files 77 // and we can convert it to .csv 78 if (file_path.endsWith(".dbt") == true) { 79 QString name = 80 file_path.section('/', -1); // remove path for displaying on combobox 81 csv_combo->addItem(name.replace(QString(".dbt"), QString(".csv"))); 82 file_names->append(file_path.replace(QString(".dbt"), QString(".csv"))); 83 } 84 85 if (file_path.endsWith(".txt") == true) { 86 dbt2csv(file_path.replace(QString(".txt"), QString(".dbt"))); 87 } 88 89 if (file_names->size() == 1) { 90 input_cleared = false; 91 showDialog(); 92 } 95 93 } 96 94 97 95 void file_ui::endOfFiles(void) { 98 ok_button->setEnabled(true); 99 100 qint64 max_file_size=0; 101 for(int i=0;i<file_names->count();i++) { 102 QFileInfo info(file_names->at(i)); 103 if(info.size()>max_file_size) { 104 max_file_size=info.size(); 105 csv_combo->setCurrentIndex(i+1);//first item of combobox is already taken 106 } 107 } 108 } 109 110 void file_ui::dbt2csv(QString file_path) 111 { 112 hdfile_t *dbtFile = NULL; 113 char *data; 114 QStringList data_type; 115 116 QString filename=file_path.section('/', -1);//remove path for displaying on logs 117 appendToLog(QString("converting %1 to csv").arg(filename)); 118 119 //open csv file 120 QString csv_filename=file_path; 121 csv_filename.replace(QString(".dbt"), QString(".csv")); 122 QFile csv_file(csv_filename); 123 124 if(!csv_file.open(QIODevice::WriteOnly | QIODevice::Text)) { 125 appendToLog(" error opening csv file!"); 126 return; 127 } 128 QTextStream out(&csv_file); 129 130 //open txt file 131 QString txt_filename=file_path; 132 txt_filename.replace(QString(".dbt"), QString(".txt")); 133 QFile txt_file(txt_filename); 134 135 if(!txt_file.open(QIODevice::ReadOnly | QIODevice::Text)) { 136 appendToLog(" error opening txt file!"); 137 return; 138 } 139 140 //read txt file 96 ok_button->setEnabled(true); 97 98 qint64 max_file_size = 0; 99 for (int i = 0; i < file_names->count(); i++) { 100 QFileInfo info(file_names->at(i)); 101 if (info.size() > max_file_size) { 102 max_file_size = info.size(); 103 csv_combo->setCurrentIndex(i + 104 1); // first item of combobox is already taken 105 } 106 } 107 } 108 109 void file_ui::dbt2csv(QString file_path) { 110 hdfile_t *dbtFile = NULL; 111 char *data; 112 QStringList data_type; 113 114 QString filename = 115 file_path.section('/', -1); // remove path for displaying on logs 116 appendToLog(QString("converting %1 to csv").arg(filename)); 117 118 // open csv file 119 QString csv_filename = file_path; 120 csv_filename.replace(QString(".dbt"), QString(".csv")); 121 QFile csv_file(csv_filename); 122 123 if (!csv_file.open(QIODevice::WriteOnly | QIODevice::Text)) { 124 appendToLog(" error opening csv file!"); 125 return; 126 } 127 QTextStream out(&csv_file); 128 129 // open txt file 130 QString txt_filename = file_path; 131 txt_filename.replace(QString(".dbt"), QString(".txt")); 132 QFile txt_file(txt_filename); 133 134 if (!txt_file.open(QIODevice::ReadOnly | QIODevice::Text)) { 135 appendToLog(" error opening txt file!"); 136 return; 137 } 138 139 // read txt file 140 QTextStream txt_in(&txt_file); 141 txt_in.readLine(); // time us 142 txt_in.readLine(); // time ns 143 while (1) { 144 if (txt_in.atEnd() == true) 145 break; 146 QString txt_line = txt_in.readLine(); 147 data_type.append(txt_line.section( 148 "(", 149 -1)); // on part de la fin pour trouver la premiere parenthese ouvrante 150 // printf("type %s\n",txt_line.section("(",-1).toLocal8Bit().constData()); 151 } 152 txt_file.close(); 153 154 dbtFile = open_hdfile(file_path.toLocal8Bit().data(), READ_MODE); 155 156 if (!dbtFile) { 157 appendToLog(" error opening dbt file!"); 158 return; 159 } 160 data = (char *)malloc(dbtFile->h.DataSize); 161 if (data == NULL) { 162 appendToLog(" error malloc!"); 163 return; 164 } 165 166 bool dataWritten = false; 167 while (1) { 168 road_time_t time; 169 road_timerange_t tr = 0; 170 int offset = 0; 171 QTextStream csv_line; 172 173 if (read_hdfile(dbtFile, (void *)data, &time, &tr) == 0) { 174 break; 175 } 176 dataWritten = true; 177 178 out << time << "," << tr; 179 for (int i = 0; i < data_type.size(); i++) { 180 if (data_type.at(i) == "float)") { 181 float *value = (float *)(data + offset); 182 offset += sizeof(float); 183 out << "," << *value; 184 } else if (data_type.at(i) == "int8_t)") { 185 int8_t *value = (int8_t *)(data + offset); 186 offset += sizeof(int8_t); 187 float fl = (float)*value; 188 out << "," << *value; 189 } else { 190 appendToLog(QString(" unhandled type: %1").arg(data_type.at(i))); 191 } 192 } 193 194 out << "\n"; 195 } 196 197 if (!dataWritten) { 198 // empty file! 199 out << "0,0"; // timr 200 for (int i = 0; i < data_type.size(); i++) { 201 out << ",0"; 202 } 203 out << "\n"; 204 } 205 206 csv_file.close(); 207 close_hdfile(dbtFile); 208 if (data != NULL) 209 free(data); 210 211 appendToLog(" ok"); 212 } 213 214 void file_ui::clearInputText(void) { 215 if (input_cleared == false) { 216 input_cleared = true; 217 input_text->clear(); 218 } 219 } 220 221 void file_ui::save(void) { 222 save_comment(); 223 if (csv_combo->currentIndex() != 0) { 224 save_csv(); 225 save_txt(); 226 } 227 228 log_text->clear(); 229 input_cleared = true; // avoid clearing it with setText 230 input_text->setText("add your log comment here"); 231 file_names->clear(); 232 csv_combo->clear(); 233 csv_combo->addItem(QString("(no base time)")); 234 235 dialog->setVisible(false); 236 ok_button->setEnabled(false); 237 emit finished(); 238 } 239 240 void file_ui::save_comment(void) { 241 QString folder_name = file_names->at(0).section('/', 0, -2); 242 243 QString filename = folder_name + "/commentaire.txt"; 244 QFile file(filename); 245 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) 246 printf("file_ui::save_comment: erreur ouverture fichier %s\n", 247 filename.toLocal8Bit().constData()); 248 QTextStream out(&file); 249 250 out << input_text->toPlainText(); 251 file.close(); 252 } 253 254 void file_ui::save_csv(void) { 255 // global csv file 256 QString folder_name = file_names->at(0).section('/', 0, -2); 257 QString filename = folder_name + "/all_logs.csv"; 258 QFile global_file(filename); 259 if (!global_file.open(QIODevice::WriteOnly | QIODevice::Text)) 260 printf("file_ui::save_csv: erreur ouverture fichier %s\n", 261 filename.toLocal8Bit().constData()); 262 QTextStream out(&global_file); 263 264 // reference csv file 265 filename = file_names->at(csv_combo->currentIndex() - 1); 266 QFile ref_file(filename); 267 // printf("file_ui::save_csv: ref %s\n",filename.toLocal8Bit().constData()); 268 if (!ref_file.open(QIODevice::ReadOnly | QIODevice::Text)) 269 printf("file_ui::save_csv: erreur ouverture ficher %s\n", 270 filename.toLocal8Bit().constData()); 271 272 // other csv files 273 int j = 0; 274 QFile m_file[file_names->count() - 1]; 275 QTextStream m_in[file_names->count() - 1]; 276 for (int i = 0; i < file_names->count(); i++) { 277 if (i == csv_combo->currentIndex() - 1) 278 continue; 279 filename = file_names->at(i); 280 m_file[j].setFileName(filename); 281 if (!m_file[j].open(QIODevice::ReadOnly | QIODevice::Text)) 282 printf("file_ui::save_csv: erreur ouverture ficher %s\n", 283 filename.toLocal8Bit().constData()); 284 m_in[j].setDevice(&m_file[j]); 285 j++; 286 } 287 288 // init 289 QTextStream ref_in(&ref_file); 290 QString m_line[file_names->count() - 1]; 291 QString m_line_prev[file_names->count() - 1]; 292 for (int i = 0; i < file_names->count() - 1; i++) { 293 m_line[i] = m_in[i].readLine(); 294 m_line_prev[i] = m_line[i]; 295 } 296 297 // organize csv files in one file 298 while (1) { 299 if (ref_in.atEnd() == true) 300 break; 301 QString ref_line = ref_in.readLine(); 302 303 qint64 ref_us = ref_line.section(',', 0, 0).toLongLong(); 304 int ref_ns = ref_line.section(',', 1, 1).toInt(); 305 // printf("ref %lld %i\n",ref_us,ref_ns); 306 307 for (int i = 0; i < file_names->count() - 1; i++) { 308 qint64 csv_us = m_line[i].section(',', 0, 0).toLongLong(); 309 int csv_ns = m_line[i].section(',', 1, 1).toInt(); 310 // printf("m %lld %i\n",csv_us,csv_ns); 311 312 while (is_greater(ref_us, csv_us, ref_ns, csv_ns) == true) { 313 m_line_prev[i] = m_line[i]; 314 if (m_in[i].atEnd() == true) 315 break; 316 m_line[i] = m_in[i].readLine(); 317 csv_us = m_line[i].section(',', 0, 0).toLongLong(); 318 csv_ns = m_line[i].section(',', 1, 1).toInt(); 319 // printf("m %lld %i\n",csv_us,csv_ns); 320 } 321 csv_us = m_line_prev[i].section(',', 0, 0).toLongLong(); 322 csv_ns = m_line_prev[i].section(',', 1, 1).toInt(); 323 // printf("m ok %lld %i\n",csv_us,csv_ns); 324 325 ref_line += "," + m_line_prev[i].section(',', 2); 326 } 327 328 out << ref_line << "\n"; 329 } 330 331 global_file.close(); 332 ref_file.close(); 333 for (int i = 0; i < file_names->count() - 1; i++) 334 m_file[i].close(); 335 } 336 337 void file_ui::save_txt(void) { 338 // global txt file 339 QString folder_name = file_names->at(0).section('/', 0, -2); 340 QString filename = folder_name + "/all_logs.txt"; 341 QFile global_file(filename); 342 if (!global_file.open(QIODevice::WriteOnly | QIODevice::Text)) 343 printf("file_ui::save_txt: erreur ouverture ficher %s\n", 344 filename.toLocal8Bit().constData()); 345 QTextStream out(&global_file); 346 347 // reference txt file 348 filename = file_names->at(csv_combo->currentIndex() - 1); 349 filename.replace(QString(".csv"), QString(".txt")); 350 QFile ref_file(filename); 351 if (!ref_file.open(QIODevice::ReadOnly | QIODevice::Text)) 352 printf("file_ui::save_txt: erreur ouverture ficher %s\n", 353 filename.toLocal8Bit().constData()); 354 355 QTextStream ref_in(&ref_file); 356 QString current_line = ref_in.readLine(); 357 int nb_lines = 1; 358 while (current_line != NULL) { 359 out << current_line << "\n"; 360 ; 361 current_line = ref_in.readLine(); 362 nb_lines++; 363 } 364 365 // other txt files 366 for (int i = 0; i < file_names->count(); i++) { 367 if (i == csv_combo->currentIndex() - 1) 368 continue; 369 filename = file_names->at(i); 370 filename.replace(QString(".csv"), QString(".txt")); 371 QFile txt_file(filename); 372 if (!txt_file.open(QIODevice::ReadOnly | QIODevice::Text)) 373 printf("file_ui::save_txt: erreur ouverture ficher %s\n", 374 filename.toLocal8Bit().constData()); 141 375 QTextStream txt_in(&txt_file); 142 txt_in.readLine(); //time us143 txt_in.readLine(); //time ns144 while(1)145 {146 if(txt_in.atEnd()==true) break;147 QString txt_line=txt_in.readLine();148 data_type.append(txt_line.section("(",-1));//on part de la fin pour trouver la premiere parenthese ouvrante149 //printf("type %s\n",txt_line.section("(",-1).toLocal8Bit().constData());376 txt_in.readLine(); // time us 377 txt_in.readLine(); // time ns 378 current_line = txt_in.readLine(); 379 while (current_line != NULL) { 380 out << nb_lines << ":" << current_line.section(':', 1) << "\n"; 381 ; 382 current_line = txt_in.readLine(); 383 nb_lines++; 150 384 } 151 385 txt_file.close(); 152 153 dbtFile=open_hdfile(file_path.toLocal8Bit().data(),READ_MODE); 154 155 if (!dbtFile) 156 { 157 appendToLog(" error opening dbt file!"); 158 return; 159 } 160 data=(char*)malloc(dbtFile->h.DataSize); 161 if(data==NULL) 162 { 163 appendToLog(" error malloc!"); 164 return; 165 } 166 167 bool dataWritten=false; 168 while(1) 169 { 170 road_time_t time; 171 road_timerange_t tr = 0; 172 int offset=0; 173 QTextStream csv_line; 174 175 if(read_hdfile(dbtFile,(void*)data,&time,&tr)==0) { 176 break; 177 } 178 dataWritten=true; 179 180 out << time << "," << tr; 181 for(int i=0;i<data_type.size();i++) 182 { 183 if(data_type.at(i)=="float)") 184 { 185 float* value=(float*)(data+offset); 186 offset+=sizeof(float); 187 out << "," << *value; 188 } 189 else if(data_type.at(i)=="int8_t)") 190 { 191 int8_t* value=(int8_t*)(data+offset); 192 offset+=sizeof(int8_t); 193 float fl=(float)*value; 194 out << "," << *value; 195 } 196 else 197 { 198 appendToLog(QString(" unhandled type: %1").arg(data_type.at(i))); 199 } 200 } 201 202 out << "\n"; 203 } 204 205 if(!dataWritten) { 206 //empty file! 207 out << "0,0";//timr 208 for(int i=0;i<data_type.size();i++) { 209 out << ",0"; 210 } 211 out << "\n"; 212 } 213 214 csv_file.close(); 215 close_hdfile(dbtFile); 216 if(data!=NULL) free(data); 217 218 appendToLog(" ok"); 219 } 220 221 void file_ui::clearInputText(void){ 222 if(input_cleared==false) { 223 input_cleared=true; 224 input_text->clear(); 225 } 226 } 227 228 void file_ui::save(void) 229 { 230 save_comment(); 231 if(csv_combo->currentIndex()!=0) 232 { 233 save_csv(); 234 save_txt(); 235 } 236 237 log_text->clear(); 238 input_cleared=true;//avoid clearing it with setText 239 input_text->setText("add your log comment here"); 240 file_names->clear(); 241 csv_combo->clear(); 242 csv_combo->addItem(QString("(no base time)")); 243 244 dialog->setVisible(false); 245 ok_button->setEnabled(false); 246 emit finished(); 247 } 248 249 void file_ui::save_comment(void) 250 { 251 QString folder_name=file_names->at(0).section('/', 0,-2); 252 253 QString filename=folder_name+"/commentaire.txt"; 254 QFile file(filename); 255 if(!file.open(QIODevice::WriteOnly | QIODevice::Text)) printf("file_ui::save_comment: erreur ouverture fichier %s\n",filename.toLocal8Bit().constData()); 256 QTextStream out(&file); 257 258 out<<input_text->toPlainText(); 259 file.close(); 260 } 261 262 void file_ui::save_csv(void) 263 { 264 //global csv file 265 QString folder_name=file_names->at(0).section('/', 0,-2); 266 QString filename=folder_name + "/all_logs.csv" ; 267 QFile global_file(filename); 268 if(!global_file.open(QIODevice::WriteOnly | QIODevice::Text)) printf("file_ui::save_csv: erreur ouverture fichier %s\n",filename.toLocal8Bit().constData()); 269 QTextStream out(&global_file); 270 271 //reference csv file 272 filename=file_names->at(csv_combo->currentIndex()-1); 273 QFile ref_file(filename); 274 //printf("file_ui::save_csv: ref %s\n",filename.toLocal8Bit().constData()); 275 if(!ref_file.open(QIODevice::ReadOnly | QIODevice::Text)) printf("file_ui::save_csv: erreur ouverture ficher %s\n",filename.toLocal8Bit().constData()); 276 277 //other csv files 278 int j=0; 279 QFile m_file[file_names->count()-1]; 280 QTextStream m_in[file_names->count()-1]; 281 for(int i=0;i<file_names->count();i++) 282 { 283 if(i==csv_combo->currentIndex()-1) continue; 284 filename=file_names->at(i); 285 m_file[j].setFileName(filename); 286 if(!m_file[j].open(QIODevice::ReadOnly | QIODevice::Text)) printf("file_ui::save_csv: erreur ouverture ficher %s\n",filename.toLocal8Bit().constData()); 287 m_in[j].setDevice(&m_file[j]); 288 j++; 289 } 290 291 //init 292 QTextStream ref_in(&ref_file); 293 QString m_line[file_names->count()-1]; 294 QString m_line_prev[file_names->count()-1]; 295 for(int i=0;i<file_names->count()-1;i++) 296 { 297 m_line[i]=m_in[i].readLine(); 298 m_line_prev[i]=m_line[i]; 299 } 300 301 //organize csv files in one file 302 while(1) 303 { 304 if(ref_in.atEnd()==true) break; 305 QString ref_line=ref_in.readLine(); 306 307 qint64 ref_us=ref_line.section(',',0,0).toLongLong(); 308 int ref_ns=ref_line.section(',',1,1).toInt(); 309 //printf("ref %lld %i\n",ref_us,ref_ns); 310 311 for(int i=0;i<file_names->count()-1;i++) 312 { 313 qint64 csv_us=m_line[i].section(',',0,0).toLongLong(); 314 int csv_ns=m_line[i].section(',',1,1).toInt(); 315 //printf("m %lld %i\n",csv_us,csv_ns); 316 317 while(is_greater(ref_us,csv_us,ref_ns,csv_ns)==true) 318 { 319 m_line_prev[i]=m_line[i]; 320 if(m_in[i].atEnd()==true) break; 321 m_line[i]=m_in[i].readLine(); 322 csv_us=m_line[i].section(',',0,0).toLongLong(); 323 csv_ns=m_line[i].section(',',1,1).toInt(); 324 //printf("m %lld %i\n",csv_us,csv_ns); 325 } 326 csv_us=m_line_prev[i].section(',',0,0).toLongLong(); 327 csv_ns=m_line_prev[i].section(',',1,1).toInt(); 328 //printf("m ok %lld %i\n",csv_us,csv_ns); 329 330 ref_line+="," + m_line_prev[i].section(',',2); 331 } 332 333 out<<ref_line << "\n"; 334 } 335 336 global_file.close(); 337 ref_file.close(); 338 for(int i=0;i<file_names->count()-1;i++) m_file[i].close(); 339 } 340 341 void file_ui::save_txt(void) 342 { 343 //global txt file 344 QString folder_name=file_names->at(0).section('/', 0,-2); 345 QString filename=folder_name + "/all_logs.txt"; 346 QFile global_file(filename); 347 if(!global_file.open(QIODevice::WriteOnly | QIODevice::Text)) printf("file_ui::save_txt: erreur ouverture ficher %s\n",filename.toLocal8Bit().constData()); 348 QTextStream out(&global_file); 349 350 //reference txt file 351 filename=file_names->at(csv_combo->currentIndex()-1); 352 filename.replace(QString(".csv"), QString(".txt")); 353 QFile ref_file(filename); 354 if(!ref_file.open(QIODevice::ReadOnly | QIODevice::Text)) printf("file_ui::save_txt: erreur ouverture ficher %s\n",filename.toLocal8Bit().constData()); 355 356 QTextStream ref_in(&ref_file); 357 QString current_line=ref_in.readLine(); 358 int nb_lines=1; 359 while(current_line!=NULL) 360 { 361 out<<current_line << "\n";; 362 current_line=ref_in.readLine(); 363 nb_lines++; 364 } 365 366 //other txt files 367 for(int i=0;i<file_names->count();i++) 368 { 369 if(i==csv_combo->currentIndex()-1) continue; 370 filename=file_names->at(i); 371 filename.replace(QString(".csv"), QString(".txt")); 372 QFile txt_file(filename); 373 if(!txt_file.open(QIODevice::ReadOnly | QIODevice::Text)) printf("file_ui::save_txt: erreur ouverture ficher %s\n",filename.toLocal8Bit().constData()); 374 QTextStream txt_in(&txt_file); 375 txt_in.readLine();//time us 376 txt_in.readLine();//time ns 377 current_line=txt_in.readLine(); 378 while(current_line!=NULL) 379 { 380 out<< nb_lines << ":" << current_line.section(':',1) << "\n";; 381 current_line=txt_in.readLine(); 382 nb_lines++; 383 } 384 txt_file.close(); 385 386 } 387 global_file.close(); 388 ref_file.close(); 389 } 390 391 392 bool file_ui::is_greater(qint64 ref_us,qint64 csv_us,int ref_ns,int csv_ns) 393 { 394 if(ref_us==csv_us) 395 { 396 if(ref_ns>csv_ns) 397 { 398 return true; 399 } 400 else 401 { 402 return false; 403 } 404 } 405 if(ref_us>csv_us) 406 { 407 return true; 408 } 409 else 410 { 411 return false; 412 } 413 } 386 } 387 global_file.close(); 388 ref_file.close(); 389 } 390 391 bool file_ui::is_greater(qint64 ref_us, qint64 csv_us, int ref_ns, int csv_ns) { 392 if (ref_us == csv_us) { 393 if (ref_ns > csv_ns) { 394 return true; 395 } else { 396 return false; 397 } 398 } 399 if (ref_us > csv_us) { 400 return true; 401 } else { 402 return false; 403 } 404 } -
trunk/tools/FlairGCS/src/file_ui.h
r10 r15 15 15 class QCloseEvent; 16 16 17 class file_ui:public QObject 18 { 19 Q_OBJECT 17 class file_ui : public QObject { 18 Q_OBJECT 20 19 21 22 23 24 25 26 20 public: 21 file_ui(); 22 ~file_ui(); 23 void log(QString text); 24 void addFile(QString file_path); 25 void endOfFiles(void); 27 26 28 29 30 31 QTextEdit *log_text,*input_text;32 33 34 35 36 37 38 bool is_greater(qint64 ref_us,qint64 csv_us,int ref_ns,int csv_ns);39 void closeEvent(QCloseEvent *e);40 27 private: 28 QDialog *dialog; 29 QStringList *file_names; 30 QTextEdit *log_text, *input_text; 31 QPushButton *ok_button; 32 QComboBox *csv_combo; 33 void save_comment(void); 34 void save_csv(void); 35 void save_txt(void); 36 void dbt2csv(QString file_path); 37 bool is_greater(qint64 ref_us, qint64 csv_us, int ref_ns, int csv_ns); 38 void closeEvent(QCloseEvent *e); 39 bool input_cleared; 41 40 42 43 44 41 private slots: 42 void save(void); 43 void clearInputText(void); 45 44 46 47 48 49 45 signals: 46 void showDialog(void); 47 void appendToLog(QString); 48 void finished(); 50 49 }; 51 50 -
trunk/tools/FlairGCS/src/main.cpp
r10 r15 18 18 int port; 19 19 20 void parseOptions(int argc, char **argv) {21 22 20 void parseOptions(int argc, char **argv) { 21 try { 22 CmdLine cmd("Command description message", ' ', "0.1"); 23 23 24 ValueArg<string> nameArg("n","name","uav name",false,"x4-0","string");25 cmd.add( nameArg);24 ValueArg<string> nameArg("n", "name", "uav name", false, "x4-0", "string"); 25 cmd.add(nameArg); 26 26 27 ValueArg<int> portArg("p","port","port number",false,9000,"int");28 cmd.add( portArg);27 ValueArg<int> portArg("p", "port", "port number", false, 9000, "int"); 28 cmd.add(portArg); 29 29 30 cmd.parse( argc, argv);30 cmd.parse(argc, argv); 31 31 32 33 name= nameArg.getValue();34 32 // Get the value parsed by each arg. 33 name = nameArg.getValue(); 34 port = portArg.getValue(); 35 35 36 } catch (ArgException &e) {// catch any exceptions37 38 36 } catch (ArgException &e) { // catch any exceptions 37 cerr << "error: " << e.error() << " for arg " << e.argId() << endl; 38 } 39 39 } 40 40 41 41 int main(int argc, char *argv[]) { 42 42 43 44 45 46 43 union { 44 uint32_t i; 45 char c[4]; 46 } bint = {0x01020304}; 47 47 48 if(bint.c[0] == 1) {49 50 51 48 if (bint.c[0] == 1) { 49 printf("error, ground station is only compatible with little endian\n"); 50 return -1; 51 } 52 52 53 53 printf(SVN_REV); 54 54 55 parseOptions(argc,argv);56 printf("listening on port %i\n",port);55 parseOptions(argc, argv); 56 printf("listening on port %i\n", port); 57 57 58 qRegisterMetaType<const char*>("const char*");59 60 61 58 qRegisterMetaType<const char *>("const char*"); 59 QLocale::setDefault(QLocale::C); 60 QApplication app(argc, argv); 61 app.setStyle(new QCleanlooksStyle); 62 62 63 Manager manager(QString::fromStdString(name),port);63 Manager manager(QString::fromStdString(name), port); 64 64 65 65 manager.show(); 66 66 67 67 app.exec(); 68 68 } -
trunk/tools/FlairGCS/src/mapwidget.cpp
r10 r15 57 57 using namespace QtMobility; 58 58 59 MapWidget::MapWidget(Map* map,QWidget *parent) 60 : QGraphicsView(parent) { 61 setCursor(Qt::ArrowCursor); 62 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 63 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 64 65 geoMap = 0; 59 MapWidget::MapWidget(Map *map, QWidget *parent) : QGraphicsView(parent) { 60 setCursor(Qt::ArrowCursor); 61 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 62 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 63 64 geoMap = 0; 65 dragging = false; 66 pressed = false; 67 landmark_match = NULL; 68 is_uptodate = true; 69 this->map = map; 70 71 m_scene = new QGraphicsScene(this); 72 setScene(m_scene); 73 setMouseTracking(true); 74 75 landmarks = new QList<Landmark *>; 76 landmarks_old = new QList<Landmark *>; 77 } 78 79 QGraphicsScene *MapWidget::scene(void) const { return m_scene; } 80 81 void MapWidget::setMap(QGraphicsGeoMap *geoMap) { 82 m_scene->clear(); 83 m_scene->addItem(geoMap); 84 this->geoMap = geoMap; 85 geoMap->resize(m_scene->sceneRect().width(), m_scene->sceneRect().height()); 86 } 87 88 void MapWidget::mousePressEvent(QMouseEvent *event) { 89 if (event->button() == Qt::LeftButton) { 90 pressed = true; 91 dragStartPosition = event->pos(); 92 QTimer::singleShot(qApp->startDragTime(), this, SLOT(initDrag())); 93 event->accept(); 94 } 95 96 if (event->button() == Qt::RightButton) { 97 QMenu *menu = new QMenu("nom", this); 98 99 if (cursor().shape() != Qt::PointingHandCursor) { 100 QAction *b, *z; //*a, 101 QList<QAction *> go_to_actions; 102 QList<QAction *> centered_actions; 103 104 QMenu *centered_menu = menu->addMenu("centered"); 105 for (int i = 0; i < points.count(); i++) { 106 QAction *action = centered_menu->addAction(points.at(i)); 107 centered_actions.append(action); 108 action->setCheckable(true); 109 if (map->centeredPoint() == i) { 110 action->setChecked(true); 111 } else { 112 action->setChecked(false); 113 } 114 } 115 116 menu->addSeparator(); 117 118 b = menu->addAction("place checkpoint"); 119 QMenu *go_to_menu = menu->addMenu("go to"); 120 for (int i = 0; i < landmarks->count(); i++) { 121 QAction *action = 122 go_to_menu->addAction(QString("checkpoint %1").arg(i + 1)); 123 go_to_actions.append(action); 124 } 125 if (landmarks->count() == 0) 126 go_to_menu->setEnabled(false); 127 128 map->appendmenu(menu); 129 z = map->execmenu(this, menu, event->globalPos()); 130 131 for (int i = 0; i < centered_actions.count(); i++) { 132 if (z == centered_actions.at(i)) { 133 if (centered_actions.at(i)->isChecked()) { 134 map->setCenteredPoint(i); 135 } else { 136 map->setCenteredPoint(-1); 137 } 138 139 break; 140 } 141 } 142 143 if (z == b) { 144 Landmark *landmark = new Landmark( 145 geoMap, geoMap->screenPositionToCoordinate(event->pos()), 146 QString("%1").arg(landmarks->count() + 1)); 147 landmarks->append(landmark); 148 is_uptodate = false; 149 } 150 for (int i = 0; i < go_to_actions.count(); i++) { 151 if (z == go_to_actions.at(i)) { 152 map->setCenteredPoint(-1); 153 geoMap->setCenter(landmarks->at(i)->coordinate()); 154 break; 155 } 156 } 157 158 } else { 159 QAction *a, *z; 160 a = menu->addAction("delete"); 161 z = menu->exec(event->globalPos()); 162 163 if (z == a) { 164 int i; 165 for (i = 0; i < landmarks->count(); i++) { 166 if (landmarks->at(i)->contains( 167 geoMap->screenPositionToCoordinate(event->pos()))) { 168 delete landmarks->at(i); 169 landmarks->removeAt(i); 170 break; 171 } 172 } 173 for (int j = i; j < landmarks->count(); j++) { 174 landmarks->at(j)->setText(QString("%1").arg(j + 1)); 175 } 176 } 177 } 178 179 delete menu; 180 } 181 } 182 183 void MapWidget::initDrag(void) { 184 if (pressed && map->isCentered() && landmark_match == NULL) { 185 dragging = true; 186 } 187 } 188 189 void MapWidget::mouseMoveEvent(QMouseEvent *event) { 190 if (!geoMap) 191 return; 192 193 Qt::CursorShape new_cursor; 194 if (dragging == true) { 195 new_cursor = Qt::ClosedHandCursor; 196 } else { 197 if (map->isCentered()) { 198 if (pressed == true) { 199 new_cursor = Qt::ForbiddenCursor; 200 } else { 201 new_cursor = Qt::ArrowCursor; 202 } 203 } else { 204 new_cursor = Qt::OpenHandCursor; 205 } 206 if (landmark_match != NULL) 207 new_cursor = Qt::PointingHandCursor; 208 } 209 210 for (int i = 0; i < landmarks->count(); i++) { 211 if (landmarks->at(i) 212 ->contains(geoMap->screenPositionToCoordinate(event->pos()))) { 213 if (pressed && landmark_match == NULL) { 214 landmark_match = landmarks->at(i); 215 landmark_match->setColor(Qt::red); 216 is_uptodate = false; 217 } 218 new_cursor = Qt::PointingHandCursor; 219 break; 220 } 221 } 222 223 if (new_cursor != cursor().shape()) 224 setCursor(new_cursor); 225 226 QPoint v = event->pos() - dragStartPosition; 227 228 if (dragging) { 229 geoMap->pan(-v.x(), -v.y()); 230 dragStartPosition = event->pos(); 231 232 } else if (landmark_match != NULL) { 233 landmark_match->setCoordinate( 234 geoMap->screenPositionToCoordinate(event->pos())); 235 236 } else if (pressed && !map->isCentered() && 237 v.manhattanLength() >= qApp->startDragDistance()) { 238 dragging = true; 239 240 } else { 241 dragStartPosition = event->pos(); 242 emit positionChanged(geoMap->screenPositionToCoordinate(event->pos())); 243 } 244 245 event->accept(); 246 } 247 248 void MapWidget::mouseReleaseEvent(QMouseEvent *event) { 249 pressed = false; 250 landmark_match = NULL; 251 252 if (dragging) { 253 QPoint v = event->pos() - dragStartPosition; 254 geoMap->pan(-v.x(), -v.y()); 66 255 dragging = false; 67 pressed = false; 68 landmark_match=NULL; 69 is_uptodate=true; 70 this->map=map; 71 72 m_scene = new QGraphicsScene(this); 73 setScene(m_scene); 74 setMouseTracking(true); 75 76 landmarks=new QList<Landmark*>; 77 landmarks_old=new QList<Landmark*>; 78 } 79 80 QGraphicsScene *MapWidget::scene(void) const 81 { 82 return m_scene; 83 } 84 85 void MapWidget::setMap(QGraphicsGeoMap *geoMap) 86 { 87 m_scene->clear(); 88 m_scene->addItem(geoMap); 89 this->geoMap = geoMap; 90 geoMap->resize(m_scene->sceneRect().width(), m_scene->sceneRect().height()); 91 } 92 93 void MapWidget::mousePressEvent(QMouseEvent *event) 94 { 95 if (event->button() == Qt::LeftButton) 96 { 97 pressed = true; 98 dragStartPosition = event->pos(); 99 QTimer::singleShot(qApp->startDragTime(), this, SLOT(initDrag())); 100 event->accept(); 101 } 102 103 if (event->button() == Qt::RightButton) 104 { 105 QMenu *menu = new QMenu("nom", this); 106 107 if(cursor().shape()!=Qt::PointingHandCursor) 108 { 109 QAction *b,*z;//*a, 110 QList<QAction*> go_to_actions; 111 QList<QAction*> centered_actions; 112 113 QMenu *centered_menu=menu->addMenu("centered"); 114 for(int i=0;i<points.count();i++) 115 { 116 QAction* action=centered_menu->addAction(points.at(i)); 117 centered_actions.append(action); 118 action->setCheckable(true); 119 if(map->centeredPoint()==i) 120 { 121 action->setChecked(true); 122 } 123 else 124 { 125 action->setChecked(false); 126 } 127 } 128 129 menu->addSeparator(); 130 131 b=menu->addAction("place checkpoint"); 132 QMenu *go_to_menu=menu->addMenu("go to"); 133 for(int i=0;i<landmarks->count();i++) 134 { 135 QAction* action=go_to_menu->addAction(QString("checkpoint %1").arg(i+1)); 136 go_to_actions.append(action); 137 } 138 if(landmarks->count()==0) go_to_menu->setEnabled(false); 139 140 map->appendmenu(menu); 141 z=map->execmenu(this,menu,event->globalPos()); 142 143 for(int i=0;i<centered_actions.count();i++) 144 { 145 if(z==centered_actions.at(i)) 146 { 147 if(centered_actions.at(i)->isChecked()) 148 { 149 map->setCenteredPoint(i); 150 } 151 else 152 { 153 map->setCenteredPoint(-1); 154 } 155 156 break; 157 } 158 } 159 160 if(z==b) 161 { 162 Landmark* landmark=new Landmark(geoMap,geoMap->screenPositionToCoordinate(event->pos()),QString("%1").arg(landmarks->count()+1)); 163 landmarks->append(landmark); 164 is_uptodate=false; 165 } 166 for(int i=0;i<go_to_actions.count();i++) 167 { 168 if(z==go_to_actions.at(i)) 169 { 170 map->setCenteredPoint(-1); 171 geoMap->setCenter(landmarks->at(i)->coordinate()); 172 break; 173 } 174 } 175 176 } 177 else 178 { 179 QAction *a,*z; 180 a=menu->addAction("delete"); 181 z=menu->exec(event->globalPos()); 182 183 if(z==a) 184 { 185 int i; 186 for(i=0;i<landmarks->count();i++) 187 { 188 if(landmarks->at(i)->contains(geoMap->screenPositionToCoordinate(event->pos()))) 189 { 190 delete landmarks->at(i); 191 landmarks->removeAt(i); 192 break; 193 } 194 } 195 for(int j=i;j<landmarks->count();j++) 196 { 197 landmarks->at(j)->setText(QString("%1").arg(j+1)); 198 } 199 } 200 } 201 202 delete menu; 203 } 204 } 205 206 void MapWidget::initDrag(void) 207 { 208 if (pressed && map->isCentered() && landmark_match==NULL) { 209 dragging = true; 210 } 211 } 212 213 void MapWidget::mouseMoveEvent(QMouseEvent *event) 214 { 215 if (!geoMap) 216 return; 217 218 Qt::CursorShape new_cursor; 219 if(dragging==true) 220 { 221 new_cursor=Qt::ClosedHandCursor; 222 } 223 else 224 { 225 if(map->isCentered()) 226 { 227 if(pressed==true) 228 { 229 new_cursor=Qt::ForbiddenCursor; 230 } 231 else 232 { 233 new_cursor=Qt::ArrowCursor; 234 } 235 } 236 else 237 { 238 new_cursor=Qt::OpenHandCursor; 239 } 240 if(landmark_match!=NULL) new_cursor=Qt::PointingHandCursor; 241 } 242 243 244 for(int i=0;i<landmarks->count();i++) 245 { 246 if(landmarks->at(i)->contains(geoMap->screenPositionToCoordinate(event->pos()))) 247 { 248 if(pressed && landmark_match==NULL) 249 { 250 landmark_match=landmarks->at(i); 251 landmark_match->setColor(Qt::red); 252 is_uptodate=false; 253 } 254 new_cursor=Qt::PointingHandCursor; 255 break; 256 } 257 } 258 259 if(new_cursor!=cursor().shape()) setCursor(new_cursor); 260 261 QPoint v = event->pos() - dragStartPosition; 262 263 if (dragging) { 264 geoMap->pan(-v.x(), -v.y()); 265 dragStartPosition = event->pos(); 266 267 } else if(landmark_match!=NULL){ 268 landmark_match->setCoordinate(geoMap->screenPositionToCoordinate(event->pos())); 269 270 } else if (pressed && !map->isCentered() && 271 v.manhattanLength() >= qApp->startDragDistance()) { 272 dragging = true; 273 274 } else { 275 dragStartPosition = event->pos(); 276 emit positionChanged(geoMap->screenPositionToCoordinate(event->pos())); 277 } 278 279 event->accept(); 280 } 281 282 void MapWidget::mouseReleaseEvent(QMouseEvent *event) 283 { 284 pressed = false; 285 landmark_match=NULL; 286 287 if (dragging) { 288 QPoint v = event->pos() - dragStartPosition; 289 geoMap->pan(-v.x(), -v.y()); 290 dragging = false; 291 } 292 293 event->accept(); 294 } 295 296 void MapWidget::resizeEvent(QResizeEvent *event) 297 { 298 if (geoMap) { 299 m_scene->setSceneRect(QRectF(0, 0, event->size().width(), event->size().height())); 300 geoMap->resize(event->size().width(), event->size().height()); 301 } 302 303 QGraphicsView::resizeEvent(event); 304 } 305 306 void MapWidget::wheelEvent(QWheelEvent *event) 307 { 308 int steps = event->delta() / 120; 309 int zoom = qBound(geoMap->minimumZoomLevel(), geoMap->zoomLevel() + steps, 310 geoMap->maximumZoomLevel()); 311 312 if (zoom != geoMap->zoomLevel()) geoMap->setZoomLevel(zoom); 313 //if(!centered) geoMap->setCenter(geoMap->screenPositionToCoordinate(event->pos())); 314 } 315 316 void MapWidget::mouseDoubleClickEvent(QMouseEvent *event) 317 { 318 if(!map->isCentered()) geoMap->setCenter(geoMap->screenPositionToCoordinate(event->pos())); 319 } 320 321 bool MapWidget::IsUptodate(void) 322 { 323 return is_uptodate; 324 } 325 326 void MapWidget::SetUptodate(void) 327 { 328 for(int i=0;i<landmarks_old->count();i++) 329 { 330 delete landmarks_old->at(i); 331 } 332 landmarks_old->clear(); 333 334 for(int i=0;i<landmarks->count();i++) 335 { 336 landmarks->at(i)->setColor(Qt::white); 337 Landmark* landmark=new Landmark(geoMap,landmarks->at(i)->coordinate(),QString("%1").arg(landmarks->count()+1)); 338 landmarks_old->append(landmark); 339 landmarks_old->at(i)->setVisible(false); 340 } 341 342 is_uptodate=true; 343 } 344 345 void MapWidget::Reset(void) 346 { 347 for(int i=0;i<landmarks->count();i++) 348 { 349 delete landmarks->at(i); 350 } 351 landmarks->clear(); 352 353 for(int i=0;i<landmarks_old->count();i++) 354 { 355 Landmark* landmark=new Landmark(geoMap,landmarks_old->at(i)->coordinate(),QString("%1").arg(landmarks->count()+1)); 356 landmarks->append(landmark); 357 landmarks->at(i)->setColor(Qt::white); 358 } 359 360 is_uptodate=true; 361 } 362 363 QList<Landmark*>* MapWidget::Landmarks(void) 364 { 365 return landmarks; 366 } 367 368 bool MapWidget::LandmarkToSend(int index) 369 { 370 if(index>=landmarks_old->count()) return true; 371 372 if(landmarks->at(index)->coordinate()!=landmarks_old->at(index)->coordinate()) 373 return true; 374 else 375 return false; 376 } 377 void MapWidget::RemoveLandmarks(void) 378 { 379 for(int i=0;i<landmarks->count();i++) 380 { 381 landmarks->at(i)->RemoveLandmark(); 382 } 383 for(int i=0;i<landmarks_old->count();i++) 384 { 385 landmarks_old->at(i)->RemoveLandmark(); 386 } 387 } 388 389 void MapWidget::AddLandmarks(QGraphicsGeoMap *geoMap) 390 { 391 for(int i=0;i<landmarks->count();i++) 392 { 393 landmarks->at(i)->AddLandmark(geoMap); 394 } 395 for(int i=0;i<landmarks_old->count();i++) 396 { 397 landmarks_old->at(i)->AddLandmark(geoMap); 398 } 399 } 400 401 void MapWidget::AddLandmark(const QGeoCoordinate &coordinate) 402 { 403 Landmark* landmark=new Landmark(geoMap,coordinate,QString("%1").arg(landmarks->count()+1)); 256 } 257 258 event->accept(); 259 } 260 261 void MapWidget::resizeEvent(QResizeEvent *event) { 262 if (geoMap) { 263 m_scene->setSceneRect( 264 QRectF(0, 0, event->size().width(), event->size().height())); 265 geoMap->resize(event->size().width(), event->size().height()); 266 } 267 268 QGraphicsView::resizeEvent(event); 269 } 270 271 void MapWidget::wheelEvent(QWheelEvent *event) { 272 int steps = event->delta() / 120; 273 int zoom = qBound(geoMap->minimumZoomLevel(), geoMap->zoomLevel() + steps, 274 geoMap->maximumZoomLevel()); 275 276 if (zoom != geoMap->zoomLevel()) 277 geoMap->setZoomLevel(zoom); 278 // if(!centered) 279 // geoMap->setCenter(geoMap->screenPositionToCoordinate(event->pos())); 280 } 281 282 void MapWidget::mouseDoubleClickEvent(QMouseEvent *event) { 283 if (!map->isCentered()) 284 geoMap->setCenter(geoMap->screenPositionToCoordinate(event->pos())); 285 } 286 287 bool MapWidget::IsUptodate(void) { return is_uptodate; } 288 289 void MapWidget::SetUptodate(void) { 290 for (int i = 0; i < landmarks_old->count(); i++) { 291 delete landmarks_old->at(i); 292 } 293 landmarks_old->clear(); 294 295 for (int i = 0; i < landmarks->count(); i++) { 296 landmarks->at(i)->setColor(Qt::white); 297 Landmark *landmark = 298 new Landmark(geoMap, landmarks->at(i)->coordinate(), 299 QString("%1").arg(landmarks->count() + 1)); 300 landmarks_old->append(landmark); 301 landmarks_old->at(i)->setVisible(false); 302 } 303 304 is_uptodate = true; 305 } 306 307 void MapWidget::Reset(void) { 308 for (int i = 0; i < landmarks->count(); i++) { 309 delete landmarks->at(i); 310 } 311 landmarks->clear(); 312 313 for (int i = 0; i < landmarks_old->count(); i++) { 314 Landmark *landmark = 315 new Landmark(geoMap, landmarks_old->at(i)->coordinate(), 316 QString("%1").arg(landmarks->count() + 1)); 404 317 landmarks->append(landmark); 405 landmark->setColor(Qt::white); 406 landmark=new Landmark(geoMap,coordinate,QString("%1").arg(landmarks_old->count()+1)); 407 landmarks_old->append(landmark); 408 landmark->setColor(Qt::white); 409 landmark->setVisible(false); 410 } 411 412 void MapWidget::AddPoint(QString name) 413 { 414 points.append(name); 415 } 318 landmarks->at(i)->setColor(Qt::white); 319 } 320 321 is_uptodate = true; 322 } 323 324 QList<Landmark *> *MapWidget::Landmarks(void) { return landmarks; } 325 326 bool MapWidget::LandmarkToSend(int index) { 327 if (index >= landmarks_old->count()) 328 return true; 329 330 if (landmarks->at(index)->coordinate() != 331 landmarks_old->at(index)->coordinate()) 332 return true; 333 else 334 return false; 335 } 336 void MapWidget::RemoveLandmarks(void) { 337 for (int i = 0; i < landmarks->count(); i++) { 338 landmarks->at(i)->RemoveLandmark(); 339 } 340 for (int i = 0; i < landmarks_old->count(); i++) { 341 landmarks_old->at(i)->RemoveLandmark(); 342 } 343 } 344 345 void MapWidget::AddLandmarks(QGraphicsGeoMap *geoMap) { 346 for (int i = 0; i < landmarks->count(); i++) { 347 landmarks->at(i)->AddLandmark(geoMap); 348 } 349 for (int i = 0; i < landmarks_old->count(); i++) { 350 landmarks_old->at(i)->AddLandmark(geoMap); 351 } 352 } 353 354 void MapWidget::AddLandmark(const QGeoCoordinate &coordinate) { 355 Landmark *landmark = new Landmark(geoMap, coordinate, 356 QString("%1").arg(landmarks->count() + 1)); 357 landmarks->append(landmark); 358 landmark->setColor(Qt::white); 359 landmark = new Landmark(geoMap, coordinate, 360 QString("%1").arg(landmarks_old->count() + 1)); 361 landmarks_old->append(landmark); 362 landmark->setColor(Qt::white); 363 landmark->setVisible(false); 364 } 365 366 void MapWidget::AddPoint(QString name) { points.append(name); } -
trunk/tools/FlairGCS/src/mapwidget.h
r10 r15 57 57 using namespace QtMobility; 58 58 59 class MapWidget : public QGraphicsView 60 { 61 Q_OBJECT 59 class MapWidget : public QGraphicsView { 60 Q_OBJECT 62 61 63 64 MapWidget(Map* map,QWidget *parent = 0);65 66 67 68 69 70 QList<Landmark*>*Landmarks(void);71 72 73 74 75 62 public: 63 MapWidget(Map *map, QWidget *parent = 0); 64 void setMap(QtMobility::QGraphicsGeoMap *geoMap); 65 QGraphicsScene *scene() const; 66 bool IsUptodate(void); 67 void SetUptodate(void); 68 void Reset(void); 69 QList<Landmark *> *Landmarks(void); 70 bool LandmarkToSend(int index); 71 void AddLandmark(const QGeoCoordinate &coordinate); 72 void RemoveLandmarks(void); 73 void AddLandmarks(QGraphicsGeoMap *geoMap); 74 void AddPoint(QString name); 76 75 77 78 76 signals: 77 void positionChanged(const QGeoCoordinate &coordinate); 79 78 80 81 82 83 84 85 86 79 protected: 80 void mousePressEvent(QMouseEvent *event); 81 void mouseMoveEvent(QMouseEvent *event); 82 void mouseReleaseEvent(QMouseEvent *event); 83 void resizeEvent(QResizeEvent *event); 84 void wheelEvent(QWheelEvent *event); 85 void mouseDoubleClickEvent(QMouseEvent *event); 87 86 88 89 87 private slots: 88 void initDrag(); 90 89 91 92 93 94 95 96 90 private: 91 QGraphicsGeoMap *geoMap; 92 bool dragging; 93 QPoint dragStartPosition; 94 bool pressed; 95 bool is_uptodate; 97 96 98 99 QList<Landmark*> *landmarks;100 QList<Landmark*> *landmarks_old;101 102 103 Map*map;97 QGraphicsScene *m_scene; 98 QList<Landmark *> *landmarks; 99 QList<Landmark *> *landmarks_old; 100 QList<QString> points; 101 Landmark *landmark_match; 102 Map *map; 104 103 }; 105 104
Note:
See TracChangeset
for help on using the changeset viewer.