//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing;
namespace Revit.SDK.Samples.ShaftHolePuncher.CS
{
///
/// Abstract class used as a base class of all drawing tool class
///
public abstract class ITool
{
# region members
protected List m_points = new List(); // Field used to store points of a line
protected Pen m_backGroundPen; // background pen used to Erase the preview line
protected Pen m_foreGroundPen; // foreground pen used to draw lines
protected Point m_preMovePoint; // store the mouse position when mouse move in pictureBox
protected Point m_preDownPoint; // store the mouse position when right mouse button clicked in pictureBox
protected bool m_finished; // indicate whether user have finished drawing
#endregion
///
/// Finished property to define whether curve was finished
///
public virtual bool Finished
{
get
{
return m_finished;
}
set
{
m_finished = value;
}
}
///
/// get all lines drawn in pictureBox
///
public virtual List Points
{
get
{
return m_points;
}
}
///
/// default constructor
///
public ITool()
{
m_backGroundPen = new Pen(System.Drawing.Color.White);
m_backGroundPen.Width *= 2;
m_foreGroundPen = new Pen(System.Drawing.Color.Black);
m_foreGroundPen.Width *= 2;
m_finished = false;
}
///
/// calculate the distance between two points
///
/// first point
/// second point
/// distance between two points
public double GetDistance(Point p1, Point p2)
{
double distance = Math.Sqrt(
(p2.X - p1.X) * (p2.X - p1.X) + (p2.Y - p1.Y) * (p2.Y - p1.Y));
return distance;
}
///
/// clear all the points in the tool
///
public virtual void Clear()
{
m_points.Clear();
}
///
/// draw a line from end point to the location where mouse moved
///
/// Graphics object,used to draw geometry
/// mouse event args
public virtual void OnMouseMove(System.Drawing.Graphics graphic,
System.Windows.Forms.MouseEventArgs e) { }
///
/// record the location point where mouse clicked
///
/// mouse event args
public virtual void OnMouseDown(System.Windows.Forms.MouseEventArgs e) { }
///
/// draw the stored lines
///
/// Graphics object, used to draw geometry
public virtual void Draw(Graphics graphic) { }
}
}