public bool ImportTt(List<string> polys, bool useNmea)
        {
            if (!_MetaOpen)
                return false;

            _Points = new List<TtPoint>();
            _Polygons = new Dictionary<string, TtPolygon>();
            _IdToCN = new Dictionary<string, string>();
            pidToCN = new Dictionary<int, string>();
            _PolyIndexes = new Dictionary<string, int>();

            Dictionary<string, TtMetaData> metaData = new Dictionary<string, TtMetaData>();
            Dictionary<string, string> metaLinkToId = new Dictionary<string, string>();
            Dictionary<string, int> qndLinks = new Dictionary<string, int>();
            List<int> pointWNMEA = new List<int>();

            Dictionary<int, List<TwoTrails.GpsAccess.NmeaBurst>> nmeas = new Dictionary<int, List<TwoTrails.GpsAccess.NmeaBurst>>();

            int viewId = metaKitViews[polydata];
            int rowCount;
            int polyCount = (int)dal.GetPolyCount();
            polyCount++;

            string tmpStr, tmpStr2;
            int tmpInt;
            double tmpDouble;

            try
            {
                #region Polygons
                rowCount = metaKit.GetRowCount(viewId);
                for (int i = 0; i < rowCount; i++)
                {
                    _Poly = new TtPolygon();

                    tmpStr = metaKit.GetString(viewId, i, 0);

                    if (!tmpStr.IsEmpty())
                    {
                        tmpStr2 = null;
                        _Poly.Name = tmpStr;
                    }
                    else
                    {
                        tmpStr2 = tmpStr;
                        _Poly.Name = String.Format("Poly {0}", polyCount);
                    }

                    _Poly.PointStartIndex = 1000 * polyCount + 10;

                    if (!polys.Contains(tmpStr))
                        continue;
                    polyCount++;

                    tmpStr = metaKit.GetString(viewId, i, 1);
                    if (!tmpStr.IsEmpty())
                        _Poly.Description = tmpStr;

                    tmpStr = metaKit.GetString(viewId, i, 10);
                    if (!tmpStr.IsEmpty())
                    {
                        if(_Poly.Description.IsEmpty())
                            _Poly.Description = tmpStr;
                        else
                            String.Format("{0}, Comment: {1}", _Poly.Description, tmpStr);
                    }

                    tmpDouble = metaKit.GetDouble(viewId, i, 11);
                    if(tmpDouble > 0)
                        _Poly.PolyAccu = tmpDouble;

                    _Polygons.Add(_Poly.CN, _Poly);
                    _IdToCN.Add(_Poly.Name, _Poly.CN);
                    _PolyIndexes.Add(_Poly.CN, 0);

                    if (tmpStr2 != null)
                    {
                        _IdToCN.Add(tmpStr2, _Poly.CN);
                    }
                }
                #endregion

                #region Metadata
                viewId = metaKitViews[metadata];

                TtMetaData newMeta;

                for (int i = 0; i < metaKit.GetRowCount(viewId); i++)
                {
                    newMeta = new TtMetaData();
                    newMeta.CN = Guid.NewGuid().ToString();

                    tmpInt = metaKit.GetInt(viewId, i, 2);
                    if (tmpInt > -1)
                        newMeta.Zone = tmpInt;

                    newMeta.Receiver = metaKit.GetString(viewId, i, 3);
                    newMeta.Laser = metaKit.GetString(viewId, i, 4);
                    newMeta.Compass = metaKit.GetString(viewId, i, 5);
                    newMeta.Crew = metaKit.GetString(viewId, i, 9);
                    newMeta.Comment = metaKit.GetString(viewId, i, 17);

                    tmpStr = metaKit.GetString(viewId, i, 10);
                    if(tmpStr.IsEmpty())
                    {
                        newMeta.Name = String.Format("Metadata {0}", metaData.Count + 1);
                        metaLinkToId.Add(newMeta.Name, newMeta.CN);
                        if (!metaLinkToId.ContainsKey(tmpStr))
                            metaLinkToId.Add(tmpStr, newMeta.CN);
                    }
                    else
                    {
                        newMeta.Name = tmpStr;
                        metaLinkToId.Add(tmpStr, newMeta.CN);
                    }

                    tmpStr = metaKit.GetString(viewId, i, 11);
                    tmpStr = tmpStr.ToLower();
                    if (tmpStr.Contains("meter"))
                        newMeta.uomDistance = UomDistance.Meters;
                    else if (tmpStr.Contains("chain"))
                        newMeta.uomDistance = UomDistance.Chains;
                    else if (tmpStr.Contains("tenth"))
                        newMeta.uomDistance = UomDistance.FeetTenths;
                    else if (tmpStr.Contains("inch"))
                        newMeta.uomDistance = UomDistance.FeetInches;
                    else if (tmpStr.Contains("yard"))
                        newMeta.uomDistance = UomDistance.Yards;

                    tmpStr = metaKit.GetString(viewId, i, 15);
                    tmpStr = tmpStr.ToLower();
                    if (tmpStr.Contains("feet"))
                        newMeta.uomElevation = UomElevation.Feet;
                    else if (tmpStr.Contains("meter"))
                        newMeta.uomElevation = UomElevation.Meters;

                    tmpStr = metaKit.GetString(viewId, i, 16);
                    tmpStr = tmpStr.ToLower();
                    if (tmpStr.Contains("deg"))
                        newMeta.uomSlope = UomSlope.Degrees;
                    else if (tmpStr.Contains("per"))
                        newMeta.uomSlope = UomSlope.Percent;

                    metaData.Add(newMeta.CN, newMeta);
                }
                #endregion

                #region Points
                TtPoint point;

                GpsPoint gps;
                SideShotPoint ssp;

                viewId = metaKitViews[ptdata];
                rowCount = metaKit.GetRowCount(viewId);
                for (int i = 0; i < rowCount; i++)
                {
                    tmpStr = metaKit.GetString(viewId, i, 0);

                    if (tmpStr.IsEmpty() || !polys.Contains(tmpStr))
                        continue;

                    point = new TtPoint();

                    _Poly = _Polygons[_IdToCN[tmpStr]];
                    point.PolyCN = _Poly.CN;
                    point.PolyName = _Poly.Name;

                    point.GroupCN = Values.MainGroup.CN;
                    point.GroupName = Values.MainGroup.Name;

                    tmpInt = metaKit.GetInt(viewId, i, 1);
                    if (tmpInt > 0)
                        point.PID = tmpInt;
                    else
                    {
                        if (_Points.Count > 1)
                            PointNaming.NamePoint(_Points[_Points.Count - 1], _Poly);
                        else
                            PointNaming.NameFirstPoint(_Poly);
                    }

                    pidToCN.Add(point.PID, point.CN);

                    tmpStr = metaKit.GetString(viewId, i, 2);
                    if (tmpStr.IsEmpty() || !tmpStr.IsBool())
                        point.OnBnd = false;
                    else
                        point.OnBnd = tmpStr.ToBool();

                    OpType op;

                    tmpStr = metaKit.GetString(viewId, i, 3);
                    if (tmpStr.IsEmpty())
                        continue;
                    else
                    {
                        try
                        {
                            op = (OpType)Enum.Parse(typeof(OpType), tmpStr, true);
                        }
                        catch
                        {
                            continue;
                        }
                    }

                    switch (op)
                    {
                        case OpType.GPS:
                        case OpType.Walk:
                        case OpType.WayPoint:
                            {
                                gps = new GpsPoint(point);

                                gps.UnAdjX = metaKit.GetDouble(viewId, i, 4);
                                gps.UnAdjY = metaKit.GetDouble(viewId, i, 5);
                                gps.UnAdjZ = metaKit.GetDouble(viewId, i, 6);
                                //gps.UnAdjX = gps.X;
                                //gps.UnAdjY = gps.Y;
                                //gps.UnAdjZ = gps.Z;

                                tmpDouble = metaKit.GetDouble(viewId, i, 32);
                                if (tmpDouble != 0)
                                    gps.ManualAccuracy = tmpDouble;

                                tmpDouble = metaKit.GetDouble(viewId, i, 33);
                                if (tmpDouble != 0)
                                    gps.RMSEr = tmpDouble;

                                if(metaKit.GetInt(viewId, i, 55) > 0)
                                    pointWNMEA.Add(point.PID);

                                if (op == OpType.Walk)
                                    point = new WalkPoint(gps);
                                else if (op == OpType.WayPoint)
                                    point = new WayPoint(gps);
                                else
                                    point = gps;
                            }
                            break;
                        case OpType.SideShot:
                        case OpType.Traverse:
                            {
                                ssp = new SideShotPoint(point);

                                tmpDouble = metaKit.GetDouble(viewId, i, 22);
                                if (tmpDouble != -1)
                                    ssp.ForwardAz = tmpDouble;

                                tmpDouble = metaKit.GetDouble(viewId, i, 23);
                                if (tmpDouble != -1)
                                    ssp.BackwardAz = tmpDouble;

                                ssp.SlopeDistance = metaKit.GetDouble(viewId, i, 24);
                                ssp.SlopeAngle = metaKit.GetDouble(viewId, i, 25);

                                if (op == OpType.Traverse)
                                    point = new TravPoint(ssp);
                                else
                                    point = ssp;
                            }
                            break;
                        case OpType.Quondam:
                            {
                                point = new QuondamPoint(point);

                                tmpStr = metaKit.GetString(viewId, i, 29);
                                try
                                {
                                    if (!tmpStr.IsEmpty())
                                    {
                                        tmpStr2 = tmpStr.Split(',')[1].Trim();
                                        qndLinks.Add(point.CN, tmpStr2.ToInteger());
                                    }
                                }
                                catch
                                {
                                    //bad quondam
                                }
                            }
                            break;
                        default:
                            continue;
                    }

                    tmpStr = metaKit.GetString(viewId, i, 56);
                    if (tmpStr.IsEmpty() || !metadata.Contains(tmpStr))
                        point.MetaDefCN = _Meta.CN;
                    else
                    {
                        point.MetaDefCN = metaData[tmpStr].CN;
                    }

                    tmpStr = metaKit.GetString(viewId, i, 38);
                    if (!tmpStr.IsEmpty())
                        point.Comment = tmpStr;

                    point.Index = _PolyIndexes[point.PolyCN];
                    _PolyIndexes[point.PolyCN]++;

                    point.Time = DateTime.Now;

                    _Points.Add(point);
                }

                for (int i = 0; i < _Points.Count; i++)
                {
                    if (_Points[i].op == OpType.Quondam)
                    {
                        if(qndLinks.ContainsKey(_Points[i].CN))
                        {
                            QuondamPoint qp = ((QuondamPoint)_Points[i]);
                            qp.ParentPoint = _Points.Where(p => p.PID == qndLinks[qp.CN]).First();
                            _Points[i] = qp;
                        }
                    }
                }

                #endregion

                #region NMEA
                if (useNmea)
                {
                    TwoTrails.GpsAccess.NmeaBurst burst;

                    viewId = metaKitViews[nmeadata];
                    tmpInt = metaKit.GetRowCount(viewId);
                    for (int i = 0; i < tmpInt; i++)
                    {
                        tmpStr = metaKit.GetString(viewId, i, 1);
                        if (tmpStr.IsInteger())
                        {
                            int pid = tmpStr.ToInteger();
                            if (pointWNMEA.Contains(pid))
                            {
                                if (!nmeas.ContainsKey(pid))
                                    nmeas.Add(pid, new List<TwoTrails.GpsAccess.NmeaBurst>());

                                burst = new TwoTrails.GpsAccess.NmeaBurst();
                                burst._CN = Guid.NewGuid().ToString();

                                burst._Used = metaKit.GetInt(viewId, i, 2) > 0;

                                tmpStr = metaKit.GetString(viewId, i, 3);
                                if (!tmpStr.IsEmpty())
                                    burst._date = DateTime.ParseExact(tmpStr, "MMddyy", null);

                                tmpStr2 = metaKit.GetString(viewId, i, 4);
                                if (!tmpStr2.IsEmpty())
                                    burst._date = DateTime.ParseExact(tmpStr + tmpStr2, "MMddyyHHmmss", null);

                                burst._GGA_longitude = metaKit.GetDouble(viewId, i, 5);
                                burst._RMC_longitude = burst._GGA_longitude;

                                burst._GGA_latitude = metaKit.GetDouble(viewId, i, 6);
                                burst._RMC_latitude = burst._GGA_latitude;

                                burst._alt_unit = Unit.METERS;
                                burst._altitude = metaKit.GetFloat(viewId, i, 11);

                                burst._horiz_dilution_position = metaKit.GetDouble(viewId, i, 12);
                                burst._fix_quality = metaKit.GetInt(viewId, i, 13);

                                burst._fix = metaKit.GetInt(viewId, i, 15);

                                burst._PDOP = metaKit.GetFloat(viewId, i, 16);
                                burst._HDOP = metaKit.GetFloat(viewId, i, 17);
                                burst._VDOP = metaKit.GetFloat(viewId, i, 18);

                                burst._magVar = metaKit.GetFloat(viewId, i, 19);
                                burst._num_of_sat = metaKit.GetInt(viewId, i, 20);
                                burst._fixed_PRNs = metaKit.GetString(viewId, i, 21);

                                burst._GGA_latDir = TwoTrails.GpsAccess.NorthSouth.North;
                                burst._GGA_longDir = TwoTrails.GpsAccess.EastWest.West;
                                burst._magVarDir = TwoTrails.GpsAccess.EastWest.East;
                                burst._RMC_latDir = TwoTrails.GpsAccess.NorthSouth.North;
                                burst._RMC_longDir = TwoTrails.GpsAccess.EastWest.West;

                                for (int j = 22; j < 70; j += 4)
                                {
                                    GpsAccess.Satellite s = new TwoTrails.GpsAccess.Satellite();

                                    s.ID = metaKit.GetString(viewId, i, j);
                                    s.Elevation = metaKit.GetInt(viewId, i, j + 1);
                                    s.Azimuth = metaKit.GetInt(viewId, i, j + 2);
                                    s.SNR = metaKit.GetInt(viewId, i, j + 3);

                                    burst.AddSatalite(s);
                                }

                                burst.Complete();

                                nmeas[pid].Add(burst);
                            }
                        }
                    }
                }

                #endregion

                dal.InsertPoints(_Points);

                foreach (TtMetaData m in metaData.Values)
                    dal.InsertMetaData(m);
                foreach (TtPolygon poly in _Polygons.Values)
                    dal.InsertPolygon(poly);

                foreach (KeyValuePair<int, List<GpsAccess.NmeaBurst>> bl in nmeas)
                    dal.SaveNmeaBursts(bl.Value, pidToCN[bl.Key]);
            }
            catch (Exception ex)
            {
                TtUtils.WriteError(ex.Message, "DataImport:ImportTt", ex.StackTrace);
                return false;
            }

            return true;
        }
