|
@@ -5,13 +5,10 @@ import subprocess
|
|
import redis
|
|
import redis
|
|
import random
|
|
import random
|
|
import PyPDF2
|
|
import PyPDF2
|
|
-import json
|
|
|
|
-import base64
|
|
|
|
import os
|
|
import os
|
|
import json
|
|
import json
|
|
import re
|
|
import re
|
|
import base64
|
|
import base64
|
|
-#https://medium.com/@emerico/convert-pdf-to-image-using-python-flask-2864fb655e01
|
|
|
|
|
|
|
|
#path = "/home/bscheibel/app/app"
|
|
#path = "/home/bscheibel/app/app"
|
|
path = "/home/centurio/Projects/engineering_drawings_ui/app/app"
|
|
path = "/home/centurio/Projects/engineering_drawings_ui/app/app"
|
|
@@ -33,7 +30,6 @@ def convert_pdf_img(filename):
|
|
PDFFILE, path + '/temporary/out'])
|
|
PDFFILE, path + '/temporary/out'])
|
|
|
|
|
|
def extract_all(uuid, filename, db):
|
|
def extract_all(uuid, filename, db):
|
|
- #order_bounding_boxes_in_each_block.main(uuid, UPLOAD_FOLDER + "/" + filename)
|
|
|
|
subprocess.call(['python3', path_extraction, str(uuid),UPLOAD_FOLDER + "/" + filename, db, str(0)])
|
|
subprocess.call(['python3', path_extraction, str(uuid),UPLOAD_FOLDER + "/" + filename, db, str(0)])
|
|
|
|
|
|
def get_file_size(file):
|
|
def get_file_size(file):
|
|
@@ -51,19 +47,6 @@ def get_file_size(file):
|
|
print(w,h,OrientationDegrees)
|
|
print(w,h,OrientationDegrees)
|
|
return w,h, orientation
|
|
return w,h, orientation
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-def check_config_file(d):
|
|
|
|
- reg_search = d
|
|
|
|
- #print(reg_search)
|
|
|
|
-
|
|
|
|
- for conf in d:
|
|
|
|
- print(conf)
|
|
|
|
-
|
|
|
|
- return "blub"
|
|
|
|
-
|
|
|
|
-
|
|
|
|
def check_links(isos):
|
|
def check_links(isos):
|
|
link_names = {}
|
|
link_names = {}
|
|
isos_names = []
|
|
isos_names = []
|
|
@@ -74,7 +57,6 @@ def check_links(isos):
|
|
for name in isos:
|
|
for name in isos:
|
|
if re.search(reg_isos, name):
|
|
if re.search(reg_isos, name):
|
|
n = 1
|
|
n = 1
|
|
- #print(name)
|
|
|
|
new_isos = re.search(reg_isos,name).group(1)
|
|
new_isos = re.search(reg_isos,name).group(1)
|
|
number = re.search(reg_isos,name).group(2)
|
|
number = re.search(reg_isos,name).group(2)
|
|
while n <= int(number):
|
|
while n <= int(number):
|
|
@@ -85,16 +67,10 @@ def check_links(isos):
|
|
for name in isos_new:
|
|
for name in isos_new:
|
|
try:
|
|
try:
|
|
name = name.replace(" ", "")
|
|
name = name.replace(" ", "")
|
|
- #name = name.replace("-"," ")
|
|
|
|
url1 = name + ".PDF"
|
|
url1 = name + ".PDF"
|
|
- #print(url)
|
|
|
|
- file = send_from_directory("static/isos",url1)
|
|
|
|
url = "isos/" + url1
|
|
url = "isos/" + url1
|
|
- #link_names.append(url)
|
|
|
|
link_names[name] = url
|
|
link_names[name] = url
|
|
- #print(link_names)
|
|
|
|
except:
|
|
except:
|
|
- #print(name)
|
|
|
|
isos_names.append(name)
|
|
isos_names.append(name)
|
|
return link_names, isos_names
|
|
return link_names, isos_names
|
|
|
|
|
|
@@ -123,15 +99,10 @@ def upload_file():
|
|
@app.route('/show/<filename>&<uuid>')
|
|
@app.route('/show/<filename>&<uuid>')
|
|
def uploaded_file(filename, uuid):
|
|
def uploaded_file(filename, uuid):
|
|
file_out = "out.jpg"
|
|
file_out = "out.jpg"
|
|
- #file_out = filename
|
|
|
|
- #if request.method == 'POST':
|
|
|
|
- # uuid = 433
|
|
|
|
if filename.endswith(".pdf") or filename.endswith(".PDF"):
|
|
if filename.endswith(".pdf") or filename.endswith(".PDF"):
|
|
w,h, orientation = get_file_size(UPLOAD_FOLDER +"/" + filename)
|
|
w,h, orientation = get_file_size(UPLOAD_FOLDER +"/" + filename)
|
|
convert_pdf_img(filename)
|
|
convert_pdf_img(filename)
|
|
db = redis.Redis("localhost")
|
|
db = redis.Redis("localhost")
|
|
- #isos = db.get(uuid+"dims")
|
|
|
|
- #print(iso)
|
|
|
|
gen_tol = db.get(str(uuid)+"tol")
|
|
gen_tol = db.get(str(uuid)+"tol")
|
|
print(gen_tol)
|
|
print(gen_tol)
|
|
isos = json.loads(db.get(str(uuid)+"isos"))
|
|
isos = json.loads(db.get(str(uuid)+"isos"))
|
|
@@ -142,16 +113,12 @@ def uploaded_file(filename, uuid):
|
|
html_code = "General tolerances according to: " + gen_tol + "<br>"
|
|
html_code = "General tolerances according to: " + gen_tol + "<br>"
|
|
html_general = ""
|
|
html_general = ""
|
|
reg = r"(-?\d{1,}\.?\d*)"
|
|
reg = r"(-?\d{1,}\.?\d*)"
|
|
- #re_gewinde = r"M\d{1,2}"
|
|
|
|
- #re_passungen = r"h\d{1,2}|H\d{1,2}"
|
|
|
|
det_coords= "0,0,0,0"
|
|
det_coords= "0,0,0,0"
|
|
with open(path+ '/config.json') as f:
|
|
with open(path+ '/config.json') as f:
|
|
config_file = json.load(f)
|
|
config_file = json.load(f)
|
|
|
|
|
|
for dim in sorted(dims):
|
|
for dim in sorted(dims):
|
|
- #print(dim)
|
|
|
|
for det in details:
|
|
for det in details:
|
|
- #print(det)
|
|
|
|
try:
|
|
try:
|
|
if dim == det:
|
|
if dim == det:
|
|
det_coords = details[det]
|
|
det_coords = details[det]
|
|
@@ -168,16 +135,6 @@ def uploaded_file(filename, uuid):
|
|
relevant_isos = []
|
|
relevant_isos = []
|
|
search_terms = {}
|
|
search_terms = {}
|
|
terms = ''
|
|
terms = ''
|
|
- #if "Ra" in d or "Rz" in d or "Rpk" in d:
|
|
|
|
- # relevant_isos.append("ISO4287.PDF")
|
|
|
|
- #if u"\u27C2" in d or u"\u25CE" in d or u"\u232D" in d or u"\u2225" in d or u"\u232F" in d or u"\u2316" in d or u"\u2313" in d or u"\u23E5" in d:
|
|
|
|
- # relevant_isos.append("ISO1101.PDF")
|
|
|
|
- #if re.search(re_gewinde,d):
|
|
|
|
- # relevant_isos.append("ISO6410.PDF")
|
|
|
|
- #if "GG" in d or "CT" in d or "GX" in d:
|
|
|
|
- # relevant_isos.append("ISO14405-1.PDF")
|
|
|
|
- #if re.search(re_passungen,d):
|
|
|
|
- # relevant_isos.append("ISO286-1.PDF")
|
|
|
|
for conf in config_file:
|
|
for conf in config_file:
|
|
if re.search(conf,d):
|
|
if re.search(conf,d):
|
|
iso = config_file[conf]
|
|
iso = config_file[conf]
|
|
@@ -185,17 +142,10 @@ def uploaded_file(filename, uuid):
|
|
relevant_isos.append(key)
|
|
relevant_isos.append(key)
|
|
for blub in iso[key]:
|
|
for blub in iso[key]:
|
|
search_terms[blub] = iso[key][blub]
|
|
search_terms[blub] = iso[key][blub]
|
|
-
|
|
|
|
- #terms = '{"Symbole":1,"Tabelle":2,"Definition":3}'
|
|
|
|
if len(search_terms) < 1:
|
|
if len(search_terms) < 1:
|
|
search_terms["Beginn"] = 1
|
|
search_terms["Beginn"] = 1
|
|
terms = json.dumps(search_terms)
|
|
terms = json.dumps(search_terms)
|
|
- #print(terms)
|
|
|
|
terms = base64.b64encode(terms.encode())
|
|
terms = base64.b64encode(terms.encode())
|
|
- #terms = "blub"
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
try:
|
|
try:
|
|
number = re.search(reg, d)
|
|
number = re.search(reg, d)
|
|
number = number.group(1)
|
|
number = number.group(1)
|
|
@@ -221,31 +171,19 @@ def uploaded_file(filename, uuid):
|
|
|
|
|
|
relevant_isos = list(set(relevant_isos))
|
|
relevant_isos = list(set(relevant_isos))
|
|
for x in relevant_isos:
|
|
for x in relevant_isos:
|
|
- #html_code += "<td style='text-align:left'> <a href=" + url_for('static', filename="isos/"+x) + " >"+ x.partition(".")[0] +"</a> </td>"
|
|
|
|
html_code += "<td style='text-align:left' data-terms='" + terms + "'> <a onclick=ui_add_tab_active('#main','" + x.partition(".")[0] + "','" + x.partition(".")[0] +"',true,'isotab','"+terms+"')>" + x.partition(".")[0] + "</a> </td>"
|
|
html_code += "<td style='text-align:left' data-terms='" + terms + "'> <a onclick=ui_add_tab_active('#main','" + x.partition(".")[0] + "','" + x.partition(".")[0] +"',true,'isotab','"+terms+"')>" + x.partition(".")[0] + "</a> </td>"
|
|
- #print(html_code)
|
|
|
|
html_code += "</tr>"
|
|
html_code += "</tr>"
|
|
html_links = ""
|
|
html_links = ""
|
|
for link in links:
|
|
for link in links:
|
|
html_links += "<a onclick =ui_add_tab_active('#main','" + link + "','" + link +"',true,'isotab','empty')> Open " + link + "</a> <br>"
|
|
html_links += "<a onclick =ui_add_tab_active('#main','" + link + "','" + link +"',true,'isotab','empty')> Open " + link + "</a> <br>"
|
|
- #html_links += "<tr> <td> <a onclick =ui_add_tab_active('#main','iso1','iso1',true,'isotab')> Open " + link + " in Tab </a> </td> </tr>"""
|
|
|
|
- #print("teeest")
|
|
|
|
return render_template('index.html', filename=file_out, isos=isos, dims=dims, text=html_code,html_general=html_general, number=number_blocks, og_filename=filename, w=w, h=h, html_links=html_links, isos_names=isos_names, orientation=orientation)
|
|
return render_template('index.html', filename=file_out, isos=isos, dims=dims, text=html_code,html_general=html_general, number=number_blocks, og_filename=filename, w=w, h=h, html_links=html_links, isos_names=isos_names, orientation=orientation)
|
|
- #return render_template('test_pdfjs_textlayer.html', og_filename=filename)
|
|
|
|
-
|
|
|
|
- #else:
|
|
|
|
- # filename = filename
|
|
|
|
- # return render_template('show_image.html', filename=filename)
|
|
|
|
-
|
|
|
|
|
|
|
|
@app.route('/uploads/<filename>')
|
|
@app.route('/uploads/<filename>')
|
|
def send_file(filename):
|
|
def send_file(filename):
|
|
return send_from_directory(UPLOAD_FOLDER, filename)
|
|
return send_from_directory(UPLOAD_FOLDER, filename)
|
|
|
|
|
|
-# No caching at all for API endpoints.
|
|
|
|
@app.after_request
|
|
@app.after_request
|
|
def add_header(response):
|
|
def add_header(response):
|
|
- # response.cache_control.no_store = True
|
|
|
|
response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0'
|
|
response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0'
|
|
response.headers['Pragma'] = 'no-cache'
|
|
response.headers['Pragma'] = 'no-cache'
|
|
response.headers['Expires'] = '-1'
|
|
response.headers['Expires'] = '-1'
|
|
@@ -282,9 +220,3 @@ def redis_set(key):
|
|
db.set(key, json_dict)
|
|
db.set(key, json_dict)
|
|
return "OK"
|
|
return "OK"
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-@app.route('/index')
|
|
|
|
-def test():
|
|
|
|
- return render_template('index.html')
|
|
|
|
-
|
|
|