Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/smesh.git] / src / OBJECT / SMESH_Grid.cxx
1 //  SMESH OBJECT : interactive object for SMESH visualization
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESH_Grid.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27
28 using namespace std;
29 #include "SMESH_Grid.h"
30
31 #include "utilities.h"
32
33 // VTK Includes
34 #include <vtkObjectFactory.h>
35
36 SMESH_Grid* SMESH_Grid::New()
37 {
38   // First try to create the object from the vtkObjectFactory
39   vtkObject* ret = vtkObjectFactory::CreateInstance("SMESH_Grid");
40   if(ret)
41     {
42       return (SMESH_Grid*)ret;
43     }
44   // If the factory was unable to create the object, then create it here.
45   return new SMESH_Grid;
46 }
47
48 void SMESH_Grid::AddNode(int idSMESHDSnode,int idVTKnode)
49 {
50   myMapNodeSMDStoVTK.Bind(idSMESHDSnode, idVTKnode);
51   myMapNodeVTKtoSMDS.Bind(idVTKnode, idSMESHDSnode);
52 }
53 void SMESH_Grid::AddElement(int idSMESHDSelement, int idVTKelement)
54 {
55   myMapElementSMDStoVTK.Bind(idSMESHDSelement, idVTKelement);
56   myMapElementVTKtoSMDS.Bind(idVTKelement, idSMESHDSelement);
57 }
58
59 void SMESH_Grid::SetIdsVTKNode(const TColStd_DataMapOfIntegerInteger& mapVTK)
60 {
61   myMapNodeVTKtoSMDS = mapVTK;
62 }
63 void SMESH_Grid::SetIdsSMESHDSNode(const TColStd_DataMapOfIntegerInteger& mapSMESHDS)
64 {
65   myMapNodeSMDStoVTK = mapSMESHDS;
66 }
67
68 void SMESH_Grid::SetIdsVTKElement(const TColStd_DataMapOfIntegerInteger& mapVTK)
69 {
70   myMapElementVTKtoSMDS = mapVTK;
71 }
72 void SMESH_Grid::SetIdsSMESHDSElement(const TColStd_DataMapOfIntegerInteger& mapSMESHDS)
73 {
74   myMapElementSMDStoVTK = mapSMESHDS;
75 }
76
77 int SMESH_Grid::GetIdVTKNode(int idSMESHDSnode)
78 {
79   if ( myMapNodeSMDStoVTK.IsBound( idSMESHDSnode ) )
80     return myMapNodeSMDStoVTK.Find(idSMESHDSnode);
81   else {
82     MESSAGE("GetIdVTKNode(): SMDS node not found: " << idSMESHDSnode);
83     return -1;
84   }
85 }
86 int SMESH_Grid::GetIdVTKElement(int idSMESHDSelement)
87 {
88   if ( myMapElementSMDStoVTK.IsBound( idSMESHDSelement ) )
89     return myMapElementSMDStoVTK.Find(idSMESHDSelement);
90   else {
91     MESSAGE("GetIdVTKElement(): SMDS element not found: " << idSMESHDSelement);    
92     return -1;
93   }
94 }
95
96 int SMESH_Grid::GetIdSMESHDSNode(int idVTKnode)
97 {
98   if ( myMapNodeVTKtoSMDS.IsBound( idVTKnode ) )
99     return myMapNodeVTKtoSMDS.Find(idVTKnode);
100   else {
101     MESSAGE("GetIdSMESHDSNode(): VTK node not found: " << idVTKnode);    
102     return -1;
103   }
104 }
105 int SMESH_Grid::GetIdSMESHDSElement(int idVTKelement)
106 {
107   if ( myMapElementVTKtoSMDS.IsBound( idVTKelement ) )
108     return myMapElementVTKtoSMDS.Find(idVTKelement);
109   else {
110     MESSAGE("GetIdSMESHDSElement(): VTK element not found: " << idVTKelement);
111     return -1;
112   }
113 }
114
115 void SMESH_Grid::ClearNode()
116 {
117   myMapNodeVTKtoSMDS.Clear();
118   myMapNodeSMDStoVTK.Clear();
119 }
120 void SMESH_Grid::ClearElement()
121 {
122   myMapElementVTKtoSMDS.Clear();
123   myMapElementSMDStoVTK.Clear();
124 }
125
126 void SMESH_Grid::RemoveNode(int id)
127 {
128   if ( myMapNodeSMDStoVTK.IsBound( id ) ) {
129     int idVTK = myMapNodeSMDStoVTK.Find(id);
130     myMapNodeSMDStoVTK.UnBind(id);
131     if ( myMapNodeVTKtoSMDS.IsBound( idVTK ) ) {
132       myMapNodeVTKtoSMDS.UnBind(idVTK);
133     }
134   }
135 }
136 void SMESH_Grid::RemoveElement(int id)
137 {
138   if ( myMapElementSMDStoVTK.IsBound( id ) ) {
139     int idVTK = myMapElementSMDStoVTK.Find(id);
140     myMapElementSMDStoVTK.UnBind(id);
141     if ( myMapElementVTKtoSMDS.IsBound( idVTK ) ) {
142       myMapElementVTKtoSMDS.UnBind(idVTK);
143     }
144   }
145 }
146
147 void SMESH_Grid::DeepCopy(vtkDataObject *src)
148 {
149   SMESH_Grid* srcGrid = SMESH_Grid::SafeDownCast(src);
150
151   if (srcGrid != NULL) {
152     CopyMaps(srcGrid);
153   }
154
155   vtkUnstructuredGrid::DeepCopy(src);
156 }
157
158 void SMESH_Grid::CopyMaps(SMESH_Grid *srcGrid)
159 {
160   this->myMapNodeVTKtoSMDS = srcGrid->myMapNodeVTKtoSMDS;
161   this->myMapNodeSMDStoVTK = srcGrid->myMapNodeSMDStoVTK;
162   this->myMapElementVTKtoSMDS = srcGrid->myMapElementVTKtoSMDS;
163   this->myMapElementSMDStoVTK = srcGrid->myMapElementSMDStoVTK;
164 }