Skip to content
Snippets Groups Projects
AvatarPanelDrawer.java 40.8 KiB
Newer Older
/* Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille
 * 
 * ludovic.apvrille AT enst.fr
 * 
 * This software is a computer program whose purpose is to allow the
 * edition of TURTLE analysis, design and deployment diagrams, to
 * allow the generation of RT-LOTOS or Java code from this diagram,
 * and at last to allow the analysis of formal validation traces
 * obtained from external tools, e.g. RTL from LAAS-CNRS and CADP
 * from INRIA Rhone-Alpes.
 * 
 * This software is governed by the CeCILL  license under French law and
 * abiding by the rules of distribution of free software.  You can  use,
 * modify and/ or redistribute the software under the terms of the CeCILL
 * license as circulated by CEA, CNRS and INRIA at the following URL
 * "http://www.cecill.info".
 * 
 * As a counterpart to the access to the source code and  rights to copy,
 * modify and redistribute granted by the license, users are provided only
 * with a limited warranty  and the software's author,  the holder of the
 * economic rights,  and the successive licensors  have only  limited
 * liability.
 * 
 * In this respect, the user's attention is drawn to the risks associated
 * with loading,  using,  modifying and/or developing or reproducing the
 * software by the user in light of its specific status of free software,
 * that may mean  that it is complicated to manipulate,  and  that  also
 * therefore means  that it is reserved for developers  and  experienced
 * professionals having in-depth computer knowledge. Users are therefore
 * encouraged to load and test the software's suitability as regards their
 * requirements in conditions enabling the security of their systems and/or
 * data to be ensured and,  more generally, to use and operate it in the
 * same conditions as regards security.
 * 
 * The fact that you are presently reading this means that you have had
 * knowledge of the CeCILL license and that you accept its terms.
 */



 
package ui;


import avatartranslator.*;
import myutil.TraceManager;
import ui.avatarbd.*;
import ui.avatarsmd.*;

import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

/**
 * Class AvatarPanelDrawer
 * Possible states of TGComponent
 * Creation: 12/06/2024
 * @author Ludovic APVRILLE
 * @see avatartranslator.AvatarSpecification
 */
public class AvatarPanelDrawer {

	private boolean hasCrypto = false;

	public AvatarPanelDrawer() {

	}

