bscheibel 4 years ago
parent
commit
ef79c4d3d1

BIN
__pycache__/wsgi.cpython-37.pyc


+ 8 - 0
app/__init__.py~

@@ -0,0 +1,8 @@
+from flask import Flask
+
+#app = Flask(__name__)
+app = Flask(__name__, static_url_path="", static_folder="static")
+app.debug = True
+#app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
+
+from app import views

BIN
app/__pycache__/__init__.cpython-37.pyc


BIN
app/__pycache__/views.cpython-37.pyc


+ 232 - 0
app/static/js/js_libs/ui.js~

@@ -0,0 +1,232 @@
+/*
+  This file is part of CPEE.
+
+  CPEE is free software: you can redistribute it and/or modify it under the terms
+  of the GNU General Public License as published by the Free Software Foundation,
+  either version 3 of the License, or (at your option) any later version.
+
+  CPEE is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+  PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License along with
+  CPEE (file COPYING in the main directory).  If not, see
+  <http://www.gnu.org/licenses/>.
+*/
+
+function ui_click_tab(moi) { // {{{
+  $(moi).trigger('click');
+} // }}}
+
+function ui_close_tab(moi){
+  var active = $(moi).parent().attr('data-tab');
+  var tabbed = $(moi).parent().parent().parent();
+  var is_inactive = $(moi).parent().hasClass('inactive');
+  $('*[data-tab=' + active + ']').remove();
+  $('*[data-belongs-to-tab=' + active + ']').remove();
+  if (!is_inactive)
+    ui_click_tab($('ui-tabbar ui-tab.default'));
+}
+
+function ui_add_close(moi) {
+  $(moi).append($('<ui-close>✖</ui-close>'));
+}
+
+function ui_empty_tab_contents(id) {
+  $('ui-content ui-area[data-belongs-to-tab=' + id + ']').empty();
+}
+
+function ui_add_tab(tabbed,title,id,closeable,additionalclasses) {
+  additionalclasses = typeof additionalclasses !== 'undefined' ? additionalclasses : '';
+  if ($('ui-tabbar ui-tab[data-tab=' + id + ']').length > 0) {
+    ui_activate_tab($('ui-tabbar ui-tab[data-tab=' + id + ']'));
+    return false;
+  } else {
+    var instab = $("<ui-tab class='inactive" + (closeable ? ' closeable' : '') + (additionalclasses == '' ? '' : ' ' + additionalclasses) + "' data-tab='" + id + "'>" + title + "</ui-tab>");
+    var insarea = $("<ui-area data-belongs-to-tab='" + id + "' class='inactive' id="+ id +"></ui-area>");
+    $(tabbed).find('ui-behind').before(instab);
+    $(tabbed).find('ui-content').append(insarea);
+    ui_add_close($('ui-tabbar ui-tab[data-tab=' + id + ']'));
+    return true;
+  }
+}
+
+function create_new_tab(title, id,terms) {
+    //console.log(title,id);
+    if (terms != "empty"){
+    var terms = atob(terms);
+    var theDiv = document.getElementById(id);
+    //var content = document.createTextNode("Test");
+    //var content = document.createTextNode(terms);
+    var newElement = document.createElement('div');
+    var textElement = document.createElement('div');
+    var array_terms = JSON.parse(terms);
+    var len = Object.keys(array_terms).length;
+    console.log(len);
+    textElement.innerHTML += "<a onclick=change_isos_tab('"+id+"','start')> Start of ISO document </a><br>";
+    for (var key in array_terms) {
+        console.log(key);
+        //theDiv.appendChild(document.createTextNode(terms[key]));
+        textElement.innerHTML += "<a onclick=change_isos_tab('"+id+"','"+array_terms[key]+"')>"+key+" </a><br>";
+    }
+    newElement.setAttribute('id', "iso_"+id);
+    console.log(terms);
+    console.log(textElement)
+    newElement.innerHTML = "<iframe width=100% height=1000px src= '/edi2/isos/" + id  + ".PDF')'> </iframe>";
+    theDiv.appendChild(textElement);
+    theDiv.appendChild(newElement);
+    }
+    else{
+        var theDiv = document.getElementById(id);
+        var newElement = document.createElement('div');
+        var textElement = document.createElement('div');
+        textElement.innerHTML += "<a onclick=change_isos_tab('"+id+"','start')> Start of ISO File. </a><br>";
+        newElement.setAttribute('id', "iso_"+id);
+        //console.log(terms);
+        newElement.innerHTML = "<iframe width=100% height=1000px src= '/edi2/isos/" + id  + ".PDF')'> </iframe>";
+        newElement.innerHTML ="<h1> hallooo </>"
+        theDiv.appendChild(textElement);
+        theDiv.appendChild(newElement);
+    }
+    return true;
+}
+
+function change_isos_tab(id, term){
+    var theDiv = document.getElementById("iso_"+id);
+    if (term == "start"){
+        term = 1;
+    }
+    theDiv.innerHTML = "<iframe width=100% height=1000px src= '/edi2/isos/" + id  + ".PDF#page="+ term+"')'> </iframe>";
+    console.log(id,term);
+    return true;
+}
+
+function ui_add_tab_active(tabbed,title,id,closeable,additionalclasses, terms) {
+  var state = ui_add_tab(tabbed,title,id,closeable,additionalclasses);
+  console.log("test");
+  if (state) { create_new_tab(title, id, terms); }
+  if (state) { ui_activate_tab($('ui-tabbar ui-tab[data-tab=' + id + ']')); }
+  return state;
+}
+
+
+
+function ui_clone_tab(tabbar,original,title,id,closeable,additionalclasses) {
+  additionalclasses = typeof additionalclasses !== 'undefined' ? additionalclasses : '';
+  var instab = $("<ui-tab class='inactive" + (closeable ? ' closeable' : '') + (additionalclasses == '' ? '' : ' ' + additionalclasses) + "' data-tab='" + id + "' id='tab_" + id + "'>" + title + "</ui-tab>");
+  var insarea = original.clone();
+  insarea.attr("data-belongs-to-tab",id);
+  insarea.attr("class","inactive");
+  $(tabbar).find('ui-behind').before(instab);
+  $(tabbar).parent().append(insarea);
+  ui_add_close($('ui-tabbed ui-tab[data-tab=' + id + ']'));
+}
+
+(function($) { //{{{
+  $.fn.dragcolumn = function() {
+    var drag = $(this);
+    var prev = drag.prev();
+    var next = drag.next();
+
+    this.on("mousedown", function(e) {
+      drag.addClass('draggable');
+      $(document).one("mouseup", function(e) {
+        drag.removeClass('draggable');
+        e.preventDefault();
+      });
+      e.preventDefault();
+    });
+
+    $(document).on("mousemove", function(e) {
+      if (!drag.hasClass('draggable'))
+        return;
+
+      // Assume 50/50 split between prev and next then adjust to
+      // the next X for prev
+      var total = prev.outerWidth() + next.outerWidth();
+      var pos = e.pageX - prev.offset().left;
+      if (pos > total) {
+        pos = total;
+      }
+
+      var leftPercentage = pos / total;
+      var rightPercentage = 1 - leftPercentage;
+
+      prev.css('flex', leftPercentage.toString());
+      next.css('flex', rightPercentage.toString());
+
+      e.preventDefault();
+    });
+  }
+  $.fn.dragresize = function() {
+    var drag = $(this);
+    var prev = drag.prev();
+    var initpos = 0;
+    var initheight = $("ui-content",prev).height();
+
+    this.on("mousedown", function(e) {
+      drag.addClass('draggable');
+      initpos = e.pageY;
+      $(document).one("mouseup", function(e) {
+        drag.removeClass('draggable');
+        e.preventDefault();
+      });
+      e.preventDefault();
+    });
+
+    $(document).on("mousemove", function(e) {
+      if (!drag.hasClass('draggable'))
+        return;
+
+      var pos = initheight - (initpos - e.pageY);
+      if (pos < 0)
+        return;
+
+      $("ui-content",prev).css('height', pos.toString());
+
+      e.preventDefault();
+    });
+  }
+})(jQuery); //}}}
+
+function ui_activate_tab(moi) { // {{{
+  var active = $(moi).attr('data-tab');
+  var tabbed = $(moi).parent().parent();
+  var tabs = [];
+  $("ui-tabbar > ui-tab",tabbed).each(function(){
+    if (!$(this).attr('class').match(/switch/)) {
+      tabs.push($(this).attr('data-tab'));
+    }
+  });
+  $(".inactive",tabbed).removeClass("inactive");
+  $.each(tabs,function(a,b){
+    if (b != active) {
+      $("ui-tabbar ui-tab[data-tab=" + b + "]",tabbed).addClass("inactive");
+      $("ui-content *[data-belongs-to-tab=" + b + "]",tabbed).addClass("inactive");
+    }
+  });
+} // }}}
+function ui_toggle_vis_tab(moi) {// {{{
+  if ($(moi)[0].nodeName == 'UI-TABBED') {
+    var tabbed = $(moi);
+  }
+  if ($(moi)[0].nodeName == 'UI-TAB') {
+    var tabbed = $(moi).parent().parent();
+  }
+  if (tabbed) {
+    tabbed.toggleClass('off');
+  }
+}// }}}
+
+$(document).ready(function() {
+  if (!($.browser.name == "Firefox" && $.browser.version >= 20) && !($.browser.name == "Chrome" && $.browser.version >= 30)) {
+    $('body').children().remove();
+    $('body').append('Sorry, only Firefox >= 20.0 and Chrom(e|ium) >= 17 for now.');
+  }
+  $('ui-rest ui-content ui-resizehandle').dragcolumn();
+  $('*[is=x-ui] > ui-resizehandle').dragresize();
+  $(document).on('click','ui-tabbar ui-tab.switch',function(){ui_toggle_vis_tab(this);});
+  $(document).on('click','ui-tabbar ui-tab:not(.switch)',function(){ui_activate_tab(this);});
+  ui_add_close($('ui-tabbar ui-tab.closeable'));
+  $(document).on('click','ui-tabbar ui-tab.closeable ui-close',function(){ui_close_tab(this);});
+});

