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"
39 #include "SMESH_PythonDump.hxx"
41 #include "utilities.h"
49 typedef map<const SMDS_MeshElement*,
50 list<const SMDS_MeshElement*> > TElemOfElemListMap;
53 using SMESH::TPythonDump;
55 //=============================================================================
59 //=============================================================================
61 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh* theMesh)
66 //=============================================================================
70 //=============================================================================
73 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
75 ::SMESH_MeshEditor anEditor( _myMesh );
78 for (int i = 0; i < IDsOfElements.length(); i++)
79 IdList.push_back( IDsOfElements[i] );
81 // Update Python script
82 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
84 TPythonDump() << "print 'RemoveElements: ', isDone";
87 return anEditor.Remove( IdList, false );
90 //=============================================================================
94 //=============================================================================
96 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
98 ::SMESH_MeshEditor anEditor( _myMesh );
100 for (int i = 0; i < IDsOfNodes.length(); i++)
101 IdList.push_back( IDsOfNodes[i] );
103 // Update Python script
104 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
106 TPythonDump() << "print 'RemoveNodes: ', isDone";
109 return anEditor.Remove( IdList, true );
112 //=============================================================================
116 //=============================================================================
118 CORBA::Boolean SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
120 int NbNodes = IDsOfNodes.length();
123 CORBA::Long index1 = IDsOfNodes[0];
124 CORBA::Long index2 = IDsOfNodes[1];
125 GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
127 // Update Python script
128 TPythonDump() << "isDone = " << this << ".AddEdge([ "
129 << index1 << ", " << index2 <<" ])";
132 CORBA::Long n1 = IDsOfNodes[0];
133 CORBA::Long n2 = IDsOfNodes[1];
134 CORBA::Long n12 = IDsOfNodes[2];
135 GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
136 GetMeshDS()->FindNode(n2),
137 GetMeshDS()->FindNode(n12));
138 // Update Python script
139 TPythonDump() << "isDone = " << this << ".AddEdge([ "
140 <<n1<<", "<<n2<<", "<<n12<<" ])";
145 //=============================================================================
149 //=============================================================================
151 CORBA::Boolean SMESH_MeshEditor_i::AddNode(CORBA::Double x,
152 CORBA::Double y, CORBA::Double z)
154 GetMeshDS()->AddNode(x, y, z);
156 // Update Python script
157 TPythonDump() << "isDone = " << this << ".AddNode( "
158 << x << ", " << y << ", " << z << " )";
163 //=============================================================================
167 //=============================================================================
169 CORBA::Boolean SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
171 int NbNodes = IDsOfNodes.length();
177 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
178 for (int i = 0; i < NbNodes; i++)
179 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
183 GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
185 else if (NbNodes == 4)
187 GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
189 else if (NbNodes == 6)
191 GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
194 else if (NbNodes == 8)
196 GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
197 nodes[4], nodes[5], nodes[6], nodes[7]);
200 // Update Python script
201 TPythonDump() << "isDone = " << this << ".AddFace( " << IDsOfNodes << " )";
203 TPythonDump() << "print 'AddFace: ', isDone";
209 //=============================================================================
213 //=============================================================================
214 CORBA::Boolean SMESH_MeshEditor_i::AddPolygonalFace
215 (const SMESH::long_array & IDsOfNodes)
217 int NbNodes = IDsOfNodes.length();
218 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
219 for (int i = 0; i < NbNodes; i++)
220 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
222 GetMeshDS()->AddPolygonalFace(nodes);
224 // Update Python script
225 TPythonDump() <<"isDone = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
227 TPythonDump() << "print 'AddPolygonalFace: ', isDone";
233 //=============================================================================
237 //=============================================================================
239 CORBA::Boolean SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
241 int NbNodes = IDsOfNodes.length();
242 vector< const SMDS_MeshNode*> n(NbNodes);
243 for(int i=0;i<NbNodes;i++)
244 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
246 SMDS_MeshElement* elem = 0;
249 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
250 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
251 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
252 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
253 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
254 n[6],n[7],n[8],n[9]);
256 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
257 n[7],n[8],n[9],n[10],n[11],n[12]);
259 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
260 n[9],n[10],n[11],n[12],n[13],n[14]);
262 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
263 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
264 n[15],n[16],n[17],n[18],n[19]);
267 // Update Python script
268 TPythonDump() << "isDone = " << this << ".AddVolume( " << IDsOfNodes << " )";
270 TPythonDump() << "print 'AddVolume: ', isDone";
276 //=============================================================================
278 * AddPolyhedralVolume
280 //=============================================================================
281 CORBA::Boolean SMESH_MeshEditor_i::AddPolyhedralVolume
282 (const SMESH::long_array & IDsOfNodes,
283 const SMESH::long_array & Quantities)
285 int NbNodes = IDsOfNodes.length();
286 std::vector<const SMDS_MeshNode*> n (NbNodes);
287 for (int i = 0; i < NbNodes; i++)
288 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
290 int NbFaces = Quantities.length();
291 std::vector<int> q (NbFaces);
292 for (int j = 0; j < NbFaces; j++)
293 q[j] = Quantities[j];
295 GetMeshDS()->AddPolyhedralVolume(n, q);
297 // Update Python script
298 TPythonDump() << "isDone = " << this << ".AddPolyhedralVolume( "
299 << IDsOfNodes << ", " << Quantities << " )";
301 TPythonDump() << "print 'AddPolyhedralVolume: ', isDone";
307 //=============================================================================
309 * AddPolyhedralVolumeByFaces
311 //=============================================================================
312 CORBA::Boolean SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
313 (const SMESH::long_array & IdsOfFaces)
315 int NbFaces = IdsOfFaces.length();
316 std::vector<const SMDS_MeshNode*> poly_nodes;
317 std::vector<int> quantities (NbFaces);
319 for (int i = 0; i < NbFaces; i++) {
320 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
321 quantities[i] = aFace->NbNodes();
323 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
325 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
329 GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
331 // Update Python script
332 TPythonDump() << "isDone = " << this << ".AddPolyhedralVolumeByFaces( "
333 << IdsOfFaces << " )";
335 TPythonDump() << "print 'AddPolyhedralVolume: ', isDone";
341 //=============================================================================
345 //=============================================================================
347 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
352 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
356 GetMeshDS()->MoveNode(node, x, y, z);
358 // Update Python script
359 TPythonDump() << "isDone = " << this << ".MoveNode( "
360 << NodeID << ", " << x << ", " << y << ", " << z << " )";
365 //=============================================================================
369 //=============================================================================
371 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
374 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
375 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
379 // Update Python script
380 TPythonDump() << "isDone = " << this << ".InverseDiag( "
381 << NodeID1 << ", " << NodeID2 << " )";
383 ::SMESH_MeshEditor aMeshEditor( _myMesh );
384 return aMeshEditor.InverseDiag ( n1, n2 );
387 //=============================================================================
391 //=============================================================================
393 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
396 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
397 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
401 // Update Python script
402 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
403 << NodeID1 << ", " << NodeID2 << " )";
405 ::SMESH_MeshEditor aMeshEditor( _myMesh );
406 return aMeshEditor.DeleteDiag ( n1, n2 );
409 //=============================================================================
413 //=============================================================================
415 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
417 ::SMESH_MeshEditor anEditor( _myMesh );
418 for (int i = 0; i < IDsOfElements.length(); i++)
420 CORBA::Long index = IDsOfElements[i];
421 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
423 anEditor.Reorient( elem );
425 // Update Python script
426 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
432 //=============================================================================
436 //=============================================================================
438 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
440 SMESH::long_array_var anElementsId = theObject->GetIDs();
441 CORBA::Boolean isDone = Reorient(anElementsId);
443 // Clear python line, created by Reorient()
444 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
445 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
447 // Update Python script
448 TPythonDump() << "isDone = " << this << ".ReorientObject( " << theObject << " )";
453 //=============================================================================
457 //=============================================================================
458 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
459 SMESH::NumericalFunctor_ptr Criterion,
460 CORBA::Double MaxAngle)
462 set<const SMDS_MeshElement*> faces;
463 for (int i = 0; i < IDsOfElements.length(); i++)
465 CORBA::Long index = IDsOfElements[i];
466 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
467 if ( elem && elem->GetType() == SMDSAbs_Face)
468 faces.insert( elem );
470 SMESH::NumericalFunctor_i* aNumericalFunctor =
471 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
472 SMESH::Controls::NumericalFunctorPtr aCrit;
473 if ( !aNumericalFunctor )
474 aCrit.reset( new SMESH::Controls::AspectRatio() );
476 aCrit = aNumericalFunctor->GetNumericalFunctor();
478 // Update Python script
479 TPythonDump() << "isDone = " << this << ".TriToQuad( "
480 << IDsOfElements << ", None, " << MaxAngle << " )";
482 TPythonDump() << "print 'TriToQuad: ', isDone";
485 ::SMESH_MeshEditor anEditor( _myMesh );
486 return anEditor.TriToQuad( faces, aCrit, MaxAngle );
489 //=============================================================================
493 //=============================================================================
494 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
495 SMESH::NumericalFunctor_ptr Criterion,
496 CORBA::Double MaxAngle)
498 SMESH::long_array_var anElementsId = theObject->GetIDs();
499 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
501 // Clear python line(s), created by TriToQuad()
502 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
503 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
505 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
508 // Update Python script
509 TPythonDump() << "isDone = " << this << ".TriToQuadObject("
510 << theObject << ", None, " << MaxAngle << " )";
512 TPythonDump() << "print 'TriToQuadObject: ', isDone";
518 //=============================================================================
522 //=============================================================================
523 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
524 SMESH::NumericalFunctor_ptr Criterion)
526 set<const SMDS_MeshElement*> faces;
527 for (int i = 0; i < IDsOfElements.length(); i++)
529 CORBA::Long index = IDsOfElements[i];
530 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
531 if ( elem && elem->GetType() == SMDSAbs_Face)
532 faces.insert( elem );
534 SMESH::NumericalFunctor_i* aNumericalFunctor =
535 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
536 SMESH::Controls::NumericalFunctorPtr aCrit;
537 if ( !aNumericalFunctor )
538 aCrit.reset( new SMESH::Controls::AspectRatio() );
540 aCrit = aNumericalFunctor->GetNumericalFunctor();
543 // Update Python script
544 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", None )";
546 TPythonDump() << "print 'QuadToTri: ', isDone";
549 ::SMESH_MeshEditor anEditor( _myMesh );
550 return anEditor.QuadToTri( faces, aCrit );
553 //=============================================================================
557 //=============================================================================
558 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
559 SMESH::NumericalFunctor_ptr Criterion)
561 SMESH::long_array_var anElementsId = theObject->GetIDs();
562 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
564 // Clear python line(s), created by QuadToTri()
565 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
566 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
568 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
571 // Update Python script
572 TPythonDump() << "isDone = " << this << ".QuadToTriObject(" << theObject << ", None )";
574 TPythonDump() << "print 'QuadToTriObject: ', isDone";
580 //=============================================================================
584 //=============================================================================
585 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
586 CORBA::Boolean Diag13)
588 set<const SMDS_MeshElement*> faces;
589 for (int i = 0; i < IDsOfElements.length(); i++)
591 CORBA::Long index = IDsOfElements[i];
592 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
593 if ( elem && elem->GetType() == SMDSAbs_Face)
594 faces.insert( elem );
597 // Update Python script
598 TPythonDump() << "isDone = " << this << ".SplitQuad( "
599 << IDsOfElements << ", " << Diag13 << " )";
601 TPythonDump() << "print 'SplitQuad: ', isDone";
604 ::SMESH_MeshEditor anEditor( _myMesh );
605 return anEditor.QuadToTri( faces, Diag13 );
608 //=============================================================================
612 //=============================================================================
613 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
614 CORBA::Boolean Diag13)
616 SMESH::long_array_var anElementsId = theObject->GetIDs();
617 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
619 // Clear python line(s), created by SplitQuad()
620 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
621 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
623 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
626 // Update Python script
627 TPythonDump() << "isDone = " << this << ".SplitQuadObject( "
628 << theObject << ", " << Diag13 << " )";
630 TPythonDump() << "print 'SplitQuadObject: ', isDone";
636 //=============================================================================
640 //=============================================================================
641 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
642 SMESH::NumericalFunctor_ptr Criterion)
644 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
645 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
647 SMESH::NumericalFunctor_i* aNumericalFunctor =
648 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
649 SMESH::Controls::NumericalFunctorPtr aCrit;
650 if (aNumericalFunctor)
651 aCrit = aNumericalFunctor->GetNumericalFunctor();
653 aCrit.reset(new SMESH::Controls::AspectRatio());
655 ::SMESH_MeshEditor anEditor (_myMesh);
656 return anEditor.BestSplit(quad, aCrit);
661 //=======================================================================
664 //=======================================================================
667 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
668 const SMESH::long_array & IDsOfFixedNodes,
669 CORBA::Long MaxNbOfIterations,
670 CORBA::Double MaxAspectRatio,
671 SMESH::SMESH_MeshEditor::Smooth_Method Method)
673 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
674 MaxAspectRatio, Method, false );
677 //=======================================================================
678 //function : SmoothParametric
680 //=======================================================================
683 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
684 const SMESH::long_array & IDsOfFixedNodes,
685 CORBA::Long MaxNbOfIterations,
686 CORBA::Double MaxAspectRatio,
687 SMESH::SMESH_MeshEditor::Smooth_Method Method)
689 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
690 MaxAspectRatio, Method, true );
693 //=======================================================================
694 //function : SmoothObject
696 //=======================================================================
699 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
700 const SMESH::long_array & IDsOfFixedNodes,
701 CORBA::Long MaxNbOfIterations,
702 CORBA::Double MaxAspectRatio,
703 SMESH::SMESH_MeshEditor::Smooth_Method Method)
705 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
706 MaxAspectRatio, Method, false);
709 //=======================================================================
710 //function : SmoothParametricObject
712 //=======================================================================
715 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
716 const SMESH::long_array & IDsOfFixedNodes,
717 CORBA::Long MaxNbOfIterations,
718 CORBA::Double MaxAspectRatio,
719 SMESH::SMESH_MeshEditor::Smooth_Method Method)
721 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
722 MaxAspectRatio, Method, true);
725 //=============================================================================
729 //=============================================================================
732 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
733 const SMESH::long_array & IDsOfFixedNodes,
734 CORBA::Long MaxNbOfIterations,
735 CORBA::Double MaxAspectRatio,
736 SMESH::SMESH_MeshEditor::Smooth_Method Method,
739 SMESHDS_Mesh* aMesh = GetMeshDS();
741 set<const SMDS_MeshElement*> elements;
742 for (int i = 0; i < IDsOfElements.length(); i++)
744 CORBA::Long index = IDsOfElements[i];
745 const SMDS_MeshElement * elem = aMesh->FindElement(index);
746 if ( elem && elem->GetType() == SMDSAbs_Face)
747 elements.insert( elem );
750 set<const SMDS_MeshNode*> fixedNodes;
751 for (int i = 0; i < IDsOfFixedNodes.length(); i++)
753 CORBA::Long index = IDsOfFixedNodes[i];
754 const SMDS_MeshNode * node = aMesh->FindNode(index);
756 fixedNodes.insert( node );
758 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
759 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
760 method = ::SMESH_MeshEditor::CENTROIDAL;
762 ::SMESH_MeshEditor anEditor( _myMesh );
763 anEditor.Smooth(elements, fixedNodes, method,
764 MaxNbOfIterations, MaxAspectRatio, IsParametric );
766 // Update Python script
767 TPythonDump() << "isDone = " << this << "."
768 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
769 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
770 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
771 << "SMESH.SMESH_MeshEditor."
772 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
773 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
775 TPythonDump() << "print 'Smooth: ', isDone";
781 //=============================================================================
785 //=============================================================================
788 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
789 const SMESH::long_array & IDsOfFixedNodes,
790 CORBA::Long MaxNbOfIterations,
791 CORBA::Double MaxAspectRatio,
792 SMESH::SMESH_MeshEditor::Smooth_Method Method,
795 SMESH::long_array_var anElementsId = theObject->GetIDs();
796 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
797 MaxAspectRatio, Method, IsParametric);
799 // Clear python line(s), created by Smooth()
800 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
801 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
803 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
806 // Update Python script
807 TPythonDump() << "isDone = " << this << "."
808 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
809 << theObject << ", " << IDsOfFixedNodes << ", "
810 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
811 << "SMESH.SMESH_MeshEditor."
812 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
813 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
815 TPythonDump() << "print 'SmoothObject: ', isDone";
821 //=============================================================================
825 //=============================================================================
827 void SMESH_MeshEditor_i::RenumberNodes()
829 // Update Python script
830 TPythonDump() << this << ".RenumberNodes()";
832 GetMeshDS()->Renumber( true );
835 //=============================================================================
839 //=============================================================================
841 void SMESH_MeshEditor_i::RenumberElements()
843 // Update Python script
844 TPythonDump() << this << ".RenumberElements()";
846 GetMeshDS()->Renumber( false );
849 //=======================================================================
850 //function : RotationSweep
852 //=======================================================================
854 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
855 const SMESH::AxisStruct & theAxis,
856 CORBA::Double theAngleInRadians,
857 CORBA::Long theNbOfSteps,
858 CORBA::Double theTolerance)
860 SMESHDS_Mesh* aMesh = GetMeshDS();
862 set<const SMDS_MeshElement*> elements;
863 for (int i = 0; i < theIDsOfElements.length(); i++)
865 CORBA::Long index = theIDsOfElements[i];
866 const SMDS_MeshElement * elem = aMesh->FindElement(index);
868 elements.insert( elem );
870 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
871 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
873 ::SMESH_MeshEditor anEditor( _myMesh );
874 anEditor.RotationSweep (elements, Ax1, theAngleInRadians,
875 theNbOfSteps, theTolerance);
877 // Update Python script
878 TPythonDump() << "axis = " << theAxis;
879 TPythonDump() << this << ".RotationSweep( "
882 << theAngleInRadians << ", "
883 << theNbOfSteps << ", "
884 << theTolerance << " )";
887 //=======================================================================
888 //function : RotationSweepObject
890 //=======================================================================
892 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
893 const SMESH::AxisStruct & theAxis,
894 CORBA::Double theAngleInRadians,
895 CORBA::Long theNbOfSteps,
896 CORBA::Double theTolerance)
898 SMESH::long_array_var anElementsId = theObject->GetIDs();
899 RotationSweep(anElementsId, theAxis, theAngleInRadians, theNbOfSteps, theTolerance);
901 // Clear python line, created by RotationSweep()
902 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
903 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
905 // Update Python script
906 TPythonDump() << this << ".RotationSweepObject( "
909 << theAngleInRadians << ", "
910 << theNbOfSteps << ", "
911 << theTolerance << " )";
914 //=======================================================================
915 //function : ExtrusionSweep
917 //=======================================================================
919 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
920 const SMESH::DirStruct & theStepVector,
921 CORBA::Long theNbOfSteps)
923 SMESHDS_Mesh* aMesh = GetMeshDS();
925 set<const SMDS_MeshElement*> elements;
926 for (int i = 0; i < theIDsOfElements.length(); i++)
928 CORBA::Long index = theIDsOfElements[i];
929 const SMDS_MeshElement * elem = aMesh->FindElement(index);
931 elements.insert( elem );
933 const SMESH::PointStruct * P = &theStepVector.PS;
934 gp_Vec stepVec( P->x, P->y, P->z );
936 ::SMESH_MeshEditor anEditor( _myMesh );
937 //anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
938 TElemOfElemListMap aHystory;
939 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
941 // Update Python script
942 TPythonDump() << "stepVector = " << theStepVector;
943 TPythonDump() << this << ".ExtrusionSweep( "
944 << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
948 //=======================================================================
949 //function : ExtrusionSweepObject
951 //=======================================================================
953 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
954 const SMESH::DirStruct & theStepVector,
955 CORBA::Long theNbOfSteps)
957 SMESH::long_array_var anElementsId = theObject->GetIDs();
958 ExtrusionSweep(anElementsId, theStepVector, theNbOfSteps);
960 // Clear python line, created by ExtrusionSweep()
961 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
962 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
964 // Update Python script
965 TPythonDump() << this << ".ExtrusionSweepObject( "
966 << theObject << ", stepVector, " << theNbOfSteps << " )";
969 //=======================================================================
970 //function : ExtrusionSweepObject1D
972 //=======================================================================
974 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
975 const SMESH::DirStruct & theStepVector,
976 CORBA::Long theNbOfSteps)
978 SMESHDS_Mesh* aMesh = GetMeshDS();
980 SMESH::long_array_var allElementsId = theObject->GetIDs();
982 set<const SMDS_MeshElement*> elements;
983 for (int i = 0; i < allElementsId->length(); i++)
985 CORBA::Long index = allElementsId[i];
986 const SMDS_MeshElement * elem = aMesh->FindElement(index);
987 if ( elem && elem->GetType() == SMDSAbs_Edge )
988 elements.insert( elem );
990 const SMESH::PointStruct * P = &theStepVector.PS;
991 gp_Vec stepVec( P->x, P->y, P->z );
993 ::SMESH_MeshEditor anEditor( _myMesh );
994 //anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
995 TElemOfElemListMap aHystory;
996 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
998 // Update Python script
999 TPythonDump() << "stepVector = " << theStepVector;
1000 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1001 << theObject << ", stepVector, " << theNbOfSteps << " )";
1004 //=======================================================================
1005 //function : ExtrusionSweepObject2D
1007 //=======================================================================
1009 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1010 const SMESH::DirStruct & theStepVector,
1011 CORBA::Long theNbOfSteps)
1013 SMESHDS_Mesh* aMesh = GetMeshDS();
1015 SMESH::long_array_var allElementsId = theObject->GetIDs();
1017 set<const SMDS_MeshElement*> elements;
1018 for (int i = 0; i < allElementsId->length(); i++)
1020 CORBA::Long index = allElementsId[i];
1021 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1022 if ( elem && elem->GetType() == SMDSAbs_Face )
1023 elements.insert( elem );
1025 const SMESH::PointStruct * P = &theStepVector.PS;
1026 gp_Vec stepVec( P->x, P->y, P->z );
1028 ::SMESH_MeshEditor anEditor( _myMesh );
1029 //anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
1030 TElemOfElemListMap aHystory;
1031 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
1033 // Update Python script
1034 TPythonDump() << "stepVector = " << theStepVector;
1035 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1036 << theObject << ", stepVector, " << theNbOfSteps << " )";
1040 //=======================================================================
1041 //function : AdvancedExtrusion
1043 //=======================================================================
1045 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1046 const SMESH::DirStruct & theStepVector,
1047 CORBA::Long theNbOfSteps,
1048 CORBA::Long theExtrFlags,
1049 CORBA::Double theSewTolerance)
1051 SMESHDS_Mesh* aMesh = GetMeshDS();
1053 set<const SMDS_MeshElement*> elements;
1054 for (int i = 0; i < theIDsOfElements.length(); i++)
1056 CORBA::Long index = theIDsOfElements[i];
1057 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1059 elements.insert( elem );
1061 const SMESH::PointStruct * P = &theStepVector.PS;
1062 gp_Vec stepVec( P->x, P->y, P->z );
1064 ::SMESH_MeshEditor anEditor( _myMesh );
1065 TElemOfElemListMap aHystory;
1066 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1067 theExtrFlags, theSewTolerance);
1069 // Update Python script
1070 TPythonDump() << "stepVector = " << theStepVector;
1071 TPythonDump() << this << ".AdvancedExtrusion("
1074 << theNbOfSteps << ","
1075 << theExtrFlags << ", "
1076 << theSewTolerance << " )";
1080 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1082 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1086 RETCASE( EXTR_NO_ELEMENTS );
1087 RETCASE( EXTR_PATH_NOT_EDGE );
1088 RETCASE( EXTR_BAD_PATH_SHAPE );
1089 RETCASE( EXTR_BAD_STARTING_NODE );
1090 RETCASE( EXTR_BAD_ANGLES_NUMBER );
1091 RETCASE( EXTR_CANT_GET_TANGENT );
1093 return SMESH::SMESH_MeshEditor::EXTR_OK;
1096 //=======================================================================
1097 //function : ExtrusionAlongPath
1099 //=======================================================================
1101 SMESH::SMESH_MeshEditor::Extrusion_Error
1102 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1103 SMESH::SMESH_Mesh_ptr thePathMesh,
1104 GEOM::GEOM_Object_ptr thePathShape,
1105 CORBA::Long theNodeStart,
1106 CORBA::Boolean theHasAngles,
1107 const SMESH::double_array & theAngles,
1108 CORBA::Boolean theHasRefPoint,
1109 const SMESH::PointStruct & theRefPoint)
1111 SMESHDS_Mesh* aMesh = GetMeshDS();
1113 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() )
1114 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1116 SMESH_Mesh_i* aMeshImp = dynamic_cast<SMESH_Mesh_i*>( SMESH_Gen_i::GetServant( thePathMesh ).in() );
1117 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1118 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1121 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1123 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
1125 return SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
1127 set<const SMDS_MeshElement*> elements;
1128 for (int i = 0; i < theIDsOfElements.length(); i++)
1130 CORBA::Long index = theIDsOfElements[i];
1131 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1133 elements.insert( elem );
1136 list<double> angles;
1137 for (int i = 0; i < theAngles.length(); i++)
1139 angles.push_back( theAngles[i] );
1142 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
1144 // Update Python script
1145 TPythonDump() << "refPoint = SMESH.PointStruct( "
1146 << refPnt.X() << ", "
1147 << refPnt.Y() << ", "
1148 << refPnt.Z() << " )";
1149 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
1150 << theIDsOfElements << ", "
1151 << thePathMesh << ", "
1152 << thePathShape << ", "
1153 << theNodeStart << ", "
1154 << theHasAngles << ", "
1155 << theAngles << ", "
1156 << theHasRefPoint << ", refPoint )";
1158 ::SMESH_MeshEditor anEditor( _myMesh );
1159 return convExtrError( anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
1160 theHasAngles, angles,
1161 theHasRefPoint, refPnt ) );
1164 //=======================================================================
1165 //function : ExtrusionAlongPathObject
1167 //=======================================================================
1169 SMESH::SMESH_MeshEditor::Extrusion_Error
1170 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
1171 SMESH::SMESH_Mesh_ptr thePathMesh,
1172 GEOM::GEOM_Object_ptr thePathShape,
1173 CORBA::Long theNodeStart,
1174 CORBA::Boolean theHasAngles,
1175 const SMESH::double_array & theAngles,
1176 CORBA::Boolean theHasRefPoint,
1177 const SMESH::PointStruct & theRefPoint)
1179 SMESH::long_array_var anElementsId = theObject->GetIDs();
1180 SMESH::SMESH_MeshEditor::Extrusion_Error error = ExtrusionAlongPath
1181 (anElementsId, thePathMesh, thePathShape, theNodeStart,
1182 theHasAngles, theAngles, theHasRefPoint, theRefPoint);
1184 // Clear python line, created by ExtrusionAlongPath()
1185 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1186 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1188 // Update Python script
1189 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
1190 << theObject << ", "
1191 << thePathMesh << ", "
1192 << thePathShape << ", "
1193 << theNodeStart << ", "
1194 << theHasAngles << ", "
1195 << theAngles << ", "
1196 << theHasRefPoint << ", refPoint )";
1201 //=======================================================================
1204 //=======================================================================
1206 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
1207 const SMESH::AxisStruct & theAxis,
1208 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
1209 CORBA::Boolean theCopy)
1211 SMESHDS_Mesh* aMesh = GetMeshDS();
1213 set<const SMDS_MeshElement*> elements;
1214 for (int i = 0; i < theIDsOfElements.length(); i++)
1216 CORBA::Long index = theIDsOfElements[i];
1217 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1219 elements.insert( elem );
1221 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
1222 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
1225 TCollection_AsciiString typeStr;
1226 switch ( theMirrorType ) {
1227 case SMESH::SMESH_MeshEditor::POINT:
1228 aTrsf.SetMirror( P );
1229 typeStr = "SMESH.SMESH_MeshEditor.POINT";
1231 case SMESH::SMESH_MeshEditor::AXIS:
1232 aTrsf.SetMirror( gp_Ax1( P, V ));
1233 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
1236 aTrsf.SetMirror( gp_Ax2( P, V ));
1237 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
1240 // Update Python script
1241 TPythonDump() << this << ".Mirror( "
1242 << theIDsOfElements << ", "
1247 ::SMESH_MeshEditor anEditor( _myMesh );
1248 anEditor.Transform (elements, aTrsf, theCopy);
1251 //=======================================================================
1252 //function : MirrorObject
1254 //=======================================================================
1256 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
1257 const SMESH::AxisStruct & theAxis,
1258 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
1259 CORBA::Boolean theCopy)
1261 SMESH::long_array_var anElementsId = theObject->GetIDs();
1262 Mirror(anElementsId, theAxis, theMirrorType, theCopy);
1264 // Clear python line, created by Mirror()
1265 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1266 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1268 // Update Python script
1269 TCollection_AsciiString typeStr;
1270 switch ( theMirrorType ) {
1271 case SMESH::SMESH_MeshEditor::POINT:
1272 typeStr = "SMESH.SMESH_MeshEditor.POINT";
1274 case SMESH::SMESH_MeshEditor::AXIS:
1275 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
1278 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
1280 TPythonDump() << "axis = " << theAxis;
1281 TPythonDump() << this << ".MirrorObject( "
1282 << theObject << ", "
1288 //=======================================================================
1289 //function : Translate
1291 //=======================================================================
1293 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
1294 const SMESH::DirStruct & theVector,
1295 CORBA::Boolean theCopy)
1297 SMESHDS_Mesh* aMesh = GetMeshDS();
1299 set<const SMDS_MeshElement*> elements;
1300 for (int i = 0; i < theIDsOfElements.length(); i++)
1302 CORBA::Long index = theIDsOfElements[i];
1303 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1305 elements.insert( elem );
1308 const SMESH::PointStruct * P = &theVector.PS;
1309 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
1311 ::SMESH_MeshEditor anEditor( _myMesh );
1312 anEditor.Transform (elements, aTrsf, theCopy);
1314 // Update Python script
1315 TPythonDump() << "vector = " << theVector;
1316 TPythonDump() << this << ".Translate( "
1322 //=======================================================================
1323 //function : TranslateObject
1325 //=======================================================================
1327 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
1328 const SMESH::DirStruct & theVector,
1329 CORBA::Boolean theCopy)
1331 SMESH::long_array_var anElementsId = theObject->GetIDs();
1332 Translate(anElementsId, theVector, theCopy);
1334 // Clear python line, created by Translate()
1335 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1336 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1338 // Update Python script
1339 TPythonDump() << this << ".TranslateObject( "
1345 //=======================================================================
1348 //=======================================================================
1350 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
1351 const SMESH::AxisStruct & theAxis,
1352 CORBA::Double theAngle,
1353 CORBA::Boolean theCopy)
1355 SMESHDS_Mesh* aMesh = GetMeshDS();
1357 set<const SMDS_MeshElement*> elements;
1358 for (int i = 0; i < theIDsOfElements.length(); i++)
1360 CORBA::Long index = theIDsOfElements[i];
1361 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1363 elements.insert( elem );
1365 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
1366 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
1369 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
1371 ::SMESH_MeshEditor anEditor( _myMesh );
1372 anEditor.Transform (elements, aTrsf, theCopy);
1374 // Update Python script
1375 TPythonDump() << "axis = " << theAxis;
1376 TPythonDump() << this << ".Rotate( "
1383 //=======================================================================
1384 //function : RotateObject
1386 //=======================================================================
1388 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
1389 const SMESH::AxisStruct & theAxis,
1390 CORBA::Double theAngle,
1391 CORBA::Boolean theCopy)
1393 SMESH::long_array_var anElementsId = theObject->GetIDs();
1394 Rotate(anElementsId, theAxis, theAngle, theCopy);
1396 // Clear python line, created by Rotate()
1397 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1398 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1400 // Update Python script
1401 TPythonDump() << this << ".RotateObject( "
1408 //=======================================================================
1409 //function : FindCoincidentNodes
1411 //=======================================================================
1413 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
1414 SMESH::array_of_long_array_out GroupsOfNodes)
1416 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
1417 ::SMESH_MeshEditor anEditor( _myMesh );
1418 set<const SMDS_MeshNode*> nodes; // no input nodes
1419 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
1421 GroupsOfNodes = new SMESH::array_of_long_array;
1422 GroupsOfNodes->length( aListOfListOfNodes.size() );
1423 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
1424 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
1426 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
1427 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
1428 SMESH::long_array& aGroup = GroupsOfNodes[ i ];
1429 aGroup.length( aListOfNodes.size() );
1430 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
1431 aGroup[ j ] = (*lIt)->GetID();
1433 // Update Python script
1434 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
1435 << Tolerance << " )";
1438 //=======================================================================
1439 //function : MergeNodes
1441 //=======================================================================
1443 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
1445 SMESHDS_Mesh* aMesh = GetMeshDS();
1447 TPythonDump aTPythonDump;
1448 aTPythonDump << this << ".MergeNodes([";
1449 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
1450 for (int i = 0; i < GroupsOfNodes.length(); i++)
1452 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
1453 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
1454 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
1455 for ( int j = 0; j < aNodeGroup.length(); j++ )
1457 CORBA::Long index = aNodeGroup[ j ];
1458 const SMDS_MeshNode * node = aMesh->FindNode(index);
1460 aListOfNodes.push_back( node );
1462 if ( aListOfNodes.size() < 2 )
1463 aListOfListOfNodes.pop_back();
1465 if ( i > 0 ) aTPythonDump << ", ";
1466 aTPythonDump << aNodeGroup;
1468 ::SMESH_MeshEditor anEditor( _myMesh );
1469 anEditor.MergeNodes( aListOfListOfNodes );
1471 // Update Python script
1472 aTPythonDump << "])";
1475 //=======================================================================
1476 //function : MergeEqualElements
1478 //=======================================================================
1480 void SMESH_MeshEditor_i::MergeEqualElements()
1482 ::SMESH_MeshEditor anEditor( _myMesh );
1483 anEditor.MergeEqualElements();
1485 // Update Python script
1486 TPythonDump() << this << ".MergeEqualElements()";
1489 //=======================================================================
1490 //function : operator
1492 //=======================================================================
1494 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1496 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
1500 RETCASE( SEW_BORDER1_NOT_FOUND );
1501 RETCASE( SEW_BORDER2_NOT_FOUND );
1502 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
1503 RETCASE( SEW_BAD_SIDE_NODES );
1504 RETCASE( SEW_VOLUMES_TO_SPLIT );
1505 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
1506 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
1507 RETCASE( SEW_BAD_SIDE1_NODES );
1508 RETCASE( SEW_BAD_SIDE2_NODES );
1510 return SMESH::SMESH_MeshEditor::SEW_OK;
1513 //=======================================================================
1514 //function : SewFreeBorders
1516 //=======================================================================
1518 SMESH::SMESH_MeshEditor::Sew_Error
1519 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
1520 CORBA::Long SecondNodeID1,
1521 CORBA::Long LastNodeID1,
1522 CORBA::Long FirstNodeID2,
1523 CORBA::Long SecondNodeID2,
1524 CORBA::Long LastNodeID2,
1525 CORBA::Boolean CreatePolygons,
1526 CORBA::Boolean CreatePolyedrs)
1528 SMESHDS_Mesh* aMesh = GetMeshDS();
1530 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
1531 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
1532 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
1533 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
1534 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
1535 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
1537 if (!aBorderFirstNode ||
1538 !aBorderSecondNode||
1540 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1541 if (!aSide2FirstNode ||
1542 !aSide2SecondNode ||
1544 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
1546 // Update Python script
1547 TPythonDump() << "error = " << this << ".SewFreeBorders( "
1548 << FirstNodeID1 << ", "
1549 << SecondNodeID1 << ", "
1550 << LastNodeID1 << ", "
1551 << FirstNodeID2 << ", "
1552 << SecondNodeID2 << ", "
1553 << LastNodeID2 << ", "
1554 << CreatePolygons<< ", "
1555 << CreatePolyedrs<< " )";
1557 ::SMESH_MeshEditor anEditor( _myMesh );
1558 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
1569 //=======================================================================
1570 //function : SewConformFreeBorders
1572 //=======================================================================
1574 SMESH::SMESH_MeshEditor::Sew_Error
1575 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
1576 CORBA::Long SecondNodeID1,
1577 CORBA::Long LastNodeID1,
1578 CORBA::Long FirstNodeID2,
1579 CORBA::Long SecondNodeID2)
1581 SMESHDS_Mesh* aMesh = GetMeshDS();
1583 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
1584 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
1585 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
1586 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
1587 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
1588 const SMDS_MeshNode* aSide2ThirdNode = 0;
1590 if (!aBorderFirstNode ||
1591 !aBorderSecondNode||
1593 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1594 if (!aSide2FirstNode ||
1596 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
1598 // Update Python script
1599 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
1600 << FirstNodeID1 << ", "
1601 << SecondNodeID1 << ", "
1602 << LastNodeID1 << ", "
1603 << FirstNodeID2 << ", "
1604 << SecondNodeID2 << " )";
1606 ::SMESH_MeshEditor anEditor( _myMesh );
1607 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
1617 //=======================================================================
1618 //function : SewBorderToSide
1620 //=======================================================================
1622 SMESH::SMESH_MeshEditor::Sew_Error
1623 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
1624 CORBA::Long SecondNodeIDOnFreeBorder,
1625 CORBA::Long LastNodeIDOnFreeBorder,
1626 CORBA::Long FirstNodeIDOnSide,
1627 CORBA::Long LastNodeIDOnSide,
1628 CORBA::Boolean CreatePolygons,
1629 CORBA::Boolean CreatePolyedrs)
1631 SMESHDS_Mesh* aMesh = GetMeshDS();
1633 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
1634 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
1635 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
1636 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
1637 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
1638 const SMDS_MeshNode* aSide2ThirdNode = 0;
1640 if (!aBorderFirstNode ||
1641 !aBorderSecondNode||
1643 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1644 if (!aSide2FirstNode ||
1646 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
1648 // Update Python script
1649 TPythonDump() << "error = " << this << ".SewBorderToSide( "
1650 << FirstNodeIDOnFreeBorder << ", "
1651 << SecondNodeIDOnFreeBorder << ", "
1652 << LastNodeIDOnFreeBorder << ", "
1653 << FirstNodeIDOnSide << ", "
1654 << LastNodeIDOnSide << ", "
1655 << CreatePolygons << ", "
1656 << CreatePolyedrs << ") ";
1658 ::SMESH_MeshEditor anEditor( _myMesh );
1659 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
1670 //=======================================================================
1671 //function : SewSideElements
1673 //=======================================================================
1675 SMESH::SMESH_MeshEditor::Sew_Error
1676 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
1677 const SMESH::long_array& IDsOfSide2Elements,
1678 CORBA::Long NodeID1OfSide1ToMerge,
1679 CORBA::Long NodeID1OfSide2ToMerge,
1680 CORBA::Long NodeID2OfSide1ToMerge,
1681 CORBA::Long NodeID2OfSide2ToMerge)
1683 SMESHDS_Mesh* aMesh = GetMeshDS();
1685 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
1686 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
1687 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
1688 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
1690 if (!aFirstNode1ToMerge ||
1691 !aFirstNode2ToMerge )
1692 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
1693 if (!aSecondNode1ToMerge||
1694 !aSecondNode2ToMerge)
1695 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
1697 set<const SMDS_MeshElement*> aSide1Elems, aSide2Elems;
1698 for (int i = 0; i < IDsOfSide1Elements.length(); i++)
1700 CORBA::Long index = IDsOfSide1Elements[i];
1701 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1703 aSide1Elems.insert( elem );
1705 for (int i = 0; i < IDsOfSide2Elements.length(); i++)
1707 CORBA::Long index = IDsOfSide2Elements[i];
1708 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1710 aSide2Elems.insert( elem );
1712 // Update Python script
1713 TPythonDump() << "error = " << this << ".SewSideElements( "
1714 << IDsOfSide1Elements << ", "
1715 << IDsOfSide2Elements << ", "
1716 << NodeID1OfSide1ToMerge << ", "
1717 << NodeID1OfSide2ToMerge << ", "
1718 << NodeID2OfSide1ToMerge << ", "
1719 << NodeID2OfSide2ToMerge << ")";
1721 ::SMESH_MeshEditor anEditor( _myMesh );
1722 return convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
1725 aSecondNode1ToMerge,
1726 aSecondNode2ToMerge));