Skip to content

Commit 3992151

Browse files
committed
Fixing annotation saving issues
* Handle case when loading when an error occurs. * Fixing selectors after loading annotation. * Fixing issues with saving blur * Fixing issues with saving bubbles * Fixing issues with saving pencil lines * Cleaning up debug output from previous work
1 parent d2b536c commit 3992151

15 files changed

+198
-58
lines changed

src/Canvas.vala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,16 +514,20 @@ public class Canvas : DrawingArea {
514514

515515
//-------------------------------------------------------------
516516
// Loads this canvas and the canvas items from XML format.
517-
public void load( Xml.Node* node ) {
517+
public bool load( Xml.Node* node ) {
518+
519+
bool image_loaded = false;
518520

519521
for( Xml.Node* it=node->children; it!=null; it=it->next ) {
520522
if( it->type == Xml.ElementType.ELEMENT_NODE ) {
521523
switch( it->name ) {
522-
case "image" : image.load( it ); break;
524+
case "image" : image_loaded = image.load( it ); break;
523525
case "items" : items.load( it ); break;
524526
}
525527
}
526-
}
528+
}
529+
530+
return( image_loaded );
527531

528532
}
529533

src/CanvasImage.vala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,13 @@ public class CanvasImage {
607607

608608
//-------------------------------------------------------------
609609
// Load the contents of this canvas image from XML format.
610-
public void load( Xml.Node* node ) {
610+
public bool load( Xml.Node* node ) {
611+
612+
var loaded = false;
611613

612614
var fname = node->get_prop( "filename" );
613615
if( fname != null ) {
614-
stdout.printf( "Opening image: %s\n", fname );
615-
_canvas.editor.open_image( fname );
616+
loaded = _canvas.editor.open_image( fname );
616617
}
617618

618619
var a = node->get_prop( "angle" );
@@ -621,6 +622,8 @@ public class CanvasImage {
621622
// TBD - We will probably want to handle the angle change in the canvas.
622623
}
623624

625+
return( loaded );
626+
624627
}
625628

626629
/****************************************************************************/

src/CanvasPoint.vala

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ public enum CanvasPointType {
3434
CONTROL,
3535
SELECTOR;
3636

37-
/* Returns the string version of this type */
37+
//-------------------------------------------------------------
38+
// Returns the string version of this type.
3839
public string to_string() {
3940
switch( this ) {
4041
case RESIZER0 : return( "resizer0" );
@@ -51,7 +52,26 @@ public enum CanvasPointType {
5152
}
5253
}
5354

54-
/* Returns the hidden/shown version of the current type */
55+
//-------------------------------------------------------------
56+
// Parses the given string and returns its CanvasPointType value.
57+
public static CanvasPointType parse( string value ) {
58+
switch( value ) {
59+
case "resizer0" : return( RESIZER0 );
60+
case "resizer1" : return( RESIZER1 );
61+
case "resizer2" : return( RESIZER2 );
62+
case "resizer3" : return( RESIZER3 );
63+
case "hidden0" : return( HIDDEN0 );
64+
case "hidden1" : return( HIDDEN1 );
65+
case "hidden2" : return( HIDDEN2 );
66+
case "hidden3" : return( HIDDEN3 );
67+
case "control" : return( CONTROL );
68+
case "selector" : return( SELECTOR );
69+
default : return( NONE );
70+
}
71+
}
72+
73+
//-------------------------------------------------------------
74+
// Returns the hidden/shown version of the current type.
5575
public CanvasPointType version( bool hide ) {
5676
switch( this ) {
5777
case RESIZER0 : return( hide ? HIDDEN0 : RESIZER0 );
@@ -66,12 +86,14 @@ public enum CanvasPointType {
6686
}
6787
}
6888

69-
/* Returns true if this point should be drawn */
89+
//-------------------------------------------------------------
90+
// Returns true if this point should be drawn.
7091
public bool draw() {
7192
return( (this == RESIZER0) || (this == RESIZER1) || (this == RESIZER2) || (this == RESIZER3) || (this == CONTROL) || (this == SELECTOR) );
7293
}
7394

74-
/* Returns the color to draw the given point */
95+
//-------------------------------------------------------------
96+
// Returns the color to draw the given point.
7597
public Gdk.RGBA color() {
7698
switch( this ) {
7799
case SELECTOR :
@@ -88,7 +110,8 @@ public enum CanvasPointType {
88110
}
89111
}
90112

91-
/* Returns true if the kind is hidden */
113+
//-------------------------------------------------------------
114+
// Returns true if the kind is hidden.
92115
public bool is_hidden() {
93116
return( (this == HIDDEN0) || (this == HIDDEN1) || (this == HIDDEN2) || (this == HIDDEN3) );
94117
}
@@ -101,57 +124,97 @@ public class CanvasPoint {
101124
public double y { get; set; default = 0.0; }
102125
public CanvasPointType kind { get; private set; default = CanvasPointType.NONE; }
103126

104-
/* Constructor */
127+
//-------------------------------------------------------------
128+
// Constructor.
105129
public CanvasPoint( CanvasPointType kind = CanvasPointType.NONE ) {
106130
this.kind = kind;
107131
}
108132

109-
/* Copy constructor */
133+
//-------------------------------------------------------------
134+
// Copy constructor
110135
public CanvasPoint.from_point( CanvasPoint point ) {
111136
copy( point );
112137
}
113138

114-
/* Constructor */
139+
//-------------------------------------------------------------
140+
// Constructor.
115141
public CanvasPoint.from_coords( double x, double y, CanvasPointType kind = CanvasPointType.NONE ) {
116142
copy_coords( x, y );
117143
this.kind = kind;
118144
}
119145

120-
/* Copies the point information to this instance */
146+
//-------------------------------------------------------------
147+
// Copies the point information to this instance.
121148
public void copy( CanvasPoint point ) {
122149
this.x = point.x;
123150
this.y = point.y;
124151
this.kind = point.kind;
125152
}
126153

127-
/* Copies the x,y coordinates to this instance */
154+
//-------------------------------------------------------------
155+
// Copies the x,y coordinates to this instance.
128156
public void copy_coords( double x, double y ) {
129157
this.x = x;
130158
this.y = y;
131159
}
132160

133-
/* Adjust the point by the given amounts */
161+
//-------------------------------------------------------------
162+
// Adjust the point by the given amounts.
134163
public void adjust( double diffx, double diffy ) {
135164
this.x += diffx;
136165
this.y += diffy;
137166
}
138167

139-
/* Resets the visual aspect of this point to non-hidden state */
168+
//-------------------------------------------------------------
169+
// Resets the visual aspect of this point to non-hidden state.
140170
public void reset_visual() {
141171
kind = kind.version( false );
142172
}
143173

144-
/* Updates the visual status of this point kind */
174+
//-------------------------------------------------------------
175+
// Updates the visual status of this point kind.
145176
public void set_visual( CanvasPointType point_kind, bool hide ) {
146177
if( point_kind != kind ) {
147178
kind = kind.version( hide );
148179
}
149180
}
150181

151-
/* Returns a printable version of this point */
182+
//-------------------------------------------------------------
183+
// Returns a printable version of this point.
152184
public string to_string() {
153185
return( "x: %g, y: %g, kind: %s".printf( x, y, kind.to_string() ) );
154186
}
155187

188+
//-------------------------------------------------------------
189+
// Saves the contents of this point in XML format.
190+
public Xml.Node* save() {
191+
Xml.Node* node = new Xml.Node( null, "point" );
192+
node->set_prop( "x", x.to_string() );
193+
node->set_prop( "y", y.to_string() );
194+
node->set_prop( "kind", kind.to_string() );
195+
return( node );
196+
}
197+
198+
//-------------------------------------------------------------
199+
// Loads the contents of this point
200+
public void load( Xml.Node* node ) {
201+
202+
var x = node->get_prop( "x" );
203+
if( x != null ) {
204+
this.x = double.parse( x );
205+
}
206+
207+
var y = node->get_prop( "y" );
208+
if( y != null ) {
209+
this.y = double.parse( y );
210+
}
211+
212+
var k = node->get_prop( "kind" );
213+
if( k != null ) {
214+
this.kind = CanvasPointType.parse( k );
215+
}
216+
217+
}
218+
156219
}
157220

src/Editor.vala

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,9 @@ public class Editor : Box {
106106

107107
//-------------------------------------------------------------
108108
// Opens the given image.
109-
public void open_image( string filename ) {
109+
public bool open_image( string filename ) {
110110
_filename = filename;
111-
if( filename.has_suffix( ".annotator" ) ) {
112-
// TBD - load( filename );
113-
} else {
114-
canvas.open_image( filename );
115-
}
111+
return( canvas.open_image( filename ) );
116112
}
117113

118114
//-------------------------------------------------------------

src/MainWindow.vala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ public class MainWindow : Gtk.ApplicationWindow {
456456

457457
/* Add the 'all image formats' filter first */
458458
var filter = new FileFilter();
459-
filter.set_filter_name( _( "All Image Formats (*)" ) );
459+
filter.set_filter_name( _( "All Loadable Formats" ) );
460460
foreach( string pattern in patterns ) {
461461
filter.add_pattern( pattern );
462462
}
@@ -498,19 +498,19 @@ public class MainWindow : Gtk.ApplicationWindow {
498498
image is successfully read and displayed.
499499
*/
500500
public void open_file( string filename ) {
501-
stdout.printf( "HERE A\n" );
501+
var opened = false;
502502
if( filename.has_suffix( ".annotator" ) ) {
503-
stdout.printf( "HERE B\n" );
504503
var export = (_editor.canvas.image.exports.get_by_name( "annotator" ) as ExportEditable);
505504
if( export != null ) {
506-
stdout.printf( "HERE C\n" );
507-
export.import( filename );
505+
opened = export.import( filename );
508506
}
509507
} else {
510-
_editor.open_image( filename );
508+
opened = _editor.open_image( filename );
509+
}
510+
if( opened ) {
511+
_zoom_btn.set_sensitive( true );
512+
_export_btn.set_sensitive( true );
511513
}
512-
_zoom_btn.set_sensitive( true );
513-
_export_btn.set_sensitive( true );
514514
}
515515

516516
/* Parses image data from standard output to use as pixbuf */

src/canvas_items/CanvasItemArrow.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ public class CanvasItemArrow : CanvasItem {
259259

260260
/* Loads this item from XML */
261261
public override void load( Xml.Node* node ) {
262-
base.load( node );
263262
var pa = node->get_prop( "peak-angle" );
264263
if( pa != null ) {
265264
_peak_a = double.parse( pa );
@@ -276,6 +275,7 @@ public class CanvasItemArrow : CanvasItem {
276275
if( vc != null ) {
277276
_valley_c = double.parse( vc );
278277
}
278+
base.load( node );
279279
}
280280

281281
/* Draw the rectangle */

src/canvas_items/CanvasItemBlur.vala

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,31 @@ public class CanvasItemBlur : CanvasItem {
121121

122122
}
123123

124-
/* Provides cursor to display when mouse cursor is hovering over the given selector */
124+
//-------------------------------------------------------------
125+
// Provides cursor to display when mouse cursor is hovering over
126+
// the given selector.
125127
public override Cursor? get_selector_cursor( int index ) {
126128
return( _sel_cursors[index] );
127129
}
128130

131+
//-------------------------------------------------------------
132+
// Saves the description of this blur item in XML format.
133+
public override Xml.Node* save( int id, string? image_dir ) {
134+
Xml.Node* node = base.save( id, image_dir );
135+
node->set_prop( "radius", blur_radius.to_string() );
136+
return( node );
137+
}
138+
139+
//-------------------------------------------------------------
140+
// Loads the description of this blur item from XML format.
141+
public override void load( Xml.Node* node ) {
142+
var r = node->get_prop( "radius" );
143+
if( r != null ) {
144+
blur_radius = int.parse( r );
145+
}
146+
base.load( node );
147+
}
148+
129149
//-------------------------------------------------------------
130150
// Adds the contextual menu item values
131151
protected override void add_contextual_menu_items( CanvasItemMenu menu ) {

src/canvas_items/CanvasItemBubble.vala

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public enum CanvasBubbleType {
4343
}
4444
}
4545

46-
public CanvasBubbleType parse( string str ) {
46+
public static CanvasBubbleType parse( string str ) {
4747
switch( str ) {
4848
case "talk" : return( TALK );
4949
case "think" : return( THINK );
@@ -152,11 +152,31 @@ public class CanvasItemBubble : CanvasItem {
152152

153153
}
154154

155-
/* Provides cursor to display when mouse cursor is hovering over the given selector */
155+
//-------------------------------------------------------------
156+
// Provides cursor to display when mouse cursor is hovering over
157+
// the given selector.
156158
public override Cursor? get_selector_cursor( int index ) {
157159
return( _sel_cursors[index] );
158160
}
159161

162+
//-------------------------------------------------------------
163+
// Saves the description of this item in XML format.
164+
public override Xml.Node* save( int id, string? image_dir ) {
165+
Xml.Node* node = base.save( id, image_dir );
166+
node->set_prop( "type", _type.to_string() );
167+
return( node );
168+
}
169+
170+
//-------------------------------------------------------------
171+
// Loads the description of this item from XML format.
172+
public override void load( Xml.Node* node ) {
173+
var t = node->get_prop( "type" );
174+
if( t != null ) {
175+
_type = CanvasBubbleType.parse( t );
176+
}
177+
base.load( node );
178+
}
179+
160180
/* Helper function that finds the two tangential points on a circle to a given point */
161181
private bool find_tangents( CanvasPoint center, double radius, CanvasPoint external, CanvasPoint pt1, CanvasPoint pt2 ) {
162182

src/canvas_items/CanvasItemImage.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ public class CanvasItemImage : CanvasItem {
142142

143143
/* Loads this item from XML */
144144
public override void load( Xml.Node* node ) {
145-
base.load( node );
146145
var n = node->get_prop( "name" );
147146
if( n != null ) {
148147
_name = n;
@@ -152,6 +151,7 @@ public class CanvasItemImage : CanvasItem {
152151
_file = bool.parse( f );
153152
}
154153
create_image( _name, _file, (int)bbox.width );
154+
base.load( node );
155155
}
156156

157157
/* Draw the rectangle */

src/canvas_items/CanvasItemMagnifier.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,11 @@ public class CanvasItemMagnifier : CanvasItem {
237237
//-------------------------------------------------------------
238238
// Loads this item from XML.
239239
public override void load( Xml.Node* node ) {
240-
base.load( node );
241240
var f = node->get_prop( "zoom-factor" );
242241
if( f != null ) {
243242
_zoom_factor = double.parse( f );
244243
}
244+
base.load( node );
245245
}
246246

247247
/* Helper function that finds the two tangential points on a circle to a given point */

0 commit comments

Comments
 (0)