/*
 * Copyright (c) 2013, Linz Center of Mechatronics GmbH (LCM), web: www.lcm.at
 * All rights reserved.
 */
/*
 * This file is licensed according to the BSD 3-clause license as follows:
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * 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.
 *     * Neither the name of the "Linz Center of Mechatronics GmbH" and "LCM" nor
 *       the names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 * 
 * 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 "Linz Center of Mechatronics GmbH" 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 is part of X2C. web: x2c.lcm.at
 * $LastChangedRevision: 4457 $
 * $LastChangedDate:: 2026-08-13 18:59:23 +0200#$
 */
/* USERCODE-BEGIN:Description */
/* Description: */
/* USERCODE-END:Description */

package at.lcm.x2c.library.math;

import at.lcm.x2c.core.structure.*;
import at.lcm.bu21.general.dtypes.*;

/* USERCODE-BEGIN:Imports */
/* USERCODE-END:Imports */

@SuppressWarnings("unused")
public class ConvFnc_Sum_FiP16 extends JavaConversionFunction {
    private static final long serialVersionUID = 1L;

    @Override
    public void convertMaskToImplementation() throws Exception {
        MaskComboBox In1MaskVal = (MaskComboBox)this.getMaskParameter("In1").getMaskDataType();
        TString In1MaskData = (TString)In1MaskVal.getData();
        String mp_In1 = In1MaskData.getString();
        MaskComboBox In2MaskVal = (MaskComboBox)this.getMaskParameter("In2").getMaskDataType();
        TString In2MaskData = (TString)In2MaskVal.getData();
        String mp_In2 = In2MaskData.getString();
        MaskComboBox In3MaskVal = (MaskComboBox)this.getMaskParameter("In3").getMaskDataType();
        TString In3MaskData = (TString)In3MaskVal.getData();
        String mp_In3 = In3MaskData.getString();
        MaskComboBox In4MaskVal = (MaskComboBox)this.getMaskParameter("In4").getMaskDataType();
        TString In4MaskData = (TString)In4MaskVal.getData();
        String mp_In4 = In4MaskData.getString();
        MaskComboBox In5MaskVal = (MaskComboBox)this.getMaskParameter("In5").getMaskDataType();
        TString In5MaskData = (TString)In5MaskVal.getData();
        String mp_In5 = In5MaskData.getString();
        MaskComboBox In6MaskVal = (MaskComboBox)this.getMaskParameter("In6").getMaskDataType();
        TString In6MaskData = (TString)In6MaskVal.getData();
        String mp_In6 = In6MaskData.getString();
        MaskComboBox In7MaskVal = (MaskComboBox)this.getMaskParameter("In7").getMaskDataType();
        TString In7MaskData = (TString)In7MaskVal.getData();
        String mp_In7 = In7MaskData.getString();
        MaskComboBox In8MaskVal = (MaskComboBox)this.getMaskParameter("In8").getMaskDataType();
        TString In8MaskData = (TString)In8MaskVal.getData();
        String mp_In8 = In8MaskData.getString();

        TNumeric signCtrVal = this.getImplementationParameterData("sign");
        double cp_sign = Double.NaN;

        /* ATTENTION: */
        /* The M2I conversion function may either use the mp_* or *MaskVal value to get the Mask Parameter value */
        /* For new or updated implementations, the mp_* value shall be used where possible */
        /* Currently, the mp_* value cannot be used for getting non-scalar Mask Parameter data but will return only the first element for these */
        /* The Implementation Parameter assignment variables cp_* can and shall be used for all Implementation Parameter data types */

        /* INFO: Implementation data assignment for array types when using the cp_* variables */
        /* If the cp_* parameter is a FLASH ARRAY, the cp_* variable is assigned an array type but without an actual array */
        /* The M2I conversion function has to assign an array with the correct size and fill it with content */
        /* If the cp_* parameter is a RAM ARRAY, the cp_* variable is assigned an array with the correct size */
        /* The first element is assigned an invalid value while the other elements are (auto)initialized with zero */
        /* The M2I conversion function has to fill the array with content */

        /* Mask parameter values */
        /* mp_In1 OR In1MaskVal (String) */
        /* mp_In2 OR In2MaskVal (String) */
        /* mp_In3 OR In3MaskVal (String) */
        /* mp_In4 OR In4MaskVal (String) */
        /* mp_In5 OR In5MaskVal (String) */
        /* mp_In6 OR In6MaskVal (String) */
        /* mp_In7 OR In7MaskVal (String) */
        /* mp_In8 OR In8MaskVal (String) */

        /* USERCODE-BEGIN:ConvMaskToImplementation */
          int mask = 0;
          
          if (In1MaskVal.getValue().equals("+")){
        	  mask = 1;
          }else if(In1MaskVal.getValue().equals("-")){
        	  mask = 2;	
          }
          if (In2MaskVal.getValue().equals("+")){
        	  mask += (1<<2);
          }else if(In2MaskVal.getValue().equals("-")){
        	  mask += (2<<2);	
          }  	  
          if (In3MaskVal.getValue().equals("+")){
        	  mask += (1<<4);
          }else if(In3MaskVal.getValue().equals("-")){
        	  mask += (2<<4);	
          }
          if (In4MaskVal.getValue().equals("+")){
        	  mask += (1<<6);
          }else if(In4MaskVal.getValue().equals("-")){
        	  mask += (2<<6);	
          }
          if (In5MaskVal.getValue().equals("+")){
        	  mask += (1<<8);
          }else if(In5MaskVal.getValue().equals("-")){
        	  mask += (2<<8);	
          }
          if (In6MaskVal.getValue().equals("+")){
        	  mask += (1<<10);
          }else if(In6MaskVal.getValue().equals("-")){
        	  mask += (2<<10);	
          }
          if (In7MaskVal.getValue().equals("+")){
        	  mask += (1<<12);
          }else if(In7MaskVal.getValue().equals("-")){
        	  mask += (2<<12);	
          }
          if (In8MaskVal.getValue().equals("+")){
        	  mask += (1<<14);
          }else if(In8MaskVal.getValue().equals("-")){
        	  mask += (2<<14);	
          }       
          
          signCtrVal.setReal(0, 0, mask);
          
        /* USERCODE-END:ConvMaskToImplementation */

        /* Implementation Parameter values */
        /* cp_sign OR signCtrVal (Value) */

        if (Double.isNaN(cp_sign)) {
            this.setImplementationParameterData("sign", signCtrVal);
        } else {
            this.setImplementationParameterData("sign", new TNumeric(cp_sign));
        }
    }

