Skip to content

Commit

Permalink
CCVolti is invokable
Browse files Browse the repository at this point in the history
  • Loading branch information
kk-mats committed Jun 7, 2019
1 parent 396a350 commit 08c82d2
Show file tree
Hide file tree
Showing 19 changed files with 257 additions and 35 deletions.
5 changes: 5 additions & 0 deletions core/global_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ void global_settings::set_ccfindersw(const QString &path, const QString &naming_
this->set_clone_detector(clone_detector::ccfindersw.name(), path, naming_rule);
}

QString global_settings::ccvolti() noexcept
{
return this->settings_.value(QString("%1/%2/%3").arg(EXTERNAL_TOOLS).arg(clone_detector::ccvolti.name()).arg(EXECUTABLE_PATH)).toString();
}

global_settings& global_settings::instance() noexcept
{
if(instance_==nullptr)
Expand Down
2 changes: 2 additions & 0 deletions core/global_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class global_settings final
void set_ccvolti(const QString &path, const QString &naming_rule) noexcept;
void set_ccfindersw(const QString &path, const QString &naming_rule) noexcept;

QString ccvolti() noexcept;

static global_settings& instance() noexcept;

static const inline QString EXTERNAL_TOOLS="externalTools";
Expand Down
17 changes: 13 additions & 4 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,22 @@ void MainWindow::external_tools_settings() noexcept

void MainWindow::invoke_ccfinderx() noexcept
{
(new invoke_ccfinderx_dialog(this->results_.target_path(), this))->exec();
this->show_invoke_dialog(new invoke_ccfinderx_dialog(this->results_.target_path(), this));
}

void MainWindow::invoke_ccvolti() noexcept
{
(new invoke_ccvolti_dialog(this->results_.target_path(), this))->exec();
this->show_invoke_dialog(new invoke_ccvolti_dialog(this->results_.target_path(), this));
}

void MainWindow::invoke_ccfindersw() noexcept
{
(new invoke_ccfindersw_dialog(this->results_.target_path(), this))->exec();
this->show_invoke_dialog(new invoke_ccfindersw_dialog(this->results_.target_path(), this));
}

void MainWindow::invoke_nicad() noexcept
{
(new invoke_nicad_dialog(this->results_.target_path(), this))->exec();
this->show_invoke_dialog(new invoke_nicad_dialog(this->results_.target_path(), this));
}

void MainWindow::remove(const std::shared_ptr<detection_result> &result) noexcept
Expand Down Expand Up @@ -230,4 +230,13 @@ bool MainWindow::request_target_path() noexcept
return false;
}

void MainWindow::show_invoke_dialog(invoke_dialog *d) noexcept
{
if(d->exec()==QDialog::Accepted)
{
this->invoker_display_dialog_->add_invoker(std::move(d->create_invoker()));
this->invoker_display_dialog_->show();
}
}

}
4 changes: 4 additions & 0 deletions gui/mainwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ private slots:
grid_properties_widget *grid_properties_widget_=new grid_properties_widget(this);
QDockWidget *grid_properties_dock_=new QDockWidget(tr("Grid Properties"), this);

invoker_display_widget *invoker_display_dialog_=new invoker_display_widget(this);

QMenu *file_menu_;
QAction *open_project_act_;
QAction *open_file_act_;
Expand Down Expand Up @@ -87,6 +89,8 @@ private slots:
void update() noexcept;

bool request_target_path() noexcept;

void show_invoke_dialog(invoke_dialog *d) noexcept;
};

}
Expand Down
1 change: 1 addition & 0 deletions gui/tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
#include "tools/invoke_ccvolti_dialog.hpp"
#include "tools/invoke_ccfindersw_dialog.hpp"
#include "tools/invoke_nicad_dialog.hpp"
#include "tools/invoker_cui_display.hpp"

#endif // TOOLS_HPP
2 changes: 1 addition & 1 deletion gui/tools/invoke_ccfindersw_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void invoke_ccfindersw_dialog::begin_setup_parameters_layout() noexcept
this->parameters_layout_=dl;
}

invoke_dialog::invoker_t invoke_ccfindersw_dialog::create_invoker() const noexcept
invoker_t invoke_ccfindersw_dialog::create_invoker() const noexcept
{
return ccfindersw_invoker();
}
Expand Down
2 changes: 1 addition & 1 deletion gui/tools/invoke_ccfindersw_dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class invoke_ccfindersw_dialog final

public:
invoke_ccfindersw_dialog(const QString &target, QWidget *parent) noexcept;
invoker_t create_invoker() const noexcept override;

