Add an update all command in the log of mesh DS. It will allow to display the whole mesh with a small number of CORBA call.

This commit is contained in:
jrt 2004-03-01 14:04:23 +00:00
parent d2b92e5939
commit 58d4e7b341
14 changed files with 332 additions and 94 deletions

View File

@ -49,7 +49,8 @@ module SMESH
ADD_PRISM,
ADD_HEXAHEDRON,
REMOVE_NODE,
REMOVE_ELEMENT
REMOVE_ELEMENT,
REMOVE_ALL
};
struct log_block

View File

@ -1271,7 +1271,7 @@ SMDS_Iterator<const SMDS_MeshNode *> * SMDS_Mesh::nodesIterator() const
}
///////////////////////////////////////////////////////////////////////////////
///Return an iterator on volumes of the current mesh. Once used this iterator
///Return an iterator on egdes of the current mesh. Once used this iterator
///must be free by the caller
///////////////////////////////////////////////////////////////////////////////
SMDS_Iterator<const SMDS_MeshEdge *> * SMDS_Mesh::edgesIterator() const
@ -1574,3 +1574,126 @@ void SMDS_Mesh::RemoveElement(const SMDS_MeshElement * elem,
delete s2;
delete s1;
}
/**
* Concat the coordinates of all nodes in an array.
* Its used to display the mesh.
* @return A array of size 3*NbNodes() containing the coordinates of nodes.
*/
double * SMDS_Mesh::getNodesCoordinates()
{
double * toReturn=new double[3*NbNodes()];
SMDS_Iterator<const SMDS_MeshNode*> * it=nodesIterator();
int i=0;
while(it->more())
{
const SMDS_MeshNode * n=it->next();
toReturn[i]=n->X();
i++;
toReturn[i]=n->Y();
i++;
toReturn[i]=n->Z();
i++;
}
delete it;
return toReturn;
}
/**
* Concat the id of all nodes in an array.
* Its used to display the mesh.
* @return A array of size NbNodes() containing the ids of nodes.
*/
long * SMDS_Mesh::getNodesID()
{
long * toReturn=new long[NbNodes()];
SMDS_Iterator<const SMDS_MeshNode*> * it=nodesIterator();
int i=0;
while(it->more())
{
const SMDS_MeshNode * n=it->next();
toReturn[i]=n->GetID();
i++;
}
delete it;
return toReturn;
}
/**
* Concat the id of nodes of edges in an array.
* Array format is {edge_id, node1_id, node2_id}
* Its used to display the mesh.
* @return A array of size 3*NbEdges() containing the edges.
*/
long * SMDS_Mesh::getEdgesIndices()
{
long * toReturn=new long[NbEdges()*3];
SMDS_Iterator<const SMDS_MeshEdge*> * it=edgesIterator();
int i=0;
while(it->more())
{
const SMDS_MeshEdge * e=it->next();
toReturn[i]=e->GetID();
i++;
SMDS_Iterator<const SMDS_MeshElement*> * itn=e->nodesIterator();
while(itn->more())
{
const SMDS_MeshElement * n=itn->next();
toReturn[i]=n->GetID();
i++;
}
delete itn;
}
delete it;
return toReturn;
}
/**
* Concat the id of nodes of triangles in an array.
* Array format is {tria_id, node1_id, node2_id, node3_id}
* Its used to display the mesh.
* @return A array of size 4*NbTriangles() containing the edges.
*/
long * SMDS_Mesh::getTrianglesIndices()
{
long * toReturn=new long[NbTriangles()*4];
SMDS_Iterator<const SMDS_MeshFace*> * it=facesIterator();
int i=0;
while(it->more())
{
const SMDS_MeshFace * f=it->next();
if(f->NbNodes()==3)
{
toReturn[i]=f->GetID();
i++;
SMDS_Iterator<const SMDS_MeshElement*> * itn=f->nodesIterator();
while(itn->more())
{
const SMDS_MeshElement * n=itn->next();
toReturn[i]=n->GetID();
i++;
}
delete itn;
}
}
delete it;
return toReturn;
}
/**
* Return the number of 3 nodes faces in the mesh.
* This method run in O(n).
* @return The number of face whose number of nodes is 3
*/
int SMDS_Mesh::NbTriangles() const
{
SMDS_Iterator<const SMDS_MeshFace*> * it=facesIterator();
int toReturn=0;
while(it->more())
{
const SMDS_MeshFace * f=it->next();
if(f->NbNodes()==3) toReturn++;
}
return toReturn;
}

