/// <summary> /// Function retrieves the point around which the connector will be drawn. /// </summary> /// <param name="c">Connector that wants to draw itself</param> /// <returns>Point where the connector should be drawn /// </returns> public override PointF ConnectionPoint(Connector c) { //counting the y coordinate of the middle of the box float middle = (Rectangle.Bottom - Rectangle.Top)/2 + Rectangle.Top; if (c == OutputConnector) //for the output connector //returns the middle of the box return new PointF(Rectangle.Right, middle); else { FerdaConstants constants = new FerdaConstants(); PointF cPoint = new PointF(0,0); //checking which connector was calling the function int whichConnector = -1; for (int i = 0; i < InputConnectors.Count; i++ ) { if ( c == InputConnectors[i] ) { whichConnector = i; break; } } //exception, if anything goes wrong if ( whichConnector == -1 ) throw new ApplicationException("KrabickaNode.ConnectionPoint : no connector recognized"); //counting which connector is in da middle //!!!! counting from 1 (not from 0) int middleConnector; if ( (InputConnectors.Count/2) == ( (float) InputConnectors.Count/2) ) middleConnector = InputConnectors.Count/2; else middleConnector = InputConnectors.Count/2 + 1; //changing to count from 0 middleConnector--; //setting the y coordinate cPoint.Y = middle + (whichConnector - middleConnector)* (constants.ConnectorGap + constants.ConnectorSize); //setting the x coordinate cPoint.X = Rectangle.Left - constants.ConnectorLeftOffset; return cPoint; } }
/// <summary> /// Default constructor for the class /// </summary> /// <remarks> /// Parametrem by se mohlo predavat jmeno vystupniho konektoru. /// Problem bude s resenim vystupniho konenktoru, pro ktery vlastne /// neni socket ale pozaduje SVG (bud kreslit natvrdo, nebo udelat /// v IBoxModule pro to nejaky zvlastni socket /// </remarks> /// <param name="site">Interface of a graph site (control) /// </param> /// <param name="box">Box that is connected with this node</param> /// <param name="resM">Resource manager of the application</param> /// <param name="svgman">Provider of svg images</param> /// <param name="view">View where this box is located</param> public BoxNode(IGraphSite site, ModulesManager.IBoxModule box, SVGManager svgman, ProjectManager.View view, ResourceManager resM) : base(site) { FerdaConstants constants = new FerdaConstants(); //filling the node this.box = box; this.svgManager = svgman; this.ResManager = resM; //determining the size Rectangle = new RectangleF(0, 0, constants.KrabickaWidth, constants.KrabickaHeight); //adding the output connector //it is not a FerdaConnector, because the box has no socket defined outputConnector = new Connector(this, ResManager.GetString("PropertiesOutputConnector"), true); Connectors.Add(outputConnector); outputConnector.ConnectorLocation = ConnectorLocations.East; //adding the input connectors inputConnectors = new ConnectorCollection(); for (int i = 0; i < box.Sockets.Length; i++) { bool packed = view.IsAnyBoxPackedIn(box, box.Sockets[i].name); inputConnectors.Add( new FerdaConnector(this, svgManager, box.Sockets[i], packed)); Connectors.Add(inputConnectors[i]); inputConnectors[i].ConnectorLocation = ConnectorLocations.West; } //getting the bitmap bitmap = svgManager.GetBoxBitmap(box); //setting the view this.view = view; //adding the moving handler OnMouseDown += new MouseEventHandler(BoxNode_OnMouseDown); OnMouseUp += new MouseEventHandler(BoxNode_OnMouseUp); Resizable = false; this.Text = box.UserName; //using a smaller font - we have big labels mFont = new Font(mFontFamily, 7, FontStyle.Regular, GraphicsUnit.Point); }