private:
QLineEdit *language_edit_=new QLineEdit(this);
Expand All @@ -45,7 +46,6 @@ class invoke_ccfindersw_dialog final
QDoubleSpinBox *rnr_=new QDoubleSpinBox(this);

void begin_setup_parameters_layout() noexcept override;
invoker_t create_invoker() const noexcept override;
};

}
Expand Down
2 changes: 1 addition & 1 deletion gui/tools/invoke_ccfinderx_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void invoke_ccfinderx_dialog::begin_setup_parameters_layout() noexcept
this->parameters_layout_=pl;
}

invoke_dialog::invoker_t invoke_ccfinderx_dialog::create_invoker() const noexcept
invoker_t invoke_ccfinderx_dialog::create_invoker() const noexcept
{
return ccfinderx_invoker(
this->target_path_edit_->text(),
Expand Down
3 changes: 2 additions & 1 deletion gui/tools/invoke_ccfinderx_dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class invoke_ccfinderx_dialog final
public:
invoke_ccfinderx_dialog(const QString &target, QWidget *parent) noexcept;

invoker_t create_invoker() const noexcept override;

private:
QSpinBox *len_=new QSpinBox(this);
QSpinBox *tks_=new QSpinBox(this);
Expand All @@ -26,7 +28,6 @@ class invoke_ccfinderx_dialog final
threads_selector *threads_=new threads_selector(1, std::thread::hardware_concurrency(), this);

void begin_setup_parameters_layout() noexcept override;
invoker_t create_invoker() const noexcept override;
};

}
Expand Down
2 changes: 1 addition & 1 deletion gui/tools/invoke_ccvolti_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void invoke_ccvolti_dialog::begin_setup_parameters_layout() noexcept
this->parameters_layout_=pl;
}

invoke_dialog::invoker_t invoke_ccvolti_dialog::create_invoker() const noexcept
invoker_t invoke_ccvolti_dialog::create_invoker() const noexcept
{
return ccvolti_invoker(
this->target_path_edit_->text(),
Expand Down
2 changes: 1 addition & 1 deletion gui/tools/invoke_ccvolti_dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class invoke_ccvolti_dialog final

public:
invoke_ccvolti_dialog(const QString &target, QWidget *parent) noexcept;
invoker_t create_invoker() const noexcept override;

private:
QSpinBox *size_=new QSpinBox(this);
Expand All @@ -28,7 +29,6 @@ class invoke_ccvolti_dialog final

void begin_setup_parameters_layout() noexcept override;

invoker_t create_invoker() const noexcept override;
};

}
Expand Down
5 changes: 2 additions & 3 deletions gui/tools/invoke_dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ class invoke_dialog
Q_OBJECT

public:
using invoker_t=std::variant<ccfinderx_invoker, ccvolti_invoker, ccfindersw_invoker, nicad_invoker>;

invoke_dialog(const QString &target, QWidget *parent=nullptr) noexcept;
~invoke_dialog() noexcept;

virtual invoker_t create_invoker() const noexcept=0;

private slots:
void get_target_path() noexcept;
void get_output_filename() noexcept;
Expand All @@ -77,7 +77,6 @@ private slots:
key_arg_box *language_;

virtual void begin_setup_parameters_layout() noexcept=0;
virtual invoker_t create_invoker() const noexcept=0;

void end_setup_parameters_layout() noexcept;

Expand Down
2 changes: 1 addition & 1 deletion gui/tools/invoke_nicad_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void invoke_nicad_dialog::begin_setup_parameters_layout() noexcept
this->parameters_layout_=pl;
}

invoke_dialog::invoker_t invoke_nicad_dialog::create_invoker() const noexcept
invoker_t invoke_nicad_dialog::create_invoker() const noexcept
{
return nicad_invoker();
}
Expand Down
2 changes: 1 addition & 1 deletion gui/tools/invoke_nicad_dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class invoke_nicad_dialog final

public:
invoke_nicad_dialog(const QString &target, QWidget *parent) noexcept;
invoker_t create_invoker() const noexcept override;

private:
QComboBox *granularity_=new QComboBox(this);

void begin_setup_parameters_layout() noexcept override;
invoker_t create_invoker() const noexcept override;
};

}
Expand Down
37 changes: 26 additions & 11 deletions gui/tools/invoker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,55 @@

