void InstrumentWidget::setSurfaceType(int type) {
  // we cannot do 3D without OpenGL
  if (type == FULL3D && !isGLEnabled()) {
    QMessageBox::warning(
        this, "Mantid - Warning",
        "OpenGL must be enabled to render the instrument in 3D.");
    return;
  }

  if (type < RENDERMODE_SIZE) {
    QApplication::setOverrideCursor(Qt::WaitCursor);
    SurfaceType surfaceType = SurfaceType(type);
    if (!m_instrumentActor)
      return;

    ProjectionSurface *surface = getSurface().get();
    int peakLabelPrecision = 6;
    bool showPeakRow = true;
    bool showPeakLabels = true;
    bool showPeakRelativeIntensity = true;
    if (surface) {
      peakLabelPrecision = surface->getPeakLabelPrecision();
      showPeakRow = surface->getShowPeakRowsFlag();
      showPeakLabels = surface->getShowPeakLabelsFlag();
    } else {
      QSettings settings;
      settings.beginGroup(InstrumentWidgetSettingsGroup);
      peakLabelPrecision = settings.value("PeakLabelPrecision", 2).toInt();
      showPeakRow = settings.value("ShowPeakRows", true).toBool();
      showPeakLabels = settings.value("ShowPeakLabels", true).toBool();

      // By default this is should be off for now.
      showPeakRelativeIntensity =
          settings.value("ShowPeakRelativeIntensities", false).toBool();
      settings.endGroup();
    }

    // Surface factory
    // If anything throws during surface creation, store error message here
    QString errorMessage;
    try {
      const auto &componentInfo = m_instrumentActor->componentInfo();
      if (!componentInfo.hasSample()) {
        throw InstrumentHasNoSampleError();
      }
      auto sample_pos = componentInfo.samplePosition();
      auto axis = getSurfaceAxis(surfaceType);

      m_maskTab->setDisabled(false);

      // create the surface
      if (surfaceType == FULL3D) {
        m_renderTab->forceLayers(false);

        if (m_instrumentActor->hasGridBank())
          m_maskTab->setDisabled(true);

        surface = new Projection3D(m_instrumentActor.get(),
                                   getInstrumentDisplayWidth(),
                                   getInstrumentDisplayHeight());
      } else if (surfaceType <= CYLINDRICAL_Z) {
        m_renderTab->forceLayers(true);
        surface =
            new UnwrappedCylinder(m_instrumentActor.get(), sample_pos, axis);
      } else if (surfaceType <= SPHERICAL_Z) {
        m_renderTab->forceLayers(true);
        surface =
            new UnwrappedSphere(m_instrumentActor.get(), sample_pos, axis);
      } else // SIDE_BY_SIDE
      {
        m_renderTab->forceLayers(true);
        surface = new PanelsSurface(m_instrumentActor.get(), sample_pos, axis);
      }
    } catch (InstrumentHasNoSampleError &) {
      QApplication::restoreOverrideCursor();
      throw;
    } catch (std::exception &e) {
      errorMessage = e.what();
    } catch (...) {
      errorMessage = "Unknown exception thrown.";
    }
    if (!errorMessage.isNull()) {
      // if exception was thrown roll back to the current surface type.
      QApplication::restoreOverrideCursor();
      QMessageBox::critical(
          this, "MantidPlot - Error",
          "Surface cannot be created because of an exception:\n\n  " +
              errorMessage + "\n\nPlease select a different surface type.");
      // if suface change was initialized by the GUI this should ensure its
      // consistency
      emit surfaceTypeChanged(m_surfaceType);
      return;
    }
    // end Surface factory

    m_surfaceType = surfaceType;
    surface->setPeakLabelPrecision(peakLabelPrecision);
    surface->setShowPeakRowsFlag(showPeakRow);
    surface->setShowPeakLabelsFlag(showPeakLabels);
    surface->setShowPeakRelativeIntensityFlag(showPeakRelativeIntensity);
    // set new surface
    setSurface(surface);

    // init tabs with new surface
    foreach (InstrumentWidgetTab *tab, m_tabs) { tab->initSurface(); }

    connect(surface, SIGNAL(executeAlgorithm(Mantid::API::IAlgorithm_sptr)),
            this, SLOT(executeAlgorithm(Mantid::API::IAlgorithm_sptr)));
    connect(surface, SIGNAL(updateInfoText()), this, SLOT(updateInfoText()),
            Qt::QueuedConnection);
    QApplication::restoreOverrideCursor();
  }
Example #2
0
void InstrumentWindow::setSurfaceType(int type) {
    // we cannot do 3D without OpenGL
    if (type == FULL3D && !isGLEnabled()) {
        QMessageBox::warning(
            this, "Mantid - Warning",
            "OpenGL must be enabled to render the instrument in 3D.");
        return;
    }

    if (type < RENDERMODE_SIZE) {
        QApplication::setOverrideCursor(Qt::WaitCursor);
        SurfaceType surfaceType = SurfaceType(type);
        if (!m_instrumentActor)
            return;

        ProjectionSurface *surface = getSurface().get();
        int peakLabelPrecision = 6;
        bool showPeakRow = true;
        bool showPeakLabels = true;
        if (surface) {
            peakLabelPrecision = surface->getPeakLabelPrecision();
            showPeakRow = surface->getShowPeakRowsFlag();
            showPeakLabels = surface->getShowPeakLabelsFlag();
        } else {
            QSettings settings;
            peakLabelPrecision =
                settings.value("Mantid/InstrumentWindow/PeakLabelPrecision", 2)
                .toInt();
            showPeakRow =
                settings.value("Mantid/InstrumentWindow/ShowPeakRows", true).toBool();
            showPeakLabels =
                settings.value("Mantid/InstrumentWindow/ShowPeakLabels", true)
                .toBool();
        }

        // Surface factory
        // If anything throws during surface creation, store error message here
        QString errorMessage;
        try {
            Mantid::Geometry::Instrument_const_sptr instr =
                m_instrumentActor->getInstrument();
            Mantid::Geometry::IComponent_const_sptr sample = instr->getSample();
            if (!sample) {
                throw InstrumentHasNoSampleError();
            }
            Mantid::Kernel::V3D sample_pos = sample->getPos();
            Mantid::Kernel::V3D axis;
            // define the axis
            if (surfaceType == SPHERICAL_Y || surfaceType == CYLINDRICAL_Y) {
                axis = Mantid::Kernel::V3D(0, 1, 0);
            } else if (surfaceType == SPHERICAL_Z || surfaceType == CYLINDRICAL_Z) {
                axis = Mantid::Kernel::V3D(0, 0, 1);
            } else if (surfaceType == SPHERICAL_X || surfaceType == CYLINDRICAL_X) {
                axis = Mantid::Kernel::V3D(1, 0, 0);
            } else // SIDE_BY_SIDE
            {
                axis = Mantid::Kernel::V3D(0, 0, 1);
            }

            // create the surface
            if (surfaceType == FULL3D) {
                surface =
                    new Projection3D(m_instrumentActor, getInstrumentDisplayWidth(),
                                     getInstrumentDisplayHeight());
            } else if (surfaceType <= CYLINDRICAL_Z) {
                surface = new UnwrappedCylinder(m_instrumentActor, sample_pos, axis);
            } else if (surfaceType <= SPHERICAL_Z) {
                surface = new UnwrappedSphere(m_instrumentActor, sample_pos, axis);
            } else // SIDE_BY_SIDE
            {
                surface = new PanelsSurface(m_instrumentActor, sample_pos, axis);
            }
        } catch (InstrumentHasNoSampleError &) {
            QApplication::restoreOverrideCursor();
            throw;
        } catch (std::exception &e) {
            errorMessage = e.what();
        } catch (...) {
            errorMessage = "Unknown exception thrown.";
        }
        if (!errorMessage.isNull()) {
            // if exception was thrown roll back to the current surface type.
            QApplication::restoreOverrideCursor();
            QMessageBox::critical(
                this, "MantidPlot - Error",
                "Surface cannot be created because of an exception:\n\n  " +
                errorMessage + "\n\nPlease select a different surface type.");
            // if suface change was initialized by the GUI this should ensure its
            // consistency
            emit surfaceTypeChanged(m_surfaceType);
            return;
        }
        // end Surface factory

        m_surfaceType = surfaceType;
        surface->setPeakLabelPrecision(peakLabelPrecision);
        surface->setShowPeakRowsFlag(showPeakRow);
        surface->setShowPeakLabelsFlag(showPeakLabels);
        // set new surface
        setSurface(surface);

        // init tabs with new surface
        foreach (InstrumentWindowTab *tab, m_tabs) {
            tab->initSurface();
        }

        // connect(surface,SIGNAL(multipleDetectorsSelected(QList<int>&)),this,SLOT(multipleDetectorsSelected(QList<int>&)));
        connect(surface, SIGNAL(executeAlgorithm(Mantid::API::IAlgorithm_sptr)),
                this, SIGNAL(execMantidAlgorithm(Mantid::API::IAlgorithm_sptr)));
        connect(surface, SIGNAL(updateInfoText()), this, SLOT(updateInfoText()),
                Qt::QueuedConnection);
        QApplication::restoreOverrideCursor();
    }