home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Plotting / aa_Intel_Only / Gnuplot / GnuplotSource / DataPane.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  8.9 KB  |  407 lines

  1. /*
  2.  *  Copyright (C) 1993  Robert Davis
  3.  *
  4.  *  This program is free software; you can redistribute it and/or
  5.  *  modify it under the terms of Version 2, or any later version, of 
  6.  *  the GNU General Public License as published by the Free Software 
  7.  *  Foundation.
  8.  */
  9.  
  10.  
  11. static char RCSId[]="$Id: DataPane.m,v 1.13 1993/05/18 03:54:59 davis Exp $";
  12.  
  13.  
  14. #import <appkit/Application.h>
  15. #import <appkit/Box.h>
  16. #import <appkit/Form.h>
  17. #import <appkit/OpenPanel.h>
  18. #import <appkit/View.h>
  19.  
  20. #import <sys/param.h>            /* MAXPATHLEN                   */
  21.  
  22. #import "CellScrollView.h"
  23. #import "DataOptionsPanel.h"
  24. #import "DataPane.h"
  25. #import "FunctionObject.h"
  26. #import "EditMatrix.h"
  27. #import "GnuplotPlot.h"
  28. #import "Status.h"
  29. #import "SubCell.h"
  30.  
  31.  
  32. @interface DataPane (Private)
  33.  
  34. - _updateFunctionsMatrix;
  35. - _updateControlsForSelectedFunction;
  36.  
  37. @end
  38.  
  39.  
  40. @implementation DataPane
  41.  
  42.  
  43. - init
  44. {
  45.     [super init];
  46.  
  47.     [NXApp loadNibSection: "DataPane.nib"
  48.             owner: self
  49.         withNames: NO
  50.          fromZone: [self zone]];
  51.  
  52.     icon = "InspectorData.tiff";
  53.  
  54.     /*  Initialize the CellScrollView of functions  */
  55.  
  56.     [functionsScrollView initMatrixCellClass:[SubCell class] cols:1];
  57.     functionsMatrix = [functionsScrollView cellMatrix];
  58.     [[functionsMatrix setAction:@selector(selectFunction:)] setTarget:self];
  59.  
  60.     return self;
  61. }
  62.  
  63.  
  64. - free
  65. {
  66.     [optionsPanel free];
  67.     return [super free];
  68. }
  69.  
  70.  
  71. /*  
  72.  *  Overridden from Pane.
  73.  */
  74. - selectControl:sender
  75. {
  76.     [functionsForm selectTextAt:0];
  77.     return self;
  78. }
  79.  
  80.  
  81. - (BOOL)updateStatus:aStatus doc:aDoc
  82. {
  83.     id        oldStatus = status;
  84.  
  85.     /*  
  86.      *  We only bother updating if status has changed since we last 
  87.      *  updated, or if we just became the current pane (didSwap) -- 
  88.      *  assuming that status and aDoc are non-nil, of course.
  89.      */
  90.  
  91.     if ([super updateStatus:aStatus doc:aDoc]
  92.     && ((status != oldStatus) || didSwap)) {
  93.  
  94.     Window *viewWindow;
  95.  
  96.     [(viewWindow = [view window]) disableDisplay];
  97.  
  98.     functionObjects = [status functions];
  99.  
  100.     [dummyFormCellX setStringValue:[status dummyVar:X_TAG]];
  101.     [dummyFormCellY setStringValue:[status dummyVar:Y_TAG]];
  102.     [dummyFormCellY setEnabled:[status isThreeD]];
  103.     [self _updateFunctionsMatrix];
  104.  
  105.     if (![functionsMatrix selectedCell]
  106.         && ![functionsMatrix multipleCellsSelected])
  107.  
  108.         [functionsMatrix selectCellAt:0:0];        /* Make a selection */
  109.  
  110.  
  111.     [self _updateControlsForSelectedFunction];
  112.  
  113.     [viewWindow reenableDisplay];
  114.  
  115.     [self perform:@selector(selectControl:)
  116.          with:self
  117.        afterDelay:1
  118.        cancelPrevious:YES];
  119.  
  120.     didSwap = NO;
  121.     [optionsPanel ownerDidSwapIn:self];    /* We're done swapping now */
  122.     return YES;
  123.  
  124.     }
  125.  
  126.     return NO;
  127. }
  128.  
  129.  
  130. - (BOOL)forceUpdateStatus:aStatus doc:aDoc
  131. {
  132.     BOOL    needsRedisplay;
  133.  
  134.     /*  
  135.      *  Must update ourself first, then update the options panel 
  136.      *  because the options panel may look at our controls, etc. to 
  137.      *  update itself.
  138.      */
  139.     needsRedisplay = [super forceUpdateStatus:aStatus doc:aDoc];
  140.  
  141.     if ([[optionsPanel panel] isVisible])
  142.     [optionsPanel forceUpdate];
  143.  
  144.     return needsRedisplay;
  145. }
  146.  
  147.  
  148.  
  149. - didSwapIn:sender
  150. {
  151.     [super didSwapIn:sender];
  152.     didSwap = YES;
  153.     return self;
  154. }
  155.  
  156.  
  157.  
  158. - didSwapOut:sender
  159. {
  160.     [super didSwapOut:sender];
  161.     [optionsPanel ownerDidSwapOut:self];
  162.     return self;
  163. }
  164.  
  165.  
  166.  
  167. - doSetDummy:sender
  168. {
  169.     [status setDummyVar:[sender tag] to:[sender stringValue]];
  170.     return self;
  171. }
  172.  
  173.  
  174. - findDataFile:sender
  175. {
  176.     const char *const *files;
  177.     id openPanel;
  178.     char fullName[MAXPATHLEN];
  179.  
  180.     openPanel = [[OpenPanel new] allowMultipleFiles:YES];
  181.     [openPanel setTitle:"Add Data File"];
  182.  
  183.     if ([openPanel runModalForTypes:NULL])
  184.         for (files = [openPanel filenames]; files && *files; files++) {
  185.  
  186.             sprintf (fullName, "%s/%s", [openPanel directory], *files);
  187.             [self addDataFile:fullName];
  188.  
  189.         }
  190.  
  191.     return self;
  192. }
  193.  
  194.  
  195. - selectFunction:sender
  196. {
  197.     if (![functionsMatrix selectedCell]
  198.     && ![functionsMatrix multipleCellsSelected]) {
  199.  
  200.     [functionsMatrix selectCellAt:0:0];
  201.     [self _updateControlsForSelectedFunction];
  202.  
  203.     } else {
  204.     [self _updateControlsForSelectedFunction];
  205.     [functionsForm selectTextAt:0];
  206.     }
  207.  
  208.     [optionsPanel forceUpdate];
  209.  
  210.     return self;
  211. }
  212.  
  213.  
  214. - deleteSelectedFunctions:sender
  215. {
  216.     int i;
  217.     int maxrow = [functionsMatrix cellCount] - 1;
  218.     int row = maxrow;
  219.     BOOL gotRow = NO;
  220.     int col = [functionsMatrix selectedCol];
  221.  
  222.     for (i = maxrow; i >= 0; i--) {
  223.         SubCell *cell = [functionsMatrix cellAt:i:0];
  224.         if ([cell isHighlighted]) {
  225.             /*
  226.              * If a cell is highlighted, remove (and free) the corresponding
  227.              * item from the list of SubObjects.
  228.              */
  229.             [[functionObjects removeObject:[cell subObject]] free];
  230.         if (!gotRow) {
  231.         row = (i == maxrow)? i - 1: i;
  232.         gotRow = YES;
  233.         } else
  234.         row--;
  235.         }
  236.     }
  237.  
  238.     [functionsScrollView loadCol:0 from:functionObjects];
  239.  
  240.     [functionsMatrix selectCellAt: row:col];
  241.     [functionsMatrix scrollCellToVisible: row:col];
  242.     [self selectFunction:self];
  243.  
  244.     /*  
  245.      *  We change the list of functions maintainted by Status without 
  246.      *  going through Status, so we need to make sure the changes are 
  247.      *  noticed. 
  248.      */
  249.     [status reportSettingsChange:self];
  250.  
  251.     return self;
  252. }
  253.  
  254.  
  255. - modifySelectedFunction:sender
  256. {
  257.     id cell = [functionsMatrix selectedCell];
  258.  
  259.     [[cell subObject] setStringValue: [functionsForm stringValue]];
  260.     [functionsScrollView loadCol:0 from:functionObjects];
  261.     [functionsMatrix selectCell:cell];
  262.     [self selectFunction:self];
  263.  
  264.     [status reportSettingsChange:self];
  265.     return self;
  266. }
  267.  
  268.  
  269. - addFunction:sender
  270. {
  271.     const char *stringValue;
  272.     int count;
  273.     FunctionObject *functionObject;
  274.  
  275.     stringValue = [functionsForm stringValue];
  276.  
  277.     if (![FunctionObject isAcceptableStringValue:stringValue])  {
  278.         [self selectFunction:self];
  279.         return nil;
  280.     }
  281.  
  282.     functionObject = [[FunctionObject allocFromZone: [status zone]]
  283.                                      initFromString: stringValue
  284.                        isThreeD: [status isThreeD]];
  285.     [functionObjects addObject:functionObject];
  286.     [functionsScrollView loadCol:0 from:functionObjects];
  287.   /*
  288.    *  Assumptions in this next line:
  289.    *    There are as many SubCells as there are functionObjects
  290.    *    We've added the new functionObject at the end of the list.
  291.    *    We want to display the functionObject we just added and highlight it.
  292.    *  In short, this is a hack.
  293.    *                                    -- CellScrollView, NeXT Example
  294.    */
  295.     count = [functionObjects count] - 1;
  296.     [functionsMatrix scrollCellToVisible:count :0];
  297.     [functionsMatrix selectCellAt:count:0];
  298.     [self selectFunction:self];
  299.  
  300.     [status reportSettingsChange:self];
  301.  
  302.     return self;
  303. }
  304.  
  305.  
  306.  
  307. - functionsMatrix
  308. {
  309.     return functionsMatrix;
  310. }
  311.  
  312.  
  313.  
  314. - addDataFile:(const char *)aPath
  315. {
  316.     int count;
  317.  
  318.     [doc addDataFile:aPath];
  319.     [functionsScrollView loadCol:0 from:functionObjects];
  320.  
  321.     /*
  322.      * Assumptions in this next line:
  323.      *    There are as many SubCells as there are functionObjects
  324.      *    We've added the new functionObject at the end of the list.
  325.      *    We want to display the functionObject we just added and highlight it.
  326.      * In short, this is a hack.
  327.      *                          -- CellScrollView, NeXT Example
  328.      */
  329.     count = [functionObjects count] - 1;
  330.     [functionsMatrix scrollCellToVisible:count :0];
  331.     [functionsMatrix selectCellAt:count:0];
  332.     [self selectFunction:self];
  333.  
  334.     return self;
  335. }
  336.  
  337.  
  338. - showOptionsPanel:sender
  339. {
  340.     if (!optionsPanel) {
  341.     optionsPanel = [[DataOptionsPanel allocFromZone:[self zone]] init];
  342.     [optionsPanel setOwner:self];
  343.     }
  344.     [optionsPanel showPanel:self];
  345.     return self;
  346. }
  347.  
  348.  
  349.  
  350. // Shuts up the compiler about unused RCSId
  351. - (const char *) rcsid
  352. {
  353.     return RCSId;
  354. }
  355.  
  356.  
  357. @end
  358.  
  359.  
  360. @implementation DataPane (Private)
  361.  
  362.  
  363. - _updateFunctionsMatrix
  364. {
  365.     int functionCount, counter = 0;
  366.     int fieldcount;
  367.     int row = [functionsMatrix selectedRow];
  368.     int col = [functionsMatrix selectedCol];
  369.  
  370.     [functionsScrollView loadCol:0 from:functionObjects];
  371.     if (functionCount = [functionObjects count]) {
  372.         for (counter = 0; counter < functionCount; counter++)
  373.             [[functionsMatrix cellAt:counter:0]
  374.                              setStringValue:[[functionObjects objectAt:counter]
  375.                                              stringValue]];
  376.     }
  377.  
  378.     fieldcount = [functionsMatrix cellCount];
  379.     while (counter < fieldcount)
  380.         [[functionsMatrix cellAt:counter++:0] setStringValue:""];
  381.  
  382.     [functionsMatrix selectCellAt:(row > fieldcount)? fieldcount:row :col];
  383.  
  384.     return self;
  385. }
  386.  
  387.  
  388. - _updateControlsForSelectedFunction
  389. {
  390.     id    singleCell = [functionsMatrix selectedCell];
  391.     BOOL enabled = (singleCell || [functionsMatrix multipleCellsSelected]);
  392.  
  393.     if (singleCell)
  394.     [functionsForm setStringValue:[[singleCell subObject] stringValue]];
  395.     else if (enabled)
  396.     [functionsForm setStringValue:""];
  397.  
  398.     [inspectButton setEnabled:enabled];
  399.     [deleteFunctionButton setEnabled:enabled];
  400.     [modifyFunctionButton setEnabled:singleCell? YES:NO];
  401.  
  402.     return self;
  403. }
  404.  
  405.  
  406. @end
  407.