	public void drawPanel(AvatarSpecification avspec, AvatarDesignPanel adp, boolean useOriginalValuesFirst) {
		//
		// Check Errors in AVSPEC
		avspec.removeAnomalies();
		TraceManager.addDev("Checking syntax of avatar spec.");
		ArrayList<AvatarError> list = AvatarSyntaxChecker.checkSyntaxErrors(avspec);
		for (AvatarError error : list) {
			TraceManager.addDev("\n*********** Error: " + error.toString() + "\n\n");
		}
		//TraceManager.addDev("Check done. " + checkingErrors.size() + " errors found\nAvatar Spec:\n" + avspec.toString());

		TraceManager.addDev("Avspec to be drawn:" + avspec.toStringRecursive(false));


		// Go for drawing!
		hasCrypto = false;
		//Map<String, Set<String>> originDestMap = new HashMap<String, Set<String>>();
		Map<String, AvatarBDBlock> blockMap = new HashMap<String, AvatarBDBlock>();
		if (adp == null) {
			return;
		}
		if (avspec == null) {
			return;
		}
		AvatarBDPanel abd = adp.abdp;

		//Find all blocks, create nested blocks starting from top left
		int xpos = 10;
		int ypos = 40;

		// Create blocks recursively, starting from top level ones with no father
		// Lowest level blocks should be 100x100, next should be 100x(number of children*100+50)...etc,
		// Find level #, 0 refers to no father, etc
		Map<AvatarBlock, Integer> blockLevelMap = new HashMap<AvatarBlock, Integer>();
		Map<AvatarBlock, Integer> blockSizeMap = new HashMap<AvatarBlock, Integer>();
		Map<AvatarBlock, Integer> blockIncMap = new HashMap<AvatarBlock, Integer>();
		int maxLevel = 0;
		for (AvatarBlock ab : avspec.getListOfBlocks()) {
			int level = 0;
			AvatarBlock block = ab;
			while (block.getFather() != null) {
				if (blockSizeMap.containsKey(block.getFather())) {
					blockSizeMap.put(block.getFather(), blockSizeMap.get(block.getFather()) + 1);
				} else {
					blockSizeMap.put(block.getFather(), 1);
					blockIncMap.put(block.getFather(), 10);
				}
				level++;
				block = block.getFather();
			}
			if (level > maxLevel) {
				maxLevel = level;
			}
			if (!blockSizeMap.containsKey(block)) {
				blockSizeMap.put(block, 0);
				blockIncMap.put(block, 10);
			}
			blockLevelMap.put(ab, level);
		}


		for (int level = 0; level < maxLevel + 1; level++) {
			for (AvatarBlock ab : avspec.getListOfBlocks()) {
				if (blockLevelMap.get(ab) == level) {
					if (level == 0) {
						TraceManager.addDev("New block at level 0");
						AvatarBDBlock bl = new AvatarBDBlock(xpos, ypos, abd.getMinX(), abd.getMaxX(), abd.getMinY(), abd.getMaxY(), false,
								null, abd);
						if ((ab.getReferenceObject() != null) && (ab.getReferenceObject() instanceof CDElement)) {
							CDElement cd = (CDElement) ab.getReferenceObject();
							bl.setUserResize(cd.getX(), cd.getY(), cd.getWidth(), cd.getHeight());
							abd.addComponent(bl, cd.getX(), cd.getY(), false, true);
						} else {
							abd.addComponent(bl, xpos, ypos, false, true);
							bl.resize(100 * blockSizeMap.get(ab) + 100, 100 + (maxLevel - level) * 50);
						}
						drawBlockProperties(avspec, ab, bl, useOriginalValuesFirst);
						AvatarSMDPanel smp = adp.getAvatarSMDPanel(bl.getValue());
						//TraceManager.addDev("\nBuilding state machine of block " + ab.getName() + " smd:" + ab.getStateMachine().toString() + "\n" +
						//       "\n");
						buildStateMachine(ab, bl, smp, useOriginalValuesFirst);
						//TraceManager.addDev("Putting in block")
						blockMap.put(bl.getValue().split("__")[bl.getValue().split("__").length - 1], bl);
						xpos += 100 * blockSizeMap.get(ab) + 200;
					} else {
						TraceManager.addDev("New block at level " + level);
						AvatarBDBlock father =
								blockMap.get(ab.getFather().getName().split("__")[ab.getFather().getName().split("__").length - 1]);
						TraceManager.addDev("Father name: " + father.getBlockName());
						if (father == null) {
							//
							continue;
						}
						AvatarBDBlock bl = new AvatarBDBlock(father.getX() + blockIncMap.get(ab.getFather()), father.getY() + 10,
								abd.getMinX(), abd.getMaxX(), abd.getMinY(), abd.getMaxY(), false, father, abd);
                        /*if ((ab.getReferenceObject() != null) && (ab.getReferenceObject() instanceof CDElement)) {
                            CDElement cd = (CDElement) ab.getReferenceObject();
                            bl.setUserResize(cd.getX(), cd.getY(), cd.getWidth(), cd.getHeight());
                            abd.addComponent(bl, cd.getX(), cd.getY(), false, true);
                        } else {*/
						//abd.addComponent(bl, xpos, ypos, false, true);
						//bl.resize(100 * blockSizeMap.get(ab) + 100, 100 + (maxLevel - level) * 50);
						//}
						abd.addComponent(bl, father.getX() + blockIncMap.get(ab.getFather()), father.getY() + 10, false, true);
						int size = 100;
						if ((ab.getReferenceObject() != null) && (ab.getReferenceObject() instanceof CDElement)) {
							CDElement cd = (CDElement) ab.getReferenceObject();
							bl.setUserResize(cd.getX(), cd.getY(), cd.getWidth(), cd.getHeight());
						} else {

							if (blockSizeMap.containsKey(ab)) {
								size = 100 * blockSizeMap.get(ab) + 50;
							}
							bl.resize(size, 100 + (maxLevel - level) * 50);
						}
						drawBlockProperties(avspec, ab, bl, useOriginalValuesFirst);
						abd.attach(bl);
						AvatarSMDPanel smp = adp.getAvatarSMDPanel(bl.getValue());
						buildStateMachine(ab, bl, smp, useOriginalValuesFirst);
						blockMap.put(bl.getValue().split("__")[bl.getValue().split("__").length - 1], bl);
						blockIncMap.put(ab.getFather(), blockIncMap.get(ab.getFather()) + size + 10);
					}
				}
			}
		}

		// Data types
		// Put them on the lower part
Loading
Loading full blame...