bscheibel пре 4 година
родитељ
комит
f40f2d3d29

+ 7 - 1
app/static/css/style.css

@@ -81,4 +81,10 @@ top: 0px;
   border: 0;
   height: 50%;
   width: 100%;
-}
+}
+
+table {
+    margin:auto;
+  }
+
+#datacolumn { padding: 0; }

BIN
app/static/isos/ISO1101.PDF


BIN
app/static/isos/ISO14405-1.PDF


BIN
app/static/isos/ISO14405-2.PDF


BIN
app/static/isos/ISO14405-3.PDF


BIN
app/static/isos/ISO2768-1.PDF


BIN
app/static/isos/ISO2768-2.PDF


BIN
app/static/isos/ISO286-2.PDF


BIN
app/static/isos/ISO8015.PDF


Разлика између датотеке није приказан због своје велике величине
+ 1916 - 0
app/static/js/viewer.css


+ 225 - 0
app/static/js/viewer.js

@@ -0,0 +1,225 @@
+/* Copyright 2016 Mozilla Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/* globals chrome */
+
+'use strict';
+
+if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME')) {
+  var defaultUrl; // eslint-disable-line no-var
+
+  (function rewriteUrlClosure() {
+    // Run this code outside DOMContentLoaded to make sure that the URL
+    // is rewritten as soon as possible.
+    let queryString = document.location.search.slice(1);
+    let m = /(^|&)file=([^&]*)/.exec(queryString);
+    defaultUrl = m ? decodeURIComponent(m[2]) : '';
+
+    // Example: chrome-extension://.../http://example.com/file.pdf
+    let humanReadableUrl = '/' + defaultUrl + location.hash;
+    history.replaceState(history.state, '', humanReadableUrl);
+    if (top === window) {
+      chrome.runtime.sendMessage('showPageAction');
+    }
+  })();
+}
+
+let pdfjsWebApp, pdfjsWebAppOptions;
+if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION')) {
+  pdfjsWebApp = require('./app.js');
+  pdfjsWebAppOptions = require('./app_options.js');
+}
+
+if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
+  require('./firefoxcom.js');
+  require('./firefox_print_service.js');
+}
+if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('GENERIC')) {
+  require('./genericcom.js');
+}
+if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME')) {
+  require('./chromecom.js');
+}
+if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME || GENERIC')) {
+  require('./pdf_print_service.js');
+}
+
+function getViewerConfiguration() {
+  return {
+    appContainer: document.body,
+    mainContainer: document.getElementById('viewerContainer'),
+    viewerContainer: document.getElementById('viewer'),
+    eventBus: null, // Using global event bus with (optional) DOM events.
+    toolbar: {
+      container: document.getElementById('toolbarViewer'),
+      numPages: document.getElementById('numPages'),
+      pageNumber: document.getElementById('pageNumber'),
+      scaleSelectContainer: document.getElementById('scaleSelectContainer'),
+      scaleSelect: document.getElementById('scaleSelect'),
+      customScaleOption: document.getElementById('customScaleOption'),
+      previous: document.getElementById('previous'),
+      next: document.getElementById('next'),
+      zoomIn: document.getElementById('zoomIn'),
+      zoomOut: document.getElementById('zoomOut'),
+      viewFind: document.getElementById('viewFind'),
+      openFile: document.getElementById('openFile'),
+      print: document.getElementById('print'),
+      presentationModeButton: document.getElementById('presentationMode'),
+      download: document.getElementById('download'),
+      viewBookmark: document.getElementById('viewBookmark'),
+    },
+    secondaryToolbar: {
+      toolbar: document.getElementById('secondaryToolbar'),
+      toggleButton: document.getElementById('secondaryToolbarToggle'),
+      toolbarButtonContainer:
+        document.getElementById('secondaryToolbarButtonContainer'),
+      presentationModeButton:
+        document.getElementById('secondaryPresentationMode'),
+      openFileButton: document.getElementById('secondaryOpenFile'),
+      printButton: document.getElementById('secondaryPrint'),
+      downloadButton: document.getElementById('secondaryDownload'),
+      viewBookmarkButton: document.getElementById('secondaryViewBookmark'),
+      firstPageButton: document.getElementById('firstPage'),
+      lastPageButton: document.getElementById('lastPage'),
+      pageRotateCwButton: document.getElementById('pageRotateCw'),
+      pageRotateCcwButton: document.getElementById('pageRotateCcw'),
+      cursorSelectToolButton: document.getElementById('cursorSelectTool'),
+      cursorHandToolButton: document.getElementById('cursorHandTool'),
+      scrollVerticalButton: document.getElementById('scrollVertical'),
+      scrollHorizontalButton: document.getElementById('scrollHorizontal'),
+      scrollWrappedButton: document.getElementById('scrollWrapped'),
+      spreadNoneButton: document.getElementById('spreadNone'),
+      spreadOddButton: document.getElementById('spreadOdd'),
+      spreadEvenButton: document.getElementById('spreadEven'),
+      documentPropertiesButton: document.getElementById('documentProperties'),
+    },
+    fullscreen: {
+      contextFirstPage: document.getElementById('contextFirstPage'),
+      contextLastPage: document.getElementById('contextLastPage'),
+      contextPageRotateCw: document.getElementById('contextPageRotateCw'),
+      contextPageRotateCcw: document.getElementById('contextPageRotateCcw'),
+    },
+    sidebar: {
+      // Divs (and sidebar button)
+      outerContainer: document.getElementById('outerContainer'),
+      viewerContainer: document.getElementById('viewerContainer'),
+      toggleButton: document.getElementById('sidebarToggle'),
+      // Buttons
+      thumbnailButton: document.getElementById('viewThumbnail'),
+      outlineButton: document.getElementById('viewOutline'),
+      attachmentsButton: document.getElementById('viewAttachments'),
+      // Views
+      thumbnailView: document.getElementById('thumbnailView'),
+      outlineView: document.getElementById('outlineView'),
+      attachmentsView: document.getElementById('attachmentsView'),
+    },
+    sidebarResizer: {
+      outerContainer: document.getElementById('outerContainer'),
+      resizer: document.getElementById('sidebarResizer'),
+    },
+    findBar: {
+      bar: document.getElementById('findbar'),
+      toggleButton: document.getElementById('viewFind'),
+      findField: document.getElementById('findInput'),
+      highlightAllCheckbox: document.getElementById('findHighlightAll'),
+      caseSensitiveCheckbox: document.getElementById('findMatchCase'),
+      entireWordCheckbox: document.getElementById('findEntireWord'),
+      findMsg: document.getElementById('findMsg'),
+      findResultsCount: document.getElementById('findResultsCount'),
+      findPreviousButton: document.getElementById('findPrevious'),
+      findNextButton: document.getElementById('findNext'),
+    },
+    passwordOverlay: {
+      overlayName: 'passwordOverlay',
+      container: document.getElementById('passwordOverlay'),
+      label: document.getElementById('passwordText'),
+      input: document.getElementById('password'),
+      submitButton: document.getElementById('passwordSubmit'),
+      cancelButton: document.getElementById('passwordCancel'),
+    },
+    documentProperties: {
+      overlayName: 'documentPropertiesOverlay',
+      container: document.getElementById('documentPropertiesOverlay'),
+      closeButton: document.getElementById('documentPropertiesClose'),
+      fields: {
+        'fileName': document.getElementById('fileNameField'),
+        'fileSize': document.getElementById('fileSizeField'),
+        'title': document.getElementById('titleField'),
+        'author': document.getElementById('authorField'),
+        'subject': document.getElementById('subjectField'),
+        'keywords': document.getElementById('keywordsField'),
+        'creationDate': document.getElementById('creationDateField'),
+        'modificationDate': document.getElementById('modificationDateField'),
+        'creator': document.getElementById('creatorField'),
+        'producer': document.getElementById('producerField'),
+        'version': document.getElementById('versionField'),
+        'pageCount': document.getElementById('pageCountField'),
+        'pageSize': document.getElementById('pageSizeField'),
+        'linearized': document.getElementById('linearizedField'),
+      },
+    },
+    errorWrapper: {
+      container: document.getElementById('errorWrapper'),
+      errorMessage: document.getElementById('errorMessage'),
+      closeButton: document.getElementById('errorClose'),
+      errorMoreInfo: document.getElementById('errorMoreInfo'),
+      moreInfoButton: document.getElementById('errorShowMore'),
+      lessInfoButton: document.getElementById('errorShowLess'),
+    },
+    printContainer: document.getElementById('printContainer'),
+    openFileInputName: 'fileInput',
+    debuggerScriptPath: './debugger.js',
+  };
+}
+
+function webViewerLoad() {
+  let config = getViewerConfiguration();
+  if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
+    Promise.all([
+      SystemJS.import('pdfjs-web/app'),
+      SystemJS.import('pdfjs-web/app_options'),
+      SystemJS.import('pdfjs-web/genericcom'),
+      SystemJS.import('pdfjs-web/pdf_print_service'),
+    ]).then(function([app, appOptions, ...otherModules]) {
+      window.PDFViewerApplication = app.PDFViewerApplication;
+      window.PDFViewerApplicationOptions = appOptions.AppOptions;
+      app.PDFViewerApplication.run(config);
+    });
+  } else {
+    if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME')) {
+      pdfjsWebAppOptions.AppOptions.set('defaultUrl', defaultUrl);
+    }
+
+    window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication;
+    window.PDFViewerApplicationOptions = pdfjsWebAppOptions.AppOptions;
+
+    if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('GENERIC')) {
+      // Give custom implementations of the default viewer a simpler way to
+      // set various `AppOptions`, by dispatching an event once all viewer
+      // files are loaded but *before* the viewer initialization has run.
+      const event = document.createEvent('CustomEvent');
+      event.initCustomEvent('webviewerloaded', true, true, {});
+      document.dispatchEvent(event);
+    }
+
+    pdfjsWebApp.PDFViewerApplication.run(config);
+  }
+}
+
+if (document.readyState === 'interactive' ||
+    document.readyState === 'complete') {
+  webViewerLoad();
+} else {
+  document.addEventListener('DOMContentLoaded', webViewerLoad, true);
+}

