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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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"
34 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
35 #include "SMESH_MeshEditor.hxx"
36 #include "SMESH_subMeshEventListener.hxx"
37 #include "SMESH_Gen_i.hxx"
38 #include "SMESH_Filter_i.hxx"
39 #include "SMESH_PythonDump.hxx"
41 #include "utilities.h"
47 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
51 #include <Standard_Failure.hxx>
54 #include <Standard_ErrorHandler.hxx>
56 #include "CASCatch.hxx"
61 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
64 using SMESH::TPythonDump;
68 //=============================================================================
70 * \brief Mesh to apply modifications for preview purposes
72 //=============================================================================
74 struct TPreviewMesh: public SMESH_Mesh
76 SMDSAbs_ElementType myPreviewType; // type to show
78 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
79 _isShapeToMesh = _id =_studyId =_idDoc = 0;
80 _myMeshDS = new SMESHDS_Mesh( _id, true );
81 myPreviewType = previewElements;
84 virtual ~TPreviewMesh() { delete _myMeshDS; }
85 //!< Copy a set of elements
86 void Copy(const TIDSortedElemSet & theElements,
87 TIDSortedElemSet& theCopyElements,
88 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
89 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
91 // loop on theIDsOfElements
92 TIDSortedElemSet::const_iterator eIt = theElements.begin();
93 for ( ; eIt != theElements.end(); ++eIt )
95 const SMDS_MeshElement* anElem = *eIt;
96 if ( !anElem ) continue;
97 SMDSAbs_ElementType type = anElem->GetType();
98 if ( type == theAvoidType ||
99 ( theSelectType != SMDSAbs_All && type != theSelectType ))
102 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
103 theCopyElements.insert( theCopyElements.end(), anElemCopy );
107 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
109 // copy element nodes
110 int anElemNbNodes = anElem->NbNodes();
111 vector< int > anElemNodesID( anElemNbNodes ) ;
112 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
113 for ( int i = 0; itElemNodes->more(); i++)
115 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
117 anElemNodesID[i] = anElemNode->GetID();
120 // creates a corresponding element on copied nodes
121 SMDS_MeshElement* anElemCopy = 0;
122 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
124 const SMDS_PolyhedralVolumeOfNodes* ph =
125 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
127 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
128 (anElemNodesID, ph->GetQuanities(),anElem->GetID());
131 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
138 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
140 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
141 anElemNode->GetID());
143 };// struct TPreviewMesh
145 static SMESH_NodeSearcher * myNodeSearcher = 0;
147 //=============================================================================
149 * \brief Deleter of myNodeSearcher at any compute event occured
151 //=============================================================================
153 struct TNodeSearcherDeleter : public SMESH_subMeshEventListener
155 TNodeSearcherDeleter(): SMESH_subMeshEventListener( false ) // won't be deleted by submesh
157 //!< Delete myNodeSearcher
160 if ( myNodeSearcher ) { delete myNodeSearcher; myNodeSearcher = 0; }
162 typedef map < int, SMESH_subMesh * > TDependsOnMap;
163 //!< The meshod called by submesh: do my main job
164 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
165 SMESH_subMeshEventListenerData*,SMESH_Hypothesis*)
167 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
169 // delete self from all submeshes
170 if ( SMESH_subMesh* myMainSubMesh = sm->GetFather()->GetSubMeshContaining(1) ) {
171 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
172 TDependsOnMap::const_iterator sm;
173 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
174 sm->second->DeleteEventListener( this );
178 //!< set self on all submeshes
179 void Set(SMESH_Mesh* mesh)
181 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
182 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
183 TDependsOnMap::const_iterator sm;
184 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
185 sm->second->SetEventListener( this, 0, sm->second );
191 //=============================================================================
195 //=============================================================================
197 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh* theMesh, bool isPreview)
200 myPreviewMode = isPreview;
203 //================================================================================
207 //================================================================================
209 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
213 //================================================================================
215 * \brief Clear members
217 //================================================================================
219 void SMESH_MeshEditor_i::initData()
221 if ( myPreviewMode ) {
222 myPreviewData = new SMESH::MeshPreviewStruct();
225 myLastCreatedElems = new SMESH::long_array();
226 myLastCreatedNodes = new SMESH::long_array();
227 TNodeSearcherDeleter::Delete();
231 //=============================================================================
235 //=============================================================================
238 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
242 ::SMESH_MeshEditor anEditor( myMesh );
245 for (int i = 0; i < IDsOfElements.length(); i++)
246 IdList.push_back( IDsOfElements[i] );
248 // Update Python script
249 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
251 TPythonDump() << "print 'RemoveElements: ', isDone";
254 return anEditor.Remove( IdList, false );
257 //=============================================================================
261 //=============================================================================
263 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
267 ::SMESH_MeshEditor anEditor( myMesh );
269 for (int i = 0; i < IDsOfNodes.length(); i++)
270 IdList.push_back( IDsOfNodes[i] );
272 // Update Python script
273 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
275 TPythonDump() << "print 'RemoveNodes: ', isDone";
278 return anEditor.Remove( IdList, true );
281 //=============================================================================
285 //=============================================================================
287 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
291 int NbNodes = IDsOfNodes.length();
292 SMDS_MeshElement* elem = 0;
295 CORBA::Long index1 = IDsOfNodes[0];
296 CORBA::Long index2 = IDsOfNodes[1];
297 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
299 // Update Python script
300 TPythonDump() << "edge = " << this << ".AddEdge([ "
301 << index1 << ", " << index2 <<" ])";
304 CORBA::Long n1 = IDsOfNodes[0];
305 CORBA::Long n2 = IDsOfNodes[1];
306 CORBA::Long n12 = IDsOfNodes[2];
307 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
308 GetMeshDS()->FindNode(n2),
309 GetMeshDS()->FindNode(n12));
310 // Update Python script
311 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
312 <<n1<<", "<<n2<<", "<<n12<<" ])";
316 return elem->GetID();
321 //=============================================================================
325 //=============================================================================
327 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
328 CORBA::Double y, CORBA::Double z)
332 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
334 // Update Python script
335 TPythonDump() << "nodeID = " << this << ".AddNode( "
336 << x << ", " << y << ", " << z << " )";
341 //=============================================================================
345 //=============================================================================
347 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
351 int NbNodes = IDsOfNodes.length();
357 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
358 for (int i = 0; i < NbNodes; i++)
359 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
361 SMDS_MeshElement* elem = 0;
363 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
365 else if (NbNodes == 4) {
366 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
368 else if (NbNodes == 6) {
369 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
372 else if (NbNodes == 8) {
373 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
374 nodes[4], nodes[5], nodes[6], nodes[7]);
377 // Update Python script
378 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
381 return elem->GetID();
386 //=============================================================================
390 //=============================================================================
391 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace
392 (const SMESH::long_array & IDsOfNodes)
396 int NbNodes = IDsOfNodes.length();
397 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
398 for (int i = 0; i < NbNodes; i++)
399 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
401 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
403 // Update Python script
404 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
406 TPythonDump() << "print 'AddPolygonalFace: ', faceID";
410 return elem->GetID();
415 //=============================================================================
419 //=============================================================================
421 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
425 int NbNodes = IDsOfNodes.length();
426 vector< const SMDS_MeshNode*> n(NbNodes);
427 for(int i=0;i<NbNodes;i++)
428 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
430 SMDS_MeshElement* elem = 0;
433 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
434 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
435 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
436 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
437 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
438 n[6],n[7],n[8],n[9]);
440 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
441 n[7],n[8],n[9],n[10],n[11],n[12]);
443 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
444 n[9],n[10],n[11],n[12],n[13],n[14]);
446 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
447 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
448 n[15],n[16],n[17],n[18],n[19]);
452 // Update Python script
453 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
455 TPythonDump() << "print 'AddVolume: ', volID";
459 return elem->GetID();
464 //=============================================================================
466 * AddPolyhedralVolume
468 //=============================================================================
469 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume
470 (const SMESH::long_array & IDsOfNodes,
471 const SMESH::long_array & Quantities)
475 int NbNodes = IDsOfNodes.length();
476 std::vector<const SMDS_MeshNode*> n (NbNodes);
477 for (int i = 0; i < NbNodes; i++)
478 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
480 int NbFaces = Quantities.length();
481 std::vector<int> q (NbFaces);
482 for (int j = 0; j < NbFaces; j++)
483 q[j] = Quantities[j];
485 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
487 // Update Python script
488 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
489 << IDsOfNodes << ", " << Quantities << " )";
491 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
495 return elem->GetID();
500 //=============================================================================
502 * AddPolyhedralVolumeByFaces
504 //=============================================================================
505 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
506 (const SMESH::long_array & IdsOfFaces)
510 int NbFaces = IdsOfFaces.length();
511 std::vector<const SMDS_MeshNode*> poly_nodes;
512 std::vector<int> quantities (NbFaces);
514 for (int i = 0; i < NbFaces; i++) {
515 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
516 quantities[i] = aFace->NbNodes();
518 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
520 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
524 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
526 // Update Python script
527 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
528 << IdsOfFaces << " )";
530 TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
534 return elem->GetID();
539 //=============================================================================
543 //=============================================================================
545 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
552 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
556 GetMeshDS()->MoveNode(node, x, y, z);
558 // Update Python script
559 TPythonDump() << "isDone = " << this << ".MoveNode( "
560 << NodeID << ", " << x << ", " << y << ", " << z << " )";
565 //=============================================================================
569 //=============================================================================
571 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
576 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
577 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
581 // Update Python script
582 TPythonDump() << "isDone = " << this << ".InverseDiag( "
583 << NodeID1 << ", " << NodeID2 << " )";
585 ::SMESH_MeshEditor aMeshEditor( myMesh );
586 return aMeshEditor.InverseDiag ( n1, n2 );
589 //=============================================================================
593 //=============================================================================
595 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
600 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
601 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
605 // Update Python script
606 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
607 << NodeID1 << ", " << NodeID2 << " )";
609 ::SMESH_MeshEditor aMeshEditor( myMesh );
611 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
613 StoreResult(aMeshEditor);
618 //=============================================================================
622 //=============================================================================
624 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
628 ::SMESH_MeshEditor anEditor( myMesh );
629 for (int i = 0; i < IDsOfElements.length(); i++)
631 CORBA::Long index = IDsOfElements[i];
632 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
634 anEditor.Reorient( elem );
636 // Update Python script
637 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
643 //=============================================================================
647 //=============================================================================
649 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
653 SMESH::long_array_var anElementsId = theObject->GetIDs();
654 CORBA::Boolean isDone = Reorient(anElementsId);
656 // Clear python line, created by Reorient()
657 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
658 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
660 // Update Python script
661 TPythonDump() << "isDone = " << this << ".ReorientObject( " << theObject << " )";
668 //================================================================================
670 * \brief function for conversion long_array to TIDSortedElemSet
671 * \param IDs - array of IDs
672 * \param aMesh - mesh
673 * \param aMap - collection to fill
674 * \param aType - element type
676 //================================================================================
678 void ToMap(const SMESH::long_array & IDs,
679 const SMESHDS_Mesh* aMesh,
680 TIDSortedElemSet& aMap,
681 const SMDSAbs_ElementType aType = SMDSAbs_All )
683 for (int i=0; i<IDs.length(); i++) {
684 CORBA::Long ind = IDs[i];
685 const SMDS_MeshElement * elem = aMesh->FindElement(ind);
686 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
692 //=============================================================================
696 //=============================================================================
697 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
698 SMESH::NumericalFunctor_ptr Criterion,
699 CORBA::Double MaxAngle)
703 SMESHDS_Mesh* aMesh = GetMeshDS();
704 TIDSortedElemSet faces;
705 ToMap(IDsOfElements, aMesh, faces, SMDSAbs_Face);
707 SMESH::NumericalFunctor_i* aNumericalFunctor =
708 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
709 SMESH::Controls::NumericalFunctorPtr aCrit;
710 if ( !aNumericalFunctor )
711 aCrit.reset( new SMESH::Controls::AspectRatio() );
713 aCrit = aNumericalFunctor->GetNumericalFunctor();
715 // Update Python script
716 TPythonDump() << "isDone = " << this << ".TriToQuad( "
717 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
719 TPythonDump() << "print 'TriToQuad: ', isDone";
722 ::SMESH_MeshEditor anEditor( myMesh );
724 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
726 StoreResult(anEditor);
732 //=============================================================================
736 //=============================================================================
737 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
738 SMESH::NumericalFunctor_ptr Criterion,
739 CORBA::Double MaxAngle)
743 SMESH::long_array_var anElementsId = theObject->GetIDs();
744 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
746 // Clear python line(s), created by TriToQuad()
747 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
748 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
750 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
753 SMESH::NumericalFunctor_i* aNumericalFunctor =
754 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
756 // Update Python script
757 TPythonDump() << "isDone = " << this << ".TriToQuadObject("
758 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
760 TPythonDump() << "print 'TriToQuadObject: ', isDone";
767 //=============================================================================
771 //=============================================================================
772 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
773 SMESH::NumericalFunctor_ptr Criterion)
777 SMESHDS_Mesh* aMesh = GetMeshDS();
778 TIDSortedElemSet faces;
779 ToMap(IDsOfElements, aMesh, faces, SMDSAbs_Face);
781 SMESH::NumericalFunctor_i* aNumericalFunctor =
782 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
783 SMESH::Controls::NumericalFunctorPtr aCrit;
784 if ( !aNumericalFunctor )
785 aCrit.reset( new SMESH::Controls::AspectRatio() );
787 aCrit = aNumericalFunctor->GetNumericalFunctor();
790 // Update Python script
791 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
793 TPythonDump() << "print 'QuadToTri: ', isDone";
796 ::SMESH_MeshEditor anEditor( myMesh );
797 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
799 StoreResult(anEditor);
805 //=============================================================================
809 //=============================================================================
810 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
811 SMESH::NumericalFunctor_ptr Criterion)
815 SMESH::long_array_var anElementsId = theObject->GetIDs();
816 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
818 // Clear python line(s), created by QuadToTri()
819 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
820 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
822 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
825 SMESH::NumericalFunctor_i* aNumericalFunctor =
826 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
828 // Update Python script
829 TPythonDump() << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
831 TPythonDump() << "print 'QuadToTriObject: ', isDone";
838 //=============================================================================
842 //=============================================================================
843 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
844 CORBA::Boolean Diag13)
848 SMESHDS_Mesh* aMesh = GetMeshDS();
849 TIDSortedElemSet faces;
850 ToMap(IDsOfElements, aMesh, faces, SMDSAbs_Face);
852 // Update Python script
853 TPythonDump() << "isDone = " << this << ".SplitQuad( "
854 << IDsOfElements << ", " << Diag13 << " )";
856 TPythonDump() << "print 'SplitQuad: ', isDone";
859 ::SMESH_MeshEditor anEditor( myMesh );
860 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
862 StoreResult(anEditor);
868 //=============================================================================
872 //=============================================================================
873 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
874 CORBA::Boolean Diag13)
878 SMESH::long_array_var anElementsId = theObject->GetIDs();
879 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
881 // Clear python line(s), created by SplitQuad()
882 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
883 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
885 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
888 // Update Python script
889 TPythonDump() << "isDone = " << this << ".SplitQuadObject( "
890 << theObject << ", " << Diag13 << " )";
892 TPythonDump() << "print 'SplitQuadObject: ', isDone";
899 //=============================================================================
903 //=============================================================================
904 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
905 SMESH::NumericalFunctor_ptr Criterion)
907 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
908 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
910 SMESH::NumericalFunctor_i* aNumericalFunctor =
911 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
912 SMESH::Controls::NumericalFunctorPtr aCrit;
913 if (aNumericalFunctor)
914 aCrit = aNumericalFunctor->GetNumericalFunctor();
916 aCrit.reset(new SMESH::Controls::AspectRatio());
918 ::SMESH_MeshEditor anEditor (myMesh);
919 return anEditor.BestSplit(quad, aCrit);
925 //=======================================================================
928 //=======================================================================
931 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
932 const SMESH::long_array & IDsOfFixedNodes,
933 CORBA::Long MaxNbOfIterations,
934 CORBA::Double MaxAspectRatio,
935 SMESH::SMESH_MeshEditor::Smooth_Method Method)
937 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
938 MaxAspectRatio, Method, false );
942 //=======================================================================
943 //function : SmoothParametric
945 //=======================================================================
948 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
949 const SMESH::long_array & IDsOfFixedNodes,
950 CORBA::Long MaxNbOfIterations,
951 CORBA::Double MaxAspectRatio,
952 SMESH::SMESH_MeshEditor::Smooth_Method Method)
954 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
955 MaxAspectRatio, Method, true );
959 //=======================================================================
960 //function : SmoothObject
962 //=======================================================================
965 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
966 const SMESH::long_array & IDsOfFixedNodes,
967 CORBA::Long MaxNbOfIterations,
968 CORBA::Double MaxAspectRatio,
969 SMESH::SMESH_MeshEditor::Smooth_Method Method)
971 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
972 MaxAspectRatio, Method, false);
976 //=======================================================================
977 //function : SmoothParametricObject
979 //=======================================================================
982 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
983 const SMESH::long_array & IDsOfFixedNodes,
984 CORBA::Long MaxNbOfIterations,
985 CORBA::Double MaxAspectRatio,
986 SMESH::SMESH_MeshEditor::Smooth_Method Method)
988 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
989 MaxAspectRatio, Method, true);
993 //=============================================================================
997 //=============================================================================
1000 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1001 const SMESH::long_array & IDsOfFixedNodes,
1002 CORBA::Long MaxNbOfIterations,
1003 CORBA::Double MaxAspectRatio,
1004 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1009 SMESHDS_Mesh* aMesh = GetMeshDS();
1011 TIDSortedElemSet elements;
1012 ToMap(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1014 set<const SMDS_MeshNode*> fixedNodes;
1015 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1016 CORBA::Long index = IDsOfFixedNodes[i];
1017 const SMDS_MeshNode * node = aMesh->FindNode(index);
1019 fixedNodes.insert( node );
1021 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1022 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1023 method = ::SMESH_MeshEditor::CENTROIDAL;
1025 ::SMESH_MeshEditor anEditor( myMesh );
1026 anEditor.Smooth(elements, fixedNodes, method,
1027 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1029 StoreResult(anEditor);
1031 // Update Python script
1032 TPythonDump() << "isDone = " << this << "."
1033 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1034 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1035 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1036 << "SMESH.SMESH_MeshEditor."
1037 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1038 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1040 TPythonDump() << "print 'Smooth: ', isDone";
1047 //=============================================================================
1051 //=============================================================================
1054 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1055 const SMESH::long_array & IDsOfFixedNodes,
1056 CORBA::Long MaxNbOfIterations,
1057 CORBA::Double MaxAspectRatio,
1058 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1063 SMESH::long_array_var anElementsId = theObject->GetIDs();
1064 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1065 MaxAspectRatio, Method, IsParametric);
1067 // Clear python line(s), created by Smooth()
1068 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1069 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1071 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1074 // Update Python script
1075 TPythonDump() << "isDone = " << this << "."
1076 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1077 << theObject << ", " << IDsOfFixedNodes << ", "
1078 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1079 << "SMESH.SMESH_MeshEditor."
1080 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1081 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1083 TPythonDump() << "print 'SmoothObject: ', isDone";
1090 //=============================================================================
1094 //=============================================================================
1096 void SMESH_MeshEditor_i::RenumberNodes()
1098 // Update Python script
1099 TPythonDump() << this << ".RenumberNodes()";
1101 GetMeshDS()->Renumber( true );
1105 //=============================================================================
1109 //=============================================================================
1111 void SMESH_MeshEditor_i::RenumberElements()
1113 // Update Python script
1114 TPythonDump() << this << ".RenumberElements()";
1116 GetMeshDS()->Renumber( false );
1120 //=======================================================================
1121 //function : RotationSweep
1123 //=======================================================================
1125 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1126 const SMESH::AxisStruct & theAxis,
1127 CORBA::Double theAngleInRadians,
1128 CORBA::Long theNbOfSteps,
1129 CORBA::Double theTolerance)
1133 TIDSortedElemSet inElements, copyElements;
1134 ToMap(theIDsOfElements, GetMeshDS(), inElements);
1136 TIDSortedElemSet* workElements = & inElements;
1137 TPreviewMesh tmpMesh( SMDSAbs_Face );
1138 SMESH_Mesh* mesh = 0;
1139 bool makeWalls=true;
1140 if ( myPreviewMode )
1142 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1143 tmpMesh.Copy( inElements, copyElements, select, avoid );
1145 workElements = & copyElements;
1146 //makeWalls = false;
1153 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1154 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1156 ::SMESH_MeshEditor anEditor( mesh );
1157 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1158 theNbOfSteps, theTolerance, makeWalls);
1160 StoreResult(anEditor);
1162 if ( !myPreviewMode ) {
1163 // Update Python script
1164 TPythonDump() << "axis = " << theAxis;
1165 TPythonDump() << this << ".RotationSweep( "
1168 << theAngleInRadians << ", "
1169 << theNbOfSteps << ", "
1170 << theTolerance << " )";
1174 //=======================================================================
1175 //function : RotationSweepObject
1177 //=======================================================================
1179 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1180 const SMESH::AxisStruct & theAxis,
1181 CORBA::Double theAngleInRadians,
1182 CORBA::Long theNbOfSteps,
1183 CORBA::Double theTolerance)
1187 SMESH::long_array_var anElementsId = theObject->GetIDs();
1188 RotationSweep(anElementsId, theAxis, theAngleInRadians, theNbOfSteps, theTolerance);
1190 // Clear python line, created by RotationSweep()
1191 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1192 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1194 // Update Python script
1195 TPythonDump() << this << ".RotationSweepObject( "
1198 << theAngleInRadians << ", "
1199 << theNbOfSteps << ", "
1200 << theTolerance << " )";
1203 //=======================================================================
1204 //function : ExtrusionSweep
1206 //=======================================================================
1208 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1209 const SMESH::DirStruct & theStepVector,
1210 CORBA::Long theNbOfSteps)
1220 SMESHDS_Mesh* aMesh = GetMeshDS();
1222 TIDSortedElemSet elements;
1223 ToMap(theIDsOfElements, aMesh, elements);
1225 const SMESH::PointStruct * P = &theStepVector.PS;
1226 gp_Vec stepVec( P->x, P->y, P->z );
1228 TElemOfElemListMap aHystory;
1229 ::SMESH_MeshEditor anEditor( myMesh );
1230 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
1232 StoreResult(anEditor);
1234 // Update Python script
1235 TPythonDump() << "stepVector = " << theStepVector;
1236 TPythonDump() << this << ".ExtrusionSweep( "
1237 << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1240 } catch(Standard_Failure) {
1242 } CASCatch_CATCH(Standard_Failure) {
1244 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1245 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1250 //=======================================================================
1251 //function : ExtrusionSweepObject
1253 //=======================================================================
1255 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1256 const SMESH::DirStruct & theStepVector,
1257 CORBA::Long theNbOfSteps)
1261 SMESH::long_array_var anElementsId = theObject->GetIDs();
1262 ExtrusionSweep(anElementsId, theStepVector, theNbOfSteps);
1264 // Clear python line, created by ExtrusionSweep()
1265 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1266 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1268 // Update Python script
1269 TPythonDump() << this << ".ExtrusionSweepObject( "
1270 << theObject << ", stepVector, " << theNbOfSteps << " )";
1273 //=======================================================================
1274 //function : ExtrusionSweepObject1D
1276 //=======================================================================
1278 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1279 const SMESH::DirStruct & theStepVector,
1280 CORBA::Long theNbOfSteps)
1284 SMESHDS_Mesh* aMesh = GetMeshDS();
1286 SMESH::long_array_var allElementsId = theObject->GetIDs();
1288 TIDSortedElemSet elements;
1289 ToMap(allElementsId, aMesh, elements);
1291 const SMESH::PointStruct * P = &theStepVector.PS;
1292 gp_Vec stepVec( P->x, P->y, P->z );
1294 ::SMESH_MeshEditor anEditor( myMesh );
1295 //anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
1296 TElemOfElemListMap aHystory;
1297 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
1299 StoreResult(anEditor);
1301 // Update Python script
1302 TPythonDump() << "stepVector = " << theStepVector;
1303 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1304 << theObject << ", stepVector, " << theNbOfSteps << " )";
1307 //=======================================================================
1308 //function : ExtrusionSweepObject2D
1310 //=======================================================================
1312 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1313 const SMESH::DirStruct & theStepVector,
1314 CORBA::Long theNbOfSteps)
1318 SMESHDS_Mesh* aMesh = GetMeshDS();
1320 SMESH::long_array_var allElementsId = theObject->GetIDs();
1322 TIDSortedElemSet elements;
1323 ToMap(allElementsId, aMesh, elements);
1325 const SMESH::PointStruct * P = &theStepVector.PS;
1326 gp_Vec stepVec( P->x, P->y, P->z );
1328 ::SMESH_MeshEditor anEditor( myMesh );
1329 //anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
1330 TElemOfElemListMap aHystory;
1331 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
1333 StoreResult(anEditor);
1335 // Update Python script
1336 TPythonDump() << "stepVector = " << theStepVector;
1337 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1338 << theObject << ", stepVector, " << theNbOfSteps << " )";
1342 //=======================================================================
1343 //function : AdvancedExtrusion
1345 //=======================================================================
1347 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1348 const SMESH::DirStruct & theStepVector,
1349 CORBA::Long theNbOfSteps,
1350 CORBA::Long theExtrFlags,
1351 CORBA::Double theSewTolerance)
1355 SMESHDS_Mesh* aMesh = GetMeshDS();
1357 TIDSortedElemSet elements;
1358 ToMap(theIDsOfElements, aMesh, elements);
1360 const SMESH::PointStruct * P = &theStepVector.PS;
1361 gp_Vec stepVec( P->x, P->y, P->z );
1363 ::SMESH_MeshEditor anEditor( myMesh );
1364 TElemOfElemListMap aHystory;
1365 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1366 theExtrFlags, theSewTolerance);
1368 StoreResult(anEditor);
1370 // Update Python script
1371 TPythonDump() << "stepVector = " << theStepVector;
1372 TPythonDump() << this << ".AdvancedExtrusion("
1375 << theNbOfSteps << ","
1376 << theExtrFlags << ", "
1377 << theSewTolerance << " )";
1381 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1383 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1387 RETCASE( EXTR_NO_ELEMENTS );
1388 RETCASE( EXTR_PATH_NOT_EDGE );
1389 RETCASE( EXTR_BAD_PATH_SHAPE );
1390 RETCASE( EXTR_BAD_STARTING_NODE );
1391 RETCASE( EXTR_BAD_ANGLES_NUMBER );
1392 RETCASE( EXTR_CANT_GET_TANGENT );
1394 return SMESH::SMESH_MeshEditor::EXTR_OK;
1397 //=======================================================================
1398 //function : ExtrusionAlongPath
1400 //=======================================================================
1402 SMESH::SMESH_MeshEditor::Extrusion_Error
1403 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
1404 SMESH::SMESH_Mesh_ptr thePathMesh,
1405 GEOM::GEOM_Object_ptr thePathShape,
1406 CORBA::Long theNodeStart,
1407 CORBA::Boolean theHasAngles,
1408 const SMESH::double_array & theAngles,
1409 CORBA::Boolean theHasRefPoint,
1410 const SMESH::PointStruct & theRefPoint)
1414 SMESHDS_Mesh* aMesh = GetMeshDS();
1416 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() )
1417 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1419 SMESH_Mesh_i* aMeshImp = dynamic_cast<SMESH_Mesh_i*>( SMESH_Gen_i::GetServant( thePathMesh ).in() );
1420 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1421 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1423 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
1424 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1426 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
1428 return SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
1430 TIDSortedElemSet elements;
1431 ToMap(theIDsOfElements, aMesh, elements);
1433 list<double> angles;
1434 for (int i = 0; i < theAngles.length(); i++) {
1435 angles.push_back( theAngles[i] );
1438 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
1440 // Update Python script
1441 TPythonDump() << "rotAngles = " << theAngles;
1443 if ( theHasRefPoint )
1444 TPythonDump() << "refPoint = SMESH.PointStruct( "
1445 << refPnt.X() << ", "
1446 << refPnt.Y() << ", "
1447 << refPnt.Z() << " )";
1449 TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
1451 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
1452 << theIDsOfElements << ", "
1453 << thePathMesh << ", "
1454 << thePathShape << ", "
1455 << theNodeStart << ", "
1456 << theHasAngles << ", "
1457 << "rotAngles" << ", "
1458 << theHasRefPoint << ", refPoint )";
1460 ::SMESH_MeshEditor anEditor( myMesh );
1461 SMESH::SMESH_MeshEditor::Extrusion_Error error =
1462 convExtrError( anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
1463 theHasAngles, angles,
1464 theHasRefPoint, refPnt ) );
1466 StoreResult(anEditor);
1471 //=======================================================================
1472 //function : ExtrusionAlongPathObject
1474 //=======================================================================
1476 SMESH::SMESH_MeshEditor::Extrusion_Error
1477 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
1478 SMESH::SMESH_Mesh_ptr thePathMesh,
1479 GEOM::GEOM_Object_ptr thePathShape,
1480 CORBA::Long theNodeStart,
1481 CORBA::Boolean theHasAngles,
1482 const SMESH::double_array & theAngles,
1483 CORBA::Boolean theHasRefPoint,
1484 const SMESH::PointStruct & theRefPoint)
1488 SMESH::long_array_var anElementsId = theObject->GetIDs();
1489 SMESH::SMESH_MeshEditor::Extrusion_Error error = ExtrusionAlongPath
1490 (anElementsId, thePathMesh, thePathShape, theNodeStart,
1491 theHasAngles, theAngles, theHasRefPoint, theRefPoint);
1493 // Clear python line, created by ExtrusionAlongPath()
1494 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1495 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1497 // Update Python script
1498 TPythonDump() << "rotAngles = " << theAngles;
1499 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
1500 << theObject << ", "
1501 << thePathMesh << ", "
1502 << thePathShape << ", "
1503 << theNodeStart << ", "
1504 << theHasAngles << ", "
1505 << "rotAngles" << ", "
1506 << theHasRefPoint<<", refPoint )";
1511 //================================================================================
1513 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
1514 * of given angles along path steps
1515 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
1516 * which proceeds the extrusion
1517 * \param PathShape is shape(edge); as the mesh can be complex, the edge
1518 * is used to define the sub-mesh for the path
1520 //================================================================================
1522 SMESH::double_array*
1523 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
1524 GEOM::GEOM_Object_ptr thePathShape,
1525 const SMESH::double_array & theAngles)
1527 SMESH::double_array_var aResult = new SMESH::double_array();
1528 return aResult._retn();
1531 //=======================================================================
1534 //=======================================================================
1536 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
1537 const SMESH::AxisStruct & theAxis,
1538 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
1539 CORBA::Boolean theCopy)
1543 SMESHDS_Mesh* aMesh = GetMeshDS();
1545 TIDSortedElemSet elements;
1546 ToMap(theIDsOfElements, aMesh, elements);
1548 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
1549 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
1552 TCollection_AsciiString typeStr;
1553 switch ( theMirrorType ) {
1554 case SMESH::SMESH_MeshEditor::POINT:
1555 aTrsf.SetMirror( P );
1556 typeStr = "SMESH.SMESH_MeshEditor.POINT";
1558 case SMESH::SMESH_MeshEditor::AXIS:
1559 aTrsf.SetMirror( gp_Ax1( P, V ));
1560 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
1563 aTrsf.SetMirror( gp_Ax2( P, V ));
1564 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
1567 // Update Python script
1568 TPythonDump() << this << ".Mirror( "
1569 << theIDsOfElements << ", "
1574 ::SMESH_MeshEditor anEditor( myMesh );
1575 anEditor.Transform (elements, aTrsf, theCopy);
1578 StoreResult(anEditor);
1583 //=======================================================================
1584 //function : MirrorObject
1586 //=======================================================================
1588 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
1589 const SMESH::AxisStruct & theAxis,
1590 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
1591 CORBA::Boolean theCopy)
1595 SMESH::long_array_var anElementsId = theObject->GetIDs();
1596 Mirror(anElementsId, theAxis, theMirrorType, theCopy);
1598 // Clear python line, created by Mirror()
1599 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1600 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1602 // Update Python script
1603 TCollection_AsciiString typeStr;
1604 switch ( theMirrorType ) {
1605 case SMESH::SMESH_MeshEditor::POINT:
1606 typeStr = "SMESH.SMESH_MeshEditor.POINT";
1608 case SMESH::SMESH_MeshEditor::AXIS:
1609 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
1612 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
1614 TPythonDump() << "axis = " << theAxis;
1615 TPythonDump() << this << ".MirrorObject( "
1616 << theObject << ", "
1622 //=======================================================================
1623 //function : Translate
1625 //=======================================================================
1627 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
1628 const SMESH::DirStruct & theVector,
1629 CORBA::Boolean theCopy)
1633 SMESHDS_Mesh* aMesh = GetMeshDS();
1635 TIDSortedElemSet elements;
1636 ToMap(theIDsOfElements, aMesh, elements);
1639 const SMESH::PointStruct * P = &theVector.PS;
1640 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
1642 ::SMESH_MeshEditor anEditor( myMesh );
1643 anEditor.Transform (elements, aTrsf, theCopy);
1646 StoreResult(anEditor);
1649 // Update Python script
1650 TPythonDump() << "vector = " << theVector;
1651 TPythonDump() << this << ".Translate( "
1657 //=======================================================================
1658 //function : TranslateObject
1660 //=======================================================================
1662 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
1663 const SMESH::DirStruct & theVector,
1664 CORBA::Boolean theCopy)
1668 SMESH::long_array_var anElementsId = theObject->GetIDs();
1669 Translate(anElementsId, theVector, theCopy);
1671 // Clear python line, created by Translate()
1672 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1673 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1675 // Update Python script
1676 TPythonDump() << this << ".TranslateObject( "
1682 //=======================================================================
1685 //=======================================================================
1687 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
1688 const SMESH::AxisStruct & theAxis,
1689 CORBA::Double theAngle,
1690 CORBA::Boolean theCopy)
1694 SMESHDS_Mesh* aMesh = GetMeshDS();
1696 TIDSortedElemSet elements;
1697 ToMap(theIDsOfElements, aMesh, elements);
1699 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
1700 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
1703 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
1705 ::SMESH_MeshEditor anEditor( myMesh );
1706 anEditor.Transform (elements, aTrsf, theCopy);
1709 StoreResult(anEditor);
1712 // Update Python script
1713 TPythonDump() << "axis = " << theAxis;
1714 TPythonDump() << this << ".Rotate( "
1721 //=======================================================================
1722 //function : RotateObject
1724 //=======================================================================
1726 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
1727 const SMESH::AxisStruct & theAxis,
1728 CORBA::Double theAngle,
1729 CORBA::Boolean theCopy)
1733 SMESH::long_array_var anElementsId = theObject->GetIDs();
1734 Rotate(anElementsId, theAxis, theAngle, theCopy);
1736 // Clear python line, created by Rotate()
1737 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1738 aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1740 // Update Python script
1741 TPythonDump() << this << ".RotateObject( "
1748 //=======================================================================
1749 //function : FindCoincidentNodes
1751 //=======================================================================
1753 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
1754 SMESH::array_of_long_array_out GroupsOfNodes)
1758 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
1759 ::SMESH_MeshEditor anEditor( myMesh );
1760 set<const SMDS_MeshNode*> nodes; // no input nodes
1761 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
1763 GroupsOfNodes = new SMESH::array_of_long_array;
1764 GroupsOfNodes->length( aListOfListOfNodes.size() );
1765 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
1766 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
1767 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
1768 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
1769 SMESH::long_array& aGroup = GroupsOfNodes[ i ];
1770 aGroup.length( aListOfNodes.size() );
1771 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
1772 aGroup[ j ] = (*lIt)->GetID();
1774 // Update Python script
1775 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
1776 << Tolerance << " )";
1779 //=======================================================================
1780 //function : MergeNodes
1782 //=======================================================================
1784 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
1788 SMESHDS_Mesh* aMesh = GetMeshDS();
1790 TPythonDump aTPythonDump;
1791 aTPythonDump << this << ".MergeNodes([";
1792 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
1793 for (int i = 0; i < GroupsOfNodes.length(); i++)
1795 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
1796 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
1797 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
1798 for ( int j = 0; j < aNodeGroup.length(); j++ )
1800 CORBA::Long index = aNodeGroup[ j ];
1801 const SMDS_MeshNode * node = aMesh->FindNode(index);
1803 aListOfNodes.push_back( node );
1805 if ( aListOfNodes.size() < 2 )
1806 aListOfListOfNodes.pop_back();
1808 if ( i > 0 ) aTPythonDump << ", ";
1809 aTPythonDump << aNodeGroup;
1811 ::SMESH_MeshEditor anEditor( myMesh );
1812 anEditor.MergeNodes( aListOfListOfNodes );
1814 // Update Python script
1815 aTPythonDump << "])";
1818 //=======================================================================
1819 //function : MergeEqualElements
1821 //=======================================================================
1823 void SMESH_MeshEditor_i::MergeEqualElements()
1827 ::SMESH_MeshEditor anEditor( myMesh );
1828 anEditor.MergeEqualElements();
1830 // Update Python script
1831 TPythonDump() << this << ".MergeEqualElements()";
1834 //================================================================================
1836 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
1837 * move the node closest to the point to point's location and return ID of the node
1839 //================================================================================
1841 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
1844 CORBA::Long theNodeID)
1846 // We keep myNodeSearcher until any mesh modification:
1847 // 1) initData() deletes myNodeSearcher at any edition,
1848 // 2) TNodeSearcherDeleter - at any mesh compute event
1852 int nodeID = theNodeID;
1853 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
1856 if ( !myNodeSearcher ) {
1857 ::SMESH_MeshEditor anEditor( myMesh );
1858 myNodeSearcher = anEditor.GetNodeSearcher();
1859 static TNodeSearcherDeleter deleter;
1860 deleter.Set( myMesh );
1863 node = myNodeSearcher->FindClosestTo( p );
1866 nodeID = node->GetID();
1867 if ( myPreviewMode ) // make preview data
1869 // in a preview mesh, make edges linked to a node
1870 TPreviewMesh tmpMesh;
1871 TIDSortedElemSet linkedNodes;
1872 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
1873 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
1874 for ( ; nIt != linkedNodes.end(); ++nIt )
1876 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
1877 tmpMesh.Copy( &edge );
1880 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
1882 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
1883 // fill preview data
1884 ::SMESH_MeshEditor anEditor( & tmpMesh );
1885 StoreResult( anEditor );
1889 GetMeshDS()->MoveNode(node, x, y, z);
1893 if ( !myPreviewMode ) {
1894 // Update Python script
1895 TPythonDump() << "nodeID = " << this
1896 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z << " )";
1902 //=======================================================================
1903 //function : convError
1905 //=======================================================================
1907 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1909 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
1913 RETCASE( SEW_BORDER1_NOT_FOUND );
1914 RETCASE( SEW_BORDER2_NOT_FOUND );
1915 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
1916 RETCASE( SEW_BAD_SIDE_NODES );
1917 RETCASE( SEW_VOLUMES_TO_SPLIT );
1918 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
1919 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
1920 RETCASE( SEW_BAD_SIDE1_NODES );
1921 RETCASE( SEW_BAD_SIDE2_NODES );
1923 return SMESH::SMESH_MeshEditor::SEW_OK;
1926 //=======================================================================
1927 //function : SewFreeBorders
1929 //=======================================================================
1931 SMESH::SMESH_MeshEditor::Sew_Error
1932 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
1933 CORBA::Long SecondNodeID1,
1934 CORBA::Long LastNodeID1,
1935 CORBA::Long FirstNodeID2,
1936 CORBA::Long SecondNodeID2,
1937 CORBA::Long LastNodeID2,
1938 CORBA::Boolean CreatePolygons,
1939 CORBA::Boolean CreatePolyedrs)
1943 SMESHDS_Mesh* aMesh = GetMeshDS();
1945 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
1946 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
1947 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
1948 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
1949 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
1950 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
1952 if (!aBorderFirstNode ||
1953 !aBorderSecondNode||
1955 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1956 if (!aSide2FirstNode ||
1957 !aSide2SecondNode ||
1959 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
1961 // Update Python script
1962 TPythonDump() << "error = " << this << ".SewFreeBorders( "
1963 << FirstNodeID1 << ", "
1964 << SecondNodeID1 << ", "
1965 << LastNodeID1 << ", "
1966 << FirstNodeID2 << ", "
1967 << SecondNodeID2 << ", "
1968 << LastNodeID2 << ", "
1969 << CreatePolygons<< ", "
1970 << CreatePolyedrs<< " )";
1972 ::SMESH_MeshEditor anEditor( myMesh );
1973 SMESH::SMESH_MeshEditor::Sew_Error error =
1974 convError( anEditor.SewFreeBorder (aBorderFirstNode,
1984 StoreResult(anEditor);
1990 //=======================================================================
1991 //function : SewConformFreeBorders
1993 //=======================================================================
1995 SMESH::SMESH_MeshEditor::Sew_Error
1996 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
1997 CORBA::Long SecondNodeID1,
1998 CORBA::Long LastNodeID1,
1999 CORBA::Long FirstNodeID2,
2000 CORBA::Long SecondNodeID2)
2004 SMESHDS_Mesh* aMesh = GetMeshDS();
2006 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
2007 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
2008 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
2009 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
2010 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
2011 const SMDS_MeshNode* aSide2ThirdNode = 0;
2013 if (!aBorderFirstNode ||
2014 !aBorderSecondNode||
2016 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
2017 if (!aSide2FirstNode ||
2019 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
2021 // Update Python script
2022 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
2023 << FirstNodeID1 << ", "
2024 << SecondNodeID1 << ", "
2025 << LastNodeID1 << ", "
2026 << FirstNodeID2 << ", "
2027 << SecondNodeID2 << " )";
2029 ::SMESH_MeshEditor anEditor( myMesh );
2030 SMESH::SMESH_MeshEditor::Sew_Error error =
2031 convError( anEditor.SewFreeBorder (aBorderFirstNode,
2040 StoreResult(anEditor);
2046 //=======================================================================
2047 //function : SewBorderToSide
2049 //=======================================================================
2051 SMESH::SMESH_MeshEditor::Sew_Error
2052 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
2053 CORBA::Long SecondNodeIDOnFreeBorder,
2054 CORBA::Long LastNodeIDOnFreeBorder,
2055 CORBA::Long FirstNodeIDOnSide,
2056 CORBA::Long LastNodeIDOnSide,
2057 CORBA::Boolean CreatePolygons,
2058 CORBA::Boolean CreatePolyedrs)
2062 SMESHDS_Mesh* aMesh = GetMeshDS();
2064 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
2065 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
2066 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
2067 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
2068 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
2069 const SMDS_MeshNode* aSide2ThirdNode = 0;
2071 if (!aBorderFirstNode ||
2072 !aBorderSecondNode||
2074 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
2075 if (!aSide2FirstNode ||
2077 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
2079 // Update Python script
2080 TPythonDump() << "error = " << this << ".SewBorderToSide( "
2081 << FirstNodeIDOnFreeBorder << ", "
2082 << SecondNodeIDOnFreeBorder << ", "
2083 << LastNodeIDOnFreeBorder << ", "
2084 << FirstNodeIDOnSide << ", "
2085 << LastNodeIDOnSide << ", "
2086 << CreatePolygons << ", "
2087 << CreatePolyedrs << ") ";
2089 ::SMESH_MeshEditor anEditor( myMesh );
2090 SMESH::SMESH_MeshEditor::Sew_Error error =
2091 convError( anEditor.SewFreeBorder (aBorderFirstNode,
2101 StoreResult(anEditor);
2107 //=======================================================================
2108 //function : SewSideElements
2110 //=======================================================================
2112 SMESH::SMESH_MeshEditor::Sew_Error
2113 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
2114 const SMESH::long_array& IDsOfSide2Elements,
2115 CORBA::Long NodeID1OfSide1ToMerge,
2116 CORBA::Long NodeID1OfSide2ToMerge,
2117 CORBA::Long NodeID2OfSide1ToMerge,
2118 CORBA::Long NodeID2OfSide2ToMerge)
2122 SMESHDS_Mesh* aMesh = GetMeshDS();
2124 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
2125 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
2126 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
2127 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
2129 if (!aFirstNode1ToMerge ||
2130 !aFirstNode2ToMerge )
2131 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
2132 if (!aSecondNode1ToMerge||
2133 !aSecondNode2ToMerge)
2134 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
2136 TIDSortedElemSet aSide1Elems, aSide2Elems;
2137 ToMap(IDsOfSide1Elements, aMesh, aSide1Elems);
2138 ToMap(IDsOfSide2Elements, aMesh, aSide2Elems);
2140 // Update Python script
2141 TPythonDump() << "error = " << this << ".SewSideElements( "
2142 << IDsOfSide1Elements << ", "
2143 << IDsOfSide2Elements << ", "
2144 << NodeID1OfSide1ToMerge << ", "
2145 << NodeID1OfSide2ToMerge << ", "
2146 << NodeID2OfSide1ToMerge << ", "
2147 << NodeID2OfSide2ToMerge << ")";
2149 ::SMESH_MeshEditor anEditor( myMesh );
2150 SMESH::SMESH_MeshEditor::Sew_Error error =
2151 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
2154 aSecondNode1ToMerge,
2155 aSecondNode2ToMerge));
2157 StoreResult(anEditor);
2162 //================================================================================
2164 * \brief Set new nodes for given element
2165 * \param ide - element id
2166 * \param newIDs - new node ids
2167 * \retval CORBA::Boolean - true if result is OK
2169 //================================================================================
2171 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
2172 const SMESH::long_array& newIDs)
2176 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
2177 if(!elem) return false;
2179 int nbn = newIDs.length();
2181 const SMDS_MeshNode* aNodes [nbn];
2184 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
2187 aNodes[nbn1] = aNode;
2190 // Update Python script
2191 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
2192 << ide << ", " << newIDs << " )";
2194 TPythonDump() << "print 'ChangeElemNodes: ', isDone";
2197 return GetMeshDS()->ChangeElementNodes( elem, aNodes, nbn1+1 );
2200 //================================================================================
2202 * \brief Update myLastCreated* or myPreviewData
2203 * \param anEditor - it contains last modification results
2205 //================================================================================
2207 void SMESH_MeshEditor_i::StoreResult(::SMESH_MeshEditor& anEditor)
2209 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
2211 list<int> aNodesConnectivity;
2212 typedef map<int, int> TNodesMap;
2215 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
2216 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
2218 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
2219 int nbEdges = aMeshDS->NbEdges();
2220 int nbFaces = aMeshDS->NbFaces();
2221 int nbVolum = aMeshDS->NbVolumes();
2222 switch ( previewType ) {
2223 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
2224 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
2225 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
2228 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
2229 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
2231 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
2233 while ( itMeshElems->more() ) {
2234 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
2235 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
2238 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
2239 while ( itElemNodes->more() ) {
2240 const SMDS_MeshNode* aMeshNode =
2241 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
2242 int aNodeID = aMeshNode->GetID();
2243 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
2244 if ( anIter == nodesMap.end() ) {
2245 // filling the nodes coordinates
2246 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
2247 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
2248 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
2249 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
2252 aNodesConnectivity.push_back(anIter->second);
2255 // filling the elements types
2256 SMDSAbs_ElementType aType;
2258 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
2259 aType = SMDSAbs_Node;
2263 aType = aMeshElem->GetType();
2264 isPoly = aMeshElem->IsPoly();
2267 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
2268 myPreviewData->elementTypes[i].isPoly = isPoly;
2269 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
2273 myPreviewData->nodesXYZ.length( j );
2275 // filling the elements connectivities
2276 list<int>::iterator aConnIter = aNodesConnectivity.begin();
2277 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
2278 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
2279 myPreviewData->elementConnectivities[i] = *aConnIter;
2285 // add new nodes into myLastCreatedNodes
2286 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
2287 myLastCreatedNodes->length(aSeq.Length());
2288 for(int i=0; i<aSeq.Length(); i++)
2289 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
2292 // add new elements into myLastCreatedElems
2293 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
2294 myLastCreatedElems->length(aSeq.Length());
2295 for(int i=0; i<aSeq.Length(); i++)
2296 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
2300 //================================================================================
2302 * Return data of mesh edition preview
2304 //================================================================================
2306 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
2308 return myPreviewData._retn();
2311 //================================================================================
2313 * \brief Returns list of it's IDs of created nodes
2314 * \retval SMESH::long_array* - list of node ID
2316 //================================================================================
2318 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
2320 return myLastCreatedNodes._retn();
2323 //================================================================================
2325 * \brief Returns list of it's IDs of created elements
2326 * \retval SMESH::long_array* - list of elements' ID
2328 //================================================================================
2330 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
2332 return myLastCreatedElems._retn();
2335 //=======================================================================
2336 //function : ConvertToQuadratic
2338 //=======================================================================
2340 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
2342 ::SMESH_MeshEditor anEditor( myMesh );
2343 anEditor.ConvertToQuadratic(theForce3d);
2344 // Update Python script
2345 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
2348 //=======================================================================
2349 //function : ConvertFromQuadratic
2351 //=======================================================================
2353 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
2355 ::SMESH_MeshEditor anEditor( myMesh );
2356 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
2357 // Update Python script
2358 TPythonDump() << this << ".ConvertFromQuadratic()";