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