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

better section headings

parent 2d2c5790
No related branches found
No related tags found
No related merge requests found
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.geuz.onelab" package="org.geuz.onelab"
android:versionCode="15" android:versionCode="16"
android:versionName="1.2.1" android:versionName="1.2.2"
android:installLocation="auto" > android:installLocation="auto" >
<uses-sdk android:minSdkVersion="14" <uses-sdk android:minSdkVersion="14"
......
...@@ -35,11 +35,11 @@ ...@@ -35,11 +35,11 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.2.0</string> <string>1.2.1</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1.2.0</string> <string>1.2.1</string>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<true/> <true/>
<key>UIFileSharingEnabled</key> <key>UIFileSharingEnabled</key>
......
...@@ -22,29 +22,37 @@ ...@@ -22,29 +22,37 @@
[super viewDidLoad]; [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. // 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(refreshParameters:)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetParameters:) name:@"resetParameters" object:nil]; name:@"refreshParameters" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetParameters:)
name:@"resetParameters" object:nil];
self.navigationItem.title = @"Model"; self.navigationItem.title = @"Model";
_sections = [[NSMutableArray alloc] init]; _sections = [[NSMutableArray alloc] init];
_sectionstitle = [[NSMutableArray alloc] init]; _sectionstitle = [[NSMutableArray alloc] init];
UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; UILongPressGestureRecognizer *lpgr =
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 1.0; lpgr.minimumPressDuration = 1.0;
[self.tableView addGestureRecognizer:lpgr]; [self.tableView addGestureRecognizer:lpgr];
[self.navigationController setToolbarHidden:NO]; [self.navigationController setToolbarHidden:NO];
control = [[UISegmentedControl alloc] initWithItems:[[NSArray alloc] initWithObjects:@"Model", @"Display", nil]]; control = [[UISegmentedControl alloc] initWithItems:[[NSArray alloc] initWithObjects:@"Model", @"Display", nil]];
UIBarButtonItem *controlBtn = [[UIBarButtonItem alloc] initWithCustomView:control]; UIBarButtonItem *controlBtn = [[UIBarButtonItem alloc] initWithCustomView:control];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *flexibleSpace =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
self.toolbarItems = [[NSArray alloc] initWithObjects:flexibleSpace, controlBtn, flexibleSpace, nil]; self.toolbarItems = [[NSArray alloc] initWithObjects:flexibleSpace, controlBtn, flexibleSpace, nil];
[control addTarget:self action:@selector(indexDidChangeForSegmentedControl:) forControlEvents:UIControlEventValueChanged]; [control addTarget:self action:@selector(indexDidChangeForSegmentedControl:) forControlEvents:UIControlEventValueChanged];
if(![[UIDevice currentDevice].model isEqualToString:@"iPad"] && if(![[UIDevice currentDevice].model isEqualToString:@"iPad"] &&
![[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]){ ![[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]){
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed:)]; 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.rightBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:@"Reset" style:UIBarButtonItemStyleBordered
target:self action:@selector(resetParameters:)];
} }
- (void)viewWillAppear:(BOOL)animated - (void)viewWillAppear:(BOOL)animated
...@@ -74,7 +82,9 @@ ...@@ -74,7 +82,9 @@
onelab::server::instance()->get(number,[name UTF8String]); onelab::server::instance()->get(number,[name UTF8String]);
if(number.size() && !number[0].getReadOnly()){ if(number.size() && !number[0].getReadOnly()){
NSLog(@"Manual edit of parameter '%s' with value '%g'", number[0].getName().c_str(), number[0].getValue()); NSLog(@"Manual edit of parameter '%s' with value '%g'", number[0].getName().c_str(), number[0].getValue());
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s", number[0].getShortName().c_str()] message:name delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil]; UIAlertView *alertView =
[[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s", number[0].getShortName().c_str()]
message:name delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput; alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView textFieldAtIndex:0].text = [NSString stringWithFormat:@"%g", number[0].getValue()]; [alertView textFieldAtIndex:0].text = [NSString stringWithFormat:@"%g", number[0].getValue()];
[alertView show]; [alertView show];
...@@ -130,7 +140,8 @@ ...@@ -130,7 +140,8 @@
[section addObject:param]; [section addObject:param];
} }
[self.tableView beginUpdates]; [self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:[[NSArray alloc] initWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic]; [self.tableView insertRowsAtIndexPaths:[[NSArray alloc] initWithObjects:indexPath, nil]
withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates]; [self.tableView endUpdates];
} }
...@@ -140,14 +151,16 @@ ...@@ -140,14 +151,16 @@
ParameterStringList *param = [[ParameterStringList alloc] initWithString:p]; ParameterStringList *param = [[ParameterStringList alloc] initWithString:p];
[section addObject:param]; [section addObject:param];
[self.tableView beginUpdates]; [self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:[[NSArray alloc] initWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationAutomatic]; [self.tableView insertRowsAtIndexPaths:[[NSArray alloc] initWithObjects:indexPath, nil]
withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates]; [self.tableView endUpdates];
} }
- (void)removeParemeterNumberAtIndex:(NSIndexPath*)index - (void)removeParemeterNumberAtIndex:(NSIndexPath*)index
{ {
[self.tableView beginUpdates]; [self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths: [NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationAutomatic]; [self.tableView deleteRowsAtIndexPaths: [NSArray arrayWithObject:index]
withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates]; [self.tableView endUpdates];
} }
...@@ -156,7 +169,8 @@ ...@@ -156,7 +169,8 @@
[_sections addObject:s]; [_sections addObject:s];
[_sectionstitle addObject:t]; [_sectionstitle addObject:t];
[self.tableView beginUpdates]; [self.tableView beginUpdates];
[self.tableView insertSections:[[NSIndexSet alloc] initWithIndex:[_sections count]-1] withRowAnimation:UITableViewRowAnimationAutomatic]; [self.tableView insertSections:[[NSIndexSet alloc] initWithIndex:[_sections count]-1]
withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates]; [self.tableView endUpdates];
[self addParameterNumber:p atIndexPath:[NSIndexPath indexPathForRow:0 inSection:[_sections count]-1]]; [self addParameterNumber:p atIndexPath:[NSIndexPath indexPathForRow:0 inSection:[_sections count]-1]];
} }
...@@ -166,41 +180,60 @@ ...@@ -166,41 +180,60 @@
[_sections addObject:s]; [_sections addObject:s];
[_sectionstitle addObject:t]; [_sectionstitle addObject:t];
[self.tableView beginUpdates]; [self.tableView beginUpdates];
[self.tableView insertSections:[[NSIndexSet alloc] initWithIndex:[_sections count]-1] withRowAnimation:UITableViewRowAnimationAutomatic]; [self.tableView insertSections:[[NSIndexSet alloc] initWithIndex:[_sections count]-1]
withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates]; [self.tableView endUpdates];
[self addParameterString:p atIndexPath:[NSIndexPath indexPathForRow:0 inSection:[_sections count]-1]]; [self addParameterString:p atIndexPath:[NSIndexPath indexPathForRow:0 inSection:[_sections count]-1]];
} }
NSString *GetSectionTitle(NSString *name)
{
NSString *s = @"";
NSArray *split = [name componentsSeparatedByString:@"/"];
for(int i = 0; i < [split count] - 1; i++){
NSString *name = [split objectAtIndex:i];
while([name length] && [name characterAtIndex:0] == ' ')
name = [name substringFromIndex:1];
while([name length] && ([name characterAtIndex:0] == '{' || [name characterAtIndex:0] == '}'))
name = [name substringFromIndex:1];
while([name length] && [name characterAtIndex:0] >= '0' && [name characterAtIndex:0] <= '9')
name = [name substringFromIndex:1];
if(i)
s = [s stringByAppendingString:@" > "];
s = [s stringByAppendingString:name];
}
return s;
}
- (void)refreshTableView - (void)refreshTableView
{ {
std::vector<onelab::number> number; std::vector<onelab::number> number;
onelab::server::instance()->get(number); onelab::server::instance()->get(number);
// check for new/updated parameters (number) // check for new/updated parameters (number)
for(int i=0;i<number.size();i++) { for(int i = 0; i < number.size(); i++) {
if(!number[i].getVisible()) continue; // Do not add invisible parameter if(!number[i].getVisible()) continue; // do not add invisible parameter
NSString *name=[NSString stringWithCString:number[i].getName().c_str() encoding:NSUTF8StringEncoding]; NSString *name = [NSString stringWithCString:number[i].getName().c_str() encoding:NSUTF8StringEncoding];
NSString *sectiontitle = [[name componentsSeparatedByString:@"/"] objectAtIndex:0]; NSString *sectiontitle = GetSectionTitle(name);
Boolean found = false; Boolean found = false;
for(int iSection = 0; iSection < [_sectionstitle count]; iSection++) { // check if the section exist
for(int iSection=0; iSection<[_sectionstitle count]; iSection++) { // Check if the section exist
if([sectiontitle isEqualToString:[_sectionstitle objectAtIndex:iSection]]) { if([sectiontitle isEqualToString:[_sectionstitle objectAtIndex:iSection]]) {
NSMutableArray *section = [_sections objectAtIndex:iSection]; NSMutableArray *section = [_sections objectAtIndex:iSection];
for(int iparameter = 0; iparameter<[section count]; iparameter++) { for(int iparameter = 0; iparameter<[section count]; iparameter++) {
if([[[section objectAtIndex: iparameter] getName] isEqualToString:name]) { // The parameter is in the section if([[[section objectAtIndex: iparameter] getName] isEqualToString:name]) { // the parameter is in the section
Parameter * p = [section objectAtIndex: iparameter]; Parameter * p = [section objectAtIndex: iparameter];
[p refresh]; // just refresh the parameter [p refresh]; // just refresh the parameter
found = true; found = true;
break; break;
} }
} }
if(!found) // The parameter is not in the section, add it if(!found) // the parameter is not in the section, add it
[self addParameterNumber:number[i] atIndexPath:[NSIndexPath indexPathForRow:[section count] inSection:iSection]]; [self addParameterNumber:number[i] atIndexPath:[NSIndexPath indexPathForRow:[section count] inSection:iSection]];
found = true; break; found = true; break;
} }
} }
if(found) continue; // the parameter is in the tableView if(found) continue; // the parameter is in the tableView
// The section has to be created // the section has to be created
NSMutableArray *newSection = [[NSMutableArray alloc] init]; NSMutableArray *newSection = [[NSMutableArray alloc] init];
[self addSection:newSection withTitle:sectiontitle withParameterNumber:number[i]]; [self addSection:newSection withTitle:sectiontitle withParameterNumber:number[i]];
} }
...@@ -209,38 +242,37 @@ ...@@ -209,38 +242,37 @@
onelab::server::instance()->get(string); onelab::server::instance()->get(string);
// check for new/updated parameters (string) // check for new/updated parameters (string)
for(int i=0;i<string.size();i++) { for(int i = 0; i < string.size(); i++) {
if(!string[i].getVisible() || string[i].getKind() == "file") continue; // Do not add invisible parameter if(!string[i].getVisible() || string[i].getKind() == "file") continue; // do not add invisible parameter
NSString *name=[NSString stringWithCString:string[i].getName().c_str() encoding:NSUTF8StringEncoding]; NSString *name = [NSString stringWithCString:string[i].getName().c_str() encoding:NSUTF8StringEncoding];
NSString *sectiontitle = [[name componentsSeparatedByString:@"/"] objectAtIndex:0]; NSString *sectiontitle = GetSectionTitle(name);
Boolean found = false; Boolean found = false;
for(int iSection = 0; iSection < [_sectionstitle count]; iSection++) { // check if the section exist
for(int iSection=0; iSection<[_sectionstitle count]; iSection++) { // Check if the section exist
if([sectiontitle isEqualToString:[_sectionstitle objectAtIndex:iSection]]) { if([sectiontitle isEqualToString:[_sectionstitle objectAtIndex:iSection]]) {
NSMutableArray *section = [_sections objectAtIndex:iSection]; NSMutableArray *section = [_sections objectAtIndex:iSection];
for(int iparameter = 0; iparameter<[section count]; iparameter++) { for(int iparameter = 0; iparameter<[section count]; iparameter++) {
if([[[section objectAtIndex: iparameter] getName] isEqualToString:name]) { // The parameter is in the section if([[[section objectAtIndex: iparameter] getName] isEqualToString:name]) { // the parameter is in the section
Parameter * p = [section objectAtIndex: iparameter]; Parameter * p = [section objectAtIndex: iparameter];
[p refresh]; // just refresh the parameter [p refresh]; // just refresh the parameter
found = true; found = true;
break; break;
} }
} }
if(!found) // The parameter is not in the section, add it if(!found) // the parameter is not in the section, add it
[self addParameterString:string[i] atIndexPath:[NSIndexPath indexPathForRow:[section count] inSection:iSection]]; [self addParameterString:string[i] atIndexPath:[NSIndexPath indexPathForRow:[section count] inSection:iSection]];
found = true; break; found = true; break;
} }
} }
if(found) continue; // the parameter is in the tableView if(found) continue; // the parameter is in the tableView
// The section have to be create // the section has to be created
NSMutableArray *newSection = [[NSMutableArray alloc] init]; NSMutableArray *newSection = [[NSMutableArray alloc] init];
[self addSection:newSection withTitle:sectiontitle withParameterString:string[i]]; [self addSection:newSection withTitle:sectiontitle withParameterString:string[i]];
} }
// check for hidden/deleted parameters // check for hidden/deleted parameters
for(int iSection=0; iSection<[_sectionstitle count]; iSection++) { for(int iSection = 0; iSection < [_sectionstitle count]; iSection++) {
NSMutableArray *section = [_sections objectAtIndex:iSection]; NSMutableArray *section = [_sections objectAtIndex:iSection];
for(int iparameter = 0; iparameter<[section count]; iparameter++) { for(int iparameter = 0; iparameter < [section count]; iparameter++) {
Parameter * p = [section objectAtIndex: iparameter]; Parameter * p = [section objectAtIndex: iparameter];
std::vector<onelab::number> number; std::vector<onelab::number> number;
onelab::server::instance()->get(number,[[p getName] UTF8String]); onelab::server::instance()->get(number,[[p getName] UTF8String]);
...@@ -286,7 +318,9 @@ ...@@ -286,7 +318,9 @@
{ {
if(((AppDelegate *)[UIApplication sharedApplication].delegate)->compute) { if(((AppDelegate *)[UIApplication sharedApplication].delegate)->compute) {
UIAlertView *alert; UIAlertView *alert;
alert = [[UIAlertView alloc] initWithTitle:@"Can't reset model parameters" message:@"The computation has to complete before you can reset the parameters." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; alert = [[UIAlertView alloc] initWithTitle:@"Can't reset model parameters"
message:@"The computation has to complete before you can reset the parameters."
delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show]; [alert show];
return; return;
} }
...@@ -324,9 +358,11 @@ ...@@ -324,9 +358,11 @@
{ {
// get the param with his name // get the param with his name
static NSString *CellIdentifier = @"parameterCell"; static NSString *CellIdentifier = @"parameterCell";
if(indexPath.section >= _sections.count) return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; if(indexPath.section >= _sections.count)
return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
NSMutableArray *sectionContent = [_sections objectAtIndex:[indexPath section]]; NSMutableArray *sectionContent = [_sections objectAtIndex:[indexPath section]];
if(indexPath.row >= sectionContent.count) return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; if(indexPath.row >= sectionContent.count)
return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
Parameter *tmp = [sectionContent objectAtIndex:[indexPath row]]; Parameter *tmp = [sectionContent objectAtIndex:[indexPath row]];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment