<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 org.opensim.threejs;

import javax.swing.SwingUtilities;
import org.json.simple.JSONObject;
import org.opensim.modeling.AbstractProperty;
import org.opensim.modeling.Model;
import org.opensim.modeling.OpenSimObject;
import org.opensim.view.nodes.PropertyEditorAdaptor;
import org.opensim.view.pub.ViewDB;

/**
 *
 * @author Ayman
 */
public class JSONMessageHandler {
    public static void handleJSON(final Model model, final OpenSimObject opensimObj, final JSONObject jsonObject){
        final String eventType = (String) jsonObject.get("event");
        SwingUtilities.invokeLater(new Runnable(){
            @Override
            public void run() {
                if (eventType.equals("select")){
                    ViewDB.getInstance().setSelectedObject(opensimObj);
                }
                else if (eventType.equals("transform-changed")){
                    // Find property and modify
                    // From Visualizer side, we always get "position", "rotation", "scale"
                    // The corresponding Properties are adhoc and vary as follows:
                    if (opensimObj != null && opensimObj.hasProperty("location")){
                        final AbstractProperty ap = opensimObj.getPropertyByName("location");
                        final PropertyEditorAdaptor pea = new PropertyEditorAdaptor(model, opensimObj, ap, null);
                        String locationString = (String) jsonObject.get("location");
                        pea.setValueVec3FromString(convertLocationStringToPropertyFormat(jsonObject));
                    }
                }
                else if (eventType.equals("geometry-changed")){
                    // update Preoperties from Json
                }
            }
       
         });
        
    }
    static void setTransformPropertiesFromJSON(final OpenSimObject opensimObj, JSONObject jsonObject){
        
    }
    static void setGeometryPropertiesFromJSON(final OpenSimObject opensimObj, JSONObject jsonObject){
        
    }
    static void setAppearancePropertiesFromJSON(OpenSimObject opensimObj, JSONObject jsonObject){
        
    }
    static String convertLocationStringToPropertyFormat(JSONObject jsonObject) {
          JSONObject positionObj = (JSONObject) jsonObject.get("position");
          String returnString = "";
          double x, y, z;
          double relativeScale = ModelVisualizationJson.getVisScaleFactor();<commit_msg>Propagate moves from visualizer to ViewDB observers<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 org.opensim.threejs;

import javax.swing.SwingUtilities;
import org.json.simple.JSONObject;
import org.opensim.modeling.AbstractProperty;
import org.opensim.modeling.Model;
import org.opensim.modeling.OpenSimObject;
import org.opensim.view.nodes.PropertyEditorAdaptor;
import org.opensim.view.pub.ViewDB;

/**
 *
 * @author Ayman
 */
public class JSONMessageHandler {
    public static void handleJSON(final Model model, final OpenSimObject opensimObj, final JSONObject jsonObject){
        final String eventType = (String) jsonObject.get("event");
        SwingUtilities.invokeLater(new Runnable(){
            @Override
            public void run() {
                if (eventType.equals("select")){
                    ViewDB.getInstance().setSelectedObject(opensimObj);
                }
                else if (eventType.equals("transform-changed")){
                    // Find property and modify
                    // From Visualizer side, we always get "position", "rotation", "scale"
                    // The corresponding Properties are adhoc and vary as follows:
                    if (opensimObj != null && opensimObj.hasProperty("location")){
                        final AbstractProperty ap = opensimObj.getPropertyByName("location");
                        final PropertyEditorAdaptor pea = new PropertyEditorAdaptor(model, opensimObj, ap, null);
                        String locationString = (String) jsonObject.get("location");
                        pea.setValueVec3FromString(convertLocationStringToPropertyFormat(jsonObject));
                        // Tell the world that objects have moved
                        ViewDB.getInstance().objectMoved(model, opensimObj);
                    }
                }
                else if (eventType.equals("geometry-changed")){
                    // update Preoperties from Json
                }
            }
       
         });
        
    }
    static void setTransformPropertiesFromJSON(final OpenSimObject opensimObj, JSONObject jsonObject){
        
    }
    static void setGeometryPropertiesFromJSON(final OpenSimObject opensimObj, JSONObject jsonObject){
        
    }
    static void setAppearancePropertiesFromJSON(OpenSimObject opensimObj, JSONObject jsonObject){
        
    }
    static String convertLocationStringToPropertyFormat(JSONObject jsonObject) {
          JSONObject positionObj = (JSONObject) jsonObject.get("position");
          String returnString = "";
          double x, y, z;
          double relativeScale = ModelVisualizationJson.getVisScaleFactor();
{'fraction_non_alphanumeric': 0.08182648401826484, 'fraction_numerical': 0.00036529680365296805, 'mean_word_length': 2.3865182436611008, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2369231', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1293, 'n_words': 342}