Forum at OOoForum.orgThe Forum
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Serializing Or Getting a Handle on CustomShape Data

Post new topic   Reply to topic Forum Index -> Macros and API
View previous topic :: View next topic  
Author Message

Joined: 11 Apr 2008
Posts: 1
Location: Redwood Shores, California

PostPosted: Fri Apr 11, 2008 11:19 am    Post subject: Serializing Or Getting a Handle on CustomShape Data Reply with quote

When a user creates shapes in Draw, I want to be able to capture the data of the shape, basically the coordinates, formulas, and text and store the shape data in a database where it is parsed and certain contents made available for other uses. I've been trying to access the data structures using Open Office basic and have hit a roadblock.


Create a new Draw document and insert a single call out shape and add some text to the call out, i.e. "This is a call out". (You may want to change the font size to 10 pts in case your deafult is to 18 pts.) Save the Draw document as ExampleCallOut.odg

I then make a copy of ExampleCallOut.odg and give it a "zip" extension, Then I view the contents of the zip archive and open the file contents.xml which has the following contents (repeated elements have been removed to keep the listing short):

            style:name="dp1" style:family="drawing-page">
               draw:name="page1" draw:style-name="dp1" draw:master-page-name="Default"
            <draw:custom-shape draw:style-name="gr1" draw:text-style-name="P2"
                  draw:layer="layout" svg:width="6.985cm" svg:height="4.445cm"
                  svg:x="6.08cm" svg:y="8.62cm">
               <text:p text:style-name="P1">This is
                  a Call Out</text:p>
               <draw:enhanced-geometry svg:viewBox="0 0 21600 21600"
                     draw:text-areas="800 800 20800 20800"
                     draw:type="round-rectangular-callout" draw:modifiers="4250 45000"
                     draw:enhanced-path="M 3590 0 X 0 3590 L ?f2 ?f3 0 8970 0 12630 ?f4 ?f5 0 18010 Y 3590 21600 L ?f6 ?f7 8970 21600 12630 21600 ?f8 ?f9 18010 21600 X 21600 18010 L ?f10 ?f11 21600 12630 21600 8970 ?f12 ?f13 21600 3590 Y 18010 0 L ?f14 ?f15 12630 0 8970 0 ?f16 ?f17 Z N"
                  <draw:equation draw:name="f0" draw:formula="$0 -10800"/>
                        draw:name="f1" draw:formula="$1 -10800"/>
                  <draw:equation draw:name="f2"
                        draw:formula="if(?f18 ,$0 ,0)"/>
                  <draw:equation draw:name="f41" draw:formula="$1 "
                  <draw:handle draw:handle-position="$0 $1"/>

(Note: see SourceForge's NotePad++ tool with the XML Tools plugin, make beautifying XML with appropriate indentations for each level a snap.)

What I really want is to get a handle on the data with the tags "draw:custom-shape", such as text:p, draw:enhanced-path, draw:equation. I could easily do this after the document is saved using perl scripts and an XML parser, but I would like to be able to access this data during a live session when the document is loaded into the Draw Desktop so the user simply clicks a menu item to store the current version in a database.


Here is some code I created to get a handle on the document and inspect its content:
REM  *****  BASIC  *****
'Main get called automatically, use Main as a caller
Sub Main
End Sub

Sub Test_Documents_Iteration
   Dim SourceD as Object
   Dim SourceName as String
   SourceName = "ExampleCallout"  ' Watch out for Case sensitivity!
   call Documents_Iteration(SourceName,SourceD)
   if  not HasUnoInterfaces(SourceD, "") Then
     Msgbox (SourceName + " not found", 16 + 0, "Missing File Warning")
   end if
    ' Explore the Shape's innards
end sub

Sub Documents_Iteration( SourceName, SourceDoc  )
  Dim oDesktop as Object, oComponents as Object, oComp as Object
  Dim oCompsEnum as Object
  Dim mname as String
  Dim i as Integer 'i counts how many windows are open in OOo
  i = 0
  oComponents = StarDesktop.getComponents()
  oCompsEnum = oComponents.createEnumeration()
  Do While oCompsEnum.hasMoreElements()
    oComp = oCompsEnum.nextElement()
    If HasUnoInterfaces(oComp, "") Then   
        ' from the basic modules: Tools-Strings: FileNameoutofPath & GetFileNameWithoutExtension
        mname = FileNameoutofPath(GetFileNameWithoutExtension(oComp.URL))
         if (mname = SourceName) Then
           SourceDoc = oComp        
       end if     
    end if
    i = i + 1 'Counter
End Sub

Sub studyShapes (oDPages)
   dim oDPage
   dim i as Integer
    dim shape1

   For i = 0 To oDPages.getCount()-1
      oDPage = oDPages.getByIndex(i)
      shape1 = oDpage.getByIndex(0)
      ' Xray is an extra module, not part of the standard package
      Xray shape1
      ' Where do I go from here to get a handle
      ' on the array containing the structures?
   next i
end Sub

I tried to study the various articles and postings regarding UNO and I'm still in the dark on how to call a UNO service with respect to a particular object. I'm not fully understanding UNO and how it can be invoke from with Open Office Basic? I thought there must be some way to request from UNO the array or sequence from CustomShapeGeometry

Does anyone have a suggestion for getting a handle on the structures that eventually are serialized to populate the draw:enhanced-path element as it appears in the saved file: contents.xml? I do know what to do once I have the array structures as several other postings and literature have explained how to manipulate structures.

I looked for examples where custom shapes are manipulated by code, but didn't see any that went down to the level off data points.
Back to top
View user's profile Send private message Visit poster's website
Super User
Super User

Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Tue Apr 15, 2008 7:10 am    Post subject: Reply with quote

Your shape1 is a service and you can use all interfaces and call the corresponding methods. Sorry, I don't see where is your problem ? All information given by XRay can be used...

You can write :

if shape1.supportsService("") then

Linux & Windows OOo3.0
UNO & C++ : WIKI
In French
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Forum Index -> Macros and API All times are GMT - 8 Hours
Page 1 of 1

Jump to:  
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