From f0662b2487377e33a8b565c4de4ced4df37b74e2 Mon Sep 17 00:00:00 2001 From: Maxime Graulich <maxime.graulich@gmail.com> Date: Thu, 1 Aug 2013 07:14:07 +0000 Subject: [PATCH] drawString for iOS and new ViewController for models list --- contrib/mobile/CMakeLists.txt | 2 + contrib/mobile/drawContext.cpp | 1 + contrib/mobile/drawString.cpp | 15 ++- contrib/mobile/drawString.h | 10 ++ .../iOS/Onelab.xcodeproj/project.pbxproj | 34 ++++-- .../mobile/iOS/Onelab/DetailViewController.h | 6 +- .../mobile/iOS/Onelab/DetailViewController.mm | 111 +++++++----------- .../mobile/iOS/Onelab/MasterViewController.mm | 2 + ...d.storyboard => iPadStoryboard.storyboard} | 66 ++++++++--- contrib/mobile/iosGModel.h | 25 ++-- 10 files changed, 165 insertions(+), 107 deletions(-) rename contrib/mobile/iOS/Onelab/en.lproj/{MainStoryboard.storyboard => iPadStoryboard.storyboard} (73%) diff --git a/contrib/mobile/CMakeLists.txt b/contrib/mobile/CMakeLists.txt index b8544c9e64..4a363582ce 100644 --- a/contrib/mobile/CMakeLists.txt +++ b/contrib/mobile/CMakeLists.txt @@ -57,6 +57,8 @@ if(ENABLE_BUILD_IOS_EMULATOR OR ENABLE_BUILD_IOS) COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/iOS/ic_launcher_retina.png ${CMAKE_CURRENT_BINARY_DIR}/Onelab/ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/drawContext.cpp ${CMAKE_CURRENT_BINARY_DIR}/Onelab/Onelab/ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/drawContext.h ${CMAKE_CURRENT_BINARY_DIR}/Onelab/Onelab/ + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/drawString.cpp ${CMAKE_CURRENT_BINARY_DIR}/Onelab/Onelab/ + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/drawString.h ${CMAKE_CURRENT_BINARY_DIR}/Onelab/Onelab/ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Trackball.cpp ${CMAKE_CURRENT_BINARY_DIR}/Onelab/Onelab/ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Trackball.h ${CMAKE_CURRENT_BINARY_DIR}/Onelab/Onelab/ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/movePosition.h ${CMAKE_CURRENT_BINARY_DIR}/Onelab/Onelab/ diff --git a/contrib/mobile/drawContext.cpp b/contrib/mobile/drawContext.cpp index 67c6fcfc9b..da877a1695 100644 --- a/contrib/mobile/drawContext.cpp +++ b/contrib/mobile/drawContext.cpp @@ -16,6 +16,7 @@ #include <Gmsh/onelabUtils.h> #include <Gmsh/PView.h> #include <Gmsh/PViewOptions.h> +#include <Gmsh/PViewData.h> #include <Gmsh/Context.h> #include <Gmsh/StringUtils.h> diff --git a/contrib/mobile/drawString.cpp b/contrib/mobile/drawString.cpp index 07e13b166f..4cb44feb38 100644 --- a/contrib/mobile/drawString.cpp +++ b/contrib/mobile/drawString.cpp @@ -1,5 +1,16 @@ +#if !defined(BUILD_ANDROID) +#define BUILD_IOS 1 +#endif + +#if defined(BUILD_IOS) +#include <OpenGLES/ES1/gl.h> +#include <OpenGLES/ES1/glext.h> +#endif + +#if defined(BUILD_ANDROID) #include <GLES/gl.h> #include <GLES/glext.h> +#endif #include "drawString.h" @@ -17,6 +28,7 @@ void drawString::setText(std::string text) { this->_text = text; getBitmapFromString(this->_text.c_str(), _size, &this->_map, &this->_height, &this->_width, &this->_realWidth); + //printf("\n%s\n", _text.c_str());for(int i=0; i<_height*_width;i++) printf("0x%x ", _map[i]);printf("\n"); } void drawString::setColor(float color[4]) @@ -36,9 +48,11 @@ void drawString::setColor(float r, float g, float b, float a) } void drawString::draw(float x, float y, float z, float w, float h, bool center) { + // TODO fix on iOS GLuint textureId; glGenTextures(1, &textureId); glBindTexture(GL_TEXTURE_2D, textureId); + //printf("\n%s\n", _text.c_str());for(int i=0; i<_height*_width;i++) printf("0x%x ", _map[i]);printf("\n"); glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, _width, _height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, _map); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glColor4f(_color[0], _color[1], _color[2], _color[3]); @@ -61,7 +75,6 @@ void drawString::draw(float x, float y, float z, float w, float h, bool center) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glDisable(GL_LIGHTING); glVertexPointer(3, GL_FLOAT, 0, vertex); glTexCoordPointer(2, GL_FLOAT, 0, texture); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); diff --git a/contrib/mobile/drawString.h b/contrib/mobile/drawString.h index 8a2640bbae..7d4556e0d7 100644 --- a/contrib/mobile/drawString.h +++ b/contrib/mobile/drawString.h @@ -1,6 +1,16 @@ #include <string> +#if !defined(BUILD_ANDROID) +#define BUILD_IOS 1 +#endif + +#if defined(BUILD_IOS) +#include "iosGModel.h" +#endif + +#if defined(BUILD_ANDROID) #include "androidGModel.h" +#endif class drawString { diff --git a/contrib/mobile/iOS/Onelab.xcodeproj/project.pbxproj b/contrib/mobile/iOS/Onelab.xcodeproj/project.pbxproj index 13fe83bc84..85c74a536c 100644 --- a/contrib/mobile/iOS/Onelab.xcodeproj/project.pbxproj +++ b/contrib/mobile/iOS/Onelab.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 9C6A645817A7C3DB00DEDAFC /* drawString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9C6A645617A7C3DB00DEDAFC /* drawString.cpp */; }; 9C95B7F61726C88E00C0CCE2 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9C95B7F51726C88E00C0CCE2 /* main.m */; }; 9C96083B1712C16300E1D4A0 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C96083A1712C16300E1D4A0 /* UIKit.framework */; }; 9C96083D1712C16300E1D4A0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C96083C1712C16300E1D4A0 /* Foundation.framework */; }; @@ -24,7 +25,7 @@ 9C96089B1712C7BE00E1D4A0 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C96089A1712C7BE00E1D4A0 /* OpenGLES.framework */; }; 9C96089D1712C7F600E1D4A0 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C96089C1712C7F600E1D4A0 /* QuartzCore.framework */; }; 9C96089F1712C8EB00E1D4A0 /* emulatorFix.c in Sources */ = {isa = PBXBuildFile; fileRef = 9C96089E1712C8EB00E1D4A0 /* emulatorFix.c */; }; - 9C9608AC1712EF0900E1D4A0 /* MainStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9C9608AA1712EF0900E1D4A0 /* MainStoryboard.storyboard */; }; + 9C9608AC1712EF0900E1D4A0 /* iPadStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9C9608AA1712EF0900E1D4A0 /* iPadStoryboard.storyboard */; }; 9C9F8BCD174B5A1B004332C5 /* ic_launcher_retina.png in Resources */ = {isa = PBXBuildFile; fileRef = 9C9F8BCC174B5A1B004332C5 /* ic_launcher_retina.png */; }; 9C9F8BCF174B5A23004332C5 /* ic_launcher.png in Resources */ = {isa = PBXBuildFile; fileRef = 9C9F8BCE174B5A23004332C5 /* ic_launcher.png */; }; 9CC85C021790286C00F241C4 /* files in Resources */ = {isa = PBXBuildFile; fileRef = 9CC85C011790286C00F241C4 /* files */; }; @@ -37,6 +38,8 @@ 9CE08E16178AEC5F00A83B4B /* movePosition.h in Sources */ = {isa = PBXBuildFile; fileRef = 9CE08E03178AE6BE00A83B4B /* movePosition.h */; }; 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 */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -50,6 +53,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 9C6A645617A7C3DB00DEDAFC /* drawString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = drawString.cpp; sourceTree = "<group>"; }; + 9C6A645717A7C3DB00DEDAFC /* drawString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = drawString.h; sourceTree = "<group>"; }; 9C95B7F51726C88E00C0CCE2 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; }; 9C9608361712C16300E1D4A0 /* Onelab.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Onelab.app; sourceTree = BUILT_PRODUCTS_DIR; }; 9C96083A1712C16300E1D4A0 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; @@ -73,7 +78,7 @@ 9C96089A1712C7BE00E1D4A0 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; }; 9C96089C1712C7F600E1D4A0 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 9C96089E1712C8EB00E1D4A0 /* emulatorFix.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = emulatorFix.c; sourceTree = "<group>"; }; - 9C9608AB1712EF0900E1D4A0 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/MainStoryboard.storyboard; sourceTree = "<group>"; }; + 9C9608AB1712EF0900E1D4A0 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/iPadStoryboard.storyboard; sourceTree = "<group>"; }; 9C99754C17390DEE0036EC24 /* iosGModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iosGModel.h; sourceTree = "<group>"; }; 9C9F8BCC174B5A1B004332C5 /* ic_launcher_retina.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ic_launcher_retina.png; sourceTree = "<group>"; }; 9C9F8BCE174B5A23004332C5 /* ic_launcher.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = ic_launcher.png; sourceTree = "<group>"; }; @@ -86,6 +91,9 @@ 9CE08E0D178AEB1600A83B4B /* GetDP.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GetDP.framework; path = Onelab/frameworks/GetDP.framework; sourceTree = "<group>"; }; 9CE08E0E178AEB1600A83B4B /* Gmsh.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Gmsh.framework; path = Onelab/frameworks/Gmsh.framework; sourceTree = "<group>"; }; 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>"; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -161,15 +169,18 @@ children = ( 9CC85C011790286C00F241C4 /* files */, 9C95B7F51726C88E00C0CCE2 /* main.m */, - 9C9608AA1712EF0900E1D4A0 /* MainStoryboard.storyboard */, + 9C9608AA1712EF0900E1D4A0 /* iPadStoryboard.storyboard */, + 9CF1C1E917AA39ED002CD2E3 /* iPhoneStoryboard.storyboard */, 9C9608491712C16300E1D4A0 /* AppDelegate.h */, + 9C96084A1712C16300E1D4A0 /* AppDelegate.mm */, 9CE08E01178AE6BE00A83B4B /* drawContext.cpp */, 9CE08E02178AE6BE00A83B4B /* drawContext.h */, + 9C6A645617A7C3DB00DEDAFC /* drawString.cpp */, + 9C6A645717A7C3DB00DEDAFC /* drawString.h */, 9C99754C17390DEE0036EC24 /* iosGModel.h */, 9CE08E03178AE6BE00A83B4B /* movePosition.h */, 9CE08E04178AE6BE00A83B4B /* Trackball.cpp */, 9CE08E05178AE6BE00A83B4B /* Trackball.h */, - 9C96084A1712C16300E1D4A0 /* AppDelegate.mm */, 9C96084F1712C16400E1D4A0 /* MasterViewController.h */, 9C9608501712C16400E1D4A0 /* MasterViewController.mm */, 9C9608521712C16400E1D4A0 /* DetailViewController.h */, @@ -177,6 +188,8 @@ 9C9608721712C47200E1D4A0 /* EAGLView.h */, 9C9608731712C47200E1D4A0 /* EAGLView.mm */, 9C96089E1712C8EB00E1D4A0 /* emulatorFix.c */, + 9CEAECC517A91CD20014D229 /* ModelListController.h */, + 9CEAECC617A91CD20014D229 /* ModelListController.mm */, ); path = Onelab; sourceTree = "<group>"; @@ -271,10 +284,11 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 9C9608AC1712EF0900E1D4A0 /* MainStoryboard.storyboard in Resources */, + 9C9608AC1712EF0900E1D4A0 /* iPadStoryboard.storyboard in Resources */, 9C9F8BCD174B5A1B004332C5 /* ic_launcher_retina.png in Resources */, 9C9F8BCF174B5A23004332C5 /* ic_launcher.png in Resources */, 9CC85C021790286C00F241C4 /* files in Resources */, + 9CF1C1EA17AA39ED002CD2E3 /* iPhoneStoryboard.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -321,6 +335,8 @@ 9C9608741712C47200E1D4A0 /* EAGLView.mm in Sources */, 9C96089F1712C8EB00E1D4A0 /* emulatorFix.c in Sources */, 9C95B7F61726C88E00C0CCE2 /* main.m in Sources */, + 9C6A645817A7C3DB00DEDAFC /* drawString.cpp in Sources */, + 9CEAECC717A91CD20014D229 /* ModelListController.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -351,12 +367,12 @@ name = InfoPlist.strings; sourceTree = "<group>"; }; - 9C9608AA1712EF0900E1D4A0 /* MainStoryboard.storyboard */ = { + 9C9608AA1712EF0900E1D4A0 /* iPadStoryboard.storyboard */ = { isa = PBXVariantGroup; children = ( 9C9608AB1712EF0900E1D4A0 /* en */, ); - name = MainStoryboard.storyboard; + name = iPadStoryboard.storyboard; sourceTree = "<group>"; }; /* End PBXVariantGroup section */ @@ -435,7 +451,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; "PROVISIONING_PROFILE[sdk=iphoneos*]" = ""; - TARGETED_DEVICE_FAMILY = 2; + TARGETED_DEVICE_FAMILY = "1,2"; VALID_ARCHS = armv7; WRAPPER_EXTENSION = app; }; @@ -462,7 +478,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; "PROVISIONING_PROFILE[sdk=iphoneos*]" = ""; - TARGETED_DEVICE_FAMILY = 2; + TARGETED_DEVICE_FAMILY = "1,2"; VALID_ARCHS = armv7; WRAPPER_EXTENSION = app; }; diff --git a/contrib/mobile/iOS/Onelab/DetailViewController.h b/contrib/mobile/iOS/Onelab/DetailViewController.h index 81c1dc10d9..ea576fab23 100644 --- a/contrib/mobile/iOS/Onelab/DetailViewController.h +++ b/contrib/mobile/iOS/Onelab/DetailViewController.h @@ -14,14 +14,10 @@ #include <gmsh/PViewData.h> #include <gmsh/PViewOptions.h> -#import "iosGModel.h" - -@interface DetailViewController : UIViewController <UISplitViewControllerDelegate, UITextFieldDelegate, UIActionSheetDelegate, UITableViewDelegate, UITableViewDataSource> +@interface DetailViewController : UIViewController <UISplitViewControllerDelegate, UITextFieldDelegate, UIActionSheetDelegate> { @private double scaleFactor; - iosGModel *mIosGModel; - NSArray *models; } - (IBAction)pinch:(UIPinchGestureRecognizer *)sender; diff --git a/contrib/mobile/iOS/Onelab/DetailViewController.mm b/contrib/mobile/iOS/Onelab/DetailViewController.mm index d5e17e5d62..927931d53d 100644 --- a/contrib/mobile/iOS/Onelab/DetailViewController.mm +++ b/contrib/mobile/iOS/Onelab/DetailViewController.mm @@ -8,6 +8,9 @@ #import <QuartzCore/QuartzCore.h> #import "DetailViewController.h" +#import "iosGModel.h" + +#import "ModelListController.h" @interface DetailViewController () @property (strong, nonatomic) UIPopoverController *masterPopoverController; @@ -49,8 +52,7 @@ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestRender) name:@"requestRender" object:nil]; [self configureView]; scaleFactor = 1.; - mIosGModel = new iosGModel((__bridge void*) self); - models = [NSArray arrayWithObjects:@"pmsm", @"magnet", nil]; + setObjCBridge((__bridge void*) self); } - (IBAction)pinch:(UIPinchGestureRecognizer *)sender @@ -102,29 +104,9 @@ - (void) showModelsList { - - for(UIView *v in self.view.subviews) - if(v.tag ==-2) - { - [self hideModelsList]; - return; - } - UITableView *modelsList = [[UITableView alloc] initWithFrame:CGRectMake(20,20,self.view.bounds.size.width-40,self.view.bounds.size.height - 2 * 40)]; - [modelsList setBackgroundColor: [UIColor colorWithRed:0.6 green:0.6 blue:0.6 alpha:.75]]; - [modelsList.layer setBorderWidth:1.]; - [modelsList.layer setBorderColor:[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1].CGColor]; - modelsList.tag = -2; - [modelsList setDataSource:self]; - [modelsList setDelegate:self]; - [self.view addSubview:modelsList]; - [self.view bringSubviewToFront:modelsList]; -} - -- (void) hideModelsList -{ - for(UIView *v in self.view.subviews) - if(v.tag == -2) - [v removeFromSuperview]; + ModelListController *modelListController = [[ModelListController alloc] init]; + modelListController.glView = glView; + [self.navigationController pushViewController:modelListController animated:true]; } - (void) showPostpro @@ -343,52 +325,49 @@ void messageFromCpp (void *self, std::string level, std::string msg) //[[NSNotificationCenter defaultCenter] postNotificationName:@"refreshParameters" object:nil]; } else if(level == "Error") - ;//[(__bridge id)self showAlert:msg title:level]; + [(__bridge id)self showAlert:msg title:level]; } - -#pragma mark - tableView - --(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +void getBitmap(void *self, const char *text, int textsize, unsigned char **map, int *height, int *width, int *realWidth) { - return 1; + [(__bridge id)self getBitmapFromStringObjC:text withTextSize:textsize inMap:map inHeight:height inWidth:width inRealWidth:realWidth]; } - --(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +-(void) getBitmapFromStringObjC:(const char *)text withTextSize:(int)textsize inMap:(unsigned char **)map inHeight:(int *)height inWidth:(int *)width inRealWidth:(int *) realWidth { - return [models count]; -} - --(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath -{ - NSString *modelName = [models objectAtIndex:indexPath.row]; - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:modelName]; - if(cell == nil) - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:modelName]; - else - return cell; - [cell.textLabel setText:modelName]; - return cell; -} - --(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section -{ - return @"Select a model"; -} + UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 25, textsize)]; + [lbl setText:[NSString stringWithCString:text encoding:[NSString defaultCStringEncoding]]]; + [lbl setBackgroundColor:[UIColor clearColor]]; + UIGraphicsBeginImageContextWithOptions(lbl.bounds.size, NO, 0.0); + [lbl.layer renderInContext:UIGraphicsGetCurrentContext()]; + UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); + + CGImageRef bitmap = [img CGImage]; + *width = CGImageGetWidth(bitmap); + *realWidth = *width; + *height = CGImageGetHeight(bitmap); + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + unsigned char *rawData = (unsigned char*) calloc(*height * *width * 4, sizeof(unsigned char)); + *map = (unsigned char*) calloc(*height * *width, sizeof(unsigned char)); + NSUInteger bytesPerPixel = 4; + NSUInteger bytesPerRow = bytesPerPixel * *width; + NSUInteger bitsPerComponent = 8; + CGContextRef context = CGBitmapContextCreate(rawData, *width, *height, + bitsPerComponent, bytesPerRow, colorSpace, + kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); + CGColorSpaceRelease(colorSpace); + + CGContextDrawImage(context, CGRectMake(0, 0, *width, *height), bitmap); + CGContextRelease(context); --(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath -{ - return 30; -} + // rawData contains the image data in the RGBA8888 pixel format. + for (int byteIndex = 0 ; byteIndex < *width * *height * 4 ; byteIndex+=4) + *(*map+byteIndex/4) = (rawData[byteIndex + 3] == 0x00)? 0x00 : 0xFF; + free(rawData); --(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath -{ - NSString *modelName = [models objectAtIndex:indexPath.row]; - //NSString *ressourcePath = [[NSBundle mainBundle] resourcePath]; - [glView loadMsh:[NSString stringWithFormat:@"%@%@%@",@"/",modelName,@".geo"]]; - //glView->mContext->load([[NSString stringWithFormat:@"%@%@%@%@",ressourcePath,@"/",modelName,@".geo"] UTF8String]); - [self hideModelsList]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshParameters" object:nil]; - return indexPath; + /*for(int y=0;y<*height;y++){ + for(int x=0;x<=*width;x++){ + printf("%c", (*(*map+y**width+x) == 0x00)? ' ' : '#'); + } + printf("\n"); + }*/ } - @end diff --git a/contrib/mobile/iOS/Onelab/MasterViewController.mm b/contrib/mobile/iOS/Onelab/MasterViewController.mm index eff7cb9e0e..b9ff02effd 100644 --- a/contrib/mobile/iOS/Onelab/MasterViewController.mm +++ b/contrib/mobile/iOS/Onelab/MasterViewController.mm @@ -193,9 +193,11 @@ { dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ [runButton setTitle:@"Stop"]; + [self refreshControl]; [runButton setAction:@selector(stopRunning)]; onelab_cb("compute"); [runButton setTitle:@"Run"]; + [self refreshControl]; [runButton setAction:@selector(runWithNewParameter)]; [self getAvailableParam]; }); diff --git a/contrib/mobile/iOS/Onelab/en.lproj/MainStoryboard.storyboard b/contrib/mobile/iOS/Onelab/en.lproj/iPadStoryboard.storyboard similarity index 73% rename from contrib/mobile/iOS/Onelab/en.lproj/MainStoryboard.storyboard rename to contrib/mobile/iOS/Onelab/en.lproj/iPadStoryboard.storyboard index 46a32c8cf6..22f7e1e20f 100644 --- a/contrib/mobile/iOS/Onelab/en.lproj/MainStoryboard.storyboard +++ b/contrib/mobile/iOS/Onelab/en.lproj/iPadStoryboard.storyboard @@ -1,14 +1,13 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> -<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="2549" systemVersion="12C60" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" initialViewController="5"> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="3084" systemVersion="12E55" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" initialViewController="5"> <dependencies> - <deployment defaultVersion="1296" identifier="iOS"/> - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="1498"/> + <deployment defaultVersion="1552" identifier="iOS"/> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="2083"/> </dependencies> <scenes> <!--Navigation Controller--> <scene sceneID="14"> <objects> - <placeholder placeholderIdentifier="IBFirstResponder" id="13" sceneMemberID="firstResponder"/> <navigationController id="3" sceneMemberID="viewController"> <navigationBar key="navigationBar" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="6"> <autoresizingMask key="autoresizingMask"/> @@ -17,13 +16,13 @@ <segue destination="19" kind="relationship" relationship="rootViewController" id="25"/> </connections> </navigationController> + <placeholder placeholderIdentifier="IBFirstResponder" id="13" sceneMemberID="firstResponder"/> </objects> - <point key="canvasLocation" x="448" y="-630"/> + <point key="canvasLocation" x="440" y="-806"/> </scene> <!--Detail View Controller - Detail--> <scene sceneID="16"> <objects> - <placeholder placeholderIdentifier="IBFirstResponder" id="15" sceneMemberID="firstResponder"/> <viewController storyboardIdentifier="" title="Detail" id="4" customClass="DetailViewController" sceneMemberID="viewController"> <view key="view" contentMode="scaleToFill" id="26" customClass="EAGLView"> <rect key="frame" x="0.0" y="64" width="703" height="660"/> @@ -31,8 +30,8 @@ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/> <simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/> <connections> - <outletCollection property="gestureRecognizers" destination="RL1-jv-cjC" id="y8D-yh-PkV"/> - <outletCollection property="gestureRecognizers" destination="Nb5-mS-uY7" id="aF3-Oi-e8B"/> + <outletCollection property="gestureRecognizers" destination="RL1-jv-cjC" appends="YES" id="y8D-yh-PkV"/> + <outletCollection property="gestureRecognizers" destination="Nb5-mS-uY7" appends="YES" id="aF3-Oi-e8B"/> </connections> </view> <toolbarItems/> @@ -40,8 +39,10 @@ <simulatedToolbarMetrics key="simulatedBottomBarMetrics"/> <connections> <outlet property="glView" destination="26" id="i7d-I7-Zhz"/> + <segue destination="E9F-81-Qlc" kind="push" id="NvT-Dc-KH4"/> </connections> </viewController> + <placeholder placeholderIdentifier="IBFirstResponder" id="15" sceneMemberID="firstResponder"/> <tapGestureRecognizer id="RL1-jv-cjC"> <connections> <action selector="tap:" destination="4" id="hTk-hm-dba"/> @@ -53,14 +54,45 @@ </connections> </pinchGestureRecognizer> </objects> - <point key="canvasLocation" x="524" y="342"/> + <point key="canvasLocation" x="1144" y="330"/> + </scene> + <!--Model List Controller - Load a new model--> + <scene sceneID="ggP-yy-g12"> + <objects> + <tableViewController id="E9F-81-Qlc" customClass="ModelListController" sceneMemberID="viewController"> + <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="tal-df-VsP"> + <rect key="frame" x="0.0" y="64" width="703" height="660"/> + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> + <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> + <simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/> + <prototypes> + <tableViewCell contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="ozg-kT-Ijz"> + <rect key="frame" x="0.0" y="22" width="703" 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="703" height="43"/> + <autoresizingMask key="autoresizingMask"/> + <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> + </view> + </tableViewCell> + </prototypes> + <connections> + <outlet property="dataSource" destination="E9F-81-Qlc" id="2Za-8v-z7o"/> + <outlet property="delegate" destination="E9F-81-Qlc" id="88m-bV-0PG"/> + </connections> + </tableView> + <navigationItem key="navigationItem" title="Load a new model" id="Z27-wO-c1E"/> + </tableViewController> + <placeholder placeholderIdentifier="IBFirstResponder" id="JFe-Hg-fSu" userLabel="First Responder" sceneMemberID="firstResponder"/> + </objects> + <point key="canvasLocation" x="1953" y="330"/> </scene> <!--Split View Controller--> <scene sceneID="18"> <objects> - <placeholder placeholderIdentifier="IBFirstResponder" id="17" sceneMemberID="firstResponder"/> <splitViewController id="5" sceneMemberID="viewController"> <toolbarItems/> + <navigationItem key="navigationItem" id="Pnc-za-KDo"/> <simulatedStatusBarMetrics key="simulatedStatusBarMetrics" statusBarStyle="blackTranslucent"/> <simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/> <connections> @@ -68,13 +100,13 @@ <segue destination="42" kind="relationship" relationship="detailViewController" id="51"/> </connections> </splitViewController> + <placeholder placeholderIdentifier="IBFirstResponder" id="17" sceneMemberID="firstResponder"/> </objects> <point key="canvasLocation" x="-879" y="-806"/> </scene> <!--Master View Controller - Master--> <scene sceneID="24"> <objects> - <placeholder placeholderIdentifier="IBFirstResponder" id="23" sceneMemberID="firstResponder"/> <tableViewController storyboardIdentifier="" title="Master" clearsSelectionOnViewWillAppear="NO" id="19" customClass="MasterViewController" sceneMemberID="viewController"> <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="singleLineEtched" allowsSelection="NO" rowHeight="44" sectionHeaderHeight="10" sectionFooterHeight="10" id="20"> <rect key="frame" x="0.0" y="64" width="320" height="704"/> @@ -110,13 +142,13 @@ </tableView> <navigationItem key="navigationItem" title="Settings" id="40"/> </tableViewController> + <placeholder placeholderIdentifier="IBFirstResponder" id="23" sceneMemberID="firstResponder"/> </objects> - <point key="canvasLocation" x="859" y="-631"/> + <point key="canvasLocation" x="851" y="-807"/> </scene> <!--Navigation Controller--> <scene sceneID="50"> <objects> - <placeholder placeholderIdentifier="IBFirstResponder" id="49" userLabel="First Responder" sceneMemberID="firstResponder"/> <navigationController id="42" sceneMemberID="viewController"> <navigationBar key="navigationBar" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="43"> <autoresizingMask key="autoresizingMask"/> @@ -125,14 +157,17 @@ <segue destination="4" kind="relationship" relationship="rootViewController" id="52"/> </connections> </navigationController> + <placeholder placeholderIdentifier="IBFirstResponder" id="49" userLabel="First Responder" sceneMemberID="firstResponder"/> </objects> - <point key="canvasLocation" x="-366" y="248"/> + <point key="canvasLocation" x="342" y="338"/> </scene> </scenes> <classes> <class className="DetailViewController" superclassName="UIViewController"> <source key="sourceIdentifier" type="project" relativePath="./Classes/DetailViewController.h"/> <relationships> + <relationship kind="action" name="PViewIntervalType:"/> + <relationship kind="action" name="PViewVisible:"/> <relationship kind="action" name="pinch:" candidateClass="UIPinchGestureRecognizer"/> <relationship kind="action" name="tap:" candidateClass="UITapGestureRecognizer"/> <relationship kind="outlet" name="detailDescriptionLabel" candidateClass="UILabel"/> @@ -144,6 +179,9 @@ <class className="MasterViewController" superclassName="UITableViewController"> <source key="sourceIdentifier" type="project" relativePath="./Classes/MasterViewController.h"/> </class> + <class className="ModelListController" superclassName="UITableViewController"> + <source key="sourceIdentifier" type="project" relativePath="./Classes/ModelListController.h"/> + </class> </classes> <simulatedMetricsContainer key="defaultSimulatedMetrics"> <simulatedStatusBarMetrics key="statusBar" statusBarStyle="blackTranslucent"/> diff --git a/contrib/mobile/iosGModel.h b/contrib/mobile/iosGModel.h index 450efbfad6..44fd703d19 100644 --- a/contrib/mobile/iosGModel.h +++ b/contrib/mobile/iosGModel.h @@ -13,7 +13,16 @@ #include <string> #include "drawContext.h" + +static void * objc; + void messageFromCpp (void *self, std::string level, std::string msg); +void getBitmap(void *self, const char *text, int textsize, unsigned char **map, int *height, int *width, int *realWidth=NULL); +//void getBitmapFromString(const char *text, int textsize, unsigned char **map, int *height, int *width, int *realWidth=NULL); +void getBitmapFromString(const char *text, int textsize, unsigned char **map, int *height, int *width, int *realWidth) +{ + getBitmap(objc, text, textsize, map, height, width, realWidth); +} class MobileMessage : GmshMessage { @@ -27,18 +36,10 @@ public: messageFromCpp(_objcObject, level, message); } }; - -class iosGModel +void setObjCBridge(void *objcObject) { -private: - void* _objcObject; -public: - iosGModel(void* objcObject) - { - _objcObject = objcObject; - Msg::SetCallback((GmshMessage*)new MobileMessage(objcObject)); - } - ~iosGModel(){} -}; + objc = objcObject; + Msg::SetCallback((GmshMessage*)new MobileMessage(objcObject)); +} #endif /* defined(__Onelab__iosGModel__) */ -- GitLab