From 858dd25460ac28c120221245980fb7568c9fc6b3 Mon Sep 17 00:00:00 2001 From: Kilian Hofmann Date: Mon, 18 Apr 2016 15:49:46 +0200 Subject: [PATCH] RTE finder parsing done, uses database if present --- .../xcdebugger/Breakpoints_v2.xcbkptlist | 194 +++++++++++++++++- FMC Planner 2/Base.lproj/Main.storyboard | 19 +- FMC Planner 2/NavDataParser.h | 3 + FMC Planner 2/NavDataParser.m | 14 +- FMC Planner 2/SharedDeclerations.h | 1 + FMC Planner 2/SharedDeclerations.m | 1 + FMC Planner 2/ViewController.m | 4 +- FMC Planner 2/ViewControllerKeyboard.m | 3 +- FMC Planner 2/ViewControllerRouteRequest.h | 5 +- FMC Planner 2/ViewControllerRouteRequest.m | 94 ++++++++- FMC Planner 2/ViewControllerScreen.m | 17 +- FMC Planner 2/ViewControllerServiceMenu.m | 13 ++ 12 files changed, 340 insertions(+), 28 deletions(-) diff --git a/FMC PLanner 2.xcworkspace/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/FMC PLanner 2.xcworkspace/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 0b22756..829b0b7 100644 --- a/FMC PLanner 2.xcworkspace/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/FMC PLanner 2.xcworkspace/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -6,32 +6,208 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FMC Planner 2/Base.lproj/Main.storyboard b/FMC Planner 2/Base.lproj/Main.storyboard index e9d0a48..e5ab854 100644 --- a/FMC Planner 2/Base.lproj/Main.storyboard +++ b/FMC Planner 2/Base.lproj/Main.storyboard @@ -1086,6 +1086,9 @@ + + + - + + + + @@ -1139,27 +1145,30 @@ + - - - + + + + - + + diff --git a/FMC Planner 2/NavDataParser.h b/FMC Planner 2/NavDataParser.h index 29853cc..08a82dd 100644 --- a/FMC Planner 2/NavDataParser.h +++ b/FMC Planner 2/NavDataParser.h @@ -18,6 +18,9 @@ @property (nonatomic) BOOL parserReady; @property (nonatomic) BOOL notActive; +#pragma mark - init +- (instancetype)initWithHandler:(void (^)(void))handler; + #pragma mark - Search for elements in normal route entry - (NSArray *)findWaypoint:(NSString *)waypoint; diff --git a/FMC Planner 2/NavDataParser.m b/FMC Planner 2/NavDataParser.m index 2460a30..8365702 100644 --- a/FMC Planner 2/NavDataParser.m +++ b/FMC Planner 2/NavDataParser.m @@ -14,7 +14,7 @@ NSString *const Airways = @"NAVDATA/awys.txt"; NSString *const Intersections = @"NAVDATA/ints.txt"; NSString *const Navaids = @"NAVDATA/navs.txt"; -- (instancetype)init +- (instancetype)initWithHandler:(void (^)(void))handler { self = [super init]; self.parserReady = false; @@ -112,9 +112,12 @@ NSString *const Navaids = @"NAVDATA/navs.txt"; } } - if (self.navaids == nil || self.intersections == nil || - self.airways == nil) { + if (self.navaids.count == 0 || self.intersections.count == 0 || + self.airways.count == 0) { self.notActive = true; + [[NSOperationQueue mainQueue] addOperationWithBlock:^{ + handler(); + }]; } self.parserReady = true; @@ -193,7 +196,10 @@ NSString *const Navaids = @"NAVDATA/navs.txt"; } for (NSString *wpt in airwayWaypoints) { if ([wpt isEqualToString:@"OK"]) { - return @[ @"DIRECT" ]; + if ([self findWaypoint:waypoint].count > 0) { + return @[ @"DIRECT" ]; + } + return nil; } if ([[wpt substringWithRange:NSMakeRange(5, 5)] isEqualToString:waypoint]) { diff --git a/FMC Planner 2/SharedDeclerations.h b/FMC Planner 2/SharedDeclerations.h index a575b5d..8b322e2 100644 --- a/FMC Planner 2/SharedDeclerations.h +++ b/FMC Planner 2/SharedDeclerations.h @@ -19,6 +19,7 @@ extern NSString *const FMCFIRSTRTEPAGE; extern NSString *const INVALID; extern NSString *const NOTREADY; +extern NSString *const NOTACTIVE; #pragma mark - Dropbox constants diff --git a/FMC Planner 2/SharedDeclerations.m b/FMC Planner 2/SharedDeclerations.m index 216ac40..ee29ab4 100644 --- a/FMC Planner 2/SharedDeclerations.m +++ b/FMC Planner 2/SharedDeclerations.m @@ -15,6 +15,7 @@ NSString *const FMCFIRSTRTEPAGE = @"FIRSTRTEPAGE"; NSString *const INVALID = @"INVALID ENTRY"; NSString *const NOTREADY = @"NAV DATA NOT READY"; +NSString *const NOTACTIVE = @"RTE CHECKS DISABLED"; NSString *const DropboxErrorDomain = @"com.weebly.alikja.FMC"; NSString *const DropboxErrorUserInfo = @"error_summary"; diff --git a/FMC Planner 2/ViewController.m b/FMC Planner 2/ViewController.m index 4f911d2..2c119a4 100644 --- a/FMC Planner 2/ViewController.m +++ b/FMC Planner 2/ViewController.m @@ -36,7 +36,9 @@ NSOperationQueue *queue = [[NSOperationQueue alloc] init]; [queue addOperationWithBlock:^{ - _navDataParser = [[NavDataParser alloc] init]; + _navDataParser = [[NavDataParser alloc] initWithHandler:^{ + _screen.Scratchpad.text = NOTACTIVE; + }]; }]; } diff --git a/FMC Planner 2/ViewControllerKeyboard.m b/FMC Planner 2/ViewControllerKeyboard.m index d4080b1..bbaf084 100644 --- a/FMC Planner 2/ViewControllerKeyboard.m +++ b/FMC Planner 2/ViewControllerKeyboard.m @@ -112,7 +112,8 @@ else if ([sender.restorationIdentifier isEqualToString:@"Clear"]) { if ([_main.screen.Scratchpad.text isEqualToString:@"DELETE"] || [_main.screen.Scratchpad.text isEqualToString:INVALID] || - [_main.screen.Scratchpad.text isEqualToString:NOTREADY]) { + [_main.screen.Scratchpad.text isEqualToString:NOTREADY] || + [_main.screen.Scratchpad.text isEqualToString:NOTACTIVE]) { _main.screen.Scratchpad.text = @""; } else if (_main.screen.Scratchpad.text.length > 0) { diff --git a/FMC Planner 2/ViewControllerRouteRequest.h b/FMC Planner 2/ViewControllerRouteRequest.h index 6fada20..dc492db 100644 --- a/FMC Planner 2/ViewControllerRouteRequest.h +++ b/FMC Planner 2/ViewControllerRouteRequest.h @@ -11,7 +11,8 @@ #import @interface ViewControllerRouteRequest - : UIViewController + : UIViewController #pragma mark - Refrence to other views in app @@ -22,6 +23,8 @@ @property (strong, nonatomic) IBOutlet UIWebView *webView; @property (strong, nonatomic) IBOutlet UITextView *textView; @property (strong, nonatomic) IBOutlet UITextField *url; +@property (strong, nonatomic) + IBOutlet UIActivityIndicatorView *activityIndicator; - (IBAction)ok:(UIButton *)sender; diff --git a/FMC Planner 2/ViewControllerRouteRequest.m b/FMC Planner 2/ViewControllerRouteRequest.m index 775f55c..e9d08de 100644 --- a/FMC Planner 2/ViewControllerRouteRequest.m +++ b/FMC Planner 2/ViewControllerRouteRequest.m @@ -17,6 +17,9 @@ loadRequest:[NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.vatroute.net"]]]; + UIView *dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)]; + _textView.inputView = dummyView; + _activityIndicator.hidden = YES; // Do any additional setup after loading the view. } @@ -29,6 +32,84 @@ - (void)parseRoute { NSArray *route = [_textView.text componentsSeparatedByString:@" "]; + NSUInteger waypoints = 0; + NSUInteger airways = 1; + NSUInteger page = 1; + [_main.save setValue:@"DIRECT" forKey:@"ROUTE 1/@LSKL1"]; + for (NSString *str in route) { + if (waypoints < airways) { + waypoints += 1; + if (_main.navDataParser.notActive == false && + [_main.navDataParser + findWaypoint:str + onAirway:[_main.save + valueForKey:[NSString + stringWithFormat: + @"ROUTE %lu/@LSKL%lu", + (unsigned long)page, + (unsigned long) + airways]]] + .count > 0) { + [_main.save + setValue:str + forKey:[NSString + stringWithFormat:@"ROUTE %lu/@LSKR%lu", + (unsigned long)page, + (unsigned long)waypoints]]; + } + else if (_main.navDataParser.notActive) { + [_main.save + setValue:str + forKey:[NSString + stringWithFormat:@"ROUTE %lu/@LSKR%lu", + (unsigned long)page, + (unsigned long)waypoints]]; + } + else { + _main.screen.Scratchpad.text = INVALID; + break; + } + } + else if (waypoints == airways) { + airways += 1; + if (_main.navDataParser.notActive == false && + [_main.navDataParser + findWaypoint:[_main.save + valueForKey:[NSString + stringWithFormat: + @"ROUTE %lu/@LSKR%lu", + (unsigned long)page, + (unsigned long) + waypoints]] + onAirway:str] + .count > 0) { + [_main.save + setValue:str + forKey:[NSString + stringWithFormat:@"ROUTE %lu/@LSKL%lu", + (unsigned long)page, + (unsigned long)airways]]; + } + else if (_main.navDataParser.notActive) { + [_main.save + setValue:str + forKey:[NSString + stringWithFormat:@"ROUTE %lu/@LSKL%lu", + (unsigned long)page, + (unsigned long)airways]]; + } + else { + _main.screen.Scratchpad.text = INVALID; + break; + } + } + if (waypoints == 6) { + waypoints = 0; + airways = 0; + page += 1; + [_main.save setValue:@(page) forKey:@"maxRte"]; + } + } } #pragma mark - Delegate @@ -38,17 +119,24 @@ navigationType:(UIWebViewNavigationType)navigationType { - NSURL *url = [request URL]; - _url.text = [url absoluteString]; + NSURL *url = request.URL; + _url.text = url.absoluteString; + _activityIndicator.hidden = NO; + [_activityIndicator startAnimating]; return YES; } +- (void)webViewDidFinishLoad:(UIWebView *)webView +{ + _activityIndicator.hidden = YES; + [_activityIndicator stopAnimating]; +} + - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_url.text]]]; - return YES; } diff --git a/FMC Planner 2/ViewControllerScreen.m b/FMC Planner 2/ViewControllerScreen.m index 3749fe9..249e5bb 100644 --- a/FMC Planner 2/ViewControllerScreen.m +++ b/FMC Planner 2/ViewControllerScreen.m @@ -75,12 +75,21 @@ NavDataParser *parser = nil; { parser = _main.navDataParser; if ([_Scratchpad.text isEqualToString:INVALID] || - [_Scratchpad.text isEqualToString:NOTREADY]) { + [_Scratchpad.text isEqualToString:NOTREADY] || + [_Scratchpad.text isEqualToString:NOTACTIVE]) { // DO NOTHING AS OF YET } else if ([_Scratchpad.text isEqualToString:@"DELETE"]) { - ((UILabel *)tapReg.view).text = @""; - _Scratchpad.text = @""; + if ([_Header.text isEqualToString:@"MENU"]) { + if (tapReg.view.tag < 8) { + ((UILabel *)tapReg.view).text = @""; + _Scratchpad.text = @""; + } + } + else { + ((UILabel *)tapReg.view).text = @""; + _Scratchpad.text = @""; + } } else if ([_Header.text isEqualToString:@"MENU"]) { if ([((UILabel *)tapReg.view) @@ -144,7 +153,7 @@ NavDataParser *parser = nil; } } else if ([[_Header.text substringToIndex:3] isEqualToString:@"ROU"]) { - if (parser.parserReady) { + if (parser.parserReady && !parser.notActive) { // Required entries for checks UILabel *opposite = nil; diff --git a/FMC Planner 2/ViewControllerServiceMenu.m b/FMC Planner 2/ViewControllerServiceMenu.m index abbf858..c86cb3f 100644 --- a/FMC Planner 2/ViewControllerServiceMenu.m +++ b/FMC Planner 2/ViewControllerServiceMenu.m @@ -139,6 +139,19 @@ _dbNavData.enabled = YES; _dbNavData.alpha = 1.0; [self.view setNeedsDisplay]; + NSOperationQueue *queue = + [[NSOperationQueue alloc] + init]; + [queue addOperationWithBlock:^{ + _main.navDataParser = + [[NavDataParser alloc] + initWithHandler:^{ + _main.screen + .Scratchpad + .text = + NOTACTIVE; + }]; + }]; }]; }]; }