Skip to content

Commit

Permalink
use_last feature partial complete with paper and scale
Browse files Browse the repository at this point in the history
use_last feature complete with paper and scale
  • Loading branch information
Chengxuan-Li committed Jun 15, 2022
1 parent cecc190 commit d9a4263
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 5 deletions.
Binary file modified .vs/RPH/v16/.suo
Binary file not shown.
91 changes: 86 additions & 5 deletions RPHAddNewLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ protected override Result RunCommand(RhinoDoc doc, RunMode mode)
// ask for options

RPHLayoutSettings settings = new RPHLayoutSettings();


while (choosing_layout_options)
{
Expand Down Expand Up @@ -103,7 +104,8 @@ protected override Result RunCommand(RhinoDoc doc, RunMode mode)
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:
Expand Down Expand Up @@ -383,7 +385,9 @@ protected override Result RunCommand(RhinoDoc doc, RunMode mode)
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 = 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();
Expand Down Expand Up @@ -443,12 +447,15 @@ protected override Result RunCommand(RhinoDoc doc, RunMode mode)
// 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;
Expand Down Expand Up @@ -528,9 +535,81 @@ public object Clone()
return this.MemberwiseClone();
}

public void StoreToUserStringTable()
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])
);
}*/


}


Expand Down Expand Up @@ -588,7 +667,7 @@ 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_User_Defined_Paper", this.paper_width, this.paper_height);
this.paper_size_name = string.Format("{0}mm_x_{1}mm_paper", this.paper_width, this.paper_height);
UpdateLocalVariables();
}

Expand Down Expand Up @@ -636,6 +715,8 @@ 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();
}

Expand Down
Binary file modified bin/RPH.pdb
Binary file not shown.
Binary file modified bin/RPH.rhp
Binary file not shown.
Binary file modified obj/Debug/RPH.dll
Binary file not shown.
Binary file modified obj/Debug/RPH.pdb
Binary file not shown.

0 comments on commit d9a4263

Please sign in to comment.