Create a new definition.
790 {
791 if (!this.compoundGraph) {
792 return null;
793 }
794
795 let nodeGraph = this.compoundGraph;
796
797
798 let category = nodeGraph.getName();
799 if (this.options['definitionName']) {
800 category = this.options['definitionName'];
801 }
802
803 let identifier = "";
804
805 let embedNamespace = true;
806
807
808 let namespace = mx.createValidName(this.options[this.NAMESPACE])
809
810 namespace = namespace.replace(':', '_')
811 if (embedNamespace && namespace.length > 0)
812 {
813 category = namespace + '_' + category;
814 }
815
816 if (category.match(/^[\d_]/)) {
817 console.warn('Category starts with a number. Adding prefix "c_" to category name.')
818 category = 'c' + category;
819 }
820
821 category = category.replace(/__/g, '_')
822
823 identifier = category;
824 if (this.options[this.VERSION])
825 identifier = identifier + '_' + this.options['version'];
826
827 let parameter_signature = '';
828 let outputs = nodeGraph.getOutputs();
829 for (let output of outputs) {
830 let outputType = output.getType();
831 parameter_signature = parameter_signature + '_' + outputType;
832 }
833 identifier = identifier + parameter_signature;
834 identifier = mx.createValidName(identifier)
835
836 identifier = identifier.replace(/__/g, '_')
837
838 let nodeDefName = this.options[this.DEFINITION_PREFIX] + identifier;
839 let nodegraphName = this.options[this.NODEGRAPH_PREFIX] + identifier;
840 let uiName = this.options[this.UI_NAME];
841 let defaultVersion = this.options[this.DEFAULT_VERSION];
842 let nodeGroup = this.options[this.NODEGROUP];
843 let version = this.options[this.VERSION]
844
845 let definitionDoc = mx.createDocument();
846
847
848 let definition = definitionDoc.addNodeDefFromGraph(nodeGraph, nodeDefName, category, nodegraphName)
849 if (version.length > 0)
850 {
851 definition.setVersionString(version);
852 }
853 if (defaultVersion)
854 definition.setDefaultVersion(defaultVersion);
855 if (nodeGroup.length > 0)
856 {
857 definition.setNodeGroup(nodeGroup);
858 }
859 let functionalGraph = definitionDoc.getNodeGraph(nodegraphName);
860
861 if (uiName.length)
862 {
863 uiName = this.sanitizeXMLString(uiName)
864 definition.setAttribute('uiname', uiName);
865 }
866
867 if (!embedNamespace && namespace.length > 0)
868 {
869 namespace = mx.createValidName(namespace)
870 definition.setNamespace(namespace);
871 functionalGraph.setNamespace(namespace);
872
873 functionalGraph.setNodeDefString(namespace + ":" + functionalGraph.getNodeDefString())
874 }
875
876 let docString = this.options[this.DOCUMENTATION]
877 if (docString)
878 {
880 definition.setDocString(docString)
881 functionalGraph.setDocString(docString)
882 }
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920 return definitionDoc;
921 }
sanitizeXMLString(docString)
Sanitize a string to be safe to use with XML / HTML.