Salome HOME
Freshly added file
[modules/smesh.git] / src / SMESH_I / SMESH_MeshEditor_i.cxx
1 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
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_MeshEditor_i.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 #include "SMESH_MeshEditor_i.hxx"
31
32 #include "SMDS_MeshEdge.hxx"
33 #include "SMDS_MeshFace.hxx"
34 #include "SMDS_MeshVolume.hxx"
35
36 #include "utilities.h"
37
38 #include <TColStd_MapOfInteger.hxx>
39 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
40
41 //=============================================================================
42 /*!
43  *  
44  */
45 //=============================================================================
46
47 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESHDS_Mesh* theMesh)
48 {
49         _myMeshDS = theMesh;
50 };
51
52 //=============================================================================
53 /*!
54  *  
55  */
56 //=============================================================================
57
58 CORBA::Boolean SMESH_MeshEditor_i::RemoveElements(const SMESH::
59         long_array & IDsOfElements)
60 {
61         for (int i = 0; i < IDsOfElements.length(); i++)
62         {
63                 CORBA::Long index = IDsOfElements[i];
64                 _myMeshDS->RemoveElement(_myMeshDS->FindElement(index));
65                 MESSAGE("Element " << index << " was removed")
66         }
67         return true;
68 };
69
70 //=============================================================================
71 /*!
72  *  
73  */
74 //=============================================================================
75
76 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::
77         long_array & IDsOfNodes)
78 {
79         // It's nodes' turn to die
80         for (int i = 0; i < IDsOfNodes.length(); i++)
81         {
82                 const SMDS_MeshNode * node=_myMeshDS->FindNode(IDsOfNodes[i]);
83                 if(node==NULL)
84                 {
85                         MESSAGE("SMESH_MeshEditor_i::RemoveNodes: Node "<<IDsOfNodes[i]
86                                 <<" not found");
87                         continue;
88                 }
89                 _myMeshDS->RemoveNode(node);
90                 MESSAGE("Node " << IDsOfNodes[i] << " was removed")
91         }
92         return true;
93 };
94
95 //=============================================================================
96 /*!
97  *  
98  */
99 //=============================================================================
100
101 CORBA::Boolean SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
102 {
103         int NbNodes = IDsOfNodes.length();
104         if (NbNodes == 2)
105         {
106                 CORBA::Long index1 = IDsOfNodes[0];
107                 CORBA::Long index2 = IDsOfNodes[1];
108                 _myMeshDS->AddEdge(_myMeshDS->FindNode(index1), _myMeshDS->FindNode(index2));
109         }
110         return true;
111 }
112
113 //=============================================================================
114 /*!
115  *  
116  */
117 //=============================================================================
118
119 CORBA::Boolean SMESH_MeshEditor_i::AddNode(CORBA::Double x,
120         CORBA::Double y, CORBA::Double z)
121 {
122         MESSAGE(" AddNode " << x << " , " << y << " , " << z)
123                 int idNode = _myMeshDS->AddNode(x, y, z)->GetID();
124         MESSAGE(" idNode " << idNode) return true;
125 }
126
127 //=============================================================================
128 /*!
129  *  
130  */
131 //=============================================================================
132
133 CORBA::Boolean SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
134 {
135         int NbNodes = IDsOfNodes.length();
136         const SMDS_MeshNode* nodes[4];
137         for(int i=0;i<NbNodes;i++) nodes[i]=_myMeshDS->FindNode(IDsOfNodes[i]);
138         if (NbNodes == 3)
139         {
140                 _myMeshDS->AddFace(nodes[0], nodes[1], nodes[2]);
141         }
142         else if (NbNodes == 4)
143         {
144                 _myMeshDS->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
145         }
146         return true;
147 };
148
149 //=============================================================================
150 /*!
151  *  
152  */
153 //=============================================================================
154
155 CORBA::Boolean SMESH_MeshEditor_i::AddVolume(const SMESH::
156         long_array & IDsOfNodes)
157 {
158         int NbNodes = IDsOfNodes.length();
159         const SMDS_MeshNode* n[8];
160         for(int i=0;i<NbNodes;i++) n[i]=_myMeshDS->FindNode(IDsOfNodes[i]);
161
162         switch(NbNodes)
163         {
164         case 4:_myMeshDS->AddVolume(n[0],n[1],n[2],n[3]); break;
165         case 5:_myMeshDS->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
166         case 6:_myMeshDS->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
167         case 8:_myMeshDS->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
168         }
169         return true;
170 };