Path: blob/devel/ElmerGUI/Application/src/operation.cpp
3203 views
/*****************************************************************************1* *2* Elmer, A Finite Element Software for Multiphysical Problems *3* *4* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *5* *6* This program is free software; you can redistribute it and/or *7* modify it under the terms of the GNU General Public License *8* as published by the Free Software Foundation; either version 2 *9* of the License, or (at your option) any later version. *10* *11* This program is distributed in the hope that it will be useful, *12* but WITHOUT ANY WARRANTY; without even the implied warranty of *13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *14* GNU General Public License for more details. *15* *16* You should have received a copy of the GNU General Public License *17* along with this program (in file fem/GPL-2); if not, write to the *18* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *19* Boston, MA 02110-1301, USA. *20* *21*****************************************************************************/2223/*****************************************************************************24* *25* ElmerGUI operation_t *26* *27*****************************************************************************28* *29* Authors: Mikko Lyly, Juha Ruokolainen and Peter Råback *30* Email: [email protected] *31* Web: http://www.csc.fi/elmer *32* Address: CSC - IT Center for Science Ltd. *33* Keilaranta 14 *34* 02101 Espoo, Finland *35* *36* Original Date: 15 Mar 2008 *37* *38*****************************************************************************/3940#include <iostream>41#include "operation.h"4243using namespace std;4445operation_t::operation_t()46{47next = 0;48type = 0;49angle = 0.0;50selected = 0;51select_set = 0;52}5354operation_t::~operation_t()55{56}5758void operation_t::appendToProject(QDomDocument *projectDoc, QDomElement *ops)59{60operation_t *p = this->next;61for(int index = 0; p; p = p->next, index++) {62QDomElement op = projectDoc->createElement("operation");63op.setAttribute("index", QString::number(index));64ops->appendChild(op);6566QDomElement type = projectDoc->createElement("type");67QDomText typeValue = projectDoc->createTextNode(QString::number(p->type));68type.appendChild(typeValue);69op.appendChild(type);7071QDomElement angle = projectDoc->createElement("angle");72QDomText angleValue = projectDoc->createTextNode(QString::number(p->angle));73angle.appendChild(angleValue);74op.appendChild(angle);7576QDomElement selected = projectDoc->createElement("selected");77selected.setAttribute("lists", QString::number(p->selected));78op.appendChild(selected);7980for(int list = 0; list < p->selected; list++) {81QDomElement selection = projectDoc->createElement("list");82QDomText selectionValue = projectDoc->createTextNode(QString::number(p->select_set[list]));83selection.appendChild(selectionValue);84selected.appendChild(selection);85}86}87}888990int operation_t::readFromProject(QDomDocument *projectDoc, QDomElement *ops)91{92operation_t *p = this->next;93operation_t *q = NULL;9495while(p != NULL) {96if(p->select_set != NULL)97delete [] p->select_set;98q = p->next;99if(p != NULL)100delete p;101p = q;102}103104int operations = 0;105q = this;106q->next = NULL;107108QDomElement op = ops->firstChildElement("operation");109110for( ; !op.isNull(); op = op.nextSiblingElement()) {111operations++;112113p = new operation_t;114p->next = NULL;115q->next = p;116q = p;117118p->type = op.firstChildElement("type").text().toInt();119p->angle = op.firstChildElement("angle").text().toDouble();120121QDomElement selected = op.firstChildElement("selected");122p->selected = selected.attribute("lists").toInt();123124p->select_set = new int[p->selected];125126QDomElement selection = selected.firstChildElement("list");127128for(int list = 0; !selection.isNull(); selection = selection.nextSiblingElement(), list++) {129if(list >= p->selected) {130cout << "Project loader: load operations: index out of bounds" << endl;131return 0;132}133p->select_set[list] = selection.text().toInt();134}135}136137return operations;138}139140141