public void DrawZone(RsMechanicalUnit mechanicalUnit) { // Draw a part that cointaions a body (cylinder) Part part = new Part(); Body cylinder = Body.CreateSolidCylinder(new Matrix4(new Vector3()), Decimal.ToDouble(_dimensions.Radius / 1000), Decimal.ToDouble(_dimensions.Height / 1000)); cylinder.Color = System.Drawing.Color.Purple; part.Bodies.Add(cylinder); // Get the base frame and modify only the translation part, this way the cylinder orientation is the same as the robots orientation Matrix4 cylinderMatrix = mechanicalUnit.BaseFrame.GlobalMatrix; cylinderMatrix.Translation = new Vector3(_dimensions.x, _dimensions.y, _dimensions.z); // Drawing a temporary graphic requires it to be present in the station, therefore the part is added prior to it being drawn as a temorary graphic // then immedietely removed from the station Station.ActiveStation.GraphicComponents.Add(part); TemporaryGraphic tg = Station.ActiveStation.TemporaryGraphics.DrawPart(cylinderMatrix, part, 0.3d); Station.ActiveStation.GraphicComponents.Remove(part); if (_CylinderGraphic != null) { Station.ActiveStation.TemporaryGraphics.Remove(_CylinderGraphic); _CylinderGraphic.Delete(); } _CylinderGraphic = tg; }
public string CreateRapidZone(RsMechanicalUnit mechanicalUnit) { if (_boxGraphic == null) { return(""); } // Get the translation of p1 in world coordinate system Matrix4 p1Matrix = _boxGraphic.Matrix; // Calculate the translation of p2 in world coordinate system Matrix4 p2Matrix = p1Matrix; p2Matrix.TranslateLocal(Decimal.ToDouble(_dimensions.Length / 1000), Decimal.ToDouble(_dimensions.Width / 1000), Decimal.ToDouble(_dimensions.Height / 1000)); // Transform to robot coordinate system p1Matrix.Translation = p1Matrix.Translation.TransformPoint(Station.ActiveStation.Transform.GlobalMatrix, mechanicalUnit.BaseFrame.GlobalMatrix); p2Matrix.Translation = p2Matrix.Translation.TransformPoint(Station.ActiveStation.Transform.GlobalMatrix, mechanicalUnit.BaseFrame.GlobalMatrix); string rapidZone = "["; rapidZone += (p1Matrix.Translation.x * 1000).ToString("0.00", CultureInfo.InvariantCulture) + ","; rapidZone += (p1Matrix.Translation.y * 1000).ToString("0.00", CultureInfo.InvariantCulture) + ","; rapidZone += (p1Matrix.Translation.z * 1000).ToString("0.00", CultureInfo.InvariantCulture) + "],["; rapidZone += (p2Matrix.Translation.x * 1000).ToString("0.00", CultureInfo.InvariantCulture) + ","; rapidZone += (p2Matrix.Translation.y * 1000).ToString("0.00", CultureInfo.InvariantCulture) + ","; rapidZone += (p2Matrix.Translation.z * 1000).ToString("0.00", CultureInfo.InvariantCulture) + "]"; return(rapidZone); }
public void DrawZone(RsMechanicalUnit mechanicalUnit) { // Draw a part that cointaions a body (sphere) Part part = new Part(); Body sphere = Body.CreateSolidSphere(new Vector3(), Decimal.ToDouble(_dimensions.Radius / 1000)); sphere.Color = System.Drawing.Color.Purple; part.Bodies.Add(sphere); // Drawing a temporary graphic requires it to be present in the station, therefore the part is added prior to it being drawn as a temorary graphic // then immedietely removed from the station Matrix4 spherePosition = new Matrix4(new Vector3(_dimensions.x, _dimensions.y, _dimensions.z)); Station.ActiveStation.GraphicComponents.Add(part); TemporaryGraphic tg = Station.ActiveStation.TemporaryGraphics.DrawPart(spherePosition, part, 0.3); Station.ActiveStation.GraphicComponents.Remove(part); if (_sphereGraphic != null) { Station.ActiveStation.TemporaryGraphics.Remove(_sphereGraphic); _sphereGraphic.Delete(); } _sphereGraphic = tg; }
private void ZoneDimensionsChanged(object sender, ZoneDimensions.DimensionsChangedEventArgs args) { if (RobotCombobox.SelectedItem != null) { RsMechanicalUnit mechUnit = RobotCombobox.SelectedItem as RsMechanicalUnit; args.zone.DrawZone(mechUnit); args.oldZone?.DeleteZone(); InstructionRichTextBox.Text = args.zone.CreateRapidZone(mechUnit); } else { Logger.AddMessage("WZcalculator: Invalid selection", true); } }
private void ProjectObjectChanged(object sender, ProjectObjectChangedEventArgs e) { if (e.ChangedObject.GetType() == typeof(Mechanism)) { if (e.ChangeType == ProjectObjectChangeType.Transform) { if (RobotCombobox.SelectedItem != null) { // Recreate the zone with the updated transform RsMechanicalUnit selectedMechUnit = RobotCombobox.SelectedItem as RsMechanicalUnit; zoneDimensions.GetCurrentZone().DrawZone(selectedMechUnit); InstructionRichTextBox.Text = zoneDimensions.GetCurrentZone().CreateRapidZone(selectedMechUnit); } } } }
public string CreateRapidZone(RsMechanicalUnit mechanicalUnit) { if (_sphereGraphic == null) { return(""); } // Transform the position of the sphere to the robots coordinate system Vector3 sphereVector = _sphereGraphic.Matrix.Translation.TransformPoint(Station.ActiveStation.Transform.GlobalMatrix, mechanicalUnit.BaseFrame.GlobalMatrix); // Build the rapid string string rapidZone = "["; rapidZone += (sphereVector.x * 1000).ToString("0.00", CultureInfo.InvariantCulture) + ","; rapidZone += (sphereVector.y * 1000).ToString("0.00", CultureInfo.InvariantCulture) + ","; rapidZone += (sphereVector.z * 1000).ToString("0.00", CultureInfo.InvariantCulture) + "],"; rapidZone += _dimensions.Radius; return(rapidZone); }
public void DrawZone(RsMechanicalUnit mechanicalUnit) { // Find the orientation of the robot base frame Vector3 orientationVector = mechanicalUnit.BaseFrame.GlobalMatrix.EulerZYX; // Create a Matrix4 with the same orientation as the robot base frame and the translation of the first corner of the box Vector3 boxTranslation = new Vector3(_dimensions.x, _dimensions.y, _dimensions.z); Matrix4 boxPosition = new Matrix4(boxTranslation, orientationVector); // Create a Vector3 that contains the dimensions Vector3 dimensionVector = new Vector3() { x = Decimal.ToDouble(_dimensions.Length) / 1000, y = Decimal.ToDouble(_dimensions.Width) / 1000, z = Decimal.ToDouble(_dimensions.Height) / 1000 }; // Draw a part that contains a box (body) Part part = new Part(); Body box = Body.CreateSolidBox(new Matrix4(new Vector3()), dimensionVector); box.Color = Color.Purple; part.Bodies.Add(box); // Drawing a temporary graphic requires it to be present in the station, therefore the part is added prior to it being drawn as a temorary graphic // then immedietely removed from the station Station.ActiveStation.GraphicComponents.Add(part); TemporaryGraphic tg = Station.ActiveStation.TemporaryGraphics.DrawPart(boxPosition, part, 0.3); Station.ActiveStation.GraphicComponents.Remove(part); if (_boxGraphic != null) { Station.ActiveStation.TemporaryGraphics.Remove(_boxGraphic); _boxGraphic.Delete(); } _boxGraphic = tg; }
private void RobotCombobox_SelectedIndexChanged(object sender, EventArgs e) { if (RobotCombobox.SelectedItem != null) { if (_lastSelectedMechUnit != null) { Selection.SelectedObjects.Remove(_lastSelectedMechUnit); } RsMechanicalUnit mech = RobotCombobox.SelectedItem as RsMechanicalUnit; // Recreate the zone with the new robot zoneDimensions.GetCurrentZone().DrawZone(mech); InstructionRichTextBox.Text = zoneDimensions.GetCurrentZone().CreateRapidZone(mech); // Only highlight the robot if the stations cointains more than 1 robots if (RobotCombobox.Items.Count > 1) { Selection.SelectedObjects.Add(mech.Mechanism); _lastSelectedMechUnit = mech.Mechanism; } } }
public string CreateRapidZone(RsMechanicalUnit mechanicalUnit) { if (_CylinderGraphic == null) { return(""); } // Transform cylinder position to the robots coordinate system Vector3 transformedVector = new Vector3(_dimensions.x, _dimensions.y, _dimensions.z); transformedVector = transformedVector.TransformPoint(Station.ActiveStation.Transform.GlobalMatrix, mechanicalUnit.BaseFrame.GlobalMatrix); // Zone is declared as [x,y,z,R,H] where R is radius in mm and H is height in mm string rapidZone = "["; rapidZone += (transformedVector.x * 1000).ToString("0.00", CultureInfo.InvariantCulture) + ","; rapidZone += (transformedVector.y * 1000).ToString("0.00", CultureInfo.InvariantCulture) + ","; rapidZone += (transformedVector.z * 1000).ToString("0.00", CultureInfo.InvariantCulture) + "],"; rapidZone += _dimensions.Radius + ","; rapidZone += _dimensions.Height; return(rapidZone); }