Hide menu
Loading...
Searching...
No Matches
visualization/qtquick_qml/baseviewer/main.cxx

Refer to Basic Viewer Example.

BaseViewerApplication.hxx

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
#ifndef BaseViewerApplication_HeaderFile
#define BaseViewerApplication_HeaderFile
#include <cadex/Base_ReaderParameters.hxx>
#include <cadex/ModelData_Model.hxx>
#include <cadex/ModelPrs_Scene.hxx>
#include <cadex/ModelPrs_SceneNode.hxx>
#include <cadex/ModelPrs_SceneNodeFactoryParameters.hxx>
#include <QtCore/QObject>
class QQuickWindow;
class QQmlEngine;
class QVariant;
namespace cadex {
class ModelPrsQtQuick_ViewPort;
}
class BaseViewerApplication : public QObject
{
Q_OBJECT
public:
BaseViewerApplication();
bool Initialize (const QUrl& theUrl, const QString& theViewPortName);
bool event (QEvent* theEvent) override;
virtual void CreateSceneNodes();
signals:
void initialized();
protected slots:
void onImportFile (const QVariant& theUrl);
protected:
void Import (const QString& theFilename);
virtual void Clear();
void ShowMessageBox (const QString& theMessage);
private:
QQuickWindow* CreateMainWindow (const QUrl& theUrl);
void onImportCompleted (QEvent* theEvent);
protected:
cadex::ModelPrs_Scene myScene;
cadex::ModelPrs_SceneNode myRoot;
cadex::Base_ReaderParameters myReaderParameters;
QQuickWindow* myMainWindow = nullptr;
cadex::ModelPrsQtQuick_ViewPort* myViewPort = nullptr;
};
#endif // BaseViewerApplication_HeaderFile
A base class for most frequently used parameters of all readers.
Definition: Base_ReaderParameters.hxx:32
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:43
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22

