comparison libinterp/corefcn/graphics.in.h @ 20577:c547458dc10e

eliminate error_state from most header files * defun-int.h, event-queue.h, graphics.in.h, oct-handle.h, ov-classdef.h, misc/f77-fcn.h, unwind-prot.h: Eliminate use of global error_state variable.
author John W. Eaton <jwe@octave.org>
date Sat, 03 Oct 2015 13:20:28 -0400
parents 564e59f75ef8
children 3af34e1ef330
comparison
equal deleted inserted replaced
20576:0fc9b572e566 20577:c547458dc10e
716 value[i] = c(i).string_value (); 716 value[i] = c(i).string_value ();
717 else 717 else
718 { 718 {
719 double d = c(i).double_value (); 719 double d = c(i).double_value ();
720 720
721 if (! error_state) 721 std::ostringstream buf;
722 { 722 buf << d;
723 std::ostringstream buf; 723 value[i] = buf.str ();
724 buf << d;
725 value[i] = buf.str ();
726 }
727 else
728 break;
729 } 724 }
730 } 725 }
731 } 726 }
732 727
733 text_label_property (const text_label_property& p) 728 text_label_property (const text_label_property& p)
793 value[i] = c(i).string_value (); 788 value[i] = c(i).string_value ();
794 else 789 else
795 { 790 {
796 double d = c(i).double_value (); 791 double d = c(i).double_value ();
797 792
798 if (! error_state) 793 std::ostringstream buf;
799 { 794 buf << d;
800 std::ostringstream buf; 795 value[i] = buf.str ();
801 buf << d;
802 value[i] = buf.str ();
803 }
804 else
805 return false;
806 } 796 }
807 } 797 }
808 798
809 stored_type = cellstr_t; 799 stored_type = cellstr_t;
810 } 800 }
811 else 801 else
812 { 802 {
813 NDArray nda = val.array_value (); 803 NDArray nda;
814 804
815 if (! error_state) 805 try
816 { 806 {
817 octave_idx_type nel = nda.numel (); 807 nda = val.array_value ();
818
819 value.resize (nel);
820
821 for (octave_idx_type i = 0; i < nel; i++)
822 {
823 std::ostringstream buf;
824 buf << nda(i);
825 value[i] = buf.str ();
826 }
827
828 stored_type = char_t;
829 } 808 }
830 else 809 catch (const octave_execution_exception&)
831 { 810 {
832 error ("set: invalid string property value for \"%s\"", 811 error ("set: invalid string property value for \"%s\"",
833 get_name ().c_str ()); 812 get_name ().c_str ());
834
835 return false;
836 } 813 }
814
815 octave_idx_type nel = nda.numel ();
816
817 value.resize (nel);
818
819 for (octave_idx_type i = 0; i < nel; i++)
820 {
821 std::ostringstream buf;
822 buf << nda(i);
823 value[i] = buf.str ();
824 }
825
826 stored_type = char_t;
837 } 827 }
838 828
839 return true; 829 return true;
840 } 830 }
841 831
1486 protected: 1476 protected:
1487 bool do_set (const octave_value& v) 1477 bool do_set (const octave_value& v)
1488 { 1478 {
1489 bool retval = array_property::do_set (v); 1479 bool retval = array_property::do_set (v);
1490 1480
1491 if (! error_state) 1481 dim_vector dv = data.dims ();
1482
1483 if (dv(0) > 1 && dv(1) == 1)
1492 { 1484 {
1493 dim_vector dv = data.dims (); 1485 int tmp = dv(0);
1494 1486 dv(0) = dv(1);
1495 if (dv(0) > 1 && dv(1) == 1) 1487 dv(1) = tmp;
1496 { 1488
1497 int tmp = dv(0); 1489 data = data.reshape (dv);
1498 dv(0) = dv(1);
1499 dv(1) = tmp;
1500
1501 data = data.reshape (dv);
1502 }
1503
1504 return retval;
1505 } 1490 }
1506 1491
1507 return false; 1492 return retval;
1508 } 1493 }
1509 1494
1510 private: 1495 private:
1511 OCTINTERP_API bool validate (const octave_value& v); 1496 OCTINTERP_API bool validate (const octave_value& v);
1512 }; 1497 };
1710 std::list<double> children_list; 1695 std::list<double> children_list;
1711 1696
1712 protected: 1697 protected:
1713 bool do_set (const octave_value& val) 1698 bool do_set (const octave_value& val)
1714 { 1699 {
1715 const Matrix new_kids = val.matrix_value (); 1700 Matrix new_kids;
1701
1702 try
1703 {
1704 new_kids = val.matrix_value ();
1705 }
1706 catch (const octave_execution_exception&)
1707 {
1708 error ("set: expecting children to be array of graphics handles");
1709 }
1716 1710
1717 octave_idx_type nel = new_kids.numel (); 1711 octave_idx_type nel = new_kids.numel ();
1718 1712
1719 const Matrix new_kids_column = new_kids.reshape (dim_vector (nel, 1)); 1713 const Matrix new_kids_column = new_kids.reshape (dim_vector (nel, 1));
1720 1714
1721 bool is_ok = true; 1715 bool is_ok = true;
1722 bool add_hidden = true; 1716 bool add_hidden = true;
1723 1717
1724 if (! error_state) 1718 const Matrix visible_kids = do_get_children (false);
1719
1720 if (visible_kids.numel () == new_kids.numel ())
1725 { 1721 {
1726 const Matrix visible_kids = do_get_children (false); 1722 Matrix t1 = visible_kids.sort ();
1727 1723 Matrix t2 = new_kids_column.sort ();
1728 if (visible_kids.numel () == new_kids.numel ()) 1724 Matrix t3 = get_hidden ().sort ();
1729 { 1725
1730 Matrix t1 = visible_kids.sort (); 1726 if (t1 != t2)
1731 Matrix t2 = new_kids_column.sort ();
1732 Matrix t3 = get_hidden ().sort ();
1733
1734 if (t1 != t2)
1735 is_ok = false;
1736
1737 if (t1 == t3)
1738 add_hidden = false;
1739 }
1740 else
1741 is_ok = false; 1727 is_ok = false;
1742 1728
1743 if (! is_ok) 1729 if (t1 == t3)
1744 error ("set: new children must be a permutation of existing children"); 1730 add_hidden = false;
1745 } 1731 }
1746 else 1732 else
1747 { 1733 is_ok = false;
1748 is_ok = false; 1734
1749 error ("set: expecting children to be array of graphics handles"); 1735 if (! is_ok)
1750 } 1736 error ("set: new children must be a permutation of existing children");
1751 1737
1752 if (is_ok) 1738 if (is_ok)
1753 { 1739 {
1754 Matrix tmp = new_kids_column; 1740 Matrix tmp = new_kids_column;
1755 1741
3393 3379
3394 void set_toolkit (const graphics_toolkit& b); 3380 void set_toolkit (const graphics_toolkit& b);
3395 3381
3396 void set___graphics_toolkit__ (const octave_value& val) 3382 void set___graphics_toolkit__ (const octave_value& val)
3397 { 3383 {
3398 if (! error_state) 3384 if (val.is_string ())
3399 { 3385 {
3400 if (val.is_string ()) 3386 std::string nm = val.string_value ();
3387 graphics_toolkit b = gtk_manager::find_toolkit (nm);
3388
3389 if (b.get_name () != nm)
3390 error ("set___graphics_toolkit__: invalid graphics toolkit");
3391 else if (nm != get___graphics_toolkit__ ())
3401 { 3392 {
3402 std::string nm = val.string_value (); 3393 set_toolkit (b);
3403 graphics_toolkit b = gtk_manager::find_toolkit (nm); 3394 mark_modified ();
3404 if (b.get_name () != nm)
3405 {
3406 error ("set___graphics_toolkit__: invalid graphics toolkit");
3407 }
3408 else
3409 {
3410 if (nm != get___graphics_toolkit__ ())
3411 {
3412 set_toolkit (b);
3413 mark_modified ();
3414 }
3415 }
3416 } 3395 }
3417 else
3418 error ("set___graphics_toolkit__ must be a string");
3419 } 3396 }
3397 else
3398 error ("set___graphics_toolkit__ must be a string");
3420 } 3399 }
3421 3400
3422 void adopt (const graphics_handle& h); 3401 void adopt (const graphics_handle& h);
3423 3402
3424 void set_position (const octave_value& val, 3403 void set_position (const octave_value& val,
4513 public: 4492 public:
4514 double get_fontsize_points (double box_pix_height = 0) const; 4493 double get_fontsize_points (double box_pix_height = 0) const;
4515 4494
4516 void set_position (const octave_value& val) 4495 void set_position (const octave_value& val)
4517 { 4496 {
4518 if (! error_state) 4497 octave_value new_val (val);
4498
4499 if (new_val.numel () == 2)
4519 { 4500 {
4520 octave_value new_val (val); 4501 dim_vector dv (1, 3);
4521 4502
4522 if (new_val.numel () == 2) 4503 new_val = new_val.resize (dv, true);
4523 {
4524 dim_vector dv (1, 3);
4525
4526 new_val = new_val.resize (dv, true);
4527 }
4528
4529 if (position.set (new_val, false))
4530 {
4531 set_positionmode ("manual");
4532 update_position ();
4533 position.run_listeners (POSTSET);
4534 mark_modified ();
4535 }
4536 else
4537 set_positionmode ("manual");
4538 } 4504 }
4505
4506 if (position.set (new_val, false))
4507 {
4508 set_positionmode ("manual");
4509 update_position ();
4510 position.run_listeners (POSTSET);
4511 mark_modified ();
4512 }
4513 else
4514 set_positionmode ("manual");
4539 } 4515 }
4540 4516
4541 // See the genprops.awk script for an explanation of the 4517 // See the genprops.awk script for an explanation of the
4542 // properties declarations. 4518 // properties declarations.
4543 4519
6094 6070
6095 if (go.valid_object ()) 6071 if (go.valid_object ())
6096 cb = go.get (name); 6072 cb = go.get (name);
6097 } 6073 }
6098 6074
6099 if (! error_state) 6075 execute_callback (h, cb, data);
6100 execute_callback (h, cb, data);
6101 } 6076 }
6102 6077
6103 static void execute_callback (const graphics_handle& h, 6078 static void execute_callback (const graphics_handle& h,
6104 const octave_value& cb, 6079 const octave_value& cb,
6105 const octave_value& data = Matrix ()) 6080 const octave_value& data = Matrix ())