private void primitivesPalette_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { paletteElement = sender as IInputElement; logger.Log("Primitives palette left mouse down " + paletteElement, Category.Debug, Priority.None); if (sender == cylinderThumb) { palettePrimitiveKind = PrimitiveKinds.Cylinder; } else if (sender == coneThumb) { palettePrimitiveKind = PrimitiveKinds.Cone; } else if (sender == sphereThumb) { palettePrimitiveKind = PrimitiveKinds.Sphere; } else if (sender == sgcThumb) { palettePrimitiveKind = PrimitiveKinds.SGC; } else if (sender == bgcThumb) { palettePrimitiveKind = PrimitiveKinds.BGC; } else if (sender == cubeThumb) { palettePrimitiveKind = PrimitiveKinds.Cuboid; } else { logger.Log("Invalid event sender", Category.Exception, Priority.High); } bool captureSucceeded = paletteElement.CaptureMouse(); if (!captureSucceeded) { logger.Log("Unable to capture mouse by a palette element " + sender, Category.Exception, Priority.None); } }
public NewPrimitive AddNewPrimitive(PrimitiveKinds primitiveKind, LineRange lineRange) { var pos3d = uiState.SketchPlane.PointFromRay(lineRange); if (pos3d != null) { undoHistory.Push(); switch (primitiveKind) { case PrimitiveKinds.Cylinder: var newCylinder = new NewCylinder(); newCylinder.Center.Value = pos3d.Value; newCylinder.Axis.Value = sketchPlane.YAxis; newCylinder.Diameter.Value = 0.2; newCylinder.Length.Value = 0.3; sessionData.NewPrimitives.Add(newCylinder); break; case PrimitiveKinds.Cone: var newCone = new NewCone(); newCone.Center.Value = pos3d.Value; newCone.Axis.Value = sketchPlane.YAxis; newCone.TopRadius.Value = 0.1; newCone.BottomRadius.Value = 0.2; newCone.Length.Value = 0.3; sessionData.NewPrimitives.Add(newCone); break; case PrimitiveKinds.Sphere: var newSphere = new NewSphere(); newSphere.Center.Value = pos3d.Value; newSphere.Radius.Value = 0.2; sessionData.NewPrimitives.Add(newSphere); break; case PrimitiveKinds.SGC: var newSGC = new NewStraightGenCylinder(); newSGC.Center.Value = pos3d.Value; newSGC.Axis.Value = sketchPlane.YAxis; newSGC.Length.Value = 0.3; newSGC.Components = SgcComponents.CreateNonLinear(20, 0.075, 0.05, 0.1); sessionData.NewPrimitives.Add(newSGC); break; case PrimitiveKinds.BGC: var newBGC = new NewBendedGenCylinder(); newBGC.Center.Value = pos3d.Value; newBGC.Axis.Value = sketchPlane.YAxis; newBGC.Length.Value = 0.3; newBGC.Components = BgcComponents.Create(20, 0.075, 0.15, newBGC.Center.Value, newBGC.Axis.Value, newBGC.Length.Value); sessionData.NewPrimitives.Add(newBGC); break; case PrimitiveKinds.Cuboid: var newCuboid = new NewCuboid(); Vector3D H = new Vector3D(0, 1, 0); Vector3D W = new Vector3D(1, 0, 0); Vector3D D = new Vector3D(0, 0, -1); newCuboid.Center.Value = pos3d.Value; newCuboid.H.Value = H; newCuboid.W.Value = W; newCuboid.D.Value = D; newCuboid.Width.Value = 0.3; newCuboid.Height.Value = 0.3; newCuboid.Depth.Value = 0.3; sessionData.NewPrimitives.Add(newCuboid); break; default: Trace.Fail("Invalid primitive kind"); break; } sessionData.NewPrimitives.Last().UpdateCurvesGeometry(); return(sessionData.NewPrimitives.Last()); } else { return(null); } }