-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRPHAddNewLayout.cs
1382 lines (1129 loc) · 52.6 KB
/
RPHAddNewLayout.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
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
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using Rhino;
using Rhino.Commands;
using Rhino.Geometry;
using Rhino.Input;
using Rhino.Input.Custom;
using Rhino.Display;
using Rhino.DocObjects.Tables;
using System;
using System.IO;
using Rhino.Collections;
using System.Collections.Generic;
using System.Drawing;
public enum layout_options_position
{
from_point,
from_rectangle
}
public enum layout_options_paper
{
iso_paper_sizes,
custom_paper_sizes
}
public enum layout_options_name
{
layout_name,
drawing_name,
drawing_alternative_name
}
//FUTURE
public enum layout_options_edge
{
drawing_edge_mm,
printing_edge_mm
}
namespace RPH
{
public class RPHAddNewLayout : Command
{
static RPHAddNewLayout _instance;
public RPHAddNewLayout()
{
_instance = this;
}
///<summary>The only instance of the RPHAddNewLayout command.</summary>
public static RPHAddNewLayout Instance
{
get { return _instance; }
}
public override string EnglishName
{
get { return "RPHAddNewLayout"; }
}
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
bool choosing_layout_options = true;
bool commit_layout_creation = true;
// ask for options
RPHLayoutSettings settings = new RPHLayoutSettings();
while (choosing_layout_options)
{
settings.LayoutCreationPreview(true);
// List<string> layout_options_general = new List<string> { "Position", "Paper", "Scale", "Name", "Edge", "User_Attributes" };
List<string> layout_options_general = new List<string> { "Position", "Paper", "Scale", "Name", "Use_Last"};
List<string> layout_options_general_defaults = new List<string> { "", settings.paper_size_name, String.Format("1:{0}", settings.scale), "", "", "" };
List<string> layout_options_position = new List<string> { "From_Point", "From_Content_Objects" };
List<string> justification = new List<string> { "Bottom_Left", "Bottom_Right", "Top_Left", "Top_Right", "Center" };
List<string> layout_options_paper = new List<string> { "ISO_Paper_Code", "Orientation", "Use_Custom_Paper_Size" };
List<string> layout_options_paper_defaults = new List<string> { settings.paper_size_name, "Portrait", "No" };
if (settings.is_landscape)
{
layout_options_paper_defaults = new List<string> { settings.paper_size_name, "Landscape", "No" };
}
List<string> layout_options_paper_codes = new List<string> { "A0", "A1", "A2", "A3", "A4", "A5" };
List<string> layout_options_name = new List<string> { "layout_name", "drawing_name", "drawing_alt_name" };
List<string> layout_options_name_defaults = new List<string> { settings.layout_name, settings.drawing_name, settings.drawing_alt_name };
Point3d point = new Point3d(0, 0, 0);
int bounding_box_mode = 2;
GetOption options_dialog_general = new GetOption();
LayoutOptionDialog layout_options_dialog_general = new LayoutOptionDialog(options_dialog_general, "Layout Settings:", layout_options_general, layout_options_general_defaults);
int general_choice_index = layout_options_dialog_general.DialogResult().Getint("choice_index", -1);
switch(general_choice_index)
{
case 1:
/// position options
GetOption options_dialog_position = new GetOption();
LayoutOptionDialog layout_options_dialog_position = new LayoutOptionDialog(options_dialog_position, "Specify Layout Position:", layout_options_position);
int position_choice_index = layout_options_dialog_position.DialogResult().Getint("choice_index", -1);
switch(position_choice_index)
{
case 1:
bool choosing_point = true;
int justification_choice_index = 1;
while (choosing_point)
{
GetPoint options_dialog_point = new GetPoint();
Vector3d[] bounding_box_relative_transform_vectors = settings.GetBoundingBoxRelativeRelativeTransformVectors(justification_choice_index);
options_dialog_point.DynamicDraw += (sender, e) => e.Display.DrawLine(
e.CurrentPoint + bounding_box_relative_transform_vectors[0], e.CurrentPoint + bounding_box_relative_transform_vectors[1],
Color.White, 2);
options_dialog_point.DynamicDraw += (sender, e) => e.Display.DrawLine(
e.CurrentPoint + bounding_box_relative_transform_vectors[1], e.CurrentPoint + bounding_box_relative_transform_vectors[2],
Color.White, 2);
options_dialog_point.DynamicDraw += (sender, e) => e.Display.DrawLine(
e.CurrentPoint + bounding_box_relative_transform_vectors[2], e.CurrentPoint + bounding_box_relative_transform_vectors[3],
Color.White, 2);
options_dialog_point.DynamicDraw += (sender, e) => e.Display.DrawLine(
e.CurrentPoint + bounding_box_relative_transform_vectors[3], e.CurrentPoint + bounding_box_relative_transform_vectors[0],
Color.White, 2);
LayoutOptionDialog layout_options_dialog_point = new LayoutOptionDialog(options_dialog_point, "Specify a Point", new List<string> { "Justification" }, new List<string> {justification[justification_choice_index - 1]});
int point_choice_index = layout_options_dialog_position.DialogResult().Getint("choice_index", -1);
if (layout_options_dialog_point.DialogResult().Getint("choice_index", -1) == 0)
{
GetOption option_dialog_justification = new GetOption();
LayoutOptionDialog layout_options_dialog_justification = new LayoutOptionDialog(option_dialog_justification, "Specify Justification Method", justification);
justification_choice_index = layout_options_dialog_justification.DialogResult().Getint("choice_index", 1);
}
if (layout_options_dialog_point.DialogResult().Getint("choice_index", -1) == 1)
{
point = layout_options_dialog_point.DialogResult().GetPoint3d("result", new Point3d(0, 0, 0));
break;
}
if (layout_options_dialog_point.DialogResult().Getint("choice_index", -1) == -1)
{
break;
}
}
Rectangle3d layout_rectangle;
switch (justification_choice_index)
{
case 1:
layout_rectangle = settings.layout_boundingbox;
layout_rectangle.Transform(Transform.Translation(point - layout_rectangle.PointAt(4)));
settings.SetLayoutScaleOrigin(point);
settings.SetLayoutBoundingBox(layout_rectangle);
settings.SetLayoutScaleOrigin(point);
break;
case 2:
layout_rectangle = settings.layout_boundingbox;
layout_rectangle.Transform(Transform.Translation(point - layout_rectangle.PointAt(1)));
settings.SetLayoutScaleOrigin(point);
settings.SetLayoutBoundingBox(layout_rectangle);
settings.SetLayoutScaleOrigin(point);
break;
case 3:
layout_rectangle = settings.layout_boundingbox;
layout_rectangle.Transform(Transform.Translation(point - layout_rectangle.PointAt(3)));
settings.SetLayoutScaleOrigin(point);
settings.SetLayoutBoundingBox(layout_rectangle);
settings.SetLayoutScaleOrigin(point);
break;
case 4:
layout_rectangle = settings.layout_boundingbox;
layout_rectangle.Transform(Transform.Translation(point - layout_rectangle.PointAt(2)));
settings.SetLayoutScaleOrigin(point);
settings.SetLayoutBoundingBox(layout_rectangle);
settings.SetLayoutScaleOrigin(point);
break;
case 5:
layout_rectangle = settings.layout_boundingbox;
layout_rectangle.Transform(Transform.Translation(point - layout_rectangle.Center));
settings.SetLayoutScaleOrigin(point);
settings.SetLayoutBoundingBox(layout_rectangle);
settings.SetLayoutScaleOrigin(point);
break;
default:
break;
}
settings.LayoutCreationPreview(true);
doc.Views.Redraw();
break;
case 2:
bool choosing_content_objects = true;
settings.LayoutCreationPreview(false);
GetObject options_dialog_objects = new GetObject();
options_dialog_objects.GeometryFilter = Rhino.DocObjects.ObjectType.Point | Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.PointSet;
LayoutOptionDialog layout_options_dialog_objects = new LayoutOptionDialog(options_dialog_objects, "Pick Content Objects"
/*, new List<string> { "Bounding_Box_Mode" }*/
);
int content_objects_choice_index = layout_options_dialog_objects.DialogResult().Getint("choice_index", -1);
/*
if (content_objects_choice_index == 0)
{
GetOption options_dialog_bounding_box_mode = new GetOption();
LayoutOptionDialog layout_options_dialog_bounding_box_mode = new LayoutOptionDialog(options_dialog_bounding_box_mode, "Specify Bounding Box Mode", new List<string> { "Accurate", "Coarse" });
if (layout_options_dialog_bounding_box_mode.DialogResult().Getint("choice_index", -1) != -1)
{
bounding_box_mode = layout_options_dialog_bounding_box_mode.DialogResult().Getint("choice_index", -1);
}
}
*/
bool accurate = false;
ObjectListBoundingBox Box = new ObjectListBoundingBox(options_dialog_objects.Objects(), accurate);
BoundingBox box = Box.Box();
Rectangle3d rectangle = new Rectangle3d(Plane.WorldXY, box.Min, box.Max);
settings.SetLayoutBoundingBox(rectangle);
settings.SetLayoutScaleOrigin(rectangle.Center);
settings.LayoutCreationPreview(true);
doc.Views.Redraw();
break;
default:
break;
}
break;
case 2:
settings.LayoutCreationPreview(true);
doc.Views.Redraw();
/// paper options
bool choosing_paper = true;
while (choosing_paper)
{
layout_options_paper_defaults[0] = settings.paper_size_name;
if (settings.is_landscape)
{
layout_options_paper_defaults[1] = "Landscape";
} else
{
layout_options_paper_defaults[1] = "Portrait";
}
GetOption options_dialog_paper = new GetOption();
LayoutOptionDialog layout_options_dialog_paper = new LayoutOptionDialog(options_dialog_paper, "Paper Settings:", layout_options_paper, layout_options_paper_defaults);
int paper_choice_index = layout_options_dialog_paper.DialogResult().Getint("choice_index", -1);
if (paper_choice_index == -1)
{
choosing_paper = false;
}
switch (paper_choice_index)
{
case 1:
GetOption options_dialog_paper_codes = new GetOption();
LayoutOptionDialog layout_options_dialog_paper_codes = new LayoutOptionDialog(options_dialog_paper_codes, "ISO Paper Size:", layout_options_paper_codes);
int paper_code_choice_index = layout_options_dialog_paper_codes.DialogResult().Getint("choice_index", -1);
if (settings.is_landscape)
{
if (paper_code_choice_index != -1)
{
settings.SetPaperSize(paper_code_choice_index - 1);
}
} else
{
if (paper_code_choice_index != -1)
{
settings.SetPaperSize(paper_code_choice_index - 1);
settings.SetPaperSize(paper_code_choice_index - 1);
}
settings.SetPaperOrientation(false);//remain original orientation because SetPaperSize() always sets it into landscape XD NOOB ME
}
doc.Views.Redraw();
break;
case 2:
GetOption options_dialog_paper_orientation = new GetOption();
LayoutOptionDialog layout_options_dialog_paper_orientation = new LayoutOptionDialog(options_dialog_paper_orientation, "Orientation:", new List<string> { "Landscape", "Portrait" });
int paper_orientation_choice_index = layout_options_dialog_paper_orientation.DialogResult().Getint("choice_index", -1);
if (paper_orientation_choice_index == 1)
{
settings.SetPaperOrientation(true);
}
if (paper_orientation_choice_index == 2)
{
settings.SetPaperOrientation(false);
}
doc.Views.Redraw();
break;
case 3:
double paper_width = settings.paper_width;
double paper_height = settings.paper_height;
GetNumber options_dialog_paper_width = new GetNumber();
LayoutOptionDialog layout_options_dialog_paper_width = new LayoutOptionDialog(options_dialog_paper_width, "Width (mm)");
int paper_width_choice_index = layout_options_dialog_paper_width.DialogResult().Getint("choice_index", -1);
if (paper_width_choice_index == 1)
{
paper_width = layout_options_dialog_paper_width.DialogResult().GetDouble("result");
}
GetNumber options_dialog_paper_height = new GetNumber();
LayoutOptionDialog layout_options_dialog_paper_height = new LayoutOptionDialog(options_dialog_paper_height, "Height (mm)");
int paper_height_choice_index = layout_options_dialog_paper_height.DialogResult().Getint("choice_index", -1);
if (paper_height_choice_index == 1)
{
paper_height = layout_options_dialog_paper_height.DialogResult().GetDouble("result");
}
settings.SetPaperSize(paper_width, paper_height);
doc.Views.Redraw();
layout_options_paper_defaults[2] = "Yes";
break;
default:
break;
}
}
break;
case 3:
settings.LayoutCreationPreview(true);
doc.Views.Redraw();
/// scale options
double scale = settings.scale;
GetNumber options_dialog_scale = new GetNumber();
LayoutOptionDialog layout_options_dialog_scale = new LayoutOptionDialog(options_dialog_scale, "Specify Drawing Scale (e.g. 100 means 1:100)");
int paper_scale_choice_index = layout_options_dialog_scale.DialogResult().Getint("choice_index", -1);
if (paper_scale_choice_index == 1)
{
scale = layout_options_dialog_scale.DialogResult().GetDouble("result", 100);
}
settings.SetScale(scale);
doc.Views.Redraw();
break;
case 4:
settings.LayoutCreationPreview(true);
/// name options
doc.Views.Redraw();
break;
case 5:
/// use last
doc.Views.Redraw();
settings.LayoutCreationPreview(false);
settings = new RPHLayoutSettings(); /// LOAD USERSTRING HERE TO RESTORE LAST SETTINGS, SAVE SETTINGS INTO RHINO USERSTRING IN RPHLayoutSettings CLASS
settings.ReadFromUserStringTable(doc);
settings.LayoutCreationPreview(true);
doc.Views.Redraw();
break;
case -1:
choosing_layout_options = false;
settings.LayoutCreationPreview(false);
doc.Views.Redraw();
break;
default:
choosing_layout_options = false;
doc.Views.Redraw();
break;
}
}
settings.LayoutCreationPreview(true);
doc.Views.Redraw();
GetOption options_dialog_commit = new GetOption();
options_dialog_commit.AcceptEnterWhenDone(true);
options_dialog_commit.AcceptNothing(true);
LayoutOptionDialog layout_options_dialog_commit = new LayoutOptionDialog(options_dialog_commit, "Previewing ... Commit Changes?", new List<string> { "Yes", "No" });
if (layout_options_dialog_commit.DialogResult().Getint("choice_index", -1) > 1 | layout_options_dialog_commit.DialogResult().Getint("choice_index", -1) < 0)
{
settings.LayoutCreationPreview(false);
doc.Views.Redraw();
return Result.Cancel;
}
else
{
commit_layout_creation = true;
choosing_layout_options = false;
}
if (commit_layout_creation)
{
settings.AddLayout(doc);
}
settings.LayoutCreationPreview(false);
doc.Views.Redraw();
// check whether all existing layouts are created with RPH
// return messages if not all layouts are created with RPH
// add new layout
// add new layout attributes
// add detail view
// adjust detail view position and scale
settings.StoreToUserStringTable(doc); /// EXPERIMENTAL
return Result.Success;
}
}
public class RPHLayoutSettings : ICloneable
{
// general built-in
String section_name = "RPHAddlayoutLastAttempt";
// paper settings
public string paper_size_name;
public double paper_width;
public double paper_height;
public bool is_landscape;
// plotting settings
public double scale = 100;
public bool drawing_elements_scaling;
// layout settings
public int layout_id;
public Guid layout_guid;
public string layout_name;
public Point3d layout_origin;
public Point3d layout_scale_origin;
public Plane layout_plane;
public Plane layout_scale_plane;
public double model_width;
public double model_height;
public Rectangle3d layout_boundingbox;
// drawing settings
public string drawing_name;
public string drawing_alt_name;
public double printing_edge;
public double drawing_edge;
// attribute settings
public ExtendedArchivableDictionary extended_user_dictionary = new ExtendedArchivableDictionary();
public ArchivableDictionary user_dictionary = new ArchivableDictionary();
// preview settings
DisplayConduitLayoutPreview layout_preview_display_conduit = new DisplayConduitLayoutPreview();
// private variables
// private Vector3d unit_x = new Vector3d(1, 0, 0);
private Vector3d layout_x = new Vector3d(0, 0, 1);
public RPHLayoutSettings()
{
this.paper_size_name = "A3";
this.paper_width = 420;
this.paper_height = 297;
UpdatePageOrientation();
UpdateModelDimensions();
this.scale = 100;
this.drawing_elements_scaling = true;
this.layout_id = 0;
this.layout_guid = Guid.NewGuid();
this.layout_name = "L_" + this.layout_guid.ToString().Substring(0, 4);
this.layout_origin = new Point3d(0, 0, 0);
this.layout_scale_origin = new Point3d(0, 0, 0);
UpdateLayoutPlane();
this.layout_boundingbox = new Rectangle3d(this.layout_plane, this.model_width, this.model_height);
UpdateLayoutBoundingBox();
this.drawing_name = "Default Drawing";
this.drawing_alt_name = "Default Drawing Alt Name";
this.printing_edge = 3; //FUTURE
this.drawing_edge = 10; //FUTURE
layout_preview_display_conduit.Enabled = false; //TODO _ ONLY FOR TESTS
//TEST?
UpdateLocalVariables();
}
public object Clone()
{
return this.MemberwiseClone();
}
public void StoreToUserStringTable(RhinoDoc doc)
{
// TODO
StringTable string_table = doc.Strings;
string_table.SetString(section_name, "paper_width", this.paper_width.ToString());
string_table.SetString(section_name, "paper_height", this.paper_height.ToString());
string_table.SetString(section_name, "scale", this.scale.ToString());
string_table.SetString(section_name, "origin", this.layout_origin.ToString());
string_table.SetString(section_name, "scale_origin", this.layout_scale_origin.ToString());
}
public void ReadFromUserStringTable(RhinoDoc doc)
{
StringTable string_table = doc.Strings;
String[] entry_names = string_table.GetEntryNames(section_name);
bool table_has_width = false;
bool table_has_height = false;
bool table_has_scale = false;
bool table_has_origin = false;
bool table_has_scale_origin = false;
foreach (string entry_name in entry_names)
{
if (entry_name.Equals("paper_width"))
{
table_has_width = true;
}
if (entry_name.Equals("paper_height"))
{
table_has_height = true;
}
if (entry_name.Equals("scale"))
{
table_has_scale = true;
}
if (entry_name.Equals("origin"))
{
table_has_origin = true;
}
if (entry_name.Equals("scale_origin"))
{
table_has_scale_origin = true;
}
}
if (table_has_width && table_has_height)
{
this.SetPaperSize(Double.Parse(string_table.GetValue(section_name, "paper_width")), Double.Parse(string_table.GetValue(section_name, "paper_height")));
}
if (table_has_scale)
{
this.SetScale(Double.Parse(string_table.GetValue(section_name, "scale")));
}
/*if (table_has_origin)
{
this.SetLayoutOrigin(
Double.Parse(string_table.GetValue(section_name, "origin").Split(new[] { ',' })[0]),
Double.Parse(string_table.GetValue(section_name, "origin").Split(new[] { ',' })[1])
);
}
if (table_has_scale_origin)
{
this.SetLayoutScaleOrigin(
Double.Parse(string_table.GetValue(section_name, "scale_origin").Split(new[] { ',' })[0]),
Double.Parse(string_table.GetValue(section_name, "scale_origin").Split(new[] { ',' })[1])
);
}*/
}
public void SetPaperSize(int code)
{
switch (code)
{
case 0:
this.paper_size_name = "A0";
this.paper_width = 1189;
this.paper_height = 841;
break;
case 1:
this.paper_size_name = "A1";
this.paper_width = 841;
this.paper_height = 594;
break;
case 2:
this.paper_size_name = "A2";
this.paper_width = 594;
this.paper_height = 420;
break;
case 3:
this.paper_size_name = "A3";
this.paper_width = 420;
this.paper_height = 297;
break;
case 4:
this.paper_size_name = "A4";
this.paper_width = 297;
this.paper_height = 210;
break;
case 5:
this.paper_size_name = "A5";
this.paper_width = 210;
this.paper_height = 148;
break;
default:
this.paper_size_name = "A3";
this.paper_width = 420;
this.paper_height = 297;
break;
}
UpdateLocalVariables();
}
public void SetPaperSize(double width, double height)
{
this.paper_width = width;
this.paper_height = height;
this.paper_size_name = string.Format("{0}mm_x_{1}mm_paper", this.paper_width, this.paper_height);
UpdateLocalVariables();
}
public void SetPaperOrientation(bool is_landscape)
{
UpdatePageOrientation();
if (this.is_landscape != is_landscape)
{
double temp_w = this.paper_height;
this.paper_height = this.paper_width;
this.paper_width = temp_w;
UpdateLocalVariables();
} else
{
UpdateLocalVariables();
}
return;
}
public void SetScale(double scale)
{
this.scale = scale;
UpdateLocalVariables();
}
public void SetDrawingElementsScaling(bool scaling)
{
this.drawing_elements_scaling = scaling;
UpdateLocalVariables();
}
public void SetLayoutId(int id)
{
this.layout_id = id;
UpdateLocalVariables();
}
public void SetLayoutName(string name)
{
this.layout_name = name;
UpdateLocalVariables();
}
public void SetLayoutOrigin(Point3d origin)
{
this.layout_scale_origin = (Point3d)(this.layout_scale_origin + origin - this.layout_origin);
this.layout_origin = origin;
// this.SetLayoutPlane(this.layout_origin, Vector3d.ZAxis);
/// TODO this is not effective?
UpdateLocalVariables();
}
public void SetLayoutOrigin(double x, double y)
{
SetLayoutOrigin(new Point3d(x, y, 0));
}
public void SetLayoutScaleOrigin(Point3d origin)
{
this.layout_scale_origin = origin;
UpdateLocalVariables();
}
public void SetLayoutScaleOrigin(double x, double y)
{
SetLayoutScaleOrigin(new Point3d(x, y, 0));
UpdateLocalVariables();
}
public void SetLayoutPlane(Point3d origin)
{
this.layout_origin = origin;
UpdateLocalVariables();
}
public void SetLayoutPlane(Point3d origin, Vector3d x_axis)
{
this.layout_origin = origin;
this.layout_x = Vector3d.ZAxis;
UpdateLocalVariables();
}
public void SetLayoutPlane(Vector3d x_axis)
{
this.layout_x = x_axis;
UpdateLocalVariables();
}
public void SetLayoutScalePlane(Point3d origin)
{
this.layout_scale_plane = new Plane(origin, this.layout_x);
}
public void SetLayoutScalePlane(Point3d origin, Vector3d x_axis)
{
this.layout_x = x_axis;
this.layout_scale_plane = new Plane(origin, x_axis);
UpdateLocalVariables();
}
public void SetLayoutBoundingBox(Rectangle3d rectangle)
{
this.layout_boundingbox = rectangle;
this.model_width = Math.Abs(rectangle.X.T1 - rectangle.X.T0);
this.model_height = Math.Abs(rectangle.Y.T1 - rectangle.Y.T0);
this.paper_width = this.model_width / this.scale * 1000;
this.paper_height = this.model_height / this.scale * 1000;
this.layout_origin = rectangle.PointAt(0);
this.layout_x = new Vector3d(rectangle.PointAt(1) - rectangle.PointAt(0));
//this.SetLayoutScaleOrigin(rectangle.Center);
this.SetLayoutPlane(this.layout_origin, Vector3d.ZAxis);
UpdateLocalVariables();
}
public void SetLayoutBoundingBox(double width, double height)
{
this.model_width = width;
this.model_height = height;
this.paper_width = this.model_width / this.scale * 1000;
this.paper_height = this.model_height / this.scale * 1000;
this.layout_boundingbox = new Rectangle3d(Plane.WorldXY, this.model_width, this.model_height);
Point3d center = new Point3d(width / 2, height / 2, 0);
this.layout_origin = new Point3d(0, 0, 0);
//SetLayoutScaleOrigin(center);
UpdateLocalVariables();
}
public void SetDrawingName(string name)
{
this.drawing_name = name;
UpdateLocalVariables();
}
public void SetDrawingAltName(string name)
{
this.drawing_alt_name = name;
UpdateLocalVariables();
}
//FUTURE
public void SetPrintingEdge(double edge)
{
this.printing_edge = edge;
UpdateLocalVariables();
}
//FUTURE
public void SetDrawingEdge(double edge)
{
this.drawing_edge = edge;
UpdateLocalVariables();
}
private void UpdateLocalVariables()
{
/// use private methods to update all relevant local variables IN ORDER -> UPDATE EVERYTHING!
// a list of methods to implement
UpdatePageOrientation();
UpdateLayoutPlane();
UpdateModelDimensions();
UpdateLayoutBoundingBox();
UpdateUserDictionary();
return;
}
private void UpdatePageOrientation()
{
/// private method called on every change made to change the page size
if (this.paper_width >= this.paper_height)
{
this.is_landscape = true;
return;
} else
{
this.is_landscape = false;
return;
}
}
private void UpdateLayoutPlane()
{
this.layout_plane = new Plane(this.layout_origin, Vector3d.ZAxis);
this.layout_scale_plane = new Plane(this.layout_scale_origin, Vector3d.ZAxis); // TODO TEST
}
private void UpdateModelDimensions()
{
this.model_width = this.paper_width * this.scale / 1000;
this.model_height = this.paper_height * this.scale / 1000;
}
private void UpdateLayoutBoundingBox()
{
Transform scaling = Transform.Scale(this.layout_scale_plane, model_width / Math.Abs(this.layout_boundingbox.X.Length), model_height / Math.Abs(this.layout_boundingbox.Y.Length), 1);
this.layout_boundingbox.Transform(scaling);
this.layout_preview_display_conduit.UpdatePreviewGeometry(this.layout_boundingbox);
}
private void UpdateUserDictionary()
{
extended_user_dictionary.SetLayoutSetting(this);
extended_user_dictionary.AddContentsFrom(GenerateArchivableDictionary());
}
public Vector3d[] GetBoundingBoxRelativeRelativeTransformVectors(int justification)
{
Point3d justified_origin = this.layout_boundingbox.Center;
switch (justification)
{
case 1:
justified_origin = this.layout_boundingbox.PointAt(4);
break;
case 2:
justified_origin = this.layout_boundingbox.PointAt(1);
break;
case 3:
justified_origin = this.layout_boundingbox.PointAt(3);
break;
case 4:
justified_origin = this.layout_boundingbox.PointAt(2);
break;
}
Vector3d vector_0 = new Vector3d(this.layout_boundingbox.PointAt(0) - justified_origin);
Vector3d vector_1 = new Vector3d(this.layout_boundingbox.PointAt(1) - justified_origin);
Vector3d vector_2 = new Vector3d(this.layout_boundingbox.PointAt(2) - justified_origin);
Vector3d vector_3 = new Vector3d(this.layout_boundingbox.PointAt(3) - justified_origin);
return new Vector3d[4] { vector_0, vector_1, vector_2, vector_3 };
}
public void LayoutCreationPreview(bool layout_creation_preview)
{
// TODO - ADD ANNOTATIONS AND TEXTS <- CONDUIT CLASS
this.layout_preview_display_conduit.Enabled = layout_creation_preview;
}
public void AddLayout(RhinoDoc doc)
{
// TODO
UpdateLocalVariables();
RhinoPageView[] page_views = doc.Views.GetPageViews();
List<Guid> layout_guids = new List<Guid>();
doc.PageUnitSystem = UnitSystem.Millimeters;
RhinoPageView layout = doc.Views.AddPageView(this.layout_name, paper_width, paper_height);
Point2d top_left = new Point2d(0, paper_height);
Point2d bottom_right = new Point2d(paper_width, 0);
Rhino.DocObjects.DetailViewObject detail = layout.AddDetailView(drawing_name, top_left, bottom_right, DefinedViewportProjection.Top);
layout.SetActiveDetail(detail.Id);
Point3d center = this.layout_boundingbox.Center;
detail.Viewport.SetCameraLocation(center, true);
detail.Viewport.SetCameraTarget(center, true);
detail.CommitViewportChanges();
detail.DetailGeometry.IsProjectionLocked = true;
detail.DetailGeometry.SetScale(scale / 1000, doc.ModelUnitSystem, 1, doc.PageUnitSystem);
detail.Attributes.UserDictionary.AddContentsFrom(user_dictionary);
detail.CommitChanges();
layout.SetPageAsActive();
doc.Views.ActiveView = layout;
doc.Views.Redraw();
}
public ArchivableDictionary GenerateArchivableDictionary()
{
// TODO - EXPERIMENTAL METHOD
user_dictionary.Set("paper_size_name", paper_size_name);
user_dictionary.Set("paper_width", paper_width);
user_dictionary.Set("paper_height", paper_height);
user_dictionary.Set("is_landscape", is_landscape);
user_dictionary.Set("scale", scale);
user_dictionary.Set("drawing_elements_scaling", drawing_elements_scaling);
user_dictionary.Set("layout_guid", layout_guid);
user_dictionary.Set("layout_id", layout_id);
user_dictionary.Set("layout_name", layout_name);
user_dictionary.Set("layout_origin", layout_origin);
user_dictionary.Set("layout_scale_origin", layout_scale_origin);
user_dictionary.Set("layout_plane", layout_plane);
user_dictionary.Set("layout_scale_plane", layout_scale_plane);
user_dictionary.Set("model_width", model_width);
user_dictionary.Set("model_height", model_height);
user_dictionary.Set("layout_boundingbox", new RectangleF((float)layout_boundingbox.PointAt(0).X, (float)layout_boundingbox.PointAt(0).Y, (float)model_width, (float)model_height));
user_dictionary.Set("drawing_name", drawing_name);
user_dictionary.Set("drawing_alt_name", drawing_alt_name);
user_dictionary.Set("printing_edge", printing_edge); //FUTURE
user_dictionary.Set("drawing_edge", drawing_edge); //FUTURE
return extended_user_dictionary;
}
}
public class ExtendedArchivableDictionary : ArchivableDictionary
{
/// <summary>
/// Extended ArchivableDictionary class with new methods to set and get RPHLayoutSettings layout_settings
/// </summary>
private RPHLayoutSettings layout_settings;
public void SetLayoutSetting(RPHLayoutSettings layout_settings)
{
this.layout_settings = layout_settings;
}
public RPHLayoutSettings GetLayoutSetting()
{
return this.layout_settings;
}
}