Commit a416e2bb authored by promayon's avatar promayon
Browse files

FIXED enforce using C locale (always use . for decimal point - not comma even...

FIXED enforce using C locale (always use . for decimal point - not comma even if the locale says differently) (undocumented bug)
FIXED PhysicalModel Component displaying Pressure and Rotation using Arrows (fix undocumented crash when trying to view .lml with Pressure or Rotation)
FIXED no more warning from moc with Sofa Widget (ui generated files are not Q_OBJECT)
FIXED remaining memory error (mismatched delete) in PML/LML
NEW units in LML



git-svn-id: svn+ssh://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk@251 ec899d31-69d1-42ba-9299-647d76f65fb3
parent 516953cc
......@@ -12,8 +12,11 @@
# Usual values for unix are /usr or /usr/local
#
# Therefore, in order to produce a proper deb for system-wide install, you can run something like:
# svn checkout svn://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk
# mkdir build
# cd tmp
# mkdir camitk
# cd camitk
# svn checkout svn://scm.forge.imag.fr/var/lib/gforge/chroot/scmrepos/svn/camitk/trunk/camitk
# mkdir build
# cd build
# cmake -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo -DCAMITK_INSTALL_ROOT:PATH=/usr -DTOOL_CORESCHEMA:BOOL=ON -DTOOL_LML:BOOL=TRUE -DTOOL_PML:BOOL=TRUE -DMML_GENERATE_GUI:BOOL=ON -DTOOL_MML:BOOL=TRUE -DMML_GENERATE_XSD_LIB:BOOL=TRUE -DACTION_ITKSEGMENTATION:BOOL=TRUE -DACTION_ITKFILTERS:BOOL=TRUE -DAPPLICATION_WIZARD:BOOL=TRUE -DCOMPONENT_VTKMESH:BOOL=TRUE -DCOMPONENT_DICOM:BOOL=TRUE -DCOMPONENT_ITKIMAGE:BOOL=TRUE -DCOMPONENT_PHYSICALMODEL:BOOL=TRUE -DCOMPONENT_MML:BOOL=TRUE -DAPIDOC_GENERATE_FOR_CAMITK_CORE:BOOL=TRUE ../camitk
# make camitk_package
......
......@@ -345,8 +345,7 @@ void LoadsManager::addDecoration(Atom *a, Load *ld, double time, double defaultS
deco->setColor(0.6, 0.88, 0.59);
}
}
if (ld->getType() == "Force") {
else { // "Force", "Rotation", "Pressure"...
deco = myPMManagerDC->getDC(a)->getDecoration("Force", GeometricObject::ARROW);
deco->setColor(1.0, 0.3, 0.15);
}
......
......@@ -26,6 +26,7 @@
#include <PressureUnit.h>
/// initializing the static class member
PressureUnit PressureUnit::PA("kPa"); /**kiloPascal*/
PressureUnit PressureUnit::KPA("kPa"); /**kiloPascal*/
PressureUnit PressureUnit::MMHG("mmHg"); /**Mercure millimeters*/
......@@ -37,6 +37,8 @@
class PressureUnit : public Unit {
public:
/// Pascal
static PressureUnit PA;
/// kiloPascal
static PressureUnit KPA;
/// Millimeters of mercure
......
......@@ -26,7 +26,8 @@
#include <TranslationUnit.h>
// initializing the static class member
TranslationUnit TranslationUnit::M("m"); /**meters*/
TranslationUnit TranslationUnit::MM("mm"); /**millimeters*/
TranslationUnit TranslationUnit::MICRO_M("m"); /**micrometers*/
TranslationUnit TranslationUnit::MICRO_M("µm"); /**micrometers*/
TranslationUnit TranslationUnit::NM("nm"); /**nanometers*/
......@@ -38,6 +38,8 @@
class TranslationUnit : public Unit {
public:
/// millimeters
static TranslationUnit M;
/// millimeters
static TranslationUnit MM;
/// micro meters
......@@ -46,7 +48,7 @@ public:
static TranslationUnit NM;
private:
TranslationUnit(const char * n) {unitString = n;}
TranslationUnit(std::string n) {unitString = n;}
};
......
......@@ -39,6 +39,7 @@ class Unit;
*/
class Unit {
public:
virtual ~Unit() {};
std::string getUnitName() { return unitString; };
protected:
std::string unitString;
......
......@@ -32,6 +32,7 @@
#include "XMLLoads.h"
#include <stdexcept>
#include "Translation.h"
#include "TranslationUnit.h"
......@@ -44,15 +45,15 @@
//---------------------- constructor --------------------
XMLLoads::XMLLoads() {
l = NULL;
l = NULL;
}
XMLLoads::XMLLoads(std::string fileName) : l(NULL) {
xmlRead(fileName);
xmlRead(fileName);
}
XMLLoads::XMLLoads(std::string fileName, Loads * allLoads) : l(allLoads){
xmlRead(fileName);
XMLLoads::XMLLoads(std::string fileName, Loads * allLoads) : l(allLoads) {
xmlRead(fileName);
}
//---------------------- destructor --------------------
......@@ -61,239 +62,244 @@ XMLLoads::~XMLLoads() {
//---------------------- getLoads --------------------
Loads * XMLLoads::getLoads() {
return l;
return l;
}
//---------------------- addLoad --------------------
void XMLLoads::addLoad(Load *load) {
if (!l)
l = new Loads(); // create empty list
if (!l)
l = new Loads(); // create empty list
l->addLoad(load);
l->addLoad(load);
}
//---------------------- xmlRead --------------------
void XMLLoads::xmlRead(std::string fileName) {
xmlFile = fileName.c_str();
xmlFile = fileName.c_str();
// the resulting document tree
xmlDocPtr doc;
//the pointer to the root node of the document
xmlNodePtr root;
// Set the locale to C for using dot as decimal point dispite locale
// Set utf8 for output to enforce using utf8 strings.
bool statusOk = setlocale(LC_CTYPE, "C.UTF-8");
statusOk = statusOk && setlocale(LC_NUMERIC, "C.UTF-8");
statusOk = statusOk && setlocale(LC_TIME, "C.UTF-8");
doc = xmlParseFile(xmlFile);
// french is: "fr_FR.UTF8"
if (!statusOk)
throw std::runtime_error("Could not set the locale to C. This is mandatory to enforce using dot as decimal separator (platform independency).");
if (doc == NULL) {
std::cerr << "Failed to open " << xmlFile << std::endl;
return ;
}
// the resulting document tree
xmlDocPtr doc;
//the pointer to the root node of the document
xmlNodePtr root;
root = xmlDocGetRootElement(doc);
doc = xmlParseFile(xmlFile);
if (root == NULL) {
std::cerr << "empty document" << std::endl;
xmlFreeDoc(doc);
return ;
}
if (doc == NULL) {
std::cerr << "Failed to open " << xmlFile << std::endl;
return ;
}
//read the xml tree root, verify if it is a loads elemnt
if (xmlStrcmp(root->name, (const xmlChar*)"loads")){
std::cerr << "failed to read the xml tree" << std::endl;
xmlFreeDoc(doc);
return ;
}
root = xmlDocGetRootElement(doc);
//parse the rest of the xml tree
for (xmlNodePtr child = root->xmlChildrenNode; child != NULL; child = child->next)
{
if (!xmlStrcmp(child->name, (const xmlChar*)"load"))
if (!parseElement(child))
std::cerr << "failed to read xml element" << std::endl;
}
if (root == NULL) {
std::cerr << "empty document" << std::endl;
xmlFreeDoc(doc);
return ;
}
//free the xml
xmlFreeDoc(doc);
//read the xml tree root, verify if it is a loads elemnt
if (xmlStrcmp(root->name, (const xmlChar*)"loads")) {
std::cerr << "failed to read the xml tree" << std::endl;
xmlFreeDoc(doc);
return ;
}
//parse the rest of the xml tree
for (xmlNodePtr child = root->xmlChildrenNode; child != NULL; child = child->next) {
if (!xmlStrcmp(child->name, (const xmlChar*)"load"))
if (!parseElement(child))
std::cerr << "failed to read xml element" << std::endl;
}
//free the xml
xmlFreeDoc(doc);
xmlCleanupParser();
xmlCleanupParser();
xmlMemoryDump();
xmlMemoryDump();
}
// ------------------ parse Element ------------------
bool XMLLoads::parseElement(xmlNodePtr elem) {
Load * currentL;
//get the type of load
xmlChar *ptype = xmlGetProp(elem, (const xmlChar*) "type");
if (ptype) {
//create a new instance switch the type
if (!xmlStrcmp(ptype, (const xmlChar*)"Translation"))
currentL = new Translation();
else
if (!xmlStrcmp(ptype, (const xmlChar*)"Rotation"))
currentL = new Rotation();
else
if (!xmlStrcmp(ptype, (const xmlChar*)"Force"))
currentL = new Force();
Load * currentL;
//get the type of load
xmlChar *ptype = xmlGetProp(elem, (const xmlChar*) "type");
if (ptype) {
//create a new instance switch the type
if (!xmlStrcmp(ptype, (const xmlChar*)"Translation"))
currentL = new Translation();
else
currentL = new Pressure();
//parse th load children to get its properties
for (xmlNodePtr child = elem->xmlChildrenNode; child != NULL; child = child->next) {
if (!xmlStrcmp(child->name, (const xmlChar*)"appliedTo"))
readLoadAppliedTo(child, currentL);
if (!xmlStrcmp(child->name, (const xmlChar*)"valueEvent"))
readLoadValueEvent(child, currentL);
if (!xmlStrcmp(ptype, (const xmlChar*)"Rotation"))
currentL = new Rotation();
else
if (!xmlStrcmp(ptype, (const xmlChar*)"Force"))
currentL = new Force();
else
currentL = new Pressure();
//parse th load children to get its properties
for (xmlNodePtr child = elem->xmlChildrenNode; child != NULL; child = child->next) {
if (!xmlStrcmp(child->name, (const xmlChar*)"appliedTo"))
readLoadAppliedTo(child, currentL);
if (!xmlStrcmp(child->name, (const xmlChar*)"valueEvent"))
readLoadValueEvent(child, currentL);
if (!xmlStrcmp(child->name, (const xmlChar*)"direction"))
readLoadDirection(child, currentL);
if (!xmlStrcmp(child->name, (const xmlChar*)"unit"))
readLoadUnit(child, currentL);
}
if (!xmlStrcmp(child->name, (const xmlChar*)"direction"))
readLoadDirection(child, currentL);
this->addLoad(currentL);
if (!xmlStrcmp(child->name, (const xmlChar*)"unit"))
readLoadUnit(child, currentL);
xmlFree(ptype);
return true;
}
this->addLoad(currentL);
xmlFree(ptype);
return true;
}
else
return false;
else
return false;
}
// ------------------ readLoadAppliedTo ------------------
void XMLLoads::readLoadAppliedTo(xmlNodePtr elem, Load *currentLoad)
{
xmlChar * pData = xmlNodeGetContent(elem);
void XMLLoads::readLoadAppliedTo(xmlNodePtr elem, Load *currentLoad) {
xmlChar * pData = xmlNodeGetContent(elem);
if (pData)
currentLoad->addTarget(std::string((char*)pData));
if (pData)
currentLoad->addTarget(std::string((char*)pData));
xmlFree(pData);
xmlFree(pData);
}
// ------------------ readLoadValueEvent ------------------
void XMLLoads::readLoadValueEvent(xmlNodePtr elem, Load *currentLoad)
{
double value = 0.0, date = 0.0;
void XMLLoads::readLoadValueEvent(xmlNodePtr elem, Load *currentLoad) {
double value = 0.0, date = 0.0;
xmlChar * pDate = xmlGetProp(elem, (const xmlChar*)"date");
xmlChar * pDate = xmlGetProp(elem, (const xmlChar*)"date");
if (pDate)
date = atof((const char*)pDate);
if (pDate)
date = atof((const char*)pDate);
xmlChar * pValue = xmlGetProp(elem, (const xmlChar*)"value");
xmlChar * pValue = xmlGetProp(elem, (const xmlChar*)"value");
if (pValue)
value = atof((const char*)pValue);
if (pValue)
value = atof((const char*)pValue);
if (pDate && pValue)
currentLoad->addEvent(new ValueEvent(value, date));
if (pDate && pValue)
currentLoad->addEvent(new ValueEvent(value, date));
xmlFree(pDate);
xmlFree(pValue);
xmlFree(pDate);
xmlFree(pValue);
}
// ------------------ readLoadDirection ------------------
void XMLLoads::readLoadDirection(xmlNodePtr elem, Load *currentLoad)
{
Direction dir;
void XMLLoads::readLoadDirection(xmlNodePtr elem, Load *currentLoad) {
Direction dir;
xmlChar * px = xmlGetProp(elem, (const xmlChar*)"x");
xmlChar * px = xmlGetProp(elem, (const xmlChar*)"x");
if (px){
if (!xmlStrcmp(px, (const xmlChar*)"NULL"))
dir.setNullX();
else
dir.setX(atof((char *) px));
}
if (px) {
if (!xmlStrcmp(px, (const xmlChar*)"NULL"))
dir.setNullX();
else
dir.setX(atof((char *) px));
}
xmlChar * py = xmlGetProp(elem, (const xmlChar*)"y");
xmlChar * py = xmlGetProp(elem, (const xmlChar*)"y");
if (py){
if (!xmlStrcmp(py, (const xmlChar*)"NULL"))
dir.setNullY();
else
dir.setY(atof((char *) py));
}
if (py) {
if (!xmlStrcmp(py, (const xmlChar*)"NULL"))
dir.setNullY();
else
dir.setY(atof((char *) py));
}
xmlChar * pz = xmlGetProp(elem, (const xmlChar*)"z");
xmlChar * pz = xmlGetProp(elem, (const xmlChar*)"z");
if (pz){
if (!xmlStrcmp(pz, (const xmlChar*)"NULL"))
dir.setNullZ();
else
dir.setZ(atof((char *) pz));
}
if (pz) {
if (!xmlStrcmp(pz, (const xmlChar*)"NULL"))
dir.setNullZ();
else
dir.setZ(atof((char *) pz));
}
if (px || py || pz)
currentLoad->setDirection(dir);
if (px || py || pz)
currentLoad->setDirection(dir);
xmlFree(px);
xmlFree(py);
xmlFree(pz);
xmlFree(px);
xmlFree(py);
xmlFree(pz);
}
// ------------------ readLoadUnit ------------------
void XMLLoads::readLoadUnit(xmlNodePtr elem, Load *currentLoad)
{
xmlChar * pData = xmlNodeGetContent(elem);
if (currentLoad->getType() == "Translation") {
//unit de type TranslationUnit
if (!xmlStrcmp(pData, (const xmlChar*)"mm")) {
currentLoad->setUnit(TranslationUnit::MM);
}
else
if (!xmlStrcmp(pData, (const xmlChar*)"microm")) {
currentLoad->setUnit(TranslationUnit::MICRO_M);
}
else
if (!xmlStrcmp(pData, (const xmlChar*)"nm")) {
currentLoad->setUnit(TranslationUnit::NM);
}
}
else
if (currentLoad->getType() == "Force") {
if (!xmlStrcmp(pData, (const xmlChar*)"N")) {
currentLoad->setUnit(ForceUnit::N);
}
else
if (!xmlStrcmp(pData, (const xmlChar*)"kN")) {
currentLoad->setUnit(ForceUnit::KN);
void XMLLoads::readLoadUnit(xmlNodePtr elem, Load *currentLoad) {
xmlChar * pData = xmlNodeGetContent(elem);
if (currentLoad->getType() == "Translation") {
//unit de type TranslationUnit
if (!xmlStrcmp(pData, (const xmlChar*)"mm")) {
currentLoad->setUnit(TranslationUnit::MM);
}
else
if (!xmlStrcmp(pData, (const xmlChar*)"pN")) {
currentLoad->setUnit(ForceUnit::PN);
}
if (!xmlStrcmp(pData, (const xmlChar*)"microm")) {
currentLoad->setUnit(TranslationUnit::MICRO_M);
}
else
if (!xmlStrcmp(pData, (const xmlChar*)"nm")) {
currentLoad->setUnit(TranslationUnit::NM);
}
}
else
if (currentLoad->getType() == "Pressure") {
if (!xmlStrcmp(pData, (const xmlChar*)"kPa")) {
currentLoad->setUnit(PressureUnit::KPA);
if (currentLoad->getType() == "Force") {
if (!xmlStrcmp(pData, (const xmlChar*)"N")) {
currentLoad->setUnit(ForceUnit::N);
}
else
if (!xmlStrcmp(pData, (const xmlChar*)"kN")) {
currentLoad->setUnit(ForceUnit::KN);
}
else
if (!xmlStrcmp(pData, (const xmlChar*)"pN")) {
currentLoad->setUnit(ForceUnit::PN);
}
}
else
if (!xmlStrcmp(pData, (const xmlChar*)"mmHg")) {
currentLoad->setUnit(PressureUnit::MMHG);
}
}
else
if (currentLoad->getType() == "Rotation") {
if (!xmlStrcmp(pData, (const xmlChar*)"radians")) {
currentLoad->setUnit(RotationUnit::RAD);
}
else
if (!xmlStrcmp(pData, (const xmlChar*)"degrees")) {
currentLoad->setUnit(RotationUnit::DEG);
if (currentLoad->getType() == "Pressure") {
if (!xmlStrcmp(pData, (const xmlChar*)"kPa")) {
currentLoad->setUnit(PressureUnit::KPA);
}
else
if (!xmlStrcmp(pData, (const xmlChar*)"mmHg")) {
currentLoad->setUnit(PressureUnit::MMHG);
}
}
}
xmlFree(pData);
else
if (currentLoad->getType() == "Rotation") {
if (!xmlStrcmp(pData, (const xmlChar*)"radians")) {
currentLoad->setUnit(RotationUnit::RAD);
}
else
if (!xmlStrcmp(pData, (const xmlChar*)"degrees")) {
currentLoad->setUnit(RotationUnit::DEG);
}
}
xmlFree(pData);
}
......@@ -93,7 +93,6 @@ if(MML_SOFA_SUPPORT)
)
qt4_wrap_ui(sofa_UIS_H ${sofa_UIS})
qt4_wrap_cpp(sofa_MOC_UI ${sofa_UIS_H})
qt4_wrap_cpp(sofa_MOCS ${sofa_MOC_SRCS})
set(sofa_QT_SRC
simulator/simulators/Sofa/SofaWidget.cpp
......
......@@ -67,7 +67,7 @@ void SofaWidget::applyChanges()
{
int r=QMessageBox::warning(this,tr("Apply scene changes"),tr("This will save current changes in scn file and reload simulation.\n Not saved data will be lost."),QMessageBox::Ok,QMessageBox::Cancel);
if (r == QMessageBox::Ok) {
WriteScn(tr(scnFile.c_str()));
writeScn(tr(scnFile.c_str()));
emit reload();
}
}
......@@ -78,7 +78,7 @@ void SofaWidget::runSofa()
//save file into temporary file
QString temp=tr(scnFileTemp.c_str()); //TODO use a temp directory?
WriteScn(temp);
writeScn(temp);
//run Sofa
QProcess *p = new QProcess(this);
......@@ -100,7 +100,7 @@ void SofaWidget::runSofa()
}
//--------------- WriteScn ---------------------------------
void SofaWidget::WriteScn(QString path)
void SofaWidget::writeScn(QString path)
{
QFile file(path) ;
if (file.open( QFile::WriteOnly))
......
......@@ -44,8 +44,10 @@ class SofaWidget: public SimulatorWidget {
/// destructor
~SofaWidget();
/// write text of QTextEdit into file in path
void WriteScn(QString path);
/** write text typed in the highlighted QTextEdit into a scn file
* @param path filename to use
*/
void writeScn(QString path);
public slots:
......@@ -57,9 +59,8 @@ class SofaWidget: public SimulatorWidget {
void sofaExited();
private:
/// the ui widget designed in qtdesigner
Ui::SofaWidget ui;
Ui::ui_SofaWidget ui;
/// sofa scn file
std::string scnFile;
/// temp copy of scn filr
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SofaWidget</class>
<widget class="QWidget" name="SofaWidget">
<class>ui_SofaWidget</class>
<widget class="QWidget" name="ui_SofaWidget">
<property name="geometry">
<rect>
<x>0</x>
......
......@@ -27,6 +27,8 @@
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <stdexcept>
// Other includes
#include "PhysicalModel.h"
//#include "Object3D.h"
......@@ -79,11 +81,6 @@ void PhysicalModel::setProgress ( const float donePercentage ) {
void PhysicalModel::clear() {
name = "";