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

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

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];
1.2       takayama  118:   [myogl setGid: gid];
                    119:   // [self showCount];
1.1       takayama  120: }
                    121:
                    122: -(void) dealloc {
                    123:   NSLog(@"dealloc of MyOpenGL instance.\n");
                    124:   // [[NSNotificationCenter defaultCenter] removeObserver: self];
                    125:   [super dealloc];
                    126: }
                    127:
                    128: -(void) closeMyOpenGL: (MyDocument *) md {
                    129:   NSLog(@"closeMyOpenGL. \n");
                    130:   [self close];
                    131: }
                    132:
                    133: -(BOOL) windowShouldClose: (NSWindow *)sender {
                    134:    // p.299 of O'reilly book.  Connect "Window --> file's owner" to connect the delegate outlet of the window
                    135:    //                          to MyOpenGLController.
                    136:    NSLog(@"x is clicked.\n");
                    137:    [MyOpenGLController removeMyOpenGLControllerWithGid: [self getGid]];
                    138:    return YES;
                    139: }
                    140: -(void) addOglComm: (NSString *)comm {
                    141:   [myogl addOglComm: comm by: self];
                    142: }
                    143: -(void) addOglInitComm: (NSString *)comm {
                    144:   [myogl addOglInitComm: comm by: self];
                    145: }
1.2       takayama  146:
                    147: -(int) countOfOglComm {return [myogl countOfOglComm];}
                    148: -(int) countOfOglInitComm {return [myogl countOfOglInitComm];}
                    149: -(int) removeLastOfOglComm {return [myogl removeLastOfOglComm];}
                    150: -(int) removeLastOfOglInitComm {return [myogl removeLastOfOglInitComm];}
                    151: -(int) removeAllOfOglComm { return [myogl removeAllOfOglComm];}
                    152: -(int) removeAllOfOglInitComm {return [myogl removeAllOfOglInitComm];}
                    153: -(NSMutableArray *) getListOfOglComm { return [myogl getListOfOglComm];}
                    154: -(NSMutableArray *) getListOfOglInitComm { return [myogl getListOfOglInitComm]; }
                    155: -(void) showEyeX: (float) x Y: (float) y Z: (float) z {
                    156:   [self clearOutput];
1.3     ! takayama  157:   [self output: [NSString stringWithFormat: @"gid=%d, n=%d, position of your eye:(%1.2f,%1.2f,%1.2f), nc=%d, ni=%d",gid,[self countOfOglComm],x,y,z,[myogl getOglCommSize],[myogl getOglInitCommSize]]];
1.2       takayama  158: }
                    159: -(void) showCount {
                    160:   [self clearOutput];
                    161:   [self output: [NSString stringWithFormat: @"gid=%d, number of OpenGL commands=%d, init=%d",
                    162:                                                gid, [self countOfOglComm], [self countOfOglInitComm]]];
                    163: }
                    164: -(void) clearOutput { [mymessage setBackgroundColor: [NSColor whiteColor]]; } //does it work?
1.1       takayama  165: -(void) output: (NSString *)msg {
                    166:   [mymessage setStringValue: msg];
                    167: }
                    168:
                    169: @end

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