diff --git a/contrib/mobile/iOS/Onelab/AppDelegate.h b/contrib/mobile/iOS/Onelab/AppDelegate.h index 570455429d78afae744317d29d48009936a37c20..90fee7680199d21e8a786c9e57450e42030d6731 100644 --- a/contrib/mobile/iOS/Onelab/AppDelegate.h +++ b/contrib/mobile/iOS/Onelab/AppDelegate.h @@ -3,8 +3,9 @@ #include "SplitViewController.h" @interface AppDelegate : UIResponder <UIApplicationDelegate>{ - @public - bool compute; + @public + bool compute; + NSMutableArray *errors; } @property (strong, nonatomic) UIWindow *window; @@ -12,4 +13,3 @@ @property (strong, nonatomic) SplitViewController *splitViewController; // iPad @end - diff --git a/contrib/mobile/iOS/Onelab/AppDelegate.mm b/contrib/mobile/iOS/Onelab/AppDelegate.mm index a8cdeca66c9cf52efee579622a145004b577520b..056014f10b23d78090ff4636947ae62d373c608a 100644 --- a/contrib/mobile/iOS/Onelab/AppDelegate.mm +++ b/contrib/mobile/iOS/Onelab/AppDelegate.mm @@ -14,7 +14,7 @@ self.splitViewController = [storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"]; } compute = false; - + errors = [[NSMutableArray alloc] init]; // Copy resource files if the version of the app has changed NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; NSString *prefsv = [prefs stringForKey:@"OnelabModelsVersion"]; diff --git a/contrib/mobile/iOS/Onelab/EAGLView.h b/contrib/mobile/iOS/Onelab/EAGLView.h index 540514329d022728de60c9ba63828dad2ee87140..32d1756a186be76d25742a6b83798c67be25fac4 100644 --- a/contrib/mobile/iOS/Onelab/EAGLView.h +++ b/contrib/mobile/iOS/Onelab/EAGLView.h @@ -11,31 +11,31 @@ Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel. */ @interface EAGLView : UIView { - -@private - /* The pixel dimensions of the backbuffer */ - GLint backingWidth; - GLint backingHeight; - - EAGLContext *context; - - /* OpenGL names for the renderbuffer and framebuffers used to render to this view */ - GLuint viewRenderbuffer, viewFramebuffer; - - /* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */ - GLuint depthRenderbuffer; - - BOOL rendering; -@public - /* our GModel drawing class */ - drawContext *mContext; - BOOL rotate; + + @private + /* The pixel dimensions of the backbuffer */ + GLint backingWidth; + GLint backingHeight; + + EAGLContext *context; + + /* OpenGL names for the renderbuffer and framebuffers used to render to this view */ + GLuint viewRenderbuffer, viewFramebuffer; + + /* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it + exists (0 if it does not exist) */ + GLuint depthRenderbuffer; + + BOOL rendering; + + @public + /* our GModel drawing class */ + drawContext *mContext; + BOOL rotate; } - (void)drawView; - (void)load:(NSString*) file; -- (UIImage*) getGLScreenshot; - @end diff --git a/contrib/mobile/iOS/Onelab/EAGLView.mm b/contrib/mobile/iOS/Onelab/EAGLView.mm index 414921a8d8e3989c8681b98f38a7f9899bcc95e6..64e54670d681aebfea8ab7e0f1da61b23d1da6d6 100644 --- a/contrib/mobile/iOS/Onelab/EAGLView.mm +++ b/contrib/mobile/iOS/Onelab/EAGLView.mm @@ -149,37 +149,4 @@ } } -- (UIImage*) getGLScreenshot -{ - NSInteger myDataLength = backingWidth * backingHeight * 4; - - GLubyte *buffer = (GLubyte *) malloc(myDataLength); - glReadPixels(0, 0, backingWidth, backingHeight, GL_RGBA, GL_UNSIGNED_BYTE, buffer); - - GLubyte *buffer2 = (GLubyte *) malloc(myDataLength); - for(int y = 0; y <backingHeight; y++){ - for(int x = 0; x <backingWidth * 4; x++){ - buffer2[(backingHeight - 1 - y) * backingWidth * 4 + x] = buffer[y * 4 * backingWidth + x]; - } - } - - CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer2, myDataLength, NULL); - - int bitsPerComponent = 8; - int bitsPerPixel = 32; - int bytesPerRow = 4 * backingWidth; - CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); - CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault; - CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; - - CGImageRef imageRef = CGImageCreate(backingWidth, backingHeight, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent); - free(buffer); - free(buffer2); - return [UIImage imageWithCGImage:imageRef]; -} - -- (void)saveGLScreenshotToPhotosAlbum { - UIImageWriteToSavedPhotosAlbum([self getGLScreenshot], nil, nil, nil); -} - @end diff --git a/contrib/mobile/iOS/Onelab/ModelViewController.h b/contrib/mobile/iOS/Onelab/ModelViewController.h index 9605d32442ea1347904873d3baa2c11a2f7d30c5..279e59f834089f0ac93a471d2ccb579957fab3f3 100644 --- a/contrib/mobile/iOS/Onelab/ModelViewController.h +++ b/contrib/mobile/iOS/Onelab/ModelViewController.h @@ -7,14 +7,13 @@ @interface ModelViewController : UIViewController <UISplitViewControllerDelegate, UIAlertViewDelegate> { - @private - double scaleFactor; - UIBarButtonItem *_runStopButton, *_playButton, *_stopButton; - UIAlertView *_loadingAlert; - UIErrorAlertView *_errorAlert; - NSMutableArray *_errors; - UIBackgroundTaskIdentifier _computeBackgroundTaskIdentifier; - NSTimer *_animation; + @private + double scaleFactor; + UIBarButtonItem *_runStopButton, *_playButton, *_stopButton; + UIAlertView *_loadingAlert; + UIErrorAlertView *_errorAlert; + UIBackgroundTaskIdentifier _computeBackgroundTaskIdentifier; + NSTimer *_animation; } - (IBAction)pinch:(UIPinchGestureRecognizer *)sender; diff --git a/contrib/mobile/iOS/Onelab/ModelViewController.mm b/contrib/mobile/iOS/Onelab/ModelViewController.mm index cd7d5c051f62c61d3ad18df1b27298f1de17ce56..b8ceaa7b3f0bee7558110e399d9a440836cd5965 100644 --- a/contrib/mobile/iOS/Onelab/ModelViewController.mm +++ b/contrib/mobile/iOS/Onelab/ModelViewController.mm @@ -76,6 +76,12 @@ //[_loadingAlert release]; _loadingAlert = nil; } + + AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; + if(appDelegate->errors.count > 0){ + _errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[appDelegate->errors firstObject] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil]; + [_errorAlert show]; + } } - (void)viewDidLoad @@ -85,20 +91,18 @@ [self configureView]; [_singleTap requireGestureRecognizerToFail:_doubleTap]; scaleFactor = 1.; - _errors = [[NSMutableArray alloc] init]; setObjCBridge((__bridge void*) self); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestRender) name:@"requestRender" object:nil]; _runStopButton = [[UIBarButtonItem alloc] initWithTitle:@"Run" style:UIBarButtonItemStylePlain target:self action:@selector(compute)]; - //UIBarButtonItem *share = [[UIBarButtonItem alloc] initWithTitle:@"Share" style:UIBarButtonItemStyleBordered target:self action:@selector(share)]; if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]){ UIBarButtonItem *model = [[UIBarButtonItem alloc] initWithTitle:@"Model list" style:UIBarButtonItemStylePlain target:self action:@selector(showModelsList)]; - [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:_runStopButton, model, /*share,*/ nil]]; + [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:_runStopButton, model, nil]]; } else { UIBarButtonItem *settings = [[UIBarButtonItem alloc] initWithTitle:@"Parameters" style:UIBarButtonItemStylePlain target:self action:@selector(showSettings)]; - [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:_runStopButton, settings, /*share,*/ nil]]; + [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:_runStopButton, settings, nil]]; } UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; @@ -131,16 +135,8 @@ [[UIApplication sharedApplication] endBackgroundTask: _computeBackgroundTaskIdentifier]; } --(void)share -{ - NSArray *dataToShare = @[[self.glView getGLScreenshot]]; - UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil]; - [self presentViewController:activityVC animated:YES completion:nil]; -} - - (void)compute { - [_errors removeAllObjects]; [_runStopButton setAction:@selector(stop)]; [_runStopButton setTitle:@"Stop"]; [_progressLabel setText:@""]; @@ -186,8 +182,9 @@ [_progressLabel setHidden:YES]; [_progressIndicator stopAnimating]; [_progressIndicator setHidden:YES]; - if(_errors.count > 0) { - _errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles:@"Show more", nil]; + AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; + if(appDelegate->errors.count > 0){ + _errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[appDelegate->errors firstObject] delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil, nil]; [_errorAlert show]; } } @@ -317,32 +314,23 @@ -(void)addError:(std::string)msg { - [_errors addObject:[Utils getStringFromCString:msg.c_str()]]; + AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; + [appDelegate->errors addObject:[Utils getStringFromCString:msg.c_str()]]; } -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { - if(buttonIndex == 0) { - [_errors removeAllObjects]; - return; - } - else [_errors removeLastObject]; - if(_errors.count > 1) - _errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles:@"Show more", nil]; - else - _errorAlert = [[UIErrorAlertView alloc] initWithTitle:@"Error" message:[_errors lastObject] delegate:self cancelButtonTitle:@"Hide" otherButtonTitles: nil]; - [_errorAlert show]; + AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; + [appDelegate->errors removeAllObjects]; } #pragma mark - Split view - -(BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation { return NO; } - void messageFromCpp (void *self, std::string level, std::string msg) { if(level == "RequestRender"){