+ 325 - 0
app/templates/index.html~

@@ -0,0 +1,325 @@
+<!--This file is part of centurio.work/edi.
+
+  centurio.work/edi is free software: you can redistribute it and/or modify it
+  under the terms of the GNU General Public License as published by the Free
+  Software Foundation, either version 3 of the License, or (at your option) any
+  later version.
+
+  centurio.work/edi is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+  more details.
+
+  You should have received a copy of the GNU General Public License along with
+  centurio.work/edi (file COPYING in the main directory).  If not, see
+  <http://www.gnu.org/licenses/>.
+-->
+
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+    <title>Resources</title>
+
+    <!-- libs, do not modify. When local than load local libs. -->
+     <script type="text/javascript" src="/js_libs/jquery.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.browser.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.svg.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.svgdom.min.js"></script>
+    <script type="text/javascript" src="/js_libs/vkbeautify.js"></script>
+    <script type="text/javascript" src="/js_libs/util.js"></script>
+    <script type="text/javascript" src="/js_libs/printf.js"></script>
+    <script type="text/javascript" src="/js_libs/strftime.min.js"></script>
+    <script type="text/javascript" src="/js_libs/parsequery.js"></script>
+    <script type="text/javascript" src="/js_libs/underscore.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.caret.min.js"></script>
+    <script type="text/javascript" src="/js_libs/jquery.cookie.js"></script>
+
+    <script type="text/javascript" src="/edi2/js_libs/ui.js"></script>
+    <link   rel="stylesheet"      href="/js_libs/ui.css" type="text/css"/>
+
+    <link   rel="stylesheet"      href="/cdp_ui/ui.css" type="text/css"/>
+
+    <link   rel="stylesheet"      href="/edi2/css/ui.css" type="text/css"/>
+    
+	<!--<script type="text/javascript" src="{{ url_for('static', filename='js/js_libs/jquery.min.js') }}"></script>
+    <script type="text/javascript" src="{{ url_for('static', filename='js/js_libs/jquery.browser.js') }}"></script>
+    <script type="text/javascript" src="{{ url_for('static', filename='js/js_libs/jquery.svg.min.js') }}"></script>
+    <script type="text/javascript" src="{{ url_for('static', filename='js/js_libs/jquery.svgdom.min.js') }}"></script>
+    <script type="text/javascript" src="{{ url_for('static', filename='js/js_libs/vkbeautify.js') }}"></script>
+    <script type="text/javascript" src="{{ url_for('static', filename='js/js_libs/util.js') }}"></script>
+    <script type="text/javascript" src="{{ url_for('static', filename='js/js_libs/printf.js') }}"></script>
+    <script type="text/javascript" src="{{ url_for('static', filename='js/js_libs//strftime.min.js') }}"></script>
+    <script type="text/javascript" src="{{ url_for('static', filename='js/js_libs/parsequery.js') }}"></script>
+    <script type="text/javascript" src="{{ url_for('static', filename='js/js_libs/underscore.min.js') }}"></script>
+    <script type="text/javascript" src="{{ url_for('static', filename='js/js_libs/jquery.caret.min.js') }}"></script>
+    <script type="text/javascript" src="{{ url_for('static', filename='js/js_libs/jquery.cookie.js') }}"></script>
+
+    <script type="text/javascript" src="{{ url_for('static', filename='js/js_libs/ui.js') }}"></script>
+    <link   rel="stylesheet"      href="{{ url_for('static', filename='js/js_libs/ui.css') }}" type="text/css"/>
+
+    <link   rel="stylesheet"      href="{{ url_for('static', filename='js/js_libs/cdp_ui.css') }}" type="text/css"/>
+
+    <link   rel="stylesheet"      href="{{ url_for('static', filename='js/js_libs/css/ui.css') }}" type="text/css"/>-->
+    <link rel="stylesheet" href="/edi2/css/style.css" type="text/css"/>
+    <link rel="stylesheet" href="/edi2/css/layout.css" type="text/css"/>
+
+  <body is="x-ui">
+    <ui-rest id="main">
+      <ui-content>
+        <ui-area id='datacolumn'>
+          <!-- <ui-rest id="sub">  with this the content does not work for other tabs -->
+            <ui-tabbar>
+              <ui-before>
+                <a class="logo" href="/"> </a>
+              </ui-before>
+              <ui-tab class="default" data-tab="drawing" >Drawing
+
+              </ui-tab>
+
+              <ui-behind                                       ></ui-behind>
+            </ui-tabbar>
+         <!--</ui-rest>-->
+          <ui-content>
+              <ui-area data-belongs-to-tab="drawing" >
+                  <div class="images">
+                  <img  class="optcontent" id="drawing" src="{{ url_for('static', filename='edi2/out.jpg') }}" alt="Drawing">
+                  </div>
+
+              </ui-area>
+
+          </ui-content>
+        </ui-area>
+
+        <ui-resizehandle data-label="drag to resize"></ui-resizehandle>
+        <ui-area id="detailcolumn1" data-minsize="20em">
+            <h3 style="text-align:center"> General Information</h3>
+            <div id="dat_details" class='x-ui-layout'>
+
+                <div class="column-one" style="width:50%;float:left">
+
+                  {{ html_links | safe }}
+
+                {% for iso in isos_names %}
+                    {{ iso }} (Document not available)<br>
+                {% endfor %}
+
+                </div>
+                <div class="column-two" style="width:50%;float:right">
+
+                {{ html_general | safe }}
+                </div>
+            </div>
+          <div id="measurements">
+                <font >
+                <form>
+                <table>
+                    <tr>
+                        <td style="text-align:center"><h3>Key Value</h3></td>
+                        <td style="text-align:center"><h3>Target Value</h3></td>
+                        <td style="text-align:center"><h3>Actual Value</h3></td>
+                        <td style="text-align:center"><h3>Relevant Isos</h3></td>
+                    </tr>
+
+                        {{ text | safe}}
+
+                </table>
+                </form>
+                </font>
+
+           </div>
+        </ui-area>
+
+      </ui-content>
+    </ui-rest>
+
+
+    <script>
+    function log(){
+      console.log("test");
+
+    }
+
+    function set_redis(key, value) {
+
+        $.ajax({
+            type: "POST",
+            url: "/redis/set/" + key,
+            data: JSON.stringify({ value: value }),
+            dataType: "json",
+            contentType: "json",
+            success: function(data)
+            {
+                (data.GET);
+            }
+        });
+    }
+
+     function get_redis(key) {
+        $.ajax({
+            type: "GET",
+            url: "redis/get/" + key,
+            data: "format=json",
+            dataType: "text",
+            success: function(data)
+            {
+                $("#result").text(data.GET);
+            }
+        });
+       }
+
+      function split_string(string) {
+            var string = str.split(" ",2);
+            return string;
+        };
+
+    </script>
+
+<script>
+
+
+    $(document).ready(function(){
+
+        $("input[type=number]").on("change keyup input", function(){
+            var array_value = [];
+            array_value[0] = $(this).attr('name');
+            array_value[1] = $(this).val();
+
+            var key = 'last' + "_" +'{{og_filename}}';
+
+            //console.log({{ dim }});
+            set_redis(key, array_value);
+        });
+
+        $("input[type=checkbox]").change(function(){
+
+           // Print entered value in a div box
+           $("#result").text($(this).attr('name'));
+           var key1 = 'last' + "_" +'{{og_filename}}';
+           var array_value1 = [];
+
+           if ($(this).is(':checked')) {
+                console.log($(this).attr('name') + ' is now checked');
+                array_value1[0] = 'relevant.' + $(this).attr('name');
+                array_value1[1] = true;
+            } else {
+                console.log($(this).attr('name') + ' is now unchecked');
+                array_value1[0] = $(this).attr('name');
+                array_value1[1] = false;
+            }
+
+           set_redis(key1, array_value1);
+
+        });
+
+
+
+        $("input[type=number]").focus(function(){
+
+
+
+
+            var number = $(this).attr('name');
+            var coords = $(this).attr('data-coords');
+            highlight_areas(coords, "red");
+            var detail = $(this).attr('data-details');
+            console.log(detail, "green");
+            highlight_details(detail, "green");
+
+        });
+
+        $("input[type=number]").blur(function(){
+
+          $("div").removeClass("red");
+          $("div").removeClass("green");
+
+        });
+
+
+      function highlight_areas(coords, color){
+
+       let w = {{w}}
+       let h = {{h}}
+       let pos = $("#drawing").position();
+       let drawing_x = pos.left;
+       let drawing_y = pos.top;
+       let array_coords = coords.split(",");
+       let coords_x = parseFloat(array_coords[0]);
+       let coords_xmax = parseFloat(array_coords[2]);
+       let coords_y = parseFloat(array_coords[1]);
+       let coords_ymax = parseFloat(array_coords[3]);
+       let coords_width = (coords_xmax - coords_x);
+
+       let coords_height = (coords_ymax - coords_y);
+
+
+       let width = $("#drawing").width();
+       let height = $("#drawing").height();
+       let rel_width = coords_width/h*width*1.4;
+       let rel_height = coords_height/w*height*1.4;
+       var orientation = "{{orientation}}";
+       var x = 0;
+       var y = 0;
+
+       if (orientation == "landscape"){
+            x = width*(coords_x*height/width/w);
+            y = height*(coords_y*width/height/h);
+       }
+       else {
+
+            x = width*(coords_x/w);
+            y = height*(coords_y/h);
+       }
+
+
+       console.log(w, h, rel_width, rel_height,x,y);
+
+       let $point1 = jQuery("<div class="+color+"/>").css({top: (drawing_y + y -5) + 'px', left: (drawing_x + x-5) + 'px', width: rel_width , height: rel_height});
+
+        $(".images").append($point1);
+
+        };
+
+       function highlight_details(coords, color){
+
+       let w = {{w}}
+       let h = {{h}}
+       let pos = $("#drawing").position();
+       let drawing_x = pos.left;
+       let drawing_y = pos.top;
+       let array_coords = coords.split(",");
+       let coords_x = parseFloat(array_coords[0]);
+       let coords_y = parseFloat(array_coords[1]);
+       let width_div = (parseFloat(array_coords[2]) - parseFloat(array_coords[0]));
+
+       let height_div = (parseFloat(array_coords[3]) - parseFloat(array_coords[1]));
+
+
+
+       let width = $("#drawing").width();
+       let rel_width = width_div/h*width;
+
+
+       let height = $("#drawing").height();
+       let rel_height = height*height_div/w;
+
+       let x = width*(coords_x*height/width/w);
+       let y= height*(coords_y*width/height/h);
+       console.log(rel_width, rel_height);
+       if (array_coords[3] > 10000) {
+           rel_height = height - y;
+
+       }
+
+
+       let $point = jQuery("<div class="+color+"/>").css({top: (drawing_y + y) + 'px', left: (drawing_x + x) + 'px', width: (rel_width) + 'px', height: (rel_height) + 'px'});
+
+        $(".images").append($point);
+
+        };
+
+     });
+
+  </script>
+  </body>
+</html>

