MDL SDK API nvidia_logo_transpbg.gif Up
argument_editor.h
Go to the documentation of this file.
1/***************************************************************************************************
2 * Copyright 2022 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
23namespace mi {
24
25namespace neuraylib {
26
27class IMdl_execution_context;
28
49{
50public:
51
53
54
70 ITransaction* transaction,
71 const char* name,
72 IMdl_factory* mdl_factory,
73 bool intent_to_edit = false);
74
80 bool is_valid() const;
81
90 bool is_valid_instance( IMdl_execution_context* context) const;
91
101
109 Element_type get_type() const;
110
112 const char* get_definition() const;
113
115 const char* get_mdl_definition() const;
116
121 bool is_array_constructor() const;
122
124 bool is_material() const;
125
127 const IType* get_return_type() const;
128
131
136 const char* get_parameter_name( Size index) const;
137
142 Size get_parameter_index( const char* name) const;
143
145 const IType_list* get_parameter_types() const;
146
153 bool is_parameter_enabled( Size index, IMdl_evaluator_api* evaluator) const;
154
156 const IExpression_list* get_arguments() const;
157
163 IExpression::Kind get_argument_kind( Size parameter_index) const;
164
170 IExpression::Kind get_argument_kind( const char* parameter_name) const;
171
173
175
191 Sint32 reset_argument( Size index);
192
209 Sint32 reset_argument( const char* name);
210
212
214
228 template<class T>
229 Sint32 get_value( Size parameter_index, T& value) const;
230
241 template <class T>
242 Sint32 get_value( const char* parameter_name, T& value) const;
243
259 template<class T>
260 Sint32 get_value( Size parameter_index, Size component_index, T& value) const;
261
274 template <class T>
275 Sint32 get_value( const char* parameter_name, Size component_index, T& value) const;
276
292 template<class T>
293 Sint32 get_value( Size parameter_index, const char* field_name, T& value) const;
294
307 template <class T>
308 Sint32 get_value( const char* parameter_name, const char* field_name, T& value) const;
309
325 template<class T>
326 Sint32 set_value( Size parameter_index, const T& value);
327
340 template <class T>
341 Sint32 set_value( const char* parameter_name, const T& value);
342
363 template<class T>
364 Sint32 set_value( Size parameter_index, Size component_index, const T& value);
365
383 template <class T>
384 Sint32 set_value( const char* parameter_name, Size component_index, const T& value);
385
403 template<class T>
404 Sint32 set_value( Size parameter_index, const char* field_name, const T& value);
405
420 template <class T>
421 Sint32 set_value( const char* parameter_name, const char* field_name, const T& value);
422
436 Sint32 get_array_length( Uint32 parameter_index, Size& size) const;
437
448 Sint32 get_array_length( const char* parameter_name, Size& size) const;
449
465 Sint32 set_array_size( Uint32 parameter_index, Size size);
466
479 Sint32 set_array_size( const char* parameter_name, Size size);
480
482
484
493 const char* get_call( Size parameter_index) const;
494
500 const char* get_call( const char* parameter_name) const;
501
519 Sint32 set_call( Size parameter_index, const char* call_name);
520
535 Sint32 set_call( const char* parameter_name, const char* call_name);
536
538
540
543
546
549
552
554 const IScene_element* get_scene_element() const;
555
558
561
563 const std::string& get_name() const;
564
566
567private:
568 void promote_to_edit_if_needed();
569
570 base::Handle<ITransaction> m_transaction;
571 base::Handle<IMdl_factory> m_mdl_factory;
572 base::Handle<IValue_factory> m_value_factory;
573 base::Handle<IExpression_factory> m_expression_factory;
577 Element_type m_type;
578 std::string m_name;
579};
580 // end group mi_neuray_mdl_elements
582
584 ITransaction* transaction, const char* name, IMdl_factory* mdl_factory, bool intent_to_edit)
585{
586 mi_neuray_assert( transaction);
587 mi_neuray_assert( name);
588
589 m_transaction = make_handle_dup( transaction);
590 m_name = name;
591 m_mdl_factory = make_handle_dup( mdl_factory);
592 m_value_factory
593 = m_mdl_factory ? m_mdl_factory->create_value_factory( m_transaction.get()) : 0;
594 m_expression_factory
595 = m_mdl_factory ? m_mdl_factory->create_expression_factory( m_transaction.get()) : 0;
596
597 if( intent_to_edit) {
598 m_edit = transaction->edit<IScene_element>( name);
599 m_access = m_edit;
600 m_old_access = m_edit;
601 m_type = m_access ? m_access->get_element_type() : static_cast<Element_type>( 0);
602 } else {
603 m_access = transaction->access<IScene_element>( name);
604 m_type = m_access ? m_access->get_element_type() : static_cast<Element_type>( 0);
605 }
606}
607
608inline bool Argument_editor::is_valid() const
609{
610#ifdef MI_NEURAYLIB_DEPRECATED_13_0
611 return m_access
612 && (m_type == ELEMENT_TYPE_MATERIAL_INSTANCE || m_type == ELEMENT_TYPE_FUNCTION_CALL);
613#else // MI_NEURAYLIB_DEPRECATED_13_0
614 return m_access
615 && (m_type == ELEMENT_TYPE_FUNCTION_CALL);
616#endif // MI_NEURAYLIB_DEPRECATED_13_0
617}
618
620{
621#ifdef MI_NEURAYLIB_DEPRECATED_13_0
622 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
623
625 return mi->is_valid(context);
626
627 } else
628#endif // MI_NEURAYLIB_DEPRECATED_13_0
629 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
630
631 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
632 return fc->is_valid(context);
633 }
634 else
635 return false;
636}
637
639{
640 promote_to_edit_if_needed();
641
642#ifdef MI_NEURAYLIB_DEPRECATED_13_0
643 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
644
645 base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
646 return mi->repair(flags, context);
647
648 } else
649#endif // MI_NEURAYLIB_DEPRECATED_13_0
650 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
651
652 base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
653 return fc->repair( flags, context);
654
655 } else
656 return -1;
657}
658
660{
661 return m_type;
662}
663
664inline const char* Argument_editor::get_definition() const
665{
666#ifdef MI_NEURAYLIB_DEPRECATED_13_0
667 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
668
670 return mi->get_material_definition();
671
672 } else
673#endif // MI_NEURAYLIB_DEPRECATED_13_0
674 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
675
676 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
677 return fc->get_function_definition();
678
679 } else
680 return 0;
681}
682
683inline const char* Argument_editor::get_mdl_definition() const
684{
685#ifdef MI_NEURAYLIB_DEPRECATED_13_0
686 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
687
689 return mi->get_mdl_material_definition();
690
691 } else
692#endif // MI_NEURAYLIB_DEPRECATED_13_0
693 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
694
695 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
696 return fc->get_mdl_function_definition();
697
698 } else
699 return 0;
700}
701
703{
704#ifdef MI_NEURAYLIB_DEPRECATED_13_0
705 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
706
707 return false;
708
709 } else
710#endif // MI_NEURAYLIB_DEPRECATED_13_0
711 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
712
713 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
714 return fc->is_array_constructor();
715
716 } else
717 return false;
718}
719
721{
722#ifdef MI_NEURAYLIB_DEPRECATED_13_0
723 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
724
725 return true;
726
727 } else
728#endif // MI_NEURAYLIB_DEPRECATED_13_0
729 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
730
732 m_access->get_interface<IFunction_call>());
733 return fc->is_material();
734
735 } else
736 return false;
737}
738
740{
741#ifdef MI_NEURAYLIB_DEPRECATED_13_0
742 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
743
745 return mi->get_parameter_count();
746
747 } else
748#endif // MI_NEURAYLIB_DEPRECATED_13_0
749 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
750
751 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
752 return fc->get_parameter_count();
753
754 } else
755 return 0;
756}
757
758inline const char* Argument_editor::get_parameter_name( Size parameter_index) const
759{
760#ifdef MI_NEURAYLIB_DEPRECATED_13_0
761 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
762
764 return mi->get_parameter_name( parameter_index);
765
766 } else
767#endif // MI_NEURAYLIB_DEPRECATED_13_0
768 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
769
770 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
771 return fc->get_parameter_name( parameter_index);
772
773 } else
774 return 0;
775}
776
777inline Size Argument_editor::get_parameter_index( const char* name) const
778{
779#ifdef MI_NEURAYLIB_DEPRECATED_13_0
780 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
781
783 return mi->get_parameter_index( name);
784
785 } else
786#endif // MI_NEURAYLIB_DEPRECATED_13_0
787 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
788
789 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
790 return fc->get_parameter_index( name);
791
792 } else
793 return 0;
794}
795
797{
798#ifdef MI_NEURAYLIB_DEPRECATED_13_0
799 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
800
801 return 0;
802
803 } else
804#endif // MI_NEURAYLIB_DEPRECATED_13_0
805 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
806
807 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
808 return fc->get_return_type();
809
810 } else
811 return 0;
812}
813
815{
816#ifdef MI_NEURAYLIB_DEPRECATED_13_0
817 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
818
820 return mi->get_parameter_types();
821
822 } else
823#endif // MI_NEURAYLIB_DEPRECATED_13_0
824 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
825
826 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
827 return fc->get_parameter_types();
828
829 } else
830 return 0;
831}
832
834{
835 if( !evaluator)
836 return true;
837
838#ifdef MI_NEURAYLIB_DEPRECATED_13_0
839 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
840
842 base::Handle<const IValue_bool> b(evaluator->is_material_parameter_enabled(
843 m_transaction.get(), m_value_factory.get(), mi.get(), index, /*error*/ NULL));
844 if (!b)
845 return true;
846 return b->get_value();
847
848 } else
849#endif // MI_NEURAYLIB_DEPRECATED_13_0
850 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
851
852 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
854 m_transaction.get(), m_value_factory.get(), fc.get(), index, /*error*/ NULL));
855 if( !b)
856 return true;
857 return b->get_value();
858
859 } else
860 return true;
861}
862
864{
865 promote_to_edit_if_needed();
866
867#ifdef MI_NEURAYLIB_DEPRECATED_13_0
868 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
869
870 base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
871 return mi->reset_argument( index);
872
873 } else
874#endif // MI_NEURAYLIB_DEPRECATED_13_0
875 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
876
877 base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
878 return fc->reset_argument( index);
879
880 } else
881 return -1;
882}
883
885{
886 promote_to_edit_if_needed();
887
888#ifdef MI_NEURAYLIB_DEPRECATED_13_0
889 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
890
891 base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
892 return mi->reset_argument( name);
893
894 } else
895#endif // MI_NEURAYLIB_DEPRECATED_13_0
896 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
897
898 base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
899 return fc->reset_argument( name);
900
901 } else
902 return -1;
903}
904
905
907{
908#ifdef MI_NEURAYLIB_DEPRECATED_13_0
909 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
910
912 return mi->get_arguments();
913
914 } else
915#endif // MI_NEURAYLIB_DEPRECATED_13_0
916 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
917
918 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
919 return fc->get_arguments();
920
921 } else
922 return 0;
923}
924
926{
927#ifdef MI_NEURAYLIB_DEPRECATED_13_0
928 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
929
931 base::Handle<const IExpression_list> arguments( mi->get_arguments());
932 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
933 return argument ? argument->get_kind() : static_cast<IExpression::Kind>( 0);
934
935 } else
936#endif // MI_NEURAYLIB_DEPRECATED_13_0
937 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
938
939 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
940 base::Handle<const IExpression_list> arguments( fc->get_arguments());
941 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
942 return argument ? argument->get_kind() : static_cast<IExpression::Kind>( 0);
943
944 } else
945 return static_cast<IExpression::Kind>( 0);
946}
947
948inline IExpression::Kind Argument_editor::get_argument_kind( const char* parameter_name) const
949{
950#ifdef MI_NEURAYLIB_DEPRECATED_13_0
951 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
952
954 base::Handle<const IExpression_list> arguments( mi->get_arguments());
955 base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
956 return argument ? argument->get_kind() : static_cast<IExpression::Kind>( 0);
957
958 } else
959#endif // MI_NEURAYLIB_DEPRECATED_13_0
960 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
961
962 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
963 base::Handle<const IExpression_list> arguments( fc->get_arguments());
964 base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
965 return argument ? argument->get_kind() : static_cast<IExpression::Kind>( 0);
966
967 } else
968 return static_cast<IExpression::Kind>( 0);
969}
970
971template <class T>
972Sint32 Argument_editor::get_value( Size parameter_index, T& value) const
973{
974#ifdef MI_NEURAYLIB_DEPRECATED_13_0
975 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
976
978 base::Handle<const IExpression_list> arguments( mi->get_arguments());
979 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
980 if( !argument)
981 return -2;
984 if( !argument_constant)
985 return -4;
986 base::Handle<const IValue> argument_value( argument_constant->get_value());
987 Sint32 result = neuraylib::get_value( argument_value.get(), value);
988 return result == 0 ? 0 : -5;
989
990 } else
991#endif // MI_NEURAYLIB_DEPRECATED_13_0
992 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
993
994 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
995 base::Handle<const IExpression_list> arguments( fc->get_arguments());
996 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
997 if( !argument)
998 return -2;
1000 argument->get_interface<IExpression_constant>());
1001 if( !argument_constant)
1002 return -4;
1003 base::Handle<const IValue> argument_value( argument_constant->get_value());
1004 Sint32 result = neuraylib::get_value( argument_value.get(), value);
1005 return result == 0 ? 0 : -5;
1006
1007 } else
1008 return -1;
1009}
1010
1011template <class T>
1012Sint32 Argument_editor::get_value( const char* name, T& value) const
1013{
1014#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1015 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1016
1018 base::Handle<const IExpression_list> arguments( mi->get_arguments());
1019 base::Handle<const IExpression> argument_( arguments->get_expression( name));
1020 if( !argument_)
1021 return -2;
1023 argument_->get_interface<IExpression_constant>());
1024 if( !argument_constant)
1025 return -4;
1026 base::Handle<const IValue> argument_value( argument_constant->get_value());
1027 Sint32 result = neuraylib::get_value( argument_value.get(), value);
1028 return result == 0 ? 0 : -5;
1029
1030 } else
1031#endif // MI_NEURAYLIB_DEPRECATED_13_0
1032 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1033
1035 m_access->get_interface<IFunction_call>());
1036 base::Handle<const IExpression_list> arguments( fc->get_arguments());
1037 base::Handle<const IExpression> argument_( arguments->get_expression( name));
1038 if( !argument_)
1039 return -2;
1041 argument_->get_interface<IExpression_constant>());
1042 if( !argument_constant)
1043 return -4;
1044 base::Handle<const IValue> argument_value( argument_constant->get_value());
1045 Sint32 result = neuraylib::get_value( argument_value.get(), value);
1046 return result == 0 ? 0 : -5;
1047
1048 } else
1049 return -1;
1050}
1051
1052template <class T>
1053Sint32 Argument_editor::get_value( Size parameter_index, Size component_index, T& value) const
1054{
1055#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1056 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1057
1059 base::Handle<const IExpression_list> arguments( mi->get_arguments());
1060 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1061 if( !argument)
1062 return -2;
1064 argument->get_interface<IExpression_constant>());
1065 if( !argument_constant)
1066 return -4;
1067 base::Handle<const IValue> argument_value( argument_constant->get_value());
1068 Sint32 result = neuraylib::get_value( argument_value.get(), component_index, value);
1069 return result == 0 ? 0 : (result == -3 ? -3 : -5);
1070
1071 } else
1072#endif // MI_NEURAYLIB_DEPRECATED_13_0
1073 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1074
1075 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
1076 base::Handle<const IExpression_list> arguments( fc->get_arguments());
1077 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1078 if( !argument)
1079 return -2;
1081 argument->get_interface<IExpression_constant>());
1082 if( !argument_constant)
1083 return -4;
1084 base::Handle<const IValue> argument_value( argument_constant->get_value());
1085 Sint32 result = neuraylib::get_value( argument_value.get(), component_index, value);
1086 return result == 0 ? 0 : (result == -3 ? -3 : -5);
1087
1088 } else
1089 return -1;
1090}
1091
1092template <class T>
1093Sint32 Argument_editor::get_value( const char* parameter_name, Size component_index, T& value) const
1094{
1095#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1096 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1097
1099 base::Handle<const IExpression_list> arguments( mi->get_arguments());
1100 base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1101 if( !argument)
1102 return -2;
1104 argument->get_interface<IExpression_constant>());
1105 if( !argument_constant)
1106 return -4;
1107 base::Handle<const IValue> argument_value( argument_constant->get_value());
1108 Sint32 result = neuraylib::get_value( argument_value.get(), component_index, value);
1109 return result == 0 ? 0 : (result == -3 ? -3 : -5);
1110
1111 } else
1112#endif // MI_NEURAYLIB_DEPRECATED_13_0
1113 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1114
1115 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
1116 base::Handle<const IExpression_list> arguments( fc->get_arguments());
1117 base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1118 if( !argument)
1119 return -2;
1121 argument->get_interface<IExpression_constant>());
1122 if( !argument_constant)
1123 return -4;
1124 base::Handle<const IValue> argument_value( argument_constant->get_value());
1125 Sint32 result = neuraylib::get_value( argument_value.get(), component_index, value);
1126 return result == 0 ? 0 : (result == -3 ? -3 : -5);
1127
1128 } else
1129 return -1;
1130}
1131
1132template <class T>
1134 Size parameter_index, const char* field_name, T& value) const
1135{
1136#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1137 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1138
1140 base::Handle<const IExpression_list> arguments( mi->get_arguments());
1141 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1142 if( !argument)
1143 return -2;
1145 argument->get_interface<IExpression_constant>());
1146 if( !argument_constant)
1147 return -4;
1148 base::Handle<const IValue> argument_value( argument_constant->get_value());
1149 Sint32 result = neuraylib::get_value( argument_value.get(), field_name, value);
1150 return result == 0 ? 0 : (result == -3 ? -3 : -5);
1151
1152 } else
1153#endif // MI_NEURAYLIB_DEPRECATED_13_0
1154 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1155
1156 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
1157 base::Handle<const IExpression_list> arguments( fc->get_arguments());
1158 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1159 if( !argument)
1160 return -2;
1162 argument->get_interface<IExpression_constant>());
1163 if( !argument_constant)
1164 return -4;
1165 base::Handle<const IValue> argument_value( argument_constant->get_value());
1166 Sint32 result = neuraylib::get_value( argument_value.get(), field_name, value);
1167 return result == 0 ? 0 : (result == -3 ? -3 : -5);
1168
1169 } else
1170 return -1;
1171}
1172
1173template <class T>
1175 const char* parameter_name, const char* field_name, T& value) const
1176{
1177#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1178 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1179
1181 base::Handle<const IExpression_list> arguments( mi->get_arguments());
1182 base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1183 if( !argument)
1184 return -2;
1186 argument->get_interface<IExpression_constant>());
1187 if( !argument_constant)
1188 return -4;
1189 base::Handle<const IValue> argument_value( argument_constant->get_value());
1190 Sint32 result = neuraylib::get_value( argument_value.get(), field_name, value);
1191 return result == 0 ? 0 : (result == -3 ? -3 : -5);
1192
1193 } else
1194#endif // MI_NEURAYLIB_DEPRECATED_13_0
1195 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1196
1197 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
1198 base::Handle<const IExpression_list> arguments( fc->get_arguments());
1199 base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1200 if( !argument)
1201 return -2;
1203 argument->get_interface<IExpression_constant>());
1204 if( !argument_constant)
1205 return -4;
1206 base::Handle<const IValue> argument_value( argument_constant->get_value());
1207 Sint32 result = neuraylib::get_value( argument_value.get(), field_name, value);
1208 return result == 0 ? 0 : (result == -3 ? -3 : -5);
1209
1210 } else
1211 return -1;
1212}
1213
1214template <class T>
1215Sint32 Argument_editor::set_value( Size parameter_index, const T& value)
1216{
1217 promote_to_edit_if_needed();
1218
1219#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1220 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1221
1222 base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1223 if( mi->is_default())
1224 return -4;
1225 base::Handle<const IExpression_list> arguments( mi->get_arguments());
1226 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1227 if( !argument)
1228 return -2;
1229 base::Handle<const IType> type( argument->get_type());
1230 base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1231 Sint32 result = neuraylib::set_value( new_value.get(), value);
1232 if( result != 0)
1233 return -5;
1234 base::Handle<IExpression> new_expression(
1235 m_expression_factory->create_constant( new_value.get()));
1236 result = mi->set_argument( parameter_index, new_expression.get());
1237 mi_neuray_assert( result == 0);
1238 return result;
1239
1240 } else
1241#endif // MI_NEURAYLIB_DEPRECATED_13_0
1242 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1243
1244 base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1245 if( fc->is_default())
1246 return -4;
1247 base::Handle<const IExpression_list> arguments( fc->get_arguments());
1248 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1249 if( !argument)
1250 return -2;
1251 base::Handle<const IType> type( argument->get_type());
1252 base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1253 Sint32 result = neuraylib::set_value( new_value.get(), value);
1254 if( result != 0)
1255 return -5;
1256 base::Handle<IExpression> new_expression(
1257 m_expression_factory->create_constant( new_value.get()));
1258 result = fc->set_argument( parameter_index, new_expression.get());
1259 mi_neuray_assert( result == 0);
1260 return result;
1261
1262 } else
1263 return -1;
1264}
1265
1266template <class T>
1267Sint32 Argument_editor::set_value( const char* parameter_name, const T& value)
1268{
1269 promote_to_edit_if_needed();
1270
1271#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1272 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1273
1274 base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1275 if( mi->is_default())
1276 return -4;
1277 base::Handle<const IExpression_list> arguments( mi->get_arguments());
1278 base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1279 if( !argument)
1280 return -2;
1281 base::Handle<const IType> type( argument->get_type());
1282 base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1283 Sint32 result = neuraylib::set_value( new_value.get(), value);
1284 if( result != 0)
1285 return -5;
1286 base::Handle<IExpression> new_expression(
1287 m_expression_factory->create_constant( new_value.get()));
1288 result = mi->set_argument( parameter_name, new_expression.get());
1289 mi_neuray_assert( result == 0);
1290 return result;
1291
1292 } else
1293#endif // MI_NEURAYLIB_DEPRECATED_13_0
1294 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1295
1296 base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1297 if( fc->is_default())
1298 return -4;
1299 base::Handle<const IExpression_list> arguments( fc->get_arguments());
1300 base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1301 if( !argument)
1302 return -2;
1303 base::Handle<const IType> type( argument->get_type());
1304 base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1305 Sint32 result = neuraylib::set_value( new_value.get(), value);
1306 if( result != 0)
1307 return -5;
1308 base::Handle<IExpression> new_expression(
1309 m_expression_factory->create_constant( new_value.get()));
1310 result = fc->set_argument( parameter_name, new_expression.get());
1311 mi_neuray_assert( result == 0);
1312 return result;
1313
1314 } else
1315 return -1;
1316}
1317
1318template <class T>
1319Sint32 Argument_editor::set_value( Size parameter_index, Size component_index, const T& value)
1320{
1321 promote_to_edit_if_needed();
1322
1323#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1324 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1325
1326 base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1327 if( mi->is_default())
1328 return -4;
1329 base::Handle<const IExpression_list> arguments( mi->get_arguments());
1330 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1331 if( !argument)
1332 return -2;
1333 if( argument->get_kind() == IExpression::EK_CONSTANT) {
1334 // reuse existing constant expression
1335 base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1336 base::Handle<IExpression_constant> new_argument_constant(
1337 new_argument->get_interface<IExpression_constant>());
1338 base::Handle<IValue> new_value( new_argument_constant->get_value());
1339 Sint32 result = neuraylib::set_value( new_value.get(), component_index, value);
1340 if( result != 0)
1341 return result == -3 ? -3 : -5;
1342 result = mi->set_argument( parameter_index, new_argument.get());
1343 mi_neuray_assert( result == 0);
1344 return result;
1345 } else {
1346 // create new constant expression
1347 base::Handle<const IType> type( argument->get_type());
1348 base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1349 Sint32 result = neuraylib::set_value( new_value.get(), component_index, value);
1350 if( result != 0)
1351 return result == -3 ? -3 : -5;
1352 base::Handle<IExpression> new_expression(
1353 m_expression_factory->create_constant( new_value.get()));
1354 result = mi->set_argument( parameter_index, new_expression.get());
1355 mi_neuray_assert( result == 0);
1356 return result;
1357 }
1358
1359 } else
1360#endif // MI_NEURAYLIB_DEPRECATED_13_0
1361 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1362
1363 base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1364 if( fc->is_default())
1365 return -4;
1366 base::Handle<const IExpression_list> arguments( fc->get_arguments());
1367 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1368 if( !argument)
1369 return -2;
1370 if( argument->get_kind() == IExpression::EK_CONSTANT) {
1371 // reuse existing constant expression
1372 base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1373 base::Handle<IExpression_constant> new_argument_constant(
1374 new_argument->get_interface<IExpression_constant>());
1375 base::Handle<IValue> new_value( new_argument_constant->get_value());
1376 Sint32 result = neuraylib::set_value( new_value.get(), component_index, value);
1377 if( result != 0)
1378 return result == -3 ? -3 : -5;
1379 result = fc->set_argument( parameter_index, new_argument.get());
1380 mi_neuray_assert( result == 0);
1381 return result;
1382 } else {
1383 // create new constant expression
1384 base::Handle<const IType> type( argument->get_type());
1385 base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1386 Sint32 result = neuraylib::set_value( new_value.get(), component_index, value);
1387 if( result != 0)
1388 return result == -3 ? -3 : -5;
1389 base::Handle<IExpression> new_expression(
1390 m_expression_factory->create_constant( new_value.get()));
1391 result = fc->set_argument( parameter_index, new_expression.get());
1392 mi_neuray_assert( result == 0);
1393 return result;
1394 }
1395
1396 } else
1397 return -1;
1398}
1399
1400template <class T>
1401Sint32 Argument_editor::set_value( const char* parameter_name, Size component_index, const T& value)
1402{
1403 promote_to_edit_if_needed();
1404
1405#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1406 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1407
1408 base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1409 if( mi->is_default())
1410 return -4;
1411 base::Handle<const IExpression_list> arguments( mi->get_arguments());
1412 base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1413 if( !argument)
1414 return -2;
1415 if( argument->get_kind() == IExpression::EK_CONSTANT) {
1416 // reuse existing constant expression
1417 base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1418 base::Handle<IExpression_constant> new_argument_constant(
1419 new_argument->get_interface<IExpression_constant>());
1420 base::Handle<IValue> new_value( new_argument_constant->get_value());
1421 Sint32 result = neuraylib::set_value( new_value.get(), component_index, value);
1422 if( result != 0)
1423 return result == -3 ? -3 : -5;
1424 result = mi->set_argument( parameter_name, new_argument.get());
1425 mi_neuray_assert( result == 0);
1426 return result;
1427 } else {
1428 // create new constant expression
1429 base::Handle<const IType> type( argument->get_type());
1430 base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1431 Sint32 result = neuraylib::set_value( new_value.get(), component_index, value);
1432 if( result != 0)
1433 return result == -3 ? -3 : -5;
1434 base::Handle<IExpression> new_expression(
1435 m_expression_factory->create_constant( new_value.get()));
1436 result = mi->set_argument( parameter_name, new_expression.get());
1437 mi_neuray_assert( result == 0);
1438 return result;
1439 }
1440
1441 } else
1442#endif // MI_NEURAYLIB_DEPRECATED_13_0
1443 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1444
1445 base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1446 if( fc->is_default())
1447 return -4;
1448 base::Handle<const IExpression_list> arguments( fc->get_arguments());
1449 base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1450 if( !argument)
1451 return -2;
1452 if( argument->get_kind() == IExpression::EK_CONSTANT) {
1453 // reuse existing constant expression
1454 base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1455 base::Handle<IExpression_constant> new_argument_constant(
1456 new_argument->get_interface<IExpression_constant>());
1457 base::Handle<IValue> new_value( new_argument_constant->get_value());
1458 Sint32 result = neuraylib::set_value( new_value.get(), component_index, value);
1459 if( result != 0)
1460 return result == -3 ? -3 : -5;
1461 result = fc->set_argument( parameter_name, new_argument.get());
1462 mi_neuray_assert( result == 0);
1463 return result;
1464 } else {
1465 // create new constant expression
1466 base::Handle<const IType> type( argument->get_type());
1467 base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1468 Sint32 result = neuraylib::set_value( new_value.get(), component_index, value);
1469 if( result != 0)
1470 return result == -3 ? -3 : -5;
1471 base::Handle<IExpression> new_expression(
1472 m_expression_factory->create_constant( new_value.get()));
1473 result = fc->set_argument( parameter_name, new_expression.get());
1474 mi_neuray_assert( result == 0);
1475 return result;
1476 }
1477
1478 } else
1479 return -1;
1480}
1481
1482template <class T>
1484 Size parameter_index, const char* field_name, const T& value)
1485{
1486 promote_to_edit_if_needed();
1487
1488#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1489 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1490
1491 base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1492 if( mi->is_default())
1493 return -4;
1494 base::Handle<const IExpression_list> arguments( mi->get_arguments());
1495 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1496 if( !argument)
1497 return -2;
1498 if( argument->get_kind() == IExpression::EK_CONSTANT) {
1499 // reuse existing constant expression
1500 base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1501 base::Handle<IExpression_constant> new_argument_constant(
1502 new_argument->get_interface<IExpression_constant>());
1503 base::Handle<IValue> new_value( new_argument_constant->get_value());
1504 Sint32 result = neuraylib::set_value( new_value.get(), field_name, value);
1505 if( result != 0)
1506 return result == -3 ? -3 : -5;
1507 result = mi->set_argument( parameter_index, new_argument.get());
1508 mi_neuray_assert( result == 0);
1509 return result;
1510 } else {
1511 // create new constant expression
1512 base::Handle<const IType> type( argument->get_type());
1513 base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1514 Sint32 result = neuraylib::set_value( new_value.get(), field_name, value);
1515 if( result != 0)
1516 return result == -3 ? -3 : -5;
1517 base::Handle<IExpression> new_expression(
1518 m_expression_factory->create_constant( new_value.get()));
1519 result = mi->set_argument( parameter_index, new_expression.get());
1520 mi_neuray_assert( result == 0);
1521 return result;
1522 }
1523
1524 } else
1525#endif // MI_NEURAYLIB_DEPRECATED_13_0
1526 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1527
1528 base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1529 if( fc->is_default())
1530 return -4;
1531 base::Handle<const IExpression_list> arguments( fc->get_arguments());
1532 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
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> new_value( new_argument_constant->get_value());
1541 Sint32 result = neuraylib::set_value( new_value.get(), field_name, value);
1542 if( result != 0)
1543 return result == -3 ? -3 : -5;
1544 result = fc->set_argument( parameter_index, new_argument.get());
1545 mi_neuray_assert( result == 0);
1546 return result;
1547 } else {
1548 // create new constant expression
1549 base::Handle<const IType> type( argument->get_type());
1550 base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1551 Sint32 result = neuraylib::set_value( new_value.get(), field_name, value);
1552 if( result != 0)
1553 return result == -3 ? -3 : -5;
1554 base::Handle<IExpression> new_expression(
1555 m_expression_factory->create_constant( new_value.get()));
1556 result = fc->set_argument( parameter_index, new_expression.get());
1557 mi_neuray_assert( result == 0);
1558 return result;
1559 }
1560
1561 } else
1562 return -1;
1563}
1564
1565template <class T>
1567 const char* parameter_name, const char* field_name, const T& value)
1568{
1569 promote_to_edit_if_needed();
1570
1571#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1572 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1573
1574 base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1575 if( mi->is_default())
1576 return -4;
1577 base::Handle<const IExpression_list> arguments( mi->get_arguments());
1578 base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1579 if( !argument)
1580 return -2;
1581 if( argument->get_kind() == IExpression::EK_CONSTANT) {
1582 // reuse existing constant expression
1583 base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1584 base::Handle<IExpression_constant> new_argument_constant(
1585 new_argument->get_interface<IExpression_constant>());
1586 base::Handle<IValue> new_value( new_argument_constant->get_value());
1587 Sint32 result = neuraylib::set_value( new_value.get(), field_name, value);
1588 if( result != 0)
1589 return result == -3 ? -3 : -5;
1590 result = mi->set_argument( parameter_name, new_argument.get());
1591 mi_neuray_assert( result == 0);
1592 return result;
1593 } else {
1594 // create new constant expression
1595 base::Handle<const IType> type( argument->get_type());
1596 base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1597 Sint32 result = neuraylib::set_value( new_value.get(), field_name, value);
1598 if( result != 0)
1599 return result == -3 ? -3 : -5;
1600 base::Handle<IExpression> new_expression(
1601 m_expression_factory->create_constant( new_value.get()));
1602 result = mi->set_argument( parameter_name, new_expression.get());
1603 mi_neuray_assert( result == 0);
1604 return result;
1605 }
1606
1607 } else
1608#endif // MI_NEURAYLIB_DEPRECATED_13_0
1609 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1610
1611 base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1612 if( fc->is_default())
1613 return -4;
1614 base::Handle<const IExpression_list> arguments( fc->get_arguments());
1615 base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1616 if( !argument)
1617 return -2;
1618 if( argument->get_kind() == IExpression::EK_CONSTANT) {
1619 // reuse existing constant expression
1620 base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1621 base::Handle<IExpression_constant> new_argument_constant(
1622 new_argument->get_interface<IExpression_constant>());
1623 base::Handle<IValue> new_value( new_argument_constant->get_value());
1624 Sint32 result = neuraylib::set_value( new_value.get(), field_name, value);
1625 if( result != 0)
1626 return result == -3 ? -3 : -5;
1627 result = fc->set_argument( parameter_name, new_argument.get());
1628 mi_neuray_assert( result == 0);
1629 return result;
1630 } else {
1631 // create new constant expression
1632 base::Handle<const IType> type( argument->get_type());
1633 base::Handle<IValue> new_value( m_value_factory->create( type.get()));
1634 Sint32 result = neuraylib::set_value( new_value.get(), field_name, value);
1635 if( result != 0)
1636 return result == -3 ? -3 : -5;
1637 base::Handle<IExpression> new_expression(
1638 m_expression_factory->create_constant( new_value.get()));
1639 result = fc->set_argument( parameter_name, new_expression.get());
1640 mi_neuray_assert( result == 0);
1641 return result;
1642 }
1643
1644 } else
1645 return -1;
1646}
1647
1648inline Sint32 Argument_editor::get_array_length( Uint32 parameter_index, Size& size) const
1649{
1650#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1651 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1652
1654 base::Handle<const IExpression_list> arguments( mi->get_arguments());
1655 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1656 if( !argument)
1657 return -2;
1659 argument->get_interface<IExpression_constant>());
1660 if( !argument_constant)
1661 return -4;
1662 base::Handle<const IValue_array> value( argument_constant->get_value<IValue_array>());
1663 if( !value)
1664 return -5;
1665 size = value->get_size();
1666 return 0;
1667
1668 } else
1669#endif // MI_NEURAYLIB_DEPRECATED_13_0
1670 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1671
1672 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
1673 base::Handle<const IExpression_list> arguments( fc->get_arguments());
1674 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1675 if( !argument)
1676 return -2;
1678 argument->get_interface<IExpression_constant>());
1679 if( !argument_constant)
1680 return -4;
1681 base::Handle<const IValue_array> value( argument_constant->get_value<IValue_array>());
1682 if( !value)
1683 return -5;
1684 size = value->get_size();
1685 return 0;
1686
1687 } else
1688 return -1;
1689}
1690
1691inline Sint32 Argument_editor::get_array_length( const char* parameter_name, Size& size) const
1692{
1693#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1694 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1695
1697 base::Handle<const IExpression_list> arguments( mi->get_arguments());
1698 base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1699 if( !argument)
1700 return -2;
1702 argument->get_interface<IExpression_constant>());
1703 if( !argument_constant)
1704 return -4;
1705 base::Handle<const IValue_array> value( argument_constant->get_value<IValue_array>());
1706 if( !value)
1707 return -5;
1708 size = value->get_size();
1709 return 0;
1710
1711 } else
1712#endif // MI_NEURAYLIB_DEPRECATED_13_0
1713 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1714
1715 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
1716 base::Handle<const IExpression_list> arguments( fc->get_arguments());
1717 base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1718 if( !argument)
1719 return -2;
1721 argument->get_interface<IExpression_constant>());
1722 if( !argument_constant)
1723 return -4;
1724 base::Handle<const IValue_array> value( argument_constant->get_value<IValue_array>());
1725 if( !value)
1726 return -5;
1727 size = value->get_size();
1728 return 0;
1729
1730 } else
1731 return -1;
1732}
1733
1735{
1736 promote_to_edit_if_needed();
1737
1738#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1739 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1740
1741 base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1742 if( mi->is_default())
1743 return -4;
1744 base::Handle<const IExpression_list> arguments( mi->get_arguments());
1745 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1746 if( !argument)
1747 return -2;
1748 if( argument->get_kind() == IExpression::EK_CONSTANT) {
1749 // reuse existing constant expression
1750 base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1751 base::Handle<IExpression_constant> new_argument_constant(
1752 new_argument->get_interface<IExpression_constant>());
1754 new_argument_constant->get_value<IValue_array>());
1755 if( !new_value)
1756 return -5;
1757 Sint32 result = new_value->set_size( size);
1758 if( result != 0)
1759 return -5;
1760 result = mi->set_argument( parameter_index, new_argument.get());
1761 mi_neuray_assert( result == 0);
1762 return result;
1763 } else {
1764 // create new constant expression
1765 base::Handle<const IType> type( argument->get_type());
1767 m_value_factory->create<IValue_array>( type.get()));
1768 if( !new_value)
1769 return -5;
1770 Sint32 result = new_value->set_size( size);
1771 if( result != 0)
1772 return -5;
1773 base::Handle<IExpression> new_expression(
1774 m_expression_factory->create_constant( new_value.get()));
1775 result = mi->set_argument( parameter_index, new_expression.get());
1776 mi_neuray_assert( result == 0);
1777 return result;
1778 }
1779
1780 } else
1781#endif // MI_NEURAYLIB_DEPRECATED_13_0
1782 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1783
1784 base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1785 if( fc->is_default())
1786 return -4;
1787 base::Handle<const IExpression_list> arguments( fc->get_arguments());
1788 base::Handle<const IExpression> argument( arguments->get_expression( parameter_index));
1789 if( !argument)
1790 return -2;
1791 if( argument->get_kind() == IExpression::EK_CONSTANT) {
1792 // reuse existing constant expression
1793 base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1794 base::Handle<IExpression_constant> new_argument_constant(
1795 new_argument->get_interface<IExpression_constant>());
1797 new_argument_constant->get_value<IValue_array>());
1798 if( !new_value)
1799 return -5;
1800 Sint32 result = new_value->set_size( size);
1801 if( result != 0)
1802 return -5;
1803 result = fc->set_argument( parameter_index, new_argument.get());
1804 mi_neuray_assert( result == 0);
1805 return result;
1806 } else {
1807 // create new constant expression
1808 base::Handle<const IType> type( argument->get_type());
1810 m_value_factory->create<IValue_array>( type.get()));
1811 if( !new_value)
1812 return -5;
1813 Sint32 result = new_value->set_size( size);
1814 if( result != 0)
1815 return -5;
1816 base::Handle<IExpression> new_expression(
1817 m_expression_factory->create_constant( new_value.get()));
1818 result = fc->set_argument( parameter_index, new_expression.get());
1819 mi_neuray_assert( result == 0);
1820 return result;
1821 }
1822
1823 } else
1824 return -1;
1825}
1826
1827inline Sint32 Argument_editor::set_array_size( const char* parameter_name, Size size)
1828{
1829 promote_to_edit_if_needed();
1830
1831#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1832 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1833
1834 base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1835 if( mi->is_default())
1836 return -4;
1837 base::Handle<const IExpression_list> arguments( mi->get_arguments());
1838 base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1839 if( !argument)
1840 return -2;
1841 if( argument->get_kind() == IExpression::EK_CONSTANT) {
1842 // reuse existing constant expression
1843 base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1844 base::Handle<IExpression_constant> new_argument_constant(
1845 new_argument->get_interface<IExpression_constant>());
1847 new_argument_constant->get_value<IValue_array>());
1848 if( !new_value)
1849 return -5;
1850 Sint32 result = new_value->set_size( size);
1851 if( result != 0)
1852 return -5;
1853 result = mi->set_argument( parameter_name, new_argument.get());
1854 mi_neuray_assert( result == 0);
1855 return result;
1856 } else {
1857 // create new constant expression
1858 base::Handle<const IType> type( argument->get_type());
1860 m_value_factory->create<IValue_array>( type.get()));
1861 if( !new_value)
1862 return -5;
1863 Sint32 result = new_value->set_size( size);
1864 if( result != 0)
1865 return -5;
1866 base::Handle<IExpression> new_expression(
1867 m_expression_factory->create_constant( new_value.get()));
1868 result = mi->set_argument( parameter_name, new_expression.get());
1869 mi_neuray_assert( result == 0);
1870 return result;
1871 }
1872
1873 } else
1874#endif // MI_NEURAYLIB_DEPRECATED_13_0
1875 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1876
1877 base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1878 if( fc->is_default())
1879 return -4;
1880 base::Handle<const IExpression_list> arguments( fc->get_arguments());
1881 base::Handle<const IExpression> argument( arguments->get_expression( parameter_name));
1882 if( !argument)
1883 return -2;
1884 if( argument->get_kind() == IExpression::EK_CONSTANT) {
1885 // reuse existing constant expression
1886 base::Handle<IExpression> new_argument( m_expression_factory->clone( argument.get()));
1887 base::Handle<IExpression_constant> new_argument_constant(
1888 new_argument->get_interface<IExpression_constant>());
1890 new_argument_constant->get_value<IValue_array>());
1891 if( !new_value)
1892 return -5;
1893 Sint32 result = new_value->set_size( size);
1894 if( result != 0)
1895 return -5;
1896 result = fc->set_argument( parameter_name, new_argument.get());
1897 mi_neuray_assert( result == 0);
1898 return result;
1899 } else {
1900 // create new constant expression
1901 base::Handle<const IType> type( argument->get_type());
1903 m_value_factory->create<IValue_array>( type.get()));
1904 if( !new_value)
1905 return -5;
1906 Sint32 result = new_value->set_size( size);
1907 if( result != 0)
1908 return -5;
1909 base::Handle<IExpression> new_expression(
1910 m_expression_factory->create_constant( new_value.get()));
1911 result = fc->set_argument( parameter_name, new_expression.get());
1912 mi_neuray_assert( result == 0);
1913 return result;
1914 }
1915
1916 } else
1917 return -1;
1918}
1919
1920inline const char* Argument_editor::get_call( Size parameter_index) const
1921{
1922#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1923 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1924
1926 base::Handle<const IExpression_list> arguments( mi->get_arguments());
1928 arguments->get_expression<IExpression_call>( parameter_index));
1929 if( !argument)
1930 return 0;
1931 return argument->get_call();
1932
1933 } else
1934#endif // MI_NEURAYLIB_DEPRECATED_13_0
1935 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1936
1937 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
1938 base::Handle<const IExpression_list> arguments( fc->get_arguments());
1940 arguments->get_expression<IExpression_call>( parameter_index));
1941 if( !argument)
1942 return 0;
1943 return argument->get_call();
1944
1945 } else
1946 return 0;
1947}
1948
1949inline const char* Argument_editor::get_call( const char* parameter_name) const
1950{
1951#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1952 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1953
1955 base::Handle<const IExpression_list> arguments( mi->get_arguments());
1957 arguments->get_expression<IExpression_call>( parameter_name));
1958 if( !argument)
1959 return 0;
1960 return argument->get_call();
1961
1962 } else
1963#endif // MI_NEURAYLIB_DEPRECATED_13_0
1964 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1965
1966 base::Handle<const IFunction_call> fc( m_access->get_interface<IFunction_call>());
1967 base::Handle<const IExpression_list> arguments( fc->get_arguments());
1969 arguments->get_expression<IExpression_call>( parameter_name));
1970 if( !argument)
1971 return 0;
1972 return argument->get_call();
1973
1974 } else
1975 return 0;
1976}
1977
1978inline Sint32 Argument_editor::set_call( Size parameter_index, const char* call_name)
1979{
1980 promote_to_edit_if_needed();
1981
1982#ifdef MI_NEURAYLIB_DEPRECATED_13_0
1983 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
1984
1985 base::Handle<IExpression_call> new_argument( m_expression_factory->create_call( call_name));
1986 if( !new_argument)
1987 return -6;
1988 base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
1989 return mi->set_argument( parameter_index, new_argument.get());
1990
1991 } else
1992#endif // MI_NEURAYLIB_DEPRECATED_13_0
1993 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
1994
1995 base::Handle<IExpression_call> new_argument( m_expression_factory->create_call( call_name));
1996 if( !new_argument)
1997 return -6;
1998 base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
1999 return fc->set_argument( parameter_index, new_argument.get());
2000
2001 } else
2002 return -1;
2003}
2004
2005inline Sint32 Argument_editor::set_call( const char* parameter_name, const char* call_name)
2006{
2007 promote_to_edit_if_needed();
2008
2009#ifdef MI_NEURAYLIB_DEPRECATED_13_0
2010 if( m_type == ELEMENT_TYPE_MATERIAL_INSTANCE) {
2011
2012 base::Handle<IExpression_call> new_argument( m_expression_factory->create_call( call_name));
2013 if( !new_argument)
2014 return -6;
2015 base::Handle<IMaterial_instance> mi( m_edit->get_interface<IMaterial_instance>());
2016 return mi->set_argument( parameter_name, new_argument.get());
2017
2018 } else
2019#endif // MI_NEURAYLIB_DEPRECATED_13_0
2020 if( m_type == ELEMENT_TYPE_FUNCTION_CALL) {
2021
2022 base::Handle<IExpression_call> new_argument( m_expression_factory->create_call( call_name));
2023 if( !new_argument)
2024 return -6;
2025 base::Handle<IFunction_call> fc( m_edit->get_interface<IFunction_call>());
2026 return fc->set_argument( parameter_name, new_argument.get());
2027
2028 } else
2029 return -1;
2030}
2031
2033{
2034 m_transaction->retain();
2035 return m_transaction.get();
2036}
2037
2039{
2040 m_mdl_factory->retain();
2041 return m_mdl_factory.get();
2042}
2043
2045{
2046 m_value_factory->retain();
2047 return m_value_factory.get();
2048}
2049
2051{
2052 m_expression_factory->retain();
2053 return m_expression_factory.get();
2054}
2055
2057{
2058 m_access->retain();
2059 return m_access.get();
2060}
2061
2063{
2064 promote_to_edit_if_needed();
2065
2066 m_edit->retain();
2067 return m_edit.get();
2068}
2069
2071{
2072 return m_type;
2073}
2074
2075inline const std::string& Argument_editor::get_name() const
2076{
2077 return m_name;
2078}
2079
2080inline void Argument_editor::promote_to_edit_if_needed()
2081{
2082 if( m_edit)
2083 return;
2084 m_edit = m_transaction->edit<IScene_element>( m_name.c_str());
2085 mi_neuray_assert( m_edit);
2086 m_old_access = m_access;
2087 m_access = m_edit;
2088}
2089
2090} // namespace neuraylib
2091
2092} // namespace mi
2093
2094#endif // MI_NEURAYLIB_ARGUMENT_EDITOR_H
Handle class template for interfaces, automatizing the lifetime control via reference counting.
Definition: handle.h:113
A wrapper around the interface for MDL material instances and function calls.
Definition: argument_editor.h:49
const IScene_element * get_scene_element() const
Get the MDL function call or material instance.
Definition: argument_editor.h:2056
bool is_valid() const
Indicates whether the argument editor is in a valid state.
Definition: argument_editor.h:608
IExpression::Kind get_argument_kind(Size parameter_index) const
Returns the expression kind of an argument.
Definition: argument_editor.h:925
IValue_factory * get_value_factory() const
Get the value factory.
Definition: argument_editor.h:2044
Sint32 set_value(Size parameter_index, const T &value)
Sets a non-compound argument.
Definition: argument_editor.h:1215
Sint32 set_array_size(Uint32 parameter_index, Size size)
Sets the length of a dynamic array argument.
Definition: argument_editor.h:1734
const std::string & get_name() const
Get the DB name of the MDL function call or material instance.
Definition: argument_editor.h:2075
bool is_material() const
Indicates whether the argument editor acts on a material instance.
Definition: argument_editor.h:720
bool is_array_constructor() const
Indicates whether the argument editor acts on a function call that is an instance of the array constr...
Definition: argument_editor.h:702
Sint32 get_value(Size parameter_index, T &value) const
Returns a non-compound argument (values of constants only, no calls).
Definition: argument_editor.h:972
const char * get_definition() const
Returns the DB name of the corresponding material or function definition.
Definition: argument_editor.h:664
IExpression_factory * get_expression_factory() const
Get the expression factory.
Definition: argument_editor.h:2050
const char * get_parameter_name(Size index) const
Returns the name of the parameter at index.
Definition: argument_editor.h:758
Element_type get_element_type() const
Get the element type.
Definition: argument_editor.h:2070
Size get_parameter_count() const
Returns the number of parameters.
Definition: argument_editor.h:739
Sint32 set_call(Size parameter_index, const char *call_name)
Sets an argument (call expressions only).
Definition: argument_editor.h:1978
Size get_parameter_index(const char *name) const
Returns the index position of a parameter.
Definition: argument_editor.h:777
bool is_parameter_enabled(Size index, IMdl_evaluator_api *evaluator) const
Checks the enable_if condition of the given parameter.
Definition: argument_editor.h:833
ITransaction * get_transaction() const
Get the transaction.
Definition: argument_editor.h:2032
Sint32 reset_argument(Size index)
Resets the argument at index.
Definition: argument_editor.h:863
const IExpression_list * get_arguments() const
Returns all arguments.
Definition: argument_editor.h:906
const IType * get_return_type() const
Returns the return type.
Definition: argument_editor.h:796
bool is_valid_instance(IMdl_execution_context *context) const
Indicates whether the material instance or function call referenced by this argument editor is valid.
Definition: argument_editor.h:619
Element_type get_type() const
Indicates whether the argument editor acts on a material instance or on a function call.
Definition: argument_editor.h:659
const char * get_call(Size parameter_index) const
Returns an argument (call expressions only).
Definition: argument_editor.h:1920
const char * get_mdl_definition() const
Returns the MDL name of the corresponding material or function definition.
Definition: argument_editor.h:683
Argument_editor(ITransaction *transaction, const char *name, IMdl_factory *mdl_factory, bool intent_to_edit=false)
Constructs an MDL argument editor for a fixed material instance or function call.
Definition: argument_editor.h:583
mi::Sint32 repair(mi::Uint32 flags, IMdl_execution_context *context)
Attempts to repair an invalid material instance or function call.
Definition: argument_editor.h:638
IMdl_factory * get_mdl_factory() const
Get the MDL factory.
Definition: argument_editor.h:2038
Sint32 get_array_length(Uint32 parameter_index, Size &size) const
Returns the length of an array argument.
Definition: argument_editor.h:1648
const IType_list * get_parameter_types() const
Returns the types of all parameters.
Definition: argument_editor.h:814
An indirect call expression.
Definition: iexpression.h:148
A constant expression.
Definition: iexpression.h:93
The interface for creating expressions.
Definition: iexpression.h:541
An ordered collection of expressions identified by name or index.
Definition: iexpression.h:239
Kind
The possible kinds of expressions.
Definition: iexpression.h:51
@ EK_CONSTANT
A constant expression. See mi::neuraylib::IExpression_constant.
Definition: iexpression.h:53
This interface represents a function call.
Definition: ifunction_call.h:52
This interface represents a material instance.
Definition: imaterial_instance.h:34
Provides access to various functions for the evaluation of MDL expressions.
Definition: imdl_evaluator_api.h:30
virtual const IValue_bool * is_function_parameter_enabled(ITransaction *trans, IValue_factory *fact, const IFunction_call *call, Size index, Sint32 *error) const =0
Evaluates if a function call parameter is enabled, i.e., the enable_if condition evaluates to true).
The execution context can be used to query status information like error and warning messages concern...
Definition: imdl_execution_context.h:126
Factory for various MDL interfaces and functions.
Definition: imdl_factory.h:49
Common base interface for all scene elements.
Definition: iscene_element.h:78
virtual Element_type get_element_type() const =0
Indicates the actual scene element represented by interfaces derived from this interface.
A transaction provides a consistent view on the database.
Definition: itransaction.h:84
virtual const base::IInterface * access(const char *name)=0
Retrieves an element from the database.
virtual base::IInterface * edit(const char *name)=0
Retrieves an element from the database and returns it ready for editing.
An ordered collection of types identified by name or index.
Definition: itype.h:542
The interface to MDL types.
Definition: itype.h:51
A value of type array.
Definition: ivalue.h:403
The interface for creating values.
Definition: ivalue.h:656
Handle<Interface> make_handle_dup(Interface *iptr)
Converts passed-in interface pointer to a handle, without taking interface over.
Definition: handle.h:438
Handle<New_interface> get_interface() const
Returns a new handle for a possibly different interface type, which is the equivalent of a dynamic ca...
Definition: handle.h:352
Interface * get() const
Access to the interface. Returns 0 for an invalid interface.
Definition: handle.h:294
unsigned int Uint32
32-bit unsigned integer.
Definition: types.h:47
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:110
signed int Sint32
32-bit signed integer.
Definition: types.h:44
#define mi_neuray_assert(expr)
If expr evaluates to true this macro shall have no effect.
Definition: assert.h:67
mi::Sint32 set_value(mi::neuraylib::IValue *value, const T &v)
Simplifies setting the value of mi::neuraylib::IValue from the corresponding classes from the base an...
Definition: ivalue.h:886
mi::Sint32 get_value(const mi::neuraylib::IValue *value, T &v)
base and math API.
Definition: ivalue.h:1161
Element_type
Distinguishes scene elements.
Definition: iscene_element.h:30
@ ELEMENT_TYPE_FUNCTION_CALL
mi::neuraylib::IFunction_call
Definition: iscene_element.h:54
Smart-pointer handle class for interfaces, const and non-const version.
Expressions of the MDL type system.
Scene element Function_call.
Scene element Material_instance.
API component that gives access to the MDL evaluator.
API component that gives access to some MDL functionality.
Database transactions.
Types of the MDL type system.
Values of the MDL type system.
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
Definition: example_derivatives.dox:5
Assertions and compile-time assertions.