<commit_before>

//
// Copyright 2010-2011 Fabric Technologies Inc. All rights reserved.
//

/**
 * The rselection manager provides selection functionality to the scene graph.
 * additional rendering pipeline and capabilities.
 */
FABRIC.SceneGraph.registerManagerType('SelectionManager', {
  briefDesc: 'The SelectionManager manages selections of objects.',
  detailedDesc: '.',
  parentManagerDesc: '',
  optionsDesc: {
  },
  factoryFn: function(options, scene) {
    scene.assignDefaults(options, {
      });

    var selection = [];
    
    var selectionManager = {
      pub:{
        isSelected:function( obj ){ 
          return selection.indexOf(obj) != -1;
        },
        select:function( obj ){
          if(!this.isSelected(obj)){ 
            this.clearSelection();
            this.addToSelection(obj);
          }
        },
        addToSelection:function( obj ){
          if(obj.fireEvent){
            obj.fireEvent('selected');
          }
          selection.push(obj);
        },
        removeFromSelection:function( obj ){ 
          if( selection.length == 0 ){
            return;
          }
          var id = selection.indexOf(obj);
          if( id != -1 ){
            // Put the color back. 
            if(obj.fireEvent){
              obj.fireEvent('deselected');
            }
            // Remove from the seleciton array.
            if( selection.length == 1 ){
              selection = []
            }else{
              selection.splice(id,1);
            }
          }
        },
        clearSelection:function(){ 
          if(selection.length > 0){
            for (var i = selection.length-1; i >=0 ; i--) {
              this.removeFromSelection(selection[i]);
            }
          }
        }
      }
    }
    
    return selectionManager;
  }});



FABRIC.SceneGraph.registerManagerType('ViewportSelectionManager', {
  briefDesc: 'The ViewportSelectorManager manages selections of objects view mouse events from the viewport.',
  detailedDesc: '.',
  parentManagerDesc: '',
  optionsDesc: {
  },
  factoryFn: function(options, scene) {
    scene.assignDefaults(options, {
      addToSelectionKeyName: 'ctrlKey'
    });
    
    var selectionManager = scene.constructManager('SelectionManager', options);
    
    scene.pub.addEventListener('mouseover_selectableinst', function(evt){
        if(evt.targetNode.fireEvent){
          evt.targetNode.fireEvent('highlight');
          scene.pub.redrawAllViewports();
        }
      });
    scene.pub.addEventListener('mouseout_selectableinst', function(evt){
        if(evt.targetNode.fireEvent){
          evt.targetNode.fireEvent('unhighlight');
          scene.pub.redrawAllViewports();
        }
      });
    scene.pub.addEventListener('mousedown_selectableinst', function(evt){
        if(evt[options.addToSelectionKeyName]){
          selectionManager.pub.addToSelection(evt.targetNode);
        }else{
          selectionManager.pub.select(evt.targetNode);
          evt.stopPropagation();
          scene.pub.redrawAllViewports();
        }
      });
    scene.pub.addEventListener('mousedown', function(evt){
        selectionManager.pub.clearSelection();
        scene.pub.redrawAllViewports();
      });
    
    return selectionManager;
  }});


// These Node definitions are inlined for now, but will
// be moved to a separate file once they are stabilized. 
FABRIC.SceneGraph.registerNodeType('SelectableInstance', {
  factoryFn: function(options, scene) {
    scene.assignDefaults(options, {
      selectionManager: undefined
    });
    var selectionManager = options.selectionManager;
    var selectableInstance = scene.constructNode('Instance', options);
    selectableInstance.pub.addEventListener('mouseover_geom', function(evt) {
      selectionManager.fireEvent('mouseover_selectableinst');
    });
    selectableInstance.pub.addEventListener('mouseout_geom', function(evt) {
      selectionManager.fireEvent('mouseout_selectableinst');
    });
    selectableInstance.pub.addEventListener('mousedown_geom', function(evt) {
      selectionManager.fireEvent('mousedown_selectableinst');
    });
    
    return selectableInstance;
  }});

<commit_msg>Revert "* SelectionManager: Added 'SelectableInstance'."<commit_after>

//
// Copyright 2010-2011 Fabric Technologies Inc. All rights reserved.
//

/**
 * The rselection manager provides selection functionality to the scene graph.
 * additional rendering pipeline and capabilities.
 */
FABRIC.SceneGraph.registerManagerType('SelectionManager', {
  briefDesc: 'The SelectionManager manages selections of objects.',
  detailedDesc: '.',
  parentManagerDesc: '',
  optionsDesc: {
  },
  factoryFn: function(options, scene) {
    scene.assignDefaults(options, {
      });

    var selection = [];
    
    var selectionManager = {
      pub:{
        isSelected:function( obj ){ 
          return selection.indexOf(obj) != -1;
        },
        select:function( obj ){
          if(!this.isSelected(obj)){ 
            this.clearSelection();
            this.addToSelection(obj);
          }
        },
        addToSelection:function( obj ){
          if(obj.fireEvent){
            obj.fireEvent('selected');
          }
          selection.push(obj);
        },
        removeFromSelection:function( obj ){ 
          if( selection.length == 0 ){
            return;
          }
          var id = selection.indexOf(obj);
          if( id != -1 ){
            // Put the color back. 
            if(obj.fireEvent){
              obj.fireEvent('deselected');
            }
            // Remove from the seleciton array.
            if( selection.length == 1 ){
              selection = []
            }else{
              selection.splice(id,1);
            }
          }
        },
        clearSelection:function(){ 
          if(selection.length > 0){
            for (var i = selection.length-1; i >=0 ; i--) {
              this.removeFromSelection(selection[i]);
            }
          }
        }
      }
    }
    
    return selectionManager;
  }});



FABRIC.SceneGraph.registerManagerType('ViewportSelectionManager', {
  briefDesc: 'The ViewportSelectorManager manages selections of objects view mouse events from the viewport.',
  detailedDesc: '.',
  parentManagerDesc: '',
  optionsDesc: {
  },
  factoryFn: function(options, scene) {
    scene.assignDefaults(options, {
      addToSelectionKeyName: 'ctrlKey'
    });
    
    var selectionManager = scene.constructManager('SelectionManager', options);
    
    scene.pub.addEventListener('mouseover_geom', function(evt){
        if(evt.targetNode.fireEvent){
          evt.targetNode.fireEvent('highlight');
          scene.pub.redrawAllViewports();
        }
      });
    scene.pub.addEventListener('mouseout_geom', function(evt){
        if(evt.targetNode.fireEvent){
          evt.targetNode.fireEvent('unhighlight');
          scene.pub.redrawAllViewports();
        }
      });
    scene.pub.addEventListener('mousedown_geom', function(evt){
        if(evt[options.addToSelectionKeyName]){
          selectionManager.pub.addToSelection(evt.targetNode);
        }else{
          selectionManager.pub.select(evt.targetNode);
          evt.stopPropagation();
          scene.pub.redrawAllViewports();
        }
      });
    scene.pub.addEventListener('mousedown', function(evt){
        selectionManager.pub.clearSelection();
        scene.pub.redrawAllViewports();
      });
    
    return selectionManager;
  }});



{'fraction_non_alphanumeric': 0.11984467059453668, 'fraction_numerical': 0.004284949116229245, 'mean_word_length': 2.294662549625055, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3387377', 'n_tokens_mistral': 2040, 'n_tokens_neox': 2007, 'n_words': 351}