<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.unibi.agbi.gnius.controller.fxml;

import edu.unibi.agbi.gnius.model.EdgeType;
import edu.unibi.agbi.gnius.model.NodeType;
import edu.unibi.agbi.gnius.exception.controller.GraphNotNullException;
import edu.unibi.agbi.gnius.exception.data.EdgeCreationException;
import edu.unibi.agbi.gnius.exception.data.NodeCreationException;

import edu.unibi.agbi.gravisfx.graph.Graph;
import edu.unibi.agbi.gravisfx.graph.node.IGravisEdge;
import edu.unibi.agbi.gravisfx.graph.node.IGravisNode;
import edu.unibi.agbi.gravisfx.graph.node.IGravisSelectable;
import edu.unibi.agbi.gravisfx.graph.node.entity.GravisCircle;
import edu.unibi.agbi.gravisfx.graph.node.entity.GravisEdge;
import edu.unibi.agbi.gravisfx.graph.node.entity.GravisRectangle;
import edu.unibi.agbi.gravisfx.presentation.GraphPane;
import edu.unibi.agbi.gravisfx.presentation.layer.TopLayer;
import java.util.ArrayList;

import java.util.List;
import javafx.application.Platform;
import javafx.scene.input.MouseEvent;

/**
 *
 * @author PR
 */
public class PresentationController
{
    private static Graph graph = null;
    
    /**
     * 
     * @param type
     * @param event
     * @return
     * @throws NodeCreationException 
     */
    public static IGravisNode create(NodeType.Type type, MouseEvent event) throws NodeCreationException {
        
        IGravisNode node;
        
        switch(type) {
            case PLACE:
                node = new GravisCircle();
                node.getShape().getStyleClass().add("gravisCircle");
                break;
            case TRANSITION:
                node = new GravisRectangle();
                node.getShape().getStyleClass().add("gravisRectangle");
                break;
            default:
                throw new NodeCreationException("No suitable node type selected!");
        }
        
        if (event != null) {
            node.setTranslate(
                    (event.getX() - graph.getTopLayer().translateXProperty().get()) / graph.getTopLayer().getScaleTransform().getX() ,
                    (event.getY() - graph.getTopLayer().translateYProperty().get()) / graph.getTopLayer().getScaleTransform().getX()
            );
        }
        
        graph.add(node);
        
        return node;
    }
    
    /**
     * 
     * @param type
     * @param source
     * @param target
     * @return
     * @throws EdgeCreationException 
     */
    public static IGravisEdge create(EdgeType.Type type, IGravisNode source, IGravisNode target) throws EdgeCreationException {
        
        IGravisEdge edge;
        switch(type) {
            case EDGE:
                edge = new GravisEdge(source, target);
                edge.getShape().getStyleClass().add("gravisEdge");
                break;
            case ARC:
                edge = new GravisEdge(source, target);
                edge.getShape().getStyleClass().add("gravisArc");
                break;
            default:
                throw new EdgeCreationException("No suitable edge type selected!");
        }
        
        graph.add(edge);
        
        return edge;
    }
    
    /**
     * Copies the given nodes.
     * Creates a new shape for the given objects relative to the existing object.
     * The translation applied to the new nodes is the current mouse pointer position.
     * 
     * @param nodes
     * @param event
     * @return
     * @throws NodeCreationException 
     */
    public static List<IGravisNode> copy(IGravisNode[] nodes, MouseEvent event) throws NodeCreationException {
        
        List<IGravisNode> nodesCopied = new ArrayList();
        IGravisNode nodeCopy;
        
        double mouseX = event.getX();
        double mouseY = event.getY();
        
        TopLayer topLayer = null;

        for (int i = 0; i < nodes.length; i++) {

            if (GravisCircle.class.isAssignableFrom(nodes[i].getClass())) {
                nodeCopy = new GravisCircle();
                nodeCopy.getShape().getStyleClass().add("gravisCircle");
            } else if (GravisRectangle.class.isAssignableFrom(nodes[i].getClass())) {
                nodeCopy = new GravisRectangle();
                nodeCopy.getShape().getStyleClass().add("gravisRectangle");
            } else {
                throw new NodeCreationException("Node type cannot be recovered! Copying aborted.");
            }
            
            if (topLayer == null) {
                topLayer = ((TopLayer)nodes[i].getShape().getParent().getParent());
            }

            nodeCopy.setTranslate(
                    (mouseX - topLayer.translateXProperty().get()) / topLayer.getScaleTransform().getX() ,
                    (mouseY - topLayer.translateYProperty().get()) / topLayer.getScaleTransform().getX()
            );

            graph.add(nodeCopy);

            nodesCopied.add(nodeCopy);
        }
        
        return nodesCopied;
    }
    
    /**
     * 
     * @param nodes
     * @param event
     * @return
     * @throws NodeCreationException 
     */
    public static List<IGravisSelectable> clone(IGravisNode[] nodes, MouseEvent event) throws NodeCreationException {
        
        List<IGravisSelectable> nodesCopied = new ArrayList();
        IGravisNode nodeCopy;
        
        double mouseX = event.getX();
        double mouseY = event.getY();
        
        TopLayer topLayer = null;
        
        return nodesCopied;
    }
    
