Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/smesh.git] / src / OBJECT / SMESH_Grid.cxx
1 using namespace std;
2 // File:        SMESH_Grid.cxx
3 // Created:     Fri Sep 27 15:47:42 2002
4 // Author:      Nicolas REJNERI
5
6 #include "SMESH_Grid.h"
7
8 #include "utilities.h"
9
10 // VTK Includes
11 #include <vtkObjectFactory.h>
12
13 SMESH_Grid* SMESH_Grid::New()
14 {
15   // First try to create the object from the vtkObjectFactory
16   vtkObject* ret = vtkObjectFactory::CreateInstance("SMESH_Grid");
17   if(ret)
18     {
19       return (SMESH_Grid*)ret;
20     }
21   // If the factory was unable to create the object, then create it here.
22   return new SMESH_Grid;
23 }
24
25 void SMESH_Grid::AddNode(int idSMESHDSnode,int idVTKnode)
26 {
27   myMapNodeSMDStoVTK.Bind(idSMESHDSnode, idVTKnode);
28   myMapNodeVTKtoSMDS.Bind(idVTKnode, idSMESHDSnode);
29 }
30 void SMESH_Grid::AddElement(int idSMESHDSelement, int idVTKelement)
31 {
32   myMapElementSMDStoVTK.Bind(idSMESHDSelement, idVTKelement);
33   myMapElementVTKtoSMDS.Bind(idVTKelement, idSMESHDSelement);
34 }
35
36 void SMESH_Grid::SetIdsVTKNode(const TColStd_DataMapOfIntegerInteger& mapVTK)
37 {
38   myMapNodeVTKtoSMDS = mapVTK;
39 }
40 void SMESH_Grid::SetIdsSMESHDSNode(const TColStd_DataMapOfIntegerInteger& mapSMESHDS)
41 {
42   myMapNodeSMDStoVTK = mapSMESHDS;
43 }
44
45 void SMESH_Grid::SetIdsVTKElement(const TColStd_DataMapOfIntegerInteger& mapVTK)
46 {
47   myMapElementVTKtoSMDS = mapVTK;
48 }
49 void SMESH_Grid::SetIdsSMESHDSElement(const TColStd_DataMapOfIntegerInteger& mapSMESHDS)
50 {
51   myMapElementSMDStoVTK = mapSMESHDS;
52 }
53
54 int SMESH_Grid::GetIdVTKNode(int idSMESHDSnode)
55 {
56   if ( myMapNodeSMDStoVTK.IsBound( idSMESHDSnode ) )
57     return myMapNodeSMDStoVTK.Find(idSMESHDSnode);
58   else {
59     MESSAGE("GetIdVTKNode(): SMDS node not found: " << idSMESHDSnode);
60     return -1;
61   }
62 }
63 int SMESH_Grid::GetIdVTKElement(int idSMESHDSelement)
64 {
65   if ( myMapElementSMDStoVTK.IsBound( idSMESHDSelement ) )
66     return myMapElementSMDStoVTK.Find(idSMESHDSelement);
67   else {
68     MESSAGE("GetIdVTKElement(): SMDS element not found: " << idSMESHDSelement);    
69     return -1;
70   }
71 }
72
73 int SMESH_Grid::GetIdSMESHDSNode(int idVTKnode)
74 {
75   if ( myMapNodeVTKtoSMDS.IsBound( idVTKnode ) )
76     return myMapNodeVTKtoSMDS.Find(idVTKnode);
77   else {
78     MESSAGE("GetIdSMESHDSNode(): VTK node not found: " << idVTKnode);    
79     return -1;
80   }
81 }
82 int SMESH_Grid::GetIdSMESHDSElement(int idVTKelement)
83 {
84   if ( myMapElementVTKtoSMDS.IsBound( idVTKelement ) )
85     return myMapElementVTKtoSMDS.Find(idVTKelement);
86   else {
87     MESSAGE("GetIdSMESHDSElement(): VTK element not found: " << idVTKelement);
88     return -1;
89   }
90 }
91
92 void SMESH_Grid::ClearNode()
93 {
94   myMapNodeVTKtoSMDS.Clear();
95   myMapNodeSMDStoVTK.Clear();
96 }
97 void SMESH_Grid::ClearElement()
98 {
99   myMapElementVTKtoSMDS.Clear();
100   myMapElementSMDStoVTK.Clear();
101 }
102
103 void SMESH_Grid::RemoveNode(int id)
104 {
105   if ( myMapNodeSMDStoVTK.IsBound( id ) ) {
106     int idVTK = myMapNodeSMDStoVTK.Find(id);
107     myMapNodeSMDStoVTK.UnBind(id);
108     if ( myMapNodeVTKtoSMDS.IsBound( idVTK ) ) {
109       myMapNodeVTKtoSMDS.UnBind(idVTK);
110     }
111   }
112 }
113 void SMESH_Grid::RemoveElement(int id)
114 {
115   if ( myMapElementSMDStoVTK.IsBound( id ) ) {
116     int idVTK = myMapElementSMDStoVTK.Find(id);
117     myMapElementSMDStoVTK.UnBind(id);
118     if ( myMapElementVTKtoSMDS.IsBound( idVTK ) ) {
119       myMapElementVTKtoSMDS.UnBind(idVTK);
120     }
121   }
122 }
123
124 void SMESH_Grid::DeepCopy(vtkDataObject *src)
125 {
126   SMESH_Grid* srcGrid = SMESH_Grid::SafeDownCast(src);
127
128   if (srcGrid != NULL) {
129     CopyMaps(srcGrid);
130   }
131
132   vtkUnstructuredGrid::DeepCopy(src);
133 }
134
135 void SMESH_Grid::CopyMaps(SMESH_Grid *srcGrid)
136 {
137   this->myMapNodeVTKtoSMDS = srcGrid->myMapNodeVTKtoSMDS;
138   this->myMapNodeSMDStoVTK = srcGrid->myMapNodeSMDStoVTK;
139   this->myMapElementVTKtoSMDS = srcGrid->myMapElementVTKtoSMDS;
140   this->myMapElementSMDStoVTK = srcGrid->myMapElementSMDStoVTK;
141 }