/*++

Copyright (C) 2024 3MF Consortium (Original Author)

All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.1-develop.

Abstract: This is an autogenerated Java file in order to allow an easy
 use of the 3MF Library

Interface version: 2.5.0

*/

package lib3mf;

import com.sun.jna.Library;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.Pointer;


import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;

public class FunctionReference extends Base {

	public FunctionReference(Lib3MFWrapper wrapper, Pointer handle) {
		super(wrapper, handle);
	}

	/**
	 * Returns the UniqueResourceID of the Function. Only functions with a 'pos'-input are allowed.
	 *
	 * @return returns the UniqueResourceID.
	 * @throws Lib3MFException
	 */
	public int getFunctionResourceID() throws Lib3MFException {
		Pointer bufferUniqueResourceID = new Memory(4);
		mWrapper.checkError(this, mWrapper.lib3mf_functionreference_getfunctionresourceid.invokeInt(new java.lang.Object[]{mHandle, bufferUniqueResourceID}));
		return bufferUniqueResourceID.getInt(0);
	}

	/**
	 * Sets the UniqueResourceID to refer to.
	 *
	 * @param uniqueResourceID UniqueResourceID of the function
	 * @throws Lib3MFException
	 */
	public void setFunctionResourceID(int uniqueResourceID) throws Lib3MFException {
		mWrapper.checkError(this, mWrapper.lib3mf_functionreference_setfunctionresourceid.invokeInt(new java.lang.Object[]{mHandle, uniqueResourceID}));
	}

	/**
	 * Returns the transformation matrix into the coordinate system of the referenced Function.
	 *
	 * @return the transformation matrix
	 * @throws Lib3MFException
	 */
	public Transform getTransform() throws Lib3MFException {
		Pointer bufferTransform = new Memory(Transform.SIZE);
		mWrapper.checkError(this, mWrapper.lib3mf_functionreference_gettransform.invokeInt(new java.lang.Object[]{mHandle, bufferTransform}));
		Transform transform = new Transform();
		transform.readFromPointer(bufferTransform, 0);
		return transform;
	}

	/**
	 * Sets the transformation matrix into the coordinate system of the referenced Function.
	 *
	 * @param transform new transformation matrix
	 * @throws Lib3MFException
	 */
	public void setTransform(Transform transform) throws Lib3MFException {
		Pointer bufferTransform = new Memory(Transform.SIZE);
		transform.writeToPointer(bufferTransform, 0);
		mWrapper.checkError(this, mWrapper.lib3mf_functionreference_settransform.invokeInt(new java.lang.Object[]{mHandle, bufferTransform}));
	}

	/**
	 * Returns the name of the function output channel to use.
	 *
	 * @return the name of the function output channel
	 * @throws Lib3MFException
	 */
	public String getChannelName() throws Lib3MFException {
		Pointer bytesNeededChannelName = new Memory(4);
		mWrapper.checkError(this, mWrapper.lib3mf_functionreference_getchannelname.invokeInt(new java.lang.Object[]{mHandle, 0, bytesNeededChannelName, null}));
		int sizeChannelName = bytesNeededChannelName.getInt(0);
		Pointer bufferChannelName = new Memory(sizeChannelName);
		mWrapper.checkError(this, mWrapper.lib3mf_functionreference_getchannelname.invokeInt(new java.lang.Object[]{mHandle, sizeChannelName, bytesNeededChannelName, bufferChannelName}));
		return new String(bufferChannelName.getByteArray(0, sizeChannelName - 1), StandardCharsets.UTF_8);
	}

	/**
	 * Sets the name of the function output channel to use.
	 *
	 * @param channelName new name of the function output channel
	 * @throws Lib3MFException
	 */
	public void setChannelName(String channelName) throws Lib3MFException {
		byte[] bytesChannelName = channelName.getBytes(StandardCharsets.UTF_8);
		Memory bufferChannelName = new Memory(bytesChannelName.length + 1);
		bufferChannelName.write(0, bytesChannelName, 0, bytesChannelName.length);
		bufferChannelName.setByte(bytesChannelName.length, (byte)0);
		mWrapper.checkError(this, mWrapper.lib3mf_functionreference_setchannelname.invokeInt(new java.lang.Object[]{mHandle, bufferChannelName}));
	}

	/**
	 * Sets the minimal feature size as a hint for the function evaluator
	 *
	 * @param minFeatureSize minimal feature size
	 * @throws Lib3MFException
	 */
	public void setMinFeatureSize(double minFeatureSize) throws Lib3MFException {
		mWrapper.checkError(this, mWrapper.lib3mf_functionreference_setminfeaturesize.invokeInt(new java.lang.Object[]{mHandle, minFeatureSize}));
	}

	/**
	 * Returns the minimal feature size as a hint for the function evaluator
	 *
	 * @return minimal feature size
	 * @throws Lib3MFException
	 */
	public double getMinFeatureSize() throws Lib3MFException {
		Pointer bufferMinFeatureSize = new Memory(8);
		mWrapper.checkError(this, mWrapper.lib3mf_functionreference_getminfeaturesize.invokeInt(new java.lang.Object[]{mHandle, bufferMinFeatureSize}));
		return bufferMinFeatureSize.getDouble(0);
	}

	/**
	 * Sets the fallback value to use if the function evaluation fails (e.g. evaluates to NaN or Inf).
	 *
	 * @param fallBackValue fallback value
	 * @throws Lib3MFException
	 */
	public void setFallBackValue(double fallBackValue) throws Lib3MFException {
		mWrapper.checkError(this, mWrapper.lib3mf_functionreference_setfallbackvalue.invokeInt(new java.lang.Object[]{mHandle, fallBackValue}));
	}

	/**
	 * Returns the fallback value to use if the function evaluation fails (e.g. evaluates to NaN or Inf).
	 *
	 * @return fallback value
	 * @throws Lib3MFException
	 */
	public double getFallBackValue() throws Lib3MFException {
		Pointer bufferFallBackValue = new Memory(8);
		mWrapper.checkError(this, mWrapper.lib3mf_functionreference_getfallbackvalue.invokeInt(new java.lang.Object[]{mHandle, bufferFallBackValue}));
		return bufferFallBackValue.getDouble(0);
	}


}

