Material Definition Language API nvidia_logo_transpbg.gif Up
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
argument_editor.h
Go to the documentation of this file.
1 /***************************************************************************************************
2  * Copyright 2018 NVIDIA Corporation. All rights reserved.
3  **************************************************************************************************/
6 
7 #ifndef MI_NEURAYLIB_ARGUMENT_EDITOR_H
8 #define MI_NEURAYLIB_ARGUMENT_EDITOR_H
9 
10 #include <mi/base/handle.h>
11 #include <mi/neuraylib/assert.h>
18 #include <mi/neuraylib/itype.h>
19 #include <mi/neuraylib/ivalue.h>
20 
21 #include <string>
22 
23 namespace mi {
24 
25 namespace neuraylib {
26 
31 class Argument_editor
51 {
52 public:
53 
55 
56 
63  Argument_editor( ITransaction* transaction, const char* name, IMdl_factory* mdl_factory);
64 
70  bool is_valid() const;
71 
77  Element_type get_type() const;
78 
80  const char* get_definition() const;
81 
83  const char* get_mdl_definition() const;
84 
89  bool is_array_constructor() const;
90 
94  const IType* get_return_type() const;
95 
97  Size get_parameter_count() const;
98 
103  const char* get_parameter_name( Size index) const;
104 
109  Size get_parameter_index( const char* name) const;
110 
112  const IType_list* get_parameter_types() const;
113 
120  bool is_parameter_enabled( Size index, IMdl_evaluator_api* evaluator) const;
121 
123  const IExpression_list* get_arguments() const;
124 
130  IExpression::Kind get_argument_kind( Size parameter_index) const;
131 
137  IExpression::Kind get_argument_kind( const char* parameter_name) const;
138 
140 
142 
156  template<class T>
157  Sint32 get_value( Size parameter_index, T& value) const;
158 
169  template <class T>
170  Sint32 get_value( const char* parameter_name, T& value) const;
171 
187  template<class T>
188  Sint32 get_value( Size parameter_index, Size component_index, T& value) const;
189 
202  template <class T>
203  Sint32 get_value( const char* parameter_name, Size component_index, T& value) const;
204 
220  template<class T>
221  Sint32 get_value( Size parameter_index, const char* field_name, T& value) const;
222 
235  template <class T>
236  Sint32 get_value( const char* parameter_name, const char* field_name, T& value) const;
237 
252  template<class T>
253  Sint32 set_value( Size parameter_index, const T& value);
254 
266  template <class T>
267  Sint32 set_value( const char* parameter_name, const T& value);
268 
288  template<class T>
289  Sint32 set_value( Size parameter_index, Size component_index, const T& value);
290 
307  template <class T>
308  Sint32 set_value( const char* parameter_name, Size component_index, const T& value);
309 
326  template<class T>
327  Sint32 set_value( Size parameter_index, const char* field_name, const T& value);
328 
342  template <class T>
343  Sint32 set_value( const char* parameter_name, const char* field_name, const T& value);
344 
358  Sint32 get_array_length( Uint32 parameter_index, Size& size) const;
359 
370  Sint32 get_array_length( const char* parameter_name, Size& size) const;
371 
386  Sint32 set_array_size( Uint32 parameter_index, Size size);
387 
399  Sint32 set_array_size( const char* parameter_name, Size size);
400 
402 
404 
413  const char* get_call( Size parameter_index) const;
414 
420  const char* get_call( const char* parameter_name) const;
421 
439  Sint32 set_call( Size parameter_index, const char* call_name);
440 
455  Sint32 set_call( const char* parameter_name, const char* call_name);
456 
458 
460 
462  ITransaction* get_transaction() const;
463 
465  IMdl_factory* get_mdl_factory() const;
466 
468  IValue_factory* get_value_factory() const;
469 
471  IExpression_factory* get_expression_factory() const;
472 
474  const IScene_element* get_scene_element() const;
475 
477  IScene_element* get_scene_element();
478 
481 
483  const std::string& get_name() const;
484 
486 
487 private:
488  void promote_to_edit_if_needed();
489 
490  base::Handle<ITransaction> m_transaction;
491  base::Handle<IMdl_factory> m_mdl_factory;
492  base::Handle<IValue_factory> m_value_factory;
493  base::Handle<IExpression_factory> m_expression_factory;
494  base::Handle<const IScene_element> m_access;
495  base::Handle<const IScene_element> m_old_access;
496  base::Handle<IScene_element> m_edit;
497  Element_type m_type;
498  std::string m_name;
499 };
500  // end group mi_neuray_mdl_elements
502 
504  ITransaction* transaction, const char* name, IMdl_factory* mdl_factory)
505 {
506  mi_neuray_assert( transaction);
507  mi_neuray_assert( name);
508 
509  m_transaction = make_handle_dup( transaction);
510  m_name = name;
511  m_mdl_factory = make_handle_dup( mdl_factory);
512  m_value_factory
513  = m_mdl_factory ? m_mdl_factory->create_value_factory( m_transaction.get()) : 0;
514  m_expression_factory
515  = m_mdl_factory ? m_mdl_factory->create_expression_factory( m_transaction.get()) : 0;
516  m_access = transaction->access<IScene_element>( name);
517  m_type = m_access ? m_access->get_element_type() : static_cast<Element_type>( 0);
518 }
519 
520 inline bool Argument_editor::is_valid() const
521 {
522  return m_access
524 }
525 
527 {
528  return m_type;
529 }
530 
531 inline const char* Argument_editor::get_definition() const
532 {
533  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
534 
535  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
536  return mi->get_material_definition();
537 
538  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
539 
540  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
541  return fc->get_function_definition();
542 
543  } else
544  return 0;
545 }
546 
547 inline const char* Argument_editor::get_mdl_definition() const
548 {
549  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
550 
551  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
552  return mi->get_mdl_material_definition();
553 
554  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
555 
556  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
557  return fc->get_mdl_function_definition();
558 
559  } else
560  return 0;
561 }
562 
564 {
565  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
566 
567  return false;
568 
569  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
570 
571  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
572  return fc->is_array_constructor();
573 
574  } else
575  return false;
576 }
577 
579 {
580  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
581 
582  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
583  return mi->get_parameter_count();
584 
585  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
586 
587  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
588  return fc->get_parameter_count();
589 
590  } else
591  return 0;
592 }
593 
594 inline const char* Argument_editor::get_parameter_name( Size parameter_index) const
595 {
596  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
597 
598  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
599  return mi->get_parameter_name( parameter_index);
600 
601  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
602 
603  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
604  return fc->get_parameter_name( parameter_index);
605 
606  } else
607  return 0;
608 }
609 
610 inline Size Argument_editor::get_parameter_index( const char* name) const
611 {
612  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
613 
614  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
615  return mi->get_parameter_index( name);
616 
617  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
618 
619  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
620  return fc->get_parameter_index( name);
621 
622  } else
623  return 0;
624 }
625 
627 {
628  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
629 
630  return 0;
631 
632  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
633 
634  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
635  return fc->get_return_type();
636 
637  } else
638  return 0;
639 }
640 
642 {
643  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
644 
645  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
646  return mi->get_parameter_types();
647 
648  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
649 
650  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
651  return fc->get_parameter_types();
652 
653  } else
654  return 0;
655 }
656 
657 inline bool Argument_editor::is_parameter_enabled( Size index, IMdl_evaluator_api* evaluator) const
658 {
659  if( !evaluator)
660  return true;
661 
662  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
663 
664  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
666  m_transaction.get(), m_value_factory.get(), mi.get(), index, /*error*/ NULL));
667  if (!b)
668  return true;
669  return b->get_value();
670 
671  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
672 
673  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
675  m_transaction.get(), m_value_factory.get(), fc.get(), index, /*error*/ NULL));
676  if (!b)
677  return true;
678  return b->get_value();
679 
680  } else
681  return true;
682 }
683 
684 
686 {
687  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
688 
689  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
690  return mi->get_arguments();
691 
692  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
693 
694  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
695  return fc->get_arguments();
696 
697  } else
698  return 0;
699 }
700 
702 {
703  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
704 
705  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
706  base::Handle<const IExpression_list> arguments( mi->get_arguments());
707  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
708  return argument ? argument->get_kind() : static_cast<IExpression::Kind>( 0);
709 
710  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
711 
712  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
713  base::Handle<const IExpression_list> arguments( fc->get_arguments());
714  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
715  return argument ? argument->get_kind() : static_cast<IExpression::Kind>( 0);
716 
717  } else
718  return static_cast<IExpression::Kind>( 0);
719 }
720 
721 inline IExpression::Kind Argument_editor::get_argument_kind( const char* parameter_name) const
722 {
723  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
724 
725  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
726  base::Handle<const IExpression_list> arguments( mi->get_arguments());
727  base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
728  return argument ? argument->get_kind() : static_cast<IExpression::Kind>( 0);
729 
730  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
731 
732  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
733  base::Handle<const IExpression_list> arguments( fc->get_arguments());
734  base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
735  return argument ? argument->get_kind() : static_cast<IExpression::Kind>( 0);
736 
737  } else
738  return static_cast<IExpression::Kind>( 0);
739 }
740 
741 template <class T>
742 Sint32 Argument_editor::get_value( Size parameter_index, T& value) const
743 {
744  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
745 
746  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
747  base::Handle<const IExpression_list> arguments( mi->get_arguments());
748  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
749  if( !argument)
750  return -2;
752  argument->get_interface<IExpression_constant>());
753  if( !argument_constant)
754  return -4;
755  base::Handle<const IValue> argument_value( argument_constant->get_value());
756  Sint32 result = neuraylib::get_value( argument_value.get(), value);
757  return result == 0 ? 0 : -5;
758 
759  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
760 
761  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
762  base::Handle<const IExpression_list> arguments( fc->get_arguments());
763  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
764  if( !argument)
765  return -2;
767  argument->get_interface<IExpression_constant>());
768  if( !argument_constant)
769  return -4;
770  base::Handle<const IValue> argument_value( argument_constant->get_value());
771  Sint32 result = neuraylib::get_value( argument_value.get(), value);
772  return result == 0 ? 0 : -5;
773 
774  } else
775  return -1;
776 }
777 
778 template <class T>
779 Sint32 Argument_editor::get_value( const char* name, T& value) const
780 {
781  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
782 
783  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
784  base::Handle<const IExpression_list> arguments( mi->get_arguments());
785  base::Handle<const IExpression> argument_( arguments->get_expression( name));
786  if( !argument_)
787  return -2;
789  argument_->get_interface<IExpression_constant>());
790  if( !argument_constant)
791  return -4;
792  base::Handle<const IValue> argument_value( argument_constant->get_value());
793  Sint32 result = neuraylib::get_value( argument_value.get(), value);
794  return result == 0 ? 0 : -5;
795 
796  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
797 
799  m_access->get_interface<IFunction_call>());
800  base::Handle<const IExpression_list> arguments( fc->get_arguments());
801  base::Handle<const IExpression> argument_( arguments->get_expression( name));
802  if( !argument_)
803  return -2;
805  argument_->get_interface<IExpression_constant>());
806  if( !argument_constant)
807  return -4;
808  base::Handle<const IValue> argument_value( argument_constant->get_value());
809  Sint32 result = neuraylib::get_value( argument_value.get(), value);
810  return result == 0 ? 0 : -5;
811 
812  } else
813  return -1;
814 }
815 
816 template <class T>
817 Sint32 Argument_editor::get_value( Size parameter_index, Size component_index, T& value) const
818 {
819  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
820 
821  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
822  base::Handle<const IExpression_list> arguments( mi->get_arguments());
823  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
824  if( !argument)
825  return -2;
827  argument->get_interface<IExpression_constant>());
828  if( !argument_constant)
829  return -4;
830  base::Handle<const IValue> argument_value( argument_constant->get_value());
831  Sint32 result = neuraylib::get_value( argument_value.get(), component_index, value);
832  return result == 0 ? 0 : (result == -3 ? -3 : -5);
833 
834  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
835 
836  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
837  base::Handle<const IExpression_list> arguments( fc->get_arguments());
838  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
839  if( !argument)
840  return -2;
842  argument->get_interface<IExpression_constant>());
843  if( !argument_constant)
844  return -4;
845  base::Handle<const IValue> argument_value( argument_constant->get_value());
846  Sint32 result = neuraylib::get_value( argument_value.get(), component_index, value);
847  return result == 0 ? 0 : (result == -3 ? -3 : -5);
848 
849  } else
850  return -1;
851 }
852 
853 template <class T>
854 Sint32 Argument_editor::get_value( const char* parameter_name, Size component_index, T& value) const
855 {
856  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
857 
858  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
859  base::Handle<const IExpression_list> arguments( mi->get_arguments());
860  base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
861  if( !argument)
862  return -2;
864  argument->get_interface<IExpression_constant>());
865  if( !argument_constant)
866  return -4;
867  base::Handle<const IValue> argument_value( argument_constant->get_value());
868  Sint32 result = neuraylib::get_value( argument_value.get(), component_index, value);
869  return result == 0 ? 0 : (result == -3 ? -3 : -5);
870 
871  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
872 
873  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
874  base::Handle<const IExpression_list> arguments( fc->get_arguments());
875  base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
876  if( !argument)
877  return -2;
879  argument->get_interface<IExpression_constant>());
880  if( !argument_constant)
881  return -4;
882  base::Handle<const IValue> argument_value( argument_constant->get_value());
883  Sint32 result = neuraylib::get_value( argument_value.get(), component_index, value);
884  return result == 0 ? 0 : (result == -3 ? -3 : -5);
885 
886  } else
887  return -1;
888 }
889 
890 template <class T>
892  Size parameter_index, const char* field_name, T& value) const
893 {
894  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
895 
896  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
897  base::Handle<const IExpression_list> arguments( mi->get_arguments());
898  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
899  if( !argument)
900  return -2;
902  argument->get_interface<IExpression_constant>());
903  if( !argument_constant)
904  return -4;
905  base::Handle<const IValue> argument_value( argument_constant->get_value());
906  Sint32 result = neuraylib::get_value( argument_value.get(), field_name, value);
907  return result == 0 ? 0 : (result == -3 ? -3 : -5);
908 
909  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
910 
911  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
912  base::Handle<const IExpression_list> arguments( fc->get_arguments());
913  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
914  if( !argument)
915  return -2;
917  argument->get_interface<IExpression_constant>());
918  if( !argument_constant)
919  return -4;
920  base::Handle<const IValue> argument_value( argument_constant->get_value());
921  Sint32 result = neuraylib::get_value( argument_value.get(), field_name, value);
922  return result == 0 ? 0 : (result == -3 ? -3 : -5);
923 
924  } else
925  return -1;
926 }
927 
928 template <class T>
930  const char* parameter_name, const char* field_name, T& value) const
931 {
932  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
933 
934  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
935  base::Handle<const IExpression_list> arguments( mi->get_arguments());
936  base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
937  if( !argument)
938  return -2;
940  argument->get_interface<IExpression_constant>());
941  if( !argument_constant)
942  return -4;
943  base::Handle<const IValue> argument_value( argument_constant->get_value());
944  Sint32 result = neuraylib::get_value( argument_value.get(), field_name, value);
945  return result == 0 ? 0 : (result == -3 ? -3 : -5);
946 
947  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
948 
949  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
950  base::Handle<const IExpression_list> arguments( fc->get_arguments());
951  base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
952  if( !argument)
953  return -2;
955  argument->get_interface<IExpression_constant>());
956  if( !argument_constant)
957  return -4;
958  base::Handle<const IValue> argument_value( argument_constant->get_value());
959  Sint32 result = neuraylib::get_value( argument_value.get(), field_name, value);
960  return result == 0 ? 0 : (result == -3 ? -3 : -5);
961 
962  } else
963  return -1;
964 }
965 
966 template <class T>
967 Sint32 Argument_editor::set_value( Size parameter_index, const T& value)
968 {
969  promote_to_edit_if_needed();
970 
971  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
972 
973  base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
974  base::Handle<const IExpression_list> arguments( mi->get_arguments());
975  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
976  if( !argument)
977  return -2;
978  base::Handle<const IType> type( argument->get_type());
979  base::Handle<IValue> new_value( m_value_factory->create( type.get()));
980  Sint32 result = neuraylib::set_value( new_value.get(), value);
981  if( result != 0)
982  return -5;
983  base::Handle<IExpression> new_expression(
984  m_expression_factory->create_constant( new_value.get()));
985  result = mi->set_argument( parameter_index, new_expression.get());
986  mi_neuray_assert( result == 0);
987  return 0;
988 
989  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
990 
991  base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
992  base::Handle<const IExpression_list> arguments( fc->get_arguments());
993  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
994  if( !argument)
995  return -2;
996  base::Handle<const IType> type( argument->get_type());
997  base::Handle<IValue> new_value( m_value_factory->create( type.get()));
998  Sint32 result = neuraylib::set_value( new_value.get(), value);
999  if( result != 0)
1000  return -5;
1001  base::Handle<IExpression> new_expression(
1002  m_expression_factory->create_constant( new_value.get()));
1003  result = fc->set_argument( parameter_index, new_expression.get());
1004  mi_neuray_assert( result == 0);
1005  return 0;
1006 
1007  } else
1008  return -1;
1009 }
1010 
1011 template <class T>
1012 Sint32 Argument_editor::set_value( const char* parameter_name, const T& value)
1013 {
1014  promote_to_edit_if_needed();
1015 
1016  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1017 
1018  base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1019  base::Handle<const IExpression_list> arguments( mi->get_arguments());
1020  base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1021  if( !argument)
1022  return -2;
1023  base::Handle<const IType> type( argument->get_type());
1024  base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1025  Sint32 result = neuraylib::set_value( new_value.get(), value);
1026  if( result != 0)
1027  return -5;
1028  base::Handle<IExpression> new_expression(
1029  m_expression_factory->create_constant( new_value.get()));
1030  result = mi->set_argument( parameter_name, new_expression.get());
1031  mi_neuray_assert( result == 0);
1032  return 0;
1033 
1034  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1035 
1036  base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1037  base::Handle<const IExpression_list> arguments( fc->get_arguments());
1038  base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1039  if( !argument)
1040  return -2;
1041  base::Handle<const IType> type( argument->get_type());
1042  base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1043  Sint32 result = neuraylib::set_value( new_value.get(), value);
1044  if( result != 0)
1045  return -5;
1046  base::Handle<IExpression> new_expression(
1047  m_expression_factory->create_constant( new_value.get()));
1048  result = fc->set_argument( parameter_name, new_expression.get());
1049  mi_neuray_assert( result == 0);
1050  return 0;
1051 
1052  } else
1053  return -1;
1054 }
1055 
1056 template <class T>
1057 Sint32 Argument_editor::set_value( Size parameter_index, Size component_index, const T& value)
1058 {
1059  promote_to_edit_if_needed();
1060 
1061  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1062 
1063  base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1064  base::Handle<const IExpression_list> arguments( mi->get_arguments());
1065  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1066  if( !argument)
1067  return -2;
1068  if( argument->get_kind() == IExpression::EK_CONSTANT) {
1069  // reuse existing constant expression
1070  base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1071  base::Handle<IExpression_constant> new_argument_constant(
1072  new_argument->get_interface<IExpression_constant>());
1073  base::Handle<IValue> new_value( new_argument_constant->get_value());
1074  Sint32 result = neuraylib::set_value( new_value.get(), component_index, value);
1075  if( result != 0)
1076  return result == -3 ? -3 : -5;
1077  result = mi->set_argument( parameter_index, new_argument.get());
1078  mi_neuray_assert( result == 0);
1079  return 0;
1080  } else {
1081  // create new constant expression
1082  base::Handle<const IType> type( argument->get_type());
1083  base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1084  Sint32 result = neuraylib::set_value( new_value.get(), component_index, value);
1085  if( result != 0)
1086  return result == -3 ? -3 : -5;
1087  base::Handle<IExpression> new_expression(
1088  m_expression_factory->create_constant( new_value.get()));
1089  result = mi->set_argument( parameter_index, new_expression.get());
1090  mi_neuray_assert( result == 0);
1091  return 0;
1092  }
1093 
1094  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1095 
1096  base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1097  base::Handle<const IExpression_list> arguments( fc->get_arguments());
1098  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1099  if( !argument)
1100  return -2;
1101  if( argument->get_kind() == IExpression::EK_CONSTANT) {
1102  // reuse existing constant expression
1103  base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1104  base::Handle<IExpression_constant> new_argument_constant(
1105  new_argument->get_interface<IExpression_constant>());
1106  base::Handle<IValue> new_value( new_argument_constant->get_value());
1107  Sint32 result = neuraylib::set_value( new_value.get(), component_index, value);
1108  if( result != 0)
1109  return result == -3 ? -3 : -5;
1110  result = fc->set_argument( parameter_index, new_argument.get());
1111  mi_neuray_assert( result == 0);
1112  return 0;
1113  } else {
1114  // create new constant expression
1115  base::Handle<const IType> type( argument->get_type());
1116  base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1117  Sint32 result = neuraylib::set_value( new_value.get(), component_index, value);
1118  if( result != 0)
1119  return result == -3 ? -3 : -5;
1120  base::Handle<IExpression> new_expression(
1121  m_expression_factory->create_constant( new_value.get()));
1122  result = fc->set_argument( parameter_index, new_expression.get());
1123  mi_neuray_assert( result == 0);
1124  return 0;
1125  }
1126 
1127  } else
1128  return -1;
1129 }
1130 
1131 template <class T>
1132 Sint32 Argument_editor::set_value( const char* parameter_name, Size component_index, const T& value)
1133 {
1134  promote_to_edit_if_needed();
1135 
1136  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1137 
1138  base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1139  base::Handle<const IExpression_list> arguments( mi->get_arguments());
1140  base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1141  if( !argument)
1142  return -2;
1143  if( argument->get_kind() == IExpression::EK_CONSTANT) {
1144  // reuse existing constant expression
1145  base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1146  base::Handle<IExpression_constant> new_argument_constant(
1147  new_argument->get_interface<IExpression_constant>());
1148  base::Handle<IValue> new_value( new_argument_constant->get_value());
1149  Sint32 result = neuraylib::set_value( new_value.get(), component_index, value);
1150  if( result != 0)
1151  return result == -3 ? -3 : -5;
1152  result = mi->set_argument( parameter_name, new_argument.get());
1153  mi_neuray_assert( result == 0);
1154  return 0;
1155  } else {
1156  // create new constant expression
1157  base::Handle<const IType> type( argument->get_type());
1158  base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1159  Sint32 result = neuraylib::set_value( new_value.get(), component_index, value);
1160  if( result != 0)
1161  return result == -3 ? -3 : -5;
1162  base::Handle<IExpression> new_expression(
1163  m_expression_factory->create_constant( new_value.get()));
1164  result = mi->set_argument( parameter_name, new_expression.get());
1165  mi_neuray_assert( result == 0);
1166  return 0;
1167  }
1168 
1169  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1170 
1171  base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1172  base::Handle<const IExpression_list> arguments( fc->get_arguments());
1173  base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1174  if( !argument)
1175  return -2;
1176  if( argument->get_kind() == IExpression::EK_CONSTANT) {
1177  // reuse existing constant expression
1178  base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1179  base::Handle<IExpression_constant> new_argument_constant(
1180  new_argument->get_interface<IExpression_constant>());
1181  base::Handle<IValue> new_value( new_argument_constant->get_value());
1182  Sint32 result = neuraylib::set_value( new_value.get(), component_index, value);
1183  if( result != 0)
1184  return result == -3 ? -3 : -5;
1185  result = fc->set_argument( parameter_name, new_argument.get());
1186  mi_neuray_assert( result == 0);
1187  return 0;
1188  } else {
1189  // create new constant expression
1190  base::Handle<const IType> type( argument->get_type());
1191  base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1192  Sint32 result = neuraylib::set_value( new_value.get(), component_index, value);
1193  if( result != 0)
1194  return result == -3 ? -3 : -5;
1195  base::Handle<IExpression> new_expression(
1196  m_expression_factory->create_constant( new_value.get()));
1197  result = fc->set_argument( parameter_name, new_expression.get());
1198  mi_neuray_assert( result == 0);
1199  return 0;
1200  }
1201 
1202  } else
1203  return -1;
1204 }
1205 
1206 template <class T>
1208  Size parameter_index, const char* field_name, const T& value)
1209 {
1210  promote_to_edit_if_needed();
1211 
1212  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1213 
1214  base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1215  base::Handle<const IExpression_list> arguments( mi->get_arguments());
1216  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1217  if( !argument)
1218  return -2;
1219  if( argument->get_kind() == IExpression::EK_CONSTANT) {
1220  // reuse existing constant expression
1221  base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1222  base::Handle<IExpression_constant> new_argument_constant(
1223  new_argument->get_interface<IExpression_constant>());
1224  base::Handle<IValue> new_value( new_argument_constant->get_value());
1225  Sint32 result = neuraylib::set_value( new_value.get(), field_name, value);
1226  if( result != 0)
1227  return result == -3 ? -3 : -5;
1228  result = mi->set_argument( parameter_index, new_argument.get());
1229  mi_neuray_assert( result == 0);
1230  return 0;
1231  } else {
1232  // create new constant expression
1233  base::Handle<const IType> type( argument->get_type());
1234  base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1235  Sint32 result = neuraylib::set_value( new_value.get(), field_name, value);
1236  if( result != 0)
1237  return result == -3 ? -3 : -5;
1238  base::Handle<IExpression> new_expression(
1239  m_expression_factory->create_constant( new_value.get()));
1240  result = mi->set_argument( parameter_index, new_expression.get());
1241  mi_neuray_assert( result == 0);
1242  return 0;
1243  }
1244 
1245  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1246 
1247  base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1248  base::Handle<const IExpression_list> arguments( fc->get_arguments());
1249  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1250  if( !argument)
1251  return -2;
1252  if( argument->get_kind() == IExpression::EK_CONSTANT) {
1253  // reuse existing constant expression
1254  base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1255  base::Handle<IExpression_constant> new_argument_constant(
1256  new_argument->get_interface<IExpression_constant>());
1257  base::Handle<IValue> new_value( new_argument_constant->get_value());
1258  Sint32 result = neuraylib::set_value( new_value.get(), field_name, value);
1259  if( result != 0)
1260  return result == -3 ? -3 : -5;
1261  result = fc->set_argument( parameter_index, new_argument.get());
1262  mi_neuray_assert( result == 0);
1263  return 0;
1264  } else {
1265  // create new constant expression
1266  base::Handle<const IType> type( argument->get_type());
1267  base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1268  Sint32 result = neuraylib::set_value( new_value.get(), field_name, value);
1269  if( result != 0)
1270  return result == -3 ? -3 : -5;
1271  base::Handle<IExpression> new_expression(
1272  m_expression_factory->create_constant( new_value.get()));
1273  result = fc->set_argument( parameter_index, new_expression.get());
1274  mi_neuray_assert( result == 0);
1275  return 0;
1276  }
1277 
1278  } else
1279  return -1;
1280 }
1281 
1282 template <class T>
1284  const char* parameter_name, const char* field_name, const T& value)
1285 {
1286  promote_to_edit_if_needed();
1287 
1288  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1289 
1290  base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1291  base::Handle<const IExpression_list> arguments( mi->get_arguments());
1292  base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1293  if( !argument)
1294  return -2;
1295  if( argument->get_kind() == IExpression::EK_CONSTANT) {
1296  // reuse existing constant expression
1297  base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1298  base::Handle<IExpression_constant> new_argument_constant(
1299  new_argument->get_interface<IExpression_constant>());
1300  base::Handle<IValue> new_value( new_argument_constant->get_value());
1301  Sint32 result = neuraylib::set_value( new_value.get(), field_name, value);
1302  if( result != 0)
1303  return result == -3 ? -3 : -5;
1304  result = mi->set_argument( parameter_name, new_argument.get());
1305  mi_neuray_assert( result == 0);
1306  return 0;
1307  } else {
1308  // create new constant expression
1309  base::Handle<const IType> type( argument->get_type());
1310  base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1311  Sint32 result = neuraylib::set_value( new_value.get(), field_name, value);
1312  if( result != 0)
1313  return result == -3 ? -3 : -5;
1314  base::Handle<IExpression> new_expression(
1315  m_expression_factory->create_constant( new_value.get()));
1316  result = mi->set_argument( parameter_name, new_expression.get());
1317  mi_neuray_assert( result == 0);
1318  return 0;
1319  }
1320 
1321  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1322 
1323  base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1324  base::Handle<const IExpression_list> arguments( fc->get_arguments());
1325  base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1326  if( !argument)
1327  return -2;
1328  if( argument->get_kind() == IExpression::EK_CONSTANT) {
1329  // reuse existing constant expression
1330  base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1331  base::Handle<IExpression_constant> new_argument_constant(
1332  new_argument->get_interface<IExpression_constant>());
1333  base::Handle<IValue> new_value( new_argument_constant->get_value());
1334  Sint32 result = neuraylib::set_value( new_value.get(), field_name, value);
1335  if( result != 0)
1336  return result == -3 ? -3 : -5;
1337  result = fc->set_argument( parameter_name, new_argument.get());
1338  mi_neuray_assert( result == 0);
1339  return 0;
1340  } else {
1341  // create new constant expression
1342  base::Handle<const IType> type( argument->get_type());
1343  base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1344  Sint32 result = neuraylib::set_value( new_value.get(), field_name, value);
1345  if( result != 0)
1346  return result == -3 ? -3 : -5;
1347  base::Handle<IExpression> new_expression(
1348  m_expression_factory->create_constant( new_value.get()));
1349  result = fc->set_argument( parameter_name, new_expression.get());
1350  mi_neuray_assert( result == 0);
1351  return 0;
1352  }
1353 
1354  } else
1355  return -1;
1356 }
1357 
1358 inline Sint32 Argument_editor::get_array_length( Uint32 parameter_index, Size& size) const
1359 {
1360  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1361 
1362  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
1363  base::Handle<const IExpression_list> arguments( mi->get_arguments());
1364  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1365  if( !argument)
1366  return -2;
1367  base::Handle<const IExpression_constant> argument_constant(
1368  argument->get_interface<IExpression_constant>());
1369  if( !argument_constant)
1370  return -4;
1371  base::Handle<const IValue_array> value( argument_constant->get_value<IValue_array>());
1372  if( !value)
1373  return -5;
1374  size = value->get_size();
1375  return 0;
1376 
1377  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1378 
1379  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
1380  base::Handle<const IExpression_list> arguments( fc->get_arguments());
1381  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1382  if( !argument)
1383  return -2;
1384  base::Handle<const IExpression_constant> argument_constant(
1385  argument->get_interface<IExpression_constant>());
1386  if( !argument_constant)
1387  return -4;
1388  base::Handle<const IValue_array> value( argument_constant->get_value<IValue_array>());
1389  if( !value)
1390  return -5;
1391  size = value->get_size();
1392  return 0;
1393 
1394  } else
1395  return -1;
1396 }
1397 
1398 inline Sint32 Argument_editor::get_array_length( const char* parameter_name, Size& size) const
1399 {
1400  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1401 
1402  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
1403  base::Handle<const IExpression_list> arguments( mi->get_arguments());
1404  base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1405  if( !argument)
1406  return -2;
1407  base::Handle<const IExpression_constant> argument_constant(
1408  argument->get_interface<IExpression_constant>());
1409  if( !argument_constant)
1410  return -4;
1411  base::Handle<const IValue_array> value( argument_constant->get_value<IValue_array>());
1412  if( !value)
1413  return -5;
1414  size = value->get_size();
1415  return 0;
1416 
1417  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1418 
1419  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
1420  base::Handle<const IExpression_list> arguments( fc->get_arguments());
1421  base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1422  if( !argument)
1423  return -2;
1424  base::Handle<const IExpression_constant> argument_constant(
1425  argument->get_interface<IExpression_constant>());
1426  if( !argument_constant)
1427  return -4;
1428  base::Handle<const IValue_array> value( argument_constant->get_value<IValue_array>());
1429  if( !value)
1430  return -5;
1431  size = value->get_size();
1432  return 0;
1433 
1434  } else
1435  return -1;
1436 }
1437 
1438 inline Sint32 Argument_editor::set_array_size( Uint32 parameter_index, Size size)
1439 {
1440  promote_to_edit_if_needed();
1441 
1442  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1443 
1444  base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1445  base::Handle<const IExpression_list> arguments( mi->get_arguments());
1446  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1447  if( !argument)
1448  return -2;
1449  if( argument->get_kind() == IExpression::EK_CONSTANT) {
1450  // reuse existing constant expression
1451  base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1452  base::Handle<IExpression_constant> new_argument_constant(
1453  new_argument->get_interface<IExpression_constant>());
1454  base::Handle<IValue_array> new_value(
1455  new_argument_constant->get_value<IValue_array>());
1456  if( !new_value)
1457  return -5;
1458  Sint32 result = new_value->set_size( size);
1459  if( result != 0)
1460  return -5;
1461  result = mi->set_argument( parameter_index, new_argument.get());
1462  mi_neuray_assert( result == 0);
1463  return 0;
1464  } else {
1465  // create new constant expression
1466  base::Handle<const IType> type( argument->get_type());
1467  base::Handle<IValue_array> new_value(
1468  m_value_factory->create<IValue_array>( type.get()));
1469  if( !new_value)
1470  return -5;
1471  Sint32 result = new_value->set_size( size);
1472  if( result != 0)
1473  return -5;
1474  base::Handle<IExpression> new_expression(
1475  m_expression_factory->create_constant( new_value.get()));
1476  result = mi->set_argument( parameter_index, new_expression.get());
1477  mi_neuray_assert( result == 0);
1478  return 0;
1479  }
1480 
1481  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1482 
1483  base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1484  base::Handle<const IExpression_list> arguments( fc->get_arguments());
1485  base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1486  if( !argument)
1487  return -2;
1488  if( argument->get_kind() == IExpression::EK_CONSTANT) {
1489  // reuse existing constant expression
1490  base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1491  base::Handle<IExpression_constant> new_argument_constant(
1492  new_argument->get_interface<IExpression_constant>());
1493  base::Handle<IValue_array> new_value(
1494  new_argument_constant->get_value<IValue_array>());
1495  if( !new_value)
1496  return -5;
1497  Sint32 result = new_value->set_size( size);
1498  if( result != 0)
1499  return -5;
1500  result = fc->set_argument( parameter_index, new_argument.get());
1501  mi_neuray_assert( result == 0);
1502  return 0;
1503  } else {
1504  // create new constant expression
1505  base::Handle<const IType> type( argument->get_type());
1506  base::Handle<IValue_array> new_value(
1507  m_value_factory->create<IValue_array>( type.get()));
1508  if( !new_value)
1509  return -5;
1510  Sint32 result = new_value->set_size( size);
1511  if( result != 0)
1512  return -5;
1513  base::Handle<IExpression> new_expression(
1514  m_expression_factory->create_constant( new_value.get()));
1515  result = fc->set_argument( parameter_index, new_expression.get());
1516  mi_neuray_assert( result == 0);
1517  return 0;
1518  }
1519 
1520  } else
1521  return -1;
1522 }
1523 
1524 inline Sint32 Argument_editor::set_array_size( const char* parameter_name, Size size)
1525 {
1526  promote_to_edit_if_needed();
1527 
1528  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1529 
1530  base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1531  base::Handle<const IExpression_list> arguments( mi->get_arguments());
1532  base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1533  if( !argument)
1534  return -2;
1535  if( argument->get_kind() == IExpression::EK_CONSTANT) {
1536  // reuse existing constant expression
1537  base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1538  base::Handle<IExpression_constant> new_argument_constant(
1539  new_argument->get_interface<IExpression_constant>());
1540  base::Handle<IValue_array> new_value(
1541  new_argument_constant->get_value<IValue_array>());
1542  if( !new_value)
1543  return -5;
1544  Sint32 result = new_value->set_size( size);
1545  if( result != 0)
1546  return -5;
1547  result = mi->set_argument( parameter_name, new_argument.get());
1548  mi_neuray_assert( result == 0);
1549  return 0;
1550  } else {
1551  // create new constant expression
1552  base::Handle<const IType> type( argument->get_type());
1553  base::Handle<IValue_array> new_value(
1554  m_value_factory->create<IValue_array>( type.get()));
1555  if( !new_value)
1556  return -5;
1557  Sint32 result = new_value->set_size( size);
1558  if( result != 0)
1559  return -5;
1560  base::Handle<IExpression> new_expression(
1561  m_expression_factory->create_constant( new_value.get()));
1562  result = mi->set_argument( parameter_name, new_expression.get());
1563  mi_neuray_assert( result == 0);
1564  return 0;
1565  }
1566 
1567  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1568 
1569  base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1570  base::Handle<const IExpression_list> arguments( fc->get_arguments());
1571  base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1572  if( !argument)
1573  return -2;
1574  if( argument->get_kind() == IExpression::EK_CONSTANT) {
1575  // reuse existing constant expression
1576  base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1577  base::Handle<IExpression_constant> new_argument_constant(
1578  new_argument->get_interface<IExpression_constant>());
1579  base::Handle<IValue_array> new_value(
1580  new_argument_constant->get_value<IValue_array>());
1581  if( !new_value)
1582  return -5;
1583  Sint32 result = new_value->set_size( size);
1584  if( result != 0)
1585  return -5;
1586  result = fc->set_argument( parameter_name, new_argument.get());
1587  mi_neuray_assert( result == 0);
1588  return 0;
1589  } else {
1590  // create new constant expression
1591  base::Handle<const IType> type( argument->get_type());
1592  base::Handle<IValue_array> new_value(
1593  m_value_factory->create<IValue_array>( type.get()));
1594  if( !new_value)
1595  return -5;
1596  Sint32 result = new_value->set_size( size);
1597  if( result != 0)
1598  return -5;
1599  base::Handle<IExpression> new_expression(
1600  m_expression_factory->create_constant( new_value.get()));
1601  result = fc->set_argument( parameter_name, new_expression.get());
1602  mi_neuray_assert( result == 0);
1603  return 0;
1604  }
1605 
1606  } else
1607  return -1;
1608 }
1609 
1610 inline const char* Argument_editor::get_call( Size parameter_index) const
1611 {
1612  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1613 
1614  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
1615  base::Handle<const IExpression_list> arguments( mi->get_arguments());
1617  arguments->get_expression<IExpression_call>( parameter_index));
1618  if( !argument)
1619  return 0;
1620  return argument->get_call();
1621 
1622  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1623 
1624  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
1625  base::Handle<const IExpression_list> arguments( fc->get_arguments());
1627  arguments->get_expression<IExpression_call>( parameter_index));
1628  if( !argument)
1629  return 0;
1630  return argument->get_call();
1631 
1632  } else
1633  return 0;
1634 }
1635 
1636 inline const char* Argument_editor::get_call( const char* parameter_name) const
1637 {
1638  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1639 
1640  base::Handle<const IMaterial_instance> mi( m_access->get_interface<IMaterial_instance>());
1641  base::Handle<const IExpression_list> arguments( mi->get_arguments());
1643  arguments->get_expression<IExpression_call>( parameter_name));
1644  if( !argument)
1645  return 0;
1646  return argument->get_call();
1647 
1648  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1649 
1650  base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
1651  base::Handle<const IExpression_list> arguments( fc->get_arguments());
1653  arguments->get_expression<IExpression_call>( parameter_name));
1654  if( !argument)
1655  return 0;
1656  return argument->get_call();
1657 
1658  } else
1659  return 0;
1660 }
1661 
1662 inline Sint32 Argument_editor::set_call( Size parameter_index, const char* call_name)
1663 {
1664  promote_to_edit_if_needed();
1665 
1666  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1667 
1668  base::Handle<IExpression_call> new_argument( m_expression_factory->create_call( call_name));
1669  if( !new_argument)
1670  return -6;
1671  base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1672  return mi->set_argument( parameter_index, new_argument.get());
1673 
1674  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1675 
1676  base::Handle<IExpression_call> new_argument( m_expression_factory->create_call( call_name));
1677  if( !new_argument)
1678  return -6;
1679  base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1680  return fc->set_argument( parameter_index, new_argument.get());
1681 
1682  } else
1683  return -1;
1684 }
1685 
1686 inline Sint32 Argument_editor::set_call( const char* parameter_name, const char* call_name)
1687 {
1688  promote_to_edit_if_needed();
1689 
1690  if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1691 
1692  base::Handle<IExpression_call> new_argument( m_expression_factory->create_call( call_name));
1693  if( !new_argument)
1694  return -6;
1695  base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1696  return mi->set_argument( parameter_name, new_argument.get());
1697 
1698  } else if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1699 
1700  base::Handle<IExpression_call> new_argument( m_expression_factory->create_call( call_name));
1701  if( !new_argument)
1702  return -6;
1703  base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1704  return fc->set_argument( parameter_name, new_argument.get());
1705 
1706  } else
1707  return -1;
1708 }
1709 
1711 {
1712  m_transaction->retain();
1713  return m_transaction.get();
1714 }
1715 
1717 {
1718  m_mdl_factory->retain();
1719  return m_mdl_factory.get();
1720 }
1721 
1723 {
1724  m_value_factory->retain();
1725  return m_value_factory.get();
1726 }
1727 
1729 {
1730  m_expression_factory->retain();
1731  return m_expression_factory.get();
1732 }
1733 
1735 {
1736  m_access->retain();
1737  return m_access.get();
1738 }
1739 
1741 {
1742  promote_to_edit_if_needed();
1743 
1744  m_edit->retain();
1745  return m_edit.get();
1746 }
1747 
1749 {
1750  return m_type;
1751 }
1752 
1754 {
1755  return m_name;
1756 }
1757 
1758 inline void Argument_editor::promote_to_edit_if_needed()
1759 {
1760  if( m_edit)
1761  return;
1762  m_edit = m_transaction->edit<IScene_element>( m_name.c_str());
1763  mi_neuray_assert( m_edit);
1764  m_old_access = m_access;
1765  m_access = m_edit;
1766 }
1767 
1768 } // namespace neuraylib
1769 
1770 } // namespace mi
1771 
1772 #endif // MI_NEURAYLIB_ARGUMENT_EDITOR_H