Exemple #1
0
void KstMatrixDialog::fillFieldsForEdit() {
  KstMatrixPtr mp;

  mp = kst_cast<KstMatrix>(_dp);
  if (mp) {
    KstRMatrixPtr rmp;

    mp->readLock();
    _tagName->setText(mp->tagName());
    _w->_minX->setText(QString::number(mp->minX()));
    _w->_minY->setText(QString::number(mp->minY()));
    _w->_xStep->setText(QString::number(mp->xStepSize()));
    _w->_yStep->setText(QString::number(mp->yStepSize()));
    mp->unlock();
  
    _w->_sourceGroup->hide();
  
    rmp = kst_cast<KstRMatrix>(mp);
    if (rmp) {
      fillFieldsForRMatrixEdit();
    } else {
      fillFieldsForSMatrixEdit();
    }
  
    updateEnables();
  
    adjustSize();
    resize(minimumSizeHint());
    setFixedHeight(height());
  }
}
Exemple #2
0
void MatrixSelector::newMatrixCreated( KstMatrixPtr v ) {
  QString name;

  v->readLock();
  name = v->tagName();
  v->unlock();
  v = 0L; // deref

  emit newMatrixCreated(name);
}
Exemple #3
0
void KstImageDialogI::calcAutoThreshold() {
  //make sure an matrix is selected
  if (!_w->_matrix->selectedMatrix().isEmpty()){
    KST::matrixList.lock().readLock();
    KstMatrixPtr matrix = *KST::matrixList.findTag(_w->_matrix->selectedMatrix());
    KST::matrixList.lock().unlock();
    if (matrix) {
      matrix->readLock();
      _w->_lowerZ->setText(QString::number(matrix->minValue()));
      _w->_upperZ->setText(QString::number(matrix->maxValue()));
      matrix->unlock();
    }
  }
}
Exemple #4
0
// This should use a smart (percentile based) algorithm to
// calculate the thresholds.  It will be expensive.
void KstImageDialogI::calcSmartThreshold() {
  //make sure an matrix is selected
  if (!_w->_matrix->selectedMatrix().isEmpty()){
    KST::matrixList.lock().readLock();
    KstMatrixPtr matrix = *KST::matrixList.findTag(_w->_matrix->selectedMatrix());
    KST::matrixList.lock().unlock();
    if (matrix) {
      matrix->readLock();
      double per = _w->_smartThresholdValue->value()/100.0;

      matrix->calcNoSpikeRange(per);
      _w->_lowerZ->setText(QString::number(matrix->minValueNoSpike()));
      _w->_upperZ->setText(QString::number(matrix->maxValueNoSpike()));
      matrix->unlock();
    }
  }
}
Exemple #5
0
void KstViewMatricesDialogI::updateViewMatricesDialog(const QString& matrixName) {
  int needed = 0;
  
  KST::matrixList.lock().readLock();
  KstMatrixPtr matrix = *KST::matrixList.findTag(matrixName);
  KST::matrixList.lock().unlock();
  if (matrix) {
    matrix->readLock();
    
    needed = matrix->xNumSteps();
    if (needed != _tableMatrices->numCols()) {
      _tableMatrices->setNumCols(needed);
    }    
    
    needed = matrix->yNumSteps();
    if (needed != _tableMatrices->numRows()) {
      _tableMatrices->setNumRows(needed);
    }  
        
    matrix->unlock();
  }
}
Exemple #6
0
void KstViewMatricesDialog::updateViewMatricesDialog(const QString& matrixName) {
  KstMatrixPtr matrix;

  KST::matrixList.lock().readLock();
  matrix = *KST::matrixList.findTag(matrixName);
  KST::matrixList.lock().unlock();
  if (matrix) {
    bool updated = false;
    int xneeded = 0;
    int yneeded = 0;

    matrix->readLock();
    xneeded = matrix->xNumSteps();
    yneeded = matrix->yNumSteps();
    matrix->unlock();

    if (xneeded != _tableMatrices->columnCount()) {
      _tableMatrices->setColumnCount(xneeded);
      updated = true;
    }

    if (yneeded != _tableMatrices->rowCount()) {
      _tableMatrices->setRowCount(yneeded);
      updated = true;
    }

    if (!updated) {
      //
      // following two lines appear to be necessary to ensure a full update...
      //

      _tableMatrices->hide();
      _tableMatrices->show();

      _tableMatrices->update();
    }
  }
}
Exemple #7
0
bool KstMatrixDialog::editObject() {
  //
  // if editing multiple objects, edit each one...
  //

  if (_editMultipleMode) {
// xxx    _fileNameDirty = !_w->_fileName->url().isEmpty();
    _gradientZAtMinDirty = !_w->_gradientZAtMin->text().isEmpty();
    _gradientZAtMaxDirty = !_w->_gradientZAtMax->text().isEmpty();
    _minXDirty = !_w->_minX->text().isEmpty();
    _minYDirty = !_w->_minY->text().isEmpty();
    _yStepDirty = !_w->_yStep->text().isEmpty();
    _xStepDirty = !_w->_xStep->text().isEmpty();

    _xStartDirty = _w->_xStart->text() != " ";
    _yStartDirty = _w->_yStart->text() != " ";
    _xNumStepsDirty = _w->_xNumSteps->text() != " ";
    _yNumStepsDirty = _w->_yNumSteps->text() != " ";

    _skipDirty = _w->_skip->text() != " ";
    _nXDirty = _w->_nX->text() != " ";
    _nYDirty = _w->_nY->text() != " ";

    bool didEdit = false;
    int i;

    for (i = 0; i < _editMultipleWidget->_objectList->count(); i++) {
      if (_editMultipleWidget->_objectList->item(i)->isSelected()) {
        KstMatrixPtr mxPtr;

        //
        // get the pointer to the object...
        //

        KST::matrixList.lock().readLock();
        mxPtr = *KST::matrixList.findTag(_editMultipleWidget->_objectList->item(i)->text());
        KST::matrixList.lock().unlock();
        
        if (!mxPtr) {
          return false;
        }

        if (!editSingleObject(mxPtr)) {
          return false;
        }

        didEdit = true;
      }
    }

    if (!didEdit) {
      QMessageBox::warning(this, QObject::tr("Kst"), QObject::tr("Select one or more objects to edit."));

      return false;
    }
  } else {
    KstMatrixPtr mp;
    QString tagName;

    mp = kst_cast<KstMatrix>(_dp);
    tagName = _tagName->text();
    if (!mp || (tagName != mp->tagName() && KstData::self()->dataTagNameNotUnique(tagName))) {
      _tagName->setFocus();

      return false;
    }

    mp->writeLock();
    mp->setTag(KstObjectTag(tagName, mp->tag().context())); // FIXME: can't change tag context
    mp->unlock();

    //
    // then edit the object...
    //

    _fileNameDirty = true;
    _fieldDirty = true;
    _xStartDirty = true;
    _xStartCountFromEndDirty = true;
    _yStartDirty = true;
    _yStartCountFromEndDirty = true;
    _xNumStepsDirty = true;
    _xNumStepsReadToEndDirty = true;
    _yNumStepsDirty = true;
    _yNumStepsReadToEndDirty = true;
    _gradientXDirty = true;
    _gradientYDirty = true;
    _gradientZAtMinDirty = true;
    _gradientZAtMaxDirty = true;
    _minXDirty = true;
    _minYDirty = true;
    _xStepDirty = true;
    _yStepDirty = true;
    _doSkipDirty = true;
    _skipDirty = true;
    _doAveDirty = true;
    _nXDirty = true;
    _nYDirty = true;

    if (!editSingleObject(mp)) {
      return false;
    }
  }

  emit modified();

  return true;
}
Exemple #8
0
void KstObjectItem::update(bool recursive, int localUseCount) {
  switch (_rtti) {
    case RTTI_OBJ_DATA_VECTOR:
    {
      KST::vectorList.lock().readLock();
      KstRVectorPtr x = kst_cast<KstRVector>(*KST::vectorList.findTag(_tag));
      KST::vectorList.lock().unlock();
      if (x) {
        x->readLock();
        // getUsage: subtract 1 for KstRVectorPtr x
        bool inUse = (x->getUsage() - 1 - localUseCount) > 0;
        if (inUse != _inUse) {
          _inUse = inUse;
          setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap());
        }
        QString field;
        if (inUse) {
          field = QString::number(x->length());
        } else {
          field = "-";
        }
        if (text(3) != field) {
          setText(3, field);
        }
        field = i18n("%3: %4 [%1..%2]").arg(x->reqStartFrame())
            .arg(x->reqStartFrame() + x->reqNumFrames())
            .arg(x->filename())
            .arg(x->field());
        if (text(4) != field) {
          setText(4, field);
        }
        _removable = x->getUsage() == 2;
        x->unlock();
      }
      // Hmmm what happens if this if() fails??  We become inconsistent?
      break;
    }
    case RTTI_OBJ_STATIC_VECTOR:
    {
      KST::vectorList.lock().readLock();
      KstSVectorPtr x = kst_cast<KstSVector>(*KST::vectorList.findTag(_tag));
      KST::vectorList.lock().unlock();
      if (x) {
        x->readLock();
        // getUsage: subtract 1 for KstRVectorPtr x
        bool inUse = (x->getUsage() - 1 - localUseCount) > 0;
        if (inUse != _inUse) {
          _inUse = inUse;
          setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap());
        }
        QString field;
        if (inUse) {
          field = QString::number(x->length());
        } else {
          field = "-";
        }
        if (text(3) != field) {
          setText(3, field);
        }
        field = i18n("%1 to %2").arg(x->min()).arg(x->max());
        if (text(4) != field) {
          setText(4, field);
        }
        _removable = x->getUsage() == 2;
        x->unlock();
      }
      // Hmmm what happens if this if() fails??  We become inconsistent?
      break;
    }
    case RTTI_OBJ_VECTOR:
    {
      KST::vectorList.lock().readLock();
      KstVectorPtr x = *KST::vectorList.findTag(_tag);
      KST::vectorList.lock().unlock();
      if (x) {
        x->readLock();
        // getUsage:
        //  subtract 1 for KstVectorPtr x
        bool inUse = (x->getUsage() - 1 - localUseCount) > 0;
        if (inUse != _inUse) {
          _inUse = inUse;
          setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap());
        }
        QString field = QString::number(x->length());
        if (text(3) != field) {
          setText(3, field);
        }
        field = i18n("[%1..%2]").arg(x->min()).arg(x->max());
        if (text(4) != field) {
          setText(4, field);
        }
        x->unlock();
        _removable = false;
      }
      break;
    }
    case RTTI_OBJ_OBJECT:
    {
      KST::dataObjectList.lock().readLock();
      KstDataObjectPtr x = *KST::dataObjectList.findTag(_tag.tag());
      KST::dataObjectList.lock().unlock();
      if (x) {
        x->readLock();
        QString field = x->typeString();
        if (text(1) != field) {
          setText(1, field);
        }
        // getUsage:
        //  subtract 1 for KstDataObjectPtr x
        bool inUse = (x->getUsage() - 1 - localUseCount) > 0;
        if (inUse != _inUse) {
          _inUse = inUse;
          setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap());
        }
        if (x->sampleCount() > 0) {
          field = QString::number(x->sampleCount());
          if (text(3) != field) {
            setText(3, field);
          }
        } else {
          if (text(3) != "-") {
            setText(3, "-");
          }          
        }
        field = x->propertyString();
        if (text(4) != field) {
          setText(4, field);
        }
        if (recursive) {
          QPtrStack<QListViewItem> trash;
          KstVectorMap vl = x->outputVectors();
          KstVectorMap::Iterator vlEnd = vl.end();

          for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) {
            KstObjectItem *oi = static_cast<KstObjectItem*>(i);
            if (vl.findTag(oi->tag().tag()) == vlEnd) {
              trash.push(i);
            }
          }
          trash.setAutoDelete(true);
          trash.clear();

          // get the output vectors
          for (KstVectorMap::Iterator p = vl.begin(); p != vlEnd; ++p) {
            bool found = false;
            QString tn = p.data()->tag().tag();
            for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) {
              KstObjectItem *oi = static_cast<KstObjectItem*>(i);
              if (oi->tag().tag() == tn) {
                oi->update();
                found = true;
                break;
              }
            }
            if (!found) {
              KstObjectItem *item = new KstObjectItem(this, p.data(), _dm);
              connect(item, SIGNAL(updated()), this, SIGNAL(updated()));
            }
          }
          
          KstMatrixMap ml = x->outputMatrices();
          KstMatrixMap::Iterator mlEnd = ml.end();
          // also get the output matrices
          for (KstMatrixMap::Iterator p = ml.begin(); p != mlEnd; ++p) {
            bool found = false;
            QString tn = p.data()->tag().tag();
            for (QListViewItem *i = firstChild(); i; i = i->nextSibling()) {
              KstObjectItem *oi = static_cast<KstObjectItem*>(i);
              if (oi->tag().tag() == tn) {
                oi->update();
                found = true;
                break;
              }
            }
            if (!found) {
              KstObjectItem *item = new KstObjectItem(this, p.data(), _dm);
              connect(item, SIGNAL(updated()), this, SIGNAL(updated()));
            }
          }
        }
        _removable = x->getUsage() == 1;
        x->unlock();
      }
      break;
    }
    case RTTI_OBJ_DATA_MATRIX:
    {
      KST::matrixList.lock().readLock();
      KstRMatrixPtr x = kst_cast<KstRMatrix>(*KST::matrixList.findTag(_tag));
      KST::matrixList.lock().unlock();
      if (x) {
        x->readLock();
          // getUsage: subtract 1 for KstRMatrixPtr x
        bool inUse = (x->getUsage() - 1 - localUseCount) > 0;
        if (inUse != _inUse) {
          _inUse = inUse;
          setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap());
        }
        QString field = QString::number(x->sampleCount());
        if (text(3) != field) {
          setText(3, field);
        }
        field = i18n("%1: %2 (%3 by %4)").arg(x->filename()).arg(x->field())
                .arg(x->xNumSteps())
                .arg(x->yNumSteps()); 
        if (text(4) != field) {
          setText(4, field);
        }
        _removable = x->getUsage() == 2;
        x->unlock();
      } 
      break;
    }
    case RTTI_OBJ_STATIC_MATRIX:
    {
      KST::matrixList.lock().readLock();
      KstSMatrixPtr x = kst_cast<KstSMatrix>(*KST::matrixList.findTag(_tag));
      KST::matrixList.lock().unlock();
      if (x) {
        x->readLock();
          // getUsage: subtract 1 for KstRMatrixPtr x
        bool inUse = (x->getUsage() - 1 - localUseCount) > 0;
        if (inUse != _inUse) {
          _inUse = inUse;
          setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap());
        }
        QString field = QString::number(x->sampleCount());
        if (text(3) != field) {
          setText(3, field);
        }
        field = i18n("%1 to %2").arg(x->gradZMin()).arg(x->gradZMax());
        if (text(4) != field) {
          setText(4, field);
        }
        _removable = x->getUsage() == 2;
        x->unlock();
      }
      break;
    }
    case RTTI_OBJ_MATRIX:
    {
      KST::matrixList.lock().readLock();
      KstMatrixPtr x = *KST::matrixList.findTag(_tag);
      KST::matrixList.lock().unlock();
      if (x) {
        x->readLock();
          // getUsage:
          //  subtract 1 for KstVectorPtr x
        bool inUse = (x->getUsage() - 1 - localUseCount) > 0;
        if (inUse != _inUse) {
          _inUse = inUse;
          setPixmap(2, inUse ? _dm->yesPixmap() : QPixmap());
        }
        QString field = QString::number(x->sampleCount());
        if (text(3) != field) {
          setText(3, field);
        }
        field = i18n("[%1..%2]").arg(x->minValue()).arg(x->maxValue());
        if (text(4) != field) {
          setText(4, field);
        }
        x->unlock();
        _removable = false;
      }
      break;
    }
    default:
      assert(0);
  }
}
Exemple #9
0
void MatrixSelector::setSelection( KstMatrixPtr v ) {
  v->readLock();
  setSelection(v->tagName());
  v->unlock();
}
Exemple #10
0
bool KstImageDialogI::newObject() {
  //if matrixCombo is empty then display an error message
  if (_w->_matrix->selectedMatrix().isEmpty()){
    KMessageBox::sorry(this, i18n("Matrix is a 2D grid of numbers, used to create image", "New image not made: define matrix first."));
    return false;
  }

  //do some checks on the inputs
  double lowerZDouble, upperZDouble;
  if (!checkParameters(lowerZDouble, upperZDouble)) {
    return false;
  }

  KST::matrixList.lock().readLock();
  KstMatrixPtr matrix = *KST::matrixList.findTag(_w->_matrix->selectedMatrix());
  KST::matrixList.lock().unlock();
  if (!matrix) {
    KMessageBox::sorry(this, i18n("Matrix is a 2D grid of numbers, used to create image", "Could not find matrix."));
    return false;
  }
  KST::dataObjectList.lock().readLock();
  matrix->readLock();

  //create a unique name
  QString tag_name = KST::suggestImageName(matrix->tag());
  if (KstData::self()->dataTagNameNotUnique(tag_name)) {
    _tagName->setFocus();
    matrix->unlock();
    KST::dataObjectList.lock().unlock();
    return false;
  }

  KstImagePtr image;
  if (_w->_contourOnly->isChecked()) {
    //need a contour map only
    QColor tempColor = _w->_contourColor->color();
    image = new KstImage(tag_name, matrix, _w->_numContourLines->text().toInt(), tempColor,
                         _w->_useVariableWeight->isChecked() ? -1 : _w->_contourWeight->value());
  } else if (_w->_colorOnly->isChecked()) {
    //need a color map only
    KPalette* newPal = new KPalette(_w->_colorPalette->selectedPalette());
    image = new KstImage(tag_name, matrix, lowerZDouble, upperZDouble,
                         _w->_realTimeAutoThreshold->isChecked(), newPal);
  } else {
    //need both a contour map and colour map
    QColor tempColor = _w->_contourColor->color();
    KPalette* newPal = new KPalette(_w->_colorPalette->selectedPalette());
    image = new KstImage(tag_name, matrix, lowerZDouble, upperZDouble,
                         _w->_realTimeAutoThreshold->isChecked(), newPal,
                         _w->_numContourLines->text().toInt(), tempColor,
                         _w->_useVariableWeight->isChecked() ? -1 : _w->_contourWeight->value());
  }
  matrix->unlock();
  KST::dataObjectList.lock().unlock();
  placeInPlot(image);
  KST::dataObjectList.lock().writeLock();
  KST::dataObjectList.append(image.data());
  KST::dataObjectList.lock().unlock();
  image = 0L; // drop the reference
  emit modified();
  return true;
}
Exemple #11
0
QString KstIfaceImpl::createImage(const QString &name,
                                  const QString &in_matrix,
                                  double lowerZ,
                                  double upperZ,
                                  const QString &paletteName,
                                  int numContours,
                                  const QColor& contourColor,
                                  uint imageType) {
  //get the matrix
  KstMatrixList matrices = kstObjectSubList<KstDataObject, KstMatrix>(KST::dataObjectList);
  KstMatrixPtr matrix = *matrices.findTag(in_matrix);
  if (!matrix) {
    return QString::null;
  }

  //make a name if necessary
  QString imgtag;
  if (name.isEmpty()) {
    imgtag = KST::suggestImageName(in_matrix);
  } else {
    QString imgtag_end = QString(name);
    //count number of data objects and make a unique name
    int i = KST::dataObjectList.count() + 1;
    imgtag = QString::number(i) + "-" + imgtag_end;
  }
  while (KstData::self()->dataTagNameNotUnique(imgtag, false)) {
    imgtag += "\'";
  }

  //determine the image type
  KstImagePtr image;
  if (imageType == 0) {
    //need a colormap
    if (lowerZ > upperZ) {
      return QString::null;
    }
    KPalette* pal = new KPalette(paletteName);
    matrix->readLock();
    image = new KstImage(imgtag, matrix, lowerZ, upperZ, false, pal);
    matrix->unlock();
  } else if (imageType == 1) {
    //need a contourmap
    if (numContours < 1) {
      return QString::null;
    }
    matrix->readLock();
    image = new KstImage(imgtag, matrix, numContours, contourColor.isValid() ? contourColor : QColor("darkBlue"), 0);
    matrix->unlock();
  } else if (imageType == 2) {
    //need both contourmap and colormap
    if (lowerZ > upperZ) {
      return QString::null;
    }
    if (numContours < 1) {
      return QString::null;
    }
    KPalette* pal = new KPalette(paletteName);
    matrix->readLock();
    image = new KstImage(imgtag, matrix, lowerZ, upperZ, false, pal,
                         numContours, contourColor.isValid() ? contourColor : QColor("darkBlue"), 0);
    matrix->unlock();
  } else {
    return QString::null;
  }

  KST::dataObjectList.lock().writeLock();
  KST::dataObjectList.append(KstDataObjectPtr(image));
  KST::dataObjectList.lock().unlock();

  _doc->forceUpdate();
  _doc->setModified();

  return imgtag;

}
Exemple #12
0
bool KstMatrixDialogI::editObject() {
  // if editing multiple objects, edit each one
  if (_editMultipleMode) {
    _fileNameDirty = !_w->_fileName->url().isEmpty();
    _gradientZAtMinDirty = !_w->_gradientZAtMin->text().isEmpty();
    _gradientZAtMaxDirty = !_w->_gradientZAtMax->text().isEmpty();
    _minXDirty = !_w->_minX->text().isEmpty();
    _minYDirty = !_w->_minY->text().isEmpty();
    _yStepDirty = !_w->_yStep->text().isEmpty();
    _xStepDirty = !_w->_xStep->text().isEmpty();

    _xStartDirty = _w->_xStart->text() != " ";
    _yStartDirty = _w->_yStart->text() != " ";
    _xNumStepsDirty = _w->_xNumSteps->text() != " ";
    _yNumStepsDirty = _w->_yNumSteps->text() != " ";

    _skipDirty = _w->_skip->text() != " ";
    _nXDirty = _w->_nX->text() != " ";
    _nYDirty = _w->_nY->text() != " ";

    bool didEdit = false;
    for (uint i = 0; i < _editMultipleWidget->_objectList->count(); i++) {
      if (_editMultipleWidget->_objectList->isSelected(i)) {
        // get the pointer to the object
        KST::matrixList.lock().readLock();
        KstMatrixPtr mxPtr = *KST::matrixList.findTag(_editMultipleWidget->_objectList->text(i));
        KST::matrixList.lock().unlock();
        if (!mxPtr) {
          return false;
        }

        if (!editSingleObject(mxPtr)) {
          return false;
        }
        didEdit = true;
      }
    }
    if (!didEdit) {
      KMessageBox::sorry(this, i18n("Select one or more objects to edit."));
      return false;
    }
  } else {
    KstMatrixPtr mp = kst_cast<KstMatrix>(_dp);
    // verify that the curve name is unique
    QString tag_name = _tagName->text();
    if (!mp || (tag_name != mp->tagName() && KstData::self()->dataTagNameNotUnique(tag_name))) {
      _tagName->setFocus();
      return false;
    }

    mp->writeLock();
    mp->setTagName(tag_name);
    mp->unlock();

    // then edit the object
    _fileNameDirty = true;
    _fieldDirty = true;
    _xStartDirty = true;
    _xStartCountFromEndDirty = true;
    _yStartDirty = true;
    _yStartCountFromEndDirty = true;
    _xNumStepsDirty = true;
    _xNumStepsReadToEndDirty = true;
    _yNumStepsDirty = true;
    _yNumStepsReadToEndDirty = true;
    _gradientXDirty = true;
    _gradientYDirty = true;
    _gradientZAtMinDirty = true;
    _gradientZAtMaxDirty = true;
    _minXDirty = true;
    _minYDirty = true;
    _xStepDirty = true;
    _yStepDirty = true;
    _doSkipDirty = true;
    _skipDirty = true;
    _doAveDirty = true;
    _nXDirty = true;
    _nYDirty = true;
    if (!editSingleObject(mp)) {
      return false;
    }
  }
  emit modified();
  return true;
}