/**************************************************************************** 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_itemdrawable/ct_fileheader.h" #include "ct_itemdrawable/ct_box2d.h" #include "ct_result/ct_resultgroup.h" #include "ct_result/model/outModel/ct_outresultmodelgroupcopy.h" #include "ct_result/model/inModel/ct_inresultmodelgrouptocopy.h" #include "ct_result/model/outModel/ct_outresultmodelgroup.h" #include "ct_result/model/inModel/ct_inresultmodelgroup.h" #include "ct_view/ct_stepconfigurabledialog.h" #include "ct_result/model/outModel/tools/ct_outresultmodelgrouptocopypossibilities.h" #include "ct_view/ct_asciifilechoicebutton.h" #include "ct_view/ct_combobox.h" // Alias for indexing models #define DEFin_resHeader "resHeader" #define DEFin_resBBox "resBBox" #define DEFin_grpHeader "grpHeader" #define DEFin_grpBBox "grpBBox" #define DEFin_header "header" #define DEFin_bbox "bbox" #define DEF_inATT "fileNameAtt" #include #include // Constructor : initialization of parameters ONF_StepSelectBBoxByFileName::ONF_StepSelectBBoxByFileName(CT_StepInitializeData &dataInit) : CT_AbstractStep(dataInit) { } // Step description (tooltip of contextual menu) QString ONF_StepSelectBBoxByFileName::getStepDescription() const { return tr("Charger l'emprise correspondant à un nom de fichier"); } // Step detailled description QString ONF_StepSelectBBoxByFileName::getStepDetailledDescription() const { return tr("No detailled description for this step"); } // Step URL QString ONF_StepSelectBBoxByFileName::getStepURL() const { //return tr("STEP URL HERE"); return CT_AbstractStep::getStepURL(); //by default URL of the plugin } // Step copy method CT_VirtualAbstractStep* ONF_StepSelectBBoxByFileName::createNewInstance(CT_StepInitializeData &dataInit) { return new ONF_StepSelectBBoxByFileName(dataInit); } //////////////////// PROTECTED METHODS ////////////////// // Creation and affiliation of IN models void ONF_StepSelectBBoxByFileName::createInResultModelListProtected() { CT_InResultModelGroup *resIn_res = createNewInResultModelForCopy(DEFin_resBBox, 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")); resIn_res->setZeroOrMoreRootGroup(); resIn_res->addGroupModel("", DEFin_grpBBox, CT_AbstractItemGroup::staticGetType(), tr("Groupe")); resIn_res->addItemModel(DEFin_grpBBox, DEFin_header, CT_AbstractSingularItemDrawable::staticGetType(), tr("Item Nom de fichier")); resIn_res->addItemAttributeModel(DEFin_header, DEF_inATT, QList() << CT_AbstractCategory::DATA_VALUE, CT_AbstractCategory::STRING, tr("Nom de fichier")); resIn_res->addItemModel(DEFin_grpBBox, DEFin_bbox, CT_AbstractAreaShape2D::staticGetType(), tr("Emprise correspondante")); CT_InResultModelGroupToCopy *resIn_resCpy = createNewInResultModelForCopy(DEFin_resHeader, 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); resIn_resCpy->setZeroOrMoreRootGroup(); resIn_resCpy->addGroupModel("", DEFin_grpHeader, CT_AbstractItemGroup::staticGetType(), tr("Groupe")); resIn_resCpy->addItemModel(DEFin_grpHeader, DEFin_header, CT_FileHeader::staticGetType(), tr("Entête de fichier")); } // Creation and affiliation of OUT models void ONF_StepSelectBBoxByFileName::createOutResultModelListProtected() { CT_OutResultModelGroupToCopyPossibilities *resCpy_res = createNewOutResultModelToCopy(DEFin_resHeader); if(resCpy_res != NULL) resCpy_res->addItemModel(DEFin_grpHeader, _outBBox_ModelName, new CT_Box2D(), tr("Emprise")); } // Semi-automatic creation of step parameters DialogBox void ONF_StepSelectBBoxByFileName::createPostConfigurationDialog() { //CT_StepConfigurableDialog *configDialog = newStandardPostConfigurationDialog(); } void ONF_StepSelectBBoxByFileName::compute() { QList inResultList = getInputResults(); CT_ResultGroup* inRes = inResultList.at(0); QMap corresp; // Création de la liste des id recherchés CT_ResultGroupIterator itGrpIn(inRes, this, DEFin_grpBBox); while (itGrpIn.hasNext() && !isStopped()) { CT_StandardItemGroup* group = (CT_StandardItemGroup*) itGrpIn.next(); if (group != NULL) { CT_AbstractSingularItemDrawable* fileHeader = (CT_AbstractSingularItemDrawable*) group->firstItemByINModelName(this, DEFin_header); CT_AbstractAreaShape2D* bbox = (CT_AbstractAreaShape2D*) group->firstItemByINModelName(this, DEFin_bbox); if (fileHeader != NULL && bbox != NULL) { CT_AbstractItemAttribute *attribute = fileHeader->firstItemAttributeByINModelName(inRes, this, DEF_inATT); if (attribute != NULL) { bool ok; QString filename = attribute->toString(fileHeader, &ok); if (ok && !filename.isEmpty()) { corresp.insert(filename.toLower(), bbox); } } } } } QList outResultList = getOutResultList(); CT_ResultGroup* outRes = outResultList.at(0); // Création de la liste des id recherchés CT_ResultGroupIterator itGrpOut(outRes, this, DEFin_grpHeader); while (itGrpOut.hasNext() && !isStopped()) { CT_StandardItemGroup* group = (CT_StandardItemGroup*) itGrpOut.next(); if (group != NULL) { CT_FileHeader* fileHeader = (CT_FileHeader*) group->firstItemByINModelName(this, DEFin_header); if (fileHeader != NULL) { QString filename = fileHeader->getFileInfo().fileName(); CT_AbstractAreaShape2D* bbox = corresp.value(filename.toLower(), NULL); if (!filename.isEmpty() && bbox != NULL) { Eigen::Vector3d min, max; bbox->getBoundingBox(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(_outBBox_ModelName.completeName(), outRes, data); group->addItemDrawable(box); } } } } }