Example #1
0
        public static string WriteFileToString(TsFile tsFile)
        {
            var writerContext = new WriterContext();

            writerContext.Write(tsFile);
            return(writerContext.GetResult());
        }
Example #2
0
        public override List <string> CreateFiles(Dictionary <string, Type> types, Dictionary <string, Function> functions)
        {
            var client = new TsFile(Settings.ClientFileName);


            foreach (var(_, type) in types)
            {
                client.Write(type.Code);
                client.Write("");
            }

            client.Write("");

            var mainFileTemplate = Context.GetTemplateFactory()
                                   .CreateClientTemplate(Settings.ServerUrl, functions.Select(x => x.Value.Code), new List <string>());

            client.Write(mainFileTemplate.TransformText());

            client.Write("");

            var exports = types.Select(x => x.Key).StrJoin(", ");

            client.Write("export { " + exports + " };");

            return(new List <string>
            {
                client.ToSystemFile()
            });
        }
Example #3
0
 public void Register(TsFile tsFile)
 {
     foreach (var tsDeclaration in tsFile.Declarations)
     {
         Register(tsFile, tsDeclaration);
     }
 }
Example #4
0
            private void Register(TsFile tsFile, TsDeclaration tsDeclaration)
            {
                switch (tsDeclaration)
                {
                case TsClass _:
                case TsInterface _:
                case TsEnum _:
                    Add(new Export(tsDeclaration, tsFile));
                    break;

                case TsFunction _:
                    break;

                case TsNamespace tsNamespace:
                    foreach (var declaration in tsNamespace.Declarations)
                    {
                        Register(tsFile, declaration);
                    }

                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(tsDeclaration),
                                                          tsDeclaration.GetType().Name,
                                                          null);
                }
            }
Example #5
0
 private static CsType[] FindExternals(TsFile tsFile)
 {
     return(tsFile.Declarations
            .SelectMany(DependencyFinder.Find)
            .Distinct()
            .ToArray());
 }
Example #6
0
 public DrawingLine(ITerraExplorerObject66 inLine, ITerrainLabel66 inLabel, string markerType, List <string> conObjGuids)
 {
     Type         = "Line";
     SkylineObj   = inLine;
     SkylineLabel = inLabel;
     MarkerType   = markerType;
     ConnObjGuids = conObjGuids;
     Ts           = new TsFile(inLine, Type, "PLine", "X", MarkerType, Name, conObjGuids);
     Ts.WriteTsFile();
 }
Example #7
0
 public DrawingRegion(ITerraExplorerObject66 inRegion, ITerrainLabel66 inLabel66, string markerType, List <string> conObjGuids)
 {
     Type         = "Region";
     SkylineObj   = inRegion;
     SkylineLabel = inLabel66;
     MarkerType   = markerType;
     ConnObjGuids = conObjGuids;
     Ts           = new TsFile(inRegion, Type, "PLine", "X", markerType, Name, ConnObjGuids);
     Ts.WriteTsFile();
 }
Example #8
0
        private IEnumerable <string> GetImportsString(TsFile fromFile, IEnumerable <ISchema> schemas)
        {
            if (fromFile.FileName == Settings.TypesFileName)
            {
                return(new List <string>());
            }

            return(new List <string>
            {
                "import { " + schemas.Select(x => x.GetName()).StrJoin(", ") + " } from \"./types\";"
            });
        }
