Skip to content

Commit

Permalink
improved new algorithm classification mechanism
Browse files Browse the repository at this point in the history
fixed #6834
  • Loading branch information
volaya committed Dec 8, 2012
1 parent eedd891 commit 7841975
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 28 deletions.
13 changes: 8 additions & 5 deletions python/plugins/sextante/core/AlgorithmClassification.py
Expand Up @@ -37,8 +37,8 @@ def loadClassification():
lines = open(AlgorithmDecorator.classificationFile())
line = lines.readline().strip("\n")
while line != "":
tokens = line.split("\t")
AlgorithmDecorator.classification[tokens[0]] = (tokens[1], tokens[2]);
tokens = line.split("\t")
AlgorithmDecorator.classification[tokens[0]] = (tokens[1], tokens[2], tokens[3]);
line = lines.readline().strip("\n")
lines.close()

Expand All @@ -47,11 +47,14 @@ def classificationFile():
return os.path.join(SextanteUtils.userFolder(), "sextante_qgis_algclass.txt")

@staticmethod
def getGroupAndName(alg):
def getGroupsAndName(alg):
if alg.commandLineName() in AlgorithmDecorator.classification:
return AlgorithmDecorator.classification[alg.commandLineName]
group, subgroup, name = AlgorithmDecorator.classification[alg.commandLineName]
if name == "USE_ORIGINAL_NAME":
name = alg.name
return (group, subgroup, name)
else:
return (alg.group, alg.name)
return ("Uncategorized", alg.group, alg.name)



Expand Down
50 changes: 29 additions & 21 deletions python/plugins/sextante/gui/SextanteToolbox.py
Expand Up @@ -201,33 +201,41 @@ def fillTreeUsingCategories(self):
for alg in algs:
if not alg.showInToolbox:
continue
altgroup, altname = AlgorithmDecorator.getGroupAndName(alg)
if text =="" or text.lower() in altname.lower():
if altgroup in groups:
groupItem = groups[altgroup]
else:
groupItem = QTreeWidgetItem()
groupItem.setText(0, altgroup)
groupItem.setToolTip(0, altgroup)
groupItem.setIcon(0, GeoAlgorithm.getDefaultIcon())
groups[altgroup] = groupItem
algItem = TreeAlgorithmItem(alg)
groupItem.addChild(algItem)

altgroup, altsubgroup, altname = AlgorithmDecorator.getGroupsAndName(alg)
if text =="" or text.lower() in altname.lower():
if altgroup not in groups:
groups[altgroup] = {}
group = groups[altgroup]
if altsubgroup not in group:
groups[altgroup][altsubgroup] = []
subgroup = groups[altgroup][altsubgroup]
subgroup.append(alg)

if len(groups) > 0:
mainItem = QTreeWidgetItem()
mainItem.setText(0, "Geoalgorithms")
mainItem.setIcon(0, GeoAlgorithm.getDefaultIcon())
mainItem.setToolTip(0, mainItem.text(0))
for groupItem in groups.values():
mainItem.setToolTip(0, mainItem.text(0))
for groupname, group in groups.items():
groupItem = QTreeWidgetItem()
groupItem.setText(0, groupname)
groupItem.setIcon(0, GeoAlgorithm.getDefaultIcon())
groupItem.setToolTip(0, groupItem.text(0))
mainItem.addChild(groupItem)
for subgroupname, subgroup in group.items():
subgroupItem = QTreeWidgetItem()
subgroupItem.setText(0, subgroupname)
subgroupItem.setIcon(0, GeoAlgorithm.getDefaultIcon())
subgroupItem.setToolTip(0, subgroupItem.text(0))
groupItem.addChild(subgroupItem)
for alg in subgroup:
algItem = TreeAlgorithmItem(alg)
subgroupItem.addChild(algItem)
subgroupItem.setExpanded(text!="")
groupItem.setExpanded(text!="")
self.algorithmTree.addTopLevelItem(mainItem)
mainItem.setExpanded(text!="")
for groupItem in groups.values():
if text != "":
groupItem.setExpanded(True)



for providerName in Sextante.algs.keys():
groups = {}
provider = Sextante.algs[providerName]
Expand Down Expand Up @@ -341,7 +349,7 @@ def __init__(self, alg):
name = alg.name
if useCategories:
icon = GeoAlgorithm.getDefaultIcon()
group, name = AlgorithmDecorator.getGroupAndName(alg)
group, subgroup, name = AlgorithmDecorator.getGroupsAndName(alg)
self.setIcon(0, icon)
self.setToolTip(0, name)

Expand Down
105 changes: 104 additions & 1 deletion python/plugins/sextante/modeler/ModelerDialog.py
Expand Up @@ -16,6 +16,9 @@
* *
***************************************************************************
"""
from sextante.core.SextanteConfig import SextanteConfig
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.AlgorithmClassification import AlgorithmDecorator

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
Expand Down Expand Up @@ -368,7 +371,107 @@ def addAlgorithm(self):
self.repaintModel()
self.view.ensureVisible(self.scene.getLastAlgorithmItem())

def fillAlgorithmTree(self):
def fillAlgorithmTree(self):
useCategories = SextanteConfig.getSetting(SextanteConfig.USE_CATEGORIES)
if useCategories:
self.fillAlgorithmTreeUsingCategories()
else:
self.fillAlgorithmTreeUsingProviders()

self.algorithmTree.sortItems(0, Qt.AscendingOrder)

def fillAlgorithmTreeUsingCategories(self):
providersToExclude = ["model", "script"]
self.algorithmTree.clear()
text = unicode(self.searchBox.text())
groups = {}
allAlgs = ModelerUtils.getAlgorithms()
for providerName in allAlgs.keys():
provider = allAlgs[providerName]
name = "ACTIVATE_" + providerName.upper().replace(" ", "_")
if not SextanteConfig.getSetting(name):
continue
if providerName in providersToExclude or len(Providers.providers[providerName].actions) != 0:
continue
algs = provider.values()
#add algorithms
for alg in algs:
if not alg.showInModeler:
continue
altgroup, altsubgroup, altname = AlgorithmDecorator.getGroupsAndName(alg)
if text =="" or text.lower() in altname.lower():
if altgroup not in groups:
groups[altgroup] = {}
group = groups[altgroup]
if altsubgroup not in group:
groups[altgroup][altsubgroup] = []
subgroup = groups[altgroup][altsubgroup]
subgroup.append(alg)

if len(groups) > 0:
mainItem = QTreeWidgetItem()
mainItem.setText(0, "Geoalgorithms")
mainItem.setIcon(0, GeoAlgorithm.getDefaultIcon())
mainItem.setToolTip(0, mainItem.text(0))
for groupname, group in groups.items():
groupItem = QTreeWidgetItem()
groupItem.setText(0, groupname)
groupItem.setIcon(0, GeoAlgorithm.getDefaultIcon())
groupItem.setToolTip(0, groupItem.text(0))
mainItem.addChild(groupItem)
for subgroupname, subgroup in group.items():
subgroupItem = QTreeWidgetItem()
subgroupItem.setText(0, subgroupname)
subgroupItem.setIcon(0, GeoAlgorithm.getDefaultIcon())
subgroupItem.setToolTip(0, subgroupItem.text(0))
groupItem.addChild(subgroupItem)
for alg in subgroup:
algItem = TreeAlgorithmItem(alg)
subgroupItem.addChild(algItem)
subgroupItem.setExpanded(text!="")
groupItem.setExpanded(text!="")
self.algorithmTree.addTopLevelItem(mainItem)
mainItem.setExpanded(text!="")

for providerName in allAlgs.keys():
groups = {}
provider = allAlgs[providerName]
name = "ACTIVATE_" + providerName.upper().replace(" ", "_")
if not SextanteConfig.getSetting(name):
continue
if providerName not in providersToExclude:
continue
algs = provider.values()
#add algorithms
for alg in algs:
if not alg.showInModeler:
continue
if text =="" or text.lower() in alg.name.lower():
if alg.group in groups:
groupItem = groups[alg.group]
else:
groupItem = QTreeWidgetItem()
groupItem.setText(0, alg.group)
groupItem.setToolTip(0, alg.group)
groups[alg.group] = groupItem
algItem = TreeAlgorithmItem(alg)
groupItem.addChild(algItem)

if len(groups) > 0:
providerItem = QTreeWidgetItem()
providerItem.setText(0, Providers.providers[providerName].getDescription())
providerItem.setIcon(0, Providers.providers[providerName].getIcon())
providerItem.setToolTip(0, providerItem.text(0))
for groupItem in groups.values():
providerItem.addChild(groupItem)
self.algorithmTree.addTopLevelItem(providerItem)
providerItem.setExpanded(text!="")
for groupItem in groups.values():
if text != "":
groupItem.setExpanded(True)


def fillAlgorithmTreeUsingProviders(self):
self.algorithmTree.clear()
text = str(self.searchBox.text())
allAlgs = ModelerUtils.getAlgorithms()
Expand Down
3 changes: 2 additions & 1 deletion python/plugins/sextante/r/RAlgorithm.py
Expand Up @@ -270,7 +270,8 @@ def getImportCommands(self):
value = value.replace("\\", "/")
filename = os.path.basename(value)
filename = filename[:-4]
commands.append(param.name + " = readOGR(\"" + value + "\",layer=\"" + filename + "\")")
folder = os.path.dirname(value)
commands.append(param.name + " = readOGR(\"" + folder + "\",layer=\"" + filename + "\")")
if isinstance(param, ParameterTable):
value = param.value
if not value.lower().endswith("csv"):
Expand Down

0 comments on commit 7841975

Please sign in to comment.