Skip to content

Commit

Permalink
open mesh button operationnal
Browse files Browse the repository at this point in the history
  • Loading branch information
LafCorentin committed Aug 14, 2020
1 parent b66e54f commit 00ac063
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 87 deletions.
1 change: 1 addition & 0 deletions meshes/.gitignore
@@ -1,2 +1,3 @@
/MainTime_0.part0.exelem
/MainTime_0.part0.exnode
*.json
Expand Up @@ -21,15 +21,16 @@ along with this program. If not, see <https://gnu.org/licenses>.
// Mapping view widget
//==============================================================================

#include "interfaces.h"
#include "cellmlfilemanager.h"
#include "corecliutils.h"
#include "coreguiutils.h"
#include "filemanager.h"
#include "cellmlzincmappingviewwidget.h"
#include "cellmlzincmappingvieweditingwidget.h"
#include "toolbarwidget.h"
#include "zincwidget.h"


//==============================================================================

#include <QFile>
Expand Down Expand Up @@ -88,8 +89,9 @@ QMimeData * CellMLZincMappingViewEditingModel::mimeData(const QModelIndexList &p

CellMLZincMappingViewEditingWidget::CellMLZincMappingViewEditingWidget(const QString &pFileName,
const QString &pMeshFileName,
QWidget *pParent) :
QWidget *pParent, CellMLZincMappingViewWidget *pViewWidget) :
Core::Widget(pParent),
mViewWidget(pViewWidget),
mMapMatch(),
mMeshFileName(pMeshFileName)
{
Expand All @@ -108,7 +110,11 @@ CellMLZincMappingViewEditingWidget::CellMLZincMappingViewEditingWidget(const QSt
QRect availableGeometry = qApp->primaryScreen()->availableGeometry();

mSaveMapping = Core::newAction(QIcon(":/oxygen/actions/document-save.png"),
mToolBarWidget);
mToolBarWidget);

mOpenMeshFile = Core::newAction(QIcon(":/oxygen/actions/document-open.png"),
mToolBarWidget);

//TODO trash could be hidden when nothing to show
mClearNode = Core::newAction(QIcon(":/oxygen/actions/edit-clear.png"),
mToolBarWidget);
Expand All @@ -123,6 +129,7 @@ CellMLZincMappingViewEditingWidget::CellMLZincMappingViewEditingWidget(const QSt
mDelayWidget->setValue(CellMLZincMappingViewZincWidget::nodeSizeOrigin);

mToolBarWidget->addAction(mSaveMapping);
mToolBarWidget->addAction(mOpenMeshFile);
mToolBarWidget->addAction(mClearNode);
mToolBarWidget->addWidget(mDelayWidget);

Expand Down Expand Up @@ -176,6 +183,8 @@ CellMLZincMappingViewEditingWidget::CellMLZincMappingViewEditingWidget(const QSt

connect(mSaveMapping, &QAction::triggered,
this, &CellMLZincMappingViewEditingWidget::saveMappingSlot);
connect(mOpenMeshFile, &QAction::triggered,
this, &CellMLZincMappingViewEditingWidget::loadMeshFile);

//create and add informative labels

Expand Down Expand Up @@ -210,6 +219,10 @@ CellMLZincMappingViewEditingWidget::CellMLZincMappingViewEditingWidget(const QSt
layout->addWidget(mVerticalSplitterWidget);

populateTree();

// Allow for things to be dropped on us

setAcceptDrops(true);
}

//==============================================================================
Expand Down Expand Up @@ -255,12 +268,77 @@ Q_UNUSED(pShowWarning)
mMeshFileName = pFileName;
mZincWidget->changeSource(pFileName);
mMapMatch.clear();

selectNode(-1);
mViewWidget->setDefaultMeshFile(pFileName);
return true;
}

//==============================================================================

void CellMLZincMappingViewEditingWidget::dragEnterEvent(QDragEnterEvent *pEvent)
{
// Accept the proposed action for the event, but only if it refers to one or
// several data store files

bool acceptEvent = false;

for (const auto &fileName : Core::droppedFileNames(pEvent)) {
for (auto fileTypeInterface : Core::dataStoreFileTypeInterfaces()) {
if (fileTypeInterface->isFile(fileName)) {
mFileTypeInterfaces.insert(fileName, fileTypeInterface);

acceptEvent = true;

break;
}
}

//TODO
if (fileName.contains(".exelem")||fileName.contains(".exnode")||fileName.contains(".exfile")) {
acceptEvent = true;
}
}

if (acceptEvent) {
pEvent->acceptProposedAction();
} else {
pEvent->ignore();
}
}

//==============================================================================

void CellMLZincMappingViewEditingWidget::dragMoveEvent(QDragMoveEvent *pEvent)
{
// Accept the proposed action for the event

pEvent->acceptProposedAction();
}

//==============================================================================

void CellMLZincMappingViewEditingWidget::dropEvent(QDropEvent *pEvent)
{
// Import/open the one or several files

for (const auto &fileName : Core::droppedFileNames(pEvent)) {
if (fileName.contains(".exelem")||fileName.contains(".exnode")||fileName.contains(".exfile")) {
setMeshFile(fileName);
} else if (mFileTypeInterfaces.contains(fileName)) {
//import(fileName); //?
//TODO
} else {
QDesktopServices::openUrl("opencor://openFile/"+fileName);
}
}

// Accept the proposed action for the event

pEvent->acceptProposedAction();
}

//==============================================================================

void CellMLZincMappingViewEditingWidget::populateTree()
{

Expand Down Expand Up @@ -438,6 +516,11 @@ void CellMLZincMappingViewEditingWidget::saveMappingSlot()
saveMapping({});
}

void CellMLZincMappingViewEditingWidget::loadMeshFile()
{
setMeshFile(Core::getOpenFileName("Open mesh file"));
}

} // namespace MappingView
} // namespace OpenCOR

