Class CollisionObjectCollection
A collection of GraphicComponent collision objects.
Inheritance
CollisionObjectCollection
Assembly: ABB.Robotics.RobotStudio.Stations.dll
Syntax
public class CollisionObjectCollection : ICollection, IEnumerable<GraphicComponent>, IEnumerable
Examples
CollisionObject Collection.
public void CollisionDetection()
{
Project.UndoContext.BeginUndoStep("CollisionDetection");
try
{
Station station = Station.ActiveStation;
#region CollisionDetectionPoint1
// Create two parts and bodies to use in collision detection.
Part p1 = new Part();
p1.Name = "My Part1";
Part p2 = new Part();
p2.Name = "My Part2";
station.GraphicComponents.Add(p1);
station.GraphicComponents.Add(p2);
#endregion
// Create two boxes.
Body box1 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box1.Name = "My Box1";
Body box2 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box2.Name = "My Box2";
// Move box2 0.105 meters along the X-axis .
box2.Transform.X = box2.Transform.X + 0.105;
// Add the boxes to the bodies.
p1.Bodies.Add(box1);
p2.Bodies.Add(box2);
// Manually check to see if there is a collision between the two parts.
// Also tests for a near miss, defined as being within 0.01 meter from each other.
#region CollisionDetectionPoint2
CollisionType colType = CollisionDetector.CheckCollision(p1, p2, 0.01);
switch (colType)
{
case CollisionType.Collision:
Logger.AddMessage(new LogMessage("Part: " + p1.Name
+ " and part: " + p2.Name + " is colliding!"));
break;
case CollisionType.NearMiss:
Logger.AddMessage(new LogMessage("There is a near miss between part: "
+ p1.Name
+ " and part: " + p2.Name + "."));
Vector3 p1Point;
Vector3 p2Point;
Logger.AddMessage(new LogMessage("The distance between them are: "
+ CollisionDetector.MinimumDistance(p1, p2, out p1Point, out p2Point)));
Logger.AddMessage(new LogMessage("The closest points are: "));
Logger.AddMessage(new LogMessage("For part: " + p1.Name + " x: " + p1Point.x
+ " y: " + p1Point.y + " z: " + p1Point.z));
Logger.AddMessage(new LogMessage("For part: " + p2.Name + " x: " + p2Point.x
+ " y: " + p2Point.y + " z: " + p2Point.z));
break;
case CollisionType.None:
Logger.AddMessage(new LogMessage("There is no collision!"));
break;
}
#endregion
// Reset the collision sets and highlights.
CollisionDetector.ResetCollisions();
// Add an event handler to the collision event.
CollisionDetector.Collision += new CollisionEventHandler(myCollisionEventHandler);
// Activate auto check for collisions each time the graphics is updated.
CollisionDetector.AutoCheck = true;
// Test for collisions on polygon level, not just for the bounding boxes.
CollisionDetector.FastCheck = false;
#region CollisionDetectionPoint3
// Add the two boxes to a collision set.
CollisionSet cs = new CollisionSet();
cs.Name = "My CollisionSet";
// Set the near miss distance to 0.01 meters.
cs.NearMissDistance = 0.01;
// Set the near miss color to black.
cs.NearMissColor = System.Drawing.Color.Black;
// Activate this collision set for collision checks.
cs.Active = true;
// Set the collision color to semi-transparent yellow.
cs.CollisionColor = Color.FromArgb(128, System.Drawing.Color.Yellow);
// Turn on highlighting of colliding objects.
cs.Highlight = true;
// Add the collision set to the station.
station.CollisionSets.Add(cs);
// Add the two parts to the two different collision object collections of the collision set.
cs.FirstGroup.Add(p1);
cs.SecondGroup.Add(p2);
#endregion
#region CollisionDetectionPoint4
// Force check the station for collisions.
CollisionDetector.CheckCollisions(station);
// Force check the collision set for collisiosn.
CollisionDetector.CheckCollisions(cs);
#endregion
// Freehand move the boxes in the graphics.
// Notice the messages generated by the event handler code,
// and the change in color of the boxes.
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
private void myCollisionEventHandler(object sender, CollisionEventArgs e)
{
switch (e.CollisionEvent)
{
case CollisionEvent.CollisionStarted:
Logger.AddMessage
(new LogMessage("Collision started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.CollisionEnded:
Logger.AddMessage(new LogMessage("Collision ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissStarted:
Logger.AddMessage(new LogMessage("Near Miss started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissEnded:
Logger.AddMessage(new LogMessage("Near Miss ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '"
+ e.FirstPart.Name + "' Second part: '" + e.SecondPart.Name + "'"));
break;
default:
break;
}
}
Properties
Count
Declaration
public virtual int Count { get; }
Property Value
IsSynchronized
Declaration
public virtual bool IsSynchronized { get; }
Property Value
Item[Int32]
Declaration
public GraphicComponent this[int index] { get; }
Parameters
Type |
Name |
Description |
Int32 |
index |
|
Property Value
Parent
Declaration
public ProjectObject Parent { get; }
Property Value
SyncRoot
Declaration
public virtual object SyncRoot { get; }
Property Value
Methods
Add(GraphicComponent)
Declaration
public void Add(GraphicComponent collisionObject)
Parameters
Examples
Add CollisionObject.
public void CollisionDetection()
{
Project.UndoContext.BeginUndoStep("CollisionDetection");
try
{
Station station = Station.ActiveStation;
#region CollisionDetectionPoint1
// Create two parts and bodies to use in collision detection.
Part p1 = new Part();
p1.Name = "My Part1";
Part p2 = new Part();
p2.Name = "My Part2";
station.GraphicComponents.Add(p1);
station.GraphicComponents.Add(p2);
#endregion
// Create two boxes.
Body box1 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box1.Name = "My Box1";
Body box2 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box2.Name = "My Box2";
// Move box2 0.105 meters along the X-axis .
box2.Transform.X = box2.Transform.X + 0.105;
// Add the boxes to the bodies.
p1.Bodies.Add(box1);
p2.Bodies.Add(box2);
// Manually check to see if there is a collision between the two parts.
// Also tests for a near miss, defined as being within 0.01 meter from each other.
#region CollisionDetectionPoint2
CollisionType colType = CollisionDetector.CheckCollision(p1, p2, 0.01);
switch (colType)
{
case CollisionType.Collision:
Logger.AddMessage(new LogMessage("Part: " + p1.Name
+ " and part: " + p2.Name + " is colliding!"));
break;
case CollisionType.NearMiss:
Logger.AddMessage(new LogMessage("There is a near miss between part: "
+ p1.Name
+ " and part: " + p2.Name + "."));
Vector3 p1Point;
Vector3 p2Point;
Logger.AddMessage(new LogMessage("The distance between them are: "
+ CollisionDetector.MinimumDistance(p1, p2, out p1Point, out p2Point)));
Logger.AddMessage(new LogMessage("The closest points are: "));
Logger.AddMessage(new LogMessage("For part: " + p1.Name + " x: " + p1Point.x
+ " y: " + p1Point.y + " z: " + p1Point.z));
Logger.AddMessage(new LogMessage("For part: " + p2.Name + " x: " + p2Point.x
+ " y: " + p2Point.y + " z: " + p2Point.z));
break;
case CollisionType.None:
Logger.AddMessage(new LogMessage("There is no collision!"));
break;
}
#endregion
// Reset the collision sets and highlights.
CollisionDetector.ResetCollisions();
// Add an event handler to the collision event.
CollisionDetector.Collision += new CollisionEventHandler(myCollisionEventHandler);
// Activate auto check for collisions each time the graphics is updated.
CollisionDetector.AutoCheck = true;
// Test for collisions on polygon level, not just for the bounding boxes.
CollisionDetector.FastCheck = false;
#region CollisionDetectionPoint3
// Add the two boxes to a collision set.
CollisionSet cs = new CollisionSet();
cs.Name = "My CollisionSet";
// Set the near miss distance to 0.01 meters.
cs.NearMissDistance = 0.01;
// Set the near miss color to black.
cs.NearMissColor = System.Drawing.Color.Black;
// Activate this collision set for collision checks.
cs.Active = true;
// Set the collision color to semi-transparent yellow.
cs.CollisionColor = Color.FromArgb(128, System.Drawing.Color.Yellow);
// Turn on highlighting of colliding objects.
cs.Highlight = true;
// Add the collision set to the station.
station.CollisionSets.Add(cs);
// Add the two parts to the two different collision object collections of the collision set.
cs.FirstGroup.Add(p1);
cs.SecondGroup.Add(p2);
#endregion
#region CollisionDetectionPoint4
// Force check the station for collisions.
CollisionDetector.CheckCollisions(station);
// Force check the collision set for collisiosn.
CollisionDetector.CheckCollisions(cs);
#endregion
// Freehand move the boxes in the graphics.
// Notice the messages generated by the event handler code,
// and the change in color of the boxes.
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
private void myCollisionEventHandler(object sender, CollisionEventArgs e)
{
switch (e.CollisionEvent)
{
case CollisionEvent.CollisionStarted:
Logger.AddMessage
(new LogMessage("Collision started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.CollisionEnded:
Logger.AddMessage(new LogMessage("Collision ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissStarted:
Logger.AddMessage(new LogMessage("Near Miss started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissEnded:
Logger.AddMessage(new LogMessage("Near Miss ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '"
+ e.FirstPart.Name + "' Second part: '" + e.SecondPart.Name + "'"));
break;
default:
break;
}
}
Contains(GraphicComponent)
Declaration
public bool Contains(GraphicComponent obj)
Parameters
Returns
CopyTo(GraphicComponent[], Int32)
Declaration
public void CopyTo(GraphicComponent[] array, int index)
Parameters
CopyTo(Array, Int32)
Declaration
public virtual void CopyTo(Array array, int index)
Parameters
GetEnumerator()
Declaration
public virtual IEnumerator GetEnumerator()
Returns
Remove(GraphicComponent)
Declaration
public void Remove(GraphicComponent collisionObject)
Parameters
Examples
Remove CollisionObject.
public void CollisionDetection()
{
Project.UndoContext.BeginUndoStep("CollisionDetection");
try
{
Station station = Station.ActiveStation;
#region CollisionDetectionPoint1
// Create two parts and bodies to use in collision detection.
Part p1 = new Part();
p1.Name = "My Part1";
Part p2 = new Part();
p2.Name = "My Part2";
station.GraphicComponents.Add(p1);
station.GraphicComponents.Add(p2);
#endregion
// Create two boxes.
Body box1 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box1.Name = "My Box1";
Body box2 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box2.Name = "My Box2";
// Move box2 0.105 meters along the X-axis .
box2.Transform.X = box2.Transform.X + 0.105;
// Add the boxes to the bodies.
p1.Bodies.Add(box1);
p2.Bodies.Add(box2);
// Manually check to see if there is a collision between the two parts.
// Also tests for a near miss, defined as being within 0.01 meter from each other.
#region CollisionDetectionPoint2
CollisionType colType = CollisionDetector.CheckCollision(p1, p2, 0.01);
switch (colType)
{
case CollisionType.Collision:
Logger.AddMessage(new LogMessage("Part: " + p1.Name
+ " and part: " + p2.Name + " is colliding!"));
break;
case CollisionType.NearMiss:
Logger.AddMessage(new LogMessage("There is a near miss between part: "
+ p1.Name
+ " and part: " + p2.Name + "."));
Vector3 p1Point;
Vector3 p2Point;
Logger.AddMessage(new LogMessage("The distance between them are: "
+ CollisionDetector.MinimumDistance(p1, p2, out p1Point, out p2Point)));
Logger.AddMessage(new LogMessage("The closest points are: "));
Logger.AddMessage(new LogMessage("For part: " + p1.Name + " x: " + p1Point.x
+ " y: " + p1Point.y + " z: " + p1Point.z));
Logger.AddMessage(new LogMessage("For part: " + p2.Name + " x: " + p2Point.x
+ " y: " + p2Point.y + " z: " + p2Point.z));
break;
case CollisionType.None:
Logger.AddMessage(new LogMessage("There is no collision!"));
break;
}
#endregion
// Reset the collision sets and highlights.
CollisionDetector.ResetCollisions();
// Add an event handler to the collision event.
CollisionDetector.Collision += new CollisionEventHandler(myCollisionEventHandler);
// Activate auto check for collisions each time the graphics is updated.
CollisionDetector.AutoCheck = true;
// Test for collisions on polygon level, not just for the bounding boxes.
CollisionDetector.FastCheck = false;
#region CollisionDetectionPoint3
// Add the two boxes to a collision set.
CollisionSet cs = new CollisionSet();
cs.Name = "My CollisionSet";
// Set the near miss distance to 0.01 meters.
cs.NearMissDistance = 0.01;
// Set the near miss color to black.
cs.NearMissColor = System.Drawing.Color.Black;
// Activate this collision set for collision checks.
cs.Active = true;
// Set the collision color to semi-transparent yellow.
cs.CollisionColor = Color.FromArgb(128, System.Drawing.Color.Yellow);
// Turn on highlighting of colliding objects.
cs.Highlight = true;
// Add the collision set to the station.
station.CollisionSets.Add(cs);
// Add the two parts to the two different collision object collections of the collision set.
cs.FirstGroup.Add(p1);
cs.SecondGroup.Add(p2);
#endregion
#region CollisionDetectionPoint4
// Force check the station for collisions.
CollisionDetector.CheckCollisions(station);
// Force check the collision set for collisiosn.
CollisionDetector.CheckCollisions(cs);
#endregion
// Freehand move the boxes in the graphics.
// Notice the messages generated by the event handler code,
// and the change in color of the boxes.
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
private void myCollisionEventHandler(object sender, CollisionEventArgs e)
{
switch (e.CollisionEvent)
{
case CollisionEvent.CollisionStarted:
Logger.AddMessage
(new LogMessage("Collision started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.CollisionEnded:
Logger.AddMessage(new LogMessage("Collision ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissStarted:
Logger.AddMessage(new LogMessage("Near Miss started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissEnded:
Logger.AddMessage(new LogMessage("Near Miss ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '"
+ e.FirstPart.Name + "' Second part: '" + e.SecondPart.Name + "'"));
break;
default:
break;
}
}
ToArray()
Declaration
public GraphicComponent[] ToArray()
Returns