In this example an organigram is created.
The user can choose the number of tree levels and the number of nodes in each level.
In this example the number of tree levels is limited to 3,
in the seond level the maximum nodes are four and
for each node in the second level the user can create 2 nodes in the third level maximum.
The user can choose a name for each node he creates.
The text is coloured purple and the size of the text changes each level.
The nodes of each level are connected automatically.
titleinput:
say "Please insert the title of the diagram: "
parse pull title
orgtitle = title
SELECT
when orgtitle == "" THEN do
say "No title specified. Please insert the TITLE of the diagram: "
CALL titleinput
END
OTHERWISE
END
/* 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}
level2input:
say "*** Please insert the NUMBER of the SECOND organigram level nodes (max 4 nodes):"
parse pull number
orgnumber2 = number
SELECT
when orgnumber2 == 0 | orgnumber2 == 1 | orgnumber2 == 2 | orgnumber2 == 3 | orgnumber2 == 4
THEN do
orgname2 =.array~new(orgnumber2)
do i = 1 to orgnumber2 by 1
say " "
say " Please insert the NAME of the SECOND level node number" i":"
parse pull name
orgname2[i] = name
-- Third Level
say "*** Please insert the NUMBER of the THIRD organigram level nodes (max 2 nodes):"
parse pull number3
orgnumber3 = number3
SELECT
when orgnumber3 == 0 | orgnumber3 == 1 | orgnumber3 == 2
THEN do
orgname3.i = .array~new(orgnumber3)
orgparents3.i = i
do j = 1 to orgnumber3
say "*** Please insert the NAME of the THIRD level node number" j":"
parse pull name3
orgname3.i[j] = name3
end
END
OTHERWISE
SAY "Invalid input - ending program!"
EXIT
END
end
END
OTHERWISE say "No valid number. Please insert a number: "
CALL level2input
END
-- Create Title Node place it in middle of the document
titlenodelength=4000
titlenodewidth=2000
--Center over the width of the page, mid point of the sheet - length of rectangle +1000 left frame space
titlenodex=((19000/2)-(titlenodelength/2))+1000
titlenodey=2000
xrectangletitle = xDocumentFactory~createInstance("{%see com.sun.star.drawing.RectangleShape}")
xxrectangletitle = xrectangletitle ~{%see com.sun.star.drawing.XShape%xshape}
xxrectangletitle ~setPosition(.bsf~new("{%see com.sun.star.awt.Point}", titlenodex, titlenodey))
xxrectangletitle ~setSize(.bsf~new("{%see com.sun.star.awt.Size}", titlenodelength, titlenodewidth))
xDrawPage~add(xxrectangletitle) -- adds the rectangle to the draw document
xText = xrectangletitle~{%see com.sun.star.text.XText%XText}
xTextCursor = xText~createTextCursor
xTextCursor~gotoEnd(.false)
xTextRange = xTextCursor~{%see com.sun.star.text.XTextRange%XTextRange}
xTextRange~setString(orgtitle)
cur = xTextCursor~{%see com.sun.star.beans.XPropertySet%xPropertySet}
cur~setPropertyValue("CharColor", box("int", "483D8B"x ~c2d)) -- set text colour blue
cur~setPropertyValue("CharHeight", box("float", "25")) -- set font size 25
cur~setPropertyValue("CharWeight", -
box("float", bsf.getConstant("{%see com.sun.star.awt.FontWeight}", "BOLD"))) -- set the font bold
--xrectangletitle ~{%see com.sun.star.text.XText%xText}~setString(orgtitle)
z=1
-- Navigates through the lvl2 Node-Array and created the nodes, max 4
DO k=1 to orgnumber2
lvl2nodelength=4000
lvl2nodewidth=2000
--create the rectancles depending on how many should be created
xfactorlvl2=(5)-k
lvl2nodex=19000+1250-(xfactorlvl2*4750)
lvl2nodey=8000
xrectanglelvl2.k = xDocumentFactory~createInstance("{%see com.sun.star.drawing.RectangleShape}")
xxrectanglelvl2.k = xrectanglelvl2.k~{%see com.sun.star.drawing.XShape%xshape}
xxrectanglelvl2.k~setPosition(.bsf~new("{%see com.sun.star.awt.Point}", lvl2nodex, lvl2nodey))
xxrectanglelvl2.k~setSize(.bsf~new("{%see com.sun.star.awt.Size}", lvl2nodelength, lvl2nodewidth))
xDrawPage~add(xxrectanglelvl2.k) -- adds the rectangle to the draw document
xText = xrectanglelvl2.k~{%see com.sun.star.text.XText%XText}
xTextCursor1 = xText~createTextCursor
xTextCursor1~gotoEnd(.false)
xTextRange1 = xTextCursor1~{%see com.sun.star.text.XTextRange%XTextRange}
xTextRange1~setString(orgname2[k])
cur1 = xTextCursor1~{%see com.sun.star.beans.XPropertySet%xPropertySet}
cur1~setPropertyValue("CharColor", box("int", "483D8B"x ~c2d)) -- set text colour blue
cur1~setPropertyValue("CharHeight", box("float", "20")) -- set font size 20
xrectanglelvl2.k = xDocumentFactory~createInstance("{%see com.sun.star.drawing.ConnectorShape}")~{%see com.sun.star.drawing.XShape%xshape}
xDrawpage~add(xrectanglelvl2.k)
xpropslvl2.k = xrectanglelvl2.k~{%see com.sun.star.beans.XPropertySet%xPropertySet}
xpropslvl2.k~setPropertyValue("StartShape", xrectangletitle)
xpropslvl2.k~setPropertyValue("StartGluePointIndex", box("int", 2))
xpropslvl2.k~setPropertyValue("EndShape", xxrectanglelvl2.k)
xpropslvl2.k~setPropertyValue("EndGluePointIndex", box("int", 4))
-- Navigates through the lvl3 Node-Array and created the nodes, max 2
DO m=1 to orgname3.k~items
lvl3parentnode=orgparents3.k
lvl3suffix=xxrectanglelvl2.k
lvl3nodelength=2000
lvl3nodewidth=2000
--create the rectancles depending on how many should be created
xfactorlvl3=(9)-z
lvl3nodex=19000+1000-(xfactorlvl3*2375)
lvl3nodey=14000
xrectanglelvl3.k.m = xDocumentFactory~createInstance("{%see com.sun.star.drawing.RectangleShape}")
xxrectanglelvl3.k.m = xrectanglelvl3.k.m~{%see com.sun.star.drawing.XShape%xshape}
xxrectanglelvl3.k.m~setPosition(.bsf~new("{%see com.sun.star.awt.Point}", lvl3nodex, lvl3nodey))
xxrectanglelvl3.k.m~setSize(.bsf~new("{%see com.sun.star.awt.Size}", lvl3nodelength, lvl3nodewidth))
xDrawPage~add(xxrectanglelvl3.k.m) -- adds the rectangle to the draw document
xText = xxrectanglelvl3.k.m~{%see com.sun.star.text.XText%XText}
xTextCursor3 = xText~createTextCursor
xTextCursor3~gotoEnd(.false)
xTextRange3 = xTextCursor3~{%see com.sun.star.text.XTextRange%XTextRange}
xTextRange3~setString(orgname3.k[m])
cur3 = xTextCursor3~{%see com.sun.star.beans.XPropertySet%xPropertySet}
cur3~setPropertyValue("CharColor", box("int", "483D8B"x ~c2d)) -- set text colour blue
cur3~setPropertyValue("CharHeight", box("float", "14")) -- set font size 14
xrectanglelvl3.k.m = xDocumentFactory~createInstance("{%see com.sun.star.drawing.ConnectorShape}")~{%see com.sun.star.drawing.XShape%xshape}
xDrawpage~add(xrectanglelvl3.k.m)
xpropslvl3.k.m = xrectanglelvl3.k.m~{%see com.sun.star.beans.XPropertySet%xPropertySet}
xpropslvl3.k.m~setPropertyValue("StartShape", lvl3suffix)
xpropslvl3.k.m~setPropertyValue("StartGluePointIndex", box("int", 2))
xpropslvl3.k.m~setPropertyValue("EndShape", xxrectanglelvl3.k.m)
xpropslvl3.k.m~setPropertyValue("EndGluePointIndex", box("int", 4))
z=z+1
END
END
::requires UNO.cls -- get UNO support