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
29 #include "SMESH_Mesh_i.hxx"
30 #include "SMESH_subMesh_i.hxx"
31 #include "SMESH_MEDMesh_i.hxx"
32 #include "SMESH_Group_i.hxx"
33 #include "SMESH_Filter_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 "SMESHDS_Command.hxx"
44 #include "SMESHDS_CommandType.hxx"
45 #include "SMESH_MeshEditor_i.hxx"
46 #include "SMESH_Gen_i.hxx"
47 #include "DriverMED_R_SMESHDS_Mesh.h"
50 #include <OSD_Path.hxx>
51 #include <OSD_File.hxx>
52 #include <OSD_Directory.hxx>
53 #include <OSD_Protection.hxx>
54 #include <TColStd_MapOfInteger.hxx>
55 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
56 #include <TColStd_SequenceOfInteger.hxx>
57 #include "TCollection_AsciiString.hxx"
65 static int MYDEBUG = 0;
67 static int MYDEBUG = 0;
72 int SMESH_Mesh_i::myIdGenerator = 0;
74 //=============================================================================
78 //=============================================================================
80 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
83 : SALOME::GenericObj_i( thePOA )
85 INFOS("SMESH_Mesh_i");
88 _id = myIdGenerator++;
90 thePOA->activate_object( this );
93 //=============================================================================
97 //=============================================================================
99 SMESH_Mesh_i::~SMESH_Mesh_i()
101 INFOS("~SMESH_Mesh_i");
102 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
103 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
104 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
107 // this method is colled from destructor of group (PAL6331)
108 //_impl->RemoveGroup( aGroup->GetLocalID() );
116 //=============================================================================
120 * Associates <this> mesh with <theShape> and puts a reference
121 * to <theShape> into the current study;
122 * the previous shape is substituted by the new one.
124 //=============================================================================
126 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
127 throw (SALOME::SALOME_Exception)
129 Unexpect aCatch(SALOME_SalomeException);
131 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
133 catch(SALOME_Exception & S_ex) {
134 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
138 //=======================================================================
139 //function : GetShapeToMesh
141 //=======================================================================
143 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
144 throw (SALOME::SALOME_Exception)
146 Unexpect aCatch(SALOME_SalomeException);
147 GEOM::GEOM_Object_var aShapeObj;
149 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
151 aShapeObj = _gen_i->ShapeToGeomObject( S );
153 catch(SALOME_Exception & S_ex) {
154 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
156 return aShapeObj._retn();
159 //=============================================================================
163 //=============================================================================
165 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
167 SMESH::DriverMED_ReadStatus res;
170 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
171 res = SMESH::DRS_OK; break;
172 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
173 res = SMESH::DRS_EMPTY; break;
174 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
175 res = SMESH::DRS_WARN_RENUMBER; break;
176 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
177 res = SMESH::DRS_WARN_SKIP_ELEM; break;
178 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
180 res = SMESH::DRS_FAIL; break;
185 //=============================================================================
189 * Imports mesh data from MED file
191 //=============================================================================
193 SMESH::DriverMED_ReadStatus
194 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
195 throw ( SALOME::SALOME_Exception )
197 Unexpect aCatch(SALOME_SalomeException);
200 status = importMEDFile( theFileName, theMeshName );
202 catch( SALOME_Exception& S_ex ) {
203 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
206 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
209 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
210 if ( !aStudy->_is_nil() ) {
211 // publishing of the groups in the study (sub-meshes are out of scope of MED import)
212 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
213 for (; it != _mapGroups.end(); it++ ) {
214 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
215 _gen_i->PublishGroup( aStudy, _this(), aGroup,
216 GEOM::GEOM_Object::_nil(), aGroup->GetName());
219 return ConvertDriverMEDReadStatus(status);
222 //=============================================================================
226 * Imports mesh data from MED file
228 //=============================================================================
230 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
231 throw ( SALOME::SALOME_Exception )
233 // Read mesh with name = <theMeshName> into SMESH_Mesh
234 _impl->UNVToMesh( theFileName );
239 //=============================================================================
243 * Imports mesh data from STL file
245 //=============================================================================
246 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
247 throw ( SALOME::SALOME_Exception )
249 // Read mesh with name = <theMeshName> into SMESH_Mesh
250 _impl->STLToMesh( theFileName );
255 //=============================================================================
259 * Imports mesh data from MED file
261 //=============================================================================
263 int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
265 // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
266 int status = _impl->MEDToMesh( theFileName, theMeshName );
268 // Create group servants, if any groups were imported
269 list<int> aGroupIds = _impl->GetGroupIds();
270 for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
271 SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
273 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
274 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
275 aGroupImpl->Register();
276 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
278 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
279 _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup );
281 // register CORBA object for persistence
282 int nextId = _gen_i->RegisterObject( aGroup );
283 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
289 //=============================================================================
293 //=============================================================================
295 static SMESH::Hypothesis_Status ConvertHypothesisStatus
296 (SMESH_Hypothesis::Hypothesis_Status theStatus)
298 SMESH::Hypothesis_Status res;
301 case SMESH_Hypothesis::HYP_OK:
302 res = SMESH::HYP_OK; break;
303 case SMESH_Hypothesis::HYP_MISSING:
304 res = SMESH::HYP_MISSING; break;
305 case SMESH_Hypothesis::HYP_CONCURENT:
306 res = SMESH::HYP_CONCURENT; break;
307 case SMESH_Hypothesis::HYP_BAD_PARAMETER:
308 res = SMESH::HYP_BAD_PARAMETER; break;
309 case SMESH_Hypothesis::HYP_INCOMPATIBLE:
310 res = SMESH::HYP_INCOMPATIBLE; break;
311 case SMESH_Hypothesis::HYP_NOTCONFORM:
312 res = SMESH::HYP_NOTCONFORM; break;
313 case SMESH_Hypothesis::HYP_ALREADY_EXIST:
314 res = SMESH::HYP_ALREADY_EXIST; break;
315 case SMESH_Hypothesis::HYP_BAD_DIM:
316 res = SMESH::HYP_BAD_DIM; break;
318 res = SMESH::HYP_UNKNOWN_FATAL;
323 //=============================================================================
327 * calls internal addHypothesis() and then adds a reference to <anHyp> under
328 * the SObject actually having a reference to <aSubShape>.
329 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
331 //=============================================================================
333 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
334 SMESH::SMESH_Hypothesis_ptr anHyp)
335 throw(SALOME::SALOME_Exception)
337 Unexpect aCatch(SALOME_SalomeException);
338 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
340 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
341 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
342 aSubShapeObject, anHyp );
344 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
346 // Update Python script
347 TCollection_AsciiString aStr ("status = ");
348 SMESH_Gen_i::AddObject(aStr, _this()) += ".AddHypothesis(";
349 SMESH_Gen_i::AddObject(aStr, aSubShapeObject) += ", ";
350 SMESH_Gen_i::AddObject(aStr, anHyp) += ")";
352 SMESH_Gen_i::AddToCurrentPyScript(aStr);
354 return ConvertHypothesisStatus(status);
357 //=============================================================================
361 //=============================================================================
363 SMESH_Hypothesis::Hypothesis_Status
364 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
365 SMESH::SMESH_Hypothesis_ptr anHyp)
367 if(MYDEBUG) MESSAGE("addHypothesis");
369 if (CORBA::is_nil(aSubShapeObject))
370 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
373 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
374 if (CORBA::is_nil(myHyp))
375 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
378 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
381 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
382 int hypId = myHyp->GetId();
383 status = _impl->AddHypothesis(myLocSubShape, hypId);
384 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
385 _mapHypo[hypId] = myHyp;
386 // assure there is a corresponding submesh
387 if ( !_impl->IsMainShape( myLocSubShape )) {
388 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
389 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
390 createSubMesh( aSubShapeObject );
394 catch(SALOME_Exception & S_ex)
396 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
401 //=============================================================================
405 //=============================================================================
407 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
408 SMESH::SMESH_Hypothesis_ptr anHyp)
409 throw(SALOME::SALOME_Exception)
411 Unexpect aCatch(SALOME_SalomeException);
412 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
414 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
415 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
416 aSubShapeObject, anHyp );
418 // Update Python script
419 TCollection_AsciiString aStr ("status = ");
420 SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveHypothesis(";
421 SMESH_Gen_i::AddObject(aStr, aSubShapeObject) += ", ";
422 SMESH_Gen_i::AddObject(aStr, anHyp) += ")";
424 SMESH_Gen_i::AddToCurrentPyScript(aStr);
426 return ConvertHypothesisStatus(status);
429 //=============================================================================
433 //=============================================================================
435 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
436 SMESH::SMESH_Hypothesis_ptr anHyp)
438 if(MYDEBUG) MESSAGE("removeHypothesis()");
439 // **** proposer liste de subShape (selection multiple)
441 if (CORBA::is_nil(aSubShapeObject))
442 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
445 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
446 if (CORBA::is_nil(myHyp))
447 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
450 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
453 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
454 int hypId = myHyp->GetId();
455 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
456 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
457 _mapHypo.erase( hypId );
459 catch(SALOME_Exception & S_ex)
461 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
466 //=============================================================================
470 //=============================================================================
472 SMESH::ListOfHypothesis *
473 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
474 throw(SALOME::SALOME_Exception)
476 Unexpect aCatch(SALOME_SalomeException);
477 if (MYDEBUG) MESSAGE("GetHypothesisList");
478 if (CORBA::is_nil(aSubShapeObject))
479 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
482 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
485 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
486 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
487 int i = 0, n = aLocalList.size();
490 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
491 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
492 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
493 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
498 catch(SALOME_Exception & S_ex) {
499 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
502 return aList._retn();
505 //=============================================================================
509 //=============================================================================
510 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
511 const char* theName )
512 throw(SALOME::SALOME_Exception)
514 Unexpect aCatch(SALOME_SalomeException);
515 MESSAGE("SMESH_Mesh_i::GetSubMesh");
516 if (CORBA::is_nil(aSubShapeObject))
517 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
520 SMESH::SMESH_subMesh_var subMesh;
521 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
523 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
525 //Get or Create the SMESH_subMesh object implementation
527 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
528 subMesh = getSubMesh( subMeshId );
530 // create a new subMesh object servant if there is none for the shape
531 if ( subMesh->_is_nil() )
532 subMesh = createSubMesh( aSubShapeObject );
534 if ( _gen_i->CanPublishInStudy( subMesh )) {
535 SALOMEDS::SObject_var aSO =
536 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
537 subMesh, aSubShapeObject, theName );
538 if ( !aSO->_is_nil()) {
539 // Update Python script
540 TCollection_AsciiString aStr (aSO->GetID());
542 SMESH_Gen_i::AddObject(aStr, _this()) += ".GetSubMesh(";
543 SMESH_Gen_i::AddObject(aStr, aSubShapeObject) += ", \"";
544 aStr += (char*)theName;
547 SMESH_Gen_i::AddToCurrentPyScript(aStr);
551 catch(SALOME_Exception & S_ex) {
552 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
554 return subMesh._retn();
557 //=============================================================================
561 //=============================================================================
563 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
564 throw (SALOME::SALOME_Exception)
566 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
567 if ( theSubMesh->_is_nil() )
570 GEOM::GEOM_Object_var aSubShapeObject;
571 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
572 if ( !aStudy->_is_nil() ) {
573 // Remove submesh's SObject
574 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
575 if ( !anSO->_is_nil() ) {
576 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
577 SALOMEDS::SObject_var anObj, aRef;
578 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
579 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
581 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
583 // Update Python script
584 TCollection_AsciiString aStr;
585 SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveSubMesh(";
586 aStr += anSO->GetID();
589 SMESH_Gen_i::AddToCurrentPyScript(aStr);
593 removeSubMesh( theSubMesh, aSubShapeObject.in() );
596 //=============================================================================
600 //=============================================================================
601 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
603 TCollection_AsciiString aStr;
604 switch (theElemType) {
618 aStr = "SMESH.VOLUME";
626 //=============================================================================
630 //=============================================================================
632 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
633 const char* theName )
634 throw(SALOME::SALOME_Exception)
636 Unexpect aCatch(SALOME_SalomeException);
637 SMESH::SMESH_Group_var aNewGroup =
638 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
640 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
641 SALOMEDS::SObject_var aSO =
642 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
643 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
644 if ( !aSO->_is_nil()) {
645 // Update Python script
646 TCollection_AsciiString aStr (aSO->GetID());
648 SMESH_Gen_i::AddObject(aStr, _this()) += ".CreateGroup(";
649 aStr += ElementTypeString(theElemType) + ", \"" + (char*)theName + "\")";
651 SMESH_Gen_i::AddToCurrentPyScript(aStr);
655 return aNewGroup._retn();
659 //=============================================================================
663 //=============================================================================
664 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
666 GEOM::GEOM_Object_ptr theGeomObj)
667 throw(SALOME::SALOME_Exception)
669 Unexpect aCatch(SALOME_SalomeException);
670 SMESH::SMESH_GroupOnGeom_var aNewGroup;
672 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
673 if ( !aShape.IsNull() ) {
674 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
675 ( createGroup( theElemType, theName, aShape ));
676 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
677 SALOMEDS::SObject_var aSO =
678 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
679 aNewGroup, theGeomObj, theName);
680 if ( !aSO->_is_nil()) {
681 // Update Python script
682 TCollection_AsciiString aStr (aSO->GetID());
684 SMESH_Gen_i::AddObject(aStr, _this()) += ".CreateGroupFromGEOM(";
685 aStr += ElementTypeString(theElemType) + ", \"" + (char*)theName + "\", ";
686 SMESH_Gen_i::AddObject(aStr, theGeomObj) += ")";
688 SMESH_Gen_i::AddToCurrentPyScript(aStr);
693 return aNewGroup._retn();
696 //=============================================================================
700 //=============================================================================
702 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
703 throw (SALOME::SALOME_Exception)
705 if ( theGroup->_is_nil() )
708 SMESH_GroupBase_i* aGroup =
709 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
713 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
714 if ( !aStudy->_is_nil() ) {
715 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
717 if ( !aGroupSO->_is_nil() ) {
718 // Update Python script
719 TCollection_AsciiString aStr;
720 SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveGroup(";
721 aStr += aGroupSO->GetID();
724 SMESH_Gen_i::AddToCurrentPyScript(aStr);
726 // Remove group's SObject
727 aStudy->NewBuilder()->RemoveObject( aGroupSO );
731 // Remove the group from SMESH data structures
732 removeGroup( aGroup->GetLocalID() );
735 //=============================================================================
736 /*! RemoveGroupWithContents
737 * Remove group with its contents
739 //=============================================================================
740 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
741 throw (SALOME::SALOME_Exception)
743 if ( theGroup->_is_nil() )
746 SMESH_GroupBase_i* aGroup =
747 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
751 SMESH::long_array_var anIds = aGroup->GetListOfID();
752 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
754 // Update Python script
755 TCollection_AsciiString aStr;
756 SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveGroupWithContents(";
757 SMESH_Gen_i::AddObject(aStr, theGroup) += ")";
759 SMESH_Gen_i::AddToCurrentPyScript(aStr);
762 if ( aGroup->GetType() == SMESH::NODE )
763 aMeshEditor->RemoveNodes( anIds );
765 aMeshEditor->RemoveElements( anIds );
768 RemoveGroup( theGroup );
770 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
771 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
772 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
775 //=============================================================================
777 * New group is created. All mesh elements that are
778 * present in initial groups are added to the new one
780 //=============================================================================
781 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
782 SMESH::SMESH_GroupBase_ptr theGroup2,
783 const char* theName )
784 throw (SALOME::SALOME_Exception)
788 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
789 theGroup1->GetType() != theGroup2->GetType() )
790 return SMESH::SMESH_Group::_nil();
793 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
794 if ( aResGrp->_is_nil() )
795 return SMESH::SMESH_Group::_nil();
797 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
798 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
800 TColStd_MapOfInteger aResMap;
802 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
803 aResMap.Add( anIds1[ i1 ] );
805 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
806 aResMap.Add( anIds2[ i2 ] );
808 SMESH::long_array_var aResIds = new SMESH::long_array;
809 aResIds->length( aResMap.Extent() );
812 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
813 for( ; anIter.More(); anIter.Next() )
814 aResIds[ resI++ ] = anIter.Key();
816 aResGrp->Add( aResIds );
818 // Clear python lines, created by CreateGroup() and Add()
819 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
820 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
821 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
823 // Update Python script
824 TCollection_AsciiString aStr;
825 SMESH_Gen_i::AddObject(aStr, aResGrp) += " = ";
826 SMESH_Gen_i::AddObject(aStr, _this()) += ".UnionGroups(";
827 SMESH_Gen_i::AddObject(aStr, theGroup1) += ", ";
828 SMESH_Gen_i::AddObject(aStr, theGroup2) += ", \"";
829 aStr += TCollection_AsciiString((char*)theName) + "\")";
831 SMESH_Gen_i::AddToCurrentPyScript(aStr);
833 return aResGrp._retn();
837 return SMESH::SMESH_Group::_nil();
841 //=============================================================================
843 * New group is created. All mesh elements that are
844 * present in both initial groups are added to the new one.
846 //=============================================================================
847 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
848 SMESH::SMESH_GroupBase_ptr theGroup2,
849 const char* theName )
850 throw (SALOME::SALOME_Exception)
852 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
853 theGroup1->GetType() != theGroup2->GetType() )
854 return SMESH::SMESH_Group::_nil();
856 // Create Intersection
857 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
858 if ( aResGrp->_is_nil() )
861 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
862 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
864 TColStd_MapOfInteger aMap1;
866 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
867 aMap1.Add( anIds1[ i1 ] );
869 TColStd_SequenceOfInteger aSeq;
871 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
872 if ( aMap1.Contains( anIds2[ i2 ] ) )
873 aSeq.Append( anIds2[ i2 ] );
875 SMESH::long_array_var aResIds = new SMESH::long_array;
876 aResIds->length( aSeq.Length() );
878 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
879 aResIds[ resI ] = aSeq( resI + 1 );
881 aResGrp->Add( aResIds );
883 // Clear python lines, created by CreateGroup() and Add()
884 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
885 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
886 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
888 // Update Python script
889 TCollection_AsciiString aStr;
890 SMESH_Gen_i::AddObject(aStr, aResGrp) += " = ";
891 SMESH_Gen_i::AddObject(aStr, _this()) += ".IntersectGroups(";
892 SMESH_Gen_i::AddObject(aStr, theGroup1) += ", ";
893 SMESH_Gen_i::AddObject(aStr, theGroup2) += ", \"";
894 aStr += TCollection_AsciiString((char*)theName) + "\")";
896 SMESH_Gen_i::AddToCurrentPyScript(aStr);
898 return aResGrp._retn();
901 //=============================================================================
903 * New group is created. All mesh elements that are present in
904 * main group but do not present in tool group are added to the new one
906 //=============================================================================
907 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
908 SMESH::SMESH_GroupBase_ptr theGroup2,
909 const char* theName )
910 throw (SALOME::SALOME_Exception)
912 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
913 theGroup1->GetType() != theGroup2->GetType() )
914 return SMESH::SMESH_Group::_nil();
917 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
918 if ( aResGrp->_is_nil() )
921 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
922 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
924 TColStd_MapOfInteger aMap2;
926 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
927 aMap2.Add( anIds2[ i2 ] );
930 TColStd_SequenceOfInteger aSeq;
931 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
932 if ( !aMap2.Contains( anIds1[ i1 ] ) )
933 aSeq.Append( anIds1[ i1 ] );
935 SMESH::long_array_var aResIds = new SMESH::long_array;
936 aResIds->length( aSeq.Length() );
938 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
939 aResIds[ resI ] = aSeq( resI + 1 );
941 aResGrp->Add( aResIds );
943 // Clear python lines, created by CreateGroup() and Add()
944 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
945 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
946 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
948 // Update Python script
949 TCollection_AsciiString aStr;
950 SMESH_Gen_i::AddObject(aStr, aResGrp) += " = ";
951 SMESH_Gen_i::AddObject(aStr, _this()) += ".CutGroups(";
952 SMESH_Gen_i::AddObject(aStr, theGroup1) += ", ";
953 SMESH_Gen_i::AddObject(aStr, theGroup2) += ", \"";
954 aStr += TCollection_AsciiString((char*)theName) + "\")";
956 SMESH_Gen_i::AddToCurrentPyScript(aStr);
958 return aResGrp._retn();
961 //=============================================================================
965 //=============================================================================
967 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
969 if(MYDEBUG) MESSAGE( "createSubMesh" );
970 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
972 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
973 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
974 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
975 SMESH::SMESH_subMesh_var subMesh
976 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
978 _mapSubMesh[subMeshId] = mySubMesh;
979 _mapSubMesh_i[subMeshId] = subMeshServant;
980 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
982 // register CORBA object for persistence
983 int nextId = _gen_i->RegisterObject( subMesh );
984 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
986 return subMesh._retn();
989 //=======================================================================
990 //function : getSubMesh
992 //=======================================================================
994 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
996 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
997 if ( it == _mapSubMeshIor.end() )
998 return SMESH::SMESH_subMesh::_nil();
1000 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
1004 //=============================================================================
1008 //=============================================================================
1010 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1011 GEOM::GEOM_Object_ptr theSubShapeObject )
1013 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1014 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1018 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1019 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1020 removeHypothesis( theSubShapeObject, aHypList[i] );
1023 catch( const SALOME::SALOME_Exception& ) {
1024 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1027 int subMeshId = theSubMesh->GetId();
1029 _mapSubMesh.erase(subMeshId);
1030 _mapSubMesh_i.erase(subMeshId);
1031 _mapSubMeshIor.erase(subMeshId);
1032 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1035 //=============================================================================
1039 //=============================================================================
1041 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1042 const char* theName,
1043 const TopoDS_Shape& theShape )
1046 SMESH::SMESH_GroupBase_var aGroup;
1047 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1048 SMESH_GroupBase_i* aGroupImpl;
1049 if ( !theShape.IsNull() )
1050 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1052 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1054 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1055 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1056 aGroupImpl->Register();
1057 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1059 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1060 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1062 // register CORBA object for persistence
1063 int nextId = _gen_i->RegisterObject( aGroup );
1064 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1066 return aGroup._retn();
1069 //=============================================================================
1071 * SMESH_Mesh_i::removeGroup
1073 * Should be called by ~SMESH_Group_i()
1075 //=============================================================================
1077 void SMESH_Mesh_i::removeGroup( const int theId )
1079 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1080 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1081 _mapGroups.erase( theId );
1082 _impl->RemoveGroup( theId );
1087 //=============================================================================
1091 //=============================================================================
1093 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1094 throw(SALOME::SALOME_Exception)
1096 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1098 SMESH::log_array_var aLog;
1100 list < SMESHDS_Command * >logDS = _impl->GetLog();
1101 aLog = new SMESH::log_array;
1103 int lg = logDS.size();
1106 list < SMESHDS_Command * >::iterator its = logDS.begin();
1107 while(its != logDS.end()){
1108 SMESHDS_Command *com = *its;
1109 int comType = com->GetType();
1111 int lgcom = com->GetNumber();
1113 const list < int >&intList = com->GetIndexes();
1114 int inum = intList.size();
1116 list < int >::const_iterator ii = intList.begin();
1117 const list < double >&coordList = com->GetCoords();
1118 int rnum = coordList.size();
1120 list < double >::const_iterator ir = coordList.begin();
1121 aLog[indexLog].commandType = comType;
1122 aLog[indexLog].number = lgcom;
1123 aLog[indexLog].coords.length(rnum);
1124 aLog[indexLog].indexes.length(inum);
1125 for(int i = 0; i < rnum; i++){
1126 aLog[indexLog].coords[i] = *ir;
1127 //MESSAGE(" "<<i<<" "<<ir.Value());
1130 for(int i = 0; i < inum; i++){
1131 aLog[indexLog].indexes[i] = *ii;
1132 //MESSAGE(" "<<i<<" "<<ii.Value());
1141 catch(SALOME_Exception & S_ex){
1142 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1144 return aLog._retn();
1148 //=============================================================================
1152 //=============================================================================
1154 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1156 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1160 //=============================================================================
1164 //=============================================================================
1166 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1168 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1172 //=============================================================================
1176 //=============================================================================
1178 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1183 //=============================================================================
1187 //=============================================================================
1189 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1191 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1195 //=============================================================================
1199 //=============================================================================
1201 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1203 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1208 //=============================================================================
1212 //=============================================================================
1214 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1216 // Update Python script
1217 TCollection_AsciiString aStr ("mesh_editor = ");
1218 SMESH_Gen_i::AddObject(aStr, _this()) += ".GetMeshEditor()";
1220 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1222 // Create MeshEditor
1223 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl );
1224 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1225 return aMesh._retn();
1228 //=============================================================================
1230 * Export in different formats
1232 //=============================================================================
1234 static void PrepareForWriting (const char* file)
1236 TCollection_AsciiString aFullName ((char*)file);
1237 OSD_Path aPath (aFullName);
1238 OSD_File aFile (aPath);
1239 if (aFile.Exists()) {
1240 // existing filesystem node
1241 if (aFile.KindOfFile() == OSD_FILE) {
1242 if (aFile.IsWriteable()) {
1245 if (aFile.Failed()) {
1246 TCollection_AsciiString msg ("File ");
1247 msg += aFullName + " cannot be replaced.";
1248 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1251 TCollection_AsciiString msg ("File ");
1252 msg += aFullName + " cannot be overwritten.";
1253 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1256 TCollection_AsciiString msg ("Location ");
1257 msg += aFullName + " is not a file.";
1258 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1262 TCollection_AsciiString aDirName = aPath.TrekValue(aPath.TrekLength());
1264 aPath.SetName(aDirName);
1265 aPath.SetExtension("");
1266 OSD_Directory aDir (aPath);
1267 TCollection_AsciiString aFullDirName;
1268 aPath.SystemName(aFullDirName);
1269 if (aDir.Exists()) {
1271 aFile.Build(OSD_WriteOnly, OSD_Protection());
1272 if (aFile.Failed()) {
1273 TCollection_AsciiString msg ("You cannot write to directory ");
1274 msg += aFullDirName + ".";
1275 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1281 TCollection_AsciiString msg ("Directory ");
1282 msg += aFullDirName + " does not exist.";
1283 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1288 void SMESH_Mesh_i::ExportToMED (const char* file,
1289 CORBA::Boolean auto_groups,
1290 SMESH::MED_VERSION theVersion)
1291 throw(SALOME::SALOME_Exception)
1293 Unexpect aCatch(SALOME_SalomeException);
1295 // Update Python script
1296 TCollection_AsciiString aStr;
1297 SMESH_Gen_i::AddObject(aStr, _this()) += ".ExportToMED(\"";
1298 aStr += TCollection_AsciiString((char*)file) + "\", ";
1299 aStr += TCollection_AsciiString((int)auto_groups) + ", ";
1300 switch (theVersion) {
1301 case SMESH::MED_V2_1:
1302 aStr += "SMESH.MED_V2_1)";
1304 case SMESH::MED_V2_2:
1305 aStr += "SMESH.MED_V2_2)";
1308 aStr += TCollection_AsciiString(theVersion) + ")";
1312 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1315 PrepareForWriting(file);
1316 char* aMeshName = "Mesh";
1317 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1318 if ( !aStudy->_is_nil() ) {
1319 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1320 if ( !aMeshSO->_is_nil() ) {
1321 aMeshName = aMeshSO->GetName();
1323 //SCRUTE(aMeshName);
1324 //SCRUTE(aMeshSO->GetID());
1326 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1327 if ( !aStudy->GetProperties()->IsLocked() )
1329 SALOMEDS::GenericAttribute_var anAttr;
1330 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1331 SALOMEDS::AttributeExternalFileDef_var aFileName;
1332 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1333 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1334 ASSERT(!aFileName->_is_nil());
1335 aFileName->SetValue(file);
1336 SALOMEDS::AttributeFileType_var aFileType;
1337 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1338 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1339 ASSERT(!aFileType->_is_nil());
1340 aFileType->SetValue("FICHIERMED");
1344 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1347 void SMESH_Mesh_i::ExportMED (const char* file,
1348 CORBA::Boolean auto_groups)
1349 throw(SALOME::SALOME_Exception)
1351 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1354 void SMESH_Mesh_i::ExportDAT (const char *file)
1355 throw(SALOME::SALOME_Exception)
1357 Unexpect aCatch(SALOME_SalomeException);
1359 // Update Python script
1360 TCollection_AsciiString aStr;
1361 SMESH_Gen_i::AddObject(aStr, _this()) += ".ExportDAT(\"";
1362 aStr += TCollection_AsciiString((char*)file) + "\")";
1364 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1367 PrepareForWriting(file);
1368 _impl->ExportDAT(file);
1371 void SMESH_Mesh_i::ExportUNV (const char *file)
1372 throw(SALOME::SALOME_Exception)
1374 Unexpect aCatch(SALOME_SalomeException);
1376 // Update Python script
1377 TCollection_AsciiString aStr;
1378 SMESH_Gen_i::AddObject(aStr, _this()) += ".ExportUNV(\"";
1379 aStr += TCollection_AsciiString((char*)file) + "\")";
1381 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1384 PrepareForWriting(file);
1385 _impl->ExportUNV(file);
1388 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1389 throw(SALOME::SALOME_Exception)
1391 Unexpect aCatch(SALOME_SalomeException);
1393 // Update Python script
1394 TCollection_AsciiString aStr;
1395 SMESH_Gen_i::AddObject(aStr, _this()) += ".ExportSTL(\"";
1396 aStr += TCollection_AsciiString((char*)file) + "\", ";
1397 aStr += TCollection_AsciiString((int)isascii) + ")";
1399 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1402 PrepareForWriting(file);
1403 _impl->ExportSTL(file, isascii);
1406 //=============================================================================
1410 //=============================================================================
1412 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1414 Unexpect aCatch(SALOME_SalomeException);
1415 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1416 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1417 return aMesh._retn();
1420 //=============================================================================
1424 //=============================================================================
1425 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1427 Unexpect aCatch(SALOME_SalomeException);
1428 return _impl->NbNodes();
1431 //=============================================================================
1435 //=============================================================================
1436 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1438 Unexpect aCatch(SALOME_SalomeException);
1439 return NbEdges() + NbFaces() + NbVolumes();
1442 //=============================================================================
1446 //=============================================================================
1447 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1449 Unexpect aCatch(SALOME_SalomeException);
1450 return _impl->NbEdges();
1453 //=============================================================================
1457 //=============================================================================
1458 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1460 Unexpect aCatch(SALOME_SalomeException);
1461 return _impl->NbFaces();
1464 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1466 Unexpect aCatch(SALOME_SalomeException);
1467 return _impl->NbTriangles();
1470 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1472 Unexpect aCatch(SALOME_SalomeException);
1473 return _impl->NbQuadrangles();
1476 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1478 Unexpect aCatch(SALOME_SalomeException);
1479 return _impl->NbPolygons();
1482 //=============================================================================
1486 //=============================================================================
1487 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1489 Unexpect aCatch(SALOME_SalomeException);
1490 return _impl->NbVolumes();
1493 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1495 Unexpect aCatch(SALOME_SalomeException);
1496 return _impl->NbTetras();
1499 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1501 Unexpect aCatch(SALOME_SalomeException);
1502 return _impl->NbHexas();
1505 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1507 Unexpect aCatch(SALOME_SalomeException);
1508 return _impl->NbPyramids();
1511 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1513 Unexpect aCatch(SALOME_SalomeException);
1514 return _impl->NbPrisms();
1517 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1519 Unexpect aCatch(SALOME_SalomeException);
1520 return _impl->NbPolyhedrons();
1523 //=============================================================================
1527 //=============================================================================
1528 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1530 Unexpect aCatch(SALOME_SalomeException);
1531 return _impl->NbSubMesh();
1534 //=============================================================================
1538 //=============================================================================
1539 char* SMESH_Mesh_i::Dump()
1541 std::ostringstream os;
1543 return CORBA::string_dup( os.str().c_str() );
1546 //=============================================================================
1550 //=============================================================================
1551 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1553 SMESH::long_array_var aResult = new SMESH::long_array();
1554 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1555 int aMinId = aSMESHDS_Mesh->MinElementID();
1556 int aMaxId = aSMESHDS_Mesh->MaxElementID();
1558 aResult->length(aMaxId - aMinId + 1);
1560 for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1563 return aResult._retn();
1566 //=============================================================================
1570 //=============================================================================
1572 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1573 throw (SALOME::SALOME_Exception)
1575 Unexpect aCatch(SALOME_SalomeException);
1576 MESSAGE("SMESH_Mesh_i::GetElementsId");
1577 SMESH::long_array_var aResult = new SMESH::long_array();
1578 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1580 if ( aSMESHDS_Mesh == NULL )
1581 return aResult._retn();
1583 long nbElements = NbElements();
1584 aResult->length( nbElements );
1585 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1586 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1587 aResult[i] = anIt->next()->GetID();
1589 return aResult._retn();
1593 //=============================================================================
1597 //=============================================================================
1599 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1600 throw (SALOME::SALOME_Exception)
1602 Unexpect aCatch(SALOME_SalomeException);
1603 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1604 SMESH::long_array_var aResult = new SMESH::long_array();
1605 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1607 if ( aSMESHDS_Mesh == NULL )
1608 return aResult._retn();
1610 long nbElements = NbElements();
1612 // No sense in returning ids of elements along with ids of nodes:
1613 // when theElemType == SMESH::ALL, return node ids only if
1614 // there are no elements
1615 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1616 return GetNodesId();
1618 aResult->length( nbElements );
1622 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1623 while ( i < nbElements && anIt->more() ) {
1624 const SMDS_MeshElement* anElem = anIt->next();
1625 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1626 aResult[i++] = anElem->GetID();
1629 aResult->length( i );
1631 return aResult._retn();
1634 //=============================================================================
1638 //=============================================================================
1640 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1641 throw (SALOME::SALOME_Exception)
1643 Unexpect aCatch(SALOME_SalomeException);
1644 MESSAGE("SMESH_subMesh_i::GetNodesId");
1645 SMESH::long_array_var aResult = new SMESH::long_array();
1646 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1648 if ( aSMESHDS_Mesh == NULL )
1649 return aResult._retn();
1651 long nbNodes = NbNodes();
1652 aResult->length( nbNodes );
1653 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1654 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1655 aResult[i] = anIt->next()->GetID();
1657 return aResult._retn();
1660 //=============================================================================
1664 //=============================================================================
1666 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1667 throw (SALOME::SALOME_Exception)
1669 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );