bool
CurvesWidget::updateCurve(const string &address, bool forceUpdate)
{
  BasicBox *box = Maquette::getInstance()->getBox(_boxID);
  if (box != NULL) { // Box Found
      AbstractCurve *abCurve = box->getCurve(address);
      map<string, CurveWidget *>::iterator curveIt2 = _curveMap.find(address);
      bool curveFound = (curveIt2 != _curveMap.end());
      unsigned int curveTabIndex = 0;
      CurveWidget *curveTab = NULL;
      if (curveFound) {
          curveTab = curveIt2->second;
        }

      static const bool FORCE_SHOW = true;
      static const bool FORCE_HIDE = false;

      unsigned int sampleRate;
      bool redundancy, interpolate;
      vector<float> values, xPercents, yValues, coeff;
      vector<string> argTypes;
      vector<short> sectionType;

      if (abCurve != NULL) { // Abstract Curve found
          if (abCurve->_show) { // Abstract curve showing
              if (curveFound) { // Curve tab existing
                  if (forceUpdate) { // Force updating through engines
                      bool getCurveSuccess = Maquette::getInstance()->getCurveAttributes(_boxID, address, 0, sampleRate, redundancy, interpolate, values, argTypes, xPercents, yValues, sectionType, coeff);
                      if (getCurveSuccess) {
                          curveTab->setAttributes(_boxID, address, 0, values, sampleRate, redundancy, FORCE_SHOW, interpolate, argTypes, xPercents, yValues, sectionType, coeff);
                          box->setCurve(address, curveTab->abstractCurve());
                          if (!_interpolation->updateLine(address, interpolate, sampleRate, redundancy, FORCE_SHOW)) {
                              _interpolation->addLine(address, interpolate, sampleRate, redundancy, FORCE_SHOW);
                            }
                        }
                    }
                  else { // No forcing : updating through abstract curve
                      curveTab->setAttributes(abCurve);
                      if (!_interpolation->updateLine(address, abCurve->_interpolate, abCurve->_sampleRate, abCurve->_redundancy, abCurve->_show)) {
                          _interpolation->addLine(address, abCurve->_interpolate, abCurve->_sampleRate, abCurve->_redundancy, abCurve->_show);
                        }
                    }
                }
              else { // Curve tab not existing
                  if (forceUpdate) { // Force creating through engines
                      bool getCurveSuccess = Maquette::getInstance()->getCurveAttributes(_boxID, address, 0, sampleRate, redundancy, interpolate, values, argTypes, xPercents, yValues, sectionType, coeff);
                      if (getCurveSuccess) {
                          // Create and set
                          curveTab = new CurveWidget(NULL);
                          _tabWidget->clear();
                          curveTab->setAttributes(_boxID, address, 0, values, sampleRate, redundancy, FORCE_SHOW, interpolate, argTypes, xPercents, yValues, sectionType, coeff);
                          QString curveAddressStr = QString::fromStdString(address);

                          // Add tab and store
                          addCurve(curveAddressStr, curveTab);
                          addToComboBox(curveAddressStr);

                          _curveMap[address] = curveTab;
                          displayCurve(_comboBox->currentText());

                          // Set box curve
                          box->setCurve(address, curveTab->abstractCurve());
                          if (!_interpolation->updateLine(address, interpolate, sampleRate, redundancy, FORCE_SHOW)) {
                              _interpolation->addLine(address, interpolate, sampleRate, redundancy, FORCE_SHOW);
                            }
                        }
                    }

                  else { // No forcing : create through abstract curve
                         // Create and set
                      curveTab = new CurveWidget(NULL);
                      curveTab->setAttributes(abCurve);
                      QString curveAddressStr = QString::fromStdString(address);

                      // Add tab and store
                      addCurve(curveAddressStr, curveTab);

                      _curveMap[address] = curveTab;

                      addToComboBox(curveAddressStr);
                      displayCurve(_comboBox->currentText());

                      if (!_interpolation->updateLine(address, abCurve->_interpolate, abCurve->_sampleRate, abCurve->_redundancy, abCurve->_show)) {
                          _interpolation->addLine(address, abCurve->_interpolate, abCurve->_sampleRate, abCurve->_redundancy, abCurve->_show);
                        }
                    }
                }
            }
          else { // Abstract curve hiding
              if (curveFound) { // Curve tab existing
                  if (forceUpdate) { // Force updating through engines
                      bool getCurveSuccess = Maquette::getInstance()->getCurveAttributes(_boxID, address, 0, sampleRate, redundancy, interpolate, values, argTypes, xPercents, yValues, sectionType, coeff);
                      if (getCurveSuccess) {
                          if (values.front() != values.back()) {
                              curveTab->setAttributes(_boxID, address, 0, values, sampleRate, redundancy, FORCE_SHOW, interpolate, argTypes, xPercents, yValues, sectionType, coeff);
                            }
                          else {
                              // Set and assign new abstract curve to box
                              curveTab->setAttributes(_boxID, address, 0, values, sampleRate, redundancy, FORCE_HIDE, interpolate, argTypes, xPercents, yValues, sectionType, coeff);
                            }
                          box->setCurve(address, curveTab->abstractCurve());
                        }
                    }

                  else {
                      // No forcing : updating through abstract curve
                    }

                  // Remove curve tab anyway
                  removeCurve(address);
                  _comboBox->setCurrentIndex(curveTabIndex);
                  displayCurve(_comboBox->currentText());
                  delete curveTab;
                  if (!_interpolation->updateLine(address, abCurve->_interpolate, abCurve->_sampleRate, abCurve->_redundancy, abCurve->_show)) {
                      _interpolation->addLine(address, abCurve->_interpolate, abCurve->_sampleRate, abCurve->_redundancy, abCurve->_show);
                    }
                }
              else { // Curve tab not existing
                  if (forceUpdate) { // Force updating through engines
                      bool getCurveSuccess = Maquette::getInstance()->getCurveAttributes(_boxID, address, 0, sampleRate, redundancy, interpolate, values, argTypes, xPercents, yValues, sectionType, coeff);
                      if (getCurveSuccess) {
                          // Create, set and assign new abstract curve to box
                          curveTab = new CurveWidget(NULL);
                          curveTab->setAttributes(_boxID, address, 0, values, sampleRate, redundancy, FORCE_HIDE, interpolate, argTypes, xPercents, yValues, sectionType, coeff);
                          box->setCurve(address, curveTab->abstractCurve());
                          if (!_interpolation->updateLine(address, interpolate, sampleRate, redundancy, FORCE_HIDE)) {
                              _interpolation->addLine(address, interpolate, sampleRate, redundancy, FORCE_HIDE);
                            }
                          delete curveTab;
                        }
                    }
                  else { // No forcing : updating through abstract curve
                      if (!_interpolation->updateLine(address, abCurve->_interpolate, abCurve->_sampleRate, abCurve->_redundancy, abCurve->_show)) {
                          _interpolation->addLine(address, abCurve->_interpolate, abCurve->_sampleRate, abCurve->_redundancy, abCurve->_show);
                        }
                    }
                }
            }
        }
      else { // Abstract Curve not found
             // Get attributes and determine if shown
          bool show = true;
          interpolate = true;

          bool getCurveSuccess = Maquette::getInstance()->getCurveAttributes(_boxID, address, 0, sampleRate, redundancy, interpolate, values, argTypes, xPercents, yValues, sectionType, coeff);
          if (getCurveSuccess) {
              if (xPercents.empty() && yValues.empty() && values.size() >= 2) {
                  if (values.front() == values.back()) {
                      show = false;
                      interpolate = false;
                    }
                }
              if (show) { // Curve showing
                  if (!curveFound) { // Curve tab not existing
                      // Creating curve tab from engines anyway (no abstract curve)
                      // Create and set
                      curveTab = new CurveWidget(NULL);
                      QString curveAddressStr = QString::fromStdString(address);

                      // Add tab and store
                      addCurve(curveAddressStr, curveTab);
                      addToComboBox(curveAddressStr);
                      displayCurve(_comboBox->currentText());
                    }
                  else { // Curve tab existing
                         // Updating curve tab from engines anyway (no abstract curve)
                    }

                  curveTab->setAttributes(_boxID, address, 0, values, sampleRate, redundancy, FORCE_SHOW, interpolate, argTypes, xPercents, yValues, sectionType, coeff);

                  // Set box curve
                  box->setCurve(address, curveTab->abstractCurve());
                  if (!_interpolation->updateLine(address, interpolate, sampleRate, redundancy, FORCE_SHOW)) {
                      _interpolation->addLine(address, interpolate, sampleRate, redundancy, FORCE_SHOW);
                    }
                }
              else { // Curve hiding
                  if (curveFound) { // Curve tab existing
                      // Creating curve tab from engines anyway (no abstract curve)
                      // Set and assign new abstract curve to box
                      curveTab->setAttributes(_boxID, address, 0, values, sampleRate, redundancy, FORCE_HIDE, interpolate, argTypes, xPercents, yValues, sectionType, coeff);
                      box->setCurve(address, curveTab->abstractCurve());

                      // Remove curve tab
                      removeCurve(address);
                    }

                  else { // Curve tab not existing
                         // Creating curve tab from engines anyway (no abstract curve)
                      curveTab = new CurveWidget(NULL);
                      curveTab->setAttributes(_boxID, address, 0, values, sampleRate, redundancy, FORCE_HIDE, interpolate, argTypes, xPercents, yValues, sectionType, coeff);
                      box->setCurve(address, curveTab->abstractCurve());
                      delete curveTab;
                    }

                  if (!_interpolation->updateLine(address, interpolate, sampleRate, redundancy, FORCE_HIDE)) {
                      _interpolation->addLine(address, interpolate, sampleRate, redundancy, FORCE_HIDE);
                    }
                }
            }
        }
    }
  else { // Box Not Found
      return false;
    }
  return false;
}
Example #2
0
bool
BoxWidget::updateCurve(const string &address, bool forceUpdate)
{
  Q_UNUSED(forceUpdate);
  BasicBox *box = Maquette::getInstance()->getBox(_boxID);

  if (box != NULL) { // Box Found
      if (box->hasCurve(address)) {
          AbstractCurve *abCurve = box->getCurve(address);
          QMap<string, CurveWidget *>::iterator curveIt2 = _curveMap->find(address);
          QString curveAddressStr = QString::fromStdString(address);

          bool curveFound = (curveIt2 != _curveMap->end());
          CurveWidget *curveTab = NULL;

          unsigned int sampleRate;
          bool redundancy, interpolate;
          vector<float> values, xPercents, yValues, coeff;
          vector<string> argTypes;
          vector<short> sectionType;

          bool getCurveSuccess = Maquette::getInstance()->getCurveAttributes(_boxID, address, 0, sampleRate, redundancy, interpolate, values, argTypes, xPercents, yValues, sectionType, coeff);

          //--- PRINT ---
//            std::cout<<"values : "<<std::endl;
//            for (unsigned int i = 0; i < yValues.size() ; i++) {
//                std::cout<<"  "<<yValues[i]<<std::endl;
//            }
//            std::cout<<std::endl;
          //-------------

          if (getCurveSuccess) {
              /********** Abstract Curve found ***********/
              if (abCurve != NULL) {
                  if (curveFound) {
                      curveTab = curveIt2.value();

                      curveTab->setAttributes(_boxID, address, 0, values, sampleRate, redundancy, abCurve->_show, interpolate, argTypes, xPercents, yValues, sectionType, coeff);
                      bool muteState = Maquette::getInstance()->getCurveMuteState(_boxID, address);

                      if (forceUpdate) {
                          if (!muteState) {
                              addCurve(curveAddressStr, curveTab);
                            }
                          else {
                              removeCurve(address);
                            }
                        }
                    }
                  else {
                      //Create
                      curveTab = new CurveWidget(NULL);

                      curveTab->setAttributes(_boxID, address, 0, values, sampleRate, redundancy, abCurve->_show, interpolate, argTypes, xPercents, yValues, sectionType, coeff);
                      bool muteState = Maquette::getInstance()->getCurveMuteState(_boxID, address);
                      if (!muteState) {
                          addCurve(curveAddressStr, curveTab);
                        }
                      else {
                          removeCurve(address);
                        }
                    }

                  //Set attributes
                  box->setCurve(address, curveTab->abstractCurve());
                }


              /******* Abstract Curve not found ********/
              else {
                  bool show = true;

//                    interpolate = !Maquette::getInstance()->getCurveMuteState(_boxID,address);
//                    if (xPercents.empty() && yValues.empty() && values.size() >= 2) {
//                        if (values.front() == values.back()) {
//                            show = false;
//                            interpolate = false;
//                        }
//                    }
                  //Set attributes
                  curveTab = new CurveWidget(NULL);
                  QString curveAddressStr = QString::fromStdString(address);
                  curveTab->setAttributes(_boxID, address, 0, values, sampleRate, redundancy, show, interpolate, argTypes, xPercents, yValues, sectionType, coeff);
                  if (interpolate) {
                      addCurve(curveAddressStr, curveTab);
                      box->setCurve(address, curveTab->abstractCurve());
                    }
                }
            }
        }
      else {
          return false;
        }
    }
  else {  // Box Not Found
      return false;
    }
  return false;
}