1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_MeshEditor_i.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESH_MeshEditor_i.hxx"
31 #include "SMDS_MeshEdge.hxx"
32 #include "SMDS_MeshFace.hxx"
33 #include "SMDS_MeshVolume.hxx"
35 #include "SMESH_MeshEditor.hxx"
37 #include "SMESH_Gen_i.hxx"
38 #include "SMESH_Filter_i.hxx"
40 #include "utilities.h"
48 //=============================================================================
52 //=============================================================================
54 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh* theMesh)
59 //=============================================================================
63 //=============================================================================
65 CORBA::Boolean SMESH_MeshEditor_i::RemoveElements(const SMESH::
66 long_array & IDsOfElements)
68 ::SMESH_MeshEditor anEditor( _myMesh );
70 for (int i = 0; i < IDsOfElements.length(); i++)
71 IdList.push_back( IDsOfElements[i] );
73 return anEditor.Remove( IdList, false );
76 //=============================================================================
80 //=============================================================================
82 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::
83 long_array & IDsOfNodes)
85 ::SMESH_MeshEditor anEditor( _myMesh );
87 for (int i = 0; i < IDsOfNodes.length(); i++)
88 IdList.push_back( IDsOfNodes[i] );
90 return anEditor.Remove( IdList, true );
93 //=============================================================================
97 //=============================================================================
99 CORBA::Boolean SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
101 int NbNodes = IDsOfNodes.length();
104 CORBA::Long index1 = IDsOfNodes[0];
105 CORBA::Long index2 = IDsOfNodes[1];
106 GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
111 //=============================================================================
115 //=============================================================================
117 CORBA::Boolean SMESH_MeshEditor_i::AddNode(CORBA::Double x,
118 CORBA::Double y, CORBA::Double z)
120 MESSAGE(" AddNode " << x << " , " << y << " , " << z)
121 int idNode = GetMeshDS()->AddNode(x, y, z)->GetID();
122 MESSAGE(" idNode " << idNode) return true;
125 //=============================================================================
129 //=============================================================================
131 CORBA::Boolean SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
133 int NbNodes = IDsOfNodes.length();
134 const SMDS_MeshNode* nodes[4];
135 for(int i=0;i<NbNodes;i++) nodes[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
138 GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
140 else if (NbNodes == 4)
142 GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
147 //=============================================================================
151 //=============================================================================
153 CORBA::Boolean SMESH_MeshEditor_i::AddVolume(const SMESH::
154 long_array & IDsOfNodes)
156 int NbNodes = IDsOfNodes.length();
157 const SMDS_MeshNode* n[8];
158 for(int i=0;i<NbNodes;i++) n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
162 case 4:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
163 case 5:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
164 case 6:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
165 case 8:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
170 //=============================================================================
174 //=============================================================================
176 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
181 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
185 GetMeshDS()->MoveNode(node, x, y, z);
190 //=============================================================================
194 //=============================================================================
196 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
199 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
200 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
204 ::SMESH_MeshEditor aMeshEditor( _myMesh );
205 return aMeshEditor.InverseDiag ( n1, n2 );
208 //=============================================================================
212 //=============================================================================
214 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
217 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
218 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
222 ::SMESH_MeshEditor aMeshEditor( _myMesh );
223 return aMeshEditor.DeleteDiag ( n1, n2 );
226 //=============================================================================
230 //=============================================================================
232 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
234 ::SMESH_MeshEditor anEditor( _myMesh );
235 for (int i = 0; i < IDsOfElements.length(); i++)
237 CORBA::Long index = IDsOfElements[i];
238 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
240 anEditor.Reorient( elem );
246 //=============================================================================
250 //=============================================================================
252 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
254 SMESH::long_array_var anElementsId = theObject->GetIDs();
255 return Reorient(anElementsId);
258 //=============================================================================
262 //=============================================================================
265 SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
266 SMESH::NumericalFunctor_ptr Criterion,
267 CORBA::Double MaxAngle)
269 set<const SMDS_MeshElement*> faces;
270 for (int i = 0; i < IDsOfElements.length(); i++)
272 CORBA::Long index = IDsOfElements[i];
273 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
274 if ( elem && elem->GetType() == SMDSAbs_Face)
275 faces.insert( elem );
277 SMESH::NumericalFunctor_i* aNumericalFunctor =
278 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
279 SMESH::Controls::NumericalFunctorPtr aCrit;
280 if ( !aNumericalFunctor )
281 aCrit.reset( new SMESH::Controls::AspectRatio() );
283 aCrit = aNumericalFunctor->GetNumericalFunctor();
285 ::SMESH_MeshEditor anEditor( _myMesh );
286 return anEditor.TriToQuad( faces, aCrit, MaxAngle );
289 //=============================================================================
293 //=============================================================================
296 SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
297 SMESH::NumericalFunctor_ptr Criterion,
298 CORBA::Double MaxAngle)
300 SMESH::long_array_var anElementsId = theObject->GetIDs();
301 return TriToQuad(anElementsId, Criterion, MaxAngle);
304 //=============================================================================
308 //=============================================================================
311 SMESH_MeshEditor_i::QuadToTri(const SMESH::long_array & IDsOfElements,
312 SMESH::NumericalFunctor_ptr Criterion)
314 set<const SMDS_MeshElement*> faces;
315 for (int i = 0; i < IDsOfElements.length(); i++)
317 CORBA::Long index = IDsOfElements[i];
318 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
319 if ( elem && elem->GetType() == SMDSAbs_Face)
320 faces.insert( elem );
322 SMESH::NumericalFunctor_i* aNumericalFunctor =
323 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
324 SMESH::Controls::NumericalFunctorPtr aCrit;
325 if ( !aNumericalFunctor )
326 aCrit.reset( new SMESH::Controls::AspectRatio() );
328 aCrit = aNumericalFunctor->GetNumericalFunctor();
330 ::SMESH_MeshEditor anEditor( _myMesh );
331 return anEditor.QuadToTri( faces, aCrit );
334 //=============================================================================
338 //=============================================================================
341 SMESH_MeshEditor_i::SplitQuad(const SMESH::long_array & IDsOfElements,
342 CORBA::Boolean Diag13)
344 set<const SMDS_MeshElement*> faces;
345 for (int i = 0; i < IDsOfElements.length(); i++)
347 CORBA::Long index = IDsOfElements[i];
348 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
349 if ( elem && elem->GetType() == SMDSAbs_Face)
350 faces.insert( elem );
353 ::SMESH_MeshEditor anEditor( _myMesh );
354 return anEditor.QuadToTri( faces, Diag13 );
357 //=============================================================================
361 //=============================================================================
364 SMESH_MeshEditor_i::SplitQuadObject(SMESH::SMESH_IDSource_ptr theObject,
365 CORBA::Boolean Diag13)
367 SMESH::long_array_var anElementsId = theObject->GetIDs();
368 return SplitQuad(anElementsId, Diag13);
371 //=============================================================================
375 //=============================================================================
378 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
379 const SMESH::long_array & IDsOfFixedNodes,
380 CORBA::Long MaxNbOfIterations,
381 CORBA::Double MaxAspectRatio,
382 SMESH::SMESH_MeshEditor::Smooth_Method Method)
384 SMESHDS_Mesh* aMesh = GetMeshDS();
386 set<const SMDS_MeshElement*> elements;
387 for (int i = 0; i < IDsOfElements.length(); i++)
389 CORBA::Long index = IDsOfElements[i];
390 const SMDS_MeshElement * elem = aMesh->FindElement(index);
391 if ( elem && elem->GetType() == SMDSAbs_Face)
392 elements.insert( elem );
395 set<const SMDS_MeshNode*> fixedNodes;
396 for (int i = 0; i < IDsOfFixedNodes.length(); i++)
398 CORBA::Long index = IDsOfFixedNodes[i];
399 const SMDS_MeshNode * node = aMesh->FindNode(index);
401 fixedNodes.insert( node );
403 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
404 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
405 method = ::SMESH_MeshEditor::CENTROIDAL;
407 ::SMESH_MeshEditor anEditor( _myMesh );
408 anEditor.Smooth( elements, fixedNodes, method, MaxNbOfIterations, MaxAspectRatio );
413 //=============================================================================
417 //=============================================================================
420 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
421 const SMESH::long_array & IDsOfFixedNodes,
422 CORBA::Long MaxNbOfIterations,
423 CORBA::Double MaxAspectRatio,
424 SMESH::SMESH_MeshEditor::Smooth_Method Method)
426 SMESH::long_array_var anElementsId = theObject->GetIDs();
427 return Smooth(anElementsId, IDsOfFixedNodes, MaxNbOfIterations, MaxAspectRatio, Method);
430 //=============================================================================
434 //=============================================================================
436 void SMESH_MeshEditor_i::RenumberNodes()
438 GetMeshDS()->Renumber( true );
441 //=============================================================================
445 //=============================================================================
447 void SMESH_MeshEditor_i::RenumberElements()
449 GetMeshDS()->Renumber( false );
452 //=======================================================================
453 //function : RotationSweep
455 //=======================================================================
457 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
458 const SMESH::AxisStruct & theAxis,
459 CORBA::Double theAngleInRadians,
460 CORBA::Long theNbOfSteps,
461 CORBA::Double theTolerance)
463 SMESHDS_Mesh* aMesh = GetMeshDS();
465 set<const SMDS_MeshElement*> elements;
466 for (int i = 0; i < theIDsOfElements.length(); i++)
468 CORBA::Long index = theIDsOfElements[i];
469 const SMDS_MeshElement * elem = aMesh->FindElement(index);
471 elements.insert( elem );
473 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
474 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
476 ::SMESH_MeshEditor anEditor( _myMesh );
477 anEditor.RotationSweep (elements, Ax1, theAngleInRadians,
478 theNbOfSteps, theTolerance);
481 //=======================================================================
482 //function : RotationSweepObject
484 //=======================================================================
486 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
487 const SMESH::AxisStruct & theAxis,
488 CORBA::Double theAngleInRadians,
489 CORBA::Long theNbOfSteps,
490 CORBA::Double theTolerance)
492 SMESH::long_array_var anElementsId = theObject->GetIDs();
493 RotationSweep(anElementsId, theAxis, theAngleInRadians, theNbOfSteps, theTolerance);
496 //=======================================================================
497 //function : ExtrusionSweep
499 //=======================================================================
501 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
502 const SMESH::DirStruct & theStepVector,
503 CORBA::Long theNbOfSteps)
505 SMESHDS_Mesh* aMesh = GetMeshDS();
507 set<const SMDS_MeshElement*> elements;
508 for (int i = 0; i < theIDsOfElements.length(); i++)
510 CORBA::Long index = theIDsOfElements[i];
511 const SMDS_MeshElement * elem = aMesh->FindElement(index);
513 elements.insert( elem );
515 const SMESH::PointStruct * P = &theStepVector.PS;
516 gp_Vec stepVec( P->x, P->y, P->z );
518 ::SMESH_MeshEditor anEditor( _myMesh );
519 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
523 //=======================================================================
524 //function : ExtrusionSweepObject
526 //=======================================================================
528 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
529 const SMESH::DirStruct & theStepVector,
530 CORBA::Long theNbOfSteps)
532 SMESH::long_array_var anElementsId = theObject->GetIDs();
533 ExtrusionSweep(anElementsId, theStepVector, theNbOfSteps);
536 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
538 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
542 RETCASE( EXTR_NO_ELEMENTS );
543 RETCASE( EXTR_PATH_NOT_EDGE );
544 RETCASE( EXTR_BAD_PATH_SHAPE );
545 RETCASE( EXTR_BAD_STARTING_NODE );
546 RETCASE( EXTR_BAD_ANGLES_NUMBER );
547 RETCASE( EXTR_CANT_GET_TANGENT );
549 return SMESH::SMESH_MeshEditor::EXTR_OK;
552 //=======================================================================
553 //function : ExtrusionAlongPath
555 //=======================================================================
557 SMESH::SMESH_MeshEditor::Extrusion_Error
558 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
559 SMESH::SMESH_Mesh_ptr thePathMesh,
560 GEOM::GEOM_Object_ptr thePathShape,
561 CORBA::Long theNodeStart,
562 CORBA::Boolean theHasAngles,
563 const SMESH::double_array & theAngles,
564 CORBA::Boolean theHasRefPoint,
565 const SMESH::PointStruct & theRefPoint)
567 SMESHDS_Mesh* aMesh = GetMeshDS();
569 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() )
570 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
572 SMESH_Mesh_i* aMeshImp = dynamic_cast<SMESH_Mesh_i*>( SMESH_Gen_i::GetServant( thePathMesh ).in() );
573 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
574 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
577 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
579 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
581 return SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
583 set<const SMDS_MeshElement*> elements;
584 for (int i = 0; i < theIDsOfElements.length(); i++)
586 CORBA::Long index = theIDsOfElements[i];
587 const SMDS_MeshElement * elem = aMesh->FindElement(index);
589 elements.insert( elem );
593 for (int i = 0; i < theAngles.length(); i++)
595 angles.push_back( theAngles[i] );
598 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
600 ::SMESH_MeshEditor anEditor( _myMesh );
601 return convExtrError( anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart, theHasAngles, angles, theHasRefPoint, refPnt ) );
604 //=======================================================================
605 //function : ExtrusionAlongPathObject
607 //=======================================================================
609 SMESH::SMESH_MeshEditor::Extrusion_Error
610 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
611 SMESH::SMESH_Mesh_ptr thePathMesh,
612 GEOM::GEOM_Object_ptr thePathShape,
613 CORBA::Long theNodeStart,
614 CORBA::Boolean theHasAngles,
615 const SMESH::double_array & theAngles,
616 CORBA::Boolean theHasRefPoint,
617 const SMESH::PointStruct & theRefPoint)
619 SMESH::long_array_var anElementsId = theObject->GetIDs();
620 return ExtrusionAlongPath( anElementsId, thePathMesh, thePathShape, theNodeStart, theHasAngles, theAngles, theHasRefPoint, theRefPoint );
623 //=======================================================================
626 //=======================================================================
628 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
629 const SMESH::AxisStruct & theAxis,
630 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
631 CORBA::Boolean theCopy)
633 SMESHDS_Mesh* aMesh = GetMeshDS();
635 set<const SMDS_MeshElement*> elements;
636 for (int i = 0; i < theIDsOfElements.length(); i++)
638 CORBA::Long index = theIDsOfElements[i];
639 const SMDS_MeshElement * elem = aMesh->FindElement(index);
641 elements.insert( elem );
643 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
644 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
647 switch ( theMirrorType ) {
648 case SMESH::SMESH_MeshEditor::POINT:
649 aTrsf.SetMirror( P );
651 case SMESH::SMESH_MeshEditor::AXIS:
652 aTrsf.SetMirror( gp_Ax1( P, V ));
655 aTrsf.SetMirror( gp_Ax2( P, V ));
658 ::SMESH_MeshEditor anEditor( _myMesh );
659 anEditor.Transform (elements, aTrsf, theCopy);
662 //=======================================================================
663 //function : MirrorObject
665 //=======================================================================
667 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
668 const SMESH::AxisStruct & theAxis,
669 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
670 CORBA::Boolean theCopy)
672 SMESH::long_array_var anElementsId = theObject->GetIDs();
673 Mirror(anElementsId, theAxis, theMirrorType, theCopy);
676 //=======================================================================
677 //function : Translate
679 //=======================================================================
681 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
682 const SMESH::DirStruct & theVector,
683 CORBA::Boolean theCopy)
685 SMESHDS_Mesh* aMesh = GetMeshDS();
687 set<const SMDS_MeshElement*> elements;
688 for (int i = 0; i < theIDsOfElements.length(); i++)
690 CORBA::Long index = theIDsOfElements[i];
691 const SMDS_MeshElement * elem = aMesh->FindElement(index);
693 elements.insert( elem );
696 const SMESH::PointStruct * P = &theVector.PS;
697 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
699 ::SMESH_MeshEditor anEditor( _myMesh );
700 anEditor.Transform (elements, aTrsf, theCopy);
703 //=======================================================================
704 //function : TranslateObject
706 //=======================================================================
708 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
709 const SMESH::DirStruct & theVector,
710 CORBA::Boolean theCopy)
712 SMESH::long_array_var anElementsId = theObject->GetIDs();
713 Translate(anElementsId, theVector, theCopy);
716 //=======================================================================
719 //=======================================================================
721 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
722 const SMESH::AxisStruct & theAxis,
723 CORBA::Double theAngle,
724 CORBA::Boolean theCopy)
726 SMESHDS_Mesh* aMesh = GetMeshDS();
728 set<const SMDS_MeshElement*> elements;
729 for (int i = 0; i < theIDsOfElements.length(); i++)
731 CORBA::Long index = theIDsOfElements[i];
732 const SMDS_MeshElement * elem = aMesh->FindElement(index);
734 elements.insert( elem );
736 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
737 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
740 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
743 ::SMESH_MeshEditor anEditor( _myMesh );
744 anEditor.Transform (elements, aTrsf, theCopy);
747 //=======================================================================
748 //function : RotateObject
750 //=======================================================================
752 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
753 const SMESH::AxisStruct & theAxis,
754 CORBA::Double theAngle,
755 CORBA::Boolean theCopy)
757 SMESH::long_array_var anElementsId = theObject->GetIDs();
758 Rotate(anElementsId, theAxis, theAngle, theCopy);
761 //=======================================================================
762 //function : FindCoincidentNodes
764 //=======================================================================
766 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
767 SMESH::array_of_long_array_out GroupsOfNodes)
769 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
770 ::SMESH_MeshEditor anEditor( _myMesh );
771 set<const SMDS_MeshNode*> nodes; // no input nodes
772 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
774 GroupsOfNodes = new SMESH::array_of_long_array;
775 GroupsOfNodes->length( aListOfListOfNodes.size() );
776 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
777 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
779 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
780 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
781 SMESH::long_array& aGroup = GroupsOfNodes[ i ];
782 aGroup.length( aListOfNodes.size() );
783 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
784 aGroup[ j ] = (*lIt)->GetID();
788 //=======================================================================
789 //function : MergeNodes
791 //=======================================================================
793 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
795 SMESHDS_Mesh* aMesh = GetMeshDS();
797 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
798 list<const SMDS_MeshElement*> elements;
799 for (int i = 0; i < GroupsOfNodes.length(); i++)
801 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
802 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
803 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
804 for ( int j = 0; j < aNodeGroup.length(); j++ )
806 CORBA::Long index = aNodeGroup[ j ];
807 const SMDS_MeshNode * node = aMesh->FindNode(index);
809 aListOfNodes.push_back( node );
811 if ( aListOfNodes.size() < 2 )
812 aListOfListOfNodes.pop_back();
814 ::SMESH_MeshEditor anEditor( _myMesh );
815 anEditor.MergeNodes( aListOfListOfNodes );
818 //=======================================================================
819 //function : MergeEqualElements
821 //=======================================================================
823 void SMESH_MeshEditor_i::MergeEqualElements()
825 ::SMESH_MeshEditor anEditor( _myMesh );
826 anEditor.MergeEqualElements();
829 //=======================================================================
830 //function : operator
832 //=======================================================================
834 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
836 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
840 RETCASE( SEW_BORDER1_NOT_FOUND );
841 RETCASE( SEW_BORDER2_NOT_FOUND );
842 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
843 RETCASE( SEW_BAD_SIDE_NODES );
844 RETCASE( SEW_VOLUMES_TO_SPLIT );
845 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
846 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
847 RETCASE( SEW_BAD_SIDE1_NODES );
848 RETCASE( SEW_BAD_SIDE2_NODES );
850 return SMESH::SMESH_MeshEditor::SEW_OK;
853 //=======================================================================
854 //function : SewFreeBorders
856 //=======================================================================
858 SMESH::SMESH_MeshEditor::Sew_Error
859 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
860 CORBA::Long SecondNodeID1,
861 CORBA::Long LastNodeID1,
862 CORBA::Long FirstNodeID2,
863 CORBA::Long SecondNodeID2,
864 CORBA::Long LastNodeID2)
866 SMESHDS_Mesh* aMesh = GetMeshDS();
868 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
869 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
870 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
871 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
872 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
873 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
875 if (!aBorderFirstNode ||
878 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
879 if (!aSide2FirstNode ||
882 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
884 ::SMESH_MeshEditor anEditor( _myMesh );
885 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
894 //=======================================================================
895 //function : SewConformFreeBorders
897 //=======================================================================
899 SMESH::SMESH_MeshEditor::Sew_Error
900 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
901 CORBA::Long SecondNodeID1,
902 CORBA::Long LastNodeID1,
903 CORBA::Long FirstNodeID2,
904 CORBA::Long SecondNodeID2)
906 SMESHDS_Mesh* aMesh = GetMeshDS();
908 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
909 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
910 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
911 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
912 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
913 const SMDS_MeshNode* aSide2ThirdNode = 0;
915 if (!aBorderFirstNode ||
918 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
919 if (!aSide2FirstNode ||
921 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
923 ::SMESH_MeshEditor anEditor( _myMesh );
924 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
933 //=======================================================================
934 //function : SewBorderToSide
936 //=======================================================================
938 SMESH::SMESH_MeshEditor::Sew_Error
939 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
940 CORBA::Long SecondNodeIDOnFreeBorder,
941 CORBA::Long LastNodeIDOnFreeBorder,
942 CORBA::Long FirstNodeIDOnSide,
943 CORBA::Long LastNodeIDOnSide)
945 SMESHDS_Mesh* aMesh = GetMeshDS();
947 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
948 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
949 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
950 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
951 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
952 const SMDS_MeshNode* aSide2ThirdNode = 0;
954 if (!aBorderFirstNode ||
957 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
958 if (!aSide2FirstNode ||
960 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
962 ::SMESH_MeshEditor anEditor( _myMesh );
963 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
972 //=======================================================================
973 //function : SewSideElements
975 //=======================================================================
977 SMESH::SMESH_MeshEditor::Sew_Error
978 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
979 const SMESH::long_array& IDsOfSide2Elements,
980 CORBA::Long NodeID1OfSide1ToMerge,
981 CORBA::Long NodeID1OfSide2ToMerge,
982 CORBA::Long NodeID2OfSide1ToMerge,
983 CORBA::Long NodeID2OfSide2ToMerge)
985 SMESHDS_Mesh* aMesh = GetMeshDS();
987 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
988 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
989 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
990 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
992 if (!aFirstNode1ToMerge ||
993 !aFirstNode2ToMerge )
994 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
995 if (!aSecondNode1ToMerge||
996 !aSecondNode2ToMerge)
997 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
999 set<const SMDS_MeshElement*> aSide1Elems, aSide2Elems;
1000 for (int i = 0; i < IDsOfSide1Elements.length(); i++)
1002 CORBA::Long index = IDsOfSide1Elements[i];
1003 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1005 aSide1Elems.insert( elem );
1007 for (int i = 0; i < IDsOfSide2Elements.length(); i++)
1009 CORBA::Long index = IDsOfSide2Elements[i];
1010 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1012 aSide2Elems.insert( elem );
1014 ::SMESH_MeshEditor anEditor( _myMesh );
1015 return convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
1018 aSecondNode1ToMerge,
1019 aSecondNode2ToMerge));