package _VisualDVM.Passes.All;
import Common.Utils.Utils_;
import _VisualDVM.Global;
import _VisualDVM.Passes.Sapfor.SapforAnalysis;
import _VisualDVM.ProjectData.Files.DBProjectFile;
import _VisualDVM.ProjectData.SapforData.Loops.Json.FileLoopsJson;
import _VisualDVM.ProjectData.SapforData.Loops.Json.LoopsJson;
public class SPF_GetGraphLoops extends SapforAnalysis {
    @Override
    public String phase() {
        return "LOOP_GRAPH";
    }
    @Override
    protected void showPreparation() {
        if (Global.mainModule.HasFile())
            Global.mainModule.getFile().form.ShowNoLoops();
    }
    @Override
    protected boolean alwaysCheck() {
        return true;
    }
    @Override
    protected boolean isAtomic() {
        return false;
    }
    @Override
    protected void performPreparation() throws Exception {
        super.performPreparation(); //удаление интеррупта.
        target.numLoops = 0;
        for (DBProjectFile file : target.db.files.Data.values()) {
            file.LoopNests.clear();
            file.AllLoops.clear();
            file.LoopGraphTitle = "Всего циклов: 0";
        }
    }
    @Override
    protected void unpack(String packed) throws Exception {
        LoopsJson loopsJson = Utils_.gson.fromJson(packed, LoopsJson.class);
        for (FileLoopsJson fileLoopsJson : loopsJson.allLoops) {
            fileLoopsJson.file = Utils_.toW(fileLoopsJson.file);
            DBProjectFile projectFile = target.db.files.get(fileLoopsJson.file);
            projectFile.saveLoops(fileLoopsJson.loops);
            target.numLoops += projectFile.AllLoops.size();
        }
    }
    @Override
    protected void FocusResult() {
        super.FocusResult();
        if (Global.mainModule.HasFile())
            Global.mainModule.getFile().form.FocusLoops();
    }
    @Override
    protected void showDone() throws Exception {
        Global.mainModule.getUI().getMainWindow().getProjectWindow().getAnalysisWindow().ShowLoopsCount();
        Global.mainModule.getUI().getMainWindow().getProjectWindow().getAnalysisWindow().ShowRegions();
        if (Global.mainModule.HasFile())
            Global.mainModule.getFile().form.ShowLoops();
        super.showDone();
    }
}