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

  Program:   Visualization Toolkit
  Module:    vtkInteractorStyleRubberBand2D.cxx

  Copyright (c) <NAME>, <NAME>, <NAME>
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm 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 notice for more information.

=========================================================================*/
/*-------------------------------------------------------------------------
  Copyright 2008 Sandia Corporation.
  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
  the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/

#include "vtkInteractorStyleRubberBand2D.h"

#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCommand.h"
#include "vtkObjectFactory.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkUnsignedCharArray.h"

vtkStandardNewMacro(vtkInteractorStyleRubberBand2D);

//--------------------------------------------------------------------------
vtkInteractorStyleRubberBand2D::vtkInteractorStyleRubberBand2D()
{
  this->PixelArray = vtkUnsignedCharArray::New();
  this->Interaction = NONE;
  this->RenderOnMouseMove = false;
  this->StartPosition[0] = 0.0;
  this->StartPosition[1] = 0.0;
  this->EndPosition[0] = 0.0;
  this->EndPosition[1] = 0.0;
}

//--------------------------------------------------------------------------
vtkInteractorStyleRubberBand2D::~vtkInteractorStyleRubberBand2D()
{
  this->PixelArray->Delete();
}

//--------------------------------------------------------------------------
void vtkInteractorStyleRubberBand2D::OnLeftButtonDown()
{
  if(this->Interaction == NONE)
    {
    this->Interaction = SELECTING;
    vtkRenderWindow *renWin = this->Interactor->GetRenderWindow();

    this->StartPosition[0] = this->Interactor->GetEventPosition()[0];
    this->StartPosition[1] = this->Interactor->GetEventPosition()[1];
    this->EndPosition[0] = this->StartPosition[0];
    this->EndPosition[1] = this->StartPosition[1];

    this->PixelArray->Initialize();
    this->PixelArray->SetNumberOfComponents(4);
    int *size = renWin->GetSize();
    this->PixelArray->SetNumberOfTuples(size[0]*size[1]);

    renWin->GetRGBACharPixelData(0, 0, size[0]-1, size[1]-1, 1, this->PixelArray);
    this->FindPokedRenderer(this->StartPosition[0], this->StartPosition[1]);
    this->InvokeEvent(vtkCommand::StartInteractionEvent);
    }
}

//--------------------------------------------------------------------------
void vtkInteractorStyleRubberBand2D::OnLeftButtonUp()
{
  if(this->Interaction == SELECTING)
    {
    this->Interaction = NONE;

    // Clear the rubber band
    int* size = this->Interactor->GetRenderWindow()->GetSize();
    unsigned char* pixels = this->PixelArray->GetPointer(0);
    this->Interactor->GetRenderWindow()->SetRGBACharPixelData(0, 0, size[0]-1, size[1]-1, pixels, 0);
    this->Interactor->GetRenderWindow()->Frame();

    unsigned int rect[5];
    rect[0] = this->StartPosition[0];
    rect[1] = this->StartPosition[1];
    rect[2] = this->EndPosition[0];
    rect[3] = this->EndPosition[1];
    if (this->Interactor->GetShiftKey())
      {
      rect[4] = SELECT_UNION;
      }
    else
      {
      rect[4] = SELECT_NORMAL;
      }
    this->InvokeEvent(vtkCommand::SelectionChangedEvent, reinterpret_cast<void*>(rect));
    this->InvokeEvent(vtkCommand::EndInteractionEvent);
    }
}

//--------------------------------------------------------------------------
void vtkInteractorStyleRubberBand2D::OnMiddleButtonDown()
{
  if(this->Interaction == NONE)
    {
    this->Interaction = PANNING;
    this->FindPokedRenderer(
      this->Interactor->GetEventPosition()[0],
      this->Interactor->GetEventPosition()[1]);
    this->InvokeEvent(vtkCommand::StartInteractionEvent);
    }
}
<commit_msg>Adding alternate mode (alt + left click) for panning<commit_after>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkInteractorStyleRubberBand2D.cxx

  Copyright (c) <NAME>, <NAME>, <NAME>
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm 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 notice for more information.

=========================================================================*/
/*-------------------------------------------------------------------------
  Copyright 2008 Sandia Corporation.
  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
  the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/

#include "vtkInteractorStyleRubberBand2D.h"

#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCommand.h"
#include "vtkObjectFactory.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkUnsignedCharArray.h"

vtkStandardNewMacro(vtkInteractorStyleRubberBand2D);

//--------------------------------------------------------------------------
vtkInteractorStyleRubberBand2D::vtkInteractorStyleRubberBand2D()
{
  this->PixelArray = vtkUnsignedCharArray::New();
  this->Interaction = NONE;
  this->RenderOnMouseMove = false;
  this->StartPosition[0] = 0.0;
  this->StartPosition[1] = 0.0;
  this->EndPosition[0] = 0.0;
  this->EndPosition[1] = 0.0;
}

//--------------------------------------------------------------------------
vtkInteractorStyleRubberBand2D::~vtkInteractorStyleRubberBand2D()
{
  this->PixelArray->Delete();
}

//--------------------------------------------------------------------------
void vtkInteractorStyleRubberBand2D::OnLeftButtonDown()
{
  if(this->Interaction == NONE)
    {
    if (this->Interactor->GetAltKey())
      {
      this->Interaction = PANNING;
      }
    else
      {
      this->Interaction = SELECTING;
      vtkRenderWindow *renWin = this->Interactor->GetRenderWindow();

      this->StartPosition[0] = this->Interactor->GetEventPosition()[0];
      this->StartPosition[1] = this->Interactor->GetEventPosition()[1];
      this->EndPosition[0] = this->StartPosition[0];
      this->EndPosition[1] = this->StartPosition[1];

      this->PixelArray->Initialize();
      this->PixelArray->SetNumberOfComponents(4);
      int *size = renWin->GetSize();
      this->PixelArray->SetNumberOfTuples(size[0]*size[1]);

      renWin->GetRGBACharPixelData(0, 0, size[0]-1, size[1]-1, 1, this->PixelArray);
      }
    this->FindPokedRenderer(this->StartPosition[0], this->StartPosition[1]);
    this->InvokeEvent(vtkCommand::StartInteractionEvent);
    }
}

//--------------------------------------------------------------------------
void vtkInteractorStyleRubberBand2D::OnLeftButtonUp()
{
  if(this->Interaction == SELECTING)
    {
    this->Interaction = NONE;

    // Clear the rubber band
    int* size = this->Interactor->GetRenderWindow()->GetSize();
    unsigned char* pixels = this->PixelArray->GetPointer(0);
    this->Interactor->GetRenderWindow()->SetRGBACharPixelData(0, 0, size[0]-1, size[1]-1, pixels, 0);
    this->Interactor->GetRenderWindow()->Frame();

    unsigned int rect[5];
    rect[0] = this->StartPosition[0];
    rect[1] = this->StartPosition[1];
    rect[2] = this->EndPosition[0];
    rect[3] = this->EndPosition[1];
    if (this->Interactor->GetShiftKey())
      {
      rect[4] = SELECT_UNION;
      }
    else
      {
      rect[4] = SELECT_NORMAL;
      }
    this->InvokeEvent(vtkCommand::SelectionChangedEvent, reinterpret_cast<void*>(rect));
    this->InvokeEvent(vtkCommand::EndInteractionEvent);
    }
  else if(this->Interaction == PANNING)
    {
    this->Interaction = NONE;
    this->InvokeEvent(vtkCommand::EndInteractionEvent);
    }
}

//--------------------------------------------------------------------------
void vtkInteractorStyleRubberBand2D::OnMiddleButtonDown()
{
  if(this->Interaction == NONE)
    {
    this->Interaction = PANNING;
    this->FindPokedRenderer(
      this->Interactor->GetEventPosition()[0],
      this->Interactor->GetEventPosition()[1]);
    this->InvokeEvent(vtkCommand::StartInteractionEvent);
    }
}

{'fraction_non_alphanumeric': 0.275588715318256, 'fraction_numerical': 0.017719748193051995, 'mean_word_length': 2.5465068210004134, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 147, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1456197', 'n_tokens_mistral': 2512, 'n_tokens_neox': 2412, 'n_words': 404}