using System;
using System.Collections.Generic;
using Grasshopper.Kernel.Attributes;
using Grasshopper.Kernel;
using Rhino.Geometry;
using CSCECDEC.Okavango.Types;
using CSCECDEC.Okavango.Attribute;
using Rhino;
namespace CSCECDEC.Okavango.Dimension
{
public class TextDotObj : GH_Component
{
///
/// Initializes a new instance of the TextDot class.
///
private TextDot Dot = null;
public TextDotObj()
: base("TextDot", "TextDot",
"创建TextDot",
Setting.PLUGINNAME, Setting.DIMENSIONCATATORY)
{
}
public override void CreateAttributes()
{
if (Properties.Settings.Default.Is_Hu_Attribute) m_attributes = new Hu_Attribute(this);
else m_attributes = new GH_ComponentAttributes(this);
}
///
/// Registers all the input parameters for this component.
///
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddPointParameter("Point", "P", "TextDot的位置", GH_ParamAccess.item,Point3d.Origin);
pManager.AddTextParameter("String", "S", "字符串", GH_ParamAccess.item);
pManager[0].Optional = true;
}
///
/// Registers all the output parameters for this component.
///
protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
{
pManager.AddGenericParameter("TextDot", "T", "TextDot", GH_ParamAccess.item);
}
protected override void BeforeSolveInstance()
{
this.Dot = null;
}
///
/// This is the method that actually does the work.
///
/// The DA object is used to retrieve from inputs and store in outputs.
protected override void SolveInstance(IGH_DataAccess DA)
{
Point3d Location = default(Point3d);
string Text = default(string);
if (!DA.GetData(0, ref Location)) return;
if (!DA.GetData(1, ref Text)) return;
this.Dot = new Rhino.Geometry.TextDot(Text,Location);
DA.SetData(0, Dot);
}
public override void BakeGeometry(RhinoDoc doc, List obj_ids)
{
doc.Objects.AddTextDot(this.Dot);
}
public override void DrawViewportMeshes(IGH_PreviewArgs args)
{
if (this.Dot == null) return;
System.Drawing.Color dotColor = System.Drawing.Color.Red;
if (this.Attributes.Selected) dotColor = System.Drawing.Color.Green;
else dotColor = System.Drawing.Color.Red;
args.Display.DrawDot(this.Dot.Point, this.Dot.Text, dotColor, System.Drawing.Color.White);
}
///
/// Provides an Icon for the component.
///
protected override System.Drawing.Bitmap Icon
{
get
{
//You can add image files to your project resources and access them like this:
// return Resources.IconForThisComponent;
return null;
}
}
///
/// Gets the unique ID for this component. Do not change this ID after release.
///
public override Guid ComponentGuid
{
get { return new Guid("24a24263-416b-48c6-a199-680d50e3ffaa"); }
}
}
}