<commit_before>/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __otbPixelDescriptionActionHandler_h
#define __otbPixelDescriptionActionHandler_h

#include "otbImageWidgetActionHandler.h"

namespace otb
{
/** \class PixelDescriptionActionHandler
*   \brief Implements pixel reporting capabilities.
* 
*   \sa ImageWidgetController
*   \sa ImageWidgetActionHandler
*/

template <class TViewerModel, class TPixelDescriptionModel, class TView> 
class PixelDescriptionActionHandler
  : public ImageWidgetActionHandler
{
public:
  /** Standard class typedefs */
  typedef PixelDescriptionActionHandler       Self;
  typedef ImageWidgetActionHandler          Superclass;
  typedef itk::SmartPointer<Self>           Pointer;
  typedef itk::SmartPointer<const Self>     ConstPointer;
  
  /** Method for creation through the object factory */
  itkNewMacro(Self);
  
  /** Runtime information */
  itkTypeMacro(PixelDescriptionActionHandler,ImageWidgetActionHandler);

  /** Viewer Model typedefs */
  typedef TViewerModel                         ViewerModelType;
  typedef typename ViewerModelType::Pointer    ViewerModelPointerType;
  typedef typename ViewerModelType::IndexType  IndexType;

  /** Pixel description model typedef */
  


   /** Handle widget resizing
   * \param widgetId The id of the resized widget
   * \param x new x location
   * \param y new y location
   * \param w new width
   * \param h new height
   */
  virtual bool HandleWidgetEvent(std::string widgetId, int event)
  {
    if(m_Model.IsNotNull() && m_PixelDescriptionModel.IsNotNull() && m_View.IsNotNull())
      {
      // If resizing the scroll widget, nothing has to be done.
      if(widgetId == m_View->GetScrollWidget()->GetIdentifier() )
	{
	switch(event)
	  {
	  case FL_ENTER:
	  {
	    return true;
	    break;
	  }
	  case FL_LEAVE:
	  {
	    return true,
	    break;
	  }
	  case FL_MOVE:
	  {
	  return true;
	  break;
	  }
	  case default:
	  {
	  return true;
	  break;
	  }





	  }
	otbMsgDevMacro(<<"PixelDescriptionActionHandler::HandleWidgetResize(): handling ("<<widgetId<<", "<<w<<", "<<h<<")");
	// Nothing has to be acted to the model, juste update the view
	m_View->Update();
	return true;
	}
      else if(widgetId == m_View->GetFullWidget()->GetIdentifier() )
	{
	otbMsgDevMacro(<<"PixelDescriptionActionHandler::HandleWidgetResize(): handling ("<<widgetId<<", "<<w<<", "<<h<<")");
	// Enlarge the model extract region
	RegionType region = m_Model->GetExtractRegion();
	typename RegionType::SizeType size = region.GetSize();
	size[0] = static_cast<unsigned int>(w);
	size[1] = static_cast<unsigned int>(h);
	region.SetSize(size);
	m_Model->SetExtractRegion(region);
	// Update the model
	m_Model->Update();
	return true;
	}
      else if(widgetId ==m_View->GetZoomWidget()->GetIdentifier() )
	{
	otbMsgDevMacro(<<"PixelDescriptionActionHandler::HandleWidgetResize(): handling ("<<widgetId<<", "<<w<<", "<<h<<")");
	// Enlarge the model scaled extract region
	RegionType region = m_Model->GetScaledExtractRegion();
	typename RegionType::SizeType size = region.GetSize();
	size[0] = static_cast<unsigned int>(static_cast<double>(w)/m_View->GetZoomWidget()->GetIsotropicZoom());
	size[1] = static_cast<unsigned int>(static_cast<double>(h)/m_View->GetZoomWidget()->GetIsotropicZoom());
	region.SetSize(size);
	m_Model->SetScaledExtractRegion(region);
	// Update the model
	m_Model->Update();
	return true;
	}
      }
    return false;
  }
  
  /** Set/Get the pointer to the model */
  itkSetObjectMacro(Model,ModelType);
  itkGetObjectMacro(Model,ModelType);

protected:
  /** Constructor */
  PixelDescriptionActionHandler() : m_View(), m_Model()
  {}

  /** Destructor */
  virtual ~PixelDescriptionActionHandler(){}
  /** Printself method */
  void PrintSelf(std::ostream& os, itk::Indent indent) const
  {
    Superclass::PrintSelf(os,indent);
  }
 <commit_msg>ENH: (Visu Refactoring) Finalizing the pixel description handler<commit_after>/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __otbPixelDescriptionActionHandler_h
#define __otbPixelDescriptionActionHandler_h

#include "otbImageWidgetActionHandler.h"

namespace otb
{
/** \class PixelDescriptionActionHandler
*   \brief Implements pixel reporting capabilities.
* 
*   \sa ImageWidgetController
*   \sa ImageWidgetActionHandler
*/

template <class TModel, class TView> 
class PixelDescriptionActionHandler
  : public ImageWidgetActionHandler
{
public:
  /** Standard class typedefs */
  typedef PixelDescriptionActionHandler       Self;
  typedef ImageWidgetActionHandler          Superclass;
  typedef itk::SmartPointer<Self>           Pointer;
  typedef itk::SmartPointer<const Self>     ConstPointer;
  
  /** Method for creation through the object factory */
  itkNewMacro(Self);
  
  /** Runtime information */
  itkTypeMacro(PixelDescriptionActionHandler,ImageWidgetActionHandler);

  /** Model typedefs */
  typedef TModel                         ModelType;
  typedef typename ModelType::Pointer    ModelPointerType;
  typedef typename ModelType::IndexType  IndexType;

  /** View typedef */
  typedef TView                                     ViewType;
  typedef typename ViewType::Pointer                ViewPointerType;
  typedef typename ViewType::ImageWidgetPointerType WidgetPointerType;

   /** Handle widget event
   */
  virtual bool HandleWidgetEvent(std::string widgetId, int event)
  {
    if(m_Model.IsNotNull() &&  m_View.IsNotNull())
      {
      // Find the source widget
      WidgetPointerType sourceWidget;
      bool handle = false;
      if(widgetId == m_View->GetScrollWidget()->GetIdentifier() )
	{
	sourceWidget = m_View->GetScrollWidget();
	handle = true;
	}
      else if(widgetId == m_View->GetFullWidget()->GetIdentifier() )
	{
	sourceWidget = m_View->GetFullWidget();
	handle = true;
	}
      else if(widgetId == m_View->GetZoomWidget()->GetIdentifier() )
	{
	sourceWidget = m_View->GetZoomWidget();
	handle = true;
	}
      if(handle)
	{
	switch(event)
	  {
	  case FL_ENTER:
	  {
	  return true;
	  break;
	  }
	  case FL_LEAVE:
	  {
	  return true;
	  break;
	  }
	  case FL_MOVE:
	  {
	  // Get the hovered index
	  IndexType index;
	  index[0]=Fl::event_x();
	  index[1]=Fl::event_y();
	  // Convert to image index
	  index = sourceWidget->ScreenIndexToImageIndex(index);
	  // Communicate new index to model
	  m_Model->UpdatePixelDescription(index);
	  return true;
	  break;
	  }
	  default:
	  {
	  break;
	  }
	  }
	}
      }
    return false;
  }
  
  /** Set/Get the pointer to the model */
  itkSetObjectMacro(Model,ModelType);
  itkGetObjectMacro(Model,ModelType);

   /** Set/Get the pointer to the view */
  itkSetObjectMacro(View,ViewType);
  itkGetObjectMacro(View,ViewType);

protected:
  /** Constructor */
  PixelDescriptionActionHandler() : m_View(), m_Model()
  {}

  /** Destructor */
  virtual ~PixelDescriptionActionHandler(){}
  /** Printself method */
  void PrintSelf(std::ostream& os, itk::Indent indent) const
  {
    Superclass::PrintSelf(os,indent);
  }
 
{'fraction_non_alphanumeric': 0.14289267504041786, 'fraction_numerical': 0.000746175848775028, 'mean_word_length': 3.8242351529694063, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2644536', 'n_tokens_mistral': 2424, 'n_tokens_neox': 2309, 'n_words': 568}