Commit 8584e1af authored by Emmanuel Promayon's avatar Emmanuel Promayon
Browse files

On the way to fix some exception handling problems

parent 09911361
......@@ -4,7 +4,7 @@
targetNamespace="http://camitk.imag.fr/cepcoreschema"
elementFormDefault="qualified"
>
<!-- The liste of possible parameters is more limited than the
<!-- The list of possible parameters is more limited than the
list of possible QVariant in Qt.
Indeed, QVariant like QUrl, QVector2D, QVector4D and QMatrix4x4
are note recognized by QPropertyViewer...
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- merge using and manual edit -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://camitk.imag.fr/cepcoreschema"
targetNamespace="http://camitk.imag.fr/cepcoreschema"
elementFormDefault="qualified"
>
<xsd:simpleType name="ParameterType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="int" />
<xsd:enumeration value="bool"/>
<xsd:enumeration value="double" />
<xsd:enumeration value="QString"/>
<xsd:enumeration value="QDate"/>
<xsd:enumeration value="QTime"/>
<xsd:enumeration value="QColor" />
<xsd:enumeration value="QPoint" />
<xsd:enumeration value="QPointF"/>
<xsd:enumeration value="QVector3D"/>
<xsd:enumeration value="QVector4D"/>
</xsd:restriction>
</xsd:simpleType>
<!-- Contact.xsd -->
<!-- Email.xsd -->
<xsd:simpleType name="Email">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[^@]+@[^\.]+\..+"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="Contact">
<xsd:sequence>
<xsd:element name="email" type="Email" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<!-- ActionExtensions.xsd -->
<!-- ActionExtension.xsd -->
<!-- Actions.xsd -->
<!-- Action.xsd -->
<!-- ClassName.xsd -->
<xsd:simpleType name="ClassName">
<!-- A Class name should begin with an upper case letter and be followed
by lower or upper case letters.
-->
<xsd:restriction base="xsd:string">
<xsd:pattern value="[A-Z](([a-z])*|([A-Z])*)+"/>
</xsd:restriction>
</xsd:simpleType>
<!-- Classification.xsd -->
<!-- ItkFilter.xsd -->
<!-- ITKOutputType.xsd -->
<xsd:simpleType name="ITKOutputType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Same as Input"/>
<xsd:enumeration value="unsigned char"/>
<xsd:enumeration value="char"/>
<xsd:enumeration value="unsigned short"/>
<xsd:enumeration value="short"/>
<xsd:enumeration value="unsigned int"/>
<xsd:enumeration value="int" />
<xsd:enumeration value="long"/>
<xsd:enumeration value="double"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="ItkFilter">
<xsd:attribute name="outputType" type="ITKOutputType" use="required"/>
</xsd:complexType>
<xsd:complexType name="Classification">
<xsd:sequence>
<xsd:element name="family" type="xsd:string"/>
<xsd:element name="tag" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="itkFilter" type="ItkFilter" minOccurs = "0" maxOccurs = "1"/>
</xsd:sequence>
</xsd:complexType>
<!-- Parameters.xsd -->
<!-- Parameter.xsd -->
<xsd:complexType name="Parameter">
<xsd:attribute name="name" use="required" type="xsd:string"/>
<xsd:attribute name="type" use="required" type="ParameterType"/>
<xsd:attribute name="description" use="required" type="xsd:string"/>
<xsd:attribute name="unit" type="xsd:string"/>
<xsd:attribute name="defaultValue" type="xsd:string"/>
<xsd:attribute name="editable" type="xsd:boolean" default="true"/>
</xsd:complexType>
<xsd:complexType name="Parameters">
<xsd:sequence>
<xsd:element name="parameter" type="Parameter" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<!-- ActionProperties.xsd -->
<xsd:complexType name="ActionProperties">
<xsd:attribute name="modal" type="xsd:boolean"/>
<xsd:attribute name="embedded" type="xsd:boolean"/>
<xsd:attribute name="delayed" type="xsd:boolean"/>
</xsd:complexType>
<xsd:complexType name="Action">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="description" type="xsd:string"/>
<xsd:element name="component" type="ClassName"/>
<xsd:element name="classification" type="Classification"/>
<xsd:element name="parameters" type="Parameters" minOccurs="0"/>
<xsd:element name="properties" type="ActionProperties" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Actions">
<xsd:sequence>
<xsd:element name="action" type="Action" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<!-- DirectoryName.xsd -->
<xsd:simpleType name="DirectoryName">
<!-- A Directory must be in lower case and have at list one letter -->
<xsd:restriction base="xsd:string">
<xsd:pattern value="([a-z])+"/>
</xsd:restriction>
</xsd:simpleType>
<!-- Dependencies.xsd -->
<!-- Dependency.xsd -->
<!-- DependencyType.xsd -->
<xsd:simpleType name="DependencyType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="library"/>
<xsd:enumeration value="cepLibrary"/>
<xsd:enumeration value="component"/>
<xsd:enumeration value="action"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="Dependency">
<xsd:attribute name="type" type="DependencyType" use="required"/>
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="additional" type="xsd:string" use="optional"/>
</xsd:complexType>
<xsd:complexType name="Dependencies">
<xsd:sequence>
<xsd:element name="dependency" type="Dependency" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ActionExtension">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="description" type="xsd:string"/>
<xsd:element name="actions" type="Actions"/>
<xsd:element name="dependencies" type="Dependencies" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ActionExtensions">
<xsd:sequence>
<xsd:element name="actionExtension" type="ActionExtension" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<!-- Applications.xsd -->
<!-- Application.xsd -->
<xsd:complexType name="Application">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="description" type="xsd:string"/>
<xsd:element name="directoryName" type="DirectoryName"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Applications">
<xsd:sequence>
<xsd:element name="application" type="Application" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<!-- ComponentExtensions.xsd -->
<!-- ComponentExtension.xsd -->
<!-- Components.xsd -->
<!-- Component.xsd -->
<!-- Representation.xsd -->
<xsd:simpleType name="Representation">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Image"/>
<xsd:enumeration value="Mesh"/>
<xsd:enumeration value="None"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="Component">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="description" type="xsd:string"/>
<xsd:element name="representation" type="Representation"/>
<xsd:element name="properties" type="Parameters" minOccurs="0"/>
<xsd:element name="fileSuffix" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Components">
<xsd:sequence>
<xsd:element name="component" type="Component" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ComponentExtension">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="description" type="xsd:string"/>
<xsd:element name="components" type="Components"/>
<xsd:element name="dependencies" type="Dependencies" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ComponentExtensions">
<xsd:sequence>
<xsd:element name="componentExtension" type="ComponentExtension" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<!-- Libraries.xsd -->
<!-- Library.xsd -->
<xsd:complexType name="Library">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="description" type="xsd:string"/>
<xsd:element name="dependencies" type="Dependencies" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="static" type="xsd:boolean" default="true"/>
</xsd:complexType>
<xsd:complexType name="Libraries">
<xsd:sequence>
<xsd:element name="library" type="Library" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="cep" type="Cep"/>
<xsd:complexType name="Cep">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="contact" type="Contact"/>
<xsd:element name="description" type="xsd:string"/>
<xsd:element name="readme" type="xsd:string" minOccurs="0"/>
<xsd:element name="copyright" type="xsd:string" minOccurs="0"/>
<xsd:element name="actionExtensions" type="ActionExtensions" minOccurs="0"/>
<xsd:element name="applications" type="Applications" minOccurs="0"/>
<xsd:element name="componentExtensions" type="ComponentExtensions" minOccurs="0"/>
<xsd:element name="libraries" type="Libraries" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
<?xml version="1.0" encoding="utf-8"?>
<!-- Manual test from build dir $CAMITK_BUILD_DIR and sources in $CAMITK_SOURCE_DIR
export CAMITK_BUILD_DIR=~/Dev/CamiTK/build/camitk
export CAMITK_SOURCE_DIR=~/Dev/CamiTK/src/camitk
workingDir=$(mktemp --tmpdir -d camitk-test-tmp.XXXXXXXXXX)
cd ~/Dev/CamiTK/build/camitk/
bin/camitk-cepgenerator -f $CAMITK_SOURCE_DIR/sdk/libraries/cepcoreschema/testdata/autogenerated.xml -d $workingDir
cd $workingDir
CAMITK_DIR=$CAMITK_BUILD_DIR cmake -DCMAKE_MODULE_PATH:PATH="$CAMITK_SOURCE_DIR/sdk/cmake/modules;$CAMITK_SOURCE_DIR/sdk/cmake/modules/macros" ../str1234
make
rm -rf $workingDir
-->
<cep xmlns="http://camitk.imag.fr/cepcoreschema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://camitk.imag.fr/cepcoreschema Cep.xsd">
<name>Complete test CEP #1</name>
<contact>
<email>timc-camitk@univ-grenoble-alpes.fr</email>
</contact>
<description>This CEP is trying to achieve a complete test of all possible cepcoreschema element</description>
<readme>This CEP is trying to achieve a complete test of all possible cepcoreschema element. Probably some specific cases are not included, but it is our best shot</readme>
<copyright><![CDATA[/*****************************************************************************
$USERDEF_LICENCE_BEGIN$
CamiTK - Computer Assisted Medical Intervention ToolKit
(c) 2001-2017 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
Visit http://camitk.imag.fr for more information
This file is part of CamiTK.
$CEP_NAME$ is under the following licence:
This is the complete licence, it covers everything, everywhere, for everyone at everytime.
Please consider thatthis is just an example...
$USERDEF_LICENCE_END$
****************************************************************************/
]]></copyright>
<actionExtensions>
<actionExtension>
<name>Test Action Extension #1</name>
<description>Test the first action extension</description>
<actions>
<action>
<name>Test Action #1</name>
<description>Test a first action, for image component, with a lot of parameters</description>
<component>ImageComponent</component>
<classification>
<family>Complete Test Actions #1</family>
<tag>Test</tag>
<tag>Action #1</tag>
<tag>ImageComponent</tag>
<itkFilter outputType="Same as Input" />
</classification>
<parameters>
<parameter name="p1" type="int" description="This is p1" unit="unit 1" defaultValue="42" editable="true" />
<parameter name="p2" type="bool" description="This is p2" unit="unit 2" defaultValue="true" editable="true" />
<parameter name="p3" type="double" description="This is p3" unit="unit 3" defaultValue="42.42" editable="true" />
<parameter name="p4" type="QString" description="This is p4" unit="unit 4" defaultValue="Default value" editable="true" />
<parameter name="p5" type="QTime" description="This is p5" unit="unit 5" defaultValue="23:58" editable="true" />
<parameter name="p6" type="QColor" description="This is p6" unit="unit 6" defaultValue="#FF0000" editable="true" />
<parameter name="p7" type="QPoint" description="This is p7" unit="unit 7" defaultValue="42,84" editable="true" />
<parameter name="p8" type="QPointF" description="This is p8" unit="unit 8" defaultValue="42.42,84.84" editable="true" />
<parameter name="p9" type="QVector3D" description="This is p9" unit="unit 9" defaultValue="(42.0,0.0,-1.0)" editable="true" />
<parameter name="p10" type="QVector4D" description="This is p10" unit="unit 10" defaultValue="42.0,0.0,-1.0,84.42)" editable="true" />
</parameters>
<properties modal="false" embedded="true" delayed="false" />
</action>
<action>
<name>Test Action #2</name>
<description>Test a second action, with no tag, no component, and with just one non editable parameters</description>
<component></component>
<classification>
<family>Complete Test Actions #1</family>
<!-- no tag... -->
</classification>
<parameters>
<parameter name="No Tag Action" type="bool" description="A &lt;b>small&lt;/b> description with &lt;i>hyper text&lt;i>" unit="€" defaultValue="false" editable="false"/>
</parameters>
<properties modal="true" embedded="false" delayed="false" />
</action>
<action>
<name>Test Action #3</name>
<description>Test a third action, with non existing "Mesh Component", and with lots of parameters and defautl editable</description>
<component></component>
<classification>
<family>Complete Test Actions #1</family>
<tag>Mesh Component</tag>
</classification>
<parameters>
<parameter name="p1" type="int" description="This is p1" unit="unit 1" defaultValue="42"/>
<parameter name="p2" type="bool" description="This is p2" unit="unit 2" defaultValue="true"/>
<parameter name="p3" type="double" description="This is p3" unit="unit 3" defaultValue="42.42"/>
<parameter name="p4" type="QString" description="This is p4" unit="unit 4" defaultValue="Default value"/>
<parameter name="p5" type="QTime" description="This is p5" unit="unit 5" defaultValue="23:58"/>
<parameter name="p6" type="QColor" description="This is p6" unit="unit 6" defaultValue="#FF0000"/>
<parameter name="p7" type="QPoint" description="This is p7" unit="unit 7" defaultValue="42,84"/>
<parameter name="p8" type="QPointF" description="This is p8" unit="unit 8" defaultValue="42.42,84.84"/>
<parameter name="p9" type="QVector3D" description="This is p9" unit="unit 9" defaultValue="(42.0,0.0,-1.0)"/>
<parameter name="p10" type="QVector4D" description="This is p10" unit="unit 10" defaultValue="42.0,0.0,-1.0,84.42)"/>
</parameters>
<properties modal="true" embedded="false" delayed="false" />
</action>
</actions>
<dependencies>
<dependency type="library" name="str1234" additional="qtpropertybrowser" />
<dependency type="library" name="itk"/>
</dependencies>
</actionExtension>
</actionExtensions>
<applications>
<application>
<name>str1234</name>
<description>str1234</description>
<directoryName>str1234</directoryName>
</application>
</applications>
<componentExtensions>
<componentExtension>
<name>str1234</name>
<description>str1234</description>
<components>
<component>
<name>str1234</name>
<description>str1234</description>
<representation>Image</representation>
<properties>
<parameter name="str1234" type="int" description="str1234" unit="str1234" defaultValue="str1234" editable="true" />
</properties>
<fileSuffix>str1234</fileSuffix>
</component>
</components>
<dependencies>
<!-- <dependency type="library" name="str1234" additional="str1234" /> -->
</dependencies>
</componentExtension>
</componentExtensions>
<libraries>
<library static="true">
<name>str1234</name>
<description>str1234</description>
<dependencies>
<dependency type="library" name="str1234" additional="str1234" />
</dependencies>
</library>
</libraries>
</cep>
#!/bin/bash
readAndInsert() {
while read -r line
do
if [[ $line =~ xsd:include ]]; then
file=$(echo $line | sed -e 's/.*="\(.*\)".*/\1/g')
echo "<!-- $file -->"
readAndInsert $file
else
if [ "$2" == "top" ]; then
echo $line
else
case $line in
*encoding*)
;;
*xsd\:schema*)
;;
*http://camitk.imag.fr/cepcoreschema*)
;;
elementFormDefault*)
;;
\>)
;;
*)
echo $line
;;
esac
fi
fi
done < $1
}
readAndInsert $1 top
......@@ -31,6 +31,7 @@
// includes from std
#include <iostream>
#include <stdexcept>
// includes from Qt
#include <QTextStream>
......@@ -77,30 +78,28 @@ CepGenerator::~CepGenerator() {
}
}
void CepGenerator::setXmlFileName(QString xmlFileName) throw (QString) {
void CepGenerator::setXmlFileName(QString xmlFileName) {
QFileInfo xmlFile(xmlFileName);
if ((! xmlFile.exists()) || (! xmlFile.isFile())) {
QString msg = "Exception from Cep generation: \n The file " + xmlFileName + " does not exist or is not a file...\n";
throw (msg);
throw "Exception from Cep generation: \n The file " + xmlFileName + " does not exist or is not a file...\n";
}
this->xmlFileName = xmlFile;
}
void CepGenerator::setDevDirectoryName(QString devDirectoryName) throw (QString) {
void CepGenerator::setDevDirectoryName(QString devDirectoryName) {
devDirectoryName = devDirectoryName + "/";
QFileInfo devDir(devDirectoryName);
if ( ! devDir.isDir()) {
QString msg = "Exception from Cep generation: \n The path " + devDirectoryName + " is not a directory\n";
throw (msg);
throw "Exception from Cep generation: \n The path " + devDirectoryName + " is not a directory\n";
}
this->devDirectoryName = devDir.absoluteDir();
}
void CepGenerator::createDomTree() throw (QString) {
void CepGenerator::createDomTree() {
std::cout << "Creating Dom Tree..." << std::endl;
std::string xmlFileStr = this->xmlFileName.canonicalFilePath().toStdString();
......@@ -108,13 +107,13 @@ void CepGenerator::createDomTree() throw (QString) {
this->domCep = cep(xmlFileStr, xml_schema::flags::dont_validate);
}
catch (const xml_schema::exception& e) {
std::cout << "Error Parsing XML file:" << std::endl;
std::cout << e << std::endl;
throw QString(e.what());
// std::cout << "Error Parsing XML file:" << std::endl;
// std::cout << e << std::endl;
throw std::invalid_argument(e.what());
}
}
void CepGenerator::generateDirectoryTree() throw (QString) {
void CepGenerator::generateDirectoryTree() {
std::cout << "Generating Directory Tree..." << std::endl;
// -------------------- Create a sub-directory with the CEP name
......@@ -182,8 +181,7 @@ void CepGenerator::serializeManifest(QString fileName) {
QFile xmlFile(xmlFileInfo.absoluteFilePath());
if (! xmlFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
QString msg = "Exception from cep file generation \n Cannot write on file " + xmlFileInfo.absoluteFilePath() + "\n";
throw msg;
throw "Exception from cep file generation \n Cannot write on file " + xmlFileInfo.absoluteFilePath() + "\n";
}
// Serialization of domCep to a std::string
......@@ -232,8 +230,7 @@ void CepGenerator::generateGlobalCMakeLists() {
cmakelistsOutFileInfo.setFile(currentDirectory.absolutePath(), "CMakeLists.txt");
QFile cmakelistsOutFile(cmakelistsOutFileInfo.absoluteFilePath());
if (! cmakelistsOutFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
QString msg = "Exception from cep file generation \n Cannot write on file " + cmakelistsOutFileInfo.absoluteFilePath() + "\n";
throw msg;
throw "Exception from cep file generation \n Cannot write on file " + cmakelistsOutFileInfo.absoluteFilePath() + "\n";
}
QTextStream out(&cmakelistsOutFile);
......@@ -284,8 +281,7 @@ void CepGenerator::generateCopyright() {
copyrightOutFileInfo.setFile(currentDirectory.absolutePath(), "COPYRIGHT");
QFile copyrightOutFile(copyrightOutFileInfo.absoluteFilePath());
if (! copyrightOutFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
QString msg = "Exception from cep file generation \n Cannot write on file " + copyrightOutFileInfo.absoluteFilePath() + "\n";
throw msg;
throw "Exception from cep file generation \n Cannot write on file " + copyrightOutFileInfo.absoluteFilePath() + "\n";
}
QTextStream out(&copyrightOutFile);
......@@ -314,8 +310,7 @@ void CepGenerator::generateReadme() {
readmeOutFileInfo.setFile(currentDirectory.absolutePath(), "README");
QFile readmeOutFile(readmeOutFileInfo.absoluteFilePath());
if (! readmeOutFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
QString msg = "Exception from cep file generation \n Cannot write on file " + readmeOutFileInfo.absoluteFilePath() + "\n";
throw msg;
throw "Exception from cep file generation \n Cannot write on file " + readmeOutFileInfo.absoluteFilePath() + "\n";
}
QTextStream out(&readmeOutFile);
......@@ -468,7 +463,7 @@ void CepGenerator::generateExtensions() {
}
void CepGenerator::process() throw (QString) {
void CepGenerator::process() {
setLicence();
generateDirectoryTree();
createComponentExtensionDoms();
......
......@@ -87,16 +87,16 @@ public :
~CepGenerator();
/// call all methods to generate the CEP from the DomTree.
void process() throw (QString);
void process();
/// Set the input XML CEP manifest (ant check its xml validity)
virtual void setXmlFileName(QString xmlFileName) throw (QString);
virtual void setXmlFileName(QString xmlFileName);
/// Create the DOM attribute domCep from the XML CEP manifest
virtual void createDomTree() throw (QString);
virtual void createDomTree();
/// Where to generate the CEP directories and files
virtual void setDevDirectoryName(QString devDirectoryName) throw (QString);
virtual void setDevDirectoryName(QString devDirectoryName);
/** XML DOM Element create by CodeSynthesis
gets the cep instance contains all of the informations of the xml file
......@@ -131,7 +131,7 @@ protected:
---- Manifest.xml
---- README
*/
virtual void generateDirectoryTree() throw(QString);
virtual void generateDirectoryTree();
/** @{ Helping Functions for generateDirectoryTree */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment