package _VisualDVM.Passes.All;
import Common.Passes.Pass;
import _VisualDVM.Global;
import _VisualDVM.ProjectData.SapforData.Functions.FuncCoordinates;
import _VisualDVM.ProjectData.SapforData.Functions.UI.Graph.FunctionsGraphForm;
public class SaveFunctionsGraphCoordinates extends Pass {
    FunctionsGraphForm graphForm = null;
    @Override
    protected boolean needsAnimation() {
        return true;
    }
    @Override
    public String getIconPath() {
        return "/icons/ScreenShot.png";
    }
    @Override
    protected boolean canStart(Object... args) {
        graphForm = Global.mainModule.getUI().getMainWindow().getProjectWindow().getFunctionsWindow().getFunctionsGraphWindow();
        if (!graphForm.isShown())
            Log.Writeln_("Сначала отобразите граф");
        if (Global.mainModule.getProject().functionsGraph.isEmpty())
            Log.Writeln_("Граф процедур пуст");
        return Log.isEmpty();
    }
    @Override
    protected void body() throws Exception {
        for (String funcName : Global.mainModule.getProject().functionsGraph.vertexCoordinates.keySet()) {
            FuncCoordinates coords = null;
            if (Global.mainModule.getProject().db.funcCoordinates.containsKey(funcName)) {
                coords = Global.mainModule.getProject().db.funcCoordinates.get(funcName);
                coords.name = funcName;
                coords.X = Global.mainModule.getProject().functionsGraph.vertexCoordinates.get(funcName).getKey();
                coords.Y = Global.mainModule.getProject().functionsGraph.vertexCoordinates.get(funcName).getValue();
                Global.mainModule.getProject().db.Update(coords);
            } else {
                coords = new FuncCoordinates();
                coords.name = funcName;
                coords.X = Global.mainModule.getProject().functionsGraph.vertexCoordinates.get(funcName).getKey();
                coords.Y = Global.mainModule.getProject().functionsGraph.vertexCoordinates.get(funcName).getValue();
                Global.mainModule.getProject().db.Insert(coords);
            }
        }
    }
}
