| View previous topic :: View next topic |
| Author |
Message |
DanielSon Newbie

Joined: 09 Dec 2005 Posts: 2
|
Posted: Fri Dec 09, 2005 1:23 pm Post subject: Interfacing with drawing or graphics |
|
|
Hey,
I am trying to create my own basic graphic development tool for creating c++ programs easily from graphic flow charts for unskilled programs who need to implement simple algorithms.
I am looking for a way to draw flow charts using triangles, circles , and squares in a way which I will be able to interface to the drawing from a c++/java/python program. This is for my graphic to code compiler which will convert the flow chart into code.
Does anyone know if Open Office can help me out with that, or of any other programs or techniques which can get the job done?
I would really appreciate any help I can get!!
Thanx,
Daniel |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
Posted: Sat Dec 10, 2005 8:42 am Post subject: |
|
|
Using OOo as a front-end seems very easy. I have not time at the moment but I think your project can be done only in several hours.
Of course you cannot ask a user to give a name to a shape but you can do it for him. I see two ways :
- write a macro for one kind of shape : here is a very old example (don'tknow if it works) :
| Code: |
Sub State
Dim StateName As string
Dim aPoint As New com.sun.star.awt.Point
Dim aSize As New com.sun.star.awt.Size
Dim oDocument, oPage, oState As Object
Dim nRadius, nX, nY As Long
StateName = InputBox("Nom symbolique de l'état ?","A renseigner","")
nRadius=900
nX=1500
nY=1500
aPoint.X = nX - nRadius
aPoint.Y = nY - nRadius
aSize.Width = nRadius * 2
aSize.Height = nRadius * 2
oDocument=ThisComponent
oState = oDocument.createInstance("com.sun.star.drawing.EllipseShape")
oState.Size = aSize
oState.Position = aPoint
oState.setName("State")
oState.FillColor = RGB(0,0,255)
'msgBox(oState.dbg_methods)
oPage = oDocument.drawPages(0)
oPage.add(oState)
oState.setString(StateName)
End Sub
Sub Action
Dim ActionName As string
Dim oDocument,oCaptionShape,oPage As Object
Dim aPoint As New com.sun.star.awt.Point
Dim aSize As New com.sun.star.awt.Size
ActionName = InputBox("Nom de l'action ?","A renseigner","")
'EtatName = InputBox("Nom de l'état à accrocher ,""A Renseigner","")
oDocument=ThisComponent
oCaptionShape=oDocument.createInstance("com.sun.star.drawing.CaptionShape")
aPoint.x=500
aPoint.y=500
aSize.width=1000
aSize.Height=1000
oCaptionShape.Position=aPoint
oCaptionShape.Size=aSize
oCaptionShape.SetName("Action")
oPage = oDocument.drawPages(0)
oPage.add(oCaptionShape)
oCaptionShape.setString(ActionName)
End Sub
Sub Transition
Dim TransitionName As string
Dim oDocument,oTransitionShape,oPage As Object
Dim aPoint As New com.sun.star.awt.Point
Dim aSize As New com.sun.star.awt.Size
TransitionName = InputBox("Nom de la transition ?","A renseigner","")
oDocument=ThisComponent
oTransitionShape=oDocument.createInstance("com.sun.star.drawing.ConnectorShape")
aPoint.x=500
aPoint.y=500
aSize.width=1000
aSize.Height=1000
oTransitionShape.Position=aPoint
oTransitionShape.Size=aSize
oTransitionShape.SetName("Trans")
oPage = oDocument.drawPages(0)
oPage.add(oTransitionShape)
oTransitionShape.setString(TransitionName)
End Sub
Sub StateInit
Dim StateName As string
Dim aPoint As New com.sun.star.awt.Point
Dim aSize As New com.sun.star.awt.Size
Dim oDocument, oPage, oState,oState2 As Object
Dim nRadius, nX, nY,ShapesCount As Long
StateName = InputBox("Nom symbolique de l'état ?","A renseigner","")
nRadius=900
nX=1500
nY=1500
aPoint.X = nX - nRadius
aPoint.Y = nY - nRadius
aSize.Width = nRadius * 2
aSize.Height = nRadius * 2
oDocument=ThisComponent
oPage = oDocument.drawPages(0)
ShapesCount=oPage.getcount() 'store the number of shapes in the page
oState = oDocument.createInstance("com.sun.star.drawing.EllipseShape")
oState.Size = aSize
oState.Position = aPoint
'oState.setName("StateInit")
oState.FillColor = RGB(0,255,0)
oPage.add(oState)
'oState.String=StateName
nRadius=700
aPoint.X = nX - nRadius
aPoint.Y = nY - nRadius
aSize.Width = nRadius * 2
aSize.Height = nRadius * 2
oState2 = oDocument.createInstance("com.sun.star.drawing.EllipseShape")
oState2.Size = aSize
oState2.Position = aPoint
'oState2.setName("StateInit")
oState2.FillColor = RGB(0,255,0)
oPage.add(oState2)
oState2.String=StateName
Dim oShapes As Object
oShapes = createUnoService("com.sun.star.drawing.ShapeCollection")
oShapes.add(oState)
oShapes.add(oState2)
Dim oGroup As Object
oGroup = oPage.group(oShapes)
oGroup.setName("Init_State")
End Sub
|
and assign a button to every macro. You will recognize the shapes in your document because they have different names (setName in OOoBasic)
- second method is to use galery where you predefine shapes with also different names.
After you can retrieve all the shapes I give you an example which put all the shapes in an scalc sheet :
| Code: |
Sub ListeObjetsDansCalc
Dim mNoArgs()
Dim sUrl As String
Dim Feuilles As Object
Dim Feuille As Object
Dim DocResultat As Object
Dim oCell AS Object
Dim nbObj as integer
Dim oShape as object
' document draw
oDocument=ThisComponent
oPage = oDocument.drawPages(0)
nbObj=oPage.getcount ' donne bien le nombre d'objets
If oPage.HasElements Then
oDesktop = createUnoService("com.sun.star.frame.Desktop")
sUrl = "private:factory/scalc"
DocResultat = oDesktop.LoadComponentFromURL(sUrl,"_blank",0,mNoArgs)
Feuilles = DocResultat.Sheets()
Feuille = DocResultat.Sheets(0)
for j=0 to oPage.getcount-1
oShape = oPage.getbyindex(j)
XRay.XRay oShape
if oShape.getShapeType="com.sun.star.drawing.ConnectorShape" Then
'XRay.XRay oShape
end if
' print oShape.getname
' msgBox(oShape.dbg_methods)
oCell = Feuille.GetCellByPosition(0,j)
oCell.string = oShape.getShapeType
oCell = Feuille.GetCellByPosition(1,j)
oCell.value = oShape.getPosition.x
oCell = Feuille.GetCellByPosition(2,j)
oCell.value = oShape.getPosition.y
oCell = Feuille.GetCellByPosition(3,j)
oCell.string = oShape.getName
' solution trouvée dans Gimmicks->GetTexts
oCell = Feuille.GetCellByPosition(4,j)
If HasUnoInterfaces(oShape,"com.sun.star.container.XIndexAccess") Then
' The Object "oPageElement" a group of Shapes, that can be accessed by their index
For s = 0 To oShape.Count - 1
oCell.string=oShape.GetByIndex(s).String
Next s
ElseIf HasUnoInterfaces(oShape, "com.sun.star.text.XText") Then
oCell.string=oShape.String
End If
next
end if
End Sub
|
I have not worked around connectors but i think they allow to retrieve which shape is connected with witch other. _________________ Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|