-2

i need to make a windows based desktop software. I have a number of simple autocad drawings file (*.dxf). If i get a new drawing I need to check if the drawing exists in the system. the *.dxf file contains different sections(HEADER,CLASSES,ENTITIES ETC). I only require "ENTITIES" section where the coordinates of the lines are given. for example,

ENTITIES
  0
LINE
  5
3B
  8
LAYER1
 10
221.190559
 20
185.708994
 30
0.0
 11
241.344721
 21
183.18762
 31
0.0
  0
LINE
  5
3C
  8
LAYER1
 10
241.344721
 20
183.18762
 30
0.0
 11
242.099368
 21
181.026461
 31
0.0
  0
ENDSEC

the next line after "10" gives x coordinates of starting point of the line the line after "20" gives y coordinates of starting point of the line

line after "11" gives x coordinates of last point of line line after "21" gives y coordinates of last point of line

i need to extract these values and add to a database. if i get a new file, i need to check if the new drawing matches any in the database. This is not a server based requirement. I need to use this in my pc. Now, I have basic knowledge in java,sql. can anybody guide me on what all tools i may need for this and the route i should follow.

CL.
  • 173,858
  • 17
  • 217
  • 259
mahe
  • 1
  • 1

1 Answers1

0

I'll split the answer in two parts

Extracting Relevant infos

I assume that the HEADER & CLASSES parts are not neccessary for evaluating if a file has changed.

I would read the File into a String in Java (or if they are really large, work with streams, but String is easier for starters). After that you can extract the section that's relevant to you - in your case it's the entities section.

If you need an idea how that's gonna work - How to split a string in Java

Comparing to existing files

I wouldn't store this whole string in the database, if it's just for matching if the file already exists. I would use a hash function for calculating the hash of the file (you can imagine it as a fingerprint of the document) and only storing the hash in the database. When a new file arrives, you calculate the hash of the relevant parts again and match it for existing hashes in the database. This way, you don't need to compare against each full file byte for byte in your database, you'll only need to look at the hash - which would be a simple SELECT * FROM Files WHERE hash = ':yourhashgoeshere'

If you're unsure how to implement such a hashing method - Hash String via SHA-256 in Java

Community
  • 1
  • 1
Simon
  • 21
  • 3
  • i cannot just compare the exact entities section of one file with another because the co-ordinates may vary even if u move the drawing from one place to another. There also comes a case where i may have a 90% match. I need to get that too...so i dont suppose i can use hash. – mahe Dec 18 '15 at 09:13