Beispiel #1
0
        private void worldList_SelectedIndexChanged(object sender, EventArgs e)
        {
            CloseObservers(Project.World);

            if (worldList.SelectedItem != null)
            {
                MyWorldConfig wc = worldList.SelectedItem as MyWorldConfig;

                if (Project.World == null || wc.NodeType != Project.World.GetType())
                {
                    Project.CreateWorld(wc.NodeType);
                    Project.World.EnableAllTasks();
                    NodePropertyView.Target = null;

                    if (NetworkView != null)
                    {
                        NetworkView.ReloadContent();
                    }

                    foreach (GraphLayoutForm graphView in GraphViews.Values)
                    {
                        graphView.Desktop.Invalidate();
                        graphView.worldButton_Click(sender, e);
                    }
                }
            }
        }
Beispiel #2
0
        private bool ImportProject(string fileName, bool showObservers = false)
        {
            MyLog.INFO.WriteLine("Importing project: " + fileName);
            try
            {
                TextReader reader  = new StreamReader(fileName);
                string     content = reader.ReadToEnd();
                reader.Close();

                MyProject importedProject = MyProject.Deserialize(content, Path.GetDirectoryName(fileName));

                //offset all imported nodes
                float maxY = NetworkView.Desktop.GetContentBounds().Bottom;
                foreach (var node in importedProject.Network.Children)
                {
                    node.Location.Y += maxY + 10.0f;
                }

                if (showObservers && importedProject.Observers != null)
                {
                    foreach (MyAbstractObserver observer in importedProject.Observers)
                    {
                        observer.RestoreTargetFromIdentifier(importedProject);

                        if (observer.GenericTarget != null)
                        {
                            ShowObserverView(observer);
                        }
                    }
                }

                Project.Network.AppendGroupContent(importedProject.Network);

                if (showObservers && importedProject.Observers != null)
                {
                    foreach (MyAbstractObserver observer in importedProject.Observers)
                    {
                        observer.UpdateTargetIdentifier();
                    }
                }

                NetworkView.ReloadContent();
                NetworkView.Desktop.ZoomToBounds();

                return(true);
            }
            catch (Exception e)
            {
                MyLog.ERROR.WriteLine("Project import failed: " + e.Message);
                return(false);
            }
        }