Skip to content

Commit

Permalink
OMEdit: Add support for LibXml2 instead of XmlPatterns (#11569)
Browse files Browse the repository at this point in the history
Closes #11558
  • Loading branch information
jschueller committed Apr 3, 2024
1 parent cf32d46 commit bc6c961
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 11 deletions.
11 changes: 9 additions & 2 deletions OMEdit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME omedit)
omc_option(OM_OMEDIT_INSTALL_RUNTIME_DLLS "Install the required runtime dll dependency DLLs to the binary directory. Valid only for Windows builds." ON)
omc_option(OM_OMEDIT_ENABLE_TESTS "Enable building of OMEdit Testsuite tests." OFF)
omc_option(OM_OMEDIT_ENABLE_QTWEBENGINE "Enable building of OMEdit with QtWebEngine instead of QtWebkit" OFF)
omc_option(OM_OMEDIT_ENABLE_LIBXML2 "Enable building of OMEdit with LibXml2 instead of XmlPatterns." OFF)

set (OM_QT_MAJOR_VERSION 5 CACHE STRING "Qt version")
find_package(Qt${OM_QT_MAJOR_VERSION} COMPONENTS Widgets PrintSupport Xml XmlPatterns OpenGL Network Svg REQUIRED)
if (OM_OMEDIT_ENABLE_QTWEBENGINE)
find_package(Qt${OM_QT_MAJOR_VERSION} COMPONENTS Widgets PrintSupport Xml OpenGL Network Svg REQUIRED)
if (OM_OMEDIT_ENABLE_QTWEBENGINE OR OM_QT_MAJOR_VERSION VERSION_GREATER_EQUAL 6)
find_package(Qt${OM_QT_MAJOR_VERSION} COMPONENTS WebEngineWidgets REQUIRED)
else ()
find_package(Qt${OM_QT_MAJOR_VERSION} COMPONENTS WebKitWidgets REQUIRED)
endif ()

if (OM_OMEDIT_ENABLE_LIBXML2 OR OM_QT_MAJOR_VERSION VERSION_GREATER_EQUAL 6)
find_package(LibXml2 REQUIRED)
else ()
find_package(Qt${OM_QT_MAJOR_VERSION} COMPONENTS XmlPatterns REQUIRED)
endif ()

find_package(OpenSceneGraph COMPONENTS osg osgViewer osgUtil osgDB osgGA REQUIRED)
find_package(OpenGL REQUIRED)

Expand Down
18 changes: 13 additions & 5 deletions OMEdit/OMEditLIB/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,24 @@ target_link_libraries(OMEditLib PUBLIC omedit::debugger::parser)
target_link_libraries(OMEditLib PUBLIC Qt${OM_QT_MAJOR_VERSION}::Xml)
target_link_libraries(OMEditLib PUBLIC Qt${OM_QT_MAJOR_VERSION}::Widgets)
target_link_libraries(OMEditLib PUBLIC Qt${OM_QT_MAJOR_VERSION}::PrintSupport)
if (OM_OMEDIT_ENABLE_QTWEBENGINE)
target_link_libraries(OMEditLib PUBLIC Qt${OM_QT_MAJOR_VERSION}::OpenGL)
target_link_libraries(OMEditLib PUBLIC Qt${OM_QT_MAJOR_VERSION}::Network)
target_link_libraries(OMEditLib PUBLIC Qt${OM_QT_MAJOR_VERSION}::Svg)

if (OM_OMEDIT_ENABLE_QTWEBENGINE OR OM_QT_MAJOR_VERSION VERSION_GREATER_EQUAL 6)
target_link_libraries(OMEditLib PUBLIC Qt${OM_QT_MAJOR_VERSION}::WebEngineWidgets)
target_compile_definitions(OMEditLib PUBLIC OM_OMEDIT_ENABLE_QTWEBENGINE)
else ()
target_link_libraries(OMEditLib PUBLIC Qt${OM_QT_MAJOR_VERSION}::WebKitWidgets)
endif ()
target_link_libraries(OMEditLib PUBLIC Qt${OM_QT_MAJOR_VERSION}::OpenGL)
target_link_libraries(OMEditLib PUBLIC Qt${OM_QT_MAJOR_VERSION}::Network)
target_link_libraries(OMEditLib PUBLIC Qt${OM_QT_MAJOR_VERSION}::Svg)
target_link_libraries(OMEditLib PUBLIC Qt${OM_QT_MAJOR_VERSION}::XmlPatterns)

if (OM_OMEDIT_ENABLE_LIBXML2 OR OM_QT_MAJOR_VERSION VERSION_GREATER_EQUAL 6)
target_link_libraries(OMEditLib PUBLIC LibXml2::LibXml2)
target_compile_definitions(OMEditLib PUBLIC OM_OMEDIT_ENABLE_LIBXML2)
else ()
target_link_libraries(OMEditLib PUBLIC Qt${OM_QT_MAJOR_VERSION}::XmlPatterns)
endif ()

