<commit_before>/*******************************************************************************
 * Copyright (c) 2013 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/
package org.csstudio.opibuilder.converter.writer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.csstudio.opibuilder.converter.model.EdmDouble;
import org.csstudio.opibuilder.converter.model.EdmInt;
import org.csstudio.opibuilder.converter.model.Edm_activeSymbolClass;
import org.w3c.dom.Element;

/**
 * XML conversion class for Edm_activeSymbolClass
 *
 * @author <NAME>
 */
public class Opi_activeSymbolClass extends OpiWidget {

    private static final String typeId = "linkingContainer";
    private static final String name = "EDM Symbol";
    private static final String version = "1.0";

    /**
     * Converts the Edm_activeRectangleClass to OPI Rectangle widget XML.
     */
    public Opi_activeSymbolClass(Context con, Edm_activeSymbolClass r) {
        super(con, r);
        setTypeId(typeId);
        setVersion(version);
        setName(name);

        if (r.getFile() != null) {
            new OpiString(widgetContext, "opi_file", convertFileExtention(r.getFile()));
        }
        new OpiInt(widgetContext, "border_style", 0);
        new OpiString(widgetContext, "group_name", "1");
        //single pv, no truth table
        if (!r.isTruthTable() && r.getNumPvs() == 1 && r.getControlPvs()!=null) {
            LinkedHashMap<String, Element> expressions = new LinkedHashMap<String, Element>();
            Map<String, EdmDouble> minMap = r.getMinValues().getEdmAttributesMap();
            Map<String, EdmDouble> maxMap = r.getMaxValues().getEdmAttributesMap();

            for (int i = 0; i < r.getNumStates(); i++) {
                Element valueNode = widgetContext.getDocument().createElement("value");
                double min = 0;
                double max = 0;
                if (minMap.get("" + i) != null)
                    min = minMap.get("" + i).get();
                if (maxMap.get("" + i) != null)
                    max = maxMap.get("" + i).get();
                valueNode.setTextContent("" + i);
                expressions.put("pv0>=" + min + "&&pv0<" + max, valueNode);
            }
            Element valueNode = widgetContext.getDocument().createElement("value");
            valueNode.setTextContent("0");
            expressions.put("true", valueNode);

            new OpiRule(widgetContext, "symbol_single_pv", "group_name", false, Arrays.asList(convertPVName(r
                    .getControlPvs().getEdmAttributesMap().get("0").get())), expressions);
        }else if(r.isTruthTable() && r.getNumPvs() >0 && r.getControlPvs()!=null){ //binary truth table
            LinkedHashMap<String, Element> expressions = new LinkedHashMap<String, Element>();
            Map<String, EdmDouble> minMap = r.getMinValues().getEdmAttributesMap();
            Map<String, EdmDouble> maxMap = r.getMaxValues().getEdmAttributesMap();
            StringBuilder pvsb = new StringBuilder("(");
            for(int i=0; i<r.getNumPvs(); i++){<commit_msg>EDM converter: handle invalid PVs in symbol widget<commit_after>/*******************************************************************************
 * Copyright (c) 2013 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/
package org.csstudio.opibuilder.converter.writer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.csstudio.opibuilder.converter.model.EdmDouble;
import org.csstudio.opibuilder.converter.model.EdmInt;
import org.csstudio.opibuilder.converter.model.Edm_activeSymbolClass;
import org.w3c.dom.Element;

/**
 * XML conversion class for Edm_activeSymbolClass
 *
 * @author <NAME>
 */
public class Opi_activeSymbolClass extends OpiWidget {

    private static final String typeId = "linkingContainer";
    private static final String name = "EDM Symbol";
    private static final String version = "1.0";

    /**
     * Converts the Edm_activeRectangleClass to OPI Rectangle widget XML.
     */
    public Opi_activeSymbolClass(Context con, Edm_activeSymbolClass r) {
        super(con, r);
        setTypeId(typeId);
        setVersion(version);
        setName(name);

        if (r.getFile() != null) {
            new OpiString(widgetContext, "opi_file", convertFileExtention(r.getFile()));
        }
        new OpiInt(widgetContext, "border_style", 0);
        new OpiString(widgetContext, "group_name", "1");
        // Single pv, no truth table
        if (!r.isTruthTable() && r.getNumPvs() == 1 && r.getControlPvs()!=null) {
            LinkedHashMap<String, Element> expressions = new LinkedHashMap<String, Element>();
            // Invalid PV always displays symbol zero in EDM.
            Element valueNode = widgetContext.getDocument().createElement("value");
            valueNode.setTextContent("0");
            expressions.put("pvSev0==-1", valueNode);

            Map<String, EdmDouble> minMap = r.getMinValues().getEdmAttributesMap();
            Map<String, EdmDouble> maxMap = r.getMaxValues().getEdmAttributesMap();

            for (int i = 0; i < r.getNumStates(); i++) {
                valueNode = widgetContext.getDocument().createElement("value");
                double min = 0;
                double max = 0;
                if (minMap.get("" + i) != null)
                    min = minMap.get("" + i).get();
                if (maxMap.get("" + i) != null)
                    max = maxMap.get("" + i).get();
                valueNode.setTextContent("" + i);
                expressions.put("pv0>=" + min + "&&pv0<" + max, valueNode);
            }
            // Final catch-all
            valueNode = widgetContext.getDocument().createElement("value");
            valueNode.setTextContent("0");
            expressions.put("true", valueNode);


            new OpiRule(widgetContext, "symbol_single_pv", "group_name", false, Arrays.asList(convertPVName(r
                    .getControlPvs().getEdmAttributesMap().get("0").get())), expressions);
        }else if(r.isTruthTable() && r.getNumPvs() >0 && r.getControlPvs()!=null){ //binary truth table
            LinkedHashMap<String, Element> expressions = new LinkedHashMap<String, Element>();
            Map<String, EdmDouble> minMap = r.getMinValues().getEdmAttributesMap();
            Map<String, EdmDouble> maxMap = r.getMaxValues().getEdmAttributesMap();
            StringBuilder pvsb = new StringBuilder("(");
            for(int i=0; i<r.getNumPvs(); i++){
{'fraction_non_alphanumeric': 0.1664364640883978, 'fraction_numerical': 0.006767955801104972, 'mean_word_length': 2.9763866007688082, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2022607', 'n_tokens_mistral': 2067, 'n_tokens_neox': 2014, 'n_words': 474}