Пример #1
0
        /*
         * add a new trip to the end of trippool
         */
        public void add(IKmlFolder trip)
        {
            IKmlFolder     addTrip     = trip;
            IKmlObjectList points      = trip.getFeatures().getChildNodes();
            IKmlPlacemark  startPoint  = (IKmlPlacemark)points.item(0);
            IKmlPlacemark  finishPoint = (IKmlPlacemark)points.item(points.getLength() - 1);
            String         startTime   = startPoint.getName();
            String         finishTime  = finishPoint.getName();
            String         startLong   = Module.getCoordinates(startPoint)["lon"].ToString();
            String         startLat    = Module.getCoordinates(startPoint)["lat"].ToString();
            String         time        = (DateTime.Parse(finishTime) - DateTime.Parse(startTime)).ToString();
            String         distance    = Module.calDistance(trip).ToString();
            String         finishLong  = Module.getCoordinates(finishPoint)["lon"].ToString();
            String         finishLat   = Module.getCoordinates(finishPoint)["lat"].ToString();

            String[] timeSplit = new String[3];
            timeSplit = time.ToString().Split(':');
            double coEff = (3600 / (double)((Convert.ToInt32(timeSplit[0]) * 3600) + (Convert.ToInt32(timeSplit[1]) * 60) + (Convert.ToInt32(timeSplit[2]))));
            String speed = Math.Round((double.Parse(distance) * coEff), 3).ToString();

            _core.Add(addTrip);
            //_attr.Add(addAtt);
            TripDetails.Rows.Add(tripCount, Day, "-", HouseHoldID, "-", Date, WeekDay, startTime, finishTime, time, distance, speed, startLong, startLat, finishLong, finishLat, "-");
            ++tripCount;
        }
Пример #2
0
        public void insertTrip(IKmlFolder trip, String tripNumber, TripPool t_pool)
        {
            //This will add a trip to the dataTable
            addToUndoTypeTable("Insert");
            undoTable.Rows.Add(tripNumber, "");
            DataRow row = NewRowDataTableCustom();

            row[0] = tripNumber;
            row[1] = databaseViewer.Rows[0][1];
            //The trip count will be set with the resetTripCount
            row[3] = databaseViewer.Rows[0][3];
            row[4] = databaseViewer.Rows[0][4];
            row[5] = databaseViewer.Rows[0][5];
            row[6] = databaseViewer.Rows[0][6];
            IKmlObjectList points      = trip.getFeatures().getChildNodes();
            IKmlPlacemark  startPoint  = (IKmlPlacemark)points.item(0);
            IKmlPlacemark  finishPoint = (IKmlPlacemark)points.item(points.getLength() - 1);

            row[12] = Module.getCoordinates(startPoint)["lon"].ToString();
            row[13] = Module.getCoordinates(startPoint)["lat"].ToString();
            row[14] = Module.getCoordinates(finishPoint)["lon"].ToString();
            row[15] = Module.getCoordinates(finishPoint)["lat"].ToString();
            databaseViewer.Rows.InsertAt(row, Convert.ToInt32(tripNumber) - 1);
            DataRow newRowKML = t_pool.NewRowDataTableCustom();

            newRowKML = copyDataRowContents(row, newRowKML);
            t_pool.getTripDetails().Rows.InsertAt(newRowKML, Convert.ToInt32(tripNumber) - 1);
            completeMissingData(t_pool);
            t_pool.resetTripCount();
            resetTripCountForDay();
        }
Пример #3
0
        public IKmlPlacemark getStart(IKmlFolder trip)
        {
            IKmlObjectList points = trip.getFeatures().getChildNodes();

            //           MessageBox.Show(points.getLength().ToString());
            return((IKmlPlacemark)points.item(0));
        }
Пример #4
0
        public String insert(String name, IKmlFolder trip, String[] att)
        {
            de_highlight();
            int    index  = int.Parse(name.Split('_')[1]);
            String style  = "";
            String _style = "";

            IKmlFolder temp1 = getByName("Trip_" + index);
            IKmlFolder temp2 = getByName("Trip_" + (index + 1));

            IKmlObjectList points = temp1.getFeatures().getChildNodes();

            for (int ii = 0; ii != points.getLength(); ii++)
            {
                IKmlPlacemark point = (IKmlPlacemark)points.item(ii);
                trip.getFeatures().appendChild(point);
                if (ii == 1)
                {
                    style = point.getStyleUrl();
                }
            }

            points = temp2.getFeatures().getChildNodes();
            for (int ii = 0; ii != points.getLength(); ii++)
            {
                IKmlPlacemark point = (IKmlPlacemark)points.item(ii);
                if (ii == 1)
                {
                    _style = point.getStyleUrl();
                }
                point.setStyleUrl(style);
                trip.getFeatures().appendChild(point);
            }

            _core.RemoveAt(index - 1);
            _attr.RemoveAt(index - 1);

            _core.RemoveAt(index - 1);
            _attr.RemoveAt(index - 1);

            _core.Insert(index - 1, trip);
            _attr.Insert(index - 1, att);

            return(_style);
        }
