1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "XmedDataModel.hxx"
21 #include <Basics_Utils.hxx>
22 #include "MEDCalcConstants.hxx"
25 // =================================================================
26 // XmedDataObject implementation
27 // =================================================================
30 XmedDataObject::XmedDataObject() : DataObject() {
33 /*! This function specified the localization of the object in the
34 * hierarchical organization
36 string XmedDataObject::getPath() {
38 string(_fieldHandler.meshname) + pathsep +
39 _getTypedFieldLabel();
43 void XmedDataObject::setFieldHandler(MEDCALC::FieldHandler fieldHandler) {
44 _fieldHandler = fieldHandler;
45 this->setLabel(string("it = ")+ToString(_fieldHandler.iteration));
47 MEDCALC::FieldHandler * XmedDataObject::getFieldHandler() {
48 return &_fieldHandler;
52 * This function implements the convention for displaying a fieldname
53 * characterized by its spatial discretisation type.
55 string XmedDataObject::_getTypedFieldLabel() {
56 // A field name could identify several MEDCoupling fields, that
57 // differ by their spatial discretization on the mesh (values on
58 // cells, values on nodes, ...). This spatial discretization is
59 // specified by the TypeOfField that is an integer value in this
65 if ( _fieldHandler.type < 0 ||
66 _fieldHandler.type >= NB_TYPE_OF_FIELDS ) {
67 return string("UNKNOWN");
69 string label(_fieldHandler.fieldname);
70 label +=" ("+string(mapTypeOfFieldLabel[_fieldHandler.type])+")";
75 // =================================================================
76 // XmedDataModel implementation
77 // =================================================================
81 * This function creates a XmedDataObject instance of DataObject and
82 * add the newly created instance to the model.
84 DataObject * XmedDataModel::newDataObject() {
85 XmedDataObject * dataObject = new XmedDataObject();
86 this->addDataObject(dataObject);
91 // =================================================================
92 // XmedDataProcessor implementation
93 // =================================================================
95 void XmedDataProcessor::preprocess(QStringList itemNameIdList) {
96 int maxsize = itemNameIdList.size();
97 _resultingFieldHandlerList = new MEDCALC::FieldHandlerList(maxsize);
98 _resultingFieldIdList = new MEDCALC::FieldIdList(maxsize);
102 MEDCALC::FieldHandlerList * XmedDataProcessor::getResultingFieldHandlerList() {
103 return _resultingFieldHandlerList._retn();
106 MEDCALC::FieldIdList * XmedDataProcessor::getResultingFieldIdList() {
107 return _resultingFieldIdList._retn();
110 void XmedDataProcessor::processDataObject(DataObject * dataObject) {
111 XmedDataObject * xmedDataObject = (XmedDataObject *)dataObject;
112 MEDCALC::FieldHandler fieldHandler = *(xmedDataObject->getFieldHandler());
113 int fieldId = fieldHandler.id;
115 int newsize = _objectIndex+1;
116 _resultingFieldHandlerList->length(newsize);
117 _resultingFieldIdList->length(newsize);
119 _resultingFieldHandlerList[_objectIndex] = fieldHandler;
120 _resultingFieldIdList[_objectIndex] = fieldId;
124 // Example (if needed) for creating the list of id from the lsite of handler
126 MEDCALC::FieldIdList_var fieldIdList = new MEDCALC::FieldIdList();
127 fieldIdList->length(fieldHandlerList->length());
128 for (int i=0; i<fieldHandlerList->length(); i++) {
129 MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[i];
130 fieldIdList[i] = fieldHandler.id;