QWidget* SpectralLibraryMatchResults::createWidget()
{
   mpTabWidget = new QTabWidget(getDockWindow()->getWidget());
   mpTabWidget->setTabPosition(QTabWidget::South);
   mpTabWidget->setTabShape(QTabWidget::Rounded);
   mpTabWidget->setMinimumHeight(100);

   // dockwindow should exist so attach to it
   DockWindow* pWindow = getDockWindow();
   if (pWindow != NULL)
   {

      pWindow->attach(SIGNAL_NAME(DockWindow, AboutToShowContextMenu),
         Slot(this, &SpectralLibraryMatchResults::updateContextMenu));

      // Connect to the session explorer now that the window has been created
      if (mpExplorer.get() == NULL)
      {
         Service<SessionExplorer> pExplorer;
         mpExplorer.reset(pExplorer.get());
      }

      // set location of the results window
#pragma message(__FILE__ "(" STRING(__LINE__) ") : warning : Replace this block when public method to locate DockWindow is available. (rforehan)")
      QMainWindow* pMainWindow = dynamic_cast<QMainWindow*>(Service<DesktopServices>()->getMainWidget());
      if (pMainWindow != NULL)
      {
         pMainWindow->addDockWidget(Qt::LeftDockWidgetArea, dynamic_cast<QDockWidget*>(pWindow), Qt::Vertical);
      }     
   }

   return mpTabWidget;
}
SpectralLibraryMatchResults::~SpectralLibraryMatchResults()
{
   Service<DesktopServices> pDesktop;

   // remove toolbar button and menu item
   QAction* pAction = getAction();
   if (pAction != NULL)
   {
      ToolBar* pToolBar = static_cast<ToolBar*>(pDesktop->getWindow("Spectral", TOOLBAR));
      if (pToolBar != NULL)
      {
         pToolBar->removeItem(pAction);
         MenuBar* pMenuBar = pToolBar->getMenuBar();
         if (pMenuBar != NULL)
         {
            pMenuBar->removeMenuItem(pAction);
         }
      }
   }

   // dockwindow should still exist so detach from it
   DockWindow* pWindow = getDockWindow();
   if (pWindow != NULL)
   {
      pWindow->detach(SIGNAL_NAME(DockWindow, AboutToShowContextMenu),
         Slot(this, &SpectralLibraryMatchResults::updateContextMenu));
   }
}
QWidget* RangeProfilePlotManager::createWidget()
{
   DockWindow* pWindow = getDockWindow();
   VERIFYRV(pWindow, NULL);
   pWindow->attach(SIGNAL_NAME(Window, SessionItemDropped), Slot(this, &RangeProfilePlotManager::dropSessionItem));
   pWindow->enableSessionItemDrops(this);
   if (!Service<SessionManager>()->isSessionLoading())
   {
      mpPlot = Service<DesktopServices>()->createPlotWidget(getName(), CARTESIAN_PLOT);
   }
   if (mpPlot == NULL)
   {
      return NULL;
   }
   mpView = mpPlot->getPlot();
#pragma message(__FILE__ "(" STRING(__LINE__) ") : warning : If a SHALLOW_SELECTION selection mode is added " \
                                              "to plot view (OPTICKS-528), mpView should use it (tclarke)")
   mpMode = (mpView == NULL) ? NULL : mpView->getMouseMode("SelectionMode");
   if (mpMode == NULL)
   {
      return NULL;
   }
   mpView->getWidget()->installEventFilter(this);
   mpPlot->attach(SIGNAL_NAME(PlotWidget, AboutToShowContextMenu),
      Slot(this, &RangeProfilePlotManager::updateContextMenu));
   mpView->enableMouseMode(mpMode, true);
   mpView->setMouseMode(mpMode);

   return mpPlot->getWidget();
}
bool ConvolutionMatrixEditor::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
{
   if (!DockWindowShell::execute(pInArgList, pOutArgList))
   {
      return false;
   }
   DockWindow* pWindow = getDockWindow();
   if (pWindow != NULL)
   {
      Service<DesktopServices>()->setDockWindowArea(pWindow, DOCK_LEFT);
   }
   return true;
}
Пример #5
0
bool AnnotationImagePalette::execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList)
{
   if (!DockWindowShell::execute(pInArgList, pOutArgList))
   {
      return false;
   }
   DockWindow* pWindow = getDockWindow();
   if (pWindow != NULL)
   {
      Service<DesktopServices>()->setDockWindowArea(pWindow, DOCK_LEFT);
   }
   return true;
}
RangeProfilePlotManager::~RangeProfilePlotManager()
{
   Window* pWindow = getDockWindow();
   if (pWindow != NULL)
   {
      pWindow->detach(SIGNAL_NAME(Window, SessionItemDropped), Slot(this, &RangeProfilePlotManager::dropSessionItem));
   }
   for (std::map<Signature*, std::string>::iterator sig = mSigPointSets.begin(); sig != mSigPointSets.end(); ++sig)
   {
      sig->first->detach(SIGNAL_NAME(Subject, Deleted), Slot(this, &RangeProfilePlotManager::signatureDeleted));
      sig->first->getDataDescriptor()->detach(SIGNAL_NAME(DataDescriptor, Renamed),
         Slot(this, &RangeProfilePlotManager::signatureRenamed));
   }
   QAction* pWindowAction = getAction();
   if (pWindowAction != NULL)
   {
      MenuBar* pMenuBar = Service<DesktopServices>()->getMainMenuBar();
      if (pMenuBar != NULL)
      {
         pMenuBar->removeMenuItem(pWindowAction);
      }
   }
}
void SpectralLibraryMatchResults::updateContextMenu(Subject& subject, const std::string& signal,
                                                    const boost::any& value)
{
   ContextMenu* pMenu = boost::any_cast<ContextMenu*>(value);
   if (pMenu == NULL)
   {
      return;
   }

   // only add actions if there are some results
   if (mpTabWidget->count() > 0)
   {
      bool isSessionItem(false);
      if (dynamic_cast<SessionExplorer*>(&subject) != NULL)
      {
         std::vector<SessionItem*> items = pMenu->getSessionItems();
         if (items.size() > 1)                                        // make sure only one item selected
         {
            return;
         }
         DockWindow* pWindow = getDockWindow();
         if (items.front() != pWindow)                             // make sure it's the results window
         {
            return;
         }
         isSessionItem = true;
      }

      QObject* pParent = pMenu->getActionParent();

      // add separator
      QAction* pSeparatorAction = new QAction(pParent);
      pSeparatorAction->setSeparator(true);
      pMenu->addAction(pSeparatorAction, SPECTRAL_LIBRARY_MATCH_RESULTS_SEPARATOR_ACTION);

      QAction* pClearAction = new QAction("&Clear", pParent);
      pClearAction->setAutoRepeat(false);
      pClearAction->setStatusTip("Clears the results from the current page");
      VERIFYNR(connect(pClearAction, SIGNAL(triggered()), this, SLOT(clearPage())));
      pMenu->addAction(pClearAction, SPECTRAL_LIBRARY_MATCH_RESULTS_CLEAR_RESULTS_ACTION);

      QAction* pAutoClearAction = new QAction("&AutoClear", pParent);
      pAutoClearAction->setAutoRepeat(false);
      pAutoClearAction->setCheckable(true);
      pAutoClearAction->setStatusTip("Enable/disable clearing existing results before adding new results");
      ResultsPage* pPage = dynamic_cast<ResultsPage*>(mpTabWidget->currentWidget());
      if (pPage != NULL)
      {
         pAutoClearAction->setChecked(pPage->getAutoClear());
         VERIFYNR(connect(pAutoClearAction, SIGNAL(toggled(bool)), pPage, SLOT(setAutoClear(bool))));
         pMenu->addAction(pAutoClearAction, SPECTRAL_LIBRARY_MATCH_RESULTS_AUTOCLEAR_ACTION);
      }

      QAction* pExpandAllAction = new QAction("&Expand All", pParent);
      pExpandAllAction->setAutoRepeat(false);
      pExpandAllAction->setStatusTip("Expands all the results nodes on the current page");
      VERIFYNR(connect(pExpandAllAction, SIGNAL(triggered()), this, SLOT(expandAllPage())));
      pMenu->addAction(pExpandAllAction, SPECTRAL_LIBRARY_MATCH_RESULTS_EXPAND_ALL_ACTION);

      QAction* pCollapseAllAction = new QAction("&Collapse All", pParent);
      pCollapseAllAction->setAutoRepeat(false);
      pCollapseAllAction->setStatusTip("Collapses all the results nodes on the current page");
      VERIFYNR(connect(pCollapseAllAction, SIGNAL(triggered()), this, SLOT(collapseAllPage())));
      pMenu->addAction(pCollapseAllAction, SPECTRAL_LIBRARY_MATCH_RESULTS_COLLAPSE_ALL_ACTION);

      QAction* pDeleteTabAction = new QAction("&Delete Page", pParent);
      pDeleteTabAction->setAutoRepeat(false);
      pDeleteTabAction->setStatusTip("Deletes the current page");
      VERIFYNR(connect(pDeleteTabAction, SIGNAL(triggered()), this, SLOT(deletePage())));
      pMenu->addAction(pDeleteTabAction, SPECTRAL_LIBRARY_MATCH_RESULTS_DELETE_PAGE_ACTION);

      if (isSessionItem == false)
      {
         QAction* pLocateAction = new QAction("&Locate Signatures", pParent);
         pLocateAction->setAutoRepeat(false);
         pLocateAction->setStatusTip("Locates the selected Signatures in the spatial data view");
         VERIFYNR(connect(pLocateAction, SIGNAL(triggered()), this, SLOT(locateSignaturesInScene())));
         pMenu->addAction(pLocateAction, SPECTRAL_LIBRARY_MATCH_RESULTS_LOCATE_ACTION);
         QAction* pCreateAverageAction = new QAction("&Create average Signature", pParent);
         pCreateAverageAction->setAutoRepeat(false);
         pCreateAverageAction->setStatusTip("Creates an average Signature from the selected "
            "Signatures in the spatial data view");
         VERIFYNR(connect(pCreateAverageAction, SIGNAL(triggered()), this, SLOT(createAverageSignature())));
         pMenu->addAction(pCreateAverageAction, SPECTRAL_LIBRARY_MATCH_RESULTS_CREATE_AVERAGE_ACTION);
      }
   }
}
bool RangeProfilePlotManager::plotProfile(Signature* pSignature)
{
   VERIFY(mpView && pSignature);
   std::string plotName = pSignature->getDisplayName();
   if (plotName.empty())
   {
      plotName = pSignature->getName();
   }
   if (plotName == "Difference")
   {
      QMessageBox::warning(Service<DesktopServices>()->getMainWidget(),
         "Invalid signature", "Signatures can not be named 'Difference' as this is a reserved "
                              "name for this plot. Please rename your signature and try again.");
      return false;
   }
   const Units* pXUnits = NULL;
   const Units* pYUnits = NULL;
   std::vector<double> xData;
   std::vector<double> yData;
   std::set<std::string> dataNames = pSignature->getDataNames();
   for (std::set<std::string>::const_iterator dataName = dataNames.begin();
      dataName != dataNames.end() && (pXUnits == NULL || pYUnits == NULL);
      ++dataName)
   {
      const Units* pUnits = pSignature->getUnits(*dataName);
      if (pUnits == NULL)
      {
         continue;
      }
      if (pUnits->getUnitType() == DISTANCE)
      {
         if (pXUnits == NULL)
         {
            pXUnits = pUnits;
            xData = dv_cast<std::vector<double> >(pSignature->getData(*dataName), std::vector<double>());
         }
      }
      else if (pYUnits == NULL)
      {
         pYUnits = pUnits;
         yData = dv_cast<std::vector<double> >(pSignature->getData(*dataName), std::vector<double>());
      }
   }
   if (xData.empty() || xData.size() != yData.size())
   {
      QMessageBox::warning(Service<DesktopServices>()->getMainWidget(),
         "Invalid signature", QString("Signatures must have a distance axis. '%1' does not and will not be plotted.")
                                 .arg(QString::fromStdString(pSignature->getName())));
      return false;
   }
   std::map<Signature*, std::string>::iterator oldPointSet = mSigPointSets.find(pSignature);
   PointSet* pSet = getPointSet(pSignature);
   if (pSet != NULL)
   {
      pSet->clear(true);
   }
   std::list<PlotObject*> curObjects;
   mpView->getObjects(POINT_SET, curObjects);
   if (pSet == NULL)
   {
      std::vector<ColorType> excluded;
      excluded.push_back(ColorType(255, 255, 255)); // background
      excluded.push_back(ColorType(200, 0, 0)); // color for the difference plot
      for (std::list<PlotObject*>::const_iterator cur = curObjects.begin(); cur != curObjects.end(); ++cur)
      {
         excluded.push_back(static_cast<PointSet*>(*cur)->getLineColor());
      }
      pSet = static_cast<PointSet*>(mpView->addObject(POINT_SET, true));
      mSigPointSets[pSignature] = plotName;
      pSignature->attach(SIGNAL_NAME(Subject, Deleted), Slot(this, &RangeProfilePlotManager::signatureDeleted));
      pSignature->getDataDescriptor()->attach(SIGNAL_NAME(DataDescriptor, Renamed),
         Slot(this, &RangeProfilePlotManager::signatureRenamed));
      std::vector<ColorType> colors;
      ColorType::getUniqueColors(1, colors, excluded);
      if (!colors.empty())
      {
         pSet->setLineColor(colors.front());
      }
   }
   pSet->setObjectName(plotName);
   for (size_t idx = 0; idx < xData.size(); ++idx)
   {
      pSet->addPoint(xData[idx], yData[idx]);
   }

   VERIFY(mpPlot);
   Axis* pBottom = mpPlot->getAxis(AXIS_BOTTOM);
   Axis* pLeft = mpPlot->getAxis(AXIS_LEFT);
   VERIFYRV(pBottom && pLeft, NULL);
   if (pBottom->getTitle().empty())
   {
      pBottom->setTitle(pXUnits->getUnitName());
   }
   if (pLeft->getTitle().empty())
   {
      pLeft->setTitle(pYUnits->getUnitName());
   }
   else if (pLeft->getTitle() != pYUnits->getUnitName())
   {
      Axis* pRight = mpPlot->getAxis(AXIS_RIGHT);
      VERIFYRV(pRight, NULL);
      if (pRight->getTitle().empty())
      {
         pRight->setTitle(pYUnits->getUnitName());
      }
   }

   std::string classificationText = dv_cast<std::string>(pSignature->getMetadata()->getAttribute("Raw Classification"),
      mpPlot->getClassificationText());
   if (classificationText.empty() == false)
   {
      FactoryResource<Classification> pClassification;
      if (pClassification->setClassification(classificationText) == true)
      {
         mpPlot->setClassification(pClassification.get());
      }
      else
      {
         QMessageBox::warning(Service<DesktopServices>()->getMainWidget(), QString::fromStdString(getName()),
            "The plot could not be updated with the signature classification.  Please ensure that the plot "
            "has the proper classification.");
      }
   }

   getDockWindow()->show();
   mpView->zoomExtents();
   mpView->refresh();

   return true;
}