1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_Mesh_i.cxx
25 // Author : Paul RASCLE, EDF
30 #include "SMESH_Mesh_i.hxx"
31 #include "SMESH_subMesh_i.hxx"
32 #include "SMESH_MEDMesh_i.hxx"
33 #include "SMESH_Group_i.hxx"
35 #include "Utils_CorbaException.hxx"
36 #include "Utils_ExceptHandlers.hxx"
37 #include "utilities.h"
39 #include "SALOME_NamingService.hxx"
40 #include "Utils_SINGLETON.hxx"
43 #include "TCollection_AsciiString.hxx"
44 #include "SMESHDS_Command.hxx"
45 #include "SMESHDS_CommandType.hxx"
46 #include "SMESH_MeshEditor_i.hxx"
47 #include "SMESH_Gen_i.hxx"
48 #include "DriverMED_R_SMESHDS_Mesh.h"
52 // _CS_gbo_050504 Ajout explicite du sstream pour ostringstream
56 //**** SMESHDS en champ
58 int SMESH_Mesh_i::myIdGenerator = 0;
60 //=============================================================================
64 //=============================================================================
66 SMESH_Mesh_i::SMESH_Mesh_i()
67 : SALOME::GenericObj_i( PortableServer::POA::_nil() )
69 MESSAGE("SMESH_Mesh_i: default constructor, not for use");
73 //=============================================================================
77 //=============================================================================
79 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
82 : SALOME::GenericObj_i( thePOA )
84 MESSAGE("SMESH_Mesh_i");
86 _id = myIdGenerator++;
88 thePOA->activate_object( this );
91 SMESH_Mesh_i::SMESH_Mesh_i(SMESH_Gen_i* gen_i,
95 MESSAGE("SMESH_Mesh_i");
101 //=============================================================================
105 //=============================================================================
107 SMESH_Mesh_i::~SMESH_Mesh_i()
109 MESSAGE("~SMESH_Mesh_i");
110 map<int, SMESH::SMESH_Group_ptr>::iterator it;
111 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
112 SMESH_Group_i* aGroup = dynamic_cast<SMESH_Group_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
114 _impl->RemoveGroup( aGroup->GetLocalID() );
121 //=============================================================================
125 * Associates <this> mesh with <theShape> and puts a reference
126 * to <theShape> into the current study;
127 * the previous shape is substituted by the new one.
129 //=============================================================================
131 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Shape_ptr theShape )
132 throw (SALOME::SALOME_Exception)
134 Unexpect aCatch(SALOME_SalomeException);
136 setShape( theShape );
138 catch(SALOME_Exception & S_ex) {
139 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
142 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
143 if ( aStudy->_is_nil() )
146 // Create a reference to <theShape>
147 SALOMEDS::SObject_var aMeshSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( _this() ) ) ) );
148 SALOMEDS::SObject_var aShapeSO = aStudy->FindObjectIOR( SMESH_Gen_i::GetORB()->object_to_string( theShape ) );
150 SALOMEDS::SObject_var anObj, aRef;
151 SALOMEDS::GenericAttribute_var anAttr;
152 SALOMEDS::AttributeIOR_var anIOR;
153 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
154 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
156 if ( aMeshSO->FindSubObject( aTag, anObj ) ) {
157 if ( anObj->ReferencedObject( aRef ) ) {
158 if ( strcmp( aRef->GetID(), aShapeSO->GetID() ) == 0 ) {
159 // Setting the same shape twice forbidden
165 anObj = aBuilder->NewObjectToTag( aMeshSO, aTag );
167 aBuilder->Addreference( anObj, aShapeSO );
170 //=============================================================================
174 * Sets shape to the mesh implementation
176 //=============================================================================
178 bool SMESH_Mesh_i::setShape( GEOM::GEOM_Shape_ptr theShape )
180 TopoDS_Shape aLocShape = _gen_i->GetShapeReader()->GetShape( SMESH_Gen_i::GetGeomEngine(), theShape );
181 _impl->ShapeToMesh( aLocShape );
185 //=============================================================================
189 //=============================================================================
191 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
193 SMESH::DriverMED_ReadStatus res;
196 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
197 res = SMESH::DRS_OK; break;
198 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
199 res = SMESH::DRS_EMPTY; break;
200 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
201 res = SMESH::DRS_WARN_RENUMBER; break;
202 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
203 res = SMESH::DRS_WARN_SKIP_ELEM; break;
204 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
206 res = SMESH::DRS_FAIL; break;
211 //=============================================================================
215 * Imports mesh data from MED file
217 //=============================================================================
219 SMESH::DriverMED_ReadStatus
220 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
221 throw ( SALOME::SALOME_Exception )
223 Unexpect aCatch(SALOME_SalomeException);
226 status = importMEDFile( theFileName, theMeshName );
228 catch( SALOME_Exception& S_ex ) {
229 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
232 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
235 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
236 if ( aStudy->_is_nil() )
237 return ConvertDriverMEDReadStatus(status);
239 // publishing of the groups in the study (sub-meshes are out of scope of MED import)
240 map<int, SMESH::SMESH_Group_ptr>::iterator it = _mapGroups.begin();
241 for (; it != _mapGroups.end(); it++ ) {
242 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_duplicate( it->second );
243 if ( _gen_i->CanPublishInStudy( aGroup ) )
244 _gen_i->PublishInStudy( aStudy,
245 SALOMEDS::SObject::_nil(),
249 return ConvertDriverMEDReadStatus(status);
252 //=============================================================================
256 * Imports mesh data from MED file
258 //=============================================================================
260 int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
262 // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
263 int status = _impl->MEDToMesh( theFileName, theMeshName );
265 // Create group servants, if any groups were imported
266 list<int> aGroupIds = _impl->GetGroupIds();
267 for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
268 SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
269 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
270 _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup );
272 // register CORBA object for persistence
273 StudyContext* myStudyContext = _gen_i->GetCurrentStudyContext();
274 string iorString = SMESH_Gen_i::GetORB()->object_to_string( aGroup );
275 int nextId = myStudyContext->addObject( iorString );
276 MESSAGE( "Add group to map with id = "<< nextId << " and IOR = " << iorString.c_str() );
282 //=============================================================================
286 //=============================================================================
288 static SMESH::Hypothesis_Status ConvertHypothesisStatus
289 (SMESH_Hypothesis::Hypothesis_Status theStatus)
291 SMESH::Hypothesis_Status res;
294 case SMESH_Hypothesis::HYP_OK:
295 res = SMESH::HYP_OK; break;
296 case SMESH_Hypothesis::HYP_MISSING:
297 res = SMESH::HYP_MISSING; break;
298 case SMESH_Hypothesis::HYP_CONCURENT:
299 res = SMESH::HYP_CONCURENT; break;
300 case SMESH_Hypothesis::HYP_BAD_PARAMETER:
301 res = SMESH::HYP_BAD_PARAMETER; break;
302 case SMESH_Hypothesis::HYP_INCOMPATIBLE:
303 res = SMESH::HYP_INCOMPATIBLE; break;
304 case SMESH_Hypothesis::HYP_NOTCONFORM:
305 res = SMESH::HYP_NOTCONFORM; break;
306 case SMESH_Hypothesis::HYP_ALREADY_EXIST:
307 res = SMESH::HYP_ALREADY_EXIST; break;
308 case SMESH_Hypothesis::HYP_BAD_DIM:
309 res = SMESH::HYP_BAD_DIM; break;
311 res = SMESH::HYP_UNKNOWN_FATAL;
316 //=============================================================================
320 * calls internal addHypothesis() and then adds a reference to <anHyp> under
321 * the SObject actually having a reference to <aSubShape>.
322 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
324 //=============================================================================
326 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
327 SMESH::SMESH_Hypothesis_ptr anHyp)
328 throw(SALOME::SALOME_Exception)
330 Unexpect aCatch(SALOME_SalomeException);
331 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShape, anHyp );
333 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
334 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
336 if ( !aStudy->_is_nil() ) {
337 // Detect whether <aSubShape> refers to this mesh or its sub-mesh
338 SALOMEDS::GenericAttribute_var anAttr;
339 SALOMEDS::AttributeIOR_var anIOR;
340 SALOMEDS::SObject_var aMeshSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( _this() ) ) ) );
341 SALOMEDS::SObject_var aMorSM, aRef;
342 CORBA::String_var aShapeIOR = CORBA::string_dup( SMESH_Gen_i::GetORB()->object_to_string( aSubShape ) );
343 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator( aMeshSO );
345 for ( it->InitEx( true ); it->More(); it->Next() ) {
346 SALOMEDS::SObject_var anObj = it->Value();
347 if ( anObj->ReferencedObject( aRef ) ) {
348 if ( aRef->FindAttribute( anAttr, "AttributeIOR" ) ) {
349 anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
350 if ( strcmp( anIOR->Value(), aShapeIOR ) == 0 ) {
351 aMorSM = anObj->GetFather();
358 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( anHyp )->_is_nil();
359 SALOMEDS::SObject_var aHypSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( anHyp ) ) ) );
360 if ( !aMorSM->_is_nil() && !aHypSO->_is_nil() ) {
361 //Find or Create Applied Hypothesis root
362 SALOMEDS::SObject_var AHR;
363 SALOMEDS::AttributeName_var aName;
364 SALOMEDS::AttributeSelectable_var aSelAttr;
365 SALOMEDS::AttributePixMap_var aPixmap;
366 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
367 long aTag = aIsAlgo ? SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag() : SMESH_Gen_i::GetRefOnAppliedHypothesisTag();
369 if ( !aMorSM->FindSubObject( aTag, AHR ) ) {
370 AHR = aBuilder->NewObjectToTag( aMorSM, aTag );
371 anAttr = aBuilder->FindOrCreateAttribute( AHR, "AttributeName" );
372 aName = SALOMEDS::AttributeName::_narrow( anAttr );
373 aName ->SetValue( aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
374 anAttr = aBuilder->FindOrCreateAttribute( AHR, "AttributeSelectable" );
375 aSelAttr = SALOMEDS::AttributeSelectable::_narrow( anAttr );
376 aSelAttr ->SetSelectable( false );
377 anAttr = aBuilder->FindOrCreateAttribute( AHR, "AttributePixMap" );
378 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
379 aPixmap ->SetPixMap( aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO" );
382 SALOMEDS::SObject_var SO = aBuilder->NewObject( AHR );
383 aBuilder->Addreference( SO, aHypSO );
388 return ConvertHypothesisStatus(status);
391 //=============================================================================
395 //=============================================================================
397 SMESH_Hypothesis::Hypothesis_Status
398 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
399 SMESH::SMESH_Hypothesis_ptr anHyp)
401 MESSAGE("addHypothesis");
402 // **** proposer liste de subShape (selection multiple)
404 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
405 if (CORBA::is_nil(mySubShape))
406 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
409 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
410 if (CORBA::is_nil(myHyp))
411 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
414 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
417 TopoDS_Shape myLocSubShape =
418 _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), mySubShape);
419 int hypId = myHyp->GetId();
420 status = _impl->AddHypothesis(myLocSubShape, hypId);
421 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
422 _mapHypo[hypId] = myHyp;
424 catch(SALOME_Exception & S_ex)
426 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
431 //=============================================================================
435 //=============================================================================
437 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
438 SMESH::SMESH_Hypothesis_ptr anHyp)
439 throw(SALOME::SALOME_Exception)
441 Unexpect aCatch(SALOME_SalomeException);
442 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShape, anHyp );
444 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
445 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
447 if ( !aStudy->_is_nil() ) {
448 // Detect whether <aSubShape> refers to this mesh or its sub-mesh
449 SALOMEDS::GenericAttribute_var anAttr;
450 SALOMEDS::AttributeIOR_var anIOR;
451 SALOMEDS::SObject_var aMeshSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( _this() ) ) ) );
452 if ( aMeshSO->_is_nil() )
453 return SMESH::HYP_UNKNOWN_FATAL;
455 SALOMEDS::SObject_var aMorSM, aRef;
456 CORBA::String_var aShapeIOR = CORBA::string_dup( SMESH_Gen_i::GetORB()->object_to_string( aSubShape ) );
457 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator( aMeshSO );
459 for ( it->InitEx( true ); it->More(); it->Next() ) {
460 SALOMEDS::SObject_var anObj = it->Value();
461 if ( anObj->ReferencedObject( aRef ) ) {
462 if ( aRef->FindAttribute( anAttr, "AttributeIOR" ) ) {
463 anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
464 if ( strcmp( anIOR->Value(), aShapeIOR ) == 0 ) {
465 aMorSM = anObj->GetFather();
472 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( anHyp )->_is_nil();
473 SALOMEDS::SObject_var aHypSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( anHyp ) ) ) );
474 if ( !aMorSM->_is_nil() && !aHypSO->_is_nil() ) {
475 // Remove a refernce to hypothesis or algorithm
476 SALOMEDS::SObject_var AHR;
477 SALOMEDS::AttributeName_var aName;
478 SALOMEDS::AttributeSelectable_var aSelAttr;
479 SALOMEDS::AttributePixMap_var aPixmap;
480 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
481 CORBA::String_var aHypIOR = CORBA::string_dup( SMESH_Gen_i::GetORB()->object_to_string( anHyp ) );
482 long aTag = aIsAlgo ? SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag() : SMESH_Gen_i::GetRefOnAppliedHypothesisTag();
484 if ( aMorSM->FindSubObject( aTag, AHR ) ) {
485 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator( AHR );
486 for ( ; it->More(); it->Next() ) {
487 SALOMEDS::SObject_var anObj = it->Value();
488 if ( anObj->ReferencedObject( aRef ) ) {
489 if ( aRef->FindAttribute( anAttr, "AttributeIOR" ) ) {
490 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
491 if ( strcmp( anIOR->Value(), aHypIOR ) == 0 ) {
492 aBuilder->RemoveObject( anObj );
503 return ConvertHypothesisStatus(status);
507 //=============================================================================
511 //=============================================================================
513 SMESH_Hypothesis::Hypothesis_Status
514 SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
515 SMESH::SMESH_Hypothesis_ptr anHyp)
517 MESSAGE("removeHypothesis()");
518 // **** proposer liste de subShape (selection multiple)
520 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
521 if (CORBA::is_nil(mySubShape))
522 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
525 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
526 if (CORBA::is_nil(myHyp))
527 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
530 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
533 TopoDS_Shape myLocSubShape =
534 _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), mySubShape);
535 int hypId = myHyp->GetId();
536 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
537 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
538 _mapHypo.erase( hypId );
540 catch(SALOME_Exception & S_ex)
542 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
547 //=============================================================================
551 //=============================================================================
553 SMESH::ListOfHypothesis *
554 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Shape_ptr aSubShape)
555 throw(SALOME::SALOME_Exception)
557 Unexpect aCatch(SALOME_SalomeException);
558 MESSAGE("GetHypothesisList");
559 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
560 if (CORBA::is_nil(mySubShape))
561 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
564 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
567 TopoDS_Shape myLocSubShape
568 = _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), mySubShape);
570 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
571 int i = 0, n = aLocalList.size();
574 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
575 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
576 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
577 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
582 catch(SALOME_Exception & S_ex) {
583 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
586 return aList._retn();
589 //=============================================================================
593 //=============================================================================
594 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Shape_ptr aSubShape,
595 const char* theName )
596 throw(SALOME::SALOME_Exception)
598 Unexpect aCatch(SALOME_SalomeException);
599 MESSAGE("SMESH_Mesh_i::GetElementsOnShape");
600 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
601 if (CORBA::is_nil(mySubShape))
602 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
607 TopoDS_Shape myLocSubShape
608 = _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), mySubShape);
610 //Get or Create the SMESH_subMesh object implementation
612 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
613 subMeshId = mySubMesh->GetId();
615 // create a new subMesh object servant if there is none for the shape
617 if (_mapSubMesh.find(subMeshId) == _mapSubMesh.end()) {
618 SMESH::SMESH_subMesh_var subMesh = createSubMesh( aSubShape );
619 if ( _gen_i->CanPublishInStudy( subMesh ) ) {
620 SALOMEDS::SObject_var aSubmeshSO = _gen_i->PublishInStudy( _gen_i->GetCurrentStudy(),
621 SALOMEDS::SObject::_nil(),
625 // Add reference to <aSubShape> to the study
626 SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
627 SALOMEDS::SObject_var aShapeSO = aStudy->FindObjectIOR( SMESH_Gen_i::GetORB()->object_to_string( aSubShape ) );
628 if ( !aSubmeshSO->_is_nil() && !aShapeSO->_is_nil() ) {
629 MESSAGE( "********** SMESH_Mesh_i::GetSubMesh(): adding shape reference..." )
630 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
631 SALOMEDS::SObject_var SO = aBuilder->NewObjectToTag( aSubmeshSO, SMESH_Gen_i::GetRefOnShapeTag() );
632 aBuilder->Addreference( SO, aShapeSO );
633 MESSAGE( "********** SMESH_Mesh_i::GetSubMesh(): shape reference added" )
638 catch(SALOME_Exception & S_ex) {
639 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
642 ASSERT(_mapSubMeshIor.find(subMeshId) != _mapSubMeshIor.end());
643 return SMESH::SMESH_subMesh::_duplicate(_mapSubMeshIor[subMeshId]);
647 //=============================================================================
651 //=============================================================================
653 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
654 throw (SALOME::SALOME_Exception)
656 MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
657 if ( theSubMesh->_is_nil() )
660 GEOM::GEOM_Shape_var aSubShape;
661 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
662 if ( !aStudy->_is_nil() ) {
663 // Remove submesh's SObject
664 SALOMEDS::SObject_var anSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( theSubMesh ) ) ) );
665 if ( !anSO->_is_nil() ) {
666 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
667 SALOMEDS::SObject_var anObj, aRef;
668 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
669 aSubShape = GEOM::GEOM_Shape::_narrow( aRef->GetObject() );
671 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
675 removeSubMesh( theSubMesh, aSubShape.in() );
679 //=============================================================================
683 //=============================================================================
685 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
686 const char* theName )
687 throw(SALOME::SALOME_Exception)
689 Unexpect aCatch(SALOME_SalomeException);
690 SMESH::SMESH_Group_var aNewGroup = createGroup( theElemType, theName );
692 // Groups should be put under separate roots according to their type (nodes, edges, faces, volumes)
693 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
694 SALOMEDS::SObject_var aGroupSO = _gen_i->PublishInStudy( _gen_i->GetCurrentStudy(),
695 SALOMEDS::SObject::_nil(),
700 return aNewGroup._retn();
704 //=============================================================================
708 //=============================================================================
710 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_Group_ptr theGroup )
711 throw (SALOME::SALOME_Exception)
713 if ( theGroup->_is_nil() )
716 SMESH_Group_i* aGroup = dynamic_cast<SMESH_Group_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
720 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
721 if ( !aStudy->_is_nil() ) {
722 // Remove group's SObject
723 SALOMEDS::SObject_var aGroupSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( theGroup ) ) ) );
724 if ( !aGroupSO->_is_nil() )
725 aStudy->NewBuilder()->RemoveObject( aGroupSO );
728 // Remove the group from SMESH data structures
729 removeGroup( aGroup->GetLocalID() );
733 //=============================================================================
737 //=============================================================================
739 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Shape_ptr theSubShape ) {
741 TopoDS_Shape myLocSubShape = _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), theSubShape);
743 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
744 int subMeshId = mySubMesh->GetId();
745 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
746 SMESH::SMESH_subMesh_var subMesh
747 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
749 _mapSubMesh[subMeshId] = mySubMesh;
750 _mapSubMesh_i[subMeshId] = subMeshServant;
751 _mapSubMeshIor[subMeshId]
752 = SMESH::SMESH_subMesh::_duplicate(subMesh);
754 // register CORBA object for persistence
755 StudyContext* myStudyContext = _gen_i->GetCurrentStudyContext();
756 string iorString = SMESH_Gen_i::GetORB()->object_to_string( subMesh );
757 int nextId = myStudyContext->addObject( iorString );
758 MESSAGE( "Add submesh to map with id = "<< nextId << " and IOR = " << iorString.c_str() );
760 return subMesh._retn();
764 //=============================================================================
768 //=============================================================================
770 void SMESH_Mesh_i::removeSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh, GEOM::GEOM_Shape_ptr theSubShape )
772 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
773 if ( theSubMesh->_is_nil() || theSubShape->_is_nil() )
777 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShape );
778 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
779 removeHypothesis( theSubShape, aHypList[i] );
782 catch( const SALOME::SALOME_Exception& ) {
783 MESSAGE("SMESH_Mesh_i::removeSubMesh(): exception caught!");
786 int subMeshId = theSubMesh->GetId();
788 _mapSubMesh.erase(subMeshId);
789 _mapSubMesh_i.erase(subMeshId);
790 _mapSubMeshIor.erase(subMeshId);
791 MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
794 //=============================================================================
798 //=============================================================================
800 SMESH::SMESH_Group_ptr SMESH_Mesh_i::createGroup( SMESH::ElementType theElemType, const char* theName )
803 SMESH::SMESH_Group_var aGroup;
804 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId ) ) {
805 SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
806 aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
807 _mapGroups[anId] = SMESH::SMESH_Group::_duplicate( aGroup );
809 // register CORBA object for persistence
810 StudyContext* myStudyContext = _gen_i->GetCurrentStudyContext();
811 string iorString = SMESH_Gen_i::GetORB()->object_to_string( aGroup );
812 int nextId = myStudyContext->addObject( iorString );
813 MESSAGE( "Add group to map with id = "<< nextId << " and IOR = " << iorString.c_str() );
815 return aGroup._retn();
819 //=============================================================================
821 * SMESH_Mesh_i::removeGroup
823 * Should be called by ~SMESH_Group_i()
825 //=============================================================================
827 void SMESH_Mesh_i::removeGroup( const int theId )
829 MESSAGE("SMESH_Mesh_i::removeGroup()" );
830 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
831 _mapGroups.erase( theId );
832 _impl->RemoveGroup( theId );
837 //=============================================================================
841 //=============================================================================
843 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
844 throw(SALOME::SALOME_Exception)
846 MESSAGE("SMESH_Mesh_i::GetLog");
848 SMESH::log_array_var aLog;
851 list < SMESHDS_Command * >logDS = _impl->GetLog();
852 aLog = new SMESH::log_array;
854 int lg = logDS.size();
857 list < SMESHDS_Command * >::iterator its = logDS.begin();
858 while (its != logDS.end())
860 SMESHDS_Command *com = *its;
861 int comType = com->GetType();
863 int lgcom = com->GetNumber();
865 const list < int >&intList = com->GetIndexes();
866 int inum = intList.size();
868 list < int >::const_iterator ii = intList.begin();
869 const list < double >&coordList = com->GetCoords();
870 int rnum = coordList.size();
872 list < double >::const_iterator ir = coordList.begin();
873 aLog[indexLog].commandType = comType;
874 aLog[indexLog].number = lgcom;
875 aLog[indexLog].coords.length(rnum);
876 aLog[indexLog].indexes.length(inum);
877 for (int i = 0; i < rnum; i++)
879 aLog[indexLog].coords[i] = *ir;
880 //MESSAGE(" "<<i<<" "<<ir.Value());
883 for (int i = 0; i < inum; i++)
885 aLog[indexLog].indexes[i] = *ii;
886 //MESSAGE(" "<<i<<" "<<ii.Value());
895 catch(SALOME_Exception & S_ex)
897 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
902 // SMESH::string_array* SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
903 // throw (SALOME::SALOME_Exception)
905 // MESSAGE("SMESH_Mesh_i::GetLog");
907 // SMESH::string_array_var aLog;
910 // const SMESHDS_ListOfCommand& logDS =_impl->GetLog();
911 // aLog = new SMESH::string_array;
914 // int lg = logDS.Extent();
916 // SMESHDS_ListIteratorOfListOfCommand its(logDS);
919 // Handle(SMESHDS_Command) com = its.Value();
920 // int comType = com->GetType();
922 // int lgcom = com->GetNumber();
925 // aLog->length(logSize);
927 // const TColStd_ListOfInteger& intList = com->GetIndexes();
928 // TColStd_ListIteratorOfListOfInteger ii(intList);
929 // const TColStd_ListOfReal& coordList = com->GetCoords();
930 // TColStd_ListIteratorOfListOfReal ir(coordList);
931 // for (int icom = 1; icom <= lgcom; icom++)
936 // case SMESHDS_AddNode:
937 // S << "AddNode " << ii.Value(); ii.Next();
938 // S << " " << ir.Value(); ir.Next();
939 // S << " " << ir.Value(); ir.Next();
940 // S << " " << ir.Value(); ir.Next();
942 // case SMESHDS_AddEdge:
943 // S << "AddEdge " << ii.Value(); ii.Next();
944 // S << " " << ii.Value(); ii.Next();
945 // S << " " << ii.Value(); ii.Next();
947 // case SMESHDS_AddTriangle:
948 // S << "AddFace " << ii.Value(); ii.Next();
949 // S << " " << ii.Value(); ii.Next();
950 // S << " " << ii.Value(); ii.Next();
951 // S << " " << ii.Value(); ii.Next();
953 // case SMESHDS_AddQuadrangle:
954 // S << "AddFace " << ii.Value(); ii.Next();
955 // S << " " << ii.Value(); ii.Next();
956 // S << " " << ii.Value(); ii.Next();
957 // S << " " << ii.Value(); ii.Next();
958 // S << " " << ii.Value(); ii.Next();
960 // case SMESHDS_AddTetrahedron:
961 // S << "AddVolume " << ii.Value(); ii.Next();
962 // S << " " << ii.Value(); ii.Next();
963 // S << " " << ii.Value(); ii.Next();
964 // S << " " << ii.Value(); ii.Next();
965 // S << " " << ii.Value(); ii.Next();
967 // case SMESHDS_AddPyramid:
968 // S << "AddVolume " << ii.Value(); ii.Next();
969 // S << " " << ii.Value(); ii.Next();
970 // S << " " << ii.Value(); ii.Next();
971 // S << " " << ii.Value(); ii.Next();
972 // S << " " << ii.Value(); ii.Next();
973 // S << " " << ii.Value(); ii.Next();
975 // case SMESHDS_AddPrism:
976 // S << "AddVolume " << ii.Value(); ii.Next();
977 // S << " " << ii.Value(); ii.Next();
978 // S << " " << ii.Value(); ii.Next();
979 // S << " " << ii.Value(); ii.Next();
980 // S << " " << ii.Value(); ii.Next();
981 // S << " " << ii.Value(); ii.Next();
982 // S << " " << ii.Value(); ii.Next();
984 // case SMESHDS_AddHexahedron:
985 // S << "AddVolume " << ii.Value(); ii.Next();
986 // S << " " << ii.Value(); ii.Next();
987 // S << " " << ii.Value(); ii.Next();
988 // S << " " << ii.Value(); ii.Next();
989 // S << " " << ii.Value(); ii.Next();
990 // S << " " << ii.Value(); ii.Next();
991 // S << " " << ii.Value(); ii.Next();
992 // S << " " << ii.Value(); ii.Next();
993 // S << " " << ii.Value(); ii.Next();
995 // case SMESHDS_RemoveNode:
996 // S << "RemoveNode " << ii.Value(); ii.Next();
998 // case SMESHDS_RemoveElement:
999 // S << "RemoveElement " << ii.Value(); ii.Next();
1005 // string ch = S.str();
1007 // aLog[indexLog++] = CORBA::string_dup(ch.c_str());
1011 // if (clearAfterGet) _impl->ClearLog();
1013 // catch (SALOME_Exception& S_ex)
1015 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1017 // return aLog._retn();
1020 //=============================================================================
1024 //=============================================================================
1026 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1028 MESSAGE("SMESH_Mesh_i::ClearLog");
1032 //=============================================================================
1036 //=============================================================================
1038 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1040 MESSAGE("SMESH_Mesh_i::GetId");
1044 //=============================================================================
1048 //=============================================================================
1050 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1055 //=============================================================================
1059 //=============================================================================
1061 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1063 MESSAGE("SMESH_Mesh_i::SetImpl");
1067 //=============================================================================
1071 //=============================================================================
1073 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1075 MESSAGE("SMESH_Mesh_i::GetImpl()");
1080 //=============================================================================
1084 //=============================================================================
1086 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1088 SMESH_MeshEditor_i *aMeshEditor =
1089 new SMESH_MeshEditor_i(_impl->GetMeshDS());
1090 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1091 return aMesh._retn();
1094 //=============================================================================
1098 //=============================================================================
1100 void SMESH_Mesh_i::ExportMED(const char *file, CORBA::Boolean auto_groups) throw(SALOME::SALOME_Exception)
1102 Unexpect aCatch(SALOME_SalomeException);
1103 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1104 if ( aStudy->_is_nil() )
1107 char* aMeshName = NULL;
1108 SALOMEDS::SObject_var aMeshSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( _this() ) ) ) );
1109 if ( !aMeshSO->_is_nil() )
1111 aMeshName = aMeshSO->GetName();
1113 //SCRUTE(aMeshName);
1114 //SCRUTE(aMeshSO->GetID());
1115 SALOMEDS::GenericAttribute_var anAttr;
1116 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1117 SALOMEDS::AttributeExternalFileDef_var aFileName;
1118 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1119 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1120 ASSERT(!aFileName->_is_nil());
1121 aFileName->SetValue(file);
1122 SALOMEDS::AttributeFileType_var aFileType;
1123 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1124 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1125 ASSERT(!aFileType->_is_nil());
1126 aFileType->SetValue("FICHIERMED");
1128 _impl->ExportMED( file, aMeshName, auto_groups );
1131 void SMESH_Mesh_i::ExportDAT(const char *file) throw(SALOME::SALOME_Exception)
1133 Unexpect aCatch(SALOME_SalomeException);
1134 _impl->ExportDAT(file);
1136 void SMESH_Mesh_i::ExportUNV(const char *file) throw(SALOME::SALOME_Exception)
1138 Unexpect aCatch(SALOME_SalomeException);
1139 _impl->ExportUNV(file);
1142 //=============================================================================
1146 //=============================================================================
1148 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1150 Unexpect aCatch(SALOME_SalomeException);
1151 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1152 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1153 return aMesh._retn();
1156 //=============================================================================
1160 //=============================================================================
1161 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1163 Unexpect aCatch(SALOME_SalomeException);
1164 return _impl->NbNodes();
1167 //=============================================================================
1171 //=============================================================================
1172 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1174 Unexpect aCatch(SALOME_SalomeException);
1175 return _impl->NbEdges();
1178 //=============================================================================
1182 //=============================================================================
1183 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1185 Unexpect aCatch(SALOME_SalomeException);
1186 return _impl->NbFaces();
1189 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1191 Unexpect aCatch(SALOME_SalomeException);
1192 return _impl->NbTriangles();
1195 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1197 Unexpect aCatch(SALOME_SalomeException);
1198 return _impl->NbQuadrangles();
1201 //=============================================================================
1205 //=============================================================================
1206 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1208 Unexpect aCatch(SALOME_SalomeException);
1209 return _impl->NbVolumes();
1212 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1214 Unexpect aCatch(SALOME_SalomeException);
1215 return _impl->NbTetras();
1218 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1220 Unexpect aCatch(SALOME_SalomeException);
1221 return _impl->NbHexas();
1224 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1226 Unexpect aCatch(SALOME_SalomeException);
1227 return _impl->NbPyramids();
1230 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1232 Unexpect aCatch(SALOME_SalomeException);
1233 return _impl->NbPrisms();
1236 //=============================================================================
1240 //=============================================================================
1241 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1243 Unexpect aCatch(SALOME_SalomeException);
1244 return _impl->NbSubMesh();
1247 //=============================================================================
1251 //=============================================================================
1252 char* SMESH_Mesh_i::Dump()
1254 std::ostringstream os;
1256 return CORBA::string_dup( os.str().c_str() );