BaseViewerApplication.cxx

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
#include "BaseViewerApplication.hxx"
#include "ImportRunnable.hxx"
#include "CustomEvents.hxx"
#include <cadex/ModelData_RepresentationSelector.hxx>
#include <cadex/ModelPrs_Scene.hxx>
#include <cadex/ModelPrs_SceneNodeFactory.hxx>
#include <cadex/ModelPrsQtQuick_ViewPort.hxx>
#include <cadex/STEP_ReaderParameters.hxx>
#include <QtCore/QFileInfo>
#include <QtCore/QThreadPool>
#include <QtGui/QOpenGLContext>
#include <QtQml/QQmlApplicationEngine>
#include <QtQuick/QQuickWindow>
#include <QtWidgets/QApplication>
#include <QtWidgets/QMessageBox>
using namespace cadex;
#if __ANDROID__
#include <QtAndroidExtras/QtAndroid>
#endif
#if __ANDROID__ && __ANDROID_DEBUG
#include <android/log.h>
namespace {
void QMessageToAndroidLogRedirector (QtMsgType theType, const QMessageLogContext& /*theContext*/, const QString& theMsg)
{
QString aText;
switch (theType) {
case QtDebugMsg: aText += "qDebug(): "; break;
case QtWarningMsg: aText += "qWarning(): "; break;
case QtCriticalMsg: aText += "qCritical(): "; break;
case QtFatalMsg: aText += "qFatal(): "; break;
case QtInfoMsg: aText += "qInfo(): "; break;
default: break;
}
aText += theMsg;
for (const QString& line : aText.split ('\n')) {
__android_log_print (ANDROID_LOG_DEBUG, "baseviewer", "%s", qPrintable (line));
}
}
}
#endif
BaseViewerApplication::BaseViewerApplication()
: myRoot (ModelPrs_SceneNode::initialized()), myReaderParameters (STEP_ReaderParameters())
{
myScene.AddRoot (myRoot);
qApp->setOrganizationName ("CAD Exchanger");
qApp->setOrganizationDomain ("cadexchanger.com");
}
namespace {
#if !__ANDROID__
QPair<int, int> OpenGlVersion()
{
auto aVersion = qMakePair (-1, -1);
QOpenGLContext aTestOpenGLContext;
aTestOpenGLContext.create();
if (aTestOpenGLContext.isValid()) {
aVersion = aTestOpenGLContext.format().version();
}
return aVersion;
}
#endif
} // end of unnamed namespace
bool BaseViewerApplication::Initialize (const QUrl& theUrl, const QString& theViewPortName)
{
#if __ANDROID__ && __ANDROID_DEBUG
// Register custom message handler.
qInstallMessageHandler (QMessageToAndroidLogRedirector);
#endif
#if !__ANDROID__
auto anOpenGlVersion = OpenGlVersion();
auto aRequiredOpenGlVersion = qMakePair (2, 1);
// Check OpenGl version.
if (anOpenGlVersion < aRequiredOpenGlVersion) {
QMessageBox::critical (nullptr,
QCoreApplication::applicationName(),
tr ("%1 requires graphic card with drivers supporting OpenGL %2.%3 or later.\n"
"Detected driver supports OpenGL %4.%5.\n"
"Please make sure you don't run %1 inside virtual machine "
"and your graphic card driver is upgraded to the latest version "
"Visit your graphic card manufacturer web-site to download the latest drivers.")
.arg (QCoreApplication::applicationName())
.arg (aRequiredOpenGlVersion.first).arg (aRequiredOpenGlVersion.second)
.arg (anOpenGlVersion.first).arg (anOpenGlVersion.second)
);
return false;
}
#endif
// Register types for qml.
ModelPrsQtQuick_ViewPort::RegisterQtTypes();
myMainWindow = CreateMainWindow (theUrl);
Q_ASSERT (myMainWindow);
#if __ANDROID__
// Request read permission on Android.
if (!QtAndroid::shouldShowRequestPermissionRationale("android.permission.READ_EXTERNAL_STORAGE")) {
QtAndroid::requestPermissions({{ "android.permission.READ_EXTERNAL_STORAGE" }},
[] (const QtAndroid::PermissionResultMap & theResult) {
if (theResult["android.permission.READ_EXTERNAL_STORAGE"] == QtAndroid::PermissionResult::Denied) {
qWarning ("User refused request to allow access to sdcard for reading.");
}
});
}
#endif
// Connect slot to signal about clicked "Import" button.
connect (myMainWindow, SIGNAL (importFile (const QVariant&)),
this, SLOT (onImportFile (const QVariant&)));
// Search ModelPrsQtQuick_ViewPort among window's qt objects and attach View Port to Scene.
myViewPort = myMainWindow->findChild<ModelPrsQtQuick_ViewPort*> (theViewPortName);
Q_ASSERT (myViewPort);
auto aRes = myViewPort->AttachToScene (myScene);
myMainWindow->showNormal();
myMainWindow->setProperty ("fileDialogNameFilters", "STEP files (*.stp *.step)");
emit initialized();
// Import model from the program arguments (when was specified).
auto anArguments = QApplication::instance()->arguments();
if (anArguments.size() > 1) {
auto anArgument = anArguments.at (1);
Import (anArgument);
}
return aRes;
}
QQuickWindow* BaseViewerApplication::CreateMainWindow (const QUrl& theUrl)
{
auto anEngine = new QQmlApplicationEngine (this);
QQmlComponent aComponent (anEngine);
aComponent.loadUrl (theUrl);
QObject* aQmlApp = nullptr;
if (!aComponent.isReady()) {
// For easy debugging redirect it to output.
qDebug() << aComponent.errorString();
QCoreApplication::postEvent (QCoreApplication::instance(), new QEvent (QEvent::Quit));
return nullptr;
}
aQmlApp = aComponent.create();
aQmlApp->setParent (this);
return qobject_cast<QQuickWindow*> (aQmlApp);
}
void BaseViewerApplication::onImportFile (const QVariant& theUrl)
{
if (!(theUrl.isValid() || !theUrl.canConvert<QUrl>())) {
qWarning() << "BaseViewerApplication::OnImport: Invalid argument [" << theUrl << "]";
return;
}
auto aFilename = theUrl.toUrl().toLocalFile();
Import (aFilename);
}
void BaseViewerApplication::Import (const QString& theFilename)
{
QFileInfo aFileInfo (theFilename);
if (!aFileInfo.exists() || !aFileInfo.isFile() || !aFileInfo.isReadable()) {
return;
}
Clear();
auto aRunnable = new ImportRunnable (theFilename, myScene, myModel, myReaderParameters, this);
QThreadPool::globalInstance()->start (aRunnable);
myMainWindow->setProperty ("loading", true);
myMainWindow->setTitle (QString ("CAD Exchanger [%1]").arg (theFilename));
}
void BaseViewerApplication::Clear()
{
myModel.Clear();
myRoot.RemoveChildrenNodes();
myScene.Update();
}
void BaseViewerApplication::CreateSceneNodes()
{
ModelPrs_SceneNodeFactory aFactory;
auto aRoot = aFactory.CreateGraph (myModel, ModelData_RM_BRep);
myRoot.AddChildNode (aRoot);
}
bool BaseViewerApplication::event (QEvent* theEvent)
{
auto anEventType = static_cast<ImportResult> (theEvent->type());
if (ImportResult::Error != anEventType && anEventType != ImportResult::Success) {
return QObject::event (theEvent);
}
onImportCompleted (theEvent);
return true;
}
void BaseViewerApplication::onImportCompleted (QEvent* theEvent)
{
auto anEventType = static_cast<ImportResult> (theEvent->type());
switch (anEventType) {
case ImportResult::Success: {
myMainWindow->setProperty ("loading", false);
myViewPort->animatedFitAll();
break;
}
case ImportResult::Error: {
Q_ASSERT (dynamic_cast<ErrorEvent*> (theEvent));
auto anEvent = static_cast<ErrorEvent*> (theEvent);
myMainWindow->setProperty ("loading", false);
ShowMessageBox (anEvent->Message());
break;
}
}
}
void BaseViewerApplication::ShowMessageBox (const QString& theMessage)
{
if (auto aDialog = myMainWindow->findChild<QObject*> ("dialog")) {
aDialog->setProperty ("message", theMessage);
QMetaObject::invokeMethod (aDialog, "open");
}
}
Defines parameters of the STEP_Reader.
Definition: STEP_ReaderParameters.hxx:27

