Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - pathfinder

Pages: [1]
1
DXF import completed

Note DXF files coordinate origin is bottom left not top right, the Y coordinate is inversed so if you had a full screen graphic the Y coordinate would be the full screen depth.

DATA export completed
POLYVECTOR export completed

See readme attached on how to use Inkscape with SVGPOLY.

put files in the .app directory, you will have to make a dummy project, paste code below.

Change files names as required. The program will do DXF > SVG > POLYVECTOR. If you want data output, change datamode=1. Glbasic code is in the POLYVECTOR.txt file after it has run.

Code: GLBasic [Select]
// --------------------------------- //
// Project: SVGPOLY
// Start: Sunday, March 10, 2013
// IDE Version: 10.202
// FREE-VERSION:
// Need Premium for Features:
// 3D Graphics
// Network Commands
// INLINE C/C+++ code
// SETCURRENTDIR("Media") // go to media files
GLOBAL screenx%,screeny%,rd$,test$,pos#,rgb1%,rgb2%,rgb3%,spno%
GLOBAL prgb1%,prgb2%,prgb3%,cirx#,ciry#,cdi#,doch%
GLOBAL tempx#, tempy#,temp1$,temp2$,debug$,count%,mode%,isline%
GLOBAL polyvx#[],polyvy#[],tempa$[],tempb$[],dxfname$
GLOBAL datamode%


//change these to set file names
//read dxf
dxfname$ = "a.dxf"
//write svg
test$ = "a.SVG"
//write polyvector code
debug$ = "POLYVECT.TXT"
//polyvector or data mode 1= data 2= polyvector
datamode = 2



DIM tempa$[400]
DIM tempb$[400]
DIM polyvx#[400]
DIM polyvy#[400]

screenx%=640
screeny%=480
//document height, should take from svg!

doch=screeny%

isline=0
mode%=0
IF DOESFILEEXIST(dxfname$)
dxftosvg(dxfname$)
ENDIF

tempx=0.0
tempy=0.0
SETSCREEN screenx%,screeny%,1


OPENFILE(1, test$, TRUE)
OPENFILE(2, debug$, FALSE)
spno% = 0
IF datamode = 2
//write functions()
WRITELINE 2,"sprite_"+MID$(test$,0,INSTR(test$,"."))+"()"
WRITELINE 2,"draw_"+MID$(test$,0,INSTR(test$,"."))+"(0,0,1,1)"
WRITELINE 2,"SHOWSCREEN"
WRITELINE 2,"KEYWAIT"
WRITELINE 2,"END"
WRITELINE 2,"FUNCTION draw_"+MID$(test$,0,INSTR(test$,"."))+":xval#,yval#,scxval#,scyval#"
ENDIF

FOR i = 1 TO 400
IF ENDOFFILE(1)=TRUE THEN BREAK

isline=0
READLINE 1,rd$

IF INSTR(rd$, "pagecolor") > 0

