Predefined Shapes
New shapes can be created to enable the operator to generate G-code from predefined shapes using specified parameters. To add a new predefined shape, right-click on the Shapes tab in the project tree and click the Add New Shape button. In the dialog that appears, enter the shape's name and press OK. Double-clicking on the created shape will display its contents. The C# language is also used to create shapes. Each shape must contain a Draw function, where the visual representation of the shape should be defined.
public void Draw(string selectedPropertyName)
{
// The shape is created within this function
}
An example shape has been created below:
//------------------------------------------------------------------------------------
// SECTION - 1
// Local variables of the shape to be created
//------------------------------------------------------------------------------------
private float partWidth = 400;
private float partHeight = 400;
private float edgeRadius1 = 40;
private float edgeRadius2 = 40;
private float edgeRadius3 = 40;
private float edgeRadius4 = 40;
private float xStartSpace = 20;
private float xEndSpace = 20;
private float yStartSpace = 20;
private float yEndSpace = 20;
//------------------------------------------------------------------------------------
// SECTION - 2
// Properties of the shape to be created
// Properties added here are automatically displayed in the shape editing form
//------------------------------------------------------------------------------------
[Category("Part Dimension"),
DisplayName("A - Part Width"),
DescriptionAttribute("Width of the part")]
public float PartWidth
{
get
{
return partWidth;
}
set
{
if (value != 0) partWidth = value;
}
}
[Category("Part Dimension"),
DisplayName("B - Part Height"),
DescriptionAttribute("Height of the part")]
public float PartHeight
{
get
{
return partHeight;
}
set
{
if (value != 0) partHeight = value;
}
}
[Category("Spaces"),
DisplayName("A - Horizontal Start Space"),
DescriptionAttribute("Horizontal Start Space of shape")]
public float XStartSpace
{
get
{
return xStartSpace;
}
set
{
if (value > 0) xStartSpace = value;
}
}
[Category("Spaces"),
DisplayName("B - Horizontal End Space"),
DescriptionAttribute("Horizontal End Space of shape")]
public float XEndSpace
{
get
{
return xEndSpace;
}
set
{
if (value > 0) xEndSpace = value;
}
}
[Category("Spaces"),
DisplayName("C - Vertical Start Space"),
DescriptionAttribute("Vertical Start Space of shape")]
public float YStartSpace
{
get
{
return yStartSpace;
}
set
{
if (value > 0) yStartSpace = value;
}
}
[Category("Spaces"),
DisplayName("D - Vertical End Space"),
DescriptionAttribute("Vertical End Space of shape")]
public float YEndSpace
{
get
{
return yEndSpace;
}
set
{
if (value > 0) yEndSpace = value;
}
}
[Category("Shape Dimension"),
DisplayName("A - Edge Radius 1"),
DescriptionAttribute("Edge radius for first edge")]
public float EdgeRadius1
{
get
{
return edgeRadius1;
}
set
{
if (value > 0) edgeRadius1 = value;
}
}
[Category("Shape Dimension"),
DisplayName("B - Edge Radius 2"),
DescriptionAttribute("Edge radius for second edge")]
public float EdgeRadius2
{
get
{
return edgeRadius2;
}
set
{
if (value > 0) edgeRadius2 = value;
}
}
[Category("Shape Dimension"),
DisplayName("C - Edge Radius 3"),
DescriptionAttribute("Edge radius for third edge")]
public float EdgeRadius3
{
get
{
return edgeRadius3;
}
set
{
if (value > 0) edgeRadius3 = value;
}
}
[Category("Shape Dimension"),
DisplayName("D - Edge Radius 4"),
DescriptionAttribute("Edge radius for fourth edge")]
public float EdgeRadius4
{
get
{
return edgeRadius4;
}
set
{
if (value > 0) edgeRadius4 = value;
}
}
//------------------------------------------------------------------------------------
// SECTION - 3
// Drawing of the shape
// When HSC Studio wants to display predefined shapes to the user,it calls this method
//------------------------------------------------------------------------------------
/// <summary>
/// The shape should be drawn within this method
/// <param name="selectedPropertyName"> The property that is clicked
/// (Property) name</param>
/// </summary>
public void Draw(string selectedPropertyName)
{
// ------ Shape
Contour c = new Contour();
doc.Model.Add(c);
Line line1 = new Line(XStartSpace + EdgeRadius1,
YStartSpace,
PartWidth - XEndSpace - EdgeRadius2,
YStartSpace);
Arc arc2 = new Arc(PartWidth - XEndSpace - EdgeRadius2,
YStartSpace + EdgeRadius2,
EdgeRadius2, ToRadian(270.0F),
ToRadian(0.0F));
Line line2 = new Line(PartWidth - XEndSpace,
YStartSpace + EdgeRadius2,
PartWidth - XEndSpace,
PartHeight - YEndSpace - EdgeRadius3);
Arc arc3 = new Arc(PartWidth - XEndSpace - EdgeRadius3,
PartHeight - YEndSpace - EdgeRadius3,
EdgeRadius3,
ToRadian(0.0F),
ToRadian(90.0F));
Line line3 = new Line(PartWidth - XEndSpace - EdgeRadius3,
PartHeight - YEndSpace,
XStartSpace + EdgeRadius4,
PartHeight - YEndSpace);
Arc arc4 = new Arc(XStartSpace + EdgeRadius4,
PartHeight - YEndSpace - EdgeRadius4,
EdgeRadius4,
ToRadian(90.0F),
ToRadian(180.0F));
Line line4 = new Line(XStartSpace,
PartHeight - YEndSpace - EdgeRadius4,
XStartSpace,
YStartSpace + EdgeRadius1);
Arc arc1 = new Arc(XStartSpace + EdgeRadius1,
YStartSpace + EdgeRadius1,
EdgeRadius1,
ToRadian(180.0F),
ToRadian(270.0F));
c.Add(line1);
c.Add(arc2);
c.Add(line2);
c.Add(arc3);
c.Add(line3);
c.Add(arc4);
c.Add(line4);
c.Add(arc1);
// ------ End of shape
// ------ Outer frame
Contour cBorder = new Contour();
doc.Model.Add(cBorder);
Line lineBorder1 = new Line(0, 0, PartWidth, 0);
Line lineBorder2 = new Line(PartWidth, 0, PartWidth, PartHeight);
Line lineBorder3 = new Line(PartWidth, PartHeight, 0, PartHeight);
Line lineBorder4 = new Line(0, PartHeight, 0, 0);
lineBorder1.Label = "Border";
lineBorder2.Label = "Border";
lineBorder3.Label = "Border";
lineBorder4.Label = "Border";
lineBorder1.Style.Color = new Color(0xFFFF0000, false);
lineBorder2.Style.Color = new Color(0xFFFF0000, false);
lineBorder3.Style.Color = new Color(0xFFFF0000, false);
lineBorder4.Style.Color = new Color(0xFFFF0000, false);
cBorder.Add(lineBorder1);
cBorder.Add(lineBorder2);
cBorder.Add(lineBorder3);
cBorder.Add(lineBorder4);
// ----- End of outer frame
// ----- Guideline indicators
if (selectedPropertyName == "A - Part Width")
{
Dimension d = new Dimension(0, -20, PartWidth, -20, 30);
d.String = "Part Width : <>";
c.Add(d);
}
else if (selectedPropertyName == "B - Part Height")
{
Dimension d = new Dimension(-20, 0, -20, PartHeight, 30);
d.String = "Part Height : <>";
c.Add(d);
}
else if (selectedPropertyName == "A - Horizontal Start Space")
{
Dimension d = new Dimension(0, -5, XStartSpace, -5, 30);
d.String = "X StartSpace: <>";
c.Add(d);
}
else if (selectedPropertyName == "B - Horizontal End Space")
{
Dimension d = new Dimension(PartWidth - XEndSpace, -5, PartWidth, -5, 30);
d.String = "X EndSpace: <>";
c.Add(d);
}
else if (selectedPropertyName == "C - Vertical Start Space")
{
Dimension d = new Dimension(-5, 0, -5, YStartSpace, 30);
d.String = "Y StartSpace: <>";
c.Add(d);
}
else if (selectedPropertyName == "D - Vertical End Space")
{
Dimension d = new Dimension(-5, PartHeight - YEndSpace, -5, PartHeight, 30);
d.String = "Y EndSpace: <>";
c.Add(d);
}
else if (selectedPropertyName == "A - Edge Radius 1")
{
Dimension d = new Dimension(XStartSpace, -5,
XStartSpace + EdgeRadius1, -5, 30);
d.String = "Radius 1 : <>";
c.Add(d);
}
else if (selectedPropertyName == "B - Edge Radius 2")
{
Dimension d = new Dimension(PartWidth - XEndSpace - EdgeRadius2,
-5, PartWidth - XEndSpace, -5, 30);
d.String = "Radius 2 : <>";
c.Add(d);
}
else if (selectedPropertyName == "C - Edge Radius 3")
{
Dimension d = new Dimension(PartWidth - XEndSpace - EdgeRadius3,
PartHeight + 5, PartWidth - XEndSpace,
PartHeight + 5, 30);
d.String = "Radius 3 : <>";
c.Add(d);
}
else if (selectedPropertyName == "D - Edge Radius 4")
{
Dimension d = new Dimension(XStartSpace, PartHeight + 5,
XStartSpace + EdgeRadius1,
PartHeight + 5, 30);
d.String = "Radius 4 : <>";
c.Add(d);
}
// ----- End of guideline indicators
}
//------------------------------------------------------------------------------------
// SECTION - 4
// Helper methods/assignments used for drawing the shape
// "It is not mandatory. However, placing the entire code
// within the Draw method could lead to complexity,
// so it has been divided into separate methods
//------------------------------------------------------------------------------------
/// <summary>
/// Converts the given degree value to radians
/// <param name="deg"> The degree value to be converted to radians </param>
/// </summary>
private float ToRadian(float deg)
{
return (deg * (float)Math.PI) / 180.0F;
}