CustomEvents.hxx

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
#ifndef CustomEvents_HeaderFile
#define CustomEvents_HeaderFile
#include <QtCore/QEvent>
#include <QtCore/QString>
enum ImportResult {
Success = QEvent::User + 1,
Error
};
class ErrorEvent : public QEvent
{
public:
ErrorEvent (const QString& myMessage);
const QString& Message() const;
private:
QString myMessage;
};
#endif // CustomEvents_HeaderFile

CustomEvents.cxx

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
#include "CustomEvents.hxx"
ErrorEvent::ErrorEvent (const QString& theMessage)
: QEvent (static_cast<QEvent::Type> (ImportResult::Error)),
myMessage (theMessage)
{
}
const QString& ErrorEvent::Message() const
{
return myMessage;
}

ImportRunnable.hxx

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
#ifndef ImportRunnable_HeaderFile
#define ImportRunnable_HeaderFile
#include "BaseViewerApplication.hxx"
#include <cadex/Base_ReaderParameters.hxx>
#include <QtCore/QRunnable>
namespace cadex {
class ModelData_Model;
class ModelPrs_Scene;
}
class ImportRunnable : public QRunnable
{
public:
ImportRunnable (const QString& theFilename,
cadex::ModelPrs_Scene& theScene,
BaseViewerApplication* theParent);
void run() override;
private:
void Read();
void DisplayModel();
private:
QString myFilename;
cadex::ModelPrs_Scene& myScene;
BaseViewerApplication* myParent;
};
#endif // ImportRunnable_HeaderFile

ImportRunnable.cxx

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
#include "ImportRunnable.hxx"
#include "CustomEvents.hxx"
#include <cadex/ModelData_Model.hxx>
#include <cadex/ModelData_ModelReader.hxx>
#include <cadex/ModelPrs_Scene.hxx>
#include <cadex/ModelPrs_SceneNode.hxx>
#include <cadex/ModelPrs_SceneNodeFactory.hxx>
#include <cadex/ModelPrs_SceneNodeFactoryParameters.hxx>
#include <QtCore/QCoreApplication>
#include <QtCore/QFileInfo>
using namespace cadex;
ImportRunnable::ImportRunnable (const QString& theFilename,
ModelPrs_Scene& theScene,
ModelData_Model& theModel,
BaseViewerApplication* theParent) :
myFilename (theFilename),
myModel (theModel),
myScene (theScene),
myParameters (theParameters),
myParent (theParent)
{
}
void ImportRunnable::Read()
{
aReader.SetReaderParameters (myParameters);
if (!aReader.Read (myFilename.toStdString().data(), myModel)) {
QCoreApplication::postEvent (myParent, new ErrorEvent ("Failed to read the file " + myFilename));
return;
}
}
void ImportRunnable::DisplayModel()
{
myParent->CreateSceneNodes();
myScene.Update();
myScene.Wait();
}
void ImportRunnable::run()
{
Read();
DisplayModel();
QCoreApplication::postEvent (myParent, new QEvent (static_cast<QEvent::Type> (ImportResult::Success)));
}
Reads any format that CAD Exchanger can import.
Definition: ModelData_ModelReader.hxx:33
void SetReaderParameters(const Base_ReaderParameters &theParameters)
Sets reader parameters.
Definition: ModelData_ModelReader.cxx:216
bool Read(const Base_UTF16String &theFilePath, ModelData_Model &theModel)
Reads the file at the specified path into the specified model.
Definition: ModelData_ModelReader.cxx:182

