/// <summary>
        /// Renders the contents of the project.
        ///
        /// Need to refactor to reduce redundant code use.
        ///
        /// </summary>
        /// <param name="HurricaneBasin">The canvas containing the basin</param>
        /// <param name="DotSize">The dot size setting. (NEEDS TO BE CHANGED)</param>
        /// <param name="StormList">The storm list to rend</param>
        public void RenderContent(Canvas HurricaneBasin, Point DotSize, List <Storm> StormList = null)
        {
            // optimise by clearing it every time (this is optimisation per v0.x standards LMAO)
            HurricaneBasin.Children.Clear();

            foreach (Layer XLayer in CurrentProject.SelectedBasin.BuildListOfZOrderedLayers())
            {
                // render loop
                foreach (Storm XStorm in XLayer.AssociatedStorms)
                {
                    if (StormList != null)
                    {
                        if (!StormList.Contains(XStorm))
                        {
                            continue;
                        }
                    }

                    Render_DrawLines(XStorm, DotSize, HurricaneBasin);

                    foreach (Node XNode in XStorm.NodeList)
                    {
                        if (XNode.NodeType.PresetShape != StormShape.Custom)
                        {
                            switch (XNode.NodeType.PresetShape)
                            {
                            // tropical systems
                            case StormShape.Circle:
                                Ellipse Ellipse = new Ellipse();

                                if (XNode.NodeType.ForceSize)
                                {
                                    DotSize = XNode.NodeType.ForcedSize;
                                }

                                Ellipse.Width  = DotSize.X;
                                Ellipse.Height = DotSize.Y;

                                // get the colour (Dano: refactor)
                                Ellipse.Fill = new SolidColorBrush(RenderBasedOnNodeIntensity(XStorm, XNode));

                                // Since there were many requests for an Invest/PTC storm type, here it is.
                                // need to fix redundant code - rc2 or iris

                                if (XNode.NodeType.ForceColour)
                                {
                                    // Invest / PTC uses [255,128,204,255] ARGB format
                                    Ellipse.Fill = new SolidColorBrush(XNode.NodeType.ForcedColour);
                                }
                                else
                                {
                                    Ellipse.Fill = new SolidColorBrush(RenderBasedOnNodeIntensity(XStorm, XNode));
                                }

                                RelativePositionConverter RPC = new RelativePositionConverter();
                                Point RP = (Point)RPC.ConvertBack(XNode.Position, typeof(Point), null, null);

                                Canvas.SetLeft(Ellipse, RP.X);
                                Canvas.SetTop(Ellipse, RP.Y);

                                HurricaneBasin.Children.Add(Ellipse);
                                continue;

                            case StormShape.Square:

                                Rectangle Rect = new Rectangle();

                                if (XNode.NodeType.ForceSize)
                                {
                                    DotSize = XNode.NodeType.ForcedSize;
                                }

                                Rect.Width  = DotSize.X - DotSize.X / 8;    // some people think the rects are too big (8/8 = 1) - this also means that all subtropical dots are 7/8ths the size of the other dots
                                Rect.Height = DotSize.Y - DotSize.Y / 8;

                                // get the colour
                                Rect.Fill = new SolidColorBrush(RenderBasedOnNodeIntensity(XStorm, XNode));

                                // Since there were many requests for an Invest/PTC storm type, here it is.
                                // need to fix redundant code - rc2 or iris

                                if (XNode.NodeType.ForceColour)
                                {
                                    // Invest / PTC uses [255,128,204,255] ARGB format
                                    Rect.Fill = new SolidColorBrush(XNode.NodeType.ForcedColour);
                                }
                                else
                                {
                                    Rect.Fill = new SolidColorBrush(RenderBasedOnNodeIntensity(XStorm, XNode));
                                }

                                // set the position
                                Canvas.SetLeft(Rect, XNode.Position.X);
                                Canvas.SetTop(Rect, XNode.Position.Y);

                                HurricaneBasin.Children.Add(Rect);
                                continue;

                            case StormShape.Triangle:

                                // draw the triangle
                                Polygon Poly = new Polygon();

                                if (XNode.NodeType.ForceSize)
                                {
                                    DotSize = XNode.NodeType.ForcedSize;
                                }

                                Poly.Points.Add(new Point(0, DotSize.Y));
                                Poly.Points.Add(new Point(DotSize.X / 2, 0));
                                Poly.Points.Add(new Point(DotSize.X, DotSize.Y));

                                // Since there were many requests for an Invest/PTC storm type, here it is.
                                if (XNode.NodeType.ForceColour)
                                {
                                    // Invest / PTC uses [255,128,204,255] ARGB format
                                    Poly.Fill = new SolidColorBrush(XNode.NodeType.ForcedColour);
                                }
                                else
                                {
                                    Poly.Fill = new SolidColorBrush(RenderBasedOnNodeIntensity(XStorm, XNode));
                                }

                                Canvas.SetLeft(Poly, XNode.Position.X);
                                Canvas.SetTop(Poly, XNode.Position.Y);

                                HurricaneBasin.Children.Add(Poly);
                                continue;
                            }
                        }
                        else // handle custom node handling
                        {
                            // We ignore forcesize for custom shapes
                            Polygon Poly = new Polygon();

                            foreach (Point Pt in XNode.NodeType.Shape.VPoints.Points) // needs some refactoring
                            {
                                Poly.Points.Add(Pt);
                            }

                            if (XNode.NodeType.Shape.IsFilled)
                            {
                                if (!XNode.NodeType.ForceColour)
                                {
                                    Poly.Fill = new SolidColorBrush(RenderBasedOnNodeIntensity(XStorm, XNode));
                                }
                                else
                                {
                                    if (XNode.NodeType.ForcedColour != null)
                                    {
                                        Poly.Fill = new SolidColorBrush(XNode.NodeType.ForcedColour);
                                    }
                                    else
                                    {
                                        // invalid forcedcolour state
                                        Poly.Fill = new SolidColorBrush(RenderBasedOnNodeIntensity(XStorm, XNode));
                                    }
                                }
                            }

                            Canvas.SetLeft(Poly, XNode.Position.X);
                            Canvas.SetTop(Poly, XNode.Position.Y);

                            HurricaneBasin.Children.Add(Poly);
                        }
                    }

                    if (ApplicationSettings.DefaultVisibleTextNames)
                    {
                        Render_DrawText(XStorm, HurricaneBasin);
                    }
                }
            }

            // Zoom and pan.
            Render_ZoomAndPan();

            // get WPF to render it
            UpdateLayout();
        }
