From 1cb4a4d4524e17d92aefa1e2331a8b619590c059 Mon Sep 17 00:00:00 2001 From: apo Date: Thu, 2 Mar 2006 10:03:01 +0000 Subject: [PATCH] Apply SMESH module performance improvement --- idl/SMESH_Mesh.idl | 6 + src/Makefile.in | 2 +- src/OBJECT/Makefile.in | 9 +- src/OBJECT/SMESH_Actor.cxx | 14 +- src/OBJECT/SMESH_DeviceActor.cxx | 2 + src/OBJECT/SMESH_Object.cxx | 403 ++---------------------- src/OBJECT/SMESH_ObjectDef.h | 2 +- src/SMESHClient/Makefile.in | 73 +++++ src/SMESHClient/SMESHClientBin.cxx | 30 ++ src/SMESHClient/SMESH_Client.cxx | 480 +++++++++++++++++++++++++++++ src/SMESHClient/SMESH_Client.hxx | 84 +++++ src/SMESHGUI/Makefile.in | 2 +- src/SMESH_I/SMESH_Mesh_i.cxx | 11 + src/SMESH_I/SMESH_Mesh_i.hxx | 2 + 14 files changed, 732 insertions(+), 388 deletions(-) create mode 100644 src/SMESHClient/Makefile.in create mode 100644 src/SMESHClient/SMESHClientBin.cxx create mode 100644 src/SMESHClient/SMESH_Client.cxx create mode 100644 src/SMESHClient/SMESH_Client.hxx diff --git a/idl/SMESH_Mesh.idl b/idl/SMESH_Mesh.idl index 28e4ca873..5a2915c8d 100644 --- a/idl/SMESH_Mesh.idl +++ b/idl/SMESH_Mesh.idl @@ -440,6 +440,12 @@ module SMESH * Get mesh description */ string Dump(); + + /*! + * Get mesh pointer + */ + long GetMeshPtr(); + }; interface SMESH_subMesh : SALOME::GenericObj, SMESH_IDSource diff --git a/src/Makefile.in b/src/Makefile.in index c4bbfd85f..66181974a 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -33,7 +33,7 @@ VPATH=.:@srcdir@ SUBDIRS = \ SMDS SMESHDS Controls Driver DriverMED DriverDAT DriverUNV DriverSTL \ - SMESH SMESH_I OBJECT SMESHFiltersSelection SMESHGUI SMESH_SWIG \ + SMESH SMESH_I SMESHClient OBJECT SMESHFiltersSelection SMESHGUI SMESH_SWIG \ MEFISTO2 StdMeshers StdMeshers_I StdMeshersGUI @MODULE@ diff --git a/src/OBJECT/Makefile.in b/src/OBJECT/Makefile.in index 8cf070ccf..a16a58ad8 100644 --- a/src/OBJECT/Makefile.in +++ b/src/OBJECT/Makefile.in @@ -43,7 +43,11 @@ LIB_SRC = SMESH_Object.cxx SMESH_DeviceActor.cxx SMESH_Actor.cxx \ LIB_CLIENT_IDL = SALOME_Exception.idl \ SALOME_GenericObj.idl \ SMESH_Mesh.idl \ - SMESH_Group.idl + SMESH_Group.idl \ + SALOMEDS.idl \ + SMESH_Gen.idl \ + GEOM_Gen.idl \ + SMESH_Hypothesis.idl # Executables targets @@ -53,6 +57,7 @@ BIN_SRC = CPPFLAGS+=$(OCC_INCLUDES) $(VTK_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome -I${GUI_ROOT_DIR}/include/salome \ $(BOOST_CPPFLAGS) $(QT_INCLUDES) LDFLAGS+=$(OCC_KERNEL_LIBS) $(VTK_LIBS) -L${KERNEL_ROOT_DIR}/lib/salome -L${GUI_ROOT_DIR}/lib/salome -lSMDS \ - -lSalomeApp -lSalomeObject -lSMESHControls + -lSMESHClient -lSalomeApp -lSalomeObject -lSMESHControls -lSalomeLifeCycleCORBA -lSalomeDS -lCASCatch -lSalomeSession +LDFLAGSFORBIN += $(LDFLAGS) @CONCLUDE@ diff --git a/src/OBJECT/SMESH_Actor.cxx b/src/OBJECT/SMESH_Actor.cxx index 5f17220f0..a7250e800 100644 --- a/src/OBJECT/SMESH_Actor.cxx +++ b/src/OBJECT/SMESH_Actor.cxx @@ -746,13 +746,13 @@ bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj, my2DActor->GetPolygonOffsetParameters(aFactor,aUnits); my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75); - //SetIsShrunkable(theGrid->GetNumberOfCells() > 10); - SetIsShrunkable(true); - SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr(); if( !mgr ) return false; + //SetIsShrunkable(theGrid->GetNumberOfCells() > 10); + SetIsShrunkable(true); + SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 0.75 ) ); int aMode = mgr->integerValue( "SMESH", "display_mode" ); @@ -835,6 +835,8 @@ bool SMESH_ActorDef::IsInfinitive(){ void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){ + if ( myIsShrinkable == theShrunkable ) + return; myIsShrinkable = theShrunkable; Modified(); } @@ -1135,6 +1137,8 @@ void SMESH_ActorDef::SetRepresentation(int theMode){ void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){ + if ( myIsPointsVisible == theIsPointsVisible ) + return; myIsPointsVisible = theIsPointsVisible; SetRepresentation(GetRepresentation()); } @@ -1175,12 +1179,16 @@ void SMESH_ActorDef::UpdateHighlight(){ void SMESH_ActorDef::highlight(bool theHighlight){ + if ( myIsHighlighted == theHighlight ) + return; myIsHighlighted = theHighlight; UpdateHighlight(); } void SMESH_ActorDef::SetPreSelected(bool thePreselect){ + if ( myIsPreselected == thePreselect ) + return; myIsPreselected = thePreselect; UpdateHighlight(); } diff --git a/src/OBJECT/SMESH_DeviceActor.cxx b/src/OBJECT/SMESH_DeviceActor.cxx index 3548aaefe..50e258213 100644 --- a/src/OBJECT/SMESH_DeviceActor.cxx +++ b/src/OBJECT/SMESH_DeviceActor.cxx @@ -646,6 +646,8 @@ void SMESH_DeviceActor::SetShrinkFactor(float theValue){ void SMESH_DeviceActor::SetHighlited(bool theIsHighlited){ + if ( myIsHighlited == theIsHighlited ) + return; myIsHighlited = theIsHighlited; Modified(); } diff --git a/src/OBJECT/SMESH_Object.cxx b/src/OBJECT/SMESH_Object.cxx index 885ee3de3..4727832dd 100644 --- a/src/OBJECT/SMESH_Object.cxx +++ b/src/OBJECT/SMESH_Object.cxx @@ -31,10 +31,15 @@ #include "SMDS_Mesh.hxx" #include "SMESH_Actor.h" #include "SMESH_ControlsDef.hxx" -#include +#include "SMESH_Client.hxx" +#include "VTKViewer_ExtractUnstructuredGrid.h" +#include CORBA_SERVER_HEADER(SMESH_Gen) #include CORBA_SERVER_HEADER(SALOME_Exception) +#include "SALOME_LifeCycleCORBA.hxx" +#include "SalomeApp_Application.h" + #include #include #include @@ -69,271 +74,6 @@ static int MYDEBUGWITHFILES = 0; #endif -namespace{ - - inline const SMDS_MeshNode* FindNode(const SMDS_Mesh* theMesh, int theId){ - if(const SMDS_MeshNode* anElem = theMesh->FindNode(theId)) return anElem; - EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<FindElement(theId)) return anElem; - EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot find a SMDS_MeshElement for ID = "<AddNodeWithID(aCoords[aCoordId], - aCoords[aCoordId+1], - aCoords[aCoordId+2], - anIndexes[anElemId]); - if(!anElem) - EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddNodeWithID for ID = "<AddEdgeWithID(anIndexes[anIndexId+1], - anIndexes[anIndexId+2], - anIndexes[anIndexId]); - if(!anElem) - EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddEdgeWithID for ID = "<AddFaceWithID(anIndexes[anIndexId+1], - anIndexes[anIndexId+2], - anIndexes[anIndexId+3], - anIndexes[anIndexId]); - if(!anElem) - EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<AddFaceWithID(anIndexes[anIndexId+1], - anIndexes[anIndexId+2], - anIndexes[anIndexId+3], - anIndexes[anIndexId+4], - anIndexes[anIndexId]); - if(!anElem) - EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "< nodes_ids (aNbNodes); - for (int i = 0; i < aNbNodes; i++) { - nodes_ids[i] = anIndexes[anIndexId++]; - } - - SMDS_MeshElement* anElem = theMesh->AddPolygonalFaceWithID(nodes_ids, aFaceId); - if (!anElem) - EXCEPTION(runtime_error, "SMDS_Mesh::FindElement - cannot AddPolygonalFaceWithID for ID = " - << anElemId); - } - } - - - inline void AddTetrasWithID(SMDS_Mesh* theMesh, - SMESH::log_array_var& theSeq, - CORBA::Long theId) - { - const SMESH::long_array& anIndexes = theSeq[theId].indexes; - CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number; - if(5*aNbElems != anIndexes.length()) - EXCEPTION(runtime_error,"AddEdgeWithID - 5*aNbElems != anIndexes.length()"); - for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=5){ - SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1], - anIndexes[anIndexId+2], - anIndexes[anIndexId+3], - anIndexes[anIndexId+4], - anIndexes[anIndexId]); - if(!anElem) - EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<AddVolumeWithID(anIndexes[anIndexId+1], - anIndexes[anIndexId+2], - anIndexes[anIndexId+3], - anIndexes[anIndexId+4], - anIndexes[anIndexId+5], - anIndexes[anIndexId]); - if(!anElem) - EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<AddVolumeWithID(anIndexes[anIndexId+1], - anIndexes[anIndexId+2], - anIndexes[anIndexId+3], - anIndexes[anIndexId+4], - anIndexes[anIndexId+5], - anIndexes[anIndexId+6], - anIndexes[anIndexId]); - if(!anElem) - EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<AddVolumeWithID(anIndexes[anIndexId+1], - anIndexes[anIndexId+2], - anIndexes[anIndexId+3], - anIndexes[anIndexId+4], - anIndexes[anIndexId+5], - anIndexes[anIndexId+6], - anIndexes[anIndexId+7], - anIndexes[anIndexId+8], - anIndexes[anIndexId]); - if(!anElem) - EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "< nodes_ids (aNbNodes); - for (int i = 0; i < aNbNodes; i++) { - nodes_ids[i] = anIndexes[anIndexId++]; - } - - int aNbFaces = anIndexes[anIndexId++]; - std::vector quantities (aNbFaces); - for (int i = 0; i < aNbFaces; i++) { - quantities[i] = anIndexes[anIndexId++]; - } - - SMDS_MeshElement* anElem = - theMesh->AddPolyhedralVolumeWithID(nodes_ids, quantities, aFaceId); - if (!anElem) - EXCEPTION(runtime_error, "SMDS_Mesh::FindElement - cannot AddPolyhedralVolumeWithID for ID = " - << anElemId); - } - } - - - inline void ChangePolyhedronNodes (SMDS_Mesh* theMesh, - SMESH::log_array_var& theSeq, - CORBA::Long theId) - { - const SMESH::long_array& anIndexes = theSeq[theId].indexes; - CORBA::Long iind = 0, aNbElems = theSeq[theId].number; - - for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++) - { - // find element - const SMDS_MeshElement* elem = FindElement(theMesh, anIndexes[iind++]); - // nb nodes - int nbNodes = anIndexes[iind++]; - // nodes - std::vector aNodes (nbNodes); - for (int iNode = 0; iNode < nbNodes; iNode++) { - aNodes[iNode] = FindNode(theMesh, anIndexes[iind++]); - } - // nb faces - int nbFaces = anIndexes[iind++]; - // quantities - std::vector quantities (nbFaces); - for (int iFace = 0; iFace < nbFaces; iFace++) { - quantities[iFace] = anIndexes[iind++]; - } - // change - theMesh->ChangePolyhedronNodes(elem, aNodes, quantities); - } - } - - -} /* Class : SMESH_VisualObjDef Description : Base class for all mesh objects to be visuilised @@ -756,6 +496,7 @@ SMESH_MeshObj::SMESH_MeshObj(SMESH::SMESH_Mesh_ptr theMesh) myMeshServer = SMESH::SMESH_Mesh::_duplicate( theMesh ); myMeshServer->Register(); myMesh = new SMDS_Mesh(); + myIsMeshFromServer = 0; } //================================================================================= @@ -765,7 +506,8 @@ SMESH_MeshObj::SMESH_MeshObj(SMESH::SMESH_Mesh_ptr theMesh) SMESH_MeshObj::~SMESH_MeshObj() { myMeshServer->Destroy(); - delete myMesh; + if ( !myIsMeshFromServer ) + delete myMesh; } //================================================================================= @@ -775,110 +517,23 @@ SMESH_MeshObj::~SMESH_MeshObj() void SMESH_MeshObj::Update( int theIsClear ) { // Update SMDS_Mesh on client part - - try - { - SMESH::log_array_var aSeq = myMeshServer->GetLog( theIsClear ); - CORBA::Long aLength = aSeq->length(); - - if( MYDEBUG ) MESSAGE( "Update: length of the script is "<RemoveNode( FindNode( myMesh, anIndexes[anElemId] ) ); - break; - - case SMESH::REMOVE_ELEMENT: - for( ; anElemId < aNbElems; anElemId++ ) - myMesh->RemoveElement( FindElement( myMesh, anIndexes[anElemId] ) ); - break; - - case SMESH::MOVE_NODE: - for(CORBA::Long aCoordId=0; anElemId < aNbElems; anElemId++, aCoordId+=3) - { - SMDS_MeshNode* node = - const_cast( FindNode( myMesh, anIndexes[anElemId] )); - node->setXYZ( aCoords[aCoordId], aCoords[aCoordId+1], aCoords[aCoordId+2] ); - } - break; - - case SMESH::CHANGE_ELEMENT_NODES: - for ( CORBA::Long i = 0; anElemId < aNbElems; anElemId++ ) - { - // find element - const SMDS_MeshElement* elem = FindElement( myMesh, anIndexes[i++] ); - // nb nodes - int nbNodes = anIndexes[i++]; - // nodes - //ASSERT( nbNodes < 9 ); - const SMDS_MeshNode* aNodes[ nbNodes ]; - for ( int iNode = 0; iNode < nbNodes; iNode++ ) - aNodes[ iNode ] = FindNode( myMesh, anIndexes[i++] ); - // change - myMesh->ChangeElementNodes( elem, aNodes, nbNodes ); - } - break; - - case SMESH::CHANGE_POLYHEDRON_NODES: - ChangePolyhedronNodes(myMesh, aSeq, anId); - break; - case SMESH::RENUMBER: - for(CORBA::Long i=0; anElemId < aNbElems; anElemId++, i+=3) - { - myMesh->Renumber( anIndexes[i], anIndexes[i+1], anIndexes[i+2] ); - } - break; - - default:; - } - } - } - catch ( SALOME::SALOME_Exception& exc ) - { - INFOS("Following exception was cought:\n\t"<FindOrLoad_Component( "FactoryServer", "SMESH" ); + SMESH::SMESH_Gen_ptr smesh = SMESH::SMESH_Gen::_narrow( comp ); + int isUpdated = 0; + SMESH_Client client; + SMDS_Mesh* meshPtr = client.Update( smesh, myMeshServer, myMesh, theIsClear, isUpdated ); + if ( meshPtr && myMesh != meshPtr ) + { + delete myMesh; + myMesh = meshPtr; + myIsMeshFromServer = 1; } - catch(...) - { - INFOS("Unknown exception was cought !!!"); - } - - if ( MYDEBUG ) + // Fill unstructured grid + if ( isUpdated ) { - MESSAGE("Update - myMesh->NbNodes() = "<NbNodes()); - MESSAGE("Update - myMesh->NbEdges() = "<NbEdges()); - MESSAGE("Update - myMesh->NbFaces() = "<NbFaces()); - MESSAGE("Update - myMesh->NbVolumes() = "<NbVolumes()); + buildPrs(); } - - // Fill unstructured grid - buildPrs(); } //================================================================================= @@ -1256,15 +911,3 @@ bool SMESH_subMeshObj::IsNodePrs() const { return mySubMeshServer->GetNumberOfElements() == 0; } - - - - - - - - - - - - diff --git a/src/OBJECT/SMESH_ObjectDef.h b/src/OBJECT/SMESH_ObjectDef.h index 134b47b10..8ce7b8558 100644 --- a/src/OBJECT/SMESH_ObjectDef.h +++ b/src/OBJECT/SMESH_ObjectDef.h @@ -125,7 +125,7 @@ public: SMDS_Mesh* GetMesh() const { return myMesh; } protected: - + int myIsMeshFromServer; SMESH::SMESH_Mesh_var myMeshServer; SMDS_Mesh* myMesh; }; diff --git a/src/SMESHClient/Makefile.in b/src/SMESHClient/Makefile.in new file mode 100644 index 000000000..fc3aa1de3 --- /dev/null +++ b/src/SMESHClient/Makefile.in @@ -0,0 +1,73 @@ +# GEOM GEOMClient : tool to transfer BREP files from GEOM server to GEOM client +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# +# +# +# File : Makefile.in +# Author : Pavel TELKOV (OCC) +# Module : SHESM + +top_srcdir=@top_srcdir@ +top_builddir=../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@top_srcdir@/idl + + +@COMMENCE@ + +# header files +EXPORT_HEADERS = \ + SMESH_Client.hxx + +# Libraries targets + +LIB = libSMESHClient.la +LIB_SRC = SMESH_Client.cxx + +LIB_CLIENT_IDL = SALOME_Comm.idl \ + SALOME_Component.idl \ + SALOMEDS.idl \ + SALOMEDS_Attributes.idl \ + SALOME_Exception.idl \ + SALOME_GenericObj.idl \ + SMESH_Mesh.idl \ + SMESH_Gen.idl \ + SMESH_Group.idl \ + SMESH_Hypothesis.idl \ + SMESH_Pattern.idl \ + SMESH_Filter.idl \ + GEOM_Gen.idl \ + MED.idl + +# Executables targets +BIN = SMESHClientBin +BIN_SRC = +BIN_CLIENT_IDL = +BIN_SERVER_IDL = + +# additionnal information to compil and link file +CPPFLAGS += $(OCC_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome +CXXFLAGS += $(OCC_CXXFLAGS) -I${KERNEL_ROOT_DIR}/include/salome +LDFLAGS += $(OCC_KERNEL_LIBS) -L${KERNEL_ROOT_DIR}/lib/salome -lSMDS -lSMESHimpl -lSMESHDS -lSMESHControls + +LDFLAGSFORBIN += $(LDFLAGS) +@CONCLUDE@ + diff --git a/src/SMESHClient/SMESHClientBin.cxx b/src/SMESHClient/SMESHClientBin.cxx new file mode 100644 index 000000000..0ac9bf899 --- /dev/null +++ b/src/SMESHClient/SMESHClientBin.cxx @@ -0,0 +1,30 @@ +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// File : +// Author : +// Module : +// $Header: + +#include "SMESH_Client.hxx" + +int main( int, char** ) +{ + return 0; +} diff --git a/src/SMESHClient/SMESH_Client.cxx b/src/SMESHClient/SMESH_Client.cxx new file mode 100644 index 000000000..98bb56583 --- /dev/null +++ b/src/SMESHClient/SMESH_Client.cxx @@ -0,0 +1,480 @@ +// SMESH SMESHClient : tool to update client mesh structure by mesh from server +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SMESH_Client.cxx +// Author : Pavel TELKOV +// Module : SMESH + +#include "SMESH_Client.hxx" + +#include +#include "OpUtil.hxx" +#include "utilities.h" + +#include + +#include CORBA_SERVER_HEADER(SALOME_Exception) + +#ifdef WNT +#include +#else +#include +#endif + +#include + +#ifndef EXCEPTION +#define EXCEPTION(TYPE, MSG) {\ + std::ostringstream aStream;\ + aStream<<__FILE__<<"["<<__LINE__<<"]::"<getPID(); +} + +namespace{ + + inline const SMDS_MeshNode* FindNode(const SMDS_Mesh* theMesh, int theId){ + if(const SMDS_MeshNode* anElem = theMesh->FindNode(theId)) return anElem; + EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<FindElement(theId)) return anElem; + EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot find a SMDS_MeshElement for ID = "<AddNodeWithID(aCoords[aCoordId], + aCoords[aCoordId+1], + aCoords[aCoordId+2], + anIndexes[anElemId]); + if(!anElem) + EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddNodeWithID for ID = "<AddEdgeWithID(anIndexes[anIndexId+1], + anIndexes[anIndexId+2], + anIndexes[anIndexId]); + if(!anElem) + EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddEdgeWithID for ID = "<AddFaceWithID(anIndexes[anIndexId+1], + anIndexes[anIndexId+2], + anIndexes[anIndexId+3], + anIndexes[anIndexId]); + if(!anElem) + EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "<AddFaceWithID(anIndexes[anIndexId+1], + anIndexes[anIndexId+2], + anIndexes[anIndexId+3], + anIndexes[anIndexId+4], + anIndexes[anIndexId]); + if(!anElem) + EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddFaceWithID for ID = "< nodes_ids (aNbNodes); + for (int i = 0; i < aNbNodes; i++) { + nodes_ids[i] = anIndexes[anIndexId++]; + } + + SMDS_MeshElement* anElem = theMesh->AddPolygonalFaceWithID(nodes_ids, aFaceId); + if (!anElem) + EXCEPTION(runtime_error, "SMDS_Mesh::FindElement - cannot AddPolygonalFaceWithID for ID = " + << anElemId); + } + } + + + inline void AddTetrasWithID(SMDS_Mesh* theMesh, + SMESH::log_array_var& theSeq, + CORBA::Long theId) + { + const SMESH::long_array& anIndexes = theSeq[theId].indexes; + CORBA::Long anElemId = 0, aNbElems = theSeq[theId].number; + if(5*aNbElems != anIndexes.length()) + EXCEPTION(runtime_error,"AddEdgeWithID - 5*aNbElems != anIndexes.length()"); + for(CORBA::Long anIndexId = 0; anElemId < aNbElems; anElemId++, anIndexId+=5){ + SMDS_MeshElement* anElem = theMesh->AddVolumeWithID(anIndexes[anIndexId+1], + anIndexes[anIndexId+2], + anIndexes[anIndexId+3], + anIndexes[anIndexId+4], + anIndexes[anIndexId]); + if(!anElem) + EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<AddVolumeWithID(anIndexes[anIndexId+1], + anIndexes[anIndexId+2], + anIndexes[anIndexId+3], + anIndexes[anIndexId+4], + anIndexes[anIndexId+5], + anIndexes[anIndexId]); + if(!anElem) + EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<AddVolumeWithID(anIndexes[anIndexId+1], + anIndexes[anIndexId+2], + anIndexes[anIndexId+3], + anIndexes[anIndexId+4], + anIndexes[anIndexId+5], + anIndexes[anIndexId+6], + anIndexes[anIndexId]); + if(!anElem) + EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "<AddVolumeWithID(anIndexes[anIndexId+1], + anIndexes[anIndexId+2], + anIndexes[anIndexId+3], + anIndexes[anIndexId+4], + anIndexes[anIndexId+5], + anIndexes[anIndexId+6], + anIndexes[anIndexId+7], + anIndexes[anIndexId+8], + anIndexes[anIndexId]); + if(!anElem) + EXCEPTION(runtime_error,"SMDS_Mesh::FindElement - cannot AddVolumeWithID for ID = "< nodes_ids (aNbNodes); + for (int i = 0; i < aNbNodes; i++) { + nodes_ids[i] = anIndexes[anIndexId++]; + } + + int aNbFaces = anIndexes[anIndexId++]; + std::vector quantities (aNbFaces); + for (int i = 0; i < aNbFaces; i++) { + quantities[i] = anIndexes[anIndexId++]; + } + + SMDS_MeshElement* anElem = + theMesh->AddPolyhedralVolumeWithID(nodes_ids, quantities, aFaceId); + if (!anElem) + EXCEPTION(runtime_error, "SMDS_Mesh::FindElement - cannot AddPolyhedralVolumeWithID for ID = " + << anElemId); + } + } + + + inline void ChangePolyhedronNodes (SMDS_Mesh* theMesh, + SMESH::log_array_var& theSeq, + CORBA::Long theId) + { + const SMESH::long_array& anIndexes = theSeq[theId].indexes; + CORBA::Long iind = 0, aNbElems = theSeq[theId].number; + + for (CORBA::Long anElemId = 0; anElemId < aNbElems; anElemId++) + { + // find element + const SMDS_MeshElement* elem = FindElement(theMesh, anIndexes[iind++]); + // nb nodes + int nbNodes = anIndexes[iind++]; + // nodes + std::vector aNodes (nbNodes); + for (int iNode = 0; iNode < nbNodes; iNode++) { + aNodes[iNode] = FindNode(theMesh, anIndexes[iind++]); + } + // nb faces + int nbFaces = anIndexes[iind++]; + // quantities + std::vector quantities (nbFaces); + for (int iFace = 0; iFace < nbFaces; iFace++) { + quantities[iFace] = anIndexes[iind++]; + } + // change + theMesh->ChangePolyhedronNodes(elem, aNodes, quantities); + } + } +} + +//================================================================================= +// function : Update +// purpose : Update mesh +//================================================================================= +SMDS_Mesh* SMESH_Client::Update( SMESH::SMESH_Gen_ptr smesh, + SMESH::SMESH_Mesh_ptr theMeshServer, + SMDS_Mesh* theMesh, + int theIsClear, + int& theIsUpdated ) +{ + SMDS_Mesh* meshPtr = theMesh; + theIsUpdated = 0; + + SMESH::log_array_var aSeq = theMeshServer->GetLog( theIsClear ); + CORBA::Long aLength = aSeq->length(); + + if( MYDEBUG ) + MESSAGE( "Update: length of the script is "<GetContainerRef(); + long pid_server = ctn_server->getPID(); + if ( (pid_client==pid_server) && (strcmp(hst_client.c_str(), ctn_server->getHostName())==0) ) + { + if ( MYDEBUG ) + MESSAGE("Info: The same process, update mesh by pointer "); + // just set client mesh pointer to server mesh pointer + meshPtr = ((SMESH_Mesh*)theMeshServer->GetMeshPtr())->GetMeshDS(); + if ( meshPtr ) + theIsUpdated = 1; + } + else + { + // update client mesh structure by logged changes commands + try + { + for ( CORBA::Long anId = 0; anId < aLength; anId++) + { + const SMESH::double_array& aCoords = aSeq[anId].coords; + const SMESH::long_array& anIndexes = aSeq[anId].indexes; + CORBA::Long anElemId = 0, aNbElems = aSeq[anId].number; + CORBA::Long aCommand = aSeq[anId].commandType; + + switch(aCommand) + { + case SMESH::ADD_NODE : AddNodesWithID ( meshPtr, aSeq, anId ); break; + case SMESH::ADD_EDGE : AddEdgesWithID ( meshPtr, aSeq, anId ); break; + case SMESH::ADD_TRIANGLE : AddTriasWithID ( meshPtr, aSeq, anId ); break; + case SMESH::ADD_QUADRANGLE : AddQuadsWithID ( meshPtr, aSeq, anId ); break; + case SMESH::ADD_POLYGON : AddPolygonsWithID ( meshPtr, aSeq, anId ); break; + case SMESH::ADD_TETRAHEDRON: AddTetrasWithID ( meshPtr, aSeq, anId ); break; + case SMESH::ADD_PYRAMID : AddPiramidsWithID ( meshPtr, aSeq, anId ); break; + case SMESH::ADD_PRISM : AddPrismsWithID ( meshPtr, aSeq, anId ); break; + case SMESH::ADD_HEXAHEDRON : AddHexasWithID ( meshPtr, aSeq, anId ); break; + case SMESH::ADD_POLYHEDRON : AddPolyhedronsWithID( meshPtr, aSeq, anId ); break; + + case SMESH::REMOVE_NODE: + for( ; anElemId < aNbElems; anElemId++ ) + meshPtr->RemoveNode( FindNode( meshPtr, anIndexes[anElemId] ) ); + break; + + case SMESH::REMOVE_ELEMENT: + for( ; anElemId < aNbElems; anElemId++ ) + meshPtr->RemoveElement( FindElement( meshPtr, anIndexes[anElemId] ) ); + break; + + case SMESH::MOVE_NODE: + for(CORBA::Long aCoordId=0; anElemId < aNbElems; anElemId++, aCoordId+=3) + { + SMDS_MeshNode* node = + const_cast( FindNode( meshPtr, anIndexes[anElemId] )); + node->setXYZ( aCoords[aCoordId], aCoords[aCoordId+1], aCoords[aCoordId+2] ); + } + break; + + case SMESH::CHANGE_ELEMENT_NODES: + for ( CORBA::Long i = 0; anElemId < aNbElems; anElemId++ ) + { + // find element + const SMDS_MeshElement* elem = FindElement( meshPtr, anIndexes[i++] ); + // nb nodes + int nbNodes = anIndexes[i++]; + // nodes + //ASSERT( nbNodes < 9 ); + const SMDS_MeshNode* aNodes[ nbNodes ]; + for ( int iNode = 0; iNode < nbNodes; iNode++ ) + aNodes[ iNode ] = FindNode( meshPtr, anIndexes[i++] ); + // change + meshPtr->ChangeElementNodes( elem, aNodes, nbNodes ); + } + break; + + case SMESH::CHANGE_POLYHEDRON_NODES: + ChangePolyhedronNodes(meshPtr, aSeq, anId); + break; + case SMESH::RENUMBER: + for(CORBA::Long i=0; anElemId < aNbElems; anElemId++, i+=3) + { + meshPtr->Renumber( anIndexes[i], anIndexes[i+1], anIndexes[i+2] ); + } + break; + + default:; + } + } + theIsUpdated = 1; + } + catch ( SALOME::SALOME_Exception& exc ) + { + INFOS("Following exception was cought:\n\t"<NbNodes() = "<NbNodes()); + MESSAGE("Update - meshPtr->NbEdges() = "<NbEdges()); + MESSAGE("Update - meshPtr->NbFaces() = "<NbFaces()); + MESSAGE("Update - meshPtr->NbVolumes() = "<NbVolumes()); + } + + return meshPtr; +} diff --git a/src/SMESHClient/SMESH_Client.hxx b/src/SMESHClient/SMESH_Client.hxx new file mode 100644 index 000000000..ff65380f8 --- /dev/null +++ b/src/SMESHClient/SMESH_Client.hxx @@ -0,0 +1,84 @@ +// SMESH SMESHClient : tool to update client mesh structure by mesh from server +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SMESH_Client.hxx +// Author : Pavel TELKOV +// Module : SMESH + +#ifndef _SMESH_Client_HeaderFile +#define _SMESH_Client_HeaderFile + +#include +#include CORBA_SERVER_HEADER(SMESH_Gen) +#include CORBA_SERVER_HEADER(SMESH_Mesh) +//#include CORBA_SERVER_HEADER(SALOME_Container) + +#ifndef _Standard_HeaderFile +#include +#endif + +#if defined WNT && defined WIN32 && defined SALOME_WNT_EXPORTS +#define SMESHCLIENT_WNT_EXPORT __declspec( dllexport ) +#else +#define SMESHCLIENT_WNT_EXPORT +#endif + +class SMDS_Mesh; + +//===================================================================== +// SMESH_Client : class definition +//===================================================================== +class SMESHCLIENT_WNT_EXPORT SMESH_Client { + +public: + + inline void* operator new(size_t,void* anAddress) + { + return anAddress; + } + inline void* operator new(size_t size) + { + return Standard::Allocate(size); + } + inline void operator delete(void *anAddress) + { + if (anAddress) Standard::Free((Standard_Address&)anAddress); + } + // Methods PUBLIC + // + SMESH_Client(); + SMESH_Client(Engines::Container_ptr client); + SMDS_Mesh* Update( SMESH::SMESH_Gen_ptr smesh, + SMESH::SMESH_Mesh_ptr theMeshServer, + SMDS_Mesh* theMesh, + int theIsClear, + int& theIsUpdated ); + +private: + // Fields PRIVATE + // + long pid_client; +}; + + +#endif diff --git a/src/SMESHGUI/Makefile.in b/src/SMESHGUI/Makefile.in index fa786a65a..0dbb8e0a0 100644 --- a/src/SMESHGUI/Makefile.in +++ b/src/SMESHGUI/Makefile.in @@ -193,7 +193,7 @@ LDFLAGS += -lSMESHObject -lSMESHFiltersSelection -lSMDS -lSMESHControls -lDlgRef $(OCC_KERNEL_LIBS) -lTKBO -lTKAdvTools -L${KERNEL_ROOT_DIR}/lib/salome -L${GUI_ROOT_DIR}/lib/salome \ -lVTKViewer -lSalomeDSClient -lSalomeDS -lSalomeApp -lSalomePrs -lSalomeNS -lSalomeLifeCycleCORBA -lOpUtil -lSalomeObject \ -lEvent -lSALOMELocalTrace -lSVTK -lOCCViewer -L${GEOM_ROOT_DIR}/lib/salome -lGEOM -lGEOMClient \ - -lGEOMBase -lGEOMObject -lGEOMFiltersSelection + -lGEOMBase -lGEOMObject -lGEOMFiltersSelection -lSalomeSession LDFLAGSFORBIN += $(LDFLAGS) diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index 03e21aa78..05d8ff0cf 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -1570,3 +1570,14 @@ SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const boo { return ( SMESH::ElementType )_impl->GetElementType( id, iselem ); } + +//============================================================================= +/*! + * + */ +//============================================================================= + +CORBA::Long SMESH_Mesh_i::GetMeshPtr() +{ + return (CORBA::Long)_impl; +} diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index 5fa53b1e5..9167f325d 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -254,6 +254,8 @@ public: virtual SMESH::long_array* GetIDs(); + CORBA::Long GetMeshPtr(); + map _mapSubMesh_i; //NRI map _mapSubMesh; //NRI -- 2.39.2