Thu, February 21, 2008
六角形データをXML形式に変換する(honeycombDrawing.jar + n2io.jar)(tool)
N2基本プログラム(商用ソフトウェア) で作成したデータ(拡張子に nn5 がついたデータ) を読み込んでXMLに変換します。
変換結果
nn5データを変換した結果のXML。
<honeycomb id='test' width='1000' height='900' >
<theme>(財)中小企業ベンチャー振興基金</theme>
<cells>
<cell x='447' y='397' w='107' h='107' code='0' ><text x='459' y='423' w='83' h='53' >(財)中小企業ベンチャー振興基金</text></cell>
<cell x='495' y='314' w='107' h='107' code='1' ><text x='507' y='340' w='83' h='53' >研究開発
補助金</text></cell>
<cell x='543' y='397' w='107' h='107' code='2' ><text x='555' y='423' w='83' h='53' >海外研究等助成金</text></cell>
<cell x='495' y='480' w='107' h='107' code='3' ><text x='507' y='506' w='83' h='53' >条件</text></cell>
<cell x='400' y='480' w='107' h='107' code='4' ><text x='412' y='506' w='83' h='53' >対象者</text></cell>
<cell x='351' y='397' w='107' h='107' code='5' ><text x='363' y='423' w='83' h='53' >対象事業</text></cell>
<cell x='399' y='314' w='107' h='107' code='6' ><text x='411' y='340' w='83' h='53' >対象費用</text></cell>
<cell x='612' y='112' w='107' h='107' code='1' ><text x='624' y='138' w='83' h='53' >研究開発
補助金</text></cell>
<cell x='660' y='29' w='107' h='107' code='1-1' ><text x='672' y='55' w='83' h='53' >新技術、新製品開発等の研究開発</text></cell>
<cell x='708' y='112' w='107' h='107' code='1-2' ><text x='720' y='138' w='83' h='53' >中小企業</text></cell>
<cell x='660' y='195' w='107' h='107' code='1-3' ><text x='672' y='221' w='83' h='53' >起業化を目指す個人の研究者</text></cell>
<cell x='565' y='195' w='107' h='107' code='1-4' ><text x='577' y='221' w='83' h='53' >研究開発の資金の一部を助成</text></cell>
<cell x='516' y='112' w='107' h='107' code='1-5' ></cell>
<cell x='564' y='29' w='107' h='107' code='1-6' ></cell>
<cell x='777' y='397' w='107' h='107' code='2' ><text x='789' y='423' w='83' h='53' >海外研究等助成金</text></cell>
<cell x='825' y='314' w='107' h='107' code='2-1' ><text x='837' y='340' w='83' h='53' >海外企業、研究機関との協同開発</text></cell>
<cell x='873' y='397' w='107' h='107' code='2-2' ><text x='885' y='423' w='83' h='53' >研究開発の資金の一部を助成</text></cell>
<cell x='825' y='480' w='107' h='107' code='2-3' ></cell>
<cell x='730' y='480' w='107' h='107' code='2-4' ></cell>
<cell x='681' y='397' w='107' h='107' code='2-5' ></cell>
<cell x='729' y='314' w='107' h='107' code='2-6' ></cell>
<cell x='612' y='682' w='107' h='107' code='3' ><text x='624' y='708' w='83' h='53' >条件</text></cell>
<cell x='660' y='599' w='107' h='107' code='3-1' ><text x='672' y='625' w='83' h='53' >補助金額:400万円以内</text></cell>
<cell x='708' y='682' w='107' h='107' code='3-2' ><text x='720' y='708' w='83' h='53' >補助率:2分の1以下</text></cell>
<cell x='660' y='765' w='107' h='107' code='3-3' ></cell>
<cell x='565' y='765' w='107' h='107' code='3-4' ></cell>
<cell x='516' y='682' w='107' h='107' code='3-5' ></cell>
<cell x='564' y='599' w='107' h='107' code='3-6' ></cell>
<cell x='283' y='682' w='107' h='107' code='4' ><text x='295' y='708' w='83' h='53' >対象者</text></cell>
<cell x='331' y='599' w='107' h='107' code='4-1' ><text x='343' y='625' w='83' h='53' >創業後10年以内</text></cell>
<cell x='379' y='682' w='107' h='107' code='4-2' ><text x='391' y='708' w='83' h='53' >新事業進出後10年以内</text></cell>
<cell x='331' y='765' w='107' h='107' code='4-3' ><text x='343' y='791' w='83' h='53' >起業化を目指す個人研究者</text></cell>
<cell x='236' y='765' w='107' h='107' code='4-4' ><text x='248' y='791' w='83' h='53' >審査委員会による審査がある</text></cell>
<cell x='187' y='682' w='107' h='107' code='4-5' ></cell>
<cell x='235' y='599' w='107' h='107' code='4-6' ></cell>
<cell x='117' y='397' w='107' h='107' code='5' ><text x='129' y='423' w='83' h='53' >対象事業</text></cell>
<cell x='165' y='314' w='107' h='107' code='5-1' ><text x='177' y='340' w='83' h='53' >技術水準が高い</text></cell>
<cell x='213' y='397' w='107' h='107' code='5-2' ><text x='225' y='423' w='83' h='53' >実現可能性が高い</text></cell>
<cell x='165' y='480' w='107' h='107' code='5-3' ><text x='177' y='506' w='83' h='53' >新規性があるプロジェクト</text></cell>
<cell x='70' y='480' w='107' h='107' code='5-4' ></cell>
<cell x='21' y='397' w='107' h='107' code='5-5' ></cell>
<cell x='69' y='314' w='107' h='107' code='5-6' ></cell>
<cell x='282' y='112' w='107' h='107' code='6' ><text x='294' y='138' w='83' h='53' >対象費用</text></cell>
<cell x='330' y='29' w='107' h='107' code='6-1' ><text x='342' y='55' w='83' h='53' >新技術、新製品の研究開発</text></cell>
<cell x='378' y='112' w='107' h='107' code='6-2' ><text x='390' y='138' w='83' h='53' >科学技術の応用研究</text></cell>
<cell x='330' y='195' w='107' h='107' code='6-3' ><text x='342' y='221' w='83' h='53' >設計費、設備費、施策費</text></cell>
<cell x='235' y='195' w='107' h='107' code='6-4' ><text x='247' y='221' w='83' h='53' >調査研究費</text></cell>
<cell x='186' y='112' w='107' h='107' code='6-5' ></cell>
<cell x='234' y='29' w='107' h='107' code='6-6' ></cell>
</cells>
</honeycomb>
code
import sys
import n2.io as n2io
import ntwo.drawing as md
import java.lang as lang
import java.io as io
import java.awt as awt
RET=lang.System.getProperty("line.separator")
W=1000
H=900
nn5filename=( sys.argv[1] )
xmlfilename=lang.String(nn5filename).replaceAll(".nn5$",".xml")
model=n2io.NN5Reader().read(io.File(nn5filename))
# create htwoycombTwo obj.
htwo=md.HoneycombTwo()
htwo.setSize(awt.Dimension(W,H))
sb=lang.StringBuffer()
ID=lang.String(nn5filename).replaceAll(".nn5$","")
sb.append("<honeycomb ")
sb.append("id='"+ID+"' ")
sb.append("width='"+str(W)+"' ")
sb.append("height='"+str(H)+"' ")
sb.append(">")
sb.append(RET)
theme=model.getNode("0").getText()
sb.append("<theme>"+theme+"</theme>")
sb.append(RET)
sb.append("<cells>")
sb.append(RET)
# draw hexagon
index=0
for shape in htwo.getHexagonShapes():
sb2=lang.StringBuffer()
rect=shape.getHexagonCell().getRectangle()
loc=rect.getLocation()
x=str(loc.x)
y=str(loc.y)
size=rect.getSize()
w=str(size.width)
h=str(size.height)
code=n2io.ACodeUtil.getACode("0-0",index)
sb2.append("<cell ")
sb2.append("x='"+x+"' ")
sb2.append("y='"+y+"' ")
sb2.append("w='"+w+"' ")
sb2.append("h='"+h+"' ")
sb2.append("code='"+code+"' ")
sb2.append(">")
node=model.getNode(n2io.ACodeUtil.fixACode(code))
if node!=None:
rect=shape.getHexagonCell().getTextBoxRectangle()
loc=rect.getLocation()
x=str(loc.x)
y=str(loc.y)
size=rect.getSize()
w=str(size.width)
h=str(size.height)
sb2.append("<text ")
sb2.append("x='"+x+"' ")
sb2.append("y='"+y+"' ")
sb2.append("w='"+w+"' ")
sb2.append("h='"+h+"' ")
sb2.append(">")
sb2.append( node.text )
sb2.append("</text>")
sb2.append("</cell>")
sb.append(sb2.toString())
sb.append(RET)
index=index+1
sb.append("</cells>")
sb.append(RET)
sb.append("</honeycomb>")
sb.append(RET)
pw=io.PrintWriter(io.OutputStreamWriter(io.FileOutputStream(io.File(xmlfilename)),"UTF-8"))
pw.print( sb.toString() )
pw.close()
$ (export CLASSPATH=honeycombDrawing.jar:n2io.jar; jython toxml.py test.nn5)