Exemple #2
0
        private protected NodeImportResult ImportNodes(XmlNode XNN)
        {
            NodeImportResult NIR = new NodeImportResult();

            // get globalstate structures in Dano, use MainWindow for Priscilla

#if DANO
            StormTypeManager ST2Manager = GlobalState.GetST2Manager();
#else
            MainWindow       MnWindow   = (MainWindow)Application.Current.MainWindow;
            StormTypeManager ST2Manager = MnWindow.ST2Manager;
#endif
            if (!XNN.HasChildNodes)
            {
                NIR.Successful = true;
                NIR.Empty      = true;
                return(NIR);
            }
            else
            {
                foreach (XmlNode XNNChild in XNN.ChildNodes)
                {
                    Node NewNode = new Node();

                    if (!XNNChild.HasChildNodes)
                    {
                        Error.Throw("Error!", "Empty node detected!", ErrorSeverity.Error, 222);
                    }
                    else
                    {
                        foreach (XmlNode NodeInformationNode in XNNChild.ChildNodes)
                        {
                            switch (NodeInformationNode.Name)
                            {
                            case "Intensity":
                                NewNode.Intensity = Convert.ToInt32(NodeInformationNode.InnerText);
                                continue;

                            case "Position":

                                Point Npos = NodeInformationNode.InnerText.SplitXY();
                                RelativePositionConverter RPC = new RelativePositionConverter();
                                RelativePosition          RP  = (RelativePosition)RPC.Convert(Npos, typeof(RelativePosition), null, null);

                                NewNode.Position = RP;
                                continue;

                            case "Type":
                                NewNode.NodeType = ST2Manager.GetStormTypeWithName(NodeInformationNode.InnerText);
                                continue;
                            }
                        }
                    }



                    NIR.Nodes.Add(NewNode);
                }

                NIR.Successful = true;
                NIR.Empty      = false;
                return(NIR);
            }
        }
        private void Window_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            Storm Sto = CurrentProject.SelectedBasin.GetCurrentStorm();


            if (Sto != null)
            {
                if (Sto.LastNode != null)
                {
                    Node LastNode = Sto.LastNode;

                    RelativePositionConverter RPC = new RelativePositionConverter();

                    RelativePosition RP = (RelativePosition)RPC.Convert(e.GetPosition(HurricaneBasin), typeof(RelativePosition), null, null);
                    LastNode.Position = RP;

                    Sto.AddNode(LastNode);
                    LastNode = null;
                }
            }
            else
            {
                // left mouse button clicked (no zoom)
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    Project CurProj = CurrentProject;

                    // fix retardation
                    if (CurProj != null && CurProj.SelectedBasin != null && CurProj.SelectedBasin.CurrentLayer != null)
                    {
                        // if we have no storms, ask the user to create a storm instead of add a track point.
                        if (Sto == null)
                        {
                            AddNewStormHost Addstwindow = new AddNewStormHost(CurProj.SelectedBasin.SeasonStartTime);
                            Addstwindow.Owner = this;
                            Addstwindow.Show();
                            return;
                        }
                        else
                        {
                            // build 524
#if PRISCILLA
                            StormTypeManager ST2M = ST2Manager;
#else
                            StormTypeManager ST2Manager = GlobalState.GetST2Manager();
#endif
                            Storm SelectedStorm = CurProj.SelectedBasin.GetCurrentStorm();

                            int NodeCount = SelectedStorm.NodeList.Count - 1;

                            // build 547: implement season start time on window feature
                            AddTrackPointHost ATPHost = new AddTrackPointHost(ST2M.GetListOfStormTypeNames(), e.GetPosition(HurricaneBasin), SelectedStorm.GetNodeDate(NodeCount));
                            ATPHost.Owner = this;
                            ATPHost.Show();
                        }
                    }
                }
                else if (e.RightButton == MouseButtonState.Pressed)
                {
                    // temporary code
                    // this should be a matrix transformation but /shrug
                    // not best practice
                    LastRightMouseClickPos = e.GetPosition(HurricaneBasin);
                }
            }
        }
