|
60 | 60 | from processing.tools import dataobjects |
61 | 61 |
|
62 | 62 |
|
63 | | -algorithmsToolbar = None |
64 | | - |
65 | | - |
66 | 63 | class Processing: |
67 | 64 |
|
68 | 65 | listeners = [] |
@@ -378,273 +375,6 @@ def runAlgorithm(algOrName, onFinish, *args, **kwargs): |
378 | 375 | progress.close() |
379 | 376 | return alg |
380 | 377 |
|
381 | | - @staticmethod |
382 | | - def createVectorMenu(): |
383 | | - algs = ['qgis:distancematrix', 'qgis:sumlinelengths', |
384 | | - 'qgis:pointsinpolygon', 'qgis:listuniquevalues', |
385 | | - 'qgis:basicstatisticsfornumericfields', |
386 | | - 'qgis:basicstatisticsfortextfields', |
387 | | - 'qgis:nearestneighbouranalysis', 'qgis:meancoordinates', |
388 | | - 'qgis:lineintersecions'] |
389 | | - for alg in algs: |
390 | | - Processing._addVectorAlgorithm(alg, Processing.tr('&Analysis Tools')) |
391 | | - |
392 | | - algs = ['qgis:randomselection', 'qgis:randomselectionwithinsubsets', |
393 | | - 'qgis:randompointsinextent', 'qgis:randompointsinlayerbounds', |
394 | | - 'qgis:randompointsinsidepolygonsfixed', |
395 | | - 'qgis:randompointsinsidepolygonsvariable', |
396 | | - 'qgis:regularpoints', 'qgis:vectorgrid', |
397 | | - 'qgis:selectbylocation', 'qgis:polygonfromlayerextent'] |
398 | | - for alg in algs: |
399 | | - Processing._addVectorAlgorithm(alg, Processing.tr('&Research Tools')) |
400 | | - |
401 | | - algs = ['qgis:convexhull', 'qgis:fixeddistancebuffer', |
402 | | - 'qgis:variabledistancebuffer', 'qgis:intersection', |
403 | | - 'qgis:union', 'qgis:symmetricaldifference', 'qgis:clip', |
404 | | - 'qgis:difference', 'qgis:dissolve', |
405 | | - 'qgis:eliminatesliverpolygons'] |
406 | | - for alg in algs: |
407 | | - Processing._addVectorAlgorithm(alg, Processing.tr('&Geoprocessing Tools')) |
408 | | - |
409 | | - algs = ['qgis:checkvalidity', 'qgis:exportaddgeometrycolumns', |
410 | | - 'qgis:polygoncentroids', 'qgis:delaunaytriangulation', |
411 | | - 'qgis:voronoipolygons', 'qgis:simplifygeometries', |
412 | | - 'qgis:densifygeometries', 'qgis:multiparttosingleparts', |
413 | | - 'qgis:singlepartstomultipart', 'qgis:polygonstolines', |
414 | | - 'qgis:linestopolygons', 'qgis:extractnodes'] |
415 | | - for alg in algs: |
416 | | - Processing._addVectorAlgorithm(alg, Processing.tr('G&eometry Tools')) |
417 | | - |
418 | | - algs = ['qgis:definecurrentprojection', |
419 | | - 'qgis:joinattributesbylocation', 'qgis:splitvectorlayer', |
420 | | - 'qgis:mergevectorlayers','qgis:createspatialindex'] |
421 | | - for alg in algs: |
422 | | - Processing._addVectorAlgorithm(alg, Processing.tr('&Data Management Tools')) |
423 | | - |
424 | | - @staticmethod |
425 | | - def createRasterMenu(): |
426 | | - algs = ['gdalogr:warpreproject', 'gdalogr:assignprojection', 'gdalogr:extractprojection'] |
427 | | - for alg in algs: |
428 | | - Processing._addRasterAlgorithm(alg, Processing.tr('Projections')) |
429 | | - |
430 | | - algs = ['gdalogr:rasterize', 'gdalogr:rasterize_over', |
431 | | - 'gdalogr:polygonize', 'gdalogr:translate', 'gdalogr:rgbtopct', |
432 | | - 'gdalogr:pcttorgb'] |
433 | | - for alg in algs: |
434 | | - Processing._addRasterAlgorithm(alg, Processing.tr('Conversion')) |
435 | | - |
436 | | - algs = ['gdalogr:contour', 'gdalogr:cliprasterbyextent', |
437 | | - 'gdalogr:cliprasterbymasklayer'] |
438 | | - for alg in algs: |
439 | | - Processing._addRasterAlgorithm(alg, Processing.tr('Extraction')) |
440 | | - |
441 | | - algs = ['gdalogr:sieve', 'gdalogr:nearblack', 'gdalogr:fillnodata', |
442 | | - 'gdalogr:proximity', 'gdalogr:griddatametrics', |
443 | | - 'gdalogr:gridaverage', 'gdalogr:gridinvdist', |
444 | | - 'gdalogr:gridnearestneighbor', 'gdalogr:aspect', |
445 | | - 'gdalogr:hillshade', 'gdalogr:roughness', 'gdalogr:slope', |
446 | | - 'gdalogr:tpi', 'gdalogr:tri'] |
447 | | - for alg in algs: |
448 | | - Processing._addRasterAlgorithm(alg, Processing.tr('Analysis')) |
449 | | - |
450 | | - algs = ['gdalogr:buildvirtualraster', 'gdalogr:merge', |
451 | | - 'gdalogr:rasterinfo', 'gdalogr:overviews', 'gdalogr:tileindex'] |
452 | | - for alg in algs: |
453 | | - Processing._addRasterAlgorithm(alg, Processing.tr('Miscellaneous')) |
454 | | - |
455 | | - @staticmethod |
456 | | - def removeVectorMenu(): |
457 | | - algs = ['qgis:distancematrix', 'qgis:sumlinelengths', |
458 | | - 'qgis:pointsinpolygon', 'qgis:listuniquevalues', |
459 | | - 'qgis:basicstatisticsfornumericfields', |
460 | | - 'qgis:basicstatisticsfortextfields', |
461 | | - 'qgis:nearestneighbouranalysis', 'qgis:meancoordinates', |
462 | | - 'qgis:lineintersecions'] |
463 | | - for alg in algs: |
464 | | - Processing._removeVectorAlgorithm(alg, Processing.tr('&Analysis Tools')) |
465 | | - |
466 | | - algs = ['qgis:randomselection', 'qgis:randomselectionwithinsubsets', |
467 | | - 'qgis:randompointsinextent', 'qgis:randompointsinlayerbounds', |
468 | | - 'qgis:randompointsinsidepolygonsfixed', |
469 | | - 'qgis:randompointsinsidepolygonsvariable', |
470 | | - 'qgis:regularpoints', 'qgis:vectorgrid', |
471 | | - 'qgis:selectbylocation', 'qgis:polygonfromlayerextent'] |
472 | | - for alg in algs: |
473 | | - Processing._removeVectorAlgorithm(alg, Processing.tr('&Research Tools')) |
474 | | - |
475 | | - algs = ['qgis:convexhull', 'qgis:fixeddistancebuffer', |
476 | | - 'qgis:variabledistancebuffer', 'qgis:intersection', |
477 | | - 'qgis:union', 'qgis:symmetricaldifference', 'qgis:clip', |
478 | | - 'qgis:difference', 'qgis:dissolve', |
479 | | - 'qgis:eliminatesliverpolygons'] |
480 | | - for alg in algs: |
481 | | - Processing._removeVectorAlgorithm(alg, Processing.tr('&Geoprocessing Tools')) |
482 | | - |
483 | | - algs = ['qgis:checkvalidity', 'qgis:exportaddgeometrycolumns', |
484 | | - 'qgis:polygoncentroids', 'qgis:delaunaytriangulation', |
485 | | - 'qgis:voronoipolygons', 'qgis:simplifygeometries', |
486 | | - 'qgis:densifygeometries', 'qgis:multiparttosingleparts', |
487 | | - 'qgis:singlepartstomultipart', 'qgis:polygonstolines', |
488 | | - 'qgis:linestopolygons', 'qgis:extractnodes'] |
489 | | - for alg in algs: |
490 | | - Processing._removeVectorAlgorithm(alg, Processing.tr('G&eometry Tools')) |
491 | | - |
492 | | - algs = ['qgis:definecurrentprojection', |
493 | | - 'qgis:joinattributesbylocation', 'qgis:splitvectorlayer', |
494 | | - 'qgis:mergevectorlayers','qgis:createspatialindex'] |
495 | | - for alg in algs: |
496 | | - Processing._removeVectorAlgorithm(alg, Processing.tr('&Data Management Tools')) |
497 | | - |
498 | | - @staticmethod |
499 | | - def removeRasterMenu(): |
500 | | - algs = ['gdalogr:warpreproject', 'gdalogr:assignprojection', 'gdalogr:extractprojection'] |
501 | | - for alg in algs: |
502 | | - Processing._removeRasterAlgorithm(alg, Processing.tr('Projections')) |
503 | | - |
504 | | - algs = ['gdalogr:rasterize', 'gdalogr:rasterize_over', |
505 | | - 'gdalogr:polygonize', 'gdalogr:translate', 'gdalogr:rgbtopct', |
506 | | - 'gdalogr:pcttorgb'] |
507 | | - for alg in algs: |
508 | | - Processing._removeRasterAlgorithm(alg, Processing.tr('Conversion')) |
509 | | - |
510 | | - algs = ['gdalogr:contour', 'gdalogr:cliprasterbyextent', |
511 | | - 'gdalogr:cliprasterbymasklayer'] |
512 | | - for alg in algs: |
513 | | - Processing._removeRasterAlgorithm(alg, Processing.tr('Extraction')) |
514 | | - |
515 | | - algs = ['gdalogr:sieve', 'gdalogr:nearblack', 'gdalogr:fillnodata', |
516 | | - 'gdalogr:proximity', 'gdalogr:griddatametrics', |
517 | | - 'gdalogr:gridaverage', 'gdalogr:gridinvdist', |
518 | | - 'gdalogr:gridnearestneighbor', 'gdalogr:aspect', |
519 | | - 'gdalogr:hillshade', 'gdalogr:roughness', 'gdalogr:slope', |
520 | | - 'gdalogr:tpi', 'gdalogr:tri'] |
521 | | - for alg in algs: |
522 | | - Processing._removeRasterAlgorithm(alg, Processing.tr('Analysis')) |
523 | | - |
524 | | - algs = ['gdalogr:buildvirtualraster', 'gdalogr:merge', |
525 | | - 'gdalogr:rasterinfo', 'gdalogr:overviews', 'gdalogr:tileindex'] |
526 | | - for alg in algs: |
527 | | - Processing._removeRasterAlgorithm(alg, Processing.tr('Miscellaneous')) |
528 | | - |
529 | | - @staticmethod |
530 | | - def _addRasterAlgorithm(name, group): |
531 | | - Processing.addAlgorithmEntry(name, Processing.tr('&Raster'), group) |
532 | | - |
533 | | - @staticmethod |
534 | | - def _addVectorAlgorithm( name, group): |
535 | | - Processing.addAlgorithmEntry(name, Processing.tr('Vect&or'), group) |
536 | | - |
537 | | - @staticmethod |
538 | | - def _removeRasterAlgorithm(name, group): |
539 | | - Processing.removeAlgorithmEntry(name, Processing.tr('&Raster'), group) |
540 | | - |
541 | | - @staticmethod |
542 | | - def _removeVectorAlgorithm( name, group): |
543 | | - Processing.removeAlgorithmEntry(name, Processing.tr('Vect&or'), group) |
544 | | - |
545 | | - @staticmethod |
546 | | - def updateMenus(): |
547 | | - showVector = ProcessingConfig.getSetting( |
548 | | - ProcessingConfig.SHOW_VECTOR_MENUS) |
549 | | - if showVector: |
550 | | - Processing.createVectorMenu() |
551 | | - else: |
552 | | - Processing.removeVectorMenu() |
553 | | - |
554 | | - showRaster = ProcessingConfig.getSetting( |
555 | | - ProcessingConfig.SHOW_RASTER_MENUS) |
556 | | - if showRaster: |
557 | | - Processing.createRasterMenu() |
558 | | - else: |
559 | | - Processing.removeRasterMenu() |
560 | | - |
561 | | - @staticmethod |
562 | | - def addAlgorithmEntry(algname, menuName, submenuName, actionText=None, icon=None, addButton=False): |
563 | | - alg = Processing.getAlgorithm(algname) |
564 | | - if alg is None: |
565 | | - return |
566 | | - |
567 | | - action = QAction(icon or alg.getIcon(), actionText or alg.name, iface.mainWindow()) |
568 | | - action.triggered.connect(lambda: Processing._executeAlgorithm(alg)) |
569 | | - |
570 | | - if menuName: |
571 | | - menu = Processing.getMenu(menuName, iface.mainWindow().menuBar()) |
572 | | - submenu = Processing.getMenu(submenuName, menu) |
573 | | - submenu.addAction(action) |
574 | | - |
575 | | - if addButton: |
576 | | - global algorithmsToolbar |
577 | | - if algorithmsToolbar is None: |
578 | | - algorithmsToolbar = iface.addToolBar('ProcessingAlgorithms') |
579 | | - algorithmsToolbar.addAction(action) |
580 | | - |
581 | | - @staticmethod |
582 | | - def removeAlgorithmEntry(algname, menuName, submenuName, actionText=None, delButton=True): |
583 | | - alg = Processing.getAlgorithm(algname) |
584 | | - if alg is None: |
585 | | - return |
586 | | - |
587 | | - if menuName: |
588 | | - menu = Processing.getMenu(menuName, iface.mainWindow().menuBar()) |
589 | | - subMenu = Processing.getMenu(submenuName, menu) |
590 | | - action = Processing.findAction(subMenu.actions(), alg, actionText) |
591 | | - if action is not None: |
592 | | - subMenu.removeAction(action) |
593 | | - |
594 | | - if len(subMenu.actions()) == 0: |
595 | | - menu.removeAction(subMenu.menuAction()) |
596 | | - |
597 | | - if delButton: |
598 | | - global algorithmsToolbar |
599 | | - if algorithmsToolbar is not None: |
600 | | - action = Processing.findAction(algorithmsToolbar.actions(), alg, actionText) |
601 | | - if action is not None: |
602 | | - algorithmsToolbar.removeAction(action) |
603 | | - |
604 | | - @staticmethod |
605 | | - def _executeAlgorithm(alg): |
606 | | - message = alg.checkBeforeOpeningParametersDialog() |
607 | | - if message: |
608 | | - dlg = MessageDialog() |
609 | | - dlg.setTitle(tr('Missing dependency')) |
610 | | - dlg.setMessage( |
611 | | - tr('<h3>Missing dependency. This algorithm cannot ' |
612 | | - 'be run :-( </h3>\n%s') % message) |
613 | | - dlg.exec_() |
614 | | - return |
615 | | - alg = alg.getCopy() |
616 | | - dlg = alg.getCustomParametersDialog() |
617 | | - if not dlg: |
618 | | - dlg = AlgorithmDialog(alg) |
619 | | - canvas = iface.mapCanvas() |
620 | | - prevMapTool = canvas.mapTool() |
621 | | - dlg.show() |
622 | | - dlg.exec_() |
623 | | - if canvas.mapTool() != prevMapTool: |
624 | | - try: |
625 | | - canvas.mapTool().reset() |
626 | | - except: |
627 | | - pass |
628 | | - canvas.setMapTool(prevMapTool) |
629 | | - |
630 | | - @staticmethod |
631 | | - def getMenu(name, parent): |
632 | | - menus = [c for c in parent.children() if isinstance(c, QMenu)] |
633 | | - menusDict = {m.title(): m for m in menus} |
634 | | - if name in menusDict: |
635 | | - return menusDict[name] |
636 | | - else: |
637 | | - menu = QMenu(name, parent) |
638 | | - parent.addMenu(menu) |
639 | | - return menu |
640 | | - |
641 | | - @staticmethod |
642 | | - def findAction(actions, alg, actionText=None): |
643 | | - for action in actions: |
644 | | - if action.text() in [actionText, alg.name]: |
645 | | - return action |
646 | | - return None |
647 | | - |
648 | 378 |
|
649 | 379 | @staticmethod |
650 | 380 | def tr(string, context=''): |
|
0 commit comments