1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_MeshEditor_i.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESH_MeshEditor_i.hxx"
31 #include "SMDS_MeshEdge.hxx"
32 #include "SMDS_MeshFace.hxx"
33 #include "SMDS_MeshVolume.hxx"
35 #include "SMESH_MeshEditor.hxx"
37 #include "SMESH_Gen_i.hxx"
38 #include "SMESH_Filter_i.hxx"
39 #include "SMESH_PythonDump.hxx"
40 #include "CASCatch.hxx"
42 #include "utilities.h"
50 typedef map<const SMDS_MeshElement*,
51 list<const SMDS_MeshElement*> > TElemOfElemListMap;
54 using SMESH::TPythonDump;
56 //=============================================================================
60 //=============================================================================
62 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh* theMesh)
67 //=============================================================================
71 //=============================================================================
74 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
76 myLastCreatedElems = new SMESH::long_array();
77 myLastCreatedNodes = new SMESH::long_array();
79 ::SMESH_MeshEditor anEditor( _myMesh );
82 for (int i = 0; i < IDsOfElements.length(); i++)
83 IdList.push_back( IDsOfElements[i] );
85 // Update Python script
86 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
88 TPythonDump() << "print 'RemoveElements: ', isDone";
91 return anEditor.Remove( IdList, false );
94 //=============================================================================
98 //=============================================================================
100 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
102 myLastCreatedElems = new SMESH::long_array();
103 myLastCreatedNodes = new SMESH::long_array();
105 ::SMESH_MeshEditor anEditor( _myMesh );
107 for (int i = 0; i < IDsOfNodes.length(); i++)
108 IdList.push_back( IDsOfNodes[i] );
110 // Update Python script
111 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
113 TPythonDump() << "print 'RemoveNodes: ', isDone";
116 return anEditor.Remove( IdList, true );
119 //=============================================================================
123 //=============================================================================
125 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
127 myLastCreatedElems = new SMESH::long_array();
128 myLastCreatedNodes = new SMESH::long_array();
130 int NbNodes = IDsOfNodes.length();
131 SMDS_MeshElement* elem = 0;
134 CORBA::Long index1 = IDsOfNodes[0];
135 CORBA::Long index2 = IDsOfNodes[1];
136 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
138 // Update Python script
139 TPythonDump() << "edge = " << this << ".AddEdge([ "
140 << index1 << ", " << index2 <<" ])";
143 CORBA::Long n1 = IDsOfNodes[0];
144 CORBA::Long n2 = IDsOfNodes[1];
145 CORBA::Long n12 = IDsOfNodes[2];
146 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
147 GetMeshDS()->FindNode(n2),
148 GetMeshDS()->FindNode(n12));
149 // Update Python script
150 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
151 <<n1<<", "<<n2<<", "<<n12<<" ])";
155 return elem->GetID();
160 //=============================================================================
164 //=============================================================================
166 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
167 CORBA::Double y, CORBA::Double z)
169 myLastCreatedElems = new SMESH::long_array();
170 myLastCreatedNodes = new SMESH::long_array();
172 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
174 // Update Python script
175 TPythonDump() << "nodeID = " << this << ".AddNode( "
176 << x << ", " << y << ", " << z << " )";
181 //=============================================================================
185 //=============================================================================
187 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
189 myLastCreatedElems = new SMESH::long_array();
190 myLastCreatedNodes = new SMESH::long_array();
192 int NbNodes = IDsOfNodes.length();
198 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
199 for (int i = 0; i < NbNodes; i++)
200 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
202 SMDS_MeshElement* elem = 0;
204 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
206 else if (NbNodes == 4) {
207 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
209 else if (NbNodes == 6) {
210 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
213 else if (NbNodes == 8) {
214 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
215 nodes[4], nodes[5], nodes[6], nodes[7]);
218 // Update Python script
219 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
222 return elem->GetID();
227 //=============================================================================
231 //=============================================================================
232 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace
233 (const SMESH::long_array & IDsOfNodes)
235 myLastCreatedElems = new SMESH::long_array();
236 myLastCreatedNodes = new SMESH::long_array();
238 int NbNodes = IDsOfNodes.length();
239 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
240 for (int i = 0; i < NbNodes; i++)
241 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
243 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
245 // Update Python script
246 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
248 TPythonDump() << "print 'AddPolygonalFace: ', faceID";
252 return elem->GetID();
257 //=============================================================================
261 //=============================================================================
263 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
265 myLastCreatedElems = new SMESH::long_array();
266 myLastCreatedNodes = new SMESH::long_array();
268 int NbNodes = IDsOfNodes.length();
269 vector< const SMDS_MeshNode*> n(NbNodes);
270 for(int i=0;i<NbNodes;i++)
271 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
273 SMDS_MeshElement* elem = 0;
276 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
277 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
278 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
279 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
280 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
281 n[6],n[7],n[8],n[9]);
283 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
284 n[7],n[8],n[9],n[10],n[11],n[12]);
286 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
287 n[9],n[10],n[11],n[12],n[13],n[14]);
289 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
290 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
291 n[15],n[16],n[17],n[18],n[19]);
295 // Update Python script
296 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
298 TPythonDump() << "print 'AddVolume: ', volID";
302 return elem->GetID();
307 //=============================================================================
309 * AddPolyhedralVolume
311 //=============================================================================
312 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume
313 (const SMESH::long_array & IDsOfNodes,
314 const SMESH::long_array & Quantities)
316 myLastCreatedElems = new SMESH::long_array();
317 myLastCreatedNodes = new SMESH::long_array();
319 int NbNodes = IDsOfNodes.length();
320 std::vector<const SMDS_MeshNode*> n (NbNodes);
321 for (int i = 0; i < NbNodes; i++)
322 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
324 int NbFaces = Quantities.length();
325 std::vector<int> q (NbFaces);
326 for (int j = 0; j < NbFaces; j++)
327 q[j] = Quantities[j];
329 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
331 // Update Python script
332 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
333 << IDsOfNodes << ", " << Quantities << " )";
335 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
339 return elem->GetID();
344 //=============================================================================
346 * AddPolyhedralVolumeByFaces
348 //=============================================================================
349 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
350 (const SMESH::long_array & IdsOfFaces)
352 myLastCreatedElems = new SMESH::long_array();
353 myLastCreatedNodes = new SMESH::long_array();
355 int NbFaces = IdsOfFaces.length();
356 std::vector<const SMDS_MeshNode*> poly_nodes;
357 std::vector<int> quantities (NbFaces);
359 for (int i = 0; i < NbFaces; i++) {
360 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
361 quantities[i] = aFace->NbNodes();
363 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
365 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
369 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
371 // Update Python script
372 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
373 << IdsOfFaces << " )";
375 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
379 return elem->GetID();
384 //=============================================================================
388 //=============================================================================
390 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
395 myLastCreatedElems = new SMESH::long_array();
396 myLastCreatedNodes = new SMESH::long_array();
398 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
402 GetMeshDS()->MoveNode(node, x, y, z);
404 // Update Python script
405 TPythonDump() << "isDone = " << this << ".MoveNode( "
406 << NodeID << ", " << x << ", " << y << ", " << z << " )";
411 //=============================================================================
415 //=============================================================================
417 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
420 myLastCreatedElems = new SMESH::long_array();
421 myLastCreatedNodes = new SMESH::long_array();
423 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
424 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
428 // Update Python script
429 TPythonDump() << "isDone = " << this << ".InverseDiag( "
430 << NodeID1 << ", " << NodeID2 << " )";
432 ::SMESH_MeshEditor aMeshEditor( _myMesh );
433 return aMeshEditor.InverseDiag ( n1, n2 );
436 //=============================================================================
440 //=============================================================================
442 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
445 myLastCreatedElems = new SMESH::long_array();
446 myLastCreatedNodes = new SMESH::long_array();
448 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
449 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
453 // Update Python script
454 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
455 << NodeID1 << ", " << NodeID2 << " )";
457 ::SMESH_MeshEditor aMeshEditor( _myMesh );
459 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
461 UpdateLastResult(aMeshEditor);
466 //=============================================================================
470 //=============================================================================
472 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
474 myLastCreatedElems = new SMESH::long_array();
475 myLastCreatedNodes = new SMESH::long_array();
477 ::SMESH_MeshEditor anEditor( _myMesh );
478 for (int i = 0; i < IDsOfElements.length(); i++)
480 CORBA::Long index = IDsOfElements[i];
481 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
483 anEditor.Reorient( elem );
485 // Update Python script
486 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
492 //=============================================================================
496 //=============================================================================
498 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
500 myLastCreatedElems = new SMESH::long_array();
501 myLastCreatedNodes = new SMESH::long_array();
503 SMESH::long_array_var anElementsId = theObject->GetIDs();
504 CORBA::Boolean isDone = Reorient(anElementsId);
506 // Clear python line, created by Reorient()
507 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
508 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
510 // Update Python script
511 TPythonDump() << "isDone = " << this << ".ReorientObject( " << theObject << " )";
517 //=======================================================================
519 //purpose : auxilary function for conversion long_array to std::map<>
520 // which is used in some methods
521 //=======================================================================
522 static void ToMap(const SMESH::long_array & IDs,
523 const SMESHDS_Mesh* aMesh,
524 std::map<int,const SMDS_MeshElement*>& aMap)
526 for (int i=0; i<IDs.length(); i++) {
527 CORBA::Long ind = IDs[i];
528 std::map<int,const SMDS_MeshElement*>::iterator It = aMap.find(ind);
530 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
531 aMap.insert( make_pair(ind,elem) );
537 //=============================================================================
541 //=============================================================================
542 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
543 SMESH::NumericalFunctor_ptr Criterion,
544 CORBA::Double MaxAngle)
546 myLastCreatedElems = new SMESH::long_array();
547 myLastCreatedNodes = new SMESH::long_array();
549 SMESHDS_Mesh* aMesh = GetMeshDS();
550 map<int,const SMDS_MeshElement*> faces;
551 ToMap(IDsOfElements, aMesh, faces);
553 SMESH::NumericalFunctor_i* aNumericalFunctor =
554 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
555 SMESH::Controls::NumericalFunctorPtr aCrit;
556 if ( !aNumericalFunctor )
557 aCrit.reset( new SMESH::Controls::AspectRatio() );
559 aCrit = aNumericalFunctor->GetNumericalFunctor();
561 // Update Python script
562 TPythonDump() << "isDone = " << this << ".TriToQuad( "
563 << IDsOfElements << ", None, " << MaxAngle << " )";
565 TPythonDump() << "print 'TriToQuad: ', isDone";
568 ::SMESH_MeshEditor anEditor( _myMesh );
570 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
572 UpdateLastResult(anEditor);
578 //=============================================================================
582 //=============================================================================
583 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
584 SMESH::NumericalFunctor_ptr Criterion,
585 CORBA::Double MaxAngle)
587 myLastCreatedElems = new SMESH::long_array();
588 myLastCreatedNodes = new SMESH::long_array();
590 SMESH::long_array_var anElementsId = theObject->GetIDs();
591 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
593 // Clear python line(s), created by TriToQuad()
594 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
595 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
597 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
600 // Update Python script
601 TPythonDump() << "isDone = " << this << ".TriToQuadObject("
602 << theObject << ", None, " << MaxAngle << " )";
604 TPythonDump() << "print 'TriToQuadObject: ', isDone";
611 //=============================================================================
615 //=============================================================================
616 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
617 SMESH::NumericalFunctor_ptr Criterion)
619 myLastCreatedElems = new SMESH::long_array();
620 myLastCreatedNodes = new SMESH::long_array();
622 SMESHDS_Mesh* aMesh = GetMeshDS();
623 map<int,const SMDS_MeshElement*> faces;
624 ToMap(IDsOfElements, aMesh, faces);
626 SMESH::NumericalFunctor_i* aNumericalFunctor =
627 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
628 SMESH::Controls::NumericalFunctorPtr aCrit;
629 if ( !aNumericalFunctor )
630 aCrit.reset( new SMESH::Controls::AspectRatio() );
632 aCrit = aNumericalFunctor->GetNumericalFunctor();
635 // Update Python script
636 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", None )";
638 TPythonDump() << "print 'QuadToTri: ', isDone";
641 ::SMESH_MeshEditor anEditor( _myMesh );
642 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
644 UpdateLastResult(anEditor);
650 //=============================================================================
654 //=============================================================================
655 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
656 SMESH::NumericalFunctor_ptr Criterion)
658 myLastCreatedElems = new SMESH::long_array();
659 myLastCreatedNodes = new SMESH::long_array();
661 SMESH::long_array_var anElementsId = theObject->GetIDs();
662 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
664 // Clear python line(s), created by QuadToTri()
665 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
666 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
668 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
671 // Update Python script
672 TPythonDump() << "isDone = " << this << ".QuadToTriObject(" << theObject << ", None )";
674 TPythonDump() << "print 'QuadToTriObject: ', isDone";
681 //=============================================================================
685 //=============================================================================
686 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
687 CORBA::Boolean Diag13)
689 myLastCreatedElems = new SMESH::long_array();
690 myLastCreatedNodes = new SMESH::long_array();
692 SMESHDS_Mesh* aMesh = GetMeshDS();
693 map<int,const SMDS_MeshElement*> faces;
694 ToMap(IDsOfElements, aMesh, faces);
696 // Update Python script
697 TPythonDump() << "isDone = " << this << ".SplitQuad( "
698 << IDsOfElements << ", " << Diag13 << " )";
700 TPythonDump() << "print 'SplitQuad: ', isDone";
703 ::SMESH_MeshEditor anEditor( _myMesh );
704 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
706 UpdateLastResult(anEditor);
712 //=============================================================================
716 //=============================================================================
717 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
718 CORBA::Boolean Diag13)
720 myLastCreatedElems = new SMESH::long_array();
721 myLastCreatedNodes = new SMESH::long_array();
723 SMESH::long_array_var anElementsId = theObject->GetIDs();
724 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
726 // Clear python line(s), created by SplitQuad()
727 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
728 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
730 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
733 // Update Python script
734 TPythonDump() << "isDone = " << this << ".SplitQuadObject( "
735 << theObject << ", " << Diag13 << " )";
737 TPythonDump() << "print 'SplitQuadObject: ', isDone";
744 //=============================================================================
748 //=============================================================================
749 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
750 SMESH::NumericalFunctor_ptr Criterion)
752 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
753 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
755 SMESH::NumericalFunctor_i* aNumericalFunctor =
756 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
757 SMESH::Controls::NumericalFunctorPtr aCrit;
758 if (aNumericalFunctor)
759 aCrit = aNumericalFunctor->GetNumericalFunctor();
761 aCrit.reset(new SMESH::Controls::AspectRatio());
763 ::SMESH_MeshEditor anEditor (_myMesh);
764 return anEditor.BestSplit(quad, aCrit);
770 //=======================================================================
773 //=======================================================================
776 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
777 const SMESH::long_array & IDsOfFixedNodes,
778 CORBA::Long MaxNbOfIterations,
779 CORBA::Double MaxAspectRatio,
780 SMESH::SMESH_MeshEditor::Smooth_Method Method)
782 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
783 MaxAspectRatio, Method, false );
787 //=======================================================================
788 //function : SmoothParametric
790 //=======================================================================
793 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
794 const SMESH::long_array & IDsOfFixedNodes,
795 CORBA::Long MaxNbOfIterations,
796 CORBA::Double MaxAspectRatio,
797 SMESH::SMESH_MeshEditor::Smooth_Method Method)
799 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
800 MaxAspectRatio, Method, true );
804 //=======================================================================
805 //function : SmoothObject
807 //=======================================================================
810 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
811 const SMESH::long_array & IDsOfFixedNodes,
812 CORBA::Long MaxNbOfIterations,
813 CORBA::Double MaxAspectRatio,
814 SMESH::SMESH_MeshEditor::Smooth_Method Method)
816 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
817 MaxAspectRatio, Method, false);
821 //=======================================================================
822 //function : SmoothParametricObject
824 //=======================================================================
827 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
828 const SMESH::long_array & IDsOfFixedNodes,
829 CORBA::Long MaxNbOfIterations,
830 CORBA::Double MaxAspectRatio,
831 SMESH::SMESH_MeshEditor::Smooth_Method Method)
833 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
834 MaxAspectRatio, Method, true);
838 //=============================================================================
842 //=============================================================================
845 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
846 const SMESH::long_array & IDsOfFixedNodes,
847 CORBA::Long MaxNbOfIterations,
848 CORBA::Double MaxAspectRatio,
849 SMESH::SMESH_MeshEditor::Smooth_Method Method,
852 myLastCreatedElems = new SMESH::long_array();
853 myLastCreatedNodes = new SMESH::long_array();
855 SMESHDS_Mesh* aMesh = GetMeshDS();
857 map<int,const SMDS_MeshElement*> elements;
858 ToMap(IDsOfElements, aMesh, elements);
860 set<const SMDS_MeshNode*> fixedNodes;
861 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
862 CORBA::Long index = IDsOfFixedNodes[i];
863 const SMDS_MeshNode * node = aMesh->FindNode(index);
865 fixedNodes.insert( node );
867 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
868 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
869 method = ::SMESH_MeshEditor::CENTROIDAL;
871 ::SMESH_MeshEditor anEditor( _myMesh );
872 anEditor.Smooth(elements, fixedNodes, method,
873 MaxNbOfIterations, MaxAspectRatio, IsParametric );
875 UpdateLastResult(anEditor);
877 // Update Python script
878 TPythonDump() << "isDone = " << this << "."
879 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
880 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
881 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
882 << "SMESH.SMESH_MeshEditor."
883 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
884 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
886 TPythonDump() << "print 'Smooth: ', isDone";
893 //=============================================================================
897 //=============================================================================
900 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
901 const SMESH::long_array & IDsOfFixedNodes,
902 CORBA::Long MaxNbOfIterations,
903 CORBA::Double MaxAspectRatio,
904 SMESH::SMESH_MeshEditor::Smooth_Method Method,
907 myLastCreatedElems = new SMESH::long_array();
908 myLastCreatedNodes = new SMESH::long_array();
910 SMESH::long_array_var anElementsId = theObject->GetIDs();
911 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
912 MaxAspectRatio, Method, IsParametric);
914 // Clear python line(s), created by Smooth()
915 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
916 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
918 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
921 // Update Python script
922 TPythonDump() << "isDone = " << this << "."
923 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
924 << theObject << ", " << IDsOfFixedNodes << ", "
925 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
926 << "SMESH.SMESH_MeshEditor."
927 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
928 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
930 TPythonDump() << "print 'SmoothObject: ', isDone";
937 //=============================================================================
941 //=============================================================================
943 void SMESH_MeshEditor_i::RenumberNodes()
945 // Update Python script
946 TPythonDump() << this << ".RenumberNodes()";
948 GetMeshDS()->Renumber( true );
952 //=============================================================================
956 //=============================================================================
958 void SMESH_MeshEditor_i::RenumberElements()
960 // Update Python script
961 TPythonDump() << this << ".RenumberElements()";
963 GetMeshDS()->Renumber( false );
967 //=======================================================================
968 //function : RotationSweep
970 //=======================================================================
972 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
973 const SMESH::AxisStruct & theAxis,
974 CORBA::Double theAngleInRadians,
975 CORBA::Long theNbOfSteps,
976 CORBA::Double theTolerance)
978 myLastCreatedElems = new SMESH::long_array();
979 myLastCreatedNodes = new SMESH::long_array();
981 SMESHDS_Mesh* aMesh = GetMeshDS();
983 map<int,const SMDS_MeshElement*> elements;
984 ToMap(theIDsOfElements, aMesh, elements);
986 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
987 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
989 ::SMESH_MeshEditor anEditor( _myMesh );
990 anEditor.RotationSweep (elements, Ax1, theAngleInRadians,
991 theNbOfSteps, theTolerance);
993 UpdateLastResult(anEditor);
995 // Update Python script
996 TPythonDump() << "axis = " << theAxis;
997 TPythonDump() << this << ".RotationSweep( "
1000 << theAngleInRadians << ", "
1001 << theNbOfSteps << ", "
1002 << theTolerance << " )";
1005 //=======================================================================
1006 //function : RotationSweepObject
1008 //=======================================================================
1010 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1011 const SMESH::AxisStruct & theAxis,
1012 CORBA::Double theAngleInRadians,
1013 CORBA::Long theNbOfSteps,
1014 CORBA::Double theTolerance)
1016 myLastCreatedElems = new SMESH::long_array();
1017 myLastCreatedNodes = new SMESH::long_array();
1019 SMESH::long_array_var anElementsId = theObject->GetIDs();
1020 RotationSweep(anElementsId, theAxis, theAngleInRadians, theNbOfSteps, theTolerance);
1022 // Clear python line, created by RotationSweep()
1023 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1024 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1026 // Update Python script
1027 TPythonDump() << this << ".RotationSweepObject( "
1030 << theAngleInRadians << ", "
1031 << theNbOfSteps << ", "
1032 << theTolerance << " )";
1035 //=======================================================================
1036 //function : ExtrusionSweep
1038 //=======================================================================
1040 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1041 const SMESH::DirStruct & theStepVector,
1042 CORBA::Long theNbOfSteps)
1044 myLastCreatedElems = new SMESH::long_array();
1045 myLastCreatedNodes = new SMESH::long_array();
1048 SMESHDS_Mesh* aMesh = GetMeshDS();
1050 map<int,const SMDS_MeshElement*> elements;
1051 ToMap(theIDsOfElements, aMesh, elements);
1053 const SMESH::PointStruct * P = &theStepVector.PS;
1054 gp_Vec stepVec( P->x, P->y, P->z );
1056 TElemOfElemListMap aHystory;
1057 ::SMESH_MeshEditor anEditor( _myMesh );
1058 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
1060 UpdateLastResult(anEditor);
1062 // Update Python script
1063 TPythonDump() << "stepVector = " << theStepVector;
1064 TPythonDump() << this << ".ExtrusionSweep( "
1065 << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1068 CASCatch_CATCH(Standard_Failure) {
1069 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1070 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1075 //=======================================================================
1076 //function : ExtrusionSweepObject
1078 //=======================================================================
1080 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1081 const SMESH::DirStruct & theStepVector,
1082 CORBA::Long theNbOfSteps)
1084 myLastCreatedElems = new SMESH::long_array();
1085 myLastCreatedNodes = new SMESH::long_array();
1087 SMESH::long_array_var anElementsId = theObject->GetIDs();
1088 ExtrusionSweep(anElementsId, theStepVector, theNbOfSteps);
1090 // Clear python line, created by ExtrusionSweep()
1091 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1092 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1094 // Update Python script
1095 TPythonDump() << this << ".ExtrusionSweepObject( "
1096 << theObject << ", stepVector, " << theNbOfSteps << " )";
1099 //=======================================================================
1100 //function : ExtrusionSweepObject1D
1102 //=======================================================================
1104 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1105 const SMESH::DirStruct & theStepVector,
1106 CORBA::Long theNbOfSteps)
1108 myLastCreatedElems = new SMESH::long_array();
1109 myLastCreatedNodes = new SMESH::long_array();
1111 SMESHDS_Mesh* aMesh = GetMeshDS();
1113 SMESH::long_array_var allElementsId = theObject->GetIDs();
1115 map<int,const SMDS_MeshElement*> elements;
1116 ToMap(allElementsId, aMesh, elements);
1118 const SMESH::PointStruct * P = &theStepVector.PS;
1119 gp_Vec stepVec( P->x, P->y, P->z );
1121 ::SMESH_MeshEditor anEditor( _myMesh );
1122 //anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
1123 TElemOfElemListMap aHystory;
1124 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
1126 UpdateLastResult(anEditor);
1128 // Update Python script
1129 TPythonDump() << "stepVector = " << theStepVector;
1130 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1131 << theObject << ", stepVector, " << theNbOfSteps << " )";
1134 //=======================================================================
1135 //function : ExtrusionSweepObject2D
1137 //=======================================================================
1139 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1140 const SMESH::DirStruct & theStepVector,
1141 CORBA::Long theNbOfSteps)
1143 myLastCreatedElems = new SMESH::long_array();
1144 myLastCreatedNodes = new SMESH::long_array();
1146 SMESHDS_Mesh* aMesh = GetMeshDS();
1148 SMESH::long_array_var allElementsId = theObject->GetIDs();
1150 map<int,const SMDS_MeshElement*> elements;
1151 ToMap(allElementsId, aMesh, elements);
1153 const SMESH::PointStruct * P = &theStepVector.PS;
1154 gp_Vec stepVec( P->x, P->y, P->z );
1156 ::SMESH_MeshEditor anEditor( _myMesh );
1157 //anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
1158 TElemOfElemListMap aHystory;
1159 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
1161 UpdateLastResult(anEditor);
1163 // Update Python script
1164 TPythonDump() << "stepVector = " << theStepVector;
1165 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1166 << theObject << ", stepVector, " << theNbOfSteps << " )";
1170 //=======================================================================
1171 //function : AdvancedExtrusion
1173 //=======================================================================
1175 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1176 const SMESH::DirStruct & theStepVector,
1177 CORBA::Long theNbOfSteps,
1178 CORBA::Long theExtrFlags,
1179 CORBA::Double theSewTolerance)
1181 myLastCreatedElems = new SMESH::long_array();
1182 myLastCreatedNodes = new SMESH::long_array();
1184 SMESHDS_Mesh* aMesh = GetMeshDS();
1186 map<int,const SMDS_MeshElement*> elements;
1187 ToMap(theIDsOfElements, aMesh, elements);
1189 const SMESH::PointStruct * P = &theStepVector.PS;
1190 gp_Vec stepVec( P->x, P->y, P->z );
1192 ::SMESH_MeshEditor anEditor( _myMesh );
1193 TElemOfElemListMap aHystory;
1194 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1195 theExtrFlags, theSewTolerance);
1197 UpdateLastResult(anEditor);
1199 // Update Python script
1200 TPythonDump() << "stepVector = " << theStepVector;
1201 TPythonDump() << this << ".AdvancedExtrusion("
1204 << theNbOfSteps << ","
1205 << theExtrFlags << ", "
1206 << theSewTolerance << " )";
1210 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1212 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1216 RETCASE( EXTR_NO_ELEMENTS );
1217 RETCASE( EXTR_PATH_NOT_EDGE );
1218 RETCASE( EXTR_BAD_PATH_SHAPE );
1219 RETCASE( EXTR_BAD_STARTING_NODE );
1220 RETCASE( EXTR_BAD_ANGLES_NUMBER );
1221 RETCASE( EXTR_CANT_GET_TANGENT );
1223 return SMESH::SMESH_MeshEditor::EXTR_OK;
1226 //=======================================================================
1227 //function : ExtrusionAlongPath
1229 //=======================================================================
1231 SMESH::SMESH_MeshEditor::Extrusion_Error
1232 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1233 SMESH::SMESH_Mesh_ptr thePathMesh,
1234 GEOM::GEOM_Object_ptr thePathShape,
1235 CORBA::Long theNodeStart,
1236 CORBA::Boolean theHasAngles,
1237 const SMESH::double_array & theAngles,
1238 CORBA::Boolean theHasRefPoint,
1239 const SMESH::PointStruct & theRefPoint)
1241 myLastCreatedElems = new SMESH::long_array();
1242 myLastCreatedNodes = new SMESH::long_array();
1244 SMESHDS_Mesh* aMesh = GetMeshDS();
1246 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() )
1247 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1249 SMESH_Mesh_i* aMeshImp = dynamic_cast<SMESH_Mesh_i*>( SMESH_Gen_i::GetServant( thePathMesh ).in() );
1250 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1251 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1253 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
1254 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1256 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
1258 return SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
1260 map<int,const SMDS_MeshElement*> elements;
1261 ToMap(theIDsOfElements, aMesh, elements);
1263 list<double> angles;
1264 for (int i = 0; i < theAngles.length(); i++) {
1265 angles.push_back( theAngles[i] );
1268 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
1270 // Update Python script
1271 TPythonDump() << "refPoint = SMESH.PointStruct( "
1272 << refPnt.X() << ", "
1273 << refPnt.Y() << ", "
1274 << refPnt.Z() << " )";
1275 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
1276 << theIDsOfElements << ", "
1277 << thePathMesh << ", "
1278 << thePathShape << ", "
1279 << theNodeStart << ", "
1280 << theHasAngles << ", "
1281 << theAngles << ", "
1282 << theHasRefPoint << ", refPoint )";
1284 ::SMESH_MeshEditor anEditor( _myMesh );
1285 SMESH::SMESH_MeshEditor::Extrusion_Error error =
1286 convExtrError( anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
1287 theHasAngles, angles,
1288 theHasRefPoint, refPnt ) );
1290 UpdateLastResult(anEditor);
1295 //=======================================================================
1296 //function : ExtrusionAlongPathObject
1298 //=======================================================================
1300 SMESH::SMESH_MeshEditor::Extrusion_Error
1301 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
1302 SMESH::SMESH_Mesh_ptr thePathMesh,
1303 GEOM::GEOM_Object_ptr thePathShape,
1304 CORBA::Long theNodeStart,
1305 CORBA::Boolean theHasAngles,
1306 const SMESH::double_array & theAngles,
1307 CORBA::Boolean theHasRefPoint,
1308 const SMESH::PointStruct & theRefPoint)
1310 myLastCreatedElems = new SMESH::long_array();
1311 myLastCreatedNodes = new SMESH::long_array();
1313 SMESH::long_array_var anElementsId = theObject->GetIDs();
1314 SMESH::SMESH_MeshEditor::Extrusion_Error error = ExtrusionAlongPath
1315 (anElementsId, thePathMesh, thePathShape, theNodeStart,
1316 theHasAngles, theAngles, theHasRefPoint, theRefPoint);
1318 // Clear python line, created by ExtrusionAlongPath()
1319 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1320 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1322 // Update Python script
1323 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
1324 << theObject << ", "
1325 << thePathMesh << ", "
1326 << thePathShape << ", "
1327 << theNodeStart << ", "
1328 << theHasAngles << ", "
1329 << theAngles << ", "
1330 << theHasRefPoint << ", refPoint )";
1335 //=======================================================================
1338 //=======================================================================
1340 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
1341 const SMESH::AxisStruct & theAxis,
1342 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
1343 CORBA::Boolean theCopy)
1345 myLastCreatedElems = new SMESH::long_array();
1346 myLastCreatedNodes = new SMESH::long_array();
1348 SMESHDS_Mesh* aMesh = GetMeshDS();
1350 map<int,const SMDS_MeshElement*> elements;
1351 ToMap(theIDsOfElements, aMesh, elements);
1353 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
1354 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
1357 TCollection_AsciiString typeStr;
1358 switch ( theMirrorType ) {
1359 case SMESH::SMESH_MeshEditor::POINT:
1360 aTrsf.SetMirror( P );
1361 typeStr = "SMESH.SMESH_MeshEditor.POINT";
1363 case SMESH::SMESH_MeshEditor::AXIS:
1364 aTrsf.SetMirror( gp_Ax1( P, V ));
1365 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
1368 aTrsf.SetMirror( gp_Ax2( P, V ));
1369 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
1372 // Update Python script
1373 TPythonDump() << this << ".Mirror( "
1374 << theIDsOfElements << ", "
1379 ::SMESH_MeshEditor anEditor( _myMesh );
1380 anEditor.Transform (elements, aTrsf, theCopy);
1383 UpdateLastResult(anEditor);
1388 //=======================================================================
1389 //function : MirrorObject
1391 //=======================================================================
1393 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
1394 const SMESH::AxisStruct & theAxis,
1395 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
1396 CORBA::Boolean theCopy)
1398 myLastCreatedElems = new SMESH::long_array();
1399 myLastCreatedNodes = new SMESH::long_array();
1401 SMESH::long_array_var anElementsId = theObject->GetIDs();
1402 Mirror(anElementsId, theAxis, theMirrorType, theCopy);
1404 // Clear python line, created by Mirror()
1405 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1406 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1408 // Update Python script
1409 TCollection_AsciiString typeStr;
1410 switch ( theMirrorType ) {
1411 case SMESH::SMESH_MeshEditor::POINT:
1412 typeStr = "SMESH.SMESH_MeshEditor.POINT";
1414 case SMESH::SMESH_MeshEditor::AXIS:
1415 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
1418 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
1420 TPythonDump() << "axis = " << theAxis;
1421 TPythonDump() << this << ".MirrorObject( "
1422 << theObject << ", "
1428 //=======================================================================
1429 //function : Translate
1431 //=======================================================================
1433 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
1434 const SMESH::DirStruct & theVector,
1435 CORBA::Boolean theCopy)
1437 myLastCreatedElems = new SMESH::long_array();
1438 myLastCreatedNodes = new SMESH::long_array();
1440 SMESHDS_Mesh* aMesh = GetMeshDS();
1442 map<int,const SMDS_MeshElement*> elements;
1443 ToMap(theIDsOfElements, aMesh, elements);
1446 const SMESH::PointStruct * P = &theVector.PS;
1447 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
1449 ::SMESH_MeshEditor anEditor( _myMesh );
1450 anEditor.Transform (elements, aTrsf, theCopy);
1453 UpdateLastResult(anEditor);
1456 // Update Python script
1457 TPythonDump() << "vector = " << theVector;
1458 TPythonDump() << this << ".Translate( "
1464 //=======================================================================
1465 //function : TranslateObject
1467 //=======================================================================
1469 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
1470 const SMESH::DirStruct & theVector,
1471 CORBA::Boolean theCopy)
1473 myLastCreatedElems = new SMESH::long_array();
1474 myLastCreatedNodes = new SMESH::long_array();
1476 SMESH::long_array_var anElementsId = theObject->GetIDs();
1477 Translate(anElementsId, theVector, theCopy);
1479 // Clear python line, created by Translate()
1480 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1481 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1483 // Update Python script
1484 TPythonDump() << this << ".TranslateObject( "
1490 //=======================================================================
1493 //=======================================================================
1495 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
1496 const SMESH::AxisStruct & theAxis,
1497 CORBA::Double theAngle,
1498 CORBA::Boolean theCopy)
1500 myLastCreatedElems = new SMESH::long_array();
1501 myLastCreatedNodes = new SMESH::long_array();
1503 SMESHDS_Mesh* aMesh = GetMeshDS();
1505 map<int,const SMDS_MeshElement*> elements;
1506 ToMap(theIDsOfElements, aMesh, elements);
1508 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
1509 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
1512 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
1514 ::SMESH_MeshEditor anEditor( _myMesh );
1515 anEditor.Transform (elements, aTrsf, theCopy);
1518 UpdateLastResult(anEditor);
1521 // Update Python script
1522 TPythonDump() << "axis = " << theAxis;
1523 TPythonDump() << this << ".Rotate( "
1530 //=======================================================================
1531 //function : RotateObject
1533 //=======================================================================
1535 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
1536 const SMESH::AxisStruct & theAxis,
1537 CORBA::Double theAngle,
1538 CORBA::Boolean theCopy)
1540 myLastCreatedElems = new SMESH::long_array();
1541 myLastCreatedNodes = new SMESH::long_array();
1543 SMESH::long_array_var anElementsId = theObject->GetIDs();
1544 Rotate(anElementsId, theAxis, theAngle, theCopy);
1546 // Clear python line, created by Rotate()
1547 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1548 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1550 // Update Python script
1551 TPythonDump() << this << ".RotateObject( "
1558 //=======================================================================
1559 //function : FindCoincidentNodes
1561 //=======================================================================
1563 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
1564 SMESH::array_of_long_array_out GroupsOfNodes)
1566 myLastCreatedElems = new SMESH::long_array();
1567 myLastCreatedNodes = new SMESH::long_array();
1569 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
1570 ::SMESH_MeshEditor anEditor( _myMesh );
1571 set<const SMDS_MeshNode*> nodes; // no input nodes
1572 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
1574 GroupsOfNodes = new SMESH::array_of_long_array;
1575 GroupsOfNodes->length( aListOfListOfNodes.size() );
1576 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
1577 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
1578 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
1579 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
1580 SMESH::long_array& aGroup = GroupsOfNodes[ i ];
1581 aGroup.length( aListOfNodes.size() );
1582 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
1583 aGroup[ j ] = (*lIt)->GetID();
1585 // Update Python script
1586 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
1587 << Tolerance << " )";
1590 //=======================================================================
1591 //function : MergeNodes
1593 //=======================================================================
1595 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
1597 myLastCreatedElems = new SMESH::long_array();
1598 myLastCreatedNodes = new SMESH::long_array();
1600 SMESHDS_Mesh* aMesh = GetMeshDS();
1602 TPythonDump aTPythonDump;
1603 aTPythonDump << this << ".MergeNodes([";
1604 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
1605 for (int i = 0; i < GroupsOfNodes.length(); i++)
1607 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
1608 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
1609 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
1610 for ( int j = 0; j < aNodeGroup.length(); j++ )
1612 CORBA::Long index = aNodeGroup[ j ];
1613 const SMDS_MeshNode * node = aMesh->FindNode(index);
1615 aListOfNodes.push_back( node );
1617 if ( aListOfNodes.size() < 2 )
1618 aListOfListOfNodes.pop_back();
1620 if ( i > 0 ) aTPythonDump << ", ";
1621 aTPythonDump << aNodeGroup;
1623 ::SMESH_MeshEditor anEditor( _myMesh );
1624 anEditor.MergeNodes( aListOfListOfNodes );
1626 // Update Python script
1627 aTPythonDump << "])";
1630 //=======================================================================
1631 //function : MergeEqualElements
1633 //=======================================================================
1635 void SMESH_MeshEditor_i::MergeEqualElements()
1637 myLastCreatedElems = new SMESH::long_array();
1638 myLastCreatedNodes = new SMESH::long_array();
1640 ::SMESH_MeshEditor anEditor( _myMesh );
1641 anEditor.MergeEqualElements();
1643 // Update Python script
1644 TPythonDump() << this << ".MergeEqualElements()";
1647 //=======================================================================
1648 //function : operator
1650 //=======================================================================
1652 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1654 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
1658 RETCASE( SEW_BORDER1_NOT_FOUND );
1659 RETCASE( SEW_BORDER2_NOT_FOUND );
1660 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
1661 RETCASE( SEW_BAD_SIDE_NODES );
1662 RETCASE( SEW_VOLUMES_TO_SPLIT );
1663 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
1664 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
1665 RETCASE( SEW_BAD_SIDE1_NODES );
1666 RETCASE( SEW_BAD_SIDE2_NODES );
1668 return SMESH::SMESH_MeshEditor::SEW_OK;
1671 //=======================================================================
1672 //function : SewFreeBorders
1674 //=======================================================================
1676 SMESH::SMESH_MeshEditor::Sew_Error
1677 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
1678 CORBA::Long SecondNodeID1,
1679 CORBA::Long LastNodeID1,
1680 CORBA::Long FirstNodeID2,
1681 CORBA::Long SecondNodeID2,
1682 CORBA::Long LastNodeID2,
1683 CORBA::Boolean CreatePolygons,
1684 CORBA::Boolean CreatePolyedrs)
1686 myLastCreatedElems = new SMESH::long_array();
1687 myLastCreatedNodes = new SMESH::long_array();
1689 SMESHDS_Mesh* aMesh = GetMeshDS();
1691 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
1692 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
1693 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
1694 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
1695 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
1696 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
1698 if (!aBorderFirstNode ||
1699 !aBorderSecondNode||
1701 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1702 if (!aSide2FirstNode ||
1703 !aSide2SecondNode ||
1705 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
1707 // Update Python script
1708 TPythonDump() << "error = " << this << ".SewFreeBorders( "
1709 << FirstNodeID1 << ", "
1710 << SecondNodeID1 << ", "
1711 << LastNodeID1 << ", "
1712 << FirstNodeID2 << ", "
1713 << SecondNodeID2 << ", "
1714 << LastNodeID2 << ", "
1715 << CreatePolygons<< ", "
1716 << CreatePolyedrs<< " )";
1718 ::SMESH_MeshEditor anEditor( _myMesh );
1719 SMESH::SMESH_MeshEditor::Sew_Error error =
1720 convError( anEditor.SewFreeBorder (aBorderFirstNode,
1730 UpdateLastResult(anEditor);
1736 //=======================================================================
1737 //function : SewConformFreeBorders
1739 //=======================================================================
1741 SMESH::SMESH_MeshEditor::Sew_Error
1742 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
1743 CORBA::Long SecondNodeID1,
1744 CORBA::Long LastNodeID1,
1745 CORBA::Long FirstNodeID2,
1746 CORBA::Long SecondNodeID2)
1748 myLastCreatedElems = new SMESH::long_array();
1749 myLastCreatedNodes = new SMESH::long_array();
1751 SMESHDS_Mesh* aMesh = GetMeshDS();
1753 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
1754 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
1755 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
1756 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
1757 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
1758 const SMDS_MeshNode* aSide2ThirdNode = 0;
1760 if (!aBorderFirstNode ||
1761 !aBorderSecondNode||
1763 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1764 if (!aSide2FirstNode ||
1766 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
1768 // Update Python script
1769 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
1770 << FirstNodeID1 << ", "
1771 << SecondNodeID1 << ", "
1772 << LastNodeID1 << ", "
1773 << FirstNodeID2 << ", "
1774 << SecondNodeID2 << " )";
1776 ::SMESH_MeshEditor anEditor( _myMesh );
1777 SMESH::SMESH_MeshEditor::Sew_Error error =
1778 convError( anEditor.SewFreeBorder (aBorderFirstNode,
1787 UpdateLastResult(anEditor);
1793 //=======================================================================
1794 //function : SewBorderToSide
1796 //=======================================================================
1798 SMESH::SMESH_MeshEditor::Sew_Error
1799 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
1800 CORBA::Long SecondNodeIDOnFreeBorder,
1801 CORBA::Long LastNodeIDOnFreeBorder,
1802 CORBA::Long FirstNodeIDOnSide,
1803 CORBA::Long LastNodeIDOnSide,
1804 CORBA::Boolean CreatePolygons,
1805 CORBA::Boolean CreatePolyedrs)
1807 myLastCreatedElems = new SMESH::long_array();
1808 myLastCreatedNodes = new SMESH::long_array();
1810 SMESHDS_Mesh* aMesh = GetMeshDS();
1812 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
1813 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
1814 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
1815 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
1816 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
1817 const SMDS_MeshNode* aSide2ThirdNode = 0;
1819 if (!aBorderFirstNode ||
1820 !aBorderSecondNode||
1822 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1823 if (!aSide2FirstNode ||
1825 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
1827 // Update Python script
1828 TPythonDump() << "error = " << this << ".SewBorderToSide( "
1829 << FirstNodeIDOnFreeBorder << ", "
1830 << SecondNodeIDOnFreeBorder << ", "
1831 << LastNodeIDOnFreeBorder << ", "
1832 << FirstNodeIDOnSide << ", "
1833 << LastNodeIDOnSide << ", "
1834 << CreatePolygons << ", "
1835 << CreatePolyedrs << ") ";
1837 ::SMESH_MeshEditor anEditor( _myMesh );
1838 SMESH::SMESH_MeshEditor::Sew_Error error =
1839 convError( anEditor.SewFreeBorder (aBorderFirstNode,
1849 UpdateLastResult(anEditor);
1855 //=======================================================================
1856 //function : SewSideElements
1858 //=======================================================================
1860 SMESH::SMESH_MeshEditor::Sew_Error
1861 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
1862 const SMESH::long_array& IDsOfSide2Elements,
1863 CORBA::Long NodeID1OfSide1ToMerge,
1864 CORBA::Long NodeID1OfSide2ToMerge,
1865 CORBA::Long NodeID2OfSide1ToMerge,
1866 CORBA::Long NodeID2OfSide2ToMerge)
1868 myLastCreatedElems = new SMESH::long_array();
1869 myLastCreatedNodes = new SMESH::long_array();
1871 SMESHDS_Mesh* aMesh = GetMeshDS();
1873 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
1874 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
1875 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
1876 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
1878 if (!aFirstNode1ToMerge ||
1879 !aFirstNode2ToMerge )
1880 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
1881 if (!aSecondNode1ToMerge||
1882 !aSecondNode2ToMerge)
1883 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
1885 map<int,const SMDS_MeshElement*> aSide1Elems, aSide2Elems;
1886 ToMap(IDsOfSide1Elements, aMesh, aSide1Elems);
1887 ToMap(IDsOfSide2Elements, aMesh, aSide2Elems);
1889 // Update Python script
1890 TPythonDump() << "error = " << this << ".SewSideElements( "
1891 << IDsOfSide1Elements << ", "
1892 << IDsOfSide2Elements << ", "
1893 << NodeID1OfSide1ToMerge << ", "
1894 << NodeID1OfSide2ToMerge << ", "
1895 << NodeID2OfSide1ToMerge << ", "
1896 << NodeID2OfSide2ToMerge << ")";
1898 ::SMESH_MeshEditor anEditor( _myMesh );
1899 SMESH::SMESH_MeshEditor::Sew_Error error =
1900 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
1903 aSecondNode1ToMerge,
1904 aSecondNode2ToMerge));
1906 UpdateLastResult(anEditor);
1911 //================================================================================
1913 * \brief Set new nodes for given element
1914 * \param ide - element id
1915 * \param newIDs - new node ids
1916 * \retval CORBA::Boolean - true if result is OK
1918 //================================================================================
1920 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
1921 const SMESH::long_array& newIDs)
1923 myLastCreatedElems = new SMESH::long_array();
1924 myLastCreatedNodes = new SMESH::long_array();
1926 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
1927 if(!elem) return false;
1929 int nbn = newIDs.length();
1931 const SMDS_MeshNode* aNodes [nbn];
1934 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
1937 aNodes[nbn1] = aNode;
1940 // Update Python script
1941 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
1942 << ide << ", " << newIDs << " )";
1944 TPythonDump() << "print 'ChangeElemNodes: ', isDone";
1947 return GetMeshDS()->ChangeElementNodes( elem, aNodes, nbn1+1 );
1950 //================================================================================
1952 * \brief Update myLastCreatedNodes and myLastCreatedElems
1953 * \param anEditor - it contains last modification results
1955 //================================================================================
1957 void SMESH_MeshEditor_i::UpdateLastResult(::SMESH_MeshEditor& anEditor)
1959 // add new elements into myLastCreatedNodes
1960 SMESH_SequenceOfElemPtr aSeq = anEditor.GetLastCreatedNodes();
1961 SMESH::long_array_var aResult = new SMESH::long_array;
1962 aResult->length(aSeq.Length());
1964 for(; i<aSeq.Length(); i++) {
1965 aResult[i] = aSeq.Value(i+1)->GetID();
1967 myLastCreatedNodes = aResult._retn();
1968 // add new elements into myLastCreatedElems
1969 aSeq = anEditor.GetLastCreatedElems();
1970 aResult = new SMESH::long_array;
1971 aResult->length(aSeq.Length());
1973 for(; i<aSeq.Length(); i++) {
1974 aResult[i] = aSeq.Value(i+1)->GetID();
1976 myLastCreatedElems = aResult._retn();
1979 //================================================================================
1981 * \brief Returns list of it's IDs of created nodes
1982 * \retval SMESH::long_array* - list of node ID
1984 //================================================================================
1986 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
1988 return myLastCreatedNodes;
1991 //================================================================================
1993 * \brief Returns list of it's IDs of created elements
1994 * \retval SMESH::long_array* - list of elements' ID
1996 //================================================================================
1998 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
2000 return myLastCreatedElems;
2004 //=======================================================================
2005 //function : ConvertToQuadratic
2007 //=======================================================================
2009 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
2011 ::SMESH_MeshEditor anEditor( _myMesh );
2012 anEditor.ConvertToQuadratic(theForce3d);
2013 // Update Python script
2014 TPythonDump() << this << ".ConvertToQuadratic( "
2015 << theForce3d << " )";
2018 //=======================================================================
2019 //function : ConvertFromQuadratic
2021 //=======================================================================
2023 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
2025 ::SMESH_MeshEditor anEditor( _myMesh );
2026 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
2027 // Update Python script
2028 TPythonDump() << this << ".ConvertFromQuadratic()";