YED

yEd.XGML.DocumentEntities.Document - Добавлены методы

10/6/2019 12:57:17 PM

Details

diff --git a/YED/YED.Console/Test/Test1_ReadWrite.cs b/YED/YED.Console/Test/Test1_ReadWrite.cs
index 23c8f10..f1b71c5 100644
--- a/YED/YED.Console/Test/Test1_ReadWrite.cs
+++ b/YED/YED.Console/Test/Test1_ReadWrite.cs
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
 using System.Diagnostics;
 
 using yEd.XGML.IO;
+using yEd.XGML.DocumentEntities;
 
 namespace YED.Console.Test
 {
@@ -21,11 +22,14 @@ namespace YED.Console.Test
             string TestFile_Src = @"Documents\Document1.xgml";
             string TestFile_Dst = @"Documents\Document1_Copy.xgml";
 
-            //Котыль
-            XGML_Reader.DropEncodingAttribute(TestFile_Src);
+            ////Котыль
+            //XGML_Reader.DropEncodingAttribute(TestFile_Src);
 
-            var xgml_model = new XGML_Reader().Read(TestFile_Src);
-            new XGML_Writer().Write(xgml_model, TestFile_Dst);
+            //var xgml_model = new XGML_Reader().Read(TestFile_Src);
+            //new XGML_Writer().Write(xgml_model, TestFile_Dst);
+
+            Document xgml_model = Document.Load(TestFile_Src);
+            xgml_model.SaveAs(TestFile_Dst);
 
             if (OpenSrc)
                 Process.Start(TestFile_Src);
diff --git a/YED/YED.Console/Test/Test2_CreateGraph_and_ExportToYed.cs b/YED/YED.Console/Test/Test2_CreateGraph_and_ExportToYed.cs
index 894f1cf..04b22d2 100644
--- a/YED/YED.Console/Test/Test2_CreateGraph_and_ExportToYed.cs
+++ b/YED/YED.Console/Test/Test2_CreateGraph_and_ExportToYed.cs
@@ -41,16 +41,14 @@ namespace YED.Console.Test
 
 
             //Изменение на уровне XDGM Document
-            var nodes = doc.Elements.Values
-                .OfType<yEd.XGML.DocumentEntities.NodeEntitie.Node>()
-                .ToList();
+            var nodes = doc.Nodes;
 
             nodes[0].graphics.fill = Color.Red;
             nodes[1].graphics.x -= 100;
             nodes[2].graphics.x += 100;
 
             //Запись
-            new XGML_Writer().Write(doc, TestFile_Dst);
+            doc.SaveAs(TestFile_Dst);
 
             if (OpenDst)
                 Process.Start(TestFile_Dst);
diff --git a/YED/yEd.XGML/DocumentEntities/Document.cs b/YED/yEd.XGML/DocumentEntities/Document.cs
index 6813dba..e899f4b 100644
--- a/YED/yEd.XGML/DocumentEntities/Document.cs
+++ b/YED/yEd.XGML/DocumentEntities/Document.cs
@@ -5,6 +5,7 @@ using System.Text;
 using System.Threading.Tasks;
 
 using yEd.XGML.DocumentEntities.Base;
+using yEd.XGML.IO;
 using yEd.XGML.DocumentEntities.NodeEntitie;
 using yEd.XGML.DocumentEntities.EdgeEntitie;
 using yEd.XGML.DocumentEntities.GroupNodeEntitie;
@@ -23,10 +24,30 @@ namespace yEd.XGML.DocumentEntities
 
 
         public Dictionary<int, IElement> Elements { private set; get; } = new Dictionary<int, IElement>();
+        
+        public IDictionary<int, Node> Nodes => Elements.Values
+            .OfType<Node>()
+            .ToDictionary(e => e.id);
+        public IDictionary<int, GroupNode> GroupNode => Elements.Values
+            .OfType<GroupNode>()
+            .ToDictionary(e=> e.id);
+        /// <summary>
+        /// Наибольший из имеющихся ID
+        /// </summary>
+        public int GetMaxNodeID => Elements.Keys.Max();
 
-        //public IDictionary<int, Node> Nodes => Elements.OfType<>();
+        public List<Edge> Edges { private set; get; } = new List<Edge>();
 
 
-        public List<Edge> Edges { private set; get; } = new List<Edge>();
+
+        public static Document Load(string file)
+        {
+            XGML_Reader.DropEncodingAttribute(file);
+            return new XGML_Reader().Read(file);
+        }
+        public void SaveAs(string file)
+        {
+            new XGML_Writer().Write(this, file);
+        }
     }
 }
diff --git a/YED/yEd.XGML/yEd.XGML.csproj b/YED/yEd.XGML/yEd.XGML.csproj
index 3acd846..8840512 100644
--- a/YED/yEd.XGML/yEd.XGML.csproj
+++ b/YED/yEd.XGML/yEd.XGML.csproj
@@ -12,6 +12,7 @@
     <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <Deterministic>true</Deterministic>
+    <TargetFrameworkProfile />
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
@@ -21,6 +22,7 @@
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>pdbonly</DebugType>
@@ -29,6 +31,7 @@
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />