//--------------------------------------------------------------------------------// // COPYRIGHT NOTICE // //--------------------------------------------------------------------------------// // Copyright (c) 2012, Instituto de Microelectronica de Sevilla (IMSE-CNM) // // // // All rights reserved. // // // // 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 IMSE-CNM 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 THE COPYRIGHT HOLDERS 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. // //--------------------------------------------------------------------------------// package xfuzzy.xfsg; import java.awt.FontMetrics; import java.awt.Graphics; import xfuzzy.lang.RulebaseCall; import xfuzzy.lang.Variable; /** * Clase que se utiliza para representar gr�ficamente el sistema difuso definido * en el lenguaje XFL3. Para realizar esta clase se han utilizado gran parte de * las funciones del m�dulo Xfedit. * * @author Jes�s Izquierdo Tena */ public class XfsgVariableDot { // ----------------------------------------------------------------------------// // MIEMBROS PUBLICOS // // ----------------------------------------------------------------------------// /** * Componente de llamada al que pertenece la variable. Null si se trata de * una variable global */ public XfsgCallComponent call; /** * Variable asociada al componente */ public Variable sysvar; /** * Posici�n horizontal del componente */ public int x; /** * Posici�n vertical del componente */ public int y; /** * Canal asignado para las conexiones */ public int channel; /** * Nivel de profundidad */ public int level; // ----------------------------------------------------------------------------// // MIEMBROS PRIVADOS // // ----------------------------------------------------------------------------// /** * Indice de la variable en el componente de llamada */ private int index; /** * Indicador del caracter de la variable asociada (entrada o salida) */ private boolean input; /** * Caracter�stica del tipo de letra */ private int descent; /** * Tipo de letra para escribir el nombre */ private FontMetrics fm; // ----------------------------------------------------------------------------// // CONSTRUCTOR // // ----------------------------------------------------------------------------// /** * Constructor de un punto asociado a una variable de una llamada */ public XfsgVariableDot(XfsgStructure structure, XfsgCallComponent call, int index, int level, boolean input) { this.fm = structure.getFontMetrics(structure.getFont()); this.descent = fm.getDescent(); this.call = call; this.index = index; this.input = input; this.sysvar = (input ? call.call.getInputVariables()[index] : call.call .getOutputVariables()[index]); this.level = level; if (call != null && !input) { this.channel = structure.counter; structure.counter++; } if (call == null && input) { this.channel = structure.counter; structure.counter++; } } /** * Constructor de un punto asociado a una variable global */ public XfsgVariableDot(XfsgStructure structure, Variable sysvar, int level, boolean input) { this.fm = structure.getFontMetrics(structure.getFont()); this.descent = fm.getDescent(); this.call = null; this.index = -1; this.input = input; this.sysvar = sysvar; this.level = level; if (call != null && !input) { this.channel = structure.counter; structure.counter++; } if (call == null && input) { this.channel = structure.counter; structure.counter++; } } /** * Verifica si el punto corresponde a una base de reglas */ public boolean isInternal() { return (call != null); } /** * Verifica si el punto corresponde a una salida */ public boolean isOutput() { return !input; } /** * Verifica si el punto corresponde a una variable global */ public boolean isGlobal() { return (call == null); } /** * Selecciona la posici�n del punto */ public void setPoint(int x, int y) { this.x = x; this.y = y; } /** * Dibuja el punto con su identificador */ public void paintDot(Graphics g) { String label = ""; if (call == null) label = sysvar.toString(); else if (call.call instanceof RulebaseCall) { RulebaseCall rbcall = (RulebaseCall) call.call; if (input) label = rbcall.getRulebase().getInputs()[index].toString(); else label = rbcall.getRulebase().getOutputs()[index].toString(); } int sw = fm.stringWidth(label); if (input) { g.drawString(label, x - sw - 2, y - descent - 4); g.fillRect(x - 5, y - 2, 5, 5); if (call == null) { new XfsgArchitecturesSimulink(label, x - 5, y - 2, 1); // System.out.println("var "+label); } } else { g.drawString(label, x + 2, y - descent - 4); g.fillRect(x, y - 2, 5, 5); if (call == null) { new XfsgArchitecturesSimulink(label, x, y - 2, 2); // System.out.println("var "+label); } } } /** * Verifica si el punto no est� enlazado */ public boolean isNull() { return (sysvar == null || sysvar.equals("NULL")); } /** * Verifica si el punto puede ser origen de un enlace */ public boolean isOrigin() { return (call == null && input) || (call != null && !input); } }