#define __CADEX_PREVIEW_DRAWINGS 1
#include "DrawingViewerApplication.hxx"
#include <cadex/ModelPrs_SceneNodeFactory.hxx>
#include <cadex/ModelPrsQtQuick_ViewPort.hxx>
#include <cadex/ModelData_Direction.hxx>
#include <cadex/ModelData_Drawing.hxx>
#include <cadex/ModelData_DrawingSheet.hxx>
#include <cadex/ModelData_Point.hxx>
#include <cadex/DWG_ReaderParameters.hxx>
#include <QtQuick/QQuickWindow>
DrawingViewerApplication::DrawingViewerApplication()
{
myReaderParameters = aDWGReaderParameters;
myRoot.SetSelectionMode (ModelPrs_SM_Node);
connect (this, &BaseViewerApplication::initialized, this, &DrawingViewerApplication::onInitialized);
connect (this, &DrawingViewerApplication::sceneNodeCreated, this, &DrawingViewerApplication::onSceneNodeCreated);
}
void DrawingViewerApplication::CreateSceneNodes()
{
auto aDrawing = myModel.Drawing();
if (!aDrawing) {
ShowMessageBox ("The imported model doesn't contain drawing entities.<br>Please import another model.");
return;
}
QStringList aSheetNamesList;
if (aDrawing.NumberOfSheets() > 1) {
aSheetNamesList.push_back ("All");
}
size_t aSheetIndex = 0;
size_t aModelSheetIndex = 0;
while (aSheetIt.HasNext()) {
const auto& aSheet = aSheetIt.Next();
aSheetIndex++;
auto aSheetIndexStr = QString::number (aSheetIndex);
QString aSheetSourceName (reinterpret_cast<const QChar*> (aSheet.Name().Data()));
QString aSheetName = (aSheetSourceName.isEmpty()) ? "Sheet_" + aSheetIndexStr : aSheetSourceName;
if (aSheetNode) {
myRoot.AddChildNode (aSheetNode);
myDrawingSheetNodes.push_back (aSheetNode);
aSheetNamesList.push_back (aSheetName);
if (aSheetName == QLatin1String ("Model")) {
aModelSheetIndex = aSheetIndex - 1;
}
}
}
if (aModelSheetIndex < myDrawingSheetNodes.size()) {
myDrawingSheetNodes[aModelSheetIndex].SetVisibilityMode (ModelPrs_VM_Visible);
}
emit sceneNodeCreated (aSheetNamesList);
}
void DrawingViewerApplication::onInitialized()
{
myMainWindow->setProperty ("fileDialogNameFilters", "DWG files (*.dwg)");
myViewPort->setCameraPositionType (ModelPrs_CMT_Top);
}
void DrawingViewerApplication::onCurrentSheetIndexChanged (int thePreviousIndex, int theCurrentIndex)
{
int aSize = static_cast<int> (myDrawingSheetNodes.size());
if (thePreviousIndex == 0 || theCurrentIndex == 0) {
for (int i = 0; i < aSize; i++) {
myDrawingSheetNodes[i].SetVisibilityMode (aMode);
}
} else {
if (thePreviousIndex > 0 && thePreviousIndex <= aSize) {
myDrawingSheetNodes[thePreviousIndex - 1].SetVisibilityMode (ModelPrs_VM_Hidden);
}
if (theCurrentIndex > 0 && theCurrentIndex <= aSize) {
myDrawingSheetNodes[theCurrentIndex - 1].SetVisibilityMode (ModelPrs_VM_Visible);
}
}
myScene.Update();
myScene.Wait();
myViewPort->animatedFitAll();
}
void DrawingViewerApplication::onSceneNodeCreated (const QStringList& theSheetNamesList)
{
myMainWindow->setProperty ("sheetNamesModel", theSheetNamesList);
connect (myMainWindow, SIGNAL (currentSheetIndexChanged (int,int)),
this, SLOT (onCurrentSheetIndexChanged (int,int)));
}
void DrawingViewerApplication::Clear()
{
disconnect (myMainWindow, SIGNAL (currentSheetIndexChanged (int,int)),
this, SLOT (onCurrentSheetIndexChanged (int,int)));
myMainWindow->setProperty ("sheetNamesModel", {});
myDrawingSheetNodes.clear();
BaseViewerApplication::Clear();
}
bool ReadDrawing() const
Specifies whether a drawing should be read from the file. This is an overloaded member function,...
Definition: Base_ReaderParameters.cxx:194
Defines parameters of the DWG reader.
Definition: DWG_ReaderParameters.hxx:27
Iterator over sheets of a drawing.
Definition: ModelData_Drawing.hxx:51
Creates a scene nodes and its children from input data model objects.
Definition: ModelPrs_SceneNodeFactory.hxx:53
ModelPrs_SceneNode CreateGraph(const ModelData_Model &theModel, ModelData_RepresentationMask theRepresentationMask)
Creates scene graph using ModelData_Model.
Definition: ModelPrs_SceneNodeFactory.cxx:735
void SetVisibilityMode(ModelPrs_VisibilityMode theMode)
Sets theMode as visibility mode.
Definition: ModelPrs_SceneNode.cxx:842
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22
@ ModelPrs_VM_Visible
Fully visible.
Definition: ModelPrs_VisibilityMode.hxx:30
@ ModelPrs_VM_Hidden
Fully unvisible.
Definition: ModelPrs_VisibilityMode.hxx:32
import QtQuick 2.12
import QtQuick.Controls 2.3
import CadEx 1.2
BaseWindow {
id: root
property alias sheetNamesModel: sheetNamesRepeater.model
signal currentSheetIndexChanged (int thePreviousIndex, int theCurrentIndex)
onSheetNamesModelChanged: {
buttonGroup.currentIndex = -1;
var aCount = sheetNamesRepeater.count;
if (aCount > 1) {
var aFind = false;
for (var i = 0; i < aCount; i++) {
if (sheetNamesRepeater.itemAt (i) && sheetNamesRepeater.itemAt (i).text === "Model") {
sheetNamesRepeater.itemAt (i).checked = true;
aFind = true;
break;
}
}
if (!aFind) {
sheetNamesRepeater.itemAt (0).checked = true;
}
} else if (sheetNamesRepeater.itemAt (0)) {
sheetNamesRepeater.itemAt (0).checked = true;
}
}
onMenuCompleted: {
menuBarItem.addMenu (displayedSheet);
}
Menu {
id: displayedSheet
title: qsTr ("&Displayed sheet")
ButtonGroup {
id: buttonGroup
property int currentIndex: -1
onCheckedButtonChanged: {
if (checkedButton) {
var aNewIndex = checkedButton.itemIndex;
currentSheetIndexChanged (currentIndex, aNewIndex);
currentIndex = aNewIndex;
} else {
currentIndex = -1;
}
}
}
Repeater {
id: sheetNamesRepeater
MenuItem {
text: modelData
checkable: true
ButtonGroup.group: buttonGroup
property int itemIndex: index
}
}
}
ModelPrsQtQuick_ViewPort {
id: viewPort
objectName : "viewPort"
anchors.fill : parent
antialiasing : true
highlightEnabled: false
viewCubeEnabled : false
mouseMode : ModelPrsQtQuick_ViewPort.Fixed2d
backgroundStyle: ModelPrsQtQuick_BackgroundStyle {
topColor : "#303030"
bottomColor: "#303030"
}
}
}
#include "DrawingViewerApplication.hxx"
#include <cadex/LicenseManager_Activate.h>
#include <QtCore/QUrl>
#include <QtWidgets/QApplication>
#include "../../../cadex_license.cxx"
int main (int argc, char *argv[])
{
auto aKey = LicenseKey::Value();
if (!CADExLicense_Activate (aKey)) {
qCritical ("Failed to activate CAD Exchanger license.");
return 1;
}
QCoreApplication::setAttribute (Qt::AA_EnableHighDpiScaling);
QApplication app (argc, argv);
DrawingViewerApplication anApp;
if (anApp.Initialize (QUrl ("qrc:/qml/DrawingViewerWindow.qml"), "viewPort")) {
return app.exec();
}
return 0;
}