Salome HOME
3870392f13bcb2c709205af40a6ac5f846d0ccca
[modules/med.git] / src / MEDCalc / gui / XmedDataModel.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "XmedDataModel.hxx"
21 #include <Basics_Utils.hxx>
22 #include "MEDCalcConstants.hxx"
23
24 //
25 // =================================================================
26 // XmedDataObject implementation
27 // =================================================================
28 //
29
30 XmedDataObject::XmedDataObject() : DataObject(), _presId(-1) {
31 }
32
33 /*! This function specified the localization of the object in the
34  * hierarchical organization
35  */
36 std::string XmedDataObject::getPath() {
37   std::string path =
38     std::string(_fieldHandler.meshname) + pathsep +
39     _getTypedFieldLabel();
40   return path;
41 }
42
43 void XmedDataObject::setFieldHandler(MEDCALC::FieldHandler fieldHandler) {
44   _fieldHandler = fieldHandler;
45   this->setLabel(std::string("it = ")+ToString(_fieldHandler.iteration));
46 }
47 MEDCALC::FieldHandler * XmedDataObject::getFieldHandler() {
48   return &_fieldHandler;
49 }
50
51 void XmedDataObject::setPresentationId(int presId) {
52   _presId = presId;
53 }
54
55 int XmedDataObject::getPresentationId() const { return _presId; }
56
57
58 /*!
59  * This function implements the convention for displaying a fieldname
60  * characterized by its spatial discretisation type.
61  */
62 std::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
67   // list:
68   // 0 = ON_CELLS
69   // 1 = ON_NODES
70   // 2 = ON_GAUSS_PT
71   // 3 = ON_GAUSS_NE
72   if ( _fieldHandler.type < 0 ||
73        _fieldHandler.type >= NB_TYPE_OF_FIELDS ) {
74     return std::string("UNKNOWN");
75   }
76   std::string label(_fieldHandler.fieldname);
77   label +=" ("+std::string(mapTypeOfFieldLabel[_fieldHandler.type])+")";
78   return label;
79 }
80
81 //
82 // =================================================================
83 // XmedDataModel implementation
84 // =================================================================
85 //
86
87 /*!
88  * This function creates a XmedDataObject instance of DataObject and
89  * add the newly created instance to the model.
90  */
91 DataObject * XmedDataModel::newDataObject() {
92   XmedDataObject * dataObject = new XmedDataObject();
93   this->addDataObject(dataObject);
94   return dataObject;
95 }
96
97 //
98 // =================================================================
99 // XmedDataProcessor implementation
100 // =================================================================
101 //
102 void XmedDataProcessor::preprocess(QStringList itemNameIdList) {
103   int maxsize = itemNameIdList.size();
104   _resultingFieldHandlerList = new MEDCALC::FieldHandlerList(maxsize);
105   _resultingFieldIdList = new MEDCALC::FieldIdList(maxsize);
106   _objectIndex = 0;
107 }
108
109 MEDCALC::FieldHandlerList * XmedDataProcessor::getResultingFieldHandlerList() {
110   return _resultingFieldHandlerList._retn();
111 }
112
113 MEDCALC::FieldIdList * XmedDataProcessor::getResultingFieldIdList() {
114   return _resultingFieldIdList._retn();
115 }
116
117 void XmedDataProcessor::processDataObject(DataObject * dataObject) {
118   XmedDataObject * xmedDataObject = (XmedDataObject *)dataObject;
119   MEDCALC::FieldHandler fieldHandler = *(xmedDataObject->getFieldHandler());
120   int fieldId = fieldHandler.id;
121
122   int newsize = _objectIndex+1;
123   _resultingFieldHandlerList->length(newsize);
124   _resultingFieldIdList->length(newsize);
125
126   _resultingFieldHandlerList[_objectIndex] = fieldHandler;
127   _resultingFieldIdList[_objectIndex]      = fieldId;
128   _objectIndex++;
129
130   // >>>>>
131   // Example (if needed) for creating the list of id from the lsite of handler
132   /*
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;
138   }
139   */
140   // <<<<<
141 }