Exemplo n.º 1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="panel"> The panel that this Manager controls</param>
        /// <param name="ld"> The domain for labeling strokes</param>
        public DisplayManager(ref SketchPanelLib.SketchPanel panel, EndPointMovedHandler endPointChange,
                              GateRotatedHandler gateRotated, bool ColorStrokes = true)
        {
            this.panel = panel;

            // Add and configure feedback
            circuitColorFeedback    = new ColorFeedback(ref panel);
            circuitMeshFeedback     = new MeshHighlightingFeedback(ref panel);
            circuitEndpointFeedback = new EndPointHighlightFeedback(ref panel, endPointChange);
            ghostGateFeedback       = new GhostGateFeedback(ref panel, gateRotated);
            currentErrors           = new List <ErrorBoxHelp>();
            //circuitParseErrorFeedback = new ParseErrorFeedback(panel);
            displayLabelTool = new DisplayLabelTool(ref panel);
            displayHelpTool  = new DisplayHelpTool(ref panel);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor.  Makes gate drawer, initializes lists, subscribes to supplied panel
        /// </summary>
        /// <param name="parent"></param>
        public GhostGateFeedback(ref SketchPanel parent, GateRotatedHandler gateRotated)
            : base(ref parent)
        {
            // Set up gate drawer
            gateDrawer                  = new GateDrawing.GateDrawing();
            gateDrawer.RotateGates      = true;
            gateDrawer.SnapRotation     = false;
            gateDrawer.LockDrawingRatio = true;
            this.gateRotated            = gateRotated;


            // Initialize our list of ghosts
            this.currGhosts = new List <GhostGate>();

            ShapeToIO   = new Dictionary <Sketch.Shape, KeyValuePair <List <string>, List <string> > >();
            ShapeToGate = new Dictionary <Shape, GhostGate>();

            displayHelpTool = new DisplayHelpTool(ref sketchPanel);

            SubscribeToPanel();
        }
Exemplo n.º 3
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);
        }