diff --git a/contrib/mobile/iOS/Onelab/AboutViewController.mm b/contrib/mobile/iOS/Onelab/AboutViewController.mm index 9bd2d9840afc6f242c0fc8b958e56986142794b4..cd6812230e8fc152ffc5c5b9585986834a6a7729 100644 --- a/contrib/mobile/iOS/Onelab/AboutViewController.mm +++ b/contrib/mobile/iOS/Onelab/AboutViewController.mm @@ -12,37 +12,37 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { - self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; - if (self) { - // Custom initialization - } - return self; + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) { + // Custom initialization + } + return self; } - (void)viewDidLoad { - [super viewDidLoad]; - // Do any additional setup after loading the view. - [self.aboutView loadHTMLString:[NSString stringWithFormat:@"<center><h3>Onelab/Mobile</h3>Version %@<p>Copyright (C) 2014 Christophe Geuzaine and Maxime Graulich, University of Liège</p><p>Visit <a href=\"http://onelab.info/\">http://onelab.info/</a> for more information</p><p>This version of Onelab/Mobile contains:</p><h3>Gmsh</h3>Version %s (<i>Build date:</i> %s)<p>Copyright (C) 1997-2014 Christophe Geuzaine and Jean-François Remacle</p><p><a href=\"http://geuz.org/gmsh/doc/CREDITS.txt\">Credits</a> and <a href=\"http://geuz.org/gmsh/doc/LICENSE.txt\">licensing information</a></p><p><i>Build options:</i> %s</p><p>Visit <a href=\"http://gmsh.info/\">http://gmsh.info</a> for more information</p><h3>GetDP</h3>Version %s (<i>Build date:</i> %s)<p>Copyright (C) 1997-2014 Patrick Dular and Christophe Geuzaine, University of Liège</p><p><a href=\"http://geuz.org/getdp/doc/CREDITS.txt\">Credits</a> and <a href=\"http://geuz.org/getdp/doc/LICENSE.txt\">licensing information</a></p><p><i>Build options:</i> %s</p><p>Visit <a href=\"http://getdp.info\">http://getdp.info</a> for more information</p></center>", - [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"], - GMSH_VERSION, - GMSH_DATE, - GMSH_CONFIG_OPTIONS, - GETDP_VERSION, - GETDP_DATE, - GETDP_CONFIG_OPTIONS] - baseURL:nil]; - + [super viewDidLoad]; + // Do any additional setup after loading the view. + [self.aboutView loadHTMLString:[NSString stringWithFormat:@"<center><h3>Onelab/Mobile</h3>Version %@<p>Copyright (C) 2014 Christophe Geuzaine and Maxime Graulich, University of Liège</p><p>Visit <a href=\"http://onelab.info/\">http://onelab.info/</a> for more information</p><p>This version of Onelab/Mobile contains:</p><h3>Gmsh</h3>Version %s (<i>Build date:</i> %s)<p>Copyright (C) 1997-2014 Christophe Geuzaine and Jean-François Remacle</p><p><a href=\"http://geuz.org/gmsh/doc/CREDITS.txt\">Credits</a> and <a href=\"http://geuz.org/gmsh/doc/LICENSE.txt\">licensing information</a></p><p><i>Build options:</i> %s</p><p>Visit <a href=\"http://gmsh.info/\">http://gmsh.info</a> for more information</p><h3>GetDP</h3>Version %s (<i>Build date:</i> %s)<p>Copyright (C) 1997-2014 Patrick Dular and Christophe Geuzaine, University of Liège</p><p><a href=\"http://geuz.org/getdp/doc/CREDITS.txt\">Credits</a> and <a href=\"http://geuz.org/getdp/doc/LICENSE.txt\">licensing information</a></p><p><i>Build options:</i> %s</p><p>Visit <a href=\"http://getdp.info\">http://getdp.info</a> for more information</p></center>", + [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"], + GMSH_VERSION, + GMSH_DATE, + GMSH_CONFIG_OPTIONS, + GETDP_VERSION, + GETDP_DATE, + GETDP_CONFIG_OPTIONS] + baseURL:nil]; + } - (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. } /* -#pragma mark - Navigation + #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender diff --git a/contrib/mobile/iOS/Onelab/AppDelegate.mm b/contrib/mobile/iOS/Onelab/AppDelegate.mm index cf6b31b2ab07ec9f8ec923cd096aa67da68462a1..64579b9e7ebce4cbc3eb2ad829e2dc3bc1bacc18 100644 --- a/contrib/mobile/iOS/Onelab/AppDelegate.mm +++ b/contrib/mobile/iOS/Onelab/AppDelegate.mm @@ -6,54 +6,74 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - // Override point for customization after application launch. - self.modelListController = (ModelListController *)self.window.rootViewController; - if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]) { - UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPadStoryboard" bundle:nil]; - self.splitViewController = [storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"]; - } - compute = false; - if (![[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"]) - { - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"]; - [[NSUserDefaults standardUserDefaults] synchronize]; - [Utils copyRes]; - } - return YES; + // Override point for customization after application launch. + self.modelListController = (ModelListController *)self.window.rootViewController; + if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || + [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]) { + UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"iPadStoryboard" bundle:nil]; + self.splitViewController = [storyboard instantiateViewControllerWithIdentifier:@"SplitViewController"]; + } + compute = false; + + // Copy resource files if the version of the app has changed + NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; + NSString *prefsv = [prefs stringForKey:@"OnelabModelsVersion"]; + NSString *bundlev = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]; + if (!prefsv || ![prefsv isEqualToString:bundlev]) { + NSLog(@"Updating models to version %@", bundlev); + [prefs setObject:bundlev forKey:@"OnelabModelsVersion"]; + [prefs synchronize]; + [Utils copyRes]; + } + else{ + NSLog(@"Leaving models as-is (version %@)", prefsv); + } + return YES; } - + - (void)applicationWillResignActive:(UIApplication *)application { - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. + // Sent when the application is about to move from active to inactive + // state. This can occur for certain types of temporary interruptions (such as + // an incoming phone call or SMS message) or when the user quits the + // application and it begins the transition to the background state. Use this + // method to pause ongoing tasks, disable timers, and throttle down OpenGL ES + // frame rates. Games should use this method to pause the game. } - (void)applicationDidEnterBackground:(UIApplication *)application { - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + // Use this method to release shared resources, save user data, invalidate + // timers, and store enough application state information to restore your + // application to its current state in case it is terminated later. If your + // application supports background execution, this method is called instead + // of applicationWillTerminate: when the user quits. } - (void)applicationWillEnterForeground:(UIApplication *)application { - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. + // Called as part of the transition from the background to the inactive state; + // here you can undo many of the changes made on entering the background. } - (void)applicationDidBecomeActive:(UIApplication *)application { - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. - [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; + // Restart any tasks that were paused (or not yet started) while the + // application was inactive. If the application was previously in the + // background, optionally refresh the user interface. + [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; } - (void)applicationWillTerminate:(UIApplication *)application { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + // Called when the application is about to terminate. Save data if + // appropriate. See also applicationDidEnterBackground:. } -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { - application.applicationIconBadgeNumber = -1; - [UIApplication sharedApplication].applicationIconBadgeNumber = -1; + application.applicationIconBadgeNumber = -1; + [UIApplication sharedApplication].applicationIconBadgeNumber = -1; } @end diff --git a/contrib/mobile/iOS/Onelab/Model.mm b/contrib/mobile/iOS/Onelab/Model.mm index 4a7783bb257d95c59ff94bb3f66f1ca784f0aeea..d57160a242ee58aaf63de83bfe046f5b8fe93fc1 100644 --- a/contrib/mobile/iOS/Onelab/Model.mm +++ b/contrib/mobile/iOS/Onelab/Model.mm @@ -2,57 +2,67 @@ @implementation Model --(id) initWithName:(NSString *)name { - self = [super init]; - if(self) { - _name = name; - _summary = nil; - _file = nil; - _url = nil; - _preview = nil; - } - return self; +-(id) initWithName:(NSString *)name +{ + self = [super init]; + if(self) { + _name = name; + _summary = nil; + _file = nil; + _url = nil; + _preview = nil; + } + return self; } --(id) initWithName:(NSString *)name withSummary:(NSString *)summary withFile:(NSString *)file { - self = [super init]; - if(self) { - _name = name; - _summary = summary; - _file = file; - _url = nil; - _preview = nil; - } - return self; +-(id) initWithName:(NSString *)name withSummary:(NSString *)summary withFile:(NSString *)file +{ + self = [super init]; + if(self) { + _name = name; + _summary = summary; + _file = file; + _url = nil; + _preview = nil; + } + return self; } --(NSString *) getName { - return _name; +-(NSString *) getName +{ + return _name; } --(NSString *) getSummary { - return _summary; +-(NSString *) getSummary +{ + return _summary; } --(NSString *) getFile { - return _file; +-(NSString *) getFile +{ + return _file; } --(NSURL *) getUrl { - return _url; +-(NSURL *) getUrl +{ + return _url; } --(UIImage *) getPreview { - return _preview; +-(UIImage *) getPreview +{ + return _preview; } --(void) setSummary:(NSString *)summary { - _summary = summary; +-(void) setSummary:(NSString *)summary +{ + _summary = summary; } --(void) setFile:(NSString *)file { - _file = file; +-(void) setFile:(NSString *)file +{ + _file = file; } --(void) setPreview:(NSString *)path { - _preview = [UIImage imageWithContentsOfFile:path]; +-(void) setPreview:(NSString *)path +{ + _preview = [UIImage imageWithContentsOfFile:path]; } --(void) setUrl:(NSString *)url { - _url = [NSURL URLWithString:url]; +-(void) setUrl:(NSString *)url +{ + _url = [NSURL URLWithString:url]; } - @end diff --git a/contrib/mobile/iOS/Onelab/ModelListController.mm b/contrib/mobile/iOS/Onelab/ModelListController.mm index 748f4e4237b860712ac9037e54559dc62863791f..571f82ee54259a3b876601f11ddb9fdd3f8ea79d 100644 --- a/contrib/mobile/iOS/Onelab/ModelListController.mm +++ b/contrib/mobile/iOS/Onelab/ModelListController.mm @@ -7,206 +7,206 @@ @implementation ModelListController -(void)viewDidLoad { - UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; - [refreshControl addTarget:self action:@selector(refreshList) forControlEvents:UIControlEventValueChanged]; - self.refreshControl = refreshControl; - - UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; - lpgr.minimumPressDuration = 1.0; - [self.tableView addGestureRecognizer:lpgr]; - - models = [[NSMutableArray alloc] init]; - NSString *docsPath = [Utils getApplicationDocumentsDirectory]; - NSArray *docs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:docsPath error:NULL]; - for(NSString* doc in docs) { - NSString *docPath = [NSString stringWithFormat:@"%@/%@/", docsPath, doc]; - BOOL isDir = NO; [[NSFileManager defaultManager] fileExistsAtPath:docPath isDirectory:&isDir]; - if(isDir){ - NSString *infos = [NSString stringWithFormat:@"%@%@", docPath, @"infos.xml"]; - if([[NSFileManager defaultManager] fileExistsAtPath:infos]) { - currentDir = docPath; - [self parseInfosFile:infos]; - } - } + UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; + [refreshControl addTarget:self action:@selector(refreshList) forControlEvents:UIControlEventValueChanged]; + self.refreshControl = refreshControl; + + UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; + lpgr.minimumPressDuration = 1.0; + [self.tableView addGestureRecognizer:lpgr]; + + models = [[NSMutableArray alloc] init]; + NSString *docsPath = [Utils getApplicationDocumentsDirectory]; + NSArray *docs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:docsPath error:NULL]; + for(NSString* doc in docs) { + NSString *docPath = [NSString stringWithFormat:@"%@/%@/", docsPath, doc]; + BOOL isDir = NO; [[NSFileManager defaultManager] fileExistsAtPath:docPath isDirectory:&isDir]; + if(isDir){ + NSString *infos = [NSString stringWithFormat:@"%@%@", docPath, @"infos.xml"]; + if([[NSFileManager defaultManager] fileExistsAtPath:infos]) { + currentDir = docPath; + [self parseInfosFile:infos]; + } } - - UIBarButtonItem *about = [[UIBarButtonItem alloc] initWithTitle:@"About" style:UIBarButtonItemStyleBordered target:self action:@selector(showAbout)]; - [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects: about, nil]]; + } + + UIBarButtonItem *about = [[UIBarButtonItem alloc] initWithTitle:@"About" style:UIBarButtonItemStyleBordered target:self action:@selector(showAbout)]; + [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects: about, nil]]; } -(void)showAbout { - [self performSegueWithIdentifier:@"showAboutSegue" sender:self]; + [self performSegueWithIdentifier:@"showAboutSegue" sender:self]; } -(void)refreshList { - NSString *docsPath = [Utils getApplicationDocumentsDirectory]; - NSArray *docs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:docsPath error:NULL]; - for(NSString* doc in docs) { - NSString *docPath = [NSString stringWithFormat:@"%@/%@/", docsPath, doc]; - BOOL isDir = NO; [[NSFileManager defaultManager] fileExistsAtPath:docPath isDirectory:&isDir]; - if(isDir){ - NSString *infos = [NSString stringWithFormat:@"%@%@", docPath, @"infos.xml"]; - if([[NSFileManager defaultManager] fileExistsAtPath:infos]) { - currentDir = docPath; - [self parseInfosFile:infos]; - } - } - } - for (int i=0;i<[models count]; i++) { - if(![[NSFileManager defaultManager] fileExistsAtPath:[models[i] getFile]]) { - [models removeObject:models[i]]; - i--; - } - } - [self.tableView reloadData]; - [self.refreshControl endRefreshing]; + NSString *docsPath = [Utils getApplicationDocumentsDirectory]; + NSArray *docs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:docsPath error:NULL]; + for(NSString* doc in docs) { + NSString *docPath = [NSString stringWithFormat:@"%@/%@/", docsPath, doc]; + BOOL isDir = NO; [[NSFileManager defaultManager] fileExistsAtPath:docPath isDirectory:&isDir]; + if(isDir){ + NSString *infos = [NSString stringWithFormat:@"%@%@", docPath, @"infos.xml"]; + if([[NSFileManager defaultManager] fileExistsAtPath:infos]) { + currentDir = docPath; + [self parseInfosFile:infos]; + } + } + } + for (int i=0;i<[models count]; i++) { + if(![[NSFileManager defaultManager] fileExistsAtPath:[models[i] getFile]]) { + [models removeObject:models[i]]; + i--; + } + } + [self.tableView reloadData]; + [self.refreshControl endRefreshing]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return 1; + return 1; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return [models count]; + return [models count]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell; - if(indexPath.row >= [models count]) - return cell; - Model *m = [models objectAtIndex:indexPath.row]; - cell = [tableView dequeueReusableCellWithIdentifier:[m getName]]; - if(cell != nil) return cell; - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:[m getName]]; - [cell.textLabel setText:[m getName]]; - if([m getSummary] != nil) [cell.detailTextLabel setText:[m getSummary]]; - if([m getPreview] != nil) cell.imageView.image = [m getPreview]; - if([m getFile] == nil) { - cell.selectionStyle = UITableViewCellSelectionStyleNone; - cell.userInteractionEnabled = NO; - cell.textLabel.alpha = 0.75; - } - cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + UITableViewCell *cell; + if(indexPath.row >= [models count]) return cell; + Model *m = [models objectAtIndex:indexPath.row]; + cell = [tableView dequeueReusableCellWithIdentifier:[m getName]]; + if(cell != nil) return cell; + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:[m getName]]; + [cell.textLabel setText:[m getName]]; + if([m getSummary] != nil) [cell.detailTextLabel setText:[m getSummary]]; + if([m getPreview] != nil) cell.imageView.image = [m getPreview]; + if([m getFile] == nil) { + cell.selectionStyle = UITableViewCellSelectionStyleNone; + cell.userInteractionEnabled = NO; + cell.textLabel.alpha = 0.75; + } + cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + return cell; } -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { - return @"Select a model"; + return @"Select a model"; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; - selectedModel = [[models objectAtIndex:indexPath.row] getFile]; - if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]){ - appDelegate.splitViewController.initialModel = selectedModel; - [UIView transitionWithView:appDelegate.window - duration:0.5 - options:UIViewAnimationOptionTransitionFlipFromLeft - animations:^{ appDelegate.window.rootViewController = appDelegate.splitViewController; } - completion:nil]; - } - else + AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; + selectedModel = [[models objectAtIndex:indexPath.row] getFile]; + if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]){ + appDelegate.splitViewController.initialModel = selectedModel; + [UIView transitionWithView:appDelegate.window + duration:0.5 + options:UIViewAnimationOptionTransitionFlipFromLeft + animations:^{ appDelegate.window.rootViewController = appDelegate.splitViewController; } + completion:nil]; + } + else { - [self performSegueWithIdentifier:@"showModelSegue" sender:self]; + [self performSegueWithIdentifier:@"showModelSegue" sender:self]; } } -(void)handleLongPress:(UILongPressGestureRecognizer *)sender { - CGPoint p = [sender locationInView:self.tableView]; - if(sender.state == UIGestureRecognizerStateCancelled) return; - NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p]; - if(indexPath == nil) return; - UIActionSheet *actionSheet; - if([[models objectAtIndex:indexPath.row] getUrl]) - actionSheet = [[UIActionSheet alloc] initWithTitle:[[models objectAtIndex:indexPath.row] getName] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Open this model", @"More information", nil]; - else - actionSheet = [[UIActionSheet alloc] initWithTitle:[[models objectAtIndex:indexPath.row] getName] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Open this model", nil]; - actionSheet.tag = indexPath.row; - [actionSheet showInView:self.view]; + CGPoint p = [sender locationInView:self.tableView]; + if(sender.state == UIGestureRecognizerStateCancelled) return; + NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p]; + if(indexPath == nil) return; + UIActionSheet *actionSheet; + if([[models objectAtIndex:indexPath.row] getUrl]) + actionSheet = [[UIActionSheet alloc] initWithTitle:[[models objectAtIndex:indexPath.row] getName] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Open this model", @"More information", nil]; + else + actionSheet = [[UIActionSheet alloc] initWithTitle:[[models objectAtIndex:indexPath.row] getName] delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Open this model", nil]; + actionSheet.tag = indexPath.row; + [actionSheet showInView:self.view]; } --(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { - switch (buttonIndex) { - case 1: - [[UIApplication sharedApplication] openURL:[[models objectAtIndex:actionSheet.tag] getUrl]]; - break; - case 0: - [self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:actionSheet.tag inSection:0]]; - break; - } +-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex +{ + switch (buttonIndex) { + case 1: + [[UIApplication sharedApplication] openURL:[[models objectAtIndex:actionSheet.tag] getUrl]]; + break; + case 0: + [self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:actionSheet.tag inSection:0]]; + break; + } } - (BOOL) parseInfosFile:(NSString *)file { - NSData *xmlFile = [[NSFileManager defaultManager] contentsAtPath:file]; - NSXMLParser *parser; - parser = [[NSXMLParser alloc] initWithData:xmlFile]; - [parser setDelegate:self]; + NSData *xmlFile = [[NSFileManager defaultManager] contentsAtPath:file]; + NSXMLParser *parser; + parser = [[NSXMLParser alloc] initWithData:xmlFile]; + [parser setDelegate:self]; + + [parser setShouldProcessNamespaces:NO]; + [parser setShouldReportNamespacePrefixes:NO]; + [parser setShouldResolveExternalEntities:NO]; - [parser setShouldProcessNamespaces:NO]; - [parser setShouldReportNamespacePrefixes:NO]; - [parser setShouldResolveExternalEntities:NO]; - - return [parser parse]; + return [parser parse]; } -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { - currentElement = elementName; - //[currentElementValue release]; - currentElementValue = nil; + currentElement = elementName; + //[currentElementValue release]; + currentElementValue = nil; } -(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { - if (!currentElementValue) - currentElementValue = [[NSMutableString alloc] initWithString:string]; - else - [currentElementValue appendString:string]; + if (!currentElementValue) + currentElementValue = [[NSMutableString alloc] initWithString:string]; + else + [currentElementValue appendString:string]; } -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { - if([elementName isEqual:@"title"]) { - for(Model *mp in models) { - if([[mp getName] isEqual:currentElementValue]){ - [parser abortParsing]; - return; - } - } - Model *m = [[Model alloc] initWithName:currentElementValue]; - [models addObject:m]; - } - else { - if(models.count < 1) return; - if([elementName isEqual:@"summary"]) { - Model *m = [models lastObject]; - [m setSummary:currentElementValue]; - } - else if([elementName isEqual:@"file"]) { - Model *m = [models lastObject]; - [m setFile:[NSString stringWithFormat:@"%@%@", currentDir, currentElementValue]]; - } - else if([elementName isEqual:@"url"]) { - Model *m = [models lastObject]; - [m setUrl:currentElementValue]; - } - else if([elementName isEqual:@"preview"]) { - Model *m = [models lastObject]; - [m setPreview:[NSString stringWithFormat:@"%@%@", currentDir, currentElementValue]]; - } + if([elementName isEqual:@"title"]) { + for(Model *mp in models) { + if([[mp getName] isEqual:currentElementValue]){ + [parser abortParsing]; + return; + } + } + Model *m = [[Model alloc] initWithName:currentElementValue]; + [models addObject:m]; + } + else { + if(models.count < 1) return; + if([elementName isEqual:@"summary"]) { + Model *m = [models lastObject]; + [m setSummary:currentElementValue]; + } + else if([elementName isEqual:@"file"]) { + Model *m = [models lastObject]; + [m setFile:[NSString stringWithFormat:@"%@%@", currentDir, currentElementValue]]; + } + else if([elementName isEqual:@"url"]) { + Model *m = [models lastObject]; + [m setUrl:currentElementValue]; + } + else if([elementName isEqual:@"preview"]) { + Model *m = [models lastObject]; + [m setPreview:[NSString stringWithFormat:@"%@%@", currentDir, currentElementValue]]; + } - } - //[currentElementValue release]; - currentElementValue = nil; + } + //[currentElementValue release]; + currentElementValue = nil; } -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { - if ([[segue identifier] isEqualToString:@"showModelSegue"]) - { - ModelViewController *modelViewController = [segue destinationViewController]; - modelViewController.initialModel = selectedModel; - } + if ([[segue identifier] isEqualToString:@"showModelSegue"]) { + ModelViewController *modelViewController = [segue destinationViewController]; + modelViewController.initialModel = selectedModel; + } } @end diff --git a/contrib/mobile/iOS/Onelab/OptionsViewController.mm b/contrib/mobile/iOS/Onelab/OptionsViewController.mm index f6a24fb07de28e800c27a2bd6248da195b87f97e..99a4ae4a3d0e951cde763d9ec9bc227825b5446e 100644 --- a/contrib/mobile/iOS/Onelab/OptionsViewController.mm +++ b/contrib/mobile/iOS/Onelab/OptionsViewController.mm @@ -17,88 +17,86 @@ - (id)initWithStyle:(UITableViewStyle)style { - self = [super initWithStyle:style]; - if (self) { - // Custom initialization - } - return self; + self = [super initWithStyle:style]; + if (self) { + // Custom initialization + } + return self; } - (void)viewDidLoad { - [super viewDidLoad]; + [super viewDidLoad]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshOptions:) name:@"refreshParameters" object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshOptions:) name:@"resetParameters" object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshOptions:) name:@"refreshParameters" object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshOptions:) name:@"resetParameters" object:nil]; - self.navigationItem.title = @"Display"; + self.navigationItem.title = @"Display"; - [self.navigationController setToolbarHidden:NO]; - control = [[UISegmentedControl alloc] initWithItems:[[NSArray alloc] initWithObjects:@"Model", @"Display", nil]]; - UIBarButtonItem *controlBtn = [[UIBarButtonItem alloc] initWithCustomView:control]; - UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; - self.toolbarItems = [[NSArray alloc] initWithObjects:flexibleSpace, controlBtn, flexibleSpace, nil]; - [control addTarget:self action:@selector(indexDidChangeForSegmentedControl:) forControlEvents:UIControlEventValueChanged]; - if(![[UIDevice currentDevice].model isEqualToString:@"iPad"] && ![[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]) - self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed:)]; - else - self.navigationItem.hidesBackButton = true; + [self.navigationController setToolbarHidden:NO]; + control = [[UISegmentedControl alloc] initWithItems:[[NSArray alloc] initWithObjects:@"Model", @"Display", nil]]; + UIBarButtonItem *controlBtn = [[UIBarButtonItem alloc] initWithCustomView:control]; + UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; + self.toolbarItems = [[NSArray alloc] initWithObjects:flexibleSpace, controlBtn, flexibleSpace, nil]; + [control addTarget:self action:@selector(indexDidChangeForSegmentedControl:) forControlEvents:UIControlEventValueChanged]; + if(![[UIDevice currentDevice].model isEqualToString:@"iPad"] && ![[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]) + self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed:)]; + else + self.navigationItem.hidesBackButton = true; } - (void)viewWillAppear:(BOOL)animated { - control.selectedSegmentIndex = 1; - [super viewWillAppear:animated]; + control.selectedSegmentIndex = 1; + [super viewWillAppear:animated]; } -(void)backButtonPressed:(id)sender { - for(UIViewController *v in [self.navigationController viewControllers]) - if([v isKindOfClass:[ModelViewController class]]) [self.navigationController popToViewController:v animated:YES]; + for(UIViewController *v in [self.navigationController viewControllers]) + if([v isKindOfClass:[ModelViewController class]]) [self.navigationController popToViewController:v animated:YES]; } - (void)indexDidChangeForSegmentedControl:(id)sender { - [self.navigationController popViewControllerAnimated:YES]; + [self.navigationController popViewControllerAnimated:YES]; } - (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. } - (void)refreshOptions:(id)sender { - [self performSelectorOnMainThread:@selector(refreshOptions) withObject:nil waitUntilDone:NO]; + [self performSelectorOnMainThread:@selector(refreshOptions) withObject:nil waitUntilDone:NO]; } - (void)refreshOptions { - NSInteger nrow = [self.tableView numberOfRowsInSection:1]; - if(PView::list.size() == 0) - { - NSMutableArray *array = [[NSMutableArray alloc] init]; - for(NSInteger i = 0; i<nrow; i++) - [array addObject:[NSIndexPath indexPathForRow:i inSection:1]]; - [self.tableView beginUpdates]; - [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithArray:array] withRowAnimation:UITableViewRowAnimationAutomatic]; - [self.tableView endUpdates]; - } - else if(nrow < PView::list.size()) - { - NSMutableArray *array = [[NSMutableArray alloc] init]; - for(NSInteger i = nrow; i<PView::list.size(); i++) - [array addObject:[NSIndexPath indexPathForRow:i-nrow inSection:1]]; - [self.tableView beginUpdates]; - [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithArray:array] withRowAnimation:UITableViewRowAnimationAutomatic]; - [self.tableView endUpdates]; - } + NSInteger nrow = [self.tableView numberOfRowsInSection:1]; + if(PView::list.size() == 0) { + NSMutableArray *array = [[NSMutableArray alloc] init]; + for(NSInteger i = 0; i<nrow; i++) + [array addObject:[NSIndexPath indexPathForRow:i inSection:1]]; + [self.tableView beginUpdates]; + [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithArray:array] withRowAnimation:UITableViewRowAnimationAutomatic]; + [self.tableView endUpdates]; + } + else if(nrow < PView::list.size()) { + NSMutableArray *array = [[NSMutableArray alloc] init]; + for(NSInteger i = nrow; i<PView::list.size(); i++) + [array addObject:[NSIndexPath indexPathForRow:i-nrow inSection:1]]; + [self.tableView beginUpdates]; + [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithArray:array] withRowAnimation:UITableViewRowAnimationAutomatic]; + [self.tableView endUpdates]; + } } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return 2; + return 2; /** Section Name 0 Options (Show mesh, Show geometry) @@ -108,155 +106,155 @@ -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { - switch (section) { - case 0: - return @"Display options"; - case 1: - return @"Result options"; - default: - return @"Other options"; - } + switch (section) { + case 0: + return @"Display options"; + case 1: + return @"Result options"; + default: + return @"Other options"; + } } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - switch (section) { - case 0: - return 4; - case 1: - return PView::list.size(); - default: - return 0; - } + switch (section) { + case 0: + return 4; + case 1: + return PView::list.size(); + default: + return 0; + } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; - if(cell == nil) - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"postproCell"]; - else { - cell = nil; - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"postproCell"]; + UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; + if(cell == nil) + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"postproCell"]; + else { + cell = nil; + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"postproCell"]; + } + [cell setFrame:CGRectMake(cell.frame.origin.x, cell.frame.origin.x, tableView.frame.size.width, cell.frame.size.height)]; + switch (indexPath.section) { + case 0: + { + [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; + UISwitch *showHideOptions = [[UISwitch alloc] initWithFrame: CGRectMake(10, 10, 100, 30)]; + UILabel *lblOptions = [[UILabel alloc] initWithFrame:CGRectMake(10 + (showHideOptions.frame.size.width)+25 , 10, (cell.bounds.size.width - (showHideOptions.frame.size.width) - 25), 30)]; + if(indexPath.row == 0) { + [lblOptions setText:@"Show geometry points"]; + [showHideOptions setOn:(CTX::instance()->geom.points)]; + [showHideOptions addTarget:self action:@selector(setShowGeomPoints:) forControlEvents:UIControlEventValueChanged]; + } + else if(indexPath.row == 1) { + [lblOptions setText:@"Show geometry lines"]; + [showHideOptions setOn:(CTX::instance()->geom.lines)]; + [showHideOptions addTarget:self action:@selector(setShowGeomLines:) forControlEvents:UIControlEventValueChanged]; + } + else if(indexPath.row == 2) { + [lblOptions setText:@"Show mesh surface edges"]; + [showHideOptions setOn:(CTX::instance()->mesh.surfacesEdges)]; + [showHideOptions addTarget:self action:@selector(setShowMeshSurfacesEdges:) forControlEvents:UIControlEventValueChanged]; + } + else if(indexPath.row == 3) { + [lblOptions setText:@"Show mesh volumes edges"]; + [showHideOptions setOn:CTX::instance()->mesh.volumesEdges]; + [showHideOptions addTarget:self action:@selector(setShowMeshVolumesEdges:) forControlEvents:UIControlEventValueChanged]; + } + [cell addSubview:showHideOptions]; + [cell addSubview:lblOptions]; } - [cell setFrame:CGRectMake(cell.frame.origin.x, cell.frame.origin.x, tableView.frame.size.width, cell.frame.size.height)]; - switch (indexPath.section) { - case 0: - { - [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; - UISwitch *showHideOptions = [[UISwitch alloc] initWithFrame: CGRectMake(10, 10, 100, 30)]; - UILabel *lblOptions = [[UILabel alloc] initWithFrame:CGRectMake(10 + (showHideOptions.frame.size.width)+25 , 10, (cell.bounds.size.width - (showHideOptions.frame.size.width) - 25), 30)]; - if(indexPath.row == 0) { - [lblOptions setText:@"Show geometry points"]; - [showHideOptions setOn:(CTX::instance()->geom.points)]; - [showHideOptions addTarget:self action:@selector(setShowGeomPoints:) forControlEvents:UIControlEventValueChanged]; - } - else if(indexPath.row == 1) { - [lblOptions setText:@"Show geometry lines"]; - [showHideOptions setOn:(CTX::instance()->geom.lines)]; - [showHideOptions addTarget:self action:@selector(setShowGeomLines:) forControlEvents:UIControlEventValueChanged]; - } - else if(indexPath.row == 2) { - [lblOptions setText:@"Show mesh surface edges"]; - [showHideOptions setOn:(CTX::instance()->mesh.surfacesEdges)]; - [showHideOptions addTarget:self action:@selector(setShowMeshSurfacesEdges:) forControlEvents:UIControlEventValueChanged]; - } - else if(indexPath.row == 3) { - [lblOptions setText:@"Show mesh volumes edges"]; - [showHideOptions setOn:CTX::instance()->mesh.volumesEdges]; - [showHideOptions addTarget:self action:@selector(setShowMeshVolumesEdges:) forControlEvents:UIControlEventValueChanged]; - } - [cell addSubview:showHideOptions]; - [cell addSubview:lblOptions]; - } - break; - case 1: - { - NSArray *rows = [tableView indexPathsForVisibleRows]; - for(NSIndexPath *mIndexpath in rows) - if(![mIndexpath isEqual:indexPath]){ - UITableViewCell *tmp = [tableView cellForRowAtIndexPath:indexPath]; - for(UIView *tmpv in tmp.subviews)for(UIView *v in tmpv.subviews) - if([v isKindOfClass:[UISwitch class]]) - [(UISwitch *)v setOn:PView::list[v.tag]->getOptions()->visible]; - } - - [cell setSelectionStyle:UITableViewCellSelectionStyleGray]; - int i = PView::list.size() - 1 - indexPath.row; - cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; - UISwitch *showHide = [[UISwitch alloc] initWithFrame: CGRectMake(10, 10, 100, 30)]; - UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(25 + (showHide.frame.size.width), 10, (cell.bounds.size.width - showHide.frame.size.width - 50), 30)]; - [showHide setOn:(PView::list[i]->getOptions()->visible == 1)]; - [showHide setTag:i]; - [showHide addTarget:self action:@selector(PViewVisible:) forControlEvents:UIControlEventValueChanged]; - [lbl setBackgroundColor: [UIColor clearColor]]; - [lbl setText:[NSString stringWithCString:PView::list[i]->getData()->getName().c_str() encoding:[NSString defaultCStringEncoding]]]; - [cell addSubview:showHide]; - [cell addSubview:lbl]; + break; + case 1: + { + NSArray *rows = [tableView indexPathsForVisibleRows]; + for(NSIndexPath *mIndexpath in rows) + if(![mIndexpath isEqual:indexPath]){ + UITableViewCell *tmp = [tableView cellForRowAtIndexPath:indexPath]; + for(UIView *tmpv in tmp.subviews)for(UIView *v in tmpv.subviews) + if([v isKindOfClass:[UISwitch class]]) + [(UISwitch *)v setOn:PView::list[v.tag]->getOptions()->visible]; } - break; + + [cell setSelectionStyle:UITableViewCellSelectionStyleGray]; + int i = PView::list.size() - 1 - indexPath.row; + cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + UISwitch *showHide = [[UISwitch alloc] initWithFrame: CGRectMake(10, 10, 100, 30)]; + UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(25 + (showHide.frame.size.width), 10, (cell.bounds.size.width - showHide.frame.size.width - 50), 30)]; + [showHide setOn:(PView::list[i]->getOptions()->visible == 1)]; + [showHide setTag:i]; + [showHide addTarget:self action:@selector(PViewVisible:) forControlEvents:UIControlEventValueChanged]; + [lbl setBackgroundColor: [UIColor clearColor]]; + [lbl setText:[NSString stringWithCString:PView::list[i]->getData()->getName().c_str() encoding:[NSString defaultCStringEncoding]]]; + [cell addSubview:showHide]; + [cell addSubview:lbl]; } - return cell; + break; + } + return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - if(indexPath.section != 1) return; - UIStoryboard *storyboard; - if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]) - storyboard = [UIStoryboard storyboardWithName:@"iPadStoryboard" bundle:nil]; - else - storyboard = [UIStoryboard storyboardWithName:@"iPhoneiPodStoryboard" bundle:nil]; - PostProcessingViewController *postPro = [storyboard instantiateViewControllerWithIdentifier:@"PostProcessingViewController"]; - [postPro setPView:PView::list[[tableView numberOfRowsInSection:1]-1- indexPath.row]]; - [self.navigationController pushViewController:postPro animated:YES]; + if(indexPath.section != 1) return; + UIStoryboard *storyboard; + if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]) + storyboard = [UIStoryboard storyboardWithName:@"iPadStoryboard" bundle:nil]; + else + storyboard = [UIStoryboard storyboardWithName:@"iPhoneiPodStoryboard" bundle:nil]; + PostProcessingViewController *postPro = [storyboard instantiateViewControllerWithIdentifier:@"PostProcessingViewController"]; + [postPro setPView:PView::list[[tableView numberOfRowsInSection:1]-1- indexPath.row]]; + [self.navigationController pushViewController:postPro animated:YES]; } - (void)setShowGeomPoints:(UISwitch*)sender { - CTX::instance()->geom.points = sender.on; - [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; + CTX::instance()->geom.points = sender.on; + [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; } - (void)setShowGeomLines:(UISwitch*)sender { - CTX::instance()->geom.lines = sender.on; - [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; + CTX::instance()->geom.lines = sender.on; + [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; } - (void)setShowMeshVolumesEdges:(UISwitch*)sender { - CTX::instance()->mesh.volumesEdges = sender.on; - CTX::instance()->mesh.changed = ENT_VOLUME; - [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; + CTX::instance()->mesh.volumesEdges = sender.on; + CTX::instance()->mesh.changed = ENT_VOLUME; + [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; } - (void)setShowMeshSurfacesEdges:(UISwitch*)sender { - CTX::instance()->mesh.surfacesEdges = sender.on; - CTX::instance()->mesh.changed = ENT_SURFACE; - [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; + CTX::instance()->mesh.surfacesEdges = sender.on; + CTX::instance()->mesh.changed = ENT_SURFACE; + [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; } -(IBAction)PViewVisible:(id)sender { - PView::list[((UISwitch*)sender).tag]->getOptions()->visible = (((UISwitch*)sender).on)? 1 : 0; - [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; + PView::list[((UISwitch*)sender).tag]->getOptions()->visible = (((UISwitch*)sender).on)? 1 : 0; + [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; } #pragma mark - textfield -(BOOL)textFieldShouldEndEditing:(UITextField *)textField { - NSInteger val = [textField.text integerValue]; - val = (val > 0)? val : 1; - val = (val < 1000)? val : 1000; - [textField setText:[NSString stringWithFormat:@"%d",val]]; - PView::list[textField.tag]->getOptions()->nbIso = val; - PView::list[textField.tag]->setChanged(true); - [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; - return YES; + NSInteger val = [textField.text integerValue]; + val = (val > 0)? val : 1; + val = (val < 1000)? val : 1000; + [textField setText:[NSString stringWithFormat:@"%d",val]]; + PView::list[textField.tag]->getOptions()->nbIso = val; + PView::list[textField.tag]->setChanged(true); + [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; + return YES; } -(BOOL)textFieldShouldReturn:(UITextField *)textField { - [textField endEditing:YES]; - return YES; + [textField endEditing:YES]; + return YES; } @end diff --git a/contrib/mobile/iOS/Onelab/Parameter.mm b/contrib/mobile/iOS/Onelab/Parameter.mm index 304f730f73d5c1b531061b8bc095e4336ada197d..8d1e5c222a025b55ba09056b464e1f77b025d90e 100644 --- a/contrib/mobile/iOS/Onelab/Parameter.mm +++ b/contrib/mobile/iOS/Onelab/Parameter.mm @@ -3,403 +3,397 @@ @implementation Parameter -(id)init { - self = [super init]; - if(self) - { - label = [[UILabel alloc] init]; - [label setBackgroundColor:[UIColor clearColor]]; - } - return self; + self = [super init]; + if(self) { + label = [[UILabel alloc] init]; + [label setBackgroundColor:[UIColor clearColor]]; + } + return self; } -(void)refresh { - return; + return; } -(NSString *)getName { - return name; + return name; } -(UILabel *)getLabel { - return label; + return label; } -(void)setFrame:(CGRect)frame { - return; + return; } -(void)setLabelFrame:(CGRect)frame { - [label setFrame:frame]; + [label setFrame:frame]; } -(void)editValue { - if(onelab_cb("check") == 1){ - [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshParameters" object:nil]; - } + if(onelab_cb("check") == 1){ + [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; + [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshParameters" object:nil]; + } } -(bool) isReadOnly {return NO;} +(double)getHeight { - return 60.0f; + return 60.0f; } @end @implementation ParameterStringList -(id) initWithString:(onelab::string)string { - self = [super init]; - if(self) + self = [super init]; + if(self) { - label.alpha = (string.getReadOnly())? 0.439216f : 1.0f; - [label setText:[NSString stringWithCString:string.getShortName().c_str() encoding:[NSString defaultCStringEncoding]]]; - name = [NSString stringWithCString:string.getName().c_str() encoding:[NSString defaultCStringEncoding]]; - button = [UIButton buttonWithType:UIButtonTypeSystem]; - [button addTarget:self action:@selector(selectValue) forControlEvents:UIControlEventTouchDown]; - [button setTitle:[NSString stringWithFormat:@"%s", string.getValue().c_str()] forState:UIControlStateNormal]; + label.alpha = (string.getReadOnly())? 0.439216f : 1.0f; + [label setText:[NSString stringWithCString:string.getShortName().c_str() encoding:[NSString defaultCStringEncoding]]]; + name = [NSString stringWithCString:string.getName().c_str() encoding:[NSString defaultCStringEncoding]]; + button = [UIButton buttonWithType:UIButtonTypeSystem]; + [button addTarget:self action:@selector(selectValue) forControlEvents:UIControlEventTouchDown]; + [button setTitle:[NSString stringWithFormat:@"%s", string.getValue().c_str()] forState:UIControlStateNormal]; } - return self; + return self; } -(void)selectValue { - std::vector<onelab::string> string; - onelab::server::instance()->get(string,[name UTF8String]); - if(string.size() < 1) return; - UIActionSheet *popupSelectValue = [[UIActionSheet alloc] initWithTitle:[NSString stringWithFormat:@"%s", string[0].getLabel().c_str()] delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; - std::vector<std::string> choices = string[0].getChoices(); - for(int i=0;i<choices.size();i++) - [popupSelectValue addButtonWithTitle:[NSString stringWithFormat:@"%s", choices[i].c_str()]]; - [popupSelectValue showInView:button]; + std::vector<onelab::string> string; + onelab::server::instance()->get(string,[name UTF8String]); + if(string.size() < 1) return; + UIActionSheet *popupSelectValue = [[UIActionSheet alloc] initWithTitle:[NSString stringWithFormat:@"%s", string[0].getLabel().c_str()] delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; + std::vector<std::string> choices = string[0].getChoices(); + for(int i=0;i<choices.size();i++) + [popupSelectValue addButtonWithTitle:[NSString stringWithFormat:@"%s", choices[i].c_str()]]; + [popupSelectValue showInView:button]; } -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { - std::vector<onelab::string> string; - onelab::server::instance()->get(string,[name UTF8String]); - if(string.size() < 1) return; - std::string selected = string[0].getChoices()[buttonIndex]; - string[0].setValue(selected); - onelab::server::instance()->set(string[0]); - [super editValue]; + std::vector<onelab::string> string; + onelab::server::instance()->get(string,[name UTF8String]); + if(string.size() < 1) return; + std::string selected = string[0].getChoices()[buttonIndex]; + string[0].setValue(selected); + onelab::server::instance()->set(string[0]); + [super editValue]; } -(void)refresh { - std::vector<onelab::string> string; - onelab::server::instance()->get(string,[name UTF8String]); - [button setTitle:[NSString stringWithFormat:@"%s", string[0].getValue().c_str()] forState:UIControlStateNormal]; + std::vector<onelab::string> string; + onelab::server::instance()->get(string,[name UTF8String]); + [button setTitle:[NSString stringWithFormat:@"%s", string[0].getValue().c_str()] forState:UIControlStateNormal]; } -(void)setFrame:(CGRect)frame { - [button setFrame:frame]; + [button setFrame:frame]; } -(UIButton *)getUIView { - return button; + return button; } -(bool)isReadOnly { - std::vector<onelab::string> string; - onelab::server::instance()->get(string,[name UTF8String]); - if(string.size() < 1) return YES; - return string[0].getReadOnly(); + std::vector<onelab::string> string; + onelab::server::instance()->get(string,[name UTF8String]); + if(string.size() < 1) return YES; + return string[0].getReadOnly(); } +(double)getHeight { - return 60.f; + return 60.f; } @end @implementation ParameterNumberList -(id) initWithNumber:(onelab::number) number { - self = [super init]; - if(self) - { - label.alpha = (number.getReadOnly())? 0.439216f : 1.0f; - [label setText:[NSString stringWithCString:number.getShortName().c_str() encoding:[NSString defaultCStringEncoding]]]; - name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]]; - button = [UIButton buttonWithType:UIButtonTypeSystem]; - [button addTarget:self action:@selector(selectValue) forControlEvents:UIControlEventTouchDown]; - [button setTitle:[NSString stringWithFormat:@"%s", number.getValueLabel(number.getValue()).c_str()] forState:UIControlStateNormal]; - } - return self; + self = [super init]; + if(self) { + label.alpha = (number.getReadOnly())? 0.439216f : 1.0f; + [label setText:[NSString stringWithCString:number.getShortName().c_str() encoding:[NSString defaultCStringEncoding]]]; + name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]]; + button = [UIButton buttonWithType:UIButtonTypeSystem]; + [button addTarget:self action:@selector(selectValue) forControlEvents:UIControlEventTouchDown]; + [button setTitle:[NSString stringWithFormat:@"%s", number.getValueLabel(number.getValue()).c_str()] forState:UIControlStateNormal]; + } + return self; } -(void)selectValue { - std::vector<onelab::number> number; - onelab::server::instance()->get(number,[name UTF8String]); - if(number.size() < 1) return; - UIActionSheet *popupSelectValue = [[UIActionSheet alloc] initWithTitle:[NSString stringWithFormat:@"%s", number[0].getLabel().c_str()] delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; - std::vector<double> choices = number[0].getChoices(); - for(int i=0;i<choices.size();i++) - [popupSelectValue addButtonWithTitle:[NSString stringWithFormat:@"%s", number[0].getValueLabel(choices[i]).c_str()]]; - [popupSelectValue showInView:button]; + std::vector<onelab::number> number; + onelab::server::instance()->get(number,[name UTF8String]); + if(number.size() < 1) return; + UIActionSheet *popupSelectValue = [[UIActionSheet alloc] initWithTitle:[NSString stringWithFormat:@"%s", number[0].getLabel().c_str()] delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; + std::vector<double> choices = number[0].getChoices(); + for(int i=0;i<choices.size();i++) + [popupSelectValue addButtonWithTitle:[NSString stringWithFormat:@"%s", number[0].getValueLabel(choices[i]).c_str()]]; + [popupSelectValue showInView:button]; } -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { - std::vector<onelab::number> number; - onelab::server::instance()->get(number,[name UTF8String]); - if(number.size() < 1) return; - double selected = number[0].getChoices()[buttonIndex]; - number[0].setValue(selected); - onelab::server::instance()->set(number[0]); - [button setTitle:[NSString stringWithFormat:@"%s", number[0].getValueLabel(number[0].getValue()).c_str()] forState:UIControlStateNormal]; - [super editValue]; + std::vector<onelab::number> number; + onelab::server::instance()->get(number,[name UTF8String]); + if(number.size() < 1) return; + double selected = number[0].getChoices()[buttonIndex]; + number[0].setValue(selected); + onelab::server::instance()->set(number[0]); + [button setTitle:[NSString stringWithFormat:@"%s", number[0].getValueLabel(number[0].getValue()).c_str()] forState:UIControlStateNormal]; + [super editValue]; } -(void)refresh { - std::vector<onelab::number> number; - onelab::server::instance()->get(number,[name UTF8String]); - [button setTitle:[NSString stringWithFormat:@"%s", number[0].getValueLabel(number[0].getValue()).c_str()] forState:UIControlStateNormal]; + std::vector<onelab::number> number; + onelab::server::instance()->get(number,[name UTF8String]); + [button setTitle:[NSString stringWithFormat:@"%s", number[0].getValueLabel(number[0].getValue()).c_str()] forState:UIControlStateNormal]; } -(void)setFrame:(CGRect)frame { - [button setFrame:frame]; + [button setFrame:frame]; } -(UIButton *)getUIView { - return button; + return button; } -(bool)isReadOnly { - std::vector<onelab::number> number; - onelab::server::instance()->get(number,[name UTF8String]); - if(number.size() < 1) return YES; - return number[0].getReadOnly(); + std::vector<onelab::number> number; + onelab::server::instance()->get(number,[name UTF8String]); + if(number.size() < 1) return YES; + return number[0].getReadOnly(); } +(double)getHeight { - return 60.f; + return 60.f; } @end @implementation ParameterNumberCheckbox -(id) initWithNumber:(onelab::number) number { - self = [super init]; - if(self) - { - label.alpha = (number.getReadOnly())? 0.439216f : 1.0f; - [label setText:[NSString stringWithCString:number.getShortName().c_str() encoding:[NSString defaultCStringEncoding]]]; - name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]]; - checkbox = [[UISwitch alloc] init]; - [checkbox setOn:(number.getValue() == 1)]; - [checkbox addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventValueChanged]; - } - return self; + self = [super init]; + if(self) { + label.alpha = (number.getReadOnly())? 0.439216f : 1.0f; + [label setText:[NSString stringWithCString:number.getShortName().c_str() encoding:[NSString defaultCStringEncoding]]]; + name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]]; + checkbox = [[UISwitch alloc] init]; + [checkbox setOn:(number.getValue() == 1)]; + [checkbox addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventValueChanged]; + } + return self; } -(void)refresh { - std::vector<onelab::number> number; - onelab::server::instance()->get(number,[name UTF8String]); - [checkbox setSelected:(number[0].getValue() == 1)]; + std::vector<onelab::number> number; + onelab::server::instance()->get(number,[name UTF8String]); + [checkbox setSelected:(number[0].getValue() == 1)]; } -(void) valueChange:(UISwitch *)sender { - std::vector<onelab::number> number; - onelab::server::instance()->get(number,[name UTF8String]); - if(number.size() < 1) return; - number[0].setValue(([sender isOn])? 1 : 0); - onelab::server::instance()->set(number[0]); - [super editValue]; + std::vector<onelab::number> number; + onelab::server::instance()->get(number,[name UTF8String]); + if(number.size() < 1) return; + number[0].setValue(([sender isOn])? 1 : 0); + onelab::server::instance()->set(number[0]); + [super editValue]; } -(void)setFrame:(CGRect)frame { - [checkbox setFrame:frame]; + [checkbox setFrame:frame]; } -(UISwitch *)getCheckbox { - return checkbox; + return checkbox; } -(bool)isReadOnly { - std::vector<onelab::number> number; - onelab::server::instance()->get(number,[name UTF8String]); - if(number.size() < 1) return YES; - return number[0].getReadOnly(); + std::vector<onelab::number> number; + onelab::server::instance()->get(number,[name UTF8String]); + if(number.size() < 1) return YES; + return number[0].getReadOnly(); } +(double)getHeight { - return 40.0f; + return 40.0f; } @end @implementation ParameterNumberStepper -(id) initWithNumber:(onelab::number) number { - self = [super init]; - if(self) - { - name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]]; - label.alpha = (number.getReadOnly())? 0.439216f : 1.0f; - stepper = [[UIStepper alloc] init]; - [stepper setValue:number.getValue()]; - [stepper setStepValue:1]; - [stepper setMaximumValue:number.getMax()]; - [stepper setMinimumValue:number.getMin()]; - [stepper addTarget:self action:@selector(stepperValueChanged:) forControlEvents:UIControlEventValueChanged]; - [label setText:[NSString stringWithFormat:@"%s %d" ,number.getShortName().c_str(), (int)number.getValue()]]; - } - return self; + self = [super init]; + if(self) { + name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]]; + label.alpha = (number.getReadOnly())? 0.439216f : 1.0f; + stepper = [[UIStepper alloc] init]; + [stepper setValue:number.getValue()]; + [stepper setStepValue:1]; + [stepper setMaximumValue:number.getMax()]; + [stepper setMinimumValue:number.getMin()]; + [stepper addTarget:self action:@selector(stepperValueChanged:) forControlEvents:UIControlEventValueChanged]; + [label setText:[NSString stringWithFormat:@"%s %d" ,number.getShortName().c_str(), (int)number.getValue()]]; + } + return self; } -(void)stepperValueChanged:(UIStepper *)sender { - std::vector<onelab::number> number; - onelab::server::instance()->get(number,[name UTF8String]); - if(number.size() < 1) return; - number[0].setValue(sender.value); - onelab::server::instance()->set(number[0]); - [label setText:[NSString stringWithFormat:@"%s %d" ,number[0].getShortName().c_str(), (int)number[0].getValue()]]; - [super editValue]; + std::vector<onelab::number> number; + onelab::server::instance()->get(number,[name UTF8String]); + if(number.size() < 1) return; + number[0].setValue(sender.value); + onelab::server::instance()->set(number[0]); + [label setText:[NSString stringWithFormat:@"%s %d" ,number[0].getShortName().c_str(), (int)number[0].getValue()]]; + [super editValue]; } -(void)refresh { - std::vector<onelab::number> number; - onelab::server::instance()->get(number,[name UTF8String]); - if(number.size() < 1) return; - [stepper setValue:number[0].getValue()]; + std::vector<onelab::number> number; + onelab::server::instance()->get(number,[name UTF8String]); + if(number.size() < 1) return; + [stepper setValue:number[0].getValue()]; } -(void)setFrame:(CGRect)frame { - [stepper setFrame:frame]; + [stepper setFrame:frame]; } -(UIStepper *)getStepper { - return stepper; + return stepper; } +(double)getHeight { - return 60.0f; + return 60.0f; } @end @implementation ParameterNumberRange -(id) initWithNumber:(onelab::number) number { - self = [super init]; - if(self) - { - label.alpha = (number.getReadOnly())? 0.439216f : 1.0f; - name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]]; - slider = [[UISlider alloc] init]; - [slider setMaximumValue:number.getMax()]; - [slider setMinimumValue:number.getMin()]; - [slider setValue:number.getValue()]; - //TODO add step ? - [slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventTouchUpOutside]; - [slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventTouchUpInside]; - [label setText:[NSString stringWithFormat:@"%@ %g" ,[NSString stringWithCString:number.getShortName().c_str() encoding:[NSString defaultCStringEncoding]], number.getValue()]]; - } - return self; + self = [super init]; + if(self) { + label.alpha = (number.getReadOnly())? 0.439216f : 1.0f; + name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]]; + slider = [[UISlider alloc] init]; + [slider setMaximumValue:number.getMax()]; + [slider setMinimumValue:number.getMin()]; + [slider setValue:number.getValue()]; + //TODO add step ? + [slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventTouchUpOutside]; + [slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventTouchUpInside]; + [label setText:[NSString stringWithFormat:@"%@ %g" ,[NSString stringWithCString:number.getShortName().c_str() encoding:[NSString defaultCStringEncoding]], number.getValue()]]; + } + return self; } -(void)refresh { - std::vector<onelab::number> number; - onelab::server::instance()->get(number,[name UTF8String]); - if(number.size() < 1) return; - [slider setMaximumValue:number[0].getMax()]; - [slider setMinimumValue:number[0].getMin()]; - [slider setValue:number[0].getValue()]; + std::vector<onelab::number> number; + onelab::server::instance()->get(number,[name UTF8String]); + if(number.size() < 1) return; + [slider setMaximumValue:number[0].getMax()]; + [slider setMinimumValue:number[0].getMin()]; + [slider setValue:number[0].getValue()]; } -(void)sliderValueChanged:(UISlider *)sender { - std::vector<onelab::number> number; - onelab::server::instance()->get(number,[name UTF8String]); - if(number.size() < 1) return; - number[0].setValue(sender.value); - onelab::server::instance()->set(number[0]); - [label setText:[NSString stringWithFormat:@"%s %g" ,number[0].getShortName().c_str(), number[0].getValue()]]; - [super editValue]; + std::vector<onelab::number> number; + onelab::server::instance()->get(number,[name UTF8String]); + if(number.size() < 1) return; + number[0].setValue(sender.value); + onelab::server::instance()->set(number[0]); + [label setText:[NSString stringWithFormat:@"%s %g" ,number[0].getShortName().c_str(), number[0].getValue()]]; + [super editValue]; } -(void)setFrame:(CGRect)frame { - [slider setFrame:frame]; + [slider setFrame:frame]; } -(UISlider *)getSlider { - return slider; + return slider; } -(bool)isReadOnly { - std::vector<onelab::number> number; - onelab::server::instance()->get(number,[name UTF8String]); - if(number.size() < 1) return YES; - return number[0].getReadOnly(); + std::vector<onelab::number> number; + onelab::server::instance()->get(number,[name UTF8String]); + if(number.size() < 1) return YES; + return number[0].getReadOnly(); } +(double)getHeight { - return 60.0f; + return 60.0f; } @end @implementation ParameterNumberTextbox -(id)initWithNumber:(onelab::number)number { - self = [super init]; - if(self) - { - label.alpha = (number.getReadOnly())? 0.439216f : 1.0f; - [label setText:[NSString stringWithCString:number.getShortName().c_str() encoding:[NSString defaultCStringEncoding]]]; - name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]]; - textbox = [[UITextField alloc] init]; - [textbox setBorderStyle:UITextBorderStyleRoundedRect]; - [textbox setKeyboardType:UIKeyboardTypeNumberPad]; - [textbox setText:[NSString stringWithFormat:@"%g", number.getValue()]]; - [textbox setDelegate:self]; - UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; - numberToolbar.barStyle = UIBarStyleBlackTranslucent; - numberToolbar.items = [NSArray arrayWithObjects: - [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], - [[UIBarButtonItem alloc]initWithTitle:@"Apply" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)], - nil]; - [numberToolbar sizeToFit]; - textbox.inputAccessoryView = numberToolbar; - } - return self; + self = [super init]; + if(self) { + label.alpha = (number.getReadOnly())? 0.439216f : 1.0f; + [label setText:[NSString stringWithCString:number.getShortName().c_str() encoding:[NSString defaultCStringEncoding]]]; + name = [NSString stringWithCString:number.getName().c_str() encoding:[NSString defaultCStringEncoding]]; + textbox = [[UITextField alloc] init]; + [textbox setBorderStyle:UITextBorderStyleRoundedRect]; + [textbox setKeyboardType:UIKeyboardTypeNumberPad]; + [textbox setText:[NSString stringWithFormat:@"%g", number.getValue()]]; + [textbox setDelegate:self]; + UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; + numberToolbar.barStyle = UIBarStyleBlackTranslucent; + numberToolbar.items = [NSArray arrayWithObjects: + [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], + [[UIBarButtonItem alloc]initWithTitle:@"Apply" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)], + nil]; + [numberToolbar sizeToFit]; + textbox.inputAccessoryView = numberToolbar; + } + return self; } -(void)refresh { - std::vector<onelab::number> number; - onelab::server::instance()->get(number,[name UTF8String]); - if(number.size() < 1) return; - [textbox setText:[NSString stringWithFormat:@"%g", number[0].getValue()]]; - [textbox reloadInputViews]; + std::vector<onelab::number> number; + onelab::server::instance()->get(number,[name UTF8String]); + if(number.size() < 1) return; + [textbox setText:[NSString stringWithFormat:@"%g", number[0].getValue()]]; + [textbox reloadInputViews]; } -(BOOL)textFieldShouldEndEditing:(UITextField *)textField { - std::vector<onelab::number> number; - onelab::server::instance()->get(number,[name UTF8String]); - if(number.size() < 1) return YES; - number[0].setValue([textField.text doubleValue]); - onelab::server::instance()->set(number[0]); - [textField setText:[NSString stringWithFormat:@"%g", number[0].getValue()]]; - [super editValue]; - return YES; + std::vector<onelab::number> number; + onelab::server::instance()->get(number,[name UTF8String]); + if(number.size() < 1) return YES; + number[0].setValue([textField.text doubleValue]); + onelab::server::instance()->set(number[0]); + [textField setText:[NSString stringWithFormat:@"%g", number[0].getValue()]]; + [super editValue]; + return YES; } -(BOOL)textFieldShouldReturn:(UITextField *)textField { - return [textField endEditing:YES]; + return [textField endEditing:YES]; } -(void)doneWithNumberPad { - [textbox endEditing:YES]; + [textbox endEditing:YES]; } -(void)setFrame:(CGRect)frame { - [textbox setFrame:frame]; + [textbox setFrame:frame]; } -(UITextField *)getTextbox { - return textbox; + return textbox; } -(bool)isReadOnly { - std::vector<onelab::number> number; - onelab::server::instance()->get(number,[name UTF8String]); - if(number.size() < 1) return YES; - return number[0].getReadOnly(); + std::vector<onelab::number> number; + onelab::server::instance()->get(number,[name UTF8String]); + if(number.size() < 1) return YES; + return number[0].getReadOnly(); } +(double)getHeight { - return 60.f; + return 60.f; } @end diff --git a/contrib/mobile/iOS/Onelab/ParametersViewController.mm b/contrib/mobile/iOS/Onelab/ParametersViewController.mm index 3d56ebe7837e6e65dac0adabbd578b6f06a4debd..1008c99c3b35f174cc2e34f820566413c816e3aa 100644 --- a/contrib/mobile/iOS/Onelab/ParametersViewController.mm +++ b/contrib/mobile/iOS/Onelab/ParametersViewController.mm @@ -13,320 +13,318 @@ - (void)awakeFromNib { - self.clearsSelectionOnViewWillAppear = NO; - self.preferredContentSize = CGSizeMake(320.0, 600.0); - [super awakeFromNib]; + self.clearsSelectionOnViewWillAppear = NO; + self.preferredContentSize = CGSizeMake(320.0, 600.0); + [super awakeFromNib]; } - (void)viewDidLoad { - [super viewDidLoad]; + [super viewDidLoad]; - // Do any additional setup after loading the view, typically from a nib. - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshParameters:) name:@"refreshParameters" object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetParameters:) name:@"resetParameters" object:nil]; + // Do any additional setup after loading the view, typically from a nib. + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshParameters:) name:@"refreshParameters" object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetParameters:) name:@"resetParameters" object:nil]; - self.navigationItem.title = @"Model"; - - _sections = [[NSMutableArray alloc] init]; - _sectionstitle = [[NSMutableArray alloc] init]; - - [self.navigationController setToolbarHidden:NO]; - control = [[UISegmentedControl alloc] initWithItems:[[NSArray alloc] initWithObjects:@"Model", @"Display", nil]]; - UIBarButtonItem *controlBtn = [[UIBarButtonItem alloc] initWithCustomView:control]; - UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; - self.toolbarItems = [[NSArray alloc] initWithObjects:flexibleSpace, controlBtn, flexibleSpace, nil]; - [control addTarget:self action:@selector(indexDidChangeForSegmentedControl:) forControlEvents:UIControlEventValueChanged]; - if(![[UIDevice currentDevice].model isEqualToString:@"iPad"] && ![[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]){ - self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed:)]; - } - self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Reset" style:UIBarButtonItemStyleBordered target:self action:@selector(resetParameters:)]; + self.navigationItem.title = @"Model"; + + _sections = [[NSMutableArray alloc] init]; + _sectionstitle = [[NSMutableArray alloc] init]; + + [self.navigationController setToolbarHidden:NO]; + control = [[UISegmentedControl alloc] initWithItems:[[NSArray alloc] initWithObjects:@"Model", @"Display", nil]]; + UIBarButtonItem *controlBtn = [[UIBarButtonItem alloc] initWithCustomView:control]; + UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; + self.toolbarItems = [[NSArray alloc] initWithObjects:flexibleSpace, controlBtn, flexibleSpace, nil]; + [control addTarget:self action:@selector(indexDidChangeForSegmentedControl:) forControlEvents:UIControlEventValueChanged]; + if(![[UIDevice currentDevice].model isEqualToString:@"iPad"] && ![[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]){ + self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed:)]; + } + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Reset" style:UIBarButtonItemStyleBordered target:self action:@selector(resetParameters:)]; } - (void)viewWillAppear:(BOOL)animated { - [self refreshParameters:nil]; - control.selectedSegmentIndex = 0; - [super viewWillAppear:animated]; + [self refreshParameters:nil]; + control.selectedSegmentIndex = 0; + [super viewWillAppear:animated]; } -(void)backButtonPressed:(id)sender { - [self.navigationController popViewControllerAnimated:YES]; + [self.navigationController popViewControllerAnimated:YES]; } - (void)indexDidChangeForSegmentedControl:(id)sender { - OptionsViewController *optionsViewController = [[OptionsViewController alloc] init]; - [self.navigationController pushViewController:optionsViewController animated:YES]; + OptionsViewController *optionsViewController = [[OptionsViewController alloc] init]; + [self.navigationController pushViewController:optionsViewController animated:YES]; } - (void)addParameterNumber:(onelab::number)p atIndexPath:(NSIndexPath*)indexPath { - NSMutableArray* section = [_sections objectAtIndex:indexPath.section]; - if(p.getChoices().size() && p.getChoices().size() == p.getValueLabels().size()) { // enumeration - ParameterNumberList *param = [[ParameterNumberList alloc] initWithNumber:p]; - [section addObject:param]; - } - else if(p.getChoices().size() == 2 && p.getChoices()[0] == 0 && p.getChoices()[1] == 1) { // check box - ParameterNumberCheckbox *param = [[ParameterNumberCheckbox alloc] initWithNumber:p]; - [section addObject:param]; - } - else if(p.getStep() == 0) { // text box - ParameterNumberTextbox *param = [[ParameterNumberTextbox alloc] initWithNumber:p]; - [section addObject:param]; - } - else if(p.getStep() == 1) { // stepper - ParameterNumberStepper *param = [[ParameterNumberStepper alloc] initWithNumber:p]; - [section addObject:param]; - } - else - { - ParameterNumberRange *param = [[ParameterNumberRange alloc] initWithNumber:p]; - [section addObject:param]; - } - [self.tableView beginUpdates]; - [self.tableView insertRowsAtIndexPaths:[[NSArray alloc] initWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic]; - [self.tableView endUpdates]; + NSMutableArray* section = [_sections objectAtIndex:indexPath.section]; + if(p.getChoices().size() && p.getChoices().size() == p.getValueLabels().size()) { // enumeration + ParameterNumberList *param = [[ParameterNumberList alloc] initWithNumber:p]; + [section addObject:param]; + } + else if(p.getChoices().size() == 2 && p.getChoices()[0] == 0 && p.getChoices()[1] == 1) { // check box + ParameterNumberCheckbox *param = [[ParameterNumberCheckbox alloc] initWithNumber:p]; + [section addObject:param]; + } + else if(p.getStep() == 0) { // text box + ParameterNumberTextbox *param = [[ParameterNumberTextbox alloc] initWithNumber:p]; + [section addObject:param]; + } + else if(p.getStep() == 1) { // stepper + ParameterNumberStepper *param = [[ParameterNumberStepper alloc] initWithNumber:p]; + [section addObject:param]; + } + else { + ParameterNumberRange *param = [[ParameterNumberRange alloc] initWithNumber:p]; + [section addObject:param]; + } + [self.tableView beginUpdates]; + [self.tableView insertRowsAtIndexPaths:[[NSArray alloc] initWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic]; + [self.tableView endUpdates]; } - (void)addParameterString:(onelab::string)p atIndexPath:(NSIndexPath*)indexPath { - NSMutableArray* section = [_sections objectAtIndex:indexPath.section]; - ParameterStringList *param = [[ParameterStringList alloc] initWithString:p]; - [section addObject:param]; - [self.tableView beginUpdates]; - [self.tableView insertRowsAtIndexPaths:[[NSArray alloc] initWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic]; - [self.tableView endUpdates]; + NSMutableArray* section = [_sections objectAtIndex:indexPath.section]; + ParameterStringList *param = [[ParameterStringList alloc] initWithString:p]; + [section addObject:param]; + [self.tableView beginUpdates]; + [self.tableView insertRowsAtIndexPaths:[[NSArray alloc] initWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic]; + [self.tableView endUpdates]; } - (void)removeParemeterNumberAtIndex:(NSIndexPath*)index { - [self.tableView beginUpdates]; - [self.tableView deleteRowsAtIndexPaths: [NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationAutomatic]; - [self.tableView endUpdates]; + [self.tableView beginUpdates]; + [self.tableView deleteRowsAtIndexPaths: [NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationAutomatic]; + [self.tableView endUpdates]; } - (void)addSection:(NSMutableArray*)s withTitle:(NSString*)t withParameterNumber:(onelab::number)p { - [_sections addObject:s]; - [_sectionstitle addObject:t]; - [self.tableView beginUpdates]; - [self.tableView insertSections:[[NSIndexSet alloc] initWithIndex:[_sections count]-1] withRowAnimation:UITableViewRowAnimationAutomatic]; - [self.tableView endUpdates]; - [self addParameterNumber:p atIndexPath:[NSIndexPath indexPathForRow:0 inSection:[_sections count]-1]]; + [_sections addObject:s]; + [_sectionstitle addObject:t]; + [self.tableView beginUpdates]; + [self.tableView insertSections:[[NSIndexSet alloc] initWithIndex:[_sections count]-1] withRowAnimation:UITableViewRowAnimationAutomatic]; + [self.tableView endUpdates]; + [self addParameterNumber:p atIndexPath:[NSIndexPath indexPathForRow:0 inSection:[_sections count]-1]]; } - (void)addSection:(NSMutableArray*)s withTitle:(NSString*)t withParameterString:(onelab::string)p { - [_sections addObject:s]; - [_sectionstitle addObject:t]; - [self.tableView beginUpdates]; - [self.tableView insertSections:[[NSIndexSet alloc] initWithIndex:[_sections count]-1] withRowAnimation:UITableViewRowAnimationAutomatic]; - [self.tableView endUpdates]; - [self addParameterString:p atIndexPath:[NSIndexPath indexPathForRow:0 inSection:[_sections count]-1]]; + [_sections addObject:s]; + [_sectionstitle addObject:t]; + [self.tableView beginUpdates]; + [self.tableView insertSections:[[NSIndexSet alloc] initWithIndex:[_sections count]-1] withRowAnimation:UITableViewRowAnimationAutomatic]; + [self.tableView endUpdates]; + [self addParameterString:p atIndexPath:[NSIndexPath indexPathForRow:0 inSection:[_sections count]-1]]; } - (void)refreshTableView { - std::vector<onelab::number> number; - onelab::server::instance()->get(number); + std::vector<onelab::number> number; + onelab::server::instance()->get(number); + + // check for new/updated parameters (number) + for(int i=0;i<number.size();i++) { + if(!number[i].getVisible()) continue; // Do not add invisible parameter + NSString *name=[NSString stringWithCString:number[i].getName().c_str() encoding:[NSString defaultCStringEncoding]]; + NSString *sectiontitle = [[name componentsSeparatedByString:@"/"] objectAtIndex:0]; + Boolean found = false; + + for(int iSection=0; iSection<[_sectionstitle count]; iSection++) { // Check if the section exist + if([sectiontitle isEqualToString:[_sectionstitle objectAtIndex:iSection]]) { + NSMutableArray *section = [_sections objectAtIndex:iSection]; + for(int iparameter = 0; iparameter<[section count]; iparameter++) { + if([[[section objectAtIndex: iparameter] getName] isEqualToString:name]) { // The parameter is in the section + Parameter * p = [section objectAtIndex: iparameter]; + [p refresh]; // just refresh the parameter + found = true; + break; + } + } + if(!found) // The parameter is not in the section, add it + [self addParameterNumber:number[i] atIndexPath:[NSIndexPath indexPathForRow:[section count] inSection:iSection]]; + found = true; break; + } + } + if(found) continue; // the parameter is in the tableView + // The section have to be create + NSMutableArray *newSection = [[NSMutableArray alloc] init]; + [self addSection:newSection withTitle:sectiontitle withParameterNumber:number[i]]; + } - // check for new/updated parameters (number) - for(int i=0;i<number.size();i++) { - if(!number[i].getVisible()) continue; // Do not add invisible parameter - NSString *name=[NSString stringWithCString:number[i].getName().c_str() encoding:[NSString defaultCStringEncoding]]; - NSString *sectiontitle = [[name componentsSeparatedByString:@"/"] objectAtIndex:0]; - Boolean found = false; - - for(int iSection=0; iSection<[_sectionstitle count]; iSection++) { // Check if the section exist - if([sectiontitle isEqualToString:[_sectionstitle objectAtIndex:iSection]]) { - NSMutableArray *section = [_sections objectAtIndex:iSection]; - for(int iparameter = 0; iparameter<[section count]; iparameter++) { - if([[[section objectAtIndex: iparameter] getName] isEqualToString:name]) { // The parameter is in the section - Parameter * p = [section objectAtIndex: iparameter]; - [p refresh]; // just refresh the parameter - found = true; - break; - } - } - if(!found) // The parameter is not in the section, add it - [self addParameterNumber:number[i] atIndexPath:[NSIndexPath indexPathForRow:[section count] inSection:iSection]]; - found = true; break; - } - } - if(found) continue; // the parameter is in the tableView - // The section have to be create - NSMutableArray *newSection = [[NSMutableArray alloc] init]; - [self addSection:newSection withTitle:sectiontitle withParameterNumber:number[i]]; - } - - std::vector<onelab::string> string; - onelab::server::instance()->get(string); - - // check for new/updated parameters (string) - for(int i=0;i<string.size();i++) { - if(!string[i].getVisible() || string[i].getKind() == "file") continue; // Do not add invisible parameter - NSString *name=[NSString stringWithCString:string[i].getName().c_str() encoding:[NSString defaultCStringEncoding]]; - NSString *sectiontitle = [[name componentsSeparatedByString:@"/"] objectAtIndex:0]; - Boolean found = false; - - for(int iSection=0; iSection<[_sectionstitle count]; iSection++) { // Check if the section exist - if([sectiontitle isEqualToString:[_sectionstitle objectAtIndex:iSection]]) { - NSMutableArray *section = [_sections objectAtIndex:iSection]; - for(int iparameter = 0; iparameter<[section count]; iparameter++) { - if([[[section objectAtIndex: iparameter] getName] isEqualToString:name]) { // The parameter is in the section - Parameter * p = [section objectAtIndex: iparameter]; - [p refresh]; // just refresh the parameter - found = true; - break; - } - } - if(!found) // The parameter is not in the section, add it - [self addParameterString:string[i] atIndexPath:[NSIndexPath indexPathForRow:[section count] inSection:iSection]]; - found = true; break; - } - } - if(found) continue; // the parameter is in the tableView - // The section have to be create - NSMutableArray *newSection = [[NSMutableArray alloc] init]; - [self addSection:newSection withTitle:sectiontitle withParameterString:string[i]]; - } - - // check for hidden/deleted parameters - for(int iSection=0; iSection<[_sectionstitle count]; iSection++) { - NSMutableArray *section = [_sections objectAtIndex:iSection]; - for(int iparameter = 0; iparameter<[section count]; iparameter++) { - Parameter * p = [section objectAtIndex: iparameter]; - std::vector<onelab::number> number; - onelab::server::instance()->get(number,[[p getName] UTF8String]); - std::vector<onelab::string> string; - onelab::server::instance()->get(string,[[p getName] UTF8String]); - if((number.size() < 1 && string.size() < 1) || (number.size() > 0 && !number[0].getVisible()) || (string.size() > 0 && !string[0].getVisible())){ - [section removeObjectAtIndex:iparameter]; - [self removeParemeterNumberAtIndex:[NSIndexPath indexPathForRow:iparameter inSection:iSection]]; - } - } - } + std::vector<onelab::string> string; + onelab::server::instance()->get(string); + + // check for new/updated parameters (string) + for(int i=0;i<string.size();i++) { + if(!string[i].getVisible() || string[i].getKind() == "file") continue; // Do not add invisible parameter + NSString *name=[NSString stringWithCString:string[i].getName().c_str() encoding:[NSString defaultCStringEncoding]]; + NSString *sectiontitle = [[name componentsSeparatedByString:@"/"] objectAtIndex:0]; + Boolean found = false; + + for(int iSection=0; iSection<[_sectionstitle count]; iSection++) { // Check if the section exist + if([sectiontitle isEqualToString:[_sectionstitle objectAtIndex:iSection]]) { + NSMutableArray *section = [_sections objectAtIndex:iSection]; + for(int iparameter = 0; iparameter<[section count]; iparameter++) { + if([[[section objectAtIndex: iparameter] getName] isEqualToString:name]) { // The parameter is in the section + Parameter * p = [section objectAtIndex: iparameter]; + [p refresh]; // just refresh the parameter + found = true; + break; + } + } + if(!found) // The parameter is not in the section, add it + [self addParameterString:string[i] atIndexPath:[NSIndexPath indexPathForRow:[section count] inSection:iSection]]; + found = true; break; + } + } + if(found) continue; // the parameter is in the tableView + // The section have to be create + NSMutableArray *newSection = [[NSMutableArray alloc] init]; + [self addSection:newSection withTitle:sectiontitle withParameterString:string[i]]; + } + + // check for hidden/deleted parameters + for(int iSection=0; iSection<[_sectionstitle count]; iSection++) { + NSMutableArray *section = [_sections objectAtIndex:iSection]; + for(int iparameter = 0; iparameter<[section count]; iparameter++) { + Parameter * p = [section objectAtIndex: iparameter]; + std::vector<onelab::number> number; + onelab::server::instance()->get(number,[[p getName] UTF8String]); + std::vector<onelab::string> string; + onelab::server::instance()->get(string,[[p getName] UTF8String]); + if((number.size() < 1 && string.size() < 1) || (number.size() > 0 && !number[0].getVisible()) || (string.size() > 0 && !string[0].getVisible())){ + [section removeObjectAtIndex:iparameter]; + [self removeParemeterNumberAtIndex:[NSIndexPath indexPathForRow:iparameter inSection:iSection]]; + } + } + } } - (void)viewDidUnload { - [super viewDidUnload]; - // Release any retained subviews of the main view. + [super viewDidUnload]; + // Release any retained subviews of the main view. } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { - return YES; + return YES; } - (void)refreshParameters:(id)sender { - [self performSelectorOnMainThread:@selector(refreshParameters) withObject:nil waitUntilDone:NO]; + [self performSelectorOnMainThread:@selector(refreshParameters) withObject:nil waitUntilDone:NO]; } - (void)refreshParameters { - if(!_lastRefresh) _lastRefresh = [NSDate date]; - else { - if([_lastRefresh timeIntervalSinceNow] >= -1) return; - _lastRefresh = [NSDate date]; - } - [self refreshTableView]; // Get the param + if(!_lastRefresh) _lastRefresh = [NSDate date]; + else { + if([_lastRefresh timeIntervalSinceNow] >= -1) return; + _lastRefresh = [NSDate date]; + } + [self refreshTableView]; // Get the param } - (void)resetParameters:(id)sender { - if(((AppDelegate *)[UIApplication sharedApplication].delegate)->compute) { - UIAlertView *alert; - alert = [[UIAlertView alloc] initWithTitle:@"Can't reset model's parameters" message:@"The compute have to be finished before you can reset model's parameters." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; - [alert show]; - return; - } - onelab_cb("reset"); - [_sections removeAllObjects]; - [_sectionstitle removeAllObjects]; - [self.tableView reloadData]; - onelab_cb("check"); - [self refreshTableView]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; + if(((AppDelegate *)[UIApplication sharedApplication].delegate)->compute) { + UIAlertView *alert; + alert = [[UIAlertView alloc] initWithTitle:@"Can't reset model's parameters" message:@"The compute have to be finished before you can reset model's parameters." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; + [alert show]; + return; + } + onelab_cb("reset"); + [_sections removeAllObjects]; + [_sectionstitle removeAllObjects]; + [self.tableView reloadData]; + onelab_cb("check"); + [self refreshTableView]; + [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; } #pragma mark - Table View - - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return [_sections count]; + return [_sections count]; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { - // Return NO if you do not want the specified item to be editable. - return YES; + // Return NO if you do not want the specified item to be editable. + return YES; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - if([_sections count] < section) - return 0; - NSMutableArray *mSection = [_sections objectAtIndex:section]; - return [mSection count]; + if([_sections count] < section) + return 0; + NSMutableArray *mSection = [_sections objectAtIndex:section]; + return [mSection count]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - // get the param with his name - static NSString *CellIdentifier = @"parameterCell"; - if(indexPath.section >= _sections.count) return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; - NSMutableArray *sectionContent = [_sections objectAtIndex:[indexPath section]]; - if(indexPath.row >= sectionContent.count) return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; - Parameter *tmp = [sectionContent objectAtIndex:[indexPath row]]; - - UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; - if(cell == nil) - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; - else { - cell = nil; - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; - } - [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; - [cell setUserInteractionEnabled:!([tmp isReadOnly])]; - [tmp setLabelFrame:CGRectMake(20, 5, cell.frame.size.width - 40, cell.frame.size.height/2)]; - [cell addSubview:[tmp getLabel]]; - if([tmp isKindOfClass:[ParameterStringList class]]) { - ParameterStringList *param = (ParameterStringList *)tmp; - [param setFrame:CGRectMake(20, 35, cell.frame.size.width - 40, cell.frame.size.height/2)]; - [cell addSubview:[param getUIView]]; - } - else if([tmp isKindOfClass:[ParameterNumberList class]]) { - ParameterNumberList *param = (ParameterNumberList *)tmp; - [param setFrame:CGRectMake(20, 35, cell.frame.size.width - 40, cell.frame.size.height/2)]; - [cell addSubview:[param getUIView]]; - } - else if([tmp isKindOfClass:[ParameterNumberCheckbox class]]) { - ParameterNumberCheckbox *param = (ParameterNumberCheckbox *)tmp; - [param setLabelFrame:CGRectMake(100, 5, cell.frame.size.width - 110, cell.frame.size.height)]; - [param setFrame:CGRectMake(20, 5, cell.frame.size.width - 40, cell.frame.size.height)]; - [cell addSubview:[param getCheckbox]]; - } - else if([tmp isKindOfClass:[ParameterNumberStepper class]]) { - ParameterNumberStepper *param = (ParameterNumberStepper *)tmp; - [param setFrame:CGRectMake(20, cell.frame.size.height/2+5, cell.frame.size.width - 40, cell.frame.size.height/2)]; - [cell addSubview:[param getStepper]]; - } - else if([tmp isKindOfClass:[ParameterNumberRange class]]) { - ParameterNumberRange *param = (ParameterNumberRange *)tmp; - [param setFrame:CGRectMake(20, cell.frame.size.height/2+5, cell.frame.size.width - 40, cell.frame.size.height/2)]; - [cell addSubview:[param getSlider]]; - } - else if([tmp isKindOfClass:[ParameterNumberTextbox class]]) { - ParameterNumberTextbox *param = (ParameterNumberTextbox *)tmp; - [param setFrame:CGRectMake(20, cell.frame.size.height/2+5, cell.frame.size.width - 40, cell.frame.size.height/2)]; - [cell addSubview:[param getTextbox]]; - } - - return cell; + // get the param with his name + static NSString *CellIdentifier = @"parameterCell"; + if(indexPath.section >= _sections.count) return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; + NSMutableArray *sectionContent = [_sections objectAtIndex:[indexPath section]]; + if(indexPath.row >= sectionContent.count) return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; + Parameter *tmp = [sectionContent objectAtIndex:[indexPath row]]; + + UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; + if(cell == nil) + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; + else { + cell = nil; + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; + } + [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; + [cell setUserInteractionEnabled:!([tmp isReadOnly])]; + [tmp setLabelFrame:CGRectMake(20, 5, cell.frame.size.width - 40, cell.frame.size.height/2)]; + [cell addSubview:[tmp getLabel]]; + if([tmp isKindOfClass:[ParameterStringList class]]) { + ParameterStringList *param = (ParameterStringList *)tmp; + [param setFrame:CGRectMake(20, 35, cell.frame.size.width - 40, cell.frame.size.height/2)]; + [cell addSubview:[param getUIView]]; + } + else if([tmp isKindOfClass:[ParameterNumberList class]]) { + ParameterNumberList *param = (ParameterNumberList *)tmp; + [param setFrame:CGRectMake(20, 35, cell.frame.size.width - 40, cell.frame.size.height/2)]; + [cell addSubview:[param getUIView]]; + } + else if([tmp isKindOfClass:[ParameterNumberCheckbox class]]) { + ParameterNumberCheckbox *param = (ParameterNumberCheckbox *)tmp; + [param setLabelFrame:CGRectMake(100, 5, cell.frame.size.width - 110, cell.frame.size.height)]; + [param setFrame:CGRectMake(20, 5, cell.frame.size.width - 40, cell.frame.size.height)]; + [cell addSubview:[param getCheckbox]]; + } + else if([tmp isKindOfClass:[ParameterNumberStepper class]]) { + ParameterNumberStepper *param = (ParameterNumberStepper *)tmp; + [param setFrame:CGRectMake(20, cell.frame.size.height/2+5, cell.frame.size.width - 40, cell.frame.size.height/2)]; + [cell addSubview:[param getStepper]]; + } + else if([tmp isKindOfClass:[ParameterNumberRange class]]) { + ParameterNumberRange *param = (ParameterNumberRange *)tmp; + [param setFrame:CGRectMake(20, cell.frame.size.height/2+5, cell.frame.size.width - 40, cell.frame.size.height/2)]; + [cell addSubview:[param getSlider]]; + } + else if([tmp isKindOfClass:[ParameterNumberTextbox class]]) { + ParameterNumberTextbox *param = (ParameterNumberTextbox *)tmp; + [param setFrame:CGRectMake(20, cell.frame.size.height/2+5, cell.frame.size.width - 40, cell.frame.size.height/2)]; + [cell addSubview:[param getTextbox]]; + } + + return cell; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - Parameter *param = [[_sections objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; - return [[param class] getHeight]; + Parameter *param = [[_sections objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]; + return [[param class] getHeight]; } -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { - return [_sectionstitle objectAtIndex:section]; + return [_sectionstitle objectAtIndex:section]; } @end diff --git a/contrib/mobile/iOS/Onelab/PostProcessingViewController.mm b/contrib/mobile/iOS/Onelab/PostProcessingViewController.mm index 5d04e12397e6094d6ff62581b3359bf5177c12a5..b463f2dcdf9979d85681e1c19c294eee66f61b6f 100644 --- a/contrib/mobile/iOS/Onelab/PostProcessingViewController.mm +++ b/contrib/mobile/iOS/Onelab/PostProcessingViewController.mm @@ -8,111 +8,111 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { - self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; - if (self) { - // Custom initialization - } - return self; + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) { + // Custom initialization + } + return self; } - (void)setPView:(PView*)p { - _pview = p; + _pview = p; } - (void)viewDidLoad { - [super viewDidLoad]; - // Do any additional setup after loading the view. - if(_pview) - { - [_Name setText:[NSString stringWithCString:_pview->getData()->getName().c_str() encoding:[NSString defaultCStringEncoding]]]; - [_IntervalsType setDataSource:self]; - [_IntervalsType setDelegate:self]; - [_Intervals setText:[NSString stringWithFormat:@"%d",_pview->getOptions()->nbIso]]; - UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; - numberToolbar.barStyle = UIBarStyleBlackTranslucent; - numberToolbar.items = [NSArray arrayWithObjects: - [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], - [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)], - nil]; - [numberToolbar sizeToFit]; - _Intervals.delegate = self; - _Intervals.inputAccessoryView = numberToolbar; - [_RaiseZ setValue:_pview->getOptions()->raise[2]]; - [_RaiseZ addTarget:self action:@selector(slideRaiseZ:) forControlEvents:UIControlEventValueChanged]; - [_IntervalsStepper setStepValue:1]; - [_IntervalsStepper setValue:_pview->getOptions()->nbIso]; - [_IntervalsStepper setMaximumValue:1000]; - [_IntervalsStepper setMinimumValue:1]; - } + [super viewDidLoad]; + // Do any additional setup after loading the view. + if(_pview) { + [_Name setText:[NSString stringWithCString:_pview->getData()->getName().c_str() encoding:[NSString defaultCStringEncoding]]]; + [_IntervalsType setDataSource:self]; + [_IntervalsType setDelegate:self]; + [_Intervals setText:[NSString stringWithFormat:@"%d",_pview->getOptions()->nbIso]]; + UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; + numberToolbar.barStyle = UIBarStyleBlackTranslucent; + numberToolbar.items = [NSArray arrayWithObjects: + [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], + [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)], + nil]; + [numberToolbar sizeToFit]; + _Intervals.delegate = self; + _Intervals.inputAccessoryView = numberToolbar; + [_RaiseZ setValue:_pview->getOptions()->raise[2]]; + [_RaiseZ addTarget:self action:@selector(slideRaiseZ:) forControlEvents:UIControlEventValueChanged]; + [_IntervalsStepper setStepValue:1]; + [_IntervalsStepper setValue:_pview->getOptions()->nbIso]; + [_IntervalsStepper setMaximumValue:1000]; + [_IntervalsStepper setMinimumValue:1]; + } } -(void)viewDidAppear:(BOOL)animated { - [_IntervalsType selectRow:_pview->getOptions()->intervalsType-1 inComponent:0 animated:YES]; + [_IntervalsType selectRow:_pview->getOptions()->intervalsType-1 inComponent:0 animated:YES]; } - (IBAction)stepperValueChanged:(UIStepper *)sender { - [_Intervals setText:[NSString stringWithFormat:@"%.0f", [sender value]]]; - _pview->getOptions()->nbIso = [sender value]; - _pview->setChanged(true); - [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; + [_Intervals setText:[NSString stringWithFormat:@"%.0f", [sender value]]]; + _pview->getOptions()->nbIso = [sender value]; + _pview->setChanged(true); + [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; } -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { - return 1; + return 1; } -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { - return 3; + return 3; } -(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { - NSArray *name = [[NSArray alloc] initWithObjects:@"Iso-values", @"Continuous map", @"Filled iso-values", nil]; - return [name objectAtIndex:row]; + NSArray *name = [[NSArray alloc] initWithObjects:@"Iso-values", @"Continuous map", @"Filled iso-values", nil]; + return [name objectAtIndex:row]; } -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { - _pview->getOptions()->intervalsType = 1+row; - _pview->setChanged(true); - [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; + _pview->getOptions()->intervalsType = 1+row; + _pview->setChanged(true); + [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; } - (void)slideRaiseZ:(UISlider*)sender { - _pview->getOptions()->raise[2] = sender.value; - _pview->setChanged(true); - [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; + _pview->getOptions()->raise[2] = sender.value; + _pview->setChanged(true); + [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; } - (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. } -(BOOL)textFieldShouldEndEditing:(UITextField *)textField { - [_IntervalsStepper setValue:_pview->getOptions()->nbIso]; - _pview->getOptions()->nbIso = [textField.text integerValue]; - _pview->setChanged(true); - [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; - return YES; + [_IntervalsStepper setValue:_pview->getOptions()->nbIso]; + _pview->getOptions()->nbIso = [textField.text integerValue]; + _pview->setChanged(true); + [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; + return YES; } -(BOOL)textFieldShouldReturn:(UITextField *)textField { - return [_Intervals endEditing:YES]; + return [_Intervals endEditing:YES]; } -(void)doneWithNumberPad { - [_Intervals endEditing:YES]; + [_Intervals endEditing:YES]; } -- (void)viewDidUnload { - [self setName:nil]; - [self setRaiseZ:nil]; - [self setIntervals:nil]; - [self setIntervalsType:nil]; - [self setName:nil]; - [self setIntervalsStepper:nil]; - [super viewDidUnload]; +- (void)viewDidUnload +{ + [self setName:nil]; + [self setRaiseZ:nil]; + [self setIntervals:nil]; + [self setIntervalsType:nil]; + [self setName:nil]; + [self setIntervalsStepper:nil]; + [super viewDidUnload]; } @end diff --git a/contrib/mobile/iOS/Onelab/Utils.mm b/contrib/mobile/iOS/Onelab/Utils.mm index 3c01ad8f1bc83ea2ce6936f7b759b30cfa30f06f..91b06afba66910b9da4bf3b51d82741bbe4e8731 100644 --- a/contrib/mobile/iOS/Onelab/Utils.mm +++ b/contrib/mobile/iOS/Onelab/Utils.mm @@ -4,24 +4,26 @@ + (NSString *) getApplicationDocumentsDirectory { - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; - return basePath; + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; + return basePath; } + (void) copyRes { - NSString *resPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"files"]; - NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); - NSString *docPath = [paths objectAtIndex:0]; //Get the docs directory - - NSArray *resContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:resPath error:NULL]; - //[[NSFileManager defaultManager] removeItemAtPath:[docPath stringByAppendingString:@"/"] error:nil]; - for (NSString* obj in resContents){ - NSError* error; - if (![[NSFileManager defaultManager] copyItemAtPath:[resPath stringByAppendingPathComponent:obj] toPath:[docPath stringByAppendingPathComponent:obj] error:&error]) - NSLog(@"Error: %@", error); - } + NSString *resPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"files"]; + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); + NSString *docPath = [paths objectAtIndex:0]; //Get the docs directory + NSArray *resContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:resPath error:NULL]; + for (NSString *obj in resContents){ + NSLog(@"Replacing model %@", obj); + NSString *modelSrc = [[resPath stringByAppendingString:@"/"] stringByAppendingString:obj]; + NSString *modelDst = [[docPath stringByAppendingString:@"/"] stringByAppendingString:obj]; + [[NSFileManager defaultManager] removeItemAtPath:modelDst error:nil]; + NSError *error; + if (![[NSFileManager defaultManager] copyItemAtPath:modelSrc toPath:modelDst error:&error]) + NSLog(@"Error: %@", error); + } } @end diff --git a/contrib/mobile/iOS/Onelab/main.mm b/contrib/mobile/iOS/Onelab/main.mm index 02b7316b83096b6e18ae326c7deaa119d4189173..d645c7246c42e45510cfcdcd7a7ff584a700d4c1 100644 --- a/contrib/mobile/iOS/Onelab/main.mm +++ b/contrib/mobile/iOS/Onelab/main.mm @@ -4,7 +4,7 @@ int main(int argc, char *argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); - } + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } }