Skip to content

Commit

Permalink
Miscellaneous improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
strawberryfield committed Aug 9, 2022
1 parent 0f37e56 commit 0012636
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 30 deletions.
11 changes: 9 additions & 2 deletions Common/Engines/BaseEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public string Script
/// Storage for the instantiated Script object
/// </summary>
protected object ScriptInstance { get; set; }
/// <summary>
/// Pointer to the command line (if any)
/// </summary>
public ICommandLine CommandLine { get; set; }

#endregion

Expand All @@ -132,6 +136,7 @@ public BaseEngine()
FillColor = MagickColors.White;
BorderColor = MagickColors.Black;
Tag = string.Empty;
CommandLine = null;
}
/// <summary>
/// Constructor
Expand All @@ -154,6 +159,7 @@ public BaseEngine(ICommandLine par)
Tag = par.Tag;
OutputName = par.OutputName;
Extension = par.Extension;
CommandLine = par;
}
#endregion

Expand Down Expand Up @@ -247,7 +253,8 @@ public void SetImageInfo(string i, string o, MagickImage image, PaperFormats p =
/// gets the program banner
/// </summary>
/// <returns></returns>
public virtual string WelcomeBannerText() =>
"Casasoft Contemporary Carte de Visite GUI\nCopyright (c) 2020-2022 Roberto Ceccarelli - Casasoft\n";
public virtual string WelcomeBannerText() => CommandLine is null ?
"Casasoft Contemporary Carte de Visite GUI\nCopyright (c) 2020-2022 Roberto Ceccarelli - Casasoft\n" :
CommandLine.WelcomeBannerText();
#endregion
}
92 changes: 68 additions & 24 deletions Common/Engines/CubettiEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,22 @@ public class CubettiEngine : BaseEngine
/// Number of rows to generate
/// </summary>
public int Rows { get; set; } = 2;

/// <summary>
/// Number of Columns to generate
/// </summary>
public int Columns { get; set; } = 3;

/// <summary>
/// Size of any cube (mm)
/// </summary>
public int Size { get; set; } = 50;

/// <summary>
/// True if samples images will be created
/// </summary>
public bool useSampleImages { get; set; }

/// <summary>
/// Output paper size
/// </summary>
Expand Down Expand Up @@ -82,6 +86,7 @@ public CubettiEngine(ICommandLine par) : base(par)
ScriptingClass = new CubettiScripting();
Script = p.Script;
parameters = new CubettiParameters();
parameters.OutputName = p.OutputName;
}
#endregion

Expand Down Expand Up @@ -147,16 +152,16 @@ public List<MagickImage> GetResults(bool quiet)
{
for (int i = 0; i < 6; i++)
{
if (!quiet) Console.WriteLine($"Reading: {FilesList[i]}");
if (!quiet)
Console.WriteLine($"Reading: {FilesList[i]}");

sources[i] = Utils.RotateResizeAndFill(new(FilesList[i]),
sourceFormat,
FillColor);
sources[i] = Utils.RotateResizeAndFill(new(FilesList[i]), sourceFormat, FillColor);
}
}

// Split images
if (!quiet) Console.Write("Splitting: ");
if (!quiet)
Console.Write("Splitting: ");

List<MagickImage[]> faces = new();
for (int row = 0; row < Rows; row++)
Expand All @@ -169,7 +174,8 @@ public List<MagickImage> GetResults(bool quiet)

for (int i = 0; i < 6; i++)
{
if (!quiet) Console.Write(".");
if (!quiet)
Console.Write(".");

face[i] = (MagickImage)sources[i].Clone();
face[i].Crop(new MagickGeometry(startX, startY, faceSize, faceSize), Gravity.Northwest);
Expand All @@ -180,18 +186,23 @@ public List<MagickImage> GetResults(bool quiet)
faces.Add(face);
}
}
if (!quiet) Console.WriteLine();
if (!quiet)
Console.WriteLine();

// Clips
BuildClips(20);

// Cubes assembling
if (!quiet) Console.Write("Generating: ");
if (!quiet)
Console.Write("Generating: ");

int cnt = 0;
foreach (MagickImage[] face in faces)
{
if (!quiet) Console.Write("#");
if (!quiet)
Console.Write("#");

cnt++;
MagickImageCollection img2 = new();
img2.Add(TopClipStrip);
img2.Add(AssemblyPartialCube(face, 0));
Expand All @@ -200,11 +211,12 @@ public List<MagickImage> GetResults(bool quiet)

MagickImage image = OutputPaper();
image.Composite(img2.AppendVertically(), Gravity.Center, 0, 0);
AddCuttingLines(image);
AddCuttingLines(image, cnt);
final.Add(image);
}

if (!quiet) Console.WriteLine();
if (!quiet)
Console.WriteLine();
return final;
}

Expand Down Expand Up @@ -256,7 +268,8 @@ private MagickImage AssemblyPartialCube(MagickImage[] face, int start)
/// Creates lines for cut
/// </summary>
/// <param name="img"></param>
public void AddCuttingLines(MagickImage img)
/// <param name="i">Current image number</param>
public void AddCuttingLines(MagickImage img, int i)
{
MagickImage trim = (MagickImage)img.Clone();
trim.Trim();
Expand All @@ -267,32 +280,52 @@ public void AddCuttingLines(MagickImage img)
d.StrokeColor(BorderColor).StrokeWidth(1);
d.Line(0, v_offset, img.Width, v_offset);
d.Line(0, img.Height - v_offset, img.Width, img.Height - v_offset);
d.Line(0, img.Height - v_offset - faceSize, img.Width, img.Height - v_offset - faceSize);
d.Line(h_offset, 0, h_offset, img.Height - v_offset);
d.Line(img.Width - h_offset, 0, img.Width - h_offset, img.Height);
d.Draw(img);

d = new();
d.FontPointSize(fmt.ToPixels(3))
.Font("Arial")
.FillColor(MagickColors.Black)
.Gravity(Gravity.Northwest)
.Text(h_offset + fmt.ToPixels(5), fmt.ToPixels(2), $"{parameters.OutputName} {i} of {Rows * Columns}")
.Draw(img);

d = new();
d.FontPointSize(fmt.ToPixels(2))
.Font("Arial")
.FillColor(MagickColors.Black)
.Gravity(Gravity.Northwest)
.Text(fmt.ToPixels(5), img.Height - v_offset, $"{WelcomeBannerText()}")
.Draw(img);

}

#region clips
private int clipSize;
private MagickImage RightClip;
private MagickImage LeftClip;
private MagickImage BottomClip;
private MagickImage TopClip;
private MagickImage EmptyClip;
private MagickImage TopClipStrip;
private MagickImage BottomClipStrip;
private MagickImage RightClip;
private MagickImage LeftClip;

private void BuildClips(int size)
{
MagickImage BottomClip;
MagickImage TopClip;
MagickImage NoseClip;
MagickImage EmptyClip;

clipSize = fmt.ToPixels(size);
RightClip = new(MagickColors.White, clipSize, faceSize);

Drawables d = new();
d.StrokeColor(BorderColor).StrokeWidth(1);
d.Line(0, 0, clipSize - 1, clipSize / 2);
d.Line(clipSize - 1, clipSize / 2, clipSize - 1, faceSize - clipSize / 2);
d.Line(clipSize - 1, faceSize - clipSize / 2, 0, faceSize);
d.Draw(RightClip);
d.StrokeColor(BorderColor).StrokeWidth(1)
.Line(0, 0, clipSize - 1, clipSize / 2)
.Line(clipSize - 1, clipSize / 2, clipSize - 1, faceSize - clipSize / 2)
.Line(clipSize - 1, faceSize - clipSize / 2, 0, faceSize)
.Draw(RightClip);

LeftClip = (MagickImage)RightClip.Clone();
LeftClip.Rotate(180);
Expand All @@ -304,10 +337,20 @@ private void BuildClips(int size)
EmptyClip = new(MagickColors.White, faceSize, clipSize);
MagickImage ClipFiller = new(MagickColors.White, clipSize, clipSize);

NoseClip = (MagickImage)EmptyClip.Clone();
int noseLeft = faceSize / 2 - clipSize / 2;
int noseRight = faceSize / 2 + clipSize / 2;
d = new();
d.StrokeColor(BorderColor).StrokeWidth(1)
.Line(noseLeft, 0, noseLeft, clipSize - 1)
.Line(noseRight, 0, noseRight, clipSize - 1)
.Line(noseLeft, clipSize - 1, noseRight, clipSize - 1)
.Draw(NoseClip);

MagickImageCollection strip = new();
strip.Add(ClipFiller);
strip.Add(BottomClip);
strip.Add(EmptyClip);
strip.Add(NoseClip);
strip.Add(BottomClip.Clone());
BottomClipStrip = (MagickImage)strip.AppendHorizontally();

Expand All @@ -317,6 +360,7 @@ private void BuildClips(int size)
strip.Add(EmptyClip);
strip.Add(TopClip.Clone());
TopClipStrip = (MagickImage)strip.AppendHorizontally();

}
#endregion

Expand All @@ -343,7 +387,7 @@ private MagickImage[] Samples()
.Font("Arial")
.FillColor(MagickColors.Black)
.Gravity(Gravity.South)
.Text(0, faceSize / 10, $"r={row+1},c={col+1}")
.Text(0, faceSize / 10, $"r={row + 1},c={col + 1}")
.Draw(tile);

ColStrip.Add(tile);
Expand Down
11 changes: 9 additions & 2 deletions Common/Engines/IEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace Casasoft.CCDV.Engines;
/// </summary>
public interface IEngine
{
#region properties
/// <summary>
/// Output resolution
/// </summary>
Expand Down Expand Up @@ -73,7 +74,13 @@ public interface IEngine
/// Class that handles user scripts
/// </summary>
IScripting ScriptingClass { get; set; }
/// <summary>
/// Pointer to the command line (if any)
/// </summary>
ICommandLine CommandLine { get; set; }
#endregion

#region methods
/// <summary>
/// Does the dirty work
/// </summary>
Expand Down Expand Up @@ -120,6 +127,6 @@ public interface IEngine
/// Sets the parameters from json formatted string
/// </summary>
/// <param name="json"></param>
void SetJsonParams(string json);

void SetJsonParams(string json);
#endregion
}
2 changes: 1 addition & 1 deletion Cubetti/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"Cubetti": {
"commandName": "Project",
"commandLineArgs": "--columns=4 --rows=3 --sample C:\\foto\\2022\\dozza\\bicingiro\\eremo_s_alberico.jpg C:\\foto\\2022\\dozza\\bicingiro\\cesenatico.jpg C:\\foto\\2022\\dozza\\bicingiro\\pallanza_v.jpg C:\\foto\\2022\\dozza\\bicingiro\\rimini_v.jpg C:\\foto\\2022\\dozza\\bicingiro\\cesena.jpg C:\\foto\\2022\\dozza\\bicingiro\\casere.jpg"
"commandLineArgs": "--columns=4 --rows=3 C:\\foto\\2022\\dozza\\bicingiro\\eremo_s_alberico.jpg C:\\foto\\2022\\dozza\\bicingiro\\cesenatico.jpg C:\\foto\\2022\\dozza\\bicingiro\\pallanza_v.jpg C:\\foto\\2022\\dozza\\bicingiro\\rimini_v.jpg C:\\foto\\2022\\dozza\\bicingiro\\cesena.jpg C:\\foto\\2022\\dozza\\bicingiro\\casere.jpg"
}
}
}
13 changes: 12 additions & 1 deletion docs/Casasoft.CCDV.Common.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0012636

Please sign in to comment.