Skip to content
Snippets Groups Projects
AvatarPanelDrawer.java 49.2 KiB
Newer Older
		}
	}

	public void drawBlockProperties(AvatarSpecification as, AvatarBlock ab, AvatarBDBlock bl, boolean useOriginalValues) {

		// Different characteristics
		if (ab.getReferenceObject() instanceof TGComponent) {
			TraceManager.addDev("*** Handling characteristics of block " + ab.getName() + " stereo:" + ab.getStereotype());
			TGComponent refComp = (TGComponent) ab.getReferenceObject();

			Color c = null;
			String colorS = ab.getCharacteristic("color");
			if (colorS != null) {
				TraceManager.addDev("Found color for block: " + colorS);
				c = new Color(Integer.parseInt(colorS));
			} else {
				c = refComp.getCurrentColor();
				if (c == null) {
					c = bl.getMainColor();
				}
			}

			if (ab.getGlobalCode() != null) {
				bl.setGlobalCode(ab.getGlobalCode());
			}

			String stereo = ab.getStereotype();
			bl.addStereotype(stereo, c.getRGB());

		}

		// Signals
		for (avatartranslator.AvatarSignal sig : ab.getSignals()) {
			String name = sig.getName().split("__")[sig.getName().split("__").length - 1];

			//           sig.setName(name);
			String[] types;
			String[] typeIds;
			List<AvatarAttribute> listOfAttributes;
			if (useOriginalValues && (sig.getListOfOriginalAttributes().size() > 0 || sig.getListOfOriginalReturnAttributes().size() > 0)) {
				listOfAttributes = sig.getListOfOriginalAttributes();
			} else {
				listOfAttributes = sig.getListOfAttributes();
			}
			int i = 0;
			types = new String[listOfAttributes.size()];
			typeIds = new String[listOfAttributes.size()];
			for (AvatarAttribute attr : listOfAttributes) {
				if (attr.isDataType()) {
					types[i] = attr.getDataType().getName();
				} else {
					types[i] = attr.getType().getStringType();
				}
				typeIds[i] = attr.getName();
				i++;
			}

			//TraceManager.addDev("Adding signal " + sig + " with name=" + name);
			bl.addSignal(new ui.AvatarSignal(sig.getInOut(), name, types, typeIds));
		}

		bl.setValueWithChange(ab.getName().split("__")[ab.getName().split("__").length - 1]);

		TraceManager.addDev("Setting name of block: " + bl.getBlockName());

		if (useOriginalValues) {
			//TraceManager.addDev("** Attributes: Using original attributes");
			for (AvatarAttribute attr : ab.getOriginalAttributes()) {
				//TraceManager.addDev("Handling original attributes");
				//TraceManager.addDev("\tHandling attribute: " + attr);
				if (attr.isDataType()) {
					bl.addAttribute(new TAttribute(attr.isConstant() ? TAttribute.CONSTANT : TAttribute.VARIABLE, 0, attr.getName(),
							attr.getProvidedInitialValue(),
							attr.getDataType().getName()));
				} else {
					int type = TAttribute.OTHER;
					if (attr.getType() == AvatarType.BOOLEAN) {
						type = TAttribute.BOOLEAN;
					}
					if (attr.getType() == AvatarType.INTEGER) {
						type = TAttribute.NATURAL;
					}
					if (attr.getType() == AvatarType.TIMER) {
						type = TAttribute.TIMER;
					}
					if (attr.hasInitialValue()) {
						bl.addAttribute(new TAttribute(attr.isConstant() ? TAttribute.CONSTANT : TAttribute.VARIABLE, 0, attr.getName(),
								attr.getInitialValue(), type));
						bl.addAttribute(new TAttribute(attr.isConstant() ? TAttribute.CONSTANT : TAttribute.VARIABLE, 0, attr.getName(),
								"", type));
					}
				}

				if (attr.getName().contains("key_") || attr.getName().contains("privKey_")) {
					hasCrypto = true;
					bl.addCryptoElements();
				}
			}
		} else {
			//TraceManager.addDev("** Handling regular attributes");
			for (AvatarAttribute attr : ab.getAttributes()) {
				//TraceManager.addDev("\tHandling attribute: " + attr);
				int type = TAttribute.OTHER;
				if (attr.getType() == AvatarType.BOOLEAN) {
					type = TAttribute.BOOLEAN;
				}
				if (attr.getType() == AvatarType.INTEGER) {
					type = TAttribute.NATURAL;
				}
				if (attr.getType() == AvatarType.TIMER) {
					type = TAttribute.TIMER;
				}
				if (attr.hasInitialValue()) {
					bl.addAttribute(new TAttribute(attr.isConstant() ? TAttribute.CONSTANT : TAttribute.VARIABLE, 0, attr.getName(),
							attr.getInitialValue(), type));
					bl.addAttribute(new TAttribute(attr.isConstant() ? TAttribute.CONSTANT : TAttribute.VARIABLE, attr.getName(), "",
							type));
				}
				if (attr.getName().contains("key_") || attr.getName().contains("privKey_")) {
					hasCrypto = true;
					bl.addCryptoElements();
				}
			}
		}

		for (AvatarAttribute attr : ab.getConstants()) {
			int type = 5;
			if (attr.getType() == AvatarType.BOOLEAN) {
				type = 4;
			}
			if (attr.getType() == AvatarType.INTEGER) {
				type = 0;
			}
			if (attr.hasInitialValue()) {
				bl.addAttribute(new TAttribute(attr.isConstant() ? TAttribute.CONSTANT : TAttribute.VARIABLE, 0, attr.getName(),
						attr.getInitialValue(), type));
				bl.addAttribute(new TAttribute(attr.isConstant() ? TAttribute.CONSTANT : TAttribute.VARIABLE, 0, attr.getName(),
						attr.getType().getDefaultInitialValue(), type));
			}
			if (attr.getName().contains("key_") || attr.getName().contains("privKey_")) {
				hasCrypto = true;
				bl.addCryptoElements();
			}
		}

		for (avatartranslator.AvatarMethod method : ab.getMethods()) {
			String methodId = "";
			if (useOriginalValues) {
				methodId = method.toOriginalString().replaceAll(" = 0", "");
			} else {
				methodId = method.toString().replaceAll(" = 0", "");
			}
			String result = methodId.replaceAll(" = false", "");
			TraceManager.addDev("Adding method:" + result);

			//TraceManager.addDev("Extra types are:" + as.getExtraTypes().toString());
			bl.addMethodIfApplicable(result, as.getExtraTypes());
		}
	}

	public String getLastKeyword(String s) {
		return s.split("__")[s.split("__").length - 1];
	}


	public void makeSecurityPragmas(AvatarSpecification avspec, AvatarDesignPanel adp) {
		AvatarBDPanel abd = adp.abdp;
		int dec = 250;
		int xPos = 100, yPos = 500;
		TGComponent tgcO;

		HashMap<Object, AvatarBDPragma> setOfNewSecurityPragmaComponent = new HashMap<>();

		for (AvatarPragma p : avspec.getPragmas()) {

			//    arr[i] = p.getName();
			TraceManager.addDev("Handling security pragma: " + p.getName());
			Object o = p.getReferenceObject();

			AvatarBDPragma comp = null;
			if (o != null) {
				//TraceManager.addDev(" - - - - Pragma " + pragmaS + " has reference object " + o.toString());
				// already created?
				comp = setOfNewSecurityPragmaComponent.get(o);
				if ((o instanceof TGComponent) && (comp == null))
					tgcO = (TGComponent)o;
				else tgcO = null;
			} else {
				tgcO = null;
			}
			if (comp == null) {
				// We must create it
				if (tgcO != null) {
					xPos = tgcO.getX();
					yPos = tgcO.getY();
				}
				comp = new AvatarBDPragma(xPos, yPos, abd.getMinX(), abd.getMaxX(), abd.getMinY(), abd.getMaxY(), false, null, abd);
				xPos = xPos + dec;
				yPos = yPos + dec;
				addComponent(p, abd, comp, xPos, yPos, false, true);
				if (tgcO != null) {
					comp.resize(tgcO.getWidth(), tgcO.getHeight());
				}
				setOfNewSecurityPragmaComponent.put(o, comp);
			}

			String value = comp.getValue();
			value = value + "\n" + p.getAdvancedValue();
			comp.setValue(value);
			comp.makeValue();

		}
	}

	public void makePerformancePragmas(AvatarSpecification avspec, AvatarDesignPanel adp) {
		AvatarBDPanel abd = adp.abdp;
		int dec = 250;
		int xPos = 100, yPos = 500;
		TGComponent tgcO;

		HashMap<Object, AvatarBDPerformancePragma> setOfNewPerformancePragmaComponent = new HashMap<>();

		for (AvatarPragmaLatency p : avspec.getLatencyPragmas()) {

			//    arr[i] = p.getName();
			TraceManager.addDev("Handling performance pragma: " + p.getName());
			Object o = p.getReferenceObject();

			AvatarBDPerformancePragma comp = null;
			if (o != null) {
				//TraceManager.addDev(" - - - - Pragma " + pragmaS + " has reference object " + o.toString());
				// already created?
				comp = setOfNewPerformancePragmaComponent.get(o);
				if ((o instanceof TGComponent) && (comp == null))
					tgcO = (TGComponent)o;
				else tgcO = null;
			} else {
				tgcO = null;
			}
			if (comp == null) {
				// We must create it
				if (tgcO != null) {
					xPos = tgcO.getX();
					yPos = tgcO.getY();
				}
				comp = new AvatarBDPerformancePragma(xPos, yPos, abd.getMinX(), abd.getMaxX(), abd.getMinY(), abd.getMaxY(), false, null, abd);
				xPos = xPos + dec;
				yPos = yPos + dec;
				addComponent(p, abd, comp, xPos, yPos, false, true);
				if (tgcO != null) {
					comp.resize(tgcO.getWidth(), tgcO.getHeight());
				}
				setOfNewPerformancePragmaComponent.put(o, comp);
			}

			String value = comp.getValue();
			value = value + "\n" + p.getAdvancedValue();
			comp.setValue(value);
			comp.makeValue();

		}
	}


	public void makeNotes(AvatarSpecification avspec, AvatarDesignPanel adp) {
		AvatarBDPanel abd = adp.abdp;
		int dec = 250;
		int xPos = 100, yPos = 500;
		TGComponent tgcO = null;
		TGCNote tgcNote;


		for(AvatarNote note: avspec.getNotes()) {
			Object o = note.getReferenceObject();

			if ((o != null) && (o instanceof TGComponent)) {
				tgcO = (TGComponent)o;
				xPos = tgcO.getX();
				yPos = tgcO.getY();
			}

			tgcNote = new TGCNote(xPos, yPos, abd.getMinX(), abd.getMaxX(), abd.getMinY(), abd.getMaxY(), false, null, abd);
			xPos = xPos + dec;
			yPos = yPos + dec;
			addComponent(note, abd, tgcNote, xPos, yPos, false, true);
			tgcNote.setValue(note.getValue());
			tgcNote.makeValue();
			if (tgcO != null) {
				tgcNote.resize(tgcO.getWidth(), tgcO.getHeight());
			}
		}
	}


	public void makeSafetyPragmas(AvatarSpecification avspec, AvatarDesignPanel adp) {
		AvatarBDPanel abd = adp.abdp;
		int dec = 250;
		int xPos = 100, yPos = 500;
		TGComponent tgcO;

		HashMap<Object, AvatarBDSafetyPragma> setOfNewSafetyPragmaComponent = new HashMap<>();

		for(String pragmaS: avspec.getSafetyPragmas()) {
			Object o = avspec.getReferenceObjectOfSafetyPragma(pragmaS);

			AvatarBDSafetyPragma comp = null;
			if (o != null) {
				//TraceManager.addDev(" - - - - Pragma " + pragmaS + " has reference object " + o.toString());
				// already created?
				comp = setOfNewSafetyPragmaComponent.get(o);
				if ((o instanceof TGComponent) && (comp == null))
					tgcO = (TGComponent)o;
				else tgcO = null;
			} else {
				tgcO = null;
			}
			if (comp == null) {
				// We must create it
				if (tgcO != null) {
					xPos = tgcO.getX();
					yPos = tgcO.getY();
				}
				comp = new AvatarBDSafetyPragma(xPos, yPos, abd.getMinX(), abd.getMaxX(), abd.getMinY(), abd.getMaxY(), false, null, abd);
				xPos = xPos + dec;
				yPos = yPos + dec;
				abd.addComponent(comp, xPos, yPos, false, true);
				if (tgcO != null) {
					comp.resize(tgcO.getWidth(), tgcO.getHeight());
				}
				setOfNewSafetyPragmaComponent.put(o, comp);
			}

			String value = comp.getValue();
			value = value + "\n" + pragmaS;
			comp.setValue(value);
			comp.makeValue();
		}



	}

	public boolean addComponent(AvatarElement ae, TDiagramPanel tdp, TGComponent tgc, int x, int y, boolean swallow, boolean addToList) {

		for(Tag tag: ae.getAllTags()) {
			TraceManager.addDev("\tTAG: tag " + tag.getTag() + " for component " + tgc);
			tgc.addTag(tag);
		}

		/*Object o = ae.getReferenceObject();
		if ((o != null) && (o instanceof CanBeTagged)) {
			for(Tag tag: ((CanBeTagged)o).getAllTags()) {
				tgc.addTag(tag);
			}
		}*/

		return tdp.addComponent(tgc, x, y,  swallow, addToList);