 |
|
|
10-14-2008, 02:21 AM
|
Parse a file using php
|
Posts: 116
Name: Paul
Location: South Africa
|
Hi guys, I just need to know if this is possible before I battle with it for the next few days, any advice would be greatly appreciated.
I am trying to make a script that can open 2 types of files, one is a .dxf and the other a .cf2 file, these are used for die drawings in the packaging industry, once open I would like it to render on screen what the drawing looks like, this may be quite tricky, i'm not sure, the code consists of comma seperated values, I will give a small example of both.
This is the code of a cf2 file
Code:
$BOF (Begin of file)
MAIN,DESIGN1 (Begin of code block)
LL,-512.45,-13.85 (Lower Left co-ords)
UR,512.35,703.85 (Upper Right co-ords)
L,2,1,0,-49.5,-203.75,-49.5,-205.73,0,0 (Line co-ords)
A,2,1,0,-49.5,-205.73,-49.03,-207.34,-46.5,-205.73,1,0,0 (Angle co-ords)
L,2,1,0,-49.03,-207.34,-44.38,-214.61,0,0
A,2,1,0,-44.38,-214.61,-41.86,-216,-41.86,-213,1,0,0
END (End of code block)
$EOF (End of file)
This is a piece of code from a dxf file
Code:
POLYLINE
5
3C
330
1F
100
AcDbEntity
8
Layer 1
62
7
370
35
100
AcDb2dPolyline
66
1
10
0.0
20
0.0
30
0.0
0
VERTEX
5
Then once drawn, I would only like 2 options
1 would be to export it out as a cf2 file
2 would be to export it out as a dxf file
Is this possible
Thanks for any response to this
|
|
|
|
10-14-2008, 03:20 AM
|
Re: Parse a file using php
|
Posts: 1,226
Name: Mike
Location: Mataro, Spain
|
If you are able to design any reasonable object model for representing this data there will no problem neither with parsing nor with rendering.
|
|
|
|
10-14-2008, 07:05 AM
|
Re: Parse a file using php
|
Posts: 932
|
Hi there,
Quote:
|
... once open I would like it to render on screen what the drawing looks like ...
|
It is indeed possible with PHP. That being said it would not be my preferred language for such a task. Additionally, if you have to ask if its possible then i'd suggest you are going to really struggle with the task.. Sorry that is not meant as rudely as it sounds  but I'm sure you know what I'm trying to get at
I think maybe java suit this task better?
best of luck,
Sir P
|
|
|
|
10-14-2008, 07:27 AM
|
Re: Parse a file using php
|
Posts: 1,226
Name: Mike
Location: Mataro, Spain
|
Sir P, you are too narrow minded this time. You sincerely suppose that php can only generate html, but php can also purfectly draw lines and shapes with functions from GD image library.
|
|
|
|
10-14-2008, 07:33 AM
|
Re: Parse a file using php
|
Posts: 932
|
Hi mtishtsky,
No no, I'm well aware of the feats of the PHP GD library... as I said above, "it is indeed possible"... I said it would not be my choice of languages to undertake the task 
|
|
|
|
10-14-2008, 07:56 AM
|
Re: Parse a file using php
|
Posts: 1,226
Name: Mike
Location: Mataro, Spain
|
I guess that draw_line(x1,y1,x2,y2) is quite the same in different languages.
|
|
|
|
10-18-2008, 02:27 AM
|
Re: Parse a file using php
|
Posts: 116
Name: Paul
Location: South Africa
|
Thanks for the comments guys, I have been trying to get this working and so far so good, I am using php with the gd library to do this, however i am sure that you can both see that I do not do nearly enough php app dev and am not that good at it so I need all the help I can get from experienced people such as yourselves. At this point I am concentrating on the easier of the 2 codes imho, the cf2 or cff2 as it should be called.
So with a code that looks like this
Code:
$BOF (Begin of file)
MAIN,DESIGN1 (Begin of code block)
LL,-512.45,-13.85 (Lower Left co-ords)
UR,512.35,703.85 (Upper Right co-ords)
L,2,1,0,-49.5,-203.75,-49.5,-205.73,0,0 (Line co-ords)
A,2,1,0,-49.5,-205.73,-49.03,-207.34,-46.5,-205.73,1,0,0 (Angle co-ords)
L,2,1,0,-49.03,-207.34,-44.38,-214.61,0,0
A,2,1,0,-44.38,-214.61,-41.86,-216,-41.86,-213,1,0,0
END (End of code block)
$EOF (End of file)
I have altered it to make it look like this
Code:
<?php
// set the HTTP header type to PNG
header("Content-type: image/png");
$left = 512.45; // Took the first value of LL
$right = 512.35; // Took the first value of UR
$top = 703.85; // Took the second value of UR
$bottom = 13.85; // Took the second value of LL
$width = $bottom+$top; // Took the second value from the array LL and added it with the second value of the array UR
$height = $left+$right; // Took the first value from the array LL and added it with the first value of the array UR
// create a pointer to a new true colour image
$im = ImageCreateTrueColor($width, $height);
// switch on image antialising if it is available
ImageAntiAlias($im, true);
// sets background to white
$white = ImageColorAllocate($im, 255, 255, 255);
ImageFillToBorder($im, 0, 0, $white, $white);
// define a black colour
$black = ImageColorAllocate($im, 0, 0, 0);
// ImageLine syntax as follows
// bool ImageLine($image, $start_x, $start_y, $end_x, $end_y, $colour);
ImageLine($im, $left-49.5, ($height-203.75)+$bottom, $left-49.5, ($height-205.73)+$bottom, $black);
//bool ImageArc($image, $cx, $cy, $width, $height, $start, $end, $color);
ImageArc($im, $left-49.5, ($height-205.73)+$bottom, 49.5-49.03, 205.73-207.34, 0, 90, $black);
ImageLine($im, $left-49.03, ($height-207.34)+$bottom, $left-44.38, ($height-214.61)+$bottom, $black);
ImageArc($im, $left-44.38, ($height-214.61)+$bottom, 44.38-41.86, 214.61-266, 0, 90, $black);
/* Original code from CF2 file
$BOF (Begin of file)
MAIN,DESIGN1 (Begin of code block)
LL,-512.45,-13.85 (Lower Left co-ords)
UR,512.35,703.85 (Upper Right co-ords)
L,2,1,0,-49.5,-203.75,-49.5,-205.73,0,0 (Line co-ords)
A,2,1,0,-49.5,-205.73,-49.03,-207.34,-46.5,-205.73,1,0,0 (Angle co-ords)
L,2,1,0,-49.03,-207.34,-44.38,-214.61,0,0
A,2,1,0,-44.38,-214.61,-41.86,-266,-41.86,-213,1,0,0
END (End of code block)
$EOF (End of file)
*/
// send the new PNG image to the browser
ImagePNG($im);
// destroy the reference pointer to the image in memory to free up resources
ImageDestroy($im);
?>
Well all looks fine to me the huge problem here is that this was done manually, and there is no point in that, except for a test, now how do I begin asking php to do this for me, all by itself.
If anybody is really interested in helping with this task I could email you a cf2 file for testing purposes I have about 7000 of them to do in total.
Any advice on how to go about doing this, code snippets, general thoughts etc. would be greatly appreciated. I would love to offer out money but alas with my currency even if I bankrupted myself it would not be worth much to you 1st world country guys.
Thanks in advance
|
|
|
|
|
« Reply to Parse a file using php
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|