Example #9
0
        public void Simple()
        {
            var tsFile = new TsFile
            {
                Imports = new[]
                {
                    new TsImport
                    {
                        Default = "FirstDefault",
                        Path    = "some/first/default"
                    },
                    new TsImport
                    {
                        Named = new[] { "FirstNamed" },
                        Path  = "some/first/named"
                    }
                },
                Declarations = new[]
                {
                    new TsNamespace
                    {
                        ExportKind   = TsExportKind.Named,
                        Name         = "SomeNamespace",
                        Declarations = new[]
                        {
                            new TsEnum
                            {
                                ExportKind = TsExportKind.Named,
                                Name       = "SomeEnum",
                                Values     = new[]
                                {
                                    new TsEnumNumberValue
                                    {
                                        Name  = "FirstEnumValue",
                                        Value = 0
                                    }
                                }
                            }
                        }
                    }
                }
            };

            tsFile.ShouldBeTranslatedTo("import FirstDefault from \"some/first/default\";",
                                        "import { FirstNamed } from \"some/first/named\";",
                                        "",
                                        "export namespace SomeNamespace {",
                                        "    export enum SomeEnum {",
                                        "        FirstEnumValue = 0,",
                                        "    }",
                                        "}");
        }
        public void WriteFile(TsFile file)
        {
            var astPayload = JsonConvert.SerializeObject(file.Statements.ToArray());

            var command = new WriteFileCommand()
            {
                AstPayload = astPayload,
                FileName   = file.FileName,
                Path       = file.Path
            };

            this.ExecuteCommand(command);
        }
Example #11
0
        public override List <string> CreateFiles(Dictionary <string, Type> types, Dictionary <string, Function> functions)
        {
            var typeFile = new TsFile(Settings.TypesFileName);

            var relatedSchemas = types.Select(x => x.Value.RelatedSchemas)
                                 .SelectMany(x => x)
                                 .Distinct();

            var imports = GetImportsString(typeFile, relatedSchemas).ToList();

            if (imports.Any())
            {
                typeFile.Write(imports);
                typeFile.Write("");
            }

            foreach (var(_, type) in types)
            {
                typeFile.Write(type.Code);
                typeFile.Write("");
            }

            var exports = types.Select(x => x.Key).StrJoin(", ");

            typeFile.Write("export { " + exports + " };");

            var mainFile = new TsFile(Settings.ClientFileName);

            relatedSchemas = functions.Select(x => x.Value.RelatedSchemas)
                             .SelectMany(x => x)
                             .Distinct();

            imports = GetImportsString(mainFile, relatedSchemas).ToList();

            var template = Context.GetTemplateFactory()
                           .CreateClientTemplate(Settings.ServerUrl, functions.Select(x => x.Value.Code), imports);

            mainFile.Write(template.TransformText());

            if (FileFilter != null)
            {
                FileFilter.Invoke(typeFile);
                FileFilter.Invoke(mainFile);
            }

            return(new List <string>
            {
                typeFile.ToSystemFile(),
                mainFile.ToSystemFile()
            });
        }
Example #12
0
        // todo same folder different case
        public static string WriteFile(string outputDirectory,
                                       TsFile tsFile)
        {
            var directory = string.IsNullOrEmpty(tsFile.Directory) || tsFile.Directory == "."
                                ? Path.GetFullPath(outputDirectory)
                                : Path.Combine(Path.GetFullPath(outputDirectory), tsFile.Directory);

            Directory.CreateDirectory(directory);
            var content  = WriteFileToString(tsFile);
            var filePath = Path.Combine(directory, tsFile.Name + ".ts");

            File.WriteAllText(filePath, content);
            return(filePath);
        }
        public override List <string> CreateFiles(Dictionary <string, Type> types, Dictionary <string, Function> functions)
        {
            var createdFile = new List <string>();

            foreach (var(name, type) in types)
            {
                var file = new TsFile(name);

                var imports = type
                              .RelatedSchemas
                              .Distinct()
                              .Select(x => GetImportsFormRelatedTypes(new List <ISchema> {
                    x
                }))
                              .SelectMany(x => x)
                              .Select(x =>
                                      "import { " + x + $" }} from \"./{x}\";")
                              .ToList();

                if (imports.Any())
                {
                    file.Write(imports);
                    file.Write("");
                }

                file.Write(type.Code);

                file.Write("");

                file.Write("export { " + name + " };");

                createdFile.Add(file.ToSystemFile());
            }

            var clientFile    = new TsFile(Settings.ClientFileName);
            var clientImports = functions.Select(x => x.Value.RelatedSchemas)
                                .SelectMany(x => x)
                                .Distinct().Select(x => "import { " + x.GetName() + " } from \"./" + x.GetName() + "\";");


            var template = Context.GetTemplateFactory()
                           .CreateClientTemplate(Settings.ServerUrl, functions.Select(x => x.Value.Code), clientImports);

            clientFile.Write(template.TransformText());

            createdFile.Add(clientFile.ToSystemFile());

            return(createdFile);
        }