Expand Down
Expand Up @@ -62,6 +62,7 @@ namespace Core {
//==============================================================================

namespace CellMLZincMappingView {
class CellMLZincMappingViewWidget;

//==============================================================================

Expand All @@ -86,8 +87,9 @@ class CellMLZincMappingViewEditingWidget : public Core::Widget

public:
explicit CellMLZincMappingViewEditingWidget(const QString &pCellmlFileName,
const QString &pMeshFileName,
QWidget *pParent);
const QString &pMeshFileName,
QWidget *pParent,
CellMLZincMappingViewWidget *pViewWidget);

void retranslateUi() override;

Expand All @@ -99,16 +101,24 @@ class CellMLZincMappingViewEditingWidget : public Core::Widget

bool setMeshFile(const QString &pFileName, bool pShowWarning = true);

private:
protected:
void dragEnterEvent(QDragEnterEvent *pEvent) override;
void dragMoveEvent(QDragMoveEvent *pEvent) override;
void dropEvent(QDropEvent *pEvent) override;

private:
struct _variable {
QString component;
QString variable;
};

CellMLZincMappingViewWidget *mViewWidget;

QMap<int, _variable> mMapMatch;

QAction *mClearNode;
QAction *mSaveMapping;
QAction *mOpenMeshFile;

QwtWheel *mDelayWidget;

Expand All @@ -135,6 +145,8 @@ class CellMLZincMappingViewEditingWidget : public Core::Widget
const QString &pFileExtension, const QString &pCaption,
const QStringList &pFileFilters);

QMap<QString, FileTypeInterface *> mFileTypeInterfaces;

signals:
void horizontalSplitterMoved(const QIntList &pSizes);
void verticalSplitterMoved(const QIntList &pSizes);
Expand All @@ -143,6 +155,7 @@ private slots:
void emitHorizontalSplitterMoved();
void emitVerticalSplitterMoved();
void saveMappingSlot();
void loadMeshFile();
};

//==============================================================================
Expand Down
Expand Up @@ -21,8 +21,6 @@ along with this program. If not, see <https://gnu.org/licenses>.
// Mapping view widget
//==============================================================================

#include "borderedwidget.h"
#include "interfaces.h"
#include "cellmlzincmappingviewwidget.h"

//==============================================================================
Expand All @@ -45,11 +43,8 @@ CellMLZincMappingViewWidget::CellMLZincMappingViewWidget(QWidget *pParent) :
{

//TODO
mMeshFileName = "/home/tuareg/Documents/OpenCOR/opencor/meshes/circulation.exnode";
mMeshFileName = "/home/tuareg/Documents/OpenCOR/opencor/meshes/trilinearCube.exfile";

// Allow for things to be dropped on us

setAcceptDrops(true);
}

