Salome HOME
First draft of a possible GUI testing framework. Still work todo:
[modules/med.git] / src / MEDCalc / gui / XmedDataModel.cxx
1 // Copyright (C) 2007-2016  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() {
31 }
32
33 /*! This function specified the localization of the object in the
34  * hierarchical organization
35  */
36 string XmedDataObject::getPath() {
37   string path =
38     string(_fieldHandler.meshname) + pathsep +
39     _getTypedFieldLabel();
40   return path;
41 }
42
43 void XmedDataObject::setFieldHandler(MEDCALC::FieldHandler fieldHandler) {
44   _fieldHandler = fieldHandler;
45   this->setLabel(string("it = ")+ToString(_fieldHandler.iteration));
46 }
47 MEDCALC::FieldHandler * XmedDataObject::getFieldHandler() {
48   return &_fieldHandler;
49 }
50
51 /*!
52  * This function implements the convention for displaying a fieldname
53  * characterized by its spatial discretisation type.
54  */
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
60   // list:
61   // 0 = ON_CELLS
62   // 1 = ON_NODES
63   // 2 = ON_GAUSS_PT
64   // 3 = ON_GAUSS_NE
65   if ( _fieldHandler.type < 0 ||
66        _fieldHandler.type >= NB_TYPE_OF_FIELDS ) {
67     return string("UNKNOWN");
68   }
69   string label(_fieldHandler.fieldname);
70   label +=" ("+string(mapTypeOfFieldLabel[_fieldHandler.type])+")";
71   return label;
72 }
73
74 //
75 // =================================================================
76 // XmedDataModel implementation
77 // =================================================================
78 //
79
80 /*!
81  * This function creates a XmedDataObject instance of DataObject and
82  * add the newly created instance to the model.
83  */
84 DataObject * XmedDataModel::newDataObject() {
85   XmedDataObject * dataObject = new XmedDataObject();
86   this->addDataObject(dataObject);
87   return dataObject;
88 }
89
90 //
91 // =================================================================
92 // XmedDataProcessor implementation
93 // =================================================================
94 //
95 void XmedDataProcessor::preprocess(QStringList itemNameIdList) {
96   int maxsize = itemNameIdList.size();
97   _resultingFieldHandlerList = new MEDCALC::FieldHandlerList(maxsize);
98   _resultingFieldIdList = new MEDCALC::FieldIdList(maxsize);
99   _objectIndex = 0;
100 }
101
102 MEDCALC::FieldHandlerList * XmedDataProcessor::getResultingFieldHandlerList() {
103   return _resultingFieldHandlerList._retn();
104 }
105
106 MEDCALC::FieldIdList * XmedDataProcessor::getResultingFieldIdList() {
107   return _resultingFieldIdList._retn();
108 }
109
110 void XmedDataProcessor::processDataObject(DataObject * dataObject) {
111   XmedDataObject * xmedDataObject = (XmedDataObject *)dataObject;
112   MEDCALC::FieldHandler fieldHandler = *(xmedDataObject->getFieldHandler());
113   int fieldId = fieldHandler.id;
114
115   int newsize = _objectIndex+1;
116   _resultingFieldHandlerList->length(newsize);
117   _resultingFieldIdList->length(newsize);
118
119   _resultingFieldHandlerList[_objectIndex] = fieldHandler;
120   _resultingFieldIdList[_objectIndex]      = fieldId;
121   _objectIndex++;
122
123   // >>>>>
124   // Example (if needed) for creating the list of id from the lsite of handler
125   /*
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;
131   }
132   */
133   // <<<<<
134 }