target_link_libraries(OMEditLib PUBLIC omc::3rd::opcua)
target_link_libraries(OMEditLib PUBLIC OMPlotLib)
target_link_libraries(OMEditLib PUBLIC OpenModelicaCompiler)
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditLIB/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include "CrashReport/CrashReportDialog.h"

#include <QtSvg/QSvgGenerator>
#include <QNetworkProxyFactory>

namespace ToolBars {
QString welcomePerspective = "welcomePerspective";
Expand Down
1 change: 0 additions & 1 deletion OMEdit/OMEditLIB/Modeling/ModelWidgetContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
#ifndef OM_OMEDIT_ENABLE_QTWEBENGINE
#include <QtWebKit>
#endif
#include <QtXmlPatterns>
#include <QSplitter>
#include <QUndoStack>
#include <QUndoView>
Expand Down
42 changes: 41 additions & 1 deletion OMEdit/OMEditLIB/Util/Utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@
#include <QStylePainter>
#include <QPainter>
#include <QColorDialog>
#include <QDir>
#include <QRegExp>
#ifdef OM_OMEDIT_ENABLE_LIBXML2
#include <libxml/parser.h>
#include <libxml/valid.h>
#else
#include <QXmlSchema>
#include <QXmlSchemaValidator>
#include <QDir>
#endif


extern "C" {
extern const char* System_openModelicaPlatform();
Expand Down Expand Up @@ -616,6 +623,38 @@ void Utilities::parseCompositeModelText(MessageHandler *pMessageHandler, QString
schemaFile.close();
const QByteArray schemaData = schemaText.toUtf8();

#ifdef OM_OMEDIT_ENABLE_LIBXML2
xmlDocPtr doc;
QByteArray contentsArray(contents.toLocal8Bit());
doc = xmlParseDoc((const xmlChar *)contentsArray.data());
if (doc)
{
xmlParserInputBufferPtr buf = xmlParserInputBufferCreateMem(schemaData.data(), schemaData.size(), XML_CHAR_ENCODING_UTF8);
xmlDtdPtr dtd = xmlIOParseDTD(NULL, buf, XML_CHAR_ENCODING_UTF8);
xmlFreeParserInputBuffer(buf);
if (dtd)
{
xmlValidCtxtPtr vctxt;
vctxt = xmlNewValidCtxt();
if (vctxt)
{
int ok = xmlValidateDtd(vctxt, doc, dtd);
if (!ok)
pMessageHandler->setFailed(true);
xmlFreeValidCtxt(vctxt);
}
else
pMessageHandler->setFailed(true);
xmlFreeDtd(dtd);
}
else
pMessageHandler->setFailed(true);
xmlFreeDoc(doc);
}
else
pMessageHandler->setFailed(true);

#else
QXmlSchema schema;
schema.setMessageHandler(pMessageHandler);
schema.load(schemaData);
Expand All @@ -627,6 +666,7 @@ void Utilities::parseCompositeModelText(MessageHandler *pMessageHandler, QString
pMessageHandler->setFailed(true);
}
}
#endif
}

/*!
Expand Down
26 changes: 24 additions & 2 deletions OMEdit/OMEditLIB/Util/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#include <QDoubleSpinBox>
#include <QCheckBox>
#include <QVariant>
#include <QAbstractMessageHandler>
#include <QDebug>
#include <QPlainTextEdit>
#include <QTextEdit>
Expand All @@ -60,6 +59,10 @@
#include <QScrollBar>
#include <QGenericMatrix>

#ifndef OM_OMEDIT_ENABLE_LIBXML2
#include <QAbstractMessageHandler>
#endif

#if defined(_WIN32)
#include <windows.h>
#include <tlhelp32.h>
Expand Down Expand Up @@ -334,10 +337,28 @@ inline QDataStream& operator>>(QDataStream& in, DebuggerConfiguration& configura
* \brief Defines the appropriate error message of the parsed XML validated againast the XML Schema.\n
* The class implementation and logic is inspired from Qt Creator sources.
*/
#ifdef OM_OMEDIT_ENABLE_LIBXML2
class MessageHandler
{
public:
MessageHandler() {}
QString statusMessage() const { return mDescription;}
int line() const { return mLine;}
int column() const { return mColumn;}
void setFailed(bool failed) {mFailed = failed;}
bool isFailed() {return mFailed;}
private:
QString mDescription;
int mLine = 0;
int mColumn = 0;
bool mFailed = false;
};
#else
class MessageHandler : public QAbstractMessageHandler
{
public:
MessageHandler() : QAbstractMessageHandler(0) {mFailed = false;}
MessageHandler()
: QAbstractMessageHandler(0) {mFailed = false;}
QString statusMessage() const { return mDescription;}
int line() const { return mSourceLocation.line();}
int column() const { return mSourceLocation.column();}
Expand All @@ -356,6 +377,7 @@ class MessageHandler : public QAbstractMessageHandler
QSourceLocation mSourceLocation;
bool mFailed;
};
#endif

typedef struct {
QString mDelay;
Expand Down

0 comments on commit bc6c961

Please sign in to comment.