Version: 6.3.1

src/SMESHDS/SMESHDS_Mesh.cxx

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