+ 4 - 11
app/templates/show_image_old_working.html

@@ -10,7 +10,8 @@
 <!--<div class="split left">-->
 <div class="container">
     <div class="column column-one">
-            <h1>Drawing</h1>
+           <!-- <h1 style='text-align:center' >Drawing</h1>-->
+
             <p> <a href="http://localhost:5000/"> Upload another drawing </a> </p>
 
         <table style='text-align:left'>
@@ -38,7 +39,7 @@
     </div>
 <!--<div class="split middle">-->
     <div class="column column-two" id="measurements">
-            <h1>Extracted Measurements</h1>
+            <!--<h1 style='text-align:center' >Extracted Measurements</h1>-->
                 <font size="3" face="Courier New" >
                 <form>
                 <table>
@@ -71,16 +72,8 @@
 
     <!--<div class="split right">
     <div class="column column-three">
-            <h1>Additional Infos</h1>
-        <table>
-            {% for link in links %}
-            <tr>
-                    {% set l=links[link] %}
-                 <td> <h3> <a href=" {{ url_for('static', filename=l) }}" > {{ link }} </a> </h3> </td>
-             </tr>
-            {% endfor %}
+            <h1 style='text-align:center' >Additional Infos</h1>-->
 
-            </table>
     </div>
 
 </div>

