/ Delusional Perception User Interface by Mazyar Sharifian from www.cubichead.com --------------------------- 10/04/2015
  
     
global string    $delusionalPerceptionWindow;
global string    $filePath;
global string    $particleShape;
global string    $size_widget;
global string    $spacing_widget;
global string    $range_widget;
global string    $depth_widget;
global string    $focal_widget;
  
  
//--------------------------------------------------
// Creating the UI elements and all the widgets
//--------------------------------------------------
  
global proc browseFiles () {
    textField -edit -text `fileDialog2 -fm 1` myTextField;
  
}
  
global proc selectSphere () {
    global string    $particleShape;
    $particleShape = "sphere(s = 1, nsp = 1)";
}
global proc selectCube () {
    global string    $particleShape;
    $particleShape = "polyCube()";
}
global proc selectCylinder () {
    global string    $particleShape;
    $particleShape = "cylinder()";
}
global proc selectTorus () {
    global string    $particleShape;
    $particleShape = "torus(ax = (0, 1, 0), s = 1, hr = 0.3)";
}
global proc selectCone () {
    global string    $particleShape;
    $particleShape = "cone()";
}
global proc selectPlane () {
    global string    $particleShape;
    $particleShape = "polyPlane(sx = 1, sy = 1)";
}
  
global proc addUIWidgets () {
    global string    $size_widget;
    global string    $spacing_widget;
    global string    $range_widget;      
    global string    $depth_widget;      
    global string    $focal_widget;    
  
    formLayout myForm;
    
    textField -w 243 -tx "" myTextField;
    
    button -label "Browse Image" -command "browseFiles" myExplorerButton;    
    
    symbolButton -image "sphere.xpm" -command "selectSphere" mySphereButton;
  
    symbolButton -image "cube.xpm" -command "selectCube" myCubeButton;
    
    symbolButton -image "cylinder.xpm" -command "selectCylinder" myCylinderButton;
    
    symbolButton -image "torus.xpm" -command "selectTorus" myTorusButton;
    
    symbolButton -image "cone.xpm" -command "selectCone" myConeButton;
    
    symbolButton -image "plane.xpm" -command "selectPlane" myPlaneButton;
    
    $size_widget = `floatSliderGrp -columnWidth 1 100
                        -label "Particle Size"
                        -field true
                        -value 0.1
                        -precision 3
                        -min 0 -max 5 mySize`;
                        
    $spacing_widget = `floatSliderGrp -columnWidth 1 100
                        -label "Spacing"
                        -field true
                        -value 0
                        -precision 3
                        -min 0 -max 5 mySpacing`;
                        
    $range_widget = `floatSliderGrp -columnWidth 1 100
                        -label "Color Range"
                        -field true
                        -value 0.9
                        -min 0 -max 1 myRange`;    
                        
    $depth_widget = `floatSliderGrp -columnWidth 1 100
                        -label "Depth"
                        -field true
                        -value 10
                        -min 1 -max 100 myDepth`;    
                        
  
    $focal_widget = `floatSliderGrp -columnWidth 1 100
                        -label "Focal Length"
                        -field true
                        -value 35
                        -min 15 -max 135 myFocal`;    
                        
    button  -label "Create Delusion" -command "createDelusionalPerception" myButton;
    
    formLayout -edit    -attachForm myTextField "left" 110
                        -attachForm myTextField "top" 25   
    
                        -attachForm myExplorerButton "left" 22
                        -attachForm myExplorerButton "top" 24   
  
                        -attachForm mySphereButton "left" 16
                        -attachForm mySphereButton "top" 64                 
  
                        -attachForm myCubeButton "left" 75
                        -attachForm myCubeButton "top" 64                 
  
                        -attachForm myCylinderButton "left" 144
                        -attachForm myCylinderButton "top" 64                 
  
                        -attachForm myTorusButton "left" 203
                        -attachForm myTorusButton "top" 64                 
  
                        -attachForm myConeButton "left" 262
                        -attachForm myConeButton "top" 64                 
  
                        -attachForm myPlaneButton "left" 321
                        -attachForm myPlaneButton "top" 64                 
               
                        -attachForm mySize "left" 7
                        -attachForm mySize "top" 111                 
  
                        -attachForm mySpacing "left" 7
                        -attachForm mySpacing "top" 141  
  
                        -attachForm myRange "left" 7
                        -attachForm myRange "top" 171  
  
                        -attachForm myDepth "left" 7
                        -attachForm myDepth "top" 201 
                        
                        -attachForm myFocal "left" 7
                        -attachForm myFocal "top" 231  
  
                        -attachForm myButton "left" 259
                        -attachForm myButton "top" 269  
  
    myForm;
    
    }
 
//--------------------------------------------------
// Applying the inputs from widgets to the python code
//--------------------------------------------------
  
global proc createDelusionalPerception() {
    global string    $particleShape;
    global string    $size_widget;
    global string    $spacing_widget;
    global string    $range_widget;
    global string    $depth_widget;
    global string    $focal_widget;
    string    $filePath = `textField -query -text myTextField`;
          
    float    $size = `floatSliderGrp -q -v $size_widget`;
    float    $space = `floatSliderGrp -q -v $spacing_widget`;
    float    $range = `floatSliderGrp -q -v $range_widget`;
    float    $depth = `floatSliderGrp -q -v $depth_widget`;
    float    $focal = `floatSliderGrp -q -v $focal_widget`;
  
    python("from delusionalPerception import *");
    $command = "delusionalPerception(" + "'" + $filePath + "','" + $particleShape + "'," + $size + "," + $space + "," + $range + "," + $depth + "," + $focal + ")";
    python($command);
    }
 
  
//--------------------------------------------------
// Creating the window
//--------------------------------------------------
  
global proc delusionalPerceptionUI() {
    global string $delusionalPerceptionWindow; 
    global string $particleShape = "sphere()";
    
    int $doesExist = `window -exists $delusionalPerceptionWindow`;
    if ($doesExist == 0) {
        $delusionalPerceptionWindow = `window -w 365 -h 300
                            -title "Delusional Perception"`;
        addUIWidgets();
        }
    showWindow $delusionalPerceptionWindow;
    }
  
delusionalPerceptionUI();
//dockControl -area "right" -content $delusionalPerceptionWindow -label "Delusional Perception";