兼容新排位软件。

This commit is contained in:
n3040 2024-02-29 16:31:57 +08:00
parent 7ce4357fbe
commit edb3ad63c3
9 changed files with 300 additions and 44 deletions

View File

@ -81,6 +81,7 @@
this.Controls.Add(this.LB_SFilePath);
this.Name = "Gui";
this.Text = "Gui";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Gui_FormClosed);
this.ResumeLayout(false);
this.PerformLayout();

View File

@ -19,7 +19,7 @@ namespace PutTowerPosition
private void BT_SelectSFile_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "S files (*.dat)|*.dat";
openFileDialog.Filter = "S or cadd files (*.dat;*.cadd)|*.dat;*.cadd";
openFileDialog.Multiselect = false;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
@ -36,5 +36,11 @@ namespace PutTowerPosition
}
}
private void Gui_FormClosed(object sender, FormClosedEventArgs e)
{
PutTowerPosition.Cmd.releaseLatestTowerList();
Application.Exit();
}
}
}

View File

@ -1,10 +1,10 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.8689
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
@ -12,7 +12,7 @@ namespace PutTowerPosition.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.0.3.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -10,8 +10,29 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PutTowerPosition</RootNamespace>
<AssemblyName>PutTowerPostion</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -23,6 +44,9 @@
<WarningLevel>4</WarningLevel>
<StartAction>Program</StartAction>
<StartProgram>C:\Program Files\AutoCAD 2010\acad.exe</StartProgram>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<PlatformTarget>x64</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
@ -32,26 +56,29 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="acdbmgd, Version=18.0.0.0, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files\AutoCAD 2010\acdbmgd.dll</HintPath>
<Reference Include="accoremgd">
<HintPath>..\..\..\Program Files\Cad2022\AutoCAD 2022\accoremgd.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="acmgd, Version=18.0.0.0, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files\AutoCAD 2010\acmgd.dll</HintPath>
<Reference Include="acdbmgd">
<HintPath>..\..\..\Program Files\Cad2022\AutoCAD 2022\acdbmgd.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="acmgd">
<HintPath>..\..\..\Program Files\Cad2022\AutoCAD 2022\acmgd.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.Office.Interop.Excel, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files (x86)\Microsoft Office\root\Office16\ADDINS\Microsoft Power Query for Excel Integrated\bin\Microsoft.Office.Interop.Excel.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>Newtonsoft.Json.11.0.2\lib\net35\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
@ -85,6 +112,7 @@
<Compile Include="Utils.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@ -95,6 +123,26 @@
<DependentUpon>Gui.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -1,8 +1,19 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
<StartProgram>D:\Program Files\Cad2022\AutoCAD 2022\acad.exe</StartProgram>
<StartAction>Program</StartAction>
</PropertyGroup>
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
<PublishUrlHistory />
<InstallUrlHistory />
<SupportUrlHistory />
<UpdateUrlHistory />
<BootstrapperUrlHistory />
<ErrorReportUrlHistory />
<FallbackCulture>en-US</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup>
</Project>

View File

