-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathplug.cs
208 lines (176 loc) · 7.38 KB
/
plug.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.IO;
using CamBam;
using CamBam.UI;
using CamBam.CAD;
using CamBam.Util;
namespace Matmill
{
// Insert logger into the matmill namespace to be bound in compile-time
class Logger
{
static public void log(int level, string s, params object[] args)
{
ThisApplication.AddLogMessage(level, s, args);
}
static public void log(string s, params object[] args)
{
ThisApplication.AddLogMessage(4, s, args);
}
static public void warn(string s, params object[] args)
{
ThisApplication.AddLogMessage("Trocho warning: " + s, args);
}
static public void err(string s, params object[] args)
{
ThisApplication.AddLogMessage("Trocho error: " + s, args);
}
}
}
namespace Trochomops
{
// alias for compatibility with the old name of trochoidal pocket
[Serializable]
public class Mop_matmill : MOPTrochopock
{
}
public static class Plug
{
const string pocket_mop_name = "Trochoidal Pocket";
const string profile_mop_name = "Trochoidal Profile";
private static void pocket_mop_onclick(object sender, EventArgs ars)
{
if (!PolylineUtils.ConfirmSelected(CamBamUI.MainUI.ActiveView))
{
return;
}
MOPTrochopock mop = new MOPTrochopock(CamBamUI.MainUI.ActiveView.CADFile, CamBamUI.MainUI.ActiveView.Selection);
CamBamUI.MainUI.InsertMOP(mop);
}
private static void profile_mop_onclick(object sender, EventArgs ars)
{
if (!PolylineUtils.ConfirmSelected(CamBamUI.MainUI.ActiveView))
{
return;
}
MOPTrochoprof mop = new MOPTrochoprof(CamBamUI.MainUI.ActiveView.CADFile, CamBamUI.MainUI.ActiveView.Selection);
CamBamUI.MainUI.InsertMOP(mop);
}
private static void insert_in_top_menu(CamBamUI ui, ToolStripMenuItem entry)
{
for (int i = 0; i < ui.Menus.mnuMachining.DropDownItems.Count; ++i)
{
ToolStripItem tsi = ui.Menus.mnuMachining.DropDownItems[i];
if (tsi is ToolStripSeparator || i == ui.Menus.mnuMachining.DropDownItems.Count - 1)
{
ui.Menus.mnuMachining.DropDownItems.Insert(i, entry);
return;
}
}
}
private static void insert_in_context_menu(CamBamUI ui, ToolStripMenuItem entry)
{
foreach (ToolStripItem tsi in ui.ViewContextMenus.ViewContextMenu.Items)
{
if (tsi is ToolStripMenuItem && tsi.Name == "machineToolStripMenuItem")
{
ToolStripMenuItem tsmi = (ToolStripMenuItem)tsi;
for (int i = 0; i < tsmi.DropDownItems.Count; ++i)
{
if (tsmi.DropDownItems[i] is ToolStripSeparator || i == tsmi.DropDownItems.Count - 1)
{
tsmi.DropDownItems.Insert(i, entry);
return;
}
}
}
}
}
private static void insert_in_toolbar(ToolStripButton button)
{
foreach (Control c in ThisApplication.TopWindow.Controls)
{
if (c is ToolStripContainer)
{
foreach (Control cc in ((ToolStripContainer)c).TopToolStripPanel.Controls)
{
if (cc is CAMToolStrip)
{
CAMToolStrip strip = (CAMToolStrip)cc;
// check if 'Custom CAMToolbar plugin' already iserted us
foreach (ToolStripButton b in strip.Items)
{
if (b.ToolTipText == button.ToolTipText)
return;
}
strip.Items.Add(button);
return;
}
}
}
}
}
private static void on_window_shown(object sender, EventArgs e)
{
ThisApplication.TopWindow.Shown -= on_window_shown;
ToolStripButton button;
button = new ToolStripButton();
button.ToolTipText = TextTranslation.Translate(profile_mop_name);
button.Click += profile_mop_onclick;
button.Image = resources.cam_trochoprof1;
insert_in_toolbar(button);
button = new ToolStripButton();
button.ToolTipText = TextTranslation.Translate(pocket_mop_name);
button.Click += pocket_mop_onclick;
button.Image = resources.cam_trochopock1;
insert_in_toolbar(button);
}
public static void InitPlugin(CamBamUI ui)
{
ToolStripMenuItem menu_entry;
menu_entry = new ToolStripMenuItem();
menu_entry.Text = profile_mop_name;
menu_entry.Click += profile_mop_onclick;
menu_entry.Image = resources.cam_trochoprof1;
insert_in_top_menu(ui, menu_entry);
menu_entry = new ToolStripMenuItem();
menu_entry.Text = profile_mop_name;
menu_entry.Click += profile_mop_onclick;
menu_entry.Image = resources.cam_trochoprof1;
insert_in_context_menu(ui, menu_entry);
menu_entry = new ToolStripMenuItem();
menu_entry.Text = pocket_mop_name;
menu_entry.Click += pocket_mop_onclick;
menu_entry.Image = resources.cam_trochopock1;
insert_in_top_menu(ui, menu_entry);
menu_entry = new ToolStripMenuItem();
menu_entry.Text = pocket_mop_name;
menu_entry.Click += pocket_mop_onclick;
menu_entry.Image = resources.cam_trochopock1;
insert_in_context_menu(ui, menu_entry);
// defer attachment to toolbar until the first show.
// Custom CAM Toolbar plugin (if installed) may already attached us after Load event, so we react on later Shown event
ThisApplication.TopWindow.Shown += on_window_shown;
if (CADFile.ExtraTypes == null)
CADFile.ExtraTypes = new List<Type>();
CADFile.ExtraTypes.Add(typeof(MOPTrochopock));
CADFile.ExtraTypes.Add(typeof(Mop_matmill));
CADFile.ExtraTypes.Add(typeof(MOPTrochoprof));
{
MOPTrochopock o = new MOPTrochopock();
XmlSerializer xmlSerializer = new XmlSerializer(typeof(MOPTrochopock));
MemoryStream stream = new MemoryStream();
xmlSerializer.Serialize(stream, o);
}
{
MOPTrochoprof o = new MOPTrochoprof();
XmlSerializer xmlSerializer = new XmlSerializer(typeof(MOPTrochoprof));
MemoryStream stream = new MemoryStream();
xmlSerializer.Serialize(stream, o);
}
}
}
}