Пример #1
0
        /// <summary>
        /// The ghost gate to be drawn and added to the Sketch. The ghost gates are tracked in
        /// Edit Menu in currGhosts. It delegates when to draw and undraw these. The Ghosts have
        /// the shape that is associated with it so that it can update Orientation.
        ///
        /// Also the name Ghost gate is super cool
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="SketchPanel"></param>
        public GhostGate(Sketch.Shape shape, ref SketchPanelLib.SketchPanel SketchPanel, ref GateDrawing.GateDrawing gateDrawer)
        {
            //initialize everything
            startPoint = new System.Windows.Point();
            endPoint   = new System.Windows.Point();

            subscribed = false;

            if (!Domain.LogicDomain.IsGate(shape.Type))
            {
                return;
            }

            myShape = shape;

            // Make the desired image
            GeometryDrawing ghostGate = gateDrawer.DrawGate(myShape.Type, myShape.Bounds, false, true, myShape.Orientation);

            System.Windows.Media.DrawingImage drawingImage = new System.Windows.Media.DrawingImage(ghostGate);
            relabelImage        = new System.Windows.Controls.Image();
            relabelImage.Source = drawingImage;

            sketchPanel = SketchPanel;

            drawingAdvice = createDrawingAdvice(ref gateDrawer);

            //Actual adding of the image
            InkCanvas.SetLeft(relabelImage, myShape.Bounds.Left);
            InkCanvas.SetTop(relabelImage, myShape.Bounds.Top);

            sketchPanel.InkCanvas.Children.Add(relabelImage);
            sketchPanel.InkCanvas.Children.Add(drawingAdvice);
        }
        private Rect centerDrawing()
        {
            removeGate();
            Rect bounds;

            if (gateChooser.SelectedItem == defaultChoice || (string)((ComboBoxItem)gateChooser.SelectedItem).Content == freehandString)
            {
                gate = null;
                return(new Rect());
            }

            gate = LogicDomain.getType((string)((ComboBoxItem)(gateChooser.SelectedItem)).Content);

            // Bounds are currently arbitrary, place shape template in the middle of canvas
            if (gate != LogicDomain.NOTBUBBLE)
            {
                bounds = new Rect(inkCanvas.Width / 2 - GATE_WIDTH / 2, inkCanvas.Height / 2 - GATE_HEIGHT / 2, GATE_WIDTH, GATE_HEIGHT);
            }
            else
            {
                bounds = new Rect(inkCanvas.Width / 2 - NOTBUBBLE_DIAMETER / 2, inkCanvas.Height / 2 - NOTBUBBLE_DIAMETER / 2, NOTBUBBLE_DIAMETER, NOTBUBBLE_DIAMETER);
            }


            // This is so NANDs look like ANDs with NOTBUBBLEs
            // Same goes for all gates in the OR family
            if (gate == LogicDomain.AND)
            {
                bounds.Width = bounds.Width - bounds.Width / 4;
            }
            else if (gate == LogicDomain.OR)
            {
                bounds.Width = bounds.Width - bounds.Width / 6 - bounds.Width / 4;
            }
            else if (gate == LogicDomain.NOR)
            {
                bounds.Width = bounds.Width - bounds.Width / 6;
            }
            else if (gate == LogicDomain.XOR)
            {
                bounds.Width = bounds.Width - bounds.Width / 4;
            }

            DrawingImage drawingImage = new DrawingImage(gateDrawer.DrawGate(gate, bounds, false, true));

            gateImage        = new Image();
            gateImage.Source = drawingImage;

            InkCanvas.SetLeft(gateImage, bounds.Left);
            InkCanvas.SetTop(gateImage, bounds.Top);

            inkCanvas.Children.Add(gateImage);
            return(bounds);
        }
