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();
139 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
140 //const SMDS_MeshNode* nodes [NbNodes];
141 for (int i = 0; i < NbNodes; i++)
142 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
146 GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
148 else if (NbNodes == 4)
150 GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
154 GetMeshDS()->AddPolygonalFace(nodes);
159 //=============================================================================
163 //=============================================================================
165 CORBA::Boolean SMESH_MeshEditor_i::AddVolume(const SMESH::
166 long_array & IDsOfNodes)
168 int NbNodes = IDsOfNodes.length();
169 const SMDS_MeshNode* n[8];
170 for(int i=0;i<NbNodes;i++) n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
174 case 4:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
175 case 5:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
176 case 6:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
177 case 8:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
182 //=============================================================================
184 * AddPolyhedralVolume
186 //=============================================================================
187 CORBA::Boolean SMESH_MeshEditor_i::AddPolyhedralVolume
188 (const SMESH::long_array & IDsOfNodes,
189 const SMESH::long_array & Quantities)
191 int NbNodes = IDsOfNodes.length();
192 std::vector<const SMDS_MeshNode*> n (NbNodes);
193 //const SMDS_MeshNode* n [NbNodes];
194 for (int i = 0; i < NbNodes; i++)
195 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
197 int NbFaces = Quantities.length();
198 std::vector<int> q (NbFaces);
200 for (int j = 0; j < NbFaces; j++)
201 q[j] = Quantities[j];
203 GetMeshDS()->AddPolyhedralVolume(n, q);
207 //=============================================================================
209 * AddPolyhedralVolumeByFaces
211 //=============================================================================
212 CORBA::Boolean SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
213 (const SMESH::long_array & IdsOfFaces)
215 int NbFaces = IdsOfFaces.length();
216 std::vector<const SMDS_MeshFace*> faces (NbFaces);
217 for (int i = 0; i < NbFaces; i++)
218 faces[i] = (SMDS_MeshFace *)GetMeshDS()->FindElement(IdsOfFaces[i]);
220 //GetMeshDS()->AddPolyhedralVolumeByFaces(faces);
225 //=============================================================================
229 //=============================================================================
231 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
236 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
240 GetMeshDS()->MoveNode(node, x, y, z);
245 //=============================================================================
249 //=============================================================================
251 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
254 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
255 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
259 ::SMESH_MeshEditor aMeshEditor( _myMesh );
260 return aMeshEditor.InverseDiag ( n1, n2 );
263 //=============================================================================
267 //=============================================================================
269 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
272 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
273 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
277 ::SMESH_MeshEditor aMeshEditor( _myMesh );
278 return aMeshEditor.DeleteDiag ( n1, n2 );
281 //=============================================================================
285 //=============================================================================
287 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
289 ::SMESH_MeshEditor anEditor( _myMesh );
290 for (int i = 0; i < IDsOfElements.length(); i++)
292 CORBA::Long index = IDsOfElements[i];
293 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
295 anEditor.Reorient( elem );
301 //=============================================================================
305 //=============================================================================
307 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
309 SMESH::long_array_var anElementsId = theObject->GetIDs();
310 return Reorient(anElementsId);
313 //=============================================================================
317 //=============================================================================
320 SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
321 SMESH::NumericalFunctor_ptr Criterion,
322 CORBA::Double MaxAngle)
324 set<const SMDS_MeshElement*> faces;
325 for (int i = 0; i < IDsOfElements.length(); i++)
327 CORBA::Long index = IDsOfElements[i];
328 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
329 if ( elem && elem->GetType() == SMDSAbs_Face)
330 faces.insert( elem );
332 SMESH::NumericalFunctor_i* aNumericalFunctor =
333 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
334 SMESH::Controls::NumericalFunctorPtr aCrit;
335 if ( !aNumericalFunctor )
336 aCrit.reset( new SMESH::Controls::AspectRatio() );
338 aCrit = aNumericalFunctor->GetNumericalFunctor();
340 ::SMESH_MeshEditor anEditor( _myMesh );
341 return anEditor.TriToQuad( faces, aCrit, MaxAngle );
344 //=============================================================================
348 //=============================================================================
351 SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
352 SMESH::NumericalFunctor_ptr Criterion,
353 CORBA::Double MaxAngle)
355 SMESH::long_array_var anElementsId = theObject->GetIDs();
356 return TriToQuad(anElementsId, Criterion, MaxAngle);
359 //=============================================================================
363 //=============================================================================
366 SMESH_MeshEditor_i::QuadToTri(const SMESH::long_array & IDsOfElements,
367 SMESH::NumericalFunctor_ptr Criterion)
369 set<const SMDS_MeshElement*> faces;
370 for (int i = 0; i < IDsOfElements.length(); i++)
372 CORBA::Long index = IDsOfElements[i];
373 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
374 if ( elem && elem->GetType() == SMDSAbs_Face)
375 faces.insert( elem );
377 SMESH::NumericalFunctor_i* aNumericalFunctor =
378 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
379 SMESH::Controls::NumericalFunctorPtr aCrit;
380 if ( !aNumericalFunctor )
381 aCrit.reset( new SMESH::Controls::AspectRatio() );
383 aCrit = aNumericalFunctor->GetNumericalFunctor();
385 ::SMESH_MeshEditor anEditor( _myMesh );
386 return anEditor.QuadToTri( faces, aCrit );
389 //=============================================================================
393 //=============================================================================
396 SMESH_MeshEditor_i::SplitQuad(const SMESH::long_array & IDsOfElements,
397 CORBA::Boolean Diag13)
399 set<const SMDS_MeshElement*> faces;
400 for (int i = 0; i < IDsOfElements.length(); i++)
402 CORBA::Long index = IDsOfElements[i];
403 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
404 if ( elem && elem->GetType() == SMDSAbs_Face)
405 faces.insert( elem );
408 ::SMESH_MeshEditor anEditor( _myMesh );
409 return anEditor.QuadToTri( faces, Diag13 );
412 //=============================================================================
416 //=============================================================================
419 SMESH_MeshEditor_i::SplitQuadObject(SMESH::SMESH_IDSource_ptr theObject,
420 CORBA::Boolean Diag13)
422 SMESH::long_array_var anElementsId = theObject->GetIDs();
423 return SplitQuad(anElementsId, Diag13);
426 //=============================================================================
430 //=============================================================================
433 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
434 const SMESH::long_array & IDsOfFixedNodes,
435 CORBA::Long MaxNbOfIterations,
436 CORBA::Double MaxAspectRatio,
437 SMESH::SMESH_MeshEditor::Smooth_Method Method)
439 SMESHDS_Mesh* aMesh = GetMeshDS();
441 set<const SMDS_MeshElement*> elements;
442 for (int i = 0; i < IDsOfElements.length(); i++)
444 CORBA::Long index = IDsOfElements[i];
445 const SMDS_MeshElement * elem = aMesh->FindElement(index);
446 if ( elem && elem->GetType() == SMDSAbs_Face)
447 elements.insert( elem );
450 set<const SMDS_MeshNode*> fixedNodes;
451 for (int i = 0; i < IDsOfFixedNodes.length(); i++)
453 CORBA::Long index = IDsOfFixedNodes[i];
454 const SMDS_MeshNode * node = aMesh->FindNode(index);
456 fixedNodes.insert( node );
458 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
459 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
460 method = ::SMESH_MeshEditor::CENTROIDAL;
462 ::SMESH_MeshEditor anEditor( _myMesh );
463 anEditor.Smooth( elements, fixedNodes, method, MaxNbOfIterations, MaxAspectRatio );
468 //=============================================================================
472 //=============================================================================
475 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
476 const SMESH::long_array & IDsOfFixedNodes,
477 CORBA::Long MaxNbOfIterations,
478 CORBA::Double MaxAspectRatio,
479 SMESH::SMESH_MeshEditor::Smooth_Method Method)
481 SMESH::long_array_var anElementsId = theObject->GetIDs();
482 return Smooth(anElementsId, IDsOfFixedNodes, MaxNbOfIterations, MaxAspectRatio, Method);
485 //=============================================================================
489 //=============================================================================
491 void SMESH_MeshEditor_i::RenumberNodes()
493 GetMeshDS()->Renumber( true );
496 //=============================================================================
500 //=============================================================================
502 void SMESH_MeshEditor_i::RenumberElements()
504 GetMeshDS()->Renumber( false );
507 //=======================================================================
508 //function : RotationSweep
510 //=======================================================================
512 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
513 const SMESH::AxisStruct & theAxis,
514 CORBA::Double theAngleInRadians,
515 CORBA::Long theNbOfSteps,
516 CORBA::Double theTolerance)
518 SMESHDS_Mesh* aMesh = GetMeshDS();
520 set<const SMDS_MeshElement*> elements;
521 for (int i = 0; i < theIDsOfElements.length(); i++)
523 CORBA::Long index = theIDsOfElements[i];
524 const SMDS_MeshElement * elem = aMesh->FindElement(index);
526 elements.insert( elem );
528 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
529 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
531 ::SMESH_MeshEditor anEditor( _myMesh );
532 anEditor.RotationSweep (elements, Ax1, theAngleInRadians,
533 theNbOfSteps, theTolerance);
536 //=======================================================================
537 //function : RotationSweepObject
539 //=======================================================================
541 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
542 const SMESH::AxisStruct & theAxis,
543 CORBA::Double theAngleInRadians,
544 CORBA::Long theNbOfSteps,
545 CORBA::Double theTolerance)
547 SMESH::long_array_var anElementsId = theObject->GetIDs();
548 RotationSweep(anElementsId, theAxis, theAngleInRadians, theNbOfSteps, theTolerance);
551 //=======================================================================
552 //function : ExtrusionSweep
554 //=======================================================================
556 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
557 const SMESH::DirStruct & theStepVector,
558 CORBA::Long theNbOfSteps)
560 SMESHDS_Mesh* aMesh = GetMeshDS();
562 set<const SMDS_MeshElement*> elements;
563 for (int i = 0; i < theIDsOfElements.length(); i++)
565 CORBA::Long index = theIDsOfElements[i];
566 const SMDS_MeshElement * elem = aMesh->FindElement(index);
568 elements.insert( elem );
570 const SMESH::PointStruct * P = &theStepVector.PS;
571 gp_Vec stepVec( P->x, P->y, P->z );
573 ::SMESH_MeshEditor anEditor( _myMesh );
574 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
578 //=======================================================================
579 //function : ExtrusionSweepObject
581 //=======================================================================
583 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
584 const SMESH::DirStruct & theStepVector,
585 CORBA::Long theNbOfSteps)
587 SMESH::long_array_var anElementsId = theObject->GetIDs();
588 ExtrusionSweep(anElementsId, theStepVector, theNbOfSteps);
591 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
593 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
597 RETCASE( EXTR_NO_ELEMENTS );
598 RETCASE( EXTR_PATH_NOT_EDGE );
599 RETCASE( EXTR_BAD_PATH_SHAPE );
600 RETCASE( EXTR_BAD_STARTING_NODE );
601 RETCASE( EXTR_BAD_ANGLES_NUMBER );
602 RETCASE( EXTR_CANT_GET_TANGENT );
604 return SMESH::SMESH_MeshEditor::EXTR_OK;
607 //=======================================================================
608 //function : ExtrusionAlongPath
610 //=======================================================================
612 SMESH::SMESH_MeshEditor::Extrusion_Error
613 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
614 SMESH::SMESH_Mesh_ptr thePathMesh,
615 GEOM::GEOM_Object_ptr thePathShape,
616 CORBA::Long theNodeStart,
617 CORBA::Boolean theHasAngles,
618 const SMESH::double_array & theAngles,
619 CORBA::Boolean theHasRefPoint,
620 const SMESH::PointStruct & theRefPoint)
622 SMESHDS_Mesh* aMesh = GetMeshDS();
624 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() )
625 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
627 SMESH_Mesh_i* aMeshImp = dynamic_cast<SMESH_Mesh_i*>( SMESH_Gen_i::GetServant( thePathMesh ).in() );
628 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
629 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
632 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
634 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
636 return SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
638 set<const SMDS_MeshElement*> elements;
639 for (int i = 0; i < theIDsOfElements.length(); i++)
641 CORBA::Long index = theIDsOfElements[i];
642 const SMDS_MeshElement * elem = aMesh->FindElement(index);
644 elements.insert( elem );
648 for (int i = 0; i < theAngles.length(); i++)
650 angles.push_back( theAngles[i] );
653 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
655 ::SMESH_MeshEditor anEditor( _myMesh );
656 return convExtrError( anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart, theHasAngles, angles, theHasRefPoint, refPnt ) );
659 //=======================================================================
660 //function : ExtrusionAlongPathObject
662 //=======================================================================
664 SMESH::SMESH_MeshEditor::Extrusion_Error
665 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
666 SMESH::SMESH_Mesh_ptr thePathMesh,
667 GEOM::GEOM_Object_ptr thePathShape,
668 CORBA::Long theNodeStart,
669 CORBA::Boolean theHasAngles,
670 const SMESH::double_array & theAngles,
671 CORBA::Boolean theHasRefPoint,
672 const SMESH::PointStruct & theRefPoint)
674 SMESH::long_array_var anElementsId = theObject->GetIDs();
675 return ExtrusionAlongPath( anElementsId, thePathMesh, thePathShape, theNodeStart, theHasAngles, theAngles, theHasRefPoint, theRefPoint );
678 //=======================================================================
681 //=======================================================================
683 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
684 const SMESH::AxisStruct & theAxis,
685 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
686 CORBA::Boolean theCopy)
688 SMESHDS_Mesh* aMesh = GetMeshDS();
690 set<const SMDS_MeshElement*> elements;
691 for (int i = 0; i < theIDsOfElements.length(); i++)
693 CORBA::Long index = theIDsOfElements[i];
694 const SMDS_MeshElement * elem = aMesh->FindElement(index);
696 elements.insert( elem );
698 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
699 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
702 switch ( theMirrorType ) {
703 case SMESH::SMESH_MeshEditor::POINT:
704 aTrsf.SetMirror( P );
706 case SMESH::SMESH_MeshEditor::AXIS:
707 aTrsf.SetMirror( gp_Ax1( P, V ));
710 aTrsf.SetMirror( gp_Ax2( P, V ));
713 ::SMESH_MeshEditor anEditor( _myMesh );
714 anEditor.Transform (elements, aTrsf, theCopy);
717 //=======================================================================
718 //function : MirrorObject
720 //=======================================================================
722 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
723 const SMESH::AxisStruct & theAxis,
724 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
725 CORBA::Boolean theCopy)
727 SMESH::long_array_var anElementsId = theObject->GetIDs();
728 Mirror(anElementsId, theAxis, theMirrorType, theCopy);
731 //=======================================================================
732 //function : Translate
734 //=======================================================================
736 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
737 const SMESH::DirStruct & theVector,
738 CORBA::Boolean theCopy)
740 SMESHDS_Mesh* aMesh = GetMeshDS();
742 set<const SMDS_MeshElement*> elements;
743 for (int i = 0; i < theIDsOfElements.length(); i++)
745 CORBA::Long index = theIDsOfElements[i];
746 const SMDS_MeshElement * elem = aMesh->FindElement(index);
748 elements.insert( elem );
751 const SMESH::PointStruct * P = &theVector.PS;
752 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
754 ::SMESH_MeshEditor anEditor( _myMesh );
755 anEditor.Transform (elements, aTrsf, theCopy);
758 //=======================================================================
759 //function : TranslateObject
761 //=======================================================================
763 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
764 const SMESH::DirStruct & theVector,
765 CORBA::Boolean theCopy)
767 SMESH::long_array_var anElementsId = theObject->GetIDs();
768 Translate(anElementsId, theVector, theCopy);
771 //=======================================================================
774 //=======================================================================
776 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
777 const SMESH::AxisStruct & theAxis,
778 CORBA::Double theAngle,
779 CORBA::Boolean theCopy)
781 SMESHDS_Mesh* aMesh = GetMeshDS();
783 set<const SMDS_MeshElement*> elements;
784 for (int i = 0; i < theIDsOfElements.length(); i++)
786 CORBA::Long index = theIDsOfElements[i];
787 const SMDS_MeshElement * elem = aMesh->FindElement(index);
789 elements.insert( elem );
791 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
792 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
795 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
798 ::SMESH_MeshEditor anEditor( _myMesh );
799 anEditor.Transform (elements, aTrsf, theCopy);
802 //=======================================================================
803 //function : RotateObject
805 //=======================================================================
807 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
808 const SMESH::AxisStruct & theAxis,
809 CORBA::Double theAngle,
810 CORBA::Boolean theCopy)
812 SMESH::long_array_var anElementsId = theObject->GetIDs();
813 Rotate(anElementsId, theAxis, theAngle, theCopy);
816 //=======================================================================
817 //function : FindCoincidentNodes
819 //=======================================================================
821 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
822 SMESH::array_of_long_array_out GroupsOfNodes)
824 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
825 ::SMESH_MeshEditor anEditor( _myMesh );
826 set<const SMDS_MeshNode*> nodes; // no input nodes
827 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
829 GroupsOfNodes = new SMESH::array_of_long_array;
830 GroupsOfNodes->length( aListOfListOfNodes.size() );
831 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
832 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
834 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
835 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
836 SMESH::long_array& aGroup = GroupsOfNodes[ i ];
837 aGroup.length( aListOfNodes.size() );
838 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
839 aGroup[ j ] = (*lIt)->GetID();
843 //=======================================================================
844 //function : MergeNodes
846 //=======================================================================
848 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
850 SMESHDS_Mesh* aMesh = GetMeshDS();
852 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
853 list<const SMDS_MeshElement*> elements;
854 for (int i = 0; i < GroupsOfNodes.length(); i++)
856 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
857 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
858 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
859 for ( int j = 0; j < aNodeGroup.length(); j++ )
861 CORBA::Long index = aNodeGroup[ j ];
862 const SMDS_MeshNode * node = aMesh->FindNode(index);
864 aListOfNodes.push_back( node );
866 if ( aListOfNodes.size() < 2 )
867 aListOfListOfNodes.pop_back();
869 ::SMESH_MeshEditor anEditor( _myMesh );
870 anEditor.MergeNodes( aListOfListOfNodes );
873 //=======================================================================
874 //function : MergeEqualElements
876 //=======================================================================
878 void SMESH_MeshEditor_i::MergeEqualElements()
880 ::SMESH_MeshEditor anEditor( _myMesh );
881 anEditor.MergeEqualElements();
884 //=======================================================================
885 //function : operator
887 //=======================================================================
889 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
891 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
895 RETCASE( SEW_BORDER1_NOT_FOUND );
896 RETCASE( SEW_BORDER2_NOT_FOUND );
897 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
898 RETCASE( SEW_BAD_SIDE_NODES );
899 RETCASE( SEW_VOLUMES_TO_SPLIT );
900 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
901 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
902 RETCASE( SEW_BAD_SIDE1_NODES );
903 RETCASE( SEW_BAD_SIDE2_NODES );
905 return SMESH::SMESH_MeshEditor::SEW_OK;
908 //=======================================================================
909 //function : SewFreeBorders
911 //=======================================================================
913 SMESH::SMESH_MeshEditor::Sew_Error
914 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
915 CORBA::Long SecondNodeID1,
916 CORBA::Long LastNodeID1,
917 CORBA::Long FirstNodeID2,
918 CORBA::Long SecondNodeID2,
919 CORBA::Long LastNodeID2,
920 CORBA::Boolean CreatePoly)
922 SMESHDS_Mesh* aMesh = GetMeshDS();
924 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
925 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
926 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
927 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
928 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
929 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
931 if (!aBorderFirstNode ||
934 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
935 if (!aSide2FirstNode ||
938 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
940 ::SMESH_MeshEditor anEditor( _myMesh );
941 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
951 //=======================================================================
952 //function : SewConformFreeBorders
954 //=======================================================================
956 SMESH::SMESH_MeshEditor::Sew_Error
957 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
958 CORBA::Long SecondNodeID1,
959 CORBA::Long LastNodeID1,
960 CORBA::Long FirstNodeID2,
961 CORBA::Long SecondNodeID2)
963 SMESHDS_Mesh* aMesh = GetMeshDS();
965 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
966 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
967 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
968 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
969 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
970 const SMDS_MeshNode* aSide2ThirdNode = 0;
972 if (!aBorderFirstNode ||
975 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
976 if (!aSide2FirstNode ||
978 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
980 ::SMESH_MeshEditor anEditor( _myMesh );
981 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
991 //=======================================================================
992 //function : SewBorderToSide
994 //=======================================================================
996 SMESH::SMESH_MeshEditor::Sew_Error
997 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
998 CORBA::Long SecondNodeIDOnFreeBorder,
999 CORBA::Long LastNodeIDOnFreeBorder,
1000 CORBA::Long FirstNodeIDOnSide,
1001 CORBA::Long LastNodeIDOnSide)
1003 SMESHDS_Mesh* aMesh = GetMeshDS();
1005 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
1006 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
1007 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
1008 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
1009 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
1010 const SMDS_MeshNode* aSide2ThirdNode = 0;
1012 if (!aBorderFirstNode ||
1013 !aBorderSecondNode||
1015 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1016 if (!aSide2FirstNode ||
1018 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
1020 ::SMESH_MeshEditor anEditor( _myMesh );
1021 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
1031 //=======================================================================
1032 //function : SewSideElements
1034 //=======================================================================
1036 SMESH::SMESH_MeshEditor::Sew_Error
1037 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
1038 const SMESH::long_array& IDsOfSide2Elements,
1039 CORBA::Long NodeID1OfSide1ToMerge,
1040 CORBA::Long NodeID1OfSide2ToMerge,
1041 CORBA::Long NodeID2OfSide1ToMerge,
1042 CORBA::Long NodeID2OfSide2ToMerge)
1044 SMESHDS_Mesh* aMesh = GetMeshDS();
1046 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
1047 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
1048 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
1049 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
1051 if (!aFirstNode1ToMerge ||
1052 !aFirstNode2ToMerge )
1053 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
1054 if (!aSecondNode1ToMerge||
1055 !aSecondNode2ToMerge)
1056 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
1058 set<const SMDS_MeshElement*> aSide1Elems, aSide2Elems;
1059 for (int i = 0; i < IDsOfSide1Elements.length(); i++)
1061 CORBA::Long index = IDsOfSide1Elements[i];
1062 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1064 aSide1Elems.insert( elem );
1066 for (int i = 0; i < IDsOfSide2Elements.length(); i++)
1068 CORBA::Long index = IDsOfSide2Elements[i];
1069 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1071 aSide2Elems.insert( elem );
1073 ::SMESH_MeshEditor anEditor( _myMesh );
1074 return convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
1077 aSecondNode1ToMerge,
1078 aSecondNode2ToMerge));