Esempio n. 2
0
 public SideShotPoint(SideShotPoint p)
     : base(p)
 {
     CopySideShot(p);
 }
Esempio n. 3
0
        private bool AdjustSideShot(TtPoint prevPoint, SideShotPoint ss)
        {
            ss.Accuracy = TtUtils.GetPointAcc(prevPoint, polys);

            return ss.AdjustPoint(prevPoint);
        }
Esempio n. 4
0
 protected void CopySideShot(SideShotPoint p)
 {
     this._op = TwoTrails.Engine.OpType.SideShot;
     this.BackwardAz = p.BackwardAz;
     this.ForwardAz = p.ForwardAz;
     this.SlopeDistance = p.SlopeDistance;
     this.SlopeAngle = p.SlopeAngle;
     this.Accuracy = p.Accuracy;
 }
        private bool SetupSideshot()
        {
            takingSideshot = true;

            if (!lastPointSaved)
            {
                SaveLastPoint(CurrentPoint);
                lastPointSaved = true;
            }

            btnCapture.Text = "Commit SS";

            SideShotPoint ss = new SideShotPoint();

            try
            {
                if (LastPoint != null)
                    ss.PID = PointNaming.NamePoint(LastPoint, Polygon);
                else
                    ss.PID = PointNaming.NameFirstPoint(Polygon);

                _index++;
                ss.PolyCN = Polygon.CN;
                ss.PolyName = Polygon.Name;
                ss.OnBnd = OnBound;
                ss.Index = _index;
                ss.GroupCN = Values.MainGroup.CN;
                ss.GroupName = Values.MainGroup.Name;
                ss.MetaDefCN = CurrMeta.CN;

                this.GuiInvoke(() =>
                {
                    txtPID.Text = ss.PID.ToString();
                    txtComment.Text = ss.Comment;
                });

                travInfoControl1.CurrentPoint = ss;
                pnlSideshot.Visible = true;

                return true;
            }
            catch (Exception ex)
            {
                TtUtils.WriteError(ex.Message, "Take5Form:SetupSideshot", ex.StackTrace);
            }

            return false;
        }
        private void InsertTrav(SideShotPoint travPoint, SQLiteTransaction trans)
        {
            StringBuilder queryBeginning = new StringBuilder();
            StringBuilder queryEnd = new StringBuilder();
            queryBeginning.AppendFormat("INSERT INTO {0} (", TwoTrailsSchema.TravPointSchema.TableName);
            queryEnd.Append("(");

            //CN
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.SharedSchema.CN);
            queryEnd.AppendFormat("'{0}',", travPoint.CN);

            //Back AZ
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TravPointSchema.BackAz);
            queryEnd.AppendFormat("{0},", (travPoint.BackwardAz == null) ? ("null") :
                (String.Format("'{0}'", travPoint.BackwardAz.ToString())));

            //Forward Az
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TravPointSchema.ForwardAz);
            queryEnd.AppendFormat("{0},", (travPoint.ForwardAz == null) ? ("NULL") :
                (String.Format("'{0}'", travPoint.ForwardAz.ToString())));

            //Horiz dist
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TravPointSchema.HorizDistance);
            queryEnd.AppendFormat("'{0}',", travPoint.HorizontalDistance);

            //Slope Distance
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TravPointSchema.SlopeDistance);
            queryEnd.AppendFormat("'{0}',", travPoint.SlopeDistance);

            //Angle
            queryBeginning.AppendFormat("{0},", TwoTrailsSchema.TravPointSchema.VerticalAngle);
            queryEnd.AppendFormat("'{0}',", travPoint.SlopeAngle);

            //Accuracy
            queryBeginning.AppendFormat("{0}", TwoTrailsSchema.TravPointSchema.Accuracy);
            queryEnd.AppendFormat("'{0}'", travPoint.Accuracy);

            queryBeginning.Append(") values ");
            queryEnd.Append(");");
            queryBeginning.AppendFormat(" {0}", queryEnd.ToString());

            SQLiteCommand update = _dbConnection.CreateCommand();

            try
            {
                if (trans != null)
                    update.Transaction = trans;
                update.CommandText = queryBeginning.ToString();
                update.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                TtUtils.WriteError(ex.Message, "DataAccessLayer:InsertTrav");
            }
            finally
            {
                update.Dispose();
            }
        }
        protected void SavePoint(TtPoint currentPoint, SideShotPoint updatedPoint, SQLiteTransaction trans)
        {
            StringBuilder query = new StringBuilder();
            query.AppendFormat("Update {0} set ", TwoTrailsSchema.TravPointSchema.TableName);
            UpdateBasePoint(currentPoint, updatedPoint, trans);

            query.AppendFormat("{0} = {1}, ", TwoTrailsSchema.TravPointSchema.ForwardAz, (updatedPoint.ForwardAz == null) ? ("NULL") :
                (String.Format("'{0}'", updatedPoint.ForwardAz.ToString())));
            query.AppendFormat("{0} = {1}, ", TwoTrailsSchema.TravPointSchema.BackAz, (updatedPoint.BackwardAz == null) ? ("NULL") :
                (String.Format("'{0}'", updatedPoint.BackwardAz.ToString())));
            query.AppendFormat("{0} = {1}, ", TwoTrailsSchema.TravPointSchema.SlopeDistance, updatedPoint.SlopeDistance);
            query.AppendFormat("{0} = {1}, ", TwoTrailsSchema.TravPointSchema.VerticalAngle, updatedPoint.SlopeAngle);
            query.AppendFormat("{0} = {1} ", TwoTrailsSchema.TravPointSchema.Accuracy, (updatedPoint.Accuracy == null) ? ("NULL") :
                (String.Format("'{0}'", updatedPoint.Accuracy.ToString())));

            query.AppendFormat("where {0} = '{1}';", TwoTrailsSchema.SharedSchema.CN, updatedPoint.CN);

            ExecuteUpdate(query.ToString(), trans);
        }
 private void DisplayTrav(SideShotPoint travPoint)
 {
     walkInfoCtrl1.Visible = false;
     take5InfoCtrl1.Visible = false;
     gpsInfoControl1.Visible = false;
     gpsInfoControl1.ShowMiscButton = false;
     travInfoControl1.Visible = true;
     travInfoControl1.CurrentPoint = travPoint;
     travInfoControl1.MetaData = CurrMeta;
     quondamInfoControl1.Visible = false;
     actionsControl.MiscButtonText = "Aquire";
     actionsControl.MiscButtonEnabled = true;
 }