1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESH_MeshEditor_i.cxx
23 // Author : Nicolas REJNERI
30 // A macro used in SMESH_TryCatch.hxx,
31 // it re-raises a CORBA SALOME exception thrown by SMESH_MeshEditor_i and caught by SMESH_CATCH
32 #define SMY_OWN_CATCH \
33 catch ( SALOME::SALOME_Exception & e ) { throw e; }
35 #include "SMESH_MeshEditor_i.hxx"
37 #include "SMDS_EdgePosition.hxx"
38 #include "SMDS_ElemIterator.hxx"
39 #include "SMDS_FacePosition.hxx"
40 #include "SMDS_IteratorOnIterators.hxx"
41 #include "SMDS_LinearEdge.hxx"
42 #include "SMDS_Mesh0DElement.hxx"
43 #include "SMDS_MeshFace.hxx"
44 #include "SMDS_MeshVolume.hxx"
45 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
46 #include "SMDS_SetIterator.hxx"
47 #include "SMDS_VolumeTool.hxx"
48 #include "SMESHDS_Group.hxx"
49 #include "SMESHDS_GroupOnGeom.hxx"
50 #include "SMESH_ControlsDef.hxx"
51 #include "SMESH_Filter_i.hxx"
52 #include "SMESH_Gen_i.hxx"
53 #include "SMESH_Group.hxx"
54 #include "SMESH_Group_i.hxx"
55 #include "SMESH_MeshAlgos.hxx"
56 #include "SMESH_MeshPartDS.hxx"
57 #include "SMESH_MesherHelper.hxx"
58 #include "SMESH_PythonDump.hxx"
59 #include "SMESH_subMeshEventListener.hxx"
60 #include "SMESH_subMesh_i.hxx"
62 #include <utilities.h>
63 #include <Utils_ExceptHandlers.hxx>
64 #include <Utils_CorbaException.hxx>
65 #include <SALOMEDS_wrap.hxx>
67 #include <BRepAdaptor_Surface.hxx>
68 #include <BRep_Tool.hxx>
69 #include <TopExp_Explorer.hxx>
71 #include <TopoDS_Edge.hxx>
72 #include <TopoDS_Face.hxx>
77 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
81 #include <Standard_Failure.hxx>
84 #include <Standard_ErrorHandler.hxx>
90 #include "SMESH_TryCatch.hxx" // include after OCCT headers!
92 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
95 using SMESH::TPythonDump;
98 namespace MeshEditor_I {
100 //=============================================================================
102 * \brief Mesh to apply modifications for preview purposes
104 //=============================================================================
106 struct TPreviewMesh: public SMESH_Mesh
108 SMDSAbs_ElementType myPreviewType; // type to show
110 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
111 _isShapeToMesh = (_id =_studyId = 0);
112 _myMeshDS = new SMESHDS_Mesh( _id, true );
113 myPreviewType = previewElements;
116 virtual ~TPreviewMesh() { delete _myMeshDS; _myMeshDS = 0; }
117 //!< Copy a set of elements
118 void Copy(const TIDSortedElemSet & theElements,
119 TIDSortedElemSet& theCopyElements,
120 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
121 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
123 // loop on theIDsOfElements
124 TIDSortedElemSet::const_iterator eIt = theElements.begin();
125 for ( ; eIt != theElements.end(); ++eIt )
127 const SMDS_MeshElement* anElem = *eIt;
128 if ( !anElem ) continue;
129 SMDSAbs_ElementType type = anElem->GetType();
130 if ( type == theAvoidType ||
131 ( theSelectType != SMDSAbs_All && type != theSelectType ))
133 const SMDS_MeshElement* anElemCopy;
134 if ( type == SMDSAbs_Node)
135 anElemCopy = Copy( cast2Node(anElem) );
137 anElemCopy = Copy( anElem );
139 theCopyElements.insert( theCopyElements.end(), anElemCopy );
143 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
145 // copy element nodes
146 int anElemNbNodes = anElem->NbNodes();
147 vector< int > anElemNodesID( anElemNbNodes ) ;
148 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
149 for ( int i = 0; itElemNodes->more(); i++)
151 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
153 anElemNodesID[i] = anElemNode->GetID();
156 // creates a corresponding element on copied nodes
157 SMDS_MeshElement* anElemCopy = 0;
158 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
160 const SMDS_VtkVolume* ph =
161 dynamic_cast<const SMDS_VtkVolume*> (anElem);
163 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
164 (anElemNodesID, ph->GetQuantities(),anElem->GetID());
167 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
174 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
176 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
177 anElemNode->GetID());
179 };// struct TPreviewMesh
181 static SMESH_NodeSearcher * theNodeSearcher = 0;
182 static SMESH_ElementSearcher * theElementSearcher = 0;
184 //=============================================================================
186 * \brief Deleter of theNodeSearcher at any compute event occured
188 //=============================================================================
190 struct TSearchersDeleter : public SMESH_subMeshEventListener
193 string myMeshPartIOR;
195 TSearchersDeleter(): SMESH_subMeshEventListener( false, // won't be deleted by submesh
196 "SMESH_MeshEditor_i::TSearchersDeleter"),
198 //!< Delete theNodeSearcher
201 if ( theNodeSearcher ) delete theNodeSearcher; theNodeSearcher = 0;
202 if ( theElementSearcher ) delete theElementSearcher; theElementSearcher = 0;
204 typedef map < int, SMESH_subMesh * > TDependsOnMap;
205 //!< The meshod called by submesh: do my main job
206 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
207 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
209 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
211 Unset( sm->GetFather() );
214 //!< set self on all submeshes and delete theNodeSearcher if other mesh is set
215 void Set(SMESH_Mesh* mesh, const string& meshPartIOR = string())
217 if ( myMesh != mesh || myMeshPartIOR != meshPartIOR)
224 myMeshPartIOR = meshPartIOR;
225 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
226 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
227 TDependsOnMap::const_iterator sm;
228 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
229 sm->second->SetEventListener( this, 0, sm->second );
233 //!< delete self from all submeshes
234 void Unset(SMESH_Mesh* mesh)
236 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
237 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
238 TDependsOnMap::const_iterator sm;
239 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
240 sm->second->DeleteEventListener( this );
245 } theSearchersDeleter;
247 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
249 TCollection_AsciiString typeStr;
250 switch ( theMirrorType ) {
251 case SMESH::SMESH_MeshEditor::POINT:
252 typeStr = "SMESH.SMESH_MeshEditor.POINT";
254 case SMESH::SMESH_MeshEditor::AXIS:
255 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
258 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
262 //================================================================================
264 * \brief function for conversion of long_array to TIDSortedElemSet
265 * \param IDs - array of IDs
266 * \param aMesh - mesh
267 * \param aMap - collection to fill
268 * \param aType - element type
270 //================================================================================
272 void arrayToSet(const SMESH::long_array & IDs,
273 const SMESHDS_Mesh* aMesh,
274 TIDSortedElemSet& aMap,
275 const SMDSAbs_ElementType aType = SMDSAbs_All )
277 for (int i=0; i<IDs.length(); i++) {
278 CORBA::Long ind = IDs[i];
279 const SMDS_MeshElement * elem =
280 (aType == SMDSAbs_Node ? aMesh->FindNode(ind) : aMesh->FindElement(ind));
281 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
282 aMap.insert( aMap.end(), elem );
285 //================================================================================
287 * \brief Retrieve elements of given type from SMESH_IDSource
289 //================================================================================
291 bool idSourceToSet(SMESH::SMESH_IDSource_ptr theIDSource,
292 const SMESHDS_Mesh* theMeshDS,
293 TIDSortedElemSet& theElemSet,
294 const SMDSAbs_ElementType theType,
295 const bool emptyIfIsMesh=false)
298 if ( CORBA::is_nil( theIDSource ) )
300 if ( emptyIfIsMesh && SMESH::DownCast<SMESH_Mesh_i*>( theIDSource ))
303 SMESH::long_array_var anIDs = theIDSource->GetIDs();
304 if ( anIDs->length() == 0 )
306 SMESH::array_of_ElementType_var types = theIDSource->GetTypes();
307 if ( types->length() == 1 && types[0] == SMESH::NODE ) // group of nodes
309 if ( theType == SMDSAbs_All || theType == SMDSAbs_Node )
310 arrayToSet( anIDs, theMeshDS, theElemSet, SMDSAbs_Node );
316 arrayToSet( anIDs, theMeshDS, theElemSet, theType);
317 return bool(anIDs->length()) == bool(theElemSet.size());
321 //================================================================================
323 * \brief Retrieve nodes from SMESH_IDSource
325 //================================================================================
327 void idSourceToNodeSet(SMESH::SMESH_IDSource_ptr theObject,
328 const SMESHDS_Mesh* theMeshDS,
329 TIDSortedNodeSet& theNodeSet)
332 if ( CORBA::is_nil( theObject ) )
334 SMESH::array_of_ElementType_var types = theObject->GetTypes();
335 SMESH::long_array_var aElementsId = theObject->GetIDs();
336 if ( types->length() == 1 && types[0] == SMESH::NODE)
338 for(int i = 0; i < aElementsId->length(); i++)
339 if ( const SMDS_MeshNode * n = theMeshDS->FindNode( aElementsId[i] ))
340 theNodeSet.insert( theNodeSet.end(), n);
342 else if ( SMESH::DownCast<SMESH_Mesh_i*>( theObject ))
344 SMDS_NodeIteratorPtr nIt = theMeshDS->nodesIterator();
345 while ( nIt->more( ))
346 if( const SMDS_MeshElement * elem = nIt->next() )
347 theNodeSet.insert( elem->begin_nodes(), elem->end_nodes());
351 for(int i = 0; i < aElementsId->length(); i++)
352 if( const SMDS_MeshElement * elem = theMeshDS->FindElement( aElementsId[i] ))
353 theNodeSet.insert( elem->begin_nodes(), elem->end_nodes());
357 //================================================================================
359 * \brief Returns elements connected to the given elements
361 //================================================================================
363 void getElementsAround(const TIDSortedElemSet& theElements,
364 const SMESHDS_Mesh* theMeshDS,
365 TIDSortedElemSet& theElementsAround)
367 if ( theElements.empty() ) return;
369 SMDSAbs_ElementType elemType = (*theElements.begin())->GetType();
370 bool sameElemType = ( elemType == (*theElements.rbegin())->GetType() );
372 theMeshDS->GetMeshInfo().NbElements( elemType ) == theElements.size() )
373 return; // all the elements are in theElements
376 elemType = SMDSAbs_All;
378 TIDSortedElemSet visitedNodes;
379 TIDSortedElemSet::const_iterator elemIt = theElements.begin();
380 for ( ; elemIt != theElements.end(); ++elemIt )
382 const SMDS_MeshElement* e = *elemIt;
383 int i = e->NbCornerNodes();
386 const SMDS_MeshNode* n = e->GetNode( i );
387 if ( visitedNodes.insert( n ).second )
389 SMDS_ElemIteratorPtr invIt = n->GetInverseElementIterator(elemType);
390 while ( invIt->more() )
392 const SMDS_MeshElement* elemAround = invIt->next();
393 if ( !theElements.count( elemAround ))
394 theElementsAround.insert( elemAround );
401 //================================================================================
403 * \brief Return a string used to detect change of mesh part on which theElementSearcher
404 * is going to be used
406 //================================================================================
408 string getPartIOR( SMESH::SMESH_IDSource_ptr theMeshPart, SMESH::ElementType type)
410 string partIOR = SMESH_Gen_i::GetORB()->object_to_string( theMeshPart );
411 if ( SMESH_Group_i* group_i = SMESH::DownCast<SMESH_Group_i*>( theMeshPart ))
412 // take into account passible group modification
413 partIOR += SMESH_Comment( ((SMESHDS_Group*)group_i->GetGroupDS())->SMDSGroup().Tic() );
414 partIOR += SMESH_Comment( type );
418 } // namespace MeshEditor_I
420 using namespace MeshEditor_I;
422 //=============================================================================
426 //=============================================================================
428 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview):
430 myMesh( &theMesh->GetImpl() ),
432 myIsPreviewMode ( isPreview ),
438 //================================================================================
442 //================================================================================
444 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
446 deleteAuxIDSources();
447 delete myPreviewMesh; myPreviewMesh = 0;
448 delete myPreviewEditor; myPreviewEditor = 0;
451 //================================================================================
453 * \brief Clear members
455 //================================================================================
457 void SMESH_MeshEditor_i::initData(bool deleteSearchers)
459 if ( myIsPreviewMode ) {
460 if ( myPreviewMesh ) myPreviewMesh->Clear();
463 if ( deleteSearchers )
464 TSearchersDeleter::Delete();
466 getEditor().GetError().reset();
467 getEditor().CrearLastCreated();
470 //================================================================================
472 * \brief Increment mesh modif time and optionally record that the performed
473 * modification may influence futher mesh re-compute.
474 * \param [in] isReComputeSafe - true if the modification does not infulence
475 * futher mesh re-compute
477 //================================================================================
479 void SMESH_MeshEditor_i::declareMeshModified( bool isReComputeSafe )
481 myMesh->GetMeshDS()->Modified();
482 if ( !isReComputeSafe )
483 myMesh->SetIsModified( true );
486 //================================================================================
488 * \brief Return either myEditor or myPreviewEditor depending on myIsPreviewMode.
489 * WARNING: in preview mode call getPreviewMesh() before getEditor()!
491 //================================================================================
493 ::SMESH_MeshEditor& SMESH_MeshEditor_i::getEditor()
495 if ( myIsPreviewMode && !myPreviewEditor ) {
496 if ( !myPreviewMesh ) getPreviewMesh();
497 myPreviewEditor = new ::SMESH_MeshEditor( myPreviewMesh );
499 return myIsPreviewMode ? *myPreviewEditor : myEditor;
502 //================================================================================
504 * \brief Initialize and return myPreviewMesh
505 * \param previewElements - type of elements to show in preview
507 * WARNING: call it once par a method!
509 //================================================================================
511 TPreviewMesh * SMESH_MeshEditor_i::getPreviewMesh(SMDSAbs_ElementType previewElements)
513 if ( !myPreviewMesh || myPreviewMesh->myPreviewType != previewElements )
515 delete myPreviewEditor;
517 delete myPreviewMesh;
518 myPreviewMesh = new TPreviewMesh( previewElements );
520 myPreviewMesh->Clear();
521 return myPreviewMesh;
524 //================================================================================
526 * Return data of mesh edition preview
528 //================================================================================
530 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
531 throw (SALOME::SALOME_Exception)
534 const bool hasBadElems = ( getEditor().GetError() && getEditor().GetError()->HasBadElems() );
536 if ( myIsPreviewMode || hasBadElems ) { // --- MeshPreviewStruct filling ---
538 list<int> aNodesConnectivity;
539 typedef map<int, int> TNodesMap;
542 SMESHDS_Mesh* aMeshDS;
543 std::auto_ptr< SMESH_MeshPartDS > aMeshPartDS;
545 aMeshPartDS.reset( new SMESH_MeshPartDS( getEditor().GetError()->myBadElements ));
546 aMeshDS = aMeshPartDS.get();
549 aMeshDS = getEditor().GetMeshDS();
551 myPreviewData = new SMESH::MeshPreviewStruct();
552 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
555 SMDSAbs_ElementType previewType = SMDSAbs_All;
557 if (TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( getEditor().GetMesh() )) {
558 previewType = aPreviewMesh->myPreviewType;
559 switch ( previewType ) {
560 case SMDSAbs_Edge : break;
561 case SMDSAbs_Face : break;
562 case SMDSAbs_Volume: break;
564 if ( aMeshDS->GetMeshInfo().NbElements() == 0 ) previewType = SMDSAbs_Node;
568 myPreviewData->elementTypes.length( aMeshDS->GetMeshInfo().NbElements( previewType ));
570 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator(previewType);
572 while ( itMeshElems->more() ) {
573 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
574 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
575 while ( itElemNodes->more() ) {
576 const SMDS_MeshNode* aMeshNode =
577 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
578 int aNodeID = aMeshNode->GetID();
579 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
580 if ( anIter == nodesMap.end() ) {
581 // filling the nodes coordinates
582 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
583 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
584 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
585 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
588 aNodesConnectivity.push_back(anIter->second);
591 // filling the elements types
592 SMDSAbs_ElementType aType = aMeshElem->GetType();
593 bool isPoly = aMeshElem->IsPoly();
595 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
596 myPreviewData->elementTypes[i].isPoly = isPoly;
597 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
601 myPreviewData->nodesXYZ.length( j );
603 // filling the elements connectivities
604 list<int>::iterator aConnIter = aNodesConnectivity.begin();
605 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
606 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
607 myPreviewData->elementConnectivities[i] = *aConnIter;
610 return myPreviewData._retn();
611 SMESH_CATCH( SMESH::throwCorbaException );
615 //================================================================================
617 * \brief Returns list of it's IDs of created nodes
618 * \retval SMESH::long_array* - list of node ID
620 //================================================================================
622 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
623 throw (SALOME::SALOME_Exception)
626 SMESH::long_array_var myLastCreatedNodes = new SMESH::long_array();
628 const SMESH_SequenceOfElemPtr& aSeq = getEditor().GetLastCreatedNodes();
629 myLastCreatedNodes->length( aSeq.Length() );
630 for (int i = 1; i <= aSeq.Length(); i++)
631 myLastCreatedNodes[i-1] = aSeq.Value(i)->GetID();
633 return myLastCreatedNodes._retn();
634 SMESH_CATCH( SMESH::throwCorbaException );
638 //================================================================================
640 * \brief Returns list of it's IDs of created elements
641 * \retval SMESH::long_array* - list of elements' ID
643 //================================================================================
645 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
646 throw (SALOME::SALOME_Exception)
649 SMESH::long_array_var myLastCreatedElems = new SMESH::long_array();
651 const SMESH_SequenceOfElemPtr& aSeq = getEditor().GetLastCreatedElems();
652 myLastCreatedElems->length( aSeq.Length() );
653 for ( int i = 1; i <= aSeq.Length(); i++ )
654 myLastCreatedElems[i-1] = aSeq.Value(i)->GetID();
656 return myLastCreatedElems._retn();
657 SMESH_CATCH( SMESH::throwCorbaException );
661 //=======================================================================
662 //function : ClearLastCreated
663 //purpose : Clears sequences of last created elements and nodes
664 //=======================================================================
666 void SMESH_MeshEditor_i::ClearLastCreated() throw (SALOME::SALOME_Exception)
669 getEditor().CrearLastCreated();
670 SMESH_CATCH( SMESH::throwCorbaException );
673 //=======================================================================
675 * Returns description of an error/warning occured during the last operation
677 //=======================================================================
679 SMESH::ComputeError* SMESH_MeshEditor_i::GetLastError()
680 throw (SALOME::SALOME_Exception)
683 SMESH::ComputeError_var errOut = new SMESH::ComputeError;
684 SMESH_ComputeErrorPtr& errIn = getEditor().GetError();
685 if ( errIn && !errIn->IsOK() )
687 errOut->code = -( errIn->myName < 0 ? errIn->myName + 1: errIn->myName ); // -1 -> 0
688 errOut->comment = errIn->myComment.c_str();
689 errOut->subShapeID = -1;
690 errOut->hasBadMesh = !errIn->myBadElements.empty();
695 errOut->subShapeID = -1;
696 errOut->hasBadMesh = false;
699 return errOut._retn();
700 SMESH_CATCH( SMESH::throwCorbaException );
704 //=======================================================================
705 //function : MakeIDSource
706 //purpose : Wrap a sequence of ids in a SMESH_IDSource
707 //=======================================================================
709 struct SMESH_MeshEditor_i::_IDSource : public POA_SMESH::SMESH_IDSource
711 SMESH::long_array _ids;
712 SMESH::ElementType _type;
713 SMESH::SMESH_Mesh_ptr _mesh;
714 SMESH::long_array* GetIDs() { return new SMESH::long_array( _ids ); }
715 SMESH::long_array* GetMeshInfo() { return 0; }
716 SMESH::SMESH_Mesh_ptr GetMesh() { return SMESH::SMESH_Mesh::_duplicate( _mesh ); }
717 bool IsMeshInfoCorrect() { return true; }
718 SMESH::array_of_ElementType* GetTypes()
720 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
721 if ( _ids.length() > 0 ) {
725 return types._retn();
729 SMESH::SMESH_IDSource_ptr SMESH_MeshEditor_i::MakeIDSource(const SMESH::long_array& ids,
730 SMESH::ElementType type)
732 if ( myAuxIDSources.size() > 10 )
733 deleteAuxIDSources();
735 _IDSource* idSrc = new _IDSource;
736 idSrc->_mesh = myMesh_i->_this();
739 myAuxIDSources.push_back( idSrc );
741 SMESH::SMESH_IDSource_var anIDSourceVar = idSrc->_this();
743 return anIDSourceVar._retn();
746 bool SMESH_MeshEditor_i::IsTemporaryIDSource( SMESH::SMESH_IDSource_ptr& idSource )
748 return SMESH::DownCast<SMESH_MeshEditor_i::_IDSource*>( idSource );
751 void SMESH_MeshEditor_i::deleteAuxIDSources()
753 std::list< _IDSource* >::iterator idSrcIt = myAuxIDSources.begin();
754 for ( ; idSrcIt != myAuxIDSources.end(); ++idSrcIt )
756 myAuxIDSources.clear();
759 //=============================================================================
763 //=============================================================================
766 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
767 throw (SALOME::SALOME_Exception)
774 for (int i = 0; i < IDsOfElements.length(); i++)
775 IdList.push_back( IDsOfElements[i] );
777 // Update Python script
778 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
781 bool ret = getEditor().Remove( IdList, false );
783 declareMeshModified( /*isReComputeSafe=*/ IDsOfElements.length() == 0 ); // issue 0020693
786 SMESH_CATCH( SMESH::throwCorbaException );
790 //=============================================================================
794 //=============================================================================
796 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
797 throw (SALOME::SALOME_Exception)
803 for (int i = 0; i < IDsOfNodes.length(); i++)
804 IdList.push_back( IDsOfNodes[i] );
806 // Update Python script
807 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
809 bool ret = getEditor().Remove( IdList, true );
811 declareMeshModified( /*isReComputeSafe=*/ !ret ); // issue 0020693
814 SMESH_CATCH( SMESH::throwCorbaException );
818 //=============================================================================
822 //=============================================================================
824 CORBA::Long SMESH_MeshEditor_i::RemoveOrphanNodes()
825 throw (SALOME::SALOME_Exception)
830 // Update Python script
831 TPythonDump() << "nbRemoved = " << this << ".RemoveOrphanNodes()";
833 // Create filter to find all orphan nodes
834 SMESH::Controls::Filter::TIdSequence seq;
835 SMESH::Controls::PredicatePtr predicate( new SMESH::Controls::FreeNodes() );
836 SMESH::Controls::Filter::GetElementsId( getMeshDS(), predicate, seq );
838 // remove orphan nodes (if there are any)
840 for ( int i = 0; i < seq.size(); i++ )
841 IdList.push_back( seq[i] );
843 int nbNodesBefore = myMesh->NbNodes();
844 getEditor().Remove( IdList, true );
845 int nbNodesAfter = myMesh->NbNodes();
847 declareMeshModified( /*isReComputeSafe=*/ IdList.size() == 0 ); // issue 0020693
848 return nbNodesBefore - nbNodesAfter;
850 SMESH_CATCH( SMESH::throwCorbaException );
854 //=============================================================================
858 //=============================================================================
860 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,CORBA::Double y, CORBA::Double z)
861 throw (SALOME::SALOME_Exception)
866 const SMDS_MeshNode* N = getMeshDS()->AddNode(x, y, z);
868 // Update Python script
869 TPythonDump() << "nodeID = " << this << ".AddNode( "
870 << TVar( x ) << ", " << TVar( y ) << ", " << TVar( z )<< " )";
872 declareMeshModified( /*isReComputeSafe=*/false );
875 SMESH_CATCH( SMESH::throwCorbaException );
879 //=============================================================================
881 * Create 0D element on the given node.
883 //=============================================================================
885 CORBA::Long SMESH_MeshEditor_i::Add0DElement(CORBA::Long IDOfNode)
886 throw (SALOME::SALOME_Exception)
891 const SMDS_MeshNode* aNode = getMeshDS()->FindNode(IDOfNode);
892 SMDS_MeshElement* elem = getMeshDS()->Add0DElement(aNode);
894 // Update Python script
895 TPythonDump() << "elem0d = " << this << ".Add0DElement( " << IDOfNode <<" )";
897 declareMeshModified( /*isReComputeSafe=*/false );
899 return elem ? elem->GetID() : 0;
901 SMESH_CATCH( SMESH::throwCorbaException );
905 //=============================================================================
907 * Create a ball element on the given node.
909 //=============================================================================
911 CORBA::Long SMESH_MeshEditor_i::AddBall(CORBA::Long IDOfNode, CORBA::Double diameter)
912 throw (SALOME::SALOME_Exception)
917 if ( diameter < std::numeric_limits<double>::min() )
918 THROW_SALOME_CORBA_EXCEPTION("Invalid diameter", SALOME::BAD_PARAM);
920 const SMDS_MeshNode* aNode = getMeshDS()->FindNode(IDOfNode);
921 SMDS_MeshElement* elem = getMeshDS()->AddBall(aNode, diameter);
923 // Update Python script
924 TPythonDump() << "ballElem = "
925 << this << ".AddBall( " << IDOfNode << ", " << diameter <<" )";
927 declareMeshModified( /*isReComputeSafe=*/false );
928 return elem ? elem->GetID() : 0;
930 SMESH_CATCH( SMESH::throwCorbaException );
934 //=============================================================================
936 * Create an edge, either linear and quadratic (this is determed
937 * by number of given nodes, two or three)
939 //=============================================================================
941 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
942 throw (SALOME::SALOME_Exception)
947 int NbNodes = IDsOfNodes.length();
948 SMDS_MeshElement* elem = 0;
951 CORBA::Long index1 = IDsOfNodes[0];
952 CORBA::Long index2 = IDsOfNodes[1];
953 elem = getMeshDS()->AddEdge( getMeshDS()->FindNode(index1),
954 getMeshDS()->FindNode(index2));
956 // Update Python script
957 TPythonDump() << "edge = " << this << ".AddEdge([ "
958 << index1 << ", " << index2 <<" ])";
961 CORBA::Long n1 = IDsOfNodes[0];
962 CORBA::Long n2 = IDsOfNodes[1];
963 CORBA::Long n12 = IDsOfNodes[2];
964 elem = getMeshDS()->AddEdge( getMeshDS()->FindNode(n1),
965 getMeshDS()->FindNode(n2),
966 getMeshDS()->FindNode(n12));
967 // Update Python script
968 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
969 <<n1<<", "<<n2<<", "<<n12<<" ])";
972 declareMeshModified( /*isReComputeSafe=*/false );
973 return elem ? elem->GetID() : 0;
975 SMESH_CATCH( SMESH::throwCorbaException );
979 //=============================================================================
983 //=============================================================================
985 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
986 throw (SALOME::SALOME_Exception)
991 int NbNodes = IDsOfNodes.length();
997 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
998 for (int i = 0; i < NbNodes; i++)
999 nodes[i] = getMeshDS()->FindNode(IDsOfNodes[i]);
1001 SMDS_MeshElement* elem = 0;
1003 case 3: elem = getMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]); break;
1004 case 4: elem = getMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]); break;
1005 case 6: elem = getMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
1006 nodes[4], nodes[5]); break;
1007 case 7: elem = getMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
1008 nodes[4], nodes[5], nodes[6]); break;
1009 case 8: elem = getMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
1010 nodes[4], nodes[5], nodes[6], nodes[7]); break;
1011 case 9: elem = getMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
1012 nodes[4], nodes[5], nodes[6], nodes[7],
1014 default: elem = getMeshDS()->AddPolygonalFace(nodes);
1017 // Update Python script
1018 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
1020 declareMeshModified( /*isReComputeSafe=*/false );
1022 return elem ? elem->GetID() : 0;
1024 SMESH_CATCH( SMESH::throwCorbaException );
1028 //=============================================================================
1032 //=============================================================================
1033 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace (const SMESH::long_array & IDsOfNodes)
1034 throw (SALOME::SALOME_Exception)
1039 int NbNodes = IDsOfNodes.length();
1040 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
1041 for (int i = 0; i < NbNodes; i++)
1042 nodes[i] = getMeshDS()->FindNode(IDsOfNodes[i]);
1044 const SMDS_MeshElement* elem = getMeshDS()->AddPolygonalFace(nodes);
1046 // Update Python script
1047 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
1049 declareMeshModified( /*isReComputeSafe=*/false );
1050 return elem ? elem->GetID() : 0;
1052 SMESH_CATCH( SMESH::throwCorbaException );
1056 //=============================================================================
1058 * Create volume, either linear and quadratic (this is determed
1059 * by number of given nodes)
1061 //=============================================================================
1063 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
1064 throw (SALOME::SALOME_Exception)
1069 int NbNodes = IDsOfNodes.length();
1070 vector< const SMDS_MeshNode*> n(NbNodes);
1071 for(int i=0;i<NbNodes;i++)
1072 n[i]= getMeshDS()->FindNode(IDsOfNodes[i]);
1074 SMDS_MeshElement* elem = 0;
1077 case 4 :elem = getMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
1078 case 5 :elem = getMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
1079 case 6 :elem = getMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
1080 case 8 :elem = getMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
1081 case 10:elem = getMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
1082 n[6],n[7],n[8],n[9]);
1084 case 12:elem = getMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
1085 n[6],n[7],n[8],n[9],n[10],n[11]);
1087 case 13:elem = getMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
1088 n[7],n[8],n[9],n[10],n[11],n[12]);
1090 case 15:elem = getMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
1091 n[9],n[10],n[11],n[12],n[13],n[14]);
1093 case 20:elem = getMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
1094 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
1095 n[15],n[16],n[17],n[18],n[19]);
1097 case 27:elem = getMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
1098 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
1099 n[15],n[16],n[17],n[18],n[19],
1100 n[20],n[21],n[22],n[23],n[24],n[25],n[26]);
1104 // Update Python script
1105 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
1107 declareMeshModified( /*isReComputeSafe=*/false );
1108 return elem ? elem->GetID() : 0;
1110 SMESH_CATCH( SMESH::throwCorbaException );
1114 //=============================================================================
1116 * AddPolyhedralVolume
1118 //=============================================================================
1119 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume (const SMESH::long_array & IDsOfNodes,
1120 const SMESH::long_array & Quantities)
1121 throw (SALOME::SALOME_Exception)
1126 int NbNodes = IDsOfNodes.length();
1127 std::vector<const SMDS_MeshNode*> n (NbNodes);
1128 for (int i = 0; i < NbNodes; i++)
1130 const SMDS_MeshNode* aNode = getMeshDS()->FindNode(IDsOfNodes[i]);
1131 if (!aNode) return 0;
1135 int NbFaces = Quantities.length();
1136 std::vector<int> q (NbFaces);
1137 for (int j = 0; j < NbFaces; j++)
1138 q[j] = Quantities[j];
1140 const SMDS_MeshElement* elem = getMeshDS()->AddPolyhedralVolume(n, q);
1142 // Update Python script
1143 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
1144 << IDsOfNodes << ", " << Quantities << " )";
1146 declareMeshModified( /*isReComputeSafe=*/false );
1147 return elem ? elem->GetID() : 0;
1149 SMESH_CATCH( SMESH::throwCorbaException );
1153 //=============================================================================
1155 * AddPolyhedralVolumeByFaces
1157 //=============================================================================
1159 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces (const SMESH::long_array & IdsOfFaces)
1160 throw (SALOME::SALOME_Exception)
1165 int NbFaces = IdsOfFaces.length();
1166 std::vector<const SMDS_MeshNode*> poly_nodes;
1167 std::vector<int> quantities (NbFaces);
1169 for (int i = 0; i < NbFaces; i++) {
1170 const SMDS_MeshElement* aFace = getMeshDS()->FindElement(IdsOfFaces[i]);
1171 quantities[i] = aFace->NbNodes();
1173 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
1174 while (It->more()) {
1175 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
1179 const SMDS_MeshElement* elem = getMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
1181 // Update Python script
1182 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
1183 << IdsOfFaces << " )";
1185 declareMeshModified( /*isReComputeSafe=*/false );
1186 return elem ? elem->GetID() : 0;
1188 SMESH_CATCH( SMESH::throwCorbaException );
1192 //=============================================================================
1194 // \brief Create 0D elements on all nodes of the given object except those
1195 // nodes on which a 0D element already exists.
1196 // \param theObject object on whose nodes 0D elements will be created.
1197 // \param theGroupName optional name of a group to add 0D elements created
1198 // and/or found on nodes of \a theObject.
1199 // \return an object (a new group or a temporary SMESH_IDSource) holding
1200 // ids of new and/or found 0D elements.
1202 //=============================================================================
1204 SMESH::SMESH_IDSource_ptr
1205 SMESH_MeshEditor_i::Create0DElementsOnAllNodes(SMESH::SMESH_IDSource_ptr theObject,
1206 const char* theGroupName)
1207 throw (SALOME::SALOME_Exception)
1212 SMESH::SMESH_IDSource_var result;
1215 TIDSortedElemSet elements, elems0D;
1216 if ( idSourceToSet( theObject, getMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
1217 getEditor().Create0DElementsOnAllNodes( elements, elems0D );
1219 SMESH::long_array_var newElems = new SMESH::long_array;
1220 newElems->length( elems0D.size() );
1221 TIDSortedElemSet::iterator eIt = elems0D.begin();
1222 for ( size_t i = 0; i < elems0D.size(); ++i, ++eIt )
1223 newElems[ i ] = (*eIt)->GetID();
1225 SMESH::SMESH_GroupBase_var groupToFill;
1226 if ( theGroupName && strlen( theGroupName ))
1228 // Get existing group named theGroupName
1229 SMESH::ListOfGroups_var groups = myMesh_i->GetGroups();
1230 for (int i = 0, nbGroups = groups->length(); i < nbGroups; i++ ) {
1231 SMESH::SMESH_GroupBase_var group = groups[i];
1232 if ( !group->_is_nil() ) {
1233 CORBA::String_var name = group->GetName();
1234 if ( strcmp( name.in(), theGroupName ) == 0 && group->GetType() == SMESH::ELEM0D ) {
1235 groupToFill = group;
1240 if ( groupToFill->_is_nil() )
1241 groupToFill = myMesh_i->CreateGroup( SMESH::ELEM0D, theGroupName );
1242 else if ( !SMESH::DownCast< SMESH_Group_i* > ( groupToFill ))
1243 groupToFill = myMesh_i->ConvertToStandalone( groupToFill );
1246 if ( SMESH_Group_i* group_i = SMESH::DownCast< SMESH_Group_i* > ( groupToFill ))
1248 group_i->Add( newElems );
1249 result = SMESH::SMESH_IDSource::_narrow( groupToFill );
1250 pyDump << groupToFill;
1254 result = MakeIDSource( newElems, SMESH::ELEM0D );
1255 pyDump << "elem0DIDs";
1258 pyDump << " = " << this << ".Create0DElementsOnAllNodes( "
1259 << theObject << ", '" << theGroupName << "' )";
1261 return result._retn();
1263 SMESH_CATCH( SMESH::throwCorbaException );
1267 //=============================================================================
1269 * \brief Bind a node to a vertex
1270 * \param NodeID - node ID
1271 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
1272 * \retval boolean - false if NodeID or VertexID is invalid
1274 //=============================================================================
1276 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
1277 throw (SALOME::SALOME_Exception)
1281 SMESHDS_Mesh * mesh = getMeshDS();
1282 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
1284 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
1286 if ( mesh->MaxShapeIndex() < VertexID )
1287 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
1289 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
1290 if ( shape.ShapeType() != TopAbs_VERTEX )
1291 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
1293 mesh->SetNodeOnVertex( node, VertexID );
1295 myMesh->SetIsModified( true );
1297 SMESH_CATCH( SMESH::throwCorbaException );
1300 //=============================================================================
1302 * \brief Store node position on an edge
1303 * \param NodeID - node ID
1304 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
1305 * \param paramOnEdge - parameter on edge where the node is located
1306 * \retval boolean - false if any parameter is invalid
1308 //=============================================================================
1310 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
1311 CORBA::Double paramOnEdge)
1312 throw (SALOME::SALOME_Exception)
1316 SMESHDS_Mesh * mesh = getMeshDS();
1317 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
1319 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
1321 if ( mesh->MaxShapeIndex() < EdgeID )
1322 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
1324 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
1325 if ( shape.ShapeType() != TopAbs_EDGE )
1326 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
1329 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
1330 if ( paramOnEdge < f || paramOnEdge > l )
1331 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
1333 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
1335 myMesh->SetIsModified( true );
1337 SMESH_CATCH( SMESH::throwCorbaException );
1340 //=============================================================================
1342 * \brief Store node position on a face
1343 * \param NodeID - node ID
1344 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
1345 * \param u - U parameter on face where the node is located
1346 * \param v - V parameter on face where the node is located
1347 * \retval boolean - false if any parameter is invalid
1349 //=============================================================================
1351 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
1352 CORBA::Double u, CORBA::Double v)
1353 throw (SALOME::SALOME_Exception)
1356 SMESHDS_Mesh * mesh = getMeshDS();
1357 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
1359 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
1361 if ( mesh->MaxShapeIndex() < FaceID )
1362 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
1364 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
1365 if ( shape.ShapeType() != TopAbs_FACE )
1366 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
1368 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
1369 bool isOut = ( u < surf.FirstUParameter() ||
1370 u > surf.LastUParameter() ||
1371 v < surf.FirstVParameter() ||
1372 v > surf.LastVParameter() );
1376 MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of "
1377 << " u( " << surf.FirstUParameter()
1378 << "," << surf.LastUParameter()
1379 << ") v( " << surf.FirstVParameter()
1380 << "," << surf.LastVParameter() << ")" );
1382 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
1385 mesh->SetNodeOnFace( node, FaceID, u, v );
1386 myMesh->SetIsModified( true );
1388 SMESH_CATCH( SMESH::throwCorbaException );
1391 //=============================================================================
1393 * \brief Bind a node to a solid
1394 * \param NodeID - node ID
1395 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
1396 * \retval boolean - false if NodeID or SolidID is invalid
1398 //=============================================================================
1400 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
1401 throw (SALOME::SALOME_Exception)
1404 SMESHDS_Mesh * mesh = getMeshDS();
1405 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
1407 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
1409 if ( mesh->MaxShapeIndex() < SolidID )
1410 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
1412 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
1413 if ( shape.ShapeType() != TopAbs_SOLID &&
1414 shape.ShapeType() != TopAbs_SHELL)
1415 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
1417 mesh->SetNodeInVolume( node, SolidID );
1419 SMESH_CATCH( SMESH::throwCorbaException );
1422 //=============================================================================
1424 * \brief Bind an element to a shape
1425 * \param ElementID - element ID
1426 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
1428 //=============================================================================
1430 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
1431 CORBA::Long ShapeID)
1432 throw (SALOME::SALOME_Exception)
1435 SMESHDS_Mesh * mesh = getMeshDS();
1436 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
1438 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
1440 if ( mesh->MaxShapeIndex() < ShapeID || ShapeID < 1 )
1441 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
1443 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
1444 if ( shape.ShapeType() != TopAbs_EDGE &&
1445 shape.ShapeType() != TopAbs_FACE &&
1446 shape.ShapeType() != TopAbs_SOLID &&
1447 shape.ShapeType() != TopAbs_SHELL )
1448 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
1450 mesh->SetMeshElementOnShape( elem, ShapeID );
1452 myMesh->SetIsModified( true );
1454 SMESH_CATCH( SMESH::throwCorbaException );
1457 //=============================================================================
1461 //=============================================================================
1463 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
1464 CORBA::Long NodeID2)
1465 throw (SALOME::SALOME_Exception)
1470 const SMDS_MeshNode * n1 = getMeshDS()->FindNode( NodeID1 );
1471 const SMDS_MeshNode * n2 = getMeshDS()->FindNode( NodeID2 );
1475 // Update Python script
1476 TPythonDump() << "isDone = " << this << ".InverseDiag( "
1477 << NodeID1 << ", " << NodeID2 << " )";
1479 int ret = getEditor().InverseDiag ( n1, n2 );
1481 declareMeshModified( /*isReComputeSafe=*/false );
1484 SMESH_CATCH( SMESH::throwCorbaException );
1488 //=============================================================================
1492 //=============================================================================
1494 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
1495 CORBA::Long NodeID2)
1496 throw (SALOME::SALOME_Exception)
1501 const SMDS_MeshNode * n1 = getMeshDS()->FindNode( NodeID1 );
1502 const SMDS_MeshNode * n2 = getMeshDS()->FindNode( NodeID2 );
1506 // Update Python script
1507 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
1508 << NodeID1 << ", " << NodeID2 << " )";
1511 bool stat = getEditor().DeleteDiag ( n1, n2 );
1513 declareMeshModified( /*isReComputeSafe=*/!stat );
1517 SMESH_CATCH( SMESH::throwCorbaException );
1521 //=============================================================================
1525 //=============================================================================
1527 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
1528 throw (SALOME::SALOME_Exception)
1533 for (int i = 0; i < IDsOfElements.length(); i++)
1535 CORBA::Long index = IDsOfElements[i];
1536 const SMDS_MeshElement * elem = getMeshDS()->FindElement(index);
1538 getEditor().Reorient( elem );
1540 // Update Python script
1541 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
1543 declareMeshModified( /*isReComputeSafe=*/ IDsOfElements.length() == 0 );
1546 SMESH_CATCH( SMESH::throwCorbaException );
1550 //=============================================================================
1554 //=============================================================================
1556 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
1557 throw (SALOME::SALOME_Exception)
1562 TPythonDump aTPythonDump; // suppress dump in Reorient()
1564 SMESH::long_array_var anElementsId = theObject->GetIDs();
1565 CORBA::Boolean isDone = Reorient(anElementsId);
1567 // Update Python script
1568 aTPythonDump << "isDone = " << this << ".ReorientObject( " << theObject << " )";
1570 declareMeshModified( /*isReComputeSafe=*/ anElementsId->length() == 0 );
1573 SMESH_CATCH( SMESH::throwCorbaException );
1577 //=======================================================================
1578 //function : Reorient2D
1579 //purpose : Reorient faces contained in \a the2Dgroup.
1580 // the2Dgroup - the mesh or its part to reorient
1581 // theDirection - desired direction of normal of \a theFace
1582 // theFace - ID of face whose orientation is checked.
1583 // It can be < 1 then \a thePoint is used to find a face.
1584 // thePoint - is used to find a face if \a theFace < 1.
1585 // return number of reoriented elements.
1586 //=======================================================================
1588 CORBA::Long SMESH_MeshEditor_i::Reorient2D(SMESH::SMESH_IDSource_ptr the2Dgroup,
1589 const SMESH::DirStruct& theDirection,
1590 CORBA::Long theFace,
1591 const SMESH::PointStruct& thePoint)
1592 throw (SALOME::SALOME_Exception)
1595 initData(/*deleteSearchers=*/false);
1597 TIDSortedElemSet elements;
1598 if ( !idSourceToSet( the2Dgroup, getMeshDS(), elements, SMDSAbs_Face, /*emptyIfIsMesh=*/1))
1599 THROW_SALOME_CORBA_EXCEPTION("No faces in given group", SALOME::BAD_PARAM);
1602 const SMDS_MeshElement* face = 0;
1605 face = getMeshDS()->FindElement( theFace );
1607 THROW_SALOME_CORBA_EXCEPTION("Inexistent face given", SALOME::BAD_PARAM);
1608 if ( face->GetType() != SMDSAbs_Face )
1609 THROW_SALOME_CORBA_EXCEPTION("Wrong element type", SALOME::BAD_PARAM);
1613 // create theElementSearcher if needed
1614 theSearchersDeleter.Set( myMesh, getPartIOR( the2Dgroup, SMESH::FACE ));
1615 if ( !theElementSearcher )
1617 if ( elements.empty() ) // search in the whole mesh
1619 if ( myMesh->NbFaces() == 0 )
1620 THROW_SALOME_CORBA_EXCEPTION("No faces in the mesh", SALOME::BAD_PARAM);
1622 theElementSearcher = SMESH_MeshAlgos::GetElementSearcher( *getMeshDS() );
1626 typedef SMDS_SetIterator<const SMDS_MeshElement*, TIDSortedElemSet::const_iterator > TIter;
1627 SMDS_ElemIteratorPtr elemsIt( new TIter( elements.begin(), elements.end() ));
1629 theElementSearcher = SMESH_MeshAlgos::GetElementSearcher( *getMeshDS(), elemsIt);
1633 gp_Pnt p( thePoint.x, thePoint.y, thePoint.z );
1634 face = theElementSearcher->FindClosestTo( p, SMDSAbs_Face );
1637 THROW_SALOME_CORBA_EXCEPTION("No face found by point", SALOME::INTERNAL_ERROR );
1638 if ( !elements.empty() && !elements.count( face ))
1639 THROW_SALOME_CORBA_EXCEPTION("Found face is not in the group", SALOME::BAD_PARAM );
1642 const SMESH::PointStruct * P = &theDirection.PS;
1643 gp_Vec dirVec( P->x, P->y, P->z );
1644 if ( dirVec.Magnitude() < std::numeric_limits< double >::min() )
1645 THROW_SALOME_CORBA_EXCEPTION("Zero size vector", SALOME::BAD_PARAM);
1647 int nbReori = getEditor().Reorient2D( elements, dirVec, face );
1650 declareMeshModified( /*isReComputeSafe=*/false );
1652 TPythonDump() << this << ".Reorient2D( "
1653 << the2Dgroup << ", "
1654 << theDirection << ", "
1656 << thePoint << " )";
1660 SMESH_CATCH( SMESH::throwCorbaException );
1664 //=============================================================================
1668 //=============================================================================
1670 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
1671 SMESH::NumericalFunctor_ptr Criterion,
1672 CORBA::Double MaxAngle)
1673 throw (SALOME::SALOME_Exception)
1678 SMESHDS_Mesh* aMesh = getMeshDS();
1679 TIDSortedElemSet faces;
1680 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1682 SMESH::NumericalFunctor_i* aNumericalFunctor =
1683 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1684 SMESH::Controls::NumericalFunctorPtr aCrit;
1685 if ( !aNumericalFunctor )
1686 aCrit.reset( new SMESH::Controls::MaxElementLength2D() );
1688 aCrit = aNumericalFunctor->GetNumericalFunctor();
1690 // Update Python script
1691 TPythonDump() << "isDone = " << this << ".TriToQuad( "
1692 << IDsOfElements << ", " << aNumericalFunctor << ", " << TVar( MaxAngle ) << " )";
1695 bool stat = getEditor().TriToQuad( faces, aCrit, MaxAngle );
1697 declareMeshModified( /*isReComputeSafe=*/!stat );
1700 SMESH_CATCH( SMESH::throwCorbaException );
1704 //=============================================================================
1708 //=============================================================================
1710 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1711 SMESH::NumericalFunctor_ptr Criterion,
1712 CORBA::Double MaxAngle)
1713 throw (SALOME::SALOME_Exception)
1718 TPythonDump aTPythonDump; // suppress dump in TriToQuad()
1719 SMESH::long_array_var anElementsId = theObject->GetIDs();
1720 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
1722 SMESH::NumericalFunctor_i* aNumericalFunctor =
1723 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1725 // Update Python script
1726 aTPythonDump << "isDone = " << this << ".TriToQuadObject("
1727 << theObject << ", " << aNumericalFunctor << ", " << TVar( MaxAngle ) << " )";
1731 SMESH_CATCH( SMESH::throwCorbaException );
1735 //=============================================================================
1739 //=============================================================================
1741 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
1742 SMESH::NumericalFunctor_ptr Criterion)
1743 throw (SALOME::SALOME_Exception)
1748 SMESHDS_Mesh* aMesh = getMeshDS();
1749 TIDSortedElemSet faces;
1750 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1752 SMESH::NumericalFunctor_i* aNumericalFunctor =
1753 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1754 SMESH::Controls::NumericalFunctorPtr aCrit;
1755 if ( !aNumericalFunctor )
1756 aCrit.reset( new SMESH::Controls::AspectRatio() );
1758 aCrit = aNumericalFunctor->GetNumericalFunctor();
1761 // Update Python script
1762 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1764 CORBA::Boolean stat = getEditor().QuadToTri( faces, aCrit );
1766 declareMeshModified( /*isReComputeSafe=*/false );
1769 SMESH_CATCH( SMESH::throwCorbaException );
1774 //=============================================================================
1778 //=============================================================================
1779 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1780 SMESH::NumericalFunctor_ptr Criterion)
1781 throw (SALOME::SALOME_Exception)
1786 TPythonDump aTPythonDump; // suppress dump in QuadToTri()
1788 SMESH::long_array_var anElementsId = theObject->GetIDs();
1789 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1791 SMESH::NumericalFunctor_i* aNumericalFunctor =
1792 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1794 // Update Python script
1795 aTPythonDump << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1797 declareMeshModified( /*isReComputeSafe=*/false );
1800 SMESH_CATCH( SMESH::throwCorbaException );
1805 //=============================================================================
1809 //=============================================================================
1810 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1811 CORBA::Boolean Diag13)
1812 throw (SALOME::SALOME_Exception)
1817 SMESHDS_Mesh* aMesh = getMeshDS();
1818 TIDSortedElemSet faces;
1819 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1821 // Update Python script
1822 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1823 << IDsOfElements << ", " << Diag13 << " )";
1825 CORBA::Boolean stat = getEditor().QuadToTri( faces, Diag13 );
1827 declareMeshModified( /*isReComputeSafe=*/ !stat );
1830 SMESH_CATCH( SMESH::throwCorbaException );
1835 //=============================================================================
1839 //=============================================================================
1840 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1841 CORBA::Boolean Diag13)
1842 throw (SALOME::SALOME_Exception)
1847 TPythonDump aTPythonDump; // suppress dump in SplitQuad()
1849 SMESH::long_array_var anElementsId = theObject->GetIDs();
1850 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1852 // Update Python script
1853 aTPythonDump << "isDone = " << this << ".SplitQuadObject( "
1854 << theObject << ", " << Diag13 << " )";
1856 declareMeshModified( /*isReComputeSafe=*/!isDone );
1859 SMESH_CATCH( SMESH::throwCorbaException );
1864 //=============================================================================
1868 //=============================================================================
1870 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1871 SMESH::NumericalFunctor_ptr Criterion)
1872 throw (SALOME::SALOME_Exception)
1877 const SMDS_MeshElement* quad = getMeshDS()->FindElement(IDOfQuad);
1878 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1880 SMESH::NumericalFunctor_i* aNumericalFunctor =
1881 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1882 SMESH::Controls::NumericalFunctorPtr aCrit;
1883 if (aNumericalFunctor)
1884 aCrit = aNumericalFunctor->GetNumericalFunctor();
1886 aCrit.reset(new SMESH::Controls::AspectRatio());
1888 int id = getEditor().BestSplit(quad, aCrit);
1889 declareMeshModified( /*isReComputeSafe=*/ id < 1 );
1892 SMESH_CATCH( SMESH::throwCorbaException );
1896 //================================================================================
1898 * \brief Split volumic elements into tetrahedrons
1900 //================================================================================
1902 void SMESH_MeshEditor_i::SplitVolumesIntoTetra (SMESH::SMESH_IDSource_ptr elems,
1903 CORBA::Short methodFlags)
1904 throw (SALOME::SALOME_Exception)
1909 SMESH::long_array_var anElementsId = elems->GetIDs();
1910 TIDSortedElemSet elemSet;
1911 arrayToSet( anElementsId, getMeshDS(), elemSet, SMDSAbs_Volume );
1913 getEditor().SplitVolumesIntoTetra( elemSet, int( methodFlags ));
1914 declareMeshModified( /*isReComputeSafe=*/true ); // it does not influence Compute()
1916 TPythonDump() << this << ".SplitVolumesIntoTetra( "
1917 << elems << ", " << methodFlags << " )";
1919 SMESH_CATCH( SMESH::throwCorbaException );
1922 //=======================================================================
1925 //=======================================================================
1928 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1929 const SMESH::long_array & IDsOfFixedNodes,
1930 CORBA::Long MaxNbOfIterations,
1931 CORBA::Double MaxAspectRatio,
1932 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1933 throw (SALOME::SALOME_Exception)
1935 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1936 MaxAspectRatio, Method, false );
1940 //=======================================================================
1941 //function : SmoothParametric
1943 //=======================================================================
1946 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1947 const SMESH::long_array & IDsOfFixedNodes,
1948 CORBA::Long MaxNbOfIterations,
1949 CORBA::Double MaxAspectRatio,
1950 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1951 throw (SALOME::SALOME_Exception)
1953 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1954 MaxAspectRatio, Method, true );
1958 //=======================================================================
1959 //function : SmoothObject
1961 //=======================================================================
1964 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1965 const SMESH::long_array & IDsOfFixedNodes,
1966 CORBA::Long MaxNbOfIterations,
1967 CORBA::Double MaxAspectRatio,
1968 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1969 throw (SALOME::SALOME_Exception)
1971 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1972 MaxAspectRatio, Method, false);
1976 //=======================================================================
1977 //function : SmoothParametricObject
1979 //=======================================================================
1982 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1983 const SMESH::long_array & IDsOfFixedNodes,
1984 CORBA::Long MaxNbOfIterations,
1985 CORBA::Double MaxAspectRatio,
1986 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1987 throw (SALOME::SALOME_Exception)
1989 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1990 MaxAspectRatio, Method, true);
1994 //=============================================================================
1998 //=============================================================================
2001 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
2002 const SMESH::long_array & IDsOfFixedNodes,
2003 CORBA::Long MaxNbOfIterations,
2004 CORBA::Double MaxAspectRatio,
2005 SMESH::SMESH_MeshEditor::Smooth_Method Method,
2007 throw (SALOME::SALOME_Exception)
2012 SMESHDS_Mesh* aMesh = getMeshDS();
2014 TIDSortedElemSet elements;
2015 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
2017 set<const SMDS_MeshNode*> fixedNodes;
2018 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
2019 CORBA::Long index = IDsOfFixedNodes[i];
2020 const SMDS_MeshNode * node = aMesh->FindNode(index);
2022 fixedNodes.insert( node );
2024 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
2025 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
2026 method = ::SMESH_MeshEditor::CENTROIDAL;
2028 getEditor().Smooth(elements, fixedNodes, method,
2029 MaxNbOfIterations, MaxAspectRatio, IsParametric );
2031 declareMeshModified( /*isReComputeSafe=*/true ); // does not prevent re-compute
2033 // Update Python script
2034 TPythonDump() << "isDone = " << this << "."
2035 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
2036 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
2037 << TVar( MaxNbOfIterations ) << ", " << TVar( MaxAspectRatio ) << ", "
2038 << "SMESH.SMESH_MeshEditor."
2039 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
2040 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
2044 SMESH_CATCH( SMESH::throwCorbaException );
2049 //=============================================================================
2053 //=============================================================================
2056 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
2057 const SMESH::long_array & IDsOfFixedNodes,
2058 CORBA::Long MaxNbOfIterations,
2059 CORBA::Double MaxAspectRatio,
2060 SMESH::SMESH_MeshEditor::Smooth_Method Method,
2062 throw (SALOME::SALOME_Exception)
2067 TPythonDump aTPythonDump; // suppress dump in smooth()
2069 SMESH::long_array_var anElementsId = theObject->GetIDs();
2070 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
2071 MaxAspectRatio, Method, IsParametric);
2073 // Update Python script
2074 aTPythonDump << "isDone = " << this << "."
2075 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
2076 << theObject << ", " << IDsOfFixedNodes << ", "
2077 << TVar( MaxNbOfIterations ) << ", " << TVar( MaxAspectRatio ) << ", "
2078 << "SMESH.SMESH_MeshEditor."
2079 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
2080 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
2084 SMESH_CATCH( SMESH::throwCorbaException );
2089 //=============================================================================
2093 //=============================================================================
2095 void SMESH_MeshEditor_i::RenumberNodes()
2096 throw (SALOME::SALOME_Exception)
2099 // Update Python script
2100 TPythonDump() << this << ".RenumberNodes()";
2102 getMeshDS()->Renumber( true );
2104 SMESH_CATCH( SMESH::throwCorbaException );
2107 //=============================================================================
2111 //=============================================================================
2113 void SMESH_MeshEditor_i::RenumberElements()
2114 throw (SALOME::SALOME_Exception)
2117 // Update Python script
2118 TPythonDump() << this << ".RenumberElements()";
2120 getMeshDS()->Renumber( false );
2122 SMESH_CATCH( SMESH::throwCorbaException );
2125 //=======================================================================
2127 * \brief Return groups by their IDs
2129 //=======================================================================
2131 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
2132 throw (SALOME::SALOME_Exception)
2137 myMesh_i->CreateGroupServants();
2138 return myMesh_i->GetGroups( *groupIDs );
2140 SMESH_CATCH( SMESH::throwCorbaException );
2144 //=======================================================================
2145 //function : rotationSweep
2147 //=======================================================================
2149 SMESH::ListOfGroups*
2150 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
2151 const SMESH::AxisStruct & theAxis,
2152 CORBA::Double theAngleInRadians,
2153 CORBA::Long theNbOfSteps,
2154 CORBA::Double theTolerance,
2155 const bool theMakeGroups,
2156 const SMDSAbs_ElementType theElementType)
2157 throw (SALOME::SALOME_Exception)
2162 TIDSortedElemSet inElements, copyElements;
2163 arrayToSet(theIDsOfElements, getMeshDS(), inElements, theElementType);
2165 TIDSortedElemSet* workElements = & inElements;
2166 bool makeWalls=true;
2167 if ( myIsPreviewMode )
2169 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
2170 getPreviewMesh( SMDSAbs_Face )->Copy( inElements, copyElements, select, avoid );
2171 workElements = & copyElements;
2172 //makeWalls = false;
2175 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
2176 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
2178 ::SMESH_MeshEditor::PGroupIDs groupIds =
2179 getEditor().RotationSweep (*workElements, Ax1, theAngleInRadians,
2180 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
2182 declareMeshModified( /*isReComputeSafe=*/true ); // does not influence Compute()
2184 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2186 SMESH_CATCH( SMESH::throwCorbaException );
2190 //=======================================================================
2191 //function : RotationSweep
2193 //=======================================================================
2195 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
2196 const SMESH::AxisStruct & theAxis,
2197 CORBA::Double theAngleInRadians,
2198 CORBA::Long theNbOfSteps,
2199 CORBA::Double theTolerance)
2200 throw (SALOME::SALOME_Exception)
2202 if ( !myIsPreviewMode ) {
2203 TPythonDump() << this << ".RotationSweep( "
2204 << theIDsOfElements << ", "
2206 << TVar( theAngleInRadians ) << ", "
2207 << TVar( theNbOfSteps ) << ", "
2208 << TVar( theTolerance ) << " )";
2210 rotationSweep(theIDsOfElements,
2218 //=======================================================================
2219 //function : RotationSweepMakeGroups
2221 //=======================================================================
2223 SMESH::ListOfGroups*
2224 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
2225 const SMESH::AxisStruct& theAxis,
2226 CORBA::Double theAngleInRadians,
2227 CORBA::Long theNbOfSteps,
2228 CORBA::Double theTolerance)
2229 throw (SALOME::SALOME_Exception)
2231 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2233 SMESH::ListOfGroups *aGroups = rotationSweep(theIDsOfElements,
2239 if (!myIsPreviewMode) {
2240 dumpGroupsList(aPythonDump, aGroups);
2241 aPythonDump << this << ".RotationSweepMakeGroups( "
2242 << theIDsOfElements << ", "
2244 << TVar( theAngleInRadians ) << ", "
2245 << TVar( theNbOfSteps ) << ", "
2246 << TVar( theTolerance ) << " )";
2251 //=======================================================================
2252 //function : RotationSweepObject
2254 //=======================================================================
2256 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
2257 const SMESH::AxisStruct & theAxis,
2258 CORBA::Double theAngleInRadians,
2259 CORBA::Long theNbOfSteps,
2260 CORBA::Double theTolerance)
2261 throw (SALOME::SALOME_Exception)
2263 if ( !myIsPreviewMode ) {
2264 TPythonDump() << this << ".RotationSweepObject( "
2265 << theObject << ", "
2267 << theAngleInRadians << ", "
2268 << theNbOfSteps << ", "
2269 << theTolerance << " )";
2271 SMESH::long_array_var anElementsId = theObject->GetIDs();
2272 rotationSweep(anElementsId,
2280 //=======================================================================
2281 //function : RotationSweepObject1D
2283 //=======================================================================
2285 void SMESH_MeshEditor_i::RotationSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
2286 const SMESH::AxisStruct & theAxis,
2287 CORBA::Double theAngleInRadians,
2288 CORBA::Long theNbOfSteps,
2289 CORBA::Double theTolerance)
2290 throw (SALOME::SALOME_Exception)
2292 if ( !myIsPreviewMode ) {
2293 TPythonDump() << this << ".RotationSweepObject1D( "
2294 << theObject << ", "
2296 << TVar( theAngleInRadians ) << ", "
2297 << TVar( theNbOfSteps ) << ", "
2298 << TVar( theTolerance ) << " )";
2300 SMESH::long_array_var anElementsId = theObject->GetIDs();
2301 rotationSweep(anElementsId,
2310 //=======================================================================
2311 //function : RotationSweepObject2D
2313 //=======================================================================
2315 void SMESH_MeshEditor_i::RotationSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
2316 const SMESH::AxisStruct & theAxis,
2317 CORBA::Double theAngleInRadians,
2318 CORBA::Long theNbOfSteps,
2319 CORBA::Double theTolerance)
2320 throw (SALOME::SALOME_Exception)
2322 if ( !myIsPreviewMode ) {
2323 TPythonDump() << this << ".RotationSweepObject2D( "
2324 << theObject << ", "
2326 << TVar( theAngleInRadians ) << ", "
2327 << TVar( theNbOfSteps ) << ", "
2328 << TVar( theTolerance ) << " )";
2330 SMESH::long_array_var anElementsId = theObject->GetIDs();
2331 rotationSweep(anElementsId,
2340 //=======================================================================
2341 //function : RotationSweepObjectMakeGroups
2343 //=======================================================================
2345 SMESH::ListOfGroups*
2346 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2347 const SMESH::AxisStruct& theAxis,
2348 CORBA::Double theAngleInRadians,
2349 CORBA::Long theNbOfSteps,
2350 CORBA::Double theTolerance)
2351 throw (SALOME::SALOME_Exception)
2353 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2355 SMESH::long_array_var anElementsId = theObject->GetIDs();
2356 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
2362 if (!myIsPreviewMode) {
2363 dumpGroupsList(aPythonDump, aGroups);
2364 aPythonDump << this << ".RotationSweepObjectMakeGroups( "
2365 << theObject << ", "
2367 << theAngleInRadians << ", "
2368 << theNbOfSteps << ", "
2369 << theTolerance << " )";
2374 //=======================================================================
2375 //function : RotationSweepObject1DMakeGroups
2377 //=======================================================================
2379 SMESH::ListOfGroups*
2380 SMESH_MeshEditor_i::RotationSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2381 const SMESH::AxisStruct& theAxis,
2382 CORBA::Double theAngleInRadians,
2383 CORBA::Long theNbOfSteps,
2384 CORBA::Double theTolerance)
2385 throw (SALOME::SALOME_Exception)
2387 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2389 SMESH::long_array_var anElementsId = theObject->GetIDs();
2390 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
2397 if (!myIsPreviewMode) {
2398 dumpGroupsList(aPythonDump, aGroups);
2399 aPythonDump << this << ".RotationSweepObject1DMakeGroups( "
2400 << theObject << ", "
2402 << TVar( theAngleInRadians ) << ", "
2403 << TVar( theNbOfSteps ) << ", "
2404 << TVar( theTolerance ) << " )";
2409 //=======================================================================
2410 //function : RotationSweepObject2DMakeGroups
2412 //=======================================================================
2414 SMESH::ListOfGroups*
2415 SMESH_MeshEditor_i::RotationSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2416 const SMESH::AxisStruct& theAxis,
2417 CORBA::Double theAngleInRadians,
2418 CORBA::Long theNbOfSteps,
2419 CORBA::Double theTolerance)
2420 throw (SALOME::SALOME_Exception)
2422 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2424 SMESH::long_array_var anElementsId = theObject->GetIDs();
2425 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
2432 if (!myIsPreviewMode) {
2433 dumpGroupsList(aPythonDump, aGroups);
2434 aPythonDump << this << ".RotationSweepObject2DMakeGroups( "
2435 << theObject << ", "
2437 << TVar( theAngleInRadians ) << ", "
2438 << TVar( theNbOfSteps ) << ", "
2439 << TVar( theTolerance ) << " )";
2445 //=======================================================================
2446 //function : extrusionSweep
2448 //=======================================================================
2450 SMESH::ListOfGroups*
2451 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
2452 const SMESH::DirStruct & theStepVector,
2453 CORBA::Long theNbOfSteps,
2455 const SMDSAbs_ElementType theElementType)
2456 throw (SALOME::SALOME_Exception)
2461 TIDSortedElemSet elements, copyElements;
2462 arrayToSet(theIDsOfElements, getMeshDS(), elements, theElementType);
2464 const SMESH::PointStruct * P = &theStepVector.PS;
2465 gp_Vec stepVec( P->x, P->y, P->z );
2467 TIDSortedElemSet* workElements = & elements;
2469 SMDSAbs_ElementType aType = SMDSAbs_Face;
2470 if (theElementType == SMDSAbs_Node)
2472 aType = SMDSAbs_Edge;
2474 if ( myIsPreviewMode ) {
2475 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
2476 getPreviewMesh( aType )->Copy( elements, copyElements, select, avoid );
2477 workElements = & copyElements;
2478 theMakeGroups = false;
2481 TElemOfElemListMap aHystory;
2482 ::SMESH_MeshEditor::PGroupIDs groupIds =
2483 getEditor().ExtrusionSweep (*workElements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
2485 declareMeshModified( /*isReComputeSafe=*/true ); // does not influence Compute()
2487 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2489 SMESH_CATCH( SMESH::throwCorbaException );
2493 //=======================================================================
2494 //function : ExtrusionSweep
2496 //=======================================================================
2498 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
2499 const SMESH::DirStruct & theStepVector,
2500 CORBA::Long theNbOfSteps)
2501 throw (SALOME::SALOME_Exception)
2503 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
2504 if (!myIsPreviewMode) {
2505 TPythonDump() << this << ".ExtrusionSweep( "
2506 << theIDsOfElements << ", " << theStepVector <<", " << TVar(theNbOfSteps) << " )";
2510 //=======================================================================
2511 //function : ExtrusionSweep0D
2513 //=======================================================================
2515 void SMESH_MeshEditor_i::ExtrusionSweep0D(const SMESH::long_array & theIDsOfElements,
2516 const SMESH::DirStruct & theStepVector,
2517 CORBA::Long theNbOfSteps)
2518 throw (SALOME::SALOME_Exception)
2520 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false, SMDSAbs_Node );
2521 if (!myIsPreviewMode) {
2522 TPythonDump() << this << ".ExtrusionSweep0D( "
2523 << theIDsOfElements << ", " << theStepVector <<", " << TVar(theNbOfSteps)<< " )";
2527 //=======================================================================
2528 //function : ExtrusionSweepObject
2530 //=======================================================================
2532 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
2533 const SMESH::DirStruct & theStepVector,
2534 CORBA::Long theNbOfSteps)
2535 throw (SALOME::SALOME_Exception)
2537 SMESH::long_array_var anElementsId = theObject->GetIDs();
2538 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
2539 if (!myIsPreviewMode) {
2540 TPythonDump() << this << ".ExtrusionSweepObject( "
2541 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
2545 //=======================================================================
2546 //function : ExtrusionSweepObject0D
2548 //=======================================================================
2550 void SMESH_MeshEditor_i::ExtrusionSweepObject0D(SMESH::SMESH_IDSource_ptr theObject,
2551 const SMESH::DirStruct & theStepVector,
2552 CORBA::Long theNbOfSteps)
2553 throw (SALOME::SALOME_Exception)
2555 SMESH::long_array_var anElementsId = theObject->GetIDs();
2556 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Node );
2557 if ( !myIsPreviewMode ) {
2558 TPythonDump() << this << ".ExtrusionSweepObject0D( "
2559 << theObject << ", " << theStepVector << ", " << TVar( theNbOfSteps ) << " )";
2563 //=======================================================================
2564 //function : ExtrusionSweepObject1D
2566 //=======================================================================
2568 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
2569 const SMESH::DirStruct & theStepVector,
2570 CORBA::Long theNbOfSteps)
2571 throw (SALOME::SALOME_Exception)
2573 SMESH::long_array_var anElementsId = theObject->GetIDs();
2574 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
2575 if ( !myIsPreviewMode ) {
2576 TPythonDump() << this << ".ExtrusionSweepObject1D( "
2577 << theObject << ", " << theStepVector << ", " << TVar( theNbOfSteps ) << " )";
2581 //=======================================================================
2582 //function : ExtrusionSweepObject2D
2584 //=======================================================================
2586 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
2587 const SMESH::DirStruct & theStepVector,
2588 CORBA::Long theNbOfSteps)
2589 throw (SALOME::SALOME_Exception)
2591 SMESH::long_array_var anElementsId = theObject->GetIDs();
2592 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
2593 if ( !myIsPreviewMode ) {
2594 TPythonDump() << this << ".ExtrusionSweepObject2D( "
2595 << theObject << ", " << theStepVector << ", " << TVar( theNbOfSteps ) << " )";
2599 //=======================================================================
2600 //function : ExtrusionSweepMakeGroups
2602 //=======================================================================
2604 SMESH::ListOfGroups*
2605 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
2606 const SMESH::DirStruct& theStepVector,
2607 CORBA::Long theNbOfSteps)
2608 throw (SALOME::SALOME_Exception)
2610 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2612 SMESH::ListOfGroups* aGroups = extrusionSweep(theIDsOfElements, theStepVector, theNbOfSteps, true);
2614 if (!myIsPreviewMode) {
2615 dumpGroupsList(aPythonDump, aGroups);
2616 aPythonDump << this << ".ExtrusionSweepMakeGroups( " << theIDsOfElements
2617 << ", " << theStepVector <<", " << TVar( theNbOfSteps ) << " )";
2622 //=======================================================================
2623 //function : ExtrusionSweepMakeGroups0D
2625 //=======================================================================
2627 SMESH::ListOfGroups*
2628 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups0D(const SMESH::long_array& theIDsOfElements,
2629 const SMESH::DirStruct& theStepVector,
2630 CORBA::Long theNbOfSteps)
2631 throw (SALOME::SALOME_Exception)
2633 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2635 SMESH::ListOfGroups* aGroups = extrusionSweep(theIDsOfElements, theStepVector, theNbOfSteps, true,SMDSAbs_Node);
2637 if (!myIsPreviewMode) {
2638 dumpGroupsList(aPythonDump, aGroups);
2639 aPythonDump << this << ".ExtrusionSweepMakeGroups0D( " << theIDsOfElements
2640 << ", " << theStepVector <<", " << TVar( theNbOfSteps ) << " )";
2645 //=======================================================================
2646 //function : ExtrusionSweepObjectMakeGroups
2648 //=======================================================================
2650 SMESH::ListOfGroups*
2651 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2652 const SMESH::DirStruct& theStepVector,
2653 CORBA::Long theNbOfSteps)
2654 throw (SALOME::SALOME_Exception)
2656 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2658 SMESH::long_array_var anElementsId = theObject->GetIDs();
2659 SMESH::ListOfGroups * aGroups = extrusionSweep(anElementsId, theStepVector, theNbOfSteps, true);
2661 if (!myIsPreviewMode) {
2662 dumpGroupsList(aPythonDump, aGroups);
2663 aPythonDump << this << ".ExtrusionSweepObjectMakeGroups( " << theObject
2664 << ", " << theStepVector << ", " << theNbOfSteps << " )";
2669 //=======================================================================
2670 //function : ExtrusionSweepObject0DMakeGroups
2672 //=======================================================================
2674 SMESH::ListOfGroups*
2675 SMESH_MeshEditor_i::ExtrusionSweepObject0DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2676 const SMESH::DirStruct& theStepVector,
2677 CORBA::Long theNbOfSteps)
2678 throw (SALOME::SALOME_Exception)
2680 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2682 SMESH::long_array_var anElementsId = theObject->GetIDs();
2683 SMESH::ListOfGroups * aGroups = extrusionSweep(anElementsId, theStepVector,
2684 theNbOfSteps, true, SMDSAbs_Node);
2685 if (!myIsPreviewMode) {
2686 dumpGroupsList(aPythonDump, aGroups);
2687 aPythonDump << this << ".ExtrusionSweepObject0DMakeGroups( " << theObject
2688 << ", " << theStepVector << ", " << TVar( theNbOfSteps ) << " )";
2693 //=======================================================================
2694 //function : ExtrusionSweepObject1DMakeGroups
2696 //=======================================================================
2698 SMESH::ListOfGroups*
2699 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2700 const SMESH::DirStruct& theStepVector,
2701 CORBA::Long theNbOfSteps)
2702 throw (SALOME::SALOME_Exception)
2704 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2706 SMESH::long_array_var anElementsId = theObject->GetIDs();
2707 SMESH::ListOfGroups * aGroups = extrusionSweep(anElementsId, theStepVector,
2708 theNbOfSteps, true, SMDSAbs_Edge);
2709 if (!myIsPreviewMode) {
2710 dumpGroupsList(aPythonDump, aGroups);
2711 aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( " << theObject
2712 << ", " << theStepVector << ", " << TVar( theNbOfSteps ) << " )";
2717 //=======================================================================
2718 //function : ExtrusionSweepObject2DMakeGroups
2720 //=======================================================================
2722 SMESH::ListOfGroups*
2723 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2724 const SMESH::DirStruct& theStepVector,
2725 CORBA::Long theNbOfSteps)
2726 throw (SALOME::SALOME_Exception)
2728 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2730 SMESH::long_array_var anElementsId = theObject->GetIDs();
2731 SMESH::ListOfGroups * aGroups = extrusionSweep(anElementsId, theStepVector,
2732 theNbOfSteps, true, SMDSAbs_Face);
2733 if (!myIsPreviewMode) {
2734 dumpGroupsList(aPythonDump, aGroups);
2735 aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( " << theObject
2736 << ", " << theStepVector << ", " << TVar( theNbOfSteps ) << " )";
2742 //=======================================================================
2743 //function : advancedExtrusion
2745 //=======================================================================
2747 SMESH::ListOfGroups*
2748 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
2749 const SMESH::DirStruct & theStepVector,
2750 CORBA::Long theNbOfSteps,
2751 CORBA::Long theExtrFlags,
2752 CORBA::Double theSewTolerance,
2753 const bool theMakeGroups)
2754 throw (SALOME::SALOME_Exception)
2759 TIDSortedElemSet elements;
2760 arrayToSet(theIDsOfElements, getMeshDS(), elements);
2762 const SMESH::PointStruct * P = &theStepVector.PS;
2763 gp_Vec stepVec( P->x, P->y, P->z );
2765 TElemOfElemListMap aHystory;
2766 ::SMESH_MeshEditor::PGroupIDs groupIds =
2767 getEditor().ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
2768 theMakeGroups, theExtrFlags, theSewTolerance);
2770 declareMeshModified( /*isReComputeSafe=*/true );
2772 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2774 SMESH_CATCH( SMESH::throwCorbaException );
2778 //=======================================================================
2779 //function : AdvancedExtrusion
2781 //=======================================================================
2783 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
2784 const SMESH::DirStruct & theStepVector,
2785 CORBA::Long theNbOfSteps,
2786 CORBA::Long theExtrFlags,
2787 CORBA::Double theSewTolerance)
2788 throw (SALOME::SALOME_Exception)
2790 if ( !myIsPreviewMode ) {
2791 TPythonDump() << "stepVector = " << theStepVector;
2792 TPythonDump() << this << ".AdvancedExtrusion("
2795 << theNbOfSteps << ","
2796 << theExtrFlags << ", "
2797 << theSewTolerance << " )";
2799 advancedExtrusion( theIDsOfElements,
2807 //=======================================================================
2808 //function : AdvancedExtrusionMakeGroups
2810 //=======================================================================
2811 SMESH::ListOfGroups*
2812 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
2813 const SMESH::DirStruct& theStepVector,
2814 CORBA::Long theNbOfSteps,
2815 CORBA::Long theExtrFlags,
2816 CORBA::Double theSewTolerance)
2817 throw (SALOME::SALOME_Exception)
2819 if (!myIsPreviewMode) {
2820 TPythonDump() << "stepVector = " << theStepVector;
2822 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
2824 SMESH::ListOfGroups * aGroups = advancedExtrusion( theIDsOfElements,
2831 if (!myIsPreviewMode) {
2832 dumpGroupsList(aPythonDump, aGroups);
2833 aPythonDump << this << ".AdvancedExtrusionMakeGroups("
2836 << theNbOfSteps << ","
2837 << theExtrFlags << ", "
2838 << theSewTolerance << " )";
2844 //================================================================================
2846 * \brief Convert extrusion error to IDL enum
2848 //================================================================================
2850 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
2852 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
2856 RETCASE( EXTR_NO_ELEMENTS );
2857 RETCASE( EXTR_PATH_NOT_EDGE );
2858 RETCASE( EXTR_BAD_PATH_SHAPE );
2859 RETCASE( EXTR_BAD_STARTING_NODE );
2860 RETCASE( EXTR_BAD_ANGLES_NUMBER );
2861 RETCASE( EXTR_CANT_GET_TANGENT );
2863 return SMESH::SMESH_MeshEditor::EXTR_OK;
2867 //=======================================================================
2868 //function : extrusionAlongPath
2870 //=======================================================================
2871 SMESH::ListOfGroups*
2872 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2873 SMESH::SMESH_Mesh_ptr thePathMesh,
2874 GEOM::GEOM_Object_ptr thePathShape,
2875 CORBA::Long theNodeStart,
2876 CORBA::Boolean theHasAngles,
2877 const SMESH::double_array & theAngles,
2878 CORBA::Boolean theHasRefPoint,
2879 const SMESH::PointStruct & theRefPoint,
2880 const bool theMakeGroups,
2881 SMESH::SMESH_MeshEditor::Extrusion_Error & theError,
2882 const SMDSAbs_ElementType theElementType)
2883 throw (SALOME::SALOME_Exception)
2886 MESSAGE("extrusionAlongPath");
2889 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
2890 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2893 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2895 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2896 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2898 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
2899 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2903 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
2905 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2909 TIDSortedElemSet elements;
2910 arrayToSet(theIDsOfElements, getMeshDS(), elements, theElementType);
2912 list<double> angles;
2913 for (int i = 0; i < theAngles.length(); i++) {
2914 angles.push_back( theAngles[i] );
2917 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
2919 int nbOldGroups = myMesh->NbGroup();
2921 ::SMESH_MeshEditor::Extrusion_Error error =
2922 getEditor().ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
2923 theHasAngles, angles, false,
2924 theHasRefPoint, refPnt, theMakeGroups );
2926 declareMeshModified( /*isReComputeSafe=*/true );
2927 theError = convExtrError( error );
2929 if ( theMakeGroups ) {
2930 list<int> groupIDs = myMesh->GetGroupIds();
2931 list<int>::iterator newBegin = groupIDs.begin();
2932 std::advance( newBegin, nbOldGroups ); // skip old groups
2933 groupIDs.erase( groupIDs.begin(), newBegin );
2934 return getGroups( & groupIDs );
2938 SMESH_CATCH( SMESH::throwCorbaException );
2942 //=======================================================================
2943 //function : extrusionAlongPathX
2945 //=======================================================================
2947 SMESH::ListOfGroups*
2948 SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements,
2949 SMESH::SMESH_IDSource_ptr Path,
2950 CORBA::Long NodeStart,
2951 CORBA::Boolean HasAngles,
2952 const SMESH::double_array& Angles,
2953 CORBA::Boolean LinearVariation,
2954 CORBA::Boolean HasRefPoint,
2955 const SMESH::PointStruct& RefPoint,
2957 const SMDSAbs_ElementType ElementType,
2958 SMESH::SMESH_MeshEditor::Extrusion_Error & Error)
2959 throw (SALOME::SALOME_Exception)
2962 SMESH::ListOfGroups* EmptyGr = new SMESH::ListOfGroups;
2966 list<double> angles;
2967 for (int i = 0; i < Angles.length(); i++) {
2968 angles.push_back( Angles[i] );
2970 gp_Pnt refPnt( RefPoint.x, RefPoint.y, RefPoint.z );
2971 int nbOldGroups = myMesh->NbGroup();
2973 if ( Path->_is_nil() ) {
2974 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2978 TIDSortedElemSet elements, copyElements;
2979 arrayToSet(IDsOfElements, getMeshDS(), elements, ElementType);
2981 TIDSortedElemSet* workElements = &elements;
2983 if ( myIsPreviewMode )
2985 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
2986 getPreviewMesh( SMDSAbs_Face )->Copy( elements, copyElements, select, avoid );
2987 workElements = & copyElements;
2991 ::SMESH_MeshEditor::Extrusion_Error error;
2993 if ( SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( Path ))
2996 SMDS_MeshNode* aNodeStart =
2997 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2998 if ( !aNodeStart ) {
2999 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
3002 error = getEditor().ExtrusionAlongTrack( *workElements, &(aMeshImp->GetImpl()), aNodeStart,
3003 HasAngles, angles, LinearVariation,
3004 HasRefPoint, refPnt, MakeGroups );
3005 declareMeshModified( /*isReComputeSafe=*/true );
3007 else if ( SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast<SMESH_subMesh_i*>( Path ))
3010 SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather();
3011 aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( aPathMesh );
3012 SMDS_MeshNode* aNodeStart =
3013 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
3014 if ( !aNodeStart ) {
3015 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
3018 SMESH_subMesh* aSubMesh =
3019 aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId());
3020 error = getEditor().ExtrusionAlongTrack( *workElements, aSubMesh, aNodeStart,
3021 HasAngles, angles, LinearVariation,
3022 HasRefPoint, refPnt, MakeGroups );
3023 declareMeshModified( /*isReComputeSafe=*/true );
3025 else if ( SMESH::DownCast<SMESH_Group_i*>( Path ))
3027 // path as group of 1D elements
3033 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
3037 Error = convExtrError( error );
3040 list<int> groupIDs = myMesh->GetGroupIds();
3041 list<int>::iterator newBegin = groupIDs.begin();
3042 std::advance( newBegin, nbOldGroups ); // skip old groups
3043 groupIDs.erase( groupIDs.begin(), newBegin );
3044 return getGroups( & groupIDs );
3048 SMESH_CATCH( SMESH::throwCorbaException );
3052 //=======================================================================
3053 //function : ExtrusionAlongPath
3055 //=======================================================================
3057 SMESH::SMESH_MeshEditor::Extrusion_Error
3058 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
3059 SMESH::SMESH_Mesh_ptr thePathMesh,
3060 GEOM::GEOM_Object_ptr thePathShape,
3061 CORBA::Long theNodeStart,
3062 CORBA::Boolean theHasAngles,
3063 const SMESH::double_array & theAngles,
3064 CORBA::Boolean theHasRefPoint,
3065 const SMESH::PointStruct & theRefPoint)
3066 throw (SALOME::SALOME_Exception)
3068 MESSAGE("ExtrusionAlongPath");
3069 if ( !myIsPreviewMode ) {
3070 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
3071 << theIDsOfElements << ", "
3072 << thePathMesh << ", "
3073 << thePathShape << ", "
3074 << theNodeStart << ", "
3075 << theHasAngles << ", "
3076 << theAngles << ", "
3077 << theHasRefPoint << ", "
3078 << "SMESH.PointStruct( "
3079 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
3080 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
3081 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
3083 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
3084 extrusionAlongPath( theIDsOfElements,
3097 //=======================================================================
3098 //function : ExtrusionAlongPathObject
3100 //=======================================================================
3102 SMESH::SMESH_MeshEditor::Extrusion_Error
3103 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
3104 SMESH::SMESH_Mesh_ptr thePathMesh,
3105 GEOM::GEOM_Object_ptr thePathShape,
3106 CORBA::Long theNodeStart,
3107 CORBA::Boolean theHasAngles,
3108 const SMESH::double_array & theAngles,
3109 CORBA::Boolean theHasRefPoint,
3110 const SMESH::PointStruct & theRefPoint)
3111 throw (SALOME::SALOME_Exception)
3113 if ( !myIsPreviewMode ) {
3114 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
3115 << theObject << ", "
3116 << thePathMesh << ", "
3117 << thePathShape << ", "
3118 << theNodeStart << ", "
3119 << theHasAngles << ", "
3120 << theAngles << ", "
3121 << theHasRefPoint << ", "
3122 << "SMESH.PointStruct( "
3123 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
3124 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
3125 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
3127 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
3128 SMESH::long_array_var anElementsId = theObject->GetIDs();
3129 extrusionAlongPath( anElementsId,
3142 //=======================================================================
3143 //function : ExtrusionAlongPathObject1D
3145 //=======================================================================
3147 SMESH::SMESH_MeshEditor::Extrusion_Error
3148 SMESH_MeshEditor_i::ExtrusionAlongPathObject1D(SMESH::SMESH_IDSource_ptr theObject,
3149 SMESH::SMESH_Mesh_ptr thePathMesh,
3150 GEOM::GEOM_Object_ptr thePathShape,
3151 CORBA::Long theNodeStart,
3152 CORBA::Boolean theHasAngles,
3153 const SMESH::double_array & theAngles,
3154 CORBA::Boolean theHasRefPoint,
3155 const SMESH::PointStruct & theRefPoint)
3156 throw (SALOME::SALOME_Exception)
3158 if ( !myIsPreviewMode ) {
3159 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject1D( "
3160 << theObject << ", "
3161 << thePathMesh << ", "
3162 << thePathShape << ", "
3163 << theNodeStart << ", "
3164 << theHasAngles << ", "
3165 << theAngles << ", "
3166 << theHasRefPoint << ", "
3167 << "SMESH.PointStruct( "
3168 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
3169 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
3170 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
3172 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
3173 SMESH::long_array_var anElementsId = theObject->GetIDs();
3174 extrusionAlongPath( anElementsId,
3188 //=======================================================================
3189 //function : ExtrusionAlongPathObject2D
3191 //=======================================================================
3193 SMESH::SMESH_MeshEditor::Extrusion_Error
3194 SMESH_MeshEditor_i::ExtrusionAlongPathObject2D(SMESH::SMESH_IDSource_ptr theObject,
3195 SMESH::SMESH_Mesh_ptr thePathMesh,
3196 GEOM::GEOM_Object_ptr thePathShape,
3197 CORBA::Long theNodeStart,
3198 CORBA::Boolean theHasAngles,
3199 const SMESH::double_array & theAngles,
3200 CORBA::Boolean theHasRefPoint,
3201 const SMESH::PointStruct & theRefPoint)
3202 throw (SALOME::SALOME_Exception)
3204 if ( !myIsPreviewMode ) {
3205 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject2D( "
3206 << theObject << ", "
3207 << thePathMesh << ", "
3208 << thePathShape << ", "
3209 << theNodeStart << ", "
3210 << theHasAngles << ", "
3211 << theAngles << ", "
3212 << theHasRefPoint << ", "
3213 << "SMESH.PointStruct( "
3214 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
3215 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
3216 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
3218 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
3219 SMESH::long_array_var anElementsId = theObject->GetIDs();
3220 extrusionAlongPath( anElementsId,
3235 //=======================================================================
3236 //function : ExtrusionAlongPathMakeGroups
3238 //=======================================================================
3240 SMESH::ListOfGroups*
3241 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
3242 SMESH::SMESH_Mesh_ptr thePathMesh,
3243 GEOM::GEOM_Object_ptr thePathShape,
3244 CORBA::Long theNodeStart,
3245 CORBA::Boolean theHasAngles,
3246 const SMESH::double_array& theAngles,
3247 CORBA::Boolean theHasRefPoint,
3248 const SMESH::PointStruct& theRefPoint,
3249 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
3250 throw (SALOME::SALOME_Exception)
3252 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3254 SMESH::ListOfGroups * aGroups = extrusionAlongPath( theIDsOfElements,
3264 if (!myIsPreviewMode) {
3265 bool isDumpGroups = aGroups && aGroups->length() > 0;
3267 aPythonDump << "(" << aGroups << ", error)";
3269 aPythonDump <<"error";
3271 aPythonDump<<" = "<< this << ".ExtrusionAlongPathMakeGroups( "
3272 << theIDsOfElements << ", "
3273 << thePathMesh << ", "
3274 << thePathShape << ", "
3275 << theNodeStart << ", "
3276 << theHasAngles << ", "
3277 << theAngles << ", "
3278 << theHasRefPoint << ", "
3279 << "SMESH.PointStruct( "
3280 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
3281 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
3282 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
3287 //=======================================================================
3288 //function : ExtrusionAlongPathObjectMakeGroups
3290 //=======================================================================
3292 SMESH::ListOfGroups* SMESH_MeshEditor_i::
3293 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3294 SMESH::SMESH_Mesh_ptr thePathMesh,
3295 GEOM::GEOM_Object_ptr thePathShape,
3296 CORBA::Long theNodeStart,
3297 CORBA::Boolean theHasAngles,
3298 const SMESH::double_array& theAngles,
3299 CORBA::Boolean theHasRefPoint,
3300 const SMESH::PointStruct& theRefPoint,
3301 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
3302 throw (SALOME::SALOME_Exception)
3304 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3306 SMESH::long_array_var anElementsId = theObject->GetIDs();
3307 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
3318 if (!myIsPreviewMode) {
3319 bool isDumpGroups = aGroups && aGroups->length() > 0;
3321 aPythonDump << "(" << aGroups << ", error)";
3323 aPythonDump <<"error";
3325 aPythonDump << " = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
3326 << theObject << ", "
3327 << thePathMesh << ", "
3328 << thePathShape << ", "
3329 << theNodeStart << ", "
3330 << theHasAngles << ", "
3331 << theAngles << ", "
3332 << theHasRefPoint << ", "
3333 << "SMESH.PointStruct( "
3334 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
3335 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
3336 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
3341 //=======================================================================
3342 //function : ExtrusionAlongPathObject1DMakeGroups
3344 //=======================================================================
3346 SMESH::ListOfGroups* SMESH_MeshEditor_i::
3347 ExtrusionAlongPathObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3348 SMESH::SMESH_Mesh_ptr thePathMesh,
3349 GEOM::GEOM_Object_ptr thePathShape,
3350 CORBA::Long theNodeStart,
3351 CORBA::Boolean theHasAngles,
3352 const SMESH::double_array& theAngles,
3353 CORBA::Boolean theHasRefPoint,
3354 const SMESH::PointStruct& theRefPoint,
3355 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
3356 throw (SALOME::SALOME_Exception)
3358 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3360 SMESH::long_array_var anElementsId = theObject->GetIDs();
3361 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
3373 if (!myIsPreviewMode) {
3374 bool isDumpGroups = aGroups && aGroups->length() > 0;
3376 aPythonDump << "(" << aGroups << ", error)";
3378 aPythonDump << "error";
3380 aPythonDump << " = " << this << ".ExtrusionAlongPathObject1DMakeGroups( "
3381 << theObject << ", "
3382 << thePathMesh << ", "
3383 << thePathShape << ", "
3384 << theNodeStart << ", "
3385 << theHasAngles << ", "
3386 << theAngles << ", "
3387 << theHasRefPoint << ", "
3388 << "SMESH.PointStruct( "
3389 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
3390 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
3391 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
3396 //=======================================================================
3397 //function : ExtrusionAlongPathObject2DMakeGroups
3399 //=======================================================================
3401 SMESH::ListOfGroups* SMESH_MeshEditor_i::
3402 ExtrusionAlongPathObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3403 SMESH::SMESH_Mesh_ptr thePathMesh,
3404 GEOM::GEOM_Object_ptr thePathShape,
3405 CORBA::Long theNodeStart,
3406 CORBA::Boolean theHasAngles,
3407 const SMESH::double_array& theAngles,
3408 CORBA::Boolean theHasRefPoint,
3409 const SMESH::PointStruct& theRefPoint,
3410 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
3411 throw (SALOME::SALOME_Exception)
3413 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3415 SMESH::long_array_var anElementsId = theObject->GetIDs();
3416 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
3428 if (!myIsPreviewMode) {
3429 bool isDumpGroups = aGroups && aGroups->length() > 0;
3431 aPythonDump << "(" << aGroups << ", error)";
3433 aPythonDump << "error";
3435 aPythonDump << " = " << this << ".ExtrusionAlongPathObject2DMakeGroups( "
3436 << theObject << ", "
3437 << thePathMesh << ", "
3438 << thePathShape << ", "
3439 << theNodeStart << ", "
3440 << theHasAngles << ", "
3441 << theAngles << ", "
3442 << theHasRefPoint << ", "
3443 << "SMESH.PointStruct( "
3444 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
3445 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
3446 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
3451 //=======================================================================
3452 //function : ExtrusionAlongPathObjX
3454 //=======================================================================
3456 SMESH::ListOfGroups* SMESH_MeshEditor_i::
3457 ExtrusionAlongPathObjX(SMESH::SMESH_IDSource_ptr Object,
3458 SMESH::SMESH_IDSource_ptr Path,
3459 CORBA::Long NodeStart,
3460 CORBA::Boolean HasAngles,
3461 const SMESH::double_array& Angles,
3462 CORBA::Boolean LinearVariation,
3463 CORBA::Boolean HasRefPoint,
3464 const SMESH::PointStruct& RefPoint,
3465 CORBA::Boolean MakeGroups,
3466 SMESH::ElementType ElemType,
3467 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
3468 throw (SALOME::SALOME_Exception)
3470 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3472 SMESH::long_array_var anElementsId = Object->GetIDs();
3473 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(anElementsId,
3482 (SMDSAbs_ElementType)ElemType,
3485 if (!myIsPreviewMode) {
3486 bool isDumpGroups = aGroups && aGroups->length() > 0;
3488 aPythonDump << "(" << *aGroups << ", error)";
3490 aPythonDump << "error";
3492 aPythonDump << " = " << this << ".ExtrusionAlongPathObjX( "
3495 << NodeStart << ", "
3496 << HasAngles << ", "
3497 << TVar( Angles ) << ", "
3498 << LinearVariation << ", "
3499 << HasRefPoint << ", "
3500 << "SMESH.PointStruct( "
3501 << TVar( HasRefPoint ? RefPoint.x : 0 ) << ", "
3502 << TVar( HasRefPoint ? RefPoint.y : 0 ) << ", "
3503 << TVar( HasRefPoint ? RefPoint.z : 0 ) << " ), "
3504 << MakeGroups << ", "
3505 << ElemType << " )";
3510 //=======================================================================
3511 //function : ExtrusionAlongPathX
3513 //=======================================================================
3515 SMESH::ListOfGroups* SMESH_MeshEditor_i::
3516 ExtrusionAlongPathX(const SMESH::long_array& IDsOfElements,
3517 SMESH::SMESH_IDSource_ptr Path,
3518 CORBA::Long NodeStart,
3519 CORBA::Boolean HasAngles,
3520 const SMESH::double_array& Angles,
3521 CORBA::Boolean LinearVariation,
3522 CORBA::Boolean HasRefPoint,
3523 const SMESH::PointStruct& RefPoint,
3524 CORBA::Boolean MakeGroups,
3525 SMESH::ElementType ElemType,
3526 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
3527 throw (SALOME::SALOME_Exception)
3529 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3531 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(IDsOfElements,
3540 (SMDSAbs_ElementType)ElemType,
3543 if (!myIsPreviewMode) {
3544 bool isDumpGroups = aGroups && aGroups->length() > 0;
3546 aPythonDump << "(" << *aGroups << ", error)";
3548 aPythonDump <<"error";
3550 aPythonDump << " = " << this << ".ExtrusionAlongPathX( "
3551 << IDsOfElements << ", "
3553 << NodeStart << ", "
3554 << HasAngles << ", "
3555 << TVar( Angles ) << ", "
3556 << LinearVariation << ", "
3557 << HasRefPoint << ", "
3558 << "SMESH.PointStruct( "
3559 << TVar( HasRefPoint ? RefPoint.x : 0 ) << ", "
3560 << TVar( HasRefPoint ? RefPoint.y : 0 ) << ", "
3561 << TVar( HasRefPoint ? RefPoint.z : 0 ) << " ), "
3562 << MakeGroups << ", "
3563 << ElemType << " )";
3568 //================================================================================
3570 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
3571 * of given angles along path steps
3572 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
3573 * which proceeds the extrusion
3574 * \param PathShape is shape(edge); as the mesh can be complex, the edge
3575 * is used to define the sub-mesh for the path
3577 //================================================================================
3579 SMESH::double_array*
3580 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
3581 GEOM::GEOM_Object_ptr thePathShape,
3582 const SMESH::double_array & theAngles)
3584 SMESH::double_array_var aResult = new SMESH::double_array();
3585 int nbAngles = theAngles.length();
3586 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
3588 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
3589 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
3590 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
3591 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
3592 return aResult._retn();
3593 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
3594 if ( nbSteps == nbAngles )
3596 aResult.inout() = theAngles;
3600 aResult->length( nbSteps );
3601 double rAn2St = double( nbAngles ) / double( nbSteps );
3602 double angPrev = 0, angle;
3603 for ( int iSt = 0; iSt < nbSteps; ++iSt )
3605 double angCur = rAn2St * ( iSt+1 );
3606 double angCurFloor = floor( angCur );
3607 double angPrevFloor = floor( angPrev );
3608 if ( angPrevFloor == angCurFloor )
3609 angle = rAn2St * theAngles[ int( angCurFloor ) ];
3612 int iP = int( angPrevFloor );
3613 double angPrevCeil = ceil(angPrev);
3614 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
3616 int iC = int( angCurFloor );
3617 if ( iC < nbAngles )
3618 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
3620 iP = int( angPrevCeil );
3622 angle += theAngles[ iC ];
3624 aResult[ iSt ] = angle;
3629 // Update Python script
3630 TPythonDump() << "rotAngles = " << theAngles;
3631 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
3632 << thePathMesh << ", "
3633 << thePathShape << ", "
3636 return aResult._retn();
3639 //=======================================================================
3642 //=======================================================================
3644 SMESH::ListOfGroups*
3645 SMESH_MeshEditor_i::mirror(TIDSortedElemSet & theElements,
3646 const SMESH::AxisStruct & theAxis,
3647 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3648 CORBA::Boolean theCopy,
3650 ::SMESH_Mesh* theTargetMesh)
3651 throw (SALOME::SALOME_Exception)
3656 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
3657 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
3659 if ( theTargetMesh )
3663 switch ( theMirrorType ) {
3664 case SMESH::SMESH_MeshEditor::POINT:
3665 aTrsf.SetMirror( P );
3667 case SMESH::SMESH_MeshEditor::AXIS:
3668 aTrsf.SetMirror( gp_Ax1( P, V ));
3671 aTrsf.SetMirror( gp_Ax2( P, V ));
3674 TIDSortedElemSet copyElements;
3675 TIDSortedElemSet* workElements = & theElements;
3677 if ( myIsPreviewMode )
3679 TPreviewMesh * tmpMesh = getPreviewMesh();
3680 tmpMesh->Copy( theElements, copyElements);
3681 if ( !theCopy && !theTargetMesh )
3683 TIDSortedElemSet elemsAround, elemsAroundCopy;
3684 getElementsAround( theElements, getMeshDS(), elemsAround );
3685 tmpMesh->Copy( elemsAround, elemsAroundCopy);
3687 workElements = & copyElements;
3688 theMakeGroups = false;
3691 ::SMESH_MeshEditor::PGroupIDs groupIds =
3692 getEditor().Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3694 if ( theCopy && !myIsPreviewMode)
3696 if ( theTargetMesh )
3698 theTargetMesh->GetMeshDS()->Modified();
3702 declareMeshModified( /*isReComputeSafe=*/false );
3705 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3707 SMESH_CATCH( SMESH::throwCorbaException );
3711 //=======================================================================
3714 //=======================================================================
3716 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
3717 const SMESH::AxisStruct & theAxis,
3718 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3719 CORBA::Boolean theCopy)
3720 throw (SALOME::SALOME_Exception)
3722 if ( !myIsPreviewMode ) {
3723 TPythonDump() << this << ".Mirror( "
3724 << theIDsOfElements << ", "
3726 << mirrorTypeName(theMirrorType) << ", "
3729 if ( theIDsOfElements.length() > 0 )
3731 TIDSortedElemSet elements;
3732 arrayToSet(theIDsOfElements, getMeshDS(), elements);
3733 mirror(elements, theAxis, theMirrorType, theCopy, false);
3738 //=======================================================================
3739 //function : MirrorObject
3741 //=======================================================================
3743 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
3744 const SMESH::AxisStruct & theAxis,
3745 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3746 CORBA::Boolean theCopy)
3747 throw (SALOME::SALOME_Exception)
3749 if ( !myIsPreviewMode ) {
3750 TPythonDump() << this << ".MirrorObject( "
3751 << theObject << ", "
3753 << mirrorTypeName(theMirrorType) << ", "
3756 TIDSortedElemSet elements;
3758 bool emptyIfIsMesh = myIsPreviewMode ? false : true;
3760 if (idSourceToSet(theObject, getMeshDS(), elements, SMDSAbs_All, emptyIfIsMesh))
3761 mirror(elements, theAxis, theMirrorType, theCopy, false);
3764 //=======================================================================
3765 //function : MirrorMakeGroups
3767 //=======================================================================
3769 SMESH::ListOfGroups*
3770 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
3771 const SMESH::AxisStruct& theMirror,
3772 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
3773 throw (SALOME::SALOME_Exception)
3775 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3777 SMESH::ListOfGroups * aGroups = 0;
3778 if ( theIDsOfElements.length() > 0 )
3780 TIDSortedElemSet elements;
3781 arrayToSet(theIDsOfElements, getMeshDS(), elements);
3782 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
3784 if (!myIsPreviewMode) {
3785 dumpGroupsList(aPythonDump, aGroups);
3786 aPythonDump << this << ".MirrorMakeGroups( "
3787 << theIDsOfElements << ", "
3788 << theMirror << ", "
3789 << mirrorTypeName(theMirrorType) << " )";
3794 //=======================================================================
3795 //function : MirrorObjectMakeGroups
3797 //=======================================================================
3799 SMESH::ListOfGroups*
3800 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3801 const SMESH::AxisStruct& theMirror,
3802 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
3803 throw (SALOME::SALOME_Exception)
3805 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
3807 SMESH::ListOfGroups * aGroups = 0;
3808 TIDSortedElemSet elements;
3809 if ( idSourceToSet(theObject, getMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3810 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
3812 if (!myIsPreviewMode)
3814 dumpGroupsList(aPythonDump,aGroups);
3815 aPythonDump << this << ".MirrorObjectMakeGroups( "
3816 << theObject << ", "
3817 << theMirror << ", "
3818 << mirrorTypeName(theMirrorType) << " )";
3823 //=======================================================================
3824 //function : MirrorMakeMesh
3826 //=======================================================================
3828 SMESH::SMESH_Mesh_ptr
3829 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
3830 const SMESH::AxisStruct& theMirror,
3831 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3832 CORBA::Boolean theCopyGroups,
3833 const char* theMeshName)
3834 throw (SALOME::SALOME_Exception)
3836 SMESH_Mesh_i* mesh_i;
3837 SMESH::SMESH_Mesh_var mesh;
3838 { // open new scope to dump "MakeMesh" command
3839 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3841 TPythonDump pydump; // to prevent dump at mesh creation
3843 mesh = makeMesh( theMeshName );
3844 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3845 if (mesh_i && theIDsOfElements.length() > 0 )
3847 TIDSortedElemSet elements;
3848 arrayToSet(theIDsOfElements, getMeshDS(), elements);
3849 mirror(elements, theMirror, theMirrorType,
3850 false, theCopyGroups, & mesh_i->GetImpl());
3851 mesh_i->CreateGroupServants();
3854 if (!myIsPreviewMode) {
3855 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
3856 << theIDsOfElements << ", "
3857 << theMirror << ", "
3858 << mirrorTypeName(theMirrorType) << ", "
3859 << theCopyGroups << ", '"
3860 << theMeshName << "' )";
3865 if (!myIsPreviewMode && mesh_i)
3866 mesh_i->GetGroups();
3868 return mesh._retn();
3871 //=======================================================================
3872 //function : MirrorObjectMakeMesh
3874 //=======================================================================
3876 SMESH::SMESH_Mesh_ptr
3877 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3878 const SMESH::AxisStruct& theMirror,
3879 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3880 CORBA::Boolean theCopyGroups,
3881 const char* theMeshName)
3882 throw (SALOME::SALOME_Exception)
3884 SMESH_Mesh_i* mesh_i;
3885 SMESH::SMESH_Mesh_var mesh;
3886 { // open new scope to dump "MakeMesh" command
3887 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3889 TPythonDump pydump; // to prevent dump at mesh creation
3891 mesh = makeMesh( theMeshName );
3892 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3893 TIDSortedElemSet elements;
3895 idSourceToSet(theObject, getMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3897 mirror(elements, theMirror, theMirrorType,
3898 false, theCopyGroups, & mesh_i->GetImpl());
3899 mesh_i->CreateGroupServants();
3901 if (!myIsPreviewMode) {
3902 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
3903 << theObject << ", "
3904 << theMirror << ", "
3905 << mirrorTypeName(theMirrorType) << ", "
3906 << theCopyGroups << ", '"
3907 << theMeshName << "' )";
3912 if (!myIsPreviewMode && mesh_i)
3913 mesh_i->GetGroups();
3915 return mesh._retn();
3918 //=======================================================================
3919 //function : translate
3921 //=======================================================================
3923 SMESH::ListOfGroups*
3924 SMESH_MeshEditor_i::translate(TIDSortedElemSet & theElements,
3925 const SMESH::DirStruct & theVector,
3926 CORBA::Boolean theCopy,
3928 ::SMESH_Mesh* theTargetMesh)
3929 throw (SALOME::SALOME_Exception)
3934 if ( theTargetMesh )
3938 const SMESH::PointStruct * P = &theVector.PS;
3939 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
3941 TIDSortedElemSet copyElements;
3942 TIDSortedElemSet* workElements = &theElements;
3944 if ( myIsPreviewMode )
3946 TPreviewMesh * tmpMesh = getPreviewMesh();
3947 tmpMesh->Copy( theElements, copyElements);
3948 if ( !theCopy && !theTargetMesh )
3950 TIDSortedElemSet elemsAround, elemsAroundCopy;
3951 getElementsAround( theElements, getMeshDS(), elemsAround );
3952 tmpMesh->Copy( elemsAround, elemsAroundCopy);
3954 workElements = & copyElements;
3955 theMakeGroups = false;
3958 ::SMESH_MeshEditor::PGroupIDs groupIds =
3959 getEditor().Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3961 if ( theCopy && !myIsPreviewMode )
3963 if ( theTargetMesh )
3965 theTargetMesh->GetMeshDS()->Modified();
3969 declareMeshModified( /*isReComputeSafe=*/false );
3973 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3975 SMESH_CATCH( SMESH::throwCorbaException );
3979 //=======================================================================
3980 //function : Translate
3982 //=======================================================================
3984 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
3985 const SMESH::DirStruct & theVector,
3986 CORBA::Boolean theCopy)
3987 throw (SALOME::SALOME_Exception)
3989 if (!myIsPreviewMode) {
3990 TPythonDump() << this << ".Translate( "
3991 << theIDsOfElements << ", "
3992 << theVector << ", "
3995 if (theIDsOfElements.length()) {
3996 TIDSortedElemSet elements;
3997 arrayToSet(theIDsOfElements, getMeshDS(), elements);
3998 translate(elements, theVector, theCopy, false);
4002 //=======================================================================
4003 //function : TranslateObject
4005 //=======================================================================
4007 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
4008 const SMESH::DirStruct & theVector,
4009 CORBA::Boolean theCopy)
4010 throw (SALOME::SALOME_Exception)
4012 if (!myIsPreviewMode) {
4013 TPythonDump() << this << ".TranslateObject( "
4014 << theObject << ", "
4015 << theVector << ", "
4018 TIDSortedElemSet elements;
4020 bool emptyIfIsMesh = myIsPreviewMode ? false : true;
4022 if (idSourceToSet(theObject, getMeshDS(), elements, SMDSAbs_All, emptyIfIsMesh))
4023 translate(elements, theVector, theCopy, false);
4026 //=======================================================================
4027 //function : TranslateMakeGroups
4029 //=======================================================================
4031 SMESH::ListOfGroups*
4032 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
4033 const SMESH::DirStruct& theVector)
4034 throw (SALOME::SALOME_Exception)
4036 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
4038 SMESH::ListOfGroups * aGroups = 0;
4039 if (theIDsOfElements.length()) {
4040 TIDSortedElemSet elements;
4041 arrayToSet(theIDsOfElements, getMeshDS(), elements);
4042 aGroups = translate(elements,theVector,true,true);
4044 if (!myIsPreviewMode) {
4045 dumpGroupsList(aPythonDump, aGroups);
4046 aPythonDump << this << ".TranslateMakeGroups( "
4047 << theIDsOfElements << ", "
4048 << theVector << " )";
4053 //=======================================================================
4054 //function : TranslateObjectMakeGroups
4056 //=======================================================================
4058 SMESH::ListOfGroups*
4059 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
4060 const SMESH::DirStruct& theVector)
4061 throw (SALOME::SALOME_Exception)
4063 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
4065 SMESH::ListOfGroups * aGroups = 0;
4066 TIDSortedElemSet elements;
4067 if (idSourceToSet(theObject, getMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
4068 aGroups = translate(elements, theVector, true, true);
4070 if (!myIsPreviewMode) {
4071 dumpGroupsList(aPythonDump, aGroups);
4072 aPythonDump << this << ".TranslateObjectMakeGroups( "
4073 << theObject << ", "
4074 << theVector << " )";
4079 //=======================================================================
4080 //function : TranslateMakeMesh
4082 //=======================================================================
4084 SMESH::SMESH_Mesh_ptr
4085 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
4086 const SMESH::DirStruct& theVector,
4087 CORBA::Boolean theCopyGroups,
4088 const char* theMeshName)
4089 throw (SALOME::SALOME_Exception)
4091 SMESH_Mesh_i* mesh_i;
4092 SMESH::SMESH_Mesh_var mesh;
4094 { // open new scope to dump "MakeMesh" command
4095 // and then "GetGroups" using SMESH_Mesh::GetGroups()
4097 TPythonDump pydump; // to prevent dump at mesh creation
4099 mesh = makeMesh( theMeshName );
4100 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
4102 if ( mesh_i && theIDsOfElements.length() )
4104 TIDSortedElemSet elements;
4105 arrayToSet(theIDsOfElements, getMeshDS(), elements);
4106 translate(elements, theVector, false, theCopyGroups, & mesh_i->GetImpl());
4107 mesh_i->CreateGroupServants();
4110 if ( !myIsPreviewMode ) {
4111 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
4112 << theIDsOfElements << ", "
4113 << theVector << ", "
4114 << theCopyGroups << ", '"
4115 << theMeshName << "' )";
4120 if (!myIsPreviewMode && mesh_i)
4121 mesh_i->GetGroups();
4123 return mesh._retn();
4126 //=======================================================================
4127 //function : TranslateObjectMakeMesh
4129 //=======================================================================
4131 SMESH::SMESH_Mesh_ptr
4132 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
4133 const SMESH::DirStruct& theVector,
4134 CORBA::Boolean theCopyGroups,
4135 const char* theMeshName)
4136 throw (SALOME::SALOME_Exception)
4139 SMESH_Mesh_i* mesh_i;
4140 SMESH::SMESH_Mesh_var mesh;
4141 { // open new scope to dump "MakeMesh" command
4142 // and then "GetGroups" using SMESH_Mesh::GetGroups()
4144 TPythonDump pydump; // to prevent dump at mesh creation
4145 mesh = makeMesh( theMeshName );
4146 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
4148 TIDSortedElemSet elements;
4150 idSourceToSet(theObject, getMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
4152 translate(elements, theVector,false, theCopyGroups, & mesh_i->GetImpl());
4153 mesh_i->CreateGroupServants();
4155 if ( !myIsPreviewMode ) {
4156 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
4157 << theObject << ", "
4158 << theVector << ", "
4159 << theCopyGroups << ", '"
4160 << theMeshName << "' )";
4165 if (!myIsPreviewMode && mesh_i)
4166 mesh_i->GetGroups();
4168 return mesh._retn();
4170 SMESH_CATCH( SMESH::throwCorbaException );
4174 //=======================================================================
4177 //=======================================================================
4179 SMESH::ListOfGroups*
4180 SMESH_MeshEditor_i::rotate(TIDSortedElemSet & theElements,
4181 const SMESH::AxisStruct & theAxis,
4182 CORBA::Double theAngle,
4183 CORBA::Boolean theCopy,
4185 ::SMESH_Mesh* theTargetMesh)
4186 throw (SALOME::SALOME_Exception)
4191 if ( theTargetMesh )
4194 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
4195 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
4198 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
4200 TIDSortedElemSet copyElements;
4201 TIDSortedElemSet* workElements = &theElements;
4202 if ( myIsPreviewMode ) {
4203 TPreviewMesh * tmpMesh = getPreviewMesh();
4204 tmpMesh->Copy( theElements, copyElements );
4205 if ( !theCopy && !theTargetMesh )
4207 TIDSortedElemSet elemsAround, elemsAroundCopy;
4208 getElementsAround( theElements, getMeshDS(), elemsAround );
4209 tmpMesh->Copy( elemsAround, elemsAroundCopy);
4211 workElements = ©Elements;
4212 theMakeGroups = false;
4215 ::SMESH_MeshEditor::PGroupIDs groupIds =
4216 getEditor().Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
4218 if ( theCopy && !myIsPreviewMode)
4220 if ( theTargetMesh ) theTargetMesh->GetMeshDS()->Modified();
4221 else declareMeshModified( /*isReComputeSafe=*/false );
4224 return theMakeGroups ? getGroups(groupIds.get()) : 0;
4226 SMESH_CATCH( SMESH::throwCorbaException );
4230 //=======================================================================
4233 //=======================================================================
4235 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
4236 const SMESH::AxisStruct & theAxis,
4237 CORBA::Double theAngle,
4238 CORBA::Boolean theCopy)
4239 throw (SALOME::SALOME_Exception)
4241 if (!myIsPreviewMode) {
4242 TPythonDump() << this << ".Rotate( "
4243 << theIDsOfElements << ", "
4245 << TVar( theAngle ) << ", "
4248 if (theIDsOfElements.length() > 0)
4250 TIDSortedElemSet elements;
4251 arrayToSet(theIDsOfElements, getMeshDS(), elements);
4252 rotate(elements,theAxis,theAngle,theCopy,false);
4256 //=======================================================================
4257 //function : RotateObject
4259 //=======================================================================
4261 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
4262 const SMESH::AxisStruct & theAxis,
4263 CORBA::Double theAngle,
4264 CORBA::Boolean theCopy)
4265 throw (SALOME::SALOME_Exception)
4267 if ( !myIsPreviewMode ) {
4268 TPythonDump() << this << ".RotateObject( "
4269 << theObject << ", "
4271 << TVar( theAngle ) << ", "
4274 TIDSortedElemSet elements;
4275 bool emptyIfIsMesh = myIsPreviewMode ? false : true;
4276 if (idSourceToSet(theObject, getMeshDS(), elements, SMDSAbs_All, emptyIfIsMesh))
4277 rotate(elements,theAxis,theAngle,theCopy,false);
4280 //=======================================================================
4281 //function : RotateMakeGroups
4283 //=======================================================================
4285 SMESH::ListOfGroups*
4286 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
4287 const SMESH::AxisStruct& theAxis,
4288 CORBA::Double theAngle)
4289 throw (SALOME::SALOME_Exception)
4291 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
4293 SMESH::ListOfGroups * aGroups = 0;
4294 if (theIDsOfElements.length() > 0)
4296 TIDSortedElemSet elements;
4297 arrayToSet(theIDsOfElements, getMeshDS(), elements);
4298 aGroups = rotate(elements,theAxis,theAngle,true,true);
4300 if (!myIsPreviewMode) {
4301 dumpGroupsList(aPythonDump, aGroups);
4302 aPythonDump << this << ".RotateMakeGroups( "
4303 << theIDsOfElements << ", "
4305 << TVar( theAngle ) << " )";
4310 //=======================================================================
4311 //function : RotateObjectMakeGroups
4313 //=======================================================================
4315 SMESH::ListOfGroups*
4316 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
4317 const SMESH::AxisStruct& theAxis,
4318 CORBA::Double theAngle)
4319 throw (SALOME::SALOME_Exception)
4321 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
4323 SMESH::ListOfGroups * aGroups = 0;
4324 TIDSortedElemSet elements;
4325 if (idSourceToSet(theObject, getMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
4326 aGroups = rotate(elements, theAxis, theAngle, true, true);
4328 if (!myIsPreviewMode) {
4329 dumpGroupsList(aPythonDump, aGroups);
4330 aPythonDump << this << ".RotateObjectMakeGroups( "
4331 << theObject << ", "
4333 << TVar( theAngle ) << " )";
4338 //=======================================================================
4339 //function : RotateMakeMesh
4341 //=======================================================================
4343 SMESH::SMESH_Mesh_ptr
4344 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
4345 const SMESH::AxisStruct& theAxis,
4346 CORBA::Double theAngleInRadians,
4347 CORBA::Boolean theCopyGroups,
4348 const char* theMeshName)
4349 throw (SALOME::SALOME_Exception)
4352 SMESH::SMESH_Mesh_var mesh;
4353 SMESH_Mesh_i* mesh_i;
4355 { // open new scope to dump "MakeMesh" command
4356 // and then "GetGroups" using SMESH_Mesh::GetGroups()
4358 TPythonDump pydump; // to prevent dump at mesh creation
4360 mesh = makeMesh( theMeshName );
4361 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
4363 if ( mesh_i && theIDsOfElements.length() > 0 )
4365 TIDSortedElemSet elements;
4366 arrayToSet(theIDsOfElements, getMeshDS(), elements);
4367 rotate(elements, theAxis, theAngleInRadians,
4368 false, theCopyGroups, & mesh_i->GetImpl());
4369 mesh_i->CreateGroupServants();
4371 if ( !myIsPreviewMode ) {
4372 pydump << mesh << " = " << this << ".RotateMakeMesh( "
4373 << theIDsOfElements << ", "
4375 << TVar( theAngleInRadians ) << ", "
4376 << theCopyGroups << ", '"
4377 << theMeshName << "' )";
4382 if (!myIsPreviewMode && mesh_i && theIDsOfElements.length() > 0 )
4383 mesh_i->GetGroups();
4385 return mesh._retn();
4387 SMESH_CATCH( SMESH::throwCorbaException );
4391 //=======================================================================
4392 //function : RotateObjectMakeMesh
4394 //=======================================================================
4396 SMESH::SMESH_Mesh_ptr
4397 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
4398 const SMESH::AxisStruct& theAxis,
4399 CORBA::Double theAngleInRadians,
4400 CORBA::Boolean theCopyGroups,
4401 const char* theMeshName)
4402 throw (SALOME::SALOME_Exception)
4405 SMESH::SMESH_Mesh_var mesh;
4406 SMESH_Mesh_i* mesh_i;
4408 {// open new scope to dump "MakeMesh" command
4409 // and then "GetGroups" using SMESH_Mesh::GetGroups()
4411 TPythonDump pydump; // to prevent dump at mesh creation
4412 mesh = makeMesh( theMeshName );
4413 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
4415 TIDSortedElemSet elements;
4417 idSourceToSet(theObject, getMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
4419 rotate(elements, theAxis, theAngleInRadians,
4420 false, theCopyGroups, & mesh_i->GetImpl());
4421 mesh_i->CreateGroupServants();
4423 if ( !myIsPreviewMode ) {
4424 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
4425 << theObject << ", "
4427 << TVar( theAngleInRadians ) << ", "
4428 << theCopyGroups << ", '"
4429 << theMeshName << "' )";
4434 if (!myIsPreviewMode && mesh_i)
4435 mesh_i->GetGroups();
4437 return mesh._retn();
4439 SMESH_CATCH( SMESH::throwCorbaException );
4443 //=======================================================================
4446 //=======================================================================
4448 SMESH::ListOfGroups*
4449 SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr theObject,
4450 const SMESH::PointStruct& thePoint,
4451 const SMESH::double_array& theScaleFact,
4452 CORBA::Boolean theCopy,
4454 ::SMESH_Mesh* theTargetMesh)
4455 throw (SALOME::SALOME_Exception)
4459 if ( theScaleFact.length() < 1 )
4460 THROW_SALOME_CORBA_EXCEPTION("Scale factor not given", SALOME::BAD_PARAM);
4461 if ( theScaleFact.length() == 2 )
4462 THROW_SALOME_CORBA_EXCEPTION("Invalid nb of scale factors : 2", SALOME::BAD_PARAM);
4464 if ( theTargetMesh )
4467 TIDSortedElemSet elements;
4468 bool emptyIfIsMesh = myIsPreviewMode ? false : true;
4469 if ( !idSourceToSet(theObject, getMeshDS(), elements, SMDSAbs_All, emptyIfIsMesh))
4474 (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[1],
4475 (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[2],
4477 double tol = std::numeric_limits<double>::max();
4479 aTrsf.SetValues( S[0], 0, 0, thePoint.x * (1-S[0]),
4480 0, S[1], 0, thePoint.y * (1-S[1]),
4481 0, 0, S[2], thePoint.z * (1-S[2]), tol, tol);
4483 TIDSortedElemSet copyElements;
4484 TIDSortedElemSet* workElements = &elements;
4485 if ( myIsPreviewMode )
4487 TPreviewMesh * tmpMesh = getPreviewMesh();
4488 tmpMesh->Copy( elements, copyElements);
4489 if ( !theCopy && !theTargetMesh )
4491 TIDSortedElemSet elemsAround, elemsAroundCopy;
4492 getElementsAround( elements, getMeshDS(), elemsAround );
4493 tmpMesh->Copy( elemsAround, elemsAroundCopy);
4495 workElements = & copyElements;
4496 theMakeGroups = false;
4499 ::SMESH_MeshEditor::PGroupIDs groupIds =
4500 getEditor().Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
4502 if ( theCopy && !myIsPreviewMode )
4504 if ( theTargetMesh ) theTargetMesh->GetMeshDS()->Modified();
4505 else declareMeshModified( /*isReComputeSafe=*/false );
4507 return theMakeGroups ? getGroups(groupIds.get()) : 0;
4509 SMESH_CATCH( SMESH::throwCorbaException );
4513 //=======================================================================
4516 //=======================================================================
4518 void SMESH_MeshEditor_i::Scale(SMESH::SMESH_IDSource_ptr theObject,
4519 const SMESH::PointStruct& thePoint,
4520 const SMESH::double_array& theScaleFact,
4521 CORBA::Boolean theCopy)
4522 throw (SALOME::SALOME_Exception)
4524 if ( !myIsPreviewMode ) {
4525 TPythonDump() << this << ".Scale( "
4526 << theObject << ", "
4528 << TVar( theScaleFact ) << ", "
4531 scale(theObject, thePoint, theScaleFact, theCopy, false);
4535 //=======================================================================
4536 //function : ScaleMakeGroups
4538 //=======================================================================
4540 SMESH::ListOfGroups*
4541 SMESH_MeshEditor_i::ScaleMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
4542 const SMESH::PointStruct& thePoint,
4543 const SMESH::double_array& theScaleFact)
4544 throw (SALOME::SALOME_Exception)
4546 TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
4548 SMESH::ListOfGroups * aGroups = scale(theObject, thePoint, theScaleFact, true, true);
4549 if (!myIsPreviewMode) {
4550 dumpGroupsList(aPythonDump, aGroups);
4551 aPythonDump << this << ".Scale("
4554 << TVar( theScaleFact ) << ",True,True)";
4560 //=======================================================================
4561 //function : ScaleMakeMesh
4563 //=======================================================================
4565 SMESH::SMESH_Mesh_ptr
4566 SMESH_MeshEditor_i::ScaleMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
4567 const SMESH::PointStruct& thePoint,
4568 const SMESH::double_array& theScaleFact,
4569 CORBA::Boolean theCopyGroups,
4570 const char* theMeshName)
4571 throw (SALOME::SALOME_Exception)
4573 SMESH_Mesh_i* mesh_i;
4574 SMESH::SMESH_Mesh_var mesh;
4575 { // open new scope to dump "MakeMesh" command
4576 // and then "GetGroups" using SMESH_Mesh::GetGroups()
4578 TPythonDump pydump; // to prevent dump at mesh creation
4579 mesh = makeMesh( theMeshName );
4580 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
4584 scale(theObject, thePoint, theScaleFact,false, theCopyGroups, & mesh_i->GetImpl());
4585 mesh_i->CreateGroupServants();
4587 if ( !myIsPreviewMode )
4588 pydump << mesh << " = " << this << ".ScaleMakeMesh( "
4589 << theObject << ", "
4591 << TVar( theScaleFact ) << ", "
4592 << theCopyGroups << ", '"
4593 << theMeshName << "' )";
4597 if (!myIsPreviewMode && mesh_i)
4598 mesh_i->GetGroups();
4600 return mesh._retn();
4604 //=======================================================================
4605 //function : FindCoincidentNodes
4607 //=======================================================================
4609 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
4610 SMESH::array_of_long_array_out GroupsOfNodes)
4611 throw (SALOME::SALOME_Exception)
4616 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
4617 TIDSortedNodeSet nodes; // no input nodes
4618 getEditor().FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
4620 GroupsOfNodes = new SMESH::array_of_long_array;
4621 GroupsOfNodes->length( aListOfListOfNodes.size() );
4622 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
4623 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
4624 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
4625 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
4626 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
4627 aGroup.length( aListOfNodes.size() );
4628 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
4629 aGroup[ j ] = (*lIt)->GetID();
4631 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
4632 << Tolerance << " )";
4634 SMESH_CATCH( SMESH::throwCorbaException );
4637 //=======================================================================
4638 //function : FindCoincidentNodesOnPart
4640 //=======================================================================
4642 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
4643 CORBA::Double Tolerance,
4644 SMESH::array_of_long_array_out GroupsOfNodes)
4645 throw (SALOME::SALOME_Exception)
4650 TIDSortedNodeSet nodes;
4651 idSourceToNodeSet( theObject, getMeshDS(), nodes );
4653 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
4655 getEditor().FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
4657 GroupsOfNodes = new SMESH::array_of_long_array;
4658 GroupsOfNodes->length( aListOfListOfNodes.size() );
4659 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
4660 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
4662 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
4663 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
4664 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
4665 aGroup.length( aListOfNodes.size() );
4666 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
4667 aGroup[ j ] = (*lIt)->GetID();
4669 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
4671 << Tolerance << " )";
4673 SMESH_CATCH( SMESH::throwCorbaException );
4676 //================================================================================
4678 * \brief Finds nodes coinsident with Tolerance within Object excluding nodes within
4679 * ExceptSubMeshOrGroups
4681 //================================================================================
4683 void SMESH_MeshEditor_i::
4684 FindCoincidentNodesOnPartBut(SMESH::SMESH_IDSource_ptr theObject,
4685 CORBA::Double theTolerance,
4686 SMESH::array_of_long_array_out theGroupsOfNodes,
4687 const SMESH::ListOfIDSources& theExceptSubMeshOrGroups)
4688 throw (SALOME::SALOME_Exception)
4693 TIDSortedNodeSet nodes;
4694 idSourceToNodeSet( theObject, getMeshDS(), nodes );
4696 for ( int i = 0; i < theExceptSubMeshOrGroups.length(); ++i )
4698 TIDSortedNodeSet exceptNodes;
4699 idSourceToNodeSet( theExceptSubMeshOrGroups[i], getMeshDS(), exceptNodes );
4700 TIDSortedNodeSet::iterator avoidNode = exceptNodes.begin();
4701 for ( ; avoidNode != exceptNodes.end(); ++avoidNode)
4702 nodes.erase( *avoidNode );
4704 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
4706 getEditor().FindCoincidentNodes( nodes, theTolerance, aListOfListOfNodes );
4708 theGroupsOfNodes = new SMESH::array_of_long_array;
4709 theGroupsOfNodes->length( aListOfListOfNodes.size() );
4710 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
4711 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
4713 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
4714 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
4715 SMESH::long_array& aGroup = (*theGroupsOfNodes)[ i ];
4716 aGroup.length( aListOfNodes.size() );
4717 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
4718 aGroup[ j ] = (*lIt)->GetID();
4720 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPartBut( "
4722 << theTolerance << ", "
4723 << theExceptSubMeshOrGroups << " )";
4725 SMESH_CATCH( SMESH::throwCorbaException );
4728 //=======================================================================
4729 //function : MergeNodes
4731 //=======================================================================
4733 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
4734 throw (SALOME::SALOME_Exception)
4739 SMESHDS_Mesh* aMesh = getMeshDS();
4741 TPythonDump aTPythonDump;
4742 aTPythonDump << this << ".MergeNodes([";
4743 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
4744 for (int i = 0; i < GroupsOfNodes.length(); i++)
4746 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
4747 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
4748 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
4749 for ( int j = 0; j < aNodeGroup.length(); j++ )
4751 CORBA::Long index = aNodeGroup[ j ];
4752 const SMDS_MeshNode * node = aMesh->FindNode(index);
4754 aListOfNodes.push_back( node );
4756 if ( aListOfNodes.size() < 2 )
4757 aListOfListOfNodes.pop_back();
4759 if ( i > 0 ) aTPythonDump << ", ";
4760 aTPythonDump << aNodeGroup;
4762 getEditor().MergeNodes( aListOfListOfNodes );
4764 aTPythonDump << "])";
4766 declareMeshModified( /*isReComputeSafe=*/false );
4768 SMESH_CATCH( SMESH::throwCorbaException );
4771 //=======================================================================
4772 //function : FindEqualElements
4774 //=======================================================================
4776 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
4777 SMESH::array_of_long_array_out GroupsOfElementsID)
4778 throw (SALOME::SALOME_Exception)
4783 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow(theObject);
4784 if ( !(!group->_is_nil() && group->GetType() == SMESH::NODE) )
4786 TIDSortedElemSet elems;
4787 idSourceToSet( theObject, getMeshDS(), elems, SMDSAbs_All, /*emptyIfIsMesh=*/true);
4789 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
4790 getEditor().FindEqualElements( elems, aListOfListOfElementsID );
4792 GroupsOfElementsID = new SMESH::array_of_long_array;
4793 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
4795 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt =
4796 aListOfListOfElementsID.begin();
4797 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j)
4799 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
4800 list<int>& listOfIDs = *arraysIt;
4801 aGroup.length( listOfIDs.size() );
4802 list<int>::iterator idIt = listOfIDs.begin();
4803 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k )
4804 aGroup[ k ] = *idIt;
4807 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
4811 SMESH_CATCH( SMESH::throwCorbaException );
4814 //=======================================================================
4815 //function : MergeElements
4817 //=======================================================================
4819 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
4820 throw (SALOME::SALOME_Exception)
4825 TPythonDump aTPythonDump;
4826 aTPythonDump << this << ".MergeElements( [";
4828 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
4830 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
4831 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
4832 aListOfListOfElementsID.push_back( list< int >() );
4833 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
4834 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
4835 CORBA::Long id = anElemsIDGroup[ j ];
4836 aListOfElemsID.push_back( id );
4838 if ( aListOfElemsID.size() < 2 )
4839 aListOfListOfElementsID.pop_back();
4840 if ( i > 0 ) aTPythonDump << ", ";
4841 aTPythonDump << anElemsIDGroup;
4844 getEditor().MergeElements(aListOfListOfElementsID);
4846 declareMeshModified( /*isReComputeSafe=*/true );
4848 aTPythonDump << "] )";
4850 SMESH_CATCH( SMESH::throwCorbaException );
4853 //=======================================================================
4854 //function : MergeEqualElements
4856 //=======================================================================
4858 void SMESH_MeshEditor_i::MergeEqualElements()
4859 throw (SALOME::SALOME_Exception)
4864 getEditor().MergeEqualElements();
4866 declareMeshModified( /*isReComputeSafe=*/true );
4868 TPythonDump() << this << ".MergeEqualElements()";
4870 SMESH_CATCH( SMESH::throwCorbaException );
4873 //=============================================================================
4875 * Move the node to a given point
4877 //=============================================================================
4879 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
4883 throw (SALOME::SALOME_Exception)
4886 initData(/*deleteSearchers=*/false);
4888 const SMDS_MeshNode * node = getMeshDS()->FindNode( NodeID );
4892 if ( theNodeSearcher )
4893 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
4895 if ( myIsPreviewMode ) // make preview data
4897 // in a preview mesh, make edges linked to a node
4898 TPreviewMesh& tmpMesh = *getPreviewMesh();
4899 TIDSortedElemSet linkedNodes;
4900 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
4901 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
4902 SMDS_MeshNode *nodeCpy1 = tmpMesh.Copy(node);
4903 for ( ; nIt != linkedNodes.end(); ++nIt )
4905 SMDS_MeshNode *nodeCpy2 = tmpMesh.Copy ( cast2Node( *nIt ));
4906 tmpMesh.GetMeshDS()->AddEdge(nodeCpy1, nodeCpy2);
4910 tmpMesh.GetMeshDS()->MoveNode(nodeCpy1, x, y, z);
4911 // fill preview data
4913 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
4914 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
4916 getMeshDS()->MoveNode(node, x, y, z);
4918 if ( !myIsPreviewMode )
4920 // Update Python script
4921 TPythonDump() << "isDone = " << this << ".MoveNode( "
4922 << NodeID << ", " << TVar(x) << ", " << TVar(y) << ", " << TVar(z) << " )";
4923 declareMeshModified( /*isReComputeSafe=*/false );
4926 SMESH_CATCH( SMESH::throwCorbaException );
4931 //================================================================================
4933 * \brief Return ID of node closest to a given point
4935 //================================================================================
4937 CORBA::Long SMESH_MeshEditor_i::FindNodeClosestTo(CORBA::Double x,
4940 throw (SALOME::SALOME_Exception)
4943 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
4945 if ( !theNodeSearcher ) {
4946 theNodeSearcher = SMESH_MeshAlgos::GetNodeSearcher( *getMeshDS() );
4949 if ( const SMDS_MeshNode* node = theNodeSearcher->FindClosestTo( p ))
4950 return node->GetID();
4952 SMESH_CATCH( SMESH::throwCorbaException );
4956 //================================================================================
4958 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
4959 * move the node closest to the point to point's location and return ID of the node
4961 //================================================================================
4963 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
4966 CORBA::Long theNodeID)
4967 throw (SALOME::SALOME_Exception)
4970 // We keep theNodeSearcher until any mesh modification:
4971 // 1) initData() deletes theNodeSearcher at any edition,
4972 // 2) TSearchersDeleter - at any mesh compute event and mesh change
4974 initData(/*deleteSearchers=*/false);
4976 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
4978 int nodeID = theNodeID;
4979 const SMDS_MeshNode* node = getMeshDS()->FindNode( nodeID );
4980 if ( !node ) // preview moving node
4982 if ( !theNodeSearcher ) {
4983 theNodeSearcher = SMESH_MeshAlgos::GetNodeSearcher( *getMeshDS() );
4986 node = theNodeSearcher->FindClosestTo( p );
4989 nodeID = node->GetID();
4990 if ( myIsPreviewMode ) // make preview data
4992 // in a preview mesh, make edges linked to a node
4993 TPreviewMesh tmpMesh = *getPreviewMesh();
4994 TIDSortedElemSet linkedNodes;
4995 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
4996 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
4997 for ( ; nIt != linkedNodes.end(); ++nIt )
4999 SMDS_LinearEdge edge( node, cast2Node( *nIt ));
5000 tmpMesh.Copy( &edge );
5003 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
5005 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
5006 // fill preview data
5008 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
5010 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
5014 getMeshDS()->MoveNode(node, x, y, z);
5018 if ( !myIsPreviewMode )
5020 TPythonDump() << "nodeID = " << this
5021 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
5022 << ", " << nodeID << " )";
5024 declareMeshModified( /*isReComputeSafe=*/false );
5029 SMESH_CATCH( SMESH::throwCorbaException );
5033 //=======================================================================
5035 * Return elements of given type where the given point is IN or ON.
5037 * 'ALL' type means elements of any type excluding nodes
5039 //=======================================================================
5041 SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double x,
5044 SMESH::ElementType type)
5045 throw (SALOME::SALOME_Exception)
5048 SMESH::long_array_var res = new SMESH::long_array;
5049 vector< const SMDS_MeshElement* > foundElems;
5051 theSearchersDeleter.Set( myMesh );
5052 if ( !theElementSearcher ) {
5053 theElementSearcher = SMESH_MeshAlgos::GetElementSearcher( *getMeshDS() );
5055 theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ),
5056 SMDSAbs_ElementType( type ),
5058 res->length( foundElems.size() );
5059 for ( int i = 0; i < foundElems.size(); ++i )
5060 res[i] = foundElems[i]->GetID();
5062 if ( !myIsPreviewMode ) // call from tui
5063 TPythonDump() << "res = " << this << ".FindElementsByPoint( "
5071 SMESH_CATCH( SMESH::throwCorbaException );
5075 //=======================================================================
5076 //function : FindAmongElementsByPoint
5077 //purpose : Searching among the given elements, return elements of given type
5078 // where the given point is IN or ON.
5079 // 'ALL' type means elements of any type excluding nodes
5080 //=======================================================================
5083 SMESH_MeshEditor_i::FindAmongElementsByPoint(SMESH::SMESH_IDSource_ptr elementIDs,
5087 SMESH::ElementType type)
5088 throw (SALOME::SALOME_Exception)
5091 SMESH::long_array_var res = new SMESH::long_array;
5093 SMESH::array_of_ElementType_var types = elementIDs->GetTypes();
5094 if ( types->length() == 1 && // a part contains only nodes or 0D elements
5095 ( types[0] == SMESH::NODE || types[0] == SMESH::ELEM0D || types[0] == SMESH::BALL) &&
5096 type != types[0] ) // but search of elements of dim > 0
5099 if ( SMESH::DownCast<SMESH_Mesh_i*>( elementIDs )) // elementIDs is the whole mesh
5100 return FindElementsByPoint( x,y,z, type );
5102 TIDSortedElemSet elements; // elems should live until FindElementsByPoint() finishes
5104 theSearchersDeleter.Set( myMesh, getPartIOR( elementIDs, type ));
5105 if ( !theElementSearcher )
5107 // create a searcher from elementIDs
5108 SMESH::SMESH_Mesh_var mesh = elementIDs->GetMesh();
5109 SMESHDS_Mesh* meshDS = SMESH::DownCast<SMESH_Mesh_i*>( mesh )->GetImpl().GetMeshDS();
5111 if ( !idSourceToSet( elementIDs, meshDS, elements,
5112 SMDSAbs_ElementType(type), /*emptyIfIsMesh=*/true))
5115 typedef SMDS_SetIterator<const SMDS_MeshElement*, TIDSortedElemSet::const_iterator > TIter;
5116 SMDS_ElemIteratorPtr elemsIt( new TIter( elements.begin(), elements.end() ));
5118 theElementSearcher = SMESH_MeshAlgos::GetElementSearcher( *getMeshDS(), elemsIt );
5121 vector< const SMDS_MeshElement* > foundElems;
5123 theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ),
5124 SMDSAbs_ElementType( type ),
5126 res->length( foundElems.size() );
5127 for ( int i = 0; i < foundElems.size(); ++i )
5128 res[i] = foundElems[i]->GetID();
5130 if ( !myIsPreviewMode ) // call from tui
5131 TPythonDump() << "res = " << this << ".FindAmongElementsByPoint( "
5132 << elementIDs << ", "
5140 SMESH_CATCH( SMESH::throwCorbaException );
5144 //=======================================================================
5145 //function : GetPointState
5146 //purpose : Return point state in a closed 2D mesh in terms of TopAbs_State enumeration.
5147 // TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
5148 //=======================================================================
5150 CORBA::Short SMESH_MeshEditor_i::GetPointState(CORBA::Double x,
5153 throw (SALOME::SALOME_Exception)
5156 theSearchersDeleter.Set( myMesh );
5157 if ( !theElementSearcher ) {
5158 theElementSearcher = SMESH_MeshAlgos::GetElementSearcher( *getMeshDS() );
5160 return CORBA::Short( theElementSearcher->GetPointState( gp_Pnt( x,y,z )));
5162 SMESH_CATCH( SMESH::throwCorbaException );
5166 //=======================================================================
5167 //function : convError
5169 //=======================================================================
5171 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
5173 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
5177 RETCASE( SEW_BORDER1_NOT_FOUND );
5178 RETCASE( SEW_BORDER2_NOT_FOUND );
5179 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
5180 RETCASE( SEW_BAD_SIDE_NODES );
5181 RETCASE( SEW_VOLUMES_TO_SPLIT );
5182 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
5183 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
5184 RETCASE( SEW_BAD_SIDE1_NODES );
5185 RETCASE( SEW_BAD_SIDE2_NODES );
5187 return SMESH::SMESH_MeshEditor::SEW_OK;
5190 //=======================================================================
5191 //function : SewFreeBorders
5193 //=======================================================================
5195 SMESH::SMESH_MeshEditor::Sew_Error
5196 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
5197 CORBA::Long SecondNodeID1,
5198 CORBA::Long LastNodeID1,
5199 CORBA::Long FirstNodeID2,
5200 CORBA::Long SecondNodeID2,
5201 CORBA::Long LastNodeID2,
5202 CORBA::Boolean CreatePolygons,
5203 CORBA::Boolean CreatePolyedrs)
5204 throw (SALOME::SALOME_Exception)
5209 SMESHDS_Mesh* aMesh = getMeshDS();
5211 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
5212 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
5213 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
5214 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
5215 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
5216 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
5218 if (!aBorderFirstNode ||
5219 !aBorderSecondNode||
5221 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
5222 if (!aSide2FirstNode ||
5223 !aSide2SecondNode ||
5225 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
5227 TPythonDump() << "error = " << this << ".SewFreeBorders( "
5228 << FirstNodeID1 << ", "
5229 << SecondNodeID1 << ", "
5230 << LastNodeID1 << ", "
5231 << FirstNodeID2 << ", "
5232 << SecondNodeID2 << ", "
5233 << LastNodeID2 << ", "
5234 << CreatePolygons<< ", "
5235 << CreatePolyedrs<< " )";
5237 SMESH::SMESH_MeshEditor::Sew_Error error =
5238 convError( getEditor().SewFreeBorder (aBorderFirstNode,
5249 declareMeshModified( /*isReComputeSafe=*/false );
5252 SMESH_CATCH( SMESH::throwCorbaException );
5253 return SMESH::SMESH_MeshEditor::Sew_Error(0);
5257 //=======================================================================
5258 //function : SewConformFreeBorders
5260 //=======================================================================
5262 SMESH::SMESH_MeshEditor::Sew_Error
5263 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
5264 CORBA::Long SecondNodeID1,
5265 CORBA::Long LastNodeID1,
5266 CORBA::Long FirstNodeID2,
5267 CORBA::Long SecondNodeID2)
5268 throw (SALOME::SALOME_Exception)
5273 SMESHDS_Mesh* aMesh = getMeshDS();
5275 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
5276 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
5277 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
5278 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
5279 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
5280 const SMDS_MeshNode* aSide2ThirdNode = 0;
5282 if (!aBorderFirstNode ||
5283 !aBorderSecondNode||
5285 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
5286 if (!aSide2FirstNode ||
5288 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
5290 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
5291 << FirstNodeID1 << ", "
5292 << SecondNodeID1 << ", "
5293 << LastNodeID1 << ", "
5294 << FirstNodeID2 << ", "
5295 << SecondNodeID2 << " )";
5297 SMESH::SMESH_MeshEditor::Sew_Error error =
5298 convError( getEditor().SewFreeBorder (aBorderFirstNode,
5307 declareMeshModified( /*isReComputeSafe=*/false );
5310 SMESH_CATCH( SMESH::throwCorbaException );
5311 return SMESH::SMESH_MeshEditor::Sew_Error(0);
5315 //=======================================================================
5316 //function : SewBorderToSide
5318 //=======================================================================
5320 SMESH::SMESH_MeshEditor::Sew_Error
5321 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
5322 CORBA::Long SecondNodeIDOnFreeBorder,
5323 CORBA::Long LastNodeIDOnFreeBorder,
5324 CORBA::Long FirstNodeIDOnSide,
5325 CORBA::Long LastNodeIDOnSide,
5326 CORBA::Boolean CreatePolygons,
5327 CORBA::Boolean CreatePolyedrs)
5328 throw (SALOME::SALOME_Exception)
5333 SMESHDS_Mesh* aMesh = getMeshDS();
5335 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
5336 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
5337 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
5338 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
5339 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
5340 const SMDS_MeshNode* aSide2ThirdNode = 0;
5342 if (!aBorderFirstNode ||
5343 !aBorderSecondNode||
5345 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
5346 if (!aSide2FirstNode ||
5348 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
5350 TPythonDump() << "error = " << this << ".SewBorderToSide( "
5351 << FirstNodeIDOnFreeBorder << ", "
5352 << SecondNodeIDOnFreeBorder << ", "
5353 << LastNodeIDOnFreeBorder << ", "
5354 << FirstNodeIDOnSide << ", "
5355 << LastNodeIDOnSide << ", "
5356 << CreatePolygons << ", "
5357 << CreatePolyedrs << ") ";
5359 SMESH::SMESH_MeshEditor::Sew_Error error =
5360 convError( getEditor().SewFreeBorder (aBorderFirstNode,
5370 declareMeshModified( /*isReComputeSafe=*/false );
5373 SMESH_CATCH( SMESH::throwCorbaException );
5374 return SMESH::SMESH_MeshEditor::Sew_Error(0);
5378 //=======================================================================
5379 //function : SewSideElements
5381 //=======================================================================
5383 SMESH::SMESH_MeshEditor::Sew_Error
5384 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
5385 const SMESH::long_array& IDsOfSide2Elements,
5386 CORBA::Long NodeID1OfSide1ToMerge,
5387 CORBA::Long NodeID1OfSide2ToMerge,
5388 CORBA::Long NodeID2OfSide1ToMerge,
5389 CORBA::Long NodeID2OfSide2ToMerge)
5390 throw (SALOME::SALOME_Exception)
5395 SMESHDS_Mesh* aMesh = getMeshDS();
5397 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
5398 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
5399 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
5400 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
5402 if (!aFirstNode1ToMerge ||
5403 !aFirstNode2ToMerge )
5404 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
5405 if (!aSecondNode1ToMerge||
5406 !aSecondNode2ToMerge)
5407 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
5409 TIDSortedElemSet aSide1Elems, aSide2Elems;
5410 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
5411 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
5413 TPythonDump() << "error = " << this << ".SewSideElements( "
5414 << IDsOfSide1Elements << ", "
5415 << IDsOfSide2Elements << ", "
5416 << NodeID1OfSide1ToMerge << ", "
5417 << NodeID1OfSide2ToMerge << ", "
5418 << NodeID2OfSide1ToMerge << ", "
5419 << NodeID2OfSide2ToMerge << ")";
5421 SMESH::SMESH_MeshEditor::Sew_Error error =
5422 convError( getEditor().SewSideElements (aSide1Elems, aSide2Elems,
5425 aSecondNode1ToMerge,
5426 aSecondNode2ToMerge));
5428 declareMeshModified( /*isReComputeSafe=*/false );
5431 SMESH_CATCH( SMESH::throwCorbaException );
5432 return SMESH::SMESH_MeshEditor::Sew_Error(0);
5435 //================================================================================
5437 * \brief Set new nodes for given element
5438 * \param ide - element id
5439 * \param newIDs - new node ids
5440 * \retval CORBA::Boolean - true if result is OK
5442 //================================================================================
5444 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
5445 const SMESH::long_array& newIDs)
5446 throw (SALOME::SALOME_Exception)
5451 const SMDS_MeshElement* elem = getMeshDS()->FindElement(ide);
5452 if(!elem) return false;
5454 int nbn = newIDs.length();
5456 vector<const SMDS_MeshNode*> aNodes(nbn);
5459 const SMDS_MeshNode* aNode = getMeshDS()->FindNode(newIDs[i]);
5462 aNodes[nbn1] = aNode;
5465 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
5466 << ide << ", " << newIDs << " )";
5468 MESSAGE("ChangeElementNodes");
5469 bool res = getMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
5471 declareMeshModified( /*isReComputeSafe=*/ !res );
5475 SMESH_CATCH( SMESH::throwCorbaException );
5479 //=======================================================================
5481 * \brief Makes a part of the mesh quadratic or bi-quadratic
5483 //=======================================================================
5485 void SMESH_MeshEditor_i::convertToQuadratic(CORBA::Boolean theForce3d,
5486 CORBA::Boolean theToBiQuad,
5487 SMESH::SMESH_IDSource_ptr theObject)
5488 throw (SALOME::SALOME_Exception)
5491 TIDSortedElemSet elems;
5493 if ( !( elemsOK = CORBA::is_nil( theObject )))
5494 elemsOK = idSourceToSet( theObject, getMeshDS(), elems,
5495 SMDSAbs_All, /*emptyIfIsMesh=*/true );
5498 if ( !elems.empty() && (*elems.begin())->GetType() == SMDSAbs_Node )
5499 THROW_SALOME_CORBA_EXCEPTION("Group of nodes is not allowed", SALOME::BAD_PARAM);
5501 if ( elems.empty() ) getEditor().ConvertToQuadratic(theForce3d, theToBiQuad);
5502 else getEditor().ConvertToQuadratic(theForce3d, elems, theToBiQuad);
5504 declareMeshModified( /*isReComputeSafe=*/false );
5507 SMESH_CATCH( SMESH::throwCorbaException );
5510 //=======================================================================
5511 //function : ConvertFromQuadratic
5513 //=======================================================================
5515 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
5516 throw (SALOME::SALOME_Exception)
5518 CORBA::Boolean isDone = getEditor().ConvertFromQuadratic();
5519 TPythonDump() << this << ".ConvertFromQuadratic()";
5520 declareMeshModified( /*isReComputeSafe=*/!isDone );
5524 //=======================================================================
5525 //function : ConvertToQuadratic
5527 //=======================================================================
5529 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
5530 throw (SALOME::SALOME_Exception)
5532 convertToQuadratic( theForce3d, false );
5533 TPythonDump() << this << ".ConvertToQuadratic("<<theForce3d<<")";
5536 //================================================================================
5538 * \brief Makes a part of the mesh quadratic
5540 //================================================================================
5542 void SMESH_MeshEditor_i::ConvertToQuadraticObject(CORBA::Boolean theForce3d,
5543 SMESH::SMESH_IDSource_ptr theObject)
5544 throw (SALOME::SALOME_Exception)
5546 convertToQuadratic( theForce3d, false, theObject );
5547 TPythonDump() << this << ".ConvertToQuadraticObject("<<theForce3d<<", "<<theObject<<")";
5550 //================================================================================
5552 * \brief Makes a part of the mesh bi-quadratic
5554 //================================================================================
5556 void SMESH_MeshEditor_i::ConvertToBiQuadratic(CORBA::Boolean theForce3d,
5557 SMESH::SMESH_IDSource_ptr theObject)
5558 throw (SALOME::SALOME_Exception)
5560 convertToQuadratic( theForce3d, true, theObject );
5561 TPythonDump() << this << ".ConvertToBiQuadratic("<<theForce3d<<", "<<theObject<<")";
5564 //================================================================================
5566 * \brief Makes a part of the mesh linear
5568 //================================================================================
5570 void SMESH_MeshEditor_i::ConvertFromQuadraticObject(SMESH::SMESH_IDSource_ptr theObject)
5571 throw (SALOME::SALOME_Exception)
5575 TIDSortedElemSet elems;
5576 if ( idSourceToSet( theObject, getMeshDS(), elems, SMDSAbs_All, /*emptyIfIsMesh=*/true ))
5578 if ( elems.empty() )
5580 ConvertFromQuadratic();
5582 else if ( (*elems.begin())->GetType() == SMDSAbs_Node )
5584 THROW_SALOME_CORBA_EXCEPTION("Group of nodes is not allowed", SALOME::BAD_PARAM);
5588 getEditor().ConvertFromQuadratic(elems);
5591 declareMeshModified( /*isReComputeSafe=*/false );
5593 pyDump << this << ".ConvertFromQuadraticObject( "<<theObject<<" )";
5595 SMESH_CATCH( SMESH::throwCorbaException );
5598 //=======================================================================
5599 //function : makeMesh
5600 //purpose : create a named imported mesh
5601 //=======================================================================
5603 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
5605 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
5606 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
5607 SALOMEDS::Study_var study = gen->GetCurrentStudy();
5608 SALOMEDS::SObject_wrap meshSO = gen->ObjectToSObject( study, mesh );
5609 gen->SetName( meshSO, theMeshName, "Mesh" );
5610 gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
5612 return mesh._retn();
5615 //=======================================================================
5616 //function : dumpGroupsList
5618 //=======================================================================
5620 void SMESH_MeshEditor_i::dumpGroupsList(TPythonDump & theDumpPython,
5621 const SMESH::ListOfGroups * theGroupList)
5623 bool isDumpGroupList = ( theGroupList && theGroupList->length() > 0 );
5624 if ( isDumpGroupList )
5625 theDumpPython << theGroupList << " = ";
5628 //================================================================================
5630 \brief Generates the unique group name.
5631 \param thePrefix name prefix
5634 //================================================================================
5636 string SMESH_MeshEditor_i::generateGroupName(const string& thePrefix)
5638 SMESH::ListOfGroups_var groups = myMesh_i->GetGroups();
5639 set<string> groupNames;
5641 // Get existing group names
5642 for (int i = 0, nbGroups = groups->length(); i < nbGroups; i++ ) {
5643 SMESH::SMESH_GroupBase_var aGroup = groups[i];
5644 if (CORBA::is_nil(aGroup))
5647 CORBA::String_var name = aGroup->GetName();
5648 groupNames.insert( name.in() );
5652 string name = thePrefix;
5655 while (!groupNames.insert(name).second)
5656 name = SMESH_Comment( thePrefix ) << "_" << index;
5661 //================================================================================
5663 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5664 \param theNodes - identifiers of nodes to be doubled
5665 \param theModifiedElems - identifiers of elements to be updated by the new (doubled)
5666 nodes. If list of element identifiers is empty then nodes are doubled but
5667 they not assigned to elements
5668 \return TRUE if operation has been completed successfully, FALSE otherwise
5669 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodeGroups()
5671 //================================================================================
5673 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNodes,
5674 const SMESH::long_array& theModifiedElems )
5675 throw (SALOME::SALOME_Exception)
5680 list< int > aListOfNodes;
5682 for ( i = 0, n = theNodes.length(); i < n; i++ )
5683 aListOfNodes.push_back( theNodes[ i ] );
5685 list< int > aListOfElems;
5686 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
5687 aListOfElems.push_back( theModifiedElems[ i ] );
5689 bool aResult = getEditor().DoubleNodes( aListOfNodes, aListOfElems );
5691 declareMeshModified( /*isReComputeSafe=*/ !aResult );
5693 // Update Python script
5694 TPythonDump() << this << ".DoubleNodes( " << theNodes << ", "<< theModifiedElems << " )";
5698 SMESH_CATCH( SMESH::throwCorbaException );
5702 //================================================================================
5704 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5705 This method provided for convenience works as DoubleNodes() described above.
5706 \param theNodeId - identifier of node to be doubled.
5707 \param theModifiedElems - identifiers of elements to be updated.
5708 \return TRUE if operation has been completed successfully, FALSE otherwise
5709 \sa DoubleNodes(), DoubleNodeGroup(), DoubleNodeGroups()
5711 //================================================================================
5713 CORBA::Boolean SMESH_MeshEditor_i::DoubleNode( CORBA::Long theNodeId,
5714 const SMESH::long_array& theModifiedElems )
5715 throw (SALOME::SALOME_Exception)
5718 SMESH::long_array_var aNodes = new SMESH::long_array;
5719 aNodes->length( 1 );
5720 aNodes[ 0 ] = theNodeId;
5722 TPythonDump pyDump; // suppress dump by the next line
5724 CORBA::Boolean done = DoubleNodes( aNodes, theModifiedElems );
5726 pyDump << this << ".DoubleNode( " << theNodeId << ", " << theModifiedElems << " )";
5730 SMESH_CATCH( SMESH::throwCorbaException );
5734 //================================================================================
5736 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5737 This method provided for convenience works as DoubleNodes() described above.
5738 \param theNodes - group of nodes to be doubled.
5739 \param theModifiedElems - group of elements to be updated.
5740 \return TRUE if operation has been completed successfully, FALSE otherwise
5741 \sa DoubleNode(), DoubleNodes(), DoubleNodeGroups()
5743 //================================================================================
5745 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(SMESH::SMESH_GroupBase_ptr theNodes,
5746 SMESH::SMESH_GroupBase_ptr theModifiedElems )
5747 throw (SALOME::SALOME_Exception)
5750 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
5753 SMESH::long_array_var aNodes = theNodes->GetListOfID();
5754 SMESH::long_array_var aModifiedElems;
5755 if ( !CORBA::is_nil( theModifiedElems ) )
5756 aModifiedElems = theModifiedElems->GetListOfID();
5759 aModifiedElems = new SMESH::long_array;
5760 aModifiedElems->length( 0 );
5763 TPythonDump pyDump; // suppress dump by the next line
5765 bool done = DoubleNodes( aNodes, aModifiedElems );
5767 pyDump << this << ".DoubleNodeGroup( " << theNodes << ", " << theModifiedElems << " )";
5771 SMESH_CATCH( SMESH::throwCorbaException );
5775 //================================================================================
5777 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements.
5778 * Works as DoubleNodeGroup(), but returns a new group with newly created nodes.
5779 * \param theNodes - group of nodes to be doubled.
5780 * \param theModifiedElems - group of elements to be updated.
5781 * \return a new group with newly created nodes
5782 * \sa DoubleNodeGroup()
5784 //================================================================================
5786 SMESH::SMESH_Group_ptr
5787 SMESH_MeshEditor_i::DoubleNodeGroupNew( SMESH::SMESH_GroupBase_ptr theNodes,
5788 SMESH::SMESH_GroupBase_ptr theModifiedElems )
5789 throw (SALOME::SALOME_Exception)
5792 SMESH::SMESH_Group_var aNewGroup;
5794 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
5795 return aNewGroup._retn();
5798 SMESH::long_array_var aNodes = theNodes->GetListOfID();
5799 SMESH::long_array_var aModifiedElems;
5800 if ( !CORBA::is_nil( theModifiedElems ) )
5801 aModifiedElems = theModifiedElems->GetListOfID();
5803 aModifiedElems = new SMESH::long_array;
5804 aModifiedElems->length( 0 );
5807 TPythonDump pyDump; // suppress dump by the next line
5809 bool aResult = DoubleNodes( aNodes, aModifiedElems );
5812 // Create group with newly created nodes
5813 SMESH::long_array_var anIds = GetLastCreatedNodes();
5814 if (anIds->length() > 0) {
5815 string anUnindexedName (theNodes->GetName());
5816 string aNewName = generateGroupName(anUnindexedName + "_double");
5817 aNewGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
5818 aNewGroup->Add(anIds);
5819 pyDump << aNewGroup << " = ";
5823 pyDump << this << ".DoubleNodeGroupNew( " << theNodes << ", "
5824 << theModifiedElems << " )";
5826 return aNewGroup._retn();
5828 SMESH_CATCH( SMESH::throwCorbaException );
5832 //================================================================================
5834 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5835 This method provided for convenience works as DoubleNodes() described above.
5836 \param theNodes - list of groups of nodes to be doubled
5837 \param theModifiedElems - list of groups of elements to be updated.
5838 \return TRUE if operation has been completed successfully, FALSE otherwise
5839 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodes()
5841 //================================================================================
5843 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(const SMESH::ListOfGroups& theNodes,
5844 const SMESH::ListOfGroups& theModifiedElems )
5845 throw (SALOME::SALOME_Exception)
5850 std::list< int > aNodes;
5852 for ( i = 0, n = theNodes.length(); i < n; i++ )
5854 SMESH::SMESH_GroupBase_var aGrp = theNodes[ i ];
5855 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() == SMESH::NODE )
5857 SMESH::long_array_var aCurr = aGrp->GetListOfID();
5858 for ( j = 0, m = aCurr->length(); j < m; j++ )
5859 aNodes.push_back( aCurr[ j ] );
5863 std::list< int > anElems;
5864 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
5866 SMESH::SMESH_GroupBase_var aGrp = theModifiedElems[ i ];
5867 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() != SMESH::NODE )
5869 SMESH::long_array_var aCurr = aGrp->GetListOfID();
5870 for ( j = 0, m = aCurr->length(); j < m; j++ )
5871 anElems.push_back( aCurr[ j ] );
5875 bool aResult = getEditor().DoubleNodes( aNodes, anElems );
5877 declareMeshModified( /*isReComputeSafe=*/false );
5879 TPythonDump() << this << ".DoubleNodeGroups( " << theNodes << ", " << theModifiedElems << " )";
5883 SMESH_CATCH( SMESH::throwCorbaException );
5887 //================================================================================
5889 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements.
5890 * Works as DoubleNodeGroups(), but returns a new group with newly created nodes.
5891 * \param theNodes - group of nodes to be doubled.
5892 * \param theModifiedElems - group of elements to be updated.
5893 * \return a new group with newly created nodes
5894 * \sa DoubleNodeGroups()
5896 //================================================================================
5898 SMESH::SMESH_Group_ptr
5899 SMESH_MeshEditor_i::DoubleNodeGroupsNew( const SMESH::ListOfGroups& theNodes,
5900 const SMESH::ListOfGroups& theModifiedElems )
5901 throw (SALOME::SALOME_Exception)
5903 SMESH::SMESH_Group_var aNewGroup;
5905 TPythonDump pyDump; // suppress dump by the next line
5907 bool aResult = DoubleNodeGroups( theNodes, theModifiedElems );
5911 // Create group with newly created nodes
5912 SMESH::long_array_var anIds = GetLastCreatedNodes();
5913 if (anIds->length() > 0) {
5914 string anUnindexedName (theNodes[0]->GetName());
5915 string aNewName = generateGroupName(anUnindexedName + "_double");
5916 aNewGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
5917 aNewGroup->Add(anIds);
5918 pyDump << aNewGroup << " = ";
5922 pyDump << this << ".DoubleNodeGroupsNew( " << theNodes << ", "
5923 << theModifiedElems << " )";
5925 return aNewGroup._retn();
5929 //================================================================================
5931 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5932 \param theElems - the list of elements (edges or faces) to be replicated
5933 The nodes for duplication could be found from these elements
5934 \param theNodesNot - list of nodes to NOT replicate
5935 \param theAffectedElems - the list of elements (cells and edges) to which the
5936 replicated nodes should be associated to.
5937 \return TRUE if operation has been completed successfully, FALSE otherwise
5938 \sa DoubleNodeGroup(), DoubleNodeGroups()
5940 //================================================================================
5942 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElem( const SMESH::long_array& theElems,
5943 const SMESH::long_array& theNodesNot,
5944 const SMESH::long_array& theAffectedElems )
5945 throw (SALOME::SALOME_Exception)
5950 SMESHDS_Mesh* aMeshDS = getMeshDS();
5951 TIDSortedElemSet anElems, aNodes, anAffected;
5952 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
5953 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
5954 arrayToSet(theAffectedElems, aMeshDS, anAffected, SMDSAbs_All);
5956 bool aResult = getEditor().DoubleNodes( anElems, aNodes, anAffected );
5958 // Update Python script
5959 TPythonDump() << this << ".DoubleNodeElem( " << theElems << ", "
5960 << theNodesNot << ", " << theAffectedElems << " )";
5962 declareMeshModified( /*isReComputeSafe=*/false );
5965 SMESH_CATCH( SMESH::throwCorbaException );
5969 //================================================================================
5971 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5972 \param theElems - the list of elements (edges or faces) to be replicated
5973 The nodes for duplication could be found from these elements
5974 \param theNodesNot - list of nodes to NOT replicate
5975 \param theShape - shape to detect affected elements (element which geometric center
5976 located on or inside shape).
5977 The replicated nodes should be associated to affected elements.
5978 \return TRUE if operation has been completed successfully, FALSE otherwise
5979 \sa DoubleNodeGroupInRegion(), DoubleNodeGroupsInRegion()
5981 //================================================================================
5983 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemInRegion ( const SMESH::long_array& theElems,
5984 const SMESH::long_array& theNodesNot,
5985 GEOM::GEOM_Object_ptr theShape )
5986 throw (SALOME::SALOME_Exception)
5992 SMESHDS_Mesh* aMeshDS = getMeshDS();
5993 TIDSortedElemSet anElems, aNodes;
5994 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
5995 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
5997 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5998 bool aResult = getEditor().DoubleNodesInRegion( anElems, aNodes, aShape );
6000 // Update Python script
6001 TPythonDump() << "isDone = " << this << ".DoubleNodeElemInRegion( " << theElems << ", "
6002 << theNodesNot << ", " << theShape << " )";
6004 declareMeshModified( /*isReComputeSafe=*/false );
6007 SMESH_CATCH( SMESH::throwCorbaException );
6011 //================================================================================
6013 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
6014 \param theElems - group of of elements (edges or faces) to be replicated
6015 \param theNodesNot - group of nodes not to replicated
6016 \param theAffectedElems - group of elements to which the replicated nodes
6017 should be associated to.
6018 \return TRUE if operation has been completed successfully, FALSE otherwise
6019 \sa DoubleNodes(), DoubleNodeGroups()
6021 //================================================================================
6024 SMESH_MeshEditor_i::DoubleNodeElemGroup(SMESH::SMESH_GroupBase_ptr theElems,
6025 SMESH::SMESH_GroupBase_ptr theNodesNot,
6026 SMESH::SMESH_GroupBase_ptr theAffectedElems)
6027 throw (SALOME::SALOME_Exception)
6030 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
6036 SMESHDS_Mesh* aMeshDS = getMeshDS();
6037 TIDSortedElemSet anElems, aNodes, anAffected;
6038 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
6039 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
6040 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
6042 bool aResult = getEditor().DoubleNodes( anElems, aNodes, anAffected );
6044 // Update Python script
6045 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroup( " << theElems << ", "
6046 << theNodesNot << ", " << theAffectedElems << " )";
6048 declareMeshModified( /*isReComputeSafe=*/false );
6051 SMESH_CATCH( SMESH::throwCorbaException );
6055 //================================================================================
6057 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements
6058 * Works as DoubleNodeElemGroup(), but returns a new group with newly created elements.
6059 * \param theElems - group of of elements (edges or faces) to be replicated
6060 * \param theNodesNot - group of nodes not to replicated
6061 * \param theAffectedElems - group of elements to which the replicated nodes
6062 * should be associated to.
6063 * \return a new group with newly created elements
6064 * \sa DoubleNodeElemGroup()
6066 //================================================================================
6068 SMESH::SMESH_Group_ptr
6069 SMESH_MeshEditor_i::DoubleNodeElemGroupNew(SMESH::SMESH_GroupBase_ptr theElems,
6070 SMESH::SMESH_GroupBase_ptr theNodesNot,
6071 SMESH::SMESH_GroupBase_ptr theAffectedElems)
6072 throw (SALOME::SALOME_Exception)
6075 SMESH::ListOfGroups_var twoGroups = DoubleNodeElemGroup2New( theElems,
6079 SMESH::SMESH_GroupBase_var baseGroup = twoGroups[0].in();
6080 SMESH::SMESH_Group_var elemGroup = SMESH::SMESH_Group::_narrow( baseGroup );
6082 pyDump << elemGroup << " = " << this << ".DoubleNodeElemGroupNew( "
6084 << theNodesNot << ", "
6085 << theAffectedElems << " )";
6087 return elemGroup._retn();
6090 //================================================================================
6092 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements
6093 * Works as DoubleNodeElemGroup(), but returns a new group with newly created elements.
6094 * \param theElems - group of of elements (edges or faces) to be replicated
6095 * \param theNodesNot - group of nodes not to replicated
6096 * \param theAffectedElems - group of elements to which the replicated nodes
6097 * should be associated to.
6098 * \return a new group with newly created elements
6099 * \sa DoubleNodeElemGroup()
6101 //================================================================================
6103 SMESH::ListOfGroups*
6104 SMESH_MeshEditor_i::DoubleNodeElemGroup2New(SMESH::SMESH_GroupBase_ptr theElems,
6105 SMESH::SMESH_GroupBase_ptr theNodesNot,
6106 SMESH::SMESH_GroupBase_ptr theAffectedElems,
6107 CORBA::Boolean theElemGroupNeeded,
6108 CORBA::Boolean theNodeGroupNeeded)
6109 throw (SALOME::SALOME_Exception)
6112 SMESH::SMESH_Group_var aNewElemGroup, aNewNodeGroup;
6113 SMESH::ListOfGroups_var aTwoGroups = new SMESH::ListOfGroups();
6114 aTwoGroups->length( 2 );
6116 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
6117 return aTwoGroups._retn();
6122 SMESHDS_Mesh* aMeshDS = getMeshDS();
6123 TIDSortedElemSet anElems, aNodes, anAffected;
6124 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
6125 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
6126 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
6129 bool aResult = getEditor().DoubleNodes( anElems, aNodes, anAffected );
6131 declareMeshModified( /*isReComputeSafe=*/ !aResult );
6137 // Create group with newly created elements
6138 CORBA::String_var elemGroupName = theElems->GetName();
6139 string aNewName = generateGroupName( string(elemGroupName.in()) + "_double");
6140 if ( !getEditor().GetLastCreatedElems().IsEmpty() && theElemGroupNeeded )
6142 SMESH::long_array_var anIds = GetLastCreatedElems();
6143 SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true);
6144 aNewElemGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
6145 aNewElemGroup->Add(anIds);
6147 if ( !getEditor().GetLastCreatedNodes().IsEmpty() && theNodeGroupNeeded )
6149 SMESH::long_array_var anIds = GetLastCreatedNodes();
6150 aNewNodeGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
6151 aNewNodeGroup->Add(anIds);
6155 // Update Python script
6158 if ( aNewElemGroup->_is_nil() ) pyDump << "nothing, ";
6159 else pyDump << aNewElemGroup << ", ";
6160 if ( aNewNodeGroup->_is_nil() ) pyDump << "nothing ] = ";
6161 else pyDump << aNewNodeGroup << " ] = ";
6163 pyDump << this << ".DoubleNodeElemGroup2New( " << theElems << ", "
6164 << theNodesNot << ", "
6165 << theAffectedElems << ", "
6166 << theElemGroupNeeded << ", "
6167 << theNodeGroupNeeded <<" )";
6169 aTwoGroups[0] = aNewElemGroup._retn();
6170 aTwoGroups[1] = aNewNodeGroup._retn();
6171 return aTwoGroups._retn();
6173 SMESH_CATCH( SMESH::throwCorbaException );
6177 //================================================================================
6179 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
6180 \param theElems - group of of elements (edges or faces) to be replicated
6181 \param theNodesNot - group of nodes not to replicated
6182 \param theShape - shape to detect affected elements (element which geometric center
6183 located on or inside shape).
6184 The replicated nodes should be associated to affected elements.
6185 \return TRUE if operation has been completed successfully, FALSE otherwise
6186 \sa DoubleNodesInRegion(), DoubleNodeGroupsInRegion()
6188 //================================================================================
6191 SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(SMESH::SMESH_GroupBase_ptr theElems,
6192 SMESH::SMESH_GroupBase_ptr theNodesNot,
6193 GEOM::GEOM_Object_ptr theShape )
6194 throw (SALOME::SALOME_Exception)
6197 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
6203 SMESHDS_Mesh* aMeshDS = getMeshDS();
6204 TIDSortedElemSet anElems, aNodes, anAffected;
6205 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
6206 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
6208 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
6209 bool aResult = getEditor().DoubleNodesInRegion( anElems, aNodes, aShape );
6212 declareMeshModified( /*isReComputeSafe=*/ !aResult );
6214 // Update Python script
6215 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupInRegion( " << theElems << ", "
6216 << theNodesNot << ", " << theShape << " )";
6219 SMESH_CATCH( SMESH::throwCorbaException );
6223 //================================================================================
6225 * \brief Re-load elements from a list of groups into a TIDSortedElemSet
6226 * \param [in] theGrpList - groups
6227 * \param [in] theMeshDS - mesh
6228 * \param [out] theElemSet - set of elements
6229 * \param [in] theIsNodeGrp - is \a theGrpList includes goups of nodes
6231 //================================================================================
6233 static void listOfGroupToSet(const SMESH::ListOfGroups& theGrpList,
6234 SMESHDS_Mesh* theMeshDS,
6235 TIDSortedElemSet& theElemSet,
6236 const bool theIsNodeGrp)
6238 for ( int i = 0, n = theGrpList.length(); i < n; i++ )
6240 SMESH::SMESH_GroupBase_var aGrp = theGrpList[ i ];
6241 if ( !CORBA::is_nil( aGrp ) && (theIsNodeGrp ? aGrp->GetType() == SMESH::NODE
6242 : aGrp->GetType() != SMESH::NODE ) )
6244 SMESH::long_array_var anIDs = aGrp->GetIDs();
6245 arrayToSet( anIDs, theMeshDS, theElemSet, theIsNodeGrp ? SMDSAbs_Node : SMDSAbs_All );
6250 //================================================================================
6252 \brief Creates a hole in a mesh by doubling the nodes of some particular elements.
6253 This method provided for convenience works as DoubleNodes() described above.
6254 \param theElems - list of groups of elements (edges or faces) to be replicated
6255 \param theNodesNot - list of groups of nodes not to replicated
6256 \param theAffectedElems - group of elements to which the replicated nodes
6257 should be associated to.
6258 \return TRUE if operation has been completed successfully, FALSE otherwise
6259 \sa DoubleNodeGroup(), DoubleNodes(), DoubleNodeElemGroupsNew()
6261 //================================================================================
6264 SMESH_MeshEditor_i::DoubleNodeElemGroups(const SMESH::ListOfGroups& theElems,
6265 const SMESH::ListOfGroups& theNodesNot,
6266 const SMESH::ListOfGroups& theAffectedElems)
6267 throw (SALOME::SALOME_Exception)
6273 SMESHDS_Mesh* aMeshDS = getMeshDS();
6274 TIDSortedElemSet anElems, aNodes, anAffected;
6275 listOfGroupToSet(theElems, aMeshDS, anElems, false );
6276 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
6277 listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
6279 bool aResult = getEditor().DoubleNodes( anElems, aNodes, anAffected );
6281 // Update Python script
6282 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroups( " << &theElems << ", "
6283 << &theNodesNot << ", " << &theAffectedElems << " )";
6285 declareMeshModified( /*isReComputeSafe=*/false );
6288 SMESH_CATCH( SMESH::throwCorbaException );
6292 //================================================================================
6294 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements
6295 * Works as DoubleNodeElemGroups(), but returns a new group with newly created elements.
6296 \param theElems - list of groups of elements (edges or faces) to be replicated
6297 \param theNodesNot - list of groups of nodes not to replicated
6298 \param theAffectedElems - group of elements to which the replicated nodes
6299 should be associated to.
6300 * \return a new group with newly created elements
6301 * \sa DoubleNodeElemGroups()
6303 //================================================================================
6305 SMESH::SMESH_Group_ptr
6306 SMESH_MeshEditor_i::DoubleNodeElemGroupsNew(const SMESH::ListOfGroups& theElems,
6307 const SMESH::ListOfGroups& theNodesNot,
6308 const SMESH::ListOfGroups& theAffectedElems)
6309 throw (SALOME::SALOME_Exception)
6312 SMESH::ListOfGroups_var twoGroups = DoubleNodeElemGroups2New( theElems,
6316 SMESH::SMESH_GroupBase_var baseGroup = twoGroups[0].in();
6317 SMESH::SMESH_Group_var elemGroup = SMESH::SMESH_Group::_narrow( baseGroup );
6319 pyDump << elemGroup << " = " << this << ".DoubleNodeElemGroupsNew( "
6321 << theNodesNot << ", "
6322 << theAffectedElems << " )";
6324 return elemGroup._retn();
6327 //================================================================================
6329 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements
6330 * Works as DoubleNodeElemGroups(), but returns a new group with newly created elements.
6331 \param theElems - list of groups of elements (edges or faces) to be replicated
6332 \param theNodesNot - list of groups of nodes not to replicated
6333 \param theAffectedElems - group of elements to which the replicated nodes
6334 should be associated to.
6335 * \return a new group with newly created elements
6336 * \sa DoubleNodeElemGroups()
6338 //================================================================================
6340 SMESH::ListOfGroups*
6341 SMESH_MeshEditor_i::DoubleNodeElemGroups2New(const SMESH::ListOfGroups& theElems,
6342 const SMESH::ListOfGroups& theNodesNot,
6343 const SMESH::ListOfGroups& theAffectedElems,
6344 CORBA::Boolean theElemGroupNeeded,
6345 CORBA::Boolean theNodeGroupNeeded)
6346 throw (SALOME::SALOME_Exception)
6349 SMESH::SMESH_Group_var aNewElemGroup, aNewNodeGroup;
6350 SMESH::ListOfGroups_var aTwoGroups = new SMESH::ListOfGroups();
6351 aTwoGroups->length( 2 );
6356 SMESHDS_Mesh* aMeshDS = getMeshDS();
6357 TIDSortedElemSet anElems, aNodes, anAffected;
6358 listOfGroupToSet(theElems, aMeshDS, anElems, false );
6359 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
6360 listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
6362 bool aResult = getEditor().DoubleNodes( anElems, aNodes, anAffected );
6364 declareMeshModified( /*isReComputeSafe=*/ !aResult );
6369 // Create group with newly created elements
6370 CORBA::String_var elemGroupName = theElems[0]->GetName();
6371 string aNewName = generateGroupName( string(elemGroupName.in()) + "_double");
6372 if ( !getEditor().GetLastCreatedElems().IsEmpty() && theElemGroupNeeded )
6374 SMESH::long_array_var anIds = GetLastCreatedElems();
6375 SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true);
6376 aNewElemGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
6377 aNewElemGroup->Add(anIds);
6379 if ( !getEditor().GetLastCreatedNodes().IsEmpty() && theNodeGroupNeeded )
6381 SMESH::long_array_var anIds = GetLastCreatedNodes();
6382 aNewNodeGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
6383 aNewNodeGroup->Add(anIds);
6387 // Update Python script
6390 if ( aNewElemGroup->_is_nil() ) pyDump << "nothing, ";
6391 else pyDump << aNewElemGroup << ", ";
6392 if ( aNewNodeGroup->_is_nil() ) pyDump << "nothing ] = ";
6393 else pyDump << aNewNodeGroup << " ] = ";
6395 pyDump << this << ".DoubleNodeElemGroups2New( " << &theElems << ", "
6396 << &theNodesNot << ", "
6397 << &theAffectedElems << ", "
6398 << theElemGroupNeeded << ", "
6399 << theNodeGroupNeeded << " )";
6401 aTwoGroups[0] = aNewElemGroup._retn();
6402 aTwoGroups[1] = aNewNodeGroup._retn();
6403 return aTwoGroups._retn();
6405 SMESH_CATCH( SMESH::throwCorbaException );
6409 //================================================================================
6411 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
6412 This method provided for convenience works as DoubleNodes() described above.
6413 \param theElems - list of groups of elements (edges or faces) to be replicated
6414 \param theNodesNot - list of groups of nodes not to replicated
6415 \param theShape - shape to detect affected elements (element which geometric center
6416 located on or inside shape).
6417 The replicated nodes should be associated to affected elements.
6418 \return TRUE if operation has been completed successfully, FALSE otherwise
6419 \sa DoubleNodeGroupInRegion(), DoubleNodesInRegion()
6421 //================================================================================
6424 SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(const SMESH::ListOfGroups& theElems,
6425 const SMESH::ListOfGroups& theNodesNot,
6426 GEOM::GEOM_Object_ptr theShape )
6427 throw (SALOME::SALOME_Exception)
6433 SMESHDS_Mesh* aMeshDS = getMeshDS();
6434 TIDSortedElemSet anElems, aNodes;
6435 listOfGroupToSet(theElems, aMeshDS, anElems,false );
6436 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
6438 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
6439 bool aResult = getEditor().DoubleNodesInRegion( anElems, aNodes, aShape );
6441 // Update Python script
6442 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupsInRegion( " << &theElems << ", "
6443 << &theNodesNot << ", " << theShape << " )";
6445 declareMeshModified( /*isReComputeSafe=*/ !aResult );
6448 SMESH_CATCH( SMESH::throwCorbaException );
6452 //================================================================================
6454 \brief Identify the elements that will be affected by node duplication (actual
6455 duplication is not performed.
6456 This method is the first step of DoubleNodeElemGroupsInRegion.
6457 \param theElems - list of groups of elements (edges or faces) to be replicated
6458 \param theNodesNot - list of groups of nodes not to replicated
6459 \param theShape - shape to detect affected elements (element which geometric center
6460 located on or inside shape).
6461 The replicated nodes should be associated to affected elements.
6462 \return groups of affected elements
6463 \sa DoubleNodeElemGroupsInRegion()
6465 //================================================================================
6466 SMESH::ListOfGroups*
6467 SMESH_MeshEditor_i::AffectedElemGroupsInRegion( const SMESH::ListOfGroups& theElems,
6468 const SMESH::ListOfGroups& theNodesNot,
6469 GEOM::GEOM_Object_ptr theShape )
6470 throw (SALOME::SALOME_Exception)
6473 MESSAGE("AffectedElemGroupsInRegion");
6474 SMESH::ListOfGroups_var aListOfGroups = new SMESH::ListOfGroups();
6475 bool isEdgeGroup = false;
6476 bool isFaceGroup = false;
6477 bool isVolumeGroup = false;
6478 SMESH::SMESH_Group_var aNewEdgeGroup = myMesh_i->CreateGroup(SMESH::EDGE, "affectedEdges");
6479 SMESH::SMESH_Group_var aNewFaceGroup = myMesh_i->CreateGroup(SMESH::FACE, "affectedFaces");
6480 SMESH::SMESH_Group_var aNewVolumeGroup = myMesh_i->CreateGroup(SMESH::VOLUME, "affectedVolumes");
6484 ::SMESH_MeshEditor aMeshEditor(myMesh);
6486 SMESHDS_Mesh* aMeshDS = getMeshDS();
6487 TIDSortedElemSet anElems, aNodes;
6488 listOfGroupToSet(theElems, aMeshDS, anElems, false);
6489 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true);
6491 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape(theShape);
6492 TIDSortedElemSet anAffected;
6493 bool aResult = aMeshEditor.AffectedElemGroupsInRegion(anElems, aNodes, aShape, anAffected);
6496 declareMeshModified( /*isReComputeSafe=*/ !aResult );
6501 int lg = anAffected.size();
6502 MESSAGE("lg="<< lg);
6503 SMESH::long_array_var volumeIds = new SMESH::long_array;
6504 volumeIds->length(lg);
6505 SMESH::long_array_var faceIds = new SMESH::long_array;
6506 faceIds->length(lg);
6507 SMESH::long_array_var edgeIds = new SMESH::long_array;
6508 edgeIds->length(lg);
6513 TIDSortedElemSet::const_iterator eIt = anAffected.begin();
6514 for (; eIt != anAffected.end(); ++eIt)
6516 const SMDS_MeshElement* anElem = *eIt;
6519 int elemId = anElem->GetID();
6520 if (myMesh->GetElementType(elemId, true) == SMDSAbs_Volume)
6521 volumeIds[ivol++] = elemId;
6522 else if (myMesh->GetElementType(elemId, true) == SMDSAbs_Face)
6523 faceIds[iface++] = elemId;
6524 else if (myMesh->GetElementType(elemId, true) == SMDSAbs_Edge)
6525 edgeIds[iedge++] = elemId;
6527 volumeIds->length(ivol);
6528 faceIds->length(iface);
6529 edgeIds->length(iedge);
6531 aNewVolumeGroup->Add(volumeIds);
6532 aNewFaceGroup->Add(faceIds);
6533 aNewEdgeGroup->Add(edgeIds);
6534 isVolumeGroup = (aNewVolumeGroup->Size() > 0);
6535 isFaceGroup = (aNewFaceGroup->Size() > 0);
6536 isEdgeGroup = (aNewEdgeGroup->Size() > 0);
6540 if (isEdgeGroup) nbGroups++;
6541 if (isFaceGroup) nbGroups++;
6542 if (isVolumeGroup) nbGroups++;
6543 aListOfGroups->length(nbGroups);
6546 if (isEdgeGroup) aListOfGroups[i++] = aNewEdgeGroup._retn();
6547 if (isFaceGroup) aListOfGroups[i++] = aNewFaceGroup._retn();
6548 if (isVolumeGroup) aListOfGroups[i++] = aNewVolumeGroup._retn();
6550 // Update Python script
6553 if (isEdgeGroup) pyDump << aNewEdgeGroup << ", ";
6554 if (isFaceGroup) pyDump << aNewFaceGroup << ", ";
6555 if (isVolumeGroup) pyDump << aNewVolumeGroup << ", ";
6557 pyDump << this << ".AffectedElemGroupsInRegion( "
6558 << &theElems << ", " << &theNodesNot << ", " << theShape << " )";
6560 return aListOfGroups._retn();
6562 SMESH_CATCH( SMESH::throwCorbaException );
6566 //================================================================================
6568 \brief Generated skin mesh (containing 2D cells) from 3D mesh
6569 The created 2D mesh elements based on nodes of free faces of boundary volumes
6570 \return TRUE if operation has been completed successfully, FALSE otherwise
6572 //================================================================================
6574 CORBA::Boolean SMESH_MeshEditor_i::Make2DMeshFrom3D()
6575 throw (SALOME::SALOME_Exception)
6580 bool aResult = getEditor().Make2DMeshFrom3D();
6582 TPythonDump() << "isDone = " << this << ".Make2DMeshFrom3D()";
6584 declareMeshModified( /*isReComputeSafe=*/ !aResult );
6587 SMESH_CATCH( SMESH::throwCorbaException );
6591 //================================================================================
6593 * \brief Double nodes on shared faces between groups of volumes and create flat elements on demand.
6594 * The list of groups must contain at least two groups. The groups have to be disjoint:
6595 * no common element into two different groups.
6596 * The nodes of the internal faces at the boundaries of the groups are doubled.
6597 * Optionally, the internal faces are replaced by flat elements.
6598 * Triangles are transformed into prisms, and quadrangles into hexahedrons.
6599 * The flat elements are stored in groups of volumes.
6600 * These groups are named according to the position of the group in the list:
6601 * the group j_n_p is the group of the flat elements that are built between the group #n and the group #p in the list.
6602 * If there is no shared faces between the group #n and the group #p in the list, the group j_n_p is not created.
6603 * All the flat elements are gathered into the group named "joints3D" (or "joints2D" in 2D situation).
6604 * The flat element of the multiple junctions between the simple junction are stored in a group named "jointsMultiples".
6605 * @param theDomains - list of groups of volumes
6606 * @param createJointElems - if TRUE, create the elements
6607 * @return TRUE if operation has been completed successfully, FALSE otherwise
6609 //================================================================================
6612 SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::ListOfGroups& theDomains,
6613 CORBA::Boolean createJointElems )
6614 throw (SALOME::SALOME_Exception)
6616 bool aResult = false;
6621 SMESHDS_Mesh* aMeshDS = getMeshDS();
6623 // MESSAGE("theDomains.length = "<<theDomains.length());
6624 if ( theDomains.length() <= 1 )
6625 THROW_SALOME_CORBA_EXCEPTION("At least 2 groups are required.", SALOME::BAD_PARAM);
6626 vector<TIDSortedElemSet> domains;
6629 for ( int i = 0, n = theDomains.length(); i < n; i++ )
6631 SMESH::SMESH_GroupBase_var aGrp = theDomains[ i ];
6632 if ( !CORBA::is_nil( aGrp ) /*&& ( aGrp->GetType() != SMESH::NODE )*/ )
6634 // if ( aGrp->GetType() != SMESH::VOLUME )
6635 // THROW_SALOME_CORBA_EXCEPTION("Not a volume group", SALOME::BAD_PARAM);
6636 TIDSortedElemSet domain;
6638 domains.push_back(domain);
6639 SMESH::long_array_var anIDs = aGrp->GetIDs();
6640 arrayToSet( anIDs, aMeshDS, domains[ i ], SMDSAbs_All );
6644 aResult = getEditor().DoubleNodesOnGroupBoundaries( domains, createJointElems );
6645 // TODO publish the groups of flat elements in study
6647 declareMeshModified( /*isReComputeSafe=*/ !aResult );
6649 // Update Python script
6650 TPythonDump() << "isDone = " << this << ".DoubleNodesOnGroupBoundaries( " << &theDomains
6651 << ", " << createJointElems << " )";
6653 SMESH_CATCH( SMESH::throwCorbaException );
6658 //================================================================================
6660 * \brief Double nodes on some external faces and create flat elements.
6661 * Flat elements are mainly used by some types of mechanic calculations.
6663 * Each group of the list must be constituted of faces.
6664 * Triangles are transformed in prisms, and quadrangles in hexahedrons.
6665 * @param theGroupsOfFaces - list of groups of faces
6666 * @return TRUE if operation has been completed successfully, FALSE otherwise
6668 //================================================================================
6671 SMESH_MeshEditor_i::CreateFlatElementsOnFacesGroups( const SMESH::ListOfGroups& theGroupsOfFaces )
6672 throw (SALOME::SALOME_Exception)
6677 SMESHDS_Mesh* aMeshDS = getMeshDS();
6679 vector<TIDSortedElemSet> faceGroups;
6682 for ( int i = 0, n = theGroupsOfFaces.length(); i < n; i++ )
6684 SMESH::SMESH_GroupBase_var aGrp = theGroupsOfFaces[ i ];
6685 if ( !CORBA::is_nil( aGrp ) && ( aGrp->GetType() != SMESH::NODE ) )
6687 TIDSortedElemSet faceGroup;
6689 faceGroups.push_back(faceGroup);
6690 SMESH::long_array_var anIDs = aGrp->GetIDs();
6691 arrayToSet( anIDs, aMeshDS, faceGroups[ i ], SMDSAbs_All );
6695 bool aResult = getEditor().CreateFlatElementsOnFacesGroups( faceGroups );
6696 // TODO publish the groups of flat elements in study
6698 declareMeshModified( /*isReComputeSafe=*/ !aResult );
6700 // Update Python script
6701 TPythonDump() << this << ".CreateFlatElementsOnFacesGroups( " << &theGroupsOfFaces << " )";
6704 SMESH_CATCH( SMESH::throwCorbaException );
6708 //================================================================================
6710 * \brief Identify all the elements around a geom shape, get the faces delimiting
6713 * Build groups of volume to remove, groups of faces to replace on the skin of the
6714 * object, groups of faces to remove inside the object, (idem edges).
6715 * Build ordered list of nodes at the border of each group of faces to replace
6716 * (to be used to build a geom subshape).
6718 //================================================================================
6720 void SMESH_MeshEditor_i::CreateHoleSkin(CORBA::Double radius,
6721 GEOM::GEOM_Object_ptr theShape,
6722 const char* groupName,
6723 const SMESH::double_array& theNodesCoords,
6724 SMESH::array_of_long_array_out GroupsOfNodes)
6725 throw (SALOME::SALOME_Exception)
6730 std::vector<std::vector<int> > aListOfListOfNodes;
6731 ::SMESH_MeshEditor aMeshEditor( myMesh );
6733 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
6734 if ( !theNodeSearcher )
6735 theNodeSearcher = SMESH_MeshAlgos::GetNodeSearcher( *getMeshDS() );
6737 vector<double> nodesCoords;
6738 for (int i = 0; i < theNodesCoords.length(); i++)
6740 nodesCoords.push_back( theNodesCoords[i] );
6743 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
6744 aMeshEditor.CreateHoleSkin(radius, aShape, theNodeSearcher, groupName,
6745 nodesCoords, aListOfListOfNodes);
6747 GroupsOfNodes = new SMESH::array_of_long_array;
6748 GroupsOfNodes->length( aListOfListOfNodes.size() );
6749 std::vector<std::vector<int> >::iterator llIt = aListOfListOfNodes.begin();
6750 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
6752 vector<int>& aListOfNodes = *llIt;
6753 vector<int>::iterator lIt = aListOfNodes.begin();;
6754 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
6755 aGroup.length( aListOfNodes.size() );
6756 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
6757 aGroup[ j ] = (*lIt);
6759 TPythonDump() << "lists_nodes = " << this << ".CreateHoleSkin( "
6762 << ", '" << groupName << "', "
6763 << theNodesCoords << " )";
6765 SMESH_CATCH( SMESH::throwCorbaException );
6768 // issue 20749 ===================================================================
6770 * \brief Creates missing boundary elements
6771 * \param elements - elements whose boundary is to be checked
6772 * \param dimension - defines type of boundary elements to create
6773 * \param groupName - a name of group to store created boundary elements in,
6774 * "" means not to create the group
6775 * \param meshName - a name of new mesh to store created boundary elements in,
6776 * "" means not to create the new mesh
6777 * \param toCopyElements - if true, the checked elements will be copied into the new mesh
6778 * \param toCopyExistingBondary - if true, not only new but also pre-existing
6779 * boundary elements will be copied into the new mesh
6780 * \param group - returns the create group, if any
6781 * \retval SMESH::SMESH_Mesh - the mesh where elements were added to
6783 // ================================================================================
6785 SMESH::SMESH_Mesh_ptr
6786 SMESH_MeshEditor_i::MakeBoundaryMesh(SMESH::SMESH_IDSource_ptr idSource,
6787 SMESH::Bnd_Dimension dim,
6788 const char* groupName,
6789 const char* meshName,
6790 CORBA::Boolean toCopyElements,
6791 CORBA::Boolean toCopyExistingBondary,
6792 SMESH::SMESH_Group_out group)
6793 throw (SALOME::SALOME_Exception)
6798 if ( dim > SMESH::BND_1DFROM2D )
6799 THROW_SALOME_CORBA_EXCEPTION("Invalid boundary dimension", SALOME::BAD_PARAM);
6801 SMESHDS_Mesh* aMeshDS = getMeshDS();
6803 SMESH::SMESH_Mesh_var mesh_var;
6804 SMESH::SMESH_Group_var group_var;
6808 TIDSortedElemSet elements;
6809 SMDSAbs_ElementType elemType = (dim == SMESH::BND_1DFROM2D) ? SMDSAbs_Face : SMDSAbs_Volume;
6810 if ( idSourceToSet( idSource, aMeshDS, elements, elemType,/*emptyIfIsMesh=*/true ))
6814 strlen(meshName) ? makeMesh(meshName) : SMESH::SMESH_Mesh::_duplicate(myMesh_i->_this());
6815 SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh_var );
6817 SMESH_Mesh* smesh_mesh = (mesh_i==myMesh_i) ? (SMESH_Mesh*)0 : &mesh_i->GetImpl();
6819 // group of new boundary elements
6820 SMESH_Group* smesh_group = 0;
6821 if ( strlen(groupName) )
6823 group_var = mesh_i->CreateGroup( SMESH::ElementType(int(elemType)-1),groupName);
6824 if ( SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>( group_var ))
6825 smesh_group = group_i->GetSmeshGroup();
6829 getEditor().MakeBoundaryMesh( elements,
6830 ::SMESH_MeshEditor::Bnd_Dimension(dim),
6834 toCopyExistingBondary);
6837 smesh_mesh->GetMeshDS()->Modified();
6840 const char* dimName[] = { "BND_2DFROM3D", "BND_1DFROM3D", "BND_1DFROM2D" };
6842 // result of MakeBoundaryMesh() is a tuple (mesh, group)
6843 if ( mesh_var->_is_nil() )
6844 pyDump << myMesh_i->_this() << ", ";
6846 pyDump << mesh_var << ", ";
6847 if ( group_var->_is_nil() )
6848 pyDump << "_NoneGroup = "; // assignment to None is forbiden
6850 pyDump << group_var << " = ";
6851 pyDump << this << ".MakeBoundaryMesh( "
6853 << "SMESH." << dimName[int(dim)] << ", "
6854 << "'" << groupName << "', "
6855 << "'" << meshName<< "', "
6856 << toCopyElements << ", "
6857 << toCopyExistingBondary << ")";
6859 group = group_var._retn();
6860 return mesh_var._retn();
6862 SMESH_CATCH( SMESH::throwCorbaException );
6863 return SMESH::SMESH_Mesh::_nil();
6866 //================================================================================
6868 * \brief Creates missing boundary elements
6869 * \param dimension - defines type of boundary elements to create
6870 * \param groupName - a name of group to store all boundary elements in,
6871 * "" means not to create the group
6872 * \param meshName - a name of a new mesh, which is a copy of the initial
6873 * mesh + created boundary elements; "" means not to create the new mesh
6874 * \param toCopyAll - if true, the whole initial mesh will be copied into
6875 * the new mesh else only boundary elements will be copied into the new mesh
6876 * \param groups - optional groups of elements to make boundary around
6877 * \param mesh - returns the mesh where elements were added to
6878 * \param group - returns the created group, if any
6879 * \retval long - number of added boundary elements
6881 //================================================================================
6883 CORBA::Long SMESH_MeshEditor_i::MakeBoundaryElements(SMESH::Bnd_Dimension dim,
6884 const char* groupName,
6885 const char* meshName,
6886 CORBA::Boolean toCopyAll,
6887 const SMESH::ListOfIDSources& groups,
6888 SMESH::SMESH_Mesh_out mesh,
6889 SMESH::SMESH_Group_out group)
6890 throw (SALOME::SALOME_Exception)
6895 if ( dim > SMESH::BND_1DFROM2D )
6896 THROW_SALOME_CORBA_EXCEPTION("Invalid boundary dimension", SALOME::BAD_PARAM);
6898 // separate groups belonging to this and other mesh
6899 SMESH::ListOfIDSources_var groupsOfThisMesh = new SMESH::ListOfIDSources;
6900 SMESH::ListOfIDSources_var groupsOfOtherMesh = new SMESH::ListOfIDSources;
6901 groupsOfThisMesh->length( groups.length() );
6902 groupsOfOtherMesh->length( groups.length() );
6903 int nbGroups = 0, nbGroupsOfOtherMesh = 0;
6904 for ( int i = 0; i < groups.length(); ++i )
6906 SMESH::SMESH_Mesh_var m = groups[i]->GetMesh();
6907 if ( myMesh_i != SMESH::DownCast<SMESH_Mesh_i*>( m ))
6908 groupsOfOtherMesh[ nbGroupsOfOtherMesh++ ] = groups[i];
6910 groupsOfThisMesh[ nbGroups++ ] = groups[i];
6911 if ( SMESH::DownCast<SMESH_Mesh_i*>( groups[i] ))
6912 THROW_SALOME_CORBA_EXCEPTION("expect a group but recieve a mesh", SALOME::BAD_PARAM);
6914 groupsOfThisMesh->length( nbGroups );
6915 groupsOfOtherMesh->length( nbGroupsOfOtherMesh );
6920 if ( nbGroupsOfOtherMesh > 0 )
6922 // process groups belonging to another mesh
6923 SMESH::SMESH_Mesh_var otherMesh = groupsOfOtherMesh[0]->GetMesh();
6924 SMESH::SMESH_MeshEditor_var editor = otherMesh->GetMeshEditor();
6925 nbAdded += editor->MakeBoundaryElements( dim, groupName, meshName, toCopyAll,
6926 groupsOfOtherMesh, mesh, group );
6929 SMESH::SMESH_Mesh_var mesh_var;
6930 SMESH::SMESH_Group_var group_var;
6933 mesh_var = SMESH::SMESH_Mesh::_duplicate( myMesh_i->_this() );
6934 const bool toCopyMesh = ( strlen( meshName ) > 0 );
6938 mesh_var = SMESH_Gen_i::GetSMESHGen()->CopyMesh(mesh_var,
6940 /*toCopyGroups=*/false,
6941 /*toKeepIDs=*/true);
6943 mesh_var = makeMesh(meshName);
6945 SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh_var );
6946 SMESH_Mesh* tgtMesh = &mesh_i->GetImpl();
6949 SMESH_Mesh* srcMesh = ( toCopyMesh && !toCopyAll ) ? myMesh : tgtMesh;
6950 SMESHDS_Mesh* srcMeshDS = srcMesh->GetMeshDS();
6952 // group of boundary elements
6953 SMESH_Group* smesh_group = 0;
6954 SMDSAbs_ElementType elemType = (dim == SMESH::BND_2DFROM3D) ? SMDSAbs_Volume : SMDSAbs_Face;
6955 if ( strlen(groupName) )
6957 SMESH::ElementType groupType = SMESH::ElementType( int(elemType)-1 );
6958 group_var = mesh_i->CreateGroup( groupType, groupName );
6959 if ( SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>( group_var ))
6960 smesh_group = group_i->GetSmeshGroup();
6963 TIDSortedElemSet elements;
6965 if ( groups.length() > 0 )
6967 for ( int i = 0; i < nbGroups; ++i )
6970 if ( idSourceToSet( groupsOfThisMesh[i], srcMeshDS, elements, elemType,/*emptyIfIsMesh=*/0 ))
6972 SMESH::Bnd_Dimension bdim =
6973 ( elemType == SMDSAbs_Volume ) ? SMESH::BND_2DFROM3D : SMESH::BND_1DFROM2D;
6974 nbAdded += getEditor().MakeBoundaryMesh( elements,
6975 ::SMESH_MeshEditor::Bnd_Dimension(bdim),
6978 /*toCopyElements=*/false,
6979 /*toCopyExistingBondary=*/srcMesh != tgtMesh,
6980 /*toAddExistingBondary=*/true,
6981 /*aroundElements=*/true);
6987 nbAdded += getEditor().MakeBoundaryMesh( elements,
6988 ::SMESH_MeshEditor::Bnd_Dimension(dim),
6991 /*toCopyElements=*/false,
6992 /*toCopyExistingBondary=*/srcMesh != tgtMesh,
6993 /*toAddExistingBondary=*/true);
6995 tgtMesh->GetMeshDS()->Modified();
6997 const char* dimName[] = { "BND_2DFROM3D", "BND_1DFROM3D", "BND_1DFROM2D" };
6999 // result of MakeBoundaryElements() is a tuple (nb, mesh, group)
7000 pyDump << "nbAdded, ";
7001 if ( mesh_var->_is_nil() )
7002 pyDump << myMesh_i->_this() << ", ";
7004 pyDump << mesh_var << ", ";
7005 if ( group_var->_is_nil() )
7006 pyDump << "_NoneGroup = "; // assignment to None is forbiden
7008 pyDump << group_var << " = ";
7009 pyDump << this << ".MakeBoundaryElements( "
7010 << "SMESH." << dimName[int(dim)] << ", "
7011 << "'" << groupName << "', "
7012 << "'" << meshName<< "', "
7013 << toCopyAll << ", "
7016 mesh = mesh_var._retn();
7017 group = group_var._retn();
7020 SMESH_CATCH( SMESH::throwCorbaException );