+ 292 - 0
app/views.py~

@@ -0,0 +1,292 @@
+#encoding
+from app import app
+from flask import request, redirect, url_for, send_from_directory, render_template
+import subprocess
+import redis
+import random
+import PyPDF2
+import json
+import base64
+import os
+import json
+import re
+import base64
+#https://medium.com/@emerico/convert-pdf-to-image-using-python-flask-2864fb655e01
+
+#path = "/home/bscheibel/app/app"
+path = "/home/centurio/Projects/engineering_drawings_ui/app"
+
+#path_extraction = '/home/bscheibel/PycharmProjects/dxf_reader/main.py'
+path_extraction = "/home/centurio/Projects/engineering_drawings_extraction/main.py"
+UPLOAD_FOLDER = path + "/temporary/"
+app.config["UPLOAD_FOLDER"] = UPLOAD_FOLDER
+ALLOWED_EXTENSIONS = set(['pdf', 'png', 'jpg', 'jpeg', 'PDF'])
+
+
+def allowed_file(filename):
+    return '.' in filename and \
+           filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
+
+def convert_pdf_img(filename):
+    PDFFILE = UPLOAD_FOLDER +"/" + filename
+    subprocess.call(['pdftoppm', '-jpeg', '-singlefile',
+                     PDFFILE,  '/edi2/out'])
+
+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)])
+
+def get_file_size(file):
+    pdf = PyPDF2.PdfFileReader(file)
+    p = pdf.getPage(0)
+
+    w = p.mediaBox.getWidth()
+    h= p.mediaBox.getHeight()
+    OrientationDegrees = p.get('/Rotate')
+    if OrientationDegrees != 0 :
+        orientation = "landscape"
+    else:
+        orientation = "portrait"
+
+    print(w,h,OrientationDegrees)
+    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):
+    link_names = {}
+    isos_names = []
+    isos = list(set(isos))
+    reg_isos = r"(ISO\s\d*)\s1\-(\d?)"
+    print(isos)
+    isos_new = []
+    for name in isos:
+        if re.search(reg_isos, name):
+            n = 1
+            #print(name)
+            new_isos = re.search(reg_isos,name).group(1)
+            number = re.search(reg_isos,name).group(2)
+            while n <= int(number):
+                isos_new.append(new_isos+"-"+str(n))
+                n += 1
+        else:
+            isos_new.append(name)
+    for name in isos_new:
+        try:
+            name = name.replace(" ", "")
+            #name = name.replace("-"," ")
+            url1 = name + ".PDF"
+            #print(url)
+            file = send_from_directory("static/isos",url1)
+            url = "isos/" + url1
+            #link_names.append(url)
+            link_names[name] = url
+            #print(link_names)
+        except:
+            #print(name)
+            isos_names.append(name)
+    return link_names, isos_names
+
+
+@app.route('/', methods=['GET', 'POST'])
+def upload_file():
+    if request.method == 'POST':
+        file = request.files['file']
+        if file and allowed_file(file.filename):
+            filename = file.filename
+            basedir = os.path.abspath(os.path.dirname(__file__))
+            file.save(os.path.join(basedir,app.config["UPLOAD_FOLDER"], filename))
+            uuid = random.randint(100,10000000)
+            extract_all(uuid, filename, 'localhost')
+            return redirect(url_for('uploaded_file', filename=filename, uuid=uuid))
+    return '''
+    <!doctype html>
+    <title>Upload new File</title>
+    <h1>Upload new File</h1>
+    <form action="" method=post enctype=multipart/form-data>
+      <p><input type=file name=file>
+         <input type=submit value=Upload>
+    </form>
+    '''
+
+@app.route('/show/<filename>&<uuid>')
+def uploaded_file(filename, uuid):
+    file_out = "out.jpg"
+    #file_out = filename
+    #if request.method == 'POST':
+    #    uuid = 433
+    if filename.endswith(".pdf") or filename.endswith(".PDF"):
+        w,h, orientation = get_file_size(UPLOAD_FOLDER +"/" + filename)
+        convert_pdf_img(filename)
+        db = redis.Redis(unix_socket_path='/tmp/redis.sock',db=7)
+        #db = redis.Redis("unix_socket_path='127.0.0.1',6379,db=7")
+        #isos = db.get(uuid+"dims")
+        #print(iso)
+        gen_tol = db.get(str(uuid)+"tol")
+        print(gen_tol)
+        isos = json.loads(db.get(str(uuid)+"isos"))
+        links, isos_names = check_links(isos)
+        dims = json.loads(db.get(str(uuid)+"dims"))
+        details = json.loads(db.get(str(uuid) + "details"))
+        number_blocks = db.get(str(uuid)+"eps")
+        html_code = "General tolerances according to: " + str(gen_tol) + "<br>"
+        html_general = ""
+        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"
+        with open(path +'/static/config.json') as f:
+            config_file = json.load(f)
+            print(config_file)
+
+        for dim in sorted(dims):
+            #print(dim)
+            for det in details:
+                #print(det)
+                try:
+                    if dim == det:
+                        det_coords = details[det]
+                        det_coords = ",".join(str(det) for det in det_coords)
+                except:
+                    det_coords = "0,0,0,0"
+            if "ZZZZ" in dim:
+                for d in dims[dim]:
+                    html_general += d + "<br>"
+                continue
+            else:
+                html_code += "<td><h4>" + dim + "</h4></td>"
+            for d in dims[dim]:
+                relevant_isos = []
+                search_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:
+                    if re.search(conf,d):
+                        iso = config_file[conf]
+                        for key in iso:
+                            relevant_isos.append(key)
+                            for blub in iso[key]:
+                                search_terms[blub] = iso[key][blub]
+
+                        #terms = '{"Symbole":1,"Tabelle":2,"Definition":3}'
+                        if len(search_terms) < 1:
+                            search_terms["Beginn"] = 1
+                        terms = json.dumps(search_terms)
+                        #print(terms)
+                        terms = base64.b64encode(terms.encode()).decode('utf-8')
+                        #terms = "blub"
+
+
+
+                try:
+                    number = re.search(reg, d)
+                    number = number.group(1)
+                    try:
+                        floats = len(number.split(".")[1])
+                        if floats <= 1:
+                            steps = 0.1
+                        elif floats == 2:
+                            steps = 0.01
+                        elif floats == 3:
+                            steps = 0.001
+                        else:
+                            steps = 0.001
+                    except:
+                        steps = 0.1
+                except:
+                    number = d
+                    steps = 0.1
+                coords = ",".join(str(e) for e in dims[dim][d])
+                html_code += "<tr><td style='text-align:center'> <input type='checkbox' name='relevant." + d + "' value='checked'> </td>" + \
+                             "<td style='text-align:center'>" + d + "</td>" + \
+                             "<td max='3' style='text-align:center'> <input type='number' step='" + str(steps) + "' data-coords='" + coords + " 'data-details='" + det_coords  +"'' name='" + d + "' value='" + number + "'> </td>"
+
+                relevant_isos = list(set(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>"
+                #print(html_code)
+                html_code += "</tr>"
+                html_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 += "<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('test_pdfjs_textlayer.html', og_filename=filename)
+
+    #else:
+    #    filename = filename
+    #    return render_template('show_image.html', filename=filename)
+
+
+@app.route('/uploads/<filename>')
+def send_file(filename):
+    return send_from_directory(UPLOAD_FOLDER, filename)
+
+# No caching at all for API endpoints.
+@app.after_request
+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['Pragma'] = 'no-cache'
+    response.headers['Expires'] = '-1'
+    response.headers['Access-Control-Allow-Origin'] = '*'
+    response.headers.add("Access-Control-Allow-Headers", "*")
+    response.headers.add("Access-Control-Allow-Methods", "*")
+    return response
+
+
+
+@app.route('/redis/get/<key>',methods=['GET'])
+def redis_get(key):
+    db = redis.Redis(unix_socket_path='/tmp/redis.sock',db=7)
+    result = json.loads(db.get(key))
+    return result
+
+@app.route('/redis/set/<key>',methods=['POST'])
+def redis_set(key):
+    value = request.get_json(force=True)
+    value = value["value"]
+    db = redis.Redis(unix_socket_path='/tmp/redis.sock',db=7)
+
+    value_name = value[0]
+    value_v = value[1]
+    try:
+        result = json.loads(db.get(key))
+        result[value_name] = value_v
+        json_res = json.dumps(result)
+        db.set(key,json_res)
+    except:
+        dict_res = {}
+        dict_res[value_name] = value_v
+        json_dict = json.dumps(dict_res)
+        db.set(key, json_dict)
+    return "OK"
+
+
+
+@app.route('/index')
+def test():
+    return render_template('index.html')
+

+ 5 - 0
wsgi.py~

@@ -0,0 +1,5 @@
+from app import app
+
+if __name__ == "__main__":
+    app.run()
+    server = Flask(__name__, static_url_path="", static_folder="static")