Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Myapp.m
Go to the documentation of this file.
1 #import "Myapp.h"
2 #import "RLE.h"
3 #import "RASF.h"
4 #import <rle.h>
5 #import <stdio.h>
6 #import <stdlib.h>
7 #import <libc.h>
8 #import <appkit/OpenPanel.h>
9 #import <appkit/SavePanel.h>
10 #import <appkit/PopUpList.h>
11 #import <appkit/Control.h>
12 #import <appkit/ActionCell.h>
13 #import <strings.h>
14 #import <appkit/tiff.h>
15 
16 // Myapp.m
17 //
18 // Written by Vince DeMarco
19 // demarco@cpsc.ucalgary.ca
20 //
21 // This program is In the Public Domain. If you make any improvements to this
22 // program please let me know
23 //
24 
25 @implementation Myapp:Application
26 + new
27 {
28  self = [super new];
29  [self activateSelf:NO];
30  saveType = 1; // Set Default type to save as Tiff
31  return(self);
32 }
33 
34 - (int)appOpenFile:(const char *)fullPath type:(const char *)type
35 {
36  id ptr;
37 
38  [self activateSelf:NO];
39  if (!strcmp(type,"rle"))
40  ptr = [[RLE alloc]init];
41  else
42  ptr = [[RASF alloc]init];
43  [ptr open:(char *)fullPath];
44  return YES;
45 }
46 
48 {
49  return YES;
50 }
51 
52 - openfile:sender
53 {
54  char temp[1024];
55  char directory[1024];
56  char *extension;
57  id ptr;
58  int loop;
59  static const char *const opentypes[] = {"rle","rasf",NULL};
60 
61  openpanel = [OpenPanel new];
62 
63  [openpanel allowMultipleFiles:YES];
64 
65  if ([openpanel runModalForTypes:opentypes]) {
66  loop = 0;
67  strncpy(directory,[openpanel directory],1024);
68  while ([openpanel filenames][loop]) {
69  sprintf(temp,"%s/%s",directory,[openpanel filenames][loop]);
70  extension = rindex(temp,'.');
71  if (!strcmp(extension,".rle"))
72  ptr = [[RLE alloc]init];
73  else
74  ptr = [[RASF alloc]init];
75 
76  [ptr open:temp];
77  ++loop;
78  }
79  }
80  return(self);
81 }
82 
83 - print:sender
84 {
85  [[mainWindow contentView] printPSCode:sender];
86  return(self);
87 }
88 
89 - save:sender
90 {
91  savepanel = [SavePanel new];
92  [savepanel setAccessoryView:savePanelAccessory];
93  [savepanel setRequiredFileType:"tiff"];
94  [savepanel setTitle:"Save To TIFF"];
95  [compPopUP setEnabled:YES];
96  saveType = 1;
97 
98  if (mainWindow != nil){
99  if ([savepanel runModal]){
100  if (saveType == 1){
101  [[mainWindow contentView] saveAsTiff:[savepanel filename] usingCompression:[self setCompType]];
102  }else{
103  [[mainWindow contentView] saveAsEPS:[savepanel filename]];
104  }
105  }
106  }
107  return(self);
108 }
109 
110 - saveTypeEPS:sender
111 {
112  [savepanel setRequiredFileType:"eps"];
113  [savepanel setTitle:"Save To EPS"];
114  [compPopUP setEnabled:NO];
115  saveType = 2;
116  return (self);
117 }
118 
119 - saveTypeTiff:sender
120 {
121  [savepanel setRequiredFileType:"tiff"];
122  [savepanel setTitle:"Save To TIFF"];
123  [compPopUP setEnabled:YES];
124  saveType = 1;
125  return(self);
126 }
127 
129 {
130 
131  const char *selected_Cell = [[compPopUP selectedCell] title];
132 
133  switch(selected_Cell[0]){
134  case 'L':
135  return(NX_TIFF_COMPRESSION_LZW);
136  case 'P':
137  return(NX_TIFF_COMPRESSION_PACKBITS);
138  case 'N':
139  return(NX_TIFF_COMPRESSION_NONE);
140  case 'J':
141  return(NX_TIFF_COMPRESSION_JPEG);
142  }
143  return(NX_TIFF_COMPRESSION_LZW);
144 }
145 @end
int setCompType()
Definition: Myapp.m:128
id compPopUP
Definition: Myapp.h:16
BOOL appAcceptsAnotherFile:(id sender)
Definition: Myapp.m:47
id init()
id saveTypeTiff:(id sender)
Definition: Myapp.m:119
id saveTypeEPS:(id sender)
Definition: Myapp.m:110
#define rindex
Definition: rle_config.h:97
id savepanel
Definition: Myapp.h:14
id savePanelAccessory
Definition: Myapp.h:15
id openpanel
Definition: Myapp.h:13
id save:(id sender)
Definition: Myapp.m:89
id new()
int saveType
Definition: Myapp.h:17
Definition: RLE.h:13
id openfile:(id sender)
Definition: Myapp.m:52
id print:(id sender)
Definition: Myapp.m:83
int appOpenFile:type:(const char *fullPath,[type] const char *type)
Definition: Myapp.m:34
id open:(char *filename)
Definition: RLE.m:31
Definition: Myapp.m:25
Definition: RASF.h:13