Back to index

salome-smesh  6.5.0
SMESH_Client.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 //  File   : SMESH_Client.cxx
00023 //  Author : Pavel TELKOV
00024 //  Module : SMESH
00025 
00026 #include "SMESH_Client.hxx"
00027 #include "SMESH_Mesh.hxx"
00028 
00029 #include "SALOME_NamingService.hxx"
00030 #include "SALOME_LifeCycleCORBA.hxx"
00031 
00032 #include <SALOMEconfig.h>
00033 #include CORBA_SERVER_HEADER(SALOME_Component)
00034 #include CORBA_SERVER_HEADER(SALOME_Exception)
00035 
00036 #include "Basics_Utils.hxx"
00037 #include "utilities.h"
00038 
00039 #ifdef WNT
00040 #include <process.h>
00041 #else
00042 #include <unistd.h>
00043 #endif
00044 
00045 #include <stdexcept>
00046 
00047 #ifndef EXCEPTION
00048 #define EXCEPTION(TYPE, MSG) {\
00049   std::ostringstream aStream;\
00050   aStream<<__FILE__<<"["<<__LINE__<<"]::"<<MSG;\
00051   throw TYPE(aStream.str());\
00052 }
00053 #endif
00054 
00055 #ifdef _DEBUG_
00056 static int MYDEBUG = 1;
00057 #else
00058 static int MYDEBUG = 0;
00059 #endif
00060 
00061 namespace
00062 {
00063 
00064   //=======================================================================
00065   //function : FindNode
00066   //=======================================================================
00067   inline const SMDS_MeshNode* FindNode(const SMDS_Mesh* theMesh, int theId){
00068     if(const SMDS_MeshNode* anElem = theMesh->FindNode(theId)) return anElem;
00069     EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
00070   }
00071 
00072 
00073   //=======================================================================
00074   //function : FindElement
00075   //=======================================================================
00076   inline const SMDS_MeshElement* FindElement(const SMDS_Mesh* theMesh, int theId){
00077     if(const SMDS_MeshElement* anElem = theMesh->FindElement(theId)) return anElem;
00078     EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot find a SMDS_MeshElement for ID = "<<theId);
00079   }
00080 
00081 
00082   //=======================================================================
00083   //function : AddNodesWithID
00084   //=======================================================================
00085   inline void AddNodesWithID(SMDS_Mesh* theMesh,
00086                              SMESH::log_array_var& theSeq,
00087                              CORBA::Long theId)
00088   {
00089     const SMESH::double_array& aCoords = theSeq[theId].coords;
00090     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00091     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00092     if(3*aNbElems != aCoords.length())
00093       EXCEPTION(runtime_error,"AddNodesWithID - 3*aNbElems != aCoords.length()");
00094     for(CORBA::Long aCoordId = 0; anElemId < aNbElems; anElemId++, aCoordId+=3){
00095       SMDS_MeshElement* anElem = theMesh->AddNodeWithID(aCoords[aCoordId],
00096                                                         aCoords[aCoordId+1],
00097                                                         aCoords[aCoordId+2],
00098                                                         anIndexes[anElemId]);
00099       if(!anElem)
00100         EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddNodeWithID for ID = "<<anElemId);
00101     }
00102   }
00103 
00104 
00105   //=======================================================================
00106   //function : Add0DElementsWithID
00107   //=======================================================================
00108   inline void Add0DElementsWithID(SMDS_Mesh* theMesh,
00109                                   SMESH::log_array_var& theSeq,
00110                                   CORBA::Long theId)
00111   {
00112     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00113     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00114     if (2*aNbElems != anIndexes.length())
00115       EXCEPTION(runtime_error,"AddEdgeWithID - 2*aNbElems != aCoords.length()");
00116     CORBA::Long anIndexId = 0;
00117     for (; anElemId < aNbElems; anElemId++, anIndexId+=2)
00118     {
00119       SMDS_MeshElement* anElem = theMesh->Add0DElementWithID(anIndexes[anIndexId+1],
00120                                                              anIndexes[anIndexId]);
00121       if (!anElem)
00122         EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot Add0DElementWithID for ID = "<<anElemId);
00123     }
00124   }
00125 
00126 
00127   //=======================================================================
00128   //function : AddEdgesWithID
00129   //=======================================================================
00130   inline void AddEdgesWithID(SMDS_Mesh* theMesh,
00131                              SMESH::log_array_var& theSeq,
00132                              CORBA::Long theId)
00133   {
00134     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00135     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00136     if(3*aNbElems != anIndexes.length())
00137       EXCEPTION(runtime_error,"AddEdgeWithID - 3*aNbElems != aCoords.length()");
00138     for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=3){
00139       SMDS_MeshElement* anElem = theMesh->AddEdgeWithID(anIndexes[anIndexId+1],
00140                                                         anIndexes[anIndexId+2],
00141                                                         anIndexes[anIndexId]);
00142       if(!anElem)
00143         EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddEdgeWithID for ID = "<<anElemId);
00144     }
00145   }
00146 
00147 
00148   //=======================================================================
00149   //function : AddTriasWithID
00150   //=======================================================================
00151   inline void AddTriasWithID(SMDS_Mesh* theMesh,
00152                              SMESH::log_array_var& theSeq,
00153                              CORBA::Long theId)
00154   {
00155     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00156     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00157     if(4*aNbElems != anIndexes.length())
00158       EXCEPTION(runtime_error,"AddTriasWithID - 4*aNbElems != anIndexes.length()");
00159     for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=4){
00160       SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
00161                                                         anIndexes[anIndexId+2],
00162                                                         anIndexes[anIndexId+3],
00163                                                         anIndexes[anIndexId]);
00164       if(!anElem)
00165         EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
00166     }
00167   }
00168 
00169 
00170   //=======================================================================
00171   //function : AddQuadsWithID
00172   //=======================================================================
00173   inline void AddQuadsWithID(SMDS_Mesh* theMesh,
00174                              SMESH::log_array_var theSeq,
00175                              CORBA::Long theId)
00176   {
00177     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00178     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00179     if(5*aNbElems != anIndexes.length())
00180       EXCEPTION(runtime_error,"AddQuadsWithID - 4*aNbElems != anIndexes.length()");
00181     for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=5){
00182       SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
00183                                                         anIndexes[anIndexId+2],
00184                                                         anIndexes[anIndexId+3],
00185                                                         anIndexes[anIndexId+4],
00186                                                         anIndexes[anIndexId]);
00187       if(!anElem)
00188         EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
00189     }
00190   }
00191 
00192 
00193   //=======================================================================
00194   //function : AddPolygonsWithID
00195   //=======================================================================
00196   inline void AddPolygonsWithID(SMDS_Mesh* theMesh,
00197                                 SMESH::log_array_var& theSeq,
00198                                 CORBA::Long theId)
00199   {
00200     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00201     CORBA::Long anIndexId = 0, aNbElems = theSeq[theId].number;
00202 
00203     for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++) {
00204       int aFaceId = anIndexes[anIndexId++];
00205 
00206       int aNbNodes = anIndexes[anIndexId++];
00207       std::vector<int> nodes_ids (aNbNodes);
00208       for (int i = 0; i < aNbNodes; i++) {
00209         nodes_ids[i] = anIndexes[anIndexId++];
00210       }
00211 
00212       SMDS_MeshElement* anElem = theMesh->AddPolygonalFaceWithID(nodes_ids, aFaceId);
00213       if (!anElem)
00214         EXCEPTION(runtime_error, "SMDS_Mesh::FindElement - cannot AddPolygonalFaceWithID for ID = "
00215                   << anElemId);
00216     }
00217   }
00218 
00219 
00220   //=======================================================================
00221   //function : AddTetrasWithID
00222   //=======================================================================
00223   inline void AddTetrasWithID(SMDS_Mesh* theMesh,
00224                               SMESH::log_array_var& theSeq,
00225                               CORBA::Long theId)
00226   {
00227     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00228     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00229     if(5*aNbElems != anIndexes.length())
00230       EXCEPTION(runtime_error,"AddTetrasWithID - 5*aNbElems != anIndexes.length()");
00231     for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=5){
00232       SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00233                                                           anIndexes[anIndexId+2],
00234                                                           anIndexes[anIndexId+3],
00235                                                           anIndexes[anIndexId+4],
00236                                                           anIndexes[anIndexId]);
00237       if(!anElem)
00238         EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
00239     }
00240   }
00241 
00242 
00243   //=======================================================================
00244   //function : AddPiramidsWithID
00245   //=======================================================================
00246   inline void AddPiramidsWithID(SMDS_Mesh* theMesh,
00247                                 SMESH::log_array_var& theSeq,
00248                                 CORBA::Long theId)
00249   {
00250     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00251     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00252     if(6*aNbElems != anIndexes.length())
00253       EXCEPTION(runtime_error,"AddPiramidsWithID - 6*aNbElems != anIndexes.length()");
00254     for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=6){
00255       SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00256                                                           anIndexes[anIndexId+2],
00257                                                           anIndexes[anIndexId+3],
00258                                                           anIndexes[anIndexId+4],
00259                                                           anIndexes[anIndexId+5],
00260                                                           anIndexes[anIndexId]);
00261       if(!anElem)
00262         EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
00263     }
00264   }
00265 
00266 
00267   //=======================================================================
00268   //function : AddPrismsWithID
00269   //=======================================================================
00270   inline void AddPrismsWithID(SMDS_Mesh* theMesh,
00271                               SMESH::log_array_var& theSeq,
00272                               CORBA::Long theId)
00273   {
00274     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00275     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00276     if(7*aNbElems != anIndexes.length())
00277       EXCEPTION(runtime_error,"AddPrismsWithID - 7*aNbElems != anIndexes.length()");
00278     for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=7){
00279       SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00280                                                           anIndexes[anIndexId+2],
00281                                                           anIndexes[anIndexId+3],
00282                                                           anIndexes[anIndexId+4],
00283                                                           anIndexes[anIndexId+5],
00284                                                           anIndexes[anIndexId+6],
00285                                                           anIndexes[anIndexId]);
00286       if(!anElem)
00287         EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
00288     }
00289   }
00290 
00291 
00292   //=======================================================================
00293   //function : AddHexasWithID
00294   //=======================================================================
00295   inline void AddHexasWithID(SMDS_Mesh* theMesh,
00296                              SMESH::log_array_var& theSeq,
00297                              CORBA::Long theId)
00298   {
00299     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00300     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00301     if(9*aNbElems != anIndexes.length())
00302       EXCEPTION(runtime_error,"AddHexasWithID - 9*aNbElems != anIndexes.length()");
00303     for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=9){
00304       SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00305                                                           anIndexes[anIndexId+2],
00306                                                           anIndexes[anIndexId+3],
00307                                                           anIndexes[anIndexId+4],
00308                                                           anIndexes[anIndexId+5],
00309                                                           anIndexes[anIndexId+6],
00310                                                           anIndexes[anIndexId+7],
00311                                                           anIndexes[anIndexId+8],
00312                                                           anIndexes[anIndexId]);
00313       if(!anElem)
00314         EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
00315     }
00316   }
00317 
00318   //=======================================================================
00319   //function : AddHexPrismWithID
00320   //=======================================================================
00321   inline void AddHexPrismWithID(SMDS_Mesh* theMesh,
00322                                 SMESH::log_array_var& theSeq,
00323                                 CORBA::Long theId)
00324   {
00325     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00326     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00327     if(13*aNbElems != anIndexes.length())
00328       EXCEPTION(runtime_error,"AddHexPrismWithID - 13*aNbElems != anIndexes.length()");
00329     for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=13){
00330       SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00331                                                           anIndexes[anIndexId+2],
00332                                                           anIndexes[anIndexId+3],
00333                                                           anIndexes[anIndexId+4],
00334                                                           anIndexes[anIndexId+5],
00335                                                           anIndexes[anIndexId+6],
00336                                                           anIndexes[anIndexId+7],
00337                                                           anIndexes[anIndexId+8],
00338                                                           anIndexes[anIndexId+9],
00339                                                           anIndexes[anIndexId+10],
00340                                                           anIndexes[anIndexId+11],
00341                                                           anIndexes[anIndexId+12],
00342                                                           anIndexes[anIndexId]);
00343       if(!anElem)
00344         EXCEPTION(runtime_error,"AddHexPrismWithID - cannot AddVolumeWithID for ID = "<<anElemId);
00345     }
00346   }
00347 
00348 
00349   //=======================================================================
00350   //function : AddPolyhedronsWithID
00351   //=======================================================================
00352   inline void AddPolyhedronsWithID (SMDS_Mesh* theMesh,
00353                                     SMESH::log_array_var& theSeq,
00354                                     CORBA::Long theId)
00355   {
00356     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00357     CORBA::Long anIndexId = 0, aNbElems = theSeq[theId].number;
00358 
00359     for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++) {
00360       int aFaceId = anIndexes[anIndexId++];
00361 
00362       int aNbNodes = anIndexes[anIndexId++];
00363       std::vector<int> nodes_ids (aNbNodes);
00364       for (int i = 0; i < aNbNodes; i++) {
00365         nodes_ids[i] = anIndexes[anIndexId++];
00366       }
00367 
00368       int aNbFaces = anIndexes[anIndexId++];
00369       std::vector<int> quantities (aNbFaces);
00370       for (int i = 0; i < aNbFaces; i++) {
00371         quantities[i] = anIndexes[anIndexId++];
00372       }
00373 
00374       SMDS_MeshElement* anElem =
00375         theMesh->AddPolyhedralVolumeWithID(nodes_ids, quantities, aFaceId);
00376       if (!anElem)
00377         EXCEPTION(runtime_error, "SMDS_Mesh::FindElement - cannot AddPolyhedralVolumeWithID for ID = "
00378                   << anElemId);
00379     }
00380   }
00381 
00382 
00383   //=======================================================================
00384   //function : AddQuadEdgesWithID
00385   //=======================================================================
00386   inline void AddQuadEdgesWithID(SMDS_Mesh* theMesh,
00387                                  SMESH::log_array_var& theSeq,
00388                                  CORBA::Long theId)
00389   {
00390     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00391     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00392     if(4*aNbElems != anIndexes.length())
00393       EXCEPTION(runtime_error,"AddQuadEdgeWithID - 4*aNbElems != aCoords.length()");
00394     for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=4){
00395       SMDS_MeshElement* anElem = theMesh->AddEdgeWithID(anIndexes[anIndexId+1],
00396                                                         anIndexes[anIndexId+2],
00397                                                         anIndexes[anIndexId+3],
00398                                                         anIndexes[anIndexId]);
00399       if(!anElem)
00400         EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddEdgeWithID for ID = "<<anElemId);
00401     }
00402   }
00403 
00404 
00405   //=======================================================================
00406   //function : AddQuadTriasWithID
00407   //=======================================================================
00408   inline void AddQuadTriasWithID(SMDS_Mesh* theMesh,
00409                                  SMESH::log_array_var& theSeq,
00410                                  CORBA::Long theId)
00411   {
00412     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00413     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00414     if(7*aNbElems != anIndexes.length())
00415       EXCEPTION(runtime_error,"AddQuadTriasWithID - 7*aNbElems != anIndexes.length()");
00416     for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=7){
00417       SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
00418                                                         anIndexes[anIndexId+2],
00419                                                         anIndexes[anIndexId+3],
00420                                                         anIndexes[anIndexId+4],
00421                                                         anIndexes[anIndexId+5],
00422                                                         anIndexes[anIndexId+6],
00423                                                         anIndexes[anIndexId]);
00424       if(!anElem)
00425         EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
00426     }
00427   }
00428 
00429 
00430   //=======================================================================
00431   //function : AddQuadQuadsWithID
00432   //=======================================================================
00433   inline void AddQuadQuadsWithID(SMDS_Mesh* theMesh,
00434                                  SMESH::log_array_var theSeq,
00435                                  CORBA::Long theId)
00436   {
00437     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00438     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00439     if(9*aNbElems != anIndexes.length())
00440       EXCEPTION(runtime_error,"AddQuadQuadsWithID - 9*aNbElems != anIndexes.length()");
00441     for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=9){
00442       SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
00443                                                         anIndexes[anIndexId+2],
00444                                                         anIndexes[anIndexId+3],
00445                                                         anIndexes[anIndexId+4],
00446                                                         anIndexes[anIndexId+5],
00447                                                         anIndexes[anIndexId+6],
00448                                                         anIndexes[anIndexId+7],
00449                                                         anIndexes[anIndexId+8],
00450                                                         anIndexes[anIndexId]);
00451       if(!anElem)
00452         EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<<anElemId);
00453     }
00454   }
00455 
00456   //=======================================================================
00457   //function : AddBiQuadQuadsWithID
00458   //=======================================================================
00459   inline void AddBiQuadQuadsWithID(SMDS_Mesh* theMesh,
00460                                    SMESH::log_array_var theSeq,
00461                                    CORBA::Long theId)
00462   {
00463     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00464     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00465     if(10*aNbElems != anIndexes.length())
00466       EXCEPTION(runtime_error,"AddBiQuadQuadsWithID - 10*aNbElems != anIndexes.length()");
00467     for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=10){
00468       SMDS_MeshElement* anElem = theMesh->AddFaceWithID(anIndexes[anIndexId+1],
00469                                                         anIndexes[anIndexId+2],
00470                                                         anIndexes[anIndexId+3],
00471                                                         anIndexes[anIndexId+4],
00472                                                         anIndexes[anIndexId+5],
00473                                                         anIndexes[anIndexId+6],
00474                                                         anIndexes[anIndexId+7],
00475                                                         anIndexes[anIndexId+8],
00476                                                         anIndexes[anIndexId+9],
00477                                                         anIndexes[anIndexId]);
00478       if(!anElem)
00479         EXCEPTION(runtime_error,"AddBiQuadQuadsWithID() - cannot AddFaceWithID for ID = "<<anElemId);
00480     }
00481   }
00482 
00483 
00484   //=======================================================================
00485   //function : AddQuadTetrasWithID
00486   //=======================================================================
00487   inline void AddQuadTetrasWithID(SMDS_Mesh* theMesh,
00488                                   SMESH::log_array_var& theSeq,
00489                                   CORBA::Long theId)
00490   {
00491     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00492     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00493     if(11*aNbElems != anIndexes.length())
00494       EXCEPTION(runtime_error,"AddQuadTetrasWithID - 11*aNbElems != anIndexes.length()");
00495     for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=11){
00496       SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00497                                                           anIndexes[anIndexId+2],
00498                                                           anIndexes[anIndexId+3],
00499                                                           anIndexes[anIndexId+4],
00500                                                           anIndexes[anIndexId+5],
00501                                                           anIndexes[anIndexId+6],
00502                                                           anIndexes[anIndexId+7],
00503                                                           anIndexes[anIndexId+8],
00504                                                           anIndexes[anIndexId+9],
00505                                                           anIndexes[anIndexId+10],
00506                                                           anIndexes[anIndexId]);
00507       if(!anElem)
00508         EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
00509     }
00510   }
00511 
00512 
00513   //=======================================================================
00514   //function : AddQuadPiramidsWithID
00515   //=======================================================================
00516   inline void AddQuadPiramidsWithID(SMDS_Mesh* theMesh,
00517                                     SMESH::log_array_var& theSeq,
00518                                     CORBA::Long theId)
00519   {
00520     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00521     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00522     if(14*aNbElems != anIndexes.length())
00523       EXCEPTION(runtime_error,"AddQuadPiramidsWithID - 14*aNbElems != anIndexes.length()");
00524     for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=14){
00525       SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00526                                                           anIndexes[anIndexId+2],
00527                                                           anIndexes[anIndexId+3],
00528                                                           anIndexes[anIndexId+4],
00529                                                           anIndexes[anIndexId+5],
00530                                                           anIndexes[anIndexId+6],
00531                                                           anIndexes[anIndexId+7],
00532                                                           anIndexes[anIndexId+8],
00533                                                           anIndexes[anIndexId+9],
00534                                                           anIndexes[anIndexId+10],
00535                                                           anIndexes[anIndexId+11],
00536                                                           anIndexes[anIndexId+12],
00537                                                           anIndexes[anIndexId+13],
00538                                                           anIndexes[anIndexId]);
00539       if(!anElem)
00540         EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
00541     }
00542   }
00543 
00544 
00545   //=======================================================================
00546   //function : AddQuadPentasWithID
00547   //=======================================================================
00548   inline void AddQuadPentasWithID(SMDS_Mesh* theMesh,
00549                                   SMESH::log_array_var& theSeq,
00550                                   CORBA::Long theId)
00551   {
00552     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00553     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00554     if(16*aNbElems != anIndexes.length())
00555       EXCEPTION(runtime_error,"AddQuadPentasWithID - 16*aNbElems != anIndexes.length()");
00556     for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=16){
00557       SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00558                                                           anIndexes[anIndexId+2],
00559                                                           anIndexes[anIndexId+3],
00560                                                           anIndexes[anIndexId+4],
00561                                                           anIndexes[anIndexId+5],
00562                                                           anIndexes[anIndexId+6],
00563                                                           anIndexes[anIndexId+7],
00564                                                           anIndexes[anIndexId+8],
00565                                                           anIndexes[anIndexId+9],
00566                                                           anIndexes[anIndexId+10],
00567                                                           anIndexes[anIndexId+11],
00568                                                           anIndexes[anIndexId+12],
00569                                                           anIndexes[anIndexId+13],
00570                                                           anIndexes[anIndexId+14],
00571                                                           anIndexes[anIndexId+15],
00572                                                           anIndexes[anIndexId]);
00573       if(!anElem)
00574         EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
00575     }
00576   }
00577 
00578 
00579   //=======================================================================
00580   //function : AddQuadHexasWithID
00581   //=======================================================================
00582   inline void AddQuadHexasWithID(SMDS_Mesh* theMesh,
00583                                  SMESH::log_array_var& theSeq,
00584                                  CORBA::Long theId)
00585   {
00586     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00587     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00588     if(21*aNbElems != anIndexes.length())
00589       EXCEPTION(runtime_error,"AddQuadHexasWithID - 21*aNbElems != anIndexes.length()");
00590     for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=21){
00591       SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00592                                                           anIndexes[anIndexId+2],
00593                                                           anIndexes[anIndexId+3],
00594                                                           anIndexes[anIndexId+4],
00595                                                           anIndexes[anIndexId+5],
00596                                                           anIndexes[anIndexId+6],
00597                                                           anIndexes[anIndexId+7],
00598                                                           anIndexes[anIndexId+8],
00599                                                           anIndexes[anIndexId+9],
00600                                                           anIndexes[anIndexId+10],
00601                                                           anIndexes[anIndexId+11],
00602                                                           anIndexes[anIndexId+12],
00603                                                           anIndexes[anIndexId+13],
00604                                                           anIndexes[anIndexId+14],
00605                                                           anIndexes[anIndexId+15],
00606                                                           anIndexes[anIndexId+16],
00607                                                           anIndexes[anIndexId+17],
00608                                                           anIndexes[anIndexId+18],
00609                                                           anIndexes[anIndexId+19],
00610                                                           anIndexes[anIndexId+20],
00611                                                           anIndexes[anIndexId]);
00612       if(!anElem)
00613         EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<<anElemId);
00614     }
00615   }
00616 
00617   //=======================================================================
00618   //function : AddTriQuadHexasWithID
00619   //=======================================================================
00620   inline void AddTriQuadHexasWithID(SMDS_Mesh* theMesh,
00621                                     SMESH::log_array_var& theSeq,
00622                                     CORBA::Long theId)
00623   {
00624     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00625     CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number;
00626     if(28*aNbElems != anIndexes.length())
00627       EXCEPTION(runtime_error,"AddTriQuadHexasWithID - 28*aNbElems != anIndexes.length()");
00628     for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=28){
00629       SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1],
00630                                                           anIndexes[anIndexId+2],
00631                                                           anIndexes[anIndexId+3],
00632                                                           anIndexes[anIndexId+4],
00633                                                           anIndexes[anIndexId+5],
00634                                                           anIndexes[anIndexId+6],
00635                                                           anIndexes[anIndexId+7],
00636                                                           anIndexes[anIndexId+8],
00637                                                           anIndexes[anIndexId+9],
00638                                                           anIndexes[anIndexId+10],
00639                                                           anIndexes[anIndexId+11],
00640                                                           anIndexes[anIndexId+12],
00641                                                           anIndexes[anIndexId+13],
00642                                                           anIndexes[anIndexId+14],
00643                                                           anIndexes[anIndexId+15],
00644                                                           anIndexes[anIndexId+16],
00645                                                           anIndexes[anIndexId+17],
00646                                                           anIndexes[anIndexId+18],
00647                                                           anIndexes[anIndexId+19],
00648                                                           anIndexes[anIndexId+20],
00649                                                           anIndexes[anIndexId+21],
00650                                                           anIndexes[anIndexId+22],
00651                                                           anIndexes[anIndexId+23],
00652                                                           anIndexes[anIndexId+24],
00653                                                           anIndexes[anIndexId+25],
00654                                                           anIndexes[anIndexId+26],
00655                                                           anIndexes[anIndexId+27],
00656                                                           anIndexes[anIndexId]);
00657       if(!anElem)
00658         EXCEPTION(runtime_error,"AddTriQuadHexasWithID() - cannot AddVolumeWithID for ID = "<<anElemId);
00659     }
00660   }
00661 
00662 
00663   //=======================================================================
00664   //function : ChangePolyhedronNodes
00665   //=======================================================================
00666   inline void ChangePolyhedronNodes (SMDS_Mesh* theMesh,
00667                                      SMESH::log_array_var& theSeq,
00668                                      CORBA::Long theId)
00669   {
00670     const SMESH::long_array& anIndexes = theSeq[theId].indexes;
00671     CORBA::Long iind = 0, aNbElems = theSeq[theId].number;
00672 
00673     for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++)
00674     {
00675       // find element
00676       const SMDS_MeshElement* elem = FindElement(theMesh, anIndexes[iind++]);
00677       // nb nodes
00678       int nbNodes = anIndexes[iind++];
00679       // nodes
00680       std::vector<const SMDS_MeshNode*> aNodes (nbNodes);
00681       for (int iNode = 0; iNode < nbNodes; iNode++) {
00682         aNodes[iNode] = FindNode(theMesh, anIndexes[iind++]);
00683       }
00684       // nb faces
00685       int nbFaces = anIndexes[iind++];
00686       // quantities
00687       std::vector<int> quantities (nbFaces);
00688       for (int iFace = 0; iFace < nbFaces; iFace++) {
00689         quantities[iFace] = anIndexes[iind++];
00690       }
00691       // change
00692       theMesh->ChangePolyhedronNodes(elem, aNodes, quantities);
00693     }
00694   }
00695 }
00696 
00697 //=======================================================================
00698 SMESH::SMESH_Gen_var
00699 SMESH_Client::GetSMESHGen(CORBA::ORB_ptr theORB,
00700                           CORBA::Boolean& theIsEmbeddedMode)
00701 {
00702   static SMESH::SMESH_Gen_var aMeshGen;
00703 
00704   if(CORBA::is_nil(aMeshGen.in())){
00705 #ifdef WNT
00706     long aClientPID = (long)_getpid();
00707 #else
00708     long aClientPID =  (long)getpid();
00709 #endif
00710 
00711     SALOME_NamingService aNamingService(theORB);
00712     SALOME_LifeCycleCORBA aLifeCycleCORBA(&aNamingService);
00713     Engines::EngineComponent_var aComponent = aLifeCycleCORBA.FindOrLoad_Component("FactoryServer","SMESH");
00714     aMeshGen = SMESH::SMESH_Gen::_narrow(aComponent);
00715 
00716     std::string aClientHostName = Kernel_Utils::GetHostname();
00717     Engines::Container_var aServerContainer = aMeshGen->GetContainerRef();
00718     CORBA::String_var aServerHostName = aServerContainer->getHostName();
00719     CORBA::Long aServerPID = aServerContainer->getPID();
00720     aMeshGen->SetEmbeddedMode((aClientPID == aServerPID) && (aClientHostName == aServerHostName.in()));
00721   }
00722   theIsEmbeddedMode = aMeshGen->IsEmbeddedMode();
00723 
00724   return aMeshGen;
00725 }
00726 
00727 
00728 //=======================================================================
00729 // function : Create()
00730 // purpose  :
00731 //=======================================================================
00732 SMESH_Client::SMESH_Client(CORBA::ORB_ptr theORB,
00733                            SMESH::SMESH_Mesh_ptr theMesh):
00734   myMeshServer(SMESH::SMESH_Mesh::_duplicate(theMesh)),
00735   mySMESHDSMesh(NULL),
00736   mySMDSMesh(NULL)
00737 {
00738   MESSAGE("SMESH_Client::SMESH_Client");
00739   myMeshServer->Register();
00740 
00741   CORBA::Boolean anIsEmbeddedMode;
00742   GetSMESHGen(theORB,anIsEmbeddedMode);
00743   if(anIsEmbeddedMode){
00744     if ( MYDEBUG )
00745       MESSAGE("Info: The same process, update mesh by pointer ");
00746     // just set client mesh pointer to server mesh pointer
00747     //SMESH_Mesh* aMesh = reinterpret_cast<SMESH_Mesh*>(theMesh->GetMeshPtr());
00748     CORBA::LongLong pointeur = theMesh->GetMeshPtr();
00749     if( MYDEBUG )
00750       MESSAGE("SMESH_Client::SMESH_Client pointeur "<<pointeur);
00751     SMESH_Mesh* aMesh = reinterpret_cast<SMESH_Mesh*> (pointeur);
00752     if ( MYDEBUG )
00753       MESSAGE("SMESH_Client::SMESH_Client aMesh "<<aMesh);
00754     //if(aMesh->GetMeshDS()->IsEmbeddedMode()){
00755     if(anIsEmbeddedMode){
00756       mySMESHDSMesh = aMesh->GetMeshDS();
00757       mySMDSMesh = mySMESHDSMesh;
00758     }
00759   }
00760   if(!mySMDSMesh)
00761     mySMDSMesh = new SMDS_Mesh();
00762 }
00763 
00764 
00765 //=================================================================================
00766 // function : ~SMESH_Client
00767 // purpose  : Destructor
00768 //=================================================================================
00769 SMESH_Client::~SMESH_Client()
00770 {
00771   myMeshServer->UnRegister();
00772   if(!mySMESHDSMesh)
00773     delete mySMDSMesh;
00774 }
00775 
00776 
00777 //=================================================================================
00778 SMDS_Mesh*
00779 SMESH_Client::GetMesh() const
00780 {
00781   return mySMDSMesh;
00782 }
00783 
00784 
00785 //=================================================================================
00786 SMDS_Mesh*
00787 SMESH_Client::operator->() const
00788 {
00789   return GetMesh();
00790 }
00791 
00792 
00793 //=================================================================================
00794 SMESH::SMESH_Mesh_ptr
00795 SMESH_Client::GetMeshServer()
00796 {
00797   return myMeshServer.in();
00798 }
00799 
00800 
00801 //=================================================================================
00802 // function : SMESH_Client
00803 // purpose  : Update mesh
00804 //=================================================================================
00805 bool
00806 SMESH_Client::Update(bool theIsClear)
00807 {
00808   bool anIsModified = true;
00809   if(mySMESHDSMesh){
00810         MESSAGE("Update mySMESHDSMesh");
00811     SMESHDS_Script* aScript = mySMESHDSMesh->GetScript();
00812     anIsModified = aScript->IsModified();
00813     aScript->SetModified(false);
00814   }else{
00815         MESSAGE("Update CORBA");
00816     SMESH::log_array_var aSeq = myMeshServer->GetLog( theIsClear );
00817     CORBA::Long aLength = aSeq->length();
00818     anIsModified = aLength > 0;
00819     if( MYDEBUG )
00820       MESSAGE( "Update: length of the script is "<<aLength );
00821 
00822     if(!anIsModified)
00823       return false;
00824 
00825     // update client mesh structure by logged changes commands
00826     try
00827     {
00828       for ( CORBA::Long anId = 0; anId < aLength; anId++)
00829       {
00830         const SMESH::double_array& aCoords = aSeq[anId].coords;
00831         const SMESH::long_array& anIndexes = aSeq[anId].indexes;
00832         CORBA::Long anElemId = 0, aNbElems = aSeq[anId].number;
00833         CORBA::Long aCommand = aSeq[anId].commandType;
00834 
00835         switch(aCommand)
00836         {
00837         case SMESH::ADD_NODE             : AddNodesWithID      ( mySMDSMesh, aSeq, anId ); break;
00838         case SMESH::ADD_ELEM0D           : Add0DElementsWithID ( mySMDSMesh, aSeq, anId ); break;
00839         case SMESH::ADD_EDGE             : AddEdgesWithID      ( mySMDSMesh, aSeq, anId ); break;
00840         case SMESH::ADD_TRIANGLE         : AddTriasWithID      ( mySMDSMesh, aSeq, anId ); break;
00841         case SMESH::ADD_QUADRANGLE       : AddQuadsWithID      ( mySMDSMesh, aSeq, anId ); break;
00842         case SMESH::ADD_POLYGON          : AddPolygonsWithID   ( mySMDSMesh, aSeq, anId ); break;
00843         case SMESH::ADD_TETRAHEDRON      : AddTetrasWithID     ( mySMDSMesh, aSeq, anId ); break;
00844         case SMESH::ADD_PYRAMID          : AddPiramidsWithID   ( mySMDSMesh, aSeq, anId ); break;
00845         case SMESH::ADD_PRISM            : AddPrismsWithID     ( mySMDSMesh, aSeq, anId ); break;
00846         case SMESH::ADD_HEXAHEDRON       : AddHexasWithID      ( mySMDSMesh, aSeq, anId ); break;
00847         case SMESH::ADD_HEXAGONAL_PRISM  : AddHexPrismWithID   ( mySMDSMesh, aSeq, anId ); break;
00848         case SMESH::ADD_POLYHEDRON       : AddPolyhedronsWithID( mySMDSMesh, aSeq, anId ); break;
00849 
00850         case SMESH::ADD_QUADEDGE         : AddQuadEdgesWithID   ( mySMDSMesh, aSeq, anId ); break;
00851         case SMESH::ADD_QUADTRIANGLE     : AddQuadTriasWithID   ( mySMDSMesh, aSeq, anId ); break;
00852         case SMESH::ADD_QUADQUADRANGLE   : AddQuadQuadsWithID   ( mySMDSMesh, aSeq, anId ); break;
00853         case SMESH::ADD_BIQUAD_QUADRANGLE: AddBiQuadQuadsWithID ( mySMDSMesh, aSeq, anId ); break;
00854         case SMESH::ADD_QUADTETRAHEDRON  : AddQuadTetrasWithID  ( mySMDSMesh, aSeq, anId ); break;
00855         case SMESH::ADD_QUADPYRAMID      : AddQuadPiramidsWithID( mySMDSMesh, aSeq, anId ); break;
00856         case SMESH::ADD_QUADPENTAHEDRON  : AddQuadPentasWithID  ( mySMDSMesh, aSeq, anId ); break;
00857         case SMESH::ADD_QUADHEXAHEDRON   : AddQuadHexasWithID   ( mySMDSMesh, aSeq, anId ); break;
00858         case SMESH::ADD_TRIQUAD_HEXA     : AddTriQuadHexasWithID( mySMDSMesh, aSeq, anId ); break;
00859 
00860         case SMESH::CLEAR_MESH:
00861           mySMDSMesh->Clear();
00862           break;
00863 
00864         case SMESH::REMOVE_NODE:
00865           for( ; anElemId < aNbElems; anElemId++ )
00866             mySMDSMesh->RemoveNode( FindNode( mySMDSMesh, anIndexes[anElemId] ) );
00867         break;
00868 
00869         case SMESH::REMOVE_ELEMENT:
00870           for( ; anElemId < aNbElems; anElemId++ )
00871             mySMDSMesh->RemoveElement( FindElement( mySMDSMesh, anIndexes[anElemId] ) );
00872         break;
00873 
00874         case SMESH::MOVE_NODE:
00875           for(CORBA::Long aCoordId=0; anElemId < aNbElems; anElemId++, aCoordId+=3)
00876           {
00877             SMDS_MeshNode* node =
00878               const_cast<SMDS_MeshNode*>( FindNode( mySMDSMesh, anIndexes[anElemId] ));
00879             node->setXYZ( aCoords[aCoordId], aCoords[aCoordId+1], aCoords[aCoordId+2] );
00880           }
00881         break;
00882 
00883         case SMESH::CHANGE_ELEMENT_NODES:
00884           for ( CORBA::Long i = 0; anElemId < aNbElems; anElemId++ )
00885           {
00886             // find element
00887             const SMDS_MeshElement* elem = FindElement( mySMDSMesh, anIndexes[i++] );
00888             // nb nodes
00889             int nbNodes = anIndexes[i++];
00890             // nodes
00891             //ASSERT( nbNodes < 9 );
00892             vector<const SMDS_MeshNode*> aNodes( nbNodes );
00893             for ( int iNode = 0; iNode < nbNodes; iNode++ )
00894               aNodes[ iNode ] = FindNode( mySMDSMesh, anIndexes[i++] );
00895             // change
00896             mySMDSMesh->ChangeElementNodes( elem, &aNodes[0], nbNodes );
00897           }
00898           break;
00899 
00900         case SMESH::CHANGE_POLYHEDRON_NODES:
00901           ChangePolyhedronNodes(mySMDSMesh, aSeq, anId);
00902           break;
00903         case SMESH::RENUMBER:
00904           for(CORBA::Long i=0; anElemId < aNbElems; anElemId++, i+=3)
00905           {
00906             mySMDSMesh->Renumber( anIndexes[i], anIndexes[i+1], anIndexes[i+2] );
00907           }
00908           break;
00909 
00910         default:;
00911         }
00912       }
00913     }
00914     catch ( SALOME::SALOME_Exception& exc )
00915     {
00916       INFOS("Following exception was cought:\n\t"<<exc.details.text);
00917     }
00918     catch( const std::exception& exc)
00919     {
00920       INFOS("Following exception was cought:\n\t"<<exc.what());
00921     }
00922     catch(...)
00923     {
00924       INFOS("Unknown exception was cought !!!");
00925     }
00926 
00927     if ( MYDEBUG && mySMDSMesh )
00928     {
00929       MESSAGE("Update - mySMDSMesh->NbNodes() = "<<mySMDSMesh->NbNodes());
00930       MESSAGE("Update - mySMDSMesh->Nb0DElements() = "<<mySMDSMesh->Nb0DElements());
00931       MESSAGE("Update - mySMDSMesh->NbEdges() = "<<mySMDSMesh->NbEdges());
00932       MESSAGE("Update - mySMDSMesh->NbFaces() = "<<mySMDSMesh->NbFaces());
00933       MESSAGE("Update - mySMDSMesh->NbVolumes() = "<<mySMDSMesh->NbVolumes());
00934     }
00935   } // end of update mesh by log script
00936 
00937   return anIsModified;
00938 }