1 // SMESH OBJECT : interactive object for SMESH visualization
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_Grid.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESH_Grid.h"
31 #include "utilities.h"
34 #include <vtkObjectFactory.h>
36 SMESH_Grid* SMESH_Grid::New()
38 // First try to create the object from the vtkObjectFactory
39 vtkObject* ret = vtkObjectFactory::CreateInstance("SMESH_Grid");
42 return (SMESH_Grid*)ret;
44 // If the factory was unable to create the object, then create it here.
45 return new SMESH_Grid;
48 void SMESH_Grid::AddNode(int idSMESHDSnode,int idVTKnode)
50 myMapNodeSMDStoVTK.Bind(idSMESHDSnode, idVTKnode);
51 myMapNodeVTKtoSMDS.Bind(idVTKnode, idSMESHDSnode);
53 void SMESH_Grid::AddElement(int idSMESHDSelement, int idVTKelement)
55 myMapElementSMDStoVTK.Bind(idSMESHDSelement, idVTKelement);
56 myMapElementVTKtoSMDS.Bind(idVTKelement, idSMESHDSelement);
59 void SMESH_Grid::SetIdsVTKNode(const TColStd_DataMapOfIntegerInteger& mapVTK)
61 myMapNodeVTKtoSMDS = mapVTK;
63 void SMESH_Grid::SetIdsSMESHDSNode(const TColStd_DataMapOfIntegerInteger& mapSMESHDS)
65 myMapNodeSMDStoVTK = mapSMESHDS;
68 void SMESH_Grid::SetIdsVTKElement(const TColStd_DataMapOfIntegerInteger& mapVTK)
70 myMapElementVTKtoSMDS = mapVTK;
72 void SMESH_Grid::SetIdsSMESHDSElement(const TColStd_DataMapOfIntegerInteger& mapSMESHDS)
74 myMapElementSMDStoVTK = mapSMESHDS;
77 int SMESH_Grid::GetIdVTKNode(int idSMESHDSnode)
79 if ( myMapNodeSMDStoVTK.IsBound( idSMESHDSnode ) )
80 return myMapNodeSMDStoVTK.Find(idSMESHDSnode);
82 MESSAGE("GetIdVTKNode(): SMDS node not found: " << idSMESHDSnode);
86 int SMESH_Grid::GetIdVTKElement(int idSMESHDSelement)
88 if ( myMapElementSMDStoVTK.IsBound( idSMESHDSelement ) )
89 return myMapElementSMDStoVTK.Find(idSMESHDSelement);
91 MESSAGE("GetIdVTKElement(): SMDS element not found: " << idSMESHDSelement);
96 int SMESH_Grid::GetIdSMESHDSNode(int idVTKnode)
98 if ( myMapNodeVTKtoSMDS.IsBound( idVTKnode ) )
99 return myMapNodeVTKtoSMDS.Find(idVTKnode);
101 MESSAGE("GetIdSMESHDSNode(): VTK node not found: " << idVTKnode);
105 int SMESH_Grid::GetIdSMESHDSElement(int idVTKelement)
107 if ( myMapElementVTKtoSMDS.IsBound( idVTKelement ) )
108 return myMapElementVTKtoSMDS.Find(idVTKelement);
110 MESSAGE("GetIdSMESHDSElement(): VTK element not found: " << idVTKelement);
115 void SMESH_Grid::ClearNode()
117 myMapNodeVTKtoSMDS.Clear();
118 myMapNodeSMDStoVTK.Clear();
120 void SMESH_Grid::ClearElement()
122 myMapElementVTKtoSMDS.Clear();
123 myMapElementSMDStoVTK.Clear();
126 void SMESH_Grid::RemoveNode(int id)
128 if ( myMapNodeSMDStoVTK.IsBound( id ) ) {
129 int idVTK = myMapNodeSMDStoVTK.Find(id);
130 myMapNodeSMDStoVTK.UnBind(id);
131 if ( myMapNodeVTKtoSMDS.IsBound( idVTK ) ) {
132 myMapNodeVTKtoSMDS.UnBind(idVTK);
136 void SMESH_Grid::RemoveElement(int id)
138 if ( myMapElementSMDStoVTK.IsBound( id ) ) {
139 int idVTK = myMapElementSMDStoVTK.Find(id);
140 myMapElementSMDStoVTK.UnBind(id);
141 if ( myMapElementVTKtoSMDS.IsBound( idVTK ) ) {
142 myMapElementVTKtoSMDS.UnBind(idVTK);
147 void SMESH_Grid::DeepCopy(vtkDataObject *src)
149 SMESH_Grid* srcGrid = SMESH_Grid::SafeDownCast(src);
151 if (srcGrid != NULL) {
155 vtkUnstructuredGrid::DeepCopy(src);
158 void SMESH_Grid::CopyMaps(SMESH_Grid *srcGrid)
160 this->myMapNodeVTKtoSMDS = srcGrid->myMapNodeVTKtoSMDS;
161 this->myMapNodeSMDStoVTK = srcGrid->myMapNodeSMDStoVTK;
162 this->myMapElementVTKtoSMDS = srcGrid->myMapElementVTKtoSMDS;
163 this->myMapElementSMDStoVTK = srcGrid->myMapElementSMDStoVTK;