Example #14
0
        /// <summary>
        /// 保存,StretchPoints以Ts部件存入数据库,ScreenPoints自己保存。
        /// </summary>
        public bool Store(ref YWCHEntEx db)
        {
            // 面
            // 根据地质对象类型,弹出数据库编录卡,保存信息(数据来源:私有模型),记录地质点guid
            var partSurfaceGuid = db.SkyFrmSymxDzdx(this.MarkerType);

            if (string.IsNullOrEmpty(partSurfaceGuid))
            {
                return(false);
            }
            var sourceSurfaceGuid = db.PublishPartVer(partSurfaceGuid);

            // 根据面点集构建ts文件
            this.TsSurface = new TsFile(WorldPoints, "TSurf", "M", MarkerType, Name, new List <string>
            {
                sourceSurfaceGuid // ?
            });
            TsSurface.WriteTsFile();

            // 上传面TS文件
            var isSurfacePartUploaded = db.SkyUploadPartVer(partSurfaceGuid, TsSurface.FilePath);

            ////线
            ////创建
            // var newLineGuid = Guid.NewGuid().ToString();
            // var partLineGuid = db.SkyNewObject(MarkerType, newLineGuid, "X", Name, GetColorRGB());
            // if (string.IsNullOrEmpty(partLineGuid))
            // return false;
            // var sourceLineGuid = db.PublishPartVer(partLineGuid);

            ////根据面点集构建ts文件
            // TsLine = new TsFile(WorldPoints, "PLine", "X", MarkerType, Name, new List<string>
            // {
            // sourceLineGuid //??
            // });
            // TsLine.WriteTsFile();

            ////上传面TS文件
            // var isLinePartUploaded = db.SkyUploadPartVer(partLineGuid, TsLine.FilePath);


            return(isSurfacePartUploaded);



            // 将ts文件与地质点关联
            // db.SkyAddConnect(1, TsLine.Guid, markerGuid);
        }
Example #15
0
        private static void AutoImport(TsFile tsFile, Export export)
        {
            var tsImport = new TsImport
            {
                Named = new[]
                {
                    export.Name
                },
                Path = Helpers.GetPathFromAToB(DirectoryToPath(tsFile.Directory),
                                               DirectoryToPath(export
                                                               .TsFile.Directory))
                       + "/" + export.Name
            };

            tsFile.Import(tsImport);
        }
        public void CanWriteTsFile()
        {
            var outputPath = Path.Combine(this.BasePath, "TestOutput");
            var fileName   = "WriteTestOutput.ts";
            var filePath   = Path.Combine(outputPath, fileName);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }

            var ast = this.GetTestAst();

            using (var subject = new TsHost(30050, 30100, 3000))
            {
                var fileInput = new TsFile()
                {
                    FileName   = fileName,
                    Path       = filePath,
                    Statements = ast
                };

                subject.WriteFile(fileInput);
            }

            File.Exists(filePath).Should().BeTrue("Output file must exist.");

            var expectedContent = this.ReadExpectedWriteFileOutput();

            var content = File.ReadAllText(filePath);

            content.Should().Be(expectedContent);
        }
