NVIDIA Iray API Home  Up
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
mdl_argument_editor.h
Go to the documentation of this file.
1 //*****************************************************************************
2 // Copyright 1986, 2016 NVIDIA Corporation. All rights reserved.
3 //*****************************************************************************
6 //*****************************************************************************
7 
8 #ifndef MI_NEURAYLIB_MDL_ARGUMENT_EDITOR_H
9 #define MI_NEURAYLIB_MDL_ARGUMENT_EDITOR_H
10 
11 #include <mi/base/handle.h>
12 #include <mi/neuraylib/assert.h>
13 #include <mi/neuraylib/iarray.h>
16 #include <mi/neuraylib/ifactory.h>
20 #include <mi/neuraylib/set_get.h>
21 #include <mi/neuraylib/version.h>
22 
23 #include <string>
24 
25 namespace mi {
26 
27 namespace neuraylib {
28 
33 class Mdl_argument_editor
53 {
54 public:
55 
57 
58 
66  ITransaction* transaction, const char* name, IFactory* factory);
67 
73  bool is_valid() const;
74 
80  Element_type get_type() const;
81 
83  const char* get_name() const;
84 
86  const char* get_definition() const;
87 
90 
95  const char* get_parameter_name( Uint32 index) const;
96 
101  Sint32 get_parameter_index( const char* name) const;
102 
110  const char* get_parameter_type( Uint32 index) const;
111 
116  const char* get_parameter_type( const char* name) const;
117 
126  bool is_parameter_type_uniform( Uint32 index) const;
127 
133  bool is_parameter_type_uniform( const char* name) const;
134 
142  const char* get_argument_type( Uint32 index) const;
143 
148  const char* get_argument_type( const char* name) const;
149 
153  const char* get_return_type() const;
154 
158  bool is_return_type_varying() const;
159 
161 
163 
179  template <class T>
180  Sint32 get_value( Uint32 argument_index, T& value) const;
181 
194  template <class T>
195  Sint32 get_value( const char* argument_name, T& value) const;
196 
213  template <class T>
214  Sint32 get_value( Uint32 argument_index, Size array_index, T& value) const;
215 
230  template <class T>
231  Sint32 get_value( const char* argument_name, Size array_index, T& value) const;
232 
249  template <class T>
250  Sint32 set_value( Uint32 argument_index, const T& value);
251 
265  template <class T>
266  Sint32 set_value( const char* argument_name, const T& value);
267 
285  template <class T>
286  Sint32 set_value( Uint32 argument_index, Size array_index, const T& value);
287 
303  template <class T>
304  Sint32 set_value( const char* argument_name, Size array_index, const T& value);
305 
307 
309 
318  bool has_attachment( Uint32 argument_index) const;
319 
325  bool has_attachment( const char* argument_name) const;
326 
337  bool has_attachment( Uint32 argument_index, Size array_index) const;
338 
346  bool has_attachment( const char* argument_name, Size array_index) const;
347 
355  const char* get_attachment( Uint32 argument_index) const;
356 
361  const char* get_attachment( const char* argument_name) const;
362 
371  const char* get_attachment( Uint32 argument_index, Size array_index) const;
372 
378  const char* get_attachment( const char* argument_name, Size array_index) const;
379 
395  Sint32 set_attachment( Uint32 argument_index, const char* attachment_name);
396 
409  Sint32 set_attachment( const char* argument_name, const char* attachment_name);
410 
428  Uint32 argument_index, Size array_index, const char* attachment_name);
429 
445  const char* argument_name, Size array_index, const char* attachment_name);
446 
461  Sint32 remove_attachment( Uint32 argument_index);
462 
474  Sint32 remove_attachment( const char* argument_name);
475 
491  Sint32 remove_attachment( Uint32 argument_index, Size array_index);
492 
506  Sint32 remove_attachment( const char* argument_name, Size array_index);
507 
509 
511 
524  Sint32 get_array_length( Uint32 argument_index, Size& size) const;
525 
535  Sint32 get_array_length( const char* argument_name, Size& size) const;
536 
549  Sint32 set_array_length( Uint32 argument_index, Size size);
550 
560  Sint32 set_array_length( const char* argument_name, Size size);
561 
563 
564 private:
565  void promote_to_edit_if_needed();
566 
567  base::Handle<neuraylib::ITransaction> m_transaction;
568  base::Handle<neuraylib::IFactory> m_factory;
569  base::Handle<const IScene_element> m_access;
570  base::Handle<const IScene_element> m_old_access;
571  base::Handle<IScene_element> m_edit;
572  Element_type m_type;
573  MISTD::string m_name;
574 };
575  // end group mi_neuray_materials
577 
579  ITransaction* transaction, const char* name, IFactory* factory)
580 {
581  mi_neuray_assert( transaction);
582  mi_neuray_assert( name);
583 
584  m_transaction = make_handle_dup( transaction);
585  m_name = name;
586  m_factory = make_handle_dup( factory);
587  m_access = transaction->access<IScene_element>( name);
588  m_type = m_access.is_valid_interface()
589  ? m_access->get_element_type() : static_cast<Element_type>( 0);
590 }
591 
592 inline bool Mdl_argument_editor::is_valid() const
593 {
594  return m_access.is_valid_interface()
596  || m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL);
597 }
598 
600 {
601  return m_type;
602 }
603 
604 inline const char* Mdl_argument_editor::get_name() const
605 {
606  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
607 
609  m_access->get_interface<IMdl_material_instance>());
610  return mi->get_name();
611 
612  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
613 
615  m_access->get_interface<IMdl_function_call>());
616  return fc->get_name();
617 
618  } else
619  return 0;
620 }
621 
622 inline const char* Mdl_argument_editor::get_definition() const
623 {
624  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
625 
627  m_access->get_interface<IMdl_material_instance>());
628  return mi->get_material_definition();
629 
630  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
631 
633  m_access->get_interface<IMdl_function_call>());
634  return fc->get_function_definition();
635 
636  } else
637  return 0;
638 }
639 
641 {
642  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
643 
645  m_access->get_interface<IMdl_material_instance>());
646  return mi->get_parameter_count();
647 
648  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
649 
651  m_access->get_interface<IMdl_function_call>());
652  return fc->get_parameter_count();
653 
654  } else
655  return 0;
656 }
657 
658 inline const char* Mdl_argument_editor::get_parameter_name( Uint32 index) const
659 {
660  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
661 
663  m_access->get_interface<IMdl_material_instance>());
664  return mi->get_parameter_name( index);
665 
666  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
667 
669  m_access->get_interface<IMdl_function_call>());
670  return fc->get_parameter_name( index);
671 
672  } else
673  return 0;
674 }
675 
676 inline Sint32 Mdl_argument_editor::get_parameter_index( const char* name) const
677 {
678  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
679 
681  m_access->get_interface<IMdl_material_instance>());
682  return mi->get_parameter_index( name);
683 
684  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
685 
687  m_access->get_interface<IMdl_function_call>());
688  return fc->get_parameter_index( name);
689 
690  } else
691  return 0;
692 }
693 
694 inline const char* Mdl_argument_editor::get_parameter_type( Uint32 index) const
695 {
696  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
697 
699  m_access->get_interface<IMdl_material_instance>());
700  return mi->get_parameter_type( index);
701 
702  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
703 
705  m_access->get_interface<IMdl_function_call>());
706  return fc->get_parameter_type( index);
707 
708  } else
709  return 0;
710 }
711 
712 inline const char* Mdl_argument_editor::get_parameter_type( const char* name) const
713 {
714  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
715 
717  m_access->get_interface<IMdl_material_instance>());
718  return mi->get_parameter_type( name);
719 
720  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
721 
723  m_access->get_interface<IMdl_function_call>());
724  return fc->get_parameter_type( name);
725 
726  } else
727  return 0;
728 }
729 
730 inline const char* Mdl_argument_editor::get_argument_type( Uint32 index) const
731 {
732  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
733 
735  m_access->get_interface<IMdl_material_instance>());
736  return mi->get_argument_type( index);
737 
738  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
739 
741  m_access->get_interface<IMdl_function_call>());
742  return fc->get_argument_type( index);
743 
744  } else
745  return 0;
746 }
747 
748 inline const char* Mdl_argument_editor::get_argument_type( const char* name) const
749 {
750  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
751 
753  m_access->get_interface<IMdl_material_instance>());
754  return mi->get_argument_type( name);
755 
756  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
757 
759  m_access->get_interface<IMdl_function_call>());
760  return fc->get_argument_type( name);
761 
762  } else
763  return 0;
764 }
765 
767 {
768  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
769 
771  m_access->get_interface<IMdl_material_instance>());
772  return mi->is_parameter_type_uniform( index);
773 
774  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
775 
777  m_access->get_interface<IMdl_function_call>());
778  return fc->is_parameter_type_uniform( index);
779 
780  } else
781  return false;
782 }
783 
784 inline bool Mdl_argument_editor::is_parameter_type_uniform( const char* name) const
785 {
786  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
787 
789  m_access->get_interface<IMdl_material_instance>());
790  return mi->is_parameter_type_uniform( name);
791 
792  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
793 
795  m_access->get_interface<IMdl_function_call>());
796  return fc->is_parameter_type_uniform( name);
797 
798  } else
799  return false;
800 }
801 
802 inline const char* Mdl_argument_editor::get_return_type() const
803 {
804  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
805 
806  return 0;
807 
808  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
809 
811  m_access->get_interface<IMdl_function_call>());
812  return fc->get_return_type();
813 
814  } else
815  return 0;
816 }
817 
819 {
820  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
821 
822  return 0;
823 
824  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
825 
827  m_access->get_interface<IMdl_function_call>());
828  return fc->is_return_type_varying();
829 
830  } else
831  return false;
832 }
833 
834 
835 
836 
837 
838 
839 
840 
841 
842 
843 
844 
845 
846 
847 
848 
849 
850 
851 
852 
853 
854 
855 
856 
857 template <class T>
858 Sint32 Mdl_argument_editor::get_value( Uint32 argument_index, T& value) const
859 {
860  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
861 
863  m_access->get_interface<IMdl_material_instance>());
864  base::Handle<const IAttachable> argument( mi->get_argument( argument_index));
865  if( !argument.is_valid_interface())
866  return -2;
867  base::Handle<const IData> data( argument->get_value());
868  Sint32 result = mi::get_value( data.get(), value);
869  return result == 0 ? 0 : -3;
870 
871  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
872 
874  m_access->get_interface<IMdl_function_call>());
875  base::Handle<const IAttachable> argument( fc->get_argument( argument_index));
876  if( !argument.is_valid_interface())
877  return -2;
878  base::Handle<const IData> data( argument->get_value());
879  Sint32 result = mi::get_value( data.get(), value);
880  return result == 0 ? 0 : -3;
881 
882  } else
883  return -1;
884 }
885 
886 template <class T>
887 Sint32 Mdl_argument_editor::get_value( const char* argument_name, T& value) const
888 {
889  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
890 
892  m_access->get_interface<IMdl_material_instance>());
893  base::Handle<const IAttachable> argument( mi->get_argument( argument_name));
894  if( !argument.is_valid_interface())
895  return -2;
896  base::Handle<const IData> data( argument->get_value());
897  Sint32 result = mi::get_value( data.get(), value);
898  return result == 0 ? 0 : -3;
899 
900  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
901 
903  m_access->get_interface<IMdl_function_call>());
904  base::Handle<const IAttachable> argument( fc->get_argument( argument_name));
905  if( !argument.is_valid_interface())
906  return -2;
907  base::Handle<const IData> data( argument->get_value());
908  Sint32 result = mi::get_value( data.get(), value);
909  return result == 0 ? 0 : -3;
910 
911  } else
912  return -1;
913 }
914 
915 template <class T>
916 Sint32 Mdl_argument_editor::get_value( Uint32 argument_index, Size array_index, T& value) const
917 {
918  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
919 
921  m_access->get_interface<IMdl_material_instance>());
922  base::Handle<const IAttachable> argument( mi->get_argument( argument_index));
923  if( !argument.is_valid_interface())
924  return -2;
925  base::Handle<const IArray> array( argument->get_value<IArray>());
926  if( !array.is_valid_interface())
927  return -2;
928  base::Handle<const IAttachable> element( array->get_element<IAttachable>( array_index));
929  if( !element.is_valid_interface())
930  return -2;
931  base::Handle<const IData> data( element->get_value());
932  Sint32 result = mi::get_value( data.get(), value);
933  return result == 0 ? 0 : -3;
934 
935  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
936 
938  m_access->get_interface<IMdl_function_call>());
939  base::Handle<const IAttachable> argument( fc->get_argument( argument_index));
940  if( !argument.is_valid_interface())
941  return -2;
942  base::Handle<const IArray> array( argument->get_value<IArray>());
943  if( !array.is_valid_interface())
944  return -2;
945  base::Handle<const IAttachable> element( array->get_element<IAttachable>( array_index));
946  if( !element.is_valid_interface())
947  return -2;
948  base::Handle<const IData> data( element->get_value());
949  Sint32 result = mi::get_value( data.get(), value);
950  return result == 0 ? 0 : -3;
951 
952  } else
953  return -1;
954 }
955 
956 template <class T>
957 Sint32 Mdl_argument_editor::get_value( const char* argument_name, Size array_index, T& value) const
958 {
959  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
960 
962  m_access->get_interface<IMdl_material_instance>());
963  base::Handle<const IAttachable> argument( mi->get_argument( argument_name));
964  if( !argument.is_valid_interface())
965  return -2;
966  base::Handle<const IArray> array( argument->get_value<IArray>());
967  if( !array.is_valid_interface())
968  return -2;
969  base::Handle<const IAttachable> element( array->get_element<IAttachable>( array_index));
970  if( !element.is_valid_interface())
971  return -2;
972  base::Handle<const IData> data( element->get_value());
973  Sint32 result = mi::get_value( data.get(), value);
974  return result == 0 ? 0 : -3;
975 
976  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
977 
979  m_access->get_interface<IMdl_function_call>());
980  base::Handle<const IAttachable> argument( fc->get_argument( argument_name));
981  if( !argument.is_valid_interface())
982  return -2;
983  base::Handle<const IArray> array( argument->get_value<IArray>());
984  if( !array.is_valid_interface())
985  return -2;
986  base::Handle<const IAttachable> element( array->get_element<IAttachable>( array_index));
987  if( !element.is_valid_interface())
988  return -2;
989  base::Handle<const IData> data( element->get_value());
990  Sint32 result = mi::get_value( data.get(), value);
991  return result == 0 ? 0 : -3;
992 
993  } else
994  return -1;
995 }
996 
997 template <class T>
998 Sint32 Mdl_argument_editor::set_value( Uint32 argument_index, const T& value)
999 {
1000  promote_to_edit_if_needed();
1001 
1002  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1003 
1004  base::Handle<IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
1005  base::Handle<const IAttachable> argument( mi->get_argument( argument_index));
1006  if( !argument.is_valid_interface())
1007  return -2;
1008  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1009  base::Handle<IData> data( clone->get_value());
1010  if( mi::set_value( data.get(), value) != 0)
1011  return -3;
1012  return mi->set_argument( argument_index, clone.get());
1013 
1014  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1015 
1016  base::Handle<IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
1017  base::Handle<const IAttachable> argument( fc->get_argument( argument_index));
1018  if( !argument.is_valid_interface())
1019  return -2;
1020  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1021  base::Handle<IData> data( clone->get_value());
1022  if( mi::set_value( data.get(), value) != 0)
1023  return -3;
1024  return fc->set_argument( argument_index, clone.get());
1025 
1026  } else
1027  return -1;
1028 }
1029 
1030 template <class T>
1031 Sint32 Mdl_argument_editor::set_value( const char* argument_name, const T& value)
1032 {
1033  promote_to_edit_if_needed();
1034 
1035  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1036 
1037  base::Handle<IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
1038  base::Handle<const IAttachable> argument( mi->get_argument( argument_name));
1039  if( !argument.is_valid_interface())
1040  return -2;
1041  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1042  base::Handle<IData> data( clone->get_value());
1043  if( mi::set_value( data.get(), value) != 0)
1044  return -3;
1045  return mi->set_argument( argument_name, clone.get());
1046 
1047  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1048 
1049  base::Handle<IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
1050  base::Handle<const IAttachable> argument( fc->get_argument( argument_name));
1051  if( !argument.is_valid_interface())
1052  return -2;
1053  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1054  base::Handle<IData> data( clone->get_value());
1055  if( mi::set_value( data.get(), value) != 0)
1056  return -3;
1057  return fc->set_argument( argument_name, clone.get());
1058 
1059  } else
1060  return -1;
1061 }
1062 
1063 template <class T>
1064 Sint32 Mdl_argument_editor::set_value( Uint32 argument_index, Size array_index, const T& value)
1065 {
1066  promote_to_edit_if_needed();
1067 
1068  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1069 
1070  base::Handle<IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
1071  base::Handle<const IAttachable> argument( mi->get_argument( argument_index));
1072  if( !argument.is_valid_interface())
1073  return -2;
1074  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1075  base::Handle<IArray> array( clone->get_value<IArray>());
1076  if( !array.is_valid_interface())
1077  return -2;
1078  base::Handle<IAttachable> element( array->get_element<IAttachable>( array_index));
1079  if( !element.is_valid_interface())
1080  return -2;
1081  base::Handle<IData> data( element->get_value());
1082  if( mi::set_value( data.get(), value) != 0)
1083  return -3;
1084  return mi->set_argument( argument_index, clone.get());
1085 
1086  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1087 
1088  base::Handle<IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
1089  base::Handle<const IAttachable> argument( fc->get_argument( argument_index));
1090  if( !argument.is_valid_interface())
1091  return -2;
1092  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1093  base::Handle<IArray> array( clone->get_value<IArray>());
1094  if( !array.is_valid_interface())
1095  return -2;
1096  base::Handle<IAttachable> element( array->get_element<IAttachable>( array_index));
1097  if( !element.is_valid_interface())
1098  return -2;
1099  base::Handle<IData> data( element->get_value());
1100  if( mi::set_value( data.get(), value) != 0)
1101  return -3;
1102  return fc->set_argument( argument_index, clone.get());
1103 
1104  } else
1105  return -1;
1106 }
1107 
1108 template <class T>
1109 Sint32 Mdl_argument_editor::set_value( const char* argument_name, Size array_index, const T& value)
1110 {
1111  promote_to_edit_if_needed();
1112 
1113  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1114 
1115  base::Handle<IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
1116  base::Handle<const IAttachable> argument( mi->get_argument( argument_name));
1117  if( !argument.is_valid_interface())
1118  return -2;
1119  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1120  base::Handle<IArray> array( clone->get_value<IArray>());
1121  if( !array.is_valid_interface())
1122  return -2;
1123  base::Handle<IAttachable> element( array->get_element<IAttachable>( array_index));
1124  if( !element.is_valid_interface())
1125  return -2;
1126  base::Handle<IData> data( element->get_value());
1127  if( mi::set_value( data.get(), value) != 0)
1128  return -3;
1129  return mi->set_argument( argument_name, clone.get());
1130 
1131  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1132 
1133  base::Handle<IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
1134  base::Handle<const IAttachable> argument( fc->get_argument( argument_name));
1135  if( !argument.is_valid_interface())
1136  return -2;
1137  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1138  base::Handle<IArray> array( clone->get_value<IArray>());
1139  if( !array.is_valid_interface())
1140  return -2;
1141  base::Handle<IAttachable> element( array->get_element<IAttachable>( array_index));
1142  if( !element.is_valid_interface())
1143  return -2;
1144  base::Handle<IData> data( element->get_value());
1145  if( mi::set_value( data.get(), value) != 0)
1146  return -3;
1147  return fc->set_argument( argument_name, clone.get());
1148 
1149  } else
1150  return -1;
1151 }
1152 
1153 inline bool Mdl_argument_editor::has_attachment( Uint32 argument_index) const
1154 {
1155  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1156 
1158  m_access->get_interface<IMdl_material_instance>());
1159  base::Handle<const IAttachable> argument( mi->get_argument( argument_index));
1160  if( !argument.is_valid_interface())
1161  return false;
1162  return argument->get_reference_name() != 0;
1163 
1164  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1165 
1167  m_access->get_interface<IMdl_function_call>());
1168  base::Handle<const IAttachable> argument( fc->get_argument( argument_index));
1169  if( !argument.is_valid_interface())
1170  return false;
1171  return argument->get_reference_name() != 0;
1172 
1173  } else
1174  return false;
1175 }
1176 
1177 inline bool Mdl_argument_editor::has_attachment( const char* argument_name) const
1178 {
1179  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1180 
1182  m_access->get_interface<IMdl_material_instance>());
1183  base::Handle<const IAttachable> argument( mi->get_argument( argument_name));
1184  if( !argument.is_valid_interface())
1185  return false;
1186  return argument->get_reference_name() != 0;
1187 
1188  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1189 
1191  m_access->get_interface<IMdl_function_call>());
1192  base::Handle<const IAttachable> argument( fc->get_argument( argument_name));
1193  if( !argument.is_valid_interface())
1194  return false;
1195  return argument->get_reference_name() != 0;
1196 
1197  } else
1198  return false;
1199 }
1200 
1201 inline bool Mdl_argument_editor::has_attachment( Uint32 argument_index, Size array_index) const
1202 {
1203  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1204 
1206  m_access->get_interface<IMdl_material_instance>());
1207  base::Handle<const IAttachable> argument( mi->get_argument( argument_index));
1208  if( !argument.is_valid_interface())
1209  return false;
1210  base::Handle<const IArray> array( argument->get_value<IArray>());
1211  if( !array.is_valid_interface())
1212  return false;
1213  base::Handle<const IAttachable> element( array->get_element<IAttachable>( array_index));
1214  if( !element.is_valid_interface())
1215  return false;
1216  return element->get_reference_name() != 0;
1217 
1218  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1219 
1221  m_access->get_interface<IMdl_function_call>());
1222  base::Handle<const IAttachable> argument( fc->get_argument( argument_index));
1223  if( !argument.is_valid_interface())
1224  return false;
1225  base::Handle<const IArray> array( argument->get_value<IArray>());
1226  if( !array.is_valid_interface())
1227  return false;
1228  base::Handle<const IAttachable> element( array->get_element<IAttachable>( array_index));
1229  if( !element.is_valid_interface())
1230  return false;
1231  return element->get_reference_name() != 0;
1232 
1233  } else
1234  return false;
1235 }
1236 
1237 inline bool Mdl_argument_editor::has_attachment( const char* argument_name, Size array_index) const
1238 {
1239  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1240 
1242  m_access->get_interface<IMdl_material_instance>());
1243  base::Handle<const IAttachable> argument( mi->get_argument( argument_name));
1244  if( !argument.is_valid_interface())
1245  return false;
1246  base::Handle<const IArray> array( argument->get_value<IArray>());
1247  if( !array.is_valid_interface())
1248  return false;
1249  base::Handle<const IAttachable> element( array->get_element<IAttachable>( array_index));
1250  if( !element.is_valid_interface())
1251  return false;
1252  return element->get_reference_name() != 0;
1253 
1254  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1255 
1257  m_access->get_interface<IMdl_function_call>());
1258  base::Handle<const IAttachable> argument( fc->get_argument( argument_name));
1259  if( !argument.is_valid_interface())
1260  return false;
1261  base::Handle<const IArray> array( argument->get_value<IArray>());
1262  if( !array.is_valid_interface())
1263  return false;
1264  base::Handle<const IAttachable> element( array->get_element<IAttachable>( array_index));
1265  if( !element.is_valid_interface())
1266  return false;
1267  return element->get_reference_name() != 0;
1268 
1269  } else
1270  return false;
1271 }
1272 
1273 inline const char* Mdl_argument_editor::get_attachment( Uint32 argument_index) const
1274 {
1275  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1276 
1278  m_access->get_interface<IMdl_material_instance>());
1279  base::Handle<const IAttachable> argument( mi->get_argument( argument_index));
1280  if( !argument.is_valid_interface())
1281  return 0;
1282  return argument->get_reference_name();
1283 
1284  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1285 
1287  m_access->get_interface<IMdl_function_call>());
1288  base::Handle<const IAttachable> argument( fc->get_argument( argument_index));
1289  if( !argument.is_valid_interface())
1290  return 0;
1291  return argument->get_reference_name();
1292 
1293  } else
1294  return 0;
1295 }
1296 
1297 inline const char* Mdl_argument_editor::get_attachment( const char* argument_name) const
1298 {
1299  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1300 
1302  m_access->get_interface<IMdl_material_instance>());
1303  base::Handle<const IAttachable> argument( mi->get_argument( argument_name));
1304  if( !argument.is_valid_interface())
1305  return 0;
1306  return argument->get_reference_name();
1307 
1308  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1309 
1311  m_access->get_interface<IMdl_function_call>());
1312  base::Handle<const IAttachable> argument( fc->get_argument( argument_name));
1313  if( !argument.is_valid_interface())
1314  return 0;
1315  return argument->get_reference_name();
1316 
1317  } else
1318  return 0;
1319 }
1320 
1322  Uint32 argument_index, Size array_index) const
1323 {
1324  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1325 
1327  m_access->get_interface<IMdl_material_instance>());
1328  base::Handle<const IAttachable> argument( mi->get_argument( argument_index));
1329  if( !argument.is_valid_interface())
1330  return 0;
1331  base::Handle<const IArray> array( argument->get_value<IArray>());
1332  if( !array.is_valid_interface())
1333  return 0;
1334  base::Handle<const IAttachable> element( array->get_element<IAttachable>( array_index));
1335  if( !element.is_valid_interface())
1336  return 0;
1337  return element->get_reference_name();
1338 
1339  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1340 
1342  m_access->get_interface<IMdl_function_call>());
1343  base::Handle<const IAttachable> argument( fc->get_argument( argument_index));
1344  if( !argument.is_valid_interface())
1345  return 0;
1346  base::Handle<const IArray> array( argument->get_value<IArray>());
1347  if( !array.is_valid_interface())
1348  return 0;
1349  base::Handle<const IAttachable> element( array->get_element<IAttachable>( array_index));
1350  if( !element.is_valid_interface())
1351  return 0;
1352  return element->get_reference_name();
1353 
1354  } else
1355  return 0;
1356 }
1357 
1359  const char* argument_name, Size array_index) const
1360 {
1361  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1362 
1364  m_access->get_interface<IMdl_material_instance>());
1365  base::Handle<const IAttachable> argument( mi->get_argument( argument_name));
1366  if( !argument.is_valid_interface())
1367  return 0;
1368  base::Handle<const IArray> array( argument->get_value<IArray>());
1369  if( !array.is_valid_interface())
1370  return 0;
1371  base::Handle<const IAttachable> element( array->get_element<IAttachable>( array_index));
1372  if( !element.is_valid_interface())
1373  return 0;
1374  return element->get_reference_name();
1375 
1376  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1377 
1379  m_access->get_interface<IMdl_function_call>());
1380  base::Handle<const IAttachable> argument( fc->get_argument( argument_name));
1381  if( !argument.is_valid_interface())
1382  return 0;
1383  base::Handle<const IArray> array( argument->get_value<IArray>());
1384  if( !array.is_valid_interface())
1385  return 0;
1386  base::Handle<const IAttachable> element( array->get_element<IAttachable>( array_index));
1387  if( !element.is_valid_interface())
1388  return 0;
1389  return element->get_reference_name();
1390 
1391  } else
1392  return 0;
1393 }
1394 
1396  Uint32 argument_index, const char* attachment_name)
1397 {
1398  promote_to_edit_if_needed();
1399 
1400  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1401 
1402  base::Handle<IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
1403  base::Handle<const IAttachable> argument( mi->get_argument( argument_index));
1404  if( !argument.is_valid_interface())
1405  return -2;
1406  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1407  if( clone->set_reference( attachment_name) != 0)
1408  return -3;
1409  return mi->set_argument( argument_index, clone.get());
1410 
1411  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1412 
1413  base::Handle<IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
1414  base::Handle<const IAttachable> argument( fc->get_argument( argument_index));
1415  if( !argument.is_valid_interface())
1416  return -2;
1417  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1418  if( clone->set_reference( attachment_name) != 0)
1419  return -3;
1420  return fc->set_argument( argument_index, clone.get());
1421 
1422  } else
1423  return -1;
1424 }
1425 
1427  const char* argument_name, const char* attachment_name)
1428 {
1429  promote_to_edit_if_needed();
1430 
1431  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1432 
1433  base::Handle<IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
1434  base::Handle<const IAttachable> argument( mi->get_argument( argument_name));
1435  if( !argument.is_valid_interface())
1436  return -2;
1437  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1438  if( clone->set_reference( attachment_name) != 0)
1439  return -3;
1440  return mi->set_argument( argument_name, clone.get());
1441 
1442  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1443 
1444  base::Handle<IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
1445  base::Handle<const IAttachable> argument( fc->get_argument( argument_name));
1446  if( !argument.is_valid_interface())
1447  return -2;
1448  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1449  if( clone->set_reference( attachment_name) != 0)
1450  return -3;
1451  return fc->set_argument( argument_name, clone.get());
1452 
1453  } else
1454  return -1;
1455 }
1456 
1458  Uint32 argument_index, Size array_index, const char* attachment_index)
1459 {
1460  promote_to_edit_if_needed();
1461 
1462  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1463 
1464  base::Handle<IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
1465  base::Handle<const IAttachable> argument( mi->get_argument( argument_index));
1466  if( !argument.is_valid_interface())
1467  return -2;
1468  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1469  base::Handle<IArray> array( clone->get_value<IArray>());
1470  if( !array.is_valid_interface())
1471  return -2;
1472  base::Handle<IAttachable> element( array->get_element<IAttachable>( array_index));
1473  if( !element.is_valid_interface())
1474  return -2;
1475  if( element->set_reference( attachment_index) != 0)
1476  return -3;
1477  return mi->set_argument( argument_index, clone.get());
1478 
1479  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1480 
1481  base::Handle<IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
1482  base::Handle<const IAttachable> argument( fc->get_argument( argument_index));
1483  if( !argument.is_valid_interface())
1484  return -2;
1485  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1486  base::Handle<IArray> array( clone->get_value<IArray>());
1487  if( !array.is_valid_interface())
1488  return -2;
1489  base::Handle<IAttachable> element( array->get_element<IAttachable>( array_index));
1490  if( !element.is_valid_interface())
1491  return -2;
1492  if( element->set_reference( attachment_index) != 0)
1493  return -3;
1494  return fc->set_argument( argument_index, clone.get());
1495 
1496  } else
1497  return -1;
1498 }
1499 
1501  const char* argument_name, Size array_index, const char* attachment_name)
1502 {
1503  promote_to_edit_if_needed();
1504 
1505  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1506 
1507  base::Handle<IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
1508  base::Handle<const IAttachable> argument( mi->get_argument( argument_name));
1509  if( !argument.is_valid_interface())
1510  return -2;
1511  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1512  base::Handle<IArray> array( clone->get_value<IArray>());
1513  if( !array.is_valid_interface())
1514  return -2;
1515  base::Handle<IAttachable> element( array->get_element<IAttachable>( array_index));
1516  if( !element.is_valid_interface())
1517  return -2;
1518  if( element->set_reference( attachment_name) != 0)
1519  return -3;
1520  return mi->set_argument( argument_name, clone.get());
1521 
1522  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1523 
1524  base::Handle<IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
1525  base::Handle<const IAttachable> argument( fc->get_argument( argument_name));
1526  if( !argument.is_valid_interface())
1527  return -2;
1528  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1529  base::Handle<IArray> array( clone->get_value<IArray>());
1530  if( !array.is_valid_interface())
1531  return -2;
1532  base::Handle<IAttachable> element( array->get_element<IAttachable>( array_index));
1533  if( !element.is_valid_interface())
1534  return -2;
1535  if( element->set_reference( attachment_name) != 0)
1536  return -3;
1537  return fc->set_argument( argument_name, clone.get());
1538 
1539  } else
1540  return -1;
1541 }
1542 
1544 {
1545  return set_attachment( argument_index, 0);
1546 }
1547 
1548 inline Sint32 Mdl_argument_editor::remove_attachment( const char* argument_name)
1549 {
1550  return set_attachment( argument_name, 0);
1551 }
1552 
1553 inline Sint32 Mdl_argument_editor::remove_attachment( Uint32 argument_index, Size array_index)
1554 {
1555  return set_attachment( argument_index, array_index, 0);
1556 }
1557 
1558 inline Sint32 Mdl_argument_editor::remove_attachment( const char* argument_name, Size array_index)
1559 {
1560  return set_attachment( argument_name, array_index, 0);
1561 }
1562 
1563 inline Sint32 Mdl_argument_editor::get_array_length( Uint32 argument_index, Size& size) const
1564 {
1565  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1566 
1568  m_access->get_interface<IMdl_material_instance>());
1569  base::Handle<const IAttachable> argument( mi->get_argument( argument_index));
1570  if( !argument.is_valid_interface())
1571  return -2;
1572  base::Handle<const IArray> array( argument->get_value<IArray>());
1573  if( !array.is_valid_interface())
1574  return -4;
1575  size = array->get_length();
1576  return 0;
1577 
1578  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1579 
1581  m_access->get_interface<IMdl_function_call>());
1582  base::Handle<const IAttachable> argument( fc->get_argument( argument_index));
1583  if( !argument.is_valid_interface())
1584  return -2;
1585  base::Handle<const IArray> array( argument->get_value<IArray>());
1586  if( !array.is_valid_interface())
1587  return -4;
1588  size = array->get_length();
1589  return 0;
1590 
1591  } else
1592  return -1;
1593 }
1594 
1595 inline Sint32 Mdl_argument_editor::get_array_length( const char* argument_name, Size& size) const
1596 {
1597  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1598 
1600  m_access->get_interface<IMdl_material_instance>());
1601  base::Handle<const IAttachable> argument( mi->get_argument( argument_name));
1602  if( !argument.is_valid_interface())
1603  return -2;
1604  base::Handle<const IArray> array( argument->get_value<IArray>());
1605  if( !array.is_valid_interface())
1606  return -4;
1607  size = array->get_length();
1608  return 0;
1609 
1610  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1611 
1613  m_access->get_interface<IMdl_function_call>());
1614  base::Handle<const IAttachable> argument( fc->get_argument( argument_name));
1615  if( !argument.is_valid_interface())
1616  return -2;
1617  base::Handle<const IArray> array( argument->get_value<IArray>());
1618  if( !array.is_valid_interface())
1619  return -4;
1620  size = array->get_length();
1621  return 0;
1622 
1623  } else
1624  return -1;
1625 }
1626 
1628 {
1629  promote_to_edit_if_needed();
1630 
1631  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1632 
1633  base::Handle<IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
1634  base::Handle<const IAttachable> argument( mi->get_argument( argument_index));
1635  if( !argument.is_valid_interface())
1636  return -2;
1637  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1638  base::Handle<IDynamic_array> dynamic_array( clone->get_value<IDynamic_array>());
1639  if( !dynamic_array.is_valid_interface())
1640  return -4;
1641  dynamic_array->set_length( size);
1642  mi->set_argument( argument_index, clone.get());
1643  return 0;
1644 
1645  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1646 
1647  base::Handle<IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
1648  base::Handle<const IAttachable> argument( fc->get_argument( argument_index));
1649  if( !argument.is_valid_interface())
1650  return -2;
1651  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1652  base::Handle<IDynamic_array> dynamic_array( clone->get_value<IDynamic_array>());
1653  if( !dynamic_array.is_valid_interface())
1654  return -4;
1655  dynamic_array->set_length( size);
1656  fc->set_argument( argument_index, clone.get());
1657  return 0;
1658 
1659  } else
1660  return -1;
1661 }
1662 
1663 inline Sint32 Mdl_argument_editor::set_array_length( const char* argument_name, Size size)
1664 {
1665  promote_to_edit_if_needed();
1666 
1667  if( m_type == ELEMENT_TYPE_MDL_MATERIAL_INSTANCE) {
1668 
1669  base::Handle<IMdl_material_instance> mi( m_edit->get_interface<IMdl_material_instance>());
1670  base::Handle<const IAttachable> argument( mi->get_argument( argument_name));
1671  if( !argument.is_valid_interface())
1672  return -2;
1673  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1674  base::Handle<IDynamic_array> dynamic_array( clone->get_value<IDynamic_array>());
1675  if( !dynamic_array.is_valid_interface())
1676  return -4;
1677  dynamic_array->set_length( size);
1678  mi->set_argument( argument_name, clone.get());
1679  return 0;
1680 
1681  } else if( m_type == ELEMENT_TYPE_MDL_FUNCTION_CALL) {
1682 
1683  base::Handle<IMdl_function_call> fc( m_edit->get_interface<IMdl_function_call>());
1684  base::Handle<const IAttachable> argument( fc->get_argument( argument_name));
1685  if( !argument.is_valid_interface())
1686  return -2;
1687  base::Handle<IAttachable> clone( m_factory->clone<IAttachable>( argument.get()));
1688  base::Handle<IDynamic_array> dynamic_array( clone->get_value<IDynamic_array>());
1689  if( !dynamic_array.is_valid_interface())
1690  return -4;
1691  dynamic_array->set_length( size);
1692  fc->set_argument( argument_name, clone.get());
1693  return 0;
1694 
1695  } else
1696  return -1;
1697 }
1698 
1699 inline void Mdl_argument_editor::promote_to_edit_if_needed()
1700 {
1701  if( m_edit.is_valid_interface())
1702  return;
1703  m_edit = m_transaction->edit<IScene_element>( m_name.c_str());
1704  mi_neuray_assert( m_edit.is_valid_interface());
1705  m_old_access = m_access;
1706  m_access = m_edit;
1707 }
1708 
1709 } // namespace neuraylib
1710 
1711 #ifdef MI_NEURAYLIB_DEPRECATED_NAMESPACE_MI_TRANSITION
1715 using neuraylib::IMdl_function_call;
1716 using neuraylib::IMdl_material_instance;
1717 using neuraylib::IScene_element;
1718 using neuraylib::Mdl_argument_editor;
1719 #endif // MI_NEURAYLIB_DEPRECATED_NAMESPACE_MI_TRANSITION
1720 
1721 } // namespace mi
1722 
1723 #endif // MI_NEURAYLIB_MDL_ARGUMENT_EDITOR_H