    <commit_msg>method for computing center of point clouds.<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.unibi.agbi.gnius.controller.fxml;

import edu.unibi.agbi.gnius.model.EdgeType;
import edu.unibi.agbi.gnius.model.NodeType;
import edu.unibi.agbi.gnius.exception.controller.GraphNotNullException;
import edu.unibi.agbi.gnius.exception.data.EdgeCreationException;
import edu.unibi.agbi.gnius.exception.data.NodeCreationException;

import edu.unibi.agbi.gravisfx.graph.Graph;
import edu.unibi.agbi.gravisfx.graph.node.IGravisEdge;
import edu.unibi.agbi.gravisfx.graph.node.IGravisNode;
import edu.unibi.agbi.gravisfx.graph.node.IGravisSelectable;
import edu.unibi.agbi.gravisfx.graph.node.entity.GravisCircle;
import edu.unibi.agbi.gravisfx.graph.node.entity.GravisEdge;
import edu.unibi.agbi.gravisfx.graph.node.entity.GravisRectangle;
import edu.unibi.agbi.gravisfx.presentation.GraphPane;
import edu.unibi.agbi.gravisfx.presentation.layer.TopLayer;
import java.util.ArrayList;

import java.util.List;
import javafx.application.Platform;
import javafx.geometry.Point2D;
import javafx.scene.input.MouseEvent;

/**
 *
 * @author PR
 */
public class PresentationController
{
    private static Graph graph = null;
    
    /**
     * 
     * @param type
     * @param event
     * @return
     * @throws NodeCreationException 
     */
    public static IGravisNode create(NodeType.Type type, MouseEvent event) throws NodeCreationException {
        
        IGravisNode node;
        
        switch(type) {
            case PLACE:
                node = new GravisCircle();
                node.getShape().getStyleClass().add("gravisCircle");
                break;
            case TRANSITION:
                node = new GravisRectangle();
                node.getShape().getStyleClass().add("gravisRectangle");
                break;
            default:
                throw new NodeCreationException("No suitable node type selected!");
        }
        
        if (event != null) {
            node.setTranslate(
                    (event.getX() - graph.getTopLayer().translateXProperty().get()) / graph.getTopLayer().getScaleTransform().getX() ,
                    (event.getY() - graph.getTopLayer().translateYProperty().get()) / graph.getTopLayer().getScaleTransform().getX()
            );
        }
        
        graph.add(node);
        
        return node;
    }
    
    /**
     * 
     * @param type
     * @param source
     * @param target
     * @return
     * @throws EdgeCreationException 
     */
    public static IGravisEdge create(EdgeType.Type type, IGravisNode source, IGravisNode target) throws EdgeCreationException {
        
        IGravisEdge edge;
        switch(type) {
            case EDGE:
                edge = new GravisEdge(source, target);
                edge.getShape().getStyleClass().add("gravisEdge");
                break;
            case ARC:
                edge = new GravisEdge(source, target);
                edge.getShape().getStyleClass().add("gravisArc");
                break;
            default:
                throw new EdgeCreationException("No suitable edge type selected!");
        }
        
        graph.add(edge);
        
        return edge;
    }
    
    /**
     * Copies the given nodes.
     * Creates a new shape for the given objects relative to the existing object.
     * The translation applied to the new nodes is the current mouse pointer position.
     * 
     * @param nodes
     * @param event
     * @return
     * @throws NodeCreationException 
     */
    public static List<IGravisNode> copy(IGravisNode[] nodes, MouseEvent event) throws NodeCreationException {
        
        List<IGravisNode> nodesCopied = new ArrayList();
        IGravisNode nodeCopy;
        
        double mouseX = event.getX();
        double mouseY = event.getY();
        
        TopLayer topLayer = null;

        for (int i = 0; i < nodes.length; i++) {

            if (GravisCircle.class.isAssignableFrom(nodes[i].getClass())) {
                nodeCopy = new GravisCircle();
                nodeCopy.getShape().getStyleClass().add("gravisCircle");
            } else if (GravisRectangle.class.isAssignableFrom(nodes[i].getClass())) {
                nodeCopy = new GravisRectangle();
                nodeCopy.getShape().getStyleClass().add("gravisRectangle");
            } else {
                throw new NodeCreationException("Node type cannot be recovered! Copying aborted.");
            }
            
            if (topLayer == null) {
                topLayer = ((TopLayer)nodes[i].getShape().getParent().getParent());
            }

            nodeCopy.setTranslate(
                    (mouseX - topLayer.translateXProperty().get()) / topLayer.getScaleTransform().getX() ,
                    (mouseY - topLayer.translateYProperty().get()) / topLayer.getScaleTransform().getX()
            );

            graph.add(nodeCopy);

            nodesCopied.add(nodeCopy);
        }
        
        return nodesCopied;
    }
    
    /**
     * Schwerpunkt von Punktwolke relativ zur Szene berechnen. 
     * Benutzen zum Verschieben, Kopieren, Einfügen usw.
     * 
     * @return 
     */
    private Point2D ComputeCenter(IGravisNode[] nodes) {
        
        double x = 0;
        double y = 0;
        
        double offsetX = graph.getTopLayer().getTranslateX();
        double offsetY = graph.getTopLayer().getTranslateY();
        
        for (IGravisNode node : nodes) {
            x += node.getTranslateX();
            y += node.getTranslateY();
        }
        
        System.out.println("X=" + x + " | Y=" + y);
        
        return new Point2D(x , y);
    }
    
    /**
     * 
     * @param nodes
     * @param event
     * @return
     * @throws NodeCreationException 
     */
    public static List<IGravisSelectable> clone(IGravisNode[] nodes, MouseEvent event) throws NodeCreationException {
        
        List<IGravisSelectable> nodesCopied = new ArrayList();
        IGravisNode nodeCopy;
        
        double mouseX = event.getX();
        double mouseY = event.getY();
        
        TopLayer topLayer = null;
        
        return nodesCopied;
    }
    
    
{'fraction_non_alphanumeric': 0.10551798981551047, 'fraction_numerical': 0.0005843559562567827, 'mean_word_length': 2.0506748153806975, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2897661', 'n_tokens_mistral': 3483, 'n_tokens_neox': 3358, 'n_words': 694}