Skip to content

Commit

Permalink
delete button operaitonnal. begin of save button
Browse files Browse the repository at this point in the history
  • Loading branch information
LafCorentin committed Aug 11, 2020
1 parent 6eb9224 commit 14458d0
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 38 deletions.
Expand Up @@ -23,6 +23,7 @@ along with this program. If not, see <https://gnu.org/licenses>.

#include "cellmlfilemanager.h"
#include "corecliutils.h"
#include "coreguiutils.h"
#include "filemanager.h"
#include "cellmlzincmappingvieweditingwidget.h"
#include "toolbarwidget.h"
Expand Down Expand Up @@ -85,7 +86,7 @@ QMimeData * CellMLZincMappingViewEditingModel::mimeData(const QModelIndexList &p

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

MappingViewEditingWidget::MappingViewEditingWidget(const QString &pFileName,
CellMLZincMappingViewEditingWidget::CellMLZincMappingViewEditingWidget(const QString &pFileName,
const QString &pMeshFileName,
QWidget *pParent) :
Core::Widget(pParent),
Expand All @@ -102,19 +103,27 @@ MappingViewEditingWidget::MappingViewEditingWidget(const QString &pFileName,

mToolBarWidget = new Core::ToolBarWidget();

QRect availableGeometry = qApp->primaryScreen()->availableGeometry();
//create and add widget and actions

mDelayWidget = new QwtWheel(mToolBarWidget);
QRect availableGeometry = qApp->primaryScreen()->availableGeometry();

mSaveMapping = Core::newAction(QIcon(":/oxygen/actions/document-save.png"),
mToolBarWidget);
//TODO trash could be hidden when nothing to show
mClearNode = Core::newAction(QIcon(":/oxygen/actions/edit-clear.png"),
mToolBarWidget);

mDelayWidget = new QwtWheel(mToolBarWidget);
mDelayWidget->setBorderWidth(0);
mDelayWidget->setFixedSize(int(0.07*availableGeometry.width()),
mDelayWidget->height()/2);
mDelayWidget->setFocusPolicy(Qt::NoFocus);
mDelayWidget->setRange(0.0, 100.0);
mDelayWidget->setWheelBorderWidth(0);

mDelayWidget->setValue(CellMLZincMappingViewZincWidget::nodeSizeOrigin);

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

layout->addWidget(mToolBarWidget);
Expand All @@ -124,14 +133,14 @@ MappingViewEditingWidget::MappingViewEditingWidget(const QString &pFileName,
mHorizontalSplitterWidget = new Core::SplitterWidget(Qt::Horizontal, this);

connect(mHorizontalSplitterWidget, &Core::SplitterWidget::splitterMoved,
this, &MappingViewEditingWidget::emitHorizontalSplitterMoved);
this, &CellMLZincMappingViewEditingWidget::emitHorizontalSplitterMoved);

//create vertical splitterwidget

mVerticalSplitterWidget = new Core::SplitterWidget(Qt::Vertical, this);

connect(mVerticalSplitterWidget, &Core::SplitterWidget::splitterMoved,
this, &MappingViewEditingWidget::emitVerticalSplitterMoved);
this, &CellMLZincMappingViewEditingWidget::emitVerticalSplitterMoved);

//create and add the variable tree:

Expand All @@ -156,11 +165,18 @@ MappingViewEditingWidget::MappingViewEditingWidget(const QString &pFileName,

mZincWidget = new CellMLZincMappingViewZincWidget(this, mMeshFileName, this);

connect(mClearNode, &QAction::triggered,
mZincWidget, &CellMLZincMappingViewZincWidget::eraseNode);
connect(mDelayWidget, &QwtWheel::valueChanged,
mZincWidget, &CellMLZincMappingViewZincWidget::setNodeSizes );
mZincWidget, &CellMLZincMappingViewZincWidget::setNodeSizes);

mHorizontalSplitterWidget->addWidget(mZincWidget);

//add the other connectionss

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

//create and add informative labels

Core::Widget *labelWidget = new Core::Widget(this);
Expand Down Expand Up @@ -190,14 +206,14 @@ MappingViewEditingWidget::MappingViewEditingWidget(const QString &pFileName,

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

void MappingViewEditingWidget::retranslateUi()
void CellMLZincMappingViewEditingWidget::retranslateUi()
{
//TODO ?
}

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

void MappingViewEditingWidget::setNodeValue(const int pId, const QString &pVariable)
void CellMLZincMappingViewEditingWidget::setNodeValue(const int pId, const QString &pVariable)
{
if (pId!=-1) {
mMapMatch.insert(pId,pVariable);
Expand All @@ -207,13 +223,23 @@ void MappingViewEditingWidget::setNodeValue(const int pId, const QString &pVaria

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

void MappingViewEditingWidget::filePermissionsChanged()
void CellMLZincMappingViewEditingWidget::eraseNodeValue(const int pId)
{
if (pId!=-1) {
mMapMatch.remove(pId);
selectNode(pId);
}
}

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

void CellMLZincMappingViewEditingWidget::filePermissionsChanged()
{
}

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

bool MappingViewEditingWidget::setMeshFile(const QString &pFileName, bool pShowWarning)
bool CellMLZincMappingViewEditingWidget::setMeshFile(const QString &pFileName, bool pShowWarning)
{
//TODO warnings ?
Q_UNUSED(pShowWarning)
Expand All @@ -227,7 +253,7 @@ Q_UNUSED(pShowWarning)

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

void MappingViewEditingWidget::populateTree()
void CellMLZincMappingViewEditingWidget::populateTree()
{

// Make sure that we have a model before actually populating ourselves
Expand Down Expand Up @@ -285,7 +311,7 @@ void MappingViewEditingWidget::populateTree()

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

void MappingViewEditingWidget::saveMapping(const QString &pFileName)
void CellMLZincMappingViewEditingWidget::saveMapping(const QString &pFileName)
{
Q_UNUSED(pFileName);

Expand All @@ -295,7 +321,7 @@ void MappingViewEditingWidget::saveMapping(const QString &pFileName)
}
//==============================================================================

void MappingViewEditingWidget::emitHorizontalSplitterMoved()
void CellMLZincMappingViewEditingWidget::emitHorizontalSplitterMoved()
{
// Let people know that our splitter has been moved

Expand All @@ -304,7 +330,7 @@ void MappingViewEditingWidget::emitHorizontalSplitterMoved()

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

void MappingViewEditingWidget::emitVerticalSplitterMoved()
void CellMLZincMappingViewEditingWidget::emitVerticalSplitterMoved()
{
// Let people know that our splitter has been moved

Expand All @@ -313,7 +339,7 @@ void MappingViewEditingWidget::emitVerticalSplitterMoved()

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

void MappingViewEditingWidget::selectNode(int pId)
void CellMLZincMappingViewEditingWidget::selectNode(int pId)
{
if (pId==-1) {
mNodeValue->setText("");
Expand All @@ -326,7 +352,7 @@ void MappingViewEditingWidget::selectNode(int pId)

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

void MappingViewEditingWidget::saveMapping()
void CellMLZincMappingViewEditingWidget::saveMappingSlot()
{
saveMapping({});
}
Expand Down
Expand Up @@ -80,26 +80,30 @@ class CellMLZincMappingViewEditingModel : public QStandardItemModel

};

class MappingViewEditingWidget : public Core::Widget
class CellMLZincMappingViewEditingWidget : public Core::Widget
{
Q_OBJECT

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

void retranslateUi() override;

void selectNode(int pId);
void setNodeValue(const int pId, const QString &pVariable);
void eraseNodeValue(const int pId);

void filePermissionsChanged();

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

private:

QAction *mClearNode;
QAction *mSaveMapping;

QwtWheel *mDelayWidget;

Core::ToolBarWidget *mToolBarWidget;
Expand Down Expand Up @@ -130,7 +134,7 @@ class MappingViewEditingWidget : public Core::Widget
private slots:
void emitHorizontalSplitterMoved();
void emitVerticalSplitterMoved();
void saveMapping();
void saveMappingSlot();
};

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

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

mEditingWidgets.insert(pFileName, mEditingWidget);
}
Expand All @@ -100,7 +100,7 @@ void CellMLZincMappingViewWidget::finalize(const QString &pFileName)
{
// Remove the editing widget, should there be one for the given file

MappingViewEditingWidget *editingWidget = mEditingWidgets.value(pFileName);
CellMLZincMappingViewEditingWidget *editingWidget = mEditingWidgets.value(pFileName);

if (editingWidget != nullptr) {
// There is an editing widget for the given file name, so delete it and
Expand All @@ -120,7 +120,7 @@ void CellMLZincMappingViewWidget::finalize(const QString &pFileName)

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

MappingViewEditingWidget* CellMLZincMappingViewWidget::editingWidget(const QString &pFileName) const
CellMLZincMappingViewEditingWidget* CellMLZincMappingViewWidget::editingWidget(const QString &pFileName) const
{
// Return the requested simulation widget

Expand All @@ -143,7 +143,7 @@ void CellMLZincMappingViewWidget::filePermissionsChanged(const QString &pFileNam
// The given file has been un/locked, so enable/disable parts of our GUI,
// should the given file be managed

MappingViewEditingWidget *editingWidget = mEditingWidgets.value(pFileName);
CellMLZincMappingViewEditingWidget *editingWidget = mEditingWidgets.value(pFileName);

if (editingWidget != nullptr) {
editingWidget->filePermissionsChanged();
Expand Down Expand Up @@ -175,7 +175,7 @@ void CellMLZincMappingViewWidget::fileRenamed(const QString &pOldFileName, const
{
// The given file has been renamed, so update our editing widgets mapping

MappingViewEditingWidget *editingWidget = mEditingWidgets.value(pOldFileName);
CellMLZincMappingViewEditingWidget *editingWidget = mEditingWidgets.value(pOldFileName);

if (editingWidget != nullptr) {
mEditingWidgets.insert(pNewFileName, editingWidget);
Expand Down
Expand Up @@ -63,7 +63,7 @@ class CellMLZincMappingViewWidget : public Core::ViewWidget
void initialize(const QString &pFileName);
void finalize(const QString &pFileName);

MappingViewEditingWidget * editingWidget(const QString &pFileName) const;
CellMLZincMappingViewEditingWidget * editingWidget(const QString &pFileName) const;

QWidget * widget(const QString &pFileName) override;

Expand All @@ -81,8 +81,8 @@ class CellMLZincMappingViewWidget : public Core::ViewWidget

private:

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

QString mMeshFileName;

Expand Down
Expand Up @@ -22,10 +22,10 @@ along with this program. If not, see <https://gnu.org/licenses>.
//==============================================================================

#include "cellmlfilemanager.h"
#include "corecliutils.h"
#include "filemanager.h"
#include "cellmlzincmappingvieweditingwidget.h"
#include "cellmlzincmappingviewzincwidget.h"
#include "corecliutils.h"
#include "filemanager.h"

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

Expand All @@ -44,7 +44,6 @@ along with this program. If not, see <https://gnu.org/licenses>.

#include "zincbegin.h"
#include "opencmiss/zinc/context.hpp"
#include "opencmiss/zinc/result.hpp"
#include "opencmiss/zinc/scenefilter.hpp"
#include "opencmiss/zinc/field.hpp"
#include "opencmiss/zinc/graphics.hpp"
Expand All @@ -58,7 +57,7 @@ namespace CellMLZincMappingView {
//==============================================================================

CellMLZincMappingViewZincWidget::CellMLZincMappingViewZincWidget(QWidget *pParent, const QString &pMainFileName,
MappingViewEditingWidget *pEditingWidget) :
CellMLZincMappingViewEditingWidget *pEditingWidget) :
ZincWidget::ZincWidget(pParent),
mMainFileName(pMainFileName),
mEditingWidget(pEditingWidget),
Expand Down Expand Up @@ -190,9 +189,10 @@ void CellMLZincMappingViewZincWidget::dropEvent(QDropEvent *pEvent)

mEditingWidget->setNodeValue(mIdSelectedNode,"component: "+splitText[1]+", variable: "+splitText.first());

// select and highlight the current node

auto fieldModule = mZincContext->getDefaultRegion().getFieldmodule();
OpenCMISS::Zinc::Node node = fieldModule.findNodesetByFieldDomainType(OpenCMISS::Zinc::Field::DOMAIN_TYPE_NODES).findNodeByIdentifier(mIdSelectedNode);
// select the node to highlight graphics

fieldModule.beginChange();

Expand All @@ -203,7 +203,6 @@ void CellMLZincMappingViewZincWidget::dropEvent(QDropEvent *pEvent)
if (!nodeGroupField.isValid()) {
nodeGroupField = mMappedSelectionGroup.createFieldNodeGroup(nodes);
}
qDebug("added !");
OpenCMISS::Zinc::NodesetGroup nodesetGroup = nodeGroupField.getNodesetGroup();
nodesetGroup.addNode(node);

Expand Down Expand Up @@ -414,6 +413,38 @@ void CellMLZincMappingViewZincWidget::setNodeSizes(int pSize) {

}

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

void CellMLZincMappingViewZincWidget::eraseNode()
{

mEditingWidget->eraseNodeValue(mIdSelectedNode);

// select and highlight the current node

auto fieldModule = mZincContext->getDefaultRegion().getFieldmodule();
OpenCMISS::Zinc::Node node = fieldModule.findNodesetByFieldDomainType(OpenCMISS::Zinc::Field::DOMAIN_TYPE_NODES).findNodeByIdentifier(mIdSelectedNode);

fieldModule.beginChange();

if (node.isValid()){
OpenCMISS::Zinc::Nodeset nodes = fieldModule.findNodesetByFieldDomainType(OpenCMISS::Zinc::Field::DOMAIN_TYPE_NODES);
OpenCMISS::Zinc::FieldNodeGroup nodeGroupField = mMappedSelectionGroup.getFieldNodeGroup(nodes);

if (!nodeGroupField.isValid()) {
nodeGroupField = mMappedSelectionGroup.createFieldNodeGroup(nodes);
}
OpenCMISS::Zinc::NodesetGroup nodesetGroup = nodeGroupField.getNodesetGroup();
nodesetGroup.removeNode(node);

} else {
if (mMappedSelectionGroup.isValid()) {
mZincContext->getDefaultRegion().getScene().setSelectionField(OpenCMISS::Zinc::Field());
}
}
fieldModule.endChange();
}

} // namespace ZincWidget
} // namespace OpenCOR

Expand Down

0 comments on commit 14458d0

Please sign in to comment.