Exemplo n.º 1
0
        /// <summary>
        /// Initializes the drag.
        /// </summary>
        public void InitializeDrag(IInputModeContext context)
        {
            var imc = context.Lookup <IModelItemCollector>();

            if (imc != null)
            {
                imc.Add(node);
            }
            rotationCenter = node.Layout.GetCenter();
            initialAngle   = GetAngle();

            var graph = context.Lookup <IGraph>();

            if (graph != null)
            {
                compoundEdit = graph.BeginEdit("Change Rotation Angle", "Change Rotation Angle");
            }

            portHandles.Clear();
            var portContext = new DelegatingContext(context);

            foreach (var port in node.Ports)
            {
                var portHandle = new DummyPortLocationModelParameterHandle(port);
                portHandle.InitializeDrag(portContext);
                portHandles.Add(portHandle);
            }
            if (reshapeHandler != null)
            {
                reshapeHandler.InitializeReshape(context);
            }
            // Collect other visible nodes and their angles
            if (SnapToSameAngleDelta > 0)
            {
                var canvas       = context.CanvasControl;
                var rotatedNodes =
                    canvas.GetCanvasObjects()
                    .Select(co => co.UserObject)
                    // only collect nodes
                    .OfType <INode>()
                    // ... that are in the viewport
                    .Where(n => canvas.Viewport.Intersects(n.Layout.ToRectD()))
                    // ... and can be rotated
                    .Where(n => n.Style is RotatableNodeStyleDecorator)
                    // ... and are not *this* node
                    .Where(n => n != node);
                // Group nodes by identical angles
                nodeAngles =
                    rotatedNodes.GroupBy(n => ((RotatableNodeStyleDecorator)n.Style).Angle)
                    .Select(nodes => Tuple.Create(nodes.Key, nodes.ToList().AsEnumerable())).ToList();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Stores the initial layout of the node in case the user cancels the resizing.
        /// </summary>
        /// <param name="inputModeContext"></param>
        public void InitializeDrag(IInputModeContext inputModeContext)
        {
            if (reshapeHandler != null)
            {
                // if there is a reshape handler: initialize to
                // ensure proper handling of a parent group node
                reshapeHandler.InitializeReshape(inputModeContext);
            }
            initialLayout.Reshape(GetNodeBasedOrientedRectangle());
            dummyLocation = initialLayout.GetAnchorLocation();
            dummySize     = initialLayout.GetSize();
            initialRect   = node.Layout.ToRectD();

            portHandles.Clear();
            var portContext = new DelegatingContext(inputModeContext);

            foreach (var port in node.Ports)
            {
                var portHandle = new DummyPortLocationModelParameterHandle(port);
                portHandle.InitializeDrag(portContext);
                portHandles.Add(portHandle);
            }
        }