Exemple #1
0
 public GraphicalConnection(GraphicalModule source, GraphicalModule dest,
                            Data.CallerSlot sourceSlot, Data.CalleeSlot destSlot, Data.Call call)
 {
     src           = source;
     this.dest     = dest;
     srcSlot       = sourceSlot;
     this.destSlot = destSlot;
     theCall       = call;
 }
 internal Point GetTipLocation(Data.CalleeSlot destSlot)
 {
     if (myModule.CalleeSlots != null)
     {
         for (int x = 0; x < myModule.CalleeSlots.Count(); x++)
         {
             if (myModule.CalleeSlots[x] == destSlot)
             {
                 return(GetCalleeTipLocation(x));
             }
         }
     }
     return(new Point());
 }
        internal bool IsSlotHit(Point point, out Data.CalleeSlot outCe, out Data.CallerSlot outCr, out Point tipLocation)
        {
            outCe       = null;
            outCr       = null;
            tipLocation = new Point();
            if (myModule.CallerSlots != null)
            {
                for (int x = 0; x < myModule.CallerSlots.Count(); x++)
                {
                    Data.CallerSlot cr = myModule.CallerSlots[x];
                    Rectangle       r  = new Rectangle(bounds.Width + Position.X - slotWidth, Position.Y + moduleBorder + x * slotSpacing + slotBorder,
                                                       slotWidth * 2, slotHeight);
                    if (r.Contains(point))
                    {
                        selectedCaller = cr;
                        outCr          = cr;
                        tipLocation    = GetCallerTipLocation(x);
                        //Form1.FireSlotSelected(this, cr.Name, cr.CompatibleCalls);
                        return(true);
                    }
                }
            }

            if (myModule.CalleeSlots != null)
            {
                for (int x = 0; x < myModule.CalleeSlots.Count(); x++)
                {
                    Data.CalleeSlot ce = myModule.CalleeSlots[x];
                    Rectangle       r  = new Rectangle(Position.X - slotWidth, Position.Y + moduleBorder + x * slotSpacing + slotBorder,
                                                       slotWidth * 2, slotHeight);
                    if (r.Contains(point))
                    {
                        selectedCallee = ce;
                        //Form1.FireSlotSelected(this, ce.Name, ce.CompatibleCalls);
                        tipLocation = GetCalleeTipLocation(x);
                        outCe       = ce;
                        return(true);
                    }
                }
            }
            return(false);
        }
        public void Draw(Graphics g)
        {
            string name = myModule.Name + "\n" + this.Name;

            if (!boundsCalculated)
            {
                textBounds   = g.MeasureString(name, moduleNameFont);
                bounds.Width = (int)(textBounds.Width + moduleBorder * 2);
                int c1 = myModule.CalleeSlots == null ? 0 : myModule.CalleeSlots.Count();
                int c2 = myModule.CallerSlots == null ? 0 : myModule.CallerSlots.Count();
                bounds.Height    = Math.Max(Math.Max(c1, c2) * slotSpacing, (int)textBounds.Height) + moduleBorder * 2;
                boundsCalculated = true;
            }
            g.FillRectangle(moduleRectBrush, new Rectangle(Position, Bounds));

            RectangleF textRect = new RectangleF(Position.X + (bounds.Width - textBounds.Width) / 2,
                                                 Position.Y + (bounds.Height - textBounds.Height) / 2,
                                                 textBounds.Width, textBounds.Height);

            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
            g.DrawString(myModule.Name, moduleClassFont, moduleNameBrush, textRect, moduleClassFormat);
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
            g.DrawString(this.Name, moduleNameFont, moduleNameBrush, textRect, moduleNameFormat);

            if (Form1.isMainView(this))
            {
                g.DrawRectangle(Pens.Black, Position.X + moduleBorder / 2, Position.Y + moduleBorder / 2, Bounds.Width - moduleBorder, Bounds.Height - moduleBorder);
            }

            if (Form1.selectedModule == this)
            {
                g.DrawRectangle(selectedModulPen2, Position.X, Position.Y, Bounds.Width, Bounds.Height);
                g.DrawRectangle(selectedModulPen1, Position.X, Position.Y, Bounds.Width, Bounds.Height);
            }

            if (myModule.CallerSlots != null)
            {
                for (int x = 0; x < myModule.CallerSlots.Count(); x++)
                {
                    Data.CallerSlot cr = myModule.CallerSlots[x];

                    Point[] ps = new Point[3] {
                        new Point(bounds.Width + Position.X - slotWidth,
                                  Position.Y + moduleBorder + x * slotSpacing + slotBorder),
                        new Point(bounds.Width + Position.X + slotWidth,
                                  Position.Y + moduleBorder + x * slotSpacing + slotBorder + slotHeight / 2),
                        new Point(bounds.Width + Position.X - slotWidth,
                                  Position.Y + moduleBorder + x * slotSpacing + slotBorder + slotHeight)
                    };
                    //Point[] psScaled = new Point[3] {
                    //    new Point(bounds.Width + Position.X - (int)(slotWidth * slotScale),
                    //        Position.Y + moduleBorder + x * slotSpacing + slotBorder - (int)(slotScale * slotHeight / 2)),
                    //    new Point(bounds.Width + Position.X + (int)(slotWidth * slotScale),
                    //        Position.Y + moduleBorder + x * slotSpacing + slotBorder),
                    //    new Point(bounds.Width + Position.X - (int)(slotWidth * slotScale),
                    //        Position.Y + moduleBorder + x * slotSpacing + slotBorder + (int)(slotScale * slotHeight / 2))
                    //};
                    if (Form1.selectedCaller == cr && Form1.selectedModule != null && this.Name == Form1.selectedModule.Name)
                    {
                        g.FillPolygon(selectedSlotBrush, ps);
                    }
                    else if (Form1.selectedCallee != null && Form1.selectedCallee.CompatibleCalls.Intersect(cr.CompatibleCalls).Count() > 0)
                    {
                        g.FillPolygon(callerBrush, ps);
                        g.DrawPolygon(compatibleSlotBorder, ps);
                    }
                    else
                    {
                        g.FillPolygon(callerBrush, ps);
                    }
                }
            }

            if (myModule.CalleeSlots != null)
            {
                for (int x = 0; x < myModule.CalleeSlots.Count(); x++)
                {
                    Data.CalleeSlot ce = myModule.CalleeSlots[x];
                    Point[]         ps = new Point[3] {
                        new Point(Position.X - slotWidth, Position.Y + moduleBorder + x * slotSpacing + slotBorder),
                        new Point(Position.X + slotWidth, Position.Y + moduleBorder + x * slotSpacing + slotBorder + slotHeight / 2),
                        new Point(Position.X - slotWidth, Position.Y + moduleBorder + x * slotSpacing + slotBorder + slotHeight)
                    };
                    if (Form1.selectedCallee == ce && Form1.selectedModule != null && this.Name == Form1.selectedModule.Name)
                    {
                        g.FillPolygon(selectedSlotBrush, ps);
                    }
                    else if (Form1.selectedCaller != null && Form1.selectedCaller.CompatibleCalls.Intersect(ce.CompatibleCalls).Count() > 0)
                    {
                        g.FillPolygon(calleeBrush, ps);
                        g.DrawPolygon(compatibleSlotBorder, ps);
                    }
                    else
                    {
                        g.FillPolygon(calleeBrush, ps);
                    }
                }
            }
        }