Пример #3
0
        /// <summary>
        /// Re-render the ghost using the given orientation.
        /// </summary>
        /// <param name="newOrientation"></param>
        private void rotateGhostTo(double newOrientation)
        {
            // It makes no sense to lock the drawing ratio if this is a subcircuit
            bool shouldLock = this.gateDrawer.LockDrawingRatio;

            if (shape.Type == Domain.LogicDomain.SUBCIRCUIT)
            {
                gateDrawer.LockDrawingRatio = false;
            }

            GeometryDrawing ghostGate = gateDrawer.DrawGate(shape.Type, shape.Bounds, false, true, newOrientation);

            gateDrawer.LockDrawingRatio = shouldLock;

            DrawingImage drawingImage = new DrawingImage(ghostGate);

            relabelImage.Source = drawingImage;
            removeIO();
            addIO(newOrientation);
        }
Пример #4
0
        /// <summary>
        /// The ghost gate to be drawn and added to the Sketch. The ghost gates are tracked in
        /// Edit Menu in currGhosts. It delegates when to draw and undraw these. The Ghosts have
        /// the shape that is associated with it so that it can update Orientation.
        ///
        /// Also the name Ghost gate is super cool
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="SketchPanel"></param>
        public GhostGate(Sketch.Shape shape, ref SketchPanelLib.SketchPanel sketchPanel,
                         ref GateDrawing.GateDrawing gateDrawer, GateRotatedHandler gateRotated, KeyValuePair <List <string>, List <string> > IO = new KeyValuePair <List <string>, List <string> >())
        {
            // Initialize everything
            startPoint          = new System.Windows.Point();
            endPoint            = new System.Windows.Point();
            subscribed          = false;
            this.shape          = shape;
            this.sketchPanel    = sketchPanel;
            this.gateDrawer     = gateDrawer;
            this.gateRotated    = gateRotated;
            this.SubCircuitDock = new DockPanel();
            this.IO             = IO;

            if (!Domain.LogicDomain.IsGate(shape.Type))
            {
                return;
            }

            // It makes no sense to lock the drawing ratio if this is a subcircuit, but we need to set it back to normal after
            bool shouldLock = this.gateDrawer.LockDrawingRatio;

            if (shape.Type == Domain.LogicDomain.SUBCIRCUIT)
            {
                gateDrawer.LockDrawingRatio = false;
            }

            // Make the desired image
            GeometryDrawing ghostGate = gateDrawer.DrawGate(shape.Type, shape.Bounds, false, true, shape.Orientation);

            // Make textbox to go with the image
            Popup     popup     = new Popup();
            TextBlock popupText = new TextBlock();

            popupText.Text           = gateDrawer.DrawingAdvice;
            popupText.TextWrapping   = System.Windows.TextWrapping.Wrap;
            popupText.Background     = Brushes.Pink;
            popupText.Foreground     = Brushes.Black;
            popup.Child              = popupText;
            popup.IsOpen             = false;
            popup.AllowsTransparency = true;
            popup.Visibility         = System.Windows.Visibility.Visible;
            popup.PlacementTarget    = sketchPanel.InkCanvas;
            popup.Placement          = PlacementMode.RelativePoint;
            popup.HorizontalOffset   = 20;
            popup.VerticalOffset     = 50;
            drawingAdvice            = popup;

            gateDrawer.LockDrawingRatio = shouldLock;

            DrawingImage drawingImage = new DrawingImage(ghostGate);

            relabelImage        = new System.Windows.Controls.Image();
            relabelImage.Source = drawingImage;
            relabelImage.Width  = drawingImage.Width;
            relabelImage.Height = drawingImage.Height;

            // Actually add the image
            InkCanvas.SetLeft(relabelImage, shape.Bounds.Left);
            InkCanvas.SetTop(relabelImage, shape.Bounds.Top);

            // If it's a subcircuit we need to display the name and where inputs/ouputs should be
            if (shape.Type == Domain.LogicDomain.SUBCIRCUIT)
            {
                addIO(shape.Orientation);
            }

            sketchPanel.InkCanvas.Children.Add(relabelImage);
            sketchPanel.InkCanvas.Children.Add(drawingAdvice);
        }