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 //=======================================================================
537 //function : ExtrusionSweepObject1D
539 //=======================================================================
541 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
542 const SMESH::DirStruct & theStepVector,
543 CORBA::Long theNbOfSteps)
545 SMESHDS_Mesh* aMesh = GetMeshDS();
547 SMESH::long_array_var allElementsId = theObject->GetIDs();
549 set<const SMDS_MeshElement*> elements;
550 for (int i = 0; i < allElementsId->length(); i++)
552 CORBA::Long index = allElementsId[i];
553 const SMDS_MeshElement * elem = aMesh->FindElement(index);
554 if ( elem && elem->GetType() == SMDSAbs_Edge )
555 elements.insert( elem );
557 const SMESH::PointStruct * P = &theStepVector.PS;
558 gp_Vec stepVec( P->x, P->y, P->z );
560 ::SMESH_MeshEditor anEditor( _myMesh );
561 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
564 //=======================================================================
565 //function : ExtrusionSweepObject2D
567 //=======================================================================
569 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
570 const SMESH::DirStruct & theStepVector,
571 CORBA::Long theNbOfSteps)
573 SMESHDS_Mesh* aMesh = GetMeshDS();
575 SMESH::long_array_var allElementsId = theObject->GetIDs();
577 set<const SMDS_MeshElement*> elements;
578 for (int i = 0; i < allElementsId->length(); i++)
580 CORBA::Long index = allElementsId[i];
581 const SMDS_MeshElement * elem = aMesh->FindElement(index);
582 if ( elem && elem->GetType() == SMDSAbs_Face )
583 elements.insert( elem );
585 const SMESH::PointStruct * P = &theStepVector.PS;
586 gp_Vec stepVec( P->x, P->y, P->z );
588 ::SMESH_MeshEditor anEditor( _myMesh );
589 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
592 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
594 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
598 RETCASE( EXTR_NO_ELEMENTS );
599 RETCASE( EXTR_PATH_NOT_EDGE );
600 RETCASE( EXTR_BAD_PATH_SHAPE );
601 RETCASE( EXTR_BAD_STARTING_NODE );
602 RETCASE( EXTR_BAD_ANGLES_NUMBER );
603 RETCASE( EXTR_CANT_GET_TANGENT );
605 return SMESH::SMESH_MeshEditor::EXTR_OK;
608 //=======================================================================
609 //function : ExtrusionAlongPath
611 //=======================================================================
613 SMESH::SMESH_MeshEditor::Extrusion_Error
614 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
615 SMESH::SMESH_Mesh_ptr thePathMesh,
616 GEOM::GEOM_Object_ptr thePathShape,
617 CORBA::Long theNodeStart,
618 CORBA::Boolean theHasAngles,
619 const SMESH::double_array & theAngles,
620 CORBA::Boolean theHasRefPoint,
621 const SMESH::PointStruct & theRefPoint)
623 SMESHDS_Mesh* aMesh = GetMeshDS();
625 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() )
626 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
628 SMESH_Mesh_i* aMeshImp = dynamic_cast<SMESH_Mesh_i*>( SMESH_Gen_i::GetServant( thePathMesh ).in() );
629 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
630 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
633 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
635 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
637 return SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
639 set<const SMDS_MeshElement*> elements;
640 for (int i = 0; i < theIDsOfElements.length(); i++)
642 CORBA::Long index = theIDsOfElements[i];
643 const SMDS_MeshElement * elem = aMesh->FindElement(index);
645 elements.insert( elem );
649 for (int i = 0; i < theAngles.length(); i++)
651 angles.push_back( theAngles[i] );
654 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
656 ::SMESH_MeshEditor anEditor( _myMesh );
657 return convExtrError( anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart, theHasAngles, angles, theHasRefPoint, refPnt ) );
660 //=======================================================================
661 //function : ExtrusionAlongPathObject
663 //=======================================================================
665 SMESH::SMESH_MeshEditor::Extrusion_Error
666 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
667 SMESH::SMESH_Mesh_ptr thePathMesh,
668 GEOM::GEOM_Object_ptr thePathShape,
669 CORBA::Long theNodeStart,
670 CORBA::Boolean theHasAngles,
671 const SMESH::double_array & theAngles,
672 CORBA::Boolean theHasRefPoint,
673 const SMESH::PointStruct & theRefPoint)
675 SMESH::long_array_var anElementsId = theObject->GetIDs();
676 return ExtrusionAlongPath( anElementsId, thePathMesh, thePathShape, theNodeStart, theHasAngles, theAngles, theHasRefPoint, theRefPoint );
679 //=======================================================================
682 //=======================================================================
684 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
685 const SMESH::AxisStruct & theAxis,
686 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
687 CORBA::Boolean theCopy)
689 SMESHDS_Mesh* aMesh = GetMeshDS();
691 set<const SMDS_MeshElement*> elements;
692 for (int i = 0; i < theIDsOfElements.length(); i++)
694 CORBA::Long index = theIDsOfElements[i];
695 const SMDS_MeshElement * elem = aMesh->FindElement(index);
697 elements.insert( elem );
699 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
700 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
703 switch ( theMirrorType ) {
704 case SMESH::SMESH_MeshEditor::POINT:
705 aTrsf.SetMirror( P );
707 case SMESH::SMESH_MeshEditor::AXIS:
708 aTrsf.SetMirror( gp_Ax1( P, V ));
711 aTrsf.SetMirror( gp_Ax2( P, V ));
714 ::SMESH_MeshEditor anEditor( _myMesh );
715 anEditor.Transform (elements, aTrsf, theCopy);
718 //=======================================================================
719 //function : MirrorObject
721 //=======================================================================
723 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
724 const SMESH::AxisStruct & theAxis,
725 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
726 CORBA::Boolean theCopy)
728 SMESH::long_array_var anElementsId = theObject->GetIDs();
729 Mirror(anElementsId, theAxis, theMirrorType, theCopy);
732 //=======================================================================
733 //function : Translate
735 //=======================================================================
737 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
738 const SMESH::DirStruct & theVector,
739 CORBA::Boolean theCopy)
741 SMESHDS_Mesh* aMesh = GetMeshDS();
743 set<const SMDS_MeshElement*> elements;
744 for (int i = 0; i < theIDsOfElements.length(); i++)
746 CORBA::Long index = theIDsOfElements[i];
747 const SMDS_MeshElement * elem = aMesh->FindElement(index);
749 elements.insert( elem );
752 const SMESH::PointStruct * P = &theVector.PS;
753 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
755 ::SMESH_MeshEditor anEditor( _myMesh );
756 anEditor.Transform (elements, aTrsf, theCopy);
759 //=======================================================================
760 //function : TranslateObject
762 //=======================================================================
764 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
765 const SMESH::DirStruct & theVector,
766 CORBA::Boolean theCopy)
768 SMESH::long_array_var anElementsId = theObject->GetIDs();
769 Translate(anElementsId, theVector, theCopy);
772 //=======================================================================
775 //=======================================================================
777 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
778 const SMESH::AxisStruct & theAxis,
779 CORBA::Double theAngle,
780 CORBA::Boolean theCopy)
782 SMESHDS_Mesh* aMesh = GetMeshDS();
784 set<const SMDS_MeshElement*> elements;
785 for (int i = 0; i < theIDsOfElements.length(); i++)
787 CORBA::Long index = theIDsOfElements[i];
788 const SMDS_MeshElement * elem = aMesh->FindElement(index);
790 elements.insert( elem );
792 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
793 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
796 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
799 ::SMESH_MeshEditor anEditor( _myMesh );
800 anEditor.Transform (elements, aTrsf, theCopy);
803 //=======================================================================
804 //function : RotateObject
806 //=======================================================================
808 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
809 const SMESH::AxisStruct & theAxis,
810 CORBA::Double theAngle,
811 CORBA::Boolean theCopy)
813 SMESH::long_array_var anElementsId = theObject->GetIDs();
814 Rotate(anElementsId, theAxis, theAngle, theCopy);
817 //=======================================================================
818 //function : FindCoincidentNodes
820 //=======================================================================
822 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
823 SMESH::array_of_long_array_out GroupsOfNodes)
825 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
826 ::SMESH_MeshEditor anEditor( _myMesh );
827 set<const SMDS_MeshNode*> nodes; // no input nodes
828 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
830 GroupsOfNodes = new SMESH::array_of_long_array;
831 GroupsOfNodes->length( aListOfListOfNodes.size() );
832 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
833 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
835 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
836 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
837 SMESH::long_array& aGroup = GroupsOfNodes[ i ];
838 aGroup.length( aListOfNodes.size() );
839 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
840 aGroup[ j ] = (*lIt)->GetID();
844 //=======================================================================
845 //function : MergeNodes
847 //=======================================================================
849 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
851 SMESHDS_Mesh* aMesh = GetMeshDS();
853 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
854 list<const SMDS_MeshElement*> elements;
855 for (int i = 0; i < GroupsOfNodes.length(); i++)
857 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
858 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
859 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
860 for ( int j = 0; j < aNodeGroup.length(); j++ )
862 CORBA::Long index = aNodeGroup[ j ];
863 const SMDS_MeshNode * node = aMesh->FindNode(index);
865 aListOfNodes.push_back( node );
867 if ( aListOfNodes.size() < 2 )
868 aListOfListOfNodes.pop_back();
870 ::SMESH_MeshEditor anEditor( _myMesh );
871 anEditor.MergeNodes( aListOfListOfNodes );
874 //=======================================================================
875 //function : MergeEqualElements
877 //=======================================================================
879 void SMESH_MeshEditor_i::MergeEqualElements()
881 ::SMESH_MeshEditor anEditor( _myMesh );
882 anEditor.MergeEqualElements();
885 //=======================================================================
886 //function : operator
888 //=======================================================================
890 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
892 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
896 RETCASE( SEW_BORDER1_NOT_FOUND );
897 RETCASE( SEW_BORDER2_NOT_FOUND );
898 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
899 RETCASE( SEW_BAD_SIDE_NODES );
900 RETCASE( SEW_VOLUMES_TO_SPLIT );
901 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
902 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
903 RETCASE( SEW_BAD_SIDE1_NODES );
904 RETCASE( SEW_BAD_SIDE2_NODES );
906 return SMESH::SMESH_MeshEditor::SEW_OK;
909 //=======================================================================
910 //function : SewFreeBorders
912 //=======================================================================
914 SMESH::SMESH_MeshEditor::Sew_Error
915 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
916 CORBA::Long SecondNodeID1,
917 CORBA::Long LastNodeID1,
918 CORBA::Long FirstNodeID2,
919 CORBA::Long SecondNodeID2,
920 CORBA::Long LastNodeID2)
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,
950 //=======================================================================
951 //function : SewConformFreeBorders
953 //=======================================================================
955 SMESH::SMESH_MeshEditor::Sew_Error
956 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
957 CORBA::Long SecondNodeID1,
958 CORBA::Long LastNodeID1,
959 CORBA::Long FirstNodeID2,
960 CORBA::Long SecondNodeID2)
962 SMESHDS_Mesh* aMesh = GetMeshDS();
964 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
965 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
966 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
967 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
968 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
969 const SMDS_MeshNode* aSide2ThirdNode = 0;
971 if (!aBorderFirstNode ||
974 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
975 if (!aSide2FirstNode ||
977 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
979 ::SMESH_MeshEditor anEditor( _myMesh );
980 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
989 //=======================================================================
990 //function : SewBorderToSide
992 //=======================================================================
994 SMESH::SMESH_MeshEditor::Sew_Error
995 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
996 CORBA::Long SecondNodeIDOnFreeBorder,
997 CORBA::Long LastNodeIDOnFreeBorder,
998 CORBA::Long FirstNodeIDOnSide,
999 CORBA::Long LastNodeIDOnSide)
1001 SMESHDS_Mesh* aMesh = GetMeshDS();
1003 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
1004 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
1005 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
1006 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
1007 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
1008 const SMDS_MeshNode* aSide2ThirdNode = 0;
1010 if (!aBorderFirstNode ||
1011 !aBorderSecondNode||
1013 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1014 if (!aSide2FirstNode ||
1016 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
1018 ::SMESH_MeshEditor anEditor( _myMesh );
1019 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
1028 //=======================================================================
1029 //function : SewSideElements
1031 //=======================================================================
1033 SMESH::SMESH_MeshEditor::Sew_Error
1034 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
1035 const SMESH::long_array& IDsOfSide2Elements,
1036 CORBA::Long NodeID1OfSide1ToMerge,
1037 CORBA::Long NodeID1OfSide2ToMerge,
1038 CORBA::Long NodeID2OfSide1ToMerge,
1039 CORBA::Long NodeID2OfSide2ToMerge)
1041 SMESHDS_Mesh* aMesh = GetMeshDS();
1043 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
1044 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
1045 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
1046 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
1048 if (!aFirstNode1ToMerge ||
1049 !aFirstNode2ToMerge )
1050 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
1051 if (!aSecondNode1ToMerge||
1052 !aSecondNode2ToMerge)
1053 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
1055 set<const SMDS_MeshElement*> aSide1Elems, aSide2Elems;
1056 for (int i = 0; i < IDsOfSide1Elements.length(); i++)
1058 CORBA::Long index = IDsOfSide1Elements[i];
1059 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1061 aSide1Elems.insert( elem );
1063 for (int i = 0; i < IDsOfSide2Elements.length(); i++)
1065 CORBA::Long index = IDsOfSide2Elements[i];
1066 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1068 aSide2Elems.insert( elem );
1070 ::SMESH_MeshEditor anEditor( _myMesh );
1071 return convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
1074 aSecondNode1ToMerge,
1075 aSecondNode2ToMerge));