Changeset 67 in flair-src


Ignore:
Timestamp:
Aug 29, 2016, 4:58:23 PM (4 years ago)
Author:
Sanahuja Guillaume
Message:

corrections bugs checkpoint map

Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/src/FrameworkManager_impl.cpp

    r55 r67  
    181181    status = UDT::close(com_sock);
    182182    if (status != 0)
    183       printf("Error udt::close %s", UDT::getlasterror().getErrorMessage());
     183      Printf("Error udt::close %s", UDT::getlasterror().getErrorMessage());
    184184
    185185    status = UDT::close(file_sock);
    186186    if (status != 0)
    187       printf("Error udt::close %s", UDT::getlasterror().getErrorMessage());
     187      Printf("Error udt::close %s", UDT::getlasterror().getErrorMessage());
    188188
    189189    SleepMS(200); // a revoir, sinon UDT::cleanup bloque en RT
     
    294294        xmlDoc *doc;
    295295        rcv_buf[bytesRead] = 0;
    296 
     296 //Printf("%s\n",rcv_buf);
    297297        doc = xmlReadMemory(rcv_buf, (int)bytesRead, "include.xml",
    298298                            "ISO-8859-1", 0);
  • trunk/lib/FlairCore/src/Map.cpp

    r15 r67  
    2121#include "GeoCoordinate.h"
    2222#include "FrameworkManager.h"
     23#include <cmath>
    2324#include <string.h>
    2425#include <sstream>
     
    8081void Map::ExtraXmlEvent(void) {
    8182
    82   // attention pas rt safe (creation checkpoint)
     83  // attention pas rt safe (creation/destruction checkpoint)
    8384  size_t i = 0;
    8485  while (1) {
    85     // printf("test %i\n",i);
    8686    double latitude, longitude;
    8787    double altitude = 0;
     
    9090    long_prop << "long" << i;
    9191    alt_prop << "alt" << i;
     92
    9293    if (GetPersistentXmlProp(lat_prop.str(), latitude) &&
    9394        GetPersistentXmlProp(long_prop.str(), longitude)) {
    9495      GetPersistentXmlProp(alt_prop.str(), altitude);
     96
    9597      if (i >= checkpoints.size()) {
     98        //add checkpoint
    9699        GeoCoordinate *checkpoint = new GeoCoordinate(
    97100            this, "checkpoint", latitude, longitude, altitude);
    98101        checkpoints.push_back(checkpoint);
    99         // printf("add %i\n",i);
     102      } else if(isnan(latitude) || isnan(longitude)) {
     103        //delete checkpoint
     104        removeCheckpoint(i);
     105        break;//si delete, la station sol n'envoit que cette info
    100106      } else {
     107        //move checkpoint
    101108        checkpoints.at(i)->SetCoordinates(latitude, longitude, altitude);
    102109      }
     
    107114    i++;
    108115  }
    109 
     116/*
    110117  for (size_t i = 0; i < checkpoints.size(); i++) {
    111118    double latitude, longitude, altitude;
    112119    checkpoints.at(i)->GetCoordinates(&latitude, &longitude, &altitude);
    113     // printf("%i %f %f\n",i,latitude,longitude);
     120     printf("%i %f %f\n",i,latitude,longitude);
     121  }*/
     122}
     123
     124void Map::removeCheckpoint(size_t index) {
     125  //left shift
     126  for (size_t i = index; i < checkpoints.size()-1; i++) {
     127    double latitude, longitude, altitude;
     128    checkpoints.at(i+1)->GetCoordinates(&latitude, &longitude, &altitude);
     129    checkpoints.at(i)->SetCoordinates(latitude,longitude,altitude);
    114130  }
     131
     132  //remove last one
     133  delete checkpoints.back();
     134  checkpoints.pop_back();
     135
     136  //remove last one in xml
     137  ostringstream lat_prop, long_prop, alt_prop;
     138  lat_prop << "lat" << checkpoints.size();
     139  long_prop << "long" << checkpoints.size();
     140  alt_prop << "alt" << checkpoints.size();
     141  UnsetPersistentXmlProp(lat_prop.str());
     142  UnsetPersistentXmlProp(long_prop.str());
     143  UnsetPersistentXmlProp(alt_prop.str());
    115144}
    116145
  • trunk/lib/FlairCore/src/Map.h

    r15 r67  
    7777  void ExtraXmlEvent(void);
    7878
     79  void removeCheckpoint(size_t index);
     80
    7981  std::vector<core::GeoCoordinate *> checkpoints;
    8082  std::vector<const core::GeoCoordinate *> to_draw;
  • trunk/lib/FlairCore/src/Widget.cpp

    r15 r67  
    8282  if (GetPersistentXmlProp<double>(prop, tmp)) {
    8383    value = tmp;
     84    return true;
     85  } else {
     86    return false;
     87  }
     88}
     89
     90template <>
     91bool Widget::GetPersistentXmlProp(std::string prop, std::string &value) {
     92  xmlChar *result = NULL;
     93  result = xmlGetProp(pimpl_->file_node, (xmlChar *)prop.c_str());
     94  if (result != NULL) {
     95    value = std::string((char *)result);
     96    xmlFree(result);
    8497    return true;
    8598  } else {
     
    208221}
    209222
     223template <> void Widget::SetPersistentXmlProp(std::string prop, std::string value) {
     224  SetVolatileXmlProp(prop, value);
     225  SetVolatileXmlProp(prop, value, pimpl_->file_node);
     226}
     227
     228void Widget::UnsetPersistentXmlProp(std::string prop) {
     229  xmlUnsetProp(pimpl_->file_node, (xmlChar *)prop.c_str());
     230}
     231
    210232void Widget::SendXml(void) { pimpl_->SendXml(); }
    211233
  • trunk/lib/FlairCore/src/Widget.h

    r15 r67  
    143143  virtual void XmlEvent(void){};
    144144
     145  /*!
     146   * \brief Unset a persistent xml property
     147   *
     148   * Unset an existent property, so it won't be saved.
     149   *
     150   * \param prop property to set
     151   */
     152  void UnsetPersistentXmlProp(std::string prop);
     153
    145154private:
    146155  class Widget_impl *pimpl_;
  • trunk/lib/FlairSensorActuator/src/NmeaGps.cpp

    r55 r67  
    195195  if (result != 1) {
    196196    Warn("unrecognized nmea sentence: %s\n",frame);
     197    return;
    197198  }
    198199
  • trunk/tools/FlairGCS/src/DataRemote.cpp

    r15 r67  
    7878
    7979void DataRemote::SendPeriod(int period, bool auto_refresh) {
     80  RemoveAllAttributes();
     81
    8082  SetAttribute("period", period);
    8183  SetAttribute("enabled", auto_refresh);
  • trunk/tools/FlairGCS/src/Landmark.cpp

    r15 r67  
    4646}
    4747
     48bool Landmark::IsUptodate(void) {
     49  if(text->brush()==QBrush(Qt::white)) {
     50    return true;
     51  } else {
     52    return false;
     53  }
     54}
     55
    4856void Landmark::setCoordinate(const QGeoCoordinate &coordinate) {
    4957  pixmap->setCoordinate(coordinate);
  • trunk/tools/FlairGCS/src/Landmark.h

    r15 r67  
    2929  void RemoveLandmark(void);
    3030  void AddLandmark(QtMobility::QGraphicsGeoMap *geoMap);
     31  bool IsUptodate(void);
    3132
    3233private:
  • trunk/tools/FlairGCS/src/Map.cpp

    r62 r67  
    9595  for (int i = 0; i < points.count(); i++) delete points.at(i);
    9696  delete mapWidget;
    97 
    98   if(geoMap!=0) delete geoMap;
    9997}
    10098
  • trunk/tools/FlairGCS/src/Map.h

    r15 r67  
    2525class Map : public DataRemote {
    2626  Q_OBJECT
     27
     28  friend class MapWidget;
    2729
    2830public:
  • trunk/tools/FlairGCS/src/XmlWidget.cpp

    r15 r67  
    291291}
    292292
     293void XmlWidget::RemoveAllAttributes() {
     294  QString name = write_elem.attribute("name");
     295
     296  QDomNamedNodeMap attributes=write_elem.attributes();
     297  while(attributes.count()!=0) {
     298    printf("%i %s\n",attributes.count(),attributes.item(0).toAttr().name().toLocal8Bit().constData());
     299    write_elem.removeAttribute(attributes.item(0).toAttr().name());
     300  }
     301  SetAttribute("name", name);
     302}
     303
    293304void XmlWidget::RenamedFrom(QString old_name) {
    294305  QString name = write_elem.attribute("name");
  • trunk/tools/FlairGCS/src/XmlWidget.h

    r16 r67  
    6868  void SetAttribute(const QString &name, float value);
    6969  void SetAttribute(const QString &name, double value);
     70  void RemoveAllAttributes(); //except name
    7071  void RemoveAttribute(const QString &name);
    7172};
  • trunk/tools/FlairGCS/src/mapwidget.cpp

    r62 r67  
    5454#include "Landmark.h"
    5555#include "Map.h"
     56#include "ConnectionLayout.h"
    5657
    5758using namespace QtMobility;
     
    6667  pressed = false;
    6768  landmark_match = NULL;
    68   is_uptodate = true;
    6969  this->map = map;
    7070
     
    107107      QList<QAction *> centered_actions;
    108108
     109      //add centered for every point
    109110      QMenu *centered_menu = menu->addMenu("centered");
    110111      for (int i = 0; i < points.count(); i++) {
     
    122123
    123124      b = menu->addAction("place checkpoint");
     125
     126      //add go to for every landmark
    124127      QMenu *go_to_menu = menu->addMenu("go to");
    125128      for (int i = 0; i < landmarks->count(); i++) {
     
    134137      z = map->execmenu(this, menu, event->globalPos());
    135138
     139      //center to the desired point
    136140      for (int i = 0; i < centered_actions.count(); i++) {
    137141        if (z == centered_actions.at(i)) {
     
    146150      }
    147151
     152      //add a landmark
    148153      if (z == b) {
    149154        Landmark *landmark = new Landmark(
     
    151156            QString("%1").arg(landmarks->count() + 1));
    152157        landmarks->append(landmark);
    153         is_uptodate = false;
    154158      }
    155159      for (int i = 0; i < go_to_actions.count(); i++) {
     
    161165      }
    162166
     167    //delete landmark
    163168    } else {
    164169      QAction *a, *z;
    165170      a = menu->addAction("delete");
    166       z = menu->exec(event->globalPos());
    167 
    168       if (z == a) {
    169         int i;
    170         for (i = 0; i < landmarks->count(); i++) {
    171           if (landmarks->at(i)->contains(
     171      //get selected landmark id
     172      int landmark_index;
     173      for (landmark_index = 0; landmark_index < landmarks->count(); landmark_index++) {
     174          if (landmarks->at(landmark_index)->contains(
    172175                  geoMap->screenPositionToCoordinate(event->pos()))) {
    173             delete landmarks->at(i);
    174             landmarks->removeAt(i);
     176            a->setEnabled(landmarks->at(landmark_index)->IsUptodate());
    175177            break;
    176178          }
    177         }
    178         for (int j = i; j < landmarks->count(); j++) {
     179      }
     180      z = menu->exec(event->globalPos());
     181
     182      if (z == a) {
     183        //remove from landmarks_old
     184        for (int i = 0; i < landmarks_old->count(); i++) {
     185          if (landmarks_old->at(i)->contains(
     186                  geoMap->screenPositionToCoordinate(event->pos()))) {
     187            landmarks_old->removeAt(i);
     188            break;
     189          }
     190        }
     191
     192        //remove from landmarks
     193        delete landmarks->at(landmark_index);
     194        landmarks->removeAt(landmark_index);
     195
     196        //reorder the remaining ones
     197        for (int j = landmark_index; j < landmarks->count(); j++) {
    179198          landmarks->at(j)->setText(QString("%1").arg(j + 1));
    180199        }
     200
     201        //send delete
     202        map->RemoveAllAttributes();
     203        map->SetAttribute("lat" + QString::number(landmark_index),"delete");
     204        map->SetAttribute("long" + QString::number(landmark_index),"delete");
     205        map->connectionLayout()->XmlToSend(map->XmlDoc());
     206        map->RemoveAttribute("lat" + QString::number(landmark_index));
     207        map->RemoveAttribute("long" + QString::number(landmark_index));
    181208      }
    182209    }
     
    219246        landmark_match = landmarks->at(i);
    220247        landmark_match->setColor(Qt::red);
    221         is_uptodate = false;
    222248      }
    223249      new_cursor = Qt::PointingHandCursor;
     
    290316}
    291317
    292 bool MapWidget::IsUptodate(void) { return is_uptodate; }
     318bool MapWidget::IsUptodate(void) {
     319  for (int i = 0; i < landmarks->count(); i++) {
     320    if(!landmarks->at(i)->IsUptodate()) return false;
     321  }
     322  return true;
     323}
    293324
    294325void MapWidget::SetUptodate(void) {
     
    306337    landmarks_old->at(i)->setVisible(false);
    307338  }
    308 
    309   is_uptodate = true;
    310339}
    311340
     
    323352    landmarks->at(i)->setColor(Qt::white);
    324353  }
    325 
    326   is_uptodate = true;
    327354}
    328355
  • trunk/tools/FlairGCS/src/mapwidget.h

    r62 r67  
    9494  QPoint dragStartPosition;
    9595  bool pressed;
    96   bool is_uptodate;
    9796
    9897  QGraphicsScene *m_scene;
Note: See TracChangeset for help on using the changeset viewer.