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 //=============================================================================
446 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
447 SMESH::NumericalFunctor_ptr Criterion,
448 CORBA::Double MaxAngle)
450 set<const SMDS_MeshElement*> faces;
451 for (int i = 0; i < IDsOfElements.length(); i++)
453 CORBA::Long index = IDsOfElements[i];
454 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
455 if ( elem && elem->GetType() == SMDSAbs_Face)
456 faces.insert( elem );
458 SMESH::NumericalFunctor_i* aNumericalFunctor =
459 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
460 SMESH::Controls::NumericalFunctorPtr aCrit;
461 if ( !aNumericalFunctor )
462 aCrit.reset( new SMESH::Controls::AspectRatio() );
464 aCrit = aNumericalFunctor->GetNumericalFunctor();
466 // Update Python script
467 TCollection_AsciiString str ("isDone = mesh_editor.TriToQuad(");
468 SMESH_Gen_i::AddArray( str, IDsOfElements ) += ", None, ";
469 str += TCollection_AsciiString((Standard_Real) MaxAngle) + ")";
470 SMESH_Gen_i::AddToCurrentPyScript( str );
472 SMESH_Gen_i::AddToCurrentPyScript( "print \"TriToQuad: \", isDone" );
475 ::SMESH_MeshEditor anEditor( _myMesh );
476 return anEditor.TriToQuad( faces, aCrit, MaxAngle );
479 //=============================================================================
483 //=============================================================================
484 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
485 SMESH::NumericalFunctor_ptr Criterion,
486 CORBA::Double MaxAngle)
488 SMESH::long_array_var anElementsId = theObject->GetIDs();
489 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
491 // Clear python line(s), created by TriToQuad()
492 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
493 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
495 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
498 // Update Python script
499 TCollection_AsciiString str ("isDone = mesh_editor.TriToQuadObject(");
500 SMESH_Gen_i::AddObject( str, theObject ) += ", None, ";
501 str += TCollection_AsciiString((Standard_Real) MaxAngle) + ")";
502 SMESH_Gen_i::AddToCurrentPyScript( str );
504 SMESH_Gen_i::AddToCurrentPyScript( "print \"TriToQuadObject: \", isDone" );
510 //=============================================================================
514 //=============================================================================
515 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
516 SMESH::NumericalFunctor_ptr Criterion)
518 set<const SMDS_MeshElement*> faces;
519 for (int i = 0; i < IDsOfElements.length(); i++)
521 CORBA::Long index = IDsOfElements[i];
522 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
523 if ( elem && elem->GetType() == SMDSAbs_Face)
524 faces.insert( elem );
526 SMESH::NumericalFunctor_i* aNumericalFunctor =
527 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
528 SMESH::Controls::NumericalFunctorPtr aCrit;
529 if ( !aNumericalFunctor )
530 aCrit.reset( new SMESH::Controls::AspectRatio() );
532 aCrit = aNumericalFunctor->GetNumericalFunctor();
535 // Update Python script
536 TCollection_AsciiString str ("isDone = mesh_editor.QuadToTri(");
537 SMESH_Gen_i::AddArray( str, IDsOfElements ) += ", None )";
538 SMESH_Gen_i::AddToCurrentPyScript( str );
540 SMESH_Gen_i::AddToCurrentPyScript( "print \"QuadToTri: \", isDone" );
543 ::SMESH_MeshEditor anEditor( _myMesh );
544 return anEditor.QuadToTri( faces, aCrit );
547 //=============================================================================
551 //=============================================================================
552 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
553 SMESH::NumericalFunctor_ptr Criterion)
555 SMESH::long_array_var anElementsId = theObject->GetIDs();
556 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
558 // Clear python line(s), created by QuadToTri()
559 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
560 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
562 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
565 // Update Python script
566 TCollection_AsciiString str ("isDone = mesh_editor.QuadToTriObject(");
567 SMESH_Gen_i::AddObject( str, theObject ) += ", None )";
568 SMESH_Gen_i::AddToCurrentPyScript( str );
570 SMESH_Gen_i::AddToCurrentPyScript( "print \"QuadToTriObject: \", isDone" );
576 //=============================================================================
580 //=============================================================================
581 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
582 CORBA::Boolean Diag13)
584 set<const SMDS_MeshElement*> faces;
585 for (int i = 0; i < IDsOfElements.length(); i++)
587 CORBA::Long index = IDsOfElements[i];
588 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
589 if ( elem && elem->GetType() == SMDSAbs_Face)
590 faces.insert( elem );
593 // Update Python script
594 TCollection_AsciiString str ("isDone = mesh_editor.SplitQuad(");
595 SMESH_Gen_i::AddArray( str, IDsOfElements ) += ", ";
596 str += TCollection_AsciiString( Diag13 ) + ")";
597 SMESH_Gen_i::AddToCurrentPyScript( str );
599 SMESH_Gen_i::AddToCurrentPyScript( "print \"SplitQuad: \", isDone" );
602 ::SMESH_MeshEditor anEditor( _myMesh );
603 return anEditor.QuadToTri( faces, Diag13 );
606 //=============================================================================
610 //=============================================================================
611 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
612 CORBA::Boolean Diag13)
614 SMESH::long_array_var anElementsId = theObject->GetIDs();
615 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
617 // Clear python line(s), created by SplitQuad()
618 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
619 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
621 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
624 // Update Python script
625 TCollection_AsciiString str ("isDone = mesh_editor.SplitQuadObject(");
626 SMESH_Gen_i::AddObject( str, theObject ) += ", ";
627 str += TCollection_AsciiString( Diag13 ) + ")";
628 SMESH_Gen_i::AddToCurrentPyScript( str );
630 SMESH_Gen_i::AddToCurrentPyScript( "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 TCollection_AsciiString str ("isDone = mesh_editor.");
768 str += (char*) (IsParametric ? "SmoothParametric( " : "Smooth( ");
769 SMESH_Gen_i::AddArray( str, IDsOfElements ) += ", ";
770 SMESH_Gen_i::AddArray( str, IDsOfFixedNodes ) += ", ";
771 str += (Standard_Integer) MaxNbOfIterations;
773 str += (Standard_Real) MaxAspectRatio;
774 if ( method == ::SMESH_MeshEditor::CENTROIDAL )
775 str += ", SMESH.SMESH_MeshEditor.CENTROIDAL_SMOOTH, ";
777 str += ", SMESH.SMESH_MeshEditor.LAPLACIAN_SMOOTH, ";
780 SMESH_Gen_i::AddToCurrentPyScript( str );
782 SMESH_Gen_i::AddToCurrentPyScript( "print \"Smooth: \", isDone" );
788 //=============================================================================
792 //=============================================================================
795 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
796 const SMESH::long_array & IDsOfFixedNodes,
797 CORBA::Long MaxNbOfIterations,
798 CORBA::Double MaxAspectRatio,
799 SMESH::SMESH_MeshEditor::Smooth_Method Method,
802 SMESH::long_array_var anElementsId = theObject->GetIDs();
803 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
804 MaxAspectRatio, Method, IsParametric);
806 // Clear python line(s), created by Smooth()
807 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
808 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
810 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
813 // Update Python script
814 TCollection_AsciiString str ("isDone = mesh_editor.");
815 str += (char*) (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ");
816 SMESH_Gen_i::AddObject( str, theObject ) += ", ";
817 SMESH_Gen_i::AddArray( str, IDsOfFixedNodes ) += ", ";
818 str += (Standard_Integer) MaxNbOfIterations;
820 str += (Standard_Real) MaxAspectRatio;
821 if ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH )
822 str += ", SMESH.SMESH_MeshEditor.CENTROIDAL_SMOOTH, ";
824 str += ", SMESH.SMESH_MeshEditor.LAPLACIAN_SMOOTH, ";
827 SMESH_Gen_i::AddToCurrentPyScript( str );
829 SMESH_Gen_i::AddToCurrentPyScript( "print \"SmoothObject: \", isDone" );
835 //=============================================================================
839 //=============================================================================
841 void SMESH_MeshEditor_i::RenumberNodes()
843 // Update Python script
844 SMESH_Gen_i::AddToCurrentPyScript( "mesh_editor.RenumberNodes()" );
846 GetMeshDS()->Renumber( true );
849 //=============================================================================
853 //=============================================================================
855 void SMESH_MeshEditor_i::RenumberElements()
857 // Update Python script
858 SMESH_Gen_i::AddToCurrentPyScript( "mesh_editor.RenumberElements()" );
860 GetMeshDS()->Renumber( false );
863 //=======================================================================
864 //function : RotationSweep
866 //=======================================================================
868 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
869 const SMESH::AxisStruct & theAxis,
870 CORBA::Double theAngleInRadians,
871 CORBA::Long theNbOfSteps,
872 CORBA::Double theTolerance)
874 SMESHDS_Mesh* aMesh = GetMeshDS();
876 set<const SMDS_MeshElement*> elements;
877 for (int i = 0; i < theIDsOfElements.length(); i++)
879 CORBA::Long index = theIDsOfElements[i];
880 const SMDS_MeshElement * elem = aMesh->FindElement(index);
882 elements.insert( elem );
884 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
885 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
887 ::SMESH_MeshEditor anEditor( _myMesh );
888 anEditor.RotationSweep (elements, Ax1, theAngleInRadians,
889 theNbOfSteps, theTolerance);
891 // Update Python script
892 TCollection_AsciiString str = "axis = ";
893 addAxis( str, theAxis );
894 SMESH_Gen_i::AddToCurrentPyScript( str );
895 str = "mesh_editor.RotationSweep(";
896 SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", axis, ";
897 str += TCollection_AsciiString( theAngleInRadians ) + ", ";
898 str += TCollection_AsciiString( (int)theNbOfSteps ) + ", ";
899 str += TCollection_AsciiString( theTolerance ) + " )";
900 SMESH_Gen_i::AddToCurrentPyScript( str );
903 //=======================================================================
904 //function : RotationSweepObject
906 //=======================================================================
908 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
909 const SMESH::AxisStruct & theAxis,
910 CORBA::Double theAngleInRadians,
911 CORBA::Long theNbOfSteps,
912 CORBA::Double theTolerance)
914 SMESH::long_array_var anElementsId = theObject->GetIDs();
915 RotationSweep(anElementsId, theAxis, theAngleInRadians, theNbOfSteps, theTolerance);
917 // Clear python line, created by RotationSweep()
918 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
919 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
921 // Update Python script
922 TCollection_AsciiString str ("mesh_editor.RotationSweepObject(");
923 SMESH_Gen_i::AddObject( str, theObject ) += ", axis, ";
924 str += TCollection_AsciiString( theAngleInRadians ) + ", ";
925 str += TCollection_AsciiString( (int)theNbOfSteps ) + ", ";
926 str += TCollection_AsciiString( theTolerance ) + " )";
927 SMESH_Gen_i::AddToCurrentPyScript( str );
930 //=======================================================================
931 //function : ExtrusionSweep
933 //=======================================================================
935 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
936 const SMESH::DirStruct & theStepVector,
937 CORBA::Long theNbOfSteps)
939 SMESHDS_Mesh* aMesh = GetMeshDS();
941 set<const SMDS_MeshElement*> elements;
942 for (int i = 0; i < theIDsOfElements.length(); i++)
944 CORBA::Long index = theIDsOfElements[i];
945 const SMDS_MeshElement * elem = aMesh->FindElement(index);
947 elements.insert( elem );
949 const SMESH::PointStruct * P = &theStepVector.PS;
950 gp_Vec stepVec( P->x, P->y, P->z );
952 ::SMESH_MeshEditor anEditor( _myMesh );
953 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
955 // Update Python script
956 TCollection_AsciiString str = "stepVector = SMESH.DirStruct( SMESH.PointStruct ( ";
957 str += (TCollection_AsciiString) stepVec.X() + ", ";
958 str += (TCollection_AsciiString) stepVec.Y() + ", ";
959 str += (TCollection_AsciiString) stepVec.Z() + " ))";
960 SMESH_Gen_i::AddToCurrentPyScript( str );
961 str = ("mesh_editor.ExtrusionSweep(");
962 SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", stepVector, ";
963 str += TCollection_AsciiString((int)theNbOfSteps) + " )";
964 SMESH_Gen_i::AddToCurrentPyScript( str );
968 //=======================================================================
969 //function : ExtrusionSweepObject
971 //=======================================================================
973 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
974 const SMESH::DirStruct & theStepVector,
975 CORBA::Long theNbOfSteps)
977 SMESH::long_array_var anElementsId = theObject->GetIDs();
978 ExtrusionSweep(anElementsId, theStepVector, theNbOfSteps);
980 // Clear python line, created by ExtrusionSweep()
981 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
982 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
984 // Update Python script
985 TCollection_AsciiString str ("mesh_editor.ExtrusionSweepObject(");
986 SMESH_Gen_i::AddObject( str, theObject ) += ", stepVector, ";
987 str += TCollection_AsciiString((int)theNbOfSteps) + " )";
988 SMESH_Gen_i::AddToCurrentPyScript( str );
990 //=======================================================================
991 //function : ExtrusionSweepObject1D
993 //=======================================================================
995 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
996 const SMESH::DirStruct & theStepVector,
997 CORBA::Long theNbOfSteps)
999 SMESHDS_Mesh* aMesh = GetMeshDS();
1001 SMESH::long_array_var allElementsId = theObject->GetIDs();
1003 set<const SMDS_MeshElement*> elements;
1004 for (int i = 0; i < allElementsId->length(); i++)
1006 CORBA::Long index = allElementsId[i];
1007 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1008 if ( elem && elem->GetType() == SMDSAbs_Edge )
1009 elements.insert( elem );
1011 const SMESH::PointStruct * P = &theStepVector.PS;
1012 gp_Vec stepVec( P->x, P->y, P->z );
1014 ::SMESH_MeshEditor anEditor( _myMesh );
1015 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
1018 //=======================================================================
1019 //function : ExtrusionSweepObject2D
1021 //=======================================================================
1023 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1024 const SMESH::DirStruct & theStepVector,
1025 CORBA::Long theNbOfSteps)
1027 SMESHDS_Mesh* aMesh = GetMeshDS();
1029 SMESH::long_array_var allElementsId = theObject->GetIDs();
1031 set<const SMDS_MeshElement*> elements;
1032 for (int i = 0; i < allElementsId->length(); i++)
1034 CORBA::Long index = allElementsId[i];
1035 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1036 if ( elem && elem->GetType() == SMDSAbs_Face )
1037 elements.insert( elem );
1039 const SMESH::PointStruct * P = &theStepVector.PS;
1040 gp_Vec stepVec( P->x, P->y, P->z );
1042 ::SMESH_MeshEditor anEditor( _myMesh );
1043 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
1046 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1048 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1052 RETCASE( EXTR_NO_ELEMENTS );
1053 RETCASE( EXTR_PATH_NOT_EDGE );
1054 RETCASE( EXTR_BAD_PATH_SHAPE );
1055 RETCASE( EXTR_BAD_STARTING_NODE );
1056 RETCASE( EXTR_BAD_ANGLES_NUMBER );
1057 RETCASE( EXTR_CANT_GET_TANGENT );
1059 return SMESH::SMESH_MeshEditor::EXTR_OK;
1062 //=======================================================================
1063 //function : ExtrusionAlongPath
1065 //=======================================================================
1067 SMESH::SMESH_MeshEditor::Extrusion_Error
1068 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1069 SMESH::SMESH_Mesh_ptr thePathMesh,
1070 GEOM::GEOM_Object_ptr thePathShape,
1071 CORBA::Long theNodeStart,
1072 CORBA::Boolean theHasAngles,
1073 const SMESH::double_array & theAngles,
1074 CORBA::Boolean theHasRefPoint,
1075 const SMESH::PointStruct & theRefPoint)
1077 SMESHDS_Mesh* aMesh = GetMeshDS();
1079 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() )
1080 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1082 SMESH_Mesh_i* aMeshImp = dynamic_cast<SMESH_Mesh_i*>( SMESH_Gen_i::GetServant( thePathMesh ).in() );
1083 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1084 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1087 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1089 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
1091 return SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
1093 set<const SMDS_MeshElement*> elements;
1094 for (int i = 0; i < theIDsOfElements.length(); i++)
1096 CORBA::Long index = theIDsOfElements[i];
1097 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1099 elements.insert( elem );
1102 list<double> angles;
1103 for (int i = 0; i < theAngles.length(); i++)
1105 angles.push_back( theAngles[i] );
1108 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
1110 // Update Python script
1111 TCollection_AsciiString str = "refPoint = SMESH.PointStruct( ";
1112 str += (TCollection_AsciiString) refPnt.X() + ", ";
1113 str += (TCollection_AsciiString) refPnt.Y() + ", ";
1114 str += (TCollection_AsciiString) refPnt.Z() + " )";
1115 SMESH_Gen_i::AddToCurrentPyScript( str );
1116 str = ("error = mesh_editor.ExtrusionAlongPath(");
1117 SMESH_Gen_i::AddArray ( str, theIDsOfElements ) += ", ";
1118 SMESH_Gen_i::AddObject( str, thePathMesh ) += ", ";
1119 SMESH_Gen_i::AddObject( str, thePathShape ) += ", ";
1120 str += TCollection_AsciiString( (int)theNodeStart ) + ", ";
1121 str += TCollection_AsciiString( (int)theHasAngles ) + ", ";
1122 SMESH_Gen_i::AddArray ( str, theAngles ) += ", ";
1123 str += (TCollection_AsciiString) theHasRefPoint + ", refPoint )";
1124 SMESH_Gen_i::AddToCurrentPyScript( str );
1126 ::SMESH_MeshEditor anEditor( _myMesh );
1127 return convExtrError( anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart, theHasAngles, angles, theHasRefPoint, refPnt ) );
1130 //=======================================================================
1131 //function : ExtrusionAlongPathObject
1133 //=======================================================================
1135 SMESH::SMESH_MeshEditor::Extrusion_Error
1136 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
1137 SMESH::SMESH_Mesh_ptr thePathMesh,
1138 GEOM::GEOM_Object_ptr thePathShape,
1139 CORBA::Long theNodeStart,
1140 CORBA::Boolean theHasAngles,
1141 const SMESH::double_array & theAngles,
1142 CORBA::Boolean theHasRefPoint,
1143 const SMESH::PointStruct & theRefPoint)
1145 SMESH::long_array_var anElementsId = theObject->GetIDs();
1146 SMESH::SMESH_MeshEditor::Extrusion_Error error = ExtrusionAlongPath
1147 (anElementsId, thePathMesh, thePathShape, theNodeStart,
1148 theHasAngles, theAngles, theHasRefPoint, theRefPoint);
1150 // Clear python line, created by ExtrusionAlongPath()
1151 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1152 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1154 // Update Python script
1155 TCollection_AsciiString str ("error = mesh_editor.ExtrusionAlongPathObject(");
1156 SMESH_Gen_i::AddObject( str, theObject ) += ", ";
1157 SMESH_Gen_i::AddObject( str, thePathMesh ) += ", ";
1158 SMESH_Gen_i::AddObject( str, thePathShape ) += ", ";
1159 str += TCollection_AsciiString( (int)theNodeStart ) + ", ";
1160 str += TCollection_AsciiString( theHasAngles ) + ", ";
1161 SMESH_Gen_i::AddArray ( str, theAngles ) += ", ";
1162 str += TCollection_AsciiString( theHasRefPoint ) + ", refPoint )";
1163 SMESH_Gen_i::AddToCurrentPyScript( str );
1168 //=======================================================================
1171 //=======================================================================
1173 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
1174 const SMESH::AxisStruct & theAxis,
1175 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
1176 CORBA::Boolean theCopy)
1178 SMESHDS_Mesh* aMesh = GetMeshDS();
1180 set<const SMDS_MeshElement*> elements;
1181 for (int i = 0; i < theIDsOfElements.length(); i++)
1183 CORBA::Long index = theIDsOfElements[i];
1184 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1186 elements.insert( elem );
1188 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
1189 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
1192 TCollection_AsciiString typeStr, copyStr( theCopy );
1193 switch ( theMirrorType ) {
1194 case SMESH::SMESH_MeshEditor::POINT:
1195 aTrsf.SetMirror( P );
1196 typeStr = "SMESH.SMESH_MeshEditor.POINT";
1198 case SMESH::SMESH_MeshEditor::AXIS:
1199 aTrsf.SetMirror( gp_Ax1( P, V ));
1200 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
1203 aTrsf.SetMirror( gp_Ax2( P, V ));
1204 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
1207 // Update Python script
1208 TCollection_AsciiString str ("mesh_editor.Mirror(");
1209 SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", ";
1210 addAxis( str, theAxis ) += ", ";
1211 str += typeStr + ", ";
1212 str += copyStr + " )";
1213 SMESH_Gen_i::AddToCurrentPyScript( str );
1215 ::SMESH_MeshEditor anEditor( _myMesh );
1216 anEditor.Transform (elements, aTrsf, theCopy);
1219 //=======================================================================
1220 //function : MirrorObject
1222 //=======================================================================
1224 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
1225 const SMESH::AxisStruct & theAxis,
1226 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
1227 CORBA::Boolean theCopy)
1229 SMESH::long_array_var anElementsId = theObject->GetIDs();
1230 Mirror(anElementsId, theAxis, theMirrorType, theCopy);
1232 // Clear python line, created by Mirror()
1233 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1234 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1236 // Update Python script
1237 TCollection_AsciiString typeStr, copyStr( theCopy );
1238 switch ( theMirrorType ) {
1239 case SMESH::SMESH_MeshEditor::POINT:
1240 typeStr = "SMESH.SMESH_MeshEditor.POINT";
1242 case SMESH::SMESH_MeshEditor::AXIS:
1243 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
1246 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
1249 TCollection_AsciiString str ("mesh_editor.MirrorObject(");
1250 SMESH_Gen_i::AddObject( str, theObject ) += ", ";
1251 addAxis( str, theAxis ) += ", ";
1252 str += typeStr + ", " + copyStr + " )";
1253 SMESH_Gen_i::AddToCurrentPyScript( str );
1256 //=======================================================================
1257 //function : Translate
1259 //=======================================================================
1261 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
1262 const SMESH::DirStruct & theVector,
1263 CORBA::Boolean theCopy)
1265 SMESHDS_Mesh* aMesh = GetMeshDS();
1267 set<const SMDS_MeshElement*> elements;
1268 for (int i = 0; i < theIDsOfElements.length(); i++)
1270 CORBA::Long index = theIDsOfElements[i];
1271 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1273 elements.insert( elem );
1276 const SMESH::PointStruct * P = &theVector.PS;
1277 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
1279 ::SMESH_MeshEditor anEditor( _myMesh );
1280 anEditor.Transform (elements, aTrsf, theCopy);
1282 // Update Python script
1283 TCollection_AsciiString str = "vector = SMESH.DirStruct( SMESH.PointStruct ( ";
1284 str += (TCollection_AsciiString) P->x + ", ";
1285 str += (TCollection_AsciiString) P->y + ", ";
1286 str += (TCollection_AsciiString) P->z + " ))";
1287 SMESH_Gen_i::AddToCurrentPyScript( str );
1288 str = ("mesh_editor.Translate(");
1289 SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", vector, ";
1290 str += (TCollection_AsciiString) theCopy + " )";
1291 SMESH_Gen_i::AddToCurrentPyScript( str );
1294 //=======================================================================
1295 //function : TranslateObject
1297 //=======================================================================
1299 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
1300 const SMESH::DirStruct & theVector,
1301 CORBA::Boolean theCopy)
1303 SMESH::long_array_var anElementsId = theObject->GetIDs();
1304 Translate(anElementsId, theVector, theCopy);
1306 // Clear python line, created by Translate()
1307 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1308 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1310 // Update Python script
1311 TCollection_AsciiString str ("mesh_editor.TranslateObject(");
1312 SMESH_Gen_i::AddObject( str, theObject ) += ", vector, ";
1313 str += TCollection_AsciiString( theCopy ) + " )";
1314 SMESH_Gen_i::AddToCurrentPyScript( str );
1317 //=======================================================================
1320 //=======================================================================
1322 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
1323 const SMESH::AxisStruct & theAxis,
1324 CORBA::Double theAngle,
1325 CORBA::Boolean theCopy)
1327 SMESHDS_Mesh* aMesh = GetMeshDS();
1329 set<const SMDS_MeshElement*> elements;
1330 for (int i = 0; i < theIDsOfElements.length(); i++)
1332 CORBA::Long index = theIDsOfElements[i];
1333 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1335 elements.insert( elem );
1337 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
1338 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
1341 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
1343 ::SMESH_MeshEditor anEditor( _myMesh );
1344 anEditor.Transform (elements, aTrsf, theCopy);
1346 // Update Python script
1347 TCollection_AsciiString str ("axis = ");
1348 addAxis( str, theAxis );
1349 SMESH_Gen_i::AddToCurrentPyScript( str );
1350 str = ("mesh_editor.Rotate(");
1351 SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", axis, ";
1352 str += (TCollection_AsciiString) theAngle + ", ";
1353 str += (TCollection_AsciiString) theCopy + " )";
1354 SMESH_Gen_i::AddToCurrentPyScript( str );
1357 //=======================================================================
1358 //function : RotateObject
1360 //=======================================================================
1362 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
1363 const SMESH::AxisStruct & theAxis,
1364 CORBA::Double theAngle,
1365 CORBA::Boolean theCopy)
1367 SMESH::long_array_var anElementsId = theObject->GetIDs();
1368 Rotate(anElementsId, theAxis, theAngle, theCopy);
1370 // Clear python line, created by Rotate()
1371 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1372 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1374 // Update Python script
1375 TCollection_AsciiString str ("mesh_editor.RotateObject(");
1376 SMESH_Gen_i::AddObject( str, theObject ) += ", axis, ";
1377 str += TCollection_AsciiString( theAngle ) + ", ";
1378 str += TCollection_AsciiString( theCopy ) + " )";
1379 SMESH_Gen_i::AddToCurrentPyScript( str );
1382 //=======================================================================
1383 //function : FindCoincidentNodes
1385 //=======================================================================
1387 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
1388 SMESH::array_of_long_array_out GroupsOfNodes)
1390 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
1391 ::SMESH_MeshEditor anEditor( _myMesh );
1392 set<const SMDS_MeshNode*> nodes; // no input nodes
1393 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
1395 GroupsOfNodes = new SMESH::array_of_long_array;
1396 GroupsOfNodes->length( aListOfListOfNodes.size() );
1397 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
1398 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
1400 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
1401 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
1402 SMESH::long_array& aGroup = GroupsOfNodes[ i ];
1403 aGroup.length( aListOfNodes.size() );
1404 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
1405 aGroup[ j ] = (*lIt)->GetID();
1409 //=======================================================================
1410 //function : MergeNodes
1412 //=======================================================================
1414 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
1416 SMESHDS_Mesh* aMesh = GetMeshDS();
1418 TCollection_AsciiString str( "mesh_editor.MergeNodes([" );
1419 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
1420 for (int i = 0; i < GroupsOfNodes.length(); i++)
1422 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
1423 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
1424 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
1425 for ( int j = 0; j < aNodeGroup.length(); j++ )
1427 CORBA::Long index = aNodeGroup[ j ];
1428 const SMDS_MeshNode * node = aMesh->FindNode(index);
1430 aListOfNodes.push_back( node );
1432 if ( aListOfNodes.size() < 2 )
1433 aListOfListOfNodes.pop_back();
1437 SMESH_Gen_i::AddArray( str, aNodeGroup );
1439 ::SMESH_MeshEditor anEditor( _myMesh );
1440 anEditor.MergeNodes( aListOfListOfNodes );
1442 // Update Python script
1443 SMESH_Gen_i::AddToCurrentPyScript( str + "])" );
1446 //=======================================================================
1447 //function : MergeEqualElements
1449 //=======================================================================
1451 void SMESH_MeshEditor_i::MergeEqualElements()
1453 ::SMESH_MeshEditor anEditor( _myMesh );
1454 anEditor.MergeEqualElements();
1456 // Update Python script
1457 SMESH_Gen_i::AddToCurrentPyScript( "mesh_editor.MergeEqualElements()" );
1460 //=======================================================================
1461 //function : operator
1463 //=======================================================================
1465 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1467 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
1471 RETCASE( SEW_BORDER1_NOT_FOUND );
1472 RETCASE( SEW_BORDER2_NOT_FOUND );
1473 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
1474 RETCASE( SEW_BAD_SIDE_NODES );
1475 RETCASE( SEW_VOLUMES_TO_SPLIT );
1476 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
1477 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
1478 RETCASE( SEW_BAD_SIDE1_NODES );
1479 RETCASE( SEW_BAD_SIDE2_NODES );
1481 return SMESH::SMESH_MeshEditor::SEW_OK;
1484 //=======================================================================
1485 //function : SewFreeBorders
1487 //=======================================================================
1489 SMESH::SMESH_MeshEditor::Sew_Error
1490 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
1491 CORBA::Long SecondNodeID1,
1492 CORBA::Long LastNodeID1,
1493 CORBA::Long FirstNodeID2,
1494 CORBA::Long SecondNodeID2,
1495 CORBA::Long LastNodeID2,
1496 CORBA::Boolean CreatePolygons,
1497 CORBA::Boolean CreatePolyedrs)
1499 SMESHDS_Mesh* aMesh = GetMeshDS();
1501 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
1502 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
1503 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
1504 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
1505 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
1506 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
1508 if (!aBorderFirstNode ||
1509 !aBorderSecondNode||
1511 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1512 if (!aSide2FirstNode ||
1513 !aSide2SecondNode ||
1515 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
1517 // Update Python script
1518 TCollection_AsciiString str ("error = mesh_editor.SewFreeBorders( ");
1519 str += TCollection_AsciiString( (int) FirstNodeID1 ) + ", ";
1520 str += TCollection_AsciiString( (int) SecondNodeID1 ) + ", ";
1521 str += TCollection_AsciiString( (int) LastNodeID1 ) + ", ";
1522 str += TCollection_AsciiString( (int) FirstNodeID2 ) + ", ";
1523 str += TCollection_AsciiString( (int) SecondNodeID2 ) + ", ";
1524 str += TCollection_AsciiString( (int) LastNodeID2 ) + ", ";
1525 str += TCollection_AsciiString( CreatePolygons ) + ", ";
1526 str += TCollection_AsciiString( CreatePolyedrs ) + ") ";
1527 SMESH_Gen_i::AddToCurrentPyScript( str );
1529 ::SMESH_MeshEditor anEditor( _myMesh );
1530 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
1541 //=======================================================================
1542 //function : SewConformFreeBorders
1544 //=======================================================================
1546 SMESH::SMESH_MeshEditor::Sew_Error
1547 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
1548 CORBA::Long SecondNodeID1,
1549 CORBA::Long LastNodeID1,
1550 CORBA::Long FirstNodeID2,
1551 CORBA::Long SecondNodeID2)
1553 SMESHDS_Mesh* aMesh = GetMeshDS();
1555 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
1556 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
1557 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
1558 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
1559 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
1560 const SMDS_MeshNode* aSide2ThirdNode = 0;
1562 if (!aBorderFirstNode ||
1563 !aBorderSecondNode||
1565 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1566 if (!aSide2FirstNode ||
1568 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
1570 // Update Python script
1571 TCollection_AsciiString str ("error = mesh_editor.SewConformFreeBorders( ");
1572 str += TCollection_AsciiString( (int) FirstNodeID1 ) + ", ";
1573 str += TCollection_AsciiString( (int) SecondNodeID1 ) + ", ";
1574 str += TCollection_AsciiString( (int) LastNodeID1 ) + ", ";
1575 str += TCollection_AsciiString( (int) FirstNodeID2 ) + ", ";
1576 str += TCollection_AsciiString( (int) SecondNodeID2 ) + ")";
1577 SMESH_Gen_i::AddToCurrentPyScript( str );
1579 ::SMESH_MeshEditor anEditor( _myMesh );
1580 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
1590 //=======================================================================
1591 //function : SewBorderToSide
1593 //=======================================================================
1595 SMESH::SMESH_MeshEditor::Sew_Error
1596 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
1597 CORBA::Long SecondNodeIDOnFreeBorder,
1598 CORBA::Long LastNodeIDOnFreeBorder,
1599 CORBA::Long FirstNodeIDOnSide,
1600 CORBA::Long LastNodeIDOnSide,
1601 CORBA::Boolean CreatePolygons,
1602 CORBA::Boolean CreatePolyedrs)
1604 SMESHDS_Mesh* aMesh = GetMeshDS();
1606 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
1607 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
1608 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
1609 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
1610 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
1611 const SMDS_MeshNode* aSide2ThirdNode = 0;
1613 if (!aBorderFirstNode ||
1614 !aBorderSecondNode||
1616 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1617 if (!aSide2FirstNode ||
1619 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
1621 // Update Python script
1622 TCollection_AsciiString str ("error = mesh_editor.SewBorderToSide( ");
1623 str += TCollection_AsciiString( (int) FirstNodeIDOnFreeBorder ) + ", ";
1624 str += TCollection_AsciiString( (int) SecondNodeIDOnFreeBorder ) + ", ";
1625 str += TCollection_AsciiString( (int) LastNodeIDOnFreeBorder ) + ", ";
1626 str += TCollection_AsciiString( (int) FirstNodeIDOnSide ) + ", ";
1627 str += TCollection_AsciiString( (int) LastNodeIDOnSide ) + ", ";
1628 str += TCollection_AsciiString( CreatePolygons ) + ", ";
1629 str += TCollection_AsciiString( CreatePolyedrs ) + ") ";
1630 SMESH_Gen_i::AddToCurrentPyScript( str );
1632 ::SMESH_MeshEditor anEditor( _myMesh );
1633 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
1644 //=======================================================================
1645 //function : SewSideElements
1647 //=======================================================================
1649 SMESH::SMESH_MeshEditor::Sew_Error
1650 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
1651 const SMESH::long_array& IDsOfSide2Elements,
1652 CORBA::Long NodeID1OfSide1ToMerge,
1653 CORBA::Long NodeID1OfSide2ToMerge,
1654 CORBA::Long NodeID2OfSide1ToMerge,
1655 CORBA::Long NodeID2OfSide2ToMerge)
1657 SMESHDS_Mesh* aMesh = GetMeshDS();
1659 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
1660 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
1661 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
1662 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
1664 if (!aFirstNode1ToMerge ||
1665 !aFirstNode2ToMerge )
1666 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
1667 if (!aSecondNode1ToMerge||
1668 !aSecondNode2ToMerge)
1669 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
1671 set<const SMDS_MeshElement*> aSide1Elems, aSide2Elems;
1672 for (int i = 0; i < IDsOfSide1Elements.length(); i++)
1674 CORBA::Long index = IDsOfSide1Elements[i];
1675 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1677 aSide1Elems.insert( elem );
1679 for (int i = 0; i < IDsOfSide2Elements.length(); i++)
1681 CORBA::Long index = IDsOfSide2Elements[i];
1682 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1684 aSide2Elems.insert( elem );
1686 // Update Python script
1687 TCollection_AsciiString str ("error = mesh_editor.SewSideElements( ");
1688 SMESH_Gen_i::AddArray( str, IDsOfSide1Elements ) += ", ";
1689 SMESH_Gen_i::AddArray( str, IDsOfSide2Elements ) += ", ";
1690 str += TCollection_AsciiString( (int) NodeID1OfSide1ToMerge ) + ", ";
1691 str += TCollection_AsciiString( (int) NodeID1OfSide2ToMerge ) + ", ";
1692 str += TCollection_AsciiString( (int) NodeID2OfSide1ToMerge ) + ", ";
1693 str += TCollection_AsciiString( (int) NodeID2OfSide2ToMerge ) + ")";
1694 SMESH_Gen_i::AddToCurrentPyScript( str );
1696 ::SMESH_MeshEditor anEditor( _myMesh );
1697 return convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
1700 aSecondNode1ToMerge,
1701 aSecondNode2ToMerge));