Exemple #1
0
KJS::Value KstBindImage::matrix(KJS::ExecState *exec) const {
  KstImagePtr d = makeImage(_d);
  if (d) {
    KstReadLocker rl(d);
    KstMatrixPtr mp = d->matrix();
    if (mp) {
      return KJS::Object(new KstBindMatrix(exec, mp));
    }
  }
  return KJS::Null();
}
Exemple #2
0
bool KstImageDialogI::editSingleObject(KstImagePtr imPtr) {
  KstMatrixPtr pMatrix;
  if (_matrixDirty) {
    //find the pMatrix
    KST::matrixList.lock().readLock();
    pMatrix = *KST::matrixList.findTag(_w->_matrix->selectedMatrix());
    KST::matrixList.lock().unlock();

    if (!pMatrix) {
      KMessageBox::sorry(this, i18n("Matrix is a 2D grid of numbers, used to create image", "Could not find pMatrix."));
      return false;
    }
  } else {
    imPtr->readLock();
    pMatrix = imPtr->matrix();
    imPtr->unlock();
  }

  imPtr->writeLock();

  // if image type was changed, get all parameters from the dialog
  if (_contourOnlyDirty || _colorOnlyDirty || _colorAndContourDirty) {
    double lowerZDouble, upperZDouble;
    if (!checkParameters(lowerZDouble, upperZDouble)) {
      //KMessageBox::sorry(this, i18n("Image type was changed: Lower Z threshold cannot be higher than Upper Z threshold."));
      //pMatrix->unlock();
      imPtr->unlock();
      return false;
    }
    if (_w->_contourOnly->isChecked()) {
      //need a contour map only
      QColor tempColor = _w->_contourColor->color();
      imPtr->changeToContourOnly(imPtr->tagName(), pMatrix, _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());
      imPtr->changeToColorOnly(imPtr->tagName(), pMatrix, 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());
      imPtr->changeToColorAndContour(imPtr->tagName(), pMatrix, lowerZDouble, upperZDouble,
                                  _w->_realTimeAutoThreshold->isChecked(), newPal,
                                  _w->_numContourLines->text().toInt(), tempColor,
                                  _w->_useVariableWeight->isChecked() ? -1 : _w->_contourWeight->value());
    }
  } else {
    // get the current or new parameters as required
    QColor pContourColor;
    double pLowerZ, pUpperZ;
    int pNumContours, pContourWeight;
    bool pRealTimeAutoThreshold, pUseVariableWeight;

    if (_lowerZDirty) {
      pLowerZ = _w->_lowerZ->text().toDouble();
    } else {
      pLowerZ = imPtr->lowerThreshold();
    }

    if (_upperZDirty) {
      pUpperZ = _w->_upperZ->text().toDouble();
    } else {
      pUpperZ = imPtr->upperThreshold();
    }

    if (_realTimeAutoThresholdDirty) {
      pRealTimeAutoThreshold = _w->_realTimeAutoThreshold->isChecked();
    } else {
      pRealTimeAutoThreshold = imPtr->autoThreshold();
    }

    if (_numContourLinesDirty) {
      pNumContours = _w->_numContourLines->text().toInt();
    } else {
      pNumContours = imPtr->numContourLines();
    }

    if (_contourWeightDirty) {
      pContourWeight = _w->_contourWeight->value();
    } else {
      pContourWeight = imPtr->contourWeight();
    }

    if (_useVariableWeightDirty) {
      pUseVariableWeight = _w->_useVariableWeight->isChecked();
    } else {
      pUseVariableWeight = imPtr->contourWeight() == -1;
    }

    if (_contourColorDirty) {
      pContourColor = _w->_contourColor->color();
    } else {
      pContourColor = imPtr->contourColor();
    }

    // check parameters for color map
    if (imPtr->hasColorMap()) {
      if (pLowerZ > pUpperZ) {
        //KMessageBox::sorry(this, i18n("The Lower Z threshold cannot be higher than Upper Z threshold."));
        //pMatrix->unlock();
        imPtr->unlock();
        return false;
      }
    }

    // don't change the image type, just change applicable settings for the
    // current image type
    if (imPtr->hasContourMap() && !imPtr->hasColorMap()) {
      imPtr->changeToContourOnly(imPtr->tagName(), pMatrix, pNumContours, pContourColor,
          pUseVariableWeight ? -1 : pContourWeight);
    } else {
      KPalette *palette;
      if (_paletteDirty) {
        palette = new KPalette(_w->_colorPalette->selectedPalette());
      } else {
        palette = imPtr->palette();
      }

      if (imPtr->hasColorMap() && !imPtr->hasContourMap()) {
        imPtr->changeToColorOnly(imPtr->tagName(), pMatrix, pLowerZ, pUpperZ,
            pRealTimeAutoThreshold, palette);
      } else {
        // images always have at least one of color or contour maps
        imPtr->changeToColorAndContour(imPtr->tagName(), pMatrix, pLowerZ, pUpperZ,
            pRealTimeAutoThreshold, palette,
            pNumContours, pContourColor,
            pUseVariableWeight ? -1 : pContourWeight);
      }
    }
  }


  imPtr->unlock();

  return true;
}