mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
0031570: Samples - add Qt samples similar to standard MFC samples
Added Qt sample OCCTOverview providing examples of use of OCCT API with relevant code and demonstration of results in the viewer. Off-topic: some unused images are removed from dox/introduction/images/
This commit is contained in:
685
samples/qt/OCCTOverview/src/ApplicationCommon.cxx
Normal file
685
samples/qt/OCCTOverview/src/ApplicationCommon.cxx
Normal file
@@ -0,0 +1,685 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#include "ApplicationCommon.h"
|
||||
|
||||
#include <Standard_WarningsDisable.hxx>
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFont>
|
||||
#include <QFrame>
|
||||
#include <QGroupBox>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QMap>
|
||||
#include <QMdiArea>
|
||||
#include <QMdiSubWindow>
|
||||
#include <QMenuBar>
|
||||
#include <QMessageBox>
|
||||
#include <QPair>
|
||||
#include <QSplitter>
|
||||
#include <QStatusBar>
|
||||
#include <QtGlobal>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
#include <Standard_WarningsRestore.hxx>
|
||||
|
||||
#include <OpenGl_GraphicDriver.hxx>
|
||||
#include <OSD_Environment.hxx>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <memory>
|
||||
|
||||
ApplicationCommonWindow::ApplicationCommonWindow (ApplicationType theCategory)
|
||||
: QMainWindow (nullptr),
|
||||
myStdToolBar (nullptr),
|
||||
myViewBar (nullptr),
|
||||
myCasCadeBar (nullptr),
|
||||
myFilePopup (nullptr),
|
||||
myCategoryPopup (nullptr)
|
||||
{
|
||||
myAppType = theCategory;
|
||||
mySampleMapper = new QSignalMapper(this);
|
||||
myExchangeMapper = new QSignalMapper(this);
|
||||
myOcafMapper = new QSignalMapper(this);
|
||||
myViewer3dMapper = new QSignalMapper(this);
|
||||
myViewer2dMapper = new QSignalMapper(this);
|
||||
|
||||
myCategoryMapper = new QSignalMapper(this);
|
||||
|
||||
connect(mySampleMapper, static_cast<void (QSignalMapper::*)(const QString &)>(&QSignalMapper::mapped),
|
||||
this, &ApplicationCommonWindow::onProcessSample);
|
||||
connect(myExchangeMapper, static_cast<void (QSignalMapper::*)(const QString &)>(&QSignalMapper::mapped),
|
||||
this, &ApplicationCommonWindow::onProcessExchange);
|
||||
connect(myOcafMapper, static_cast<void (QSignalMapper::*)(const QString &)>(&QSignalMapper::mapped),
|
||||
this, &ApplicationCommonWindow::onProcessOcaf);
|
||||
connect(myViewer3dMapper, static_cast<void (QSignalMapper::*)(const QString &)>(&QSignalMapper::mapped),
|
||||
this, &ApplicationCommonWindow::onProcessViewer3d);
|
||||
connect(myViewer2dMapper, static_cast<void (QSignalMapper::*)(const QString &)>(&QSignalMapper::mapped),
|
||||
this, &ApplicationCommonWindow::onProcessViewer2d);
|
||||
|
||||
connect(myCategoryMapper, static_cast<void (QSignalMapper::*)(const QString &)>(&QSignalMapper::mapped),
|
||||
this, &ApplicationCommonWindow::onChangeCategory);
|
||||
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
QFont aCodeViewFont;
|
||||
aCodeViewFont.setFamily("Courier");
|
||||
aCodeViewFont.setFixedPitch(true);
|
||||
aCodeViewFont.setPointSize(10);
|
||||
|
||||
QGroupBox* aCodeFrame = new QGroupBox(tr("Sample code"));
|
||||
QVBoxLayout* aCodeLayout = new QVBoxLayout(aCodeFrame);
|
||||
aCodeLayout->setContentsMargins(3, 3, 3, 3);
|
||||
myCodeView = new QTextEdit(aCodeFrame);
|
||||
aCodeLayout->addWidget(myCodeView);
|
||||
myCodeView->setDocumentTitle("Code");
|
||||
myCodeView->setLineWrapMode(QTextEdit::NoWrap);
|
||||
myCodeView->setReadOnly(true);
|
||||
myCodeView->setFont(aCodeViewFont);
|
||||
myCodeViewHighlighter = new OcctHighlighter(myCodeView->document());
|
||||
|
||||
QGroupBox* aResultFrame = new QGroupBox(tr("Output"));
|
||||
QVBoxLayout* aResultLayout = new QVBoxLayout(aResultFrame);
|
||||
aResultLayout->setContentsMargins(3, 3, 3, 3);
|
||||
myResultView = new QTextEdit(aResultFrame);
|
||||
aResultLayout->addWidget(myResultView);
|
||||
myResultView->setDocumentTitle("Output");
|
||||
myResultView->setReadOnly(true);
|
||||
myResultView->setFont(aCodeViewFont);
|
||||
|
||||
QSplitter* aCodeResultSplitter = new QSplitter(Qt::Vertical);
|
||||
aCodeResultSplitter->addWidget(aCodeFrame);
|
||||
aCodeResultSplitter->addWidget(aResultFrame);
|
||||
|
||||
myDocument3d = createNewDocument();
|
||||
myDocument2d = createNewDocument();
|
||||
|
||||
QFrame* aViewFrame = new QFrame;
|
||||
aViewFrame->setFrameStyle(QFrame::Panel | QFrame::Sunken);
|
||||
aViewFrame->setLineWidth(3);
|
||||
QVBoxLayout* aViewLayout = new QVBoxLayout(aViewFrame);
|
||||
aViewLayout->setContentsMargins(0, 0, 0, 0);
|
||||
myGeomWidget = new GeomWidget(myDocument3d, myDocument2d, this);
|
||||
aViewLayout->addWidget(myGeomWidget);
|
||||
//myGeomWidget->setContentsMargins(0, 0, 0, 0);
|
||||
QSplitter* aGeomTextSplitter = new QSplitter(Qt::Horizontal);
|
||||
|
||||
aGeomTextSplitter->addWidget(aViewFrame);
|
||||
aGeomTextSplitter->addWidget(aCodeResultSplitter);
|
||||
aGeomTextSplitter->setStretchFactor(0, 1);
|
||||
aGeomTextSplitter->setStretchFactor(1, 1);
|
||||
QList<int> aSizeList{ 640, 640 };
|
||||
aGeomTextSplitter->setSizes(aSizeList);
|
||||
setCentralWidget(aGeomTextSplitter);
|
||||
|
||||
Q_INIT_RESOURCE(Samples);
|
||||
|
||||
TCollection_AsciiString aSampleSourcePach = getSampleSourceDir();
|
||||
myGeometrySamples = new GeometrySamples(aSampleSourcePach,
|
||||
myDocument3d->getContext());
|
||||
myTopologySamples = new TopologySamples(aSampleSourcePach,
|
||||
myDocument3d->getContext());
|
||||
myTriangulationSamples = new TriangulationSamples(aSampleSourcePach,
|
||||
myDocument3d->getContext());
|
||||
myDataExchangeSamples = new DataExchangeSamples(aSampleSourcePach,
|
||||
myGeomWidget->Get3dView(),
|
||||
myDocument3d->getContext());
|
||||
myOcafSamples = new OcafSamples(aSampleSourcePach,
|
||||
myDocument3d->getViewer(),
|
||||
myDocument3d->getContext());
|
||||
myViewer3dSamples = new Viewer3dSamples(aSampleSourcePach,
|
||||
myGeomWidget->Get3dView(),
|
||||
myDocument3d->getContext());
|
||||
myViewer2dSamples = new Viewer2dSamples(aSampleSourcePach,
|
||||
myGeomWidget->Get2dView(),
|
||||
myDocument2d->getViewer(),
|
||||
myDocument2d->getContext());
|
||||
|
||||
MenuFormJson(":/menus/Geometry.json", mySampleMapper, myGeometryMenus);
|
||||
MenuFormJson(":/menus/Topology.json", mySampleMapper, myTopologyMenus);
|
||||
MenuFormJson(":/menus/Triangulation.json", mySampleMapper, myTriangulationMenus);
|
||||
MenuFormJson(":/menus/DataExchange.json", myExchangeMapper, myDataExchangeMenus);
|
||||
MenuFormJson(":/menus/Ocaf.json", myOcafMapper, myOcafMenus);
|
||||
MenuFormJson(":/menus/Viewer3d.json", myViewer3dMapper, myViewer3dMenus);
|
||||
MenuFormJson(":/menus/Viewer2d.json", myViewer2dMapper, myViewer2dMenus);
|
||||
|
||||
onChangeCategory(ALL_CATEGORIES[myAppType]);
|
||||
|
||||
resize(1280, 560);
|
||||
}
|
||||
|
||||
void ApplicationCommonWindow::RebuildMenu()
|
||||
{
|
||||
menuBar()->clear();
|
||||
|
||||
myStdActions[FileQuit] = CreateAction(&ApplicationCommonWindow::onCloseAllWindows, "Quit", "CTRL+Q");
|
||||
myStdActions[HelpAbout] = CreateAction(&ApplicationCommonWindow::onAbout, "About", "F1", ":/icons/help.png");
|
||||
|
||||
// populate a menu with all actions
|
||||
myFilePopup = new QMenu(this);
|
||||
myFilePopup = menuBar()->addMenu(tr("&File"));
|
||||
myFilePopup->addAction(myStdActions[FileQuit]);
|
||||
|
||||
myCategoryPopup = new QMenu(this);
|
||||
myCategoryPopup = menuBar()->addMenu(tr("&Category"));
|
||||
|
||||
for (ApplicationType aCategory: ALL_CATEGORIES.keys())
|
||||
{
|
||||
QString aCategoryName = ALL_CATEGORIES.value(aCategory);
|
||||
QAction* anAction = myCategoryPopup->addAction(aCategoryName);
|
||||
anAction->setText(aCategoryName);
|
||||
myCategoryMapper->setMapping(anAction, aCategoryName);
|
||||
connect(anAction, &QAction::triggered, myCategoryMapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
|
||||
myCategoryPopup->addAction(anAction);
|
||||
myCategoryActions.insert(aCategory, anAction);
|
||||
}
|
||||
|
||||
for (QMenu* aSampleMenu : GetCurrentMenus())
|
||||
{
|
||||
menuBar()->addMenu(aSampleMenu);
|
||||
}
|
||||
|
||||
// add a help menu
|
||||
QMenu* aHelp = new QMenu(this);
|
||||
menuBar()->addSeparator();
|
||||
aHelp = menuBar()->addMenu(tr("&Help"));
|
||||
aHelp->addAction(myStdActions[HelpAbout]);
|
||||
}
|
||||
|
||||
Handle(BaseSample) ApplicationCommonWindow::GetCurrentSamples()
|
||||
{
|
||||
switch (myAppType)
|
||||
{
|
||||
case Geometry: return myGeometrySamples;
|
||||
case Topology: return myTopologySamples;
|
||||
case Triangulation: return myTriangulationSamples;
|
||||
case DataExchange: return myDataExchangeSamples;
|
||||
case Ocaf: return myOcafSamples;
|
||||
case Viewer2d: return myViewer2dSamples;
|
||||
case Viewer3d: return myViewer3dSamples;
|
||||
case Unknown:
|
||||
break;
|
||||
}
|
||||
throw QString("Unknown Application type");
|
||||
}
|
||||
|
||||
const QList<QMenu*>& ApplicationCommonWindow::GetCurrentMenus()
|
||||
{
|
||||
switch (myAppType)
|
||||
{
|
||||
case Geometry: return myGeometryMenus;
|
||||
case Topology: return myTopologyMenus;
|
||||
case Triangulation: return myTriangulationMenus;
|
||||
case DataExchange: return myDataExchangeMenus;
|
||||
case Ocaf: return myOcafMenus;
|
||||
case Viewer2d: return myViewer2dMenus;
|
||||
case Viewer3d: return myViewer3dMenus;
|
||||
case Unknown:
|
||||
break;
|
||||
}
|
||||
throw QString("Unknown Application type");
|
||||
}
|
||||
|
||||
DocumentCommon* ApplicationCommonWindow::createNewDocument()
|
||||
{
|
||||
return new DocumentCommon(this);
|
||||
}
|
||||
|
||||
void ApplicationCommonWindow::onChangeCategory(const QString& theCategory)
|
||||
{
|
||||
myAppType = ALL_CATEGORIES.key(theCategory);
|
||||
setWindowTitle(ALL_CATEGORIES[myAppType]);
|
||||
|
||||
myOcafSamples->ClearExtra();
|
||||
myViewer3dSamples->ClearExtra();
|
||||
myViewer2dSamples->ClearExtra();
|
||||
|
||||
GetCurrentSamples()->Clear();
|
||||
myDocument3d->Clear();
|
||||
myDocument2d->Clear();
|
||||
|
||||
myCodeView->setPlainText("");
|
||||
myResultView->setPlainText("");
|
||||
GetCurrentSamples()->AppendCube();
|
||||
myDocument3d->SetObjects(GetCurrentSamples()->Get3dObjects());
|
||||
myGeomWidget->FitAll();
|
||||
|
||||
RebuildMenu();
|
||||
|
||||
switch (myAppType)
|
||||
{
|
||||
case DataExchange:
|
||||
{
|
||||
myDataExchangeSamples->AppendBottle();
|
||||
myDocument3d->SetObjects(GetCurrentSamples()->Get3dObjects());
|
||||
myGeomWidget->Show3d();
|
||||
break;
|
||||
}
|
||||
case Ocaf:
|
||||
{
|
||||
onProcessOcaf("CreateOcafDocument");
|
||||
myGeomWidget->Show3d();
|
||||
break;
|
||||
}
|
||||
case Viewer2d:
|
||||
{
|
||||
myGeomWidget->Show2d();
|
||||
break;
|
||||
}
|
||||
case Viewer3d:
|
||||
{
|
||||
myViewer3dSamples->AppendBottle();
|
||||
myDocument3d->SetObjects(GetCurrentSamples()->Get3dObjects());
|
||||
myGeomWidget->Show3d();
|
||||
break;
|
||||
}
|
||||
case Geometry:
|
||||
case Topology:
|
||||
case Triangulation:
|
||||
case Unknown:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationCommonWindow::onAbout()
|
||||
{
|
||||
QMessageBox::information(this, tr("OCCT Overview"),
|
||||
tr("Qt based application to study OpenCASCADE Technology"),
|
||||
tr("Ok"), QString::null, QString::null, 0, 0);
|
||||
}
|
||||
|
||||
TCollection_AsciiString ApplicationCommonWindow::getSampleSourceDir()
|
||||
{
|
||||
TCollection_AsciiString aSampleSourceDir = OSD_Environment("CSF_OCCTOverviewSampleCodePath").Value();
|
||||
if (aSampleSourceDir.IsEmpty())
|
||||
{
|
||||
TCollection_AsciiString aCasRoot = OSD_Environment("CASROOT").Value();
|
||||
if (!aCasRoot.IsEmpty())
|
||||
{
|
||||
aSampleSourceDir = aCasRoot + "/samples/OCCTOverview/code";
|
||||
}
|
||||
}
|
||||
return aSampleSourceDir;
|
||||
}
|
||||
|
||||
template <typename PointerToMemberFunction>
|
||||
QAction* ApplicationCommonWindow::CreateAction (PointerToMemberFunction theHandlerMethod,
|
||||
const QString& theActionName,
|
||||
const QString& theShortcut,
|
||||
const QString& theIconName)
|
||||
{
|
||||
QAction* aAction(NULL);
|
||||
if (theIconName.isEmpty())
|
||||
{
|
||||
aAction = new QAction(theActionName, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
QPixmap aIcon = QPixmap(theIconName);
|
||||
aAction = new QAction(aIcon, theActionName, this);
|
||||
}
|
||||
aAction->setToolTip(theActionName);
|
||||
aAction->setStatusTip(theActionName);
|
||||
aAction->setShortcut(theShortcut);
|
||||
connect(aAction, &QAction::triggered, this, theHandlerMethod);
|
||||
return aAction;
|
||||
}
|
||||
|
||||
template <typename PointerToMemberFunction>
|
||||
QAction* ApplicationCommonWindow::CreateSample (PointerToMemberFunction theHandlerMethod,
|
||||
const char* theActionName)
|
||||
{
|
||||
QAction* aAction = new QAction(QObject::tr(theActionName), this);
|
||||
connect(aAction, &QAction::triggered, this, theHandlerMethod);
|
||||
return aAction;
|
||||
}
|
||||
|
||||
void ApplicationCommonWindow::resizeEvent(QResizeEvent* e)
|
||||
{
|
||||
QMainWindow::resizeEvent(e);
|
||||
statusBar()->setSizeGripEnabled(!isMaximized());
|
||||
}
|
||||
|
||||
void ApplicationCommonWindow::onProcessSample(const QString& theSampleName)
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
setWindowTitle(ALL_CATEGORIES[myAppType] + " - " + theSampleName);
|
||||
GetCurrentSamples()->Process(theSampleName.toUtf8().data());
|
||||
myDocument3d->SetObjects(GetCurrentSamples()->Get3dObjects());
|
||||
myDocument2d->SetObjects(GetCurrentSamples()->Get2dObjects());
|
||||
myCodeView->setPlainText(GetCurrentSamples()->GetCode().ToCString());
|
||||
myResultView->setPlainText(GetCurrentSamples()->GetResult().ToCString());
|
||||
myGeomWidget->FitAll();
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void ApplicationCommonWindow::onProcessExchange(const QString& theSampleName)
|
||||
{
|
||||
setWindowTitle(ALL_CATEGORIES[myAppType] + " - " + theSampleName);
|
||||
int aMode = 0;
|
||||
QString aFileName = selectFileName(theSampleName, getDataExchangeDialog(theSampleName), aMode);
|
||||
if (aFileName.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
myDataExchangeSamples->SetFileName(aFileName.toUtf8().data());
|
||||
myDataExchangeSamples->SetStepType(static_cast<STEPControl_StepModelType>(aMode));
|
||||
myDataExchangeSamples->Process(theSampleName.toUtf8().data());
|
||||
myDocument3d->SetObjects(myDataExchangeSamples->Get3dObjects());
|
||||
myDocument2d->SetObjects(myDataExchangeSamples->Get2dObjects());
|
||||
myCodeView->setPlainText(myDataExchangeSamples->GetCode().ToCString());
|
||||
myResultView->setPlainText(myDataExchangeSamples->GetResult().ToCString());
|
||||
myGeomWidget->FitAll();
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void ApplicationCommonWindow::onProcessOcaf(const QString& theSampleName)
|
||||
{
|
||||
setWindowTitle(ALL_CATEGORIES[myAppType] + " - " + theSampleName);
|
||||
|
||||
if (theSampleName.indexOf("Dialog") == 0)
|
||||
{
|
||||
int aMode = 0; // not used
|
||||
QString aFileName = selectFileName(theSampleName, getOcafDialog(theSampleName), aMode);
|
||||
if (aFileName.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
myOcafSamples->SetFileName(aFileName.toUtf8().data());
|
||||
}
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
myOcafSamples->Process(theSampleName.toUtf8().data());
|
||||
myDocument2d->SetObjects(myOcafSamples->Get2dObjects());
|
||||
myCodeView->setPlainText(myOcafSamples->GetCode().ToCString());
|
||||
myResultView->setPlainText(myOcafSamples->GetResult().ToCString());
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void ApplicationCommonWindow::onProcessViewer3d(const QString& theSampleName)
|
||||
{
|
||||
setWindowTitle(ALL_CATEGORIES[myAppType] + " - " + theSampleName);
|
||||
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
myViewer3dSamples->Process(theSampleName.toUtf8().data());
|
||||
myCodeView->setPlainText(myViewer3dSamples->GetCode().ToCString());
|
||||
myResultView->setPlainText(myViewer3dSamples->GetResult().ToCString());
|
||||
myGeomWidget->FitAll();
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void ApplicationCommonWindow::onProcessViewer2d(const QString& theSampleName)
|
||||
{
|
||||
setWindowTitle(ALL_CATEGORIES[myAppType] + " - " + theSampleName);
|
||||
|
||||
Standard_Boolean anIsFileSample = Viewer2dSamples::IsFileSample(theSampleName.toUtf8().data());
|
||||
QString aFileName;
|
||||
if (anIsFileSample)
|
||||
{
|
||||
int aMode = 0; // not used
|
||||
aFileName = selectFileName(theSampleName, getOcafDialog(theSampleName), aMode);
|
||||
if (aFileName.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
myViewer2dSamples->SetFileName(aFileName.toUtf8().data());
|
||||
}
|
||||
if (!anIsFileSample || (anIsFileSample && !aFileName.isEmpty()))
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
myViewer2dSamples->Process(theSampleName.toUtf8().data());
|
||||
if (!Viewer2dSamples::IsShadedSample(theSampleName.toUtf8().data()))
|
||||
{
|
||||
myDocument2d->SetObjects(myViewer2dSamples->Get2dObjects(), Standard_False);
|
||||
}
|
||||
else
|
||||
{
|
||||
myDocument2d->SetObjects(myViewer2dSamples->Get2dObjects(), Standard_True);
|
||||
}
|
||||
myCodeView->setPlainText(myViewer2dSamples->GetCode().ToCString());
|
||||
myResultView->setPlainText(myViewer2dSamples->GetResult().ToCString());
|
||||
myGeomWidget->Show2d();
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
else
|
||||
{
|
||||
myResultView->setPlainText("No file selected!");
|
||||
}
|
||||
}
|
||||
|
||||
QString ApplicationCommonWindow::selectFileName(const QString& theSampleName,
|
||||
TranslateDialog* theDialog, int& theMode)
|
||||
{
|
||||
Q_UNUSED(theSampleName)
|
||||
|
||||
std::shared_ptr<TranslateDialog> aDialog(theDialog);
|
||||
|
||||
int ret = aDialog->exec();
|
||||
theMode = aDialog->getMode();
|
||||
|
||||
qApp->processEvents();
|
||||
|
||||
QString aFilename;
|
||||
QStringList aFileNameList;
|
||||
if (ret != QDialog::Accepted)
|
||||
{
|
||||
return aFilename;
|
||||
}
|
||||
aFileNameList = aDialog->selectedFiles();
|
||||
if (!aFileNameList.isEmpty())
|
||||
{
|
||||
aFilename = aFileNameList[0];
|
||||
}
|
||||
|
||||
if (!QFileInfo(aFilename).completeSuffix().length())
|
||||
{
|
||||
QString selFilter = aDialog->selectedNameFilter();
|
||||
int idx = selFilter.indexOf("(*.");
|
||||
if (idx != -1)
|
||||
{
|
||||
QString tail = selFilter.mid(idx + 3);
|
||||
idx = tail.indexOf(" ");
|
||||
if (idx == -1)
|
||||
{
|
||||
idx = tail.indexOf(")");
|
||||
}
|
||||
QString ext = tail.left(idx);
|
||||
if (ext.length())
|
||||
{
|
||||
aFilename += QString(".") + ext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return aFilename;
|
||||
}
|
||||
|
||||
TranslateDialog* ApplicationCommonWindow::getDataExchangeDialog(const QString& theSampleName)
|
||||
{
|
||||
TranslateDialog* aTranslateDialog = new TranslateDialog(this, 0, true);
|
||||
TCollection_AsciiString aSampleName(theSampleName.toUtf8().data());
|
||||
|
||||
if (DataExchangeSamples::IsExportSample(aSampleName))
|
||||
{
|
||||
aTranslateDialog->setWindowTitle("Export file");
|
||||
aTranslateDialog->setFileMode(QFileDialog::AnyFile);
|
||||
aTranslateDialog->setAcceptMode(QFileDialog::AcceptSave);
|
||||
}
|
||||
else if (DataExchangeSamples::IsImportSample(aSampleName))
|
||||
{
|
||||
aTranslateDialog->setWindowTitle("Import file");
|
||||
aTranslateDialog->setFileMode(QFileDialog::ExistingFile);
|
||||
aTranslateDialog->setAcceptMode(QFileDialog::AcceptOpen);
|
||||
}
|
||||
QString aFormatFilter;
|
||||
if (DataExchangeSamples::IsBrepSample(aSampleName))
|
||||
{
|
||||
aFormatFilter = "BREP Files(*.brep *.rle)";
|
||||
}
|
||||
else if (DataExchangeSamples::IsStepSample(aSampleName))
|
||||
{
|
||||
aFormatFilter = "STEP Files (*.stp *.step)";
|
||||
aTranslateDialog->addMode(STEPControl_ManifoldSolidBrep, "Manifold Solid Brep");
|
||||
aTranslateDialog->addMode(STEPControl_FacetedBrep, "Faceted Brep");
|
||||
aTranslateDialog->addMode(STEPControl_ShellBasedSurfaceModel, "Shell Based Surface Model");
|
||||
aTranslateDialog->addMode(STEPControl_GeometricCurveSet, "Geometric Curve Set");
|
||||
}
|
||||
else if (DataExchangeSamples::IsIgesSample(aSampleName))
|
||||
{
|
||||
aFormatFilter = "IGES Files (*.igs *.iges)";
|
||||
}
|
||||
else if (DataExchangeSamples::IsStlSample(aSampleName))
|
||||
{
|
||||
aFormatFilter = "STL Files (*.stl)";
|
||||
}
|
||||
else if (DataExchangeSamples::IsVrmlSample(aSampleName))
|
||||
{
|
||||
aFormatFilter = "VRML Files (*.vrml)";
|
||||
}
|
||||
else if (DataExchangeSamples::IsImageSample(aSampleName))
|
||||
{
|
||||
aFormatFilter = "All Image Files (*.bmp *.gif *.jpg *.jpeg *.png *.tga)";
|
||||
}
|
||||
QStringList aFilters;
|
||||
aFilters.append(aFormatFilter);
|
||||
aFilters.append("All Files(*.*)");
|
||||
|
||||
aTranslateDialog->setNameFilters(aFilters);
|
||||
aTranslateDialog->clear();
|
||||
return aTranslateDialog;
|
||||
}
|
||||
|
||||
TranslateDialog* ApplicationCommonWindow::getOcafDialog(const QString& theSampleName)
|
||||
{
|
||||
TranslateDialog* aTranslateDialog = new TranslateDialog(this, 0, true);
|
||||
TCollection_AsciiString aSampleName(theSampleName.toUtf8().data());
|
||||
|
||||
if (OcafSamples::IsExportSample(aSampleName))
|
||||
{
|
||||
aTranslateDialog->setWindowTitle("Export file");
|
||||
aTranslateDialog->setFileMode(QFileDialog::AnyFile);
|
||||
aTranslateDialog->setAcceptMode(QFileDialog::AcceptSave);
|
||||
}
|
||||
else if (OcafSamples::IsImportSample(aSampleName))
|
||||
{
|
||||
aTranslateDialog->setWindowTitle("Import file");
|
||||
aTranslateDialog->setFileMode(QFileDialog::ExistingFile);
|
||||
aTranslateDialog->setAcceptMode(QFileDialog::AcceptOpen);
|
||||
}
|
||||
QStringList aFilters;
|
||||
if (OcafSamples::IsBinarySample(aSampleName))
|
||||
{
|
||||
aFilters.append("Binary OCAF Sample (*.cbf)");
|
||||
}
|
||||
if (OcafSamples::IsXmlSample(aSampleName))
|
||||
{
|
||||
aFilters.append("XML OCAF Sample (*.xml)");
|
||||
}
|
||||
aFilters.append("All Files(*.*)");
|
||||
|
||||
aTranslateDialog->setNameFilters(aFilters);
|
||||
aTranslateDialog->clear();
|
||||
return aTranslateDialog;
|
||||
}
|
||||
|
||||
QMenu* ApplicationCommonWindow::MenuFromJsonObject (const QJsonValue& theJsonValue,
|
||||
const QString& theKey,
|
||||
QWidget* theParent,
|
||||
QSignalMapper* theMapper)
|
||||
{
|
||||
QMenu* aMenu = new QMenu(theKey, theParent);
|
||||
if (theJsonValue.isObject())
|
||||
{
|
||||
QJsonObject aBranchObject = theJsonValue.toObject();
|
||||
for (const QString& aBranchKey : aBranchObject.keys())
|
||||
{
|
||||
aMenu->addMenu(MenuFromJsonObject(aBranchObject.value(aBranchKey), aBranchKey, aMenu, theMapper));
|
||||
}
|
||||
}
|
||||
else if (theJsonValue.isArray())
|
||||
{
|
||||
QJsonArray aDataArray = theJsonValue.toArray();
|
||||
for (const QJsonValue& aDataValue : aDataArray)
|
||||
{
|
||||
if (aDataValue.isObject())
|
||||
{
|
||||
QJsonObject aDataObject = aDataValue.toObject();
|
||||
QString aSampleName = aDataObject["function"].toString();
|
||||
QAction* anAction = aMenu->addAction(aSampleName);
|
||||
anAction->setText(aDataObject["text"].toString());
|
||||
|
||||
theMapper->setMapping(anAction, aSampleName);
|
||||
connect(anAction, &QAction::triggered, theMapper,
|
||||
static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
|
||||
}
|
||||
}
|
||||
}
|
||||
return aMenu;
|
||||
}
|
||||
|
||||
void ApplicationCommonWindow::MenuFormJson (const QString& thePath,
|
||||
QSignalMapper* theMapper,
|
||||
QList<QMenu*>& theMunusList)
|
||||
{
|
||||
theMunusList.clear();
|
||||
QFile aJsonFile(thePath);
|
||||
QString anErrorMessage;
|
||||
if (aJsonFile.error() != QFile::NoError)
|
||||
{
|
||||
anErrorMessage = aJsonFile.errorString();
|
||||
Message::SendFail() << "QFile creating error: " << anErrorMessage.toUtf8().constData();
|
||||
return;
|
||||
}
|
||||
if (!aJsonFile.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
Message::SendFail() << "File " << thePath.toUtf8().constData() << " could not open";
|
||||
if (aJsonFile.error() != QFile::NoError)
|
||||
{
|
||||
anErrorMessage = aJsonFile.errorString();
|
||||
Message::SendFail() << "QFile opening error: " << anErrorMessage.toUtf8().constData();
|
||||
}
|
||||
return;
|
||||
}
|
||||
QString aJsonString = aJsonFile.readAll();
|
||||
aJsonFile.close();
|
||||
|
||||
QJsonDocument aJsonDoc = QJsonDocument::fromJson(aJsonString.toUtf8());
|
||||
if (aJsonDoc.isObject())
|
||||
{
|
||||
QJsonObject aJsonObj = aJsonDoc.object();
|
||||
for (const QString& aKey : aJsonObj.keys())
|
||||
{
|
||||
QJsonValue aJsonValue = aJsonObj.value(aKey);
|
||||
if (aJsonValue.isObject())
|
||||
{
|
||||
theMunusList.push_back(MenuFromJsonObject(aJsonValue.toObject(), aKey, this, theMapper));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
197
samples/qt/OCCTOverview/src/ApplicationCommon.h
Normal file
197
samples/qt/OCCTOverview/src/ApplicationCommon.h
Normal file
@@ -0,0 +1,197 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#ifndef APPLICATION_COMMON_OVERVIEW_H
|
||||
#define APPLICATION_COMMON_OVERVIEW_H
|
||||
|
||||
#include "BaseSample.h"
|
||||
#include "CommonSample.h"
|
||||
#include "DataExchangeSamples.h"
|
||||
#include "DocumentCommon.h"
|
||||
#include "GeometrySamples.h"
|
||||
#include "GeomWidget.h"
|
||||
#include "OcafSamples.h"
|
||||
#include "OcctHighlighter.h"
|
||||
#include "TopologySamples.h"
|
||||
#include "TranslateDialog.h"
|
||||
#include "TriangulationSamples.h"
|
||||
#include "View.h"
|
||||
#include "Viewer2dSamples.h"
|
||||
#include "Viewer3dSamples.h"
|
||||
|
||||
#include <Standard_WarningsDisable.hxx>
|
||||
#include <QApplication>
|
||||
#include <QAction>
|
||||
#include <QList>
|
||||
#include <QMainWindow>
|
||||
#include <QMdiArea>
|
||||
#include <QMenu>
|
||||
#include <QSignalMapper>
|
||||
#include <QToolBar>
|
||||
#include <QTextEdit>
|
||||
#include <QWidget>
|
||||
#include <Standard_WarningsRestore.hxx>
|
||||
|
||||
enum StdActions
|
||||
{
|
||||
FileNew, FilePrefUseVBO, FileClose, FilePreferences, FileQuit, ViewTool, ViewStatus, HelpAbout
|
||||
};
|
||||
|
||||
enum ToolActions
|
||||
{
|
||||
ToolWireframe, ToolShading, ToolColor, ToolMaterial, ToolTransparency, ToolDelete
|
||||
};
|
||||
|
||||
enum ApplicationType
|
||||
{
|
||||
Geometry,
|
||||
Topology,
|
||||
Triangulation,
|
||||
DataExchange,
|
||||
Ocaf,
|
||||
Viewer2d,
|
||||
Viewer3d,
|
||||
Unknown
|
||||
};
|
||||
|
||||
const QMap<ApplicationType, QString> ALL_CATEGORIES =
|
||||
{
|
||||
{ ApplicationType::Geometry,"Geometry"},
|
||||
{ ApplicationType::Topology, "Topology"},
|
||||
{ ApplicationType::Triangulation, "Triangulation"},
|
||||
{ ApplicationType::DataExchange, "DataExchange"},
|
||||
{ ApplicationType::Ocaf, "OCAF"},
|
||||
{ ApplicationType::Viewer3d, "3D viewer"},
|
||||
{ ApplicationType::Viewer2d, "2D Viewer"}
|
||||
};
|
||||
|
||||
//! Main application window
|
||||
class COMMONSAMPLE_EXPORT ApplicationCommonWindow: public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ApplicationCommonWindow(ApplicationType theCategory);
|
||||
|
||||
ApplicationType GetApplicationType() const { return myAppType; }
|
||||
void SetApplicationType(ApplicationType theApplicationType) { myAppType = theApplicationType; }
|
||||
|
||||
static TCollection_AsciiString getSampleSourceDir();
|
||||
|
||||
protected:
|
||||
virtual DocumentCommon* createNewDocument();
|
||||
|
||||
public slots:
|
||||
virtual void onAbout();
|
||||
virtual void onChangeCategory(const QString& theCategory);
|
||||
|
||||
protected:
|
||||
template <typename PointerToMemberFunction>
|
||||
QAction* CreateAction(PointerToMemberFunction theHandlerMethod,
|
||||
const QString& theActionName,
|
||||
const QString& theShortcut = "",
|
||||
const QString& theIconName = "");
|
||||
|
||||
template <typename PointerToMemberFunction>
|
||||
QAction* CreateSample(PointerToMemberFunction theHandlerMethod,
|
||||
const char* theActionName);
|
||||
|
||||
virtual void resizeEvent( QResizeEvent* );
|
||||
QMenu* getFilePopup() { return myFilePopup; }
|
||||
QToolBar* getCasCadeBar() { return myCasCadeBar; }
|
||||
|
||||
QMenu* MenuFromJsonObject (const QJsonValue& theJsonValue,
|
||||
const QString& theKey,
|
||||
QWidget* theParent,
|
||||
QSignalMapper* theMapper);
|
||||
void MenuFormJson (const QString& thePath,
|
||||
QSignalMapper* theMapper,
|
||||
QList<QMenu*>& theMunusList);
|
||||
|
||||
private slots:
|
||||
void onCloseAllWindows() { qApp->closeAllWindows(); }
|
||||
|
||||
void onProcessSample(const QString& theSampleName);
|
||||
void onProcessExchange(const QString& theSampleName);
|
||||
void onProcessOcaf(const QString& theSampleName);
|
||||
void onProcessViewer3d(const QString& theSampleName);
|
||||
void onProcessViewer2d(const QString& theSampleName);
|
||||
|
||||
private:
|
||||
|
||||
void RebuildMenu();
|
||||
Handle(BaseSample) GetCurrentSamples();
|
||||
const QList<QMenu*>& GetCurrentMenus();
|
||||
|
||||
QString selectFileName(const QString& theSampleName, TranslateDialog* theDialog, int& theMode);
|
||||
TranslateDialog* getDataExchangeDialog(const QString& theSampleName);
|
||||
TranslateDialog* getOcafDialog(const QString& theSampleName);
|
||||
|
||||
private:
|
||||
ApplicationType myAppType;
|
||||
|
||||
Handle(GeometrySamples) myGeometrySamples;
|
||||
Handle(TopologySamples) myTopologySamples;
|
||||
Handle(TriangulationSamples) myTriangulationSamples;
|
||||
Handle(DataExchangeSamples) myDataExchangeSamples;
|
||||
Handle(OcafSamples) myOcafSamples;
|
||||
Handle(Viewer3dSamples) myViewer3dSamples;
|
||||
Handle(Viewer2dSamples) myViewer2dSamples;
|
||||
|
||||
QMap<StdActions, QAction*> myStdActions;
|
||||
QMap<ApplicationType, QAction*> myCategoryActions;
|
||||
QMap<ToolActions, QAction*> myToolActions;
|
||||
QMap<Graphic3d_NameOfMaterial, QAction*> myMaterialActions;
|
||||
|
||||
QToolBar* myStdToolBar;
|
||||
QToolBar* myViewBar;
|
||||
QToolBar* myCasCadeBar;
|
||||
QMenu* myFilePopup;
|
||||
QMenu* myCategoryPopup;
|
||||
|
||||
// QList<QMenu*> mySamplePopups;
|
||||
QList<QMenu*> myGeometryMenus;
|
||||
QList<QMenu*> myTopologyMenus;
|
||||
QList<QMenu*> myTriangulationMenus;
|
||||
QList<QMenu*> myDataExchangeMenus;
|
||||
QList<QMenu*> myOcafMenus;
|
||||
QList<QMenu*> myViewer3dMenus;
|
||||
QList<QMenu*> myViewer2dMenus;
|
||||
|
||||
QSignalMapper* mySampleMapper;
|
||||
QSignalMapper* myExchangeMapper;
|
||||
QSignalMapper* myOcafMapper;
|
||||
QSignalMapper* myViewer3dMapper;
|
||||
QSignalMapper* myViewer2dMapper;
|
||||
|
||||
QSignalMapper* myCategoryMapper;
|
||||
|
||||
QTextEdit* myCodeView;
|
||||
QTextEdit* myResultView;
|
||||
OcctHighlighter* myCodeViewHighlighter;
|
||||
|
||||
GeomWidget* myGeomWidget;
|
||||
|
||||
DocumentCommon* myDocument3d;
|
||||
DocumentCommon* myDocument2d;
|
||||
};
|
||||
|
||||
#endif
|
43
samples/qt/OCCTOverview/src/CommonSample.h
Normal file
43
samples/qt/OCCTOverview/src/CommonSample.h
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#ifndef COMMONSAMPLE_H
|
||||
#define COMMONSAMPLE_H
|
||||
|
||||
#ifndef NO_COMMONSAMPLE_EXPORTS
|
||||
#ifdef COMMONSAMPLE_EXPORTS
|
||||
#ifdef _WIN32
|
||||
#define COMMONSAMPLE_EXPORT __declspec( dllexport )
|
||||
#else
|
||||
#define COMMONSAMPLE_EXPORT
|
||||
#endif
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
#define COMMONSAMPLE_EXPORT __declspec( dllimport )
|
||||
#else
|
||||
#define COMMONSAMPLE_EXPORT
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#define COMMONSAMPLE_EXPORT
|
||||
#endif
|
||||
|
||||
#endif
|
108
samples/qt/OCCTOverview/src/DocumentCommon.cxx
Normal file
108
samples/qt/OCCTOverview/src/DocumentCommon.cxx
Normal file
@@ -0,0 +1,108 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#include "DocumentCommon.h"
|
||||
|
||||
#include "ApplicationCommon.h"
|
||||
#include "Transparency.h"
|
||||
|
||||
#include <Standard_WarningsDisable.hxx>
|
||||
#include <QApplication>
|
||||
#include <QColor>
|
||||
#include <QColorDialog>
|
||||
#include <QStatusBar>
|
||||
#include <Standard_WarningsRestore.hxx>
|
||||
|
||||
#include <AIS_InteractiveObject.hxx>
|
||||
#include <Aspect_DisplayConnection.hxx>
|
||||
#include <Graphic3d_NameOfMaterial.hxx>
|
||||
#include <OpenGl_GraphicDriver.hxx>
|
||||
#include <OSD_Environment.hxx>
|
||||
|
||||
#include <TCollection_AsciiString.hxx>
|
||||
|
||||
// =======================================================================
|
||||
// function : Viewer
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Handle(V3d_Viewer) DocumentCommon::Viewer(const Standard_ExtString,
|
||||
const Standard_CString,
|
||||
const Standard_Real theViewSize,
|
||||
const V3d_TypeOfOrientation theViewProj,
|
||||
const Standard_Boolean theComputedMode,
|
||||
const Standard_Boolean theDefaultComputedMode)
|
||||
{
|
||||
static Handle(OpenGl_GraphicDriver) aGraphicDriver;
|
||||
if (aGraphicDriver.IsNull())
|
||||
{
|
||||
Handle(Aspect_DisplayConnection) aDisplayConnection;
|
||||
#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX))
|
||||
aDisplayConnection = new Aspect_DisplayConnection(OSD_Environment("DISPLAY").Value());
|
||||
#endif
|
||||
aGraphicDriver = new OpenGl_GraphicDriver(aDisplayConnection);
|
||||
}
|
||||
|
||||
Handle(V3d_Viewer) aViewer = new V3d_Viewer(aGraphicDriver);
|
||||
aViewer->SetDefaultViewSize(theViewSize);
|
||||
aViewer->SetDefaultViewProj(theViewProj);
|
||||
aViewer->SetComputedMode(theComputedMode);
|
||||
aViewer->SetDefaultComputedMode(theDefaultComputedMode);
|
||||
return aViewer;
|
||||
}
|
||||
|
||||
DocumentCommon::DocumentCommon(ApplicationCommonWindow* theApp)
|
||||
: QObject (theApp),
|
||||
myContextIsEmpty(true)
|
||||
{
|
||||
TCollection_ExtendedString a3DName("Visu3D");
|
||||
|
||||
myViewer = Viewer(a3DName.ToExtString(), "", 1000.0, V3d_XposYnegZpos, Standard_True, Standard_True);
|
||||
|
||||
myViewer->SetDefaultLights();
|
||||
myViewer->SetLightOn();
|
||||
|
||||
myContext = new AIS_InteractiveContext(myViewer);
|
||||
}
|
||||
|
||||
void DocumentCommon::SetObjects (const NCollection_Vector<Handle(AIS_InteractiveObject)>& theObjects,
|
||||
Standard_Boolean theDisplayShaded)
|
||||
{
|
||||
myContext->RemoveAll(Standard_False);
|
||||
myContextIsEmpty = theObjects.IsEmpty();
|
||||
for (const Handle(AIS_InteractiveObject) anObject : theObjects)
|
||||
{
|
||||
if (!theDisplayShaded)
|
||||
{
|
||||
myContext->Display(anObject, Standard_False);
|
||||
}
|
||||
else
|
||||
{
|
||||
myContext->Display(anObject, AIS_Shaded, 0, Standard_False);
|
||||
}
|
||||
}
|
||||
myViewer->Redraw();
|
||||
}
|
||||
|
||||
void DocumentCommon::Clear()
|
||||
{
|
||||
myContext->RemoveAll(Standard_True);
|
||||
myContextIsEmpty = true;
|
||||
}
|
75
samples/qt/OCCTOverview/src/DocumentCommon.h
Normal file
75
samples/qt/OCCTOverview/src/DocumentCommon.h
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#ifndef DOCUMENT_COMMON_OVERVIEW_H
|
||||
#define DOCUMENT_COMMON_OVERVIEW_H
|
||||
|
||||
#include "CommonSample.h"
|
||||
|
||||
#include <Standard_WarningsDisable.hxx>
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <Standard_WarningsRestore.hxx>
|
||||
|
||||
#include <AIS_InteractiveContext.hxx>
|
||||
#include <V3d_Viewer.hxx>
|
||||
|
||||
class ApplicationCommonWindow;
|
||||
|
||||
//! Implements visualization of samples content
|
||||
class COMMONSAMPLE_EXPORT DocumentCommon : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
DocumentCommon(ApplicationCommonWindow* );
|
||||
~DocumentCommon() { }
|
||||
|
||||
const Handle(AIS_InteractiveContext)& getContext() { return myContext; }
|
||||
|
||||
const Handle(V3d_Viewer)& getViewer() { return myViewer; }
|
||||
|
||||
void setViewer (const Handle(V3d_Viewer)& theViewer) { myViewer = theViewer; }
|
||||
|
||||
void SetObjects(const NCollection_Vector<Handle(AIS_InteractiveObject)>& theObjects,
|
||||
Standard_Boolean theDisplayShaded = Standard_False);
|
||||
void Clear();
|
||||
bool IsEmpty() const { return myContextIsEmpty; }
|
||||
|
||||
signals:
|
||||
void selectionChanged();
|
||||
void sendCloseDocument( DocumentCommon* );
|
||||
|
||||
private:
|
||||
Handle(V3d_Viewer) Viewer (const Standard_ExtString theName,
|
||||
const Standard_CString theDomain,
|
||||
const Standard_Real theViewSize,
|
||||
const V3d_TypeOfOrientation theViewProj,
|
||||
const Standard_Boolean theComputedMode,
|
||||
const Standard_Boolean theDefaultComputedMode );
|
||||
|
||||
private:
|
||||
Handle(V3d_Viewer) myViewer;
|
||||
Handle(AIS_InteractiveContext) myContext;
|
||||
bool myContextIsEmpty;
|
||||
};
|
||||
|
||||
#endif
|
19
samples/qt/OCCTOverview/src/FILES
Normal file
19
samples/qt/OCCTOverview/src/FILES
Normal file
@@ -0,0 +1,19 @@
|
||||
ApplicationCommon.cxx
|
||||
ApplicationCommon.h
|
||||
CommonSample.h
|
||||
DocumentCommon.cxx
|
||||
DocumentCommon.h
|
||||
GeomWidget.cxx
|
||||
GeomWidget.h
|
||||
Main.cxx
|
||||
OcctHighlighter.cxx
|
||||
OcctHighlighter.h
|
||||
OcctWindow.cxx
|
||||
OcctWindow.h
|
||||
OCCTOverview.qrc
|
||||
TranslateDialog.h
|
||||
TranslateDialog.cxx
|
||||
Transparency.cxx
|
||||
Transparency.h
|
||||
View.cxx
|
||||
View.h
|
100
samples/qt/OCCTOverview/src/GeomWidget.cxx
Normal file
100
samples/qt/OCCTOverview/src/GeomWidget.cxx
Normal file
@@ -0,0 +1,100 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#include "GeomWidget.h"
|
||||
|
||||
#include <Standard_WarningsDisable.hxx>
|
||||
#include <QFrame>
|
||||
#include <QBoxLayout>
|
||||
#include <QTextEdit>
|
||||
#include <QStackedLayout>
|
||||
#include <QToolBar>
|
||||
#include <QStackedWidget>
|
||||
#include <Standard_WarningsRestore.hxx>
|
||||
|
||||
GeomWidget::GeomWidget (DocumentCommon* theDocument3d,
|
||||
DocumentCommon* theDocument2d,
|
||||
QWidget* theParent)
|
||||
: QWidget (theParent),
|
||||
myDocument3d(theDocument3d),
|
||||
myDocument2d(theDocument2d)
|
||||
{
|
||||
QVBoxLayout* aMainLayout = new QVBoxLayout(this);
|
||||
aMainLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
my2dVidget = new QWidget;
|
||||
QVBoxLayout* a2dLayout = new QVBoxLayout(my2dVidget);
|
||||
a2dLayout->setContentsMargins(0, 0, 0, 0);
|
||||
a2dLayout->setSpacing(0);
|
||||
myView2d = new View(myDocument2d->getContext(), false, this);
|
||||
QToolBar* aToolBar2d = new QToolBar;
|
||||
aToolBar2d->addActions(myView2d->getViewActions());
|
||||
a2dLayout->addWidget(aToolBar2d);
|
||||
a2dLayout->addWidget(myView2d);
|
||||
|
||||
my3dVidget = new QWidget;
|
||||
QVBoxLayout* a3dLayout = new QVBoxLayout(my3dVidget);
|
||||
a3dLayout->setContentsMargins(0, 0, 0, 0);
|
||||
a3dLayout->setSpacing(0);
|
||||
myView3d = new View(myDocument3d->getContext(), true, this);
|
||||
QToolBar* aToolBar3d = new QToolBar;
|
||||
aToolBar3d->addActions(myView3d->getViewActions());
|
||||
aToolBar3d->addSeparator();
|
||||
aToolBar3d->addActions(myView3d->getRaytraceActions());
|
||||
a3dLayout->addWidget(aToolBar3d);
|
||||
a3dLayout->addWidget(myView3d);
|
||||
|
||||
myStackWidget = new QStackedWidget(this);
|
||||
aMainLayout->addWidget(myStackWidget);
|
||||
myStackWidget->addWidget(my2dVidget);
|
||||
myStackWidget->addWidget(my3dVidget);
|
||||
|
||||
FitAll();
|
||||
}
|
||||
|
||||
void GeomWidget::FitAll()
|
||||
{
|
||||
if (myDocument2d->IsEmpty())
|
||||
Show3d();
|
||||
else
|
||||
Show2d();
|
||||
}
|
||||
|
||||
void GeomWidget::Show3d()
|
||||
{
|
||||
myView3d->axo();
|
||||
myView3d->fitAll();
|
||||
QAction* aShadingAction = myView3d->getViewAction(ViewAction::Shading);
|
||||
aShadingAction->trigger();
|
||||
aShadingAction->setChecked(true);
|
||||
QAction* aHlrOffAction = myView3d->getViewAction(ViewAction::HlrOff);
|
||||
aHlrOffAction->trigger();
|
||||
aHlrOffAction->setChecked(true);
|
||||
myStackWidget->setCurrentWidget(my3dVidget);
|
||||
setStatusTip("Mouse buttons: Right-Zoom, Middle-Pan, Left-Rotate");
|
||||
}
|
||||
|
||||
void GeomWidget::Show2d()
|
||||
{
|
||||
myView2d->fitAll();
|
||||
myStackWidget->setCurrentWidget(my2dVidget);
|
||||
setStatusTip("Mouse buttons: Right-Zoom, Middle-Pan");
|
||||
}
|
65
samples/qt/OCCTOverview/src/GeomWidget.h
Normal file
65
samples/qt/OCCTOverview/src/GeomWidget.h
Normal file
@@ -0,0 +1,65 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#ifndef GEOMWIDGET_H
|
||||
#define GEOMWIDGET_H
|
||||
|
||||
#include "View.h"
|
||||
#include "DocumentCommon.h"
|
||||
|
||||
#include <Standard_WarningsDisable.hxx>
|
||||
#include <QWidget>
|
||||
#include <Standard_WarningsRestore.hxx>
|
||||
|
||||
class ApplicationCommon;
|
||||
class QStackedWidget;
|
||||
|
||||
//! Qt widget for organize 3D & 2D documents
|
||||
class GeomWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
GeomWidget(DocumentCommon* theDocument3d,
|
||||
DocumentCommon* theDocument2d,
|
||||
QWidget* theParent = nullptr);
|
||||
|
||||
void FitAll();
|
||||
|
||||
Handle(V3d_View) Get3dView() { return myView3d->getView(); }
|
||||
|
||||
Handle(V3d_View) Get2dView() { return myView2d->getView(); }
|
||||
|
||||
void Show3d();
|
||||
void Show2d();
|
||||
|
||||
private:
|
||||
View* myView3d;
|
||||
View* myView2d;
|
||||
|
||||
QWidget* my3dVidget;
|
||||
QWidget* my2dVidget;
|
||||
QStackedWidget* myStackWidget;
|
||||
|
||||
DocumentCommon* myDocument3d;
|
||||
DocumentCommon* myDocument2d;
|
||||
};
|
||||
|
||||
#endif //GEOMWIDGET_H
|
78
samples/qt/OCCTOverview/src/Main.cxx
Normal file
78
samples/qt/OCCTOverview/src/Main.cxx
Normal file
@@ -0,0 +1,78 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#include "ApplicationCommon.h"
|
||||
|
||||
#include <OSD_Environment.hxx>
|
||||
|
||||
#include <Standard_WarningsDisable.hxx>
|
||||
#include <QApplication>
|
||||
#include <QCommandLineParser>
|
||||
#include <QLocale>
|
||||
#include <QSettings>
|
||||
#include <QStringList>
|
||||
#include <QTranslator>
|
||||
#include <Standard_WarningsRestore.hxx>
|
||||
|
||||
int main ( int argc, char* argv[] )
|
||||
{
|
||||
Q_INIT_RESOURCE(OCCTOverview);
|
||||
|
||||
QApplication aQApp( argc, argv );
|
||||
|
||||
QSettings settings("OCCTOverview.conf", QSettings::IniFormat);
|
||||
settings.beginGroup("ApplicationSetting");
|
||||
ApplicationType aCategory = static_cast<ApplicationType>(settings.value("ApplicationType", "").toInt());
|
||||
settings.endGroup();
|
||||
|
||||
ApplicationCommonWindow* aWindow = new ApplicationCommonWindow(aCategory);
|
||||
QString aResName(":/icons/lamp.png");
|
||||
aWindow->setWindowIcon(QPixmap(aResName));
|
||||
|
||||
settings.beginGroup("WindowPosition");
|
||||
int x = settings.value("x", -1).toInt();
|
||||
int y = settings.value("y", -1).toInt();
|
||||
int width = settings.value("width", -1).toInt();
|
||||
int height = settings.value("height", -1).toInt();
|
||||
settings.endGroup();
|
||||
|
||||
if (x > 0 && y > 0 && width > 0 && height > 0)
|
||||
{
|
||||
aWindow->setGeometry(x, y, width, height);
|
||||
}
|
||||
aWindow->SetApplicationType(aCategory);
|
||||
|
||||
aWindow->show();
|
||||
int aResult = aQApp.exec();
|
||||
|
||||
settings.beginGroup("WindowPosition");
|
||||
settings.setValue("x", aWindow->x());
|
||||
settings.setValue("y", aWindow->y());
|
||||
settings.setValue("width", aWindow->width());
|
||||
settings.setValue("height", aWindow->height());
|
||||
settings.endGroup();
|
||||
|
||||
settings.beginGroup("ApplicationSetting");
|
||||
settings.setValue("ApplicationType", aWindow->GetApplicationType());
|
||||
settings.endGroup();
|
||||
|
||||
return aResult;
|
||||
}
|
29
samples/qt/OCCTOverview/src/OCCTOverview.qrc
Normal file
29
samples/qt/OCCTOverview/src/OCCTOverview.qrc
Normal file
@@ -0,0 +1,29 @@
|
||||
<RCC>
|
||||
<qresource prefix="/icons">
|
||||
<file alias="lamp.png">../res/lamp.png</file>
|
||||
<file alias="view_axo.png">../res/view_axo.png</file>
|
||||
<file alias="view_back.png">../res/view_back.png</file>
|
||||
<file alias="view_bottom.png">../res/view_bottom.png</file>
|
||||
<file alias="view_comp_off.png">../res/view_comp_off.png</file>
|
||||
<file alias="view_comp_on.png">../res/view_comp_on.png</file>
|
||||
<file alias="view_fitall.png">../res/view_fitall.png</file>
|
||||
<file alias="view_front.png">../res/view_front.png</file>
|
||||
<file alias="view_left.png">../res/view_left.png</file>
|
||||
<file alias="view_reset.png">../res/view_reset.png</file>
|
||||
<file alias="view_top.png">../res/view_top.png</file>
|
||||
<file alias="antialiasing.png">../res/antialiasing.png</file>
|
||||
<file alias="raytracing.png">../res/raytracing.png</file>
|
||||
<file alias="reflections.png">../res/reflections.png</file>
|
||||
<file alias="shadows.png">../res/shadows.png</file>
|
||||
<file alias="view_right.png">../res/view_right.png</file>
|
||||
<file alias="tool_material.png">../res/tool_material.png</file>
|
||||
<file alias="tool_color.png">../res/tool_color.png</file>
|
||||
<file alias="tool_delete.png">../res/tool_delete.png</file>
|
||||
<file alias="tool_shading.png">../res/tool_shading.png</file>
|
||||
<file alias="tool_transparency.png">../res/tool_transparency.png</file>
|
||||
<file alias="tool_wireframe.png">../res/tool_wireframe.png</file>
|
||||
<file alias="help.png">../res/help.png</file>
|
||||
<file alias="cursor_rotate.png">../res/cursor_rotate.png</file>
|
||||
<file alias="cursor_zoom.png">../res/cursor_zoom.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
254
samples/qt/OCCTOverview/src/OcctHighlighter.cxx
Normal file
254
samples/qt/OCCTOverview/src/OcctHighlighter.cxx
Normal file
@@ -0,0 +1,254 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#include "OcctHighlighter.h"
|
||||
|
||||
#include <Standard_WarningsDisable.hxx>
|
||||
#include <QFont>
|
||||
#include <Standard_WarningsRestore.hxx>
|
||||
|
||||
static const QString anOcctPatterns[] =
|
||||
{
|
||||
QStringLiteral("gp_Pnt"), QStringLiteral("gp_XYZ"), QStringLiteral("gp_Vec"),
|
||||
QStringLiteral("gp_Dir"), QStringLiteral("gp_Ax1"), QStringLiteral("gp_Ax2"),
|
||||
QStringLiteral("gp_Ax3"), QStringLiteral("gp_Lin"), QStringLiteral("gp_Circ"),
|
||||
QStringLiteral("gp_Elips"), QStringLiteral("gp_Parab"), QStringLiteral("gp_Hypr"),
|
||||
QStringLiteral("gp_Cylinder"), QStringLiteral("gp_Cone"), QStringLiteral("gp_Sphere"),
|
||||
QStringLiteral("gp_Torus"), QStringLiteral("gp_Pnt2d"), QStringLiteral("gp_XY"),
|
||||
QStringLiteral("gp_Ax2d"), QStringLiteral("gp_Ax22d"), QStringLiteral("gp_Lin2d"),
|
||||
QStringLiteral("gp_Circ2d."), QStringLiteral("gp_Elips2d"), QStringLiteral("gp_Parab2d"),
|
||||
QStringLiteral("gp_Hypr2d"), QStringLiteral("Geom2d_BSplineCurve"), QStringLiteral("Geom2d_BezierCurve"),
|
||||
QStringLiteral("Geom2d_OffsetCurve"), QStringLiteral("ProjLib"), QStringLiteral("ElSLib"),
|
||||
QStringLiteral("Extrema_ExtElCS"), QStringLiteral("Extrema_POnCurv"), QStringLiteral("IntAna_Quadric"),
|
||||
QStringLiteral("IntAna_IntConicQuad"), QStringLiteral("GccAna_Lin2d2Tan"), QStringLiteral("GccEnt_QualifiedCirc"),
|
||||
QStringLiteral("Geom2dAPI_ProjectPointOnCurve"), QStringLiteral("Geom2dAPI_ExtremaCurveCurve"),
|
||||
QStringLiteral("Geom2dAPI_InterCurveCurve"), QStringLiteral("Geom2dAPI_PointsToBSpline"),
|
||||
QStringLiteral("Geom_CartesianPoint"), QStringLiteral("Geom_VectorWithMagnitude"), QStringLiteral("Geom_Axis1Placement"),
|
||||
QStringLiteral("Geom_Axis2Placement"), QStringLiteral("Geom_Line"), QStringLiteral("Geom_Circle"),
|
||||
QStringLiteral("Geom_Ellipse"), QStringLiteral("Geom_Parabola"), QStringLiteral("Geom_Hyperbola"),
|
||||
QStringLiteral("Geom_BSplineCurve"), QStringLiteral("Geom_BezierCurve"), QStringLiteral("Geom_TrimmedCurve"),
|
||||
QStringLiteral("Geom_OffsetCurve"), QStringLiteral("Geom_BSplineSurface"), QStringLiteral("Geom_BezierSurface"),
|
||||
QStringLiteral("Geom_Plane"), QStringLiteral("Geom_CylindricalSurface"), QStringLiteral("Geom_ConicalSurface"),
|
||||
QStringLiteral("Geom_SphericalSurface"), QStringLiteral("Geom_ToroidalSurface"), QStringLiteral("Geom_RectangularTrimmedSurface"),
|
||||
QStringLiteral("Geom_OffsetSurface"), QStringLiteral("Geom_SurfaceOfLinearExtrusion"), QStringLiteral("Geom_SurfaceOfRevolution"),
|
||||
QStringLiteral("BndLib_Add3dCurve"), QStringLiteral("BndLib_AddSurface"), QStringLiteral("GeomAdaptor_Curve"),
|
||||
QStringLiteral("GeomAdaptor_Surface"), QStringLiteral("GeomAPI_PointsToBSpline"), QStringLiteral("GeomAPI_PointsToBSplineSurface"),
|
||||
QStringLiteral("GeomConvert"), QStringLiteral("Geom2d_CartesianPoint"), QStringLiteral("Geom2d_VectorWithMagnitude"),
|
||||
QStringLiteral("Geom2d_Line"), QStringLiteral("Geom2d_Circle"), QStringLiteral("Geom2d_Ellipse"),
|
||||
QStringLiteral("Geom2d_Parabola"), QStringLiteral("Geom2d_Hyperbola"), QStringLiteral("Geom2d_TrimmedCurve"),
|
||||
QStringLiteral("Geom2dAdaptor_Curve"), QStringLiteral("Bnd_Box2d"), QStringLiteral("BndLib_Add2dCurve"),
|
||||
QStringLiteral("Adaptor2d_Curve2d"), QStringLiteral("BRepBuilderAPI_MakeEdge"), QStringLiteral("BRepBuilderAPI_MakeFace"),
|
||||
QStringLiteral("BRepPrimAPI_MakeBox"), QStringLiteral("AIS_Point"), QStringLiteral("AIS_TextLabel"), QStringLiteral("AIS_Axis"),
|
||||
QStringLiteral("AIS_Circle"), QStringLiteral("AIS_Plane"), QStringLiteral("AIS_Shape"), QStringLiteral("AIS_ColoredShape"),
|
||||
QStringLiteral("GProp_PEquation"), QStringLiteral("Extrema_ExtCS"), QStringLiteral("GCPnts_QuasiUniformDeflection"),
|
||||
QStringLiteral("GProp_GProps"), QStringLiteral("GProp_PrincipalProps"), QStringLiteral("TopoDS"),
|
||||
QStringLiteral("TopoDS_Iterator"), QStringLiteral("TopoDS_Compound"), QStringLiteral("TopoDS_Edge"), QStringLiteral("TopoDS_Face"),
|
||||
QStringLiteral("TopoDS_Shell"), QStringLiteral("TopoDS_Solid"), QStringLiteral("TopoDS_Vertex"),
|
||||
QStringLiteral("TopoDS_Wire"), QStringLiteral("TopExp"), QStringLiteral("TopExp_Explorer"),
|
||||
QStringLiteral("TColgp_Array2OfPnt"), QStringLiteral("BRep_Builder"), QStringLiteral("BRepGProp"), QStringLiteral("BRep_Tool"),
|
||||
QStringLiteral("BRepTools"), QStringLiteral("BRepTools_ReShape"), QStringLiteral("BRepAdaptor_Curve"),
|
||||
QStringLiteral("BRepAdaptor_CompCurve"), QStringLiteral("BRepAdaptor_Surface"), QStringLiteral("BRepAlgoAPI_Common"),
|
||||
QStringLiteral("BRepAlgoAPI_Cut"), QStringLiteral("BRepAlgoAPI_Fuse"), QStringLiteral("BRepAlgoAPI_Section"),
|
||||
QStringLiteral("BRepAlgoAPI_Splitter"), QStringLiteral("BRepAlgoAPI_Defeaturing"), QStringLiteral("BRepBuilderAPI_Copy"),
|
||||
QStringLiteral("BRepBuilderAPI_MakeVertex"), QStringLiteral("BRepBuilderAPI_MakeEdge"), QStringLiteral("BRepBuilderAPI_MakeFace"),
|
||||
QStringLiteral("BRepBuilderAPI_MakePolygon"), QStringLiteral("BRepBuilderAPI_MakeShell"), QStringLiteral("BRepBuilderAPI_MakeSolid"),
|
||||
QStringLiteral("BRepBuilderAPI_MakeWire"), QStringLiteral("BRepBuilderAPI_NurbsConvert"), QStringLiteral("BRepBuilderAPI_Sewing"),
|
||||
QStringLiteral("BRepBuilderAPI_Transform"), QStringLiteral("BRepCheck_Analyzer"), QStringLiteral("BRepPrimAPI_MakeBox"),
|
||||
QStringLiteral("BRepPrimAPI_MakeCylinder"), QStringLiteral("BRepPrimAPI_MakeRevol"), QStringLiteral("BRepFilletAPI_MakeChamfer"),
|
||||
QStringLiteral("BRepFilletAPI_MakeFillet"), QStringLiteral("BRepOffsetAPI_MakeOffset"), QStringLiteral("BRepOffsetAPI_MakeEvolved.hxx"),
|
||||
QStringLiteral("Standard_Integer"), QStringLiteral("Standard_Real"), QStringLiteral("Standard_Boolean"), QStringLiteral("Standard_ShortReal"),
|
||||
QStringLiteral("Standard_Character"), QStringLiteral("Standard_Byte"), QStringLiteral("Standard_Address"), QStringLiteral("Standard_Size"),
|
||||
QStringLiteral("Standard_Time"), QStringLiteral("Standard_Utf8Char"), QStringLiteral("Standard_Utf8UChar"),
|
||||
QStringLiteral("Standard_ExtCharacter"), QStringLiteral("Standard_Utf16Char"), QStringLiteral("Standard_Utf32Char"),
|
||||
QStringLiteral("Standard_WideChar"), QStringLiteral("Standard_CString"), QStringLiteral("Standard_ExtString"),
|
||||
QStringLiteral("NCollection_Vector"), QStringLiteral("TCollection_AsciiString"), QStringLiteral("TCollection_BaseSequence"),
|
||||
QStringLiteral("TCollection_BasicMap"), QStringLiteral("TCollection_BasicMapIterator"), QStringLiteral("TCollection_ExtendedString"),
|
||||
QStringLiteral("TCollection_HAsciiString"), QStringLiteral("TCollection_HExtendedString"), QStringLiteral("TCollection_MapNode"),
|
||||
QStringLiteral("TCollection_MapNodePtr"), QStringLiteral("TCollection_SeqNode"), QStringLiteral("TCollection_SeqNodePtr"),
|
||||
QStringLiteral("TCollection_Side"), QStringLiteral("Standard_False"), QStringLiteral("Standard_True"),
|
||||
QStringLiteral("TCollection"), QStringLiteral("NCollection"), QStringLiteral("gp_Trsf"), QStringLiteral("Handle"),
|
||||
QStringLiteral("Aspect_TOL_DASH"), QStringLiteral("Aspect_TOM_O_STAR"), QStringLiteral("Aspect_TOL_SOLID"),
|
||||
QStringLiteral("Aspect_TOM_O_STAR"), QStringLiteral("AIS_InteractiveObject"), QStringLiteral("AIS_ListOfInteractive"),
|
||||
QStringLiteral("Aspect_GDM_Lines"), QStringLiteral("Aspect_GDM_Points"), QStringLiteral("Aspect_TOM_POINT"),
|
||||
QStringLiteral("Aspect_TOM_RING1"), QStringLiteral("Aspect_TOM_O"),QStringLiteral("BinDrivers"),
|
||||
QStringLiteral("DefineFormat"), QStringLiteral("Font_FA_Bold"), QStringLiteral("Font_FA_BoldItalic"),
|
||||
QStringLiteral("Font_FA_Italic"), QStringLiteral("Font_FA_Regular"), QStringLiteral("DownCast"),
|
||||
QStringLiteral("gp_Pln"), QStringLiteral("Graphic3d_AspectMarker3d"), QStringLiteral("Graphic3d_HTA_LEFT"),
|
||||
QStringLiteral("Graphic3d_NameOfMaterial"), QStringLiteral("Graphic3d_NOM_BRONZE"), QStringLiteral("Graphic3d_NOM_PLASTIC"),
|
||||
QStringLiteral("Graphic3d_VTA_BOTTOM"), QStringLiteral("OpenGl_GraphicDriver"), QStringLiteral("PCDM_RS_OK"),
|
||||
QStringLiteral("PCDM_SS_OK"), QStringLiteral("PCDM_ReaderStatus"), QStringLiteral("PCDM_StoreStatus"),
|
||||
QStringLiteral("Prs3d_Drawer"), QStringLiteral("TPrsStd_AISPresentation"), QStringLiteral("Quantity_Color"),
|
||||
QStringLiteral("Quantity_NameOfColor"), QStringLiteral("Quantity_NOC_BLUE1"), QStringLiteral("Quantity_NOC_CADETBLUE"),
|
||||
QStringLiteral("Quantity_NOC_GREEN"), QStringLiteral("Quantity_NOC_MAGENTA1"), QStringLiteral("Quantity_NOC_RED"),
|
||||
QStringLiteral("Quantity_NOC_YELLOW"), QStringLiteral("Quantity_NOC_WHITE"), QStringLiteral("Quantity_NOC_MATRABLUE"),
|
||||
QStringLiteral("Quantity_TOC_RGB"), QStringLiteral("Quantity_TOC_HLS"), QStringLiteral("Standard_GUID"),
|
||||
QStringLiteral("TColStd_ListIteratorOfListOfTransient"), QStringLiteral("TColStd_ListOfTransient"), QStringLiteral("TDataStd_Integer"),
|
||||
QStringLiteral("TDataStd_Name"), QStringLiteral("TDataStd_Real"), QStringLiteral("TFunction_Driver"),
|
||||
QStringLiteral("TFunction_DriverTable"), QStringLiteral("TFunction_Function"), QStringLiteral("TFunction_Logbook"),
|
||||
QStringLiteral("TDF_Label"), QStringLiteral("TDF_TagSource"), QStringLiteral("TNaming_NamedShape"),
|
||||
QStringLiteral("TopAbs_EDGE"), QStringLiteral("TopAbs_FACE"), QStringLiteral("TopAbs_VERTEX"),
|
||||
QStringLiteral("TPrsStd_AISPresentation"), QStringLiteral("TPrsStd_AISViewer"), QStringLiteral("V3d_AmbientLight"),
|
||||
QStringLiteral("V3d_DirectionalLight"), QStringLiteral("V3d_PositionalLight"), QStringLiteral("V3d_SpotLight"),
|
||||
QStringLiteral("XmlDrivers")
|
||||
};
|
||||
|
||||
static const QString aHelperPatterns[] =
|
||||
{
|
||||
QStringLiteral("AdaptorCurve_AIS"), QStringLiteral("AdaptorVec_AIS"), QStringLiteral("AdaptorCurve2d_AIS"),
|
||||
QStringLiteral("AdaptorPnt2d_AIS"), QStringLiteral("Sample2D_Image"), QStringLiteral("Sample2D_Markers"),
|
||||
QStringLiteral("Sample2D_Face"), QStringLiteral("TOcafFunction_BoxDriver"), QStringLiteral("TOcafFunction_CylDriver"),
|
||||
QStringLiteral("DisplayPresentation")
|
||||
};
|
||||
|
||||
static const QString aKeywordPatterns[] =
|
||||
{
|
||||
QStringLiteral("\\balignas\\b"), QStringLiteral("\\balignof\\b"), QStringLiteral("\\band\\b"),
|
||||
QStringLiteral("\\band_eq\\b"), QStringLiteral("\\basm\\b"), QStringLiteral("\\bauto\\b"),
|
||||
QStringLiteral("\\bbitand\\b"), QStringLiteral("\\bbitor\\b"), QStringLiteral("\\bbool\\b"),
|
||||
QStringLiteral("\\bbreak\\b"), QStringLiteral("\\bcase\\b"), QStringLiteral("\\bcatch\\b"),
|
||||
QStringLiteral("\\bchar\\b"), QStringLiteral("\\bchar16_t\\b"), QStringLiteral("\\bchar32_t\\b"),
|
||||
QStringLiteral("\\bclass\\b"), QStringLiteral("\\bcompl\\b"), QStringLiteral("\\bconst\\b"),
|
||||
QStringLiteral("\\bconstexpr\\b"), QStringLiteral("\\bconst_cast\\b"), QStringLiteral("\\bcontinue\\b"),
|
||||
QStringLiteral("\\bdecltype\\b"), QStringLiteral("\\bdefault\\b"), QStringLiteral("\\bdelete\\b"),
|
||||
QStringLiteral("\\bdo\\b"), QStringLiteral("\\bdouble\\b"), QStringLiteral("\\bdynamic_cast\\b"),
|
||||
QStringLiteral("\\belse\\b"), QStringLiteral("\\benum\\b"), QStringLiteral("\\bexplicit\\b"),
|
||||
QStringLiteral("\\bexport\\b"), QStringLiteral("\\bextern\\b"), QStringLiteral("\\bfalse\\b"),
|
||||
QStringLiteral("\\bfloat\\b"), QStringLiteral("\\bfor\\b"), QStringLiteral("\\bfriend\\b"),
|
||||
QStringLiteral("\\bgoto\\b"), QStringLiteral("\\bif\\b"), QStringLiteral("\\binline\\b"),
|
||||
QStringLiteral("\\bint\\b"), QStringLiteral("\\blong\\b"), QStringLiteral("\\bmutable\\b"),
|
||||
QStringLiteral("\\bnamespace\\b"), QStringLiteral("\\bnew\\b"), QStringLiteral("\\bnoexcept\\b"),
|
||||
QStringLiteral("\\bnot\\b"), QStringLiteral("\\bnot_eq\\b"), QStringLiteral("\\bnullptr\\b"),
|
||||
QStringLiteral("\\boperator\\b"), QStringLiteral("\\bor\\b"), QStringLiteral("\\bor_eq\\b"),
|
||||
QStringLiteral("\\bprivate\\b"), QStringLiteral("\\bprotected\\b"), QStringLiteral("\\bpublic\\b"),
|
||||
QStringLiteral("\\bregister\\b"), QStringLiteral("\\breinterpret_cast\\b"), QStringLiteral("\\breturn\\b"),
|
||||
QStringLiteral("\\bshort\\b"), QStringLiteral("\\bsigned\\b"), QStringLiteral("\\bsizeof\\b"),
|
||||
QStringLiteral("\\bstatic\\b"), QStringLiteral("\\bstatic_assert\\b"), QStringLiteral("\\bstatic_cast\\b"),
|
||||
QStringLiteral("\\bstruct\\b"),QStringLiteral("\\bswitch\\b"), QStringLiteral("\\btemplate\\b"),
|
||||
QStringLiteral("\\bthis\\b"), QStringLiteral("\\bthread_local\\b"), QStringLiteral("\\bthrow\\b"),
|
||||
QStringLiteral("\\btrue\\b"), QStringLiteral("\\btry\\b"), QStringLiteral("\\btypedef\\b"),
|
||||
QStringLiteral("\\btypeid\\b"), QStringLiteral("\\btypename\\b"),QStringLiteral("\\bunion\\b"),
|
||||
QStringLiteral("\\bunsigned\\b"), QStringLiteral("\\busing\\b"), QStringLiteral("\\bvirtual\\b"),
|
||||
QStringLiteral("\\bvoid\\b"), QStringLiteral("\\bvolatile\\b"), QStringLiteral("\\bwchar_t\\b"),
|
||||
QStringLiteral("\\bwhile\\b"), QStringLiteral("\\bxor\\b"), QStringLiteral("\\bxor_eq\\b"),
|
||||
QStringLiteral("\\boverride\\b"), QStringLiteral("\\bfinal\\b")
|
||||
};
|
||||
|
||||
OcctHighlighter::OcctHighlighter(QTextDocument* theParent)
|
||||
: QSyntaxHighlighter (theParent)
|
||||
{
|
||||
HighlightingRule aRule;
|
||||
|
||||
myOcctFormat.setForeground(Qt::darkCyan);
|
||||
|
||||
for (const QString& aPattern : anOcctPatterns)
|
||||
{
|
||||
aRule.myPattern = QRegularExpression(aPattern);
|
||||
aRule.myFormat = myOcctFormat;
|
||||
myHighlightingRules.append(aRule);
|
||||
}
|
||||
|
||||
myHelperFormat.setForeground(Qt::red);
|
||||
for (const QString& aPattern : aHelperPatterns)
|
||||
{
|
||||
aRule.myPattern = QRegularExpression(aPattern);
|
||||
aRule.myFormat = myHelperFormat;
|
||||
myHighlightingRules.append(aRule);
|
||||
}
|
||||
|
||||
|
||||
myKeywordFormat.setForeground(Qt::darkBlue);
|
||||
myKeywordFormat.setFontWeight(QFont::Bold);
|
||||
for (const QString& aPattern : aKeywordPatterns)
|
||||
{
|
||||
aRule.myPattern = QRegularExpression(aPattern);
|
||||
aRule.myFormat = myKeywordFormat;
|
||||
myHighlightingRules.append(aRule);
|
||||
}
|
||||
|
||||
myMemberFormat.setFontWeight(QFont::Bold);
|
||||
aRule.myPattern = QRegularExpression(QStringLiteral("\\bmy[0-9A-Za-z]+\\b"));
|
||||
aRule.myFormat = myMemberFormat;
|
||||
myHighlightingRules.append(aRule);
|
||||
|
||||
myLocalFormat.setForeground(Qt::darkMagenta);
|
||||
aRule.myPattern = QRegularExpression(QStringLiteral("\\ba[0-9A-Za-z]+\\b"));
|
||||
aRule.myFormat = myLocalFormat;
|
||||
myHighlightingRules.append(aRule);
|
||||
|
||||
myQuotationFormat.setForeground(Qt::darkRed);
|
||||
aRule.myPattern = QRegularExpression(QStringLiteral("\".*\""));
|
||||
aRule.myFormat = myQuotationFormat;
|
||||
myHighlightingRules.append(aRule);
|
||||
|
||||
myFunctionFormat.setFontItalic(true);
|
||||
myFunctionFormat.setForeground(Qt::blue);
|
||||
aRule.myPattern = QRegularExpression(QStringLiteral("\\b[A-Za-z0-9_]+(?=\\()"));
|
||||
aRule.myFormat = myFunctionFormat;
|
||||
myHighlightingRules.append(aRule);
|
||||
|
||||
mySingleLineCommentFormat.setForeground(Qt::darkGreen);
|
||||
aRule.myPattern = QRegularExpression(QStringLiteral("//[^\n]*"));
|
||||
aRule.myFormat = mySingleLineCommentFormat;
|
||||
myHighlightingRules.append(aRule);
|
||||
|
||||
myMultiLineCommentFormat.setForeground(Qt::darkGreen);
|
||||
|
||||
myCommentStartExpression = QRegularExpression(QStringLiteral("/\\*"));
|
||||
myCommentEndExpression = QRegularExpression(QStringLiteral("\\*/"));
|
||||
}
|
||||
|
||||
void OcctHighlighter::highlightBlock (const QString& theText)
|
||||
{
|
||||
for (const HighlightingRule& rule : qAsConst(myHighlightingRules))
|
||||
{
|
||||
QRegularExpressionMatchIterator matchIterator = rule.myPattern.globalMatch(theText);
|
||||
while (matchIterator.hasNext())
|
||||
{
|
||||
QRegularExpressionMatch match = matchIterator.next();
|
||||
setFormat(match.capturedStart(), match.capturedLength(), rule.myFormat);
|
||||
}
|
||||
}
|
||||
|
||||
setCurrentBlockState(0);
|
||||
|
||||
int startIndex = 0;
|
||||
if (previousBlockState() != 1)
|
||||
startIndex = theText.indexOf(myCommentStartExpression);
|
||||
|
||||
while (startIndex >= 0)
|
||||
{
|
||||
QRegularExpressionMatch match = myCommentEndExpression.match(theText, startIndex);
|
||||
int endIndex = match.capturedStart();
|
||||
int commentLength = 0;
|
||||
if (endIndex == -1)
|
||||
{
|
||||
setCurrentBlockState(1);
|
||||
commentLength = theText.length() - startIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
commentLength = endIndex - startIndex
|
||||
+ match.capturedLength();
|
||||
}
|
||||
setFormat(startIndex, commentLength, myMultiLineCommentFormat);
|
||||
startIndex = theText.indexOf(myCommentStartExpression, startIndex + commentLength);
|
||||
}
|
||||
}
|
75
samples/qt/OCCTOverview/src/OcctHighlighter.h
Normal file
75
samples/qt/OCCTOverview/src/OcctHighlighter.h
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#ifndef OCCTHIGHLIGHTER_H
|
||||
#define OCCTHIGHLIGHTER_H
|
||||
|
||||
#include <Standard_Macro.hxx>
|
||||
|
||||
#include <Standard_WarningsDisable.hxx>
|
||||
#include <QRegularExpression>
|
||||
#include <QSyntaxHighlighter>
|
||||
#include <QString>
|
||||
#include <QTextDocument>
|
||||
#include <QTextCharFormat>
|
||||
#include <Standard_WarningsRestore.hxx>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTextDocument;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
//! Implements C++ and OCCT objects syntax
|
||||
//! highlighting for sample code window
|
||||
class OcctHighlighter: public QSyntaxHighlighter
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
OcctHighlighter(QTextDocument* theParent = 0);
|
||||
|
||||
protected:
|
||||
void highlightBlock(const QString& theText) Standard_OVERRIDE;
|
||||
|
||||
private:
|
||||
struct HighlightingRule
|
||||
{
|
||||
QRegularExpression myPattern;
|
||||
QTextCharFormat myFormat;
|
||||
};
|
||||
|
||||
private:
|
||||
QVector<HighlightingRule> myHighlightingRules;
|
||||
|
||||
QRegularExpression myCommentStartExpression;
|
||||
QRegularExpression myCommentEndExpression;
|
||||
|
||||
QTextCharFormat myKeywordFormat;
|
||||
QTextCharFormat mySingleLineCommentFormat;
|
||||
QTextCharFormat myMultiLineCommentFormat;
|
||||
QTextCharFormat myQuotationFormat;
|
||||
QTextCharFormat myFunctionFormat;
|
||||
QTextCharFormat myOcctFormat;
|
||||
QTextCharFormat myMemberFormat;
|
||||
QTextCharFormat myLocalFormat;
|
||||
QTextCharFormat myHelperFormat;
|
||||
};
|
||||
|
||||
#endif
|
179
samples/qt/OCCTOverview/src/OcctWindow.cxx
Normal file
179
samples/qt/OCCTOverview/src/OcctWindow.cxx
Normal file
@@ -0,0 +1,179 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#include "OcctWindow.h"
|
||||
|
||||
IMPLEMENT_STANDARD_RTTIEXT(OcctWindow, Aspect_Window)
|
||||
|
||||
// =======================================================================
|
||||
// function : OcctWindow
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
OcctWindow::OcctWindow(QWidget* theWidget, const Quantity_NameOfColor theBackColor)
|
||||
: myWidget (theWidget)
|
||||
{
|
||||
SetBackground(theBackColor);
|
||||
myXLeft = myWidget->rect().left();
|
||||
myYTop = myWidget->rect().top();
|
||||
myXRight = myWidget->rect().right();
|
||||
myYBottom = myWidget->rect().bottom();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : NativeParentHandle
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Aspect_Drawable OcctWindow::NativeParentHandle() const
|
||||
{
|
||||
QWidget* aParentWidget = myWidget->parentWidget();
|
||||
if (aParentWidget != NULL)
|
||||
{
|
||||
return (Aspect_Drawable)aParentWidget->winId();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Map
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OcctWindow::Map() const
|
||||
{
|
||||
myWidget->show();
|
||||
myWidget->update();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Unmap
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OcctWindow::Unmap() const
|
||||
{
|
||||
myWidget->hide();
|
||||
myWidget->update();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : DoResize
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Aspect_TypeOfResize OcctWindow::DoResize()
|
||||
{
|
||||
int aMask = 0;
|
||||
Aspect_TypeOfResize aMode = Aspect_TOR_UNKNOWN;
|
||||
|
||||
if (!myWidget->isMinimized())
|
||||
{
|
||||
if (Abs(myWidget->rect().left() - myXLeft) > 2)
|
||||
{
|
||||
aMask |= 1;
|
||||
}
|
||||
if (Abs(myWidget->rect().right() - myXRight) > 2)
|
||||
{
|
||||
aMask |= 2;
|
||||
}
|
||||
if (Abs(myWidget->rect().top() - myYTop) > 2)
|
||||
{
|
||||
aMask |= 4;
|
||||
}
|
||||
if (Abs(myWidget->rect().bottom() - myYBottom) > 2)
|
||||
{
|
||||
aMask |= 8;
|
||||
}
|
||||
|
||||
switch (aMask)
|
||||
{
|
||||
case 0:
|
||||
aMode = Aspect_TOR_NO_BORDER;
|
||||
break;
|
||||
case 1:
|
||||
aMode = Aspect_TOR_LEFT_BORDER;
|
||||
break;
|
||||
case 2:
|
||||
aMode = Aspect_TOR_RIGHT_BORDER;
|
||||
break;
|
||||
case 4:
|
||||
aMode = Aspect_TOR_TOP_BORDER;
|
||||
break;
|
||||
case 5:
|
||||
aMode = Aspect_TOR_LEFT_AND_TOP_BORDER;
|
||||
break;
|
||||
case 6:
|
||||
aMode = Aspect_TOR_TOP_AND_RIGHT_BORDER;
|
||||
break;
|
||||
case 8:
|
||||
aMode = Aspect_TOR_BOTTOM_BORDER;
|
||||
break;
|
||||
case 9:
|
||||
aMode = Aspect_TOR_BOTTOM_AND_LEFT_BORDER;
|
||||
break;
|
||||
case 10:
|
||||
aMode = Aspect_TOR_RIGHT_AND_BOTTOM_BORDER;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
} // end switch
|
||||
|
||||
*((Standard_Integer*)&myXLeft) = myWidget->rect().left();
|
||||
*((Standard_Integer*)&myXRight) = myWidget->rect().right();
|
||||
*((Standard_Integer*)&myYTop) = myWidget->rect().top();
|
||||
*((Standard_Integer*)&myYBottom) = myWidget->rect().bottom();
|
||||
}
|
||||
|
||||
return aMode;
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Ratio
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
Standard_Real OcctWindow::Ratio() const
|
||||
{
|
||||
QRect aRect = myWidget->rect();
|
||||
return Standard_Real(aRect.right() - aRect.left()) / Standard_Real(aRect.bottom() - aRect.top());
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Size
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OcctWindow::Size(Standard_Integer& theWidth, Standard_Integer& theHeight) const
|
||||
{
|
||||
QRect aRect = myWidget->rect();
|
||||
theWidth = aRect.width();
|
||||
theHeight = aRect.height();
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : Position
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void OcctWindow::Position(Standard_Integer& theX1, Standard_Integer& theY1,
|
||||
Standard_Integer& theX2, Standard_Integer& theY2) const
|
||||
{
|
||||
theX1 = myWidget->rect().left();
|
||||
theX2 = myWidget->rect().right();
|
||||
theY1 = myWidget->rect().top();
|
||||
theY2 = myWidget->rect().bottom();
|
||||
}
|
111
samples/qt/OCCTOverview/src/OcctWindow.h
Normal file
111
samples/qt/OCCTOverview/src/OcctWindow.h
Normal file
@@ -0,0 +1,111 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#ifndef OcctWindow_H
|
||||
#define OcctWindow_H
|
||||
|
||||
#include <Aspect_Window.hxx>
|
||||
|
||||
#include <Standard_WarningsDisable.hxx>
|
||||
#include <QWidget>
|
||||
#include <Standard_WarningsRestore.hxx>
|
||||
|
||||
//! OcctWindow class implements Aspect_Window interface using Qt API
|
||||
//! as a platform-independent source of window geometry information.
|
||||
//! A similar class should be used instead of platform-specific OCCT
|
||||
//! classes (WNT_Window, Xw_Window) in any Qt 5 application using OCCT
|
||||
//! 3D visualization.
|
||||
//!
|
||||
//! With Qt 5, the requirement for a Qt-based application to rely fully
|
||||
//! on Qt public API and stop using platform-specific APIs looks mandatory.
|
||||
//! An example of this is changed QWidget event sequence: when a widget is
|
||||
//! first shown on the screen, a resize event is generated before the
|
||||
//! underlying native window is resized correctly, however the QWidget instance
|
||||
//! already holds correct size information at that moment. The OCCT classes
|
||||
//! acting as a source of window geometry for V3d_View class (WNT_Window, Xw_Window)
|
||||
//! are no longer compatible with changed Qt behavior because they rely on
|
||||
//! platform-specific API that cannot return correct window geometry information
|
||||
//! in some cases. A reasonable solution is to provide a Qt-based implementation
|
||||
//! of Aspect_Window interface at application level.
|
||||
class OcctWindow : public Aspect_Window
|
||||
{
|
||||
DEFINE_STANDARD_RTTIEXT(OcctWindow,Aspect_Window)
|
||||
public:
|
||||
|
||||
//! Constructor
|
||||
OcctWindow( QWidget* theWidget, const Quantity_NameOfColor theBackColor = Quantity_NOC_MATRAGRAY );
|
||||
|
||||
//! Destructor
|
||||
virtual ~OcctWindow()
|
||||
{
|
||||
myWidget = NULL;
|
||||
}
|
||||
|
||||
//! Returns native Window handle
|
||||
virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE
|
||||
{
|
||||
return (Aspect_Drawable)myWidget->winId();
|
||||
}
|
||||
|
||||
//! Returns parent of native Window handle.
|
||||
virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE;
|
||||
|
||||
//! Applies the resizing to the window <me>
|
||||
virtual Aspect_TypeOfResize DoResize() Standard_OVERRIDE;
|
||||
|
||||
//! Returns True if the window <me> is opened
|
||||
//! and False if the window is closed.
|
||||
virtual Standard_Boolean IsMapped() const Standard_OVERRIDE
|
||||
{
|
||||
return !(myWidget->isMinimized() || myWidget->isHidden());
|
||||
}
|
||||
|
||||
//! Apply the mapping change to the window <me>
|
||||
//! and returns TRUE if the window is mapped at screen.
|
||||
virtual Standard_Boolean DoMapping() const Standard_OVERRIDE { return Standard_True; }
|
||||
|
||||
//! Opens the window <me>.
|
||||
virtual void Map() const Standard_OVERRIDE;
|
||||
|
||||
//! Closes the window <me>.
|
||||
virtual void Unmap() const Standard_OVERRIDE;
|
||||
|
||||
virtual void Position( Standard_Integer& theX1, Standard_Integer& theY1,
|
||||
Standard_Integer& theX2, Standard_Integer& theY2 ) const Standard_OVERRIDE;
|
||||
|
||||
//! Returns The Window RATIO equal to the physical
|
||||
//! WIDTH/HEIGHT dimensions.
|
||||
virtual Standard_Real Ratio() const Standard_OVERRIDE;
|
||||
|
||||
virtual void Size( Standard_Integer& theWidth, Standard_Integer& theHeight ) const Standard_OVERRIDE;
|
||||
|
||||
virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE { return NULL; }
|
||||
|
||||
protected:
|
||||
Standard_Integer myXLeft;
|
||||
Standard_Integer myYTop;
|
||||
Standard_Integer myXRight;
|
||||
Standard_Integer myYBottom;
|
||||
QWidget* myWidget;
|
||||
};
|
||||
|
||||
|
||||
#endif // OcctWindow_H
|
113
samples/qt/OCCTOverview/src/TranslateDialog.cxx
Normal file
113
samples/qt/OCCTOverview/src/TranslateDialog.cxx
Normal file
@@ -0,0 +1,113 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#include "TranslateDialog.h"
|
||||
|
||||
#include <Standard_WarningsDisable.hxx>
|
||||
#include <QGridLayout>
|
||||
#include <Standard_WarningsRestore.hxx>
|
||||
|
||||
TranslateDialog::TranslateDialog(QWidget* parent, Qt::WindowFlags flags, bool modal)
|
||||
: QFileDialog(parent, flags)
|
||||
{
|
||||
setOption(QFileDialog::DontUseNativeDialog);
|
||||
setModal(modal);
|
||||
|
||||
QGridLayout* grid = ::qobject_cast<QGridLayout*>(layout());
|
||||
|
||||
if (grid)
|
||||
{
|
||||
QVBoxLayout *vbox = new QVBoxLayout;
|
||||
|
||||
QWidget* paramGroup = new QWidget(this);
|
||||
paramGroup->setLayout(vbox);
|
||||
|
||||
myBox = new QComboBox(paramGroup);
|
||||
vbox->addWidget(myBox);
|
||||
|
||||
int row = grid->rowCount();
|
||||
grid->addWidget(paramGroup, row, 1, 1, 3); // make combobox occupy 1 row and 3 columns starting from 1
|
||||
}
|
||||
}
|
||||
|
||||
TranslateDialog::~TranslateDialog()
|
||||
{
|
||||
}
|
||||
|
||||
int TranslateDialog::getMode() const
|
||||
{
|
||||
if (myBox->currentIndex() < 0 || myBox->currentIndex() > (int)myList.count() - 1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return myList.at(myBox->currentIndex());
|
||||
}
|
||||
}
|
||||
|
||||
void TranslateDialog::setMode(const int mode)
|
||||
{
|
||||
int idx = myList.indexOf(mode);
|
||||
if (idx >= 0)
|
||||
{
|
||||
myBox->setCurrentIndex(idx);
|
||||
}
|
||||
}
|
||||
|
||||
void TranslateDialog::addMode(const int mode, const QString& name)
|
||||
{
|
||||
myBox->show();
|
||||
myBox->addItem(name);
|
||||
myList.append(mode);
|
||||
myBox->updateGeometry();
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
void TranslateDialog::clear()
|
||||
{
|
||||
myList.clear();
|
||||
myBox->clear();
|
||||
myBox->hide();
|
||||
myBox->updateGeometry();
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
QListView* TranslateDialog::findListView(const QObjectList & childList)
|
||||
{
|
||||
QListView* listView = 0;
|
||||
for (int i = 0, n = childList.count(); i < n && !listView; i++)
|
||||
{
|
||||
listView = qobject_cast<QListView*>(childList.at(i));
|
||||
if (!listView && childList.at(i))
|
||||
{
|
||||
listView = findListView(childList.at(i)->children());
|
||||
}
|
||||
}
|
||||
return listView;
|
||||
}
|
||||
|
||||
void TranslateDialog::showEvent(QShowEvent* event)
|
||||
{
|
||||
QFileDialog::showEvent(event);
|
||||
QListView* aListView = findListView(children());
|
||||
aListView->setViewMode(QListView::ListMode);
|
||||
}
|
56
samples/qt/OCCTOverview/src/TranslateDialog.h
Normal file
56
samples/qt/OCCTOverview/src/TranslateDialog.h
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#ifndef TRANSLATEDIALOG_H
|
||||
#define TRANSLATEDIALOG_H
|
||||
|
||||
#include <Standard_WarningsDisable.hxx>
|
||||
#include <QComboBox>
|
||||
#include <QFileDialog>
|
||||
#include <QList>
|
||||
#include <QListView>
|
||||
#include <QShowEvent>
|
||||
#include <QWidget>
|
||||
#include <Standard_WarningsRestore.hxx>
|
||||
|
||||
//! Qt file dialog for save and restore sample files
|
||||
class TranslateDialog : public QFileDialog
|
||||
{
|
||||
public:
|
||||
TranslateDialog(QWidget* = 0, Qt::WindowFlags flags = 0, bool = true);
|
||||
~TranslateDialog();
|
||||
int getMode() const;
|
||||
void setMode(const int);
|
||||
void addMode(const int, const QString&);
|
||||
void clear();
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* event);
|
||||
|
||||
private:
|
||||
QListView* findListView(const QObjectList&);
|
||||
|
||||
private:
|
||||
QComboBox* myBox;
|
||||
QList<int> myList;
|
||||
};
|
||||
|
||||
#endif // TRANSLATEDIALOG_H
|
46
samples/qt/OCCTOverview/src/Transparency.cxx
Normal file
46
samples/qt/OCCTOverview/src/Transparency.cxx
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#include "Transparency.h"
|
||||
|
||||
#include <Standard_WarningsDisable.hxx>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <Standard_WarningsRestore.hxx>
|
||||
|
||||
DialogTransparency::DialogTransparency(QWidget* parent)
|
||||
: QDialog(parent, Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint)
|
||||
{
|
||||
setWindowTitle(tr("Transparency"));
|
||||
QHBoxLayout* base = new QHBoxLayout(this);
|
||||
|
||||
base->addWidget(new QLabel("0", this));
|
||||
|
||||
mySlider = new QSlider(Qt::Horizontal, this);
|
||||
mySlider->setRange(0, 10);
|
||||
mySlider->setTickPosition(QSlider::TicksBelow);
|
||||
mySlider->setTickInterval(1);
|
||||
mySlider->setPageStep(2);
|
||||
base->addWidget(mySlider);
|
||||
connect(mySlider, SIGNAL(valueChanged(int)), this, SIGNAL(sendTransparencyChanged(int)));
|
||||
|
||||
base->addWidget(new QLabel("10", this));
|
||||
}
|
55
samples/qt/OCCTOverview/src/Transparency.h
Normal file
55
samples/qt/OCCTOverview/src/Transparency.h
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#include <Standard_WarningsDisable.hxx>
|
||||
#include <QDialog>
|
||||
#include <QSlider>
|
||||
#include <QWidget>
|
||||
#include <Standard_WarningsRestore.hxx>
|
||||
|
||||
#include <AIS_InteractiveContext.hxx>
|
||||
|
||||
class QSlider;
|
||||
|
||||
//! Qt dialog with slider for change shapes transparency
|
||||
class DialogTransparency : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DialogTransparency ( QWidget * parent=0 );
|
||||
~DialogTransparency() { }
|
||||
|
||||
int value() const
|
||||
{
|
||||
return mySlider->value();
|
||||
}
|
||||
|
||||
void setValue(int theVal) const
|
||||
{
|
||||
mySlider->setValue(theVal);
|
||||
}
|
||||
|
||||
signals:
|
||||
void sendTransparencyChanged(int value);
|
||||
|
||||
private:
|
||||
QSlider* mySlider;
|
||||
};
|
676
samples/qt/OCCTOverview/src/View.cxx
Normal file
676
samples/qt/OCCTOverview/src/View.cxx
Normal file
@@ -0,0 +1,676 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#if !defined _WIN32
|
||||
#define QT_CLEAN_NAMESPACE /* avoid definition of INT32 and INT8 */
|
||||
#endif
|
||||
|
||||
#include "View.h"
|
||||
|
||||
#include "ApplicationCommon.h"
|
||||
#include "OcctWindow.h"
|
||||
#include "Transparency.h"
|
||||
|
||||
#include <Standard_WarningsDisable.hxx>
|
||||
#include <QApplication>
|
||||
#include <QBoxLayout>
|
||||
#include <QFileInfo>
|
||||
#include <QFileDialog>
|
||||
#include <QMouseEvent>
|
||||
#include <QMdiSubWindow>
|
||||
#include <QColorDialog>
|
||||
#include <QCursor>
|
||||
#include <QPainter>
|
||||
#include <QStyleFactory>
|
||||
#include <Standard_WarningsRestore.hxx>
|
||||
|
||||
#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && QT_VERSION < 0x050000
|
||||
#include <QX11Info>
|
||||
#endif
|
||||
|
||||
#include <Aspect_DisplayConnection.hxx>
|
||||
#include <Graphic3d_GraphicDriver.hxx>
|
||||
#include <Graphic3d_TextureEnv.hxx>
|
||||
|
||||
namespace
|
||||
{
|
||||
//! Map Qt buttons bitmask to virtual keys.
|
||||
static Aspect_VKeyMouse qtMouseButtons2VKeys(Qt::MouseButtons theButtons)
|
||||
{
|
||||
Aspect_VKeyMouse aButtons = Aspect_VKeyMouse_NONE;
|
||||
if ((theButtons & Qt::LeftButton) != 0)
|
||||
{
|
||||
aButtons |= Aspect_VKeyMouse_LeftButton;
|
||||
}
|
||||
if ((theButtons & Qt::MiddleButton) != 0)
|
||||
{
|
||||
aButtons |= Aspect_VKeyMouse_MiddleButton;
|
||||
}
|
||||
if ((theButtons & Qt::RightButton) != 0)
|
||||
{
|
||||
aButtons |= Aspect_VKeyMouse_RightButton;
|
||||
}
|
||||
return aButtons;
|
||||
}
|
||||
|
||||
//! Map Qt mouse modifiers bitmask to virtual keys.
|
||||
static Aspect_VKeyFlags qtMouseModifiers2VKeys(Qt::KeyboardModifiers theModifiers)
|
||||
{
|
||||
Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE;
|
||||
if ((theModifiers & Qt::ShiftModifier) != 0)
|
||||
{
|
||||
aFlags |= Aspect_VKeyFlags_SHIFT;
|
||||
}
|
||||
if ((theModifiers & Qt::ControlModifier) != 0)
|
||||
{
|
||||
aFlags |= Aspect_VKeyFlags_CTRL;
|
||||
}
|
||||
if ((theModifiers & Qt::AltModifier) != 0)
|
||||
{
|
||||
aFlags |= Aspect_VKeyFlags_ALT;
|
||||
}
|
||||
return aFlags;
|
||||
}
|
||||
|
||||
static QCursor* defCursor = NULL;
|
||||
static QCursor* handCursor = NULL;
|
||||
static QCursor* panCursor = NULL;
|
||||
static QCursor* globPanCursor = NULL;
|
||||
static QCursor* zoomCursor = NULL;
|
||||
static QCursor* rotCursor = NULL;
|
||||
|
||||
}
|
||||
|
||||
View::View (const Handle(AIS_InteractiveContext)& theContext, bool theIs3dView, QWidget* theParent)
|
||||
: QWidget(theParent),
|
||||
myIsRaytracing(false),
|
||||
myIsShadowsEnabled(true),
|
||||
myIsReflectionsEnabled(false),
|
||||
myIsAntialiasingEnabled(false),
|
||||
myIs3dView (theIs3dView),
|
||||
myBackMenu(NULL)
|
||||
{
|
||||
#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && QT_VERSION < 0x050000
|
||||
XSynchronize(x11Info().display(), true);
|
||||
#endif
|
||||
myContext = theContext;
|
||||
myCurZoom = 0;
|
||||
|
||||
setAttribute(Qt::WA_PaintOnScreen);
|
||||
setAttribute(Qt::WA_NoSystemBackground);
|
||||
|
||||
myDefaultGestures = myMouseGestureMap;
|
||||
myCurrentMode = CurrentAction3d::Nothing;
|
||||
setMouseTracking(true);
|
||||
|
||||
initViewActions();
|
||||
initCursors();
|
||||
|
||||
setBackgroundRole(QPalette::NoRole);//NoBackground );
|
||||
// set focus policy to threat QContextMenuEvent from keyboard
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
setAttribute(Qt::WA_PaintOnScreen);
|
||||
setAttribute(Qt::WA_NoSystemBackground);
|
||||
init();
|
||||
}
|
||||
|
||||
void View::init()
|
||||
{
|
||||
if (myV3dView.IsNull())
|
||||
{
|
||||
myV3dView = myContext->CurrentViewer()->CreateView();
|
||||
}
|
||||
|
||||
Handle(OcctWindow) hWnd = new OcctWindow(this);
|
||||
myV3dView->SetWindow(hWnd);
|
||||
if (!hWnd->IsMapped())
|
||||
{
|
||||
hWnd->Map();
|
||||
}
|
||||
|
||||
if (myIs3dView)
|
||||
{
|
||||
myV3dView->SetBackgroundColor(Quantity_Color(0.0, 0.0, 0.3, Quantity_TOC_RGB));
|
||||
}
|
||||
else
|
||||
{
|
||||
myV3dView->SetBackgroundColor(Quantity_Color(0.0, 0.2, 0.0, Quantity_TOC_RGB));
|
||||
myV3dView->SetProj(V3d_Zpos);
|
||||
}
|
||||
|
||||
myV3dView->MustBeResized();
|
||||
|
||||
if (myIsRaytracing)
|
||||
{
|
||||
myV3dView->ChangeRenderingParams().Method = Graphic3d_RM_RAYTRACING;
|
||||
}
|
||||
}
|
||||
|
||||
void View::paintEvent(QPaintEvent *)
|
||||
{
|
||||
myV3dView->InvalidateImmediate();
|
||||
FlushViewEvents(myContext, myV3dView, true);
|
||||
}
|
||||
|
||||
void View::resizeEvent(QResizeEvent *)
|
||||
{
|
||||
if (!myV3dView.IsNull())
|
||||
{
|
||||
myV3dView->MustBeResized();
|
||||
}
|
||||
}
|
||||
|
||||
void View::OnSelectionChanged(const Handle(AIS_InteractiveContext)& theCtx,
|
||||
const Handle(V3d_View)& theView)
|
||||
{
|
||||
Q_UNUSED(theCtx)
|
||||
Q_UNUSED(theView)
|
||||
}
|
||||
|
||||
void View::fitAll()
|
||||
{
|
||||
myV3dView->FitAll();
|
||||
myV3dView->ZFitAll();
|
||||
myV3dView->Redraw();
|
||||
}
|
||||
|
||||
void View::axo()
|
||||
{
|
||||
if (myIs3dView)
|
||||
{
|
||||
myV3dView->SetProj(V3d_XposYnegZpos);
|
||||
}
|
||||
}
|
||||
|
||||
void View::hlrOff()
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
myV3dView->SetComputedMode(Standard_False);
|
||||
myV3dView->Redraw();
|
||||
QAction* aShadingAction = getViewAction(ViewAction::Shading);
|
||||
aShadingAction->setEnabled(true);
|
||||
QAction* aWireframeAction = getViewAction(ViewAction::Wireframe);
|
||||
aWireframeAction->setEnabled(true);
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void View::hlrOn()
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
myV3dView->SetComputedMode(Standard_True);
|
||||
myV3dView->Redraw();
|
||||
QAction* aShadingAction = getViewAction(ViewAction::Shading);
|
||||
aShadingAction->setEnabled(false);
|
||||
QAction* aWireframeAction = getViewAction(ViewAction::Wireframe);
|
||||
aWireframeAction->setEnabled(false);
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
void View::shading()
|
||||
{
|
||||
myContext->SetDisplayMode(1, Standard_True);
|
||||
}
|
||||
|
||||
void View::wireframe()
|
||||
{
|
||||
myContext->SetDisplayMode(0, Standard_True);
|
||||
}
|
||||
|
||||
void View::SetRaytracedShadows(bool theState)
|
||||
{
|
||||
myV3dView->ChangeRenderingParams().IsShadowEnabled = theState;
|
||||
myIsShadowsEnabled = theState;
|
||||
myContext->UpdateCurrentViewer();
|
||||
}
|
||||
|
||||
void View::SetRaytracedReflections(bool theState)
|
||||
{
|
||||
myV3dView->ChangeRenderingParams().IsReflectionEnabled = theState;
|
||||
myIsReflectionsEnabled = theState;
|
||||
myContext->UpdateCurrentViewer();
|
||||
}
|
||||
|
||||
void View::onRaytraceAction()
|
||||
{
|
||||
QAction* aSentBy = (QAction*)sender();
|
||||
|
||||
if (aSentBy == myRaytraceActions.value(RaytraceAction::ToolRaytracing))
|
||||
{
|
||||
bool aState = myRaytraceActions.value(RaytraceAction::ToolRaytracing)->isChecked();
|
||||
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
if (aState)
|
||||
EnableRaytracing();
|
||||
else
|
||||
DisableRaytracing();
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
|
||||
if (aSentBy == myRaytraceActions.value(RaytraceAction::ToolShadows))
|
||||
{
|
||||
bool aState = myRaytraceActions.value(RaytraceAction::ToolShadows)->isChecked();
|
||||
SetRaytracedShadows(aState);
|
||||
}
|
||||
|
||||
if (aSentBy == myRaytraceActions.value(RaytraceAction::ToolReflections))
|
||||
{
|
||||
bool aState = myRaytraceActions.value(RaytraceAction::ToolReflections)->isChecked();
|
||||
SetRaytracedReflections(aState);
|
||||
}
|
||||
|
||||
if (aSentBy == myRaytraceActions.value(RaytraceAction::ToolAntialiasing))
|
||||
{
|
||||
bool aState = myRaytraceActions.value(RaytraceAction::ToolAntialiasing)->isChecked();
|
||||
SetRaytracedAntialiasing(aState);
|
||||
}
|
||||
}
|
||||
|
||||
void View::SetRaytracedAntialiasing(bool theState)
|
||||
{
|
||||
myV3dView->ChangeRenderingParams().IsAntialiasingEnabled = theState;
|
||||
myIsAntialiasingEnabled = theState;
|
||||
myContext->UpdateCurrentViewer();
|
||||
}
|
||||
|
||||
void View::EnableRaytracing()
|
||||
{
|
||||
if (!myIsRaytracing)
|
||||
{
|
||||
myV3dView->ChangeRenderingParams().Method = Graphic3d_RM_RAYTRACING;
|
||||
}
|
||||
myIsRaytracing = true;
|
||||
myContext->UpdateCurrentViewer();
|
||||
}
|
||||
|
||||
void View::DisableRaytracing()
|
||||
{
|
||||
if (myIsRaytracing)
|
||||
{
|
||||
myV3dView->ChangeRenderingParams().Method = Graphic3d_RM_RASTERIZATION;
|
||||
}
|
||||
myIsRaytracing = false;
|
||||
myContext->UpdateCurrentViewer();
|
||||
}
|
||||
|
||||
void View::updateToggled(bool isOn)
|
||||
{
|
||||
QAction* sentBy = (QAction*)sender();
|
||||
if (!isOn)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (QAction* anAction : myViewActions)
|
||||
{
|
||||
if (anAction && (anAction != sentBy))
|
||||
{
|
||||
anAction->setCheckable(true);
|
||||
anAction->setChecked(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sentBy == myViewActions.value(ViewAction::FitArea))
|
||||
setCursor(*handCursor);
|
||||
else if (sentBy == myViewActions.value(ViewAction::Zoom))
|
||||
setCursor(*zoomCursor);
|
||||
else if (sentBy == myViewActions.value(ViewAction::Pan))
|
||||
setCursor(*panCursor);
|
||||
else if (sentBy == myViewActions.value(ViewAction::GlobalPan))
|
||||
setCursor(*globPanCursor);
|
||||
else if (sentBy == myViewActions.value(ViewAction::Rotation))
|
||||
setCursor(*rotCursor);
|
||||
else
|
||||
setCursor(*defCursor);
|
||||
|
||||
sentBy->setCheckable(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void View::initCursors()
|
||||
{
|
||||
if (!defCursor)
|
||||
defCursor = new QCursor(Qt::ArrowCursor);
|
||||
if (!handCursor)
|
||||
handCursor = new QCursor(Qt::PointingHandCursor);
|
||||
if (!panCursor)
|
||||
panCursor = new QCursor(Qt::SizeAllCursor);
|
||||
if (!globPanCursor)
|
||||
globPanCursor = new QCursor(Qt::CrossCursor);
|
||||
if (!zoomCursor)
|
||||
zoomCursor = new QCursor(QPixmap(":/icons/cursor_zoom.png"));
|
||||
if (!rotCursor)
|
||||
rotCursor = new QCursor(QPixmap(":/icons/cursor_rotate.png"));
|
||||
}
|
||||
|
||||
QList<QAction*> View::getViewActions()
|
||||
{
|
||||
initViewActions();
|
||||
return myViewActions.values();
|
||||
}
|
||||
|
||||
QList<QAction*> View::getRaytraceActions()
|
||||
{
|
||||
initRaytraceActions();
|
||||
return myRaytraceActions.values();
|
||||
}
|
||||
|
||||
QAction* View::getViewAction(ViewAction theAction)
|
||||
{
|
||||
return myViewActions.value(theAction);
|
||||
}
|
||||
|
||||
QAction* View::getRaytraceAction(RaytraceAction theAction)
|
||||
{
|
||||
return myRaytraceActions.value(theAction);
|
||||
}
|
||||
|
||||
/*!
|
||||
Get paint engine for the OpenGL viewer. [ virtual public ]
|
||||
*/
|
||||
QPaintEngine* View::paintEngine() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
QAction* View::RegisterAction(QString theIconPath, QString thePromt, void (View::*theSlot)(void))
|
||||
{
|
||||
QAction* anAction = new QAction(QPixmap(theIconPath), thePromt, this);
|
||||
anAction->setToolTip(thePromt);
|
||||
anAction->setStatusTip(thePromt);
|
||||
connect(anAction, &QAction::triggered, this, theSlot);
|
||||
return anAction;
|
||||
}
|
||||
|
||||
void View::initViewActions()
|
||||
{
|
||||
if (!myViewActions.empty())
|
||||
return;
|
||||
myViewActions[ViewAction::FitAll] = RegisterAction(":/icons/view_fitall.png", tr("Fit all"), &View::fitAll);
|
||||
if (myIs3dView)
|
||||
{
|
||||
myViewActions[ViewAction::Axo] = RegisterAction(":/icons/view_axo.png", tr("Isometric"), &View::axo);
|
||||
|
||||
QActionGroup* aShadingActionGroup = new QActionGroup(this);
|
||||
QAction* aShadingAction = RegisterAction(":/icons/tool_shading.png", tr("Shading"), &View::shading);
|
||||
aShadingAction->setCheckable(true);
|
||||
aShadingActionGroup->addAction(aShadingAction);
|
||||
myViewActions[ViewAction::Shading] = aShadingAction;
|
||||
|
||||
QAction* aWireframeAction = RegisterAction(":/icons/tool_wireframe.png", tr("Wireframe"), &View::wireframe);
|
||||
aWireframeAction->setCheckable(true);
|
||||
aShadingActionGroup->addAction(aWireframeAction);
|
||||
myViewActions[ViewAction::Wireframe] = aWireframeAction;
|
||||
|
||||
QActionGroup* aHlrActionGroup = new QActionGroup(this);
|
||||
QAction* aHlrOffAction = RegisterAction(":/icons/view_comp_off.png", tr("HLR off"), &View::hlrOff);
|
||||
aHlrOffAction->setCheckable(true);
|
||||
aHlrActionGroup->addAction(aHlrOffAction);
|
||||
myViewActions[ViewAction::HlrOff] = aHlrOffAction;
|
||||
|
||||
QAction* aHlrOnAction = RegisterAction(":/icons/view_comp_on.png", tr("HLR on"), &View::hlrOn);
|
||||
aHlrOnAction->setCheckable(true);
|
||||
aHlrActionGroup->addAction(aHlrOnAction);
|
||||
myViewActions[ViewAction::HlrOn] = aHlrOnAction;
|
||||
|
||||
myViewActions[ViewAction::Transparency] = RegisterAction(":/icons/tool_transparency.png", tr("Transparency"), &View::onTransparency);
|
||||
}
|
||||
}
|
||||
|
||||
void View::initRaytraceActions()
|
||||
{
|
||||
if (!myRaytraceActions.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QAction* aRayTraceAction = RegisterAction(":/icons/raytracing.png", tr("Ray-tracing"), &View::onRaytraceAction);
|
||||
myRaytraceActions[RaytraceAction::ToolRaytracing] = aRayTraceAction;
|
||||
aRayTraceAction->setCheckable(true);
|
||||
aRayTraceAction->setChecked(false);
|
||||
|
||||
QAction* aShadowAction = RegisterAction(":/icons/shadows.png", tr("Shadows"), &View::onRaytraceAction);
|
||||
myRaytraceActions[RaytraceAction::ToolShadows] = aShadowAction;
|
||||
aShadowAction->setCheckable(true);
|
||||
aShadowAction->setChecked(true);
|
||||
|
||||
QAction* aReflectAction = RegisterAction(":/icons/reflections.png", tr("Reflections"), &View::onRaytraceAction);
|
||||
myRaytraceActions[RaytraceAction::ToolReflections] = aReflectAction;
|
||||
aReflectAction->setCheckable(true);
|
||||
aReflectAction->setChecked(false);
|
||||
|
||||
QAction* anAntiAliasingAction = RegisterAction(":/icons/antialiasing.png", tr("Anti-aliasing"), &View::onRaytraceAction);
|
||||
myRaytraceActions[RaytraceAction::ToolAntialiasing] = anAntiAliasingAction;
|
||||
anAntiAliasingAction->setCheckable(true);
|
||||
anAntiAliasingAction->setChecked(false);
|
||||
}
|
||||
|
||||
void View::activateCursor(const CurrentAction3d theMode)
|
||||
{
|
||||
QCursor* aCursor = defCursor;
|
||||
switch (theMode)
|
||||
{
|
||||
case CurrentAction3d::DynamicPanning: aCursor = panCursor; break;
|
||||
case CurrentAction3d::DynamicZooming: aCursor = zoomCursor; break;
|
||||
case CurrentAction3d::DynamicRotation: aCursor = rotCursor; break;
|
||||
case CurrentAction3d::GlobalPanning: aCursor = globPanCursor; break;
|
||||
case CurrentAction3d::WindowZooming: aCursor = handCursor; break;
|
||||
case CurrentAction3d::Nothing: aCursor = defCursor; break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
setCursor(*aCursor);
|
||||
}
|
||||
|
||||
void View::mousePressEvent(QMouseEvent* theEvent)
|
||||
{
|
||||
Qt::MouseButtons aMouseButtons = theEvent->buttons();
|
||||
if (!myIs3dView)
|
||||
{
|
||||
aMouseButtons.setFlag(Qt::LeftButton, false);
|
||||
}
|
||||
const Graphic3d_Vec2i aPnt(theEvent->pos().x(), theEvent->pos().y());
|
||||
const Aspect_VKeyFlags aFlags = qtMouseModifiers2VKeys(theEvent->modifiers());
|
||||
if (!myV3dView.IsNull()
|
||||
&& UpdateMouseButtons(aPnt, qtMouseButtons2VKeys(aMouseButtons), aFlags, false))
|
||||
{
|
||||
updateView();
|
||||
}
|
||||
myClickPos = aPnt;
|
||||
}
|
||||
|
||||
void View::mouseReleaseEvent(QMouseEvent* theEvent)
|
||||
{
|
||||
Qt::MouseButtons aMouseButtons = theEvent->buttons();
|
||||
if (!myIs3dView)
|
||||
{
|
||||
aMouseButtons.setFlag(Qt::LeftButton, false);
|
||||
}
|
||||
const Graphic3d_Vec2i aPnt(theEvent->pos().x(), theEvent->pos().y());
|
||||
const Aspect_VKeyFlags aFlags = qtMouseModifiers2VKeys(theEvent->modifiers());
|
||||
if (!myV3dView.IsNull()
|
||||
&& UpdateMouseButtons(aPnt, qtMouseButtons2VKeys(aMouseButtons), aFlags, false))
|
||||
{
|
||||
updateView();
|
||||
}
|
||||
|
||||
if (myCurrentMode == CurrentAction3d::GlobalPanning)
|
||||
{
|
||||
myV3dView->Place(aPnt.x(), aPnt.y(), myCurZoom);
|
||||
}
|
||||
if (myCurrentMode != CurrentAction3d::Nothing)
|
||||
{
|
||||
setCurrentAction(CurrentAction3d::Nothing);
|
||||
}
|
||||
}
|
||||
|
||||
void View::mouseMoveEvent(QMouseEvent* theEvent)
|
||||
{
|
||||
Qt::MouseButtons aMouseButtons = theEvent->buttons();
|
||||
if (!myIs3dView)
|
||||
{
|
||||
aMouseButtons.setFlag(Qt::LeftButton, false);
|
||||
}
|
||||
const Graphic3d_Vec2i aNewPos(theEvent->pos().x(), theEvent->pos().y());
|
||||
if (!myV3dView.IsNull()
|
||||
&& UpdateMousePosition(aNewPos, qtMouseButtons2VKeys(aMouseButtons), qtMouseModifiers2VKeys(theEvent->modifiers()), false))
|
||||
{
|
||||
updateView();
|
||||
}
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
//function : wheelEvent
|
||||
//purpose :
|
||||
//==============================================================================
|
||||
void View::wheelEvent(QWheelEvent* theEvent)
|
||||
{
|
||||
const Graphic3d_Vec2i aPos(theEvent->pos().x(), theEvent->pos().y());
|
||||
if (!myV3dView.IsNull()
|
||||
&& UpdateZoom(Aspect_ScrollDelta(aPos, theEvent->delta() / 8)))
|
||||
{
|
||||
updateView();
|
||||
}
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
// function : updateView
|
||||
// purpose :
|
||||
// =======================================================================
|
||||
void View::updateView()
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
void View::defineMouseGestures()
|
||||
{
|
||||
myMouseGestureMap.Clear();
|
||||
AIS_MouseGesture aRot = AIS_MouseGesture_RotateOrbit;
|
||||
activateCursor(myCurrentMode);
|
||||
switch (myCurrentMode)
|
||||
{
|
||||
case CurrentAction3d::Nothing:
|
||||
{
|
||||
myMouseGestureMap = myDefaultGestures;
|
||||
break;
|
||||
}
|
||||
case CurrentAction3d::DynamicZooming:
|
||||
{
|
||||
myMouseGestureMap.Bind(Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_Zoom);
|
||||
break;
|
||||
}
|
||||
case CurrentAction3d::GlobalPanning:
|
||||
{
|
||||
break;
|
||||
}
|
||||
case CurrentAction3d::WindowZooming:
|
||||
{
|
||||
myMouseGestureMap.Bind(Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_ZoomWindow);
|
||||
break;
|
||||
}
|
||||
case CurrentAction3d::DynamicPanning:
|
||||
{
|
||||
myMouseGestureMap.Bind(Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_Pan);
|
||||
break;
|
||||
}
|
||||
case CurrentAction3d::DynamicRotation:
|
||||
{
|
||||
myMouseGestureMap.Bind(Aspect_VKeyMouse_LeftButton, aRot);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void View::addItemInPopup(QMenu* theMenu)
|
||||
{
|
||||
Q_UNUSED(theMenu)
|
||||
}
|
||||
|
||||
void View::onBackground()
|
||||
{
|
||||
QColor aColor;
|
||||
Standard_Real R1;
|
||||
Standard_Real G1;
|
||||
Standard_Real B1;
|
||||
myV3dView->BackgroundColor(Quantity_TOC_RGB, R1, G1, B1);
|
||||
aColor.setRgb((Standard_Integer)(R1 * 255), (Standard_Integer)(G1 * 255), (Standard_Integer)(B1 * 255));
|
||||
|
||||
QColor aRetColor = QColorDialog::getColor(aColor);
|
||||
if (aRetColor.isValid())
|
||||
{
|
||||
R1 = aRetColor.red() / 255.;
|
||||
G1 = aRetColor.green() / 255.;
|
||||
B1 = aRetColor.blue() / 255.;
|
||||
myV3dView->SetBackgroundColor(Quantity_TOC_RGB, R1, G1, B1);
|
||||
}
|
||||
myV3dView->Redraw();
|
||||
}
|
||||
|
||||
void View::onEnvironmentMap()
|
||||
{
|
||||
if (myBackMenu->actions().at(1)->isChecked())
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "",
|
||||
tr("All Image Files (*.bmp *.gif *.jpg *.jpeg *.png *.tga)"));
|
||||
|
||||
const TCollection_AsciiString anUtf8Path(fileName.toUtf8().data());
|
||||
Handle(Graphic3d_TextureEnv) aTexture = new Graphic3d_TextureEnv(anUtf8Path);
|
||||
myV3dView->SetTextureEnv(aTexture);
|
||||
}
|
||||
else
|
||||
{
|
||||
myV3dView->SetTextureEnv(Handle(Graphic3d_TextureEnv)());
|
||||
}
|
||||
|
||||
myV3dView->Redraw();
|
||||
}
|
||||
|
||||
void View::onTransparency()
|
||||
{
|
||||
AIS_ListOfInteractive anAisObjectsList;
|
||||
myContext->DisplayedObjects(anAisObjectsList);
|
||||
if (anAisObjectsList.Extent() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
double aTranspValue = anAisObjectsList.First()->Transparency();
|
||||
DialogTransparency aDlg(this);
|
||||
aDlg.setValue(int(aTranspValue * 10));
|
||||
connect(&aDlg, SIGNAL(sendTransparencyChanged(int)), SLOT(onTransparencyChanged(int)));
|
||||
aDlg.exec();
|
||||
}
|
||||
|
||||
void View::onTransparencyChanged(int theVal)
|
||||
{
|
||||
AIS_ListOfInteractive anAisObjectsList;
|
||||
myContext->DisplayedObjects(anAisObjectsList);
|
||||
double aTranspValue = theVal / 10.;
|
||||
for (Handle(AIS_InteractiveObject) anAisObject : anAisObjectsList)
|
||||
{
|
||||
myContext->SetTransparency(anAisObject, aTranspValue, Standard_False);
|
||||
}
|
||||
myContext->UpdateCurrentViewer();
|
||||
}
|
169
samples/qt/OCCTOverview/src/View.h
Normal file
169
samples/qt/OCCTOverview/src/View.h
Normal file
@@ -0,0 +1,169 @@
|
||||
// Copyright (c) 2020 OPEN CASCADE SAS
|
||||
//
|
||||
// This file is part of the examples of the Open CASCADE Technology software library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||
|
||||
#ifndef VIEW_H
|
||||
#define VIEW_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <Standard_WarningsDisable.hxx>
|
||||
#include <QAction>
|
||||
#include <QList>
|
||||
#include <QMenu>
|
||||
#include <QToolBar>
|
||||
#include <QWidget>
|
||||
#include <Standard_WarningsRestore.hxx>
|
||||
|
||||
#include <AIS_InteractiveContext.hxx>
|
||||
#include <AIS_ViewController.hxx>
|
||||
#include <V3d_View.hxx>
|
||||
|
||||
class TopoDS_Shape;
|
||||
|
||||
enum CurrentAction3d { Nothing, DynamicZooming, WindowZooming,
|
||||
DynamicPanning, GlobalPanning, DynamicRotation, ObjectDececting };
|
||||
enum ViewAction { FitAll, FitArea, Zoom, Pan, GlobalPan, Front, Back, Top, Bottom,
|
||||
Left, Right, Axo, Rotation, Reset, HlrOff, HlrOn, Shading, Wireframe, Transparency };
|
||||
enum RaytraceAction { ToolRaytracing, ToolShadows, ToolReflections, ToolAntialiasing };
|
||||
|
||||
//! Qt widget containing V3d_View and toolbar with view manipulation buttons.
|
||||
//! Also use AIS_ViewController for redirecting user input (mouse, keyboard)
|
||||
//! into 3D viewer events (rotation, panning, zooming)
|
||||
class View: public QWidget, protected AIS_ViewController
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
View (const Handle(AIS_InteractiveContext)& theContext, bool theIs3dView, QWidget* theParent);
|
||||
|
||||
~View()
|
||||
{
|
||||
delete myBackMenu;
|
||||
}
|
||||
|
||||
virtual void init();
|
||||
QList<QAction*> getViewActions();
|
||||
QAction* getViewAction(ViewAction theAction);
|
||||
QList<QAction*> getRaytraceActions();
|
||||
QAction* getRaytraceAction(RaytraceAction theAction);
|
||||
|
||||
void EnableRaytracing();
|
||||
void DisableRaytracing();
|
||||
|
||||
void SetRaytracedShadows (bool theState);
|
||||
void SetRaytracedReflections (bool theState);
|
||||
void SetRaytracedAntialiasing (bool theState);
|
||||
|
||||
bool IsRaytracingMode() const { return myIsRaytracing; }
|
||||
bool IsShadowsEnabled() const { return myIsShadowsEnabled; }
|
||||
bool IsReflectionsEnabled() const { return myIsReflectionsEnabled; }
|
||||
bool IsAntialiasingEnabled() const { return myIsAntialiasingEnabled; }
|
||||
|
||||
static QString GetMessages(int type,TopAbs_ShapeEnum aSubShapeType, TopAbs_ShapeEnum aShapeType);
|
||||
static QString GetShapeType(TopAbs_ShapeEnum aShapeType);
|
||||
|
||||
Standard_EXPORT static void OnButtonuseraction(int ExerciceSTEP, Handle(AIS_InteractiveContext)& );
|
||||
Standard_EXPORT static void DoSelection(int Id, Handle(AIS_InteractiveContext)& );
|
||||
Standard_EXPORT static void OnSetSelectionMode(Handle(AIS_InteractiveContext)&,
|
||||
Standard_Integer&,
|
||||
TopAbs_ShapeEnum& SelectionMode,
|
||||
Standard_Boolean& );
|
||||
virtual QPaintEngine* paintEngine() const;
|
||||
const Handle(V3d_View)& getView() const { return myV3dView; }
|
||||
signals:
|
||||
void selectionChanged();
|
||||
|
||||
public slots:
|
||||
void fitAll();
|
||||
void axo();
|
||||
void hlrOn();
|
||||
void hlrOff();
|
||||
void shading();
|
||||
void wireframe();
|
||||
void onTransparency();
|
||||
|
||||
void updateToggled( bool );
|
||||
void onBackground();
|
||||
void onEnvironmentMap();
|
||||
void onRaytraceAction();
|
||||
|
||||
private slots:
|
||||
void onTransparencyChanged(int theVal);
|
||||
|
||||
protected:
|
||||
virtual void paintEvent( QPaintEvent* ) Standard_OVERRIDE;
|
||||
virtual void resizeEvent( QResizeEvent* ) Standard_OVERRIDE;
|
||||
virtual void mousePressEvent( QMouseEvent* ) Standard_OVERRIDE;
|
||||
virtual void mouseReleaseEvent(QMouseEvent* ) Standard_OVERRIDE;
|
||||
virtual void mouseMoveEvent( QMouseEvent* ) Standard_OVERRIDE;
|
||||
virtual void wheelEvent(QWheelEvent*) Standard_OVERRIDE;
|
||||
|
||||
virtual void addItemInPopup( QMenu* );
|
||||
|
||||
Handle(AIS_InteractiveContext)& getContext() { return myContext; }
|
||||
|
||||
void activateCursor( const CurrentAction3d );
|
||||
|
||||
CurrentAction3d getCurrentMode() const { return myCurrentMode; }
|
||||
|
||||
private:
|
||||
void initCursors();
|
||||
void initViewActions();
|
||||
void initRaytraceActions();
|
||||
|
||||
QAction* RegisterAction(QString theIconPath, QString thePromt, void (View::*theSlot)(void));
|
||||
|
||||
private:
|
||||
bool myIsRaytracing;
|
||||
bool myIsShadowsEnabled;
|
||||
bool myIsReflectionsEnabled;
|
||||
bool myIsAntialiasingEnabled;
|
||||
|
||||
bool myIs3dView;
|
||||
|
||||
Handle(V3d_View) myV3dView;
|
||||
Handle(AIS_InteractiveContext) myContext;
|
||||
AIS_MouseGestureMap myDefaultGestures;
|
||||
Graphic3d_Vec2i myClickPos;
|
||||
|
||||
void updateView();
|
||||
|
||||
//! Setup mouse gestures.
|
||||
void defineMouseGestures();
|
||||
|
||||
//! Set current action.
|
||||
void setCurrentAction (CurrentAction3d theAction)
|
||||
{
|
||||
myCurrentMode = theAction;
|
||||
defineMouseGestures();
|
||||
}
|
||||
|
||||
//! Handle selection changed event.
|
||||
void OnSelectionChanged(const Handle(AIS_InteractiveContext)& theCtx,
|
||||
const Handle(V3d_View)& theView) Standard_OVERRIDE;
|
||||
CurrentAction3d myCurrentMode;
|
||||
Standard_Real myCurZoom;
|
||||
QMap<ViewAction, QAction*> myViewActions;
|
||||
QMap<RaytraceAction, QAction*> myRaytraceActions;
|
||||
QMenu* myBackMenu;
|
||||
QToolBar* myViewBar;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user