View File

@ -167,6 +167,7 @@ class SMDS_Mesh:public SMDS_MeshObject
int NbNodes() const;
int NbEdges() const;
int NbFaces() const;
int NbTriangles() const;
int NbVolumes() const;
int NbSubMesh() const;
void DumpNodes() const;
@ -184,6 +185,11 @@ class SMDS_Mesh:public SMDS_MeshObject
void setConstructionFaces(bool);
void setInverseElements(bool);
double * getNodesCoordinates();
long * getNodesID();
long * getEdgesIndices();
long * getTrianglesIndices();
private:
SMDS_Mesh(SMDS_Mesh * parent);
SMDS_MeshFace * createTriangle(SMDS_MeshNode * node1,

View File

@ -127,7 +127,8 @@ throw(SALOME_Exception)
//=============================================================================
/*!
*
* @TODO Doing a full update after computation is not optimal when doing a local
* remeshing.
*/
//=============================================================================
@ -139,7 +140,7 @@ throw(SALOME_Exception)
/*
Algo : s'appuie ou non sur une geometrie
Si geometrie:
Vertex : rien à faire (range le point)
Vertex : rien <EFBFBD>faire (range le point)
Edge, Wire, collection d'edge et wire : 1D
Face, Shell, collection de Face et Shells : 2D
Solid, Collection de Solid : 3D
@ -184,6 +185,8 @@ Solid, Collection de Solid : 3D
smToCompute = sm->GetFirstToCompute();
}
aMesh.GetMeshDS()->logFullUpdate();
return ret;
}
@ -437,6 +440,8 @@ SMESH_Mesh * SMESH_Gen::Import(int studyId, const char * fileName,
reader->SetFile(string(fileName));
reader->Read();
mesh->GetMeshDS()->logFullUpdate();
return mesh;
}

View File

@ -29,6 +29,7 @@
#include "SMESHDS_CommandType.hxx"
#include <list>
using namespace std;
class SMESHDS_Command
{

View File

@ -38,7 +38,8 @@ SMESHDS_AddPrism,
SMESHDS_AddHexahedron,
SMESHDS_RemoveNode,
SMESHDS_RemoveElement,
SMESHDS_MoveNode
SMESHDS_MoveNode,
SMESHDS_UpdateAll
};

View File

@ -577,3 +577,12 @@ void SMESHDS_Mesh::SetMeshElementOnShape(const SMDS_MeshElement* anElement,
SMESHDS_Mesh::~SMESHDS_Mesh()
{
}
/**
* Add FULL_UPDATE command to the log of this mesh. Once interpreted by the
* graphical client it will (re)draw the full mesh.
*/
void SMESHDS_Mesh::logFullUpdate()
{
myScript->UpdateAll();
}

View File

@ -133,7 +133,8 @@ class SMESHDS_Mesh:public SMDS_Mesh
void SetNodeOnVertex(SMDS_MeshNode * aNode, int Index);
void SetMeshElementOnShape(const SMDS_MeshElement * anElt, int Index);
~SMESHDS_Mesh();
void logFullUpdate();
private:
struct HashTopoDS_Shape
{

View File

@ -26,7 +26,6 @@
// Module : SMESH
// $Header:
using namespace std;
#include "SMESHDS_Script.hxx"
//=======================================================================
@ -321,3 +320,12 @@ const list<SMESHDS_Command*>& SMESHDS_Script::GetCommands()
{
return myCommands;
}
/**
* Add UpdateAll command to the log of this mesh. Once interpreted by the
* graphical client it will (re)draw the full mesh.
*/
void SMESHDS_Script::UpdateAll()
{
myCommands.insert(myCommands.end(), new SMESHDS_Command(SMESHDS_UpdateAll));
}

View File

@ -52,6 +52,7 @@ class SMESHDS_Script
void RemoveElement(int ElementID);
void Clear();
const list<SMESHDS_Command*> & GetCommands();
void UpdateAll();
~SMESHDS_Script();
private:

View File

@ -3982,13 +3982,13 @@ bool SMESHGUI::CustomPopup(QAD_Desktop * parent,
return false;
}
//=============================================================================
/*! Method: BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
* Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
/**
* Ensures that the actor for the given <theIO> exists in the active VTK view
* @TODO Handle multiple selection.
*/
//=============================================================================
void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
{
MESSAGE("SMESHGUI::BuildPresentation("<<theIO->getEntry()<<")");
/* Create or retrieve an object SMESHGUI */
SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
@ -3997,7 +3997,8 @@ void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
if (activeFrame->getTypeView() == VIEW_VTK)
{
// VTK
SALOMEDS::SObject_var fatherSF =
// Some ideas to handle multiple selection...
/*SALOMEDS::SObject_var fatherSF =
smeshGUI->myStudy->FindObjectID(activeFrame->entry());
SALOME_Selection *Sel =
@ -4005,8 +4006,8 @@ void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
getSelection());
SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
// for(;It.More();It.Next()) {
// Handle(SALOME_InteractiveObject) IObject = It.Value();
for(;It.More();It.Next()) {
Handle(SALOME_InteractiveObject) IObject = It.Value();*/
Handle(SALOME_InteractiveObject) IObject = theIO;
if (IObject->hasEntry())
{
@ -4014,42 +4015,39 @@ void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
Standard_Boolean res;
SMESH_Actor *ac =
smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
// Actor not found at all -> mesh is not computed -> do nothing!!!
if (!res)
{
/*SMESH::SMESH_Mesh_var aM;
* SALOMEDS::SObject_var aMorSM = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
* SALOMEDS::SObject_var father = aMorSM->GetFather();
* SALOMEDS::SObject_var fatherComp = aMorSM->GetFatherComponent();
*
* // Non-displayable objects (Hypo, Algo) have tags < 3 or have a father different from component
* if (aMorSM->Tag() < 3 || strcmp(father->GetID(), fatherComp->GetID()) != 0)
* continue;
*
* SALOMEDS::GenericAttribute_var anAttr;
* SALOMEDS::AttributeIOR_var anIOR;
* if ( !aMorSM->_is_nil() ) {
* if (aMorSM->FindAttribute(anAttr, "AttributeIOR") ) {
* anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
* aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
* }
* }
*
* if (!aM->_is_nil()) {
* smeshGUI->InitActor(aM);
* ac = smeshGUI->ReadScript(aM);
* }
*
* if (ac) {
* smeshGUI->DisplayActor( ac, true );
* smeshGUI->DisplayEdges( ac );
* smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
* } */
// continue;
SALOMEDS::SObject_var aMorSM=smeshGUI->myStudy->FindObjectID( IObject->getEntry());
SALOMEDS::GenericAttribute_var anAttr;
SALOMEDS::AttributeIOR_var anIOR;
if(aMorSM->FindAttribute(anAttr, "AttributeIOR"))
{
anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
SMESH::SMESH_Mesh_var aM =
SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()));
if(!aM->_is_nil())
{
smeshGUI->InitActor(aM);
ac = smeshGUI->ReadScript(aM);
smeshGUI->DisplayActor( ac, true );
smeshGUI->DisplayEdges( ac );
smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
}
else
{
MESSAGE("Do not know how to display something which is not a SMESH_Mesh");
}
}
else
{
MESSAGE("The object "<<theIO->getEntry()<<
" do not have \"AttributeIOR\" attribute");
}
}
else
{ // The actor exists in some view
{
// The actor exists in some view
// Check whether the actor belongs to the active view
VTKViewer_RenderWindowInteractor *rwInter =
((VTKViewer_ViewFrame *) activeFrame->getRightFrame()->
@ -4072,12 +4070,11 @@ void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
smeshGUI->ChangeRepresentation(ac, ac->getDisplayMode());
}
}
// }
}
else
{
MESSAGE
("BuildPresentation() must not be called while non-VTK view is active")}
MESSAGE("BuildPresentation() must not be called while non-VTK view is active");
}
}
//=============================================================================
@ -4100,13 +4097,14 @@ void SMESHGUI::setOrb()
ASSERT(!CORBA::is_nil(_orb));
}
//=============================================================================
/*!
*
/**
* Get the history of all commands made in the SMESH server. This list of command
* is used to display the mesh in the VTK view
* @TODO Handle the REMOVE_ALL command.
*/
//=============================================================================
SMESH_Actor *SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr aMesh)
{
MESSAGE("SMESHGUI::ReadScript");
SMESH_Actor *MeshActor;
if (!aMesh->_is_nil())
{
@ -4115,11 +4113,8 @@ SMESH_Actor *SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr aMesh)
if (result)
{
SMESH::log_array_var aSeq = aMesh->GetLog(true);
if (aSeq->length() == 0)
{
MESSAGE("ReadScript(): log is empty") return MeshActor;
}
MESSAGE("SMESHGUI::ReadScript: The log contains "<<aSeq->length()
<<" commands.");
for (unsigned int ind = 0; ind < aSeq->length(); ind++)
{
@ -4180,6 +4175,10 @@ SMESH_Actor *SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr aMesh)
aSeq[ind].coords, aSeq[ind].indexes);
break;
}
case SMESH::REMOVE_ALL:
MESSAGE("REMOVE_ALL command not yet implemented");
break;
default: MESSAGE("Warning: Unknown script command.");
}
}
return MeshActor;
@ -4232,6 +4231,7 @@ void SMESHGUI::Dump(SMESH_Actor * Mactor)
void SMESHGUI::AddNodes(SMESH_Actor * Mactor, int number,
const SMESH::double_array & coords, const SMESH::long_array & indexes)
{
MESSAGE("SMESHGUI::AddNodes(number="<<number<<")");
QApplication::setOverrideCursor(Qt::waitCursor);
if (Mactor->GetMapper() == NULL)
{
@ -4289,8 +4289,9 @@ void SMESHGUI::AddNode(SMESH_Actor * Mactor, int idnode, float x, float y,
float z)
{
QApplication::setOverrideCursor(Qt::waitCursor);
MESSAGE("SMESHGUI::AddNode " << idnode << " : " << x << ";" << y << ";" <<
z) if (Mactor->GetMapper() == NULL)
MESSAGE("SMESHGUI::AddNode " << idnode << " : " << x << ";" << y << ";" << z);
if (Mactor->GetMapper() == NULL)
{
vtkPoints *Pts = vtkPoints::New();
int idVTK = Pts->InsertNextPoint(x, y, z);
@ -4951,6 +4952,7 @@ void SMESHGUI::AddEdge(SMESH_Actor * Mactor, int idedge, int idnode1,
void SMESHGUI::AddTriangles(SMESH_Actor * Mactor, int number,
const SMESH::double_array & coords, const SMESH::long_array & indexes)
{
MESSAGE("SMESHGUI::AddTriangles(number="<<number<<")");
QApplication::setOverrideCursor(Qt::waitCursor);
//vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
@ -5895,6 +5897,7 @@ void SMESHGUI::InitActor(SMESH::SMESH_Mesh_ptr aMesh)
//=============================================================================
void SMESHGUI::Update()
{
MESSAGE("SMESHGUI::Update");
if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
{ //VTK
vtkRenderer *theRenderer =

View File

@ -1521,6 +1521,7 @@ void SMESH_Gen_i::loadMesh(char * name, HDFfile * hdf_file,
myReader->SetMeshId(myMeshId);
myReader->SetFile(datafilename);
myReader->Read();
mySMESHDSMesh->logFullUpdate();
MESSAGE("Loaded a mesh with " << mySMESHDSMesh->NbNodes() <<" nodes");
}
}

View File

@ -162,18 +162,15 @@ CORBA::Boolean
return ret;
};
//=============================================================================
/*!
*
/**
*@TODO Not implemented
*/
//=============================================================================
SMESH::ListOfHypothesis *
SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Shape_ptr aSubShape)
throw(SALOME::SALOME_Exception)
{
MESSAGE("GetHypothesisList");
// ****
MESSAGE("GetHypothesisList: Not implemented");
return NULL;
};
//=============================================================================
@ -230,25 +227,100 @@ SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetElementsOnShape(GEOM::
return SMESH::SMESH_subMesh::_duplicate(_mapSubMeshIor[subMeshId]);
}
//=============================================================================
/*!
*
/**
* Translate the UpdateAll SMESHDS_Command to a set of SMESH::log_command.
* As the input log need to be resized, it is realocated.
* @param logBlock The log where to insert created commands
* @param index The place where to insert created commands in log
* @return The realocated and resized log.
* @TODO Add support for other type of elements
*/
//=============================================================================
SMESH::log_array_var SMESH_Mesh_i::
createUpdateAllCommand(SMESH::log_array_var log, int * index)
{
MESSAGE("SMESH_Mesh_i::createUpdateAllCommand");
SMESH::log_array_var aLog=new SMESH::log_array(log->length()+4);
aLog->length(log->length()+4);
for(int i=0;i<*index;i++)
{
aLog[i]=log[i];
}
log->length(0);
int id=*index;
//Remove all elements
aLog[id].commandType=SMESH::REMOVE_ALL;
id++;
//Export nodes
aLog[id].commandType=SMESH::ADD_NODE;
aLog[id].number=_impl->GetMeshDS()->NbNodes();
double * nodesCoordinates=_impl->GetMeshDS()->getNodesCoordinates();
aLog[id].coords=SMESH::double_array(
aLog[id].number*3,
aLog[id].number*3,
nodesCoordinates);
long * nodesID=_impl->GetMeshDS()->getNodesID();
aLog[id].indexes=SMESH::long_array(
aLog[id].number,
aLog[id].number,
nodesID);
id++;
MESSAGE("Export edges");
//Export edges
aLog[id].commandType=SMESH::ADD_EDGE;
aLog[id].number=_impl->GetMeshDS()->NbEdges();
aLog[id].coords.length(0);
long * edgesIndices=_impl->GetMeshDS()->getEdgesIndices();
aLog[id].indexes=SMESH::long_array(
aLog[id].number*3,
aLog[id].number*3,
edgesIndices);
id++;
MESSAGE("Export triangles");
//Export triangles
aLog[id].commandType=SMESH::ADD_TRIANGLE;
aLog[id].number=_impl->GetMeshDS()->NbTriangles();
aLog[id].coords.length(0);
long * triasIndices=_impl->GetMeshDS()->getTrianglesIndices();
aLog[id].indexes=SMESH::long_array(
aLog[id].number*4,
aLog[id].number*4,
triasIndices);
(*index)+=4;
return aLog;
}
/**
* Return the log of the current mesh. CORBA wrap of the SMESH::GetLog method
* with a special treatment for SMESHDS_UpdateAll commands
* @param clearAfterGet Tell if the log must be cleared after being returned
* @return the log
*/
SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
throw(SALOME::SALOME_Exception)
throw(SALOME::SALOME_Exception)
{
MESSAGE("SMESH_Mesh_i::GetLog");
SMESH::log_array_var aLog;
try
{
/*try
{*/
list < SMESHDS_Command * >logDS = _impl->GetLog();
aLog = new SMESH::log_array;
int indexLog = 0;
int lg = logDS.size();
SCRUTE(lg);
MESSAGE("Number of command in the log: "<<lg);
aLog->length(lg);
list < SMESHDS_Command * >::iterator its = logDS.begin();
while (its != logDS.end())
@ -267,32 +339,38 @@ throw(SALOME::SALOME_Exception)
//SCRUTE(rnum);
list < double >::const_iterator ir = coordList.begin();
aLog[indexLog].commandType = comType;
aLog[indexLog].number = lgcom;
aLog[indexLog].coords.length(rnum);
aLog[indexLog].indexes.length(inum);
for (int i = 0; i < rnum; i++)
if(comType==SMESHDS_UpdateAll)
{
aLog[indexLog].coords[i] = *ir;
//MESSAGE(" "<<i<<" "<<ir.Value());
ir++;
aLog=createUpdateAllCommand(aLog, &indexLog);
}
for (int i = 0; i < inum; i++)
else
{
aLog[indexLog].indexes[i] = *ii;
//MESSAGE(" "<<i<<" "<<ii.Value());
ii++;
}
indexLog++;
aLog[indexLog].number = lgcom;
aLog[indexLog].coords.length(rnum);
aLog[indexLog].indexes.length(inum);
for (int i = 0; i < rnum; i++)
{
aLog[indexLog].coords[i] = *ir;
//MESSAGE(" "<<i<<" "<<ir.Value());
ir++;
}
for (int i = 0; i < inum; i++)
{
aLog[indexLog].indexes[i] = *ii;
//MESSAGE(" "<<i<<" "<<ii.Value());
ii++;
}
indexLog++;
}
its++;
}
if (clearAfterGet)
_impl->ClearLog();
}
if (clearAfterGet) _impl->ClearLog();
return aLog._retn();
/*}
catch(SALOME_Exception & S_ex)
{
THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
}
return aLog._retn();
}*/
}
// SMESH::string_array* SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)

View File

@ -138,7 +138,7 @@ public:
map<int, ::SMESH_subMesh*> _mapSubMesh; //NRI
private:
SMESH::log_array_var createUpdateAllCommand(SMESH::log_array_var log, int * index);
::SMESH_Mesh* _impl; // :: force no namespace here
SMESH_Gen_i* _gen_i;
// CORBA::ORB_ptr _orb;