BaseWindow.qml

import QtQuick 2.7
import QtQuick.Controls 2.3
import Qt.labs.platform 1.0 as Platform
import Qt.labs.settings 1.0
import CadEx 1.2
ApplicationWindow {
title: qsTr ("CAD Exchanger")
minimumWidth : 1000
minimumHeight: 600
width : 1000
height: 600
property alias loading: busyIndicator.running
property alias menuBarItem: menuBarItem
property alias fileMenuItem: fileMenuItem
property alias fileDialogNameFilters: fileDialog.nameFilters
signal menuCompleted
signal importFile (var url);
menuBar: MenuBar {
id: menuBarItem
enabled: !loading
Menu {
id: fileMenuItem
title: qsTr("&File")
MenuItem {
text: qsTr ("&Import...")
onTriggered: {
fileDialog.open()
}
}
MenuSeparator { }
MenuItem {
text: qsTr ("&Quit")
onTriggered: {
Qt.quit();
}
}
}
Component.onCompleted: {
menuCompleted();
}
}
Settings {
id: settings
property url lastImportDirectory: Platform.StandardPaths.writableLocation (Platform.StandardPaths.HomeLocation)
}
Platform.FileDialog {
id: fileDialog
title: qsTr ("Please choose a file")
fileMode: Platform.FileDialog.OpenFile
options: Platform.FileDialog.DontResolveSymlinks | Platform.FileDialog.DontUseCustomDirectoryIcons
folder: settings.lastImportDirectory
onAccepted: {
settings.lastImportDirectory = folder;
importFile (file);
}
}
Dialog {
id: dialog
objectName: "dialog"
title: qsTr ("Error")
parent: ApplicationWindow.overlay
x: (parent.width - width) / 2
y: (parent.height - height) / 2
width: 300
standardButtons: Dialog.Ok
visible: false
closePolicy: Popup.CloseOnEscape
dim: true
property string message
Label {
anchors.left: parent.left
anchors.right: parent.right
text: dialog.message
wrapMode: Text.WordWrap
}
}
BusyIndicator {
id: busyIndicator
running: false
visible: running
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottomMargin: 20
width: 80
height: 80
parent: ApplicationWindow.overlay
}
}

BaseViewerWindow.qml

import CadEx 1.2
BaseWindow {
property var viewPort: viewPortItem
ModelPrsQtQuick_ViewPort {
id: viewPortItem
objectName: "viewPort"
anchors.fill: parent
highlightEnabled: true
}
}

main.cxx

// ****************************************************************************
// $Id$
//
// Copyright (C) 2008-2014, Roman Lygin. All rights reserved.
// Copyright (C) 2014-2023, CADEX. All rights reserved.
//
// This file is part of the CAD Exchanger software.
//
// You may use this file under the terms of the BSD license as follows:
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ****************************************************************************
#include "BaseViewerApplication.hxx"
#include <cadex/LicenseManager_Activate.h>
#include <QtCore/QUrl>
#include <QtWidgets/QApplication>
#include "../../../cadex_license.cxx"
using namespace cadex;
int main (int argc, char *argv[])
{
auto aKey = LicenseKey::Value();
// Activate the license (aKey must be defined in cadex_license.cxx).
if (!CADExLicense_Activate (aKey)) {
qCritical ("Failed to activate CAD Exchanger license.");
return 1;
}
// Set dpi scaling before creating an application.
QCoreApplication::setAttribute (Qt::AA_EnableHighDpiScaling);
// Create QApplication because Qt.labs.platform module requires Qt Widgets library.
// For more information see https://doc.qt.io/qt-5.12/qml-qt-labs-platform-filedialog.html#availability
QApplication app (argc, argv);
BaseViewerApplication anApp;
if (anApp.Initialize (QUrl ("qrc:/qml/BaseViewerWindow.qml"), "viewPort")) {
return app.exec();
}
return 0;
}