Пример #5
0
        public void addAtPosition(IKmlFolder trip, int tripNumber)
        {
            IKmlFolder     addTrip     = trip;
            IKmlObjectList points      = trip.getFeatures().getChildNodes();
            IKmlPlacemark  startPoint  = (IKmlPlacemark)points.item(0);
            IKmlPlacemark  finishPoint = (IKmlPlacemark)points.item(points.getLength() - 1);
            String         startTime   = startPoint.getName();
            String         finishTime  = finishPoint.getName();
            String         startLong   = Module.getCoordinates(startPoint)["lon"].ToString();
            String         startLat    = Module.getCoordinates(startPoint)["lat"].ToString();
            String         time        = (DateTime.Parse(finishTime) - DateTime.Parse(startTime)).ToString();
            String         distance    = Module.calDistance(trip).ToString();
            String         finishLong  = Module.getCoordinates(finishPoint)["lon"].ToString();
            String         finishLat   = Module.getCoordinates(finishPoint)["lat"].ToString();

            String[] timeSplit = new String[3];
            timeSplit = time.ToString().Split(':');
            double coEff = (3600 / (double)((Convert.ToInt32(timeSplit[0]) * 3600) + (Convert.ToInt32(timeSplit[1]) * 60) + (Convert.ToInt32(timeSplit[2]))));
            String speed = Math.Round((double.Parse(distance) * coEff), 3).ToString();
            //          _core.Add(addTrip);
            //_attr.Add(addAtt);
            DataRow newRow = NewRowDataTableCustom();

            newRow["KMLTrip"]     = tripCount;
            newRow["HouseHoldID"] = HouseHoldID;
            newRow["Trip"]        = "-";
            newRow["Person"]      = "-";
            newRow["Day"]         = Day;
            newRow["Date"]        = Date;
            newRow["WeekDay"]     = WeekDay;
            newRow["Start Time"]  = startTime;
            newRow["Finish Time"] = finishTime;
            newRow["Time"]        = time;
            newRow["Distance"]    = distance;
            newRow["Speed"]       = speed;
            newRow["StartLong"]   = startLong;
            newRow["StartLat"]    = startLat;
            newRow["Finishlong"]  = finishLong;
            newRow["FinishLat"]   = finishLat;
            newRow["Remain"]      = "-";
            TripDetails.Rows.InsertAt(newRow, tripNumber);
            resetTripCount();
        }
Пример #6
0
        public String ch_col(String name, String col)
        {
            IKmlStyleMap sm        = ge.createStyleMap("");
            IKmlStyle    normal    = mkStyle(col, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.3);
            IKmlStyle    highlight = mkStyle(col, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.4);

            sm.setNormalStyle(normal);
            sm.setHighlightStyle(highlight);
            IKmlFolder     trip   = getByName(name);
            IKmlObjectList points = trip.getFeatures().getChildNodes();
            String         temp   = ((IKmlPlacemark)points.item(0)).getComputedStyle().getIconStyle().getColor().get();

            for (int i = 0; i < points.getLength(); i++)
            {
                IKmlPlacemark pt = (IKmlPlacemark)points.item(i);
                pt.setStyleSelector(sm);
            }
            return(temp);
        }
Пример #7
0
        public void resetTripData(String trip)
        {
            IKmlFolder tripData = getByName(trip);

            for (int i = 0; i != TripDetails.Rows.Count; ++i)
            {
                if (TripDetails.Rows[i]["KMLTrip"].ToString().Trim().Equals(Module.getIndex(trip).ToString()))
                {
                    //                   MessageBox.Show("FCKING "+trip);
                    IKmlFolder     addTrip     = tripData;
                    IKmlObjectList points      = tripData.getFeatures().getChildNodes();
                    IKmlPlacemark  startPoint  = (IKmlPlacemark)points.item(0);
                    IKmlPlacemark  finishPoint = (IKmlPlacemark)points.item(points.getLength() - 1);
                    String         startTime   = startPoint.getName();
                    String         finishTime  = finishPoint.getName();
                    String         startLong   = Module.getCoordinates(startPoint)["lon"].ToString();
                    String         startLat    = Module.getCoordinates(startPoint)["lat"].ToString();
                    String         time        = (Convert.ToDateTime(finishTime) - Convert.ToDateTime(startTime)).ToString();
                    String         distance    = Module.calDistance(tripData).ToString();
                    String         finishLong  = Module.getCoordinates(finishPoint)["lon"].ToString();
                    String         finishLat   = Module.getCoordinates(finishPoint)["lat"].ToString();
                    String[]       timeSplit   = new String[3];
                    timeSplit = time.ToString().Split(':');
                    double coEff = (3600 / (double)((Convert.ToInt32(timeSplit[0]) * 3600) + (Convert.ToInt32(timeSplit[1]) * 60) + (Convert.ToInt32(timeSplit[2]))));
                    String speed = Math.Round((double.Parse(distance) * coEff), 3).ToString();
                    TripDetails.Rows[i]["Start Time"]  = startTime;
                    TripDetails.Rows[i]["Finish Time"] = finishTime;
                    TripDetails.Rows[i]["Time"]        = time;
                    TripDetails.Rows[i]["Distance"]    = distance;
                    TripDetails.Rows[i]["Speed"]       = speed;
                    TripDetails.Rows[i]["StartLong"]   = startLong;
                    TripDetails.Rows[i]["StartLat"]    = startLat;
                    TripDetails.Rows[i]["Finishlong"]  = finishLong;
                    TripDetails.Rows[i]["FinishLat"]   = finishLat;
                    TripDetails.Rows[i]["Remain"]      = "-";
                }
            }
        }