Example #17
0
 public Export(TsDeclaration tsDeclaration, TsFile tsFile)
 {
     CsType = tsDeclaration.CsType;
     Name   = tsDeclaration.Name;
     TsFile = tsFile;
 }
        /// <summary>
        /// 生成曲面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonXBuild_Click(object sender, EventArgs e)
        {
            double attitudeL = this.doubleInputAttitudeLength.Value;
            double shapeR    = this.doubleInputShapeRadium.Value;

            // 生成产状数据集
            double       nx = 0.0, ny = 0.0, nz = 0.0;
            List <Point> sourceAttitudePoints = new List <Point>(this.targetMarkersList.Count * 4);

            foreach (var marker in this.targetMarkersList)
            {
                nx += Math.Sin(marker.MyDip * Math.PI / 180) * Math.Sin(marker.MyAngle * Math.PI / 180)
                      / this.targetMarkersList.Count;
                ny += Math.Cos(marker.MyDip * Math.PI / 180) * Math.Sin(marker.MyAngle * Math.PI / 180)
                      / this.targetMarkersList.Count;
                nz += Math.Cos(marker.MyAngle * Math.PI / 180) / this.targetMarkersList.Count;


                double dx         = -Math.Tan(marker.MyAngle * Math.PI / 180) * Math.Cos(marker.MyDip * Math.PI / 180);
                double dy         = -Math.Tan(marker.MyAngle * Math.PI / 180) * Math.Sin(marker.MyDip * Math.PI / 180);
                Point  northPoint = new Point(
                    marker.X,
                    marker.Y + attitudeL,
                    marker.Z + dy * attitudeL);
                Point southPoint = new Point(
                    marker.X,
                    marker.Y - attitudeL,
                    marker.Z - dy * attitudeL);
                Point eastPoint = new Point(
                    marker.X + attitudeL,
                    marker.Y,
                    marker.Z + dx * attitudeL);
                Point westPoint = new Point(
                    marker.X - attitudeL,
                    marker.Y,
                    marker.Z - dx * attitudeL);

                sourceAttitudePoints.AddRange(new[] { northPoint, southPoint, eastPoint, westPoint });
            }

            Point middlePoint = CurveAlgorithm.MiddlePointOfPoints(this.targetMarkersList);

            // 平均产状平面
            Vector3D n     = new Vector3D(nx, ny, nz);
            var      plane = new MathNet.Spatial.Euclidean.Plane(
                new Point3D(middlePoint.X, middlePoint.Y, middlePoint.Z),
                n.Normalize());

            double a0 = -plane.D / plane.C;
            double a1 = -plane.A / plane.C;
            double a2 = -plane.B / plane.C;

            // 插值点数据集
            List <Point> sourcePoints = new List <Point>(this.targetMarkersList);

            sourcePoints.AddRange(sourceAttitudePoints);

            SurfaceEquation surfaceEquation = new SurfaceEquation(a0, a1, a2, sourcePoints, shapeR);

            // 确定曲面区域
            List <Point> edgePoints = CurveAlgorithm.GetEdgePoints(sourcePoints, this.GridEdgeLength);

            // 区域内插加密点 GeoHelper.InsertPointsInPolygon
            List <Point> pointsList = GeoHelper.InsertPointsInPolygon(edgePoints, this.GridEdgeLength);

            // 生成网格 Triangulations
            Triangulations tris = new Triangulations(pointsList, new List <Point>());

            // 计算插值 SurfaceMesh
            tris.MeshSurface(surfaceEquation);

            // 绘制曲面
            IColor66 fillColor = this.sgworld.Creator.CreateColor(128, 128, 128, 128);
            IColor66 lineColor = this.sgworld.Creator.CreateColor(255, 255, 255, 0);

            var parentGid = GeoHelper.CreateGroup("产状地质曲面", ref this.sgworld);



            Facet facet = new Facet(ref this.sgworld, tris.TsData, "Test", parentGid, lineColor, fillColor);

            // facet.DrawFacet();

            // 保存三角网结果
            TsFile ts = new TsFile(
                tris.TsData,
                "TSurf",
                "M",
                "JGM",
                "Name",
                new List <string>());

            ts.WriteTsFile();
            ts.UpdateTsFile(ref this.db);

            ToastNotification.Show(this, "曲面模型已保存为模型部件", 2500, eToastPosition.MiddleCenter);
        }