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"
50 //=======================================================================
53 //=======================================================================
55 static TCollection_AsciiString& addAxis(TCollection_AsciiString& theStr,
56 const SMESH::AxisStruct & theAxis)
58 theStr += "SMESH.AxisStruct( ";
59 theStr += TCollection_AsciiString( theAxis.x ) + ", ";
60 theStr += TCollection_AsciiString( theAxis.y ) + ", ";
61 theStr += TCollection_AsciiString( theAxis.z ) + ", ";
62 theStr += TCollection_AsciiString( theAxis.vx ) + ", ";
63 theStr += TCollection_AsciiString( theAxis.vy ) + ", ";
64 theStr += TCollection_AsciiString( theAxis.vz ) + " )";
68 //=============================================================================
72 //=============================================================================
74 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh* theMesh)
79 //=============================================================================
83 //=============================================================================
86 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
88 ::SMESH_MeshEditor anEditor( _myMesh );
91 for (int i = 0; i < IDsOfElements.length(); i++)
92 IdList.push_back( IDsOfElements[i] );
94 // Update Python script
95 TCollection_AsciiString str ("isDone = mesh_editor.RemoveElements(");
96 SMESH_Gen_i::AddArray( str, IDsOfElements ) += ")";
97 SMESH_Gen_i::AddToCurrentPyScript( str );
99 SMESH_Gen_i::AddToCurrentPyScript( "print \"RemoveElements: \", isDone" );
102 return anEditor.Remove( IdList, false );
105 //=============================================================================
109 //=============================================================================
111 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::
112 long_array & IDsOfNodes)
114 ::SMESH_MeshEditor anEditor( _myMesh );
116 for (int i = 0; i < IDsOfNodes.length(); i++)
117 IdList.push_back( IDsOfNodes[i] );
119 // Update Python script
120 TCollection_AsciiString str ("isDone = mesh_editor.RemoveNodes(");
121 SMESH_Gen_i::AddArray( str, IDsOfNodes ) += ")";
122 SMESH_Gen_i::AddToCurrentPyScript( str );
124 SMESH_Gen_i::AddToCurrentPyScript( "print \"RemoveNodes: \", isDone" );
127 return anEditor.Remove( IdList, true );
130 //=============================================================================
134 //=============================================================================
136 CORBA::Boolean SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
138 int NbNodes = IDsOfNodes.length();
141 CORBA::Long index1 = IDsOfNodes[0];
142 CORBA::Long index2 = IDsOfNodes[1];
143 GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
145 // Update Python script
146 TCollection_AsciiString str ("isDone = mesh_editor.AddEdge([");
147 str += TCollection_AsciiString((int) index1) + ", ";
148 str += TCollection_AsciiString((int) index2) + " ])";
149 SMESH_Gen_i::AddToCurrentPyScript( str );
154 //=============================================================================
158 //=============================================================================
160 CORBA::Boolean SMESH_MeshEditor_i::AddNode(CORBA::Double x,
161 CORBA::Double y, CORBA::Double z)
163 GetMeshDS()->AddNode(x, y, z);
165 // Update Python script
166 TCollection_AsciiString str ("isDone = mesh_editor.AddNode(");
167 str += TCollection_AsciiString( x ) + ", ";
168 str += TCollection_AsciiString( y ) + ", ";
169 str += TCollection_AsciiString( z ) + " )";
170 SMESH_Gen_i::AddToCurrentPyScript( str );
175 //=============================================================================
179 //=============================================================================
181 CORBA::Boolean SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
183 int NbNodes = IDsOfNodes.length();
189 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
190 for (int i = 0; i < NbNodes; i++)
191 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
195 GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
197 else if (NbNodes == 4)
199 GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
203 GetMeshDS()->AddPolygonalFace(nodes);
206 // Update Python script
207 TCollection_AsciiString str ("isDone = mesh_editor.AddFace(");
208 SMESH_Gen_i::AddArray( str, IDsOfNodes ) += ")";
209 SMESH_Gen_i::AddToCurrentPyScript( str );
211 SMESH_Gen_i::AddToCurrentPyScript( "print \"AddFace: \", isDone" );
217 //=============================================================================
221 //=============================================================================
223 CORBA::Boolean SMESH_MeshEditor_i::AddVolume(const SMESH::
224 long_array & IDsOfNodes)
226 int NbNodes = IDsOfNodes.length();
227 vector< const SMDS_MeshNode*> n(NbNodes);
228 for(int i=0;i<NbNodes;i++)
229 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
233 case 4:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
234 case 5:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
235 case 6:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
236 case 8:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
238 // Update Python script
239 TCollection_AsciiString str ("isDone = mesh_editor.AddVolume(");
240 SMESH_Gen_i::AddArray( str, IDsOfNodes ) += ")";
241 SMESH_Gen_i::AddToCurrentPyScript( str );
243 SMESH_Gen_i::AddToCurrentPyScript( "print \"AddVolume: \", isDone" );
249 //=============================================================================
251 * AddPolyhedralVolume
253 //=============================================================================
254 CORBA::Boolean SMESH_MeshEditor_i::AddPolyhedralVolume
255 (const SMESH::long_array & IDsOfNodes,
256 const SMESH::long_array & Quantities)
258 int NbNodes = IDsOfNodes.length();
259 std::vector<const SMDS_MeshNode*> n (NbNodes);
260 for (int i = 0; i < NbNodes; i++)
261 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
263 int NbFaces = Quantities.length();
264 std::vector<int> q (NbFaces);
265 for (int j = 0; j < NbFaces; j++)
266 q[j] = Quantities[j];
268 GetMeshDS()->AddPolyhedralVolume(n, q);
270 // Update Python script
271 TCollection_AsciiString str ("isDone = mesh_editor.AddPolyhedralVolume(");
272 SMESH_Gen_i::AddArray( str, IDsOfNodes ) += ", ";
273 SMESH_Gen_i::AddArray( str, Quantities ) += ")";
274 SMESH_Gen_i::AddToCurrentPyScript( str );
276 SMESH_Gen_i::AddToCurrentPyScript( "print \"AddPolyhedralVolume: \", isDone" );
282 //=============================================================================
284 * AddPolyhedralVolumeByFaces
286 //=============================================================================
287 CORBA::Boolean SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
288 (const SMESH::long_array & IdsOfFaces)
290 int NbFaces = IdsOfFaces.length();
291 std::vector<const SMDS_MeshNode*> poly_nodes;
292 std::vector<int> quantities (NbFaces);
294 for (int i = 0; i < NbFaces; i++) {
295 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
296 quantities[i] = aFace->NbNodes();
298 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
300 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
304 GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
306 // Update Python script
307 TCollection_AsciiString str ("isDone = mesh_editor.AddPolyhedralVolumeByFaces(");
308 SMESH_Gen_i::AddArray( str, IdsOfFaces ) += ")";
309 SMESH_Gen_i::AddToCurrentPyScript( str );
311 SMESH_Gen_i::AddToCurrentPyScript( "print \"AddPolyhedralVolume: \", isDone" );
317 //=============================================================================
321 //=============================================================================
323 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
328 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
332 GetMeshDS()->MoveNode(node, x, y, z);
334 // Update Python script
335 TCollection_AsciiString str ("isDone = mesh_editor.MoveNode(");
336 str += TCollection_AsciiString((Standard_Integer) NodeID) + ", ";
337 str += TCollection_AsciiString((Standard_Real) x) + ", ";
338 str += TCollection_AsciiString((Standard_Real) y) + ", ";
339 str += TCollection_AsciiString((Standard_Real) z) + " )";
340 SMESH_Gen_i::AddToCurrentPyScript( str );
345 //=============================================================================
349 //=============================================================================
351 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
354 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
355 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
359 // Update Python script
360 TCollection_AsciiString str ("isDone = mesh_editor.InverseDiag(");
361 str += TCollection_AsciiString((Standard_Integer) NodeID1) + ", ";
362 str += TCollection_AsciiString((Standard_Integer) NodeID2) + " )";
363 SMESH_Gen_i::AddToCurrentPyScript( str );
365 ::SMESH_MeshEditor aMeshEditor( _myMesh );
366 return aMeshEditor.InverseDiag ( n1, n2 );
369 //=============================================================================
373 //=============================================================================
375 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
378 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
379 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
383 // Update Python script
384 TCollection_AsciiString str ("isDone = mesh_editor.DeleteDiag(");
385 str += TCollection_AsciiString((Standard_Integer) NodeID1) + ", ";
386 str += TCollection_AsciiString((Standard_Integer) NodeID2) + " )";
387 SMESH_Gen_i::AddToCurrentPyScript( str );
389 ::SMESH_MeshEditor aMeshEditor( _myMesh );
390 return aMeshEditor.DeleteDiag ( n1, n2 );
393 //=============================================================================
397 //=============================================================================
399 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
401 ::SMESH_MeshEditor anEditor( _myMesh );
402 for (int i = 0; i < IDsOfElements.length(); i++)
404 CORBA::Long index = IDsOfElements[i];
405 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
407 anEditor.Reorient( elem );
409 // Update Python script
410 TCollection_AsciiString str ("isDone = mesh_editor.Reorient(");
411 SMESH_Gen_i::AddArray( str, IDsOfElements ) += ")";
412 SMESH_Gen_i::AddToCurrentPyScript( str );
418 //=============================================================================
422 //=============================================================================
424 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
426 SMESH::long_array_var anElementsId = theObject->GetIDs();
427 CORBA::Boolean isDone = Reorient(anElementsId);
429 // Clear python line, created by Reorient()
430 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
431 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
433 // Update Python script
434 TCollection_AsciiString str ("isDone = mesh_editor.ReorientObject(");
435 SMESH_Gen_i::AddObject( str, theObject ) += ")";
436 SMESH_Gen_i::AddToCurrentPyScript( str );
441 //=============================================================================
445 //=============================================================================
448 SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
449 SMESH::NumericalFunctor_ptr Criterion,
450 CORBA::Double MaxAngle)
452 set<const SMDS_MeshElement*> faces;
453 for (int i = 0; i < IDsOfElements.length(); i++)
455 CORBA::Long index = IDsOfElements[i];
456 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
457 if ( elem && elem->GetType() == SMDSAbs_Face)
458 faces.insert( elem );
460 SMESH::NumericalFunctor_i* aNumericalFunctor =
461 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
462 SMESH::Controls::NumericalFunctorPtr aCrit;
463 if ( !aNumericalFunctor )
464 aCrit.reset( new SMESH::Controls::AspectRatio() );
466 aCrit = aNumericalFunctor->GetNumericalFunctor();
468 // Update Python script
469 TCollection_AsciiString str ("isDone = mesh_editor.TriToQuad(");
470 SMESH_Gen_i::AddArray( str, IDsOfElements ) += ", None, ";
471 str += (Standard_Real) MaxAngle;
472 SMESH_Gen_i::AddToCurrentPyScript( str + ")" );
474 SMESH_Gen_i::AddToCurrentPyScript( "print \"TriToQuad: \", isDone" );
477 ::SMESH_MeshEditor anEditor( _myMesh );
478 return anEditor.TriToQuad( faces, aCrit, MaxAngle );
481 //=============================================================================
485 //=============================================================================
488 SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
489 SMESH::NumericalFunctor_ptr Criterion,
490 CORBA::Double MaxAngle)
492 SMESH::long_array_var anElementsId = theObject->GetIDs();
493 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
495 // Clear python line(s), created by TriToQuad()
496 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
497 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
499 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
502 // Update Python script
503 TCollection_AsciiString str ("isDone = mesh_editor.TriToQuadObject(");
504 SMESH_Gen_i::AddObject( str, theObject ) += ", None, ";
505 str += (Standard_Real) MaxAngle;
506 SMESH_Gen_i::AddToCurrentPyScript( str + ")" );
508 SMESH_Gen_i::AddToCurrentPyScript( "print \"TriToQuadObject: \", isDone" );
514 //=============================================================================
518 //=============================================================================
521 SMESH_MeshEditor_i::QuadToTri(const SMESH::long_array & IDsOfElements,
522 SMESH::NumericalFunctor_ptr Criterion)
524 set<const SMDS_MeshElement*> faces;
525 for (int i = 0; i < IDsOfElements.length(); i++)
527 CORBA::Long index = IDsOfElements[i];
528 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
529 if ( elem && elem->GetType() == SMDSAbs_Face)
530 faces.insert( elem );
532 SMESH::NumericalFunctor_i* aNumericalFunctor =
533 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
534 SMESH::Controls::NumericalFunctorPtr aCrit;
535 if ( !aNumericalFunctor )
536 aCrit.reset( new SMESH::Controls::AspectRatio() );
538 aCrit = aNumericalFunctor->GetNumericalFunctor();
541 // Update Python script
542 TCollection_AsciiString str ("isDone = mesh_editor.QuadToTri(");
543 SMESH_Gen_i::AddArray( str, IDsOfElements ) += ", None ), ";
544 SMESH_Gen_i::AddToCurrentPyScript( str );
546 SMESH_Gen_i::AddToCurrentPyScript( "print \"QuadToTri: \", isDone" );
549 ::SMESH_MeshEditor anEditor( _myMesh );
550 return anEditor.QuadToTri( faces, aCrit );
553 //=============================================================================
557 //=============================================================================
560 SMESH_MeshEditor_i::SplitQuad(const SMESH::long_array & IDsOfElements,
561 CORBA::Boolean Diag13)
563 set<const SMDS_MeshElement*> faces;
564 for (int i = 0; i < IDsOfElements.length(); i++)
566 CORBA::Long index = IDsOfElements[i];
567 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
568 if ( elem && elem->GetType() == SMDSAbs_Face)
569 faces.insert( elem );
572 // Update Python script
573 TCollection_AsciiString str ("isDone = mesh_editor.SplitQuad(");
574 SMESH_Gen_i::AddArray( str, IDsOfElements ) += ", ";
575 str += TCollection_AsciiString( Diag13 );
576 SMESH_Gen_i::AddToCurrentPyScript( str + ")" );
578 SMESH_Gen_i::AddToCurrentPyScript( "print \"SplitQuad: \", isDone" );
581 ::SMESH_MeshEditor anEditor( _myMesh );
582 return anEditor.QuadToTri( faces, Diag13 );
585 //=============================================================================
589 //=============================================================================
592 SMESH_MeshEditor_i::SplitQuadObject(SMESH::SMESH_IDSource_ptr theObject,
593 CORBA::Boolean Diag13)
595 SMESH::long_array_var anElementsId = theObject->GetIDs();
596 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
598 // Clear python line(s), created by SplitQuad()
599 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
600 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
602 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
605 // Update Python script
606 TCollection_AsciiString str ("isDone = mesh_editor.SplitQuadObject(");
607 SMESH_Gen_i::AddObject( str, theObject ) += ", ";
608 str += TCollection_AsciiString( Diag13 ) + ")";
609 SMESH_Gen_i::AddToCurrentPyScript( str );
611 SMESH_Gen_i::AddToCurrentPyScript( "print \"SplitQuadObject: \", isDone" );
617 //=======================================================================
620 //=======================================================================
623 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
624 const SMESH::long_array & IDsOfFixedNodes,
625 CORBA::Long MaxNbOfIterations,
626 CORBA::Double MaxAspectRatio,
627 SMESH::SMESH_MeshEditor::Smooth_Method Method)
629 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
630 MaxAspectRatio, Method, false );
633 //=======================================================================
634 //function : SmoothParametric
636 //=======================================================================
639 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
640 const SMESH::long_array & IDsOfFixedNodes,
641 CORBA::Long MaxNbOfIterations,
642 CORBA::Double MaxAspectRatio,
643 SMESH::SMESH_MeshEditor::Smooth_Method Method)
645 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
646 MaxAspectRatio, Method, true );
649 //=======================================================================
650 //function : SmoothObject
652 //=======================================================================
655 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
656 const SMESH::long_array & IDsOfFixedNodes,
657 CORBA::Long MaxNbOfIterations,
658 CORBA::Double MaxAspectRatio,
659 SMESH::SMESH_MeshEditor::Smooth_Method Method)
661 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
662 MaxAspectRatio, Method, false);
665 //=======================================================================
666 //function : SmoothParametricObject
668 //=======================================================================
671 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
672 const SMESH::long_array & IDsOfFixedNodes,
673 CORBA::Long MaxNbOfIterations,
674 CORBA::Double MaxAspectRatio,
675 SMESH::SMESH_MeshEditor::Smooth_Method Method)
677 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
678 MaxAspectRatio, Method, true);
681 //=============================================================================
685 //=============================================================================
688 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
689 const SMESH::long_array & IDsOfFixedNodes,
690 CORBA::Long MaxNbOfIterations,
691 CORBA::Double MaxAspectRatio,
692 SMESH::SMESH_MeshEditor::Smooth_Method Method,
695 SMESHDS_Mesh* aMesh = GetMeshDS();
697 set<const SMDS_MeshElement*> elements;
698 for (int i = 0; i < IDsOfElements.length(); i++)
700 CORBA::Long index = IDsOfElements[i];
701 const SMDS_MeshElement * elem = aMesh->FindElement(index);
702 if ( elem && elem->GetType() == SMDSAbs_Face)
703 elements.insert( elem );
706 set<const SMDS_MeshNode*> fixedNodes;
707 for (int i = 0; i < IDsOfFixedNodes.length(); i++)
709 CORBA::Long index = IDsOfFixedNodes[i];
710 const SMDS_MeshNode * node = aMesh->FindNode(index);
712 fixedNodes.insert( node );
714 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
715 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
716 method = ::SMESH_MeshEditor::CENTROIDAL;
718 ::SMESH_MeshEditor anEditor( _myMesh );
719 anEditor.Smooth(elements, fixedNodes, method,
720 MaxNbOfIterations, MaxAspectRatio, IsParametric );
722 // Update Python script
723 TCollection_AsciiString str ("isDone = mesh_editor.");
724 str += (char*) (IsParametric ? "SmoothParametric( " : "Smooth( ");
725 SMESH_Gen_i::AddArray( str, IDsOfElements ) += ", ";
726 SMESH_Gen_i::AddArray( str, IDsOfFixedNodes ) += ", ";
727 str += (Standard_Integer) MaxNbOfIterations;
729 str += (Standard_Real) MaxAspectRatio;
730 if ( method == ::SMESH_MeshEditor::CENTROIDAL )
731 str += ", SMESH.SMESH_MeshEditor.CENTROIDAL_SMOOTH, ";
733 str += ", SMESH.SMESH_MeshEditor.LAPLACIAN_SMOOTH, ";
736 SMESH_Gen_i::AddToCurrentPyScript( str );
738 SMESH_Gen_i::AddToCurrentPyScript( "print \"Smooth: \", isDone" );
744 //=============================================================================
748 //=============================================================================
751 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
752 const SMESH::long_array & IDsOfFixedNodes,
753 CORBA::Long MaxNbOfIterations,
754 CORBA::Double MaxAspectRatio,
755 SMESH::SMESH_MeshEditor::Smooth_Method Method,
758 SMESH::long_array_var anElementsId = theObject->GetIDs();
759 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
760 MaxAspectRatio, Method, IsParametric);
762 // Clear python line(s), created by Smooth()
763 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
764 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
766 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
769 // Update Python script
770 TCollection_AsciiString str ("isDone = mesh_editor.");
771 str += (char*) (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ");
772 SMESH_Gen_i::AddObject( str, theObject ) += ", ";
773 SMESH_Gen_i::AddArray( str, IDsOfFixedNodes ) += ", ";
774 str += (Standard_Integer) MaxNbOfIterations;
776 str += (Standard_Real) MaxAspectRatio;
777 if ( Method == ::SMESH_MeshEditor::CENTROIDAL )
778 str += ", SMESH.SMESH_MeshEditor.CENTROIDAL_SMOOTH, ";
780 str += ", SMESH.SMESH_MeshEditor.LAPLACIAN_SMOOTH, ";
783 SMESH_Gen_i::AddToCurrentPyScript( str );
785 SMESH_Gen_i::AddToCurrentPyScript( "print \"SmoothObject: \", isDone" );
791 //=============================================================================
795 //=============================================================================
797 void SMESH_MeshEditor_i::RenumberNodes()
799 // Update Python script
800 SMESH_Gen_i::AddToCurrentPyScript( "mesh_editor.RenumberNodes()" );
802 GetMeshDS()->Renumber( true );
805 //=============================================================================
809 //=============================================================================
811 void SMESH_MeshEditor_i::RenumberElements()
813 // Update Python script
814 SMESH_Gen_i::AddToCurrentPyScript( "mesh_editor.RenumberElements()" );
816 GetMeshDS()->Renumber( false );
819 //=======================================================================
820 //function : RotationSweep
822 //=======================================================================
824 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
825 const SMESH::AxisStruct & theAxis,
826 CORBA::Double theAngleInRadians,
827 CORBA::Long theNbOfSteps,
828 CORBA::Double theTolerance)
830 SMESHDS_Mesh* aMesh = GetMeshDS();
832 set<const SMDS_MeshElement*> elements;
833 for (int i = 0; i < theIDsOfElements.length(); i++)
835 CORBA::Long index = theIDsOfElements[i];
836 const SMDS_MeshElement * elem = aMesh->FindElement(index);
838 elements.insert( elem );
840 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
841 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
843 ::SMESH_MeshEditor anEditor( _myMesh );
844 anEditor.RotationSweep (elements, Ax1, theAngleInRadians,
845 theNbOfSteps, theTolerance);
847 // Update Python script
848 TCollection_AsciiString str = "axis = ";
849 addAxis( str, theAxis );
850 SMESH_Gen_i::AddToCurrentPyScript( str );
851 str = "mesh_editor.RotationSweep(";
852 SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", axis, ";
853 str += TCollection_AsciiString( theAngleInRadians ) + ", ";
854 str += TCollection_AsciiString( (int)theNbOfSteps ) + ", ";
855 str += TCollection_AsciiString( theTolerance ) + " )";
856 SMESH_Gen_i::AddToCurrentPyScript( str );
859 //=======================================================================
860 //function : RotationSweepObject
862 //=======================================================================
864 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
865 const SMESH::AxisStruct & theAxis,
866 CORBA::Double theAngleInRadians,
867 CORBA::Long theNbOfSteps,
868 CORBA::Double theTolerance)
870 SMESH::long_array_var anElementsId = theObject->GetIDs();
871 RotationSweep(anElementsId, theAxis, theAngleInRadians, theNbOfSteps, theTolerance);
873 // Clear python line, created by RotationSweep()
874 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
875 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
877 // Update Python script
878 TCollection_AsciiString str ("mesh_editor.RotationSweepObject(");
879 SMESH_Gen_i::AddObject( str, theObject ) += ", axis, ";
880 str += TCollection_AsciiString( theAngleInRadians ) + ", ";
881 str += TCollection_AsciiString( (int)theNbOfSteps ) + ", ";
882 str += TCollection_AsciiString( theTolerance ) + " )";
883 SMESH_Gen_i::AddToCurrentPyScript( str );
886 //=======================================================================
887 //function : ExtrusionSweep
889 //=======================================================================
891 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
892 const SMESH::DirStruct & theStepVector,
893 CORBA::Long theNbOfSteps)
895 SMESHDS_Mesh* aMesh = GetMeshDS();
897 set<const SMDS_MeshElement*> elements;
898 for (int i = 0; i < theIDsOfElements.length(); i++)
900 CORBA::Long index = theIDsOfElements[i];
901 const SMDS_MeshElement * elem = aMesh->FindElement(index);
903 elements.insert( elem );
905 const SMESH::PointStruct * P = &theStepVector.PS;
906 gp_Vec stepVec( P->x, P->y, P->z );
908 ::SMESH_MeshEditor anEditor( _myMesh );
909 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
911 // Update Python script
912 TCollection_AsciiString str = "stepVector = SMESH.DirStruct( SMESH.PointStruct ( ";
913 str += (TCollection_AsciiString) stepVec.X() + ", ";
914 str += (TCollection_AsciiString) stepVec.Y() + ", ";
915 str += (TCollection_AsciiString) stepVec.Z() + " ))";
916 SMESH_Gen_i::AddToCurrentPyScript( str );
917 str = ("mesh_editor.ExtrusionSweep(");
918 SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", stepVector, ";
919 str += TCollection_AsciiString((int)theNbOfSteps) + " )";
920 SMESH_Gen_i::AddToCurrentPyScript( str );
924 //=======================================================================
925 //function : ExtrusionSweepObject
927 //=======================================================================
929 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
930 const SMESH::DirStruct & theStepVector,
931 CORBA::Long theNbOfSteps)
933 SMESH::long_array_var anElementsId = theObject->GetIDs();
934 ExtrusionSweep(anElementsId, theStepVector, theNbOfSteps);
936 // Clear python line, created by ExtrusionSweep()
937 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
938 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
940 // Update Python script
941 TCollection_AsciiString str ("mesh_editor.ExtrusionSweepObject(");
942 SMESH_Gen_i::AddObject( str, theObject ) += ", stepVector, ";
943 str += TCollection_AsciiString((int)theNbOfSteps) + " )";
944 SMESH_Gen_i::AddToCurrentPyScript( str );
946 //=======================================================================
947 //function : ExtrusionSweepObject1D
949 //=======================================================================
951 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
952 const SMESH::DirStruct & theStepVector,
953 CORBA::Long theNbOfSteps)
955 SMESHDS_Mesh* aMesh = GetMeshDS();
957 SMESH::long_array_var allElementsId = theObject->GetIDs();
959 set<const SMDS_MeshElement*> elements;
960 for (int i = 0; i < allElementsId->length(); i++)
962 CORBA::Long index = allElementsId[i];
963 const SMDS_MeshElement * elem = aMesh->FindElement(index);
964 if ( elem && elem->GetType() == SMDSAbs_Edge )
965 elements.insert( elem );
967 const SMESH::PointStruct * P = &theStepVector.PS;
968 gp_Vec stepVec( P->x, P->y, P->z );
970 ::SMESH_MeshEditor anEditor( _myMesh );
971 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
974 //=======================================================================
975 //function : ExtrusionSweepObject2D
977 //=======================================================================
979 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
980 const SMESH::DirStruct & theStepVector,
981 CORBA::Long theNbOfSteps)
983 SMESHDS_Mesh* aMesh = GetMeshDS();
985 SMESH::long_array_var allElementsId = theObject->GetIDs();
987 set<const SMDS_MeshElement*> elements;
988 for (int i = 0; i < allElementsId->length(); i++)
990 CORBA::Long index = allElementsId[i];
991 const SMDS_MeshElement * elem = aMesh->FindElement(index);
992 if ( elem && elem->GetType() == SMDSAbs_Face )
993 elements.insert( elem );
995 const SMESH::PointStruct * P = &theStepVector.PS;
996 gp_Vec stepVec( P->x, P->y, P->z );
998 ::SMESH_MeshEditor anEditor( _myMesh );
999 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
1002 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1004 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1008 RETCASE( EXTR_NO_ELEMENTS );
1009 RETCASE( EXTR_PATH_NOT_EDGE );
1010 RETCASE( EXTR_BAD_PATH_SHAPE );
1011 RETCASE( EXTR_BAD_STARTING_NODE );
1012 RETCASE( EXTR_BAD_ANGLES_NUMBER );
1013 RETCASE( EXTR_CANT_GET_TANGENT );
1015 return SMESH::SMESH_MeshEditor::EXTR_OK;
1018 //=======================================================================
1019 //function : ExtrusionAlongPath
1021 //=======================================================================
1023 SMESH::SMESH_MeshEditor::Extrusion_Error
1024 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1025 SMESH::SMESH_Mesh_ptr thePathMesh,
1026 GEOM::GEOM_Object_ptr thePathShape,
1027 CORBA::Long theNodeStart,
1028 CORBA::Boolean theHasAngles,
1029 const SMESH::double_array & theAngles,
1030 CORBA::Boolean theHasRefPoint,
1031 const SMESH::PointStruct & theRefPoint)
1033 SMESHDS_Mesh* aMesh = GetMeshDS();
1035 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() )
1036 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1038 SMESH_Mesh_i* aMeshImp = dynamic_cast<SMESH_Mesh_i*>( SMESH_Gen_i::GetServant( thePathMesh ).in() );
1039 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1040 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1043 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1045 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
1047 return SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
1049 set<const SMDS_MeshElement*> elements;
1050 for (int i = 0; i < theIDsOfElements.length(); i++)
1052 CORBA::Long index = theIDsOfElements[i];
1053 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1055 elements.insert( elem );
1058 list<double> angles;
1059 for (int i = 0; i < theAngles.length(); i++)
1061 angles.push_back( theAngles[i] );
1064 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
1066 // Update Python script
1067 TCollection_AsciiString str = "refPoint = SMESH.PointStruct( ";
1068 str += (TCollection_AsciiString) refPnt.X() + ", ";
1069 str += (TCollection_AsciiString) refPnt.Y() + ", ";
1070 str += (TCollection_AsciiString) refPnt.Z() + " )";
1071 SMESH_Gen_i::AddToCurrentPyScript( str );
1072 str = ("error = mesh_editor.ExtrusionAlongPath(");
1073 SMESH_Gen_i::AddArray ( str, theIDsOfElements ) += ", ";
1074 SMESH_Gen_i::AddObject( str, thePathMesh ) += ", ";
1075 SMESH_Gen_i::AddObject( str, thePathShape ) += ", ";
1076 str += TCollection_AsciiString( (int)theNodeStart ) + ", ";
1077 str += TCollection_AsciiString( (int)theHasAngles ) + ", ";
1078 SMESH_Gen_i::AddArray ( str, theAngles ) += ", ";
1079 str += (TCollection_AsciiString) theHasRefPoint + ", refPoint )";
1080 SMESH_Gen_i::AddToCurrentPyScript( str );
1082 ::SMESH_MeshEditor anEditor( _myMesh );
1083 return convExtrError( anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart, theHasAngles, angles, theHasRefPoint, refPnt ) );
1086 //=======================================================================
1087 //function : ExtrusionAlongPathObject
1089 //=======================================================================
1091 SMESH::SMESH_MeshEditor::Extrusion_Error
1092 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
1093 SMESH::SMESH_Mesh_ptr thePathMesh,
1094 GEOM::GEOM_Object_ptr thePathShape,
1095 CORBA::Long theNodeStart,
1096 CORBA::Boolean theHasAngles,
1097 const SMESH::double_array & theAngles,
1098 CORBA::Boolean theHasRefPoint,
1099 const SMESH::PointStruct & theRefPoint)
1101 SMESH::long_array_var anElementsId = theObject->GetIDs();
1102 SMESH::SMESH_MeshEditor::Extrusion_Error error = ExtrusionAlongPath
1103 (anElementsId, thePathMesh, thePathShape, theNodeStart,
1104 theHasAngles, theAngles, theHasRefPoint, theRefPoint);
1106 // Clear python line, created by ExtrusionAlongPath()
1107 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1108 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1110 // Update Python script
1111 TCollection_AsciiString str ("error = mesh_editor.ExtrusionAlongPathObject(");
1112 SMESH_Gen_i::AddObject( str, theObject ) += ", ";
1113 SMESH_Gen_i::AddObject( str, thePathMesh ) += ", ";
1114 SMESH_Gen_i::AddObject( str, thePathShape ) += ", ";
1115 str += TCollection_AsciiString( (int)theNodeStart ) + ", ";
1116 str += TCollection_AsciiString( theHasAngles ) + ", ";
1117 SMESH_Gen_i::AddArray ( str, theAngles ) += ", ";
1118 str += TCollection_AsciiString( theHasRefPoint ) + ", refPoint )";
1119 SMESH_Gen_i::AddToCurrentPyScript( str );
1124 //=======================================================================
1127 //=======================================================================
1129 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
1130 const SMESH::AxisStruct & theAxis,
1131 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
1132 CORBA::Boolean theCopy)
1134 SMESHDS_Mesh* aMesh = GetMeshDS();
1136 set<const SMDS_MeshElement*> elements;
1137 for (int i = 0; i < theIDsOfElements.length(); i++)
1139 CORBA::Long index = theIDsOfElements[i];
1140 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1142 elements.insert( elem );
1144 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
1145 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
1148 TCollection_AsciiString typeStr, copyStr( theCopy );
1149 switch ( theMirrorType ) {
1150 case SMESH::SMESH_MeshEditor::POINT:
1151 aTrsf.SetMirror( P );
1152 typeStr = "SMESH.SMESH_MeshEditor.POINT";
1154 case SMESH::SMESH_MeshEditor::AXIS:
1155 aTrsf.SetMirror( gp_Ax1( P, V ));
1156 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
1159 aTrsf.SetMirror( gp_Ax2( P, V ));
1160 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
1163 // Update Python script
1164 TCollection_AsciiString str ("mesh_editor.Mirror(");
1165 SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", ";
1166 addAxis( str, theAxis ) += ", ";
1167 str += typeStr + ", ";
1168 str += copyStr + " )";
1169 SMESH_Gen_i::AddToCurrentPyScript( str );
1171 ::SMESH_MeshEditor anEditor( _myMesh );
1172 anEditor.Transform (elements, aTrsf, theCopy);
1175 //=======================================================================
1176 //function : MirrorObject
1178 //=======================================================================
1180 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
1181 const SMESH::AxisStruct & theAxis,
1182 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
1183 CORBA::Boolean theCopy)
1185 SMESH::long_array_var anElementsId = theObject->GetIDs();
1186 Mirror(anElementsId, theAxis, theMirrorType, theCopy);
1188 // Clear python line, created by Mirror()
1189 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1190 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1192 // Update Python script
1193 TCollection_AsciiString typeStr, copyStr( theCopy );
1194 switch ( theMirrorType ) {
1195 case SMESH::SMESH_MeshEditor::POINT:
1196 typeStr = "SMESH.SMESH_MeshEditor.POINT";
1198 case SMESH::SMESH_MeshEditor::AXIS:
1199 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
1202 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
1205 TCollection_AsciiString str ("mesh_editor.MirrorObject(");
1206 SMESH_Gen_i::AddObject( str, theObject ) += ", ";
1207 addAxis( str, theAxis ) += ", ";
1208 str += typeStr + ", " + copyStr + " )";
1209 SMESH_Gen_i::AddToCurrentPyScript( str );
1212 //=======================================================================
1213 //function : Translate
1215 //=======================================================================
1217 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
1218 const SMESH::DirStruct & theVector,
1219 CORBA::Boolean theCopy)
1221 SMESHDS_Mesh* aMesh = GetMeshDS();
1223 set<const SMDS_MeshElement*> elements;
1224 for (int i = 0; i < theIDsOfElements.length(); i++)
1226 CORBA::Long index = theIDsOfElements[i];
1227 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1229 elements.insert( elem );
1232 const SMESH::PointStruct * P = &theVector.PS;
1233 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
1235 ::SMESH_MeshEditor anEditor( _myMesh );
1236 anEditor.Transform (elements, aTrsf, theCopy);
1238 // Update Python script
1239 TCollection_AsciiString str = "vector = SMESH.DirStruct( SMESH.PointStruct ( ";
1240 str += (TCollection_AsciiString) P->x + ", ";
1241 str += (TCollection_AsciiString) P->y + ", ";
1242 str += (TCollection_AsciiString) P->z + " ))";
1243 SMESH_Gen_i::AddToCurrentPyScript( str );
1244 str = ("mesh_editor.Translate(");
1245 SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", vector, ";
1246 str += (TCollection_AsciiString) theCopy + " )";
1247 SMESH_Gen_i::AddToCurrentPyScript( str );
1250 //=======================================================================
1251 //function : TranslateObject
1253 //=======================================================================
1255 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
1256 const SMESH::DirStruct & theVector,
1257 CORBA::Boolean theCopy)
1259 SMESH::long_array_var anElementsId = theObject->GetIDs();
1260 Translate(anElementsId, theVector, theCopy);
1262 // Clear python line, created by Translate()
1263 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1264 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1266 // Update Python script
1267 TCollection_AsciiString str ("mesh_editor.TranslateObject(");
1268 SMESH_Gen_i::AddObject( str, theObject ) += ", vector, ";
1269 str += TCollection_AsciiString( theCopy ) + " )";
1270 SMESH_Gen_i::AddToCurrentPyScript( str );
1273 //=======================================================================
1276 //=======================================================================
1278 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
1279 const SMESH::AxisStruct & theAxis,
1280 CORBA::Double theAngle,
1281 CORBA::Boolean theCopy)
1283 SMESHDS_Mesh* aMesh = GetMeshDS();
1285 set<const SMDS_MeshElement*> elements;
1286 for (int i = 0; i < theIDsOfElements.length(); i++)
1288 CORBA::Long index = theIDsOfElements[i];
1289 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1291 elements.insert( elem );
1293 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
1294 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
1297 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
1299 ::SMESH_MeshEditor anEditor( _myMesh );
1300 anEditor.Transform (elements, aTrsf, theCopy);
1302 // Update Python script
1303 TCollection_AsciiString str ("axis = ");
1304 addAxis( str, theAxis );
1305 SMESH_Gen_i::AddToCurrentPyScript( str );
1306 str = ("mesh_editor.Rotate(");
1307 SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", axis, ";
1308 str += (TCollection_AsciiString) theAngle + ", ";
1309 str += (TCollection_AsciiString) theCopy + " )";
1310 SMESH_Gen_i::AddToCurrentPyScript( str );
1313 //=======================================================================
1314 //function : RotateObject
1316 //=======================================================================
1318 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
1319 const SMESH::AxisStruct & theAxis,
1320 CORBA::Double theAngle,
1321 CORBA::Boolean theCopy)
1323 SMESH::long_array_var anElementsId = theObject->GetIDs();
1324 Rotate(anElementsId, theAxis, theAngle, theCopy);
1326 // Clear python line, created by Rotate()
1327 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1328 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1330 // Update Python script
1331 TCollection_AsciiString str ("mesh_editor.RotateObject(");
1332 SMESH_Gen_i::AddObject( str, theObject ) += ", axis, ";
1333 str += TCollection_AsciiString( theAngle ) + ", ";
1334 str += TCollection_AsciiString( theCopy ) + " )";
1335 SMESH_Gen_i::AddToCurrentPyScript( str );
1338 //=======================================================================
1339 //function : FindCoincidentNodes
1341 //=======================================================================
1343 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
1344 SMESH::array_of_long_array_out GroupsOfNodes)
1346 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
1347 ::SMESH_MeshEditor anEditor( _myMesh );
1348 set<const SMDS_MeshNode*> nodes; // no input nodes
1349 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
1351 GroupsOfNodes = new SMESH::array_of_long_array;
1352 GroupsOfNodes->length( aListOfListOfNodes.size() );
1353 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
1354 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
1356 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
1357 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
1358 SMESH::long_array& aGroup = GroupsOfNodes[ i ];
1359 aGroup.length( aListOfNodes.size() );
1360 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
1361 aGroup[ j ] = (*lIt)->GetID();
1365 //=======================================================================
1366 //function : MergeNodes
1368 //=======================================================================
1370 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
1372 SMESHDS_Mesh* aMesh = GetMeshDS();
1374 TCollection_AsciiString str( "mesh_editor.MergeNodes([" );
1375 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
1376 for (int i = 0; i < GroupsOfNodes.length(); i++)
1378 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
1379 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
1380 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
1381 for ( int j = 0; j < aNodeGroup.length(); j++ )
1383 CORBA::Long index = aNodeGroup[ j ];
1384 const SMDS_MeshNode * node = aMesh->FindNode(index);
1386 aListOfNodes.push_back( node );
1388 if ( aListOfNodes.size() < 2 )
1389 aListOfListOfNodes.pop_back();
1393 SMESH_Gen_i::AddArray( str, aNodeGroup );
1395 ::SMESH_MeshEditor anEditor( _myMesh );
1396 anEditor.MergeNodes( aListOfListOfNodes );
1398 // Update Python script
1399 SMESH_Gen_i::AddToCurrentPyScript( str + "])" );
1402 //=======================================================================
1403 //function : MergeEqualElements
1405 //=======================================================================
1407 void SMESH_MeshEditor_i::MergeEqualElements()
1409 ::SMESH_MeshEditor anEditor( _myMesh );
1410 anEditor.MergeEqualElements();
1412 // Update Python script
1413 SMESH_Gen_i::AddToCurrentPyScript( "mesh_editor.MergeEqualElements()" );
1416 //=======================================================================
1417 //function : operator
1419 //=======================================================================
1421 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1423 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
1427 RETCASE( SEW_BORDER1_NOT_FOUND );
1428 RETCASE( SEW_BORDER2_NOT_FOUND );
1429 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
1430 RETCASE( SEW_BAD_SIDE_NODES );
1431 RETCASE( SEW_VOLUMES_TO_SPLIT );
1432 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
1433 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
1434 RETCASE( SEW_BAD_SIDE1_NODES );
1435 RETCASE( SEW_BAD_SIDE2_NODES );
1437 return SMESH::SMESH_MeshEditor::SEW_OK;
1440 //=======================================================================
1441 //function : SewFreeBorders
1443 //=======================================================================
1445 SMESH::SMESH_MeshEditor::Sew_Error
1446 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
1447 CORBA::Long SecondNodeID1,
1448 CORBA::Long LastNodeID1,
1449 CORBA::Long FirstNodeID2,
1450 CORBA::Long SecondNodeID2,
1451 CORBA::Long LastNodeID2,
1452 CORBA::Boolean CreatePolygons,
1453 CORBA::Boolean CreatePolyedrs)
1455 SMESHDS_Mesh* aMesh = GetMeshDS();
1457 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
1458 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
1459 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
1460 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
1461 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
1462 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
1464 if (!aBorderFirstNode ||
1465 !aBorderSecondNode||
1467 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1468 if (!aSide2FirstNode ||
1469 !aSide2SecondNode ||
1471 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
1473 // Update Python script
1474 TCollection_AsciiString str ("error = mesh_editor.SewFreeBorders( ");
1475 str += TCollection_AsciiString( (int) FirstNodeID1 ) + ", ";
1476 str += TCollection_AsciiString( (int) SecondNodeID1 ) + ", ";
1477 str += TCollection_AsciiString( (int) LastNodeID1 ) + ", ";
1478 str += TCollection_AsciiString( (int) FirstNodeID2 ) + ", ";
1479 str += TCollection_AsciiString( (int) SecondNodeID2 ) + ", ";
1480 str += TCollection_AsciiString( (int) LastNodeID2 ) + ", ";
1481 str += TCollection_AsciiString( CreatePolygons ) + ", ";
1482 str += TCollection_AsciiString( CreatePolyedrs ) + ") ";
1483 SMESH_Gen_i::AddToCurrentPyScript( str );
1485 ::SMESH_MeshEditor anEditor( _myMesh );
1486 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
1497 //=======================================================================
1498 //function : SewConformFreeBorders
1500 //=======================================================================
1502 SMESH::SMESH_MeshEditor::Sew_Error
1503 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
1504 CORBA::Long SecondNodeID1,
1505 CORBA::Long LastNodeID1,
1506 CORBA::Long FirstNodeID2,
1507 CORBA::Long SecondNodeID2)
1509 SMESHDS_Mesh* aMesh = GetMeshDS();
1511 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
1512 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
1513 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
1514 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
1515 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
1516 const SMDS_MeshNode* aSide2ThirdNode = 0;
1518 if (!aBorderFirstNode ||
1519 !aBorderSecondNode||
1521 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1522 if (!aSide2FirstNode ||
1524 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
1526 // Update Python script
1527 TCollection_AsciiString str ("error = mesh_editor.SewConformFreeBorders( ");
1528 str += TCollection_AsciiString( (int) FirstNodeID1 ) + ", ";
1529 str += TCollection_AsciiString( (int) SecondNodeID1 ) + ", ";
1530 str += TCollection_AsciiString( (int) LastNodeID1 ) + ", ";
1531 str += TCollection_AsciiString( (int) FirstNodeID2 ) + ", ";
1532 str += TCollection_AsciiString( (int) SecondNodeID2 ) + ")";
1533 SMESH_Gen_i::AddToCurrentPyScript( str );
1535 ::SMESH_MeshEditor anEditor( _myMesh );
1536 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
1546 //=======================================================================
1547 //function : SewBorderToSide
1549 //=======================================================================
1551 SMESH::SMESH_MeshEditor::Sew_Error
1552 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
1553 CORBA::Long SecondNodeIDOnFreeBorder,
1554 CORBA::Long LastNodeIDOnFreeBorder,
1555 CORBA::Long FirstNodeIDOnSide,
1556 CORBA::Long LastNodeIDOnSide,
1557 CORBA::Boolean CreatePolygons,
1558 CORBA::Boolean CreatePolyedrs)
1560 SMESHDS_Mesh* aMesh = GetMeshDS();
1562 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
1563 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
1564 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
1565 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
1566 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
1567 const SMDS_MeshNode* aSide2ThirdNode = 0;
1569 if (!aBorderFirstNode ||
1570 !aBorderSecondNode||
1572 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1573 if (!aSide2FirstNode ||
1575 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
1577 // Update Python script
1578 TCollection_AsciiString str ("error = mesh_editor.SewBorderToSide( ");
1579 str += TCollection_AsciiString( (int) FirstNodeIDOnFreeBorder ) + ", ";
1580 str += TCollection_AsciiString( (int) SecondNodeIDOnFreeBorder ) + ", ";
1581 str += TCollection_AsciiString( (int) LastNodeIDOnFreeBorder ) + ", ";
1582 str += TCollection_AsciiString( (int) FirstNodeIDOnSide ) + ", ";
1583 str += TCollection_AsciiString( (int) LastNodeIDOnSide ) + ", ";
1584 str += TCollection_AsciiString( CreatePolygons ) + ", ";
1585 str += TCollection_AsciiString( CreatePolyedrs ) + ") ";
1586 SMESH_Gen_i::AddToCurrentPyScript( str );
1588 ::SMESH_MeshEditor anEditor( _myMesh );
1589 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
1600 //=======================================================================
1601 //function : SewSideElements
1603 //=======================================================================
1605 SMESH::SMESH_MeshEditor::Sew_Error
1606 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
1607 const SMESH::long_array& IDsOfSide2Elements,
1608 CORBA::Long NodeID1OfSide1ToMerge,
1609 CORBA::Long NodeID1OfSide2ToMerge,
1610 CORBA::Long NodeID2OfSide1ToMerge,
1611 CORBA::Long NodeID2OfSide2ToMerge)
1613 SMESHDS_Mesh* aMesh = GetMeshDS();
1615 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
1616 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
1617 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
1618 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
1620 if (!aFirstNode1ToMerge ||
1621 !aFirstNode2ToMerge )
1622 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
1623 if (!aSecondNode1ToMerge||
1624 !aSecondNode2ToMerge)
1625 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
1627 set<const SMDS_MeshElement*> aSide1Elems, aSide2Elems;
1628 for (int i = 0; i < IDsOfSide1Elements.length(); i++)
1630 CORBA::Long index = IDsOfSide1Elements[i];
1631 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1633 aSide1Elems.insert( elem );
1635 for (int i = 0; i < IDsOfSide2Elements.length(); i++)
1637 CORBA::Long index = IDsOfSide2Elements[i];
1638 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1640 aSide2Elems.insert( elem );
1642 // Update Python script
1643 TCollection_AsciiString str ("error = mesh_editor.SewSideElements( ");
1644 SMESH_Gen_i::AddArray( str, IDsOfSide1Elements ) += ", ";
1645 SMESH_Gen_i::AddArray( str, IDsOfSide2Elements ) += ", ";
1646 str += TCollection_AsciiString( (int) NodeID1OfSide1ToMerge ) + ", ";
1647 str += TCollection_AsciiString( (int) NodeID1OfSide2ToMerge ) + ", ";
1648 str += TCollection_AsciiString( (int) NodeID2OfSide1ToMerge ) + ", ";
1649 str += TCollection_AsciiString( (int) NodeID2OfSide2ToMerge ) + ")";
1650 SMESH_Gen_i::AddToCurrentPyScript( str );
1652 ::SMESH_MeshEditor anEditor( _myMesh );
1653 return convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
1656 aSecondNode1ToMerge,
1657 aSecondNode2ToMerge));