forked from Timelessww/DotNetARX2012
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotSettingsEx.cs
More file actions
707 lines (698 loc) · 24.2 KB
/
Copy pathPlotSettingsEx.cs
File metadata and controls
707 lines (698 loc) · 24.2 KB
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.PlottingServices;
namespace DotNetARX
{
/// <summary>
/// 增强型打印设置类,支持数据绑定
/// </summary>
public class PlotSettingsEx : PlotSettings, INotifyPropertyChanged
{
#region INotifyPropertyChanged接口的实现
/// <summary>
/// 在更改属性值时发生的事件
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// 处理属性更改事件的函数
/// </summary>
/// <param name="info">属性名</param>
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
#endregion
//获取当前打印设置验证类
private PlotSettingsValidator validator=PlotSettingsValidator.Current;
/// <summary>
/// 复制构造函数,从已有打印设置中获取打印设置
/// </summary>
/// <param name="ps">已有打印设置</param>
public PlotSettingsEx(PlotSettings ps)
: base(ps.ModelType)
{
this.CopyFrom(ps);//从已有打印设置中获取打印设置
//更新打印设备、图纸尺寸和打印样式表信息
validator.RefreshLists(this);
}
#region 覆盖基类属性
/// <summary>
/// 获取或设置当前图纸尺寸(中文表示)
/// </summary>
public new string CanonicalMediaName
{
get
{
//将图纸尺寸从英文名改为中文名
string mediaLocal=base.CanonicalMediaName.Replace("_", " ").Replace("MM", "毫米").Replace("Inches", "英寸").Replace("Pixels", "像素");
return mediaLocal;//返回中文名的图纸尺寸
}
set
{
if (value != CanonicalMediaName)//如果图纸尺寸有变化
{
//将图纸尺寸从中文名改为英文名
string mediaName=value.Replace(" ", "_").Replace("毫米", "MM").Replace("英寸", "Inches").Replace("像素", "Pixels");
//设置当前图纸尺寸
validator.SetCanonicalMediaName(this, mediaName);
//向客户端发出某一属性值已更改的通知
NotifyPropertyChanged("CanonicalMediaName");
}
}
}
/// <summary>
/// 获取或设置当前打印样式表
/// </summary>
public new string CurrentStyleSheet
{
get { return base.CurrentStyleSheet; }
set
{
if (value != CurrentStyleSheet)
{
if (value != "无")
{
validator.SetCurrentStyleSheet(this, value);
}
else validator.SetCurrentStyleSheet(this, "");
NotifyPropertyChanged("CurrentStyleSheet");
}
}
}
/// <summary>
/// 获取或设置自定义打印比例
/// </summary>
public new CustomScale CustomPrintScale
{
get { return base.CustomPrintScale; }
set
{
if (value != CustomPrintScale)
{
validator.SetCustomPrintScale(this, value);
NotifyPropertyChanged("CustomPrintScale");
}
}
}
/// <summary>
/// 获取或设置是否居中打印
/// </summary>
public new bool PlotCentered
{
get { return base.PlotCentered; }
set
{
if (value != PlotCentered)
{
validator.SetPlotCentered(this, value);
NotifyPropertyChanged("PlotCentered");
}
}
}
/// <summary>
/// 获取或设置当前打印设备名称
/// </summary>
public new string PlotConfigurationName
{
get { return base.PlotConfigurationName; }
set
{
if (value != PlotConfigurationName)
{
validator.SetPlotConfigurationName(this, value, null);
NotifyPropertyChanged("PlotConfigurationName");
}
}
}
/// <summary>
/// 获取或设置当前打印原点(原点是从图纸边界的介质边缘偏移而来的)。
/// </summary>
public new Point2d PlotOrigin
{
get { return base.PlotOrigin; }
set
{
if (value != PlotOrigin)
{
validator.SetPlotOrigin(this, value);
NotifyPropertyChanged("PlotOrigin");
}
}
}
/// <summary>
/// 获取或设置打印比例
/// </summary>
public new PlotPaperUnit PlotPaperUnits
{
get { return base.PlotPaperUnits; }
set
{
if (value != PlotPaperUnits)
{
validator.SetPlotPaperUnits(this, value);
NotifyPropertyChanged("PlotPaperUnits");
}
}
}
/// <summary>
/// 获取或设置图形方向
/// </summary>
public new PlotRotation PlotRotation
{
get { return base.PlotRotation; }
set
{
if (value != PlotRotation)
{
validator.SetPlotRotation(this, value);
NotifyPropertyChanged("PlotRotation");
}
}
}
/// <summary>
/// 获取或设置打印范围
/// </summary>
public new Autodesk.AutoCAD.DatabaseServices.PlotType PlotType
{
get { return base.PlotType; }
set
{
if (value != PlotType)
{
validator.SetPlotType(this, value);
NotifyPropertyChanged("PlotType");
}
}
}
/// <summary>
/// 获取或设置打印视口名
/// </summary>
public new string PlotViewName
{
get { return base.PlotViewName; }
set
{
if (value != PlotViewName)
{
validator.SetPlotViewName(this, value);
NotifyPropertyChanged("PlotViewName");
}
}
}
/// <summary>
/// 获取或设置打印窗口的范围
/// </summary>
public new Extents2d PlotWindowArea
{
get { return base.PlotWindowArea; }
set
{
if (value != PlotWindowArea)
{
validator.SetPlotWindowArea(this, value);
NotifyPropertyChanged("PlotWindowArea");
}
}
}
/// <summary>
/// 获取或设置当前标准比例(实数形式)
/// </summary>
public new double StdScale
{
get { return base.StdScale; }
set
{
if (value != StdScale)
{
validator.SetStdScale(this, value);
NotifyPropertyChanged("StdScale");
}
}
}
/// <summary>
/// 获取或设置当前标准比例(枚举形式)
/// </summary>
public new StdScaleType StdScaleType
{
get { return base.StdScaleType; }
set
{
if (value != StdScaleType)
{
validator.SetStdScaleType(this, value);
NotifyPropertyChanged("StdScaleType");
}
}
}
/// <summary>
/// 获取或设置是否选用标准比例
/// </summary>
public new bool UseStandardScale
{
get { return base.UseStandardScale; }
set
{
if (value != UseStandardScale)
{
validator.SetUseStandardScale(this, value);
NotifyPropertyChanged("UseStandardScale");
}
}
}
#endregion
/// <summary>
/// 获取或设置当前图形单位
/// </summary>
public double Denominator
{
get { return base.CustomPrintScale.Denominator; }
set
{
if (value != Denominator)
{
CustomScale newScale=new CustomScale(CustomPrintScale.Numerator, value);
validator.SetCustomPrintScale(this, newScale);
NotifyPropertyChanged("Denominator");
}
}
}
/// <summary>
/// 获取或设置当前图纸单位
/// </summary>
public double Numerator
{
get { return base.CustomPrintScale.Numerator; }
set
{
if (value != Numerator)
{
CustomScale newScale=new CustomScale(value, CustomPrintScale.Denominator);
validator.SetCustomPrintScale(this, newScale);
NotifyPropertyChanged("Numerator");
}
}
}
/// <summary>
/// 获取或设置当前X方向的打印偏移
/// </summary>
public double PlotOriginX
{
get { return base.PlotOrigin.X; }
set
{
if (value != PlotOriginX)
{
Point2d newOrigin=new Point2d(value, PlotOrigin.Y);
validator.SetPlotOrigin(this, newOrigin);
NotifyPropertyChanged("PlotOriginX");
}
}
}
/// <summary>
/// 获取或设置当前Y方向的打印偏移
/// </summary>
public double PlotOriginY
{
get { return base.PlotOrigin.Y; }
set
{
if (value != PlotOriginY)
{
Point2d newOrigin=new Point2d(PlotOrigin.X, value);
validator.SetPlotOrigin(this, newOrigin);
NotifyPropertyChanged("PlotOriginY");
}
}
}
/// <summary>
/// 获取或设置打印时是否布满图纸
/// </summary>
public bool PlotExtent
{
get
{
if (this.UseStandardScale && this.StdScaleType == StdScaleType.ScaleToFit)
return true;
else return false;
}
set
{
if (value != PlotExtent)
{
if (value)
{
validator.SetUseStandardScale(this, true);
validator.SetStdScaleType(this, StdScaleType.ScaleToFit);
}
else validator.SetUseStandardScale(this, false);
NotifyPropertyChanged("PlotExtent");
}
}
}
/// <summary>
/// 获取或设置是否反向打印
/// </summary>
public bool PlotReverse
{
get
{
if (PlotRotation == PlotRotation.Degrees180 || PlotRotation == PlotRotation.Degrees270) return true;
else return false;
}
set
{
if (value != PlotReverse)
{
int numRotation=(int)PlotRotation;
if (value == true)
{
numRotation += 2;
}
else
numRotation -= 2;
validator.SetPlotRotation(this, (Autodesk.AutoCAD.DatabaseServices.PlotRotation)numRotation);
NotifyPropertyChanged("PlotReverse");
}
}
}
#region 列表类属性
/// <summary>
/// 获取当前打印设备列表
/// </summary>
public List<string> DeviceList
{
get
{
StringCollection deviceCollection=validator.GetPlotDeviceList();
List<string> deviceList=new List<string>();
foreach (string device in deviceCollection)
{
deviceList.Add(device);
}
return deviceList;
}
}
/// <summary>
/// 获取当前图纸尺寸列表(中文表示)
/// </summary>
public List<string> MediaList
{
get
{
StringCollection mediaCollection=validator.GetCanonicalMediaNameList(this);
List<string> mediaList=new List<string>();
foreach (string media in mediaCollection)
{
string mediaLocal=media.Replace("_", " ").Replace("MM", "毫米").Replace("Inches", "英寸").Replace("Pixels", "像素");
mediaList.Add(mediaLocal);
}
return mediaList; ;
}
}
/// <summary>
/// 获取当前打印范围列表(中文表示)
/// </summary>
public List<string> PlotTypeList
{
get
{
if (ModelType)//模型空间
return (new List<string> { "窗口", "图形界限", "显示" });
else//图纸空间
return (new List<string> { "布局", "窗口", "范围", "显示" });
}
}
/// <summary>
/// 获取当前打印单位列表(中文表示)
/// </summary>
public List<string> PlotUnitList
{
get
{
if (PlotPaperUnits == PlotPaperUnit.Pixels)
return (new List<string> { "像素" });
else
return (new List<string> { "毫米", "英寸" });
}
}
/// <summary>
/// 获取颜色相关打印样式列表
/// </summary>
public List<string> ColorDependentPlotStyles
{
get
{
List<string> styleSheetList=(from string style in validator.GetPlotStyleSheetList()
where style.EndsWith("ctb")
select style).ToList();
styleSheetList.Insert(0, "无");
return styleSheetList;
}
}
/// <summary>
/// 获取命名打印样式列表
/// </summary>
public List<string> NamedPlotStyles
{
get
{
List<string> styleSheetList=(from string style in validator.GetPlotStyleSheetList()
where style.EndsWith("stb")
select style).ToList();
styleSheetList.Insert(0, "无");
return styleSheetList;
}
}
/// <summary>
/// 获取标准打印比例列表
/// </summary>
public Dictionary<StdScaleType, string> StdScaleTypeList
{
get
{
var scaleTypeDict=new Dictionary<StdScaleType, string>();
List<string> scaleTypeList=new List<string>()
{
"自定义","1/128'' = 1'-0''","1/64'' = 1'-0''","1/32'' = 1'-0''","1/16'' = 1'-0''","3/32'' = 1'-0''",
"1/8'' = 1'-0''","3/16'' = 1'-0''","1/4'' = 1'-0''","3/8'' = 1'-0''","1/2'' = 1'-0''","3/4'' = 1'-0''",
"1'' = 1'-0''","3'' = 1'-0''","6'' = 1'-0''","1'-0'''' = 1'-0''",
"1:1","1:2","1:4","1:8","1:10","1:16","1:20","1:30","1:40","1:50","1:100",
"2:1","4:1","8:1","10:1","100:1","1000:1"
};
scaleTypeDict.Add(StdScaleType.ScaleToFit, scaleTypeList[0]);
for (int i = 16; i <= 32; i++)
{
scaleTypeDict.Add((StdScaleType)i, scaleTypeList[i]);
}
for (int i = 1; i < 16; i++)
{
scaleTypeDict.Add((StdScaleType)i, scaleTypeList[i]);
}
return scaleTypeDict;
}
}
#endregion
#region 中文属性
/// <summary>
/// 获取或设置打印范围(中文)
/// </summary>
public string PlotTypeLocal
{
get
{
string plotTypeLocal="";
switch (base.PlotType)
{
case Autodesk.AutoCAD.DatabaseServices.PlotType.Display:
plotTypeLocal = "显示";
break;
case Autodesk.AutoCAD.DatabaseServices.PlotType.Extents:
plotTypeLocal = "范围";
break;
case Autodesk.AutoCAD.DatabaseServices.PlotType.Layout:
plotTypeLocal = "布局";
break;
case Autodesk.AutoCAD.DatabaseServices.PlotType.Limits:
plotTypeLocal = "图形界限";
break;
case Autodesk.AutoCAD.DatabaseServices.PlotType.View:
plotTypeLocal = "视图";
break;
case Autodesk.AutoCAD.DatabaseServices.PlotType.Window:
plotTypeLocal = "窗口";
break;
}
return plotTypeLocal;
}
set
{
if (value != PlotTypeLocal)
{
switch (value)
{
case "显示":
PlotType = Autodesk.AutoCAD.DatabaseServices.PlotType.Display;
break;
case "范围":
PlotType = Autodesk.AutoCAD.DatabaseServices.PlotType.Extents;
break;
case "布局":
PlotType = Autodesk.AutoCAD.DatabaseServices.PlotType.Layout;
break;
case "图形界限":
PlotType = Autodesk.AutoCAD.DatabaseServices.PlotType.Limits;
break;
case "视图":
PlotType = Autodesk.AutoCAD.DatabaseServices.PlotType.View;
break;
case "窗口":
PlotType = Autodesk.AutoCAD.DatabaseServices.PlotType.Window;
break;
}
NotifyPropertyChanged("PlotTypeLocal");
}
}
}
/// <summary>
/// 获取或设置打印单位(中文)
/// </summary>
public string PlotPaperUnitsLocal
{
get
{
string plotUnitLocal="";
switch (base.PlotPaperUnits)
{
case PlotPaperUnit.Inches: plotUnitLocal = "英寸"; break;
case PlotPaperUnit.Millimeters: plotUnitLocal = "毫米"; break;
case PlotPaperUnit.Pixels: plotUnitLocal = "像素"; break;
}
return plotUnitLocal;
}
set
{
if (value != PlotPaperUnitsLocal)
{
switch (value)
{
case "英寸": validator.SetPlotPaperUnits(this, PlotPaperUnit.Inches); break;
case "毫米": validator.SetPlotPaperUnits(this, PlotPaperUnit.Millimeters); break;
case "像素": validator.SetPlotPaperUnits(this, PlotPaperUnit.Pixels); break;
}
NotifyPropertyChanged("PlotPaperUnitsLocal");
}
}
}
/// <summary>
/// 获取或设置当前标准打印比例(中文)
/// </summary>
public string StdScaleTypeLocal
{
get
{
if (!UseStandardScale) return "自定义";
else
return StdScaleTypeList[StdScaleType];
}
set
{
if (value != StdScaleTypeLocal)
{
StdScaleType newScaleType=StdScaleTypeList.First(s => s.Value == value).Key;
validator.SetStdScaleType(this, newScaleType);
NotifyPropertyChanged("StdScaleTypeLocal");
}
}
}
#endregion
/// <summary>
/// 是否打印到文件
/// </summary>
public bool IsPlotToFile
{
get
{
//如果未选择打印设备,则直接返回
if (PlotConfigurationName == "无") return false;
//获取当前打印配置,并返回其是否打印到文件属性
PlotConfig config=PlotConfigManager.CurrentConfig;
return config.IsPlotToFile;
}
}
/// <summary>
/// 可以不打印到文件
/// </summary>
public bool NoPlotToFile
{
get
{
//如果未选择打印设备,则直接返回
if (PlotConfigurationName == "无") return false;
//获取当前打印配置,并返回其是否必须打印到文件
PlotConfig config=PlotConfigManager.CurrentConfig;
if (config.PlotToFileCapability == PlotToFileCapability.MustPlotToFile)
return false;
else return true;
}
}
/// <summary>
/// 获取或设置是否横向打印
/// </summary>
public bool PlotHorizontal
{
get
{
if (base.PlotRotation == PlotRotation.Degrees090 || base.PlotRotation == PlotRotation.Degrees270) return true;
else return false;
}
set
{
if (value != PlotHorizontal)
{
if (value == true)
{
if (PlotReverse)
validator.SetPlotRotation(this, PlotRotation.Degrees270);
else
validator.SetPlotRotation(this, PlotRotation.Degrees090);
}
else
{
if (PlotReverse)
validator.SetPlotRotation(this, PlotRotation.Degrees180);
else
validator.SetPlotRotation(this, PlotRotation.Degrees000);
}
}
NotifyPropertyChanged("PlotHorizontal");
}
}
/// <summary>
/// 更新其它的打印设置
/// </summary>
/// <param name="psId">打印设置对象</param>
public void UpdatePlotSettings(ObjectId psId)
{
Document doc=Application.DocumentManager.MdiActiveDocument;
using (doc.LockDocument())
using (Transaction trans = doc.TransactionManager.StartTransaction())
{
PlotSettings ps=psId.GetObject(OpenMode.ForWrite) as PlotSettings;
if (ps != null)
{
ps.CopyFrom(this);//复制当前打印设置
}
trans.Commit();
}
}
}
}