LAMPCAE/src/MainWindow/MainWindow.cpp

1344 lines
42 KiB
C++
Raw Normal View History

2023-05-08 06:32:41 +00:00
/**
* @file mainWindow.cpp
* @brief
* @author FastCAE(fastcae@diso.cn)
* @version 2.5.0
* @date 2022-03-29 16:12
* @copyright Copyright (c) Since 2020 All rights reserved.
*
* ============================================================================
* Program: FastCAE
*
* Copyright (c) Since 2020 All rights reserved.
* See License or http://www.fastcae.com/ for details.
*
* BSD 3-Clause License
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED.
* ==================================================================================
*/
#include "MainWindow.h"
2023-05-09 11:00:22 +00:00
2023-05-08 06:32:41 +00:00
#include "ConfigOptions/ConfigOptions.h"
#include "ConfigOptions/GeometryConfig.h"
2023-05-09 11:00:22 +00:00
#include "ConfigOptions/GlobalConfig.h"
2023-05-08 06:32:41 +00:00
#include "ConfigOptions/MeshConfig.h"
#include "ConfigOptions/PostConfig.h"
#include "ConfigOptions/ProjectTreeConfig.h"
2023-05-09 11:00:22 +00:00
#include "CustomizerHelper.h"
#include "DialogAbout.h"
#include "Geometry/geometryData.h"
#include "GeometryWidgets/dialogSketchPlane.h"
#include "GmshModule/GmshModule.h"
#include "IO/IOConfig.h"
#include "MainWidgets/ControlPanel.h"
#include "MainWidgets/DialogCreateGeoComponent.h"
#include "MainWidgets/DialogCreateSet.h"
#include "MainWidgets/DialogFilterMesh.h"
#include "MainWidgets/DialogVTKTransform.h"
#include "MainWidgets/messageWindow.h"
#include "MainWidgets/preWindow.h"
#include "MainWidgets/ProcessWindow.h"
#include "MainWidgets/projectSolveDialog.h"
#include "MainWindowPy.h"
#include "MeshData/meshKernal.h"
#include "MeshData/meshSingleton.h"
2023-05-08 06:32:41 +00:00
#include "ModelData/modelDataBaseExtend.h"
#include "ModelData/modelDataSingleton.h"
2023-05-09 11:00:22 +00:00
#include "ModuleBase/ModuleBase.h"
#include "ModuleBase/ModuleType.h"
#include "ModuleBase/ThreadTaskManager.h"
2023-05-08 06:32:41 +00:00
#include "PluginManager/PluginManager.h"
#include "PythonModule/PyAgent.h"
#include "SARibbonMWUi.h"
2023-05-09 11:00:22 +00:00
#include "Settings/BusAPI.h"
#include "Settings/GraphOption.h"
#include "SignalHandler.h"
#include "SolverControl/DialogSolverManager.h"
#include "SubWindowManager.h"
#include "Translator.h"
#include <QApplication>
#include <QCloseEvent>
#include <QDebug>
#include <QDesktopServices>
#include <QFileDialog>
#include <QLabel>
#include <QList>
#include <QMdiSubWindow>
#include <QMessageBox>
#include <QSignalMapper>
#include <QTreeWidgetItem>
// ribbon
2023-05-08 06:32:41 +00:00
#include "SARibbonBar/SARibbonBar.h"
#include "SARibbonBar/SARibbonCategory.h"
#include "SARibbonBar/SARibbonContextCategory.h"
2023-05-09 11:00:22 +00:00
#include "SARibbonBar/SARibbonPannel.h"
2023-05-08 06:32:41 +00:00
#include "SARibbonBar/SARibbonTabBar.h"
// Post
2023-05-09 11:00:22 +00:00
#include "Common/Types.h"
2023-05-08 06:32:41 +00:00
#include "PostInterface/AnimationToolBar.h"
#include "PostInterface/RenderDirector.h"
//logger
#include "Common/DebugLogger.h"
2023-05-09 11:00:22 +00:00
namespace GUI {
MainWindow::MainWindow(bool useRibbon): SARibbonMainWindow(nullptr, useRibbon), _ui(new Ui::MainWindowRibbon)
2023-05-08 06:32:41 +00:00
{
2023-05-09 11:00:22 +00:00
if(useRibbon) {
2023-05-08 06:32:41 +00:00
_ui->setupRibbonUi(this);
// ribbon customize
// MainWindow的初始化生成QAction
2023-05-09 11:00:22 +00:00
// 生成ribbon布局
m_ribbonActionMgr = new SARibbonActionsManager(static_cast<SARibbonMainWindow*>(this));
2023-05-08 06:32:41 +00:00
m_ribbonActionMgr->setAllActionCanCustomize(true); // 设置所有管理的action可编辑
2023-05-09 11:00:22 +00:00
} else {
2023-05-08 06:32:41 +00:00
_ui->setupUi(this);
}
this->setContextMenuPolicy(Qt::NoContextMenu);
QString lang = Setting::BusAPI::instance()->getLanguage(); // 获取语言
2023-05-08 06:32:41 +00:00
registerMoudel(); // 控制面版 参数设置面板、 日志输出面板、 进程面版
2023-05-09 11:00:22 +00:00
_signalHandler = new SignalHandler(this);
_translator = new Translator();
2023-05-08 06:32:41 +00:00
_subWindowManager = new SubWindowManager(this, _ui->mdiArea, _signalHandler, _controlPanel);
setPostAnimationToolBar(useRibbon);
connectSignals();
// registerMoudel();
_ui->mdiArea->setViewMode(QMdiArea::TabbedView);
_ui->mdiArea->setTabPosition(QTabWidget::North);
_ui->mdiArea->setTabShape(QTabWidget::Rounded);
this->ChangeLanguage(lang);
QString workingdir = Setting::BusAPI::instance()->getWorkingDir();
2023-05-09 11:00:22 +00:00
if(workingdir.isEmpty())
2023-05-08 06:32:41 +00:00
setWorkingDir();
Setting::BusAPI::instance()->setMainWindow(this);
2023-05-09 11:00:22 +00:00
Setting::GraphOption* gp = Setting::BusAPI::instance()->getGraphOption();
2023-05-08 06:32:41 +00:00
_ui->actionDisplayPoint->setChecked(gp->isShowGeoPoint());
_ui->actionDisplayCurve->setChecked(gp->isShowGeoEdge());
_ui->actionDisplayFace->setChecked(gp->isShowGeoSurface());
this->setGeometryDisplay();
updateRecentMenu();
setCurrentFile("");
this->startSketch(false);
QString slogo = ConfigOption::ConfigOption::getInstance()->getGlobalConfig()->getLogo();
this->setIcon(QApplication::applicationDirPath() + "/../ConfigFiles/icon/" + slogo);
_signalHandler->updateActionsStates();
MainWindowPy::init(this, _signalHandler);
Gmsh::GmshModule::getInstance(this);
this->showGraphRange(0, 0);
Py::PythonAgent::getInstance()->initialize(this); // 初始界面参数设置
2023-05-08 06:32:41 +00:00
Plugins::PluginManager::getInstance()->loadPlugs(this);
_customizerHelper = new CustomizerHelper(this, _ui);
_customizerHelper->registerInterface();
_subWindowManager->openPreWindow(); // 前处理窗口展示
2023-05-08 06:32:41 +00:00
isLoadRecordScripFile();
// ribbon customize
// MainWindow的构造函数最后
2023-05-09 11:00:22 +00:00
if(useRibbon) {
const QString strCostomizePath =QApplication::applicationDirPath() + "/customization.xml";
2023-05-08 06:32:41 +00:00
sa_apply_customize_from_xml_file(strCostomizePath, this, m_ribbonActionMgr);
}
}
MainWindow::~MainWindow()
{
Py::PythonAgent::getInstance()->finalize();
Plugins::PluginManager::getInstance()->releasePlugs();
Gmsh::GmshModule::getInstance(this)->finalize();
ModuleBase::ThreadTaskManager::getInstance()->clearThreadTaskList();
2023-05-09 11:00:22 +00:00
if(_signalHandler != nullptr)
2023-05-08 06:32:41 +00:00
delete _signalHandler;
2023-05-09 11:00:22 +00:00
if(_controlPanel != nullptr)
2023-05-08 06:32:41 +00:00
delete _controlPanel;
2023-05-09 11:00:22 +00:00
if(_messageWindow != nullptr)
2023-05-08 06:32:41 +00:00
delete _messageWindow;
2023-05-09 11:00:22 +00:00
if(_processWindow != nullptr)
2023-05-08 06:32:41 +00:00
delete _processWindow;
2023-05-09 11:00:22 +00:00
if(_ui != nullptr)
2023-05-08 06:32:41 +00:00
delete _ui;
_ui = nullptr;
2023-05-09 11:00:22 +00:00
if(_translator != nullptr)
2023-05-08 06:32:41 +00:00
delete _translator;
2023-05-09 11:00:22 +00:00
if(_viewSignalMapper != nullptr)
2023-05-08 06:32:41 +00:00
delete _viewSignalMapper;
2023-05-09 11:00:22 +00:00
if(_selectSignalMapper != nullptr)
2023-05-08 06:32:41 +00:00
delete _selectSignalMapper;
// if (_displayModeSignalMapper != nullptr) delete _displayModeSignalMapper;
2023-05-09 11:00:22 +00:00
if(_recentFileMapper != nullptr)
2023-05-08 06:32:41 +00:00
delete _recentFileMapper;
2023-05-09 11:00:22 +00:00
if(_recentMenu != nullptr)
2023-05-08 06:32:41 +00:00
delete _recentMenu;
2023-05-09 11:00:22 +00:00
if(_graphRange != nullptr)
2023-05-08 06:32:41 +00:00
delete _graphRange;
2023-05-09 11:00:22 +00:00
if(_customizerHelper != nullptr)
2023-05-08 06:32:41 +00:00
delete _customizerHelper;
2023-05-09 11:00:22 +00:00
if(_postToolBar != nullptr)
2023-05-08 06:32:41 +00:00
delete _postToolBar;
// ribbon customize
2023-05-09 11:00:22 +00:00
if(m_ribbonActionMgr != nullptr) {
2023-05-08 06:32:41 +00:00
delete m_ribbonActionMgr;
}
}
void MainWindow::connectSignals()
{
connect(this, SIGNAL(closeMainWindow()), this, SLOT(closeWindow()));
connect(this, SIGNAL(sendInfoToStatesBar(QString)), this, SLOT(setStatusBarInfo(QString)));
2023-05-09 11:00:22 +00:00
// connect(this, SIGNAL(importMeshByNamesSig(QString)), this,
// SLOT(importMesh(QString)));
2023-05-09 11:00:22 +00:00
connect(this, SIGNAL(importMeshDataSetSig(vtkDataSet*)), this,
SLOT(importMeshDataset(vtkDataSet*)));
connect(this, SIGNAL(printMessageSig(Common::Message, QString)), this,
SLOT(printMessage(Common::Message, QString)));
2023-05-08 06:32:41 +00:00
connect(_ui->actionNew, SIGNAL(triggered()), this, SLOT(on_actionNew()));
connect(_ui->actionOpen, SIGNAL(triggered()), this, SLOT(on_actionOpen()));
connect(_ui->actionSave, SIGNAL(triggered()), this, SLOT(on_actionSave()));
connect(_ui->actionSaveAs, SIGNAL(triggered()), this, SLOT(on_actionSaveAs()));
connect(_ui->actionWorkingDir, SIGNAL(triggered()), this, SLOT(setWorkingDir()));
connect(_ui->actionImportMesh, SIGNAL(triggered()), this, SLOT(on_importMesh()));
connect(_ui->actionExportMesh, SIGNAL(triggered()), this, SLOT(on_exportMesh()));
connect(_ui->actionImportGeometry, SIGNAL(triggered()), this, SLOT(on_importGeometry()));
connect(_ui->actionExportGeometry, SIGNAL(triggered()), this, SLOT(on_exportGeometry()));
connect(_ui->actionClose, SIGNAL(triggered()), this, SLOT(closeWindow()));
connect(_ui->actionSolver_Manager, SIGNAL(triggered()), this, SLOT(on_solverManager()));
connect(_ui->actionSolve, SIGNAL(triggered()), this, SLOT(on_solve()));
connect(_ui->actionSolve_Options, SIGNAL(triggered()), this, SLOT(on_solveOption()));
connect(_ui->actionGraph_Options, SIGNAL(triggered()), this, SLOT(on_graphOption()));
connect(_ui->actionAbout, SIGNAL(triggered()), this, SLOT(on_about()));
connect(_ui->actionUser_Manual, SIGNAL(triggered()), this, SLOT(on_userManual()));
connect(_ui->actionCreate_Set, SIGNAL(triggered()), this, SLOT(on_CreateSet()));
2023-05-09 11:00:22 +00:00
connect(_ui->actionCreateGeoComponent, SIGNAL(triggered()), this,
SLOT(on_CreateGeoComponent()));
2023-05-08 06:32:41 +00:00
connect(_ui->actionSave_Script, SIGNAL(triggered()), this, SLOT(on_SaveScript()));
connect(_ui->actionExecute_Script, SIGNAL(triggered()), this, SLOT(on_ExecuateScript()));
2023-05-09 11:00:22 +00:00
connect(_ui->actionPluginManager, SIGNAL(triggered()),
Plugins::PluginManager::getInstance(), SLOT(manage()));
2023-05-08 06:32:41 +00:00
connect(_ui->actionFilterMesh, SIGNAL(triggered()), this, SLOT(on_FilterMesh()));
connect(_ui->actionVTKTranslation, SIGNAL(triggered()), this, SLOT(on_VTKTranslation()));
2023-05-09 11:00:22 +00:00
// 设置视角
2023-05-08 06:32:41 +00:00
_viewSignalMapper = new QSignalMapper(this);
connect(_ui->actionFitView, SIGNAL(triggered()), _viewSignalMapper, SLOT(map()));
connect(_ui->actionViewXPlus, SIGNAL(triggered()), _viewSignalMapper, SLOT(map()));
connect(_ui->actionViewXMinus, SIGNAL(triggered()), _viewSignalMapper, SLOT(map()));
connect(_ui->actionViewYPlus, SIGNAL(triggered()), _viewSignalMapper, SLOT(map()));
connect(_ui->actionViewYMinus, SIGNAL(triggered()), _viewSignalMapper, SLOT(map()));
connect(_ui->actionViewZPlus, SIGNAL(triggered()), _viewSignalMapper, SLOT(map()));
connect(_ui->actionViewZMinus, SIGNAL(triggered()), _viewSignalMapper, SLOT(map()));
_viewSignalMapper->setMapping(_ui->actionFitView, QString("fit"));
_viewSignalMapper->setMapping(_ui->actionViewXPlus, QString("XPlus"));
_viewSignalMapper->setMapping(_ui->actionViewXMinus, QString("XMinus"));
_viewSignalMapper->setMapping(_ui->actionViewYPlus, QString("YPlus"));
_viewSignalMapper->setMapping(_ui->actionViewYMinus, QString("YMinus"));
_viewSignalMapper->setMapping(_ui->actionViewZPlus, QString("ZPlus"));
_viewSignalMapper->setMapping(_ui->actionViewZMinus, QString("ZMinus"));
2023-05-09 11:00:22 +00:00
connect(_viewSignalMapper, SIGNAL(mapped(QString)), _subWindowManager,
SLOT(setView(QString)));
// 设置mesh选择模式
2023-05-08 06:32:41 +00:00
_selectSignalMapper = new QSignalMapper(this);
connect(_ui->actionSelectOff, SIGNAL(triggered()), _selectSignalMapper, SLOT(map()));
// connect(_ui->actionSelectGeoBody, SIGNAL(triggered()), _selectSignalMapper, SLOT(map()));
connect(_ui->actionSelectMeshNode, SIGNAL(triggered()), _selectSignalMapper, SLOT(map()));
connect(_ui->actionSelectMeshCell, SIGNAL(triggered()), _selectSignalMapper, SLOT(map()));
connect(_ui->actionBoxMeshNode, SIGNAL(triggered()), _selectSignalMapper, SLOT(map()));
connect(_ui->actionBoxMeshCell, SIGNAL(triggered()), _selectSignalMapper, SLOT(map()));
_selectSignalMapper->setMapping(_ui->actionSelectOff, (int)ModuleBase::SelectModel::None);
2023-05-09 11:00:22 +00:00
//_selectSignalMapper->setMapping(_ui->actionSelectGeoBody,
//(int)ModuleBase::SelectModel::GeometryBody);
_selectSignalMapper->setMapping(_ui->actionSelectMeshNode,
(int)ModuleBase::SelectModel::MeshNode);
_selectSignalMapper->setMapping(_ui->actionSelectMeshCell,
(int)ModuleBase::SelectModel::MeshCell);
_selectSignalMapper->setMapping(_ui->actionBoxMeshNode,
(int)ModuleBase::SelectModel::BoxMeshNode);
_selectSignalMapper->setMapping(_ui->actionBoxMeshCell,
(int)ModuleBase::SelectModel::BoxMeshCell);
2023-05-08 06:32:41 +00:00
connect(_selectSignalMapper, SIGNAL(mapped(int)), this, SIGNAL(selectModelChangedSig(int)));
connect(_selectSignalMapper, SIGNAL(mapped(int)), this, SLOT(selectModelChanged(int)));
2023-05-09 11:00:22 +00:00
// 网格显示模式
2023-05-08 06:32:41 +00:00
// _displayModeSignalMapper = new QSignalMapper(this);
connect(_ui->actionDisplayNode, SIGNAL(triggered()), this, SLOT(setMeshDisplay()));
connect(_ui->actionPreDisplayWireFrame, SIGNAL(triggered()), this, SLOT(setMeshDisplay()));
2023-05-08 06:32:41 +00:00
connect(_ui->actionDisplaySurface, SIGNAL(triggered()), this, SLOT(setMeshDisplay()));
2023-05-09 11:00:22 +00:00
// 几何显示模式(点、线、面)
2023-05-08 06:32:41 +00:00
connect(_ui->actionDisplayPoint, SIGNAL(triggered()), this, SLOT(setGeometryDisplay()));
connect(_ui->actionDisplayCurve, SIGNAL(triggered()), this, SLOT(setGeometryDisplay()));
connect(_ui->actionDisplayFace, SIGNAL(triggered()), this, SLOT(setGeometryDisplay()));
2023-05-09 11:00:22 +00:00
// 设置几何选取模式(点、线、面)
2023-05-08 06:32:41 +00:00
_selectGeometryModeMapper = new QSignalMapper(this);
connect(_ui->actionSelectOff, SIGNAL(triggered()), _selectGeometryModeMapper, SLOT(map()));
2023-05-09 11:00:22 +00:00
connect(_ui->actionSelectPoint, SIGNAL(triggered()), _selectGeometryModeMapper,
SLOT(map()));
connect(_ui->actionSelectCurve, SIGNAL(triggered()), _selectGeometryModeMapper,
SLOT(map()));
2023-05-08 06:32:41 +00:00
connect(_ui->actionSelectFace, SIGNAL(triggered()), _selectGeometryModeMapper, SLOT(map()));
2023-05-09 11:00:22 +00:00
connect(_ui->actionSelectGeometryBody, SIGNAL(triggered()), _selectGeometryModeMapper,
SLOT(map()));
_selectGeometryModeMapper->setMapping(_ui->actionSelectOff,
(int)ModuleBase::SelectModel::None);
_selectGeometryModeMapper->setMapping(_ui->actionSelectPoint,
(int)ModuleBase::SelectModel::GeometryWinPoint);
_selectGeometryModeMapper->setMapping(_ui->actionSelectCurve,
(int)ModuleBase::SelectModel::GeometryWinCurve);
_selectGeometryModeMapper->setMapping(_ui->actionSelectFace,
(int)ModuleBase::SelectModel::GeometryWinSurface);
_selectGeometryModeMapper->setMapping(_ui->actionSelectGeometryBody,
(int)ModuleBase::SelectModel::GeometryWinBody);
connect(_selectGeometryModeMapper, SIGNAL(mapped(int)), this,
SLOT(selectGeometryModelChanged(int)));
connect(_selectGeometryModeMapper, SIGNAL(mapped(int)), this,
SIGNAL(selectModelChangedSig(int)));
connect(_ui->actionPre_Window, SIGNAL(triggered()), _subWindowManager,
SLOT(openPreWindow()));
connect(this, SIGNAL(importGeometrySig(QStringList)), this,
SLOT(importGeometry(QStringList)));
2023-05-08 06:32:41 +00:00
connect(this, SIGNAL(exportGeometrySig(QString)), this, SLOT(exportGeometry(QString)));
connect(_ui->actionCreate_Sketch, SIGNAL(triggered()), this, SLOT(on_sketchClicked()));
2023-05-09 11:00:22 +00:00
connect(this, SIGNAL(showGraphRangeSig(double, double)), this,
SLOT(showGraphRange(double, double)));
connect(this, SIGNAL(startSketchSig(bool, double*, double*)), this,
SLOT(startSketch(bool)));
2023-05-08 06:32:41 +00:00
// connect(this, SIGNAL(updateActionsStatesSig()), this, SLOT(updateActionsStates()));
connect(this, SIGNAL(updatePreMeshActorSig()), this, SLOT(updatePreMeshActor()));
connect(this, SIGNAL(updatePreGeometryActorSig()), this, SLOT(updatePreGeometryActor()));
connect(this, SIGNAL(openPlot()), _signalHandler, SLOT(openPlotFile()));
2023-05-08 06:32:41 +00:00
}
void MainWindow::registerMoudel()
{
2023-05-09 11:00:22 +00:00
/// 添加ProjectWindow
2023-05-08 06:32:41 +00:00
_controlPanel = new MainWidget::ControlPanel(this);
_controlPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
addDockWidget(Qt::LeftDockWidgetArea, _controlPanel);
this->setCorner(Qt::Corner::BottomLeftCorner, Qt::LeftDockWidgetArea);
2023-05-09 11:00:22 +00:00
/// 添加MessageWindow
2023-05-08 06:32:41 +00:00
_messageWindow = new MainWidget::MessageWindow(this);
_messageWindow->setAllowedAreas(Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea);
addDockWidget(Qt::BottomDockWidgetArea, _messageWindow);
2023-05-09 11:00:22 +00:00
/// 添加ProcessWindow
2023-05-08 06:32:41 +00:00
_processWindow = new MainWidget::ProcessWindow(this);
_processWindow->setAllowedAreas(Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea);
addDockWidget(Qt::BottomDockWidgetArea, _processWindow);
}
2023-05-09 11:00:22 +00:00
Ui::MainWindowRibbon* MainWindow::getUi()
2023-05-08 06:32:41 +00:00
{
return _ui;
}
2023-05-09 11:00:22 +00:00
Translator* MainWindow::GetTranslator()
2023-05-08 06:32:41 +00:00
{
return _translator;
}
void MainWindow::setStatusBarInfo(QString info)
{
_ui->statusbar->showMessage(info, 10000);
}
2023-05-09 11:00:22 +00:00
void MainWindow::setMD5(const QString& md5)
2023-05-08 06:32:41 +00:00
{
_MD5 = md5;
}
2023-05-09 11:00:22 +00:00
void MainWindow::setCurrentFile(const QString& file)
2023-05-08 06:32:41 +00:00
{
2023-05-09 11:00:22 +00:00
if(!file.isEmpty()) {
2023-05-08 06:32:41 +00:00
QFileInfo F(file);
2023-05-09 11:00:22 +00:00
if(!F.exists())
2023-05-08 06:32:41 +00:00
return;
_currentFile = F.absoluteFilePath();
}
2023-05-09 11:00:22 +00:00
QString lang = Setting::BusAPI::instance()->getLanguage();
QString title;
ConfigOption::GlobalConfig* g = ConfigOption::ConfigOption::getInstance()->getGlobalConfig();
2023-05-08 06:32:41 +00:00
title = g->getSoftName();
2023-05-09 11:00:22 +00:00
if(lang.toLower() == "chinese")
2023-05-08 06:32:41 +00:00
title = g->getChineseName();
2023-05-09 11:00:22 +00:00
if(title.isEmpty())
title = u8"MicrowaveMeasurementSimulationSubSystemCAE";
2023-05-09 11:00:22 +00:00
if(!_currentFile.isEmpty())
2023-05-08 06:32:41 +00:00
title = QString("%1-[%2]").arg(title).arg(_currentFile);
this->setWindowTitle(title);
DebugInfo("setCurrentFile TitleName: %s\n", title.toStdU16String().c_str());
2023-05-08 06:32:41 +00:00
}
void MainWindow::updatePreMeshActor()
{
_subWindowManager->updatePreMeshActor();
}
void MainWindow::updatePreGeometryActor()
{
_subWindowManager->updatePreGeometryActor();
}
2023-05-09 11:00:22 +00:00
void MainWindow::closeEvent(QCloseEvent* event)
2023-05-08 06:32:41 +00:00
{
QString md5 = _signalHandler->getMD5();
2023-05-09 11:00:22 +00:00
if(md5 != _MD5) {
int nRet =
QMessageBox::warning(this, tr("Save"), tr("Do you want to save before exit ?"),
tr("Yes"), tr("No"), tr("Cancel"));
switch(nRet) {
case 2:
event->ignore();
return;
case 0:
this->on_actionSave();
case 1:
// clean data
default:
break;
2023-05-08 06:32:41 +00:00
}
2023-05-09 11:00:22 +00:00
if(nullptr != event)
2023-05-08 06:32:41 +00:00
event->accept();
}
// if (!_designModel)
_subWindowManager->closeAllSubWindow();
Setting::BusAPI::instance()->writeINI();
}
void MainWindow::closeWindow()
{
close();
}
void MainWindow::ChangeLanguage(QString lang)
{
Setting::BusAPI::instance()->setLanguage(lang);
2023-05-09 11:00:22 +00:00
if(nullptr == _ui)
2023-05-08 06:32:41 +00:00
return;
2023-05-09 11:00:22 +00:00
if(lang == "English") {
2023-05-08 06:32:41 +00:00
_ui->actionChinese->setChecked(false);
_ui->actionEnglish->setChecked(true);
_translator->toEnglish();
2023-05-09 11:00:22 +00:00
} else if(lang == "Chinese") {
2023-05-08 06:32:41 +00:00
_ui->actionChinese->setChecked(true);
_ui->actionEnglish->setChecked(false);
_translator->toChinese();
}
Plugins::PluginManager::getInstance()->reTranslate(lang);
2023-05-09 11:00:22 +00:00
if(isUseRibbon())
2023-05-08 06:32:41 +00:00
_ui->retranslateRibbonUi(this);
else
_ui->retranslateUi(this);
2023-05-09 11:00:22 +00:00
if(_recentMenu != nullptr)
2023-05-08 06:32:41 +00:00
_recentMenu->setTitle(tr("Recent"));
_controlPanel->reTranslate();
_messageWindow->reTranslate();
_subWindowManager->reTranslate();
2023-05-09 11:00:22 +00:00
if(_processWindow != nullptr)
2023-05-08 06:32:41 +00:00
_processWindow->reTranslate();
ConfigOption::GlobalConfig* g =ConfigOption::ConfigOption::getInstance()->getGlobalConfig();
QString title = "MicrowaveMeasurementSimulationSubSystemCAE"; // 修改 标识 FastCAE
2023-05-09 11:00:22 +00:00
if(lang.toLower() == "chinese") {
2023-05-08 06:32:41 +00:00
QString f = g->getChineseName();
2023-05-09 11:00:22 +00:00
if(!f.isEmpty())
2023-05-08 06:32:41 +00:00
title = f;
2023-05-09 11:00:22 +00:00
} else {
2023-05-08 06:32:41 +00:00
QString f = g->getSoftName();
2023-05-09 11:00:22 +00:00
if(!f.isEmpty())
2023-05-08 06:32:41 +00:00
title = f;
}
2023-05-09 11:00:22 +00:00
if(!_currentFile.isEmpty())
2023-05-08 06:32:41 +00:00
title = QString("%1-[%2]").arg(title).arg(_currentFile);
this->setWindowTitle(title);
}
void MainWindow::on_actionNew()
{
// if (!_designModel)
_signalHandler->on_actionNew();
// emit updateActionStatesSig();
}
void MainWindow::on_actionOpen()
{
/* emit sig_action_open();*/
QString md5 = _signalHandler->getMD5();
2023-05-09 11:00:22 +00:00
if(md5 != _MD5) {
2023-05-08 06:32:41 +00:00
QMessageBox::StandardButton but;
2023-05-09 11:00:22 +00:00
but =
QMessageBox::warning(this, tr("Warning"), tr("Do you want to save current data ?"),
QMessageBox::Yes | QMessageBox::No);
if(but == QMessageBox::Yes)
2023-05-08 06:32:41 +00:00
on_actionSave();
}
// _signalHandler->clearData();
2023-05-09 11:00:22 +00:00
QString dir = Setting::BusAPI::instance()->getWorkingDir();
2023-05-08 06:32:41 +00:00
QString fillter = tr("Project file(*.diso);;Project file(*.xml)");
#ifdef Q_OS_LINUX
fillter = tr("DISO file(*.diso);;XML file(*.xml)");
#endif
2023-05-09 11:00:22 +00:00
QString title = tr("Open a project");
2023-05-08 06:32:41 +00:00
QString filePath = QFileDialog::getOpenFileName(this, title, dir, fillter);
2023-05-09 11:00:22 +00:00
if(filePath.isEmpty())
2023-05-08 06:32:41 +00:00
return;
// _signalHandler->clearData();
// _signalHandler->openProjectFile(filePath);
QString pycode = QString("MainWindow.openProjectFile(\"%1\")").arg(filePath);
qDebug() << pycode;
Py::PythonAgent::getInstance()->submit(pycode);
}
void MainWindow::on_actionSave()
{
2023-05-09 11:00:22 +00:00
if(!_currentFile.isEmpty()) {
2023-05-08 06:32:41 +00:00
QString pycode = QString("MainWindow.saveProjectFile(\"%1\")").arg(_currentFile);
Py::PythonAgent::getInstance()->submit(pycode);
2023-05-09 11:00:22 +00:00
} else
2023-05-08 06:32:41 +00:00
on_actionSaveAs();
}
void MainWindow::on_actionSaveAs()
{
QString fillter = tr("Project file(*.diso);;Project file(*.xml)");
#ifdef Q_OS_LINUX
fillter = tr("DISO file(*.diso);;XML file(*.xml)");
#endif
2023-05-09 11:00:22 +00:00
QString title = tr("Save project");
QString dir = Setting::BusAPI::instance()->getWorkingDir();
2023-05-08 06:32:41 +00:00
// QString filePath = QFileDialog::getSaveFileName(this, title, dir, fillter);
QFileDialog dlg(this, title, dir, fillter);
dlg.setAcceptMode(QFileDialog::AcceptSave);
2023-05-09 11:00:22 +00:00
if(QDialog::Accepted != dlg.exec())
2023-05-08 06:32:41 +00:00
return;
QString filePath = dlg.selectedFiles().at(0);
2023-05-09 11:00:22 +00:00
if(filePath.isEmpty())
2023-05-08 06:32:41 +00:00
return;
#ifdef Q_OS_LINUX
bool isproj = filePath.toLower().endsWith(".diso") || filePath.toLower().endsWith(".xml");
2023-05-09 11:00:22 +00:00
if(!isproj) {
2023-05-08 06:32:41 +00:00
QString suffix = dlg.selectedNameFilter();
2023-05-09 11:00:22 +00:00
if(suffix.contains("diso"))
2023-05-08 06:32:41 +00:00
suffix = "diso";
2023-05-09 11:00:22 +00:00
else if(suffix.contains("xml"))
2023-05-08 06:32:41 +00:00
suffix = "xml";
filePath = filePath + "." + suffix;
}
#endif
bool empty = Geometry::GeometryData::getInstance()->isEmpty();
2023-05-09 11:00:22 +00:00
if(filePath.right(3).toLower() == "xml" && !empty) {
QMessageBox::StandardButton bt = QMessageBox::warning(
this, tr("Warning"), tr("Geometry will be lost! still continue?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if(bt == QMessageBox::No)
2023-05-08 06:32:41 +00:00
return;
}
2023-05-09 11:00:22 +00:00
if(!filePath.isEmpty()) {
2023-05-08 06:32:41 +00:00
QString pycode = QString("MainWindow.saveProjectFile(\"%1\")").arg(filePath);
Py::PythonAgent::getInstance()->submit(pycode);
}
}
void MainWindow::on_importMesh()
{
QStringList suffixlist = IO::IOConfigure::getMeshImporters();
// QStringList list = IO::IOConfigure::getMeshImporters();
2023-05-09 11:00:22 +00:00
if(suffixlist.isEmpty()) {
2023-05-08 06:32:41 +00:00
QMessageBox::warning(this, tr("Warning"), tr("The MeshPlugin is not installed !"));
return;
}
2023-05-09 11:00:22 +00:00
QStringList meshsuffix =
ConfigOption::ConfigOption::getInstance()->getMeshConfig()->getImportSuffix().split(
";");
2023-05-08 06:32:41 +00:00
QStringList list;
2023-05-09 11:00:22 +00:00
for(QString s : meshsuffix) {
for(int i = 0; i < suffixlist.size(); i++) {
2023-05-08 06:32:41 +00:00
QString suffix = suffixlist.at(i);
2023-05-09 11:00:22 +00:00
if(suffix.contains(s))
2023-05-08 06:32:41 +00:00
list.append(suffix);
}
}
std::sort(list.begin(), list.end());
2023-05-09 11:00:22 +00:00
QString suffixes = list.join(";;");
2023-05-08 06:32:41 +00:00
QString senderName = sender()->objectName();
2023-05-09 11:00:22 +00:00
int modelID = -1;
if(senderName.contains("Only INP_")) {
2023-05-08 06:32:41 +00:00
suffixes = list.at(0);
2023-05-09 11:00:22 +00:00
modelID = senderName.right(1).toInt();
2023-05-08 06:32:41 +00:00
}
2023-05-09 11:00:22 +00:00
QString workDir = Setting::BusAPI::instance()->getWorkingDir();
2023-05-08 06:32:41 +00:00
QFileDialog dlg(this, tr("Import Mesh"), workDir, suffixes);
dlg.setAcceptMode(QFileDialog::AcceptOpen);
dlg.setFileMode(QFileDialog::ExistingFile);
2023-05-09 11:00:22 +00:00
if(dlg.exec() != QFileDialog::Accepted)
2023-05-08 06:32:41 +00:00
return;
2023-05-09 11:00:22 +00:00
QString aSuffix = dlg.selectedNameFilter();
2023-05-08 06:32:41 +00:00
QString fileName = dlg.selectedFiles().join(",");
2023-05-09 11:00:22 +00:00
if(fileName.isEmpty())
2023-05-08 06:32:41 +00:00
return;
2023-05-09 11:00:22 +00:00
QString pyCode = QString("MainWindow.importMesh(\"%1\",\"%2\",%3)")
.arg(fileName)
.arg(aSuffix)
.arg(modelID);
2023-05-08 06:32:41 +00:00
Py::PythonAgent::getInstance()->submit(pyCode);
}
void MainWindow::on_exportGeometry()
{
2023-05-09 11:00:22 +00:00
QString dir = Setting::BusAPI::instance()->getWorkingDir();
2023-05-08 06:32:41 +00:00
2023-05-09 11:00:22 +00:00
ConfigOption::GeometryConfig* geoconfig =
ConfigOption::ConfigOption::getInstance()->getGeometryConfig();
QString conSuffix = geoconfig->getExportSuffix().toLower();
QStringList sl = conSuffix.split(";");
2023-05-08 06:32:41 +00:00
conSuffix.clear();
2023-05-09 11:00:22 +00:00
for(QString s : sl) {
2023-05-08 06:32:41 +00:00
conSuffix += " *." + s;
}
conSuffix = QString("Geometry Files(%1)").arg(conSuffix);
QString regSuffix{};
2023-05-09 11:00:22 +00:00
QString title = tr("Export Geometry");
QString filename = QFileDialog::getSaveFileName(
this, title, dir, conSuffix + regSuffix /* + ";;All Files(*.*)"*/);
if(filename.isEmpty())
2023-05-08 06:32:41 +00:00
return;
QString pycode = QString("MainWindow.exportGeometry(\"%1\")").arg(filename);
Py::PythonAgent::getInstance()->submit(pycode);
}
void MainWindow::on_exportMesh()
{
QStringList suffixlist = IO::IOConfigure::getMeshExporters();
// QStringList list = IO::IOConfigure::getMeshImporters();
2023-05-09 11:00:22 +00:00
if(suffixlist.isEmpty()) {
2023-05-08 06:32:41 +00:00
QMessageBox::warning(this, tr("Warning"), tr("The MeshPlugin is not installed !"));
return;
}
2023-05-09 11:00:22 +00:00
if(MeshData::MeshData::getInstance()->getKernalCount() == 0) {
2023-05-08 06:32:41 +00:00
QMessageBox::warning(this, tr("Warning"), tr("No one has any grid!"));
return;
}
2023-05-09 11:00:22 +00:00
QStringList meshsuffix =
ConfigOption::ConfigOption::getInstance()->getMeshConfig()->getExportSuffix().split(
";");
2023-05-08 06:32:41 +00:00
QStringList list;
2023-05-09 11:00:22 +00:00
for(QString s : meshsuffix) {
for(int i = 0; i < suffixlist.size(); i++) {
2023-05-08 06:32:41 +00:00
QString suffix = suffixlist.at(i);
2023-05-09 11:00:22 +00:00
if(suffix.contains(s))
2023-05-08 06:32:41 +00:00
list.append(suffix);
}
}
std::sort(list.begin(), list.end());
2023-05-09 11:00:22 +00:00
QString suffixes = list.join(";;");
2023-05-08 06:32:41 +00:00
QString senderName = sender()->objectName();
2023-05-09 11:00:22 +00:00
int modelID = -1;
if(senderName.contains("Only INP_")) {
2023-05-08 06:32:41 +00:00
suffixes = list.at(0);
2023-05-09 11:00:22 +00:00
modelID = senderName.right(1).toInt();
2023-05-08 06:32:41 +00:00
}
2023-05-09 11:00:22 +00:00
QString workDir = Setting::BusAPI::instance()->getWorkingDir();
2023-05-08 06:32:41 +00:00
QFileDialog dlg(this, tr("Export Mesh"), workDir, suffixes);
dlg.setAcceptMode(QFileDialog::AcceptSave);
2023-05-09 11:00:22 +00:00
if(dlg.exec() != QFileDialog::FileName)
2023-05-08 06:32:41 +00:00
return;
2023-05-09 11:00:22 +00:00
QString aSuffix = dlg.selectedNameFilter();
2023-05-08 06:32:41 +00:00
QString aFileName = dlg.selectedFiles().join(",");
2023-05-09 11:00:22 +00:00
if(aFileName.isEmpty())
2023-05-08 06:32:41 +00:00
return;
2023-05-09 11:00:22 +00:00
QString pyCode = QString("MainWindow.exportMesh(\"%1\",\"%2\",%3)")
.arg(aFileName)
.arg(aSuffix)
.arg(modelID);
2023-05-08 06:32:41 +00:00
Py::PythonAgent::getInstance()->submit(pyCode);
}
// void MainWindow::importMesh(QString fileName ,QString suffix, int modelId)
// {
// _signalHandler->importMesh(fileName, suffix, modelId);
// }
2023-05-09 11:00:22 +00:00
void MainWindow::importMeshDataset(vtkDataSet* dataset)
2023-05-08 06:32:41 +00:00
{
2023-05-09 11:00:22 +00:00
if(dataset == nullptr)
2023-05-08 06:32:41 +00:00
return;
2023-05-09 11:00:22 +00:00
MeshData::MeshKernal* k = new MeshData::MeshKernal;
2023-05-08 06:32:41 +00:00
k->setMeshData(dataset);
MeshData::MeshData::getInstance()->appendMeshKernal(k);
_subWindowManager->openPreWindow();
// _subWindowManager->updatePreMeshActor();
emit updateMeshTreeSig();
emit updateActionStatesSig();
}
void MainWindow::on_importGeometry()
{
2023-05-09 11:00:22 +00:00
QString dir = Setting::BusAPI::instance()->getWorkingDir();
ConfigOption::GeometryConfig* geoconfig =
ConfigOption::ConfigOption::getInstance()->getGeometryConfig();
QString conSuffix = geoconfig->getImportSuffix().toLower();
QStringList sl = conSuffix.split(";");
2023-05-08 06:32:41 +00:00
conSuffix.clear();
2023-05-09 11:00:22 +00:00
for(QString s : sl) {
2023-05-08 06:32:41 +00:00
conSuffix += " *." + s;
}
conSuffix = QString("Geometry Files(%1)").arg(conSuffix);
2023-05-09 11:00:22 +00:00
QString regSuffix{};
2023-05-08 06:32:41 +00:00
2023-05-09 11:00:22 +00:00
QString title = tr("Import Geometry");
QStringList filenames = QFileDialog::getOpenFileNames(
this, title, dir, conSuffix + regSuffix /*+ ";;All Files(*.*)"*/);
if(filenames.isEmpty())
2023-05-08 06:32:41 +00:00
return;
/*
QString files = filenames.join(",");
2023-05-09 11:00:22 +00:00
QString pycode =
QString("MainWindow.importGeometry(\"%1\")").arg(files);
2023-05-08 06:32:41 +00:00
*/
QStringList pyCodes;
2023-05-09 11:00:22 +00:00
for(int i = 0; i < filenames.size(); i++) {
2023-05-08 06:32:41 +00:00
pyCodes.append(QString("MainWindow.importGeometry(\"%1\")").arg(filenames[i]));
}
Py::PythonAgent::getInstance()->submit(pyCodes);
}
void MainWindow::importGeometry(QStringList filenames)
{
_subWindowManager->openPreWindow();
2023-05-09 11:00:22 +00:00
if(!_signalHandler->importGeometry(filenames))
2023-05-08 06:32:41 +00:00
return;
}
void MainWindow::exportGeometry(QString f)
{
2023-05-09 11:00:22 +00:00
if(!_signalHandler->exportGeometry(f))
2023-05-08 06:32:41 +00:00
return;
Py::PythonAgent::getInstance()->unLock();
}
void MainWindow::on_solidMesh()
{
_signalHandler->generateSolidMesh();
}
void MainWindow::on_surfaceMesh()
{
_signalHandler->generateSurfaceMesh();
}
2023-05-09 11:00:22 +00:00
void MainWindow::on_genMesh() {}
2023-05-08 06:32:41 +00:00
void MainWindow::setWorkingDir()
{
Setting::BusAPI::instance()->setWorkingDir();
}
void MainWindow::on_solverManager()
{
SolverControl::SolverManagerDialog dlg(this);
dlg.exec();
}
void MainWindow::on_solve()
{
2023-05-09 11:00:22 +00:00
bool showDlg = true;
2023-05-08 06:32:41 +00:00
MainWidget::ProjcctSolveDialog dlg(this, showDlg);
2023-05-09 11:00:22 +00:00
if(showDlg)
2023-05-08 06:32:41 +00:00
dlg.exec();
}
void MainWindow::solveProject(int id)
{
2023-05-09 11:00:22 +00:00
bool showDlg = true;
2023-05-08 06:32:41 +00:00
MainWidget::ProjcctSolveDialog dlg(this, showDlg, id);
2023-05-09 11:00:22 +00:00
if(showDlg)
2023-05-08 06:32:41 +00:00
dlg.exec();
}
void MainWindow::on_solveOption()
{
// Setting::BusAPI::instance()->setSolverOptions();
}
void MainWindow::on_graphOption()
{
Setting::BusAPI::instance()->setGraphOptions();
}
void MainWindow::selectModelChanged(int model)
{
_ui->actionSelectOff->setChecked(false);
//_ui->actionSelectGeoBody->setChecked(false);
_ui->actionSelectMeshNode->setChecked(false);
_ui->actionSelectMeshCell->setChecked(false);
_ui->actionBoxMeshNode->setChecked(false);
_ui->actionBoxMeshCell->setChecked(false);
2023-05-09 11:00:22 +00:00
switch(model) {
case(int)ModuleBase::SelectModel::None:
_ui->actionSelectOff->setChecked(true);
break;
case(int)ModuleBase::SelectModel::MeshNode:
_ui->actionSelectMeshNode->setChecked(true);
break;
case(int)ModuleBase::SelectModel::MeshCell:
_ui->actionSelectMeshCell->setChecked(true);
break;
case(int)ModuleBase::SelectModel::BoxMeshNode:
_ui->actionBoxMeshNode->setChecked(true);
break;
case(int)ModuleBase::SelectModel::BoxMeshCell:
_ui->actionBoxMeshCell->setChecked(true);
break;
default:
break;
2023-05-08 06:32:41 +00:00
}
}
2023-05-09 11:00:22 +00:00
SubWindowManager* MainWindow::getSubWindowManager()
2023-05-08 06:32:41 +00:00
{
return _subWindowManager;
}
void MainWindow::on_about()
{
AboutDialog dlg;
dlg.exec();
}
void MainWindow::on_userManual()
{
2023-05-09 11:00:22 +00:00
QString file =
ConfigOption::ConfigOption::getInstance()->getGlobalConfig()->GetUserManual();
2023-05-08 06:32:41 +00:00
QString userManulFile = QApplication::applicationDirPath() + "/../Doc/" + file;
2023-05-09 11:00:22 +00:00
if(file.isEmpty()) {
2023-05-08 06:32:41 +00:00
QDesktopServices::openUrl(QUrl("http://www.fastcae.com/index.php?mod=document"));
return;
}
QFile f(userManulFile);
2023-05-09 11:00:22 +00:00
if(!f.exists()) {
2023-05-08 06:32:41 +00:00
ModuleBase::Message msg;
2023-05-09 11:00:22 +00:00
msg.type = Common::Message::Warning;
2023-05-08 06:32:41 +00:00
msg.message = tr("Please make sure \" %1 \" file exist!").arg(userManulFile);
emit printMessageToMessageWindow(msg);
2023-05-09 11:00:22 +00:00
} else {
if(!QDesktopServices::openUrl(QUrl::fromLocalFile(userManulFile))) {
2023-05-08 06:32:41 +00:00
QString mess = QString(tr("%1 not exist !")).arg(file);
QMessageBox::warning(this, QString(tr("Warning")), mess);
}
}
}
void MainWindow::setMeshDisplay()
{
bool showNode = _ui->actionDisplayNode->isChecked();
bool showEdge = _ui->actionPreDisplayWireFrame->isChecked();
2023-05-08 06:32:41 +00:00
bool showFace = _ui->actionDisplaySurface->isChecked();
2023-05-09 11:00:22 +00:00
auto gp = Setting::BusAPI::instance()->getGraphOption();
2023-05-08 06:32:41 +00:00
gp->isShowMeshNode(showNode);
gp->isShowMeshEdge(showEdge);
gp->isShowMeshFace(showFace);
emit this->meshDisplayModeChangedSig();
}
void MainWindow::selectGeometryModelChanged(int m)
{
// bool active{true};
_ui->actionSelectOff->setChecked(false);
_ui->actionSelectPoint->setChecked(false);
_ui->actionSelectCurve->setChecked(false);
_ui->actionSelectFace->setChecked(false);
_ui->actionSelectGeometryBody->setChecked(false);
2023-05-09 11:00:22 +00:00
switch(m) {
case(int)ModuleBase::SelectModel::None:
_ui->actionSelectOff->setChecked(true);
break;
case(int)ModuleBase::SelectModel::GeometryPoint:
case(int)ModuleBase::SelectModel::GeometryWinPoint:
_ui->actionSelectPoint->setChecked(true);
break;
case(int)ModuleBase::SelectModel::GeometryCurve:
case(int)ModuleBase::SelectModel::GeometryWinCurve:
_ui->actionSelectCurve->setChecked(true);
break;
case(int)ModuleBase::SelectModel::GeometrySurface:
case(int)ModuleBase::SelectModel::GeometryWinSurface:
_ui->actionSelectFace->setChecked(true);
break;
case(int)ModuleBase::SelectModel::GeometryBody:
case(int)ModuleBase::SelectModel::GeometryWinBody:
_ui->actionSelectGeometryBody->setChecked(true);
break;
;
default:
break;
2023-05-08 06:32:41 +00:00
}
// emit selectGeoActiveSig(active);
}
void MainWindow::setGeometryDisplay()
{
2023-05-09 11:00:22 +00:00
bool checkvertex = _ui->actionDisplayPoint->isChecked();
bool checkcurve = _ui->actionDisplayCurve->isChecked();
bool checkface = _ui->actionDisplayFace->isChecked();
2023-05-08 06:32:41 +00:00
2023-05-09 11:00:22 +00:00
Setting::GraphOption* gp = Setting::BusAPI::instance()->getGraphOption();
2023-05-08 06:32:41 +00:00
gp->isShowGeoPoint(checkvertex);
gp->isShowGeoEdge(checkcurve);
gp->isShowGeoSurface(checkface);
emit selectGeometryDisplay(checkvertex, checkcurve, checkface);
}
void MainWindow::updateRecentMenu()
{
2023-05-09 11:00:22 +00:00
if(_recentMenu == nullptr) {
2023-05-08 06:32:41 +00:00
_recentMenu = new QMenu(tr("Recent"));
_ui->menuFile->addMenu(_recentMenu);
}
_recentMenu->clear();
2023-05-09 11:00:22 +00:00
if(_recentFileMapper == nullptr) {
2023-05-08 06:32:41 +00:00
_recentFileMapper = new QSignalMapper;
}
_recentFileMapper->disconnect();
QStringList rencentFile = Setting::BusAPI::instance()->getRencetFiles();
2023-05-09 11:00:22 +00:00
for(int i = 0; i < rencentFile.size(); ++i) {
QString f = rencentFile.at(i);
QAction* action = _recentMenu->addAction(f);
2023-05-08 06:32:41 +00:00
action->setStatusTip(f);
connect(action, SIGNAL(triggered()), _recentFileMapper, SLOT(map()));
_recentFileMapper->setMapping(action, f);
}
connect(_recentFileMapper, SIGNAL(mapped(QString)), this, SLOT(openRencentFile(QString)));
}
void MainWindow::setActionVisible(QString objname, bool enable)
{
2023-05-09 11:00:22 +00:00
QList<QAction*> acs = this->findChildren<QAction*>();
for(QAction* a : acs) {
if(a->objectName().toLower() == objname.toLower()) {
2023-05-08 06:32:41 +00:00
a->setVisible(enable);
break;
}
}
}
void MainWindow::openRencentFile(QString file)
{
QFileInfo info(file);
2023-05-09 11:00:22 +00:00
if(!info.exists()) {
2023-05-08 06:32:41 +00:00
QMessageBox::warning(this, tr("Warning"), tr("File \"%1\" is not exist !"));
return;
}
QString md5 = _signalHandler->getMD5();
2023-05-09 11:00:22 +00:00
if(md5 != _MD5) {
2023-05-08 06:32:41 +00:00
QMessageBox::StandardButton but;
2023-05-09 11:00:22 +00:00
but =
QMessageBox::warning(this, tr("Warning"), tr("Do you want to save current data ?"),
QMessageBox::Yes | QMessageBox::No);
if(but == QMessageBox::Yes)
2023-05-08 06:32:41 +00:00
on_actionSave();
}
_signalHandler->clearData(false);
QString dir = Setting::BusAPI::instance()->getWorkingDir();
2023-05-09 11:00:22 +00:00
bool ok = _signalHandler->openProjectFile(file);
if(!ok)
2023-05-08 06:32:41 +00:00
return;
_subWindowManager->openPreWindow();
_subWindowManager->updatePreActors();
setCurrentFile(file);
updateRecentMenu();
emit updateActionStatesSig();
}
2023-05-09 11:00:22 +00:00
void MainWindow::keyPressEvent(QKeyEvent* e)
2023-05-08 06:32:41 +00:00
{
Q_UNUSED(e)
2023-05-09 11:00:22 +00:00
qDebug() << "press";
2023-05-08 06:32:41 +00:00
}
2023-05-09 11:00:22 +00:00
void MainWindow::keyReleaseEvent(QKeyEvent* e)
2023-05-08 06:32:41 +00:00
{
Q_UNUSED(e)
2023-05-09 11:00:22 +00:00
qDebug() << "release";
2023-05-08 06:32:41 +00:00
}
2023-05-09 11:00:22 +00:00
void MainWindow::showEvent(QShowEvent* e)
2023-05-08 06:32:41 +00:00
{
QMainWindow::showEvent(e);
_signalHandler->showUserGuidence(true);
}
bool MainWindow::isLoadRecordScripFile()
{
QFile file(qApp->applicationDirPath() + "/../temp/RecordScript.py");
2023-05-09 11:00:22 +00:00
if(!file.exists() || file.size() == 0)
2023-05-08 06:32:41 +00:00
return false;
2023-05-09 11:00:22 +00:00
QMessageBox::StandardButton result = QMessageBox::warning(
this, tr("Do you need to load?"),
tr("The program quit with an exception before, do you want to reload the contents?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
2023-05-08 06:32:41 +00:00
2023-05-09 11:00:22 +00:00
switch(result) {
case QMessageBox::Yes:
Py::PythonAgent::getInstance()->execScript(file.fileName());
break;
case QMessageBox::No:
QFile::remove(qApp->applicationDirPath() + "/../temp/RecordScript.py");
break;
default:
break;
2023-05-08 06:32:41 +00:00
}
return true;
}
void MainWindow::setSketchPageVisible(bool visible)
{
2023-05-09 11:00:22 +00:00
SARibbonBar* ribbon = ribbonBar();
if(ribbon->ribbonTabBar()->currentIndex() == 0)
2023-05-08 06:32:41 +00:00
return;
// int index = -1;
2023-05-09 11:00:22 +00:00
if(visible) {
2023-05-08 06:32:41 +00:00
ribbon->showContextCategory(_ui->sketch_tool_context);
// index = ribbon->tabIndex(_ui->sketch_tool_page);
ribbon->raiseCategory(_ui->sketch_tool_page);
2023-05-09 11:00:22 +00:00
} else {
2023-05-08 06:32:41 +00:00
ribbon->hideContextCategory(_ui->sketch_tool_context);
// index = ribbon->tabIndex(_ui->geometry_page);
ribbon->raiseCategory(_ui->sketch_tool_page);
}
// ribbon->setCurrentIndex(index);
// ribbon->onCurrentRibbonTabChanged(index);
}
void MainWindow::changeStyleToRibbon(bool ok)
{
Setting::BusAPI::instance()->isUseRibbon(ok);
bool isRibbon = this->isUseRibbon();
2023-05-09 11:00:22 +00:00
if(isRibbon == ok)
2023-05-08 06:32:41 +00:00
return;
QMessageBox mbox(QMessageBox::Information, tr("Info"), tr("Restart to load the style!"));
/*QPushButton *button1 = */
mbox.addButton(tr("Restart later"), QMessageBox::RejectRole);
2023-05-09 11:00:22 +00:00
QPushButton* button2 = mbox.addButton(tr("Restart now"), QMessageBox::YesRole);
2023-05-08 06:32:41 +00:00
mbox.exec();
2023-05-09 11:00:22 +00:00
if(mbox.clickedButton() == button2) {
2023-05-08 06:32:41 +00:00
this->closeEvent(nullptr);
qApp->exit(-1000);
}
}
void MainWindow::setPostAnimationToolBar(bool ribbon)
{
_postToolBar = new Post::AnimationToolBar(this, _controlPanel->getPostTreeWidget());
Post::RenderDirector::getInstance()->setAnimationToolBar(_postToolBar);
2023-05-09 11:00:22 +00:00
if(ribbon) {
2023-05-08 06:32:41 +00:00
_postToolBar->setVisible(false);
auto rBar = this->ribbonBar();
2023-05-09 11:00:22 +00:00
if(rBar == nullptr)
2023-05-08 06:32:41 +00:00
return;
auto category = rBar->categoryByName(tr("3DRender"));
2023-05-09 11:00:22 +00:00
if(category == nullptr)
2023-05-08 06:32:41 +00:00
return;
2023-05-09 11:00:22 +00:00
auto pannel = category->addPannel(QString());
2023-05-08 06:32:41 +00:00
auto actList = _postToolBar->actions();
2023-05-09 11:00:22 +00:00
for(auto action : actList) {
2023-05-08 06:32:41 +00:00
action->setEnabled(false);
2023-05-09 11:00:22 +00:00
if(action->objectName() == "QWidget") {
2023-05-08 06:32:41 +00:00
auto widget = _postToolBar->widgetForAction(action);
2023-05-09 11:00:22 +00:00
if(widget == nullptr)
2023-05-08 06:32:41 +00:00
continue;
widget->setVisible(true);
pannel->addLargeWidget(widget);
continue;
}
pannel->addLargeAction(action);
}
2023-05-09 11:00:22 +00:00
} else {
2023-05-08 06:32:41 +00:00
_postToolBar->setVisible(true);
this->addToolBar(_postToolBar);
}
}
/*void MainWindow::changeActionState(actionState state)
{
if (state == normalState)
{
}
else if (state == customState)
{
}
}*/
void MainWindow::on_CreateSet()
{
MainWidget::CreateSetDialog dlg(this, _subWindowManager->getPreWindow());
dlg.exec();
}
void MainWindow::on_CreateGeoComponent()
{
MainWidget::CreateGeoComponentDialog dlg(this, _subWindowManager->getPreWindow());
dlg.exec();
}
void MainWindow::clearWidgets()
{
_subWindowManager->closeAllSubWindow();
_subWindowManager->openPreWindow();
_controlPanel->clearWidget();
}
void MainWindow::printMessage(Common::Message type, QString m)
{
ModuleBase::Message s(type, m);
2023-05-09 11:00:22 +00:00
emit printMessageToMessageWindow(s);
2023-05-08 06:32:41 +00:00
}
void MainWindow::on_SaveScript()
{
2023-05-09 11:00:22 +00:00
QString dir = Setting::BusAPI::instance()->getWorkingDir();
QString suffix = "Python(*.py)";
QString title = tr("Save Script");
2023-05-08 06:32:41 +00:00
QString filenames = QFileDialog::getSaveFileName(this, title, dir, suffix);
2023-05-09 11:00:22 +00:00
if(filenames.isEmpty())
2023-05-08 06:32:41 +00:00
return;
Py::PythonAgent::getInstance()->saveScript(filenames);
}
void MainWindow::on_ExecuateScript()
{
2023-05-09 11:00:22 +00:00
QString fillter = "Python(*.py)";
QString title = tr("Execute Script");
QString dir = Setting::BusAPI::instance()->getWorkingDir();
2023-05-08 06:32:41 +00:00
QString filePath = QFileDialog::getOpenFileName(this, title, dir, fillter);
2023-05-09 11:00:22 +00:00
if(filePath.isEmpty())
2023-05-08 06:32:41 +00:00
return;
bool ok = Py::PythonAgent::getInstance()->execScript(filePath);
2023-05-09 11:00:22 +00:00
if(!ok)
QMessageBox::warning(this, tr("Warning"),
QString(tr("%1 execute failed !")).arg(filePath));
2023-05-08 06:32:41 +00:00
}
2023-05-09 11:00:22 +00:00
MainWidget::ControlPanel* MainWindow::getControlPanel()
2023-05-08 06:32:41 +00:00
{
return _controlPanel;
}
void MainWindow::on_sketchClicked()
{
bool ischecked = _ui->actionCreate_Sketch->isChecked();
2023-05-09 11:00:22 +00:00
if(ischecked) {
if(!_subWindowManager->isPreWindowOpened())
2023-05-08 06:32:41 +00:00
_subWindowManager->openPreWindow();
2023-05-09 11:00:22 +00:00
auto dlg =
new GeometryWidget::SketchPlanDialog(this, _subWindowManager->getPreWindow());
2023-05-08 06:32:41 +00:00
dlg->show();
2023-05-09 11:00:22 +00:00
} else {
2023-05-08 06:32:41 +00:00
// auto p = _subWindowManager->getPreWindow();
emit startSketchSig(false, nullptr, nullptr);
}
}
void MainWindow::startSketch(bool s)
{
_ui->actionCreate_Sketch->setChecked(s);
2023-05-09 11:00:22 +00:00
if(isUseRibbon())
2023-05-08 06:32:41 +00:00
setSketchPageVisible(s);
2023-05-09 11:00:22 +00:00
else {
2023-05-08 06:32:41 +00:00
_ui->GeomertryFeatureToolBar->setVisible(!s);
_ui->ChamferToolBar->setVisible(!s);
_ui->BoolToolBar->setVisible(!s);
_ui->FeatureOpertionToolBar->setVisible(!s);
_ui->SketchToolBar->setVisible(s);
}
}
void MainWindow::on_FilterMesh()
{
MainWidget::FilterMeshDialog dlg(this, _subWindowManager->getPreWindow());
dlg.exec();
}
void MainWindow::on_VTKTranslation()
{
MainWidget::DialogVTKTransform dlg(this);
dlg.exec();
}
void MainWindow::showGraphRange(double w, double h)
{
2023-05-09 11:00:22 +00:00
if(_graphRange == nullptr) {
2023-05-08 06:32:41 +00:00
_graphRange = new QLabel(this);
_ui->statusbar->addPermanentWidget(_graphRange);
}
QString text = QString(tr("Canvas %1mm * %2mm ")).arg(w).arg(h);
_graphRange->setText(text);
}
// void MainWindow::updateActionsStates()
// {
// _signalHandler->updateActionsStates();
// }
2023-05-09 11:00:22 +00:00
CustomizerHelper* MainWindow::getCustomizerHelper()
2023-05-08 06:32:41 +00:00
{
return _customizerHelper;
}
2023-05-09 11:00:22 +00:00
SignalHandler* MainWindow::getSignalHandler()
2023-05-08 06:32:41 +00:00
{
return _signalHandler;
}
2023-05-09 11:00:22 +00:00
MainWidget::MessageWindow* MainWindow::getMessageWindow()
2023-05-08 06:32:41 +00:00
{
return _messageWindow;
}
void MainWindow::setIcon(QString iconPath)
{
this->setWindowIcon(QIcon(iconPath));
_subWindowManager->setIcon(iconPath);
}
2023-05-09 11:00:22 +00:00
QAction* MainWindow::getAction(QString& objName)
2023-05-08 06:32:41 +00:00
{
2023-05-09 11:00:22 +00:00
QList<QAction*> acs = this->findChildren<QAction*>();
for(QAction* a : acs) {
if(a->objectName().toLower() == objName.toLower())
2023-05-08 06:32:41 +00:00
return a;
}
return nullptr;
}
2023-05-09 11:00:22 +00:00
QToolBar* MainWindow::getToolBar(QString& objName)
2023-05-08 06:32:41 +00:00
{
2023-05-09 11:00:22 +00:00
QList<QToolBar*> tbs = this->findChildren<QToolBar*>();
for(auto a : tbs) {
if(a->objectName().toLower() == objName.toLower())
2023-05-08 06:32:41 +00:00
return a;
}
return nullptr;
}
2023-05-09 11:00:22 +00:00
QMenu* MainWindow::getMenu(QString& objName)
2023-05-08 06:32:41 +00:00
{
2023-05-09 11:00:22 +00:00
QList<QMenu*> mes = this->findChildren<QMenu*>();
for(auto a : mes) {
if(a->objectName().toLower() == objName.toLower())
2023-05-08 06:32:41 +00:00
return a;
}
return nullptr;
}
2023-05-09 11:00:22 +00:00
QPair<QWidget*, QList<QAction*>>
MainWindow::createWidgetAndAction(const QString& title, const QStringList& actionStrs)
2023-05-08 06:32:41 +00:00
{
2023-05-09 11:00:22 +00:00
QAction* action{};
QList<QAction*> actions;
QPair<QWidget*, QList<QAction*>> value;
2023-05-08 06:32:41 +00:00
2023-05-09 11:00:22 +00:00
if(isUseRibbon()) {
SARibbonCategory* page = ribbonBar()->addCategoryPage(title);
2023-05-08 06:32:41 +00:00
// 给定制的panel添加名称
2023-05-09 11:00:22 +00:00
SARibbonPannel* pannel = page->addPannel(QObject::tr("Customization"));
2023-05-08 06:32:41 +00:00
pannel->setCanCustomize(false); // 不能编辑
2023-05-09 11:00:22 +00:00
for(QString actionStr : actionStrs) {
2023-05-08 06:32:41 +00:00
action = new QAction(actionStr, this);
action->setObjectName(actionStr);
actions.append(action);
pannel->addLargeAction(action);
}
value.first = page;
2023-05-09 11:00:22 +00:00
} else {
QMenu* menu = new QMenu(title);
for(QString actionStr : actionStrs) {
2023-05-08 06:32:41 +00:00
action = new QAction(actionStr, this);
action->setObjectName(actionStr);
actions.append(action);
menu->addAction(action);
}
value.first = menu;
}
value.second = actions;
return value;
}
2023-05-09 11:00:22 +00:00
Post::AnimationToolBar* MainWindow::getAnimationToolBar()
2023-05-08 06:32:41 +00:00
{
return _postToolBar;
}
2023-05-09 11:00:22 +00:00
SARibbonActionsManager* MainWindow::getActionManager()
2023-05-08 06:32:41 +00:00
{
return m_ribbonActionMgr;
}
2023-05-09 11:00:22 +00:00
} // namespace GUI