pos# = INSTR(rd$, UCASE$("pagecolor"))
rd$ = LCASE$(MID$(rd$,pos#+12,6))
rgb1% = 0
rgb2% = 0
rgb3% = 0
FOR j = 1 TO 6
IF j = 1 THEN rgb1 = hextoint(MID$(rd$,0,1))*16
IF j = 2 THEN rgb1 = rgb1 +hextoint(MID$(rd$,1,1))
IF j = 3 THEN rgb2 = hextoint(MID$(rd$,2,1))*16
IF j = 4 THEN rgb2 = rgb2 +hextoint(MID$(rd$,3,1))
IF j = 5 THEN rgb3 = hextoint(MID$(rd$,4,1))*16
IF j = 6 THEN rgb3 = rgb3 +hextoint(MID$(rd$,5,1))
NEXT
prgb1%=rgb1%
prgb2%=rgb2%
prgb3%=rgb3%
WRITELINE 2,"DRAWRECT 0, 0, "+screenx%+", "+screeny%+",RGB("+prgb1%+","+prgb2%+","+prgb3%+")"

ENDIF



pos# = INSTR(rd$, "<path")

//draw and write a circle
IF INSTR(rd$, "arc") > 0
READLINE 1,rd$
pos# = INSTR(rd$, "fill:#")
rd$ = LCASE$(MID$(rd$,pos#+6,6))
rgb1% = 0
rgb2% = 0
rgb3% = 0
FOR j = 1 TO 6
IF j = 1 THEN rgb1 = hextoint(MID$(rd$,0,1))*16
IF j = 2 THEN rgb1 = rgb1 +hextoint(MID$(rd$,1,1))
IF j = 3 THEN rgb2 = hextoint(MID$(rd$,2,1))*16
IF j = 4 THEN rgb2 = rgb2 +hextoint(MID$(rd$,3,1))
IF j = 5 THEN rgb3 = hextoint(MID$(rd$,4,1))*16
IF j = 6 THEN rgb3 = rgb3 +hextoint(MID$(rd$,5,1))
NEXT


READLINE 1,rd$
READLINE 1,rd$

cirx=MID$(rd$,INSTR(rd$, "sodipodi:cx=")+13,LEN(rd$)-1)
READLINE 1,rd$
ciry=MID$(rd$,INSTR(rd$, "sodipodi:cy=")+13,LEN(rd$)-1)
READLINE 1,rd$
cdi=MID$(rd$,INSTR(rd$, "sodipodi:rx=")+13,LEN(rd$)-1)
FOR i=0 TO 359
DRAWLINE cirx,ciry, cdi*SIN(i) + cirx, cdi*COS(i)+ciry, RGB(rgb1%, rgb2%, rgb3%)
NEXT
SHOWSCREEN

//WRITELINE 2,"//CIRCLE"
WRITELINE 2,"FOR i=0 TO 359"
WRITELINE 2,"DRAWLINE "+cirx+"+xval,"+ciry+"+yval,"+cdi+"*SIN(i) + "+cirx+"+xval, "+cdi+"*COS(i)+"+(ciry)+"+yval,RGB("+rgb1%+","+rgb2%+","+rgb3%+")"
WRITELINE 2,"NEXT"
isline = 2
ENDIF


IF INSTR(rd$, "fill:#") > 0 OR INSTR(rd$, "fill:n") > 0
//colour

IF INSTR(rd$, "fill:#") > 0


pos# = INSTR(rd$, "fill:#")
rd$ = LCASE$(MID$(rd$,pos#+6,6))



ELSE
pos# = INSTR(rd$, "stroke:#")
rd$ = LCASE$(MID$(rd$,pos#+8,6))
IF isline<>2 THEN isline=1
ENDIF
rgb1% = 0
rgb2% = 0
rgb3% = 0
FOR j = 1 TO 6
IF j = 1 THEN rgb1 = hextoint(MID$(rd$,0,1))*16
IF j = 2 THEN rgb1 = rgb1 +hextoint(MID$(rd$,1,1))
IF j = 3 THEN rgb2 = hextoint(MID$(rd$,2,1))*16
IF j = 4 THEN rgb2 = rgb2 +hextoint(MID$(rd$,3,1))
IF j = 5 THEN rgb3 = hextoint(MID$(rd$,4,1))*16
IF j = 6 THEN rgb3 = rgb3 +hextoint(MID$(rd$,5,1))
NEXT
spno% = spno%+1


//clear screen TO match SVG background
DRAWRECT 0, 0, screenx%, screeny%,RGB(prgb1%,prgb2%,prgb3%)


IF isline=0
//SPRITE INFO
DRAWRECT spno%, 0, 32, 32, RGB(rgb1%, rgb2%, rgb3%)
GRABSPRITE spno%, 0, 0, 32, 32
tempa$[spno%]="DRAWRECT 0, 0, 32, 32, RGB("+rgb1%+","+rgb2%+","+rgb3%+")"

tempb$[spno%]="GRABSPRITE "+spno%+", 0, 0, 32, 32"


ENDIF

//drawpoly
mode%=0
READLINE 1,rd$
WHILE INSTR(rd$, "d=")<1
READLINE 1,rd$
WEND


//WRITELINE 2,"//"+rd$
//if M in svg made in Inkscape treat as absolute Coords
IF INSTR(rd$, "-")>0 THEN mode%=0
IF INSTR(rd$, "M")>0 THEN mode%=1
rd$=LCASE$(rd$)






//convert Inkscape svg L path standard
IF INSTR(rd$, "l")>1
mode%=1
rd$=REPLACE$(rd$,CHR$(32),",")
rd$=REPLACE$(rd$,"l"," ")
ENDIF
IF MID$(rd$,LEN(rd$)-2,1) <> " "
rd$=MID$(rd$,0,LEN(rd$)-2)+" z"
ENDIF


IF MID$(rd$,INSTR(rd$, "m")+1,1)=" "
pos# = INSTR(rd$, "m")+2
ELSE
pos# = INSTR(rd$, "m")+1
ENDIF


//WRITELINE 2,"//mode%="+mode%

count%=0
temp1$=""
temp2$=""
tempx=0.0
tempy=0.0

REDIM polyvx[400]
REDIM polyvy[400]
        WHILE pos# < LEN(rd$)-3



        rd$=MID$(rd$,pos#,LEN(rd$))
        IF INSTR(rd$," ")<1 THEN BREAK

IF count% = 0

        temp1$ =MID$(rd$,0,INSTR(rd$,","))
        temp2$ =MID$(rd$,INSTR(rd$,",")+1,(INSTR(rd$," ")-INSTR(rd$,",")-1))

        tempx = temp1$
        tempy = temp2$


polyvx[count%]=tempx
polyvy[count%]=tempy
count%=count%+1

ELSE



        temp1$ =MID$(rd$,0,INSTR(rd$,","))
        temp2$ =MID$(rd$,INSTR(rd$,",")+1,(INSTR(rd$," ")-INSTR(rd$,",")-1))
IF mode%=0


        tempx = tempx+temp1$
        tempy = tempy+temp2$

        ELSE

        tempx = temp1$
        tempy = temp2$

        ENDIF

polyvx[count%]=tempx
polyvy[count%]=tempy

                count%=count%+1
                ENDIF



        pos# = INSTR(rd$," ")+1
        IF pos# = INSTR(rd$,"z") THEN BREAK
        IF pos#+1 = INSTR(rd$,"z") THEN BREAK
        IF count% = 399 THEN BREAK

WEND

IF datamode = 2
IF isline=0 AND count%>2
//STARTPOLY spno%
WRITELINE 2,"STARTPOLY "+spno%
FOR m = count%-1 TO 0 STEP -1
//POLYVECTOR  polyvx[m], polyvy[m] ,0,0,RGB(rgb1%, rgb2%, rgb3%)
WRITELINE 2,"POLYVECTOR ("+polyvx[m] +"*scxval)+xval,("+polyvy[m]+"*scyval)+yval,0,0,rgb(255,255,255)"
NEXT
//ENDPOLY
WRITELINE 2,"ENDPOLY"
ENDIF
ELSE
//data
WRITELINE 2, "STARTDATA  poly_"+MID$(test$,0,LEN(test$)-4)+":"
WRITELINE 2, "//sprite number,xcoord,ycood"
//in loop
FOR m = count%-1 TO 0 STEP -1
WRITELINE 2, "DATA "+spno%+","+polyvx[m] +","+polyvy[m]
NEXT
ENDIF



IF datamode = 2
IF isline=1
DRAWLINE polyvx[0], polyvy[0],polyvx[1], polyvy[1],RGB(rgb1%, rgb2%, rgb3%)
WRITELINE 2,"DRAWLINE "+polyvx[0] +"+xval,"+polyvy[0]+"+yval,"+polyvx[1]+"+xval,"+polyvy[1]+"+yval, RGB("+rgb1%+","+rgb2%+","+rgb3%+")"
ENDIF
ELSE
//data
WRITELINE 2, "STARTDATA  poly_"+MID$(test$,0,LEN(test$)-4)+":"
WRITELINE 2, "//sprite number,xcoord,ycood"
//in loop
FOR m = count%-1 TO 0 STEP -1
WRITELINE 2, "DATA "+spno%+","+polyvx[m] +","+polyvy[m]
NEXT
ENDIF
WRITELINE 2, "ENDDATA"


SHOWSCREEN
SLEEP 40


ENDIF



NEXT


IF datamode = 2
WRITELINE 2,"ENDFUNCTION"
WRITELINE 2,""
WRITELINE 2,"FUNCTION sprite_"+MID$(test$,0,INSTR(test$,"."))+":"

FOR i = 1 TO spno%
WRITELINE 2,tempa$[i]
WRITELINE 2,tempb$[i]
NEXT
WRITELINE 2,"ENDFUNCTION"
ENDIF

CLOSEFILE 1
CLOSEFILE 2

FUNCTION dxftosvg:dxfin$
LOCAL idnum#, writepath$,svgout$,tempval#

OPENFILE(3,dxfin$, TRUE)
svgout$=MID$(dxfin$,0,LEN(dxfin$)-4)+".svg"
OPENFILE(4,svgout$,FALSE)
idnum = 1000
//header
WRITELINE 4, "<svg"
WRITELINE 4, "   inkscape:version=" + CHR$(34) + "0.48.4 r9939" + CHR$(34) + ">"
WRITELINE 4, "  <g"
WRITELINE 4, "     inkscape:label=" + CHR$(34) + "Layer 1" + CHR$(34)
WRITELINE 4, "     inkscape:groupmode= " + CHR$(34) + "layer" + CHR$(34)
WRITELINE 4, "     id=" + CHR$(34) + "layer1" + CHR$(34) + ">"
WHILE 1=1
IF ENDOFFILE(3) = 1 THEN BREAK
READLINE  3, rd$
IF rd$ = "LWPOLYLINE"
idnum=idnum+1
writepath$="       d=" + CHR$(34) + "M"
WHILE 1=1
READLINE  3, rd$
IF rd$ = " 10"
READLINE  3, rd$
writepath$=writepath$ + " " + rd$
ENDIF

IF rd$ = " 20"
READLINE  3, rd$
IF MID$(rd$,0,1) = "-"
 rd$=MID$(rd$,1,LEN(rd$)-1)
 ELSE
 tempval = rd$
 IF tempval <>0
 rd$="-" +rd$
 ELSE
 
 ENDIF
 ENDIF
writepath$=writepath$ + "," +rd$
ENDIF
IF rd$ = "  0" THEN BREAK
WEND
writepath$=writepath$ + " z" + CHR$(34)

WRITELINE 4, "    <path"
WRITELINE 4, "       style=" + CHR$(34) + "fill:#ffffff;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + CHR$(34)
WRITELINE 4, writepath$
WRITELINE 4, "       id=" + CHR$(34) + "path" + idnum + CHR$(34)
WRITELINE 4, "       inkscape:connector-curvature=" + CHR$(34) + "0" + CHR$(34) + " />"

ENDIF
WEND

WRITELINE 4, "  </g>"
WRITELINE 4, "</svg>"
CLOSEFILE 3
CLOSEFILE 4
ENDFUNCTION



FUNCTION hextoint:temp$

LOCAL r%
SELECT UCASE$(temp$)
CASE "0"
r%=0
CASE "1"
r%=1
CASE "2"
r%=2
CASE "3"
r%=3
CASE "4"
r%=4
CASE "5"
r%=5
CASE "6"
r%=6
CASE "7"
r%=7
CASE "8"
r%=8
CASE "9"
r%=9
CASE "A"
r%=10
CASE "B"
r%=11
CASE "C"
r%=12
CASE "D"
r%=13
CASE "E"
r%=14
CASE "F"
r%=15
ENDSELECT
RETURN r%
ENDFUNCTION
 

Pages: [1]