@ -13,6 +13,12 @@ using System.Security.Cryptography;
using System.Runtime.InteropServices;
using System.IO;
using System.Reflection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Xml.Linq;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Runtime.Remoting.Lifetime;
[assembly: CommandClass(typeof(PutTowerPosition.Cmd))]
namespace PutTowerPosition
@ -21,7 +27,7 @@ namespace PutTowerPosition
public class Cmd
{
struct spanStruct
public struct spanStruct
{
public string towerName;
@ -60,12 +66,24 @@ namespace PutTowerPosition
gui.Show();
}
public static void releaseLatestTowerList()
{
latestTowerList = null;
}
public static void PutTowerPosition(string SFilePath)
{
string excelFile = findCordinationExcel(SFilePath);
Dictionary<string, double[]> cordDic = readCordExcel(excelFile);
List<spanStruct> spanList = readSSpan(SFilePath);
string rootDir = Path.GetDirectoryName(SFilePath);
List<spanStruct> spanList=null;
if (SFilePath.EndsWith(".dat"))
{
spanList = readSSpan(SFilePath);
}
if (SFilePath.EndsWith(".cadd"))
{
spanList = readCaddSpan(SFilePath);
}
Document acDoc;
Database acCurDb;
//acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.Open(filePath, true);
@ -107,27 +125,38 @@ namespace PutTowerPosition
}
Position[] cordinationList = calTowerXYPostion(cordDic, spanList);
foreach (Position point in cordinationList)
if (cordinationList != null)
{
DBPoint dbPoint = new DBPoint(new Point3d(point.Y, point.X, 0));
dbPoint.Layer = "TW";
acBlkTblRec.AppendEntity(dbPoint);
acTrans.AddNewlyCreatedDBObject(dbPoint, true);
acCurDb.Pdmode = 35;
acCurDb.Pdsize = 15;
DBText dbTowerName=new DBText();
dbTowerName.TextString = point.towerName;
Point3d towerNamePoint = new Point3d(point.Y + 20, point.X + 20,0);
dbTowerName.Position = towerNamePoint;
dbTowerName.Layer = "TW";
dbTowerName.Height = 40;
acBlkTblRec.AppendEntity(dbTowerName);
acTrans.AddNewlyCreatedDBObject(dbTowerName,true);
Tower latestTower;
latestTower.name = dbTowerName.ObjectId;
latestTower.point = dbPoint.ObjectId;
latestTowerList.Add(latestTower);
foreach (Position point in cordinationList)
{
DBPoint dbPoint = new DBPoint(new Point3d(point.Y, point.X, 0));
dbPoint.Layer = "TW";
acBlkTblRec.AppendEntity(dbPoint);
acTrans.AddNewlyCreatedDBObject(dbPoint, true);
acCurDb.Pdmode = 35;
acCurDb.Pdsize = 15;
DBText dbTowerName = new DBText();
dbTowerName.TextString = point.towerName;
Point3d towerNamePoint = new Point3d(point.Y + 20, point.X + 20, 0);
dbTowerName.Position = towerNamePoint;
dbTowerName.Layer = "TW";
dbTowerName.Height = 40;
acBlkTblRec.AppendEntity(dbTowerName);
acTrans.AddNewlyCreatedDBObject(dbTowerName, true);
Tower latestTower;
latestTower.name = dbTowerName.ObjectId;
latestTower.point = dbPoint.ObjectId;
latestTowerList.Add(latestTower);
}
//写坐标
StreamWriter cordTextWriter = new StreamWriter(rootDir + "/cord.txt");
foreach (Position point in cordinationList)
{
cordTextWriter.WriteLine(point.towerName + "," + point.Y + "," + point.X);//地理Y和X坐标与数学坐标相比是反的。
}
cordTextWriter.Close();
}
acTrans.Commit();
}
//acBlkTblRec.Database.SaveAs(outputFilePath, false, DwgVersion.Current, acDoc.Database.SecurityParameters);
@ -288,14 +317,79 @@ namespace PutTowerPosition
break;
}
double[] cordination = new double[2];
cordination[0] = (double)(get_value(w_sheet, "B" + i.ToString()));
cordination[1] = (double)(get_value(w_sheet, "C" + i.ToString()));
towerCordination.Add(towerName, cordination);
cordination[1] = (double)(get_value(w_sheet, "B" + i.ToString()));
cordination[0] = (double)(get_value(w_sheet, "C" + i.ToString()));
towerCordination.Add(towerName.Trim(), cordination);
}
return towerCordination;
}
public static List<spanStruct> readCaddSpan(string CaddFilePath)
{
//StreamReader reader = new StreamReader(SFilePath, Encoding.GetEncoding("gb2312"));
string json = File.ReadAllText(CaddFilePath, Encoding.GetEncoding("gb2312"));
JObject objs = JObject.Parse(json);
JArray dingweiData = objs["08定位数据"]["01定位数据"] as JArray;
double basicMileage = 0;
List<spanStruct> spanList = new List<spanStruct>();
foreach (JObject towerInfo in dingweiData)
{
double mileage = (double)towerInfo["03累距"];
double span = mileage - basicMileage;
string towerName;
towerName= (string)towerInfo["00塔号"];
spanStruct _span;
_span.towerName = towerName;
_span.span = span;
spanList.Add(_span);
basicMileage = mileage;
}
//Dictionary<string, char> has_tower = new Dictionary<string, char>();
//while ((line = reader.ReadLine()) != null)
//{
// if (line.Trim().StartsWith("首端") | line.Trim().StartsWith("塔号"))
// {
// continue;
// }
// if (line.Trim() == "")
// {
// continue;
// }
// string norm_line;
// norm_line = Regex.Replace(line, @"\s+", ",");
// if (norm_line.StartsWith(","))
// {
// norm_line = norm_line.Substring(1);
// }
// string[] sep = norm_line.Split(',');
// string towerName = sep[0];
// if (has_tower.ContainsKey(towerName))
// {
// continue;
// }
// has_tower.Add(towerName, ' ');
// double mileage = Double.Parse(sep[1]);
// double span;
// if (basicMileage == -1)
// {
// basicMileage = mileage;
// }
// span = mileage - basicMileage;
// spanStruct _span;
// _span.towerName = towerName;
// _span.span = span;
// spanList.Add(_span);
// basicMileage = mileage;
//}
//reader.Close();
return spanList;
}
static List<spanStruct> readSSpan(string SFilePath)
{
StreamReader reader = new StreamReader(SFilePath, Encoding.GetEncoding("gb2312"));
@ -352,9 +446,16 @@ namespace PutTowerPosition
tensionStart = 0;
//find next end point
Point2D endPoint;
int inCaseOfInfinite=0;
while (true)
{
inCaseOfInfinite++;
Position startPosition;
if (!cordDic.ContainsKey(SSpan[tensionStart].towerName))
{
MessageBox.Show("字典中无关键字" + SSpan[tensionStart].towerName);
return null;
}
startPoint.X = cordDic[SSpan[tensionStart].towerName][0];
startPoint.Y = cordDic[SSpan[tensionStart].towerName][1];
startPosition.towerName = SSpan[tensionStart].towerName;
@ -394,6 +495,11 @@ namespace PutTowerPosition
{
break;
}
if (inCaseOfInfinite > 10000)
{
MessageBox.Show("进入无限循环了。");
break;
}
}
return cordinationList;

6
Test/App.config Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

19
Test/Program.cs Normal file
View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PutTowerPosition;
namespace PutTowerPosition
{
internal class Program
{
static void Main(string[] args)
{
PutTowerPosition.Cmd.readCaddSpan("d:\\工程\\750kV白银3回\\排位\\750白银3\\750白银3.cadd");
System.Console.WriteLine("Finished.");
System.Console.ReadKey();
}
}
}

59
Test/Test.csproj Normal file
View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{31613C09-BD2B-41D1-A375-0FC306504569}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Test</RootNamespace>
<AssemblyName>Test</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PutTowerPosition\PutTowerPosition.csproj">
<Project>{ca8fb7a3-ceb6-471c-bb97-76cbfa17293c}</Project>
<Name>PutTowerPosition</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>