comparison src/graphics.cc @ 8063:41bc700ff642

Trigger actions/listeners only for actual property change
author Michael Goffioul
date Tue, 26 Aug 2008 13:39:24 -0400
parents e04a4beeb283
children a028a5960e18
comparison
equal deleted inserted replaced
8062:e04a4beeb283 8063:41bc700ff642
457 return go; 457 return go;
458 } 458 }
459 459
460 // --------------------------------------------------------------------- 460 // ---------------------------------------------------------------------
461 461
462 void 462 bool
463 base_property::set (const octave_value& v, bool do_run ) 463 base_property::set (const octave_value& v, bool do_run )
464 { 464 {
465 do_set (v); 465 if (do_set (v))
466 466 {
467 // notify backend 467
468 if (id >= 0) 468 // notify backend
469 { 469 if (id >= 0)
470 graphics_object go = gh_manager::get_object (parent); 470 {
471 if (go) 471 graphics_object go = gh_manager::get_object (parent);
472 { 472 if (go)
473 graphics_backend backend = go.get_backend(); 473 {
474 if (backend) 474 graphics_backend backend = go.get_backend();
475 backend.property_changed (go, id); 475 if (backend)
476 } 476 backend.property_changed (go, id);
477 } 477 }
478 478 }
479 // run listeners 479
480 if (do_run && ! error_state) 480 // run listeners
481 run_listeners (POSTSET); 481 if (do_run && ! error_state)
482 run_listeners (POSTSET);
483
484 return true;
485 }
486
487 return false;
482 } 488 }
483 489
484 490
485 void 491 void
486 base_property::run_listeners (listener_mode mode) 492 base_property::run_listeners (listener_mode mode)
566 } 572 }
567 573
568 return retval; 574 return retval;
569 } 575 }
570 576
571 void 577 bool
572 color_property::do_set (const octave_value& val) 578 color_property::do_set (const octave_value& val)
573 { 579 {
574 if (val.is_string ()) 580 if (val.is_string ())
575 { 581 {
576 std::string s = val.string_value (); 582 std::string s = val.string_value ();
577 583
578 if (! s.empty ()) 584 if (! s.empty ())
579 { 585 {
580 if (radio_val.contains (s)) 586 if (radio_val.contains (s))
581 { 587 {
582 current_val = s; 588 if (current_type != radio_t || current_val != s)
583 current_type = radio_t; 589 {
590 current_val = s;
591 current_type = radio_t;
592 return true;
593 }
584 } 594 }
585 else 595 else
586 { 596 {
587 color_values col (s); 597 color_values col (s);
588 if (! error_state) 598 if (! error_state)
589 { 599 {
590 color_val = col; 600 if (current_type != color_t || col != color_val)
591 current_type = color_t; 601 {
602 color_val = col;
603 current_type = color_t;
604 return true;
605 }
592 } 606 }
593 else 607 else
594 error ("invalid value for color property \"%s\" (value = %s)", 608 error ("invalid value for color property \"%s\" (value = %s)",
595 get_name ().c_str (), s.c_str ()); 609 get_name ().c_str (), s.c_str ());
596 } 610 }
597 } 611 }
598 else 612 else
599 error ("invalid value for color property \"%s\"", 613 error ("invalid value for color property \"%s\"",
600 get_name ().c_str ()); 614 get_name ().c_str ());
606 if (m.numel () == 3) 620 if (m.numel () == 3)
607 { 621 {
608 color_values col (m (0), m (1), m(2)); 622 color_values col (m (0), m (1), m(2));
609 if (! error_state) 623 if (! error_state)
610 { 624 {
611 color_val = col; 625 if (current_type != color_t || col != color_val)
612 current_type = color_t; 626 {
627 color_val = col;
628 current_type = color_t;
629 return true;
630 }
613 } 631 }
614 } 632 }
615 else 633 else
616 error ("invalid value for color property \"%s\"", 634 error ("invalid value for color property \"%s\"",
617 get_name ().c_str ()); 635 get_name ().c_str ());
618 } 636 }
619 else 637 else
620 error ("invalid value for color property \"%s\"", 638 error ("invalid value for color property \"%s\"",
621 get_name ().c_str ()); 639 get_name ().c_str ());
622 } 640
623 641 return false;
624 void 642 }
643
644 bool
625 double_radio_property::do_set (const octave_value& val) 645 double_radio_property::do_set (const octave_value& val)
626 { 646 {
627 if (val.is_string ()) 647 if (val.is_string ())
628 { 648 {
629 std::string s = val.string_value (); 649 std::string s = val.string_value ();
630 650
631 if (! s.empty () && radio_val.contains (s)) 651 if (! s.empty () && radio_val.contains (s))
632 { 652 {
633 current_val = s; 653 if (current_type != radio_t || s != current_val)
634 current_type = radio_t; 654 {
655 current_val = s;
656 current_type = radio_t;
657 return true;
658 }
635 } 659 }
636 else 660 else
637 error ("invalid value for double_radio property \"%s\"", 661 error ("invalid value for double_radio property \"%s\"",
638 get_name ().c_str ()); 662 get_name ().c_str ());
639 } 663 }
640 else if (val.is_scalar_type () && val.is_real_type ()) 664 else if (val.is_scalar_type () && val.is_real_type ())
641 { 665 {
642 dval = val.double_value (); 666 double new_dval = val.double_value ();
643 current_type = double_t; 667
668 if (current_type != double_t || new_dval != dval)
669 {
670 dval = new_dval;
671 current_type = double_t;
672 return true;
673 }
644 } 674 }
645 else 675 else
646 error ("invalid value for double_radio property \"%s\"", 676 error ("invalid value for double_radio property \"%s\"",
647 get_name ().c_str ()); 677 get_name ().c_str ());
678
679 return false;
648 } 680 }
649 681
650 bool 682 bool
651 array_property::validate (const octave_value& v) 683 array_property::validate (const octave_value& v)
652 { 684 {
693 else 725 else
694 return true; 726 return true;
695 } 727 }
696 728
697 return xok; 729 return xok;
730 }
731
732 bool
733 array_property::is_equal (const octave_value& v) const
734 {
735 if (data.type_name () == v.type_name ())
736 {
737 if (data.dims () == v.dims ())
738 {
739 #define CHECK_ARRAY_EQUAL(T,F) \
740 { \
741 const T* d1 = data.F ().data (); \
742 const T* d2 = v.F ().data (); \
743 \
744 bool flag = true; \
745 \
746 for (int i = 0; flag && i < data.numel (); i++) \
747 if (d1[i] != d2[i]) \
748 flag = false; \
749 \
750 return flag; \
751 }
752
753 if (data.is_double_type())
754 CHECK_ARRAY_EQUAL (double, array_value)
755 else if (data.is_single_type ())
756 CHECK_ARRAY_EQUAL (float, float_array_value)
757 else if (data.is_int8_type ())
758 CHECK_ARRAY_EQUAL (octave_int8, int8_array_value)
759 else if (data.is_int16_type ())
760 CHECK_ARRAY_EQUAL (octave_int16, int16_array_value)
761 else if (data.is_int32_type ())
762 CHECK_ARRAY_EQUAL (octave_int32, int32_array_value)
763 else if (data.is_int64_type ())
764 CHECK_ARRAY_EQUAL (octave_int64, int64_array_value)
765 else if (data.is_uint8_type ())
766 CHECK_ARRAY_EQUAL (octave_uint8, uint8_array_value)
767 else if (data.is_uint16_type ())
768 CHECK_ARRAY_EQUAL (octave_uint16, uint16_array_value)
769 else if (data.is_uint32_type ())
770 CHECK_ARRAY_EQUAL (octave_uint32, uint32_array_value)
771 else if (data.is_uint64_type ())
772 CHECK_ARRAY_EQUAL (octave_uint64, uint64_array_value)
773 }
774 }
775
776 return false;
698 } 777 }
699 778
700 void 779 void
701 array_property::get_data_limits (void) 780 array_property::get_data_limits (void)
702 { 781 {
727 else 806 else
728 get_array_limits (data.array_value (), xmin, xmax, xminp); 807 get_array_limits (data.array_value (), xmin, xmax, xminp);
729 } 808 }
730 } 809 }
731 810
732 void 811 bool
733 handle_property::do_set (const octave_value& v) 812 handle_property::do_set (const octave_value& v)
734 { 813 {
735 double dv = v.double_value (); 814 double dv = v.double_value ();
736 815
737 if (! error_state) 816 if (! error_state)
738 { 817 {
739 graphics_handle gh = gh_manager::lookup (dv); 818 graphics_handle gh = gh_manager::lookup (dv);
740 819
741 if (xisnan (gh.value ()) || gh.ok ()) 820 if (xisnan (gh.value ()) || gh.ok ())
742 current_val = gh; 821 {
822 if (current_val != gh)
823 {
824 current_val = gh;
825 return true;
826 }
827 }
743 else 828 else
744 error ("set: invalid graphics handle (= %g) for property \"%s\"", 829 error ("set: invalid graphics handle (= %g) for property \"%s\"",
745 dv, get_name ().c_str ()); 830 dv, get_name ().c_str ());
746 } 831 }
747 else 832 else
748 error ("set: invalid graphics handle for property \"%s\"", 833 error ("set: invalid graphics handle for property \"%s\"",
749 get_name ().c_str ()); 834 get_name ().c_str ());
835
836 return false;
750 } 837 }
751 838
752 bool 839 bool
753 callback_property::validate (const octave_value& v) const 840 callback_property::validate (const octave_value& v) const
754 { 841 {