namespace asterism
{
QProcess* invoker::execute() noexcept
{
this->process_->setArguments(this->args_);
this->process_->start();
return this->process_;
}

QString invoker::tool_name() const noexcept
{
return QString();
}

invoker::invoker() noexcept
{}

ccfinderx_invoker::ccfinderx_invoker(const QString &dirname, const QString &output, const QString &lang, const int b, const int t, const bool f, const bool w, const int threads) noexcept
{
QString ws=f ? "f+" : "f-";
ws+=w ? "w+" : "w-";
args_<<"d"<<lang<<"-o"<<output<<"-b"<<QString::number(b)<<"-t"<<QString::number(t)<<"-w"<<ws<<"-d"<<dirname<<"--threads"<<QString::number(threads);
}

void ccfinderx_invoker::invoke(const QString &exe_path) noexcept
QString ccfinderx_invoker::tool_name() const noexcept
{

return clone_detector::ccfinderx.name();
}

ccvolti_invoker::ccvolti_invoker(const QString &dirname, const QString &lang, const QString &output, const double sim, const int size, const int sizeb, const int t) noexcept
{
this->process_->setProgram("java");
const auto oc=output+".csv";
const auto ocs=output+".txt";
this->args_<<"-d"<<dirname<<"-l"<<lang<<"-oc"<<oc<<"-ocs"<<ocs<<"--sim"<<QString::number(sim)<<"--size"<<QString::number(size)<<"--sizeb"<<QString::number(sizeb)<<"-t"<<QString::number(t);
this->args_<<"-jar"<<global_settings::instance().ccvolti()<<"-d"<<dirname<<"-l"<<lang<<"-oc"<<oc<<"-ocs"<<ocs<<"--sim"<<QString::number(sim)<<"--size"<<QString::number(size)<<"--sizeb"<<QString::number(sizeb)<<"-t"<<QString::number(t);
}

void ccvolti_invoker::invoke(const QString &exe_path) noexcept
QString ccvolti_invoker::tool_name() const noexcept
{
QProcess ccvolti;
this->args_.push_front(exe_path);
this->args_.push_front("-jar");
ccvolti.setArguments(this->args_);
ccvolti.start("java");
return clone_detector::ccvolti.name();
}

void ccfindersw_invoker::invoke(const QString & exe_path) noexcept

QString ccfindersw_invoker::tool_name() const noexcept
{
return clone_detector::ccfindersw.name();
}

void nicad_invoker::invoke(const QString & exe_path) noexcept
QString nicad_invoker::tool_name() const noexcept
{
return clone_detector::nicad.name();
}

}
30 changes: 25 additions & 5 deletions gui/tools/invoker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,71 @@
#include <variant>
#include <thread>

#include "core/global_settings.hpp"

namespace asterism
{

class invoker
{
public:
virtual void invoke(const QString &exe_path) noexcept=0;
QProcess* execute() noexcept;
virtual QString tool_name() const noexcept=0;

protected:
invoker() noexcept;

QStringList args_;
QProcess *process_=new QProcess;
};

class ccfinderx_invoker final
: public invoker
{
public:
ccfinderx_invoker() noexcept=default;
ccfinderx_invoker(const ccfinderx_invoker &v) noexcept=default;
ccfinderx_invoker(ccfinderx_invoker &&v) noexcept=default;
ccfinderx_invoker(const QString &dirname, const QString &output, const QString &lang, const int b, const int t, const bool f, const bool w, const int threads) noexcept;
void invoke(const QString &exe_path) noexcept override;
QString tool_name() const noexcept override;
};


class ccvolti_invoker final
: public invoker
{
public:
ccvolti_invoker() noexcept=default;
ccvolti_invoker(const ccvolti_invoker &v) noexcept=default;
ccvolti_invoker(ccvolti_invoker &&v) noexcept=default;
ccvolti_invoker(const QString &dirname, const QString &lang, const QString &output, const double sim, const int size, const int sizeb, const int t) noexcept;
void invoke(const QString &exe_path) noexcept override;
QString tool_name() const noexcept override;
};


class ccfindersw_invoker final
: public invoker
{
public:
void invoke(const QString &exe_path) noexcept override;
ccfindersw_invoker() noexcept=default;
ccfindersw_invoker(const ccfindersw_invoker &v) noexcept=default;
ccfindersw_invoker(ccfindersw_invoker &&v) noexcept=default;
QString tool_name() const noexcept override;
};


class nicad_invoker final
: public invoker
{
public:
void invoke(const QString &exe_path) noexcept override;
nicad_invoker() noexcept=default;
nicad_invoker(const nicad_invoker &v) noexcept=default;
nicad_invoker(nicad_invoker &&v) noexcept=default;
QString tool_name() const noexcept override;
};

using invoker_t=std::variant<ccfinderx_invoker, ccvolti_invoker, ccfindersw_invoker, nicad_invoker>;

}

#endif // INVOKER_HPP
Loading

0 comments on commit 08c82d2

Please sign in to comment.