khenid

Untitled

Mar 21st, 2015
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  GraphicView.m
  3. //  W24X
  4. //
  5. //  Created by Carey Richardson on 1/31/15.
  6. //  Copyright (c) 2015 Edge of the Atlas. All rights reserved.
  7. //
  8.  
  9. #import "GraphicView.h"
  10.  
  11. #define DEGREES_TO_RADIANS(degrees)((M_PI * degrees)/180)
  12.  
  13. @implementation GraphicView
  14.  
  15. @synthesize myDelegate = _myDelegate;
  16. @synthesize thisStation, graphicBackgroundColor, baseRadius, metarObject, tfrObject, tafObject, airmetObject;
  17.  
  18. -(id)init{
  19.     //
  20.     self = [super init];
  21.     if(self){
  22.         // set vars
  23.         //NSLog(@"init");
  24.        
  25.         // set app delegate
  26.         appDelegate = [[UIApplication sharedApplication] delegate];
  27.        
  28.         // init vars
  29.         baseRadius = 58;
  30.         metarObject = [MetarObject new];
  31.         tfrObject = [TFRObject new];
  32.         tafObject = [TAFObject new];
  33.         airmetObject = [AirmetObject new];
  34.     }
  35.     return self;
  36. }
  37.  
  38. -(void)metarSingleTap:(UITapGestureRecognizer*)gesture {
  39.     // callback
  40.     [_myDelegate metarDataToggleTouched];
  41. }
  42.  
  43. -(void)metarDoubleTap:(UITapGestureRecognizer*)gesture {
  44.     // callback
  45.     [_myDelegate metarTouchedWithMetar:metarObject];
  46. }
  47.  
  48. -(void)tafSingleTap:(UITapGestureRecognizer*)gesture {
  49.     // check
  50.     NSLog(@"single");
  51. }
  52.  
  53. -(void)tafDoubleTap:(UITapGestureRecognizer*)gesture {
  54.     // callback
  55.     [_myDelegate tafTouchedWithTAF:tafObject];
  56. }
  57.  
  58. -(void)updateView{
  59.     //NSLog(@"updating");
  60.     [self setNeedsDisplay];
  61. }
  62.  
  63. -(void)drawRect:(CGRect)rect {
  64.     // Drawing code
  65.     //NSLog(@"drawing");
  66.    
  67.     // check
  68.     if([self subviews].count > 0){
  69.         // clear
  70.         for(UIView *tempView in [self subviews]){
  71.             // remove
  72.             [tempView removeFromSuperview];
  73.         }
  74.     }
  75.    
  76.     // vars
  77.     CGPoint center = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2);
  78.     float metarRadius = baseRadius;
  79.     float tfrRadius = metarRadius + 8;
  80.     float tafRadius = tfrRadius + 48;
  81.     float tafOuterPadding = 1;
  82.    
  83.     float airmetIFRRadius = tafRadius + tafOuterPadding + 8;
  84.     float airmetIFROuterPadding = 1;
  85.     float airmetICERadius = airmetIFRRadius + airmetIFROuterPadding + 8;
  86.     float airmetICEOuterPadding = 1;
  87.     float airmetTURBRadius = airmetICERadius + airmetICEOuterPadding + 8;
  88.     float airmetTURBOuterPadding = 1;
  89.     float airmetMTNRadius = airmetTURBRadius + airmetTURBOuterPadding + 8;
  90.     float airmetMTNOuterPadding = 1;
  91.     float airmetCONVRadius = airmetMTNRadius + airmetMTNOuterPadding + 8;
  92.    
  93.     // offset
  94.     NSDate *nowDate = [NSDate date];
  95.     NSTimeInterval timeZoneSeconds = [[NSTimeZone localTimeZone] secondsFromGMT];
  96.     NSDate *utcDate = [nowDate dateByAddingTimeInterval:(timeZoneSeconds * -1)];
  97.     NSDate *metarDate = metarObject.dateUTC;
  98.     NSTimeInterval distanceBetweenDates = [utcDate timeIntervalSinceDate:metarDate];
  99.     double minutesInAnHour = 60;
  100.     double secondsInAnHour = 3600;
  101.     NSInteger minutesBetweenDates = distanceBetweenDates / minutesInAnHour;
  102.     NSInteger hoursBetweenDates = distanceBetweenDates / secondsInAnHour;
  103.     NSInteger timeOffset = hoursBetweenDates;
  104.    
  105.     /*NSLog(@"now utc %@", utcDate);
  106.     NSLog(@"metar utc %@", metarDate);
  107.     NSLog(@"minutes between dates %ld", (long)minutesBetweenDates);
  108.     NSLog(@"hours between dates %ld", (long)hoursBetweenDates);
  109.     NSLog(@"time offset %ld", (long)timeOffset);
  110.     NSLog(@"global time offset %ld", (long)[appDelegate.myGlobals timeOffset]);*/
  111.    
  112.     // check
  113.     if([appDelegate.myGlobals airmetOn]){
  114.         /* ==================== */
  115.         // airmet conv bkg
  116.         /* ====================*/
  117.         UIBezierPath *airmetCONVBkg = [UIBezierPath bezierPathWithArcCenter:center radius:airmetCONVRadius startAngle:DEGREES_TO_RADIANS(0)  endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
  118.         [graphicBackgroundColor setFill];
  119.         [airmetCONVBkg fill];
  120.        
  121.         /* ==================== */
  122.         // airmet conv
  123.         /* ====================*/
  124.         for(AirmetSegmentObject *convObject in airmetObject.convSegments){
  125.             // vars
  126.             UIColor *convFill = [appDelegate.myGlobals getColorWithName:convObject.color];
  127.            
  128.             NSTimeInterval metarTimeInterval = [metarObject.dateUTC timeIntervalSince1970];
  129.             NSTimeInterval tafStartTimeInterval = [convObject.startDateUTC timeIntervalSince1970];
  130.             NSTimeInterval tafEndTimeInterval = [convObject.endDateUTC timeIntervalSince1970];
  131.             NSInteger startTimeBetweenDates = tafStartTimeInterval - metarTimeInterval;
  132.             NSInteger endTimeBetweenDates = tafEndTimeInterval - metarTimeInterval;
  133.             float startTime = (startTimeBetweenDates/3600) - timeOffset;
  134.             float endTime = (endTimeBetweenDates/3600) - timeOffset;
  135.            
  136.             // check
  137.             if(startTime < 0){
  138.                 // set
  139.                 startTime = 0;
  140.             }
  141.            
  142.             // check
  143.             if(endTime < 0){
  144.                 // set
  145.                 endTime = 0;
  146.             }
  147.            
  148.             float startDegrees = DEGREES_TO_RADIANS((startTime - 6) * 15);
  149.             float endDegrees = DEGREES_TO_RADIANS((endTime - 6) * 15);
  150.            
  151.             // conv segment
  152.             UIBezierPath *convSegment = [UIBezierPath bezierPath];
  153.             [convSegment moveToPoint:center];
  154.             [convSegment addArcWithCenter:center radius:airmetCONVRadius startAngle:startDegrees endAngle:endDegrees clockwise:YES];
  155.             [convSegment addLineToPoint:center];
  156.             [convFill setFill];
  157.             [convSegment fill];
  158.         }
  159.        
  160.         /* ==================== */
  161.         // airmet mtn spacer
  162.         /* ====================*/
  163.         UIBezierPath *airmetMTNSpacer = [UIBezierPath bezierPathWithArcCenter:center radius:(airmetMTNRadius + airmetMTNOuterPadding) startAngle:DEGREES_TO_RADIANS(0)  endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
  164.         [graphicBackgroundColor setFill];
  165.         [airmetMTNSpacer fill];
  166.        
  167.         /* ==================== */
  168.         // airmet mtn bkg
  169.         /* ====================*/
  170.         UIBezierPath *airmetMTNBkg = [UIBezierPath bezierPathWithArcCenter:center radius:airmetMTNRadius startAngle:DEGREES_TO_RADIANS(0)  endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
  171.         [graphicBackgroundColor setFill];
  172.         [airmetMTNBkg fill];
  173.        
  174.         /* ==================== */
  175.         // airmet mtn
  176.         /* ====================*/
  177.         for(AirmetSegmentObject *mtnObject in airmetObject.mtnSegments){
  178.             // vars
  179.             UIColor *mtnFill = [appDelegate.myGlobals getColorWithName:mtnObject.color];
  180.            
  181.             NSTimeInterval metarTimeInterval = [metarObject.dateUTC timeIntervalSince1970];
  182.             NSTimeInterval tafStartTimeInterval = [mtnObject.startDateUTC timeIntervalSince1970];
  183.             NSTimeInterval tafEndTimeInterval = [mtnObject.endDateUTC timeIntervalSince1970];
  184.             NSInteger startTimeBetweenDates = tafStartTimeInterval - metarTimeInterval;
  185.             NSInteger endTimeBetweenDates = tafEndTimeInterval - metarTimeInterval;
  186.             float startTime = (startTimeBetweenDates/3600) - timeOffset;
  187.             float endTime = (endTimeBetweenDates/3600) - timeOffset;
  188.            
  189.             // check
  190.             if(startTime < 0){
  191.                 // set
  192.                 startTime = 0;
  193.             }
  194.            
  195.             // check
  196.             if(endTime < 0){
  197.                 // set
  198.                 endTime = 0;
  199.             }
  200.            
  201.             float startDegrees = DEGREES_TO_RADIANS((startTime - 6) * 15);
  202.             float endDegrees = DEGREES_TO_RADIANS((endTime - 6) * 15);
  203.            
  204.             // mtn segment
  205.             UIBezierPath *mtnSegment = [UIBezierPath bezierPath];
  206.             [mtnSegment moveToPoint:center];
  207.             [mtnSegment addArcWithCenter:center radius:airmetMTNRadius startAngle:startDegrees endAngle:endDegrees clockwise:YES];
  208.             [mtnSegment addLineToPoint:center];
  209.             [mtnFill setFill];
  210.             [mtnSegment fill];
  211.         }
  212.        
  213.         /* ==================== */
  214.         // airmet turb spacer
  215.         /* ====================*/
  216.         UIBezierPath *airmetTURBSpacer = [UIBezierPath bezierPathWithArcCenter:center radius:(airmetTURBRadius + airmetTURBOuterPadding) startAngle:DEGREES_TO_RADIANS(0)  endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
  217.         [graphicBackgroundColor setFill];
  218.         [airmetTURBSpacer fill];
  219.        
  220.         /* ==================== */
  221.         // airmet turb bkg
  222.         /* ====================*/
  223.         UIBezierPath *airmetTURBBkg = [UIBezierPath bezierPathWithArcCenter:center radius:airmetTURBRadius startAngle:DEGREES_TO_RADIANS(0)  endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
  224.         [graphicBackgroundColor setFill];
  225.         [airmetTURBBkg fill];
  226.        
  227.         /* ==================== */
  228.         // airmet turb
  229.         /* ====================*/
  230.         for(AirmetSegmentObject *turbObject in airmetObject.turbSegments){
  231.             // vars
  232.             UIColor *turbFill = [appDelegate.myGlobals getColorWithName:turbObject.color];
  233.            
  234.             NSTimeInterval metarTimeInterval = [metarObject.dateUTC timeIntervalSince1970];
  235.             NSTimeInterval tafStartTimeInterval = [turbObject.startDateUTC timeIntervalSince1970];
  236.             NSTimeInterval tafEndTimeInterval = [turbObject.endDateUTC timeIntervalSince1970];
  237.             NSInteger startTimeBetweenDates = tafStartTimeInterval - metarTimeInterval;
  238.             NSInteger endTimeBetweenDates = tafEndTimeInterval - metarTimeInterval;
  239.             float startTime = (startTimeBetweenDates/3600) - timeOffset;
  240.             float endTime = (endTimeBetweenDates/3600) - timeOffset;
  241.            
  242.             // check
  243.             if(startTime < 0){
  244.                 // set
  245.                 startTime = 0;
  246.             }
  247.            
  248.             // check
  249.             if(endTime < 0){
  250.                 // set
  251.                 endTime = 0;
  252.             }
  253.            
  254.             float startDegrees = DEGREES_TO_RADIANS((startTime - 6) * 15);
  255.             float endDegrees = DEGREES_TO_RADIANS((endTime - 6) * 15);
  256.            
  257.             /*NSLog(@"this station %@", thisStation.stationId);
  258.             NSLog(@"metar time interval %f", metarTimeInterval);
  259.             NSLog(@"taf start interval %f", tafStartTimeInterval);
  260.             NSLog(@"taf end interval %f", tafEndTimeInterval);
  261.             NSLog(@"start time %0.2f", startTime);
  262.             NSLog(@"end time %0.2f\n\n", endTime);*/
  263.            
  264.             // turb segment
  265.             UIBezierPath *turbSegment = [UIBezierPath bezierPath];
  266.             [turbSegment moveToPoint:center];
  267.             [turbSegment addArcWithCenter:center radius:airmetTURBRadius startAngle:startDegrees endAngle:endDegrees clockwise:YES];
  268.             [turbSegment addLineToPoint:center];
  269.             [turbFill setFill];
  270.             [turbSegment fill];
  271.         }
  272.        
  273.         /* ==================== */
  274.         // airmet ice spacer
  275.         /* ====================*/
  276.         UIBezierPath *airmetICESpacer = [UIBezierPath bezierPathWithArcCenter:center radius:(airmetICERadius + airmetICEOuterPadding) startAngle:DEGREES_TO_RADIANS(0)  endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
  277.         [graphicBackgroundColor setFill];
  278.         [airmetICESpacer fill];
  279.        
  280.         /* ==================== */
  281.         // airmet ice bkg
  282.         /* ====================*/
  283.         UIBezierPath *airmetICEBkg = [UIBezierPath bezierPathWithArcCenter:center radius:airmetICERadius startAngle:DEGREES_TO_RADIANS(0)  endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
  284.         [graphicBackgroundColor setFill];
  285.         [airmetICEBkg fill];
  286.        
  287.         /* ==================== */
  288.         // airmet ice
  289.         /* ====================*/
  290.         for(AirmetSegmentObject *iceObject in airmetObject.iceSegments){
  291.             // vars
  292.             UIColor *iceFill = [appDelegate.myGlobals getColorWithName:iceObject.color];
  293.            
  294.             NSTimeInterval metarTimeInterval = [metarObject.dateUTC timeIntervalSince1970];
  295.             NSTimeInterval tafStartTimeInterval = [iceObject.startDateUTC timeIntervalSince1970];
  296.             NSTimeInterval tafEndTimeInterval = [iceObject.endDateUTC timeIntervalSince1970];
  297.             NSInteger startTimeBetweenDates = tafStartTimeInterval - metarTimeInterval;
  298.             NSInteger endTimeBetweenDates = tafEndTimeInterval - metarTimeInterval;
  299.             float startTime = (startTimeBetweenDates/3600) - timeOffset;
  300.             float endTime = (endTimeBetweenDates/3600) - timeOffset;
  301.            
  302.             // check
  303.             if(startTime < 0){
  304.                 // set
  305.                 startTime = 0;
  306.             }
  307.            
  308.             // check
  309.             if(endTime < 0){
  310.                 // set
  311.                 endTime = 0;
  312.             }
  313.            
  314.             float startDegrees = DEGREES_TO_RADIANS((startTime - 6) * 15);
  315.             float endDegrees = DEGREES_TO_RADIANS((endTime - 6) * 15);
  316.            
  317.             // ice segment
  318.             UIBezierPath *iceSegment = [UIBezierPath bezierPath];
  319.             [iceSegment moveToPoint:center];
  320.             [iceSegment addArcWithCenter:center radius:airmetICERadius startAngle:startDegrees endAngle:endDegrees clockwise:YES];
  321.             [iceSegment addLineToPoint:center];
  322.             [iceFill setFill];
  323.             [iceSegment fill];
  324.         }
  325.        
  326.         /* ==================== */
  327.         // airmet ifr spacer
  328.         /* ====================*/
  329.         UIBezierPath *airmetIFRSpacer = [UIBezierPath bezierPathWithArcCenter:center radius:(airmetIFRRadius + airmetIFROuterPadding) startAngle:DEGREES_TO_RADIANS(0)  endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
  330.         [graphicBackgroundColor setFill];
  331.         [airmetIFRSpacer fill];
  332.        
  333.         /* ==================== */
  334.         // airmet ifr bkg
  335.         /* ====================*/
  336.         UIBezierPath *airmetIFRBkg = [UIBezierPath bezierPathWithArcCenter:center radius:airmetIFRRadius startAngle:DEGREES_TO_RADIANS(0)  endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
  337.         [graphicBackgroundColor setFill];
  338.         [airmetIFRBkg fill];
  339.        
  340.         /* ==================== */
  341.         // airmet ifr
  342.         /* ====================*/
  343.         for(AirmetSegmentObject *ifrObject in airmetObject.ifrSegments){
  344.             // vars
  345.             UIColor *ifrFill = [appDelegate.myGlobals getColorWithName:ifrObject.color];
  346.            
  347.             NSTimeInterval metarTimeInterval = [metarObject.dateUTC timeIntervalSince1970];
  348.             NSTimeInterval tafStartTimeInterval = [ifrObject.startDateUTC timeIntervalSince1970];
  349.             NSTimeInterval tafEndTimeInterval = [ifrObject.endDateUTC timeIntervalSince1970];
  350.             NSInteger startTimeBetweenDates = tafStartTimeInterval - metarTimeInterval;
  351.             NSInteger endTimeBetweenDates = tafEndTimeInterval - metarTimeInterval;
  352.             float startTime = (startTimeBetweenDates/3600) - timeOffset;
  353.             float endTime = (endTimeBetweenDates/3600) - timeOffset;
  354.            
  355.             // check
  356.             if(startTime < 0){
  357.                 // set
  358.                 startTime = 0;
  359.             }
  360.            
  361.             // check
  362.             if(endTime < 0){
  363.                 // set
  364.                 endTime = 0;
  365.             }
  366.            
  367.             float startDegrees = DEGREES_TO_RADIANS((startTime - 6) * 15);
  368.             float endDegrees = DEGREES_TO_RADIANS((endTime - 6) * 15);
  369.            
  370.             // ifr segment
  371.             UIBezierPath *ifrSegment = [UIBezierPath bezierPath];
  372.             [ifrSegment moveToPoint:center];
  373.             [ifrSegment addArcWithCenter:center radius:airmetIFRRadius startAngle:startDegrees endAngle:endDegrees clockwise:YES];
  374.             [ifrSegment addLineToPoint:center];
  375.             [ifrFill setFill];
  376.             [ifrSegment fill];
  377.         }
  378.     }
  379.    
  380.     /* ==================== */
  381.     // airmet spacer
  382.     /* ====================*/
  383.     UIBezierPath *airmetSpacer = [UIBezierPath bezierPathWithArcCenter:center radius:(tafRadius + tafOuterPadding) startAngle:DEGREES_TO_RADIANS(0)  endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
  384.     [graphicBackgroundColor setFill];
  385.     [airmetSpacer fill];
  386.    
  387.     //NSLog(@"station reporting %@", thisStation.reporting);
  388.    
  389.     // check
  390.     if([thisStation.reporting isEqualToString:@"M"]){
  391.         /* ==================== */
  392.         // taf background
  393.         /* ====================*/
  394.         UIBezierPath *tafBkg = [UIBezierPath bezierPathWithArcCenter:center radius:tafRadius startAngle:DEGREES_TO_RADIANS(0)  endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
  395.         [[UIColor colorWithRed:70/255.0 green:70/255.0 blue:70/255.0 alpha:1] setFill];
  396.         [tafBkg fill];
  397.     }
  398.     else{
  399.         /* ==================== */
  400.         // taf background
  401.         /* ====================*/
  402.         UIBezierPath *tafBkg = [UIBezierPath bezierPathWithArcCenter:center radius:tafRadius startAngle:DEGREES_TO_RADIANS(0)  endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
  403.         [[UIColor colorWithRed:210/255.0 green:210/255.0 blue:210/255.0 alpha:1] setFill];
  404.         [tafBkg fill];
  405.        
  406.         //NSLog(@"taf segments %d", tafObject.segments.count);
  407.        
  408.         /* ==================== */
  409.         // taf segments
  410.         /* ====================*/
  411.         for(TAFSegmentObject *tafSegmentObject in [tafObject segments]){
  412.             // vars
  413.             UIColor *tafFill = [appDelegate.myGlobals getColorWithName:tafSegmentObject.color];
  414. //            NSUInteger thisWidth = (tafRadius * 2) - 0;
  415.             BOOL willCreateSegment = YES;
  416.            
  417.             NSTimeInterval metarTimeInterval = [metarObject.dateUTC timeIntervalSince1970];
  418.             NSTimeInterval tafStartTimeInterval = [tafSegmentObject.startDateUTC timeIntervalSince1970];
  419.             NSTimeInterval tafEndTimeInterval = [tafSegmentObject.endDateUTC timeIntervalSince1970];
  420.             NSInteger startTimeBetweenDates = tafStartTimeInterval - metarTimeInterval;
  421.             NSInteger endTimeBetweenDates = tafEndTimeInterval - metarTimeInterval;
  422.             float startTime = (startTimeBetweenDates/3600) - timeOffset;
  423.             float endTime = (endTimeBetweenDates/3600) - timeOffset;
  424.            
  425.             /*NSLog(@"metar time interval %f", metarTimeInterval);
  426.             NSLog(@"taf start interval %f", tafStartTimeInterval);
  427.             NSLog(@"taf end interval %f", tafEndTimeInterval);
  428.             NSLog(@"start time %0.2f", startTime);
  429.             NSLog(@"end time %0.2f\n\n", endTime);*/
  430.            
  431.             // check
  432.             if(startTime < 0){
  433.                 // check
  434.                 if(endTime <= 0){
  435.                     // set
  436.                     willCreateSegment = NO;
  437.                 }
  438.                 else{
  439.                     // set
  440.                     startTime = 0;
  441.                 }
  442.             }
  443.            
  444.             // check
  445.             if(willCreateSegment){
  446.                 // circle 2
  447.                 UIBezierPath *tafSegment = [UIBezierPath bezierPath];
  448.                 [tafSegment moveToPoint:center];
  449.                 [tafSegment addArcWithCenter:center radius:tafRadius startAngle:DEGREES_TO_RADIANS(((startTime - 6) * 15) + 1) endAngle:DEGREES_TO_RADIANS(((endTime - 6) * 15) - 1) clockwise:YES];
  450.                 [tafSegment addLineToPoint:center];
  451.                 [tafFill setFill];
  452.                 [tafSegment fill];
  453.                
  454.                 // check
  455.                 if(tafSegmentObject.icons.count == 1){
  456.                     // vars
  457.                     /*NSDictionary *firstIconDict = [tafSegmentObject.icons objectAtIndex:0];
  458.                    
  459.                     // create view
  460.                     UIView *iconView = [[UIView alloc] initWithFrame:CGRectMake((center.x - (thisWidth/2)), (center.y - (thisWidth/2)), thisWidth, thisWidth)];
  461.                     [iconView setBackgroundColor:[UIColor clearColor]];
  462.                     [self addSubview:iconView];
  463.                    
  464.                     // image
  465.                     UIImage *iconImage = [UIImage imageNamed:[firstIconDict objectForKey:@"i"]];
  466.                     UIImageView *iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake((thisWidth/2) - 12, 12, 24, 24)];
  467.                     [iconImageView setImage:iconImage];
  468.                     [iconView addSubview:iconImageView];
  469.                    
  470.                     // halfway
  471.                     float halfwayAngle = ((endTime - startTime)/2) + startTime;
  472.                    
  473.                     // rotate
  474.                     iconView.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(halfwayAngle * 15));*/
  475.                 }
  476.                 else if(tafSegmentObject.icons.count == 2){
  477.                     // vars
  478.                     /*NSDictionary *firstIconDict = [tafSegmentObject.icons objectAtIndex:0];
  479.                     NSDictionary *secondIconDict = [tafSegmentObject.icons objectAtIndex:1];
  480.                    
  481.                     // create view
  482.                     UIView *iconViewLeft = [[UIView alloc] initWithFrame:CGRectMake((center.x - (thisWidth/2)), (center.y - (thisWidth/2)), thisWidth, thisWidth)];
  483.                     [iconViewLeft setBackgroundColor:[UIColor clearColor]];
  484.                     [self addSubview:iconViewLeft];
  485.                    
  486.                     // create view
  487.                     UIView *iconViewRight = [[UIView alloc] initWithFrame:CGRectMake((center.x - (thisWidth/2)), (center.y - (thisWidth/2)), thisWidth, thisWidth)];
  488.                     [iconViewRight setBackgroundColor:[UIColor clearColor]];
  489.                     [self addSubview:iconViewRight];
  490.                    
  491.                     // image
  492.                     UIImage *iconImageLeft = [UIImage imageNamed:[firstIconDict objectForKey:@"i"]];
  493.                     UIImageView *iconImageViewLeft = [[UIImageView alloc] initWithFrame:CGRectMake((thisWidth/2) - 12, 12, 24, 24)];
  494.                     [iconImageViewLeft setImage:iconImageLeft];
  495.                     [iconViewLeft addSubview:iconImageViewLeft];
  496.                    
  497.                     // image
  498.                     UIImage *iconImageRight = [UIImage imageNamed:[secondIconDict objectForKey:@"i"]];
  499.                     UIImageView *iconImageViewRight = [[UIImageView alloc] initWithFrame:CGRectMake((thisWidth/2) - 12, 12, 24, 24)];
  500.                     [iconImageViewRight setImage:iconImageRight];
  501.                     [iconViewRight addSubview:iconImageViewRight];
  502.                    
  503.                     // halfway
  504.                     float thirdAngle = ((endTime - startTime)/3) + startTime;
  505.                    
  506.                     // rotate
  507.                     iconViewLeft.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(thirdAngle * 15));
  508.                     iconViewRight.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS((thirdAngle * 2) * 15));*/
  509.                 }
  510.             }
  511.         }
  512.        
  513.         /* ==================== */
  514.         // taf arrows
  515.         /* ====================*/
  516.         if([appDelegate.myGlobals dataLevel] > 0){
  517.             for(TAFSegmentObject *tafSegmentObject in [tafObject segments]){
  518.                 // vars
  519.                 BOOL willCreateArrow = YES;
  520.                 NSTimeInterval metarTimeInterval = [metarObject.dateUTC timeIntervalSince1970];
  521.                 NSTimeInterval tafStartTimeInterval = [tafSegmentObject.startDateUTC timeIntervalSince1970];
  522.                 NSInteger startTimeBetweenDates = tafStartTimeInterval - metarTimeInterval;
  523.                 float startTime = (startTimeBetweenDates/3600) - timeOffset;
  524.                 NSString *displayTime = [NSString stringWithFormat:@"%0.0f", startTime];
  525.                
  526.                 NSCalendar *calendar = [NSCalendar currentCalendar];
  527.                 NSDateComponents *components = [calendar components:(NSHourCalendarUnit) fromDate:tafSegmentObject.startDateUTC];
  528.                 NSInteger hour = [components hour];
  529.                
  530.                 // check
  531.                 if([appDelegate.myGlobals timeOffset] == 0){
  532.                     // set
  533.                     displayTime = [NSString stringWithFormat:@"%ld", (long)hour];
  534.                 }
  535.                 else if([appDelegate.myGlobals timeOffset] == 2){
  536.                     // vars
  537.                     NSInteger localHourDifference = (timeZoneSeconds * -1) / secondsInAnHour;
  538.                     NSInteger offsetHour = hour - localHourDifference;
  539.                    
  540.                     // check
  541.                     if(offsetHour < 0){
  542.                         // set
  543.                         offsetHour = offsetHour * -1;
  544.                     }
  545.                    
  546.                     // set
  547.                     displayTime = [NSString stringWithFormat:@"%ld", (long)offsetHour];
  548.                 }
  549.                
  550.                 // check
  551.                 if(startTime <= 0){
  552.                     // set
  553.                     willCreateArrow = NO;
  554.                 }
  555.                
  556.                 // check
  557.                 if(willCreateArrow){
  558.                     // vars
  559.                     NSUInteger thisWidth = (tafRadius * 2) - 58;
  560.                    
  561.                     // create view
  562.                     UIView *arrowView = [[UIView alloc] initWithFrame:CGRectMake((center.x - (thisWidth/2)), (center.y - (thisWidth/2)), thisWidth, thisWidth)];
  563.                     [arrowView setBackgroundColor:[UIColor clearColor]];
  564.                     [self addSubview:arrowView];
  565.                    
  566.                     // arrow image
  567.                     UIImage *timeStartImage = [UIImage imageNamed:@"TimeArrow.png"];
  568.                     UIImageView *timeStartImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, thisWidth, thisWidth)];
  569.                     [timeStartImageView setImage:timeStartImage];
  570.                     [arrowView addSubview:timeStartImageView];
  571.                    
  572.                     // label
  573.                     UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake((thisWidth/2) - 14, 3, 28, 20)];
  574.                     [timeLabel setBackgroundColor:[UIColor clearColor]];
  575.                     [timeLabel setText:displayTime];
  576.                     [timeLabel setTextColor:[UIColor blackColor]];
  577.                     [timeLabel setTextAlignment:NSTextAlignmentCenter];
  578.                     [timeLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Medium" size:9]];
  579.                     [arrowView addSubview:timeLabel];
  580.                    
  581.                     // rotate
  582.                     arrowView.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(startTime * 15));
  583.                     timeLabel.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(-startTime * 15));
  584.                 }
  585.             }
  586.         }
  587.        
  588.         /* ==================== */
  589.         // taf rect
  590.         /* ====================*/
  591.         UIBezierPath *tafStartRect = [UIBezierPath bezierPathWithRect:CGRectMake((center.x - 2), (center.y - tafRadius), 4, (tafRadius - tfrRadius))];
  592.         [graphicBackgroundColor setFill];
  593.         [tafStartRect fill];
  594.     }
  595.    
  596.     // check
  597.     if([appDelegate.myGlobals dataLevel] > 1){
  598.         // check
  599.         if(thisStation.midnightUTC){
  600.             /* ==================== */
  601.             // sunset sunrise
  602.             /* ====================*/
  603.             NSTimeInterval metarTimeInterval = [metarObject.dateUTC timeIntervalSince1970];
  604.             NSTimeInterval midnightTimeInterval = [thisStation.midnightUTC timeIntervalSince1970];
  605.             NSTimeInterval sunsetTimeInterval = [thisStation.sunsetUTC timeIntervalSince1970];
  606.             NSTimeInterval sunriseTimeInterval = [thisStation.sunriseUTC timeIntervalSince1970];
  607.             NSTimeInterval timeZoneSeconds = [[NSTimeZone localTimeZone] secondsFromGMT];
  608.            
  609.             NSInteger midnightTimeBetweenDates = midnightTimeInterval - metarTimeInterval;
  610.             NSInteger startTimeBetweenDates = sunsetTimeInterval - metarTimeInterval;
  611.             NSInteger endTimeBetweenDates = sunriseTimeInterval - metarTimeInterval;
  612.            
  613.             float midnightTime = (midnightTimeBetweenDates/3600) + timeZoneSeconds;
  614.             float sunsetTime = roundf((startTimeBetweenDates - timeZoneSeconds)/3600);
  615.             float sunriseTime = roundf((endTimeBetweenDates - timeZoneSeconds)/3600);
  616.            
  617.             UIBezierPath *sunCircle = [UIBezierPath bezierPathWithArcCenter:center radius:airmetCONVRadius startAngle:DEGREES_TO_RADIANS((sunsetTime - 6) * 15)  endAngle:DEGREES_TO_RADIANS((sunriseTime - 6) * 15) clockwise:YES];
  618.             [[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:.25] setFill];
  619.             [sunCircle fill];
  620.            
  621.             /* ==================== */
  622.             // midnight rect
  623.             /* ====================*/
  624.             UIBezierPath *midnightBkgCircle = [UIBezierPath bezierPath];
  625.             [midnightBkgCircle moveToPoint:center];
  626.             [midnightBkgCircle addArcWithCenter:center radius:airmetCONVRadius startAngle:DEGREES_TO_RADIANS(((midnightTime - 6) * 15)- 2) endAngle:DEGREES_TO_RADIANS(((midnightTime - 6) * 15) + 2) clockwise:YES];
  627.             [midnightBkgCircle addLineToPoint:center];
  628.             [[UIColor blackColor] setFill];
  629.             [midnightBkgCircle fill];
  630.            
  631.             UIBezierPath *midnightCircle = [UIBezierPath bezierPath];
  632.             [midnightCircle moveToPoint:center];
  633.             [midnightCircle addArcWithCenter:center radius:airmetCONVRadius startAngle:DEGREES_TO_RADIANS(((midnightTime - 6) * 15) - 1) endAngle:DEGREES_TO_RADIANS(((midnightTime - 6) * 15) + 1) clockwise:YES];
  634.             [midnightCircle addLineToPoint:center];
  635.             [[UIColor whiteColor] setFill];
  636.             [midnightCircle fill];
  637.            
  638.             //NSLog(@"start angle %0.f", DEGREES_TO_RADIANS(((midnightTime - 6) * 15)- 2) );
  639.             //NSLog(@"end angle %0.f", DEGREES_TO_RADIANS(((midnightTime - 6) * 15) + 2) );
  640.         }
  641.     }
  642.    
  643.     /* ==================== */
  644.     // tfr background
  645.     /* ====================*/
  646.     UIBezierPath *tfrBkg = [UIBezierPath bezierPathWithArcCenter:center radius:tfrRadius startAngle:DEGREES_TO_RADIANS(0)  endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
  647.     [[UIColor colorWithRed:210/255.0 green:210/255.0 blue:210/255.0 alpha:1] setFill];
  648.     [tfrBkg fill];
  649.    
  650.     /* ==================== */
  651.     // tfr
  652.     /* ====================*/
  653.     // check
  654.     if([appDelegate.myGlobals tfrOn]){
  655.         // vars
  656.         UIColor *tfrFill = [appDelegate.myGlobals getColorWithName:tfrObject.color];
  657.        
  658.         // circle 2
  659.         UIBezierPath *tfrCircle = [UIBezierPath bezierPath];
  660.         [tfrCircle moveToPoint:center];
  661.         [tfrCircle addArcWithCenter:center radius:tfrRadius startAngle:DEGREES_TO_RADIANS(((tfrObject.timeStart - timeOffset) - 6) * 15) endAngle:DEGREES_TO_RADIANS(((tfrObject.timeEnd - timeOffset) - 6) * 15) clockwise:YES];
  662.         [tfrCircle addLineToPoint:center];
  663.         [tfrFill setFill];
  664.         [tfrCircle fill];
  665.     }
  666.    
  667.     /* ==================== */
  668.     // metar
  669.     /* ====================*/
  670.     UIColor *metarFill = [appDelegate.myGlobals getColorWithName:metarObject.color];
  671.    
  672.     // circle 1
  673.     UIBezierPath *metarCircle = [UIBezierPath bezierPathWithArcCenter:center radius:metarRadius startAngle:DEGREES_TO_RADIANS(0)  endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
  674.     [metarFill setFill];
  675.     [metarCircle fill];
  676.    
  677.     /* ==================== */
  678.     // time circle
  679.     /* ==================== */
  680.     // check
  681.     if([appDelegate.myGlobals metarTimeOn]){
  682.         // vars
  683.         float endAngle = 360;
  684.        
  685.         // check
  686.         if(minutesBetweenDates < 60){
  687.             // set
  688.             endAngle = (minutesBetweenDates - 15) * 6;
  689.         }
  690.        
  691.         // vars
  692.         UIColor *timeCircleFill = [appDelegate.myGlobals getColorWithName:@"dark green"];
  693.        
  694.         // time circle
  695.         UIBezierPath *timeCircle = [UIBezierPath bezierPath];
  696.         [timeCircle moveToPoint:center];
  697.         [timeCircle addArcWithCenter:center radius:metarRadius startAngle:DEGREES_TO_RADIANS((-6 * 15)) endAngle:DEGREES_TO_RADIANS(endAngle) clockwise:YES];
  698.         [timeCircle addLineToPoint:center];
  699.         [timeCircleFill setFill];
  700.         [timeCircle fill];
  701.        
  702.         // metar
  703.         UIBezierPath *metarCover = [UIBezierPath bezierPathWithArcCenter:center radius:(metarRadius - 8) startAngle:DEGREES_TO_RADIANS(0)  endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
  704.         [metarFill setFill];
  705.         [metarCover fill];
  706.     }
  707.    
  708.     // check
  709.     if([appDelegate.myGlobals dataLevel] > 0){
  710.         // check
  711.         if([appDelegate.myGlobals metarData] == 1){
  712.             // wind speed label
  713.             NSUInteger wsLabelWidth = 50;
  714.             UILabel *windSpeedLabel = [[UILabel alloc] initWithFrame:CGRectMake((center.x - round(wsLabelWidth/2)), (center.y - round(wsLabelWidth/2)), 50, 50)];
  715.             [windSpeedLabel setBackgroundColor:[UIColor clearColor]];
  716.             [windSpeedLabel setText:[NSString stringWithFormat:@"%ld", (long)metarObject.windSpeed]];
  717.             [windSpeedLabel setTextColor:[UIColor whiteColor]];
  718.             [windSpeedLabel setTextAlignment:NSTextAlignmentCenter];
  719.             [windSpeedLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Medium" size:24]];
  720.             [self addSubview:windSpeedLabel];
  721.            
  722.             // check
  723.             if([appDelegate.myGlobals windArrowOn]){
  724.                 // wind speed direction
  725.                 UIImage *windDirectionImage = [UIImage imageNamed:@"Arrow.png"];
  726.                 UIImageView *windDirectionImageView = [[UIImageView alloc] initWithFrame:CGRectMake((center.x - metarRadius), (center.y - metarRadius), metarRadius*2, metarRadius*2)];
  727.                 [windDirectionImageView setImage:windDirectionImage];
  728.                 windDirectionImageView.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(metarObject.windDirection));
  729.                 [self addSubview:windDirectionImageView];
  730.             }
  731.         }
  732.         else if([appDelegate.myGlobals metarData] == 2){
  733.             // bar label
  734.             NSUInteger barLabelWidth = 100;
  735.             NSUInteger barLabelHeight = 50;
  736.             UILabel *barLabel = [[UILabel alloc] initWithFrame:CGRectMake((center.x - round(barLabelWidth/2)), (center.y - round(barLabelHeight/2)), barLabelWidth, barLabelHeight)];
  737.             [barLabel setBackgroundColor:[UIColor clearColor]];
  738.             [barLabel setText:[NSString stringWithFormat:@"%00.02f", metarObject.barometerPressure]];
  739.             [barLabel setTextColor:[UIColor whiteColor]];
  740.             [barLabel setTextAlignment:NSTextAlignmentCenter];
  741.             [barLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Medium" size:24]];
  742.             [self addSubview:barLabel];
  743.         }
  744.         else if([appDelegate.myGlobals metarData] == 3){
  745.             // bar label
  746.             NSUInteger tempLabelWidth = 100;
  747.             NSUInteger tempLabelHeight = 50;
  748.             UILabel *tempLabel = [[UILabel alloc] initWithFrame:CGRectMake((center.x - round(tempLabelWidth/2)), (center.y - round(tempLabelHeight/2)), tempLabelWidth, tempLabelHeight)];
  749.             [tempLabel setBackgroundColor:[UIColor clearColor]];
  750.             [tempLabel setText:[NSString stringWithFormat:@"%0.1f°", metarObject.temperature]];
  751.             [tempLabel setTextColor:[UIColor whiteColor]];
  752.             [tempLabel setTextAlignment:NSTextAlignmentCenter];
  753.             [tempLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Medium" size:24]];
  754.             [self addSubview:tempLabel];
  755.         }
  756.     }
  757.    
  758.     /* ==================== */
  759.     // taf button
  760.     /* ====================*/
  761.     UIButton *tafButton = [UIButton buttonWithType:UIButtonTypeCustom];
  762.     [tafButton setFrame:CGRectMake(0, 0, tafRadius * 2, tafRadius * 2)];
  763.     [tafButton setCenter:center];
  764.     [tafButton setBackgroundColor:[UIColor clearColor]];
  765.     [tafButton.layer setCornerRadius:(tafRadius)];
  766.     //[tafButton addTarget:self action:@selector(tafTouched:) forControlEvents:UIControlEventTouchUpInside];
  767.     [self addSubview:tafButton];
  768.    
  769.     UITapGestureRecognizer *tafSingleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tafSingleTap:)];
  770.     UITapGestureRecognizer *tafDoubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tafDoubleTap:)];
  771.    
  772.     [tafSingleTap setNumberOfTapsRequired:1];
  773.     [tafDoubleTap setNumberOfTapsRequired:2];
  774.    
  775.     [tafSingleTap requireGestureRecognizerToFail:tafDoubleTap];
  776.    
  777.     [tafButton addGestureRecognizer:tafSingleTap];
  778.     [tafButton addGestureRecognizer:tafDoubleTap];
  779.    
  780.     /* ==================== */
  781.     // metar button
  782.     /* ====================*/
  783.     UIButton *metarButton = [UIButton buttonWithType:UIButtonTypeCustom];
  784.     [metarButton setFrame:CGRectMake(0, 0, metarRadius * 2, metarRadius * 2)];
  785.     [metarButton setCenter:center];
  786.     [metarButton setBackgroundColor:[UIColor clearColor]];
  787.     [metarButton.layer setCornerRadius:(metarRadius)];
  788.     //[metarButton addTarget:self action:@selector(metarTouched:) forControlEvents:UIControlEventTouchUpInside];
  789.     [self addSubview:metarButton];
  790.    
  791.     UITapGestureRecognizer *metarSingleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(metarSingleTap:)];
  792.     UITapGestureRecognizer *metarDoubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(metarDoubleTap:)];
  793.    
  794.     [metarSingleTap setNumberOfTapsRequired:1];
  795.     [metarDoubleTap setNumberOfTapsRequired:2];
  796.    
  797.     [metarSingleTap requireGestureRecognizerToFail:metarDoubleTap];
  798.    
  799.     [metarButton addGestureRecognizer:metarSingleTap];
  800.     [metarButton addGestureRecognizer:metarDoubleTap];
  801. }
  802.  
  803.  
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812.  
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826. @end
Advertisement
Add Comment
Please, Sign In to add comment