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"
54 //**** SMESHDS en champ
56 int SMESH_Mesh_i::myIdGenerator = 0;
58 //=============================================================================
62 //=============================================================================
64 SMESH_Mesh_i::SMESH_Mesh_i()
65 : SALOME::GenericObj_i( PortableServer::POA::_nil() )
67 MESSAGE("SMESH_Mesh_i: default constructor, not for use");
71 //=============================================================================
75 //=============================================================================
77 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
80 : SALOME::GenericObj_i( thePOA )
82 MESSAGE("SMESH_Mesh_i");
84 _id = myIdGenerator++;
86 thePOA->activate_object( this );
89 SMESH_Mesh_i::SMESH_Mesh_i(SMESH_Gen_i* gen_i,
93 MESSAGE("SMESH_Mesh_i");
99 //=============================================================================
103 //=============================================================================
105 SMESH_Mesh_i::~SMESH_Mesh_i()
107 MESSAGE("~SMESH_Mesh_i");
108 map<int, SMESH::SMESH_Group_ptr>::iterator it;
109 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
110 SMESH_Group_i* aGroup = dynamic_cast<SMESH_Group_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
112 _impl->RemoveGroup( aGroup->GetLocalID() );
119 //=============================================================================
123 * Associates <this> mesh with <theShape> and puts a reference
124 * to <theShape> into the current study;
125 * the previous shape is substituted by the new one.
127 //=============================================================================
129 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Shape_ptr theShape )
130 throw (SALOME::SALOME_Exception)
132 Unexpect aCatch(SALOME_SalomeException);
134 setShape( theShape );
136 catch(SALOME_Exception & S_ex) {
137 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
140 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
141 if ( aStudy->_is_nil() )
144 // Create a reference to <theShape>
145 SALOMEDS::SObject_var aMeshSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( _this() ) ) ) );
146 SALOMEDS::SObject_var aShapeSO = aStudy->FindObjectIOR( SMESH_Gen_i::GetORB()->object_to_string( theShape ) );
148 SALOMEDS::SObject_var anObj, aRef;
149 SALOMEDS::GenericAttribute_var anAttr;
150 SALOMEDS::AttributeIOR_var anIOR;
151 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
152 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
154 if ( aMeshSO->FindSubObject( aTag, anObj ) ) {
155 if ( anObj->ReferencedObject( aRef ) ) {
156 if ( strcmp( aRef->GetID(), aShapeSO->GetID() ) == 0 ) {
157 // Setting the same shape twice forbidden
163 anObj = aBuilder->NewObjectToTag( aMeshSO, aTag );
165 aBuilder->Addreference( anObj, aShapeSO );
168 //=============================================================================
172 * Sets shape to the mesh implementation
174 //=============================================================================
176 bool SMESH_Mesh_i::setShape( GEOM::GEOM_Shape_ptr theShape )
178 TopoDS_Shape aLocShape = _gen_i->GetShapeReader()->GetShape( SMESH_Gen_i::GetGeomEngine(), theShape );
179 _impl->ShapeToMesh( aLocShape );
183 //=============================================================================
187 //=============================================================================
189 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
191 SMESH::DriverMED_ReadStatus res;
194 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
195 res = SMESH::DRS_OK; break;
196 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
197 res = SMESH::DRS_EMPTY; break;
198 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
199 res = SMESH::DRS_WARN_RENUMBER; break;
200 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
201 res = SMESH::DRS_WARN_SKIP_ELEM; break;
202 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
204 res = SMESH::DRS_FAIL; break;
209 //=============================================================================
213 * Imports mesh data from MED file
215 //=============================================================================
217 SMESH::DriverMED_ReadStatus
218 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
219 throw ( SALOME::SALOME_Exception )
221 Unexpect aCatch(SALOME_SalomeException);
224 status = importMEDFile( theFileName, theMeshName );
226 catch( SALOME_Exception& S_ex ) {
227 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
230 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
233 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
234 if ( aStudy->_is_nil() )
235 return ConvertDriverMEDReadStatus(status);
237 // publishing of the groups in the study (sub-meshes are out of scope of MED import)
238 map<int, SMESH::SMESH_Group_ptr>::iterator it = _mapGroups.begin();
239 for (; it != _mapGroups.end(); it++ ) {
240 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_duplicate( it->second );
241 if ( _gen_i->CanPublishInStudy( aGroup ) )
242 _gen_i->PublishInStudy( aStudy,
243 SALOMEDS::SObject::_nil(),
247 return ConvertDriverMEDReadStatus(status);
250 //=============================================================================
254 * Imports mesh data from MED file
256 //=============================================================================
258 int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
260 // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
261 int status = _impl->MEDToMesh( theFileName, theMeshName );
263 // Create group servants, if any groups were imported
264 list<int> aGroupIds = _impl->GetGroupIds();
265 for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
266 SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
267 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
268 _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup );
270 // register CORBA object for persistence
271 StudyContext* myStudyContext = _gen_i->GetCurrentStudyContext();
272 string iorString = SMESH_Gen_i::GetORB()->object_to_string( aGroup );
273 int nextId = myStudyContext->addObject( iorString );
274 MESSAGE( "Add group to map with id = "<< nextId << " and IOR = " << iorString.c_str() );
280 //=============================================================================
284 //=============================================================================
286 static SMESH::Hypothesis_Status ConvertHypothesisStatus
287 (SMESH_Hypothesis::Hypothesis_Status theStatus)
289 SMESH::Hypothesis_Status res;
292 case SMESH_Hypothesis::HYP_OK:
293 res = SMESH::HYP_OK; break;
294 case SMESH_Hypothesis::HYP_MISSING:
295 res = SMESH::HYP_MISSING; break;
296 case SMESH_Hypothesis::HYP_CONCURENT:
297 res = SMESH::HYP_CONCURENT; break;
298 case SMESH_Hypothesis::HYP_BAD_PARAMETER:
299 res = SMESH::HYP_BAD_PARAMETER; break;
300 case SMESH_Hypothesis::HYP_INCOMPATIBLE:
301 res = SMESH::HYP_INCOMPATIBLE; break;
302 case SMESH_Hypothesis::HYP_NOTCONFORM:
303 res = SMESH::HYP_NOTCONFORM; break;
304 case SMESH_Hypothesis::HYP_ALREADY_EXIST:
305 res = SMESH::HYP_ALREADY_EXIST; break;
306 case SMESH_Hypothesis::HYP_BAD_DIM:
307 res = SMESH::HYP_BAD_DIM; break;
309 res = SMESH::HYP_UNKNOWN_FATAL;
314 //=============================================================================
318 * calls internal addHypothesis() and then adds a reference to <anHyp> under
319 * the SObject actually having a reference to <aSubShape>.
320 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
322 //=============================================================================
324 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
325 SMESH::SMESH_Hypothesis_ptr anHyp)
326 throw(SALOME::SALOME_Exception)
328 Unexpect aCatch(SALOME_SalomeException);
329 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShape, anHyp );
331 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
332 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
334 if ( !aStudy->_is_nil() ) {
335 // Detect whether <aSubShape> refers to this mesh or its sub-mesh
336 SALOMEDS::GenericAttribute_var anAttr;
337 SALOMEDS::AttributeIOR_var anIOR;
338 SALOMEDS::SObject_var aMeshSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( _this() ) ) ) );
339 SALOMEDS::SObject_var aMorSM, aRef;
340 CORBA::String_var aShapeIOR = CORBA::string_dup( SMESH_Gen_i::GetORB()->object_to_string( aSubShape ) );
341 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator( aMeshSO );
343 for ( it->InitEx( true ); it->More(); it->Next() ) {
344 SALOMEDS::SObject_var anObj = it->Value();
345 if ( anObj->ReferencedObject( aRef ) ) {
346 if ( aRef->FindAttribute( anAttr, "AttributeIOR" ) ) {
347 anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
348 if ( strcmp( anIOR->Value(), aShapeIOR ) == 0 ) {
349 aMorSM = anObj->GetFather();
356 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( anHyp )->_is_nil();
357 SALOMEDS::SObject_var aHypSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( anHyp ) ) ) );
358 if ( !aMorSM->_is_nil() && !aHypSO->_is_nil() ) {
359 //Find or Create Applied Hypothesis root
360 SALOMEDS::SObject_var AHR;
361 SALOMEDS::AttributeName_var aName;
362 SALOMEDS::AttributeSelectable_var aSelAttr;
363 SALOMEDS::AttributePixMap_var aPixmap;
364 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
365 long aTag = aIsAlgo ? SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag() : SMESH_Gen_i::GetRefOnAppliedHypothesisTag();
367 if ( !aMorSM->FindSubObject( aTag, AHR ) ) {
368 AHR = aBuilder->NewObjectToTag( aMorSM, aTag );
369 anAttr = aBuilder->FindOrCreateAttribute( AHR, "AttributeName" );
370 aName = SALOMEDS::AttributeName::_narrow( anAttr );
371 aName ->SetValue( aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
372 anAttr = aBuilder->FindOrCreateAttribute( AHR, "AttributeSelectable" );
373 aSelAttr = SALOMEDS::AttributeSelectable::_narrow( anAttr );
374 aSelAttr ->SetSelectable( false );
375 anAttr = aBuilder->FindOrCreateAttribute( AHR, "AttributePixMap" );
376 aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr );
377 aPixmap ->SetPixMap( aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO" );
380 SALOMEDS::SObject_var SO = aBuilder->NewObject( AHR );
381 aBuilder->Addreference( SO, aHypSO );
386 return ConvertHypothesisStatus(status);
389 //=============================================================================
393 //=============================================================================
395 SMESH_Hypothesis::Hypothesis_Status
396 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
397 SMESH::SMESH_Hypothesis_ptr anHyp)
399 MESSAGE("addHypothesis");
400 // **** proposer liste de subShape (selection multiple)
402 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
403 if (CORBA::is_nil(mySubShape))
404 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
407 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
408 if (CORBA::is_nil(myHyp))
409 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
412 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
415 TopoDS_Shape myLocSubShape =
416 _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), mySubShape);
417 int hypId = myHyp->GetId();
418 status = _impl->AddHypothesis(myLocSubShape, hypId);
419 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
420 _mapHypo[hypId] = myHyp;
422 catch(SALOME_Exception & S_ex)
424 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
429 //=============================================================================
433 //=============================================================================
435 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
436 SMESH::SMESH_Hypothesis_ptr anHyp)
437 throw(SALOME::SALOME_Exception)
439 Unexpect aCatch(SALOME_SalomeException);
440 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShape, anHyp );
442 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
443 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
445 if ( !aStudy->_is_nil() ) {
446 // Detect whether <aSubShape> refers to this mesh or its sub-mesh
447 SALOMEDS::GenericAttribute_var anAttr;
448 SALOMEDS::AttributeIOR_var anIOR;
449 SALOMEDS::SObject_var aMeshSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( _this() ) ) ) );
450 if ( aMeshSO->_is_nil() )
451 return SMESH::HYP_UNKNOWN_FATAL;
453 SALOMEDS::SObject_var aMorSM, aRef;
454 CORBA::String_var aShapeIOR = CORBA::string_dup( SMESH_Gen_i::GetORB()->object_to_string( aSubShape ) );
455 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator( aMeshSO );
457 for ( it->InitEx( true ); it->More(); it->Next() ) {
458 SALOMEDS::SObject_var anObj = it->Value();
459 if ( anObj->ReferencedObject( aRef ) ) {
460 if ( aRef->FindAttribute( anAttr, "AttributeIOR" ) ) {
461 anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
462 if ( strcmp( anIOR->Value(), aShapeIOR ) == 0 ) {
463 aMorSM = anObj->GetFather();
470 bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( anHyp )->_is_nil();
471 SALOMEDS::SObject_var aHypSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( anHyp ) ) ) );
472 if ( !aMorSM->_is_nil() && !aHypSO->_is_nil() ) {
473 // Remove a refernce to hypothesis or algorithm
474 SALOMEDS::SObject_var AHR;
475 SALOMEDS::AttributeName_var aName;
476 SALOMEDS::AttributeSelectable_var aSelAttr;
477 SALOMEDS::AttributePixMap_var aPixmap;
478 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
479 CORBA::String_var aHypIOR = CORBA::string_dup( SMESH_Gen_i::GetORB()->object_to_string( anHyp ) );
480 long aTag = aIsAlgo ? SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag() : SMESH_Gen_i::GetRefOnAppliedHypothesisTag();
482 if ( aMorSM->FindSubObject( aTag, AHR ) ) {
483 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator( AHR );
484 for ( ; it->More(); it->Next() ) {
485 SALOMEDS::SObject_var anObj = it->Value();
486 if ( anObj->ReferencedObject( aRef ) ) {
487 if ( aRef->FindAttribute( anAttr, "AttributeIOR" ) ) {
488 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
489 if ( strcmp( anIOR->Value(), aHypIOR ) == 0 ) {
490 aBuilder->RemoveObject( anObj );
501 return ConvertHypothesisStatus(status);
505 //=============================================================================
509 //=============================================================================
511 SMESH_Hypothesis::Hypothesis_Status
512 SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
513 SMESH::SMESH_Hypothesis_ptr anHyp)
515 MESSAGE("removeHypothesis()");
516 // **** proposer liste de subShape (selection multiple)
518 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
519 if (CORBA::is_nil(mySubShape))
520 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
523 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
524 if (CORBA::is_nil(myHyp))
525 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
528 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
531 TopoDS_Shape myLocSubShape =
532 _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), mySubShape);
533 int hypId = myHyp->GetId();
534 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
535 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
536 _mapHypo.erase( hypId );
538 catch(SALOME_Exception & S_ex)
540 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
545 //=============================================================================
549 //=============================================================================
551 SMESH::ListOfHypothesis *
552 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Shape_ptr aSubShape)
553 throw(SALOME::SALOME_Exception)
555 Unexpect aCatch(SALOME_SalomeException);
556 MESSAGE("GetHypothesisList");
557 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
558 if (CORBA::is_nil(mySubShape))
559 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
562 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
565 TopoDS_Shape myLocSubShape
566 = _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), mySubShape);
568 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
569 int i = 0, n = aLocalList.size();
572 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
573 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
574 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
575 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
580 catch(SALOME_Exception & S_ex) {
581 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
584 return aList._retn();
587 //=============================================================================
591 //=============================================================================
592 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Shape_ptr aSubShape,
593 const char* theName )
594 throw(SALOME::SALOME_Exception)
596 Unexpect aCatch(SALOME_SalomeException);
597 MESSAGE("SMESH_Mesh_i::GetElementsOnShape");
598 GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
599 if (CORBA::is_nil(mySubShape))
600 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
605 TopoDS_Shape myLocSubShape
606 = _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), mySubShape);
608 //Get or Create the SMESH_subMesh object implementation
610 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
611 subMeshId = mySubMesh->GetId();
613 // create a new subMesh object servant if there is none for the shape
615 if (_mapSubMesh.find(subMeshId) == _mapSubMesh.end()) {
616 SMESH::SMESH_subMesh_var subMesh = createSubMesh( aSubShape );
617 if ( _gen_i->CanPublishInStudy( subMesh ) ) {
618 SALOMEDS::SObject_var aSubmeshSO = _gen_i->PublishInStudy( _gen_i->GetCurrentStudy(),
619 SALOMEDS::SObject::_nil(),
623 // Add reference to <aSubShape> to the study
624 SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
625 SALOMEDS::SObject_var aShapeSO = aStudy->FindObjectIOR( SMESH_Gen_i::GetORB()->object_to_string( aSubShape ) );
626 if ( !aSubmeshSO->_is_nil() && !aShapeSO->_is_nil() ) {
627 MESSAGE( "********** SMESH_Mesh_i::GetSubMesh(): adding shape reference..." )
628 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
629 SALOMEDS::SObject_var SO = aBuilder->NewObjectToTag( aSubmeshSO, SMESH_Gen_i::GetRefOnShapeTag() );
630 aBuilder->Addreference( SO, aShapeSO );
631 MESSAGE( "********** SMESH_Mesh_i::GetSubMesh(): shape reference added" )
636 catch(SALOME_Exception & S_ex) {
637 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
640 ASSERT(_mapSubMeshIor.find(subMeshId) != _mapSubMeshIor.end());
641 return SMESH::SMESH_subMesh::_duplicate(_mapSubMeshIor[subMeshId]);
645 //=============================================================================
649 //=============================================================================
651 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
652 throw (SALOME::SALOME_Exception)
654 MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
655 if ( theSubMesh->_is_nil() )
658 GEOM::GEOM_Shape_var aSubShape;
659 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
660 if ( !aStudy->_is_nil() ) {
661 // Remove submesh's SObject
662 SALOMEDS::SObject_var anSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( theSubMesh ) ) ) );
663 if ( !anSO->_is_nil() ) {
664 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
665 SALOMEDS::SObject_var anObj, aRef;
666 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
667 aSubShape = GEOM::GEOM_Shape::_narrow( aRef->GetObject() );
669 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
673 removeSubMesh( theSubMesh, aSubShape.in() );
677 //=============================================================================
681 //=============================================================================
683 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
684 const char* theName )
685 throw(SALOME::SALOME_Exception)
687 Unexpect aCatch(SALOME_SalomeException);
688 SMESH::SMESH_Group_var aNewGroup = createGroup( theElemType, theName );
690 // Groups should be put under separate roots according to their type (nodes, edges, faces, volumes)
691 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
692 SALOMEDS::SObject_var aGroupSO = _gen_i->PublishInStudy( _gen_i->GetCurrentStudy(),
693 SALOMEDS::SObject::_nil(),
698 return aNewGroup._retn();
702 //=============================================================================
706 //=============================================================================
708 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_Group_ptr theGroup )
709 throw (SALOME::SALOME_Exception)
711 if ( theGroup->_is_nil() )
714 SMESH_Group_i* aGroup = dynamic_cast<SMESH_Group_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
718 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
719 if ( !aStudy->_is_nil() ) {
720 // Remove group's SObject
721 SALOMEDS::SObject_var aGroupSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( theGroup ) ) ) );
722 if ( !aGroupSO->_is_nil() )
723 aStudy->NewBuilder()->RemoveObject( aGroupSO );
726 // Remove the group from SMESH data structures
727 removeGroup( aGroup->GetLocalID() );
731 //=============================================================================
735 //=============================================================================
737 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Shape_ptr theSubShape ) {
739 TopoDS_Shape myLocSubShape = _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), theSubShape);
741 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
742 int subMeshId = mySubMesh->GetId();
743 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
744 SMESH::SMESH_subMesh_var subMesh
745 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
747 _mapSubMesh[subMeshId] = mySubMesh;
748 _mapSubMesh_i[subMeshId] = subMeshServant;
749 _mapSubMeshIor[subMeshId]
750 = SMESH::SMESH_subMesh::_duplicate(subMesh);
752 // register CORBA object for persistence
753 StudyContext* myStudyContext = _gen_i->GetCurrentStudyContext();
754 string iorString = SMESH_Gen_i::GetORB()->object_to_string( subMesh );
755 int nextId = myStudyContext->addObject( iorString );
756 MESSAGE( "Add submesh to map with id = "<< nextId << " and IOR = " << iorString.c_str() );
758 return subMesh._retn();
762 //=============================================================================
766 //=============================================================================
768 void SMESH_Mesh_i::removeSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh, GEOM::GEOM_Shape_ptr theSubShape )
770 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
771 if ( theSubMesh->_is_nil() || theSubShape->_is_nil() )
775 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShape );
776 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
777 removeHypothesis( theSubShape, aHypList[i] );
780 catch( const SALOME::SALOME_Exception& ) {
781 MESSAGE("SMESH_Mesh_i::removeSubMesh(): exception caught!");
784 int subMeshId = theSubMesh->GetId();
786 _mapSubMesh.erase(subMeshId);
787 _mapSubMesh_i.erase(subMeshId);
788 _mapSubMeshIor.erase(subMeshId);
789 MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
792 //=============================================================================
796 //=============================================================================
798 SMESH::SMESH_Group_ptr SMESH_Mesh_i::createGroup( SMESH::ElementType theElemType, const char* theName )
801 SMESH::SMESH_Group_var aGroup;
802 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId ) ) {
803 SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
804 aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
805 _mapGroups[anId] = SMESH::SMESH_Group::_duplicate( aGroup );
807 // register CORBA object for persistence
808 StudyContext* myStudyContext = _gen_i->GetCurrentStudyContext();
809 string iorString = SMESH_Gen_i::GetORB()->object_to_string( aGroup );
810 int nextId = myStudyContext->addObject( iorString );
811 MESSAGE( "Add group to map with id = "<< nextId << " and IOR = " << iorString.c_str() );
813 return aGroup._retn();
817 //=============================================================================
819 * SMESH_Mesh_i::removeGroup
821 * Should be called by ~SMESH_Group_i()
823 //=============================================================================
825 void SMESH_Mesh_i::removeGroup( const int theId )
827 MESSAGE("SMESH_Mesh_i::removeGroup()" );
828 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
829 _mapGroups.erase( theId );
830 _impl->RemoveGroup( theId );
835 //=============================================================================
839 //=============================================================================
841 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
842 throw(SALOME::SALOME_Exception)
844 MESSAGE("SMESH_Mesh_i::GetLog");
846 SMESH::log_array_var aLog;
849 list < SMESHDS_Command * >logDS = _impl->GetLog();
850 aLog = new SMESH::log_array;
852 int lg = logDS.size();
855 list < SMESHDS_Command * >::iterator its = logDS.begin();
856 while (its != logDS.end())
858 SMESHDS_Command *com = *its;
859 int comType = com->GetType();
861 int lgcom = com->GetNumber();
863 const list < int >&intList = com->GetIndexes();
864 int inum = intList.size();
866 list < int >::const_iterator ii = intList.begin();
867 const list < double >&coordList = com->GetCoords();
868 int rnum = coordList.size();
870 list < double >::const_iterator ir = coordList.begin();
871 aLog[indexLog].commandType = comType;
872 aLog[indexLog].number = lgcom;
873 aLog[indexLog].coords.length(rnum);
874 aLog[indexLog].indexes.length(inum);
875 for (int i = 0; i < rnum; i++)
877 aLog[indexLog].coords[i] = *ir;
878 //MESSAGE(" "<<i<<" "<<ir.Value());
881 for (int i = 0; i < inum; i++)
883 aLog[indexLog].indexes[i] = *ii;
884 //MESSAGE(" "<<i<<" "<<ii.Value());
893 catch(SALOME_Exception & S_ex)
895 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
900 // SMESH::string_array* SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
901 // throw (SALOME::SALOME_Exception)
903 // MESSAGE("SMESH_Mesh_i::GetLog");
905 // SMESH::string_array_var aLog;
908 // const SMESHDS_ListOfCommand& logDS =_impl->GetLog();
909 // aLog = new SMESH::string_array;
912 // int lg = logDS.Extent();
914 // SMESHDS_ListIteratorOfListOfCommand its(logDS);
917 // Handle(SMESHDS_Command) com = its.Value();
918 // int comType = com->GetType();
920 // int lgcom = com->GetNumber();
923 // aLog->length(logSize);
925 // const TColStd_ListOfInteger& intList = com->GetIndexes();
926 // TColStd_ListIteratorOfListOfInteger ii(intList);
927 // const TColStd_ListOfReal& coordList = com->GetCoords();
928 // TColStd_ListIteratorOfListOfReal ir(coordList);
929 // for (int icom = 1; icom <= lgcom; icom++)
934 // case SMESHDS_AddNode:
935 // S << "AddNode " << ii.Value(); ii.Next();
936 // S << " " << ir.Value(); ir.Next();
937 // S << " " << ir.Value(); ir.Next();
938 // S << " " << ir.Value(); ir.Next();
940 // case SMESHDS_AddEdge:
941 // S << "AddEdge " << ii.Value(); ii.Next();
942 // S << " " << ii.Value(); ii.Next();
943 // S << " " << ii.Value(); ii.Next();
945 // case SMESHDS_AddTriangle:
946 // S << "AddFace " << ii.Value(); ii.Next();
947 // S << " " << ii.Value(); ii.Next();
948 // S << " " << ii.Value(); ii.Next();
949 // S << " " << ii.Value(); ii.Next();
951 // case SMESHDS_AddQuadrangle:
952 // S << "AddFace " << ii.Value(); ii.Next();
953 // S << " " << ii.Value(); ii.Next();
954 // S << " " << ii.Value(); ii.Next();
955 // S << " " << ii.Value(); ii.Next();
956 // S << " " << ii.Value(); ii.Next();
958 // case SMESHDS_AddTetrahedron:
959 // S << "AddVolume " << ii.Value(); ii.Next();
960 // S << " " << ii.Value(); ii.Next();
961 // S << " " << ii.Value(); ii.Next();
962 // S << " " << ii.Value(); ii.Next();
963 // S << " " << ii.Value(); ii.Next();
965 // case SMESHDS_AddPyramid:
966 // S << "AddVolume " << ii.Value(); ii.Next();
967 // S << " " << ii.Value(); ii.Next();
968 // S << " " << ii.Value(); ii.Next();
969 // S << " " << ii.Value(); ii.Next();
970 // S << " " << ii.Value(); ii.Next();
971 // S << " " << ii.Value(); ii.Next();
973 // case SMESHDS_AddPrism:
974 // S << "AddVolume " << ii.Value(); ii.Next();
975 // S << " " << ii.Value(); ii.Next();
976 // S << " " << 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();
982 // case SMESHDS_AddHexahedron:
983 // S << "AddVolume " << ii.Value(); ii.Next();
984 // S << " " << ii.Value(); ii.Next();
985 // S << " " << 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();
993 // case SMESHDS_RemoveNode:
994 // S << "RemoveNode " << ii.Value(); ii.Next();
996 // case SMESHDS_RemoveElement:
997 // S << "RemoveElement " << ii.Value(); ii.Next();
1003 // string ch = S.str();
1005 // aLog[indexLog++] = CORBA::string_dup(ch.c_str());
1009 // if (clearAfterGet) _impl->ClearLog();
1011 // catch (SALOME_Exception& S_ex)
1013 // THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1015 // return aLog._retn();
1018 //=============================================================================
1022 //=============================================================================
1024 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1026 MESSAGE("SMESH_Mesh_i::ClearLog");
1030 //=============================================================================
1034 //=============================================================================
1036 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1038 MESSAGE("SMESH_Mesh_i::GetId");
1042 //=============================================================================
1046 //=============================================================================
1048 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1053 //=============================================================================
1057 //=============================================================================
1059 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1061 MESSAGE("SMESH_Mesh_i::SetImpl");
1065 //=============================================================================
1069 //=============================================================================
1071 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1073 MESSAGE("SMESH_Mesh_i::GetImpl()");
1078 //=============================================================================
1082 //=============================================================================
1084 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1086 SMESH_MeshEditor_i *aMeshEditor =
1087 new SMESH_MeshEditor_i(_impl->GetMeshDS());
1088 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1089 return aMesh._retn();
1092 //=============================================================================
1096 //=============================================================================
1098 void SMESH_Mesh_i::ExportMED(const char *file, CORBA::Boolean auto_groups) throw(SALOME::SALOME_Exception)
1100 Unexpect aCatch(SALOME_SalomeException);
1101 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1102 if ( aStudy->_is_nil() )
1105 char* aMeshName = NULL;
1106 SALOMEDS::SObject_var aMeshSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( _this() ) ) ) );
1107 if ( !aMeshSO->_is_nil() )
1108 aMeshName = aMeshSO->GetName();
1110 _impl->ExportMED( file, aMeshName, auto_groups );
1113 void SMESH_Mesh_i::ExportDAT(const char *file) throw(SALOME::SALOME_Exception)
1115 Unexpect aCatch(SALOME_SalomeException);
1116 _impl->ExportDAT(file);
1118 void SMESH_Mesh_i::ExportUNV(const char *file) throw(SALOME::SALOME_Exception)
1120 Unexpect aCatch(SALOME_SalomeException);
1121 _impl->ExportUNV(file);
1124 //=============================================================================
1128 //=============================================================================
1130 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1132 Unexpect aCatch(SALOME_SalomeException);
1133 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1134 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1135 return aMesh._retn();
1138 //=============================================================================
1142 //=============================================================================
1143 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1145 Unexpect aCatch(SALOME_SalomeException);
1146 return _impl->NbNodes();
1149 //=============================================================================
1153 //=============================================================================
1154 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1156 Unexpect aCatch(SALOME_SalomeException);
1157 return _impl->NbEdges();
1160 //=============================================================================
1164 //=============================================================================
1165 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1167 Unexpect aCatch(SALOME_SalomeException);
1168 return _impl->NbFaces();
1171 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1173 Unexpect aCatch(SALOME_SalomeException);
1174 return _impl->NbTriangles();
1177 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1179 Unexpect aCatch(SALOME_SalomeException);
1180 return _impl->NbQuadrangles();
1183 //=============================================================================
1187 //=============================================================================
1188 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1190 Unexpect aCatch(SALOME_SalomeException);
1191 return _impl->NbVolumes();
1194 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1196 Unexpect aCatch(SALOME_SalomeException);
1197 return _impl->NbTetras();
1200 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1202 Unexpect aCatch(SALOME_SalomeException);
1203 return _impl->NbHexas();
1206 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1208 Unexpect aCatch(SALOME_SalomeException);
1209 return _impl->NbPyramids();
1212 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1214 Unexpect aCatch(SALOME_SalomeException);
1215 return _impl->NbPrisms();
1218 //=============================================================================
1222 //=============================================================================
1223 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1225 Unexpect aCatch(SALOME_SalomeException);
1226 return _impl->NbSubMesh();
1229 //=============================================================================
1233 //=============================================================================
1234 char* SMESH_Mesh_i::Dump()
1236 std::ostringstream os;
1238 return CORBA::string_dup( os.str().c_str() );