diff options
Diffstat (limited to 'Master/CGuCAD/projects/CsMgdAcad1')
13 files changed, 1564 insertions, 0 deletions
diff --git a/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1.sln b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1.sln new file mode 100644 index 0000000..f8e713d --- /dev/null +++ b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1.sln @@ -0,0 +1,20 @@ +
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual Studio 2005
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CsMgdAcad1", "CsMgdAcad1\CsMgdAcad1.csproj", "{FB5AE77B-ECBA-4167-944F-BC4FF7E830F3}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {FB5AE77B-ECBA-4167-944F-BC4FF7E830F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FB5AE77B-ECBA-4167-944F-BC4FF7E830F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FB5AE77B-ECBA-4167-944F-BC4FF7E830F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FB5AE77B-ECBA-4167-944F-BC4FF7E830F3}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1.suo b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1.suo Binary files differnew file mode 100644 index 0000000..274c410 --- /dev/null +++ b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1.suo diff --git a/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/ClassDiagram1.cd b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/ClassDiagram1.cd new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/ClassDiagram1.cd @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/Commands.cs b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/Commands.cs new file mode 100644 index 0000000..076f037 --- /dev/null +++ b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/Commands.cs @@ -0,0 +1,50 @@ +// (C) Copyright 2002-2007 by Autodesk, Inc.
+//
+// Permission to use, copy, modify, and distribute this software in
+// object code form for any purpose and without fee is hereby granted,
+// provided that the above copyright notice appears in all copies and
+// that both that copyright notice and the limited warranty and
+// restricted rights notice below appear in all supporting
+// documentation.
+//
+// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
+// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
+// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
+// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
+// UNINTERRUPTED OR ERROR FREE.
+//
+// Use, duplication, or disclosure by the U.S. Government is subject to
+// restrictions set forth in FAR 52.227-19 (Commercial Computer
+// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
+// (Rights in Technical Data and Computer Software), as applicable.
+//
+
+using System;
+using Autodesk.AutoCAD.Runtime;
+
+[assembly: CommandClass(typeof(CsMgdAcad1.CGCAD_seiCommands))]
+
+namespace CsMgdAcad1
+{
+ /// <summary>
+ /// Summary description for CGCAD_seiCommands.
+ /// </summary>
+ public class CGCAD_seiCommands
+ {
+ public CGCAD_seiCommands()
+ {
+ //
+ // TODO: Add constructor logic here
+ //
+ }
+
+ // Define Command "AsdkCmd1"
+ [CommandMethod("testcs")]
+ static public void test() // This method can have any name
+ {
+ TestCSApp t = new TestCSApp();
+ t.Main();
+ }
+
+ }
+}
\ No newline at end of file diff --git a/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/CsMgdAcad1.csproj b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/CsMgdAcad1.csproj new file mode 100644 index 0000000..e763052 --- /dev/null +++ b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/CsMgdAcad1.csproj @@ -0,0 +1,63 @@ +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.50727</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{FB5AE77B-ECBA-4167-944F-BC4FF7E830F3}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>CsMgdAcad1</RootNamespace>
+ <AssemblyName>CsMgdAcad1</AssemblyName>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <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' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="acdbmgd, Version=17.2.0.0, Culture=neutral, processorArchitecture=x86">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>C:\Programme\AutoCAD Civil 3D 2009\acdbmgd.dll</HintPath>
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="acmgd, Version=17.2.0.0, Culture=neutral, processorArchitecture=x86">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>C:\Programme\AutoCAD Civil 3D 2009\acmgd.dll</HintPath>
+ <Private>False</Private>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Commands.cs" />
+ <Compile Include="Edge.cs" />
+ <Compile Include="Node.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Speiche.cs" />
+ <Compile Include="SpeichenStern.cs" />
+ <Compile Include="SpeichenSternList.cs" />
+ <Compile Include="TestCSApp.cs" />
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\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.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
\ No newline at end of file diff --git a/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/CsMgdAcad1.csproj.user b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/CsMgdAcad1.csproj.user new file mode 100644 index 0000000..c6517cb --- /dev/null +++ b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/CsMgdAcad1.csproj.user @@ -0,0 +1,10 @@ +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <StartAction>Program</StartAction>
+ <StartProgram>C:\Programme\AutoCAD Civil 3D 2009\acad.exe</StartProgram>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <StartAction>Program</StartAction>
+ <StartProgram>C:\Programme\AutoCAD Civil 3D 2009\acad.exe</StartProgram>
+ </PropertyGroup>
+</Project>
\ No newline at end of file diff --git a/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/Edge.cs b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/Edge.cs new file mode 100644 index 0000000..a71927b --- /dev/null +++ b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/Edge.cs @@ -0,0 +1,151 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+using Autodesk.AutoCAD.Runtime;
+using Autodesk.AutoCAD.DatabaseServices;
+using Autodesk.AutoCAD.ApplicationServices;
+using Autodesk.AutoCAD.EditorInput;
+using Autodesk.AutoCAD.Geometry;
+using System.Collections;
+
+namespace CsMgdAcad1
+{
+ enum EdgeType
+ {
+ TK, EMPTY, CONTOUR, INNER
+ }
+ class Edge
+ {
+ public int iEdgeIdx;
+ public EdgeType eEdgeType;
+ public Node pStartNode;
+ public Node pEndNode;
+
+ public Edge(EdgeType t)
+ {
+ this.eEdgeType = t;
+ }
+
+ public double GetAngleToXAxis()
+ {
+ double angle;
+ angle = Math.Atan2(pEndNode.point.Y - pStartNode.point.Y, pEndNode.point.X - pStartNode.point.X);
+ if (angle < 0.0)
+ {
+ angle += 2 * Math.PI;
+ }
+ return angle;
+ }
+ public double GetInvAngleToXAxis()
+ {
+ double angle;
+ angle = Math.Atan2(pStartNode.point.Y - pEndNode.point.Y, pStartNode.point.X - pEndNode.point.X);
+ if (angle < 0.0)
+ {
+ angle += 2 * Math.PI;
+ }
+ return angle;
+ }
+
+ public double GetInvAngleToXAxisDeg()
+ {
+ return GetInvAngleToXAxis() * 180 / Math.PI;
+ }
+ public double GetAngleToXAxisDeg()
+ {
+ return GetAngleToXAxis() * 180 / Math.PI;
+ }
+ public double GetLength()
+ {
+ double length;
+ double x = pEndNode.point.X - pStartNode.point.X;
+ double y = pEndNode.point.Y - pStartNode.point.Y;
+ length = Math.Sqrt(x * x + y * y);
+ return length;
+ }
+
+ public bool arePointsOnSameSide(Edge otherEdge)
+ {
+ //bool res = false;
+ //Vector3d startPointVector = new Vector3d(pStartNode.point.X, pStartNode.point.Y, 0);
+ //Vector3d endPointVector = new Vector3d(pEndNode.point.X, pEndNode.point.Y, 0);
+ //Vector3d normalVector = startPointVector.CrossProduct(endPointVector);
+
+ //Vector3d p = new Vector3d(otherEdge.pStartNode.point.X, otherEdge.pStartNode.point.Y, 0);
+ //Vector3d q = new Vector3d(otherEdge.pEndNode.point.X, otherEdge.pEndNode.point.Y, 0);
+
+ //double pRelPos = normalVector.DotProduct(p);
+ //double qRelPos = normalVector.DotProduct(q);
+ //res = Math.Sign(pRelPos) == Math.Sign(qRelPos);
+ //return res;
+ return arePointsOnSameSide(otherEdge.pStartNode, otherEdge.pEndNode);
+ }
+
+ public bool arePointsOnSameSide(Node n1, Node n2)
+ {
+ bool res = false;
+ const double EPS = 0.0000000001;
+
+ Vector3d startPointVector = new Vector3d(pStartNode.point.X, pStartNode.point.Y, 1);
+ Vector3d endPointVector = new Vector3d(pEndNode.point.X, pEndNode.point.Y, 1);
+ Vector3d normalVector = startPointVector.CrossProduct(endPointVector);
+
+ Vector3d p = new Vector3d(n1.point.X, n1.point.Y, 1);
+ Vector3d q = new Vector3d(n2.point.X, n2.point.Y, 1);
+
+ double pRelPos = normalVector.DotProduct(p);
+ double qRelPos = normalVector.DotProduct(q);
+ int sgnP =Math.Sign(pRelPos);
+ if (Math.Abs(pRelPos) < EPS)
+ {
+ sgnP = 1;
+ }
+ int sgnQ = Math.Sign(qRelPos);
+ if (Math.Abs(qRelPos) < EPS)
+ {
+ sgnQ = 1;
+ }
+ res = sgnP == sgnQ;
+ return res;
+ }
+
+ public bool intersects(Edge otherEdge)
+ {
+ if (pStartNode.iNodeIdx == otherEdge.pStartNode.iNodeIdx || pStartNode.iNodeIdx == otherEdge.pEndNode.iNodeIdx
+ || pEndNode.iNodeIdx == otherEdge.pStartNode.iNodeIdx || pEndNode.iNodeIdx == otherEdge.pEndNode.iNodeIdx)
+ {
+ return false;
+ }
+ Vector3d sVec1 = new Vector3d(pStartNode.point.X, pStartNode.point.Y, 0);
+ Vector3d eVec1 = new Vector3d(pEndNode.point.X, pEndNode.point.Y, 0);
+ Vector3d sVec2 = new Vector3d(otherEdge.pStartNode.point.X, otherEdge.pStartNode.point.Y, 0);
+ Vector3d eVec2 = new Vector3d(otherEdge.pEndNode.point.X, otherEdge.pEndNode.point.Y, 0);
+ Vector3d n1 = sVec1.CrossProduct(eVec1);
+ Vector3d n2 = sVec2.CrossProduct(eVec2);
+ Vector3d temp = n1.CrossProduct(n2);
+ Vector3d intersectionPoint = new Vector3d(temp.X / temp.Z, temp.Y / temp.Z, 1);
+ if (intersectionPoint.IsEqualTo(sVec1) || intersectionPoint.IsEqualTo(eVec1)
+ || intersectionPoint.IsEqualTo(sVec2) || intersectionPoint.IsEqualTo(eVec2))
+ {
+ return false;
+ }
+
+ Vector3d v1 = new Vector3d(intersectionPoint.X - pStartNode.point.X, intersectionPoint.Y - pStartNode.point.Y, 0);
+ Vector3d v2 = new Vector3d(pEndNode.point.X - intersectionPoint.X, pEndNode.point.Y - intersectionPoint.Y, 0);
+ Vector3d v3 = new Vector3d(intersectionPoint.X - otherEdge.pStartNode.point.X, intersectionPoint.Y - otherEdge.pStartNode.point.Y, 0);
+ Vector3d v4 = new Vector3d(otherEdge.pEndNode.point.X - intersectionPoint.X, otherEdge.pEndNode.point.Y - intersectionPoint.Y, 0);
+ if (v1.IsEqualTo(v2) || v3.IsEqualTo(v4))
+ {
+ return false;
+ }
+ if ((Math.Sign(v1.X) == Math.Sign(v2.X)) && (Math.Sign(v1.Y) == Math.Sign(v2.Y)) && (Math.Sign(v3.X) == Math.Sign(v4.X)) && (Math.Sign(v3.Y) == Math.Sign(v4.Y)))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+}
diff --git a/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/Node.cs b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/Node.cs new file mode 100644 index 0000000..ddd7e18 --- /dev/null +++ b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/Node.cs @@ -0,0 +1,47 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+using Autodesk.AutoCAD.Runtime;
+using Autodesk.AutoCAD.DatabaseServices;
+using Autodesk.AutoCAD.ApplicationServices;
+using Autodesk.AutoCAD.EditorInput;
+using Autodesk.AutoCAD.Geometry;
+using System.Collections;
+
+namespace CsMgdAcad1
+{
+ class Node
+ {
+ public int iNodeIdx;
+ public Point2d point;
+
+ public double GetAngleToEdgeStartPoint(Edge edge)
+ {
+ double angle;
+ angle = Math.Atan2(edge.pStartNode.point.Y - point.Y,edge.pStartNode.point.X - point.X );
+ if (angle < 0.0)
+ {
+ angle += 2 * Math.PI;
+ }
+ return angle;
+ }
+ public double GetAngleToEdgeStartPointDeg(Edge edge)
+ {
+ return GetAngleToEdgeStartPoint(edge) * 180 / Math.PI;
+ }
+ public double GetAngleToEdgeEndPoint(Edge edge)
+ {
+ double angle;
+ angle = Math.Atan2(edge.pEndNode.point.Y - point.Y, edge.pEndNode.point.X - point.X);
+ if (angle < 0.0)
+ {
+ angle += 2 * Math.PI;
+ }
+ return angle;
+ }
+ public double GetAngleToEdgeEndPointDeg(Edge edge)
+ {
+ return GetAngleToEdgeEndPoint(edge) * 180 / Math.PI;
+ }
+ }
+}
diff --git a/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/Properties/AssemblyInfo.cs b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f57adaa --- /dev/null +++ b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/Properties/AssemblyInfo.cs @@ -0,0 +1,79 @@ +// (C) Copyright 2002-2007 by Autodesk, Inc.
+//
+// Permission to use, copy, modify, and distribute this software in
+// object code form for any purpose and without fee is hereby granted,
+// provided that the above copyright notice appears in all copies and
+// that both that copyright notice and the limited warranty and
+// restricted rights notice below appear in all supporting
+// documentation.
+//
+// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
+// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
+// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
+// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
+// UNINTERRUPTED OR ERROR FREE.
+//
+// Use, duplication, or disclosure by the U.S. Government is subject to
+// restrictions set forth in FAR 52.227-19 (Commercial Computer
+// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
+// (Rights in Technical Data and Computer Software), as applicable.
+//
+
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+//
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+//
+[assembly: AssemblyTitle("")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+//
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+
+[assembly: AssemblyVersion("1.0.*")]
+
+//
+// In order to sign your assembly you must specify a key to use. Refer to the
+// Microsoft .NET Framework documentation for more information on assembly signing.
+//
+// Use the attributes below to control which key is used for signing.
+//
+// Notes:
+// (*) If no key is specified, the assembly is not signed.
+// (*) KeyName refers to a key that has been installed in the Crypto Service
+// Provider (CSP) on your machine. KeyFile refers to a file which contains
+// a key.
+// (*) If the KeyFile and the KeyName values are both specified, the
+// following processing occurs:
+// (1) If the KeyName can be found in the CSP, that key is used.
+// (2) If the KeyName does not exist and the KeyFile does exist, the key
+// in the KeyFile is installed into the CSP and used.
+// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
+// When specifying the KeyFile, the location of the KeyFile should be
+// relative to the project output directory which is
+// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
+// located in the project directory, you would specify the AssemblyKeyFile
+// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
+// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
+// documentation for more information on this.
+//
+[assembly: AssemblyDelaySign(false)]
+[assembly: AssemblyKeyFile("")]
+[assembly: AssemblyKeyName("")]
diff --git a/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/Speiche.cs b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/Speiche.cs new file mode 100644 index 0000000..393040c --- /dev/null +++ b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/Speiche.cs @@ -0,0 +1,52 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+using Autodesk.AutoCAD.ApplicationServices;
+
+namespace CsMgdAcad1
+{
+ class Speiche
+ {
+ public double rangeStartAngle;
+ public Speiche nextSpeiche;
+ public Edge edge;
+ public const double EPS = 0.000000000000001;
+
+ public Speiche()
+ {
+ this.nextSpeiche = this;
+ this.rangeStartAngle = 0.0d;
+ this.edge = new Edge(EdgeType.EMPTY);
+ }
+ public void Dump() {
+ if (edge.eEdgeType == EdgeType.CONTOUR || edge.eEdgeType == EdgeType.INNER)
+ {
+ Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(
+ "\n\tAngle " + rangeStartAngle + " blocked by edge: [" + edge.pStartNode.iNodeIdx + ";"
+ + edge.pEndNode.iNodeIdx + "], index:" + edge.iEdgeIdx + ", type: " + edge.eEdgeType);
+ }
+ else {
+ Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(
+ "\n\tAngle " + rangeStartAngle + " blocked by edge: type: " + edge.eEdgeType);
+ }
+
+ }
+ public Speiche GetEndSpeicheForAngle(double searchAngle)
+ {
+ Speiche actSpeiche = this;
+ while (actSpeiche.nextSpeiche.rangeStartAngle != 0.0)
+ {
+ if (actSpeiche.rangeStartAngle < searchAngle &&
+ (actSpeiche.nextSpeiche.rangeStartAngle >= searchAngle || actSpeiche.nextSpeiche.rangeStartAngle == 0.0))
+ {
+ return actSpeiche.nextSpeiche;
+ }
+ else
+ {
+ actSpeiche = actSpeiche.nextSpeiche;
+ }
+ }
+ return actSpeiche.nextSpeiche;
+ }
+ }
+}
diff --git a/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/SpeichenStern.cs b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/SpeichenStern.cs new file mode 100644 index 0000000..ce68d22 --- /dev/null +++ b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/SpeichenStern.cs @@ -0,0 +1,522 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+using Autodesk.AutoCAD.Runtime;
+using Autodesk.AutoCAD.DatabaseServices;
+using Autodesk.AutoCAD.ApplicationServices;
+using Autodesk.AutoCAD.EditorInput;
+using Autodesk.AutoCAD.Geometry;
+using System.Collections;
+
+namespace CsMgdAcad1
+{
+ class SpeichenStern
+ {
+ public const int TK = -1;
+ public const int EMPTY = -2;
+
+ public Speiche wurzelSpeiche;
+ public Node node;
+
+ public SpeichenStern(Node node)
+ {
+ this.wurzelSpeiche = new Speiche();
+ this.node = node;
+ }
+
+ public int GetEdgeIdxForAngle(double searchAngle)
+ {
+ return GetStartSpeicheForAngle(searchAngle).edge.iEdgeIdx;
+ }
+
+ public Speiche GetBlockingSpeicheForAngle(double searchAngle)
+ {
+ if (wurzelSpeiche.Equals(wurzelSpeiche.nextSpeiche))
+ {
+ return wurzelSpeiche;
+ }
+ Speiche actSpeiche = wurzelSpeiche;
+
+ while (actSpeiche.nextSpeiche.rangeStartAngle != 0.0d)
+ {
+ if (actSpeiche.rangeStartAngle <= searchAngle &&
+ (actSpeiche.nextSpeiche.rangeStartAngle > searchAngle || actSpeiche.nextSpeiche.rangeStartAngle == 0.0d) )
+ {
+ return actSpeiche;
+ }
+ actSpeiche = actSpeiche.nextSpeiche;
+ }
+ return wurzelSpeiche;
+ }
+
+ public Speiche GetStartSpeicheForAngle(double searchAngle)
+ {
+ if (wurzelSpeiche.Equals(wurzelSpeiche.nextSpeiche))
+ {
+ return wurzelSpeiche;
+ }
+ Speiche startSpeiche = wurzelSpeiche;
+
+ while (startSpeiche.nextSpeiche.rangeStartAngle != 0.0d)
+ {
+ if (startSpeiche.rangeStartAngle <= searchAngle &&
+ (startSpeiche.nextSpeiche.rangeStartAngle > searchAngle || startSpeiche.nextSpeiche.rangeStartAngle == 0.0d) )
+ {
+ return startSpeiche;
+ }
+ startSpeiche = startSpeiche.nextSpeiche;
+ }
+ return startSpeiche;
+ }
+
+ public Speiche GetEndSpeicheForAngle(double searchAngle)
+ {
+ if (wurzelSpeiche.Equals(wurzelSpeiche.nextSpeiche))
+ {
+ return wurzelSpeiche;
+ }
+ Speiche endSpeiche = wurzelSpeiche;
+
+ while (endSpeiche.nextSpeiche.rangeStartAngle != 0.0d)
+ {
+ if (endSpeiche.rangeStartAngle < searchAngle && (endSpeiche.nextSpeiche.rangeStartAngle >= searchAngle || endSpeiche.nextSpeiche.rangeStartAngle == 0.0d) )
+ {
+ return endSpeiche.nextSpeiche;
+ }
+ endSpeiche = endSpeiche.nextSpeiche;
+ }
+ return endSpeiche.nextSpeiche;
+ }
+
+ public void SetEdgeForAngleRange(Edge edge, double rangeStartAngle, double rangeEndAngle)
+ {
+ // for debugging only, adjust indice and set breakpoint
+ if(this.node.iNodeIdx == 4 && edge.iEdgeIdx== 1)
+ {
+ int i = -1;
+ }
+ bool over360Deg = false;
+ if(rangeStartAngle > rangeEndAngle) {
+ if (Math.Abs(rangeStartAngle - rangeEndAngle) > 180.0d)
+ {
+ over360Deg = true;
+ }
+ else
+ {
+ double tmp;
+ tmp = rangeStartAngle;
+ rangeStartAngle = rangeEndAngle;
+ rangeEndAngle = tmp;
+ }
+ }
+
+ if (over360Deg && edge.eEdgeType == EdgeType.CONTOUR)
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nInserting edge [" + edge.pStartNode.iNodeIdx + ";" + edge.pEndNode.iNodeIdx + "] into Speichenstern " + node.iNodeIdx);
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nStart Range Angle: " + rangeStartAngle + " end range angle: " + rangeEndAngle);
+ if (wurzelSpeiche.edge.eEdgeType == EdgeType.EMPTY)
+ {
+ if (wurzelSpeiche.nextSpeiche.rangeStartAngle == rangeEndAngle)
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCase A0");
+ wurzelSpeiche.edge = edge;
+ Speiche ends = GetStartSpeicheForAngle(rangeStartAngle);
+ if (ends.rangeStartAngle == rangeStartAngle)
+ {
+ ends.edge = edge;
+ return;
+ }
+ else if (ends.rangeStartAngle < rangeStartAngle)
+ {
+ Speiche newSpeiche = new Speiche();
+ newSpeiche.rangeStartAngle = rangeStartAngle;
+ newSpeiche.edge = edge;
+ newSpeiche.nextSpeiche = ends.nextSpeiche;
+ ends.nextSpeiche = newSpeiche;
+ return;
+ }
+ }
+ else if (wurzelSpeiche.nextSpeiche.rangeStartAngle > rangeEndAngle)
+ {
+ Speiche newSpeiche = new Speiche();
+ newSpeiche.rangeStartAngle = rangeEndAngle;
+ newSpeiche.edge = wurzelSpeiche.edge;
+ newSpeiche.nextSpeiche = wurzelSpeiche.nextSpeiche;
+ wurzelSpeiche.nextSpeiche = newSpeiche;
+ wurzelSpeiche.edge = edge;
+ Speiche ends = GetStartSpeicheForAngle(rangeStartAngle);
+ if (ends.rangeStartAngle == rangeStartAngle)
+ {
+ ends.edge = edge;
+ return;
+ }
+ else if (ends.rangeStartAngle < rangeStartAngle)
+ {
+ Speiche newSpeiche2 = new Speiche();
+ newSpeiche2.rangeStartAngle = rangeStartAngle;
+ newSpeiche2.edge = edge;
+ newSpeiche2.nextSpeiche = ends.nextSpeiche;
+ ends.nextSpeiche = newSpeiche2;
+ return;
+ }
+ }
+ }
+ else if (wurzelSpeiche.edge.eEdgeType == EdgeType.TK)
+ {
+ Speiche ssp = GetStartSpeicheForAngle(rangeStartAngle);
+ if (ssp.edge.eEdgeType == EdgeType.EMPTY)
+ {
+ ssp.edge = edge;
+ }
+ return;
+ }
+ else if (wurzelSpeiche.edge.eEdgeType == EdgeType.CONTOUR || wurzelSpeiche.edge.eEdgeType == EdgeType.INNER)
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCase A1a");
+ Edge blockingEdge = wurzelSpeiche.edge;
+ if (blockingEdge.arePointsOnSameSide(this.node, edge.pStartNode) && blockingEdge.arePointsOnSameSide(this.node, edge.pEndNode))
+ {
+ Speiche ends = GetStartSpeicheForAngle(rangeStartAngle);
+ if(ends.nextSpeiche.Equals(wurzelSpeiche) ) {
+ wurzelSpeiche.edge = edge;
+ if (rangeEndAngle > wurzelSpeiche.nextSpeiche.rangeStartAngle)
+ {
+ wurzelSpeiche.nextSpeiche = wurzelSpeiche.nextSpeiche.nextSpeiche;
+ }
+ if(ends.rangeStartAngle < rangeStartAngle) {
+ Speiche newSpeiche = new Speiche();
+ newSpeiche.rangeStartAngle = rangeStartAngle;
+ newSpeiche.edge = edge;
+ newSpeiche.nextSpeiche = ends.nextSpeiche;
+ ends.nextSpeiche = newSpeiche;
+ }
+ /*ends.edge = edge;
+ ends.nextSpeiche = wurzelSpeiche;*/
+ }
+ return;
+ }
+ else
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nBlocking edge is nearer to node, discrading new edge");
+
+ return;
+ }
+
+ }
+
+ Speiche ss = GetStartSpeicheForAngle(rangeEndAngle);
+ ss.edge = edge;
+ Speiche es = ss.GetEndSpeicheForAngle(rangeStartAngle);
+ if (rangeStartAngle > es.rangeStartAngle)
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCase A");
+ Speiche newSpeiche = new Speiche();
+ newSpeiche.rangeStartAngle = rangeStartAngle;
+ newSpeiche.edge = edge;
+ newSpeiche.nextSpeiche = es.nextSpeiche;
+ es.nextSpeiche = newSpeiche;
+ }
+ else
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCase B");
+ es.edge = edge;
+ }
+ return;
+ }
+
+ Speiche startSpeiche = GetStartSpeicheForAngle(rangeStartAngle);
+ if (startSpeiche.edge.eEdgeType == EdgeType.TK)
+ {
+ if(!over360Deg && Math.Abs(rangeEndAngle-rangeStartAngle) > 180.0d) {
+ return;
+ }
+ if(edge.eEdgeType == EdgeType.CONTOUR)
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCase C");
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nTrying to insert contour edge in outside area. Adjusting angles");
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nInserting edge [" + edge.pStartNode.iNodeIdx + ";" + edge.pEndNode.iNodeIdx + "] into Speichenstern " + node.iNodeIdx);
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nStart Range Angle: " + rangeStartAngle + " end range angle: " + rangeEndAngle);
+ Speiche ends = GetStartSpeicheForAngle(rangeEndAngle);
+ if(startSpeiche.Equals(ends)) {
+ return;
+ }
+ if (startSpeiche.nextSpeiche.edge.eEdgeType != EdgeType.TK && rangeEndAngle > startSpeiche.nextSpeiche.rangeStartAngle)
+ {
+ startSpeiche.nextSpeiche.edge = edge;
+ }
+ return;
+ }
+ else
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCase D");
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nTrying to insert edge in outside area. This should never happen!");
+ return;
+ }
+ }
+ Speiche endSpeiche = startSpeiche.GetEndSpeicheForAngle(rangeEndAngle);
+ if (endSpeiche.Equals(startSpeiche))
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nStartspeiche equal to endspeiche. This should never happen!");
+ endSpeiche = endSpeiche.nextSpeiche;
+ }
+ bool newEdgeIsNearerToNode = false;
+ if (startSpeiche.edge.eEdgeType != EdgeType.EMPTY)
+ {
+ newEdgeIsNearerToNode = startSpeiche.edge.arePointsOnSameSide(this.node, edge.pStartNode) && startSpeiche.edge.arePointsOnSameSide(this.node, edge.pEndNode);
+ }
+ if (startSpeiche.edge.eEdgeType == EdgeType.EMPTY || newEdgeIsNearerToNode || Math.Abs(edge.iEdgeIdx - startSpeiche.edge.iEdgeIdx) == 1)
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nInserting edge [" + edge.pStartNode.iNodeIdx + ";" + edge.pEndNode.iNodeIdx + "] into Speichenstern " + node.iNodeIdx);
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nStart Range Angle: " + rangeStartAngle + " end range angle: " + rangeEndAngle);
+
+ if (startSpeiche.rangeStartAngle == rangeStartAngle && endSpeiche.rangeStartAngle == rangeEndAngle)
+ {
+ startSpeiche.edge = edge;
+ startSpeiche.nextSpeiche = endSpeiche;
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCase E");
+ }
+ else if (startSpeiche.rangeStartAngle == rangeStartAngle && endSpeiche.rangeStartAngle == 0.0d)
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCase F");
+ if (startSpeiche.nextSpeiche.edge.eEdgeType == EdgeType.TK)
+ {
+ startSpeiche.edge = edge;
+ }
+ else
+ {
+ if (rangeEndAngle != 0.0d && rangeEndAngle != 360.0d)
+ {
+ Speiche newSpeiche = new Speiche();
+ newSpeiche.edge = startSpeiche.edge;
+ startSpeiche.edge = edge;
+ newSpeiche.rangeStartAngle = rangeEndAngle;
+ startSpeiche.nextSpeiche = newSpeiche;
+ newSpeiche.nextSpeiche = endSpeiche;
+ }
+ else
+ {
+ startSpeiche.edge = edge;
+ startSpeiche.nextSpeiche = endSpeiche;
+ }
+ }
+ }
+ else if (startSpeiche.rangeStartAngle == rangeStartAngle && endSpeiche.rangeStartAngle > rangeEndAngle)
+ {
+ if (rangeEndAngle > startSpeiche.nextSpeiche.rangeStartAngle)
+ {
+ startSpeiche.edge = edge;
+ startSpeiche.nextSpeiche = endSpeiche;
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCase G1");
+ }
+ else
+ {
+ Speiche newSpeiche = new Speiche();
+ newSpeiche.rangeStartAngle = rangeEndAngle;
+ newSpeiche.edge = startSpeiche.edge;
+ startSpeiche.edge = edge;
+ startSpeiche.nextSpeiche = newSpeiche;
+ newSpeiche.nextSpeiche = endSpeiche;
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCase G2");
+ }
+ }
+ else if (startSpeiche.rangeStartAngle < rangeStartAngle && endSpeiche.rangeStartAngle == rangeEndAngle)
+ {
+ Speiche newSpeiche = new Speiche();
+ newSpeiche.rangeStartAngle = rangeStartAngle;
+ newSpeiche.edge = edge;
+ startSpeiche.nextSpeiche = newSpeiche;
+ newSpeiche.nextSpeiche = endSpeiche;
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCase H");
+ }
+ else if (startSpeiche.rangeStartAngle < rangeStartAngle && endSpeiche.rangeStartAngle == 0.0d)
+ {
+
+ if (rangeEndAngle > startSpeiche.nextSpeiche.rangeStartAngle && startSpeiche.nextSpeiche.edge.eEdgeType == EdgeType.TK)
+ {
+ Speiche newSpeiche = new Speiche();
+ newSpeiche.rangeStartAngle = rangeStartAngle;
+ newSpeiche.edge = edge;
+ newSpeiche.nextSpeiche = startSpeiche.nextSpeiche;
+ startSpeiche.nextSpeiche = newSpeiche;
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCase I1");
+ }
+ else
+ {
+ if (rangeEndAngle > startSpeiche.nextSpeiche.rangeStartAngle)
+ {
+ Speiche newSpeiche1 = new Speiche();
+ Speiche newSpeiche2 = new Speiche();
+ newSpeiche1.rangeStartAngle = rangeStartAngle;
+ newSpeiche2.rangeStartAngle = rangeEndAngle;
+ newSpeiche2.nextSpeiche = endSpeiche;
+ newSpeiche2.edge = startSpeiche.edge;
+ newSpeiche1.edge = edge;
+ newSpeiche1.nextSpeiche = newSpeiche2;
+ startSpeiche.nextSpeiche = newSpeiche1;
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCase I2");
+ }
+ else
+ {
+ Speiche newSpeiche = new Speiche();
+ newSpeiche.rangeStartAngle = rangeStartAngle;
+ newSpeiche.edge = edge;
+ startSpeiche.nextSpeiche = newSpeiche;
+ newSpeiche.nextSpeiche = endSpeiche;
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCase I3");
+ }
+ }
+ }
+ else if (startSpeiche.rangeStartAngle < rangeStartAngle && endSpeiche.rangeStartAngle > rangeEndAngle)
+ {
+ if (rangeEndAngle > startSpeiche.nextSpeiche.rangeStartAngle)
+ {
+ Speiche newSpeiche1 = new Speiche();
+ newSpeiche1.rangeStartAngle = rangeStartAngle;
+ newSpeiche1.edge = edge;
+ Speiche newSpeiche2 = new Speiche();
+ newSpeiche2.rangeStartAngle = rangeEndAngle;
+ newSpeiche2.edge = startSpeiche.edge;
+ newSpeiche1.nextSpeiche = newSpeiche2;
+ newSpeiche2.nextSpeiche = endSpeiche;
+ startSpeiche.nextSpeiche = newSpeiche1;
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCase J1");
+ }
+ else
+ {
+ Speiche newSpeiche1 = new Speiche();
+ newSpeiche1.rangeStartAngle = rangeStartAngle;
+ newSpeiche1.edge = edge;
+ Speiche newSpeiche2 = new Speiche();
+ newSpeiche2.rangeStartAngle = rangeEndAngle;
+ newSpeiche2.edge = startSpeiche.edge;
+ newSpeiche1.nextSpeiche = newSpeiche2;
+ newSpeiche2.nextSpeiche = endSpeiche;
+ startSpeiche.nextSpeiche = newSpeiche1;
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nCase J2");
+ }
+ }
+ //}
+ }
+ }
+
+ public void InsertInnerEdge(Edge edge, double rangeStartAngle, double rangeEndAngle)
+ {
+ //for debugging only
+ if (this.node.iNodeIdx == 5 && edge.pStartNode.iNodeIdx == 4 && edge.pEndNode.iNodeIdx == 6)
+ {
+ int xy = -1;
+ }
+ bool over360Deg = false;
+ if (rangeStartAngle > rangeEndAngle)
+ {
+ if (Math.Abs(rangeStartAngle - rangeEndAngle) > 180.0d)
+ {
+ over360Deg = true;
+ }
+ else
+ {
+ double tmp;
+ tmp = rangeStartAngle;
+ rangeStartAngle = rangeEndAngle;
+ rangeEndAngle = tmp;
+ }
+ }
+ Speiche ssp = new Speiche();
+ Speiche esp = new Speiche();
+
+ if (over360Deg)
+ {
+ ssp = wurzelSpeiche;
+ while (ssp.rangeStartAngle < rangeEndAngle)
+ {
+ ssp = ssp.nextSpeiche;
+ }
+ esp = GetEndSpeicheForAngle(rangeStartAngle);
+ }
+ else
+ {
+ ssp = GetStartSpeicheForAngle(rangeStartAngle);
+ esp = GetEndSpeicheForAngle(rangeEndAngle);
+ }
+ if (over360Deg)
+ {
+ }
+ else
+ {
+ if (ssp.edge.eEdgeType == EdgeType.TK)
+ {
+ return;
+ }
+ }
+ if ((ssp.edge.eEdgeType == EdgeType.INNER || ssp.edge.eEdgeType == EdgeType.CONTOUR)
+ && (esp.edge.eEdgeType == EdgeType.INNER || esp.edge.eEdgeType == EdgeType.CONTOUR))
+ {
+ bool arePointsOnSameSide = false;
+
+ if(ssp.edge.pStartNode.iNodeIdx != edge.pStartNode.iNodeIdx && ssp.edge.pEndNode.iNodeIdx != edge.pStartNode.iNodeIdx)
+ {
+ arePointsOnSameSide = ssp.edge.arePointsOnSameSide(this.node, edge.pStartNode);
+ }
+ else if(ssp.edge.pStartNode.iNodeIdx != edge.pEndNode.iNodeIdx && ssp.edge.pEndNode.iNodeIdx != edge.pEndNode.iNodeIdx)
+ {
+ arePointsOnSameSide = ssp.edge.arePointsOnSameSide(this.node, edge.pEndNode);
+ }
+ else if(ssp.edge.pStartNode.iNodeIdx != edge.pEndNode.iNodeIdx && ssp.edge.pEndNode.iNodeIdx != edge.pEndNode.iNodeIdx)
+ {
+ arePointsOnSameSide = esp.edge.arePointsOnSameSide(this.node, edge.pStartNode);
+ }
+ else if(esp.edge.pStartNode.iNodeIdx != edge.pEndNode.iNodeIdx && esp.edge.pEndNode.iNodeIdx != edge.pEndNode.iNodeIdx)
+ {
+ arePointsOnSameSide = esp.edge.arePointsOnSameSide(this.node, edge.pEndNode);
+ }
+ if (arePointsOnSameSide)
+ {
+ if (over360Deg)
+ {
+ wurzelSpeiche.edge = edge;
+ wurzelSpeiche.nextSpeiche = ssp;
+ esp.edge = edge;
+ esp.nextSpeiche = wurzelSpeiche;
+ }
+ else
+ {
+ ssp.edge = edge;
+ ssp.nextSpeiche = esp;
+ }
+ }
+ }
+ else
+ {
+ if (over360Deg)
+ {
+ wurzelSpeiche.edge = edge;
+ wurzelSpeiche.nextSpeiche = ssp;
+ esp.edge = edge;
+ esp.nextSpeiche = wurzelSpeiche;
+ }
+ else
+ {
+ ssp.edge = edge;
+ if(ssp.nextSpeiche.edge.eEdgeType == EdgeType.TK)
+ {
+ // do nothing more...
+ }
+ else
+ {
+ ssp.nextSpeiche = esp;
+ }
+ }
+ }
+ }
+
+ public void Dump()
+ {
+ Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\n Speichenstern for Node "+node.iNodeIdx);
+ Speiche actSpeiche = wurzelSpeiche;
+ do {
+ actSpeiche.Dump();
+ actSpeiche = actSpeiche.nextSpeiche;
+ } while(actSpeiche != wurzelSpeiche);
+ }
+ }
+}
diff --git a/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/SpeichenSternList.cs b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/SpeichenSternList.cs new file mode 100644 index 0000000..7f9a1a0 --- /dev/null +++ b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/SpeichenSternList.cs @@ -0,0 +1,127 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+using Autodesk.AutoCAD.Runtime;
+using Autodesk.AutoCAD.DatabaseServices;
+using Autodesk.AutoCAD.ApplicationServices;
+using Autodesk.AutoCAD.EditorInput;
+using Autodesk.AutoCAD.Geometry;
+using System.Collections;
+
+namespace CsMgdAcad1
+{
+ class SpeichenSternList
+ {
+ public ArrayList alSpeichenSterne;
+
+ public SpeichenSternList(ArrayList nodes)
+ {
+ alSpeichenSterne = new ArrayList();
+ for (int i = 0; i < nodes.Count; i++ )
+ {
+ SpeichenStern s = new SpeichenStern((Node)nodes[i]);
+ alSpeichenSterne.Add(s);
+ }
+ }
+
+ public SpeichenStern GetSpeichenStern(int idx) {
+ return (SpeichenStern)alSpeichenSterne[idx];
+ }
+
+ public void SetSpeichenSternAt(int idx, SpeichenStern speichenStern)
+ {
+ if (idx < alSpeichenSterne.Count)
+ {
+ alSpeichenSterne[idx] = speichenStern;
+ }
+ }
+
+ public void Dump()
+ {
+ Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\n-------Start Speichensternliste------------");
+ for (int i = 0; i < alSpeichenSterne.Count; i++)
+ {
+ SpeichenStern s = (SpeichenStern)alSpeichenSterne[i];
+ s.Dump();
+ }
+ Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\n-------Ende Speichensternliste------------");
+ }
+
+ public void SetOutsideRanges(ArrayList contourEdges)
+ {
+ for (int c = 0; c < alSpeichenSterne.Count;c++ )
+ {
+ SpeichenStern s = (SpeichenStern)alSpeichenSterne[c];
+ double arrivingContourAngleAtNode = 0.0d;
+ double leavingContourAngleAtNode = 0.0d;
+ for (int ec = 0; ec < contourEdges.Count;ec++ )
+ {
+ Edge actEdge = (Edge)contourEdges[ec];
+ if(actEdge.pStartNode.iNodeIdx == s.node.iNodeIdx) {
+ leavingContourAngleAtNode = actEdge.GetAngleToXAxisDeg();
+ }
+ else if (actEdge.pEndNode.iNodeIdx == s.node.iNodeIdx)
+ {
+ arrivingContourAngleAtNode = actEdge.GetInvAngleToXAxisDeg();
+ }
+ }
+
+ if (leavingContourAngleAtNode > arrivingContourAngleAtNode)
+ {
+ Speiche s1 = new Speiche();
+ s1.rangeStartAngle = arrivingContourAngleAtNode;
+ s1.edge = new Edge(EdgeType.TK);
+ Speiche s2 = new Speiche();
+ s2.rangeStartAngle = leavingContourAngleAtNode;
+ s2.edge = new Edge(EdgeType.EMPTY);
+ s.wurzelSpeiche.nextSpeiche = s1;
+ s1.nextSpeiche = s2;
+ s2.nextSpeiche = s.wurzelSpeiche;
+ }
+ else
+ {
+ s.wurzelSpeiche.edge = new Edge(EdgeType.TK);
+ Speiche s1 = new Speiche();
+ s1.rangeStartAngle = leavingContourAngleAtNode;
+ s1.edge = new Edge(EdgeType.EMPTY);
+ Speiche s2 = new Speiche();
+ s2.edge = new Edge(EdgeType.TK);
+ s2.rangeStartAngle = arrivingContourAngleAtNode;
+ s.wurzelSpeiche.nextSpeiche = s1;
+ s1.nextSpeiche = s2;
+ s2.nextSpeiche = s.wurzelSpeiche;
+ }
+ }
+ }
+
+ public void SetContourEdges(ArrayList contourEdges)
+ {
+ for (int edgeCounter = 0; edgeCounter < contourEdges.Count;edgeCounter++ )
+ {
+ Edge actContourEdge = (Edge)contourEdges[edgeCounter];
+ SpeichenStern testSpeichenstern = GetSpeichenStern(actContourEdge.pStartNode.iNodeIdx);
+ double edgeAngleAtNode = actContourEdge.GetAngleToXAxisDeg();
+ Speiche blockingSpeiche = testSpeichenstern.GetBlockingSpeicheForAngle(edgeAngleAtNode);
+ if (blockingSpeiche.edge.eEdgeType == EdgeType.TK)
+ {
+ Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nEdge ["+actContourEdge.pStartNode.iNodeIdx+";"+actContourEdge.pEndNode.iNodeIdx+"] "+
+ "with angle "+edgeAngleAtNode+" is in outside area" );
+ continue;
+ }
+ else
+ {
+ for (int c = 0; c < alSpeichenSterne.Count; c++)
+ {
+ if (c != actContourEdge.pStartNode.iNodeIdx && c != actContourEdge.pEndNode.iNodeIdx)
+ {
+ SpeichenStern insertSpeichenstern = (SpeichenStern)alSpeichenSterne[c];
+ double rangeStartAngle = insertSpeichenstern.node.GetAngleToEdgeStartPointDeg(actContourEdge);
+ double rangeEndAngle = insertSpeichenstern.node.GetAngleToEdgeEndPointDeg(actContourEdge);
+ insertSpeichenstern.SetEdgeForAngleRange(actContourEdge, rangeStartAngle, rangeEndAngle);
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/TestCSApp.cs b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/TestCSApp.cs new file mode 100644 index 0000000..d4b621d --- /dev/null +++ b/Master/CGuCAD/projects/CsMgdAcad1/CsMgdAcad1/TestCSApp.cs @@ -0,0 +1,442 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+using Autodesk.AutoCAD.Runtime;
+using Autodesk.AutoCAD.DatabaseServices;
+using Autodesk.AutoCAD.ApplicationServices;
+using Autodesk.AutoCAD.EditorInput;
+using Autodesk.AutoCAD.Geometry;
+using System.Collections;
+
+namespace CsMgdAcad1
+{
+ class TestCSApp
+ {
+ public const string EDGE_LAYER = "Edge Layer";
+ public const string TRIANGLE_LAYER = "Triangle Layer";
+
+ public class edgeComparer : IComparer
+ {
+ int IComparer.Compare(Object x, Object y)
+ {
+ Edge e1 = (Edge) x;
+ Edge e2 = (Edge) y;
+ double difference = e1.GetLength() - e2.GetLength();
+ if (difference < 0.0) return -1;
+ else if (difference == 0) return 0;
+ else return 1;
+ }
+
+ }
+ public class triangleEdgeComparer : IComparer
+ {
+ int IComparer.Compare(Object x, Object y)
+ {
+ Edge e1 = (Edge)x;
+ Edge e2 = (Edge)y;
+ if(e1.eEdgeType == EdgeType.CONTOUR && e2.eEdgeType != EdgeType.CONTOUR) {
+ return -1;
+ }
+ else if (e2.eEdgeType == EdgeType.CONTOUR && e1.eEdgeType != EdgeType.CONTOUR)
+ {
+ return 1;
+ }
+ else {
+ if(e1.pStartNode.iNodeIdx < e2.pStartNode.iNodeIdx)
+ {
+ return -1;
+ }
+ else if (e1.pStartNode.iNodeIdx > e2.pStartNode.iNodeIdx)
+ {
+ return 1;
+ }
+ else
+ {
+ if (e1.pEndNode.iNodeIdx < e2.pEndNode.iNodeIdx)
+ {
+ return -1;
+ }
+ else if (e1.pEndNode.iNodeIdx < e2.pEndNode.iNodeIdx)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+ }
+ }
+
+ }
+
+ public void Main()
+ {
+ Polyline pPolyline = null;
+ bool res = GetPolyLine(ref pPolyline);
+ if (!res)
+ {
+ Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nError selecting Polyline! Exiting!");
+ return;
+ }
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPolyline has " + pPolyline.NumberOfVertices + " vertices");
+ //if(pPolyline.GetPoint2dAt(0) != pPolyline.GetPoint2dAt(pPolyline.NumberOfVertices-1) ) {
+ // Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPolyline is not closed!");
+ //}
+ ArrayList alNodes = GetNodesFromPolyline(pPolyline);
+
+ SpeichenSternList speichenSterne = new SpeichenSternList(alNodes);
+
+ ArrayList alContourEdges = GetContourFromNodes(alNodes);
+ speichenSterne.SetOutsideRanges(alContourEdges);
+ Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nSpeichenSterne after initializing");
+ speichenSterne.Dump();
+ speichenSterne.SetContourEdges(alContourEdges);
+ Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nSpeichenSterne after inserting contour edges");
+ speichenSterne.Dump();
+ ArrayList alEdgePool = GetEdgePool(alNodes);
+ ArrayList alValidInnerEdges = new ArrayList();
+ int iNeededInnerEdges = alNodes.Count - 3;
+ int iNeededTriangles = alNodes.Count - 2;
+ int iNumValidInnerEdges = 0;
+ for (int i = 0; i < alEdgePool.Count; i++)
+ {
+ Edge edgeToTest = (Edge) alEdgePool[i];
+ SpeichenStern s = speichenSterne.GetSpeichenStern(edgeToTest.pStartNode.iNodeIdx);
+ Edge blockingEdge = s.GetBlockingSpeicheForAngle(edgeToTest.GetAngleToXAxisDeg()).edge;
+ if(blockingEdge.eEdgeType == EdgeType.TK) {
+ continue;
+ }
+ if(blockingEdge.arePointsOnSameSide(s.node,edgeToTest.pStartNode)) {
+ alValidInnerEdges.Add(edgeToTest);
+ for (int j = 0; j < speichenSterne.alSpeichenSterne.Count;j++ )
+ {
+ if(j != edgeToTest.pStartNode.iNodeIdx && j != edgeToTest.pEndNode.iNodeIdx) {
+ SpeichenStern updateSp = speichenSterne.GetSpeichenStern(j);
+ Node n = updateSp.node;
+ double rs = n.GetAngleToEdgeStartPointDeg(edgeToTest);
+ double re = n.GetAngleToEdgeEndPointDeg(edgeToTest);
+ updateSp.InsertInnerEdge(edgeToTest, rs, re);
+ }
+ }
+ iNumValidInnerEdges++;
+ }
+ if (iNumValidInnerEdges >= iNeededInnerEdges)
+ {
+ break;
+ }
+ }
+ Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nSpeichenSterne after inserting inner edges");
+ speichenSterne.Dump();
+
+ CreateLayer(EDGE_LAYER);
+ CreateLayer(TRIANGLE_LAYER);
+
+ //DrawLines(alContourEdges);
+ DrawLines(alValidInnerEdges);
+ //DrawLines(alEdgePool);
+ alContourEdges.AddRange(alValidInnerEdges);
+ DrawTriangles(alContourEdges, iNeededTriangles);
+ }
+
+ private void DrawTriangles(ArrayList edges,int iNeedTriangles)
+ {
+ edges.Sort(new triangleEdgeComparer());
+ for (int i = 0; i < edges.Count; i++)
+ {
+ Edge e = (Edge)edges[i];
+ Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nEdge: [" + e.pStartNode.iNodeIdx + ";" + e.pEndNode.iNodeIdx + "] Type: " + e.eEdgeType);
+ }
+ Point3d p1 = new Point3d(0.0, 0.0, 0.0);
+ Point3d p2 = new Point3d(0.0, 0.0, 0.0);
+ Point3d p3 = new Point3d(0.0, 0.0, 0.0);
+ bool foundAFace = false;
+ int triangleCounter = 0;
+ for (int i = 0; i < edges.Count; i++)
+ {
+ Edge e1 = (Edge)edges[i];
+ for (int j = i+1; j < edges.Count; j++)
+ {
+ Edge e2 = (Edge)edges[j];
+ for (int k = j+1; k < edges.Count; k++)
+ {
+ Edge e3 = (Edge)edges[k];
+ int sp1Idx = e1.pStartNode.iNodeIdx;
+ int sp2Idx = e2.pStartNode.iNodeIdx;
+ int sp3Idx = e3.pStartNode.iNodeIdx;
+ int ep1Idx = e1.pEndNode.iNodeIdx;
+ int ep2Idx = e2.pEndNode.iNodeIdx;
+ int ep3Idx = e3.pEndNode.iNodeIdx;
+
+ if(e1.iEdgeIdx == e2.iEdgeIdx || e1.iEdgeIdx == e3.iEdgeIdx || e2.iEdgeIdx == e3.iEdgeIdx) {
+ continue;
+ }
+ if (sp1Idx == ep3Idx && ep1Idx == sp2Idx && ep2Idx == sp3Idx)
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nAdding Face: [" + s1Idx + ";" + e1Idx + "],["+s2Idx+";"+e2Idx+"],["+s3Idx+";"+e3Idx+"]" );
+ p1 = new Point3d(e1.pStartNode.point.X, e1.pStartNode.point.Y, 0);
+ p2 = new Point3d(e2.pStartNode.point.X, e2.pStartNode.point.Y, 0);
+ p3 = new Point3d(e3.pStartNode.point.X, e3.pStartNode.point.Y, 0);
+
+ foundAFace = true;
+ }
+ else if (sp1Idx == sp2Idx && ep2Idx == ep3Idx && sp3Idx == ep1Idx)
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nAdding Face: [" + s1Idx + ";" + e1Idx + "],[" + s2Idx + ";" + e2Idx + "],[" + s3Idx + ";" + e3Idx + "]");
+ p1 = new Point3d(e1.pStartNode.point.X, e1.pStartNode.point.Y, 0);
+ p2 = new Point3d(e3.pStartNode.point.X, e3.pStartNode.point.Y, 0);
+ p3 = new Point3d(e3.pEndNode.point.X, e3.pEndNode.point.Y, 0);
+ foundAFace = true;
+ } else if (sp1Idx == ep2Idx && ep1Idx == sp3Idx && sp2Idx == sp3Idx) {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nAdding Face: [" + s1Idx + ";" + e1Idx + "],[" + s2Idx + ";" + e2Idx + "],[" + s3Idx + ";" + e3Idx + "]");
+ p1 = new Point3d(e1.pStartNode.point.X, e1.pStartNode.point.Y, 0);
+ p2 = new Point3d(e2.pStartNode.point.X, e2.pStartNode.point.Y, 0);
+ p3 = new Point3d(e3.pStartNode.point.X, e3.pStartNode.point.Y, 0);
+ foundAFace = true;
+ }
+ else if (sp1Idx == sp2Idx && ep1Idx == ep3Idx && sp3Idx == ep2Idx)
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nAdding Face: [" + s1Idx + ";" + e1Idx + "],[" + s2Idx + ";" + e2Idx + "],[" + s3Idx + ";" + e3Idx + "]");
+ p1 = new Point3d(e1.pStartNode.point.X, e1.pStartNode.point.Y, 0);
+ p2 = new Point3d(e1.pEndNode.point.X, e1.pEndNode.point.Y, 0);
+ p3 = new Point3d(e3.pStartNode.point.X, e3.pStartNode.point.Y, 0);
+ foundAFace = true;
+ }
+ else if (sp1Idx == sp3Idx && ep1Idx == sp2Idx && ep2Idx == ep3Idx)
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nAdding Face: [" + s1Idx + ";" + e1Idx + "],[" + s2Idx + ";" + e2Idx + "],[" + s3Idx + ";" + e3Idx + "]");
+ p1 = new Point3d(e1.pStartNode.point.X, e1.pStartNode.point.Y, 0);
+ p2 = new Point3d(e1.pEndNode.point.X, e1.pEndNode.point.Y, 0);
+ p3 = new Point3d(e3.pEndNode.point.X, e3.pEndNode.point.Y, 0);
+ foundAFace = true;
+ }
+ else if (sp1Idx == ep2Idx && ep1Idx == sp3Idx && sp2Idx == ep3Idx)
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nAdding Face: [" + s1Idx + ";" + e1Idx + "],[" + s2Idx + ";" + e2Idx + "],[" + s3Idx + ";" + e3Idx + "]");
+ p1 = new Point3d(e1.pStartNode.point.X, e1.pStartNode.point.Y, 0);
+ p2 = new Point3d(e1.pEndNode.point.X, e1.pEndNode.point.Y, 0);
+ p3 = new Point3d(e2.pStartNode.point.X, e2.pStartNode.point.Y, 0);
+ foundAFace = true;
+ }
+ else if (sp1Idx == ep2Idx && ep1Idx == ep3Idx && sp2Idx == sp3Idx)
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nAdding Face: [" + s1Idx + ";" + e1Idx + "],[" + s2Idx + ";" + e2Idx + "],[" + s3Idx + ";" + e3Idx + "]");
+ p1 = new Point3d(e1.pStartNode.point.X, e1.pStartNode.point.Y, 0);
+ p2 = new Point3d(e1.pEndNode.point.X, e1.pEndNode.point.Y, 0);
+ p3 = new Point3d(e2.pStartNode.point.X, e2.pStartNode.point.Y, 0);
+ foundAFace = true;
+ }
+ else
+ {
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nSkipping Face: [" + sp1Idx + ";" + ep1Idx + "],[" + sp2Idx + ";" + ep2Idx + "],[" + sp3Idx + ";" + ep3Idx + "]");
+ }
+ if(foundAFace) {
+ DrawFace(p1, p2, p3);
+ triangleCounter++;
+ foundAFace = false;
+ }
+ if (triangleCounter >= iNeedTriangles)
+ {
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ private ArrayList GetEdgePool(ArrayList alNodes)
+ {
+ ArrayList res = new ArrayList();
+ int cnt = alNodes.Count;
+ for (int i = 0; i < alNodes.Count-1; i++)
+ {
+ for(int j=i+1;j<alNodes.Count;j++)
+ {
+ if (((i == 0) && (j == alNodes.Count - 1)) || (j - i == 1))
+ {
+ continue;
+ }
+ else
+ {
+ Edge e = new Edge(EdgeType.INNER);
+ e.pStartNode = (Node) alNodes[i];
+ e.pEndNode = (Node) alNodes[j];
+ e.iEdgeIdx = cnt;
+ cnt++;
+ res.Add(e);
+ }
+ }
+ }
+ res.Sort(new edgeComparer());
+ //for (int i = 0; i < res.Count;i++ )
+ //{
+ // int s = ((Edge)res[i]).pStartNode.iNodeIdx;
+ // int e = ((Edge)res[i]).pEndNode.iNodeIdx;
+ // Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nInner edge: [" + s + ";" + e + "] length: " + ((Edge)res[i]).GetLength());
+ //}
+ return res;
+ }
+
+ private void DrawFace(Point3d p1, Point3d p2, Point3d p3)
+ {
+ Face f = new Face(p1,p2,p3,p1, false, false, false,false);
+ f.Layer = TRIANGLE_LAYER;
+ AddObject((Entity)f);
+ }
+
+ private void DrawLines(ArrayList alEdges)
+ {
+ for (int i = 0; i < alEdges.Count; i++)
+ {
+ Edge edge = (Edge)alEdges[i];
+ Point3d s = new Point3d(edge.pStartNode.point.X, edge.pStartNode.point.Y, 0);
+ Point3d e = new Point3d(edge.pEndNode.point.X, edge.pEndNode.point.Y, 0);
+ Line line = new Line(s, e);
+ line.Layer = EDGE_LAYER;
+ AddObject((Entity)line);
+ }
+ }
+
+ private ArrayList GetNodesFromPolyline(Polyline pPolyline)
+ {
+ ArrayList res = new ArrayList();
+ int iNumNodes = iNumNodes = pPolyline.NumberOfVertices;
+ if (pPolyline.GetPoint2dAt(0) == pPolyline.GetPoint2dAt(pPolyline.NumberOfVertices - 1))
+ {
+ // first and last node are identical, drop last node
+ iNumNodes--;
+ }
+ for (int i = 0; i < iNumNodes; i++)
+ {
+ Node strNode = new Node();
+ strNode.iNodeIdx = i;
+ strNode.point = pPolyline.GetPoint2dAt(i);
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nAdding node "+i);
+ res.Add(strNode);
+ }
+ return res;
+ }
+
+ private ArrayList GetContourFromNodes(ArrayList alNodes)
+ {
+ ArrayList res = new ArrayList();
+ Edge edge;
+ Node startNode;
+ Node endNode;
+ int edgeCounter = 0;
+ for (int i = 1; i < alNodes.Count; i++)
+ {
+ startNode = (Node)alNodes[i-1];
+ endNode = (Node)alNodes[i];
+ edge = new Edge(EdgeType.CONTOUR);
+ edge.iEdgeIdx = edgeCounter++;
+ edge.pStartNode = startNode;
+ edge.pEndNode = endNode;
+ res.Add(edge);
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nAdding contour [" +startNode.iNodeIdx+","+endNode.iNodeIdx+"]");
+ }
+ // edge from last node to first node
+ startNode = (Node)alNodes[alNodes.Count-1];
+ endNode = (Node)alNodes[0];
+ edge = new Edge(EdgeType.CONTOUR);
+ edge.iEdgeIdx = edgeCounter++;
+ edge.pStartNode = startNode;
+ edge.pEndNode = endNode;
+ res.Add(edge);
+ //Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nAdding contour [" + startNode.iNodeIdx + "," + endNode.iNodeIdx + "]");
+ return res;
+ }
+
+ private bool GetPolyLine(ref Polyline pPolyline)
+ {
+ Editor editor = Application.DocumentManager.MdiActiveDocument.Editor;
+ PromptEntityOptions options = new PromptEntityOptions("\nPolyline auswählen");
+ PromptEntityResult selelctedEntity = editor.GetEntity(options);
+
+ Database db = Application.DocumentManager.MdiActiveDocument.Database;
+ Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
+ Transaction transaction = tm.StartTransaction();
+ BlockTable blockTable = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
+ BlockTableRecord blockTableRecord = (BlockTableRecord)tm.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForRead, false);
+
+ try
+ {
+ pPolyline = (Polyline)tm.GetObject(selelctedEntity.ObjectId, OpenMode.ForRead, false);
+ transaction.Commit();
+ return true;
+ }
+ catch
+ {
+ editor.WriteMessage("\nFehler beim Lesen der Polyline");
+ transaction.Dispose();
+ return false;
+ }
+ }
+
+ public bool AddObject(Entity entity)
+ {
+ Database db = Application.DocumentManager.MdiActiveDocument.Database;
+ Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
+ Transaction transaction = tm.StartTransaction();
+ BlockTable blockTable = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
+ BlockTableRecord blockTableRecord = (BlockTableRecord)tm.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
+ blockTableRecord.AppendEntity(entity);
+ tm.AddNewlyCreatedDBObject(entity, true);
+ transaction.Commit();
+ return true;
+ }
+
+ public void CreateLayer(string sLayer)
+ {
+ Database db = Application.DocumentManager.MdiActiveDocument.Database;
+ Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
+ Transaction transaction = tm.StartTransaction();
+ Editor editor = Application.DocumentManager.MdiActiveDocument.Editor;
+
+ try
+ {// get the LayerTable
+ LayerTable layerTable = (LayerTable)tm.GetObject(db.LayerTableId, OpenMode.ForRead, false);
+ // check if layer already exists
+ if (!layerTable.Has(sLayer))
+ {
+ LayerTableRecord layerTableRecord = new LayerTableRecord();
+ layerTableRecord.Name = sLayer;
+ // layer set to not frozen
+ layerTableRecord.IsFrozen = false;
+
+ // layer set to ON
+ layerTableRecord.IsOff = false;
+
+ // set layer to un-locked
+ layerTableRecord.IsLocked = false;
+
+ // set layer color
+ switch(sLayer) {
+ case EDGE_LAYER:
+ // red
+ layerTableRecord.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(255,0,0);
+ break;
+ case TRIANGLE_LAYER:
+ // blue
+ layerTableRecord.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(0, 0, 255);
+ break;
+ }
+
+ // Now, add the new layer to its container
+ layerTable.UpgradeOpen();
+ layerTable.Add(layerTableRecord);
+ tm.AddNewlyCreatedDBObject(layerTableRecord, true);
+ }
+ else
+ {
+ editor.WriteMessage("\nLayer '" + sLayer + "' gibt es schon");
+ }
+ transaction.Commit();
+ }
+ catch (Autodesk.AutoCAD.Runtime.Exception)
+ {
+ transaction.Dispose();
+ }
+ }
+ }
+}
|
