From 5bbbfdad35e9ae65ced0f29eb88b1600e8ead687 Mon Sep 17 00:00:00 2001 From: William Joye Date: Wed, 5 Jun 2019 13:04:41 -0400 Subject: GUI: colobar cmds load/save errors now report via Error proc --- ds9/doc/release/r8.1.html | 1 + ds9/library/colorbar.tcl | 97 +++++++++++++++++++++++-------------- tksao/colorbar/colorbar.C | 119 +++++++++++++++++++++++++--------------------- 3 files changed, 125 insertions(+), 92 deletions(-) diff --git a/ds9/doc/release/r8.1.html b/ds9/doc/release/r8.1.html index b58b6b8..8548a4c 100644 --- a/ds9/doc/release/r8.1.html +++ b/ds9/doc/release/r8.1.html @@ -81,6 +81,7 @@
  • 05.15.2019 RELEASE version 8.1b1
  • 05.28.2019 URL: more tolerant of mime types when downloading via http.
  • 06.04.2019 COLORBAR: fixed a number of issues with updating the screen with color tags active.
  • +
  • 06.05.2019 GUI: colobar load/save errors now report via Error proc.
  • xx.xx.2019 RELEASE version 8.1b2
  • diff --git a/ds9/library/colorbar.tcl b/ds9/library/colorbar.tcl index f3a657f..c3fa35f 100644 --- a/ds9/library/colorbar.tcl +++ b/ds9/library/colorbar.tcl @@ -133,33 +133,39 @@ proc LoadColormap {} { } # used by backup -proc LoadColormapFile {filename} { +proc LoadColormapFile {fn} { global colorbar global icolorbar global current global ds9 - if {$filename != {}} { - colorbar load "\{$filename\}" - set id [colorbar get id] - set colorbar(map) [colorbar get name] + if {$fn == {}} { + return + } + + if {[catch {colorbar load "\{$fn\}"} rr]} { + Error $rr + return + } + + set id [colorbar get id] + set colorbar(map) [colorbar get name] + + $ds9(mb).color.user add radiobutton \ + -label "$colorbar(map)" \ + -variable colorbar(map) \ + -command [list ChangeColormapID $id] - $ds9(mb).color.user add radiobutton \ + if {[winfo exists $icolorbar(top)]} { + $icolorbar(mb).colormap.user add radiobutton \ -label "$colorbar(map)" \ -variable colorbar(map) \ -command [list ChangeColormapID $id] - - if {[winfo exists $icolorbar(top)]} { - $icolorbar(mb).colormap.user add radiobutton \ - -label "$colorbar(map)" \ - -variable colorbar(map) \ - -command [list ChangeColormapID $id] - } - incr icolorbar(count) - - ChangeColormapID $id } + incr icolorbar(count) + + ChangeColormapID $id } proc SaveColormap {} { @@ -167,36 +173,45 @@ proc SaveColormap {} { SaveColormapFile [SaveFileDialog colorbarfbox] } -proc SaveColormapFile {filename} { - if {$filename != {}} { - colorbar save "\{$filename\}" +proc SaveColormapFile {fn} { + if {$fn == {}} { + return + } + + if {[catch {colorbar save "\{$fn\}"} rr]} { + Error $rr + return } } proc LoadContrastBias {} { global dcolorbar - set filename [OpenFileDialog contrastbiasfbox] - if {$filename != {}} { - if {![catch {set ch [open $filename r]}]} { - set ll [gets $ch] - close $ch - set dcolorbar(contrast) [lindex $ll 0] - set dcolorbar(bias) [lindex $ll 1] - ApplyColormap - } + set fn [OpenFileDialog contrastbiasfbox] + if {$fn == {}} { + return + } + + if {![catch {set ch [open $fn r]}]} { + set ll [gets $ch] + close $ch + set dcolorbar(contrast) [lindex $ll 0] + set dcolorbar(bias) [lindex $ll 1] + ApplyColormap } } proc SaveContrastBias {} { global dcolorbar - set filename [SaveFileDialog contrastbiasfbox] - if {$filename != {}} { - if {![catch {set ch [open $filename w]}]} { - puts $ch "$dcolorbar(contrast) $dcolorbar(bias)" - close $ch - } + set fn [SaveFileDialog contrastbiasfbox] + if {$fn == {}} { + return + } + + if {![catch {set ch [open $fn w]}]} { + puts $ch "$dcolorbar(contrast) $dcolorbar(bias)" + close $ch } } @@ -676,7 +691,10 @@ proc LoadColorTag {fn} { if {$fn != {}} { # yes, we need this UpdateColormapLevel - $current(colorbar) tag load "\{$fn\}" + if {[catch {$current(colorbar) tag load "\{$fn\}"} rr]} { + Error $rr + return + } if {$current(frame) != {}} { $current(frame) colormap [$current(colorbar) get colormap] $current(frame) colorbar tag "\{[$current(colorbar) get tag]\}" @@ -688,8 +706,13 @@ proc SaveColorTag {} { global current set fn [SaveFileDialog colortagfbox] - if {$fn != {}} { - $current(colorbar) tag save "\{$fn\}" + if {$fn == {}} { + return + } + + if {[catch {colorbar tag save "\{$fn\}"} rr]} { + Error $rr + return } } diff --git a/tksao/colorbar/colorbar.C b/tksao/colorbar/colorbar.C index a35610d..49229cd 100644 --- a/tksao/colorbar/colorbar.C +++ b/tksao/colorbar/colorbar.C @@ -723,69 +723,78 @@ void Colorbar::tagLoadCmd(const char* fn) { ifstream str(fn); - if (str) { - ctags.deleteAll(); - - while (!str.eof()) { - int mm=0; - int nn=0; - double aa =0; - double bb =0; - char color[32]; - *color ='\0'; - - str >> aa >> bb >> color; - - if (aa && bb && *color) { - // special case - if (aa>lut[cnt-1] && bb>lut[cnt-1]) - continue; - else if (aa=0; ii--) - if (bb>lut[ii]) { - nn=ii; - break; - } - - Vector rr = Vector(mm,nn)/cnt*colorCount; - ctags.append(new ColorTag(this,rr[0],rr[1],color)); - } - } + if (!str) { + Tcl_AppendResult(interp, " unable to load color tags: ", fn, NULL); + result = TCL_ERROR; + return; + } - updateColors(); + ctags.deleteAll(); + + while (!str.eof()) { + int mm=0; + int nn=0; + double aa =0; + double bb =0; + char color[32]; + *color ='\0'; + + str >> aa >> bb >> color; + + if (aa && bb && *color) { + // special case + if (aa>lut[cnt-1] && bb>lut[cnt-1]) + continue; + else if (aa=0; ii--) + if (bb>lut[ii]) { + nn=ii; + break; + } + + Vector rr = Vector(mm,nn)/cnt*colorCount; + ctags.append(new ColorTag(this,rr[0],rr[1],color)); + } } + + updateColors(); } void Colorbar::tagSaveCmd(const char* fn) { ofstream str(fn); - if (str) { - ctags.head(); - while (ctags.current()) { - int startid = float(ctags.current()->start())/colorCount * cnt; - int stopid = float(ctags.current()->stop())/colorCount * cnt; - if (startid<0) - startid = 0; - if (startid>=cnt) - startid = cnt-1; - if (stopid<0) - stopid = 0; - if (stopid>=cnt) - stopid = cnt-1; - str << lut[startid] << ' ' << lut[stopid] << ' ' - << ctags.current()->colorname() << endl; - ctags.next(); - } + if (!str) { + Tcl_AppendResult(interp, " unable to save color tags: ", fn, NULL); + result = TCL_ERROR; + return; + } + + ctags.head(); + while (ctags.current()) { + int startid = float(ctags.current()->start())/colorCount * cnt; + int stopid = float(ctags.current()->stop())/colorCount * cnt; + if (startid<0) + startid = 0; + if (startid>=cnt) + startid = cnt-1; + if (stopid<0) + stopid = 0; + if (stopid>=cnt) + stopid = cnt-1; + + str << lut[startid] << ' ' << lut[stopid] << ' ' + << ctags.current()->colorname() << endl; + ctags.next(); } } -- cgit v0.12 From 762c557b335405159118aa614fc16bfb1f1dfa81 Mon Sep 17 00:00:00 2001 From: William Joye Date: Wed, 5 Jun 2019 13:04:53 -0400 Subject: GUI: colobar cmds load/save errors now report via Error proc --- ds9/doc/release/r8.1.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ds9/doc/release/r8.1.html b/ds9/doc/release/r8.1.html index 8548a4c..1eeb36a 100644 --- a/ds9/doc/release/r8.1.html +++ b/ds9/doc/release/r8.1.html @@ -81,7 +81,7 @@
  • 05.15.2019 RELEASE version 8.1b1
  • 05.28.2019 URL: more tolerant of mime types when downloading via http.
  • 06.04.2019 COLORBAR: fixed a number of issues with updating the screen with color tags active.
  • -
  • 06.05.2019 GUI: colobar load/save errors now report via Error proc.
  • +
  • 06.05.2019 GUI: colobar cmds load/save errors now report via Error proc.
  • xx.xx.2019 RELEASE version 8.1b2
  • -- cgit v0.12 From 98377b7120a4cd7be1387147966a6064c8519bd5 Mon Sep 17 00:00:00 2001 From: William Joye Date: Wed, 5 Jun 2019 13:16:54 -0400 Subject: GUI: colobar cmds load/save errors now report via Error proc --- tksao/colorbar/colorbar.C | 11 +++++++++-- tksao/colorbar/colormap.h | 2 +- tksao/colorbar/lut.C | 5 +++-- tksao/colorbar/lut.h | 2 +- tksao/colorbar/sao.C | 5 +++-- tksao/colorbar/sao.h | 2 +- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/tksao/colorbar/colorbar.C b/tksao/colorbar/colorbar.C index 49229cd..5b7a817 100644 --- a/tksao/colorbar/colorbar.C +++ b/tksao/colorbar/colorbar.C @@ -487,7 +487,10 @@ void Colorbar::mapCmd(int id) void Colorbar::saveCmd(const char* fn) { - cmaps.current()->save(fn); + if (!cmaps.current()->save(fn)) { + Tcl_AppendResult(interp, " unable to save colormap: ", fn, NULL); + result = TCL_ERROR; + } } void Colorbar::saveCmd(int id, const char* fn) @@ -495,12 +498,16 @@ void Colorbar::saveCmd(int id, const char* fn) ColorMapInfo* ptr = cmaps.begin(); while (ptr) { if (ptr->getID() == id) { - ptr->save(fn); + if (!ptr->save(fn)) { + Tcl_AppendResult(interp, " unable to save colormap: ", fn, NULL); + result = TCL_ERROR; + } return; } ptr = ptr->next(); } + Tcl_AppendResult(interp, " unable to save colormap: ", fn, NULL); result = TCL_ERROR; } diff --git a/tksao/colorbar/colormap.h b/tksao/colorbar/colormap.h index 9d1c006..45a66e0 100644 --- a/tksao/colorbar/colormap.h +++ b/tksao/colorbar/colormap.h @@ -53,7 +53,7 @@ public: virtual ColorMapInfo* dup() =0; virtual int load() =0; virtual int load(const char*) =0; - virtual void save(const char*) =0; + virtual int save(const char*) =0; virtual unsigned char getRedChar(int, int) =0; virtual unsigned char getGreenChar(int, int) =0; diff --git a/tksao/colorbar/lut.C b/tksao/colorbar/lut.C index 3b51110..08340c4 100644 --- a/tksao/colorbar/lut.C +++ b/tksao/colorbar/lut.C @@ -96,12 +96,13 @@ int LUTColorMap::load(const char* var) return 1; // we found at least one RGBColor } -void LUTColorMap::save(const char* fn) +int LUTColorMap::save(const char* fn) { ofstream fstr(fn); if (!fstr) - return; + return 0; fstr << *this; + return 1; } unsigned char LUTColorMap::getRedChar(int ii, int count) diff --git a/tksao/colorbar/lut.h b/tksao/colorbar/lut.h index 8b8bdf3..8249572 100644 --- a/tksao/colorbar/lut.h +++ b/tksao/colorbar/lut.h @@ -57,7 +57,7 @@ public: ColorMapInfo* dup() {return new LUTColorMap(*this);} int load(); int load(const char* var); - void save(const char*); + int save(const char*); unsigned char getRedChar(int, int); unsigned char getGreenChar(int, int); diff --git a/tksao/colorbar/sao.C b/tksao/colorbar/sao.C index c862371..10ff9bf 100644 --- a/tksao/colorbar/sao.C +++ b/tksao/colorbar/sao.C @@ -105,12 +105,13 @@ int SAOColorMap::load(const char* var) return 1; // we found at least one LIColor for each RGB } -void SAOColorMap::save(const char* fn) +int SAOColorMap::save(const char* fn) { ofstream f(fn); if (!f) - return; + return 0; f << *this; + return 1; } unsigned char SAOColorMap::getColorChar(int i, int count, List* cc) diff --git a/tksao/colorbar/sao.h b/tksao/colorbar/sao.h index 8e1d357..b67b7a7 100644 --- a/tksao/colorbar/sao.h +++ b/tksao/colorbar/sao.h @@ -65,7 +65,7 @@ public: ColorMapInfo* dup() {return new SAOColorMap(*this);} int load(); int load(const char* var); - void save(const char*); + int save(const char*); unsigned char getRedChar(int i, int c) {return getColorChar(i,c,&red);} unsigned char getGreenChar(int i, int c) {return getColorChar(i,c,&green);} -- cgit v0.12