mirror of
https://github.com/jeremytammik/RevitSdkSamples.git
synced 2026-09-17 01:52:14 +00:00
added Revit 2022 SDK minus except *rvt and *rfa
This commit is contained in:
@@ -0,0 +1,264 @@
|
||||
//
|
||||
// (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.NewOpenings.CS
|
||||
{
|
||||
/// <summary>
|
||||
/// Tool used to draw arc.
|
||||
/// </summary>
|
||||
class ArcTool : ITool
|
||||
{
|
||||
private bool m_isFinished = false;
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
public ArcTool()
|
||||
{
|
||||
m_type = ToolType.Arc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw Arcs
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object</param>
|
||||
public override void Draw(System.Drawing.Graphics graphic)
|
||||
{
|
||||
foreach (List<Point> line in m_lines)
|
||||
{
|
||||
int count = line.Count;
|
||||
if (count == 3)
|
||||
{
|
||||
DrawArc(graphic, m_foreGroundPen, line[0], line[1], line[3]);
|
||||
}
|
||||
else if (count > 3)
|
||||
{
|
||||
DrawArc(graphic, m_foreGroundPen, line[0], line[1], line[2]);
|
||||
for (int i = 1; i < count - 3; i += 2)
|
||||
{
|
||||
DrawArc(graphic, m_foreGroundPen, line[i], line[i + 2], line[i + 3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mouse down event handler
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to draw geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public override void OnMouseDown(Graphics graphic, MouseEventArgs e)
|
||||
{
|
||||
if (MouseButtons.Left == e.Button)
|
||||
{
|
||||
m_points.Add(e.Location);
|
||||
m_preMovePoint = e.Location;
|
||||
|
||||
if (m_points.Count >= 4 && m_points.Count % 2 == 0)
|
||||
{
|
||||
graphic.DrawLine(m_backGroundPen,
|
||||
m_points[m_points.Count - 3], m_preMovePoint);
|
||||
}
|
||||
Draw(graphic);
|
||||
|
||||
if (m_isFinished)
|
||||
{
|
||||
m_isFinished = false;
|
||||
List<Point> line = new List<Point>(m_points);
|
||||
m_lines.Add(line);
|
||||
m_points.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mouse move event handler
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to draw geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public override void OnMouseMove(Graphics graphic, MouseEventArgs e)
|
||||
{
|
||||
if (2 == m_points.Count)
|
||||
{
|
||||
DrawArc(graphic, m_backGroundPen, m_points[0], m_points[1], m_preMovePoint);
|
||||
m_preMovePoint = e.Location;
|
||||
DrawArc(graphic, m_foreGroundPen, m_points[0], m_points[1], e.Location);
|
||||
|
||||
}
|
||||
else if (m_points.Count > 2 && m_points.Count % 2 == 0)
|
||||
{
|
||||
DrawArc(graphic, m_backGroundPen, m_points[m_points.Count - 3],
|
||||
m_points[m_points.Count - 1], m_preMovePoint);
|
||||
m_preMovePoint = e.Location;
|
||||
DrawArc(graphic, m_foreGroundPen, m_points[m_points.Count - 3],
|
||||
m_points[m_points.Count - 1], e.Location);
|
||||
}
|
||||
else if (!m_isFinished && m_points.Count > 2 && m_points.Count % 2 == 1)
|
||||
{
|
||||
graphic.DrawLine(m_backGroundPen, m_points[m_points.Count - 2], m_preMovePoint);
|
||||
m_preMovePoint = e.Location;
|
||||
graphic.DrawLine(m_foreGroundPen, m_points[m_points.Count - 2], e.Location);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mouse right key click
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to draw geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public override void OnRightMouseClick(Graphics graphic, MouseEventArgs e)
|
||||
{
|
||||
if (!m_isFinished && e.Button == MouseButtons.Right && m_points.Count > 0)
|
||||
{
|
||||
m_isFinished = true;
|
||||
m_points.Add(m_points[0]);
|
||||
graphic.DrawLine(m_backGroundPen, m_points[m_points.Count - 3], e.Location);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mouse middle key down event handler
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to draw geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public override void OnMidMouseDown(Graphics graphic, MouseEventArgs e)
|
||||
{
|
||||
base.OnMidMouseDown(graphic, e);
|
||||
if (m_isFinished)
|
||||
{
|
||||
m_isFinished = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the arc center
|
||||
/// </summary>
|
||||
/// <param name="p1">Point on arc</param>
|
||||
/// <param name="p2">Point on arc</param>
|
||||
/// <param name="p3">Point on arc</param>
|
||||
/// <returns></returns>
|
||||
private PointF ComputeCenter(PointF p1, PointF p2, PointF p3)
|
||||
{
|
||||
float deta = 4 * (p2.X - p1.X) * (p3.Y - p1.Y) - 4 * (p2.Y - p1.Y) * (p3.X - p1.X);
|
||||
|
||||
if (deta == 0)
|
||||
{
|
||||
throw new Exception("Divided by Zero!");
|
||||
}
|
||||
float constD1 = p2.X * p2.X + p2.Y * p2.Y - (p1.X * p1.X + p1.Y * p1.Y);
|
||||
float constD2 = p3.X * p3.X + p3.Y * p3.Y - (p1.X * p1.X + p1.Y * p1.Y);
|
||||
|
||||
float centerX = (constD1 * 2 * (p3.Y - p1.Y) - constD2 * 2 * (p2.Y - p1.Y)) / deta;
|
||||
float centerY = (constD2 * 2 * (p2.X - p1.X) - constD1 * 2 * (p3.X - p1.X)) / deta;
|
||||
|
||||
return new PointF(centerX, centerY);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw arc
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to draw geometry</param>
|
||||
/// <param name="pen">Used to set drawing color</param>
|
||||
/// <param name="p1">Point on arc</param>
|
||||
/// <param name="p2">Point on arc</param>
|
||||
/// <param name="p3">Point on arc</param>
|
||||
private void DrawArc(Graphics graphic, Pen pen, PointF p1, PointF p2, PointF p3)
|
||||
{
|
||||
try
|
||||
{
|
||||
PointF pCenter = ComputeCenter(p1, p2, p3);
|
||||
|
||||
//computer the arc rectangle
|
||||
float radius = (float)Math.Sqrt((p1.X - pCenter.X) * (p1.X - pCenter.X)
|
||||
+ (p1.Y - pCenter.Y) * (p1.Y - pCenter.Y));
|
||||
SizeF size = new SizeF(radius, radius);
|
||||
PointF upLeft = pCenter - size;
|
||||
SizeF sizeRect = new SizeF(2 * radius, 2 * radius);
|
||||
RectangleF rectF = new RectangleF(upLeft, sizeRect);
|
||||
|
||||
double startCos = (p1.X - pCenter.X) / radius;
|
||||
double startSin = (p1.Y - pCenter.Y) / radius;
|
||||
|
||||
double endCos = (p2.X - pCenter.X) / radius;
|
||||
double endSin = (p2.Y - pCenter.Y) / radius;
|
||||
|
||||
double midCos = (p3.X - pCenter.X) / radius;
|
||||
double midSin = (p3.Y - pCenter.Y) / radius;
|
||||
|
||||
double startAngle = 0, endAngle = 0, midAngle = 0;
|
||||
|
||||
//computer the angle between [0, 360]
|
||||
startAngle = GetAngle(startSin, startCos);
|
||||
endAngle = GetAngle(endSin, endCos);
|
||||
midAngle = GetAngle(midSin, midCos);
|
||||
|
||||
//get the min angle and sweep angle
|
||||
double minAngle = Math.Min(startAngle, endAngle);
|
||||
double maxAngle = Math.Max(startAngle, endAngle);
|
||||
double sweepAngle = Math.Abs(endAngle - startAngle);
|
||||
if (midAngle < minAngle || midAngle > maxAngle)
|
||||
{
|
||||
minAngle = maxAngle;
|
||||
sweepAngle = 360 - sweepAngle;
|
||||
}
|
||||
graphic.DrawArc(pen, rectF, (float)minAngle, (float)sweepAngle);
|
||||
}
|
||||
//catch divided by zero exception
|
||||
catch (Exception)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get angle between [0,360]
|
||||
/// </summary>
|
||||
/// <param name="sin">Sin(Angle) value</param>
|
||||
/// <param name="cos">Cos(Angle) value</param>
|
||||
/// <returns></returns>
|
||||
private double GetAngle(double sin, double cos)
|
||||
{
|
||||
double result = 0;
|
||||
if (sin > 0)
|
||||
{
|
||||
result = (180 / Math.PI) * Math.Acos(cos);
|
||||
}
|
||||
else if (cos < 0)
|
||||
{
|
||||
result = 180 + (180 / Math.PI) * Math.Acos(Math.Abs(cos));
|
||||
}
|
||||
else if (cos > 0)
|
||||
{
|
||||
result = 360 - (180 / Math.PI) * Math.Acos(Math.Abs(cos));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
//
|
||||
// (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.NewOpenings.CS
|
||||
{
|
||||
/// <summary>
|
||||
/// Tool used to draw circle
|
||||
/// </summary>
|
||||
class CircleTool:ITool
|
||||
{
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
public CircleTool()
|
||||
{
|
||||
m_type = ToolType.Circle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw circles contained in the tool
|
||||
/// </summary>
|
||||
/// <param name="graphic"></param>
|
||||
public override void Draw(Graphics graphic)
|
||||
{
|
||||
foreach (List<Point> line in m_lines)
|
||||
{
|
||||
DrawCircle(graphic, m_foreGroundPen, line[0], line[1]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mouse down event handler
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to draw geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public override void OnMouseDown(Graphics graphic, MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseDown(graphic, e);
|
||||
if (MouseButtons.Left == e.Button)
|
||||
{
|
||||
m_preMovePoint = e.Location;
|
||||
m_points.Add(e.Location);
|
||||
|
||||
if (2 == m_points.Count)
|
||||
{
|
||||
DrawCircle(graphic, m_foreGroundPen, m_points[0], m_points[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mouse move event handler
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to draw geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public override void OnMouseMove(Graphics graphic, MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(graphic, e);
|
||||
|
||||
if (1 == m_points.Count)
|
||||
{
|
||||
DrawCircle(graphic, m_backGroundPen, m_points[0], m_preMovePoint);
|
||||
m_preMovePoint = e.Location;
|
||||
DrawCircle(graphic, m_foreGroundPen, m_points[0], e.Location);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mouse up event handler
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to draw geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public override void OnMouseUp(Graphics graphic, MouseEventArgs e)
|
||||
{
|
||||
base.OnMouseUp(graphic, e);
|
||||
|
||||
if (2 == m_points.Count)
|
||||
{
|
||||
List<Point> line = new List<Point>(m_points);
|
||||
m_lines.Add(line);
|
||||
m_points.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw circle with center and one point on circle
|
||||
/// </summary>
|
||||
/// <param name="graphics">Graphics object, used to draw geometry</param>
|
||||
/// <param name="pen">Pen used to set drawing color</param>
|
||||
/// <param name="pCenter">Circle center</param>
|
||||
/// <param name="pBound">One point on circle</param>
|
||||
private void DrawCircle(Graphics graphics,Pen pen, Point pCenter, Point pBound)
|
||||
{
|
||||
int radius = (int)Math.Sqrt((pBound.X - pCenter.X) * (pBound.X - pCenter.X)
|
||||
+ (pBound.Y - pCenter.Y) * (pBound.Y - pCenter.Y));
|
||||
Size radiusSize = new Size(radius, radius);
|
||||
Point uperLeft = pCenter - radiusSize;
|
||||
graphics.DrawEllipse(pen, uperLeft.X, uperLeft.Y, 2 * radius, 2 * radius);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// (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;
|
||||
|
||||
namespace Revit.SDK.Samples.NewOpenings.CS
|
||||
{
|
||||
/// <summary>
|
||||
/// Tool used to draw nothing
|
||||
/// </summary>
|
||||
class EmptyTool : ITool
|
||||
{
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
public EmptyTool()
|
||||
{
|
||||
m_type = ToolType.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw nothing
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object</param>
|
||||
public override void Draw(System.Drawing.Graphics graphic)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
//
|
||||
// (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.NewOpenings.CS
|
||||
{
|
||||
/// <summary>
|
||||
/// Stand for the draw tool type
|
||||
/// </summary>
|
||||
public enum ToolType
|
||||
{
|
||||
/// <summary>
|
||||
/// Draw nothing
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// Draw polygon
|
||||
/// </summary>
|
||||
Line,
|
||||
|
||||
/// <summary>
|
||||
/// Draw rectangle
|
||||
/// </summary>
|
||||
Rectangle,
|
||||
|
||||
/// <summary>
|
||||
/// Draw circle
|
||||
/// </summary>
|
||||
Circle,
|
||||
|
||||
/// <summary>
|
||||
/// Draw arc
|
||||
/// </summary>
|
||||
Arc
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Abstract class use as base class of all draw tool class
|
||||
/// </summary>
|
||||
public abstract class ITool
|
||||
{
|
||||
# region members
|
||||
/// <summary>
|
||||
/// ToolType is enum type indicate draw tools.
|
||||
/// </summary>
|
||||
protected ToolType m_type;
|
||||
|
||||
/// <summary>
|
||||
/// Field used to store points of a line
|
||||
/// </summary>
|
||||
protected List<Point> m_points = new List<Point>();
|
||||
|
||||
/// <summary>
|
||||
/// Field used to store lines
|
||||
/// </summary>
|
||||
protected List<List<Point>> m_lines = new List<List<Point>>();
|
||||
|
||||
/// <summary>
|
||||
/// Background pen used to erase the preview line
|
||||
/// </summary>
|
||||
protected Pen m_backGroundPen;
|
||||
|
||||
/// <summary>
|
||||
/// Foreground pen used to draw lines
|
||||
/// </summary>
|
||||
protected Pen m_foreGroundPen;
|
||||
|
||||
/// <summary>
|
||||
/// Store the mouse position when mouse move in pictureBox
|
||||
/// </summary>
|
||||
protected Point m_preMovePoint;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
public ITool()
|
||||
{
|
||||
m_backGroundPen = Pens.White;
|
||||
m_foreGroundPen = Pens.Red;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all lines drawn in pictureBox
|
||||
/// </summary>
|
||||
public List<List<Point>> GetLines()
|
||||
{
|
||||
return m_lines;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the tool type
|
||||
/// </summary>
|
||||
public virtual ToolType ToolType
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Right mouse click event handler
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to draw geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public virtual void OnRightMouseClick(Graphics graphic, MouseEventArgs e) { }
|
||||
|
||||
/// <summary>
|
||||
/// Mouse move event handler
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to draw geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public virtual void OnMouseMove(Graphics graphic, MouseEventArgs e) { }
|
||||
|
||||
/// <summary>
|
||||
/// Mouse down event handler
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to draw geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public virtual void OnMouseDown(Graphics graphic, MouseEventArgs e) { }
|
||||
|
||||
/// <summary>
|
||||
/// Mouse up event handler
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to draw geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public virtual void OnMouseUp(Graphics graphic, MouseEventArgs e) { }
|
||||
|
||||
/// <summary>
|
||||
/// Mouse middle key down event handler
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to draw geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public virtual void OnMidMouseDown(Graphics graphic, MouseEventArgs e)
|
||||
{
|
||||
this.m_points.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw geometries contained in the tool. which class derived from this class
|
||||
/// must implement this abstract method
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to draw geometry</param>
|
||||
public abstract void Draw(Graphics graphic);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
//
|
||||
// (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.NewOpenings.CS
|
||||
{
|
||||
/// <summary>
|
||||
/// Tool used to draw line
|
||||
/// </summary>
|
||||
public class LineTool:ITool
|
||||
{
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
public LineTool()
|
||||
{
|
||||
m_type = ToolType.Line;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mouse move event handle
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to draw geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public override void OnMouseMove(System.Drawing.Graphics graphic, MouseEventArgs e)
|
||||
{
|
||||
if(m_points.Count != 0)
|
||||
{
|
||||
graphic.DrawLine(m_backGroundPen, m_points[m_points.Count - 1], m_preMovePoint);
|
||||
m_preMovePoint = e.Location;
|
||||
graphic.DrawLine(m_foreGroundPen, m_points[m_points.Count - 1], e.Location);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mouse down event handler
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to draw geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public override void OnMouseDown(System.Drawing.Graphics graphic, MouseEventArgs e)
|
||||
{
|
||||
if(e.Button == MouseButtons.Left)
|
||||
{
|
||||
m_preMovePoint = e.Location;
|
||||
m_points.Add(e.Location);
|
||||
|
||||
if (m_points.Count >= 2)
|
||||
{
|
||||
graphic.DrawLine(m_foreGroundPen, m_points[m_points.Count - 2],
|
||||
m_points[m_points.Count - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Right mouse click handler
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to drawing geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public override void OnRightMouseClick(Graphics graphic, MouseEventArgs e)
|
||||
{
|
||||
if(MouseButtons.Right == e.Button && m_points.Count > 2)
|
||||
{
|
||||
List<Point> line = new List<Point>(m_points);
|
||||
m_lines.Add(line);
|
||||
|
||||
graphic.DrawLine(m_foreGroundPen, m_points[m_points.Count - 1], m_points[0]);
|
||||
graphic.DrawLine(m_backGroundPen, m_points[m_points.Count - 1], m_preMovePoint);
|
||||
m_points.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw lines
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object, used to draw geometry</param>
|
||||
public override void Draw(Graphics graphic)
|
||||
{
|
||||
foreach(List<Point> line in m_lines)
|
||||
{
|
||||
for (int i = 0; i < line.Count - 1;i++ )
|
||||
{
|
||||
graphic.DrawLine(m_foreGroundPen, line[i], line[i + 1]);
|
||||
}
|
||||
//close the line
|
||||
graphic.DrawLine(m_foreGroundPen, line[line.Count - 1], line[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,485 @@
|
||||
//
|
||||
// (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 Autodesk.Revit.DB;
|
||||
|
||||
|
||||
namespace Revit.SDK.Samples.NewOpenings.CS
|
||||
{
|
||||
/// <summary>
|
||||
/// Vector4 class use to store vector
|
||||
/// and contain method to handle the vector
|
||||
/// </summary>
|
||||
public class Vector4
|
||||
{
|
||||
#region Member and propertys
|
||||
/// <summary>
|
||||
/// The coordinate x value
|
||||
/// </summary>
|
||||
private float m_x;
|
||||
|
||||
/// <summary>
|
||||
/// The coordinate y value
|
||||
/// </summary>
|
||||
private float m_y;
|
||||
|
||||
/// <summary>
|
||||
/// The coordinate z value
|
||||
/// </summary>
|
||||
private float m_z;
|
||||
|
||||
/// <summary>
|
||||
/// The coordinate w value
|
||||
/// </summary>
|
||||
private float m_w = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// The coordinate x value
|
||||
/// </summary>
|
||||
public float X
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_x;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_x = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///The coordinate y value
|
||||
/// </summary>
|
||||
public float Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_y;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_y = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The coordinate z value
|
||||
/// </summary>
|
||||
public float Z
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_z;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_z = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The coordinate w value
|
||||
/// </summary>
|
||||
public float W
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_w;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_w = value;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public Vector4(float x, float y, float z)
|
||||
{
|
||||
this.X = x; this.Y = y; this.Z = z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy constructor
|
||||
/// </summary>
|
||||
public Vector4( Vector4 v)
|
||||
{
|
||||
this.X = v.X; this.Y = v.Y; this.Z = v.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor, transform Autodesk.Revit.DB.XYZ to vector
|
||||
/// </summary>
|
||||
public Vector4(Autodesk.Revit.DB.XYZ v)
|
||||
{
|
||||
this.X = (float)v.X; this.Y = (float)v.Y; this.Z = (float)v.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add two vector
|
||||
/// </summary>
|
||||
/// <param name="va">First vector</param>
|
||||
/// <param name="vb">Second vector</param>
|
||||
public static Vector4 operator+ (Vector4 va, Vector4 vb)
|
||||
{
|
||||
return new Vector4(va.X + vb.X, va.Y + vb.Y, va.Z + vb.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtraction of two vector
|
||||
/// </summary>
|
||||
/// <param name="va">First vector</param>
|
||||
/// <param name="vb">Second vector</param>
|
||||
/// <returns>Subtraction of two vector</returns>
|
||||
public static Vector4 operator- (Vector4 va, Vector4 vb)
|
||||
{
|
||||
return new Vector4(va.X - vb.X, va.Y - vb.Y, va.Z - vb.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get vector multiply by an double value
|
||||
/// </summary>
|
||||
/// <param name="v">Vector</param>
|
||||
/// <param name="factor">Double value</param>
|
||||
/// <returns> Vector multiply by an double value</returns>
|
||||
public static Vector4 operator* (Vector4 v,float factor)
|
||||
{
|
||||
return new Vector4(v.X * factor, v.Y * factor, v.Z * factor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get vector divided by an double value
|
||||
/// </summary>
|
||||
/// <param name="v">vector</param>
|
||||
/// <param name="factor">double value</param>
|
||||
/// <returns> vector divided by an double value</returns>
|
||||
public static Vector4 operator /(Vector4 v, float factor)
|
||||
{
|
||||
return new Vector4(v.X / factor, v.Y / factor, v.Z / factor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// dot multiply vector
|
||||
/// </summary>
|
||||
/// <param name="v">vector</param>
|
||||
public float DotProduct(Vector4 v)
|
||||
{
|
||||
return (this.X * v.X + this.Y * v.Y + this.Z * v.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get normal vector of two vector
|
||||
/// </summary>
|
||||
/// <param name="v">second vector</param>
|
||||
/// <returns> normal vector of two vector</returns>
|
||||
public Vector4 CrossProduct(Vector4 v)
|
||||
{
|
||||
return new Vector4(this.Y * v.Z - this.Z * v.Y,this.Z * v.X
|
||||
- this.X * v.Z,this.X * v.Y - this.Y * v.X);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dot multiply two vector
|
||||
/// </summary>
|
||||
/// <param name="va">First vector</param>
|
||||
/// <param name="vb">Second vector</param>
|
||||
public static float DotProduct(Vector4 va, Vector4 vb)
|
||||
{
|
||||
return (va.X * vb.X + va.Y * vb.Y + va.Z * vb.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get normal vector of two vector
|
||||
/// </summary>
|
||||
/// <param name="va">First vector</param>
|
||||
/// <param name="vb">Second vector</param>
|
||||
/// <returns> Normal vector of two vector</returns>
|
||||
public static Vector4 CrossProduct(Vector4 va, Vector4 vb)
|
||||
{
|
||||
return new Vector4(va.Y * vb.Z - va.Z * vb.Y, va.Z * vb.X
|
||||
- va.X * vb.Z, va.X * vb.Y - va.Y * vb.X);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get unit vector
|
||||
/// </summary>
|
||||
public void Normalize()
|
||||
{
|
||||
float length = Length();
|
||||
if(length == 0)
|
||||
{
|
||||
length = 1;
|
||||
}
|
||||
this.X /= length;
|
||||
this.Y /= length;
|
||||
this.Z /= length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the length of vector
|
||||
/// </summary>
|
||||
public float Length()
|
||||
{
|
||||
return (float)Math.Sqrt(this.X * this.X + this.Y * this.Y + this.Z * this.Z);
|
||||
}
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Matrix used to transform between UCS coordinate and world coordinate.
|
||||
/// </summary>
|
||||
public class Matrix4
|
||||
{
|
||||
#region MatrixType
|
||||
/// <summary>
|
||||
/// matrix algorithm
|
||||
/// </summary>
|
||||
public enum MatrixType
|
||||
{
|
||||
/// <summary>
|
||||
/// rotation matrix
|
||||
/// </summary>
|
||||
Rotation,
|
||||
|
||||
/// <summary>
|
||||
/// translation matrix
|
||||
/// </summary>
|
||||
TransLation,
|
||||
|
||||
/// <summary>
|
||||
/// scale matrix
|
||||
/// </summary>
|
||||
Scale,
|
||||
|
||||
/// <summary>
|
||||
/// rotation and translation mix matrix
|
||||
/// </summary>
|
||||
RotationAndTransLation,
|
||||
|
||||
/// <summary>
|
||||
/// identity matrix
|
||||
/// </summary>
|
||||
Normal
|
||||
};
|
||||
private float[,] m_matrix = new float[4,4];
|
||||
private MatrixType m_type;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Construct a identity matrix
|
||||
/// </summary>
|
||||
public Matrix4()
|
||||
{
|
||||
m_type = MatrixType.Normal;
|
||||
Identity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Construct a rotation matrix,origin at (0,0,0)
|
||||
/// </summary>
|
||||
/// <param name="xAxis">identity of x axis</param>
|
||||
/// <param name="yAxis">identity of y axis</param>
|
||||
/// <param name="zAxis">identity of z axis</param>
|
||||
public Matrix4(Vector4 xAxis,Vector4 yAxis, Vector4 zAxis)
|
||||
{
|
||||
m_type = MatrixType.Rotation;
|
||||
Identity();
|
||||
m_matrix[0, 0] = xAxis.X; m_matrix[0, 1] = xAxis.Y; m_matrix[0, 2] = xAxis.Z;
|
||||
m_matrix[1, 0] = yAxis.X; m_matrix[1, 1] = yAxis.Y; m_matrix[1, 2] = yAxis.Z;
|
||||
m_matrix[2, 0] = zAxis.X; m_matrix[2, 1] = zAxis.Y; m_matrix[2, 2] = zAxis.Z;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ctor,translation matrix.
|
||||
/// </summary>
|
||||
/// <param name="origin">origin of UCS in world coordinate</param>
|
||||
public Matrix4(Vector4 origin)
|
||||
{
|
||||
m_type = MatrixType.TransLation;
|
||||
Identity();
|
||||
m_matrix[3, 0] = origin.X; m_matrix[3, 1] = origin.Y; m_matrix[3, 2] = origin.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// rotation and translation matrix constructor
|
||||
/// </summary>
|
||||
/// <param name="xAxis">x Axis</param>
|
||||
/// <param name="yAxis">y Axis</param>
|
||||
/// <param name="zAxis">z Axis</param>
|
||||
/// <param name="origin">origin</param>
|
||||
public Matrix4(Vector4 xAxis, Vector4 yAxis, Vector4 zAxis, Vector4 origin)
|
||||
{
|
||||
m_type = MatrixType.RotationAndTransLation;
|
||||
Identity();
|
||||
m_matrix[0, 0] = xAxis.X; m_matrix[0, 1] = xAxis.Y; m_matrix[0, 2] = xAxis.Z;
|
||||
m_matrix[1, 0] = yAxis.X; m_matrix[1, 1] = yAxis.Y; m_matrix[1, 2] = yAxis.Z;
|
||||
m_matrix[2, 0] = zAxis.X; m_matrix[2, 1] = zAxis.Y; m_matrix[2, 2] = zAxis.Z;
|
||||
m_matrix[3, 0] = origin.X; m_matrix[3, 1] = origin.Y; m_matrix[3, 2] = origin.Z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// scale matrix constructor
|
||||
/// </summary>
|
||||
/// <param name="scale">scale factor</param>
|
||||
public Matrix4(float scale)
|
||||
{
|
||||
m_type = MatrixType.Scale;
|
||||
Identity();
|
||||
m_matrix[0, 0] = m_matrix[1, 1] = m_matrix[2, 2] = scale;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// indexer of matrix
|
||||
/// </summary>
|
||||
/// <param name="row">row number</param>
|
||||
/// <param name="column">column number</param>
|
||||
/// <returns></returns>
|
||||
public float this[int row,int column]
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.m_matrix[row, column];
|
||||
}
|
||||
set
|
||||
{
|
||||
this.m_matrix[row, column] = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Identity matrix
|
||||
/// </summary>
|
||||
public void Identity()
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
this.m_matrix[i, j] = 0.0f;
|
||||
}
|
||||
}
|
||||
this.m_matrix[0, 0] = 1.0f;
|
||||
this.m_matrix[1, 1] = 1.0f;
|
||||
this.m_matrix[2, 2] = 1.0f;
|
||||
this.m_matrix[3, 3] = 1.0f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiply matrix left and right
|
||||
/// </summary>
|
||||
/// <param name="left">Left matrix</param>
|
||||
/// <param name="right">Right matrix</param>
|
||||
/// <returns></returns>
|
||||
public static Matrix4 Multiply(Matrix4 left, Matrix4 right)
|
||||
{
|
||||
Matrix4 result = new Matrix4();
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
result[i, j] = left[i, 0] * right[0, j] + left[i, 1] * right[1, j]
|
||||
+ left[i, 2] * right[2, j] + left[i, 3] * right[3, j];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transform point use this matrix
|
||||
/// </summary>
|
||||
/// <param name="point">Point needed to be transformed</param>
|
||||
/// <returns>Transform result</returns>
|
||||
public Vector4 TransForm(Vector4 point)
|
||||
{
|
||||
return new Vector4(point.X * this[0, 0] + point.Y * this[1, 0]
|
||||
+ point.Z * this[2, 0]+ point.W * this[3, 0],
|
||||
point.X * this[0, 1] + point.Y * this[1, 1]
|
||||
+ point.Z * this[2, 1]+ point.W * this[3, 1],
|
||||
point.X * this[0, 2] + point.Y * this[1, 2]
|
||||
+ point.Z * this[2, 2]+ point.W * this[3, 2]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If it is a rotation matrix,this method can get the rotation inverse matrix.
|
||||
/// </summary>
|
||||
/// <returns>rotation inverse matrix</returns>
|
||||
public Matrix4 RotationInverse()
|
||||
{
|
||||
return new Matrix4(new Vector4(this[0, 0], this[1, 0], this[2, 0]),
|
||||
new Vector4(this[0, 1], this[1, 1], this[2, 1]),
|
||||
new Vector4(this[0, 2], this[1, 2], this[2, 2]));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If it is a translation matrix,
|
||||
/// this method can get the translation inverse matrix.
|
||||
/// </summary>
|
||||
/// <returns>translation inverse matrix</returns>
|
||||
public Matrix4 TransLationInverse()
|
||||
{
|
||||
return new Matrix4(new Vector4(-this[3, 0], -this[3, 1], -this[3, 2]));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get inverse matrix
|
||||
/// </summary>
|
||||
/// <returns>Inverse matrix</returns>
|
||||
public Matrix4 Inverse()
|
||||
{
|
||||
switch(m_type)
|
||||
{
|
||||
case MatrixType.Rotation:
|
||||
return RotationInverse();
|
||||
|
||||
case MatrixType.TransLation:
|
||||
return TransLationInverse();
|
||||
|
||||
case MatrixType.RotationAndTransLation:
|
||||
return Multiply(TransLationInverse(),RotationInverse());
|
||||
|
||||
case MatrixType.Scale:
|
||||
return ScaleInverse();
|
||||
|
||||
case MatrixType.Normal:
|
||||
return new Matrix4();
|
||||
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If it is a scale matrix,this method can get the scale inverse matrix.
|
||||
/// </summary>
|
||||
/// <returns>Scale inverse matrix</returns>
|
||||
public Matrix4 ScaleInverse()
|
||||
{
|
||||
return new Matrix4(1 / m_matrix[0,0]);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RevitAddIns>
|
||||
<AddIn Type="Command">
|
||||
<Assembly>NewOpenings.dll</Assembly>
|
||||
<ClientId>a574ee1a-991e-418b-8b4c-25e8a1ed9394</ClientId>
|
||||
<FullClassName>Revit.SDK.Samples.NewOpenings.CS.Command</FullClassName>
|
||||
<Text>New Openings</Text>
|
||||
<Description>Create openings on the selected floor or wall.</Description>
|
||||
<VisibilityMode>AlwaysVisible</VisibilityMode>
|
||||
<VendorId>ADSK</VendorId>
|
||||
<VendorDescription>Autodesk, www.autodesk.com</VendorDescription>
|
||||
</AddIn>
|
||||
</RevitAddIns>
|
||||
@@ -0,0 +1,107 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{379E2FAA-67A6-4360-BEE6-37496B7BB89A}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Revit.SDK.Samples.NewOpenings.CS</RootNamespace>
|
||||
<AssemblyName>NewOpenings</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ArcTool.cs" />
|
||||
<Compile Include="EmptyTool.cs" />
|
||||
<Compile Include="NewOpeningsForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="NewOpeningsForm.Designer.cs">
|
||||
<DependentUpon>NewOpeningsForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="CircleTool.cs" />
|
||||
<Compile Include="Command.cs" />
|
||||
<Compile Include="LineTool.cs" />
|
||||
<Compile Include="MathTools.cs" />
|
||||
<Compile Include="Profile.cs" />
|
||||
<Compile Include="ProfileFloor.cs" />
|
||||
<Compile Include="ProfileWall.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ITool.cs" />
|
||||
<Compile Include="RectTool.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="NewOpeningsForm.resx">
|
||||
<SubType>Designer</SubType>
|
||||
<DependentUpon>NewOpeningsForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(SolutionDir)VSProps\SDKSamples.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>set FILEFORSAMPLEREG="$(SolutionDir)..\..\..\..\Regression\API\SDKSamples\UpdateSampleDllForRegression.pl"
|
||||
if exist %25FILEFORSAMPLEREG%25 perl %25FILEFORSAMPLEREG%25 $(ProjectExt) "$(ProjectPath)" "$(TargetPath)" "$(SolutionDir)"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
//
|
||||
// (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.
|
||||
//
|
||||
|
||||
|
||||
namespace Revit.SDK.Samples.NewOpenings.CS
|
||||
{
|
||||
partial class NewOpeningsForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed;
|
||||
/// otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.OkButton = new System.Windows.Forms.Button();
|
||||
this.openingPictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.cancelButton = new System.Windows.Forms.Button();
|
||||
this.Notelabel = new System.Windows.Forms.Label();
|
||||
this.Notelabel2 = new System.Windows.Forms.Label();
|
||||
((System.ComponentModel.ISupportInitialize)(this.openingPictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// OkButton
|
||||
//
|
||||
this.OkButton.Location = new System.Drawing.Point(221, 439);
|
||||
this.OkButton.Name = "OkButton";
|
||||
this.OkButton.Size = new System.Drawing.Size(80, 26);
|
||||
this.OkButton.TabIndex = 0;
|
||||
this.OkButton.Text = "&OK";
|
||||
this.OkButton.UseVisualStyleBackColor = true;
|
||||
this.OkButton.Click += new System.EventHandler(this.OkButton_Click);
|
||||
//
|
||||
// openingPictureBox
|
||||
//
|
||||
this.openingPictureBox.BackColor = System.Drawing.SystemColors.Window;
|
||||
this.openingPictureBox.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.openingPictureBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.openingPictureBox.Name = "openingPictureBox";
|
||||
this.openingPictureBox.Size = new System.Drawing.Size(415, 381);
|
||||
this.openingPictureBox.TabIndex = 1;
|
||||
this.openingPictureBox.TabStop = false;
|
||||
this.openingPictureBox.MouseDown += new System.Windows.Forms.MouseEventHandler(this.openingPictureBox_MouseDown);
|
||||
this.openingPictureBox.MouseMove += new System.Windows.Forms.MouseEventHandler(this.openingPictureBox_MouseMove);
|
||||
this.openingPictureBox.Paint += new System.Windows.Forms.PaintEventHandler(this.openingPictureBox_Paint);
|
||||
this.openingPictureBox.MouseUp += new System.Windows.Forms.MouseEventHandler(this.openingPictureBox_MouseUp);
|
||||
//
|
||||
// cancelButton
|
||||
//
|
||||
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
||||
this.cancelButton.Location = new System.Drawing.Point(316, 439);
|
||||
this.cancelButton.Name = "cancelButton";
|
||||
this.cancelButton.Size = new System.Drawing.Size(80, 26);
|
||||
this.cancelButton.TabIndex = 1;
|
||||
this.cancelButton.Text = "&Cancel";
|
||||
this.cancelButton.UseVisualStyleBackColor = true;
|
||||
this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
|
||||
//
|
||||
// Notelabel
|
||||
//
|
||||
this.Notelabel.AutoSize = true;
|
||||
this.Notelabel.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.Notelabel.Location = new System.Drawing.Point(-3, 393);
|
||||
this.Notelabel.Name = "Notelabel";
|
||||
this.Notelabel.Size = new System.Drawing.Size(415, 13);
|
||||
this.Notelabel.TabIndex = 2;
|
||||
this.Notelabel.Text = " Use middle button of mouse to switch tool to draw Opening in Preview";
|
||||
//
|
||||
// Notelabel2
|
||||
//
|
||||
this.Notelabel2.AutoSize = true;
|
||||
this.Notelabel2.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.Notelabel2.Location = new System.Drawing.Point(-3, 416);
|
||||
this.Notelabel2.Name = "Notelabel2";
|
||||
this.Notelabel2.Size = new System.Drawing.Size(270, 13);
|
||||
this.Notelabel2.TabIndex = 3;
|
||||
this.Notelabel2.Text = " Click right button of mouse to close the lines";
|
||||
//
|
||||
// NewOpeningsForm
|
||||
//
|
||||
this.AcceptButton = this.OkButton;
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.BackColor = System.Drawing.SystemColors.Control;
|
||||
this.CancelButton = this.cancelButton;
|
||||
this.ClientSize = new System.Drawing.Size(415, 473);
|
||||
this.Controls.Add(this.Notelabel2);
|
||||
this.Controls.Add(this.Notelabel);
|
||||
this.Controls.Add(this.cancelButton);
|
||||
this.Controls.Add(this.openingPictureBox);
|
||||
this.Controls.Add(this.OkButton);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
|
||||
this.MaximizeBox = false;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "NewOpeningsForm";
|
||||
this.ShowInTaskbar = false;
|
||||
this.Text = "New Openings";
|
||||
((System.ComponentModel.ISupportInitialize)(this.openingPictureBox)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Button OkButton;
|
||||
private System.Windows.Forms.PictureBox openingPictureBox;
|
||||
private System.Windows.Forms.Button cancelButton;
|
||||
private System.Windows.Forms.Label Notelabel;
|
||||
private System.Windows.Forms.Label Notelabel2;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
//
|
||||
// (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.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing.Drawing2D;
|
||||
using Autodesk.Revit.DB;
|
||||
using Point = System.Drawing.Point;
|
||||
|
||||
namespace Revit.SDK.Samples.NewOpenings.CS
|
||||
{
|
||||
/// <summary>
|
||||
/// Main form used to display the profile of Wall or Floor and draw the opening profiles.
|
||||
/// </summary>
|
||||
public partial class NewOpeningsForm : System.Windows.Forms.Form
|
||||
{
|
||||
#region class members
|
||||
private Profile m_profile; //save the profile date (ProfileFloor or ProfileWall)
|
||||
private Matrix4 m_to2DMatrix; //save the matrix use to transform 3D to 2D
|
||||
private Matrix4 m_moveToCenterMatrix; //save the matrix use to move point to origin
|
||||
private Matrix4 m_scaleMatrix; //save the matrix use to scale
|
||||
private ITool m_tool = null; //current using tool
|
||||
private Queue<ITool> m_tools = new Queue<ITool>(); //all tool can use in pictureBox
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// default constructor
|
||||
/// </summary>
|
||||
public NewOpeningsForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="profile">ProfileWall or ProfileFloor</param>
|
||||
public NewOpeningsForm(Profile profile)
|
||||
:this()
|
||||
{
|
||||
m_profile = profile;
|
||||
m_to2DMatrix = m_profile.To2DMatrix();
|
||||
m_moveToCenterMatrix = m_profile.ToCenterMatrix();
|
||||
InitTools();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add tools, then use can draw by these tools in picture box
|
||||
/// </summary>
|
||||
private void InitTools()
|
||||
{
|
||||
//wall
|
||||
if(m_profile is ProfileWall)
|
||||
{
|
||||
m_tool = new RectTool();
|
||||
m_tools.Enqueue(m_tool);
|
||||
m_tools.Enqueue(new EmptyTool());
|
||||
}
|
||||
//floor
|
||||
else
|
||||
{
|
||||
m_tool = new LineTool();
|
||||
m_tools.Enqueue(m_tool);
|
||||
m_tools.Enqueue(new RectTool());
|
||||
m_tools.Enqueue(new CircleTool());
|
||||
m_tools.Enqueue(new ArcTool());
|
||||
m_tools.Enqueue(new EmptyTool());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// use matrix to transform point
|
||||
/// </summary>
|
||||
/// <param name="pts">contain the points to be transform</param>
|
||||
private void TransFormPoints(Point[] pts)
|
||||
{
|
||||
System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(
|
||||
1, 0, 0, 1, this.openingPictureBox.Width / 2, this.openingPictureBox.Height / 2);
|
||||
matrix.Invert();
|
||||
matrix.TransformPoints(pts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get four points on circle by center and one point on circle
|
||||
/// </summary>
|
||||
/// <param name="points">contain the center and one point on circle</param>
|
||||
private List<Vector4> GenerateCircle4Point(List<Point> points)
|
||||
{
|
||||
Matrix rotation = new Matrix();
|
||||
|
||||
//get the circle center and bound point
|
||||
Point center = points[0];
|
||||
Point bound = points[1];
|
||||
rotation.RotateAt(90, (PointF)center);
|
||||
Point[] circle = new Point[4];
|
||||
circle[0] = points[1];
|
||||
for(int i = 1; i < 4; i++)
|
||||
{
|
||||
Point[] ps = new Point[1] { bound };
|
||||
rotation.TransformPoints(ps);
|
||||
circle[i] = ps[0];
|
||||
bound = ps[0];
|
||||
}
|
||||
return TransForm2DTo3D(circle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transform the point on Form to 3d world coordinate of Revit
|
||||
/// </summary>
|
||||
/// <param name="ps">contain the points to be transform</param>
|
||||
private List<Vector4> TransForm2DTo3D(Point[] ps)
|
||||
{
|
||||
List<Vector4> result = new List<Vector4>();
|
||||
TransFormPoints(ps);
|
||||
Matrix4 transFormMatrix = Matrix4.Multiply(
|
||||
m_scaleMatrix.Inverse(),m_moveToCenterMatrix);
|
||||
transFormMatrix = Matrix4.Multiply(transFormMatrix, m_to2DMatrix);
|
||||
foreach (Point point in ps)
|
||||
{
|
||||
Vector4 v = new Vector4(point.X, point.Y, 0);
|
||||
v = transFormMatrix.TransForm(v);
|
||||
result.Add(v);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// calculate the matrix use to scale
|
||||
/// </summary>
|
||||
/// <param name="size">pictureBox size</param>
|
||||
private Matrix4 ComputerScaleMatrix(Size size)
|
||||
{
|
||||
PointF[] boundPoints = m_profile.GetFaceBounds();
|
||||
float width = ((float)size.Width) / (boundPoints[1].X - boundPoints[0].X);
|
||||
float hight = ((float)size.Height) / (boundPoints[1].Y - boundPoints[0].Y);
|
||||
float factor = width <= hight ? width : hight;
|
||||
return new Matrix4(factor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the matrix use to transform 3D to 2D
|
||||
/// </summary>
|
||||
private Matrix4 Comuter3DTo2DMatrix()
|
||||
{
|
||||
Matrix4 result = Matrix4.Multiply(
|
||||
m_to2DMatrix.Inverse(), m_moveToCenterMatrix.Inverse());
|
||||
result = Matrix4.Multiply(result, m_scaleMatrix);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void OkButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
foreach (ITool tool in m_tools)
|
||||
{
|
||||
List<List<Point>> curcves = tool.GetLines();
|
||||
foreach (List<Point> curve in curcves)
|
||||
{
|
||||
List<Vector4> ps3D;
|
||||
|
||||
if (tool.ToolType == ToolType.Circle)
|
||||
{
|
||||
ps3D = GenerateCircle4Point(curve);
|
||||
}
|
||||
else if (tool.ToolType == ToolType.Rectangle)
|
||||
{
|
||||
Point[] ps = new Point[4] { curve[0], new Point(curve[0].X, curve[1].Y),
|
||||
curve[1], new Point(curve[1].X, curve[0].Y) };
|
||||
ps3D = TransForm2DTo3D(ps);
|
||||
}
|
||||
else
|
||||
{
|
||||
ps3D = TransForm2DTo3D(curve.ToArray());
|
||||
}
|
||||
m_profile.DrawOpening(ps3D, tool.ToolType);
|
||||
}
|
||||
}
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void cancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void openingPictureBox_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
//Draw the pictures in the m_tools list
|
||||
foreach (ITool tool in m_tools)
|
||||
{
|
||||
tool.Draw(e.Graphics);
|
||||
}
|
||||
|
||||
//draw the tips string
|
||||
e.Graphics.DrawString(m_tool.ToolType.ToString(),
|
||||
SystemFonts.DefaultFont, SystemBrushes.Highlight, 2, 5);
|
||||
|
||||
//move the origin to the picture center
|
||||
Size size = this.openingPictureBox.Size;
|
||||
e.Graphics.Transform = new System.Drawing.Drawing2D.Matrix(
|
||||
1, 0, 0, 1, size.Width / 2, size.Height / 2);
|
||||
|
||||
//draw profile
|
||||
Size scaleSize = new Size((int)(0.85 * size.Width), (int)(0.85 * size.Height));
|
||||
m_scaleMatrix = ComputerScaleMatrix(scaleSize);
|
||||
Matrix4 trans = Comuter3DTo2DMatrix();
|
||||
m_profile.Draw2D(e.Graphics, Pens.Blue, trans);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// mouse event handle
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void openingPictureBox_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (MouseButtons.Left == e.Button || MouseButtons.Right == e.Button)
|
||||
{
|
||||
Graphics g = openingPictureBox.CreateGraphics();
|
||||
|
||||
m_tool.OnMouseDown(g, e);
|
||||
m_tool.OnRightMouseClick(g, e);
|
||||
}
|
||||
else if (MouseButtons.Middle == e.Button)
|
||||
{
|
||||
m_tool.OnMidMouseDown(null, null);
|
||||
m_tool = m_tools.Peek();
|
||||
m_tools.Enqueue(m_tool);
|
||||
m_tools.Dequeue();
|
||||
Graphics graphic = openingPictureBox.CreateGraphics();
|
||||
graphic.DrawString(m_tool.ToolType.ToString(),
|
||||
SystemFonts.DefaultFont, SystemBrushes.Highlight, 2, 5);
|
||||
this.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mouse event handle
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void openingPictureBox_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
Graphics g = openingPictureBox.CreateGraphics();
|
||||
m_tool.OnMouseUp(g, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mouse event handle
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void openingPictureBox_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
Graphics graphics = openingPictureBox.CreateGraphics();
|
||||
m_tool.OnMouseMove(graphics, e);
|
||||
PaintEventArgs paintArg = new PaintEventArgs(graphics, new System.Drawing.Rectangle());
|
||||
openingPictureBox_Paint(null, paintArg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -0,0 +1,374 @@
|
||||
//
|
||||
// (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 Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit.DB.Structure;
|
||||
using Autodesk.Revit;
|
||||
using System.Drawing;
|
||||
using Point = System.Drawing.Point;
|
||||
|
||||
namespace Revit.SDK.Samples.NewOpenings.CS
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class of ProfileFloor and ProfileWall
|
||||
/// contain the profile information and can make matrix to transform point to 2D plane
|
||||
/// </summary>
|
||||
public abstract class Profile
|
||||
{
|
||||
#region members
|
||||
/// <summary>
|
||||
///Wall or Floor element
|
||||
/// </summary>
|
||||
protected Autodesk.Revit.DB.Element m_dataProfile;
|
||||
|
||||
/// <summary>
|
||||
/// geometry object [face]
|
||||
/// </summary>
|
||||
protected List<Edge> m_face;
|
||||
|
||||
/// <summary>
|
||||
/// command data
|
||||
/// </summary>
|
||||
protected Autodesk.Revit.UI.ExternalCommandData m_commandData;
|
||||
|
||||
/// <summary>
|
||||
/// Application creator
|
||||
/// </summary>
|
||||
protected Autodesk.Revit.Creation.Application m_appCreator;
|
||||
|
||||
/// <summary>
|
||||
/// Document creator
|
||||
/// </summary>
|
||||
protected Autodesk.Revit.Creation.Document m_docCreator;
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Abstract method to create Opening
|
||||
/// </summary>
|
||||
public abstract void DrawOpening(List<Vector4> points, ToolType type);
|
||||
|
||||
/// <summary>
|
||||
/// Draw profile of wall or floor in 2D
|
||||
/// </summary>
|
||||
/// <param name="graphics">form graphic</param>
|
||||
/// <param name="pen">pen use to draw line in pictureBox</param>
|
||||
/// <param name="matrix4">matrix used to transform points between 3d and 2d.</param>>
|
||||
public void Draw2D(Graphics graphics, Pen pen, Matrix4 matrix4)
|
||||
{
|
||||
foreach (Edge edge in m_face)
|
||||
{
|
||||
List<XYZ> points = edge.Tessellate() as List<XYZ>;
|
||||
for (int i = 0; i < points.Count - 1; i++)
|
||||
{
|
||||
Autodesk.Revit.DB.XYZ point1 = points[i];
|
||||
Autodesk.Revit.DB.XYZ point2 = points[i + 1];
|
||||
|
||||
Vector4 v1 = new Vector4(point1);
|
||||
Vector4 v2 = new Vector4(point2);
|
||||
|
||||
v1 = matrix4.TransForm(v1);
|
||||
v2 = matrix4.TransForm(v2);
|
||||
graphics.DrawLine(pen, new Point((int)v1.X, (int)v1.Y),
|
||||
new Point((int)v2.X, (int)v2.Y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="elem">Selected element</param>
|
||||
/// <param name="commandData">ExternalCommandData</param>
|
||||
public Profile(Autodesk.Revit.DB.Element elem, ExternalCommandData commandData)
|
||||
{
|
||||
m_dataProfile = elem;
|
||||
m_commandData = commandData;
|
||||
m_appCreator = m_commandData.Application.Application.Create;
|
||||
m_docCreator = m_commandData.Application.ActiveUIDocument.Document.Create;
|
||||
|
||||
List<List<Edge>> faces = GetFaces(m_dataProfile);
|
||||
m_face = GetNeedFace(faces);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get edges of element's profile
|
||||
/// </summary>
|
||||
/// <param name="elem">Selected element</param>
|
||||
public List<List<Edge>> GetFaces(Autodesk.Revit.DB.Element elem)
|
||||
{
|
||||
List<List<Edge>> faceEdges = new List<List<Edge>>();
|
||||
Options options = m_appCreator.NewGeometryOptions();
|
||||
options.DetailLevel = ViewDetailLevel.Medium;
|
||||
options.ComputeReferences = true;
|
||||
Autodesk.Revit.DB.GeometryElement geoElem = elem.get_Geometry(options);
|
||||
|
||||
//GeometryObjectArray gObjects = geoElem.Objects;
|
||||
IEnumerator<GeometryObject> Objects = geoElem.GetEnumerator();
|
||||
//foreach (GeometryObject geo in gObjects)
|
||||
while (Objects.MoveNext())
|
||||
{
|
||||
GeometryObject geo = Objects.Current;
|
||||
|
||||
Solid solid = geo as Solid;
|
||||
if (solid != null)
|
||||
{
|
||||
EdgeArray edges = solid.Edges;
|
||||
FaceArray faces = solid.Faces;
|
||||
foreach (Face face in faces)
|
||||
{
|
||||
EdgeArrayArray edgeArrarr = face.EdgeLoops;
|
||||
foreach (EdgeArray edgeArr in edgeArrarr)
|
||||
{
|
||||
List<Edge> edgesList = new List<Edge>();
|
||||
foreach (Edge edge in edgeArr)
|
||||
{
|
||||
edgesList.Add(edge);
|
||||
}
|
||||
faceEdges.Add(edgesList);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return faceEdges;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Face Normal
|
||||
/// </summary>
|
||||
/// <param name="face">Edges in a face</param>
|
||||
private Vector4 GetFaceNormal(List<Edge> face)
|
||||
{
|
||||
Edge eg0 = face[0];
|
||||
Edge eg1 = face[1];
|
||||
|
||||
List<XYZ> points = eg0.Tessellate() as List<XYZ>;
|
||||
Autodesk.Revit.DB.XYZ start = points[0];
|
||||
Autodesk.Revit.DB.XYZ end = points[1];
|
||||
|
||||
Vector4 vStart = new Vector4((float)start.X, (float)start.Y, (float)start.Z);
|
||||
Vector4 vEnd = new Vector4((float)end.X, (float)end.Y, (float)end.Z);
|
||||
Vector4 vSub = vEnd - vStart;
|
||||
|
||||
points = eg1.Tessellate() as List<XYZ>;
|
||||
start = points[0];
|
||||
end = points[1];
|
||||
|
||||
vStart = new Vector4((float)start.X, (float)start.Y, (float)start.Z);
|
||||
vEnd = new Vector4((float)end.X, (float)end.Y, (float)end.Z);
|
||||
Vector4 vSub2 = vEnd - vStart;
|
||||
|
||||
Vector4 result = vSub.CrossProduct(vSub2);
|
||||
result.Normalize();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get First Face
|
||||
/// </summary>
|
||||
/// <param name="faces">edges in all faces</param>
|
||||
private List<Edge> GetNeedFace(List<List<Edge>> faces)
|
||||
{
|
||||
if (m_dataProfile is Wall)
|
||||
{
|
||||
return GetWallFace(faces);
|
||||
}
|
||||
return faces[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a matrix which can transform points to 2D
|
||||
/// </summary>
|
||||
public Matrix4 To2DMatrix()
|
||||
{
|
||||
if (m_dataProfile is Wall)
|
||||
{
|
||||
return WallMatrix();
|
||||
}
|
||||
List<XYZ> eg0 = m_face[0].Tessellate() as List<XYZ>;
|
||||
List<XYZ> eg1 = m_face[1].Tessellate() as List<XYZ>;
|
||||
|
||||
Vector4 v1 = new Vector4((float)eg0[0].X,
|
||||
(float)eg0[0].Y, (float)eg0[0].Z);
|
||||
|
||||
Vector4 v2 = new Vector4((float)eg0[1].X,
|
||||
(float)eg0[1].Y, (float)eg0[1].Z);
|
||||
Vector4 v21 = v1 - v2;
|
||||
v21.Normalize();
|
||||
|
||||
Vector4 v3 = new Vector4((float)eg1[0].X,
|
||||
(float)eg1[0].Y, (float)eg1[0].Z);
|
||||
|
||||
Vector4 v4 = new Vector4((float)eg1[1].X,
|
||||
(float)eg1[1].Y, (float)eg1[1].Z);
|
||||
Vector4 v43 = v4 - v3;
|
||||
v43.Normalize();
|
||||
|
||||
Vector4 vZAxis = Vector4.CrossProduct(v43, v21);
|
||||
Vector4 vYAxis = Vector4.CrossProduct(vZAxis, v43);
|
||||
vYAxis.Normalize();
|
||||
vZAxis.Normalize();
|
||||
Vector4 vOrigin = (v4 + v1) / 2;
|
||||
|
||||
Matrix4 result = new Matrix4(v43, vYAxis, vZAxis, vOrigin);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wall matrix
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Matrix4 WallMatrix()
|
||||
{
|
||||
//get the location curve
|
||||
LocationCurve location = m_dataProfile.Location as LocationCurve;
|
||||
Vector4 xAxis = new Vector4(1, 0, 0);
|
||||
Vector4 yAxis = new Vector4(0, 1, 0);
|
||||
Vector4 zAxis = new Vector4(0, 0, 1);
|
||||
Vector4 origin = new Vector4(0, 0, 0);
|
||||
if (location != null)
|
||||
{
|
||||
Curve curve = location.Curve;
|
||||
Autodesk.Revit.DB.XYZ start = curve.GetEndPoint(0);
|
||||
Autodesk.Revit.DB.XYZ end = curve.GetEndPoint(1);
|
||||
|
||||
xAxis = new Vector4((float)(end.X - start.X),
|
||||
(float)(end.Y - start.Y), (float)(end.Z - start.Z));
|
||||
xAxis.Normalize();
|
||||
|
||||
yAxis = new Vector4(0, 0, 1);
|
||||
|
||||
zAxis = Vector4.CrossProduct(xAxis, yAxis);
|
||||
zAxis.Normalize();
|
||||
|
||||
origin = new Vector4((float)(end.X + start.X) / 2,
|
||||
(float)(end.Y + start.Y) / 2, (float)(end.Z + start.Z) / 2);
|
||||
}
|
||||
return new Matrix4(xAxis, yAxis, zAxis, origin);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get wall face
|
||||
/// </summary>
|
||||
/// <param name="faces"></param>
|
||||
/// <returns></returns>
|
||||
private List<Edge> GetWallFace(List<List<Edge>> faces)
|
||||
{
|
||||
LocationCurve location = m_dataProfile.Location as LocationCurve;
|
||||
Curve curve = location.Curve;
|
||||
List<XYZ> xyzs = curve.Tessellate() as List<XYZ>;
|
||||
Vector4 zAxis = new Vector4(0, 0, 1);
|
||||
|
||||
if (xyzs.Count == 2)
|
||||
{
|
||||
return faces[0];
|
||||
}
|
||||
|
||||
foreach (List<Edge> face in faces)
|
||||
{
|
||||
foreach (Edge edge in face)
|
||||
{
|
||||
List<XYZ> edgexyzs = edge.Tessellate() as List<XYZ>;
|
||||
if (xyzs.Count == edgexyzs.Count)
|
||||
{
|
||||
Vector4 normal = GetFaceNormal(face);
|
||||
Vector4 cross = Vector4.CrossProduct(zAxis, normal);
|
||||
cross.Normalize();
|
||||
if (cross.Length() == 1)
|
||||
{
|
||||
return face;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return faces[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a matrix which can move points to origin
|
||||
/// </summary>
|
||||
public Matrix4 ToCenterMatrix()
|
||||
{
|
||||
//translate the origin to bound center
|
||||
PointF[] bounds = GetFaceBounds();
|
||||
PointF min = bounds[0];
|
||||
PointF max = bounds[1];
|
||||
PointF center = new PointF((min.X + max.X) / 2, (min.Y + max.Y) / 2);
|
||||
return new Matrix4(new Vector4(center.X, center.Y, 0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get Face Bounds
|
||||
/// </summary>
|
||||
public PointF[] GetFaceBounds()
|
||||
{
|
||||
Matrix4 matrix = To2DMatrix();
|
||||
Matrix4 inverseMatrix = matrix.Inverse();
|
||||
float minX = 0, maxX = 0, minY = 0, maxY = 0;
|
||||
bool bFirstPoint = true;
|
||||
foreach (Edge edge in m_face)
|
||||
{
|
||||
List<XYZ> points = edge.Tessellate() as List<XYZ>;
|
||||
|
||||
foreach (Autodesk.Revit.DB.XYZ point in points)
|
||||
{
|
||||
Vector4 v = new Vector4(point);
|
||||
Vector4 v1 = inverseMatrix.TransForm(v);
|
||||
|
||||
if (bFirstPoint)
|
||||
{
|
||||
minX = maxX = v1.X;
|
||||
minY = maxY = v1.Y;
|
||||
bFirstPoint = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (v1.X < minX)
|
||||
{
|
||||
minX = v1.X;
|
||||
}
|
||||
else if (v1.X > maxX)
|
||||
{
|
||||
maxX = v1.X;
|
||||
}
|
||||
|
||||
if (v1.Y < minY)
|
||||
{
|
||||
minY = v1.Y;
|
||||
}
|
||||
else if (v1.Y > maxY)
|
||||
{
|
||||
maxY = v1.Y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
PointF[] resultPoints = new PointF[2] {
|
||||
new PointF(minX, minY), new PointF(maxX, maxY) };
|
||||
return resultPoints;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
//
|
||||
// (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 Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
namespace Revit.SDK.Samples.NewOpenings.CS
|
||||
{
|
||||
/// <summary>
|
||||
/// ProfileFloor class contain the information about profile of floor,
|
||||
/// and contain method to create Opening on floor
|
||||
/// </summary>
|
||||
public class ProfileFloor : Profile
|
||||
{
|
||||
private Floor m_data;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="floor">Selected floor</param>
|
||||
/// <param name="commandData">ExternalCommandData</param>
|
||||
public ProfileFloor(Floor floor, ExternalCommandData commandData)
|
||||
: base(floor, commandData)
|
||||
{
|
||||
m_data = floor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create Opening on floor
|
||||
/// </summary>
|
||||
/// <param name="points">Points use to create Opening</param>
|
||||
/// <param name="type">Tool type</param>
|
||||
public override void DrawOpening(List<Vector4> points, ToolType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ToolType.Line:
|
||||
case ToolType.Rectangle:
|
||||
DrawPlineOpening(points);
|
||||
break;
|
||||
|
||||
case ToolType.Circle:
|
||||
DrawCircleOpening(points);
|
||||
break;
|
||||
|
||||
case ToolType.Arc:
|
||||
DrawArcOpening(points);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create Opening which make up of line on floor
|
||||
/// </summary>
|
||||
/// <param name="points">Points use to create Opening</param>
|
||||
private void DrawPlineOpening(List<Vector4> points)
|
||||
{
|
||||
Autodesk.Revit.DB.XYZ p1, p2; Line curve;
|
||||
CurveArray curves = m_appCreator.NewCurveArray();
|
||||
for (int i = 0; i < points.Count - 1; i++)
|
||||
{
|
||||
p1 = new Autodesk.Revit.DB.XYZ(points[i].X, points[i].Y, points[i].Z);
|
||||
p2 = new Autodesk.Revit.DB.XYZ(points[i + 1].X, points[i + 1].Y, points[i + 1].Z);
|
||||
curve = Line.CreateBound(p1, p2);
|
||||
curves.Append(curve);
|
||||
}
|
||||
|
||||
p1 = new Autodesk.Revit.DB.XYZ(points[points.Count - 1].X,
|
||||
points[points.Count - 1].Y, points[points.Count - 1].Z);
|
||||
p2 = new Autodesk.Revit.DB.XYZ(points[0].X, points[0].Y, points[0].Z);
|
||||
curve = Line.CreateBound(p1, p2);
|
||||
curves.Append(curve);
|
||||
|
||||
m_docCreator.NewOpening(m_data, curves, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create Opening which make up of Circle on floor
|
||||
/// </summary>
|
||||
/// <param name="points">Points use to create Opening</param>
|
||||
private void DrawCircleOpening(List<Vector4> points)
|
||||
{
|
||||
CurveArray curves = m_appCreator.NewCurveArray();
|
||||
Autodesk.Revit.DB.XYZ p1 = new Autodesk.Revit.DB.XYZ(points[0].X, points[0].Y, points[0].Z);
|
||||
Autodesk.Revit.DB.XYZ p2 = new Autodesk.Revit.DB.XYZ(points[1].X, points[1].Y, points[1].Z);
|
||||
Autodesk.Revit.DB.XYZ p3 = new Autodesk.Revit.DB.XYZ(points[2].X, points[2].Y, points[2].Z);
|
||||
Autodesk.Revit.DB.XYZ p4 = new Autodesk.Revit.DB.XYZ(points[3].X, points[3].Y, points[3].Z);
|
||||
Arc arc = Arc.Create(p1, p3, p2);
|
||||
Arc arc2 = Arc.Create(p1, p3, p4);
|
||||
curves.Append(arc);
|
||||
curves.Append(arc2);
|
||||
m_docCreator.NewOpening(m_data, curves, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create Opening which make up of Arc on floor
|
||||
/// </summary>
|
||||
/// <param name="points">Points use to create Opening</param>
|
||||
private void DrawArcOpening(List<Vector4> points)
|
||||
{
|
||||
CurveArray curves = m_appCreator.NewCurveArray();
|
||||
Arc arc; Autodesk.Revit.DB.XYZ p1, p2, p3;
|
||||
p1 = new Autodesk.Revit.DB.XYZ(points[0].X, points[0].Y, points[0].Z);
|
||||
p2 = new Autodesk.Revit.DB.XYZ(points[1].X, points[1].Y, points[1].Z);
|
||||
p3 = new Autodesk.Revit.DB.XYZ(points[2].X, points[2].Y, points[2].Z);
|
||||
arc = Arc.Create(p1, p2, p3);
|
||||
curves.Append(arc);
|
||||
for (int i = 1; i < points.Count - 3; i += 2)
|
||||
{
|
||||
p1 = new Autodesk.Revit.DB.XYZ(points[i].X, points[i].Y, points[i].Z);
|
||||
p2 = new Autodesk.Revit.DB.XYZ(points[i + 2].X, points[i + 2].Y, points[i + 2].Z);
|
||||
p3 = new Autodesk.Revit.DB.XYZ(points[i + 3].X, points[i + 3].Y, points[i + 3].Z);
|
||||
arc = Arc.Create(p1, p2, p3);
|
||||
curves.Append(arc);
|
||||
}
|
||||
m_docCreator.NewOpening(m_data, curves, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// (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 Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Revit.SDK.Samples.NewOpenings.CS
|
||||
{
|
||||
/// <summary>
|
||||
/// ProfileWall class contain the information about profile of wall,
|
||||
/// and contain method to create Opening on wall
|
||||
/// </summary>
|
||||
public class ProfileWall : Profile
|
||||
{
|
||||
private Wall m_data;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="wall">Selected wall</param>
|
||||
/// <param name="commandData">ExternalCommandData</param>
|
||||
public ProfileWall(Wall wall, ExternalCommandData commandData)
|
||||
: base(wall, commandData)
|
||||
{
|
||||
m_data = wall;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create opening on wall
|
||||
/// </summary>
|
||||
/// <param name="points">Points use to create Opening</param>
|
||||
/// <param name="type">Tool type</param>
|
||||
public override void DrawOpening(List<Vector4> points, ToolType type)
|
||||
{
|
||||
//get the rectangle two points
|
||||
Autodesk.Revit.DB.XYZ p1 = new Autodesk.Revit.DB.XYZ (points[0].X, points[0].Y, points[0].Z);
|
||||
Autodesk.Revit.DB.XYZ p2 = new Autodesk.Revit.DB.XYZ (points[2].X, points[2].Y, points[2].Z);
|
||||
|
||||
//draw opening on wall
|
||||
m_docCreator.NewOpening(m_data, p1, p2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// (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.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Revit.SDK.Samples.NewOpenings.CS")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Revit.SDK.Samples.NewOpenings.CS")]
|
||||
[assembly: AssemblyCopyright("Copyright © Autodesk, Inc. 2009")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("24bba31e-7240-4bf6-9e56-65f17cda4993")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
Binary file not shown.
@@ -0,0 +1,130 @@
|
||||
//
|
||||
// (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.NewOpenings.CS
|
||||
{
|
||||
/// <summary>
|
||||
/// Tool used to draw rectangle
|
||||
/// </summary>
|
||||
class RectTool:ITool
|
||||
{
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
public RectTool()
|
||||
{
|
||||
m_type = ToolType.Rectangle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mouse move event handler
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object,used to draw geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public override void OnMouseMove(Graphics graphic, MouseEventArgs e)
|
||||
{
|
||||
if(m_points.Count == 1)
|
||||
{
|
||||
DrawRect(graphic, m_backGroundPen, m_points[0], m_preMovePoint);
|
||||
m_preMovePoint = e.Location;
|
||||
DrawRect(graphic, m_foreGroundPen, m_points[0], m_preMovePoint);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mouse down event handler
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object,used to draw geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public override void OnMouseDown(Graphics graphic, MouseEventArgs e)
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
m_preMovePoint = e.Location;
|
||||
m_points.Add(e.Location);
|
||||
|
||||
if(m_points.Count == 2)
|
||||
{
|
||||
DrawRect(graphic, m_foreGroundPen, m_points[0], m_points[1]);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mouse up event handler
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object,used to draw geometry</param>
|
||||
/// <param name="e">Mouse event argument</param>
|
||||
public override void OnMouseUp(Graphics graphic, MouseEventArgs e)
|
||||
{
|
||||
if(m_points.Count == 2 )
|
||||
{
|
||||
List<Point> line = new List<Point>(m_points);
|
||||
m_lines.Add(line);
|
||||
m_points.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw rectangles
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object,used to draw geometry </param>
|
||||
public override void Draw(Graphics graphic)
|
||||
{
|
||||
foreach (List<Point> line in m_lines)
|
||||
{
|
||||
DrawRect(graphic, m_foreGroundPen, line[0], line[1]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draw rectangle use the given two opposite point p1 and p2
|
||||
/// </summary>
|
||||
/// <param name="graphic">Graphics object,used to draw geometry</param>
|
||||
/// <param name="pen">Pen used to set color</param>
|
||||
/// <param name="p1">Rectangle one corner</param>
|
||||
/// <param name="p2">Opposite corner of p1</param>
|
||||
private void DrawRect(Graphics graphic,Pen pen,Point p1, Point p2)
|
||||
{
|
||||
Size p = new Size(p2.X - p1.X, p2.Y - p1.Y);
|
||||
if(p.Width >= 0 && p.Height >= 0)
|
||||
{
|
||||
graphic.DrawRectangle(pen, p1.X, p1.Y, p.Width, p.Height);
|
||||
}
|
||||
//draw four lines
|
||||
else
|
||||
{
|
||||
Point[] points = new Point[5]{p1, new Point(p1.X, p2.Y),
|
||||
p2, new Point(p2.X, p1.Y), p1};
|
||||
graphic.DrawLines(pen, points);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
//
|
||||
// (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.Collections;
|
||||
using System.Drawing;
|
||||
|
||||
using Autodesk.Revit;
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using Autodesk.Revit.DB.Structure;
|
||||
|
||||
namespace Revit.SDK.Samples.NewOpenings.CS
|
||||
{
|
||||
/// <summary>
|
||||
/// The entrance of this example, implement the Execute method of IExternalCommand
|
||||
/// Show how to create Opening in Revit by RevitAPI
|
||||
/// </summary>
|
||||
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
|
||||
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
|
||||
[Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]
|
||||
public class Command:IExternalCommand
|
||||
{
|
||||
#region IExternalCommand Members Implementation
|
||||
/// <summary>
|
||||
/// Implement this method as an external command for Revit.
|
||||
/// </summary>
|
||||
/// <param name="commandData">An object that is passed to the external application
|
||||
/// which contains data related to the command,
|
||||
/// such as the application object and active view.</param>
|
||||
/// <param name="message">A message that can be set by the external application
|
||||
/// which will be displayed if a failure or cancellation is returned by
|
||||
/// the external command.</param>
|
||||
/// <param name="elements">A set of elements to which the external application
|
||||
/// can add elements that are to be highlighted in case of failure or cancellation.</param>
|
||||
/// <returns>Return the status of the external command.
|
||||
/// A result of Succeeded means that the API external method functioned as expected.
|
||||
/// Cancelled can be used to signify that the user cancelled the external operation
|
||||
/// at some point. Failure should be returned if the application is unable to proceed with
|
||||
/// the operation.</returns>
|
||||
public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
|
||||
ref string message, Autodesk.Revit.DB.ElementSet elements)
|
||||
{
|
||||
Transaction transaction = new Transaction(commandData.Application.ActiveUIDocument.Document, "External Tool");
|
||||
try
|
||||
{
|
||||
transaction.Start();
|
||||
Wall wall = null;
|
||||
Floor floor = null;
|
||||
|
||||
ElementSet elems = new ElementSet();
|
||||
foreach (ElementId elementId in commandData.Application.ActiveUIDocument.Selection.GetElementIds())
|
||||
{
|
||||
elems.Insert(commandData.Application.ActiveUIDocument.Document.GetElement(elementId));
|
||||
}
|
||||
#region selection error handle
|
||||
//if user have some wrong selection, give user an error message
|
||||
if (1 != elems.Size)
|
||||
{
|
||||
message = "please selected one Object (Floor or Wall) to create Opening.";
|
||||
return Autodesk.Revit.UI.Result.Cancelled;
|
||||
}
|
||||
|
||||
Autodesk.Revit.DB.Element selectElem = null;
|
||||
foreach (Autodesk.Revit.DB.Element e in elems)
|
||||
{
|
||||
selectElem = e;
|
||||
}
|
||||
|
||||
if (!(selectElem is Wall) && !(selectElem is Floor))
|
||||
{
|
||||
message = "please selected one Object (Floor or Wall) to create Opening.";
|
||||
return Autodesk.Revit.UI.Result.Cancelled;
|
||||
}
|
||||
#endregion
|
||||
try
|
||||
{
|
||||
if (selectElem is Wall)
|
||||
{
|
||||
wall = selectElem as Wall;
|
||||
ProfileWall profileWall = new ProfileWall(wall, commandData);
|
||||
NewOpeningsForm newOpeningsForm = new NewOpeningsForm(profileWall);
|
||||
newOpeningsForm.ShowDialog();
|
||||
}
|
||||
else if (selectElem is Floor)
|
||||
{
|
||||
floor = selectElem as Floor;
|
||||
ProfileFloor profileFloor = new ProfileFloor(floor, commandData);
|
||||
NewOpeningsForm newOpeningsForm = new NewOpeningsForm(profileFloor);
|
||||
newOpeningsForm.ShowDialog();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
message = ex.Message;
|
||||
return Autodesk.Revit.UI.Result.Cancelled;
|
||||
}
|
||||
|
||||
return Autodesk.Revit.UI.Result.Succeeded;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
message = e.Message;
|
||||
return Autodesk.Revit.UI.Result.Failed;
|
||||
}
|
||||
finally
|
||||
{
|
||||
transaction.Commit();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user