public static int NamePoint(TtPoint previousPoint, TtPolygon parentPolygon)
        {
            if (previousPoint == null)
                return NameFirstPoint(parentPolygon);

            return NamePoint(previousPoint, parentPolygon.IncrementBy);
        }
        public Take5Form(TtPolygon poly, DataAccessLayer dal, TtMetaData meta, TtPoint currentPoint, int currIndex)
        {
            if (Engine.Values.WideScreen)
                InitializeComponentWide();
            else
                InitializeComponent();

            Init(poly, dal, meta, currentPoint, currIndex);
        }
        public AcquireGpsForm(TtPoint p, int currentZone, DataAccessLayer dal)
        {
            if(Engine.Values.WideScreen)
                InitializeComponentWide();
            else
                InitializeComponent();

            Init(p, currentZone, dal);
        }
        public static int NamePoint(TtPoint previousPoint, int incrementBy)
        {
            if (incrementBy < 1)
                throw new Exception("Invalid Increment Value");

            int rem = incrementBy - (previousPoint.PID % incrementBy);

            if (rem > 0)
                return (previousPoint.PID + rem);

            return (previousPoint.PID + incrementBy);
        }
        public void DeletePoint(TtPoint point, IDictionary<string, TtPoint> points)
        {
            TtPointCommand cmd = new DeletePointCommand(point);

            _Undocommands.Push(cmd);
            _Redocommands.Clear();

            cmd.Execute(points);

            if (UndoRedoUpdate != null)
                UndoRedoUpdate();
        }
        private void lstPoints_SelectedIndexChanged2(object sender, EventArgs e)
        {
            ListView.SelectedIndexCollection indexes = lstPoints.SelectedIndices;

            if (lstPoints.SelectedIndices.Count > 0)
            {
                _SelectedPoint = _Points[lstPoints.SelectedIndices[0]];
            }
            else
            {
                _SelectedPoint = null;
            }
        }
        void GetOldTravPointData(TtPoint pt)
        {
            SideShotPoint t = (SideShotPoint)pt;
            StringBuilder fields = new StringBuilder();
            fields.AppendFormat("{0}, {1}, {2}, {3}",
                TwoTrailsSchema.TravPointSchema.BackAz,
                TwoTrailsSchema.TravPointSchema.ForwardAz,
                TwoTrailsSchema.TravPointSchema.SlopeDistance,
                TwoTrailsSchema.TravPointSchema.VerticalAngle);
            StringBuilder query = new StringBuilder();
            query.AppendFormat("select {0} from {1} where {2} = '{3}'",
                fields.ToString(),
                TwoTrailsSchema.TravPointSchema.TableName,
                TwoTrailsSchema.SharedSchema.CN,
                t.CN);

            SQLiteCommand cmd = _dbConnection.CreateCommand();

            try
            {
                cmd.CommandText = query.ToString();

                SQLiteDataReader reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    if (!reader.IsDBNull(0))
                        t.BackwardAz = reader.GetDouble(0);
                    if (!reader.IsDBNull(1))
                        t.ForwardAz = reader.GetDouble(1);
                    if (!reader.IsDBNull(2))
                        t.SlopeDistance = reader.GetDouble(2);
                    if (!reader.IsDBNull(3))
                        t.SlopeAngle = reader.GetDouble(3);

                    if (DalVersion < DbReleaseVersions.D1_2_0)
                    {
                        t.SlopeAngle /= 3.6;
                    }
                }
            }
            catch (Exception ex)
            {
                TtUtils.WriteError(ex.Message, "DataAccessLayer:GetTravPointData", ex.StackTrace);
            }
            finally
            {
                cmd.Dispose();
            }
        }
 public QuondamPoint(TtPoint p)
     : base(p)
 {
     if (p.op == TwoTrails.Engine.OpType.Quondam)
     {
         QuondamPoint q = (QuondamPoint)p;
         _op = TwoTrails.Engine.OpType.Quondam;
         this.ParentPoint = q.ParentPoint;
     }
     else
     {
         _op = TwoTrails.Engine.OpType.Quondam;
         this.ParentPoint = null;
     }
 }
 public SideShotPoint(TtPoint p)
     : base(p)
 {
     if (p.op == TwoTrails.Engine.OpType.SideShot)
     {
         CopySideShot((SideShotPoint)p);
         _op = TwoTrails.Engine.OpType.SideShot;
     }
     else if (p.op == TwoTrails.Engine.OpType.Traverse)
     {
         CopySideShot((TravPoint)p);
         _op = TwoTrails.Engine.OpType.SideShot;
     }
     else
     {
         DefaultSideShotValues();
         _op = TwoTrails.Engine.OpType.SideShot;
     }
 }
 public GpsPoint(TtPoint p)
     : base(p)
 {
     /*
     if (p.op == TwoTrails.Engine.OpType.Take5 ||
         p.op == TwoTrails.Engine.OpType.GPS ||
         p.op == TwoTrails.Engine.OpType.WayPoint ||
         p.op == TwoTrails.Engine.OpType.Walk)
     */
     if(p.GetType() == typeof(GpsPoint))
     {
         GpsCopy((GpsPoint)p);
         _op = TwoTrails.Engine.OpType.GPS;
     }
     else
     {
         _op = TwoTrails.Engine.OpType.GPS;
         DefaultGpsValues();
     }
 }
        private void Init()
        {
            this.Icon = Properties.Resources.Map;

            _SelectedPoint = null;
            this.DialogResult = DialogResult.Cancel;

            lstPoints.Columns.Add("Point", -2, HorizontalAlignment.Left);
            lstPoints.Columns.Add("Operation", -2, HorizontalAlignment.Left);
            lstPoints.Columns.Add("Polygon", -2, HorizontalAlignment.Center);

            foreach (TtPoint point in _Points)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = point.PID.ToString();
                lvi.SubItems.Add(point.op.ToString());
                lvi.SubItems.Add(point.PolyName);
                lstPoints.Items.Add(lvi);
            }
        }
 public EditPointCommand(TtPoint newPoint)
 {
     CommandType = TtPointCommandType.SingleEdit;
     _NewPoint = TtUtils.CopyPoint(newPoint);
 }
        private void drawMiscPoint(TtPoint point, bool adjusted, Graphics g, bool wLabel)
        {
            Point newPoint = new Point();
            Brush brush;
            Rectangle recPoint = new Rectangle();

            if (adjusted)
            {
                newPoint = calcPointLocation(point.AdjX, point.AdjY);
                brush = brushAdjMiscPoint;
            }
            else
            {
                newPoint = calcPointLocation(point.UnAdjX, point.UnAdjY);
                brush = brushUnadjMiscPoint;
            }

            recPoint.X = newPoint.X - 2;
            recPoint.Y = newPoint.Y - 2;
            recPoint.Width = 4;
            recPoint.Height = 4;

            try
            {
                if (inScreen(newPoint))
                {
                    if (MapValues.mapPoints)
                    {
                        g.FillEllipse(brush, recPoint);

                        if (adjusted)
                            pns.Add(new PointName(point.AdjX, point.AdjY, point.PID.ToString()));
                        else
                            pns.Add(new PointName(point.UnAdjX, point.UnAdjY, point.PID.ToString()));
                    }
                    //??
                    if (wLabel)
                    {
                        drawPointLabel(g, point.PID.ToString(), font, brushLabel, newPoint);
                    }
                }
            }
            catch (Exception ex)
            {
                TtUtils.WriteError(ex.Message, "MapFormLogic- MiscPoint", ex.StackTrace);
            }
        }
        private TtPoint InvertPoint(TtPoint point)
        {
            //Invert the point from positive to negative (windows forms 0,0 starts at top left)
            point.AdjY *= -1;
            point.UnAdjY *= -1;

            return point;
        }
        public Take5Form(TtPolygon poly, DataAccessLayer dal, TtMetaData meta, TtPoint lastPoint, int cIndex)
        {
            InitializeComponent();

            Init(poly, dal, meta, lastPoint, cIndex);
        }
        public void Init()
        {
            this.Icon = Properties.Resources.Map;
            _init = false;

            _Polygons = new List<TtPolygon>();
            _FromPoints = new List<TtPoint>();
            _ToPoints = new List<TtPoint>();
            _PolyNames = new List<string>();
            _FromPointNames = new List<string>();
            _ToPointNames = new List<string>();
            _Meta = new List<TtMetaData>();

            pointsAvail = false;

            _FromPoint = null;
            _ToPoint = null;
            _FromPolygon = null;
            _ToPolygon = null;
            _CurrMeta = null;

            _navigating = false;

            if (DAL != null)
            {
                _Polygons = DAL.GetPolygons();

                _Meta = DAL.GetMetaData();

                if (_Meta.Count > 0)
                {
                    foreach (TtMetaData m in _Meta)
                    {
                        cboMeta.Items.Add(m.Name);
                    }

                    _CurrMeta = _Meta[0];
            #if (PocketPC || WindowsCE || Mobile)
                    btnMeta.Text = _CurrMeta.Name;
            #endif
                    cboMeta.SelectedIndex = 0;
                }

                if (_Polygons.Count > 0)
                {
                    foreach (TtPolygon poly in _Polygons)
                    {
                        if (DAL.GetPointCount(poly.CN) > 0)
                            pointsAvail = true;
                    }
                }
            }
            else
            {
            #if (PocketPC || WindowsCE || Mobile)
                btnMeta.Enabled = false;
            #endif
                cboMeta.Enabled = false;
                _CurrMeta = Values.Settings.ReadMetaSettings();

                if (_CurrMeta == null)
                {
                    _CurrMeta = new TtMetaData()
                    {
                        CN = Guid.Empty.ToString(),
                        Name = "DefaultMeta",
                        magDec = 0,
                        decType = DeclinationType.MagDec,
                        Zone = 13,
                        uomSlope = UomSlope.Percent,
                        uomElevation = UomElevation.Feet,
                        uomDistance = UomDistance.FeetTenths,
                        datum = Datum.NAD83
                    };
                }
            }

            UseMyPos = false;

            #region Setup Controls
            if (Values.Settings.DeviceOptions.UseSelection)
            {
                cboFromPoint.Visible = false;
                cboFromPoly.Visible = false;
                cboToPoint.Visible = false;
                cboToPoly.Visible = false;
                cboMeta.Visible = false;

            #if (PocketPC || WindowsCE || Mobile)
                btnToPoint.Visible = true;
                btnToPoly.Visible = true;
                btnFromPoint.Visible = true;
                btnFromPoly.Visible = true;
                btnMeta.Visible = true;

                btnToPoint.Enabled = true;
                btnToPoly.Enabled = true;
                btnFromPoint.Enabled = true;
                btnFromPoly.Enabled = true;
            #endif
                cboFromPoint.Enabled = false;
                cboFromPoly.Enabled = false;
                cboToPoint.Enabled = false;
                cboToPoly.Enabled = false;
            }
            else
            {
                cboFromPoint.Visible = true;
                cboFromPoly.Visible = true;
                cboToPoint.Visible = true;
                cboToPoly.Visible = true;
                cboMeta.Visible = true;

            #if (PocketPC || WindowsCE || Mobile)
                btnToPoint.Visible = false;
                btnToPoly.Visible = false;
                btnFromPoint.Visible = false;
                btnFromPoly.Visible = false;
                btnMeta.Visible = false;

                btnToPoint.Enabled = false;
                btnToPoly.Enabled = false;
                btnFromPoint.Enabled = false;
                btnFromPoly.Enabled = false;
            #endif
                cboFromPoint.Enabled = true;
                cboFromPoly.Enabled = true;
                cboToPoint.Enabled = true;
                cboToPoly.Enabled = true;
            }

            txtFromX.Enabled = false;
            txtFromY.Enabled = false;
            txtToX.Enabled = false;
            txtToY.Enabled = false;

            if (pointsAvail == true)
            {
                foreach (TtPolygon poly in _Polygons)
                {
                    cboFromPoly.Items.Add(poly.Name);
                    cboToPoly.Items.Add(poly.Name);
                    _PolyNames.Add(poly.Name);
                }

                cboFromPoly.SelectedIndex = 0;
                cboToPoly.SelectedIndex = 0;
                //ChangeFromPoly(0);
                //ChangeToPoly(0);
            }
            else
            {
                radToPoint.Enabled = false;
                radFromPoint.Enabled = false;

                txtFromX.Enabled = true;
                txtFromY.Enabled = true;
                txtToX.Enabled = true;
                txtToY.Enabled = true;

                radFromUTM.Checked = true;
                radToUTM.Checked = true;
            }
            #endregion
        }
 private void radFromPoint_CheckedChanged2(object sender, EventArgs e)
 {
     if (radFromPoint.Checked)
     {
         cboFromPoint.Enabled = true;
         cboFromPoly.Enabled = true;
     #if (PocketPC || WindowsCE || Mobile)
         btnFromPoint.Enabled = true;
         btnFromPoly.Enabled = true;
     #endif
         txtFromX.Enabled = false;
         txtFromY.Enabled = false;
         ChangeFromPoly(0);
     }
     else
     {
         cboFromPoint.Enabled = false;
         cboFromPoly.Enabled = false;
     #if (PocketPC || WindowsCE || Mobile)
         btnFromPoint.Enabled = false;
         btnFromPoly.Enabled = false;
     #endif
         txtFromX.Enabled = true;
         txtFromY.Enabled = true;
         _FromPoint = null;
     }
 }
        public void Init(TtPoint p, int currentZone, DataAccessLayer dal)
        {
            Values.GPSA.BurstReceived += GPSA_BurstReceived;
            Values.GPSA.InvalidStringFound += GPSA_InvalidStringFound;
            Values.GPSA.ComTimeout += GPSA_ComTimeout;
            Values.GPSA.GpsStarted += GPSA_GpsStarted;
            Values.GPSA.GpsEnded += GPSA_GpsEnded;
            Values.GPSA.GpsError += GPSA_GpsError;
            _init = true;

            this.currentZone = currentZone;

            pointName = p.PID;
            this.Text = "Point: " + pointName;
            pointCN = p.CN;

            DAL = dal;

            logged = 0;
            recieved = 0;
            logging = bLogBtn = _data = calculated = false;

            NmeaData = new List<NmeaBurst>();

            if (dal.GetPointCount(p.PolyCN) < 1)
            {
                checkMeta = true;
            }
        }
 public DeletePointCommand(TtPoint oldPoint)
 {
     CommandType = TtPointCommandType.Delete;
     _OldPoint = oldPoint;
 }
        private void ChangeFromPoint(int index)
        {
            if (index < 0 || index > _FromPoints.Count - 1)
            {
                _FromPoint = null;
            #if (PocketPC || WindowsCE || Mobile)
                btnFromPoint.Text = "";
            #endif
            }
            else
            {
                _FromPoint = _FromPoints[index];
            #if (PocketPC || WindowsCE || Mobile)
                btnFromPoint.Text = _FromPoint.PID.ToString();
            #endif
            }

            UtmYFrom = _FromPoint.UnAdjY;
            UtmXFrom = _FromPoint.UnAdjX;

            txtFromX.Text = UtmXFrom.ToString("F5").Truncate(12);
            txtFromY.Text = UtmYFrom.ToString("F5").Truncate(12);
        }
 public WayPoint(TtPoint p)
     : base(p)
 {
     if (p.IsGpsType())
     {
         GpsCopy((GpsPoint)p);
         _op = TwoTrails.Engine.OpType.WayPoint;
     }
     else
     {
         DefaultGpsValues();
         _op = TwoTrails.Engine.OpType.WayPoint;
     }
 }
 public Take5Point(TtPoint p)
     : base(p)
 {
     if (p.op == TwoTrails.Engine.OpType.Take5 ||
         p.op == TwoTrails.Engine.OpType.GPS ||
         p.op == TwoTrails.Engine.OpType.WayPoint ||
         p.op == TwoTrails.Engine.OpType.Walk)
     {
         GpsCopy((GpsPoint)p);
         _op = TwoTrails.Engine.OpType.Take5;
     }
     else
     {
         DefaultGpsValues();
         _op = TwoTrails.Engine.OpType.Take5;
     }
 }
 public void Add(TtPoint pt)
 {
     points.Add(pt);
     _calculated = false;
     _weight = -1;
 }
        private bool AdjustSideShot(TtPoint prevPoint, SideShotPoint ss)
        {
            ss.Accuracy = TtUtils.GetPointAcc(prevPoint, polys);

            return ss.AdjustPoint(prevPoint);
        }
        public override void Execute(IDictionary<string, TtPoint> points)
        {
            _OldPoint = TtUtils.CopyPoint(points[_NewPoint.CN]);

            points[_NewPoint.CN] = _NewPoint;
        }
        private QuondamPoint CreateQuondam(TtPoint parentpoint, TtPolygon poly, TtMetaData meta)
        {
            QuondamPoint tmpPoint = new QuondamPoint();
            tmpPoint.PolyCN = poly.CN;
            tmpPoint.PolyName = poly.Name;
            tmpPoint.MetaDefCN = meta.CN;
            tmpPoint.GroupCN = Values.MainGroup.CN;
            tmpPoint.GroupName = Values.MainGroup.Name;

            if (parentpoint.op == OpType.Quondam)
            {
                tmpPoint.ParentPoint = ((QuondamPoint)parentpoint).ParentPoint;
            }
            else
                tmpPoint.ParentPoint = parentpoint;

            tmpPoint.OnBnd = parentpoint.OnBnd;

            return tmpPoint;
        }
        private TtPoint MakePoint(TtPoint point, TtPolygon poly, bool link, int index)
        {
            if (link)
                point = new QuondamPoint() { ParentPoint = point };
            else
                point = TtUtils.ClonePoint(point);

            if (index == 0)
                point.PID = PointNaming.NameFirstPoint( _NewPoly);
            else
                point.PID = PointNaming.NamePoint(newPoints[ newPoints.Count - 1], _NewPoly);

            point.Index = index;
            point.MetaDefCN = _Meta.CN;

            return point;
        }
 public override bool CalculatePoint(TtPoint parent)
 {
     return CalculatePoint();
 }
        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;
        }
        private void ChangeFromPoly(int index)
        {
            if(index < 0 || index > _Polygons.Count -1)
                return;

            if (_FromPolygon != _Polygons[index])
            {
                _FromPolygon = _Polygons[index];
            #if (PocketPC || WindowsCE || Mobile)
                btnFromPoly.Text = _FromPolygon.Name;
            #endif

                cboFromPoint.Items.Clear();
                _FromPointNames.Clear();

                _FromPoints = DAL.GetPointsInPolygon(_FromPolygon.CN);

                if (_FromPoints.Count == 0)
                {
                    _FromPoint = new GpsPoint(0, 0, 0);
                    txtFromX.Text = String.Empty;
                    txtFromY.Text = String.Empty;
                    cboFromPoint.Text = String.Empty;
                }
                else
                {
                    foreach (TtPoint p in _FromPoints)
                    {
                        cboFromPoint.Items.Add(p.PID);
                        _FromPointNames.Add(p.PID.ToString());
                    }

                    cboFromPoint.SelectedIndex = 0;
                }
            }
        }