[BACK]Return to MyOpenGLController.m CVS log [TXT][DIR] Up to [local] / OpenXM / src / cfep

Annotation of OpenXM/src/cfep/MyOpenGLController.m, Revision 1.1.1.1

1.1       takayama    1: //
                      2: //  MyOpenGLController.m
                      3: //  cfep
                      4: //
                      5: //  Created by Nobuki Takayama on 06/02/18.
                      6: //  Copyright 2006 OpenXM.org. All rights reserved.
                      7: //
                      8:
                      9: #import "MyOpenGLController.h"
                     10:
                     11: // MyOpenGL window id (gid) is an indeger.
                     12: static MyOpenGLController *oglWindow[GID_MAX];  // gid --> MyOpenGLController instance.
                     13: static MyDocument *oglParent[GID_MAX];           // gid --> parent MyDocument.
                     14: static int MyOpenGLControllerInitialized = 0;
                     15: static int Gid=0;
                     16:
                     17:
                     18: @implementation MyOpenGLController
                     19: +(void) initMyOpenGLController {
                     20:   int i;
                     21:   if (MyOpenGLControllerInitialized) return;
                     22:   for (i=0; i<GID_MAX; i++) { oglWindow[i] = nil; oglParent[i] = nil; }
                     23:   MyOpenGLControllerInitialized = 1;
                     24: }
                     25: +(MyOpenGLController *)getOglWindow: (int) tid {
                     26:   return oglWindow[tid];
                     27: }
                     28: +(MyDocument *)getOglParent: (int) tid {
                     29:   return oglParent[tid];
                     30: }
                     31:
                     32: +(int) myOpenGLControllerOwnedBy: (MyDocument *) owner with: (int) tid {
                     33:    MyOpenGLController *ogl;
                     34:    if ((tid >= 0) && (tid <GID_MAX)) {
                     35:      if (oglWindow[tid]) return tid;
                     36:         else {
                     37:                ogl = [[MyOpenGLController allocWithZone:[MyOpenGLController zone]] init];
                     38:                [ogl setGid: tid];
                     39:                [ogl retain];
                     40:                [ogl showWindow: nil];
                     41:                oglWindow[tid] = ogl;
                     42:                oglParent[tid] = owner;
                     43:                return tid;
                     44:        }
                     45:    }
                     46:    return -1;
                     47: }
                     48: +(int) myOpenGLControllerOwnedBy: (MyDocument *) owner {
                     49:    int tid;
                     50:
                     51:    [MyOpenGLController initMyOpenGLController];
                     52:    tid = Gid;
                     53:    if (tid < GID_MAX) {
                     54:     Gid++;
                     55:        return [MyOpenGLController myOpenGLControllerOwnedBy: owner with: tid];
                     56:    }else{
                     57:     return -1;
                     58:    }
                     59: }
                     60: +(void) removeMyOpenGLControllerOwnedBy: (MyDocument *) owner {
                     61:   int i;
                     62:   [MyOpenGLController initMyOpenGLController];
                     63:   for (i=0; i<GID_MAX; i++) {
                     64:     if (oglParent[i] == owner) {
                     65:           [MyOpenGLController removeMyOpenGLControllerWithGid: i];
                     66:        }
                     67:   }
                     68: }
                     69: +(MyOpenGLController *) removeMyOpenGLControllerWithGid: (int) tid {
                     70:   MyOpenGLController *oglC;
                     71:   [MyOpenGLController initMyOpenGLController];
                     72:   oglC = oglWindow[tid];
                     73:   if (oglWindow[tid]) [oglWindow[tid] closeMyOpenGL: oglParent[tid]];
                     74:   oglWindow[tid] = nil;
                     75:   oglParent[tid] = nil;
                     76:   [oglC autorelease]; // it is OK?
                     77:   return oglC;
                     78: }
                     79:
                     80: /*  They are put at oxEvaluateSelected in MyDocument.m to test the system. --> gtest.rr
                     81:    [MyOpenGLController addOglComm: @"[glColor4f,1.0,0.0,0.0,1.0]" to: 0 from: self];
                     82:    [MyOpenGLController addOglComm: @"[glRectf,-0.5,-0.5,0.5,0.5]" to: 0 from: self];
                     83:    [MyOpenGLController addOglComm: @"[glib_flush0]" to: 0 from: self];
                     84: */
                     85:
                     86: +(void) addOglComm:     (NSString *)comm to: (int) tid from: (MyDocument *) owner {
                     87:   if ((0<=tid) && (tid<GID_MAX)) {
                     88:        if (oglWindow[tid] == nil) {
                     89:          tid = [MyOpenGLController myOpenGLControllerOwnedBy: owner with: tid];
                     90:        }
                     91:     if (tid >= 0) [oglWindow[tid] addOglComm: comm];
                     92:   }else ;
                     93: }
                     94: +(void) addOglInitComm: (NSString *)comm to: (int) tid from: (MyDocument *) owner {
                     95:   if ((0<=tid) && (tid<GID_MAX)) {
                     96:        if (oglWindow[tid] == nil) {
                     97:          tid = [MyOpenGLController myOpenGLControllerOwnedBy: owner with: tid];
                     98:        }
                     99:     if (tid >= 0) [oglWindow[tid] addOglInitComm: comm];
                    100:   }else ;
                    101: }
                    102:
                    103:
                    104: -(id) init {
                    105:   self = [self initWithWindowNibName: @"MyOpenGL"];
                    106:   if (self) [self setWindowFrameAutosaveName: @"cfep OpenGLView"];
                    107:   return self;
                    108: }
                    109: -(void) setGid: (int) mygid {
                    110:   gid = mygid;
                    111: }
                    112: -(int)getGid {
                    113:   return gid;
                    114: }
                    115:
                    116: -(void) windowDidLoad {
                    117:   [super windowDidLoad];
                    118: }
                    119:
                    120: -(void) dealloc {
                    121:   NSLog(@"dealloc of MyOpenGL instance.\n");
                    122:   // [[NSNotificationCenter defaultCenter] removeObserver: self];
                    123:   [super dealloc];
                    124: }
                    125:
                    126: -(void) closeMyOpenGL: (MyDocument *) md {
                    127:   NSLog(@"closeMyOpenGL. \n");
                    128:   [self close];
                    129: }
                    130:
                    131: -(BOOL) windowShouldClose: (NSWindow *)sender {
                    132:    // p.299 of O'reilly book.  Connect "Window --> file's owner" to connect the delegate outlet of the window
                    133:    //                          to MyOpenGLController.
                    134:    NSLog(@"x is clicked.\n");
                    135:    [MyOpenGLController removeMyOpenGLControllerWithGid: [self getGid]];
                    136:    return YES;
                    137: }
                    138: -(void) addOglComm: (NSString *)comm {
                    139:   [myogl addOglComm: comm by: self];
                    140: }
                    141: -(void) addOglInitComm: (NSString *)comm {
                    142:   [myogl addOglInitComm: comm by: self];
                    143: }
                    144: -(void) output: (NSString *)msg {
                    145:   [mymessage setStringValue: msg];
                    146: }
                    147:
                    148: @end

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>