    @Override
    public void convertImplementationToMask() throws Exception {
        MaskComboBox In1MaskVal = (MaskComboBox)this.getMaskParameter("In1").getMaskDataType();
        TString In1MaskData = (TString)In1MaskVal.getData();
        String mp_In1 = null;
        MaskComboBox In2MaskVal = (MaskComboBox)this.getMaskParameter("In2").getMaskDataType();
        TString In2MaskData = (TString)In2MaskVal.getData();
        String mp_In2 = null;
        MaskComboBox In3MaskVal = (MaskComboBox)this.getMaskParameter("In3").getMaskDataType();
        TString In3MaskData = (TString)In3MaskVal.getData();
        String mp_In3 = null;
        MaskComboBox In4MaskVal = (MaskComboBox)this.getMaskParameter("In4").getMaskDataType();
        TString In4MaskData = (TString)In4MaskVal.getData();
        String mp_In4 = null;
        MaskComboBox In5MaskVal = (MaskComboBox)this.getMaskParameter("In5").getMaskDataType();
        TString In5MaskData = (TString)In5MaskVal.getData();
        String mp_In5 = null;
        MaskComboBox In6MaskVal = (MaskComboBox)this.getMaskParameter("In6").getMaskDataType();
        TString In6MaskData = (TString)In6MaskVal.getData();
        String mp_In6 = null;
        MaskComboBox In7MaskVal = (MaskComboBox)this.getMaskParameter("In7").getMaskDataType();
        TString In7MaskData = (TString)In7MaskVal.getData();
        String mp_In7 = null;
        MaskComboBox In8MaskVal = (MaskComboBox)this.getMaskParameter("In8").getMaskDataType();
        TString In8MaskData = (TString)In8MaskVal.getData();
        String mp_In8 = null;

        TNumeric signCtrVal = this.getImplementationParameterData("sign");
        double cp_sign = signCtrVal.getReal(0, 0);

        /* ATTENTION: */
        /* The I2M conversion function may either use the cp_* or *CtrlVal value to get the Implementation Parameter value */
        /* For new or updated implementations, the cp_* value shall be used for all Implementation Parameter data types */
        /* The Mask Parameter assignment variables cp_* shall be used where possible */
        /* Currently, the mp_* variable assignment value cannot be used for setting non-scalar Mask Parameter data */

        /* Implementation Parameter values */
        /* cp_sign OR signCtrVal (Value) */

        /* USERCODE-BEGIN:ConvImplementationToMask */
          int sign;
          int mask = 0;
          
          /* get controller parameter */
          mask = (int)signCtrVal.getReal(0, 0);
          
          /* calculate mask parameters */
          sign = mask & 0x0003;
          if (sign==1){
        	  In1MaskData = new TString("+");
          }else if (sign == 2){
        	  In1MaskData = new TString("-");
          }else{
        	  In1MaskData = new TString("0");
          }
          
          sign = (mask>>2) & 0x0003;
          if (sign == 1){
        	  In2MaskData = new TString("+");
          }else if (sign == 2){
        	  In2MaskData = new TString("-");
          }else{
        	  In2MaskData = new TString("0");
          } 

          sign = (mask>>4) & 0x0003;
          if (sign == 1){
        	  In3MaskData = new TString("+");
          }else if (sign == 2){
        	  In3MaskData = new TString("-");
          }else{
        	  In3MaskData = new TString("0");
          } 
          
          sign = (mask>>6) & 0x0003;
          if (sign == 1){
        	  In4MaskData = new TString("+");
          }else if (sign == 2){
        	  In4MaskData = new TString("-");
          }else{
        	  In4MaskData = new TString("0");
          }
          
          sign = (mask>>8) & 0x0003;
          if (sign == 1){
        	  In5MaskData = new TString("+");
          }else if (sign == 2){
        	  In5MaskData = new TString("-");
          }else{
        	  In5MaskData = new TString("0");
          } 
          
          sign = (mask>>10) & 0x0003;
          if (sign == 1){
        	  In6MaskData = new TString("+");
          }else if (sign == 2){
        	  In6MaskData = new TString("-");
          }else{
        	  In6MaskData = new TString("0");
          }
          
          sign = (mask>>12) & 0x0003;
          if (sign == 1){
        	  In7MaskData = new TString("+");
          }else if (sign == 2){
        	  In7MaskData = new TString("-");
          }else{
        	  In7MaskData = new TString("0");
          } 
          
          sign = (mask>>14) & 0x0003;
          if (sign == 1){
        	  In8MaskData = new TString("+");
          }else if (sign == 2){
        	  In8MaskData = new TString("-");
          }else{
        	  In8MaskData = new TString("0");
          }
          
        /* USERCODE-END:ConvImplementationToMask */

        /* Mask parameter values */
        /* mp_In1 OR In1MaskVal (String) */
        /* mp_In2 OR In2MaskVal (String) */
        /* mp_In3 OR In3MaskVal (String) */
        /* mp_In4 OR In4MaskVal (String) */
        /* mp_In5 OR In5MaskVal (String) */
        /* mp_In6 OR In6MaskVal (String) */
        /* mp_In7 OR In7MaskVal (String) */
        /* mp_In8 OR In8MaskVal (String) */

        if (mp_In1 == null) {
            this.getMaskParameter("In1").setValue(In1MaskData.getString());
        } else {
            this.getMaskParameter("In1").setValue(mp_In1);
        }
        if (mp_In2 == null) {
            this.getMaskParameter("In2").setValue(In2MaskData.getString());
        } else {
            this.getMaskParameter("In2").setValue(mp_In2);
        }
        if (mp_In3 == null) {
            this.getMaskParameter("In3").setValue(In3MaskData.getString());
        } else {
            this.getMaskParameter("In3").setValue(mp_In3);
        }
        if (mp_In4 == null) {
            this.getMaskParameter("In4").setValue(In4MaskData.getString());
        } else {
            this.getMaskParameter("In4").setValue(mp_In4);
        }
        if (mp_In5 == null) {
            this.getMaskParameter("In5").setValue(In5MaskData.getString());
        } else {
            this.getMaskParameter("In5").setValue(mp_In5);
        }
        if (mp_In6 == null) {
            this.getMaskParameter("In6").setValue(In6MaskData.getString());
        } else {
            this.getMaskParameter("In6").setValue(mp_In6);
        }
        if (mp_In7 == null) {
            this.getMaskParameter("In7").setValue(In7MaskData.getString());
        } else {
            this.getMaskParameter("In7").setValue(mp_In7);
        }
        if (mp_In8 == null) {
            this.getMaskParameter("In8").setValue(In8MaskData.getString());
        } else {
            this.getMaskParameter("In8").setValue(mp_In8);
        }
    }
}
