├── .gitignore ├── CatiaNET.sln ├── CatiaNET ├── Catia.cs ├── CatiaNET.csproj ├── FactoryExtensions.cs ├── Line.cs ├── MazeTree.cs ├── Properties │ └── AssemblyInfo.cs ├── Tuple.cs └── Utils.cs ├── LICENSE ├── README.md ├── TSBLogo ├── App.config ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── TSBLogo.csproj └── WinNC └── ZAVRSNI.MPF /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studo 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | *_i.c 42 | *_p.c 43 | *_i.h 44 | *.ilk 45 | *.meta 46 | *.obj 47 | *.pch 48 | *.pdb 49 | *.pgc 50 | *.pgd 51 | *.rsp 52 | *.sbr 53 | *.tlb 54 | *.tli 55 | *.tlh 56 | *.tmp 57 | *.tmp_proj 58 | *.log 59 | *.vspscc 60 | *.vssscc 61 | .builds 62 | *.pidb 63 | *.svclog 64 | *.scc 65 | 66 | # Chutzpah Test files 67 | _Chutzpah* 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | *.cachefile 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | *.vspx 81 | 82 | # TFS 2012 Local Workspace 83 | $tf/ 84 | 85 | # Guidance Automation Toolkit 86 | *.gpState 87 | 88 | # ReSharper is a .NET coding add-in 89 | _ReSharper*/ 90 | *.[Rr]e[Ss]harper 91 | *.DotSettings.user 92 | 93 | # JustCode is a .NET coding addin-in 94 | .JustCode 95 | 96 | # TeamCity is a build add-in 97 | _TeamCity* 98 | 99 | # DotCover is a Code Coverage Tool 100 | *.dotCover 101 | 102 | # NCrunch 103 | _NCrunch_* 104 | .*crunch*.local.xml 105 | 106 | # MightyMoose 107 | *.mm.* 108 | AutoTest.Net/ 109 | 110 | # Web workbench (sass) 111 | .sass-cache/ 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.[Pp]ublish.xml 131 | *.azurePubxml 132 | # TODO: Comment the next line if you want to checkin your web deploy settings 133 | # but database connection strings (with potential passwords) will be unencrypted 134 | *.pubxml 135 | *.publishproj 136 | 137 | # NuGet Packages 138 | *.nupkg 139 | # The packages folder can be ignored because of Package Restore 140 | **/packages/* 141 | # except build/, which is used as an MSBuild target. 142 | !**/packages/build/ 143 | # Uncomment if necessary however generally it will be regenerated when needed 144 | #!**/packages/repositories.config 145 | 146 | # Windows Azure Build Output 147 | csx/ 148 | *.build.csdef 149 | 150 | # Windows Store app package directory 151 | AppPackages/ 152 | 153 | # Others 154 | *.[Cc]ache 155 | ClientBin/ 156 | [Ss]tyle[Cc]op.* 157 | ~$* 158 | *~ 159 | *.dbmdl 160 | *.dbproj.schemaview 161 | *.pfx 162 | *.publishsettings 163 | node_modules/ 164 | bower_components/ 165 | 166 | # RIA/Silverlight projects 167 | Generated_Code/ 168 | 169 | # Backup & report files from converting an old project file 170 | # to a newer Visual Studio version. Backup files are not needed, 171 | # because we have git ;-) 172 | _UpgradeReport_Files/ 173 | Backup*/ 174 | UpgradeLog*.XML 175 | UpgradeLog*.htm 176 | 177 | # SQL Server files 178 | *.mdf 179 | *.ldf 180 | 181 | # Business Intelligence projects 182 | *.rdl.data 183 | *.bim.layout 184 | *.bim_*.settings 185 | 186 | # Microsoft Fakes 187 | FakesAssemblies/ 188 | 189 | # Node.js Tools for Visual Studio 190 | .ntvs_analysis.dat 191 | 192 | # Visual Studio 6 build log 193 | *.plg 194 | 195 | # Visual Studio 6 workspace options file 196 | *.opt 197 | -------------------------------------------------------------------------------- /CatiaNET.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CatiaNET", "CatiaNET\CatiaNET.csproj", "{E6B8811F-9460-4FB9-903E-22AF91134FDA}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TSBLogo", "TSBLogo\TSBLogo.csproj", "{8C719216-32C8-4036-ADF6-DDBAD4703245}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {E6B8811F-9460-4FB9-903E-22AF91134FDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {E6B8811F-9460-4FB9-903E-22AF91134FDA}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {E6B8811F-9460-4FB9-903E-22AF91134FDA}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {E6B8811F-9460-4FB9-903E-22AF91134FDA}.Release|Any CPU.Build.0 = Release|Any CPU 18 | {8C719216-32C8-4036-ADF6-DDBAD4703245}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {8C719216-32C8-4036-ADF6-DDBAD4703245}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {8C719216-32C8-4036-ADF6-DDBAD4703245}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {8C719216-32C8-4036-ADF6-DDBAD4703245}.Release|Any CPU.Build.0 = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /CatiaNET/Catia.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Runtime.InteropServices; 6 | using System.Windows; 7 | 8 | using INFITF; 9 | using PARTITF; 10 | using MECMOD; 11 | 12 | namespace CatiaNET { 13 | public class Catia { 14 | public static Application CatiaInstance; 15 | 16 | static Catia() { 17 | try { 18 | CatiaInstance = Marshal.GetActiveObject("Catia.Application") as Application; 19 | } catch (Exception) { 20 | } 21 | if (CatiaInstance == null) 22 | Console.WriteLine("Could not find Catia interface"); 23 | } 24 | 25 | public static PartDocument GetCurrentPartDocument() { 26 | return (PartDocument)CatiaInstance.ActiveDocument; 27 | } 28 | 29 | public static Sketch GetCurrentSketch() { 30 | return GetCurrentPartDocument().Part.InWorkObject as Sketch; 31 | } 32 | 33 | public static void EditSketch(Sketch S, Action A) { 34 | if (S == null) 35 | throw new ArgumentException("Sketch is null", "S"); 36 | Factory2D F = S.OpenEdition(); 37 | if (F == null) 38 | throw new Exception("Could not open edition"); 39 | try { 40 | A(F); 41 | } finally { 42 | S.CloseEdition(); 43 | 44 | } 45 | } 46 | 47 | static void Logo(Factory2D F, float X, float Y, float Height, float Fatness) { 48 | const double AngleOffset = 0.09; 49 | 50 | Ellipse2D LeftUpper = F.CreateEllipse(X, Y - Fatness / 2 + Height, 51 | 0, 0, Height / 2, Height, -3 * Math.PI / 2, -Math.PI / 2); 52 | 53 | Ellipse2D RightUpperUpper = F.CreateEllipse(X, Y - Fatness / 2 + Height, 54 | 0, 0, Height / 2 - Fatness, Height - Fatness, Math.PI / 2, Math.PI - AngleOffset); 55 | 56 | Ellipse2D RightUpperLower = F.CreateEllipse(X, Y - Fatness / 2 + Height, 57 | 0, 0, Height / 2 - Fatness, Height - Fatness, Math.PI + AngleOffset, 3 * Math.PI / 2); 58 | 59 | Ellipse2D LeftLower = F.CreateEllipse(X, Y + Fatness / 2 - Height, 60 | 0, 0, Height / 2 - Fatness, Height - Fatness, 3 * Math.PI / 2, Math.PI / 2); 61 | Ellipse2D RightLower = F.CreateEllipse(X, Y + Fatness / 2 - Height, 62 | 0, 0, Height / 2, Height, 3 * Math.PI / 2, Math.PI / 2); 63 | 64 | LeftUpper.EndPoint = LeftLower.EndPoint; 65 | RightUpperLower.EndPoint = RightLower.EndPoint; 66 | 67 | Circle2D UpperCircle = F.CreateCircle(X, (Y + Height * 2) - Fatness, Fatness / 2, -Math.PI / 2, Math.PI / 2); 68 | UpperCircle.EndPoint = LeftUpper.StartPoint; 69 | UpperCircle.StartPoint = RightUpperUpper.StartPoint; 70 | 71 | Circle2D LowerCircle = F.CreateCircle(X, (Y - Height * 2) + Fatness, Fatness / 2, Math.PI / 2, -Math.PI / 2); 72 | LowerCircle.StartPoint = LeftLower.StartPoint; 73 | LowerCircle.EndPoint = RightLower.StartPoint; 74 | 75 | Point2D BarLowerStart = RightUpperLower.StartPoint; 76 | Line2D BarLower = F.CreateLine(BarLowerStart.GetPos().X, BarLowerStart.GetPos().Y, 77 | BarLowerStart.GetPos().X + Height / 2, BarLowerStart.GetPos().Y); 78 | BarLower.StartPoint = BarLowerStart; 79 | 80 | Point2D BarUpperStart = RightUpperUpper.EndPoint; 81 | Line2D BarUpper = F.CreateLine(BarUpperStart.GetPos().X, BarUpperStart.GetPos().Y, 82 | BarUpperStart.GetPos().X + Height / 2, BarUpperStart.GetPos().Y); 83 | BarUpper.StartPoint = BarUpperStart; 84 | 85 | double UpperX = BarUpper.EndPoint.GetPos().X; 86 | double UpperY = BarUpper.EndPoint.GetPos().Y; 87 | double LowerY = BarLower.EndPoint.GetPos().Y; 88 | double R = (UpperY - LowerY) / 2; 89 | Circle2D BarCircle = F.CreateCircle(UpperX, LowerY + R, R, -Math.PI / 2, Math.PI / 2); 90 | BarCircle.EndPoint = BarUpper.EndPoint; 91 | BarCircle.StartPoint = BarLower.EndPoint; 92 | } 93 | 94 | public static void GenerateMaze(double W, double H, int GridX, int GridY) { 95 | List> LookupTable = new List>(); 96 | Func TableGet = (A) => { 97 | for (int i = 0; i < LookupTable.Count; i++) 98 | if (LookupTable[i].Item1 == A) 99 | return LookupTable[i].Item2; 100 | return null; 101 | }; 102 | 103 | Maze M = new Maze(GridX, GridY); 104 | Line[] Lines = M.Generate(W, H); 105 | 106 | EditSketch(GetCurrentSketch(), (F) => { 107 | for (int i = 0; i < Lines.Length; i++) 108 | F.DrawLine(Lines[i]); 109 | 110 | /*Line2D L = F.DrawLine(new Vector(20, 20), new Vector(100, 100)); 111 | F.DrawLine(L.EndPoint, new Vector(30, 20));*/ 112 | }); 113 | GetCurrentPartDocument().Part.Update(); 114 | } 115 | 116 | public static void GenerateLogo(float X, float Y, float Height, float Fatness) { 117 | EditSketch(GetCurrentSketch(), (F) => Logo(F, X, Y, Height, Fatness)); 118 | GetCurrentPartDocument().Part.Update(); 119 | } 120 | } 121 | } -------------------------------------------------------------------------------- /CatiaNET/CatiaNET.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {E6B8811F-9460-4FB9-903E-22AF91134FDA} 8 | Library 9 | Properties 10 | CatiaNET 11 | CatiaNET 12 | v4.0 13 | 512 14 | 15 | 16 | 17 | true 18 | full 19 | false 20 | D:\Zavrsni3\bin\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | D:\Zavrsni3\bin\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | {73130905-462A-11D1-A26A-0000F87546A1} 58 | 0 59 | 0 60 | 0 61 | tlbimp 62 | False 63 | True 64 | 65 | 66 | {14F197B2-0771-11D1-A5B1-00A0C9575177} 67 | 0 68 | 0 69 | 0 70 | tlbimp 71 | False 72 | True 73 | 74 | 75 | {0770412C-722E-11D2-8378-0060941974FF} 76 | 0 77 | 0 78 | 0 79 | tlbimp 80 | False 81 | True 82 | 83 | 84 | {0D90A5C9-3B08-11D1-A26C-0000F87546FD} 85 | 0 86 | 0 87 | 0 88 | tlbimp 89 | False 90 | True 91 | 92 | 93 | {D8431606-E4B5-11D1-A5D3-00A0C95752ED} 94 | 0 95 | 0 96 | 0 97 | tlbimp 98 | False 99 | True 100 | 101 | 102 | {5065F8B6-61BB-11D1-9D85-0000F8759F82} 103 | 0 104 | 0 105 | 0 106 | tlbimp 107 | False 108 | True 109 | 110 | 111 | 112 | 119 | -------------------------------------------------------------------------------- /CatiaNET/FactoryExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | using System.Windows; 7 | using MECMOD; 8 | 9 | namespace CatiaNET { 10 | public static class FactoryExtensions { 11 | static Dictionary LookupTable = new Dictionary(); 12 | 13 | public static Vector GetPos(this Point2D P) { 14 | object[] Pos = new object[2]; 15 | P.GetCoordinates(Pos); 16 | return new Vector((double)Pos[0], (double)Pos[1]); 17 | } 18 | 19 | public static Point2D DrawPoint(this Factory2D F, Vector P) { 20 | return F.CreatePoint(P.X, P.Y); 21 | } 22 | 23 | static Line2D CreateLine(this Factory2D F, Vector Start, Vector End) { 24 | return F.CreateLine(Start.X, Start.Y, End.X, End.Y); 25 | } 26 | 27 | public static Line2D DrawLine(this Factory2D F, Line L) { 28 | return F.DrawLine(L.Start, L.End); 29 | } 30 | 31 | public static Line2D DrawLine(this Factory2D F, Vector Start, Vector End) { 32 | Line2D L = F.CreateLine(Start, End); 33 | if (LookupTable.ContainsKey(Start)) 34 | L.StartPoint = LookupTable[Start]; 35 | else { 36 | L.StartPoint = L.StartPoint; 37 | LookupTable.Add(Start, L.StartPoint); 38 | } 39 | if (LookupTable.ContainsKey(End)) 40 | L.EndPoint = LookupTable[End]; 41 | else { 42 | L.EndPoint = L.EndPoint; 43 | LookupTable.Add(End, L.EndPoint); 44 | } 45 | return L; 46 | } 47 | 48 | public static Line2D DrawLine(this Factory2D F, Point2D Start, Point2D End) { 49 | Line2D L = F.CreateLine(Start.GetPos(), End.GetPos()); 50 | L.StartPoint = Start; 51 | L.EndPoint = End; 52 | return L; 53 | } 54 | 55 | public static Line2D DrawLine(this Factory2D F, Point2D Start, Vector End) { 56 | Line2D L = F.CreateLine(Start.GetPos(), End); 57 | L.StartPoint = Start; 58 | if (LookupTable.ContainsKey(End)) 59 | L.EndPoint = LookupTable[End]; 60 | else { 61 | L.EndPoint = L.EndPoint; 62 | LookupTable.Add(End, L.EndPoint); 63 | } 64 | return L; 65 | } 66 | 67 | public static Line2D DrawLine(this Factory2D F, Vector Start, Point2D End) { 68 | Line2D L = F.CreateLine(Start, End.GetPos()); 69 | if (LookupTable.ContainsKey(Start)) 70 | L.StartPoint = LookupTable[Start]; 71 | else { 72 | L.StartPoint = L.StartPoint; 73 | LookupTable.Add(Start, L.StartPoint); 74 | } 75 | L.EndPoint = End; 76 | return L; 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /CatiaNET/Line.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Windows; 6 | 7 | namespace CatiaNET { 8 | public struct Line { 9 | public Vector Start, End; 10 | 11 | public Line(double X1, double Y1, double X2, double Y2) 12 | : this(new Vector(X1, Y1), new Vector(X2, Y2)) { 13 | } 14 | 15 | public Line(Vector Start, Vector End) { 16 | this.Start = Start; 17 | this.End = End; 18 | } 19 | 20 | public bool IsEqualAngle(Line Line2, double Tolerance = 1) { 21 | double AngA = Vector.AngleBetween(Start, End).ToAng(); 22 | double AngB = Vector.AngleBetween(Line2.Start, Line2.End).ToAng(); 23 | return Math.Abs(AngA - AngB) < Tolerance; 24 | } 25 | 26 | public override bool Equals(object obj) { 27 | if (obj == null || GetType() != obj.GetType()) 28 | return false; 29 | return ((Line)obj) == this; 30 | } 31 | 32 | public override int GetHashCode() { 33 | return (Start.GetHashCode() * 251) + End.GetHashCode(); 34 | } 35 | 36 | public static bool operator ==(Line A, Line B) { 37 | return A.Start == B.Start && A.End == B.End; 38 | } 39 | 40 | public static bool operator !=(Line A, Line B) { 41 | return !(A == B); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /CatiaNET/MazeTree.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Windows; 6 | using System.Drawing; 7 | using System.Drawing.Imaging; 8 | 9 | using Point = System.Windows.Point; 10 | 11 | namespace CatiaNET { 12 | public static class Extensions { 13 | public static IEnumerable Shuffle(this IEnumerable Src, Random RNG) { 14 | var E = Src.ToArray(); 15 | for (var i = E.Length - 1; i >= 0; i--) { 16 | var swapIndex = RNG.Next(i + 1); 17 | yield return E[swapIndex]; 18 | E[swapIndex] = E[i]; 19 | } 20 | } 21 | 22 | public static CellState OppositeWall(this CellState Orig) { 23 | return (CellState)(((int)Orig >> 2) | ((int)Orig << 2)) & CellState.Initial; 24 | } 25 | 26 | public static string GetStates(this CellState CS) { 27 | string[] Names = Enum.GetNames(typeof(CellState)); 28 | StringBuilder SB = new StringBuilder(); 29 | for (int i = 0; i < Names.Length; i++) 30 | if (CS.HasFlag((CellState)Enum.Parse(typeof(CellState), Names[i]))) 31 | SB.AppendFormat("{0} ", Names[i]); 32 | return SB.ToString().Trim(); 33 | } 34 | } 35 | 36 | [Flags] 37 | public enum CellState { 38 | Bottom = 1 << 0, 39 | Right = 1 << 1, 40 | Top = 1 << 2, 41 | Left = 1 << 3, 42 | Visited = 1 << 5, 43 | Initial = Bottom | Right | Top | Left, 44 | } 45 | 46 | public struct RemoveWallAction { 47 | public Point Neighbour; 48 | public CellState Wall; 49 | } 50 | 51 | public class Maze { 52 | private readonly CellState[,] Cells; 53 | private readonly int Width; 54 | private readonly int Height; 55 | private readonly Random RNG; 56 | 57 | public Maze(int Width, int Height) { 58 | this.Width = Width; 59 | this.Height = Height; 60 | Cells = new CellState[Width, Height]; 61 | for (var x = 0; x < Width; x++) 62 | for (var y = 0; y < Height; y++) 63 | Cells[x, y] = CellState.Initial; 64 | //RNG = new Random(42); 65 | RNG = new Random(); 66 | VisitCell(RNG.Next(Width), RNG.Next(Height)); 67 | } 68 | 69 | public CellState this[int x, int y] { 70 | get { 71 | return Cells[x, y]; 72 | } 73 | set { 74 | Cells[x, y] = value; 75 | } 76 | } 77 | 78 | public IEnumerable GetNeighbours(Point p) { 79 | if (p.X > 0) 80 | yield return new RemoveWallAction { 81 | Neighbour = new Point(p.X - 1, p.Y), 82 | Wall = CellState.Left 83 | }; 84 | if (p.Y > 0) 85 | yield return new RemoveWallAction { 86 | Neighbour = new Point(p.X, p.Y - 1), 87 | Wall = CellState.Bottom 88 | }; 89 | if (p.X < Width - 1) 90 | yield return new RemoveWallAction { 91 | Neighbour = new Point(p.X + 1, p.Y), 92 | Wall = CellState.Right 93 | }; 94 | if (p.Y < Height - 1) 95 | yield return new RemoveWallAction { 96 | Neighbour = new Point(p.X, p.Y + 1), 97 | Wall = CellState.Top 98 | }; 99 | } 100 | 101 | public void VisitCell(int x, int y) { 102 | this[x, y] |= CellState.Visited; 103 | foreach (var p in GetNeighbours(new Point(x, y)).Shuffle(RNG).Where(z => 104 | !(this[(int)z.Neighbour.X, (int)z.Neighbour.Y].HasFlag(CellState.Visited)))) { 105 | this[x, y] -= p.Wall; 106 | this[(int)p.Neighbour.X, (int)p.Neighbour.Y] -= p.Wall.OppositeWall(); 107 | VisitCell((int)p.Neighbour.X, (int)p.Neighbour.Y); 108 | } 109 | } 110 | 111 | public CellState GetCell(int X, int Y) { 112 | if (X < 0 || X >= Cells.GetLength(0)) 113 | return CellState.Initial; 114 | if (Y < 0 || Y >= Cells.GetLength(1)) 115 | return CellState.Initial; 116 | return Cells[X, Y]; 117 | } 118 | 119 | public bool HasFlag(int X, int Y, CellState F) { 120 | return GetCell(X, Y).HasFlag(F); 121 | } 122 | 123 | public Line[] GenerateWalls(int X, int Y, double ScaleX, double ScaleY) { 124 | List Lines = new List(); 125 | CellState S = GetCell(X, Y); 126 | float OriginalOffset = 0.5f; 127 | float Offset = OriginalOffset; 128 | 129 | float XOffset = OriginalOffset; 130 | float YOffset = OriginalOffset; 131 | 132 | if (S.HasFlag(CellState.Bottom)) { 133 | XOffset = !HasFlag(X, Y, CellState.Right) ? 1 : Offset; 134 | 135 | Lines.Add(new Line(X * ScaleX, Y * ScaleY, (X + XOffset) * ScaleX, Y * ScaleY)); // Bottom 136 | } 137 | 138 | if (S.HasFlag(CellState.Left)) { 139 | YOffset = !HasFlag(X, Y, CellState.Top) ? 1 : Offset; 140 | 141 | Lines.Add(new Line((X) * ScaleX, Y * ScaleY, (X) * ScaleX, (Y + YOffset) * ScaleY)); // Left 142 | } 143 | 144 | if (S.HasFlag(CellState.Top)) { 145 | XOffset = !HasFlag(X, Y, CellState.Right) ? 1 : Offset; 146 | 147 | Lines.Add(new Line(X * ScaleX, (Y + YOffset) * ScaleY, (X + XOffset) * ScaleX, (Y + YOffset) * ScaleY)); // Top 148 | } 149 | 150 | if (S.HasFlag(CellState.Right)) { 151 | YOffset = !HasFlag(X, Y, CellState.Top) ? 1 : Offset; 152 | 153 | Lines.Add(new Line((X + XOffset) * ScaleX, Y * ScaleY, (X + XOffset) * ScaleX, (Y + YOffset) * ScaleY)); // Right 154 | } 155 | 156 | // Top missing 157 | if (!S.HasFlag(CellState.Bottom) && !S.HasFlag(CellState.Right) && HasFlag(X, Y - 1, CellState.Right)) 158 | Lines.Add(new Line((X + OriginalOffset) * ScaleX, Y * ScaleY, (X + 1) * ScaleX, Y * ScaleY)); // Bottom 159 | 160 | // Bottom missing 161 | if (!S.HasFlag(CellState.Top) && !S.HasFlag(CellState.Right) && !HasFlag(X + 1, Y, CellState.Top)) 162 | Lines.Add(new Line((X + OriginalOffset) * ScaleX, (Y + 1) * ScaleY, (X + 1) * ScaleX, (Y + 1) * ScaleY)); // Bottom 163 | 164 | // Left missing 165 | if (!S.HasFlag(CellState.Left) && HasFlag(X - 1, Y, CellState.Top) && HasFlag(X, Y + 1, CellState.Left)) 166 | Lines.Add(new Line((X) * ScaleX, (Y + OriginalOffset) * ScaleY, (X) * ScaleX, (Y + YOffset) * ScaleY)); // Left 167 | 168 | // Right missing 169 | if (!S.HasFlag(CellState.Right) && HasFlag(X + 1, Y, CellState.Top) && HasFlag(X + 1, Y + 1, CellState.Bottom) 170 | && !(HasFlag(X, Y + 1, CellState.Right) || HasFlag(X, Y + 1, CellState.Bottom))) 171 | Lines.Add(new Line((X + 1) * ScaleX, (Y + OriginalOffset) * ScaleY, (X + 1) * ScaleX, (Y + YOffset) * ScaleY)); // Left 172 | 173 | if (X == 4 && Y == 0) { 174 | Console.WriteLine(GetCell(X - 1, Y).GetStates()); 175 | Console.WriteLine(S.GetStates()); 176 | Console.WriteLine(GetCell(X, Y + 1).GetStates()); 177 | Console.ReadLine(); 178 | } 179 | 180 | //Lines.Add(new Line(X * ScaleX, Y * ScaleY, (X + 1) * ScaleX, Y * ScaleY)); // Bottom 181 | //Lines.Add(new Line((X) * ScaleX, Y * ScaleY, (X) * ScaleX, (Y + 1) * ScaleY)); // Left 182 | //Lines.Add(new Line(X * ScaleX, (Y + 1) * ScaleY, (X + 1) * ScaleX, (Y + 1) * ScaleY)); // Top 183 | //Lines.Add(new Line((X + 1) * ScaleX, Y * ScaleY, (X + 1) * ScaleX, (Y + 1) * ScaleY)); // Right 184 | 185 | // Old code 186 | /*if (S.HasFlag(CellState.Top)) { 187 | Lines.Add(new Line(new Vector(X * ScaleX, (Y) * ScaleY), 188 | new Vector((X + 1) * ScaleX, (Y) * ScaleY))); 189 | } 190 | if (S.HasFlag(CellState.Left)) { 191 | Lines.Add(new Line(new Vector(X * ScaleX, Y * ScaleY), 192 | new Vector(X * ScaleX, (Y + 1) * ScaleY))); 193 | }//*/ 194 | 195 | return Lines.ToArray(); 196 | } 197 | 198 | public Line[] Generate(double ScaleX, double ScaleY) { 199 | HashSet Lines = new HashSet(); 200 | const int Size = 2; 201 | 202 | Bitmap Bmp = new Bitmap(Width * Size + 1, Height * Size + 1); 203 | Graphics BmpGraphics = Graphics.FromImage(Bmp); 204 | BmpGraphics.Clear(Color.White); 205 | BmpGraphics.Dispose(); 206 | Color FillClr = Color.Black; 207 | 208 | Func GetPixel = (XX, YY) => { 209 | if (XX < 0 || XX >= Bmp.Width || YY < 0 || YY >= Bmp.Height) 210 | return true; 211 | Color Col = Bmp.GetPixel(XX, YY); 212 | if (Col.R == 0 && Col.G == 0 && Col.B == 0) 213 | return true; 214 | return false; 215 | }; 216 | 217 | Action SetPixel = (XX, YY, B) => { 218 | if (XX < 0 || XX >= Bmp.Width || YY < 0 || YY >= Bmp.Height) 219 | return; 220 | Color Col = Color.Black; 221 | if (!B) 222 | Col = Color.White; 223 | Bmp.SetPixel(XX, YY, Col); 224 | }; 225 | 226 | Action PutLeft = (XX, YY) => { 227 | for (int h = 0; h < Size + 1; h++) 228 | SetPixel(XX * Size, YY * Size + h, true); 229 | }; 230 | Action PutBottom = (XX, YY) => { 231 | for (int h = 0; h < Size + 1; h++) 232 | SetPixel(XX * Size + h, YY * Size, true); 233 | }; 234 | 235 | for (int y = 0; y < Height; y++) 236 | for (int x = 0; x < Width; x++) { 237 | if (HasFlag(x, y, CellState.Left)) 238 | PutLeft(x, y); 239 | if (HasFlag(x, y, CellState.Bottom)) 240 | PutBottom(x, y); 241 | } 242 | 243 | for (int y = 0; y < Bmp.Height; y++) 244 | for (int x = 0; x < Bmp.Width; x++) 245 | if (y + 1 == Bmp.Height || x + 1 == Bmp.Width) 246 | SetPixel(x, y, true); 247 | 248 | ScaleX /= Bmp.Width; 249 | ScaleY /= Bmp.Height; 250 | 251 | Lines.Add(new Line(0, Bmp.Height * ScaleY, Bmp.Width * ScaleX, Bmp.Height * ScaleY)); 252 | Lines.Add(new Line(0, 0, 0, Bmp.Height * ScaleY)); 253 | Lines.Add(new Line(0, 0, Bmp.Width * ScaleX, 0)); 254 | Lines.Add(new Line(Bmp.Width * ScaleX, 0, Bmp.Width * ScaleX, Bmp.Height * ScaleY)); 255 | 256 | for (int y = 0; y < Bmp.Height; y++) 257 | for (int x = 0; x < Bmp.Width; x++) 258 | if (!GetPixel(x, y)) { // If empty 259 | if (GetPixel(x, y + 1)) // Top 260 | Lines.Add(new Line(x * ScaleX, (y + 1) * ScaleY, (x + 1) * ScaleX, (y + 1) * ScaleY)); 261 | if (GetPixel(x - 1, y)) // Left 262 | Lines.Add(new Line(x * ScaleX, y * ScaleY, x * ScaleX, (y + 1) * ScaleY)); 263 | if (GetPixel(x, y - 1)) // Bottom 264 | Lines.Add(new Line(x * ScaleX, y * ScaleY, (x + 1) * ScaleX, y * ScaleY)); 265 | if (GetPixel(x + 1, y)) // Right 266 | Lines.Add(new Line((x + 1) * ScaleX, y * ScaleY, (x + 1) * ScaleX, (y + 1) * ScaleY)); 267 | } 268 | 269 | Bmp.RotateFlip(RotateFlipType.RotateNoneFlipY); 270 | Bmp.Save("maze.png", ImageFormat.Png); 271 | return Lines.ToArray(); 272 | } 273 | } 274 | } -------------------------------------------------------------------------------- /CatiaNET/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("CatiaNET")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("CatiaNET")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("e97014c2-c1b4-4aac-afe3-ccd85c92577e")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /CatiaNET/Tuple.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace CatiaNET { 7 | /*class Tuple { 8 | public T1 Item1; 9 | public T2 Item2; 10 | 11 | public Tuple(T1 A, T2 B) { 12 | Item1 = A; 13 | Item2 = B; 14 | } 15 | }*/ 16 | } -------------------------------------------------------------------------------- /CatiaNET/Utils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.VisualBasic; 6 | using System.Windows; 7 | 8 | namespace CatiaNET { 9 | public static class Utils { 10 | public static string TypeName(this object O) { 11 | return Information.TypeName(O); 12 | } 13 | 14 | public static T[] Concat(this T[] A, T[] B) { 15 | T[] New = new T[A.Length + B.Length]; 16 | Array.Copy(A, New, A.Length); 17 | Array.Copy(B, 0, New, A.Length, B.Length); 18 | return New; 19 | } 20 | 21 | public static double Dot(Vector A, Vector B) { 22 | return A.X * B.X + A.Y * B.Y; 23 | } 24 | 25 | public static double Fract(double D) { 26 | return D - Math.Truncate(D); 27 | } 28 | 29 | public static double ToAng(this double Rad) { 30 | return Rad * 180.0 / Math.PI; 31 | } 32 | 33 | public static double Rand(double X, double Y) { 34 | return Fract(Math.Sin(Dot(new Vector(X, Y), new Vector(12.9898, 78.233))) * 43758.5453); 35 | } 36 | 37 | public static Vector HashOffset(this Vector V, double Amp = 5) { 38 | return new Vector(V.X + Rand(V.X, V.Y) * Amp, V.Y + Rand(V.X, V.Y) * Amp); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CatiaNET 2 | Catia V5R20 programming interface tools for .NET 3 | -------------------------------------------------------------------------------- /TSBLogo/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /TSBLogo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using CatiaNET; 6 | 7 | namespace TSBLogo { 8 | class Program { 9 | static string Prompt(string P) { 10 | Console.Write(P); 11 | return Console.ReadLine(); 12 | } 13 | 14 | static int PromptInt(string P) { 15 | return int.Parse(Prompt(P)); 16 | } 17 | 18 | [STAThread] 19 | static void Main(string[] args) { 20 | Console.Title = "TSB Logo"; 21 | 22 | //Prompt("Press enter to generate maze ... "); 23 | Catia.GenerateMaze(300, 500, 15, 25); 24 | //Catia.GenerateMaze(PromptInt("Width: "), PromptInt("Height: "), PromptInt("Grid X: "), PromptInt("Grid Y: ")); 25 | /*Prompt("Press enter to generate logo ... "); 26 | Catia.GenerateLogo(90, 250, 100, 16);*/ 27 | 28 | Console.WriteLine("Done!"); 29 | //Console.ReadLine(); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /TSBLogo/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TSBLogo")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TSBLogo")] 13 | [assembly: AssemblyCopyright("Copyright © 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("33a78402-5fa7-42e8-b20c-e83472a7eaf0")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /TSBLogo/TSBLogo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {8C719216-32C8-4036-ADF6-DDBAD4703245} 8 | Exe 9 | Properties 10 | TSBLogo 11 | TSBLogo 12 | v4.0 13 | 512 14 | 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | D:\Zavrsni3\bin\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | D:\Zavrsni3\bin\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | {e6b8811f-9460-4fb9-903e-22af91134fda} 54 | CatiaNET 55 | 56 | 57 | 58 | 65 | --------------------------------------------------------------------------------