=================================================================== RCS file: /home/cvs/OpenXM/src/cfep/MyDocument.m,v retrieving revision 1.2 retrieving revision 1.9 diff -u -p -r1.2 -r1.9 --- OpenXM/src/cfep/MyDocument.m 2006/03/06 08:55:31 1.2 +++ OpenXM/src/cfep/MyDocument.m 2011/07/15 22:57:34 1.9 @@ -18,7 +18,17 @@ static int myDocumentSaidTheMessageAboutX = 0; @implementation MyDocument +static int NoEngine = 0; // experimental. +static NSMenuItem *menuItemNoEngine = nil; // NoEngine +// For OnState or OffState in the execution menu +static NSMenuItem *menuItemNotebookMode = nil; +static NSMenuItem *menuItemBasicMode = nil; +static NSMenuItem *menuItemRisaAsir = nil; +static NSMenuItem *menuItemKanSm1 = nil; +static NSMenuItem *menuItemOutputDebugMessages = nil; //cf. debugMyTunnel; +static NSMenuItem *menuItemPrettyPrint = nil; // prettyPrint. + - (void)dealloc { MyOutputWindowController *mowc; if (myDebug) NSLog(@"dealloc of MyDocument.\n"); @@ -64,6 +74,10 @@ static int myDocumentSaidTheMessageAboutX = 0; [self addMenuExec]; // adding the execution menu. [textViewIn setAllowsUndo:YES]; if ([textViewIn isContinuousSpellCheckingEnabled]) [textViewIn toggleContinuousSpellChecking: self]; // Turn off the spell checking. + if ([MyEnvironment isX11Installed] != 1) + [self messageDialog: NSLocalizedString(@"X11 is not installed. To install it, insert MacOS DVD1 and open Optional install->Applications->X11",nil) with: 0]; +// if ([MyEnvironment isGccInstalled] != 1) +// [self messageDialog: NSLocalizedString(@"gcc is not installed. To install it, insert MacOS DVD1 and open Xcode Tools->XcodeTools.mpkg",nil) with: 0]; [self sayTheMessageAboutX]; [self initAux]; } @@ -140,6 +154,7 @@ static int myDocumentSaidTheMessageAboutX = 0; myDecoder = [[MyDecoder alloc] init]; [myDecoder retain]; [self openMyModel: myEnvironment ]; + [MyOpenGLController initMyOpenGLController]; // For the second execution, it will do nothing. } -(int) getMyDocumentKey { return myDocumentKey; } @@ -156,6 +171,8 @@ static int myDocumentSaidTheMessageAboutX = 0; [peerEndEvaluteMark retain]; [self stopIndicator]; + if (NoEngine && (!restartMode)) { task = nil; return; } + // Initialization to call /bin/bash outboundPipe = [NSPipe pipe]; // since autorelease is called in pipe. inboundPipe = [NSPipe pipe]; @@ -218,6 +235,7 @@ static int myDocumentSaidTheMessageAboutX = 0; -(id) restartMyModel: (enum peer_type) peerType { MyEnvironment *myEnvironment; + restartMode = 1; [self closeMyModel]; myEnvironment = [[MyEnvironment alloc] initFor: peerType]; //BUG. leak memory? [myEnvironment retain]; @@ -231,8 +249,11 @@ static int myDocumentSaidTheMessageAboutX = 0; NSLog(@"myDocumentSaidTheMessageAboutX=%d\n",myDocumentSaidTheMessageAboutX); if (!myDocumentSaidTheMessageAboutX) { if ([MyEnvironment checkX] != 1) - [self messageDialog: - NSLocalizedString(@"A few commands (plot, ...) cannot be used, because X11 is not running.",nil) with: 0]; + // [self messageDialog: + // NSLocalizedString(@"A few commands (plot, ...) cannot be used, because X11 is not running.",nil) with: 0]; + [self changeOutputCounterFieldWithString: + [NSLocalizedString(@"Output mini-view: ",nil) stringByAppendingString: + NSLocalizedString(@"A few commands (plot, ...) cannot be used, because X11 is not running.",nil)]]; myDocumentSaidTheMessageAboutX = 1; } } @@ -242,6 +263,7 @@ static int myDocumentSaidTheMessageAboutX = 0; NSMutableString *cmd; NSRange r; + if (!task) return; if (inEvaluation) { NSLog(@"In evaluatioin. "); [self messageDialog: NSLocalizedString(@"Evaluating...",nil) with: 0]; @@ -274,7 +296,13 @@ static int myDocumentSaidTheMessageAboutX = 0; [textViewIn replaceCharactersInRange: NSMakeRange(pos,0) withString: @"\n"]; } cmd0 = [cmd0 substringWithRange:r ]; - } + } + [self outputBorderLine: [NSColor magentaColor]]; + [self outputString: cmd0]; + if ([cmd0 length] > 0) { + if ([cmd0 characterAtIndex: ([cmd0 length]-1)] != 0xa) [self outputString: @"\n"]; + } + [self outputBorderLine: [NSColor yellowColor]]; }else{ cmd0 = [textViewIn string]; MyOutputWindowController *mc; @@ -304,7 +332,7 @@ static int myDocumentSaidTheMessageAboutX = 0; [alert release]; fprintf(stderr,"Trying to interrupt.\n"); - [task interrupt]; + if (task) [task interrupt]; inputCounter = outputCounter = 0; [self stopIndicator]; [myDecoder reset]; @@ -361,6 +389,7 @@ static int myDocumentSaidTheMessageAboutX = 0; NSLog(@"Evaluating... "); NSLog(@"%@",cmd); // Evaluation is here. + if (!task) return -1; cmdInData = [cmd dataUsingEncoding: NSUTF8StringEncoding]; @try { //todo if (yes) [outboundFileHandle writeData: peerStartEvaluateMark]; @@ -388,9 +417,15 @@ static int myDocumentSaidTheMessageAboutX = 0; else { MyOutputWindowController *mc; mc = [MyOutputWindowController sharedMyOutputWindowController: self]; - [mc outputStringToOutputWindow: amt]; + if (prettyPrint) [mc outputStringToOutputWindow: amt withColor: [NSColor blueColor]]; + else [mc outputStringToOutputWindow: amt]; } } +-(void)outputBorderLine: (NSColor *)color { + MyOutputWindowController *mc; + mc = [MyOutputWindowController sharedMyOutputWindowController: self]; + [mc outputStringToOutputWindow: @"----------------------------------------\n" withColor: color]; +} - (void) outputErrorString: (NSString *) amt { int oldEnd; int newEnd; @@ -976,6 +1011,8 @@ int debugInbound = 0; NSRange r; NSRange r3; int currentLine,i; + [self outputErrorString: NSLocalizedString(@"Move to the line ",nil)]; + [self outputErrorString: [NSString stringWithFormat: @"%d\n",line]]; // move the selection to the line line. s = [textViewIn string]; if (onlySelectedArea || notebookMode) r = [textViewIn selectedRange]; @@ -996,6 +1033,8 @@ int debugInbound = 0; } -(int) gotoNextError: (id) sender{ int n; + if (onlySelectedArea || notebookMode) + [self outputErrorString: NSLocalizedString(@"The next error action will not work properly in this mode.\n",nil)]; n = [self nextLine: 0]; if (n >= 0) { [self gotoLine: n]; return n;} else return -1; @@ -1011,6 +1050,7 @@ int debugInbound = 0; return -1; } gid = [[a objectAtIndex: 0] intValue]; + if ([[a objectAtIndex: 1] hasPrefix: @"meta"]) {[self openGLMeta: [a objectAtIndex: 1] to: gid]; return; } [MyOpenGLController addOglComm: [a objectAtIndex: 1] to: gid from: self]; return 0; } @@ -1026,7 +1066,52 @@ int debugInbound = 0; [MyOpenGLController addOglInitComm: [a objectAtIndex: 1] to: gid from: self]; return 0; } +-(void)openGLMeta: (NSString *) cmd to: (int) gid{ + MyOpenGLController *oglc; + oglc = [MyOpenGLController getOglWindow: gid]; + if (!oglc) {[self printErrorMessage: + [NSString stringWithFormat: @"Invalid gid %d in openGLMeta command %@\n",gid,cmd]]; return; } + if ([cmd hasPrefix: @"meta_showListOfOglComm"]) { + [self showListOfOglComm: gid]; return ; + }else if ([cmd hasPrefix: @"meta_removeAllInit"]) { // longer command must come first, because we use prefix. + [oglc removeAllOfOglInitComm]; + }else if ([cmd hasPrefix: @"meta_removeLastInit"]) { + [oglc removeLastOfOglInitComm]; + }else if ([cmd hasPrefix: @"meta_removeAll"]) { + [oglc removeAllOfOglComm]; + }else if ([cmd hasPrefix: @"meta_removeLast"]) { + [oglc removeLastOfOglComm]; + }else{ + [self printErrorMessage: [NSString stringWithFormat: @"Unknown OpenGL meta command %@\n",cmd]]; + } +} +-(void) showListOfOglComm: (int) gid { + MyDocument *md; + MyOpenGLController *oglc; + NSMutableArray *comm; + int i,n; + md = self; + oglc = [MyOpenGLController getOglWindow: gid]; + if (!oglc) {[self outputErrorString: @"Invalid gid in showListOfOglComm\n"]; return; } + comm = [oglc getListOfOglInitComm]; + n = [comm count]; + [md outputString: NSLocalizedString(@"OpenGL init commands\n",nil)]; + for (i=0; i