Skip to content
Snippets Groups Projects
Commit 0dd1be68 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

replace models when a new version of the app is detected

parent d41d51a1
No related branches found
No related tags found
No related merge requests found
......@@ -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&egrave;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&ccedil;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&egrave;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&egrave;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&ccedil;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&egrave;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
......
......@@ -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
......@@ -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
......@@ -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
......@@ -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
This diff is collapsed.
This diff is collapsed.
......@@ -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
......@@ -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
......@@ -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]));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment