/**************************************************************************** Copyright (C) 2010-2012 the Office National des Forêts (ONF), France All rights reserved. Contact : alexandre.piboule@onf.fr Developers : Alexandre PIBOULE (ONF) This file is part of PluginONF library. PluginONF is free library: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. PluginONF 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 Lesser General Public License along with PluginONF. If not, see . *****************************************************************************/ #include "onf_stepselectbboxbyfilename.h" #include "ct_view/ct_asciifilechoicebutton.h" #include "ct_view/ct_combobox.h" #include #include ONF_StepSelectBBoxByFileName::ONF_StepSelectBBoxByFileName() : SuperClass() { } QString ONF_StepSelectBBoxByFileName::description() const { return tr("Charger l'emprise correspondant à un nom de fichier"); } QString ONF_StepSelectBBoxByFileName::detailledDescription() const { return tr(""); } QString ONF_StepSelectBBoxByFileName::inputDescription() const { return SuperClass::inputDescription() + tr("

"); } QString ONF_StepSelectBBoxByFileName::outputDescription() const { return SuperClass::outputDescription() + tr("

"); } QString ONF_StepSelectBBoxByFileName::detailsDescription() const { return tr(""); } QString ONF_StepSelectBBoxByFileName::URL() const { //return tr("STEP URL HERE"); return SuperClass::URL(); //by default URL of the plugin } CT_VirtualAbstractStep* ONF_StepSelectBBoxByFileName::createNewInstance() const { return new ONF_StepSelectBBoxByFileName(); } //////////////////// PROTECTED METHODS ////////////////// void ONF_StepSelectBBoxByFileName::declareInputModels(CT_StepInModelStructureManager& manager) { manager.addResult(_inResult, tr("Emprises disponibles"), tr("Résultat contenant toutes les emprises disponibles.\n" "Chaque groupe contient :\n" "- Une Emprise (item ayant une boite englobante : en général Forme 2D)\n" "- Un item avec un attribut conteant le nom du fichier correspondant (Header)\n")); manager.setZeroOrMoreRootGroup(_inResult, _inZeroOrMoreRootGroup); manager.addGroup(_inZeroOrMoreRootGroup, _inGrpBBox); manager.addItem(_inGrpBBox, _inItemBBox, tr("Item Nom de fichier")); manager.addItemAttribute(_inItemBBox, _inAtt, CT_AbstractCategory::DATA_VALUE, tr("Nom de fichier")); manager.addItem(_inGrpBBox, _inBbox, tr("Emprise correspondante")); manager.addResult(_inResultFile, tr("Fichier dont l'emprise doit être chargée"), tr("Résultat contenant le nom du fichier pour lequel il faut charger l'emprise (Header)"), true); manager.setZeroOrMoreRootGroup(_inResultFile, _inZeroOrMoreRootGroupFile); manager.addGroup(_inZeroOrMoreRootGroupFile, _inGrpHeader); manager.addItem(_inGrpHeader, _inHeader, tr("Entête de fichier")); } void ONF_StepSelectBBoxByFileName::declareOutputModels(CT_StepOutModelStructureManager& manager) { manager.addResultCopy(_inResultFile); manager.addItem(_inGrpHeader, _outBBox, tr("Emprise")); } void ONF_StepSelectBBoxByFileName::compute() { QMap corresp; // Création de la liste des id recherchés for (const CT_StandardItemGroup* group : _inGrpBBox.iterateInputs(_inResult)) { if (isStopped()) {return;} const CT_AbstractSingularItemDrawable* fileHeader = group->singularItem(_inItemBBox); const CT_AbstractAreaShape2D* bbox = group->singularItem(_inBbox); if (fileHeader != nullptr && bbox != nullptr) { const CT_AbstractItemAttribute *attribute = fileHeader->itemAttribute(_inAtt); if (attribute != nullptr) { bool ok; QString filename = attribute->toString(fileHeader, &ok); if (ok && !filename.isEmpty()) { corresp.insert(filename.toLower(), bbox); } } } } for (CT_StandardItemGroup* group : _inGrpBBox.iterateOutputs(_inResultFile)) { if (isStopped()) {return;} const CT_FileHeader* fileHeader = group->singularItem(_inHeader); if (fileHeader != nullptr) { QString filename = fileHeader->fileInfo().fileName(); const CT_AbstractAreaShape2D* bbox = corresp.value(filename.toLower(), nullptr); if (!filename.isEmpty() && bbox != nullptr) { Eigen::Vector3d min, max; bbox->boundingBox(min, max); Eigen::Vector2d min2d, max2d; min2d(0) = min(0); min2d(1) = min(1); max2d(0) = max(0); max2d(1) = max(1); CT_Box2DData *data = new CT_Box2DData(min2d, max2d); CT_Box2D *box = new CT_Box2D(data); group->addSingularItem(_outBBox, box); } } } }