Exemple #4
0
        public bool ExportCore(Project Proj, string FileName)
        {
            XmlDocument XDoc  = new XmlDocument();
            XmlNode     XRoot = XDoc.CreateElement("Project");

            Proj.FileName = FileName;
            // Version 2.0: Write the metadata
            XmlNode XMetadataNode = XDoc.CreateElement("Metadata");
            // Version of the format.
            XmlNode XAuthor             = XDoc.CreateElement("Author");
            XmlNode XFormatVersionMajor = XDoc.CreateElement("FormatVersionMajor");
            XmlNode XFormatVersionMinor = XDoc.CreateElement("FormatVersionMinor");
            XmlNode XProjectName        = XDoc.CreateElement("ProjectName");

            XmlNode XTimestamp = XDoc.CreateElement("Timestamp");

            XAuthor.InnerText             = Environment.UserName;
            XFormatVersionMajor.InnerText = FormatVersionMajor.ToString();
            XFormatVersionMinor.InnerText = FormatVersionMinor.ToString();
            string ProjectName = Proj.Name;

            if (ProjectName == null)
            {
                XProjectName.InnerText = Proj.Name;
            }
            else
            {
                XProjectName.InnerText = "Track Maker Project";
            }

            // ISO 8601 date format
            XTimestamp.InnerText = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            XmlNode XBasinsNode = XDoc.CreateElement("Basins");

            foreach (Basin Bas in Proj.OpenBasins)
            {
                XmlNode XBasinNode       = XDoc.CreateElement("Basin");
                XmlNode XBasinNameNode   = XDoc.CreateElement("UserTag");
                XmlNode XBasinNameBasin  = XDoc.CreateElement("Name");
                XmlNode XBasinIsOpen     = XDoc.CreateElement("IsOpen");
                XmlNode XBasinIsSelected = XDoc.CreateElement("IsSelected");
                XmlNode XBasinLayers     = XDoc.CreateElement("Layers");

                XBasinNameNode.InnerText   = Bas.UserTag;
                XBasinNameBasin.InnerText  = Bas.Name;
                XBasinIsOpen.InnerText     = Bas.IsOpen.ToString();
                XBasinIsSelected.InnerText = Bas.IsSelected.ToString();
                // build a layer

                foreach (Layer Lay in Bas.Layers)
                {
                    XmlNode XLayerNode     = XDoc.CreateElement("Layer");
                    XmlNode XLayerNameNode = XDoc.CreateElement("Name");
                    XmlNode XLayerGUIDNode = XDoc.CreateElement("GUID");
                    XmlNode XStormsNode    = XDoc.CreateElement("Storms");

                    XLayerNameNode.InnerText = Lay.Name;
                    XLayerGUIDNode.InnerText = Lay.LayerId.ToString();

                    // dump the storm info to file
                    foreach (Storm XStorm in Lay.AssociatedStorms)
                    {
                        // create the xml nodes.
                        XmlNode XStormNode          = XDoc.CreateElement("Storm");
                        XmlNode XStormFormationDate = XDoc.CreateElement("FormationDate");
                        XmlNode XStormID            = XDoc.CreateElement("ID");
                        XmlNode XStormName          = XDoc.CreateElement("Name");
                        XmlNode XStormNodeList      = XDoc.CreateElement("Nodes");
                        XmlNode XStormNodeListDel   = XDoc.CreateElement("DeletedNodes"); // the undone nodes

                        // set the basic info - name etc
                        XStormFormationDate.InnerText = XStorm.FormationDate.ToString();
                        XStormID.InnerText            = XStorm.Id.ToString();
                        XStormName.InnerText          = XStorm.Name;

                        // populate the node list
                        foreach (Node XNode in XStorm.NodeList)
                        {
                            // add new nodes
                            XmlNode XNodeNode      = XDoc.CreateElement("Node");
                            XmlNode XNodeIntensity = XDoc.CreateElement("Intensity");
                            XmlNode XNodePosition  = XDoc.CreateElement("Position");
                            XmlNode XNodePressure  = XDoc.CreateElement("Pressure");
                            XmlNode XNodeType      = XDoc.CreateElement("Type");

                            // set the info
                            XNodeIntensity.InnerText = XNode.Intensity.ToString();

                            RelativePositionConverter RPC = new RelativePositionConverter();
                            Point RP = (Point)RPC.ConvertBack(XNode.Position, typeof(Point), null, null);

                            XNodePosition.InnerText = RP.ToStringEmerald();
                            XNodePressure.InnerText = XNode.Pressure.ToString();
                            XNodeType.InnerText     = XNode.NodeType.Name;

                            // build the node list xml structure
                            XNodeNode.AppendChild(XNodeIntensity);
                            XNodeNode.AppendChild(XNodePosition);
                            XNodeNode.AppendChild(XNodePressure);
                            XNodeNode.AppendChild(XNodeType);
                            XStormNodeList.AppendChild(XNodeNode);
                        }

                        // Populate the deleted node list xmlinfo for the basin save information.

                        foreach (Node XNode in XStorm.NodeList_Deleted)
                        {
                            // add new nodes
                            XmlNode XNodeNode      = XDoc.CreateElement("Node");
                            XmlNode XNodeIntensity = XDoc.CreateElement("Intensity");
                            XmlNode XNodePosition  = XDoc.CreateElement("Position");
                            XmlNode XNodeType      = XDoc.CreateElement("Type");

                            // set the info
                            XNodeIntensity.InnerText = XNode.Intensity.ToString();

                            RelativePositionConverter RPC = new RelativePositionConverter();
                            Point RP = (Point)RPC.ConvertBack(XNode.Position, typeof(Point), null, null);

                            XNodePosition.InnerText = RP.ToStringEmerald();
                            XNodeType.InnerText     = XNode.NodeType.Name;

                            // build the node list xml structure
                            XNodeNode.AppendChild(XNodeIntensity);
                            XNodeNode.AppendChild(XNodePosition);
                            XNodeNode.AppendChild(XNodeType);
                            XStormNodeListDel.AppendChild(XNodeNode);
                        }
                        // build perstorm xml

                        XStormNode.AppendChild(XStormFormationDate);
                        XStormNode.AppendChild(XStormID);
                        XStormNode.AppendChild(XStormName);
                        XStormNode.AppendChild(XStormNodeList);
                        XStormNode.AppendChild(XStormNodeListDel);

                        XStormsNode.AppendChild(XStormNode);
                    }

                    XLayerNode.AppendChild(XLayerNameNode);
                    XLayerNode.AppendChild(XLayerGUIDNode);
                    XLayerNode.AppendChild(XStormsNode);

                    XBasinLayers.AppendChild(XLayerNode);
                }

                // Build the Basins node

                XBasinNode.AppendChild(XBasinNameNode);
                XBasinNode.AppendChild(XBasinNameBasin);
                XBasinNode.AppendChild(XBasinLayers);

                XBasinsNode.AppendChild(XBasinNode);
            }

            // build metadata

            XMetadataNode.AppendChild(XAuthor);
            XMetadataNode.AppendChild(XFormatVersionMajor);
            XMetadataNode.AppendChild(XFormatVersionMinor);
            XMetadataNode.AppendChild(XProjectName);

            XRoot.AppendChild(XMetadataNode);

            // build storms
            XRoot.AppendChild(XBasinsNode);

            XDoc.AppendChild(XRoot);

            XDoc.Save(FileName);

            // on success
            GlobalState.SetCurrentOpenFile(FileName);
            return(true);
        }