Пример #8
0
        public ArrayList trimToEnd(String name, String time)
        {
            IKmlFolder     trip   = getByName(name);
            IKmlObjectList points = trip.getFeatures().getChildNodes();
            ArrayList      buffer = new ArrayList();

            for (int i = points.getLength() - 1; i >= 0; i--)
            {
                if (Convert.ToDateTime(((IKmlPlacemark)points.item(i)).getName()) > Convert.ToDateTime(time))
                {
                    buffer.Add(points.item(i));
                }
                else
                {
                    break;
                }
            }
            for (int i = 0; i < buffer.Count; i++)
            {
                trip.getFeatures().removeChild(buffer[i]);
            }
            return(buffer);
        }
Пример #9
0
        public PointPool(IKmlFolder trip)
        {
            core  = new Hashtable();
            names = new ArrayList();
            IKmlObjectList points = trip.getFeatures().getChildNodes();

            for (int i = 0; i < points.getLength(); i++)
            {
                IKmlPlacemark pt = (IKmlPlacemark)points.item(i);
                core[pt.getName()] = pt;
                names.Add(pt.getName());
            }
            p_highlight = "";
            _style      = "";
        }
Пример #10
0
        public Boolean join(String t_name1, String t_name2)
        {
            try
            {
                IKmlFolder temp  = ge.createFolder("");
                String[]   trip1 = t_pool.getTripDetailsForTrip(Module.getIndex(t_name1).ToString());
                String[]   trip2 = t_pool.getTripDetailsForTrip(Module.getIndex(t_name2).ToString());

                IKmlPlacemark point = t_pool.getStart(t_pool.getByName(t_name2));

                String[] trip = (String[])trip1.Clone();

                /*               trip[5] = trip2[5];
                 *             trip[6] = Module.duration(trip[4], trip[5]);
                 *             trip[11] = trip2[11];
                 *             trip[12] = trip2[12];
                 */
                Hashtable cord1 = Module.getCoordinates(t_pool.getFinish(t_pool.getByName(t_name1)));
                Hashtable cord2 = Module.getCoordinates(t_pool.getStart(t_pool.getByName(t_name2)));

/*
 *              trip[7] = (double.Parse(trip1[7]) + double.Parse(trip2[7]) + DistanceAlgorithm.DistanceBetweenPlaces((double)cord1["lat"], (double)cord1["lon"]
 *                          , (double)cord2["lat"], (double)cord2["lon"])).ToString();
 *
 *              trip[8] = Math.Round((double.Parse(trip[7]) / Module.durationConverter(trip[6])), 3).ToString();
 */
                String         style = t_pool.insert(t_name1, temp, trip, ge.createStyle(""));
                IKmlObjectList days  = ge.getFeatures().getChildNodes();
                IKmlDocument   day   = (IKmlDocument)days.item(0);
                day.getFeatures().appendChild(temp);

                ArrayList data = new ArrayList();
                data.Add(t_name1);
                data.Add(point);
                data.Add(trip1);
                data.Add(trip2);
                data.Add(style);
                record.joi_trip(data);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #11
0
        public void addToStart(String name, IKmlPlacemark point)
        {
            IKmlFolder     trip   = getByName(name);
            IKmlObjectList points = trip.getFeatures().getChildNodes();

            String col = ((IKmlPlacemark)trip.getFeatures().getChildNodes().item(2)).getComputedStyle().getIconStyle().getColor().get();

            IKmlStyleMap sm        = ge.createStyleMap("");
            IKmlStyle    normal    = mkStyle(col, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.3);
            IKmlStyle    highlight = mkStyle(col, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.4);

            sm.setNormalStyle(normal);
            sm.setHighlightStyle(highlight);

            point.setStyleSelector(sm);

            trip.getFeatures().insertBefore(point, points.item(0));
        }
Пример #12
0
        public IKmlPlacemark getNextPoint(IKmlFolder trip, IKmlPlacemark point)
        {
            bool           flag   = false;
            IKmlObjectList points = trip.getFeatures().getChildNodes();

            for (int i = 0; i != points.getLength(); ++i)
            {
                IKmlPlacemark pt = (IKmlPlacemark)points.item(i);
                if (flag == true)
                {
                    return(pt);
                }
                if (pt.getName() == point.getName())
                {
                    flag = true;
                }
            }
            return(null);
        }
Пример #13
0
        /*
         * distance calculation using big-circle formula
         */
        public static double calDistance(IKmlFolder trip)
        {
            double         distance = 0;
            IKmlObjectList points   = trip.getFeatures().getChildNodes();
            IKmlPlacemark  prev     = null;

            for (int i = 0; i != (points.getLength()); i++)
            {
                IKmlPlacemark curr = (IKmlPlacemark)points.item(i);
                if (prev != null)
                {
                    double d = DistanceAlgorithm.DistanceBetweenPlaces((double)getCoordinates(curr)["lat"], (double)getCoordinates(curr)["lon"]
                                                                       , (double)getCoordinates(prev)["lat"], (double)getCoordinates(prev)["lon"]);
                    distance += d;
                }
                prev = curr;
            }
            return(Math.Round(distance, 3));
        }
Пример #14
0
        public IKmlCamera allocate()
        {
            double         lat = 0, lon = 0;
            IKmlObjectList days  = ge.getFeatures().getChildNodes();
            IKmlDocument   day   = (IKmlDocument)days.item(0);
            IKmlObjectList trips = day.getFeatures().getChildNodes();

            for (int i = 0; i != (t_pool.getSize() / 2); i++)
            {
                IKmlFolder     trip   = t_pool.getByName("Trip_" + (i + 1));
                IKmlObjectList points = trip.getFeatures().getChildNodes();
                IKmlPlacemark  point  = (IKmlPlacemark)points.item(1);

                lon = (double)Module.getCoordinates(point)["lon"];
                lat = (double)Module.getCoordinates(point)["lat"];
            }
            //lon = lon / t_pool.getSize();
            // lat = lat / t_pool.getSize();
            IKmlCamera vw = ge.createCamera("");

            vw.set(lat, lon, 25000.0, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 0, 0);
            return(vw);
        }
Пример #15
0
        public IKmlFolder[] split(int index, IKmlFolder raw, IKmlPlacemark _point, String style)
        {
            IKmlFolder[] output = new IKmlFolder[2];

            String     col   = randomCol();
            IKmlFolder temp1 = ge.createFolder("");
            IKmlFolder temp2 = ge.createFolder("");

            temp1.setName("Trip_" + (index).ToString());
            temp2.setName("Trip_" + (index + 1).ToString());

            int            sw     = 0;
            IKmlObjectList points = raw.getFeatures().getChildNodes();

            for (int i = 0; i != points.getLength(); i++)
            {
                IKmlPlacemark point = (IKmlPlacemark)points.item(i);
                if (point.getName() == _point.getName())
                {
                    sw = 1;
                }
                if (sw == 0)
                {
                    temp1.getFeatures().appendChild(point);
                }
                else
                {
                    IKmlStyleMap sm = ge.createStyleMap("");
                    if (style != null)
                    {
                        if (point.getGeometry().getType() != "KmlPoint")
                        {
                            IKmlStyle sty = ge.createStyle("");
                            sty.getLineStyle().setWidth((float)4);
                            sty.getLineStyle().getColor().set(style);
                            point.setStyleSelector(sty);
                        }
                        else
                        {
                            IKmlStyle normal    = mkStyle(style, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.3);
                            IKmlStyle highlight = mkStyle(style, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.4);
                            sm.setNormalStyle(normal);
                            sm.setHighlightStyle(highlight);
                            point.setStyleSelector(sm);
                        }
                    }
                    else
                    {
                        if (point.getGeometry().getType() != "KmlPoint")
                        {
                            IKmlStyle sty = ge.createStyle("");
                            sty.getLineStyle().setWidth((float)4);
                            sty.getLineStyle().getColor().set(col);
                            point.setStyleSelector(sty);
                        }
                        else
                        {
                            IKmlStyle normal    = mkStyle(col, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.3);
                            IKmlStyle highlight = mkStyle(col, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.4);
                            sm.setNormalStyle(normal);
                            sm.setHighlightStyle(highlight);
                            point.setStyleSelector(sm);
                        }
                    }
                    temp2.getFeatures().appendChild(point);
                }
            }
            output[0] = temp1;
            output[1] = temp2;
            return(output);
        }
Пример #16
0
        public IKmlPlacemark getFinish(IKmlFolder trip)
        {
            IKmlObjectList points = trip.getFeatures().getChildNodes();

            return((IKmlPlacemark)points.item(points.getLength() - 1));
        }
Пример #17
0
        public Boolean undo(Hashtable mem)
        {
            try
            {
                if (mem["opt"] == "del")
                {
                    ArrayList rev = (ArrayList)mem["data"];

                    IKmlFolder _trip = (IKmlFolder)rev[1];
                    _trip.setVisibility(1);
                    t_pool.add((String)rev[0], _trip, (String[])rev[2]);
                }
                else if (mem["opt"] == "spl")
                {
                    ArrayList  rev  = (ArrayList)mem["data"];
                    IKmlFolder trip = (IKmlFolder)rev[1];

                    t_pool.insert((String)rev[0], trip, (String[])rev[2], ge.createStyle(""));
                    trip.setVisibility(1);
                    IKmlObjectList days = ge.getFeatures().getChildNodes();
                    IKmlDocument   day  = (IKmlDocument)days.item(0);
                    day.getFeatures().appendChild(trip);
                }
                else if (mem["opt"] == "joi")
                {
                    ArrayList  rev  = (ArrayList)mem["data"];
                    IKmlFolder temp = ge.createFolder("");

                    String       name = (String)rev[0];
                    IKmlFolder[] sub  = split(int.Parse((name.Split('_')[1])), t_pool.getByName(name), (IKmlPlacemark)rev[1], (String)rev[4]);

                    IKmlObjectList days = ge.getFeatures().getChildNodes();
                    IKmlDocument   day  = (IKmlDocument)days.item(0);

                    day.getFeatures().appendChild(sub[0]);
                    day.getFeatures().appendChild(sub[1]);

                    t_pool.insert(int.Parse((name.Split('_')[1])), sub[0], (String[])rev[2], sub[1], (String[])rev[3]);
                }
                else if (mem["opt"] == "ins")
                {
                    String     rev  = (String)mem["data"];
                    IKmlFolder trip = t_pool.getByName(rev);
                    trip.setVisibility(0);

                    t_pool.remove(rev);
                }
                else if (mem["opt"] == "crt")
                {
                    IKmlPlacemark pt = (IKmlPlacemark)mem["data"];
                    ge.getFeatures().removeChild(pt);
                }
                else if (mem["opt"] == "mk_start" || mem["opt"] == "mk_finish")
                {
                    ArrayList     rev  = (ArrayList)mem["data"];
                    IKmlPlacemark pt   = (IKmlPlacemark)rev[1];
                    IKmlFolder    trip = t_pool.getByName((String)rev[0]);
                    //trip.getFeatures().removeChild(pt);
                    //ge.getFeatures().appendChild(pt);
                }
                else if (mem["opt"] == "tm_start")
                {
                    ArrayList      rev    = (ArrayList)mem["data"];
                    IKmlFolder     trip   = t_pool.getByName((String)rev[0]);
                    IKmlObjectList points = trip.getFeatures().getChildNodes();
//                   MessageBox.Show(points.getLength().ToString()+" "+rev.Count.ToString());
                    for (int i = rev.Count - 1; i != 0; i--)
                    {
                        points = trip.getFeatures().getChildNodes();
                        trip.getFeatures().insertBefore(rev[i], points.item(0));
                    }
                }
                else if (mem["opt"] == "tm_finish")
                {
                    ArrayList      rev    = (ArrayList)mem["data"];
                    IKmlFolder     trip   = t_pool.getByName((String)rev[0]);
                    IKmlObjectList points = trip.getFeatures().getChildNodes();
                    //                   MessageBox.Show(points.getLength().ToString()+" "+rev.Count.ToString());
                    for (int i = rev.Count - 1; i != 0; i--)
                    {
                        points = trip.getFeatures().getChildNodes();
                        trip.getFeatures().insertBefore(rev[i], points.item(points.getLength() - 1));
                    }
                }
                else if (mem["opt"] == "ch_color")
                {
                    ArrayList rev = (ArrayList)mem["data"];
                    t_pool.ch_col((String)rev[0], (String)rev[1]);
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #18
0
        public Boolean test_undo()
        {
            bool      gflag = true;
            bool      fflag = true;
            Hashtable temp  = record.undo();

            if (temp["opt"] == "spl")
            {
                ArrayList data = (ArrayList)temp["data"];
                String    name = (String)data[0];
                //          String[] att = (String[])data[2];

                int ts_init = t_pool.getSize();
                int l_t1    = t_pool.getByName(name).getFeatures().getChildNodes().getLength();
                int l_t2    = t_pool.getByName("Trip_" + (Module.getIndex(name) + 1)).getFeatures().getChildNodes().getLength();

                String t_f = t_pool.getFinish(t_pool.getByName(name)).getName().ToString();
                String t_s = t_pool.getStart(t_pool.getByName("Trip_" + (Module.getIndex(name) + 1))).getName().ToString();

                core.undo(temp);
                MessageBox.Show(l_t1 + "   " + l_t2 + "  " + t_pool.getByName(name).getFeatures().getChildNodes().getLength());

                try
                {
                    Assert.AreEqual(ts_init, t_pool.getSize() + 1);
                    //                  MessageBox.Show(l_t1 + "   " + l_t2 + "  " + t_pool.getByName(name).getFeatures().getChildNodes().getLength());
                    //                  Assert.AreEqual(t_pool.getByName(name).getFeatures().getChildNodes().getLength(), l_t1 + l_t2);
                    Console.WriteLine("#Passed undo the previous split on GUI level");
                }
                catch
                {
                    Console.WriteLine("#Failed to undo the previous split on GUI level ");
                    gflag = false;
                }
                try
                {
                    IKmlObjectList days        = ge.getFeatures().getChildNodes();
                    IKmlDocument   day         = (IKmlDocument)days.item(0);
                    String         r_start     = txtedit.getViewer().Rows[0]["Start"].ToString();
                    String         r_finsih    = txtedit.getViewer().Rows[1]["Finish"].ToString();
                    String         r_duration1 = txtedit.getViewer().Rows[0]["Time"].ToString();
                    String         r_duration2 = txtedit.getViewer().Rows[1]["Time"].ToString();

                    double gap = ((Convert.ToDateTime(txtedit.getViewer().Rows[1]["Start"].ToString()) - Convert.ToDateTime(txtedit.getViewer().Rows[0]["Finish"].ToString()))).TotalSeconds;

                    String r_slon = txtedit.getViewer().Rows[0]["sLongitude"].ToString();
                    String r_flon = txtedit.getViewer().Rows[1]["fLongitude"].ToString();
                    String r_slat = txtedit.getViewer().Rows[0]["sLatitude"].ToString();
                    String r_flat = txtedit.getViewer().Rows[1]["fLatitude"].ToString();

                    txtedit.joinTrips(day.getName(), name, "Trip_" + (Module.getIndex(name) + 1), t_pool);
                    try
                    {
                        Assert.AreEqual(txtedit.getViewer().Rows[0]["Finish"].ToString(), t_f);
                        Assert.AreEqual(txtedit.getViewer().Rows[0]["Start"].ToString(), t_s);

                        Console.WriteLine("#Passed to compute the correct start and finish time");
                    }
                    catch
                    {
                        Console.WriteLine("#Failed to compute the correct start and finish time ");
                        fflag = false;
                    }
                    String flon = txtedit.getViewer().Rows[0]["fLongitude"].ToString();
                    String slat = txtedit.getViewer().Rows[0]["sLatitude"].ToString();


                    try
                    {
                        //                                Assert.AreEqual(flon, r_slon);
                        //                               Assert.AreEqual(slat, r_flon);
                        Console.WriteLine("#Passed to compute the correct start and finish coordinates");
                    }
                    catch
                    {
                        Console.WriteLine("#Failed to compute the correct start and finish coordinates");
                        fflag = false;
                    }
                    Assert.AreEqual(fflag, true);
                    Console.WriteLine("#Passed the test for undo the previous split on file level ");
                }
                catch
                {
                    Console.WriteLine("#Failed the test for undo the previous split on file level -");
                }
            }
            else if (temp["opt"] == "ins")
            {
                String name    = (String)temp["data"];
                int    ts_init = t_pool.getSize();

                MessageBox.Show(name);
                core.undo(temp);

                MessageBox.Show(ts_init + "   " + t_pool.getSize());
                try
                {
                    Assert.AreEqual(ts_init, t_pool.getSize() + 1);
                    //                  MessageBox.Show(l_t1 + "   " + l_t2 + "  " + t_pool.getByName(name).getFeatures().getChildNodes().getLength());
                    //                  Assert.AreEqual(t_pool.getByName(name).getFeatures().getChildNodes().getLength(), l_t1 + l_t2);
                    Console.WriteLine("#Passed undo the previous insert on GUI level ");
                }
                catch
                {
                    Console.WriteLine("#Failed to undo the previous insert on GUI level ");
                    gflag = false;
                }
            }


            return(gflag && fflag);
        }
Пример #19
0
        public Boolean split_test(String name, int index)
        {
            //create a kml folder by tripname
            IKmlFolder temp = t_pool.getByName(name);

            // get the current placemark and the pre placemark at a given index
            IKmlPlacemark sst = (IKmlPlacemark)temp.getFeatures().getChildNodes().item(index - 1);
            IKmlPlacemark st  = (IKmlPlacemark)temp.getFeatures().getChildNodes().item(index);

            // get trip size, number of trips and number of columns(lat,long ,elapse time etc)
            int pt_size     = temp.getFeatures().getChildNodes().getLength();
            int init_size_t = t_pool.getSize();

            core.split(st);
            //get index + 1 of the current trip
            String _name = "Trip_" + (Module.getIndex(name) + 1);

            Boolean gflag = true;
            Boolean fflag = true;

            try
            {
                int final_size_t = t_pool.getSize();
                //compare the initial size of the t pool against the final t pool.
                Assert.AreEqual(init_size_t, final_size_t - 1);
                //compare  the split index with the size of the first half of the splitted trip
                Assert.AreEqual(index, t_pool.getByName(name).getFeatures().getChildNodes().getLength());
                // compare the split index with the size of the second half of the splitted trip
                Assert.AreEqual(pt_size - index, t_pool.getByName(_name).getFeatures().getChildNodes().getLength());
                Console.WriteLine("     >>>>>>>>>>>> Passed the test for split the trip on GUI level <<<<<<<<<<<<");
            }
            catch
            {
                Console.WriteLine("     -----------> Failed the test for split the trip on GUI level <-----------");
                gflag = false;
            }

            try
            {
                IKmlObjectList days       = ge.getFeatures().getChildNodes();
                IKmlDocument   day        = (IKmlDocument)days.item(0);
                String         r_start    = txtedit.getViewer().Rows[0]["Start"].ToString();
                String         r_finsih   = txtedit.getViewer().Rows[0]["Finish"].ToString();
                String         r_duration = txtedit.getViewer().Rows[0]["Time"].ToString();
                String         r_slon     = txtedit.getViewer().Rows[0]["sLongitude"].ToString();
                String         r_flon     = txtedit.getViewer().Rows[0]["fLongitude"].ToString();
                String         r_slat     = txtedit.getViewer().Rows[0]["sLatitude"].ToString();
                String         r_flat     = txtedit.getViewer().Rows[0]["fLatitude"].ToString();


                txtedit.splitTrip(day.getName(), Module.getIndex(name).ToString(), t_pool.getStart(t_pool.getByName("Trip_" + (Module.getIndex(name) + 1))), t_pool.getFinish(t_pool.getByName(name)), t_pool);
                try
                {
                    Assert.AreEqual(txtedit.getViewer().Rows[0]["Finish"].ToString(), t_pool.getFinish(t_pool.getByName(name)).getName().ToString());
                    Assert.AreEqual(txtedit.getViewer().Rows[1]["Start"].ToString(), t_pool.getStart(t_pool.getByName("Trip_" + (Module.getIndex(name) + 1))).getName().ToString());

                    Console.WriteLine("     >>>>>>>>>>>> Succeed to compute the correct start and finish time <<<<<<<<<<<<");
                }
                catch
                {
                    Console.WriteLine("     -----------> Failed to compute the correct start and finish time <-----------");
                    fflag = false;
                }

                try
                {
                    double tp1 = Module.durationConverter(txtedit.getViewer().Rows[0]["Time"].ToString());
                    double gap = ((Convert.ToDateTime(txtedit.getViewer().Rows[1]["Start"].ToString()) - Convert.ToDateTime(txtedit.getViewer().Rows[0]["Finish"].ToString()))).TotalSeconds;
                    double tp2 = Module.durationConverter(txtedit.getViewer().Rows[1]["Time"].ToString());

                    //       MessageBox.Show(Module.durationConverter(txtedit.getViewer().Rows[0]["Time"].ToString()) + "  " + t.ToString() + "    " + Module.durationConverter(txtedit.getViewer().Rows[1]["Time"].ToString()) + "  " + Module.durationConverter(r_duration));
                    Assert.AreEqual(Module.durationConverter(r_duration), tp1 + gap + tp2);
                    Console.WriteLine("     >>>>>>>>>>>> Succeed to compute the correct trip duration <<<<<<<<<<<<");
                }
                catch
                {
                    Console.WriteLine("     -----------> Failed to compute the correct the trip duration <-----------");
                    fflag = false;
                }

                try
                {
                    String n_slon = txtedit.getViewer().Rows[1]["sLongitude"].ToString();
                    String n_slat = txtedit.getViewer().Rows[1]["sLatitude"].ToString();
                    String n_flon = txtedit.getViewer().Rows[0]["sLongitude"].ToString();
                    String n_flat = txtedit.getViewer().Rows[0]["sLatitude"].ToString();

                    String a_slon = Module.getCoordinates(t_pool.getStart(t_pool.getByName("Trip_" + (Module.getIndex(name) + 1))))["lon"].ToString();
                    String a_slat = Module.getCoordinates(t_pool.getStart(t_pool.getByName("Trip_" + (Module.getIndex(name) + 1))))["lat"].ToString();

                    String a_flon = Module.getCoordinates(t_pool.getStart(t_pool.getByName(name)))["lon"].ToString();
                    String a_flat = Module.getCoordinates(t_pool.getStart(t_pool.getByName(name)))["lat"].ToString();


/*
 *                  MessageBox.Show(n_slon+"    "+a_slon);
 *                  MessageBox.Show(n_slat + "    " + a_slat);
 *
 *                  MessageBox.Show(n_flon + "    " + a_flon);
 *                  MessageBox.Show(n_flat + "    " + a_flat);
 *
 *                  Assert.AreEqual(n_slat.Trim(), a_slat.Trim());
 *                  Assert.AreEqual(n_slon.Trim(), a_slon.Trim());
 *
 *                  Assert.AreEqual(n_flat.Trim(), a_flat.Trim());
 *                  Assert.AreEqual(n_flon.Trim(), a_flon.Trim());
 */
                    Console.WriteLine("     >>>>>>>>>>>> Succeed to compute the correct start and finish coordinates <<<<<<<<<<<<<");
                }
                catch
                {
                    Console.WriteLine("     -----------> Failed to compute the correct start and finish coordinates <----------");
                    fflag = false;
                }
                Assert.AreEqual(true, fflag);
                Console.WriteLine("     >>>>>>>>>>>> Passed the test for split the trip on file level <<<<<<<<<<<<<");
            }
            catch
            {
                Console.WriteLine("     -----------> Failed the test for split the trip on file level <----------");
            }
            return(gflag && fflag);
        }
Пример #20
0
        /*
         * insert a trip into trippool and remove the trip at the same index as well as the one after ( this is used by join )
         */
        public String insert(String name, IKmlFolder trip, String[] att, IKmlStyle sty)
        {
            de_highlight();
            int        index = int.Parse(name.Split('_')[1]);
            String     style = "";
            IKmlFolder temp1 = getByName("Trip_" + index);
            IKmlFolder temp2 = getByName("Trip_" + (index + 1));

            IKmlObjectList points = temp1.getFeatures().getChildNodes();

            for (int ii = 0; ii != points.getLength(); ii++)
            {
                IKmlPlacemark point = (IKmlPlacemark)points.item(ii);
                trip.getFeatures().appendChild(point);
                if (ii == 0)
                {
                    style = point.getComputedStyle().getIconStyle().getColor().get();
                }
            }
            points = temp2.getFeatures().getChildNodes();

            IKmlStyleMap sm        = ge.createStyleMap("");
            IKmlStyle    normal    = mkStyle(style, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.3);
            IKmlStyle    highlight = mkStyle(style, @"http://maps.google.com/mapfiles/kml/paddle/wht-blank.png", (float)0.4);

            sm.setNormalStyle(normal);
            sm.setHighlightStyle(highlight);
            for (int ii = 0; ii != points.getLength(); ii++)
            {
                IKmlPlacemark point = (IKmlPlacemark)points.item(ii);


                if (ii == 0)
                {
                    _style = point.getComputedStyle().getIconStyle().getColor().get();
                }
                if (point.getGeometry().getType() != "KmlPoint")
                {
                    point.getComputedStyle().getLineStyle().setWidth((float)4);
                    point.getComputedStyle().getLineStyle().getColor().set(style);
                }
                else
                {
                    point.setStyleSelector(sm);
                }
                trip.getFeatures().appendChild(point);
            }

            _core.RemoveAt(index - 1);
            // _attr.RemoveAt(index - 1);
            // removeKMLTrip(index.ToString());

            _core.RemoveAt(index - 1);
            //_attr.RemoveAt(index - 1);
            // removeKMLTrip(index.ToString());

            _core.Insert(index - 1, trip);
            // _attr.Insert(index - 1, att);
            // addAtPosition(trip, index - 1);

            return(_style);
        }
Пример #21
0
        public Boolean split(IKmlPlacemark sp_point)
        {
            try
            {
                Hashtable cords = Module.getCoordinates(sp_point);

                IKmlFolder _trip = (IKmlFolder)sp_point.getParentNode();
                _trip.setVisibility(0);

                String    t_name = t_pool.getParent(sp_point.getName());
                String[]  t_att  = t_pool.getTripDetailsForTrip(Module.getIndex(t_name).ToString());
                ArrayList trip   = new ArrayList();
                trip.Add(t_name);
                trip.Add(_trip);
                trip.Add(t_att);
                record.spl_trip(trip);

                int          index = int.Parse((t_name.Split('_')[1]));
                IKmlFolder[] sub   = split(index, _trip, sp_point, null);

                IKmlPlacemark fn     = t_pool.getFinish(sub[0]);
                Hashtable     _cords = Module.getCoordinates(fn);

                String[] att_temp1 = (String[])t_att.Clone();
                String[] att_temp2 = (String[])t_att.Clone();

/*
 *              att_temp1[5] = fn.getName();
 *              att_temp2[4] = sp_point.getName();
 *
 *              att_temp1[6] = Module.duration(att_temp1[4], att_temp1[5]);
 *              att_temp2[6] = Module.duration(att_temp2[4], att_temp2[5]);
 *
 *              att_temp1[11] = _cords["lon"].ToString();
 *              att_temp1[12] = _cords["lat"].ToString();
 *
 *              att_temp2[9] = cords["lon"].ToString();
 *              att_temp2[10] = cords["lat"].ToString();
 */
                IKmlObjectList days = ge.getFeatures().getChildNodes();
                IKmlDocument   day  = (IKmlDocument)days.item(0);

                day.getFeatures().appendChild(sub[0]);
                day.getFeatures().appendChild(sub[1]);

/*
 *              if (sub[0].getFeatures().getChildNodes().getLength() <= sub[1].getFeatures().getChildNodes().getLength())
 *              {
 *                  double distance = Module.calDistance(sub[0]);
 *                  att_temp1[7] = distance.ToString();
 *                  att_temp2[7] = (double.Parse(t_att[7]) - distance).ToString();
 *              }
 *              else
 *              {
 *                  double distance = Module.calDistance(sub[1]);
 *                  att_temp2[7] = distance.ToString();
 *                  att_temp1[7] = (double.Parse(t_att[7]) - distance).ToString();
 *              }
 */
                /*
                 * The duration of a trip from might be less than 0 when the program interpreter inconsistent kml and txt file
                 *
                 * chen
                 */
                /*               try
                 *             {
                 *                 att_temp1[8] = Math.Round((double.Parse(att_temp1[7]) / Module.durationConverter(att_temp1[6])), 3).ToString();
                 *                 att_temp2[8] = Math.Round((double.Parse(att_temp2[7]) / Module.durationConverter(att_temp2[6])), 3).ToString();
                 *             }
                 *             catch
                 *             {
                 *                 MessageBox.Show("kml and txt file doesn't match");
                 *                 att_temp2[8] = "-0";
                 *                 att_temp1[8] = "-0";
                 *             }
                 */
                t_pool.insert(index, sub[0], att_temp1, sub[1], att_temp2);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #22
0
        /*
         * get the coordinates of a point
         */

        public IKmlPlacemark getStart(IKmlFolder trip)
        {
            IKmlObjectList points = trip.getFeatures().getChildNodes();

            return((IKmlPlacemark)points.item(0));
        }