1 // Copyright (C) 2007-2013 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.
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>
24 // =================================================================
25 // XmedDataObject implementation
26 // =================================================================
29 XmedDataObject::XmedDataObject() : DataObject() {
32 /*! This function specified the localization of the object in the
33 * hierarchical organization
35 string XmedDataObject::getPath() {
37 string(_fieldHandler.meshname) + pathsep +
38 _getTypedFieldLabel();
42 void XmedDataObject::setFieldHandler(MEDOP::FieldHandler fieldHandler) {
43 _fieldHandler = fieldHandler;
44 this->setLabel(string("it = ")+ToString(_fieldHandler.iteration));
46 MEDOP::FieldHandler * XmedDataObject::getFieldHandler() {
47 return &_fieldHandler;
50 const char * XmedDataObject::mapTypeOfFieldLabel[XmedDataObject::NB_TYPE_OF_FIELDS] =
51 {"ON_CELLS", "ON_NODES", "ON_GAUSS_PT", "ON_GAUSS_NE" };
53 * This function implements the convention for displaying a fieldname
54 * characterized by its spatial discretisation type.
56 string XmedDataObject::_getTypedFieldLabel() {
57 // A field name could identify several MEDCoupling fields, that
58 // differ by their spatial discretization on the mesh (values on
59 // cells, values on nodes, ...). This spatial discretization is
60 // specified by the TypeOfField that is an integer value in this
66 if ( _fieldHandler.type < 0 ||
67 _fieldHandler.type >= XmedDataObject::NB_TYPE_OF_FIELDS ) {
68 return string("UNKNOWN");
70 string label(_fieldHandler.fieldname);
71 label +=" ("+string(mapTypeOfFieldLabel[_fieldHandler.type])+")";
76 // =================================================================
77 // XmedDataModel implementation
78 // =================================================================
82 * This function creates a XmedDataObject instance of DataObject and
83 * add the newly created instance to the model.
85 DataObject * XmedDataModel::newDataObject() {
86 XmedDataObject * dataObject = new XmedDataObject();
87 this->addDataObject(dataObject);
92 // =================================================================
93 // XmedDataProcessor implementation
94 // =================================================================
96 void XmedDataProcessor::preprocess(QStringList itemNameIdList) {
97 int maxsize = itemNameIdList.size();
98 _resultingFieldHandlerList = new MEDOP::FieldHandlerList(maxsize);
99 _resultingFieldIdList = new MEDOP::FieldIdList(maxsize);
103 MEDOP::FieldHandlerList * XmedDataProcessor::getResultingFieldHandlerList() {
104 return _resultingFieldHandlerList._retn();
107 MEDOP::FieldIdList * XmedDataProcessor::getResultingFieldIdList() {
108 return _resultingFieldIdList._retn();
111 void XmedDataProcessor::processDataObject(DataObject * dataObject) {
112 XmedDataObject * xmedDataObject = (XmedDataObject *)dataObject;
113 MEDOP::FieldHandler fieldHandler = *(xmedDataObject->getFieldHandler());
114 int fieldId = fieldHandler.id;
116 int newsize = _objectIndex+1;
117 _resultingFieldHandlerList->length(newsize);
118 _resultingFieldIdList->length(newsize);
120 _resultingFieldHandlerList[_objectIndex] = fieldHandler;
121 _resultingFieldIdList[_objectIndex] = fieldId;
125 // Example (if needed) for creating the list of id from the lsite of handler
127 MEDOP::FieldIdList_var fieldIdList = new MEDOP::FieldIdList();
128 fieldIdList->length(fieldHandlerList->length());
129 for (int i=0; i<fieldHandlerList->length(); i++) {
130 MEDOP::FieldHandler fieldHandler = (*fieldHandlerList)[i];
131 fieldIdList[i] = fieldHandler.id;