Skip to content

Commit

Permalink
Merge 36f598e into b8471ab
Browse files Browse the repository at this point in the history
  • Loading branch information
agarny committed Jun 26, 2018
2 parents b8471ab + 36f598e commit 61f314e
Show file tree
Hide file tree
Showing 26 changed files with 752 additions and 540 deletions.
138 changes: 86 additions & 52 deletions src/plugins/editing/CellMLTextView/src/cellmltextviewconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,40 @@ namespace CellMLTextView {

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

CellMLTextViewConverterWarning::CellMLTextViewConverterWarning(int pLine,
const QString &pMessage) :
mLine(pLine),
mMessage(pMessage)
CellMLTextViewConverterWarning::CellMLTextViewConverterWarning(const QString &pMessage,
int pLineNumber,
int pColumnNumber) :
mMessage(pMessage),
mLineNumber(pLineNumber),
mColumnNumber(pColumnNumber)
{
}

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

int CellMLTextViewConverterWarning::line() const
QString CellMLTextViewConverterWarning::message() const
{
// Return our message

return mMessage;
}

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

int CellMLTextViewConverterWarning::lineNumber() const
{
// Return our line number

return mLine;
return mLineNumber;
}

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

QString CellMLTextViewConverterWarning::message() const
int CellMLTextViewConverterWarning::columnNumber() const
{
// Return our message
// Return our column number

return mMessage;
return mColumnNumber;
}

//==============================================================================
Expand Down Expand Up @@ -178,29 +189,29 @@ QString CellMLTextViewConverter::output() const

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

int CellMLTextViewConverter::errorLine() const
QString CellMLTextViewConverter::errorMessage() const
{
// Return our error line
// Return our error message

return mErrorLine;
return mErrorMessage;
}

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

int CellMLTextViewConverter::errorColumn() const
int CellMLTextViewConverter::errorLine() const
{
// Return our error column
// Return our error line

return mErrorColumn;
return mErrorLine;
}

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

QString CellMLTextViewConverter::errorMessage() const
int CellMLTextViewConverter::errorColumn() const
{
// Return our error message
// Return our error column

return mErrorMessage;
return mErrorColumn;
}

//==============================================================================
Expand Down Expand Up @@ -251,9 +262,9 @@ void CellMLTextViewConverter::reset()

mLastOutputType = None;

mErrorMessage = QString();
mErrorLine = -1;
mErrorColumn = -1;
mErrorMessage = QString();

mWarnings = CellMLTextViewConverterWarnings();

Expand Down Expand Up @@ -607,8 +618,9 @@ bool CellMLTextViewConverter::processUnitsNode(const QDomNode &pDomNode,
QString baseUnits = cellmlAttributeNodeValue(pDomNode, "base_units", false);

if (!baseUnits.isEmpty() && baseUnits.compare("yes") && baseUnits.compare("no")) {
mErrorLine = pDomNode.lineNumber();
mErrorMessage = tr("A 'base_units' attribute must have a value of 'yes' or 'no'.");
mErrorLine = pDomNode.lineNumber();
mErrorColumn = pDomNode.columnNumber();

return false;
}
Expand Down Expand Up @@ -1243,6 +1255,7 @@ QString CellMLTextViewConverter::processMathmlNode(const QDomNode &pDomNode,
}

mErrorLine = domNode.lineNumber();
mErrorColumn = domNode.columnNumber();

pHasError = true;

Expand Down Expand Up @@ -1807,6 +1820,7 @@ QString CellMLTextViewConverter::processRootNode(const QDomNode &pDomNode,
mErrorMessage = tr("The first sibling of a '%1' element with two siblings must be a '%2' element.").arg("root")
.arg("degree");
mErrorLine = childNode.lineNumber();
mErrorColumn = childNode.columnNumber();

pHasError = true;

Expand Down Expand Up @@ -1970,6 +1984,7 @@ QString CellMLTextViewConverter::processDiffNode(const QDomNode &pDomNode,
mErrorMessage = tr("The first sibling of a '%1' element with two siblings must be a '%2' element.").arg("diff")
.arg("bvar");
mErrorLine = childNode.lineNumber();
mErrorColumn = childNode.columnNumber();

pHasError = true;

Expand Down Expand Up @@ -2056,6 +2071,7 @@ QString CellMLTextViewConverter::processBvarNode(const QDomNode &pDomNode,
mErrorMessage = tr("The second child element of a '%1' element with two child elements must be a '%2' element.").arg("bvar")
.arg("degree");
mErrorLine = childNode.lineNumber();
mErrorColumn = childNode.columnNumber();

pHasError = true;

Expand Down Expand Up @@ -2173,16 +2189,18 @@ bool CellMLTextViewConverter::processRelationshipRefNode(const QDomNode &pDomNod
if (!relationship.compare("encapsulation")) {
isEncapsulation = true;
} else if (relationship.compare("containment")) {
mErrorLine = pDomNode.lineNumber();
mErrorMessage = tr("A 'relationship' attribute in the CellML namespace must have a value of 'encapsulation' or 'containment'.");
mErrorLine = pDomNode.lineNumber();
mErrorColumn = pDomNode.columnNumber();

return false;
}
}

if (isEncapsulation && !name.isEmpty()) {
mErrorLine = pDomNode.lineNumber();
mErrorMessage = tr("A 'relationship_ref' element with a 'relationship' attribute value of 'encapsulation' must not define a 'name' attribute.");
mErrorLine = pDomNode.lineNumber();
mErrorColumn = pDomNode.columnNumber();

return false;
}
Expand Down Expand Up @@ -2321,8 +2339,9 @@ bool CellMLTextViewConverter::processMapComponentsNode(const QDomNode &pDomNode,
// Make sure that we haven't already processed a map components node

if (!pMapComponents.isEmpty()) {
mErrorLine = pDomNode.lineNumber();
mErrorMessage = tr("A 'connection' element must contain exactly one 'map_components' element.");
mErrorLine = pDomNode.lineNumber();
mErrorColumn = pDomNode.columnNumber();

return false;
}
Expand Down Expand Up @@ -2405,68 +2424,81 @@ bool CellMLTextViewConverter::processUnknownNode(const QDomNode &pDomNode,

break;
case QDomNode::AttributeNode:
mWarnings << CellMLTextViewConverterWarning(pDomNode.lineNumber(),
tr("An attribute was found in the original CellML file, but it was not processed."));
mWarnings << CellMLTextViewConverterWarning(tr("An attribute was found in the original CellML file, but it was not processed."),
pDomNode.lineNumber(),
pDomNode.columnNumber());

break;
case QDomNode::TextNode:
mWarnings << CellMLTextViewConverterWarning(pDomNode.lineNumber(),
tr("Some text was found in the original CellML file, but it was not processed."));
mWarnings << CellMLTextViewConverterWarning(tr("Some text was found in the original CellML file, but it was not processed."),
pDomNode.lineNumber(),
pDomNode.columnNumber());

break;
case QDomNode::CDATASectionNode:
mWarnings << CellMLTextViewConverterWarning(pDomNode.lineNumber(),
tr("A CDATA section was found in the original CellML file, but it was not processed."));
mWarnings << CellMLTextViewConverterWarning(tr("A CDATA section was found in the original CellML file, but it was not processed."),
pDomNode.lineNumber(),
pDomNode.columnNumber());

break;
case QDomNode::EntityReferenceNode:
mWarnings << CellMLTextViewConverterWarning(pDomNode.lineNumber(),
tr("An entity reference was found in the original CellML file, but it was not processed."));
mWarnings << CellMLTextViewConverterWarning(tr("An entity reference was found in the original CellML file, but it was not processed."),
pDomNode.lineNumber(),
pDomNode.columnNumber());

break;
case QDomNode::EntityNode:
mWarnings << CellMLTextViewConverterWarning(pDomNode.lineNumber(),
tr("An entity was found in the original CellML file, but it was not processed."));
mWarnings << CellMLTextViewConverterWarning(tr("An entity was found in the original CellML file, but it was not processed."),
pDomNode.lineNumber(),
pDomNode.columnNumber());

break;
case QDomNode::ProcessingInstructionNode:
mWarnings << CellMLTextViewConverterWarning(pDomNode.lineNumber(),
tr("A processing instruction was found in the original CellML file, but it is not known and cannot therefore be processed."));
mWarnings << CellMLTextViewConverterWarning(tr("A processing instruction was found in the original CellML file, but it is not known and cannot therefore be processed."),
pDomNode.lineNumber(),
pDomNode.columnNumber());

break;
case QDomNode::CommentNode:
mWarnings << CellMLTextViewConverterWarning(pDomNode.lineNumber(),
tr("A comment was found in the original CellML file, but it was not processed."));
mWarnings << CellMLTextViewConverterWarning(tr("A comment was found in the original CellML file, but it was not processed."),
pDomNode.lineNumber(),
pDomNode.columnNumber());

break;
case QDomNode::DocumentNode:
mWarnings << CellMLTextViewConverterWarning(pDomNode.lineNumber(),
tr("A document was found in the original CellML file, but it was not processed."));
mWarnings << CellMLTextViewConverterWarning(tr("A document was found in the original CellML file, but it was not processed."),
pDomNode.lineNumber(),
pDomNode.columnNumber());

break;
case QDomNode::DocumentTypeNode:
mWarnings << CellMLTextViewConverterWarning(pDomNode.lineNumber(),
tr("A document type was found in the original CellML file, but it was not processed."));
mWarnings << CellMLTextViewConverterWarning(tr("A document type was found in the original CellML file, but it was not processed."),
pDomNode.lineNumber(),
pDomNode.columnNumber());

break;
case QDomNode::DocumentFragmentNode:
mWarnings << CellMLTextViewConverterWarning(pDomNode.lineNumber(),
tr("A document fragment was found in the original CellML file, but it was not processed."));
mWarnings << CellMLTextViewConverterWarning(tr("A document fragment was found in the original CellML file, but it was not processed."),
pDomNode.lineNumber(),
pDomNode.columnNumber());

break;
case QDomNode::NotationNode:
mWarnings << CellMLTextViewConverterWarning(pDomNode.lineNumber(),
tr("A notation was found in the original CellML file, but it was not processed."));
mWarnings << CellMLTextViewConverterWarning(tr("A notation was found in the original CellML file, but it was not processed."),
pDomNode.lineNumber(),
pDomNode.columnNumber());

break;
case QDomNode::BaseNode:
mWarnings << CellMLTextViewConverterWarning(pDomNode.lineNumber(),
tr("A base was found in the original CellML file, but it was not processed."));
mWarnings << CellMLTextViewConverterWarning(tr("A base was found in the original CellML file, but it was not processed."),
pDomNode.lineNumber(),
pDomNode.columnNumber());

break;
case QDomNode::CharacterDataNode:
mWarnings << CellMLTextViewConverterWarning(pDomNode.lineNumber(),
tr("Some character data was found in the original CellML file, but it is not known and cannot therefore be processed."));
mWarnings << CellMLTextViewConverterWarning(tr("Some character data was found in the original CellML file, but it is not known and cannot therefore be processed."),
pDomNode.lineNumber(),
pDomNode.columnNumber());

break;
}
Expand All @@ -2483,17 +2515,19 @@ void CellMLTextViewConverter::processUnsupportedNode(const QDomNode &pDomNode,
// The given node is known, but we don't support it, so consider it as an
// error or a warning, depending on the case

int lineNumber = pDomNode.lineNumber();
QString message = tr("A%1 '%2' element was found in the original CellML file, but it is not supported and cannot therefore be processed.").arg(pExtra)
.arg(pDomNode.prefix().isEmpty()?
pDomNode.localName():
pDomNode.prefix()+":"+pDomNode.localName());
int lineNumber = pDomNode.lineNumber();
int columnNumber = pDomNode.columnNumber();

if (pError) {
mErrorLine = lineNumber;
mErrorMessage = message;
mErrorLine = lineNumber;
mErrorColumn = columnNumber;
} else {
mWarnings << CellMLTextViewConverterWarning(lineNumber, message);
mWarnings << CellMLTextViewConverterWarning(message, lineNumber, columnNumber);
}

// Keep track of the give node, if it is a child of the model element and if
Expand Down
15 changes: 8 additions & 7 deletions src/plugins/editing/CellMLTextView/src/cellmltextviewconverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ namespace CellMLTextView {
class CellMLTextViewConverterWarning
{
public:
explicit CellMLTextViewConverterWarning(int pLine, const QString &pMessage);

int line() const;
explicit CellMLTextViewConverterWarning(const QString &pMessage,
int pLineNumber, int pColumnNumber);

QString message() const;
int lineNumber() const;
int columnNumber() const;

private:
int mLine;

QString mMessage;
int mLineNumber;
int mColumnNumber;
};

//==============================================================================
Expand All @@ -69,9 +70,9 @@ class CellMLTextViewConverter : public QObject

QString output() const;

QString errorMessage() const;
int errorLine() const;
int errorColumn() const;
QString errorMessage() const;

bool hasWarnings() const;
CellMLTextViewConverterWarnings warnings() const;
Expand Down Expand Up @@ -116,9 +117,9 @@ class CellMLTextViewConverter : public QObject

OutputType mLastOutputType;

QString mErrorMessage;
int mErrorLine;
int mErrorColumn;
QString mErrorMessage;

CellMLTextViewConverterWarnings mWarnings;

Expand Down
24 changes: 21 additions & 3 deletions src/plugins/editing/CellMLTextView/src/cellmltextviewplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,16 @@ QString CellMLTextViewPlugin::viewDefaultFileExtension() const

QWidget * CellMLTextViewPlugin::viewWidget(const QString &pFileName)
{
// Make sure that we are dealing with a CellML file
// Make sure that we are dealing with a CellML 1.0/1.1 file

if (!CellMLSupport::CellmlFileManager::instance()->cellmlFile(pFileName))
CellMLSupport::CellmlFile *cellmlFile = CellMLSupport::CellmlFileManager::instance()->cellmlFile(pFileName);
CellMLSupport::CellmlFile::Version cellmlVersion = cellmlFile->version();

if ( !cellmlFile
|| ( (cellmlVersion != CellMLSupport::CellmlFile::Cellml_1_0)
&& (cellmlVersion != CellMLSupport::CellmlFile::Cellml_1_1))) {
return 0;
}

// Update and return our CellML Text view widget using the given CellML
// file
Expand Down Expand Up @@ -458,7 +464,19 @@ int CellMLTextViewPlugin::importExport(const QStringList &pArguments,
errorMessage = QString("The file could not be opened (%1).").arg(Core::formatMessage(errorMessage));
}

// At this stage, we have the contents of the file, so we can do the
// At this stage, we have the contents of the file, so we need to check that
// it is a CellML 1.0/1.1 file if we want to import it

if (errorMessage.isEmpty() && pImport) {
CellMLSupport::CellmlFile::Version cellmlVersion = CellMLSupport::CellmlFile::fileContentsVersion(fileContents);

if ( (cellmlVersion != CellMLSupport::CellmlFile::Cellml_1_0)
&& (cellmlVersion != CellMLSupport::CellmlFile::Cellml_1_1)) {
errorMessage = QString("Only CellML 1.0/1.1 files can be imported.");
}
}

// We know that the file is a CellML 1.0/1.1 file, so we can do the
// import/export

if (errorMessage.isEmpty()) {
Expand Down

0 comments on commit 61f314e

Please sign in to comment.