From e24fa093f02592c63577b16ba4d740f99635eda9 Mon Sep 17 00:00:00 2001 From: Maxime Graulich <maxime.graulich@gmail.com> Date: Thu, 1 Aug 2013 10:15:45 +0000 Subject: [PATCH] Adapt the code for iPhone --- .../iOS/Onelab.xcodeproj/project.pbxproj | 16 ++- contrib/mobile/iOS/Onelab/AppDelegate.mm | 8 +- .../mobile/iOS/Onelab/DetailViewController.mm | 18 +++ .../mobile/iOS/Onelab/MasterViewController.mm | 7 +- .../mobile/iOS/Onelab/ModelListController.h | 20 +++ .../mobile/iOS/Onelab/ModelListController.mm | 79 ++++++++++++ .../en.lproj/iPhoneStoryboard.storyboard | 118 ++++++++++++++++++ 7 files changed, 257 insertions(+), 9 deletions(-) create mode 100644 contrib/mobile/iOS/Onelab/ModelListController.h create mode 100644 contrib/mobile/iOS/Onelab/ModelListController.mm create mode 100644 contrib/mobile/iOS/Onelab/en.lproj/iPhoneStoryboard.storyboard diff --git a/contrib/mobile/iOS/Onelab.xcodeproj/project.pbxproj b/contrib/mobile/iOS/Onelab.xcodeproj/project.pbxproj index 85c74a536c..6a2ae13f10 100644 --- a/contrib/mobile/iOS/Onelab.xcodeproj/project.pbxproj +++ b/contrib/mobile/iOS/Onelab.xcodeproj/project.pbxproj @@ -39,7 +39,7 @@ 9CE08E17178AEC5F00A83B4B /* Trackball.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9CE08E04178AE6BE00A83B4B /* Trackball.cpp */; }; 9CE08E18178AEC5F00A83B4B /* Trackball.h in Sources */ = {isa = PBXBuildFile; fileRef = 9CE08E05178AE6BE00A83B4B /* Trackball.h */; }; 9CEAECC717A91CD20014D229 /* ModelListController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9CEAECC617A91CD20014D229 /* ModelListController.mm */; }; - 9CF1C1EA17AA39ED002CD2E3 /* iPhoneStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9CF1C1E917AA39ED002CD2E3 /* iPhoneStoryboard.storyboard */; }; + 9CF1C1ED17AA6E7E002CD2E3 /* iPhoneStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9CF1C1EB17AA6E7E002CD2E3 /* iPhoneStoryboard.storyboard */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -93,7 +93,7 @@ 9CE08E0F178AEB1600A83B4B /* petsc.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = petsc.framework; path = Onelab/frameworks/petsc.framework; sourceTree = "<group>"; }; 9CEAECC517A91CD20014D229 /* ModelListController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModelListController.h; sourceTree = "<group>"; }; 9CEAECC617A91CD20014D229 /* ModelListController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ModelListController.mm; sourceTree = "<group>"; }; - 9CF1C1E917AA39ED002CD2E3 /* iPhoneStoryboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = iPhoneStoryboard.storyboard; sourceTree = "<group>"; }; + 9CF1C1EC17AA6E7E002CD2E3 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/iPhoneStoryboard.storyboard; sourceTree = "<group>"; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -170,7 +170,7 @@ 9CC85C011790286C00F241C4 /* files */, 9C95B7F51726C88E00C0CCE2 /* main.m */, 9C9608AA1712EF0900E1D4A0 /* iPadStoryboard.storyboard */, - 9CF1C1E917AA39ED002CD2E3 /* iPhoneStoryboard.storyboard */, + 9CF1C1EB17AA6E7E002CD2E3 /* iPhoneStoryboard.storyboard */, 9C9608491712C16300E1D4A0 /* AppDelegate.h */, 9C96084A1712C16300E1D4A0 /* AppDelegate.mm */, 9CE08E01178AE6BE00A83B4B /* drawContext.cpp */, @@ -288,7 +288,7 @@ 9C9F8BCD174B5A1B004332C5 /* ic_launcher_retina.png in Resources */, 9C9F8BCF174B5A23004332C5 /* ic_launcher.png in Resources */, 9CC85C021790286C00F241C4 /* files in Resources */, - 9CF1C1EA17AA39ED002CD2E3 /* iPhoneStoryboard.storyboard in Resources */, + 9CF1C1ED17AA6E7E002CD2E3 /* iPhoneStoryboard.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -375,6 +375,14 @@ name = iPadStoryboard.storyboard; sourceTree = "<group>"; }; + 9CF1C1EB17AA6E7E002CD2E3 /* iPhoneStoryboard.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 9CF1C1EC17AA6E7E002CD2E3 /* en */, + ); + name = iPhoneStoryboard.storyboard; + sourceTree = "<group>"; + }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ diff --git a/contrib/mobile/iOS/Onelab/AppDelegate.mm b/contrib/mobile/iOS/Onelab/AppDelegate.mm index dea0894e52..62eed5fa53 100644 --- a/contrib/mobile/iOS/Onelab/AppDelegate.mm +++ b/contrib/mobile/iOS/Onelab/AppDelegate.mm @@ -13,9 +13,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. - UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController; - UINavigationController *navigationController = [splitViewController.viewControllers lastObject]; - splitViewController.delegate = (id)navigationController.topViewController; + if([[UIDevice currentDevice].model isEqualToString:@"iPad"] || [[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]){ + UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController; + UINavigationController *navigationController = [splitViewController.viewControllers lastObject]; + splitViewController.delegate = (id)navigationController.topViewController; + } return YES; } diff --git a/contrib/mobile/iOS/Onelab/DetailViewController.mm b/contrib/mobile/iOS/Onelab/DetailViewController.mm index 927931d53d..337eceb979 100644 --- a/contrib/mobile/iOS/Onelab/DetailViewController.mm +++ b/contrib/mobile/iOS/Onelab/DetailViewController.mm @@ -11,6 +11,7 @@ #import "iosGModel.h" #import "ModelListController.h" +#import "MasterViewController.h" @interface DetailViewController () @property (strong, nonatomic) UIPopoverController *masterPopoverController; @@ -53,6 +54,15 @@ [self configureView]; scaleFactor = 1.; setObjCBridge((__bridge void*) self); + if(![[UIDevice currentDevice].model isEqualToString:@"iPad"] && ![[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]){ + UIBarButtonItem *settings = [[UIBarButtonItem alloc] initWithTitle:@"Settings" style:UIBarButtonItemStyleBordered target:self action:@selector(showSettings)]; + UIBarButtonItem *postpro = [[UIBarButtonItem alloc] initWithTitle:@"Post processing" style:UIBarButtonItemStyleBordered target:self action:@selector(showPostpro)]; + UIBarButtonItem *more = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showMore:)]; + UIBarButtonItem *model = [[UIBarButtonItem alloc] initWithTitle:@"Load model" style:UIBarButtonItemStyleBordered target:self action:@selector(showModelsList)]; + NSArray *btns = [[NSArray alloc] initWithObjects:settings, postpro, more, nil]; + [self.navigationItem setLeftBarButtonItems:btns]; + [self.navigationItem setRightBarButtonItem:model]; + } } - (IBAction)pinch:(UIPinchGestureRecognizer *)sender @@ -73,6 +83,7 @@ glView->mContext->eventHandler(2,mScale); [glView drawView]; } + -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; @@ -108,6 +119,12 @@ modelListController.glView = glView; [self.navigationController pushViewController:modelListController animated:true]; } + +- (void) showSettings +{ + MasterViewController *masterViewController = [[MasterViewController alloc] init]; + [self.navigationController pushViewController:masterViewController animated:true]; +} - (void) showPostpro { @@ -223,6 +240,7 @@ - (void)viewDidUnload { + [self setGlView:nil]; [self setGlView:nil]; [self setGlView:nil]; [super viewDidUnload]; diff --git a/contrib/mobile/iOS/Onelab/MasterViewController.mm b/contrib/mobile/iOS/Onelab/MasterViewController.mm index b9ff02effd..fe5a7aaea7 100644 --- a/contrib/mobile/iOS/Onelab/MasterViewController.mm +++ b/contrib/mobile/iOS/Onelab/MasterViewController.mm @@ -32,7 +32,6 @@ runButton = [[UIBarButtonItem alloc] initWithTitle:@"Run" style:UIBarButtonItemStyleBordered target:self action:@selector(runWithNewParameter)]; [runButton setTitle:@"Run"]; // ?? do nothink ?? self.navigationItem.leftBarButtonItem = runButton; - UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshObject:)]; self.navigationItem.rightBarButtonItem = addButton; @@ -157,6 +156,7 @@ } else if([v isKindOfClass:UIPickerView.class]){ UIView *picker = (UISlider*)v; + [(UIPickerView *)picker reloadAllComponents]; int index=0; for(int i=0;i<number[0].getChoices().size();i++) if(number[0].getChoices()[i] == number[0].getValue()){index = i; break;} @@ -176,6 +176,7 @@ if(string.size() > 0) { UIView *picker = [self.tableView viewWithTag:(1000*i+n)]; if([picker isKindOfClass:UIPickerView.class]){ + [(UIPickerView *)picker reloadAllComponents]; int index = -1; for(int i=0;i<string[0].getChoices().size();i++) if(string[0].getChoices()[i] == string[0].getValue()){index = i; break;} @@ -191,7 +192,7 @@ - (void)runWithNewParameter { - dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // TODO fix Run/Stop for iPhone [runButton setTitle:@"Stop"]; [self refreshControl]; [runButton setAction:@selector(stopRunning)]; @@ -201,6 +202,8 @@ [runButton setAction:@selector(runWithNewParameter)]; [self getAvailableParam]; }); + if(![[UIDevice currentDevice].model isEqualToString:@"iPad"] && ![[UIDevice currentDevice].model isEqualToString:@"iPad Simulator"]) + [self.navigationController popViewControllerAnimated:YES]; } - (void)stopRunning diff --git a/contrib/mobile/iOS/Onelab/ModelListController.h b/contrib/mobile/iOS/Onelab/ModelListController.h new file mode 100644 index 0000000000..1ce2da94b0 --- /dev/null +++ b/contrib/mobile/iOS/Onelab/ModelListController.h @@ -0,0 +1,20 @@ +// +// ModelListController.h +// Onelab +// +// Created by Maxime Graulich on 31/07/13. +// Copyright (c) 2013 Maxime Graulich. All rights reserved. +// + +#import <UIKit/UIKit.h> + +#import "AppDelegate.h" +#import "EAGLView.h" + +@interface ModelListController : UITableViewController +{ + @private + NSArray *models; +} +@property (nonatomic, retain) EAGLView *glView; +@end diff --git a/contrib/mobile/iOS/Onelab/ModelListController.mm b/contrib/mobile/iOS/Onelab/ModelListController.mm new file mode 100644 index 0000000000..40cb714229 --- /dev/null +++ b/contrib/mobile/iOS/Onelab/ModelListController.mm @@ -0,0 +1,79 @@ +// +// ModelListController.m +// Onelab +// +// Created by Maxime Graulich on 31/07/13. +// Copyright (c) 2013 Maxime Graulich. All rights reserved. +// + +#import "ModelListController.h" + +@interface ModelListController () { + +} +@end + +// TODO Get model list from "Documents" + +@implementation ModelListController +-(void)viewDidLoad +{ + models = [NSArray arrayWithObjects:@"magnet", @"pmsm", nil]; +} + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return [models count]; +} +-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell *cell; + //NSString *modelName = [models objectAtIndex:indexPath.row]; + switch (indexPath.row) { + case 0: + cell = [tableView dequeueReusableCellWithIdentifier:@"magnet"]; + if(cell == nil) + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"magnet"]; + else + return cell; + [cell.textLabel setText:@"Magnet"]; + [cell.detailTextLabel setText:@"A simple magnet example"]; + cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + return cell; + break; + case 1: + cell = [tableView dequeueReusableCellWithIdentifier:@"pmsm"]; + if(cell == nil) + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"pmsm"]; + else + return cell; + [cell.textLabel setText:@"Eight-pole permanent magnet synchronous machine"]; + cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + return cell; + break; + default: + cell = [tableView dequeueReusableCellWithIdentifier:@"Default"]; + if(cell == nil) + return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Default"]; + else + return cell; + break; + } +} +-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section +{ + return @"Select a model"; +} +-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + NSString *modelName = [models objectAtIndex:indexPath.row]; + [_glView loadMsh:[NSString stringWithFormat:@"%@%@%@",@"/",modelName,@".geo"]]; + [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshParameters" object:nil]; + [self.navigationController popViewControllerAnimated:YES]; +} +@end diff --git a/contrib/mobile/iOS/Onelab/en.lproj/iPhoneStoryboard.storyboard b/contrib/mobile/iOS/Onelab/en.lproj/iPhoneStoryboard.storyboard new file mode 100644 index 0000000000..072632c821 --- /dev/null +++ b/contrib/mobile/iOS/Onelab/en.lproj/iPhoneStoryboard.storyboard @@ -0,0 +1,118 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="3084" systemVersion="12E55" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="I1M-SS-j3f"> + <dependencies> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="2083"/> + </dependencies> + <scenes> + <!--Model List Controller--> + <scene sceneID="v3E-aL-qiK"> + <objects> + <tableViewController id="8XI-KV-K1E" customClass="ModelListController" sceneMemberID="viewController"> + <tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="ofD-4s-Mim"> + <rect key="frame" x="0.0" y="64" width="320" height="504"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> + <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> + <prototypes> + <tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="8O1-DW-97N"> + <rect key="frame" x="0.0" y="22" width="320" height="44"/> + <autoresizingMask key="autoresizingMask"/> + <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center"> + <rect key="frame" x="0.0" y="0.0" width="320" height="43"/> + <autoresizingMask key="autoresizingMask"/> + <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> + </view> + </tableViewCell> + </prototypes> + <connections> + <outlet property="dataSource" destination="8XI-KV-K1E" id="5Ne-fR-Zie"/> + <outlet property="delegate" destination="8XI-KV-K1E" id="67d-6G-z9P"/> + </connections> + </tableView> + <navigationItem key="navigationItem" id="bTC-Xy-gnq"/> + </tableViewController> + <placeholder placeholderIdentifier="IBFirstResponder" id="sp3-KN-vaL" userLabel="First Responder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="694" y="814"/> + </scene> + <!--Navigation Controller--> + <scene sceneID="TnB-4A-3kW"> + <objects> + <navigationController definesPresentationContext="YES" id="I1M-SS-j3f" sceneMemberID="viewController"> + <navigationBar key="navigationBar" contentMode="scaleToFill" id="PjF-cd-bFm"> + <autoresizingMask key="autoresizingMask"/> + </navigationBar> + <connections> + <segue destination="OiL-mG-skg" kind="relationship" relationship="rootViewController" id="UkG-u2-VAg"/> + </connections> + </navigationController> + <placeholder placeholderIdentifier="IBFirstResponder" id="qsh-gT-wFK" userLabel="First Responder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="-358" y="160"/> + </scene> + <!--Detail View Controller--> + <scene sceneID="fWt-EU-2g3"> + <objects> + <viewController id="OiL-mG-skg" customClass="DetailViewController" sceneMemberID="viewController"> + <view key="view" multipleTouchEnabled="YES" contentMode="scaleToFill" id="A17-hO-dzV" customClass="EAGLView"> + <rect key="frame" x="0.0" y="64" width="320" height="504"/> + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> + <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> + <connections> + <outletCollection property="gestureRecognizers" destination="XLG-6q-wbG" appends="YES" id="JUu-eN-y4h"/> + <outletCollection property="gestureRecognizers" destination="StI-Xa-wrS" appends="YES" id="Kp1-Fg-fCR"/> + </connections> + </view> + <navigationItem key="navigationItem" id="O8R-vc-R66"/> + <connections> + <outlet property="glView" destination="A17-hO-dzV" id="yPd-pv-3Ee"/> + <segue destination="n8O-vS-ZZf" kind="push" id="5lx-rp-xZu"/> + <segue destination="8XI-KV-K1E" kind="push" id="c2c-M2-TZ8"/> + </connections> + </viewController> + <placeholder placeholderIdentifier="IBFirstResponder" id="Fka-9L-vc2" userLabel="First Responder" sceneMemberID="firstResponder"/> + <tapGestureRecognizer id="XLG-6q-wbG"> + <connections> + <action selector="tap:" destination="OiL-mG-skg" id="cd0-Dq-hwq"/> + </connections> + </tapGestureRecognizer> + <pinchGestureRecognizer id="StI-Xa-wrS"> + <connections> + <action selector="pinch:" destination="OiL-mG-skg" id="Vrg-tX-ANM"/> + </connections> + </pinchGestureRecognizer> + </objects> + <point key="canvasLocation" x="154" y="160"/> + </scene> + <!--Master View Controller - Root View Controller--> + <scene sceneID="Bc9-Ej-79r"> + <objects> + <tableViewController id="n8O-vS-ZZf" customClass="MasterViewController" sceneMemberID="viewController"> + <tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="FRc-si-Od5"> + <rect key="frame" x="0.0" y="64" width="320" height="504"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> + <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> + <prototypes> + <tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="GT1-C2-8Ww"> + <rect key="frame" x="0.0" y="22" width="320" height="44"/> + <autoresizingMask key="autoresizingMask"/> + <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center"> + <rect key="frame" x="0.0" y="0.0" width="320" height="43"/> + <autoresizingMask key="autoresizingMask"/> + <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> + </view> + </tableViewCell> + </prototypes> + </tableView> + <navigationItem key="navigationItem" title="Root View Controller" id="iYS-au-E4P"/> + </tableViewController> + <placeholder placeholderIdentifier="IBFirstResponder" id="unW-um-vwm" userLabel="First Responder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="694" y="160"/> + </scene> + </scenes> + <simulatedMetricsContainer key="defaultSimulatedMetrics"> + <simulatedStatusBarMetrics key="statusBar"/> + <simulatedOrientationMetrics key="orientation"/> + <simulatedScreenMetrics key="destination" type="retina4"/> + </simulatedMetricsContainer> +</document> \ No newline at end of file -- GitLab