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

remove tableView animations + sort parameters by name in each section (should...

remove tableView animations + sort parameters by name in each section (should still fix sorting of sections)
parent d0ffd532
No related branches found
No related tags found
No related merge requests found
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1.5.1.1</string> <string>1.5.1.2</string>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<true/> <true/>
<key>UIFileSharingEnabled</key> <key>UIFileSharingEnabled</key>
......
...@@ -29,20 +29,27 @@ ...@@ -29,20 +29,27 @@
{ {
[super viewDidLoad]; [super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshOptions:) name:@"refreshParameters" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshOptions:)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshOptions:) name:@"resetParameters" object:nil]; 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]; [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:)];
else else
self.navigationItem.hidesBackButton = true; self.navigationItem.hidesBackButton = true;
} }
...@@ -55,7 +62,8 @@ ...@@ -55,7 +62,8 @@
-(void)backButtonPressed:(id)sender -(void)backButtonPressed:(id)sender
{ {
for(UIViewController *v in [self.navigationController viewControllers]) for(UIViewController *v in [self.navigationController viewControllers])
if([v isKindOfClass:[ModelViewController class]]) [self.navigationController popToViewController:v animated:YES]; if([v isKindOfClass:[ModelViewController class]])
[self.navigationController popToViewController:v animated:YES];
} }
- (void)indexDidChangeForSegmentedControl:(id)sender - (void)indexDidChangeForSegmentedControl:(id)sender
...@@ -76,23 +84,7 @@ ...@@ -76,23 +84,7 @@
- (void)refreshOptions - (void)refreshOptions
{ {
NSInteger nrow = [self.tableView numberOfRowsInSection:1]; [self.tableView reloadData];
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 #pragma mark - Table view data source
...@@ -131,38 +123,49 @@ ...@@ -131,38 +123,49 @@
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if(cell == nil) if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"postproCell"]; cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"postproCell"];
}
else { else {
cell = nil; cell = nil;
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"postproCell"]; 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)]; [cell setFrame:CGRectMake(cell.frame.origin.x, cell.frame.origin.x,
tableView.frame.size.width, cell.frame.size.height)];
switch (indexPath.section) { switch (indexPath.section) {
case 0: case 0:
{ {
[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
UISwitch *showHideOptions = [[UISwitch alloc] initWithFrame: CGRectMake(15, 6.5, 100, 30)]; UISwitch *showHideOptions = [[UISwitch alloc] initWithFrame: CGRectMake(15, 6.5, 100, 30)];
UILabel *lblOptions = [[UILabel alloc] initWithFrame:CGRectMake(25 + (showHideOptions.frame.size.width), 8, (tableView.frame.size.width - (showHideOptions.frame.size.width) - 50), 30)]; UILabel *lblOptions =
[[UILabel alloc] initWithFrame:CGRectMake
(25 + (showHideOptions.frame.size.width), 8,
(tableView.frame.size.width - (showHideOptions.frame.size.width) - 50), 30)];
if(indexPath.row == 0) { if(indexPath.row == 0) {
[lblOptions setText:@"Show geometry points"]; [lblOptions setText:@"Show geometry points"];
[showHideOptions setOn:(CTX::instance()->geom.points)]; [showHideOptions setOn:(CTX::instance()->geom.points)];
[showHideOptions addTarget:self action:@selector(setShowGeomPoints:) forControlEvents:UIControlEventValueChanged]; [showHideOptions addTarget:self action:@selector(setShowGeomPoints:)
forControlEvents:UIControlEventValueChanged];
} }
else if(indexPath.row == 1) { else if(indexPath.row == 1) {
[lblOptions setText:@"Show geometry lines"]; [lblOptions setText:@"Show geometry lines"];
[showHideOptions setOn:(CTX::instance()->geom.lines)]; [showHideOptions setOn:(CTX::instance()->geom.lines)];
[showHideOptions addTarget:self action:@selector(setShowGeomLines:) forControlEvents:UIControlEventValueChanged]; [showHideOptions addTarget:self action:@selector(setShowGeomLines:)
forControlEvents:UIControlEventValueChanged];
} }
else if(indexPath.row == 2) { else if(indexPath.row == 2) {
[lblOptions setText:@"Show mesh surface edges"]; [lblOptions setText:@"Show mesh surface edges"];
[showHideOptions setOn:(CTX::instance()->mesh.surfacesEdges)]; [showHideOptions setOn:(CTX::instance()->mesh.surfacesEdges)];
[showHideOptions addTarget:self action:@selector(setShowMeshSurfacesEdges:) forControlEvents:UIControlEventValueChanged]; [showHideOptions addTarget:self action:@selector(setShowMeshSurfacesEdges:)
forControlEvents:UIControlEventValueChanged];
} }
else if(indexPath.row == 3) { else if(indexPath.row == 3) {
[lblOptions setText:@"Show mesh volumes edges"]; [lblOptions setText:@"Show mesh volumes edges"];
[showHideOptions setOn:CTX::instance()->mesh.volumesEdges]; [showHideOptions setOn:CTX::instance()->mesh.volumesEdges];
[showHideOptions addTarget:self action:@selector(setShowMeshVolumesEdges:) forControlEvents:UIControlEventValueChanged]; [showHideOptions addTarget:self action:@selector(setShowMeshVolumesEdges:)
forControlEvents:UIControlEventValueChanged];
} }
[cell addSubview:showHideOptions]; [cell addSubview:showHideOptions];
[cell addSubview:lblOptions]; [cell addSubview:lblOptions];
...@@ -183,7 +186,9 @@ ...@@ -183,7 +186,9 @@
int i = PView::list.size() - 1 - indexPath.row; int i = PView::list.size() - 1 - indexPath.row;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UISwitch *showHide = [[UISwitch alloc] initWithFrame: CGRectMake(15, 6.5, 100, 30)]; UISwitch *showHide = [[UISwitch alloc] initWithFrame: CGRectMake(15, 6.5, 100, 30)];
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(25 + (showHide.frame.size.width), 8, (tableView.frame.size.width - showHide.frame.size.width - 50), 30)]; UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake
(25 + (showHide.frame.size.width), 8,
(tableView.frame.size.width - showHide.frame.size.width - 50), 30)];
[showHide setOn:(PView::list[i]->getOptions()->visible == 1)]; [showHide setOn:(PView::list[i]->getOptions()->visible == 1)];
[showHide setTag:i]; [showHide setTag:i];
[showHide addTarget:self action:@selector(PViewVisible:) forControlEvents:UIControlEventValueChanged]; [showHide addTarget:self action:@selector(PViewVisible:) forControlEvents:UIControlEventValueChanged];
...@@ -206,7 +211,8 @@ ...@@ -206,7 +211,8 @@
storyboard = [UIStoryboard storyboardWithName:@"iPadStoryboard" bundle:nil]; storyboard = [UIStoryboard storyboardWithName:@"iPadStoryboard" bundle:nil];
else else
storyboard = [UIStoryboard storyboardWithName:@"iPhoneiPodStoryboard" bundle:nil]; storyboard = [UIStoryboard storyboardWithName:@"iPhoneiPodStoryboard" bundle:nil];
PostProcessingViewController *postPro = [storyboard instantiateViewControllerWithIdentifier:@"PostProcessingViewController"]; PostProcessingViewController *postPro =
[storyboard instantiateViewControllerWithIdentifier:@"PostProcessingViewController"];
[postPro setPView:PView::list[[tableView numberOfRowsInSection:1]-1- indexPath.row]]; [postPro setPView:PView::list[[tableView numberOfRowsInSection:1]-1- indexPath.row]];
[self.navigationController pushViewController:postPro animated:YES]; [self.navigationController pushViewController:postPro animated:YES];
} }
...@@ -216,23 +222,27 @@ ...@@ -216,23 +222,27 @@
CTX::instance()->geom.points = sender.on; CTX::instance()->geom.points = sender.on;
[[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil];
} }
- (void)setShowGeomLines:(UISwitch*)sender - (void)setShowGeomLines:(UISwitch*)sender
{ {
CTX::instance()->geom.lines = sender.on; CTX::instance()->geom.lines = sender.on;
[[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil];
} }
- (void)setShowMeshVolumesEdges:(UISwitch*)sender - (void)setShowMeshVolumesEdges:(UISwitch*)sender
{ {
CTX::instance()->mesh.volumesEdges = sender.on; CTX::instance()->mesh.volumesEdges = sender.on;
CTX::instance()->mesh.changed = ENT_VOLUME; CTX::instance()->mesh.changed = ENT_VOLUME;
[[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil];
} }
- (void)setShowMeshSurfacesEdges:(UISwitch*)sender - (void)setShowMeshSurfacesEdges:(UISwitch*)sender
{ {
CTX::instance()->mesh.surfacesEdges = sender.on; CTX::instance()->mesh.surfacesEdges = sender.on;
CTX::instance()->mesh.changed = ENT_SURFACE; CTX::instance()->mesh.changed = ENT_SURFACE;
[[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil];
} }
-(IBAction)PViewVisible:(id)sender -(IBAction)PViewVisible:(id)sender
{ {
PView::list[((UISwitch*)sender).tag]->getOptions()->visible = (((UISwitch*)sender).on)? 1 : 0; PView::list[((UISwitch*)sender).tag]->getOptions()->visible = (((UISwitch*)sender).on)? 1 : 0;
...@@ -252,6 +262,7 @@ ...@@ -252,6 +262,7 @@
[[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"requestRender" object:nil];
return YES; return YES;
} }
-(BOOL)textFieldShouldReturn:(UITextField *)textField -(BOOL)textFieldShouldReturn:(UITextField *)textField
{ {
[textField endEditing:YES]; [textField endEditing:YES];
......
...@@ -39,12 +39,15 @@ ...@@ -39,12 +39,15 @@
[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 *flexibleSpace =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; [[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 = self.navigationItem.leftBarButtonItem =
...@@ -116,9 +119,8 @@ ...@@ -116,9 +119,8 @@
[self.navigationController pushViewController:optionsViewController animated:YES]; [self.navigationController pushViewController:optionsViewController animated:YES];
} }
- (void)addParameterNumber:(onelab::number)p atIndexPath:(NSIndexPath*)indexPath - (void)addParameterNumber:(onelab::number)p inSection:(NSMutableArray*)section
{ {
NSMutableArray* section = [_sections objectAtIndex:indexPath.section];
if(p.getChoices().size() && p.getChoices().size() == p.getValueLabels().size()) { // enumeration if(p.getChoices().size() && p.getChoices().size() == p.getValueLabels().size()) { // enumeration
ParameterNumberList *param = [[ParameterNumberList alloc] initWithNumber:p]; ParameterNumberList *param = [[ParameterNumberList alloc] initWithNumber:p];
[section addObject:param]; [section addObject:param];
...@@ -141,51 +143,26 @@ ...@@ -141,51 +143,26 @@
ParameterNumberRange *param = [[ParameterNumberRange alloc] initWithNumber:p]; ParameterNumberRange *param = [[ParameterNumberRange alloc] initWithNumber:p];
[section addObject:param]; [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 - (void)addParameterString:(onelab::string)p inSection:(NSMutableArray*)section
{ {
NSMutableArray* section = [_sections objectAtIndex:indexPath.section];
ParameterStringList *param = [[ParameterStringList alloc] initWithString:p]; ParameterStringList *param = [[ParameterStringList alloc] initWithString:p];
[section addObject:param]; [section addObject:param];
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:[[NSArray alloc] initWithObjects:indexPath, nil]
withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}
- (void)removeParameterAtIndex:(NSIndexPath*)index
{
[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 - (void)addSection:(NSMutableArray*)s withTitle:(NSString*)t withParameterNumber:(onelab::number)p
{ {
[_sections addObject:s]; [_sections addObject:s];
[_sectionstitle addObject:t]; [_sectionstitle addObject:t];
[self.tableView beginUpdates]; [self addParameterNumber:p inSection:s];
[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 - (void)addSection:(NSMutableArray*)s withTitle:(NSString*)t withParameterString:(onelab::string)p
{ {
[_sections addObject:s]; [_sections addObject:s];
[_sectionstitle addObject:t]; [_sectionstitle addObject:t];
[self.tableView beginUpdates]; [self addParameterString:p inSection:s];
[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]];
} }
NSString *GetSectionTitle(NSString *name) NSString *GetSectionTitle(NSString *name)
...@@ -207,6 +184,11 @@ NSString *GetSectionTitle(NSString *name) ...@@ -207,6 +184,11 @@ NSString *GetSectionTitle(NSString *name)
return s; return s;
} }
NSInteger compareParameter(id p1, id p2, void *context)
{
return [[p1 getName] compare:[p2 getName]];
}
- (void)refreshTableView - (void)refreshTableView
{ {
std::vector<onelab::number> number; std::vector<onelab::number> number;
...@@ -220,11 +202,12 @@ NSString *GetSectionTitle(NSString *name) ...@@ -220,11 +202,12 @@ NSString *GetSectionTitle(NSString *name)
NSString *name = [Utils getStringFromCString:number[i].getName().c_str()]; NSString *name = [Utils getStringFromCString:number[i].getName().c_str()];
NSString *sectiontitle = GetSectionTitle(name); 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++) {
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;
...@@ -232,16 +215,10 @@ NSString *GetSectionTitle(NSString *name) ...@@ -232,16 +215,10 @@ NSString *GetSectionTitle(NSString *name)
} }
} }
if(!found){ // the parameter is not in the section, add it if(!found){ // the parameter is not in the section, add it
// FIXME: we should insert it at the right position [self addParameterNumber:number[i] inSection:section];
// int index = 0;
// while(index < [section count]) {
// if([[[section objectAtIndex: index] getName] compare:name] == NSOrderedAscending) break;
// index++;
// }
// + do the necessary reloads of indexPaths in the updates
[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
...@@ -255,15 +232,15 @@ NSString *GetSectionTitle(NSString *name) ...@@ -255,15 +232,15 @@ NSString *GetSectionTitle(NSString *name)
// 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;
NSString *name = [Utils getStringFromCString:string[i].getName().c_str()]; NSString *name = [Utils getStringFromCString:string[i].getName().c_str()];
NSString *sectiontitle = GetSectionTitle(name); 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++) {
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]) {
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;
...@@ -271,10 +248,10 @@ NSString *GetSectionTitle(NSString *name) ...@@ -271,10 +248,10 @@ NSString *GetSectionTitle(NSString *name)
} }
} }
if(!found){ // the parameter is not in the section, add it if(!found){ // the parameter is not in the section, add it
// FIXME: we should insert it at the right position [self addParameterString:string[i] inSection:section];
[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
...@@ -296,10 +273,17 @@ NSString *GetSectionTitle(NSString *name) ...@@ -296,10 +273,17 @@ NSString *GetSectionTitle(NSString *name)
(number.size() > 0 && !number[0].getVisible()) || (number.size() > 0 && !number[0].getVisible()) ||
(string.size() > 0 && !string[0].getVisible())){ (string.size() > 0 && !string[0].getVisible())){
[section removeObjectAtIndex:iparameter]; [section removeObjectAtIndex:iparameter];
[self removeParameterAtIndex:[NSIndexPath indexPathForRow:iparameter inSection:iSection]];
} }
} }
} }
// sort parameters in each section
for(int iSection = 0; iSection < [_sections count]; iSection++) {
NSMutableArray *section = [_sections objectAtIndex:iSection];
[section sortUsingFunction:compareParameter context:nil];
}
[self.tableView reloadData];
} }
- (void)viewDidUnload - (void)viewDidUnload
...@@ -320,7 +304,9 @@ NSString *GetSectionTitle(NSString *name) ...@@ -320,7 +304,9 @@ NSString *GetSectionTitle(NSString *name)
- (void)refreshParameters - (void)refreshParameters
{ {
if(!_lastRefresh) _lastRefresh = [NSDate date]; if(!_lastRefresh){
_lastRefresh = [NSDate date];
}
else { else {
if([_lastRefresh timeIntervalSinceNow] >= -0.1) return; if([_lastRefresh timeIntervalSinceNow] >= -0.1) return;
_lastRefresh = [NSDate date]; _lastRefresh = [NSDate date];
...@@ -332,7 +318,8 @@ NSString *GetSectionTitle(NSString *name) ...@@ -332,7 +318,8 @@ NSString *GetSectionTitle(NSString *name)
{ {
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" alert = [[UIAlertView alloc]
initWithTitle:@"Can't reset model parameters"
message:@"The computation has to complete before you can reset the parameters." message:@"The computation has to complete before you can reset the parameters."
delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show]; [alert show];
...@@ -373,51 +360,63 @@ NSString *GetSectionTitle(NSString *name) ...@@ -373,51 +360,63 @@ NSString *GetSectionTitle(NSString *name)
// 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) if(indexPath.section >= _sections.count)
return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
NSMutableArray *sectionContent = [_sections objectAtIndex:[indexPath section]]; NSMutableArray *sectionContent = [_sections objectAtIndex:[indexPath section]];
if(indexPath.row >= sectionContent.count) if(indexPath.row >= sectionContent.count)
return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 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];
if(cell == nil) if(cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
else { else {
cell = nil; cell = nil;
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
} }
[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[tmp setLabelFrame:CGRectMake(20, 5, tableView.frame.size.width - 40, cell.frame.size.height/2)]; [tmp setLabelFrame:CGRectMake(20, 5, tableView.frame.size.width - 40,
cell.frame.size.height/2)];
[cell addSubview:[tmp getLabel]]; [cell addSubview:[tmp getLabel]];
if([tmp isKindOfClass:[ParameterStringList class]]) { if([tmp isKindOfClass:[ParameterStringList class]]) {
ParameterStringList *param = (ParameterStringList *)tmp; ParameterStringList *param = (ParameterStringList *)tmp;
[param setFrame:CGRectMake(20, 35, tableView.frame.size.width - 40, cell.frame.size.height/2)]; [param setFrame:CGRectMake(20, 35, tableView.frame.size.width - 40,
cell.frame.size.height/2)];
[cell addSubview:[param getUIView]]; [cell addSubview:[param getUIView]];
} }
else if([tmp isKindOfClass:[ParameterNumberList class]]) { else if([tmp isKindOfClass:[ParameterNumberList class]]) {
ParameterNumberList *param = (ParameterNumberList *)tmp; ParameterNumberList *param = (ParameterNumberList *)tmp;
[param setFrame:CGRectMake(20, 35, tableView.frame.size.width - 40, cell.frame.size.height/2)]; [param setFrame:CGRectMake(20, 35, tableView.frame.size.width - 40,
cell.frame.size.height/2)];
[cell addSubview:[param getUIView]]; [cell addSubview:[param getUIView]];
} }
else if([tmp isKindOfClass:[ParameterNumberCheckbox class]]) { else if([tmp isKindOfClass:[ParameterNumberCheckbox class]]) {
ParameterNumberCheckbox *param = (ParameterNumberCheckbox *)tmp; ParameterNumberCheckbox *param = (ParameterNumberCheckbox *)tmp;
[param setLabelFrame:CGRectMake(85, 10, tableView.frame.size.width - 95, cell.frame.size.height/2)]; [param setLabelFrame:CGRectMake(85, 10, tableView.frame.size.width - 95,
[param setFrame:CGRectMake(20, 5, tableView.frame.size.width - 40, cell.frame.size.height)]; cell.frame.size.height/2)];
[param setFrame:CGRectMake(20, 5, tableView.frame.size.width - 40,
cell.frame.size.height)];
[cell addSubview:[param getCheckbox]]; [cell addSubview:[param getCheckbox]];
} }
else if([tmp isKindOfClass:[ParameterNumberStepper class]]) { else if([tmp isKindOfClass:[ParameterNumberStepper class]]) {
ParameterNumberStepper *param = (ParameterNumberStepper *)tmp; ParameterNumberStepper *param = (ParameterNumberStepper *)tmp;
[param setFrame:CGRectMake(20, cell.frame.size.height/2 + 5, tableView.frame.size.width - 40, cell.frame.size.height/2)]; [param setFrame:CGRectMake(20, cell.frame.size.height/2 + 5,
tableView.frame.size.width - 40, cell.frame.size.height/2)];
[cell addSubview:[param getStepper]]; [cell addSubview:[param getStepper]];
} }
else if([tmp isKindOfClass:[ParameterNumberRange class]]) { else if([tmp isKindOfClass:[ParameterNumberRange class]]) {
ParameterNumberRange *param = (ParameterNumberRange *)tmp; ParameterNumberRange *param = (ParameterNumberRange *)tmp;
[param setFrame:CGRectMake(20, cell.frame.size.height/2 + 10, tableView.frame.size.width - 40, cell.frame.size.height/2)]; [param setFrame:CGRectMake(20, cell.frame.size.height/2 + 10,
tableView.frame.size.width - 40, cell.frame.size.height/2)];
[cell addSubview:[param getSlider]]; [cell addSubview:[param getSlider]];
} }
else if([tmp isKindOfClass:[ParameterNumberTextbox class]]) { else if([tmp isKindOfClass:[ParameterNumberTextbox class]]) {
ParameterNumberTextbox *param = (ParameterNumberTextbox *)tmp; ParameterNumberTextbox *param = (ParameterNumberTextbox *)tmp;
[param setFrame:CGRectMake(20, cell.frame.size.height/2 + 10, tableView.frame.size.width - 40, cell.frame.size.height/2)]; [param setFrame:CGRectMake(20, cell.frame.size.height/2 + 10,
tableView.frame.size.width - 40, cell.frame.size.height/2)];
[cell addSubview:[param getTextbox]]; [cell addSubview:[param getTextbox]];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment