Search in sources :

Example 46 with Survey

use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.

the class StationRenameTest method testRenameStation.

@Test
public void testRenameStation() {
    Survey testSurvey = BasicTestSurveyCreator.createStraightNorth();
    Station s2 = testSurvey.getStationByName("2");
    SurveyUpdater.renameStation(testSurvey, s2, "ShinyNewName");
    Station shinyNewStation = testSurvey.getStationByName("ShinyNewName");
    Assert.assertEquals("ShinyNewName", shinyNewStation.getName());
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Survey(org.hwyl.sexytopo.model.survey.Survey) Test(org.junit.Test)

Example 47 with Survey

use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.

the class StationRenameTest method testGetStationByNameGetsExistingStation.

@Test
public void testGetStationByNameGetsExistingStation() {
    Survey testSurvey = BasicTestSurveyCreator.createStraightNorth();
    Station s1 = testSurvey.getStationByName("1");
    Assert.assertEquals("1", s1.getName());
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Survey(org.hwyl.sexytopo.model.survey.Survey) Test(org.junit.Test)

Example 48 with Survey

use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.

the class SurveyUpdaterTest method testUpdateWithOneLegAddsOneLegToSurvey.

@Test
public void testUpdateWithOneLegAddsOneLegToSurvey() {
    Leg leg = new Leg(5, 0, 0);
    Survey survey = new Survey("Test Survey");
    SurveyUpdater.update(survey, leg);
    Assert.assertEquals(survey.getAllLegs().size(), 1);
}
Also used : Survey(org.hwyl.sexytopo.model.survey.Survey) Leg(org.hwyl.sexytopo.model.survey.Leg) Test(org.junit.Test)

Example 49 with Survey

use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.

the class PocketTopoTxtImporter method toSurvey.

public Survey toSurvey(File file) {
    String text = Loader.slurpFile(file.getAbsolutePath());
    // FIXME we're ignoring the metadata for now
    Survey survey = new Survey(getDefaultName(file));
    parseDataAndUpdateSurvey(survey, text);
    Sketch elevation = getElevation(survey, text);
    survey.setElevationSketch(elevation);
    Sketch plan = getPlan(survey, text);
    survey.setPlanSketch(plan);
    survey.setSaved(true);
    return survey;
}
Also used : Survey(org.hwyl.sexytopo.model.survey.Survey) Sketch(org.hwyl.sexytopo.model.sketch.Sketch)

Example 50 with Survey

use of org.hwyl.sexytopo.model.survey.Survey in project sexytopo by richsmith.

the class MetadataTranslater method translateAndUpdateConnections.

@SuppressWarnings("UnnecessaryContinue")
private static void translateAndUpdateConnections(Context context, Survey survey, JSONObject json, Set<String> surveyNamesNotToLoad) throws Exception {
    try {
        JSONObject connectionsObject = json.getJSONObject(CONNECTIONS_TAG);
        Map<String, JSONArray> outerMap = Util.toMap(connectionsObject);
        for (String stationName : outerMap.keySet()) {
            Station station = survey.getStationByName(stationName);
            JSONArray setArray = outerMap.get(stationName);
            for (JSONArray connectionPair : toListOfArrays(setArray)) {
                assert connectionPair.length() == 2;
                String connectedSurveyName = connectionPair.get(0).toString();
                String connectionPointName = connectionPair.get(1).toString();
                if (surveyNamesNotToLoad.contains(connectedSurveyName)) {
                    // if this survey is already loaded, don't do the whole infinite loop thing
                    continue;
                } else {
                    // we *really* want to avoid infinite loops :)
                    // this should be added on load, but just as a precaution..
                    surveyNamesNotToLoad.add(connectedSurveyName);
                    try {
                        Survey connectedSurvey = Loader.loadSurvey(context, connectedSurveyName, surveyNamesNotToLoad, false);
                        Station connectionPoint = connectedSurvey.getStationByName(connectionPointName);
                        if (connectionPoint == null) {
                            Log.e("Connection point not found: " + connectionPoint.getName());
                            throw new Exception("Connection point not found");
                        }
                        survey.connect(station, connectedSurvey, connectionPoint);
                    } catch (Exception exception) {
                        // the linked survey or connecting station has probably been deleted;
                        // not much we can do...
                        Log.e("Could not load connected survey " + connectedSurveyName);
                        continue;
                    }
                }
            }
        }
    } catch (JSONException exception) {
        Log.e(exception.toString());
        throw new Exception("Error loading connected surveys");
    }
}
Also used : Station(org.hwyl.sexytopo.model.survey.Station) Survey(org.hwyl.sexytopo.model.survey.Survey) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONException(org.json.JSONException)

Aggregations

Survey (org.hwyl.sexytopo.model.survey.Survey)101 Test (org.junit.Test)56 Station (org.hwyl.sexytopo.model.survey.Station)31 Leg (org.hwyl.sexytopo.model.survey.Leg)24 AlertDialog (android.app.AlertDialog)10 SuppressLint (android.annotation.SuppressLint)9 Coord2D (org.hwyl.sexytopo.model.graph.Coord2D)9 ArrayAdapter (android.widget.ArrayAdapter)8 File (java.io.File)6 HashMap (java.util.HashMap)6 View (android.view.View)5 EditText (android.widget.EditText)5 ArrayList (java.util.ArrayList)5 Set (java.util.Set)5 Context (android.content.Context)4 SharedPreferences (android.content.SharedPreferences)4 Editable (android.text.Editable)4 List (java.util.List)4 Map (java.util.Map)4 R (org.hwyl.sexytopo.R)4