private void DuplicateIfNecessary() { if (originalDuplicate == null) { var primitiveData = PrimitivesPickService.GetPrimitiveData(currentSnappedPrimitive) as SnappedPrimitive; duplicator.DuplicateSnapped(primitiveData, out currentDuplicate, out originalDuplicate); } }
private void primitivesPalette_MouseMove(object sender, MouseEventArgs e) { Debug.WriteLine("Primitives pallette mouse move"); if (paletteElement == null) // this means that the user has not started dragging an element from the palette { return; } if (currentDragStrategy != null) // we are currently doing something else (for example, dragging a primitive over the sketch) { return; // we don't want to do anything while doing something else with the mouse.. surely not to add a new primitive. } Debug.WriteLine("Current drag strategy is null"); var isMouseOverViewportRoot = IsMouseOverViewportRoot(e); // we will add a primitive and transfer the "responsibility" to the primitive drag strategy // so that from now on it handles mouse events if (isMouseOverViewportRoot) { Debug.WriteLine("Mouse is over viewport root"); var pos3d = GetPosition3D(e); if (pos3d.Ray3D == null) { return; } Debug.WriteLine("Successfully got a ray"); // we add a new primitive and pick its visual so that we can later give it to the drag strategy var newPrimitive = viewModel.AddNewPrimitive(palettePrimitiveKind, pos3d.Ray3D.Value); Debug.WriteLine("Successfully locked on the primitive visual"); viewModel.SelectPrimitive(newPrimitive); var primitiveVisual = (from view in sketchModellingView.GetNewPrimitiveViews() let primitiveData = PrimitivesPickService.GetPrimitiveData(view) where object.ReferenceEquals(primitiveData, newPrimitive) select view).First(); // we make the current mouse drag strategy to be the strategy for "new primitive" objects. This strategy // will be used from now on until the primitive is snapped. currentDragStrategy = newPrimitiveDragStrategy; currentDragStrategy.OnMouseDown(GetPosition3D(e), Tuple.Create(primitiveVisual, newPrimitive)); // we transfer the responsibility of capturing subsequent mouse events to the vpRoot paletteElement.ReleaseMouseCapture(); vpRoot.CaptureMouse(); paletteElement = null; } }
public BaseNewPrimitiveView(NewPrimitiveViewModel viewModel, ILoggerFacade logger) { this.viewModel = viewModel; this.logger = logger; translation = new TranslateTransform3D(); scale = new ScaleTransform3D(); rotation = new RotateTransform3D(); Transform = new Transform3DGroup { Children = { rotation, scale, translation } }; PrimitivesPickService.SetPrimitiveData(this, viewModel.Model); }
public Visual3D Create(object item) { Visual3D result = null; item.MatchClass <SnappedCylinder>(cylinderData => result = CreateCylinderView(cylinderData)); item.MatchClass <SnappedCone>(coneData => result = CreateConeView(coneData)); item.MatchClass <SnappedSphere>(sphereData => result = CreateSphereView(sphereData)); item.MatchClass <SnappedStraightGenCylinder>(sgc => result = CreateSgcView(sgc)); item.MatchClass <SnappedBendedGenCylinder>(bgc => result = CreateBgcView(bgc)); item.MatchClass <SnappedCuboid>(cuboidData => result = CreateCuboidView(cuboidData)); Contract.Assume(result != null); PrimitivesPickService.SetPrimitiveData(result, item as SnappedPrimitive); return(result); }
private void vpRoot_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (currentDragStrategy == null) { var positionInfo = GetPosition3D(e); var primitiveVisual = PrimitivesPickService.PickPrimitiveVisual(viewport3d, positionInfo.Pos2D); if (primitiveVisual != null) { var primitiveData = PrimitivesPickService.GetPrimitiveData(primitiveVisual); viewModel.SelectPrimitive(primitiveData); primitiveData.MatchClass <NewPrimitive>(_ => currentDragStrategy = newPrimitiveDragStrategy); primitiveData.MatchClass <SnappedPrimitive>(_ => currentDragStrategy = snappedDragStrategy); Debug.Assert(currentDragStrategy != null); currentDragStrategy.OnMouseDown(GetPosition3D(e), Tuple.Create(primitiveVisual, primitiveData)); vpRoot.CaptureMouse(); } else { viewModel.UnselectPrimitives(); } } }