//==============================================================================
Expand Down Expand Up @@ -81,7 +76,7 @@ void CellMLZincMappingViewWidget::initialize(const QString &pFileName)
if (mEditingWidget == nullptr) {
// No editing widget exists for the given file, so create one

mEditingWidget = new CellMLZincMappingViewEditingWidget(pFileName, mMeshFileName,this);
mEditingWidget = new CellMLZincMappingViewEditingWidget(pFileName, mMeshFileName,this, this);

mEditingWidgets.insert(pFileName, mEditingWidget);
}
Expand Down Expand Up @@ -185,71 +180,11 @@ void CellMLZincMappingViewWidget::fileRenamed(const QString &pOldFileName, const

//==============================================================================

void CellMLZincMappingViewWidget::dragEnterEvent(QDragEnterEvent *pEvent)
void CellMLZincMappingViewWidget::setDefaultMeshFile(const QString &pFileName)
{
// Accept the proposed action for the event, but only if it refers to one or
// several data store files

bool acceptEvent = false;

for (const auto &fileName : Core::droppedFileNames(pEvent)) {
for (auto fileTypeInterface : Core::dataStoreFileTypeInterfaces()) {
if (fileTypeInterface->isFile(fileName)) {
mFileTypeInterfaces.insert(fileName, fileTypeInterface);

acceptEvent = true;

break;
}
}

//TODO
if (fileName.contains(".exelem")||fileName.contains(".exnode")||fileName.contains(".exfile")) {
acceptEvent = true;
qDebug("drop of %s accepted",qPrintable(fileName));
}
}

if (acceptEvent) {
pEvent->acceptProposedAction();
} else {
pEvent->ignore();
}
mMeshFileName = pFileName;
}

//==============================================================================

void CellMLZincMappingViewWidget::dragMoveEvent(QDragMoveEvent *pEvent)
{
// Accept the proposed action for the event

pEvent->acceptProposedAction();
}

//==============================================================================

void CellMLZincMappingViewWidget::dropEvent(QDropEvent *pEvent)
{
// Import/open the one or several files

for (const auto &fileName : Core::droppedFileNames(pEvent)) {
if (fileName.contains(".exelem")||fileName.contains(".exnode")||fileName.contains(".exfile")) {
qDebug(">>> open %s !",qPrintable(fileName));
mEditingWidget->setMeshFile(fileName);
mMeshFileName = fileName;
} else if (mFileTypeInterfaces.contains(fileName)) {
//import(fileName); //?
//TODO
} else {
qDebug(">>> send %s to opencor to open it !",qPrintable(fileName));
QDesktopServices::openUrl("opencor://openFile/"+fileName);
}
}

// Accept the proposed action for the event

pEvent->acceptProposedAction();
}

//==============================================================================

Expand Down
Expand Up @@ -25,8 +25,6 @@ along with this program. If not, see <https://gnu.org/licenses>.

//==============================================================================

#include "cellmlfile.h"
#include "corecliutils.h"
#include "cellmlzincmappingvieweditingwidget.h"
#include "viewwidget.h"

Expand Down Expand Up @@ -72,22 +70,16 @@ class CellMLZincMappingViewWidget : public Core::ViewWidget
void fileReloaded(const QString &pFileName);
void fileRenamed(const QString &pOldFileName, const QString &pNewFileName);

bool saveFile(const QString &pOldFileName, const QString &pNewFileName);
//bool saveFile(const QString &pOldFileName, const QString &pNewFileName);

protected:
void dragEnterEvent(QDragEnterEvent *pEvent) override;
void dragMoveEvent(QDragMoveEvent *pEvent) override;
void dropEvent(QDropEvent *pEvent) override;
void setDefaultMeshFile(const QString &pFileName);

private:

CellMLZincMappingViewEditingWidget* mEditingWidget = nullptr;
QMap<QString, CellMLZincMappingViewEditingWidget*> mEditingWidgets;

QString mMeshFileName;

QMap<QString, FileTypeInterface *> mFileTypeInterfaces;

};

//==============================================================================
Expand Down
Expand Up @@ -98,7 +98,9 @@ void CellMLZincMappingViewZincWidget::changeSource(const QString &pMainFileName)

setupRegion();

draw();
//mSceneViewer.setScene(region.getScene());
//draw();
initializeGL();
}

//==============================================================================
Expand Down Expand Up @@ -229,6 +231,8 @@ void CellMLZincMappingViewZincWidget::setup()
setContext(mZincContext);
}

//==============================================================================

void CellMLZincMappingViewZincWidget::setupRegion()
{
//Create and initialize region and scene
Expand Down

0 comments on commit 00ac063

Please sign in to comment.