connectorshape connect shapes Nicole Scholz How can I connect shapes?

How can shapes be connected with other shapes or with themselves?

In this example rectangles are connected with other rectangles and a recgtangle and a cirlcle are connected with themselves.

/* Retrieve the Desktop object, we need its XComponentLoader interface to load a new document*/ oDesktop = UNO.createDesktop() -- get the UNO Desktop service object xComponentLoader = oDesktop~{%see com.sun.star.frame.XDesktop%XDesktop}~{%see com.sun.star.frame.XComponentLoader%XComponentLoader} -- get componentLoader interface */ /* open the blank *.sxd - file */ url = "private:factory/sdraw" xDrawComponent = xComponentLoader~loadComponentFromURL(url, "_blank", 0, - .UNO~noProps) /* need document's factory to be able to insert created objects */ xDocumentFactory = xDrawComponent~{%see com.sun.star.lang.XMultiServiceFactory%XMultiServiceFactory} /* get draw page by index */ xDrawPage = xDrawComponent~{%see com.sun.star.drawing.XDrawPagesSupplier%XDrawPagesSupplier}~getDrawPages~getByIndex(0)~{%see com.sun.star.drawing.XDrawPage%XDrawPage} /* draw a rectangle */ xrectangle = xDocumentFactory~createInstance("{%see com.sun.star.drawing.RectangleShape}") xxrectangle = xrectangle~{%see com.sun.star.drawing.XShape%xshape} xxrectangle~setPosition(.bsf~new("{%see com.sun.star.awt.Point}", 1000, 1000)) xxrectangle~setSize(.bsf~new("{%see com.sun.star.awt.Size}", 2000, 2000)) xDrawPage~add(xxrectangle) -- adds the rectangle to the draw document /* draw a rectangle */ xrectangle1 = xDocumentFactory~createInstance("{%see com.sun.star.drawing.RectangleShape}") xxrectangle1 = xrectangle1~{%see com.sun.star.drawing.XShape%xshape} xxrectangle1~setPosition(.bsf~new("{%see com.sun.star.awt.Point}", 1000, 4000)) xxrectangle1~setSize(.bsf~new("{%see com.sun.star.awt.Size}", 2000, 2000)) xDrawPage~add(xxrectangle1) -- adds the rectangle to the draw document xrectangle = xDocumentFactory~createInstance("{%see com.sun.star.drawing.ConnectorShape}")~{%see com.sun.star.drawing.XShape%xshape} xrectangle1 = xDocumentFactory~createInstance("{%see com.sun.star.drawing.ConnectorShape}")~{%see com.sun.star.drawing.XShape%xshape} xDrawpage~add(xrectangle) xDrawPage~add(xrectangle1) xprops = xrectangle~{%see com.sun.star.beans.XPropertySet%xPropertySet} xprops~setPropertyValue("StartShape", xxrectangle) xprops~setPropertyValue("StartGluePointIndex", box("int", 2)) -- connect from the bottom line of the xxrectangle xprops~setPropertyValue("EndShape", xxrectangle1) xprops~setPropertyValue("EndGluePointIndex", box("int", 4)) -- connect to the top line of the xxrectangle1 /* draw a rectangle */ xrectangle2 = xDocumentFactory~createInstance("{%see com.sun.star.drawing.RectangleShape}") xxrectangle2 = xrectangle2~{%see com.sun.star.drawing.XShape%xshape} xxrectangle2~setPosition(.bsf~new("{%see com.sun.star.awt.Point}", 8000, 2000)) xxrectangle2~setSize(.bsf~new("{%see com.sun.star.awt.Size}", 2000, 2000)) xDrawPage~add(xxrectangle2) -- adds the rectangle to the draw document xrectangle2 = xDocumentFactory~createInstance("{%see com.sun.star.drawing.ConnectorShape}")~{%see com.sun.star.drawing.XShape%xshape} xDrawpage~add(xrectangle2) xprops2 = xrectangle2~{%see com.sun.star.beans.XPropertySet%xPropertySet} xprops2~setPropertyValue("StartShape", xxrectangle2) xprops2~setPropertyValue("StartGluePointIndex", box("int", 1)) -- connect from the right edge of the xxrectangle2 xprops2~setPropertyValue("EndShape", xxrectangle2) xprops2~setPropertyValue("EndGluePointIndex", box("int", 2)) -- connect to the left edge of the xxrectangle2 /* draw a rectangle */ xrectangle3 = xDocumentFactory~createInstance("{%see com.sun.star.drawing.RectangleShape}") xxrectangle3 = xrectangle3~{%see com.sun.star.drawing.XShape%xshape} xxrectangle3~setPosition(.bsf~new("{%see com.sun.star.awt.Point}", 5000, 2000)) xxrectangle3~setSize(.bsf~new("{%see com.sun.star.awt.Size}", 2000, 2000)) xDrawPage~add(xxrectangle3) -- adds the rectangle to the draw document xrectangle3 = xDocumentFactory~createInstance("{%see com.sun.star.drawing.ConnectorShape}")~{%see com.sun.star.drawing.XShape%xshape} xDrawpage~add(xrectangle3) xprops3 = xrectangle3~{%see com.sun.star.beans.XPropertySet%xPropertySet} xprops3~setPropertyValue("StartShape", xxrectangle3) xprops3~setPropertyValue("StartGluePointIndex", box("int", 4)) xprops3~setPropertyValue("EndShape", xxrectangle) xprops3~setPropertyValue("EndGluePointIndex", box("int", 1)) /* create a circle and add it to the shape */ xCircle = xDocumentFactory~createInstance("{%see com.sun.star.drawing.EllipseShape}") xxcircle = xcircle~{%see com.sun.star.drawing.XShape%xShape} xxCircle~setPosition(.bsf~new("{%see com.sun.star.awt.Point}", 12000, 2000)) xxCircle~setSize(.bsf~new("{%see com.sun.star.awt.Size}", 2000, 2000)) xDrawPage~add(xxCircle) xcircle = xDocumentFactory~createInstance("{%see com.sun.star.drawing.ConnectorShape}")~{%see com.sun.star.drawing.XShape%xshape} xDrawpage~add(xcircle) xprops4 = xcircle~{%see com.sun.star.beans.XPropertySet%xPropertySet} xprops4~setPropertyValue("StartShape", xxcircle) xprops4~setPropertyValue("StartGluePointIndex", box("int", 1)) xprops4~setPropertyValue("EndShape", xxcircle) xprops4~setPropertyValue("EndGluePointIndex", box("int", 3)) ::requires UNO.cls -- get UNO support