+ 73 - 36
app/templates/show_pdf.html

@@ -1,9 +1,8 @@
-<!DOCTYPE html><meta charset="utf-8">
+<!DOCTYPE html><meta charset="utf-8"/>
 <link rel="stylesheet" href="{{ url_for('static', filename='css/text_layer_builder.css') }}" />
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
-<!--
 <script src="//mozilla.github.io/pdf.js/build/pdf.js"></script>
- -->
+<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}"/>
 
 <script type="javascript" src="//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.3.200/pdf.js"></script>
 <!-- das funktioniert!!!!!
@@ -17,51 +16,89 @@
 <script type="javascript" src="{{ url_for('static', filename='js/text_layer_builder.js') }}"></script>
 <script type="javascript" src="{{ url_for('static', filename='js/ui_utils.js') }}"></script>
 <body>
-<canvas id="the-canvas"></canvas>
+<div id="container"> {{og_filename}}</div>
 <script>
 
-
+var og_filename = "{{og_filename}}";
 var url = "{{ url_for('send_file', filename=og_filename) }}";
 console.log(og_filename);
 
 var pdfjsLib = window['pdfjs-dist/build/pdf'];
 
-pdfjsLib.getDocument(url).promise.then(function(pdf){
-    var page_num = 1;
-    pdf.getPage(page_num).then(function(page){
-        var scale = 1.5;
-        var viewport = page.getViewport(scale);
-        var canvas = $('#the-canvas')[0];
-        var context = canvas.getContext('2d');
-        canvas.height = viewport.height;
-        canvas.width = viewport.width;
-
-        var canvasOffset = $(canvas).offset();
-        var $textLayerDiv = $('#text-layer').css({
-            height : viewport.height+'px',
-            width : viewport.width+'px',
-            top : canvasOffset.top,
-            left : canvasOffset.left
-        });
+pdfjsLib.getDocument(url)
+  .promise.then(function(pdf) {
 
-        page.render({
-            canvasContext : context,
-            viewport : viewport
-        });
+    // Get div#container and cache it for later use
+    var container = document.getElementById("container");
 
-        page.getTextContent().then(function(textContent){
-           console.log( textContent.items[0] );
-            var textLayer = new TextLayerBuilder({
-                textLayerDiv : $textLayerDiv.get(0),
-                pageIndex : page_num - 1,
-                viewport : viewport
-            });
+    // Loop from 1 to total_number_of_pages in PDF document
+    for (var i = 1; i <= pdf.numPages; i++) {
 
-            textLayer.setTextContent(textContent);
-            textLayer.render();
-        });
+        // Get desired page
+        pdf.getPage(i).then(function(page) {
+
+          var scale = 1.5;
+          var viewport = page.getViewport({scale: scale});
+          var div = document.createElement("div");
+
+          // Set id attribute with page-#{pdf_page_number} format
+          div.setAttribute("id", "page-" + (page.pageIndex + 1));
+
+          // This will keep positions of child elements as per our needs
+          div.setAttribute("style", "position: relative");
+
+          // Append div within div#container
+          container.appendChild(div);
+
+          // Create a new Canvas element
+          var canvas = document.createElement("canvas");
+
+          // Append Canvas within div#page-#{pdf_page_number}
+          div.appendChild(canvas);
+
+          var context = canvas.getContext('2d');
+          canvas.height = viewport.height;
+          canvas.width = viewport.width;
+
+          var renderContext = {
+            canvasContext: context,
+            viewport: viewport
+          };
+
+          // Render PDF page
+         page.render(renderContext)
+  .promise.then(function() {
+    // Get text-fragments
+    return page.getTextContent();
+    console.log(textContent);
+  })
+  .then(function(textContent) {
+    // Create div which will hold text-fragments
+    var textLayerDiv = document.createElement("div");
+
+    // Set it's class to textLayer which have required CSS styles
+    textLayerDiv.setAttribute("class", "textLayer");
+
+    // Append newly created div in `div#page-#{pdf_page_number}`
+    div.appendChild(textLayerDiv);
+
+    // Create new instance of TextLayerBuilder class
+    var textLayer = new TextLayerBuilder({
+      textLayerDiv: textLayerDiv,
+      pageIndex: page.pageIndex,
+      viewport: viewport
     });
+
+    // Set text-fragments
+    textLayer.setTextContent(textContent);
+
+    // Render text-fragments
+    textLayer.render();
+  });
+        });
+    }
 });
+
 </script>
 </body>
 </html>

+ 1 - 0
app/templates/viewer.html

@@ -0,0 +1 @@
+<a href="/web/viewer.html?file={{ url_for('send_file', filename=og_filename) }}">Open yourpdf.pdf with PDF.js</a>

+ 71 - 16
app/views.py

@@ -53,19 +53,37 @@ def check_config_file(d):
 
 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[url1] = url
-            print(link_names)
+            link_names[name] = url
+            #print(link_names)
         except:
-            print("Sorry file not found")
-    return link_names
+            #print(name)
+            isos_names.append(name)
+    return link_names, isos_names
 
 
 @app.route('/', methods=['GET', 'POST'])
@@ -91,7 +109,7 @@ def upload_file():
 
 @app.route('/show/<filename>&<uuid>')
 def uploaded_file(filename, uuid):
-    file_out = "out.jpg"
+    """file_out = "out.jpg"
     #file_out = filename
     #if request.method == 'POST':
     #    uuid = 433
@@ -102,26 +120,56 @@ def uploaded_file(filename, uuid):
         #isos = db.get(uuid+"dims")
         #print(iso)
         isos = json.loads(db.get(str(uuid)+"isos"))
-        links = check_links(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 = ""
         html_general = ""
         reg = r"(-?\d{1,}\.?\d*)"
-        for dim in dims:
-            print(dim)
+        #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('/home/bscheibel/app/app/config.json') as f:
+            config_file = json.load(f)
+
+        for dim in sorted(dims):
+            #print(dim)
             for det in details:
-                print(det)
+                #print(det)
                 try:
                     if dim == det:
                         det_coords = details[det]
                         det_coords = ",".join(str(det) for det in det_coords)
                 except:
-                    det_coords = "0"
-
-            html_code += "<td><h4>" + dim + "</h4></td>"
+                    det_coords = "0,0,0,0"
+            if "ZZZZ" in dim:
+                for d in dims[dim]:
+                    html_general += d + "<br>"
+            else:
+                html_code += "<td><h4>" + dim + "</h4></td>"
             for d in dims[dim]:
+                relevant_isos = []
+                search_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)
+                            search_terms = iso[key]
+
+                terms = ",".join(str(e) for e in search_terms)
+
                 try:
                     number = re.search(reg, d)
                     number = number.group(1)
@@ -150,11 +198,18 @@ def uploaded_file(filename, uuid):
                     #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')>" + x.partition(".")[0] + "</a>  </td>"
                 #print(html_code)
-        return render_template('show_image_old_working.html', filename=file_out, isos=isos, dims=dims, text=html_code, number=number_blocks, og_filename=filename, w=w, h=h, links=links)
+                html_code += "</tr>"
+                html_links = ""
+                for link in links:
+                    html_links += "<a onclick =ui_add_tab_active('#main','" + link + "','" + link +"',true,'isotab')> 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>"""
+        #return render_template('show_pdf.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)
+    return render_template('show_pdf.html', og_filename=filename)
+
+    #else:
+    #    filename = filename
+    #    return render_template('show_image.html', filename=filename)
 
-    else:
-        filename = filename
-        return render_template('show_image.html', filename=filename)
 
 @app.route('/uploads/<filename>')
 def send_file(filename):