home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / Gnuplot / Source / ThreeDPane.m < prev    next >
Encoding:
Text File  |  1993-03-18  |  7.1 KB  |  359 lines

  1.  
  2. static char RCSId[]="$Id: ThreeDPane.m,v 1.1.1.1 1993/03/18 03:36:18 davis Exp $";
  3.  
  4.  
  5. #import <appkit/Application.h>
  6. #import <appkit/Box.h>
  7. #import <appkit/Matrix.h>
  8. #import <appkit/Slider.h>
  9. #import <appkit/TextField.h>
  10. #import <appkit/TextFieldCell.h>
  11. #import <appkit/View.h>
  12.  
  13. #import "ContourOptionsPanel.h"
  14. #import "GnuplotPlot.h"
  15. #import "Status.h"
  16. #import "StatusContour.h"
  17. #import "ThreeDPane.h"
  18.  
  19.  
  20. #define    SURF_WIREFRAME    0
  21. #define    SURF_OPAQUE    1
  22. #define    SURF_INVISIBLE    2
  23.  
  24.  
  25. @interface ThreeDPane (Private)
  26.  
  27. - _updateRotationIsThreeD:(BOOL)isThreeD;
  28. - _updateContourIsThreeD:(BOOL)isThreeD;
  29. - _updateSurfaceTypeIsThreeD:(BOOL)isThreeD;
  30. - _updateIsoSamplesIsThreeD:(BOOL)isThreeD;
  31.  
  32. @end
  33.  
  34.  
  35.  
  36.  
  37. @implementation ThreeDPane
  38.  
  39.  
  40. - init
  41. {
  42.     [super init];
  43.  
  44.     [NXApp loadNibSection: "ThreeDPane.nib"
  45.             owner: self
  46.         withNames: NO
  47.          fromZone: [self zone]];
  48.  
  49.     view = [window setContentView:[[View alloc] init]];
  50.     icon = "InspectorThreeD.tiff";
  51.  
  52.     return self;
  53. }
  54.  
  55.  
  56. /*  
  57.  *  Overridden from Pane.
  58.  */
  59. - selectControl:sender
  60. {
  61.     [isoSamplesMatrix selectText:self];
  62.     return self;
  63. }
  64.  
  65.  
  66. - (BOOL)updateStatus:aStatus doc:aDoc
  67. {
  68.     id oldStatus = status;
  69.     id oldDoc = doc;
  70.  
  71.     /*  
  72.      *  We only bother updating if status has changed since we last 
  73.      *  updated, or if we just became the current pane (didSwap) -- 
  74.      *  assuming that status and aDoc are non-nil, of course.
  75.      */
  76.  
  77.     if ([super updateStatus:aStatus doc:aDoc]
  78.     && ((status != oldStatus) || didSwap)) {
  79.  
  80.     BOOL isThreeD, isPolar;
  81.     Window *viewWindow;
  82.  
  83.     [(viewWindow = [view window]) disableDisplay];
  84.  
  85.         [threeDButton setState:(isThreeD = [status isThreeD])];
  86.         [threeDButton setEnabled:!(isPolar = [status isPolar])];
  87.  
  88.         [self _updateRotationIsThreeD:isThreeD];
  89.     [self _updateContourIsThreeD:isThreeD];
  90.     [self _updateSurfaceTypeIsThreeD:isThreeD];
  91.     [self _updateIsoSamplesIsThreeD:isThreeD];
  92.  
  93.     [viewWindow reenableDisplay];
  94.  
  95.     [self perform:@selector(selectControl:)
  96.          with:self
  97.        afterDelay:1
  98.        cancelPrevious:YES];
  99.  
  100.     didSwap = NO;
  101.     return YES;
  102.     }
  103.  
  104.     return NO;
  105. }
  106.  
  107.  
  108. - (BOOL)forceUpdateStatus:aStatus doc:aDoc
  109. {
  110.     if ([[contourOptionsPanel panel] isVisible])
  111.     [contourOptionsPanel forceUpdate];
  112.  
  113.     return [super forceUpdateStatus:aStatus doc:aDoc];
  114. }
  115.  
  116.  
  117.  
  118. - didSwapIn:sender
  119. {
  120.     [super didSwapIn:self];
  121.     didSwap = YES;
  122.     return self;
  123. }
  124.  
  125.  
  126. - doSetThreeD:sender
  127. {
  128.     BOOL isThreeD;
  129.  
  130.     [status setThreeD:isThreeD = [sender state]];
  131.  
  132.     /*  
  133.      *  Settings changes that might affect other controls in the same 
  134.      *  pane should update the pane using the current status and doc.
  135.      */
  136.  
  137.     [self forceUpdateStatus:status doc:doc];
  138.     [view display];
  139.  
  140.     return self;
  141. }
  142.  
  143.  
  144. - doSetSurfaceType:sender
  145. {
  146.     BOOL oldReport = [status report];
  147.  
  148.     [status setReport:NO];
  149.  
  150.     switch ([surfaceTypeMatrix selectedTag]) {
  151.     case SURF_WIREFRAME:
  152.     [status setSurface:YES];
  153.     [status setHiddenThreeD:NO];
  154.     break;
  155.     case SURF_OPAQUE:
  156.     [status setSurface:YES];
  157.     [status setHiddenThreeD:YES];
  158.     break;
  159.     case SURF_INVISIBLE:
  160.     [status setSurface:NO];
  161.     [status setHiddenThreeD:NO];
  162.     break;
  163.     }
  164.  
  165.     [status setReport:oldReport];
  166.     [status reportSettingsChange:self];
  167.  
  168.     [self forceUpdateStatus:status doc:doc];
  169.     [view display];
  170.  
  171.     return self;
  172. }
  173.  
  174.  
  175. - doSetIsoSamples:sender
  176. {
  177.     return [status setIsoSamplesCoord:[sender selectedTag]
  178.                    to:[sender intValue]];
  179. }
  180.  
  181.  
  182. - doSetRotation:sender
  183. {
  184.     if (sender == rotMatrix)
  185.     [status setRotCoord:[sender selectedTag]
  186.              to:[[sender selectedCell] floatValue]];
  187.     else
  188.     if (sender == rotZSlider)
  189.         [status setRotCoord:Z_TAG to:359.0 - [sender floatValue]];
  190.     else
  191.         [status setRotCoord:[sender tag] to:[sender floatValue]];
  192.  
  193.     [self _updateRotationIsThreeD:[status isThreeD]];
  194.     return self;
  195. }
  196.  
  197.  
  198. - doResetRotation:sender
  199. {
  200.     [status resetRotation];
  201.     [self _updateRotationIsThreeD:[status isThreeD]];
  202.     return self;
  203. }
  204.  
  205.  
  206. - doSetContourBase:sender
  207. {
  208.     return [status setContourBase:[sender state]];
  209. }
  210.  
  211.  
  212. - doSetContourSurface:sender
  213. {
  214.     return [status setContourSurface:[sender state]];
  215. }
  216.  
  217.  
  218. - showContourOptionsPanel:sender
  219. {
  220.     if (!contourOptionsPanel)
  221.     contourOptionsPanel = [[ContourOptionsPanel allocFromZone:[self zone]]
  222.                    init];
  223.     [contourOptionsPanel showPanel:self];
  224.     return self;
  225. }
  226.  
  227.  
  228.  
  229. - windowDidUpdate:sender
  230. {
  231.     return self;
  232. }
  233.  
  234.  
  235. // Shuts up the compiler about unused RCSId
  236. - (const char *) rcsid
  237. {
  238.     return RCSId;
  239. }
  240.  
  241.  
  242. @end
  243.  
  244.  
  245.  
  246. @implementation ThreeDPane (Private)
  247.  
  248. - _updateRotationIsThreeD:(BOOL)isThreeD
  249. {
  250.     float aFloat;
  251.     Box *aBox;
  252.     Cell *aCell;
  253.     BOOL wasEnabled;
  254.  
  255.     [rotXSlider setFloatValue:aFloat = [status rotCoord:X_TAG]];
  256.     [rotXSlider setEnabled: isThreeD];
  257.     [aCell = [rotMatrix findCellWithTag:X_TAG] setFloatValue:aFloat];
  258.     [aCell setEnabled: isThreeD];
  259.  
  260.     [rotZSlider setFloatValue:359.0 - (aFloat = [status rotCoord:Z_TAG])];
  261.     [rotZSlider setEnabled: isThreeD];
  262.     [aCell = [rotMatrix findCellWithTag:Z_TAG] setFloatValue:aFloat];
  263.     [aCell setEnabled: isThreeD];
  264.  
  265.     [rotationResetButton setEnabled:isThreeD];
  266.  
  267.     /* 
  268.      *  If the plot is not threeD, we'll make the text title of the 
  269.      *  box dark gray to indicate that all 3d rotation is disabled.  
  270.      *  We only redisplay if the enabledment changes.
  271.      */
  272.     wasEnabled = [[aBox = [[rotXSlider superview] superview] cell] isEnabled];
  273.     if (wasEnabled != isThreeD)
  274.         [[aBox cell] setEnabled: isThreeD];
  275.  
  276.     return self;
  277. }
  278.  
  279.  
  280. - _updateContourIsThreeD:(BOOL)isThreeD
  281. {
  282.     Box *aBox;
  283.     BOOL wasEnabled;
  284.     BOOL isOpaque = [status hiddenThreeD];
  285.  
  286.     wasEnabled = [[aBox = [[contourBaseButton superview] superview]
  287.            cell] isEnabled];
  288.     if (wasEnabled != isThreeD)
  289.         [[aBox cell] setEnabled: isThreeD];
  290.  
  291.     [contourBaseButton setState:[status contourBase]];
  292.     [contourBaseButton setEnabled:isThreeD];
  293.  
  294.     /* 
  295.      * Contours on surfaces don't seem to show up when hidden line 
  296.      * removal is turned on (in 3.3 beta).
  297.      */
  298.  
  299.     [contourSurfaceButton setState:[status contourSurface] && !isOpaque];
  300.     [contourSurfaceButton setEnabled:isThreeD && !isOpaque];
  301.  
  302.     [contourOptionsButton setEnabled:isThreeD];
  303.  
  304.     return self;
  305. }
  306.  
  307.  
  308.  
  309. - _updateSurfaceTypeIsThreeD:(BOOL)isThreeD
  310. {
  311.     Box *aBox;
  312.     BOOL wasEnabled;
  313.  
  314.     wasEnabled = [[aBox = [[surfaceTypeMatrix superview] superview]
  315.            cell] isEnabled];
  316.     if (wasEnabled != isThreeD)
  317.         [[aBox cell] setEnabled: isThreeD];
  318.  
  319.     if ([status surface]) {
  320.     if ([status hiddenThreeD])
  321.         [surfaceTypeMatrix selectCellWithTag:SURF_OPAQUE];
  322.     else
  323.         [surfaceTypeMatrix selectCellWithTag:SURF_WIREFRAME];
  324.     } else
  325.     [surfaceTypeMatrix selectCellWithTag:SURF_INVISIBLE];
  326.  
  327.     [surfaceTypeMatrix setEnabled:isThreeD];
  328.  
  329.     return self;
  330. }
  331.  
  332.  
  333.  
  334. - _updateIsoSamplesIsThreeD:(BOOL)isThreeD
  335. {
  336.     BOOL wasEnabled;
  337.     Box *aBox;
  338.  
  339.     [[isoSamplesMatrix findCellWithTag:X_TAG] setIntValue:
  340.      [status isoSamples:X_TAG]];
  341.  
  342.     [[isoSamplesMatrix findCellWithTag:Y_TAG] setIntValue:
  343.      [status isoSamples:Y_TAG]];
  344.  
  345.     [isoSamplesMatrix setEnabled:isThreeD];
  346.     [isoSamplesLabel setTextGray: isThreeD? NX_BLACK: NX_DKGRAY];
  347.  
  348.     wasEnabled = [[aBox = [[isoSamplesMatrix superview]
  349.                          superview] cell] isEnabled];
  350.     if (wasEnabled != isThreeD)
  351.     [[aBox cell] setEnabled: isThreeD];
  352.  
  353.     return self;
  354. }
  355.  
  356.  
  357.  
  358. @end
  359.