Back to index

salome-smesh  6.5.0
SMESHDS_Mesh.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMESHDS : management of mesh data and SMESH document
00024 //  File   : SMESH_Mesh.cxx
00025 //  Author : Yves FRICAUD, OCC
00026 //  Module : SMESH
00027 //  $Header: 
00028 //
00029 #include "SMESHDS_Mesh.hxx"
00030 
00031 #include "SMESHDS_Group.hxx"
00032 #include "SMDS_VertexPosition.hxx"
00033 #include "SMDS_EdgePosition.hxx"
00034 #include "SMDS_FacePosition.hxx"
00035 #include "SMDS_SpacePosition.hxx"
00036 #include "SMDS_Downward.hxx"
00037 #include "SMESHDS_GroupOnGeom.hxx"
00038 
00039 #include <Standard_ErrorHandler.hxx>
00040 #include <Standard_OutOfRange.hxx>
00041 #include <TopExp.hxx>
00042 #include <TopExp_Explorer.hxx>
00043 #include <TopoDS_Iterator.hxx>
00044 
00045 #include "utilities.h"
00046 
00047 using namespace std;
00048 
00049 /*Standard_Boolean IsEqual( const TopoDS_Shape& S1, const TopoDS_Shape& S2 ) 
00050   {
00051     return S1.IsSame( S2 );
00052   }*/
00053 
00054 //=======================================================================
00055 //function : Create
00056 //purpose  : 
00057 //=======================================================================
00058 SMESHDS_Mesh::SMESHDS_Mesh(int theMeshID, bool theIsEmbeddedMode):
00059   myMeshID(theMeshID),
00060   myIsEmbeddedMode(theIsEmbeddedMode),
00061   myCurSubID(-1)
00062 {
00063   myScript = new SMESHDS_Script(theIsEmbeddedMode);
00064   myCurSubMesh = 0;
00065   SetPersistentId(theMeshID);
00066 }
00067 
00068 //=======================================================================
00069 bool SMESHDS_Mesh::IsEmbeddedMode()
00070 {
00071   return myIsEmbeddedMode;
00072 }
00073 
00074 //================================================================================
00080 //================================================================================
00081 
00082 void SMESHDS_Mesh::SetPersistentId(int id)
00083 {
00084   if (NbNodes() == 0)
00085     myPersistentID = id;
00086 }
00087 //================================================================================
00091 //================================================================================
00092 
00093 int SMESHDS_Mesh::GetPersistentId() const
00094 {
00095   return myPersistentID;
00096 }
00097 
00098 //=======================================================================
00099 //function : ShapeToMesh
00100 //purpose  : 
00101 //=======================================================================
00102 void SMESHDS_Mesh::ShapeToMesh(const TopoDS_Shape & S)
00103 {
00104   if ( !myShape.IsNull() && S.IsNull() )
00105   {
00106     // removal of a shape to mesh, delete ...
00107     // - hypotheses
00108     myShapeToHypothesis.Clear();
00109     // - shape indices in SMDS_Position of nodes
00110     map<int,SMESHDS_SubMesh*>::iterator i_sub = myShapeIndexToSubMesh.begin();
00111     for ( ; i_sub != myShapeIndexToSubMesh.end(); i_sub++ ) {
00112       if ( !i_sub->second->IsComplexSubmesh() ) {
00113         SMDS_NodeIteratorPtr nIt = i_sub->second->GetNodes();
00114         while ( nIt->more() )
00115           i_sub->second->RemoveNode(nIt->next(), false);
00116       }
00117     }
00118     // - sub-meshes
00119     TShapeIndexToSubMesh::iterator i_sm = myShapeIndexToSubMesh.begin();
00120     for ( ; i_sm != myShapeIndexToSubMesh.end(); ++i_sm )
00121       delete i_sm->second;
00122     myShapeIndexToSubMesh.clear();
00123     myIndexToShape.Clear();
00124     // - groups on geometry
00125     set<SMESHDS_GroupBase*>::iterator gr = myGroups.begin();
00126     while ( gr != myGroups.end() ) {
00127       if ( dynamic_cast<SMESHDS_GroupOnGeom*>( *gr ))
00128         myGroups.erase( gr++ );
00129       else
00130         gr++;
00131     }
00132   }
00133   else {
00134     myShape = S;
00135     if ( !S.IsNull() )
00136       TopExp::MapShapes(myShape, myIndexToShape);
00137   }
00138 }
00139 
00140 //=======================================================================
00141 //function : AddHypothesis
00142 //purpose  : 
00143 //=======================================================================
00144 
00145 bool SMESHDS_Mesh::AddHypothesis(const TopoDS_Shape & SS,
00146                                  const SMESHDS_Hypothesis * H)
00147 {
00148   if (!myShapeToHypothesis.IsBound(SS.Oriented(TopAbs_FORWARD))) {
00149     list<const SMESHDS_Hypothesis *> aList;
00150     myShapeToHypothesis.Bind(SS.Oriented(TopAbs_FORWARD), aList);
00151   }
00152   list<const SMESHDS_Hypothesis *>& alist =
00153     myShapeToHypothesis(SS.Oriented(TopAbs_FORWARD)); // ignore orientation of SS
00154 
00155   //Check if the Hypothesis is still present
00156   list<const SMESHDS_Hypothesis*>::iterator ith = find(alist.begin(),alist.end(), H );
00157 
00158   if (alist.end() != ith) return false;
00159 
00160   alist.push_back(H);
00161   return true;
00162 }
00163 
00164 //=======================================================================
00165 //function : RemoveHypothesis
00166 //purpose  : 
00167 //=======================================================================
00168 
00169 bool SMESHDS_Mesh::RemoveHypothesis(const TopoDS_Shape &       S,
00170                                     const SMESHDS_Hypothesis * H)
00171 {
00172   if( myShapeToHypothesis.IsBound( S.Oriented(TopAbs_FORWARD) ) )
00173   {
00174     list<const SMESHDS_Hypothesis *>& alist=myShapeToHypothesis.ChangeFind( S.Oriented(TopAbs_FORWARD) );
00175     list<const SMESHDS_Hypothesis*>::iterator ith=find(alist.begin(),alist.end(), H );
00176     if (ith != alist.end())
00177     {
00178       alist.erase(ith);
00179       return true;
00180     }
00181   }
00182   return false;
00183 }
00184 
00185 //=======================================================================
00186 //function : AddNode
00187 //purpose  : 
00188 //=======================================================================
00189 SMDS_MeshNode* SMESHDS_Mesh::AddNode(double x, double y, double z){
00190   SMDS_MeshNode* node = SMDS_Mesh::AddNode(x, y, z);
00191   if(node!=NULL) myScript->AddNode(node->GetID(), x, y, z);
00192   return node;
00193 }
00194 
00195 SMDS_MeshNode* SMESHDS_Mesh::AddNodeWithID(double x, double y, double z, int ID){
00196   SMDS_MeshNode* node = SMDS_Mesh::AddNodeWithID(x,y,z,ID);
00197   if(node!=NULL) myScript->AddNode(node->GetID(), x, y, z);
00198   return node;
00199 }
00200 
00201 //=======================================================================
00202 //function : MoveNode
00203 //purpose  : 
00204 //=======================================================================
00205 void SMESHDS_Mesh::MoveNode(const SMDS_MeshNode *n, double x, double y, double z)
00206 {
00207   SMDS_MeshNode * node=const_cast<SMDS_MeshNode*>(n);
00208   node->setXYZ(x,y,z);
00209   myScript->MoveNode(n->GetID(), x, y, z);
00210 }
00211 
00212 //=======================================================================
00213 //function : ChangeElementNodes
00214 //purpose  : 
00215 //=======================================================================
00216 
00217 bool SMESHDS_Mesh::ChangeElementNodes(const SMDS_MeshElement * elem,
00218                                       const SMDS_MeshNode    * nodes[],
00219                                       const int                nbnodes)
00220 {
00221   //MESSAGE("SMESHDS_Mesh::ChangeElementNodes");
00222   if ( ! SMDS_Mesh::ChangeElementNodes( elem, nodes, nbnodes ))
00223     return false;
00224 
00225   vector<int> IDs( nbnodes );
00226   for ( int i = 0; i < nbnodes; i++ )
00227     IDs [ i ] = nodes[ i ]->GetID();
00228   myScript->ChangeElementNodes( elem->GetID(), &IDs[0], nbnodes);
00229 
00230   return true;
00231 }
00232 
00233 //=======================================================================
00234 //function : ChangePolygonNodes
00235 //purpose  : 
00236 //=======================================================================
00237 bool SMESHDS_Mesh::ChangePolygonNodes
00238                    (const SMDS_MeshElement *     elem,
00239                     vector<const SMDS_MeshNode*> nodes)
00240 {
00241   ASSERT(nodes.size() > 3);
00242 
00243   return ChangeElementNodes(elem, &nodes[0], nodes.size());
00244 }
00245 
00246 //=======================================================================
00247 //function : ChangePolyhedronNodes
00248 //purpose  : 
00249 //=======================================================================
00250 bool SMESHDS_Mesh::ChangePolyhedronNodes
00251                    (const SMDS_MeshElement * elem,
00252                     std::vector<const SMDS_MeshNode*> nodes,
00253                     std::vector<int>                  quantities)
00254 {
00255   ASSERT(nodes.size() > 3);
00256 
00257   if (!SMDS_Mesh::ChangePolyhedronNodes(elem, nodes, quantities))
00258     return false;
00259 
00260   int i, len = nodes.size();
00261   std::vector<int> nodes_ids (len);
00262   for (i = 0; i < len; i++) {
00263     nodes_ids[i] = nodes[i]->GetID();
00264   }
00265   myScript->ChangePolyhedronNodes(elem->GetID(), nodes_ids, quantities);
00266 
00267   return true;
00268 }
00269 
00270 //=======================================================================
00271 //function : Renumber
00272 //purpose  : 
00273 //=======================================================================
00274 
00275 void SMESHDS_Mesh::Renumber (const bool isNodes, const int startID, const int deltaID)
00276 {
00277   // TODO not possible yet to have node numbers not starting to O and continuous.
00278   if (!this->isCompacted())
00279     this->compactMesh();
00280 //  SMDS_Mesh::Renumber( isNodes, startID, deltaID );
00281 //  myScript->Renumber( isNodes, startID, deltaID );
00282 }
00283 
00284 //=======================================================================
00285 //function : Add0DElement
00286 //purpose  :
00287 //=======================================================================
00288 SMDS_Mesh0DElement* SMESHDS_Mesh::Add0DElementWithID(int nodeID, int ID)
00289 {
00290   SMDS_Mesh0DElement* anElem = SMDS_Mesh::Add0DElementWithID(nodeID, ID);
00291   if (anElem) myScript->Add0DElement(ID, nodeID);
00292   return anElem;
00293 }
00294 
00295 SMDS_Mesh0DElement* SMESHDS_Mesh::Add0DElementWithID
00296                                   (const SMDS_MeshNode * node, int ID)
00297 {
00298   return Add0DElementWithID(node->GetID(), ID);
00299 }
00300 
00301 SMDS_Mesh0DElement* SMESHDS_Mesh::Add0DElement(const SMDS_MeshNode * node)
00302 {
00303   SMDS_Mesh0DElement* anElem = SMDS_Mesh::Add0DElement(node);
00304   if (anElem) myScript->Add0DElement(anElem->GetID(), node->GetID());
00305   return anElem;
00306 }
00307 
00308 //=======================================================================
00309 //function :AddEdgeWithID
00310 //purpose  : 
00311 //=======================================================================
00312 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(int n1, int n2, int ID)
00313 {
00314   SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdgeWithID(n1,n2,ID);
00315   if(anElem) myScript->AddEdge(ID,n1,n2);
00316   return anElem;
00317 }
00318 
00319 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
00320                                            const SMDS_MeshNode * n2, 
00321                                            int ID)
00322 {
00323   return AddEdgeWithID(n1->GetID(),
00324                        n2->GetID(),
00325                        ID);
00326 }
00327 
00328 SMDS_MeshEdge* SMESHDS_Mesh::AddEdge(const SMDS_MeshNode * n1,
00329                                      const SMDS_MeshNode * n2)
00330 {
00331   SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdge(n1,n2);
00332   if(anElem) myScript->AddEdge(anElem->GetID(), 
00333                                n1->GetID(), 
00334                                n2->GetID());
00335   return anElem;
00336 }
00337 
00338 //=======================================================================
00339 //function :AddFace
00340 //purpose  : 
00341 //=======================================================================
00342 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int ID)
00343 {
00344   SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, ID);
00345   if(anElem) myScript->AddFace(ID,n1,n2,n3);
00346   return anElem;
00347 }
00348 
00349 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
00350                                            const SMDS_MeshNode * n2,
00351                                            const SMDS_MeshNode * n3, 
00352                                            int ID)
00353 {
00354   return AddFaceWithID(n1->GetID(),
00355                        n2->GetID(),
00356                        n3->GetID(),
00357                        ID);
00358 }
00359 
00360 SMDS_MeshFace* SMESHDS_Mesh::AddFace( const SMDS_MeshNode * n1,
00361                                       const SMDS_MeshNode * n2,
00362                                       const SMDS_MeshNode * n3)
00363 {
00364   SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3);
00365   if(anElem) myScript->AddFace(anElem->GetID(), 
00366                                n1->GetID(), 
00367                                n2->GetID(),
00368                                n3->GetID());
00369   return anElem;
00370 }
00371 
00372 //=======================================================================
00373 //function :AddFace
00374 //purpose  : 
00375 //=======================================================================
00376 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4, int ID)
00377 {
00378   SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1, n2, n3, n4, ID);
00379   if(anElem) myScript->AddFace(ID, n1, n2, n3, n4);
00380   return anElem;
00381 }
00382 
00383 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
00384                                            const SMDS_MeshNode * n2,
00385                                            const SMDS_MeshNode * n3,
00386                                            const SMDS_MeshNode * n4, 
00387                                            int ID)
00388 {
00389   return AddFaceWithID(n1->GetID(),
00390                        n2->GetID(),
00391                        n3->GetID(),
00392                        n4->GetID(),
00393                        ID);
00394 }
00395 
00396 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
00397                                      const SMDS_MeshNode * n2,
00398                                      const SMDS_MeshNode * n3,
00399                                      const SMDS_MeshNode * n4)
00400 {
00401   SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1, n2, n3, n4);
00402   if(anElem) myScript->AddFace(anElem->GetID(), 
00403                                n1->GetID(), 
00404                                n2->GetID(), 
00405                                n3->GetID(),
00406                                n4->GetID());
00407   return anElem;
00408 }
00409 
00410 //=======================================================================
00411 //function :AddVolume
00412 //purpose  : 
00413 //=======================================================================
00414 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int ID)
00415 {
00416   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, ID);
00417   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4);
00418   return anElem;
00419 }
00420 
00421 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
00422                                                const SMDS_MeshNode * n2,
00423                                                const SMDS_MeshNode * n3,
00424                                                const SMDS_MeshNode * n4, 
00425                                                int ID)
00426 {
00427   return AddVolumeWithID(n1->GetID(), 
00428                          n2->GetID(), 
00429                          n3->GetID(),
00430                          n4->GetID(),
00431                          ID);
00432 }
00433 
00434 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
00435                                          const SMDS_MeshNode * n2,
00436                                          const SMDS_MeshNode * n3,
00437                                          const SMDS_MeshNode * n4)
00438 {
00439   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4);
00440   if(anElem) myScript->AddVolume(anElem->GetID(), 
00441                                  n1->GetID(), 
00442                                  n2->GetID(), 
00443                                  n3->GetID(),
00444                                  n4->GetID());
00445   return anElem;
00446 }
00447 
00448 //=======================================================================
00449 //function :AddVolume
00450 //purpose  : 
00451 //=======================================================================
00452 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int ID)
00453 {
00454   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, ID);
00455   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5);
00456   return anElem;
00457 }
00458 
00459 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
00460                                                const SMDS_MeshNode * n2,
00461                                                const SMDS_MeshNode * n3,
00462                                                const SMDS_MeshNode * n4,
00463                                                const SMDS_MeshNode * n5, 
00464                                                int ID)
00465 {
00466   return AddVolumeWithID(n1->GetID(), 
00467                          n2->GetID(), 
00468                          n3->GetID(),
00469                          n4->GetID(), 
00470                          n5->GetID(),
00471                          ID);
00472 }
00473 
00474 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
00475                                          const SMDS_MeshNode * n2,
00476                                          const SMDS_MeshNode * n3,
00477                                          const SMDS_MeshNode * n4,
00478                                          const SMDS_MeshNode * n5)
00479 {
00480   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5);
00481   if(anElem) myScript->AddVolume(anElem->GetID(), 
00482                                  n1->GetID(), 
00483                                  n2->GetID(), 
00484                                  n3->GetID(),
00485                                  n4->GetID(), 
00486                                  n5->GetID());
00487   return anElem;
00488 }
00489 
00490 //=======================================================================
00491 //function :AddVolume
00492 //purpose  : 
00493 //=======================================================================
00494 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int ID)
00495 {
00496   SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, ID);
00497   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6);
00498   return anElem;
00499 }
00500 
00501 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
00502                                                const SMDS_MeshNode * n2,
00503                                                const SMDS_MeshNode * n3,
00504                                                const SMDS_MeshNode * n4,
00505                                                const SMDS_MeshNode * n5,
00506                                                const SMDS_MeshNode * n6, 
00507                                                int ID)
00508 {
00509   return AddVolumeWithID(n1->GetID(), 
00510                          n2->GetID(), 
00511                          n3->GetID(),
00512                          n4->GetID(), 
00513                          n5->GetID(), 
00514                          n6->GetID(),
00515                          ID);
00516 }
00517 
00518 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
00519                                          const SMDS_MeshNode * n2,
00520                                          const SMDS_MeshNode * n3,
00521                                          const SMDS_MeshNode * n4,
00522                                          const SMDS_MeshNode * n5,
00523                                          const SMDS_MeshNode * n6)
00524 {
00525   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6);
00526   if(anElem) myScript->AddVolume(anElem->GetID(), 
00527                                  n1->GetID(), 
00528                                  n2->GetID(), 
00529                                  n3->GetID(),
00530                                  n4->GetID(), 
00531                                  n5->GetID(), 
00532                                  n6->GetID());
00533   return anElem;
00534 }
00535 
00536 //=======================================================================
00537 //function :AddVolume
00538 //purpose  : 
00539 //=======================================================================
00540 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int ID)
00541 {
00542   SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, ID);
00543   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6, n7, n8);
00544   return anElem;
00545 }
00546 
00547 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
00548                                                const SMDS_MeshNode * n2,
00549                                                const SMDS_MeshNode * n3,
00550                                                const SMDS_MeshNode * n4,
00551                                                const SMDS_MeshNode * n5,
00552                                                const SMDS_MeshNode * n6,
00553                                                const SMDS_MeshNode * n7,
00554                                                const SMDS_MeshNode * n8, 
00555                                                int ID)
00556 {
00557   return AddVolumeWithID(n1->GetID(), 
00558                          n2->GetID(), 
00559                          n3->GetID(),
00560                          n4->GetID(), 
00561                          n5->GetID(), 
00562                          n6->GetID(), 
00563                          n7->GetID(), 
00564                          n8->GetID(),
00565                          ID);
00566 }
00567 
00568 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
00569                                          const SMDS_MeshNode * n2,
00570                                          const SMDS_MeshNode * n3,
00571                                          const SMDS_MeshNode * n4,
00572                                          const SMDS_MeshNode * n5,
00573                                          const SMDS_MeshNode * n6,
00574                                          const SMDS_MeshNode * n7,
00575                                          const SMDS_MeshNode * n8)
00576 {
00577   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6, n7, n8);
00578   if(anElem) myScript->AddVolume(anElem->GetID(), 
00579                                  n1->GetID(), 
00580                                  n2->GetID(), 
00581                                  n3->GetID(),
00582                                  n4->GetID(), 
00583                                  n5->GetID(), 
00584                                  n6->GetID(), 
00585                                  n7->GetID(), 
00586                                  n8->GetID());
00587   return anElem;
00588 }
00589 
00590 
00591 //=======================================================================
00592 //function :AddVolume
00593 //purpose  : add hexagonal prism
00594 //=======================================================================
00595 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
00596                                                int n5, int n6, int n7, int n8,
00597                                                int n9, int n10, int n11, int n12,
00598                                                int ID)
00599 {
00600   SMDS_MeshVolume *anElem= SMDS_Mesh::AddVolumeWithID(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, ID);
00601   if(anElem) myScript->AddVolume(ID, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12);
00602   return anElem;
00603 }
00604 
00605 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
00606                                                const SMDS_MeshNode * n2,
00607                                                const SMDS_MeshNode * n3,
00608                                                const SMDS_MeshNode * n4,
00609                                                const SMDS_MeshNode * n5,
00610                                                const SMDS_MeshNode * n6,
00611                                                const SMDS_MeshNode * n7,
00612                                                const SMDS_MeshNode * n8, 
00613                                                const SMDS_MeshNode * n9, 
00614                                                const SMDS_MeshNode * n10, 
00615                                                const SMDS_MeshNode * n11, 
00616                                                const SMDS_MeshNode * n12, 
00617                                                int ID)
00618 {
00619   return AddVolumeWithID(n1->GetID(), 
00620                          n2->GetID(),
00621                          n3->GetID(),
00622                          n4->GetID(),
00623                          n5->GetID(),
00624                          n6->GetID(),
00625                          n7->GetID(),
00626                          n8->GetID(),
00627                          n9->GetID(),
00628                          n10->GetID(),
00629                          n11->GetID(),
00630                          n12->GetID(),
00631                          ID);
00632 }
00633 
00634 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
00635                                          const SMDS_MeshNode * n2,
00636                                          const SMDS_MeshNode * n3,
00637                                          const SMDS_MeshNode * n4,
00638                                          const SMDS_MeshNode * n5,
00639                                          const SMDS_MeshNode * n6,
00640                                          const SMDS_MeshNode * n7,
00641                                          const SMDS_MeshNode * n8, 
00642                                          const SMDS_MeshNode * n9, 
00643                                          const SMDS_MeshNode * n10, 
00644                                          const SMDS_MeshNode * n11, 
00645                                          const SMDS_MeshNode * n12)
00646 {
00647   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12);
00648   if(anElem) myScript->AddVolume(anElem->GetID(), 
00649                                  n1->GetID(),
00650                                  n2->GetID(),
00651                                  n3->GetID(),
00652                                  n4->GetID(),
00653                                  n5->GetID(),
00654                                  n6->GetID(),
00655                                  n7->GetID(),
00656                                  n8->GetID(),
00657                                  n9->GetID(),
00658                                  n10->GetID(),
00659                                  n11->GetID(),
00660                                  n12->GetID());
00661   return anElem;
00662 }
00663 
00664 
00665 //=======================================================================
00666 //function : AddPolygonalFace
00667 //purpose  : 
00668 //=======================================================================
00669 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID (const std::vector<int>& nodes_ids,
00670                                                      const int               ID)
00671 {
00672   SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFaceWithID(nodes_ids, ID);
00673   if (anElem) {
00674     myScript->AddPolygonalFace(ID, nodes_ids);
00675   }
00676   return anElem;
00677 }
00678 
00679 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFaceWithID
00680                              (const std::vector<const SMDS_MeshNode*>& nodes,
00681                               const int                                ID)
00682 {
00683   SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFaceWithID(nodes, ID);
00684   if (anElem) {
00685     int i, len = nodes.size();
00686     std::vector<int> nodes_ids (len);
00687     for (i = 0; i < len; i++) {
00688       nodes_ids[i] = nodes[i]->GetID();
00689     }
00690     myScript->AddPolygonalFace(ID, nodes_ids);
00691   }
00692   return anElem;
00693 }
00694 
00695 SMDS_MeshFace* SMESHDS_Mesh::AddPolygonalFace
00696                              (const std::vector<const SMDS_MeshNode*>& nodes)
00697 {
00698   SMDS_MeshFace *anElem = SMDS_Mesh::AddPolygonalFace(nodes);
00699   if (anElem) {
00700     int i, len = nodes.size();
00701     std::vector<int> nodes_ids (len);
00702     for (i = 0; i < len; i++) {
00703       nodes_ids[i] = nodes[i]->GetID();
00704     }
00705     myScript->AddPolygonalFace(anElem->GetID(), nodes_ids);
00706   }
00707   return anElem;
00708 }
00709 
00710 //=======================================================================
00711 //function : AddPolyhedralVolume
00712 //purpose  : 
00713 //=======================================================================
00714 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID (const std::vector<int>& nodes_ids,
00715                                                           const std::vector<int>& quantities,
00716                                                           const int               ID)
00717 {
00718   SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes_ids, quantities, ID);
00719   if (anElem) {
00720     myScript->AddPolyhedralVolume(ID, nodes_ids, quantities);
00721   }
00722   return anElem;
00723 }
00724 
00725 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolumeWithID
00726                                (const std::vector<const SMDS_MeshNode*>& nodes,
00727                                 const std::vector<int>&                  quantities,
00728                                 const int                                ID)
00729 {
00730   SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolumeWithID(nodes, quantities, ID);
00731   if (anElem) {
00732     int i, len = nodes.size();
00733     std::vector<int> nodes_ids (len);
00734     for (i = 0; i < len; i++) {
00735       nodes_ids[i] = nodes[i]->GetID();
00736     }
00737     myScript->AddPolyhedralVolume(ID, nodes_ids, quantities);
00738   }
00739   return anElem;
00740 }
00741 
00742 SMDS_MeshVolume* SMESHDS_Mesh::AddPolyhedralVolume
00743                                (const std::vector<const SMDS_MeshNode*>& nodes,
00744                                 const std::vector<int>&                  quantities)
00745 {
00746   SMDS_MeshVolume *anElem = SMDS_Mesh::AddPolyhedralVolume(nodes, quantities);
00747   if (anElem) {
00748     int i, len = nodes.size();
00749     std::vector<int> nodes_ids (len);
00750     for (i = 0; i < len; i++) {
00751       nodes_ids[i] = nodes[i]->GetID();
00752     }
00753     myScript->AddPolyhedralVolume(anElem->GetID(), nodes_ids, quantities);
00754   }
00755   return anElem;
00756 }
00757 
00758 //=======================================================================
00759 //function : removeFromContainers
00760 //purpose  : 
00761 //=======================================================================
00762 
00763 static void removeFromContainers (map<int,SMESHDS_SubMesh*>&     theSubMeshes,
00764                                   set<SMESHDS_GroupBase*>&       theGroups,
00765                                   list<const SMDS_MeshElement*>& theElems,
00766                                   const bool                     isNode)
00767 {
00768   if ( theElems.empty() )
00769     return;
00770 
00771   // Rm from group
00772   // Element can belong to several groups
00773   if ( !theGroups.empty() )
00774   {
00775     set<SMESHDS_GroupBase*>::iterator GrIt = theGroups.begin();
00776     for ( ; GrIt != theGroups.end(); GrIt++ )
00777     {
00778       SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>( *GrIt );
00779       if ( !group || group->IsEmpty() ) continue;
00780 
00781       list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
00782       for ( ; elIt != theElems.end(); elIt++ )
00783       {
00784         group->SMDSGroup().Remove( *elIt );
00785         if ( group->IsEmpty() ) break;
00786       }
00787     }
00788   }
00789 
00790   const bool deleted=true;
00791 
00792   // Rm from sub-meshes
00793   // Element should belong to only one sub-mesh
00794   if ( !theSubMeshes.empty() )
00795   {
00796     SMESHDS_Mesh* mesh = theSubMeshes.begin()->second->getParent();
00797     list<const SMDS_MeshElement *>::iterator elIt = theElems.begin();
00798     if ( isNode ) {
00799       for ( ; elIt != theElems.end(); ++elIt )
00800         if ( SMESHDS_SubMesh* sm = mesh->MeshElements( (*elIt)->getshapeId() ))
00801           sm->RemoveNode( static_cast<const SMDS_MeshNode*> (*elIt), deleted );
00802     }
00803     else {
00804       for ( ; elIt != theElems.end(); ++elIt )
00805         if ( SMESHDS_SubMesh* sm = mesh->MeshElements( (*elIt)->getshapeId() ))
00806           sm->RemoveElement( *elIt, deleted );
00807     }
00808   }
00809 }
00810 
00811 //=======================================================================
00812 //function : RemoveNode
00813 //purpose  : 
00814 //=======================================================================
00815 void SMESHDS_Mesh::RemoveNode(const SMDS_MeshNode * n)
00816 {
00817   if ( n->NbInverseElements() == 0 && !(hasConstructionEdges() || hasConstructionFaces()))
00818   {
00819     SMESHDS_SubMesh* subMesh=0;
00820     map<int,SMESHDS_SubMesh*>::iterator SubIt =
00821       myShapeIndexToSubMesh.find( n->getshapeId() );
00822     if ( SubIt != myShapeIndexToSubMesh.end() )
00823       subMesh = SubIt->second;
00824     else
00825       SubIt = myShapeIndexToSubMesh.begin();
00826     for ( ; !subMesh && SubIt != myShapeIndexToSubMesh.end(); SubIt++ )
00827       if (!SubIt->second->IsComplexSubmesh() && SubIt->second->Contains( n ))
00828         subMesh = SubIt->second;
00829 
00830     RemoveFreeNode( n, subMesh, true);
00831     return;
00832   }
00833     
00834   myScript->RemoveNode(n->GetID());
00835   
00836   list<const SMDS_MeshElement *> removedElems;
00837   list<const SMDS_MeshElement *> removedNodes;
00838 
00839   SMDS_Mesh::RemoveElement( n, removedElems, removedNodes, true );
00840 
00841   removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
00842   removeFromContainers( myShapeIndexToSubMesh, myGroups, removedNodes, true );
00843 }
00844 
00845 //=======================================================================
00846 //function : RemoveFreeNode
00847 //purpose  : 
00848 //=======================================================================
00849 void SMESHDS_Mesh::RemoveFreeNode(const SMDS_MeshNode * n,
00850                                   SMESHDS_SubMesh *     subMesh,
00851                                   bool                  fromGroups)
00852 {
00853   myScript->RemoveNode(n->GetID());
00854 
00855   // Rm from group
00856   // Node can belong to several groups
00857   if (fromGroups && !myGroups.empty()) {
00858     set<SMESHDS_GroupBase*>::iterator GrIt = myGroups.begin();
00859     for (; GrIt != myGroups.end(); GrIt++) {
00860       SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>(*GrIt);
00861       if (!group || group->IsEmpty()) continue;
00862       group->SMDSGroup().Remove(n);
00863     }
00864   }
00865 
00866   // Rm from sub-mesh
00867   // Node should belong to only one sub-mesh
00868   if( subMesh )
00869     subMesh->RemoveNode(n,/*deleted=*/false);
00870 
00871   SMDS_Mesh::RemoveFreeElement(n);
00872 }
00873 
00874 //=======================================================================
00875 //function : RemoveElement
00876 //purpose  : 
00877 //========================================================================
00878 void SMESHDS_Mesh::RemoveElement(const SMDS_MeshElement * elt)
00879 {
00880   if (elt->GetType() == SMDSAbs_Node)
00881   {
00882     RemoveNode( static_cast<const SMDS_MeshNode*>( elt ));
00883     return;
00884   }
00885   if (!hasConstructionEdges() && !hasConstructionFaces())
00886   {
00887     SMESHDS_SubMesh* subMesh=0;
00888     map<int,SMESHDS_SubMesh*>::iterator SubIt = myShapeIndexToSubMesh.begin();
00889     for ( ; !subMesh && SubIt != myShapeIndexToSubMesh.end(); SubIt++ )
00890       if (!SubIt->second->IsComplexSubmesh() && SubIt->second->Contains( elt ))
00891         subMesh = SubIt->second;
00892     //MESSAGE("subMesh " << elt->getshapeId());
00893     RemoveFreeElement( elt, subMesh, true);
00894     return;
00895   }
00896  
00897   myScript->RemoveElement(elt->GetID());
00898 
00899   list<const SMDS_MeshElement *> removedElems;
00900   list<const SMDS_MeshElement *> removedNodes;
00901 
00902   SMDS_Mesh::RemoveElement(elt, removedElems, removedNodes, false);
00903   
00904   removeFromContainers( myShapeIndexToSubMesh, myGroups, removedElems, false );
00905 }
00906 
00907 //=======================================================================
00908 //function : RemoveFreeElement
00909 //purpose  : 
00910 //========================================================================
00911 void SMESHDS_Mesh::RemoveFreeElement(const SMDS_MeshElement * elt,
00912                                      SMESHDS_SubMesh *        subMesh,
00913                                      bool                     fromGroups)
00914 {
00915   //MESSAGE(" --------------------------------> SMESHDS_Mesh::RemoveFreeElement " << subMesh << " " << fromGroups);
00916   if (elt->GetType() == SMDSAbs_Node) {
00917     RemoveFreeNode( static_cast<const SMDS_MeshNode*>(elt), subMesh);
00918     return;
00919   }
00920 
00921   if (hasConstructionEdges() || hasConstructionFaces())
00922     // this methods is only for meshes without descendants
00923     return;
00924 
00925   myScript->RemoveElement(elt->GetID());
00926 
00927   // Rm from group
00928   // Node can belong to several groups
00929   if ( fromGroups && !myGroups.empty() ) {
00930     set<SMESHDS_GroupBase*>::iterator GrIt = myGroups.begin();
00931     for (; GrIt != myGroups.end(); GrIt++) {
00932       SMESHDS_Group* group = dynamic_cast<SMESHDS_Group*>(*GrIt);
00933       if (group && !group->IsEmpty())
00934         group->SMDSGroup().Remove(elt);
00935     }
00936   }
00937 
00938   // Rm from sub-mesh
00939   // Element should belong to only one sub-mesh
00940   if( subMesh )
00941     subMesh->RemoveElement(elt, /*deleted=*/false);
00942 
00943   SMDS_Mesh::RemoveFreeElement(elt);
00944 }
00945 
00946 //================================================================================
00950 //================================================================================
00951 
00952 void SMESHDS_Mesh::ClearMesh()
00953 {
00954   myScript->ClearMesh();
00955   SMDS_Mesh::Clear();
00956 
00957   // clear submeshes
00958   map<int,SMESHDS_SubMesh*>::iterator sub, subEnd = myShapeIndexToSubMesh.end();
00959   for ( sub = myShapeIndexToSubMesh.begin(); sub != subEnd; ++sub )
00960     sub->second->Clear();
00961 
00962   // clear groups
00963   TGroups::iterator group, groupEnd = myGroups.end();
00964   for ( group = myGroups.begin(); group != groupEnd; ++group ) {
00965     if ( SMESHDS_Group* g = dynamic_cast<SMESHDS_Group*>(*group)) {
00966       SMDSAbs_ElementType groupType = g->GetType();
00967       g->Clear();
00968       g->SetType( groupType );
00969     }
00970   }
00971 }
00972 
00973 //================================================================================
00981 //================================================================================
00982 
00983 SMESHDS_SubMesh* SMESHDS_Mesh::getSubmesh( const TopoDS_Shape & shape )
00984 {
00985   if ( shape.IsNull() )
00986     return 0;
00987 
00988   if ( !myCurSubShape.IsNull() && shape.IsSame( myCurSubShape ))
00989     return myCurSubMesh;
00990 
00991   getSubmesh( ShapeToIndex( shape ));
00992   myCurSubShape = shape;
00993   return myCurSubMesh;
00994 }
00995 
00996 //================================================================================
01003 //================================================================================
01004 
01005 SMESHDS_SubMesh* SMESHDS_Mesh::getSubmesh( const int Index )
01006 {
01007   //Update or build submesh
01008   if ( Index != myCurSubID ) {
01009     map<int,SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.find( Index );
01010     if ( it == myShapeIndexToSubMesh.end() )
01011       it = myShapeIndexToSubMesh.insert( make_pair(Index, new SMESHDS_SubMesh(this, Index) )).first;
01012     myCurSubMesh = it->second;
01013     myCurSubID = Index;
01014     myCurSubShape.Nullify(); // myCurSubShape no more corresponds to submesh
01015   }
01016   return myCurSubMesh;
01017 }
01018 
01019 //================================================================================
01025 //================================================================================
01026 
01027 bool SMESHDS_Mesh::add(const SMDS_MeshElement* elem, SMESHDS_SubMesh* subMesh )
01028 {
01029   if ( elem && subMesh ) {
01030     if ( elem->GetType() == SMDSAbs_Node )
01031       subMesh->AddNode( static_cast<const SMDS_MeshNode* >( elem ));
01032     else
01033       subMesh->AddElement( elem );
01034     return true;
01035   }
01036   return false;
01037 }
01038 
01039 //=======================================================================
01040 //function : SetNodeOnVolume
01041 //purpose  : 
01042 //=======================================================================
01043 void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode *      aNode,
01044                                    const TopoDS_Shell & S)
01045 {
01046   if ( add( aNode, getSubmesh(S) ))
01047     aNode->SetPosition ( SMDS_SpacePosition::originSpacePosition() );
01048 }
01049 
01050 //=======================================================================
01051 //function : SetNodeOnVolume
01052 //purpose  : 
01053 //=======================================================================
01054 void SMESHDS_Mesh::SetNodeInVolume(SMDS_MeshNode *      aNode,
01055                                    const TopoDS_Solid & S)
01056 {
01057   if ( add( aNode, getSubmesh(S) ))
01058     aNode->SetPosition ( SMDS_SpacePosition::originSpacePosition() );
01059 }
01060 
01061 //=======================================================================
01062 //function : SetNodeOnFace
01063 //purpose  : 
01064 //=======================================================================
01065 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode *     aNode,
01066                                  const TopoDS_Face & S,
01067                                  double              u,
01068                                  double              v)
01069 {
01070   if ( add( aNode, getSubmesh(S) ))
01071     aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition( u, v)));
01072 }
01073 
01074 //=======================================================================
01075 //function : SetNodeOnEdge
01076 //purpose  : 
01077 //=======================================================================
01078 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode *     aNode,
01079                                  const TopoDS_Edge & S,
01080                                  double              u)
01081 {
01082   if ( add( aNode, getSubmesh(S) ))
01083     aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(u)));
01084 }
01085 
01086 //=======================================================================
01087 //function : SetNodeOnVertex
01088 //purpose  : 
01089 //=======================================================================
01090 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode *       aNode,
01091                                    const TopoDS_Vertex & S)
01092 {
01093   if ( add( aNode, getSubmesh(S) ))
01094     aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition()));
01095 }
01096 
01097 //=======================================================================
01098 //function : UnSetNodeOnShape
01099 //purpose  : 
01100 //=======================================================================
01101 void SMESHDS_Mesh::UnSetNodeOnShape(const SMDS_MeshNode* aNode)
01102 {
01103   int shapeId = aNode->getshapeId();
01104   if (shapeId >= 0)
01105     {
01106       map<int, SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.find(shapeId);
01107       if (it != myShapeIndexToSubMesh.end())
01108         it->second->RemoveNode(aNode, /*deleted=*/false);
01109     }
01110 }
01111 
01112 //=======================================================================
01113 //function : SetMeshElementOnShape
01114 //purpose  : 
01115 //=======================================================================
01116 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement * anElement,
01117                                          const TopoDS_Shape &     S)
01118 {
01119   add( anElement, getSubmesh(S) );
01120 }
01121 
01122 //=======================================================================
01123 //function : UnSetMeshElementOnShape
01124 //purpose  : 
01125 //=======================================================================
01126 void SMESHDS_Mesh::UnSetMeshElementOnShape(const SMDS_MeshElement * elem,
01127                                            const TopoDS_Shape &     S)
01128 {
01129   int Index = myIndexToShape.FindIndex(S);
01130 
01131   map<int,SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.find( Index );
01132   if ( it != myShapeIndexToSubMesh.end() )
01133     {
01134       if (elem->GetType() == SMDSAbs_Node)
01135         it->second->RemoveNode(static_cast<const SMDS_MeshNode*> (elem), /*deleted=*/false);
01136       else
01137         it->second->RemoveElement(elem, /*deleted=*/false);
01138     }
01139 }
01140 
01141 //=======================================================================
01142 //function : ShapeToMesh
01143 //purpose  : 
01144 //=======================================================================
01145 TopoDS_Shape SMESHDS_Mesh::ShapeToMesh() const
01146 {
01147         return myShape;
01148 }
01149 
01150 //=======================================================================
01151 //function : IsGroupOfSubShapes
01152 //purpose  : return true if at least one sub-shape of theShape is a sub-shape
01153 //           of myShape or theShape == myShape
01154 //=======================================================================
01155 
01156 bool SMESHDS_Mesh::IsGroupOfSubShapes (const TopoDS_Shape& theShape) const
01157 {
01158   if ( myIndexToShape.Contains(theShape) )
01159     return true;
01160 
01161   for ( TopoDS_Iterator it( theShape ); it.More(); it.Next() )
01162     if (IsGroupOfSubShapes( it.Value() ))
01163       return true;
01164 
01165   return false;
01166 }
01167 
01172 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const TopoDS_Shape & S) const
01173 {
01174   int Index = ShapeToIndex(S);
01175   TShapeIndexToSubMesh::const_iterator anIter = myShapeIndexToSubMesh.find(Index);
01176   if (anIter != myShapeIndexToSubMesh.end())
01177     return anIter->second;
01178   else
01179     return NULL;
01180 }
01181 
01185 SMESHDS_SubMesh * SMESHDS_Mesh::MeshElements(const int Index) const
01186 {
01187   TShapeIndexToSubMesh::const_iterator anIter = myShapeIndexToSubMesh.find(Index);
01188   if (anIter != myShapeIndexToSubMesh.end())
01189     return anIter->second;
01190   else
01191     return NULL;
01192 }
01193 
01194 //=======================================================================
01195 //function : SubMeshIndices
01196 //purpose  : 
01197 //=======================================================================
01198 list<int> SMESHDS_Mesh::SubMeshIndices() const
01199 {
01200   list<int> anIndices;
01201   std::map<int,SMESHDS_SubMesh*>::const_iterator anIter = myShapeIndexToSubMesh.begin();
01202   for (; anIter != myShapeIndexToSubMesh.end(); anIter++) {
01203     anIndices.push_back((*anIter).first);
01204   }
01205   return anIndices;
01206 }
01207 
01208 //=======================================================================
01209 //function : GetHypothesis
01210 //purpose  : 
01211 //=======================================================================
01212 
01213 const list<const SMESHDS_Hypothesis*>&
01214 SMESHDS_Mesh::GetHypothesis(const TopoDS_Shape & S) const
01215 {
01216   if ( myShapeToHypothesis.IsBound( S.Oriented(TopAbs_FORWARD) ) ) // ignore orientation of S
01217      return myShapeToHypothesis.Find( S.Oriented(TopAbs_FORWARD) );
01218 
01219   static list<const SMESHDS_Hypothesis*> empty;
01220   return empty;
01221 }
01222 
01223 //================================================================================
01227 //================================================================================
01228 
01229 bool SMESHDS_Mesh::IsUsedHypothesis(const SMESHDS_Hypothesis * H) const
01230 {
01231   ShapeToHypothesis::Iterator s2h( myShapeToHypothesis );
01232   for ( ; s2h.More(); s2h.Next() )
01233     if ( std::find( s2h.Value().begin(), s2h.Value().end(), H ) != s2h.Value().end() )
01234       return true;
01235   return false;
01236 }
01237 
01238 //=======================================================================
01239 //function : GetScript
01240 //purpose  : 
01241 //=======================================================================
01242 SMESHDS_Script* SMESHDS_Mesh::GetScript()
01243 {
01244         return myScript;
01245 }
01246 
01247 //=======================================================================
01248 //function : ClearScript
01249 //purpose  : 
01250 //=======================================================================
01251 void SMESHDS_Mesh::ClearScript()
01252 {
01253         myScript->Clear();
01254 }
01255 
01256 //=======================================================================
01257 //function : HasMeshElements
01258 //purpose  : 
01259 //=======================================================================
01260 bool SMESHDS_Mesh::HasMeshElements(const TopoDS_Shape & S) const
01261 {
01262         if (myShape.IsNull()) MESSAGE("myShape is NULL");
01263         int Index = myIndexToShape.FindIndex(S);
01264         return myShapeIndexToSubMesh.find(Index)!=myShapeIndexToSubMesh.end();
01265 }
01266 
01267 //=======================================================================
01268 //function : HasHypothesis
01269 //purpose  : 
01270 //=======================================================================
01271 bool SMESHDS_Mesh::HasHypothesis(const TopoDS_Shape & S)
01272 {
01273   return myShapeToHypothesis.IsBound(S.Oriented(TopAbs_FORWARD));
01274 }
01275 
01276 //=======================================================================
01277 //function : NewSubMesh 
01278 //purpose  : 
01279 //=======================================================================
01280 SMESHDS_SubMesh * SMESHDS_Mesh::NewSubMesh(int Index)
01281 {
01282   SMESHDS_SubMesh* SM = 0;
01283   TShapeIndexToSubMesh::iterator anIter = myShapeIndexToSubMesh.find(Index);
01284   if (anIter == myShapeIndexToSubMesh.end())
01285   {
01286     SM = new SMESHDS_SubMesh(this, Index);
01287     myShapeIndexToSubMesh[Index]=SM;
01288   }
01289   else
01290     SM = anIter->second;
01291   return SM;
01292 }
01293 
01294 //=======================================================================
01295 //function : AddCompoundSubmesh
01296 //purpose  : 
01297 //=======================================================================
01298 
01299 int SMESHDS_Mesh::AddCompoundSubmesh(const TopoDS_Shape& S,
01300                                      TopAbs_ShapeEnum    type)
01301 {
01302   int aMainIndex = 0;
01303   if ( IsGroupOfSubShapes( S ))
01304   {
01305     aMainIndex = myIndexToShape.Add( S );
01306     bool all = ( type == TopAbs_SHAPE );
01307     if ( all ) // corresponding simple submesh may exist
01308       aMainIndex = -aMainIndex;
01309     //MESSAGE("AddCompoundSubmesh index = " << aMainIndex );
01310     SMESHDS_SubMesh * aNewSub = NewSubMesh( aMainIndex );
01311     if ( !aNewSub->IsComplexSubmesh() ) // is empty
01312     {
01313       int shapeType = Max( TopAbs_SOLID, all ? myShape.ShapeType() : type );
01314       int typeLimit = all ? TopAbs_VERTEX : type;
01315       for ( ; shapeType <= typeLimit; shapeType++ )
01316       {
01317         TopExp_Explorer exp( S, TopAbs_ShapeEnum( shapeType ));
01318         for ( ; exp.More(); exp.Next() )
01319         {
01320           int index = myIndexToShape.FindIndex( exp.Current() );
01321           if ( index )
01322             aNewSub->AddSubMesh( NewSubMesh( index ));
01323         }
01324       }
01325     }
01326   }
01327   return aMainIndex;
01328 }
01329 
01330 //=======================================================================
01331 //function : IndexToShape
01332 //purpose  : 
01333 //=======================================================================
01334 const TopoDS_Shape& SMESHDS_Mesh::IndexToShape(int ShapeIndex) const
01335 {
01336   try
01337   {
01338     return myIndexToShape.FindKey(ShapeIndex);
01339   }
01340   catch ( Standard_OutOfRange )
01341   {
01342   }
01343   static TopoDS_Shape nullShape;
01344   return nullShape;
01345 }
01346 
01347 //================================================================================
01351 //================================================================================
01352 
01353 int SMESHDS_Mesh::MaxSubMeshIndex() const
01354 {
01355   return myShapeIndexToSubMesh.empty() ? 0 : myShapeIndexToSubMesh.rbegin()->first;
01356 }
01357 
01358 //=======================================================================
01359 //function : ShapeToIndex
01360 //purpose  : 
01361 //=======================================================================
01362 int SMESHDS_Mesh::ShapeToIndex(const TopoDS_Shape & S) const
01363 {
01364   if (myShape.IsNull())
01365     MESSAGE("myShape is NULL");
01366 
01367   int index = myIndexToShape.FindIndex(S);
01368   
01369   return index;
01370 }
01371 
01372 //=======================================================================
01373 //function : SetNodeOnVolume
01374 //purpose  : 
01375 //=======================================================================
01376 void SMESHDS_Mesh::SetNodeInVolume(const SMDS_MeshNode* aNode, int Index)
01377 {
01378   //add(aNode, getSubmesh(Index));
01379   if ( add( aNode, getSubmesh( Index )))
01380     ((SMDS_MeshNode*) aNode)->SetPosition( SMDS_SpacePosition::originSpacePosition());
01381 }
01382 
01383 //=======================================================================
01384 //function : SetNodeOnFace
01385 //purpose  : 
01386 //=======================================================================
01387 void SMESHDS_Mesh::SetNodeOnFace(SMDS_MeshNode* aNode, int Index, double u, double v)
01388 {
01389   //Set Position on Node
01390   if ( add( aNode, getSubmesh( Index )))
01391     aNode->SetPosition(SMDS_PositionPtr(new SMDS_FacePosition( u, v)));
01392 }
01393 
01394 //=======================================================================
01395 //function : SetNodeOnEdge
01396 //purpose  : 
01397 //=======================================================================
01398 void SMESHDS_Mesh::SetNodeOnEdge(SMDS_MeshNode* aNode,
01399                                  int            Index,
01400                                  double         u)
01401 {
01402   //Set Position on Node
01403   if ( add( aNode, getSubmesh( Index )))
01404     aNode->SetPosition(SMDS_PositionPtr(new SMDS_EdgePosition(u)));
01405 }
01406 
01407 //=======================================================================
01408 //function : SetNodeOnVertex
01409 //purpose  : 
01410 //=======================================================================
01411 void SMESHDS_Mesh::SetNodeOnVertex(SMDS_MeshNode* aNode, int Index)
01412 {
01413   //Set Position on Node
01414   if ( add( aNode, getSubmesh( Index )))
01415     aNode->SetPosition(SMDS_PositionPtr(new SMDS_VertexPosition()));
01416 }
01417 
01418 //=======================================================================
01419 //function : SetMeshElementOnShape
01420 //purpose  : 
01421 //=======================================================================
01422 void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement* anElement,
01423                                          int                     Index)
01424 {
01425   add( anElement, getSubmesh( Index ));
01426 }
01427 
01428 //=======================================================================
01429 //function : ~SMESHDS_Mesh
01430 //purpose  : 
01431 //=======================================================================
01432 SMESHDS_Mesh::~SMESHDS_Mesh()
01433 {
01434   // myScript
01435   delete myScript;
01436   // submeshes
01437   TShapeIndexToSubMesh::iterator i_sm = myShapeIndexToSubMesh.begin();
01438   for ( ; i_sm != myShapeIndexToSubMesh.end(); ++i_sm )
01439     delete i_sm->second;
01440 }
01441 
01442 
01443 //********************************************************************
01444 //********************************************************************
01445 //********                                                   *********
01446 //*****       Methods for addition of quadratic elements        ******
01447 //********                                                   *********
01448 //********************************************************************
01449 //********************************************************************
01450 
01451 //=======================================================================
01452 //function : AddEdgeWithID
01453 //purpose  : 
01454 //=======================================================================
01455 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(int n1, int n2, int n12, int ID) 
01456 {
01457   SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdgeWithID(n1,n2,n12,ID);
01458   if(anElem) myScript->AddEdge(ID,n1,n2,n12);
01459   return anElem;
01460 }
01461 
01462 //=======================================================================
01463 //function : AddEdge
01464 //purpose  : 
01465 //=======================================================================
01466 SMDS_MeshEdge* SMESHDS_Mesh::AddEdge(const SMDS_MeshNode* n1,
01467                                      const SMDS_MeshNode* n2,
01468                                      const SMDS_MeshNode* n12)
01469 {
01470   SMDS_MeshEdge* anElem = SMDS_Mesh::AddEdge(n1,n2,n12);
01471   if(anElem) myScript->AddEdge(anElem->GetID(), 
01472                                n1->GetID(), 
01473                                n2->GetID(),
01474                                n12->GetID());
01475   return anElem;
01476 }
01477 
01478 //=======================================================================
01479 //function : AddEdgeWithID
01480 //purpose  : 
01481 //=======================================================================
01482 SMDS_MeshEdge* SMESHDS_Mesh::AddEdgeWithID(const SMDS_MeshNode * n1,
01483                                            const SMDS_MeshNode * n2, 
01484                                            const SMDS_MeshNode * n12, 
01485                                            int ID)
01486 {
01487   return AddEdgeWithID(n1->GetID(),
01488                        n2->GetID(),
01489                        n12->GetID(),
01490                        ID);
01491 }
01492 
01493 
01494 //=======================================================================
01495 //function : AddFace
01496 //purpose  : 
01497 //=======================================================================
01498 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
01499                                      const SMDS_MeshNode * n2,
01500                                      const SMDS_MeshNode * n3,
01501                                      const SMDS_MeshNode * n12,
01502                                      const SMDS_MeshNode * n23,
01503                                      const SMDS_MeshNode * n31)
01504 {
01505   SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1,n2,n3,n12,n23,n31);
01506   if(anElem) myScript->AddFace(anElem->GetID(), 
01507                                n1->GetID(), n2->GetID(), n3->GetID(),
01508                                n12->GetID(), n23->GetID(), n31->GetID());
01509   return anElem;
01510 }
01511 
01512 //=======================================================================
01513 //function : AddFaceWithID
01514 //purpose  : 
01515 //=======================================================================
01516 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3,
01517                                            int n12,int n23,int n31, int ID)
01518 {
01519   SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1,n2,n3,n12,n23,n31,ID);
01520   if(anElem) myScript->AddFace(ID,n1,n2,n3,n12,n23,n31);
01521   return anElem;
01522 }
01523 
01524 //=======================================================================
01525 //function : AddFaceWithID
01526 //purpose  : 
01527 //=======================================================================
01528 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
01529                                            const SMDS_MeshNode * n2,
01530                                            const SMDS_MeshNode * n3,
01531                                            const SMDS_MeshNode * n12,
01532                                            const SMDS_MeshNode * n23,
01533                                            const SMDS_MeshNode * n31, 
01534                                            int ID)
01535 {
01536   return AddFaceWithID(n1->GetID(), n2->GetID(), n3->GetID(),
01537                        n12->GetID(), n23->GetID(), n31->GetID(),
01538                        ID);
01539 }
01540 
01541 
01542 //=======================================================================
01543 //function : AddFace
01544 //purpose  : 
01545 //=======================================================================
01546 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
01547                                      const SMDS_MeshNode * n2,
01548                                      const SMDS_MeshNode * n3,
01549                                      const SMDS_MeshNode * n4,
01550                                      const SMDS_MeshNode * n12,
01551                                      const SMDS_MeshNode * n23,
01552                                      const SMDS_MeshNode * n34,
01553                                      const SMDS_MeshNode * n41)
01554 {
01555   SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1,n2,n3,n4,n12,n23,n34,n41);
01556   if(anElem) myScript->AddFace(anElem->GetID(), 
01557                                n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
01558                                n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID());
01559   return anElem;
01560 }
01561 
01562 //=======================================================================
01563 //function : AddFaceWithID
01564 //purpose  : 
01565 //=======================================================================
01566 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
01567                                            int n12,int n23,int n34,int n41, int ID)
01568 {
01569   SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,ID);
01570   if(anElem) myScript->AddFace(ID,n1,n2,n3,n4,n12,n23,n34,n41);
01571   return anElem;
01572 }
01573 
01574 //=======================================================================
01575 //function : AddFaceWithID
01576 //purpose  : 
01577 //=======================================================================
01578 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
01579                                            const SMDS_MeshNode * n2,
01580                                            const SMDS_MeshNode * n3,
01581                                            const SMDS_MeshNode * n4,
01582                                            const SMDS_MeshNode * n12,
01583                                            const SMDS_MeshNode * n23,
01584                                            const SMDS_MeshNode * n34, 
01585                                            const SMDS_MeshNode * n41, 
01586                                            int ID)
01587 {
01588   return AddFaceWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
01589                        n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
01590                        ID);
01591 }
01592 
01593 
01594 //=======================================================================
01595 //function : AddFace
01596 //purpose  : 
01597 //=======================================================================
01598 SMDS_MeshFace* SMESHDS_Mesh::AddFace(const SMDS_MeshNode * n1,
01599                                      const SMDS_MeshNode * n2,
01600                                      const SMDS_MeshNode * n3,
01601                                      const SMDS_MeshNode * n4,
01602                                      const SMDS_MeshNode * n12,
01603                                      const SMDS_MeshNode * n23,
01604                                      const SMDS_MeshNode * n34,
01605                                      const SMDS_MeshNode * n41, 
01606                                      const SMDS_MeshNode * nCenter)
01607 {
01608   SMDS_MeshFace *anElem = SMDS_Mesh::AddFace(n1,n2,n3,n4,n12,n23,n34,n41,nCenter);
01609   if(anElem) myScript->AddFace(anElem->GetID(), 
01610                                n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
01611                                n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
01612                                nCenter->GetID());
01613   return anElem;
01614 }
01615 
01616 //=======================================================================
01617 //function : AddFaceWithID
01618 //purpose  : 
01619 //=======================================================================
01620 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(int n1, int n2, int n3, int n4,
01621                                            int n12,int n23,int n34,int n41,
01622                                            int nCenter, int ID)
01623 {
01624   SMDS_MeshFace *anElem = SMDS_Mesh::AddFaceWithID(n1,n2,n3,n4,n12,n23,n34,n41,nCenter,ID);
01625   if(anElem) myScript->AddFace(ID,n1,n2,n3,n4,n12,n23,n34,n41,nCenter);
01626   return anElem;
01627 }
01628 
01629 //=======================================================================
01630 //function : AddFaceWithID
01631 //purpose  : 
01632 //=======================================================================
01633 SMDS_MeshFace* SMESHDS_Mesh::AddFaceWithID(const SMDS_MeshNode * n1,
01634                                            const SMDS_MeshNode * n2,
01635                                            const SMDS_MeshNode * n3,
01636                                            const SMDS_MeshNode * n4,
01637                                            const SMDS_MeshNode * n12,
01638                                            const SMDS_MeshNode * n23,
01639                                            const SMDS_MeshNode * n34, 
01640                                            const SMDS_MeshNode * n41, 
01641                                            const SMDS_MeshNode * nCenter, 
01642                                            int ID)
01643 {
01644   return AddFaceWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
01645                        n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
01646                        nCenter->GetID(), ID);
01647 }
01648 
01649 
01650 //=======================================================================
01651 //function : AddVolume
01652 //purpose  : 
01653 //=======================================================================
01654 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
01655                                          const SMDS_MeshNode * n2, 
01656                                          const SMDS_MeshNode * n3,
01657                                          const SMDS_MeshNode * n4,
01658                                          const SMDS_MeshNode * n12,
01659                                          const SMDS_MeshNode * n23,
01660                                          const SMDS_MeshNode * n31,
01661                                          const SMDS_MeshNode * n14, 
01662                                          const SMDS_MeshNode * n24,
01663                                          const SMDS_MeshNode * n34)
01664 {
01665   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n12,n23,n31,n14,n24,n34);
01666   if(anElem) myScript->AddVolume(anElem->GetID(), 
01667                                  n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
01668                                  n12->GetID(), n23->GetID(), n31->GetID(),
01669                                  n14->GetID(), n24->GetID(), n34->GetID());
01670   return anElem;
01671 }
01672 
01673 //=======================================================================
01674 //function : AddVolumeWithID
01675 //purpose  : 
01676 //=======================================================================
01677 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
01678                                                int n12,int n23,int n31,
01679                                                int n14,int n24,int n34, int ID)
01680 {
01681   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n12,n23,
01682                                                        n31,n14,n24,n34,ID);
01683   if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n12,n23,n31,n14,n24,n34);
01684   return anElem;
01685 }
01686         
01687 //=======================================================================
01688 //function : AddVolumeWithID
01689 //purpose  : 2d order tetrahedron of 10 nodes
01690 //=======================================================================
01691 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
01692                                                const SMDS_MeshNode * n2,
01693                                                const SMDS_MeshNode * n3,
01694                                                const SMDS_MeshNode * n4,
01695                                                const SMDS_MeshNode * n12,
01696                                                const SMDS_MeshNode * n23,
01697                                                const SMDS_MeshNode * n31,
01698                                                const SMDS_MeshNode * n14, 
01699                                                const SMDS_MeshNode * n24,
01700                                                const SMDS_MeshNode * n34,
01701                                                int ID)
01702 {
01703   return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
01704                          n12->GetID(), n23->GetID(), n31->GetID(),
01705                          n14->GetID(), n24->GetID(), n34->GetID(), ID);
01706 }
01707 
01708 
01709 //=======================================================================
01710 //function : AddVolume
01711 //purpose  : 
01712 //=======================================================================
01713 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
01714                                          const SMDS_MeshNode * n2, 
01715                                          const SMDS_MeshNode * n3,
01716                                          const SMDS_MeshNode * n4,
01717                                          const SMDS_MeshNode * n5, 
01718                                          const SMDS_MeshNode * n12,
01719                                          const SMDS_MeshNode * n23,
01720                                          const SMDS_MeshNode * n34,
01721                                          const SMDS_MeshNode * n41,
01722                                          const SMDS_MeshNode * n15, 
01723                                          const SMDS_MeshNode * n25,
01724                                          const SMDS_MeshNode * n35,
01725                                          const SMDS_MeshNode * n45)
01726 {
01727   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n5,n12,n23,n34,n41,
01728                                                  n15,n25,n35,n45);
01729   if(anElem)
01730     myScript->AddVolume(anElem->GetID(), n1->GetID(), n2->GetID(),
01731                         n3->GetID(), n4->GetID(), n5->GetID(),
01732                         n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
01733                         n15->GetID(), n25->GetID(), n35->GetID(), n45->GetID());
01734   return anElem;
01735 }
01736 
01737 //=======================================================================
01738 //function : AddVolumeWithID
01739 //purpose  : 
01740 //=======================================================================
01741 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4, int n5,
01742                                                int n12,int n23,int n34,int n41,
01743                                                int n15,int n25,int n35,int n45, int ID)
01744 {
01745   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n5,
01746                                                        n12,n23,n34,n41,
01747                                                        n15,n25,n35,n45,ID);
01748   if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n5,n12,n23,n34,n41,
01749                                  n15,n25,n35,n45);
01750   return anElem;
01751 }
01752         
01753 //=======================================================================
01754 //function : AddVolumeWithID
01755 //purpose  : 2d order pyramid of 13 nodes
01756 //=======================================================================
01757 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
01758                                                const SMDS_MeshNode * n2,
01759                                                const SMDS_MeshNode * n3,
01760                                                const SMDS_MeshNode * n4,
01761                                                const SMDS_MeshNode * n5, 
01762                                                const SMDS_MeshNode * n12,
01763                                                const SMDS_MeshNode * n23,
01764                                                const SMDS_MeshNode * n34,
01765                                                const SMDS_MeshNode * n41,
01766                                                const SMDS_MeshNode * n15, 
01767                                                const SMDS_MeshNode * n25,
01768                                                const SMDS_MeshNode * n35,
01769                                                const SMDS_MeshNode * n45,
01770                                                int ID)
01771 {
01772   return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(),
01773                          n4->GetID(), n5->GetID(),
01774                          n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
01775                          n15->GetID(), n25->GetID(), n35->GetID(), n45->GetID(),
01776                          ID);
01777 }
01778 
01779 
01780 //=======================================================================
01781 //function : AddVolume
01782 //purpose  : 
01783 //=======================================================================
01784 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
01785                                          const SMDS_MeshNode * n2, 
01786                                          const SMDS_MeshNode * n3,
01787                                          const SMDS_MeshNode * n4,
01788                                          const SMDS_MeshNode * n5, 
01789                                          const SMDS_MeshNode * n6, 
01790                                          const SMDS_MeshNode * n12,
01791                                          const SMDS_MeshNode * n23,
01792                                          const SMDS_MeshNode * n31, 
01793                                          const SMDS_MeshNode * n45,
01794                                          const SMDS_MeshNode * n56,
01795                                          const SMDS_MeshNode * n64, 
01796                                          const SMDS_MeshNode * n14,
01797                                          const SMDS_MeshNode * n25,
01798                                          const SMDS_MeshNode * n36)
01799 {
01800   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n5,n6,n12,n23,n31,
01801                                                  n45,n56,n64,n14,n25,n36);
01802   if(anElem)
01803     myScript->AddVolume(anElem->GetID(), n1->GetID(), n2->GetID(),
01804                         n3->GetID(), n4->GetID(), n5->GetID(), n6->GetID(),
01805                         n12->GetID(), n23->GetID(), n31->GetID(),
01806                         n45->GetID(), n56->GetID(), n64->GetID(),
01807                         n14->GetID(), n25->GetID(), n36->GetID());
01808   return anElem;
01809 }
01810 
01811 //=======================================================================
01812 //function : AddVolumeWithID
01813 //purpose  : 
01814 //=======================================================================
01815 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3,
01816                                                int n4, int n5, int n6,
01817                                                int n12,int n23,int n31,
01818                                                int n45,int n56,int n64,
01819                                                int n14,int n25,int n36, int ID)
01820 {
01821   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n5,n6,
01822                                                        n12,n23,n31,
01823                                                        n45,n56,n64,
01824                                                        n14,n25,n36,ID);
01825   if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n5,n6,n12,n23,n31,
01826                                  n45,n56,n64,n14,n25,n36);
01827   return anElem;
01828 }
01829         
01830 //=======================================================================
01831 //function : AddVolumeWithID
01832 //purpose  : 2d order Pentahedron with 15 nodes
01833 //=======================================================================
01834 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
01835                                                const SMDS_MeshNode * n2,
01836                                                const SMDS_MeshNode * n3,
01837                                                const SMDS_MeshNode * n4,
01838                                                const SMDS_MeshNode * n5, 
01839                                                const SMDS_MeshNode * n6, 
01840                                                const SMDS_MeshNode * n12,
01841                                                const SMDS_MeshNode * n23,
01842                                                const SMDS_MeshNode * n31, 
01843                                                const SMDS_MeshNode * n45,
01844                                                const SMDS_MeshNode * n56,
01845                                                const SMDS_MeshNode * n64, 
01846                                                const SMDS_MeshNode * n14,
01847                                                const SMDS_MeshNode * n25,
01848                                                const SMDS_MeshNode * n36,
01849                                                int ID)
01850 {
01851   return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(),
01852                          n4->GetID(), n5->GetID(), n6->GetID(),
01853                          n12->GetID(), n23->GetID(), n31->GetID(),
01854                          n45->GetID(), n56->GetID(), n64->GetID(),
01855                          n14->GetID(), n25->GetID(), n36->GetID(),
01856                          ID);
01857 }
01858 
01859 
01860 //=======================================================================
01861 //function : AddVolume
01862 //purpose  : add quadratic hexahedron
01863 //=======================================================================
01864 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
01865                                          const SMDS_MeshNode * n2, 
01866                                          const SMDS_MeshNode * n3,
01867                                          const SMDS_MeshNode * n4,
01868                                          const SMDS_MeshNode * n5, 
01869                                          const SMDS_MeshNode * n6, 
01870                                          const SMDS_MeshNode * n7,
01871                                          const SMDS_MeshNode * n8, 
01872                                          const SMDS_MeshNode * n12,
01873                                          const SMDS_MeshNode * n23,
01874                                          const SMDS_MeshNode * n34,
01875                                          const SMDS_MeshNode * n41, 
01876                                          const SMDS_MeshNode * n56,
01877                                          const SMDS_MeshNode * n67,
01878                                          const SMDS_MeshNode * n78,
01879                                          const SMDS_MeshNode * n85, 
01880                                          const SMDS_MeshNode * n15,
01881                                          const SMDS_MeshNode * n26,
01882                                          const SMDS_MeshNode * n37,
01883                                          const SMDS_MeshNode * n48)
01884 {
01885   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n5,n6,n7,n8,
01886                                                  n12,n23,n34,n41,
01887                                                  n56,n67,n78,n85,
01888                                                  n15,n26,n37,n48);
01889   if(anElem)
01890     myScript->AddVolume(anElem->GetID(), n1->GetID(), n2->GetID(),
01891                         n3->GetID(), n4->GetID(), n5->GetID(),
01892                         n6->GetID(), n7->GetID(), n8->GetID(),
01893                         n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
01894                         n56->GetID(), n67->GetID(), n78->GetID(), n85->GetID(),
01895                         n15->GetID(), n26->GetID(), n37->GetID(), n48->GetID());
01896   return anElem;
01897 }
01898 
01899 //=======================================================================
01900 //function : AddVolumeWithID
01901 //purpose  : 
01902 //=======================================================================
01903 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
01904                                                int n5, int n6, int n7, int n8,
01905                                                int n12,int n23,int n34,int n41,
01906                                                int n56,int n67,int n78,int n85,
01907                                                int n15,int n26,int n37,int n48, int ID)
01908 {
01909   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n5,n6,n7,n8,
01910                                                        n12,n23,n34,n41,
01911                                                        n56,n67,n78,n85,
01912                                                        n15,n26,n37,n48,ID);
01913   if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n5,n6,n7,n8,n12,n23,n34,n41,
01914                                  n56,n67,n78,n85,n15,n26,n37,n48);
01915   return anElem;
01916 }
01917         
01918 //=======================================================================
01919 //function : AddVolumeWithID
01920 //purpose  : 2d order Hexahedrons with 20 nodes
01921 //=======================================================================
01922 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
01923                                                const SMDS_MeshNode * n2,
01924                                                const SMDS_MeshNode * n3,
01925                                                const SMDS_MeshNode * n4,
01926                                                const SMDS_MeshNode * n5, 
01927                                                const SMDS_MeshNode * n6, 
01928                                                const SMDS_MeshNode * n7,
01929                                                const SMDS_MeshNode * n8, 
01930                                                const SMDS_MeshNode * n12,
01931                                                const SMDS_MeshNode * n23,
01932                                                const SMDS_MeshNode * n34,
01933                                                const SMDS_MeshNode * n41, 
01934                                                const SMDS_MeshNode * n56,
01935                                                const SMDS_MeshNode * n67,
01936                                                const SMDS_MeshNode * n78,
01937                                                const SMDS_MeshNode * n85, 
01938                                                const SMDS_MeshNode * n15,
01939                                                const SMDS_MeshNode * n26,
01940                                                const SMDS_MeshNode * n37,
01941                                                const SMDS_MeshNode * n48,
01942                                                int ID)
01943 {
01944   return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
01945                          n5->GetID(), n6->GetID(), n7->GetID(), n8->GetID(),
01946                          n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
01947                          n56->GetID(), n67->GetID(), n78->GetID(), n85->GetID(),
01948                          n15->GetID(), n26->GetID(), n37->GetID(), n48->GetID(),
01949                          ID);
01950 }
01951 
01952 //=======================================================================
01953 //function : AddVolume
01954 //purpose  : add tri-quadratic hexahedron of 27 nodes
01955 //=======================================================================
01956 
01957 SMDS_MeshVolume* SMESHDS_Mesh::AddVolume(const SMDS_MeshNode * n1,
01958                                          const SMDS_MeshNode * n2, 
01959                                          const SMDS_MeshNode * n3,
01960                                          const SMDS_MeshNode * n4,
01961                                          const SMDS_MeshNode * n5, 
01962                                          const SMDS_MeshNode * n6, 
01963                                          const SMDS_MeshNode * n7,
01964                                          const SMDS_MeshNode * n8, 
01965                                          const SMDS_MeshNode * n12,
01966                                          const SMDS_MeshNode * n23,
01967                                          const SMDS_MeshNode * n34,
01968                                          const SMDS_MeshNode * n41, 
01969                                          const SMDS_MeshNode * n56,
01970                                          const SMDS_MeshNode * n67,
01971                                          const SMDS_MeshNode * n78,
01972                                          const SMDS_MeshNode * n85, 
01973                                          const SMDS_MeshNode * n15,
01974                                          const SMDS_MeshNode * n26,
01975                                          const SMDS_MeshNode * n37,
01976                                          const SMDS_MeshNode * n48, 
01977                                          const SMDS_MeshNode * n1234,
01978                                          const SMDS_MeshNode * n1256,
01979                                          const SMDS_MeshNode * n2367,
01980                                          const SMDS_MeshNode * n3478,
01981                                          const SMDS_MeshNode * n1458,
01982                                          const SMDS_MeshNode * n5678,
01983                                          const SMDS_MeshNode * nCenter)
01984 {
01985   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolume(n1,n2,n3,n4,n5,n6,n7,n8,
01986                                                  n12,n23,n34,n41,
01987                                                  n56,n67,n78,n85,
01988                                                  n15,n26,n37,n48,
01989                                                  n1234,n1256,n2367,n3478,n1458,n5678,nCenter);
01990   if(anElem)
01991     myScript->AddVolume(anElem->GetID(), n1->GetID(), n2->GetID(),
01992                         n3->GetID(), n4->GetID(), n5->GetID(),
01993                         n6->GetID(), n7->GetID(), n8->GetID(),
01994                         n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
01995                         n56->GetID(), n67->GetID(), n78->GetID(), n85->GetID(),
01996                         n15->GetID(), n26->GetID(), n37->GetID(), n48->GetID(),
01997                         n1234->GetID(),n1256->GetID(),n2367->GetID(),n3478->GetID(),
01998                         n1458->GetID(),n5678->GetID(),nCenter->GetID());
01999   return anElem;
02000 }
02001 
02002 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(int n1, int n2, int n3, int n4,
02003                                                int n5, int n6, int n7, int n8,
02004                                                int n12,int n23,int n34,int n41,
02005                                                int n56,int n67,int n78,int n85,
02006                                                int n15,int n26,int n37,int n48,
02007                                                int n1234,int n1256,int n2367,int n3478,
02008                                                int n1458,int n5678,int nCenter,
02009                                                int ID)
02010 {
02011   SMDS_MeshVolume *anElem = SMDS_Mesh::AddVolumeWithID(n1,n2,n3,n4,n5,n6,n7,n8,
02012                                                        n12,n23,n34,n41,
02013                                                        n56,n67,n78,n85,
02014                                                        n15,n26,n37,n48,
02015                                                        n1234, n1256, n2367, n3478,
02016                                                        n1458, n5678, nCenter,
02017                                                        ID);
02018   if(anElem) myScript->AddVolume(ID,n1,n2,n3,n4,n5,n6,n7,n8,n12,n23,n34,n41,
02019                                  n56,n67,n78,n85,n15,n26,n37,n48,
02020                                  n1234, n1256, n2367, n3478,
02021                                  n1458, n5678, nCenter);
02022   return anElem;
02023 }
02024 
02025 SMDS_MeshVolume* SMESHDS_Mesh::AddVolumeWithID(const SMDS_MeshNode * n1,
02026                                                const SMDS_MeshNode * n2,
02027                                                const SMDS_MeshNode * n3,
02028                                                const SMDS_MeshNode * n4,
02029                                                const SMDS_MeshNode * n5, 
02030                                                const SMDS_MeshNode * n6, 
02031                                                const SMDS_MeshNode * n7,
02032                                                const SMDS_MeshNode * n8, 
02033                                                const SMDS_MeshNode * n12,
02034                                                const SMDS_MeshNode * n23,
02035                                                const SMDS_MeshNode * n34,
02036                                                const SMDS_MeshNode * n41, 
02037                                                const SMDS_MeshNode * n56,
02038                                                const SMDS_MeshNode * n67,
02039                                                const SMDS_MeshNode * n78,
02040                                                const SMDS_MeshNode * n85, 
02041                                                const SMDS_MeshNode * n15,
02042                                                const SMDS_MeshNode * n26,
02043                                                const SMDS_MeshNode * n37,
02044                                                const SMDS_MeshNode * n48, 
02045                                                const SMDS_MeshNode * n1234,
02046                                                const SMDS_MeshNode * n1256,
02047                                                const SMDS_MeshNode * n2367,
02048                                                const SMDS_MeshNode * n3478,
02049                                                const SMDS_MeshNode * n1458,
02050                                                const SMDS_MeshNode * n5678,
02051                                                const SMDS_MeshNode * nCenter,
02052                                                int ID)
02053 {
02054   return AddVolumeWithID(n1->GetID(), n2->GetID(), n3->GetID(), n4->GetID(),
02055                          n5->GetID(), n6->GetID(), n7->GetID(), n8->GetID(),
02056                          n12->GetID(), n23->GetID(), n34->GetID(), n41->GetID(),
02057                          n56->GetID(), n67->GetID(), n78->GetID(), n85->GetID(),
02058                          n15->GetID(), n26->GetID(), n37->GetID(), n48->GetID(),
02059                          n1234->GetID(),n1256->GetID(),n2367->GetID(),n3478->GetID(),
02060                          n1458->GetID(),n5678->GetID(),nCenter->GetID(), ID);
02061 }
02062 
02063 void SMESHDS_Mesh::compactMesh()
02064 {
02065   int newNodeSize = 0;
02066   int nbNodes = myNodes.size();
02067   int nbVtkNodes = myGrid->GetNumberOfPoints();
02068   MESSAGE("nbNodes=" << nbNodes << " nbVtkNodes=" << nbVtkNodes);
02069   int nbNodeTemp = nbVtkNodes;
02070   if (nbNodes > nbVtkNodes)
02071     nbNodeTemp = nbNodes;
02072   vector<int> idNodesOldToNew;
02073   idNodesOldToNew.clear();
02074   idNodesOldToNew.resize(nbNodeTemp, -1); // all unused id will be -1
02075 
02076   for (int i = 0; i < nbNodes; i++)
02077     {
02078       if (myNodes[i])
02079         {
02080           int vtkid = myNodes[i]->getVtkId();
02081           idNodesOldToNew[vtkid] = i; // old vtkId --> old smdsId (valid smdsId are >= 0)
02082           newNodeSize++;
02083         }
02084     }
02085   bool areNodesModified = (newNodeSize < nbVtkNodes);
02086   MESSAGE("------------------------- compactMesh Nodes Modified: " << areNodesModified);
02087   areNodesModified = true;
02088 
02089   int newCellSize = 0;
02090   int nbCells = myCells.size();
02091   int nbVtkCells = myGrid->GetNumberOfCells();
02092   MESSAGE("nbCells=" << nbCells << " nbVtkCells=" << nbVtkCells);
02093   int nbCellTemp = nbVtkCells;
02094   if (nbCells > nbVtkCells)
02095     nbCellTemp = nbCells;
02096   vector<int> idCellsOldToNew;
02097   idCellsOldToNew.clear();
02098   idCellsOldToNew.resize(nbCellTemp, -1); // all unused id will be -1
02099 
02100   for (int i = 0; i < nbCells; i++)
02101     {
02102       if (myCells[i])
02103         {
02104 //          //idCellsOldToNew[i] = myCellIdVtkToSmds[i]; // valid vtk indexes are > = 0
02105 //          int vtkid = myCells[i]->getVtkId();
02106 //          idCellsOldToNew[vtkid] = i; // old vtkId --> old smdsId (not used in input)
02107           newCellSize++;
02108         }
02109     }
02110   if (areNodesModified)
02111     myGrid->compactGrid(idNodesOldToNew, newNodeSize, idCellsOldToNew, newCellSize);
02112   else
02113     myGrid->compactGrid(idNodesOldToNew, 0, idCellsOldToNew, newCellSize);
02114 
02115   int nbVtkPts = myGrid->GetNumberOfPoints();
02116   nbVtkCells = myGrid->GetNumberOfCells();
02117   if (nbVtkPts != newNodeSize)
02118     {
02119       MESSAGE("===> nbVtkPts != newNodeSize " << nbVtkPts << " " << newNodeSize);
02120       if (nbVtkPts > newNodeSize) newNodeSize = nbVtkPts; // several points with same SMDS Id
02121     }
02122   if (nbVtkCells != newCellSize)
02123     {
02124       MESSAGE("===> nbVtkCells != newCellSize " << nbVtkCells << " " << newCellSize);
02125       if (nbVtkCells > newCellSize) newCellSize = nbVtkCells; // several cells with same SMDS Id
02126     }
02127 
02128   // --- SMDS_MeshNode and myNodes (id in SMDS and in VTK are the same), myNodeIdFactory
02129 
02130   if (areNodesModified)
02131     {
02132       MESSAGE("-------------- modify myNodes");
02133       SetOfNodes newNodes;
02134       newNodes.resize(newNodeSize+1,0); // 0 not used, SMDS numbers 1..n
02135       int newSmdsId = 0;
02136       for (int i = 0; i < nbNodes; i++)
02137         {
02138           if (myNodes[i])
02139             {
02140               newSmdsId++; // SMDS id start to 1
02141               int oldVtkId = myNodes[i]->getVtkId();
02142               int newVtkId = idNodesOldToNew[oldVtkId];
02143               //MESSAGE("myNodes["<< i << "] vtkId " << oldVtkId << " --> " << newVtkId);
02144               myNodes[i]->setVtkId(newVtkId);
02145               myNodes[i]->setId(newSmdsId);
02146               newNodes[newSmdsId] = myNodes[i];
02147               //MESSAGE("myNodes["<< i << "] --> newNodes[" << newSmdsId << "]");
02148             }
02149         }
02150       myNodes.swap(newNodes);
02151       this->myNodeIDFactory->emptyPool(newSmdsId); // newSmdsId = number of nodes
02152       MESSAGE("myNodes.size " << myNodes.size());
02153     }
02154 
02155   // --- SMDS_MeshCell, myCellIdVtkToSmds, myCellIdSmdsToVtk, myCells
02156 
02157   int vtkIndexSize = myCellIdVtkToSmds.size();
02158   int maxVtkId = -1;
02159   for (int oldVtkId = 0; oldVtkId < vtkIndexSize; oldVtkId++)
02160     {
02161       int oldSmdsId = this->myCellIdVtkToSmds[oldVtkId];
02162       if (oldSmdsId > 0)
02163         {
02164           int newVtkId = idCellsOldToNew[oldVtkId];
02165           if (newVtkId > maxVtkId)
02166             maxVtkId = newVtkId;
02167           //MESSAGE("myCells["<< oldSmdsId << "] vtkId " << oldVtkId << " --> " << newVtkId);
02168           myCells[oldSmdsId]->setVtkId(newVtkId);
02169         }
02170     }
02171 //  MESSAGE("myCells.size()=" << myCells.size()
02172 //          << " myCellIdSmdsToVtk.size()=" << myCellIdSmdsToVtk.size()
02173 //          << " myCellIdVtkToSmds.size()=" << myCellIdVtkToSmds.size() );
02174 
02175   SetOfCells newCells;
02176   //vector<int> newSmdsToVtk;
02177   vector<int> newVtkToSmds;
02178 
02179   assert(maxVtkId < newCellSize);
02180   newCells.resize(newCellSize+1, 0); // 0 not used, SMDS numbers 1..n
02181   //newSmdsToVtk.resize(newCellSize+1, -1);
02182   newVtkToSmds.resize(newCellSize+1, -1);
02183 
02184   int myCellsSize = myCells.size();
02185   int newSmdsId = 0;
02186   for (int i = 0; i < myCellsSize; i++)
02187     {
02188       if (myCells[i])
02189         {
02190           newSmdsId++; // SMDS id start to 1
02191           assert(newSmdsId <= newCellSize);
02192           newCells[newSmdsId] = myCells[i];
02193           newCells[newSmdsId]->setId(newSmdsId);
02194           //MESSAGE("myCells["<< i << "] --> newCells[" << newSmdsId << "]");
02195           int idvtk = myCells[i]->getVtkId();
02196           //newSmdsToVtk[newSmdsId] = idvtk;
02197           assert(idvtk < newCellSize);
02198           newVtkToSmds[idvtk] = newSmdsId;
02199         }
02200     }
02201 
02202   myCells.swap(newCells);
02203   //myCellIdSmdsToVtk.swap(newSmdsToVtk);
02204   myCellIdVtkToSmds.swap(newVtkToSmds);
02205   MESSAGE("myCells.size()=" << myCells.size()
02206           << " myCellIdVtkToSmds.size()=" << myCellIdVtkToSmds.size() );
02207   this->myElementIDFactory->emptyPool(newSmdsId);
02208 
02209   this->myScript->SetModified(true); // notify GUI client for buildPrs when update
02210 
02211   // --- compact list myNodes and myElements in submeshes
02212 
02213   map<int,SMESHDS_SubMesh*>::iterator it = myShapeIndexToSubMesh.begin();
02214   for(; it != myShapeIndexToSubMesh.end(); ++it)
02215     {
02216       (*it).second->compactList();
02217     }
02218 
02219 }
02220 
02221 void SMESHDS_Mesh::CleanDownWardConnectivity()
02222 {
02223   myGrid->CleanDownwardConnectivity();
02224 }
02225 
02226 void SMESHDS_Mesh::BuildDownWardConnectivity(bool withEdges)
02227 {
02228   myGrid->BuildDownwardConnectivity(withEdges);
02229 }
02230 
02237 bool SMESHDS_Mesh::ModifyCellNodes(int vtkVolId, std::map<int,int> localClonedNodeIds)
02238 {
02239   myGrid->ModifyCellNodes(vtkVolId, localClonedNodeIds);
02240   return true;
02241 }