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(), _presId(-1) {
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;
51 void XmedDataObject::setPresentationId(int presId) {
55 int XmedDataObject::getPresentationId() const { return _presId; }
59 * This function implements the convention for displaying a fieldname
60 * characterized by its spatial discretisation type.
62 string XmedDataObject::_getTypedFieldLabel() {
63 // A field name could identify several MEDCoupling fields, that
64 // differ by their spatial discretization on the mesh (values on
65 // cells, values on nodes, ...). This spatial discretization is
66 // specified by the TypeOfField that is an integer value in this
72 if ( _fieldHandler.type < 0 ||
73 _fieldHandler.type >= NB_TYPE_OF_FIELDS ) {
74 return string("UNKNOWN");
76 string label(_fieldHandler.fieldname);
77 label +=" ("+string(mapTypeOfFieldLabel[_fieldHandler.type])+")";
82 // =================================================================
83 // XmedDataModel implementation
84 // =================================================================
88 * This function creates a XmedDataObject instance of DataObject and
89 * add the newly created instance to the model.
91 DataObject * XmedDataModel::newDataObject() {
92 XmedDataObject * dataObject = new XmedDataObject();
93 this->addDataObject(dataObject);
98 // =================================================================
99 // XmedDataProcessor implementation
100 // =================================================================
102 void XmedDataProcessor::preprocess(QStringList itemNameIdList) {
103 int maxsize = itemNameIdList.size();
104 _resultingFieldHandlerList = new MEDCALC::FieldHandlerList(maxsize);
105 _resultingFieldIdList = new MEDCALC::FieldIdList(maxsize);
109 MEDCALC::FieldHandlerList * XmedDataProcessor::getResultingFieldHandlerList() {
110 return _resultingFieldHandlerList._retn();
113 MEDCALC::FieldIdList * XmedDataProcessor::getResultingFieldIdList() {
114 return _resultingFieldIdList._retn();
117 void XmedDataProcessor::processDataObject(DataObject * dataObject) {
118 XmedDataObject * xmedDataObject = (XmedDataObject *)dataObject;
119 MEDCALC::FieldHandler fieldHandler = *(xmedDataObject->getFieldHandler());
120 int fieldId = fieldHandler.id;
122 int newsize = _objectIndex+1;
123 _resultingFieldHandlerList->length(newsize);
124 _resultingFieldIdList->length(newsize);
126 _resultingFieldHandlerList[_objectIndex] = fieldHandler;
127 _resultingFieldIdList[_objectIndex] = fieldId;
131 // Example (if needed) for creating the list of id from the lsite of handler
133 MEDCALC::FieldIdList_var fieldIdList = new MEDCALC::FieldIdList();
134 fieldIdList->length(fieldHandlerList->length());
135 for (int i=0; i<fieldHandlerList->length(); i++) {
136 MEDCALC::FieldHandler fieldHandler = (*fieldHandlerList)[i];
137 fieldIdList[i] = fieldHandler.id;