Target Polyhedron_3 builds and executes, but with all scripting and RegExp (deprecated) commented

This commit is contained in:
Andreas Fabri 2023-04-19 17:06:44 +01:00
parent 5601e035ff
commit 5030d671d5
9 changed files with 64 additions and 33 deletions

View File

@ -73,10 +73,12 @@
#include <CGAL/Qt/manipulatedCameraFrame.h> #include <CGAL/Qt/manipulatedCameraFrame.h>
#include <CGAL/Qt/manipulatedFrame.h> #include <CGAL/Qt/manipulatedFrame.h>
#include "Color_map.h"
#ifdef QT_SCRIPT_LIB #ifdef QT_SCRIPT_LIB
# include <QScriptEngine> # include <QScriptEngine>
# include <QScriptValue> # include <QScriptValue>
#include "Color_map.h"
using namespace CGAL::Three; using namespace CGAL::Three;
@ -123,6 +125,7 @@ const QString debug_widgets_names[9] = {
# endif # endif
#endif #endif
#if 0
QScriptValue myPrintFunction(QScriptContext *context, QScriptEngine *engine) QScriptValue myPrintFunction(QScriptContext *context, QScriptEngine *engine)
{ {
MainWindow* mw = qobject_cast<MainWindow*>(engine->parent()); MainWindow* mw = qobject_cast<MainWindow*>(engine->parent());
@ -138,6 +141,7 @@ QScriptValue myPrintFunction(QScriptContext *context, QScriptEngine *engine)
return engine->undefinedValue(); return engine->undefinedValue();
} }
#endif
inline inline
QKeySequence combine(Qt::Modifier m, Qt::Key k) QKeySequence combine(Qt::Modifier m, Qt::Key k)
@ -166,8 +170,8 @@ MainWindow::MainWindow(const QStringList &keywords, bool verbose, QWidget* paren
is_locked = false; is_locked = false;
// remove the Load Script menu entry, when the demo has not been compiled with QT_SCRIPT_LIB // remove the Load Script menu entry, when the demo has not been compiled with QT_SCRIPT_LIB
#if !defined(QT_SCRIPT_LIB) #if !defined(QT_SCRIPT_LIB)
ui->menuBar->removeAction(ui->actionLoadScript); // ui->menuBar->removeAction(ui->actionLoadScript);
ui->menuBar->removeAction(ui->on_actionLoad_a_Scene_from_a_Script_File); // ui->menuBar->removeAction(ui->on_actionLoad_a_Scene_from_a_Script_File);
#endif #endif
// Save some pointers from ui, for latter use. // Save some pointers from ui, for latter use.
sceneView = ui->sceneView; sceneView = ui->sceneView;
@ -528,6 +532,7 @@ void MainWindow::filterOperations(bool)
#include <CGAL/Three/exceptions.h> #include <CGAL/Three/exceptions.h>
#if 0
void MainWindow::evaluate_script(QString script, void MainWindow::evaluate_script(QString script,
const QString& filename, const QString& filename,
const bool quiet) { const bool quiet) {
@ -595,6 +600,7 @@ void MainWindow::enableScriptDebugger(bool b /* = true */)
this->error(tr("Your version of Qt is too old, and for that reason " this->error(tr("Your version of Qt is too old, and for that reason "
"the Qt Script Debugger is not available.")); "the Qt Script Debugger is not available."));
} }
#endif
namespace { namespace {
bool actionsByName(QAction* x, QAction* y) { bool actionsByName(QAction* x, QAction* y) {
@ -650,8 +656,8 @@ bool MainWindow::load_plugin(QString fileName, bool blacklisted)
QFileInfo fileinfo(fileName); QFileInfo fileinfo(fileName);
//set plugin name //set plugin name
QString name = fileinfo.fileName(); QString name = fileinfo.fileName();
name.remove(QRegExp("^lib")); name.remove(QRegularExpression("^lib"));
name.remove(QRegExp("\\..*")); name.remove(QRegularExpression("\\..*"));
//do not load it if it is in the blacklist //do not load it if it is in the blacklist
if(blacklisted) if(blacklisted)
{ {
@ -1138,20 +1144,22 @@ bool MainWindow::file_matches_filter(const QString& filters,
QString filename_striped=fileinfo.fileName(); QString filename_striped=fileinfo.fileName();
//match all filters between () //match all filters between ()
QRegExp all_filters_rx("\\((.*)\\)"); QRegularExpression all_filters_rx("\\((.*)\\)");
QStringList split_filters = filters.split(";;"); QStringList split_filters = filters.split(";;");
Q_FOREACH(const QString& filter, split_filters) { Q_FOREACH(const QString& filter, split_filters) {
//extract filters //extract filters
#if 0 // AF @todo
if ( all_filters_rx.indexIn(filter)!=-1 ){ if ( all_filters_rx.indexIn(filter)!=-1 ){
Q_FOREACH(const QString& pattern,all_filters_rx.cap(1).split(' ')){ Q_FOREACH(const QString& pattern,all_filters_rx.cap(1).split(' ')){
QRegExp rx(pattern); QRegularExpression rx(pattern);
rx.setPatternSyntax(QRegExp::Wildcard); rx.setPatternSyntax(QRegularExpression::Wildcard);
if ( rx.exactMatch(filename_striped) ){ if ( rx.exactMatch(filename_striped) ){
return true; return true;
} }
} }
} }
#endif
} }
return false; return false;
} }
@ -1268,6 +1276,7 @@ void MainWindow::open(QString filename)
bool MainWindow::open(QString filename, QString loader_name) { bool MainWindow::open(QString filename, QString loader_name) {
QFileInfo fileinfo(filename); QFileInfo fileinfo(filename);
boost::optional<bool> item_opt; boost::optional<bool> item_opt;
#if 0 // AF
try { try {
item_opt = wrap_a_call_to_cpp item_opt = wrap_a_call_to_cpp
([this, fileinfo, loader_name]() ([this, fileinfo, loader_name]()
@ -1284,6 +1293,7 @@ bool MainWindow::open(QString filename, QString loader_name) {
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
return false; return false;
} }
#endif
return true; return true;
} }
@ -1887,6 +1897,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
event->accept(); event->accept();
} }
#if 0
bool MainWindow::loadScript(QString filename) bool MainWindow::loadScript(QString filename)
{ {
QFileInfo fileinfo(filename); QFileInfo fileinfo(filename);
@ -1920,12 +1931,15 @@ bool MainWindow::loadScript(QFileInfo info)
#endif #endif
return false; return false;
} }
#endif
void MainWindow::throw_exception() { void MainWindow::throw_exception() {
#if 0 // AF
wrap_a_call_to_cpp([]() { wrap_a_call_to_cpp([]() {
throw std::runtime_error("Exception thrown in " throw std::runtime_error("Exception thrown in "
"MainWindow::throw_exception()"); "MainWindow::throw_exception()");
}, this, __FILE__, __LINE__); }, this, __FILE__, __LINE__);
#endif
} }
void MainWindow::on_actionLoadScript_triggered() void MainWindow::on_actionLoadScript_triggered()
@ -2046,7 +2060,7 @@ void MainWindow::on_actionSaveAs_triggered()
sf = plugin->saveNameFilters().split(";;").first(); sf = plugin->saveNameFilters().split(";;").first();
} }
} }
QRegExp extensions("\\(\\*\\..+\\)"); QRegularExpression extensions("\\(\\*\\..+\\)");
QStringList filter_exts; QStringList filter_exts;
if(filters.empty()) if(filters.empty())
{ {
@ -2056,6 +2070,7 @@ void MainWindow::on_actionSaveAs_triggered()
.arg(item->name())); .arg(item->name()));
return; return;
} }
#if 0 // AF
Q_FOREACH(QString string, filters) Q_FOREACH(QString string, filters)
{ {
QStringList sl = string.split(";;"); QStringList sl = string.split(";;");
@ -2065,6 +2080,8 @@ void MainWindow::on_actionSaveAs_triggered()
filter_exts.append(extensions.capturedTexts()); filter_exts.append(extensions.capturedTexts());
} }
} }
#endif
filters << tr("All files (*)"); filters << tr("All files (*)");
if(canSavePlugins.isEmpty()) { if(canSavePlugins.isEmpty()) {
QMessageBox::warning(this, QMessageBox::warning(this,
@ -2094,9 +2111,9 @@ void MainWindow::on_actionSaveAs_triggered()
if(filename.isEmpty()) if(filename.isEmpty())
return; return;
last_saved_dir = QFileInfo(filename).absoluteDir().path(); last_saved_dir = QFileInfo(filename).absoluteDir().path();
extensions.indexIn(sf.split(";;").first()); // AF extensions.indexIn(sf.split(";;").first());
QString filter_ext, filename_ext; QString filter_ext, filename_ext;
filter_ext = extensions.cap().split(" ").first();// in case of syntax like (*.a *.b) // AF filter_ext = extensions.cap().split(" ").first();// in case of syntax like (*.a *.b)
filter_ext.remove(")"); filter_ext.remove(")");
filter_ext.remove("("); filter_ext.remove("(");
@ -2804,9 +2821,11 @@ void MainWindow::colorItems()
return; return;
std::vector<QColor> colors_; std::vector<QColor> colors_;
colors_.reserve(nb_files); colors_.reserve(nb_files);
#
compute_color_map(scene->item(scene->selectionIndices().last())->color(), compute_color_map(scene->item(scene->selectionIndices().last())->color(),
static_cast<unsigned>(nb_files), static_cast<unsigned>(nb_files),
std::back_inserter(colors_)); std::back_inserter(colors_));
std::size_t nb_item = -1; std::size_t nb_item = -1;
Q_FOREACH(int id, scene->selectionIndices()) Q_FOREACH(int id, scene->selectionIndices())
{ {
@ -3859,7 +3878,7 @@ void MainWindow::on_actionLoad_a_Scene_from_a_Script_File_triggered()
if(filename.isEmpty()) if(filename.isEmpty())
return; return;
} }
loadScript(QFileInfo(filename));
if(do_download){ if(do_download){
QFile tmp_file(filename); QFile tmp_file(filename);
tmp_file.remove(); tmp_file.remove();

View File

@ -3,12 +3,13 @@
#include "config.h" #include "config.h"
#include "MainWindow_config.h" #include "MainWindow_config.h"
#include <QtOpenGL/qgl.h> #include <QOpenGLWidget>
#include <CGAL/Qt/DemosMainWindow.h> #include <CGAL/Qt/DemosMainWindow.h>
#include <CGAL/Three/Three.h> #include <CGAL/Three/Three.h>
#include <QScriptEngine> // AF @todo Scripting has changed
#include <QScriptable> // #include <QScriptEngine>
// #include <QScriptable>
#include <QVector> #include <QVector>
@ -60,8 +61,8 @@ namespace Ui {
class MAINWINDOW_EXPORT MainWindow : class MAINWINDOW_EXPORT MainWindow :
public CGAL::Qt::DemosMainWindow, public CGAL::Qt::DemosMainWindow,
public Messages_interface, public Messages_interface,
public CGAL::Three::Three, public CGAL::Three::Three
protected QScriptable // AF , protected QScriptable
{ {
Q_OBJECT Q_OBJECT
Q_INTERFACES(Messages_interface) Q_INTERFACES(Messages_interface)
@ -147,12 +148,13 @@ public Q_SLOTS:
index of the item to be reloaded as data attached to the action. index of the item to be reloaded as data attached to the action.
The index must identify a valid `Scene_item`.*/ The index must identify a valid `Scene_item`.*/
void reloadItem(); void reloadItem();
#if 0
//! Loads a script. Returns true if it worked. //! Loads a script. Returns true if it worked.
bool loadScript(QString filename); bool loadScript(QString filename);
//! Loads a script. Returns true if it worked. //! Loads a script. Returns true if it worked.
bool loadScript(QFileInfo); bool loadScript(QFileInfo);
#endif
/*! /*!
* Gives the keyboard input focus to the widget searchEdit. * Gives the keyboard input focus to the widget searchEdit.
@ -261,7 +263,7 @@ public Q_SLOTS:
* If able, finds a script debugger and interrupts current action. Default * If able, finds a script debugger and interrupts current action. Default
* value for parameter is true. * value for parameter is true.
*/ */
void enableScriptDebugger(bool = true); // void enableScriptDebugger(bool = true);
/// This slot is used to test exception handling in Qt Scripts. /// This slot is used to test exception handling in Qt Scripts.
void throw_exception(); void throw_exception();
@ -449,9 +451,11 @@ public:
//! Calls evaluate_script(script, filename, true). //! Calls evaluate_script(script, filename, true).
void evaluate_script_quiet(QString script, void evaluate_script_quiet(QString script,
const QString & fileName = QString()); const QString & fileName = QString());
#endif
QMutex mutex; QMutex mutex;
QWaitCondition wait_condition; QWaitCondition wait_condition;
#endif
public Q_SLOTS: public Q_SLOTS:
void on_actionSa_ve_Scene_as_Script_triggered(); void on_actionSa_ve_Scene_as_Script_triggered();
void on_actionLoad_a_Scene_from_a_Script_File_triggered(); void on_actionLoad_a_Scene_from_a_Script_File_triggered();

View File

@ -129,10 +129,10 @@ Polyhedron_demo::Polyhedron_demo(int& argc, char **argv,
} }
#endif #endif
mainWindow.loadScript(":/cgal/Polyhedron_3/javascript/lib.js"); // mainWindow.loadScript(":/cgal/Polyhedron_3/javascript/lib.js");
QFileInfo autostart_js("autostart.js"); QFileInfo autostart_js("autostart.js");
if(!parser.isSet(no_autostart) && autostart_js.exists()) { if(!parser.isSet(no_autostart) && autostart_js.exists()) {
mainWindow.loadScript(autostart_js); // mainWindow.loadScript(autostart_js);
} }
Q_FOREACH(QString filename, parser.positionalArguments()) { Q_FOREACH(QString filename, parser.positionalArguments()) {
mainWindow.open(filename); mainWindow.open(filename);

View File

@ -15,7 +15,7 @@
#include <QObject> #include <QObject>
#include <QMetaObject> #include <QMetaObject>
#include <QString> #include <QString>
#include <QGLWidget> #include <QOpenGLWidget>
#include <QEvent> #include <QEvent>
#include <QMouseEvent> #include <QMouseEvent>
#include <QPainter> #include <QPainter>

View File

@ -7,7 +7,7 @@
#include <CGAL/Three/Scene_draw_interface.h> #include <CGAL/Three/Scene_draw_interface.h>
#include <CGAL/Three/Viewer_config.h> #include <CGAL/Three/Viewer_config.h>
#include <QtOpenGL/qgl.h> #include <QtOpenGLWidgets>
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QString> #include <QString>
#include <QColor> #include <QColor>

View File

@ -2,6 +2,7 @@
#include "ui_Show_point_dialog.h" #include "ui_Show_point_dialog.h"
#include <QClipboard> #include <QClipboard>
#include <QRegularExpression>
Show_point_dialog::Show_point_dialog(QWidget* parent) Show_point_dialog::Show_point_dialog(QWidget* parent)
: QDialog(parent) : QDialog(parent)
@ -50,7 +51,8 @@ void Show_point_dialog::interprete_string(const QString& string)
+ "|" + not_double_char_re + "+" + double_re + "|" + not_double_char_re + "+" + double_re
+ ")" + ")"
+ "$"; + "$";
QRegExp re(full_re); #if 0 // AF @todo QRegExp had exactMatch() and cap()
QRegularExpression re(full_re);
if(re.exactMatch(string)) { if(re.exactMatch(string)) {
// const double x = re.cap(1).toDouble(); // const double x = re.cap(1).toDouble();
// const double y = re.cap(2).toDouble(); // const double y = re.cap(2).toDouble();
@ -66,6 +68,7 @@ void Show_point_dialog::interprete_string(const QString& string)
ui->coord_z->setText(QString()); ui->coord_z->setText(QString());
m_has_correct_coordinates = false; m_has_correct_coordinates = false;
} }
#endif
} }
double Show_point_dialog::get_x() const double Show_point_dialog::get_x() const

View File

@ -18,6 +18,7 @@
#include <QStyleFactory> #include <QStyleFactory>
#include <QAction> #include <QAction>
#include <QMultipleInputDialog.h> #include <QMultipleInputDialog.h>
#include <QRegularExpression>
#include <QRegularExpressionMatch> #include <QRegularExpressionMatch>
#ifdef CGAL_USE_WEBSOCKETS #ifdef CGAL_USE_WEBSOCKETS
#include <QtWebSockets/QWebSocket> #include <QtWebSockets/QWebSocket>
@ -1838,7 +1839,7 @@ void Viewer::setLighting()
connect(dialog->position_lineEdit, &QLineEdit::editingFinished, connect(dialog->position_lineEdit, &QLineEdit::editingFinished,
[this, dialog]() [this, dialog]()
{ {
QStringList list = dialog->position_lineEdit->text().split(QRegExp(","), CGAL_QT_SKIP_EMPTY_PARTS); QStringList list = dialog->position_lineEdit->text().split(QRegularExpression(","), CGAL_QT_SKIP_EMPTY_PARTS);
if (list.isEmpty()) return; if (list.isEmpty()) return;
if (list.size()!=3){ if (list.size()!=3){
QMessageBox *msgBox = new QMessageBox; QMessageBox *msgBox = new QMessageBox;

View File

@ -19,7 +19,7 @@ include(${CGAL_MODULES_DIR}/CGAL_add_test.cmake)
set(moc_file_name "") set(moc_file_name "")
else() else()
set(moc_file_name ${plugin_implementation_base_name}.moc ) set(moc_file_name ${plugin_implementation_base_name}.moc )
qt5_generate_moc( ${plugin_implementation_base_name}.cpp "${CMAKE_CURRENT_BINARY_DIR}/${moc_file_name}" ) qt6_generate_moc( ${plugin_implementation_base_name}.cpp "${CMAKE_CURRENT_BINARY_DIR}/${moc_file_name}" )
add_file_dependencies( ${moc_file_name} "${CMAKE_CURRENT_SOURCE_DIR}/${plugin_implementation_base_name}.cpp" ) add_file_dependencies( ${moc_file_name} "${CMAKE_CURRENT_SOURCE_DIR}/${plugin_implementation_base_name}.cpp" )
endif() endif()
@ -49,7 +49,7 @@ include(${CGAL_MODULES_DIR}/CGAL_add_test.cmake)
set_property(TEST "compilation_of__demo_framework" set_property(TEST "compilation_of__demo_framework"
APPEND PROPERTY FIXTURES_SETUP "demo_framework_SetupFixture") APPEND PROPERTY FIXTURES_SETUP "demo_framework_SetupFixture")
set_property(TEST "compilation_of__demo_framework" set_property(TEST "compilation_of__demo_framework"
APPEND PROPERTY DEPENDS "compilation_of__CGAL_Qt5_moc_and_resources") APPEND PROPERTY DEPENDS "compilation_of__CGAL_Qt6_moc_and_resources")
endif() endif()
endif() endif()
else() else()

View File

@ -19,9 +19,9 @@
#include <exception> #include <exception>
#include <QString> #include <QString>
#include <QApplication> #include <QApplication>
#include <QScriptable> //#include <QScriptable>
#include <QScriptContext> //#include <QScriptContext>
#include <QScriptEngine> //#include <QScriptEngine>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <QStringList> #include <QStringList>
@ -60,6 +60,7 @@ struct Optional_or_bool<void> {
enum Context { CURRENT_CONTEXT, PARENT_CONTEXT }; enum Context { CURRENT_CONTEXT, PARENT_CONTEXT };
#if 1 // AF @todo scripting has changed
/// This function template wraps a `Callable` that can be called without /// This function template wraps a `Callable` that can be called without
/// any argument (such as a lambda expression without arguments), and in /// any argument (such as a lambda expression without arguments), and in
/// case the function call is in a Qt Script context, wraps the call in a /// case the function call is in a Qt Script context, wraps the call in a
@ -69,7 +70,7 @@ enum Context { CURRENT_CONTEXT, PARENT_CONTEXT };
template <typename Callable> template <typename Callable>
typename Optional_or_bool<typename cpp11::result_of<Callable()>::type>::type typename Optional_or_bool<typename cpp11::result_of<Callable()>::type>::type
wrap_a_call_to_cpp(Callable f, wrap_a_call_to_cpp(Callable f,
QScriptable* qs = 0, // QScriptable* qs = 0,
const char* file = 0, const char* file = 0,
int line = -1, int line = -1,
Context c = CURRENT_CONTEXT) { Context c = CURRENT_CONTEXT) {
@ -78,12 +79,13 @@ wrap_a_call_to_cpp(Callable f,
typedef typename O_r_b::type Return_type; typedef typename O_r_b::type Return_type;
const bool no_try_catch = qApp->property("no-try-catch").toBool(); const bool no_try_catch = qApp->property("no-try-catch").toBool();
if(no_try_catch || qs == 0 || !qs->context()) return O_r_b::invoke(f); if(no_try_catch /* || qs == 0 || !qs->context() */ ) return O_r_b::invoke(f);
else else
try { try {
return O_r_b::invoke(f); return O_r_b::invoke(f);
} }
catch(const std::exception& e) { catch(const std::exception& e) {
#if 0
const Script_exception* se = dynamic_cast<const Script_exception*>(&e); const Script_exception* se = dynamic_cast<const Script_exception*>(&e);
QScriptContext* context = qs->context(); QScriptContext* context = qs->context();
QStringList qt_bt = context->backtrace(); QStringList qt_bt = context->backtrace();
@ -121,9 +123,11 @@ wrap_a_call_to_cpp(Callable f,
qScriptValueFromSequence(context->engine(), qt_bt)); qScriptValueFromSequence(context->engine(), qt_bt));
std::cerr << "result after throwError: " std::cerr << "result after throwError: "
<< qPrintable(v.toString()) << std::endl; << qPrintable(v.toString()) << std::endl;
#endif
return Return_type(); return Return_type();
} }
} }
#endif
} // end namespace Three } // end namespace Three
} // end namespace CGAL } // end namespace CGAL