X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_MeshEditor_i.cxx;h=2af4dc18e57320f9fabbec0188c89b36f1205941;hp=ff3eed5e8eedafd07c8b472ab3b852e5fee815d4;hb=bbd637f1323572d6977c72f404142bc5bfb70787;hpb=358f8ddd54e7ed553eecc22ca665575e4019e3a0 diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index ff3eed5e8..2af4dc18e 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -37,10 +37,17 @@ #include "SMESH_Gen_i.hxx" #include "SMESH_Filter_i.hxx" #include "SMESH_PythonDump.hxx" -#include "CASCatch.hxx" #include "utilities.h" - +#include "Utils_ExceptHandlers.hxx" +#include "Utils_CorbaException.hxx" + +#include +#include +#include +#include +#include +#include #include #include #include @@ -53,8 +60,6 @@ #ifdef NO_CAS_CATCH #include -#else -#include "CASCatch.hxx" #endif #include @@ -198,6 +203,22 @@ namespace { } } }; + + TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType ) + { + TCollection_AsciiString typeStr; + switch ( theMirrorType ) { + case SMESH::SMESH_MeshEditor::POINT: + typeStr = "SMESH.SMESH_MeshEditor.POINT"; + break; + case SMESH::SMESH_MeshEditor::AXIS: + typeStr = "SMESH.SMESH_MeshEditor.AXIS"; + break; + default: + typeStr = "SMESH.SMESH_MeshEditor.PLANE"; + } + return typeStr; + } } //============================================================================= @@ -206,9 +227,10 @@ namespace { */ //============================================================================= -SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh* theMesh, bool isPreview) +SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview) { - myMesh = theMesh; + myMesh_i = theMesh; + myMesh = & theMesh->GetImpl(); myPreviewMode = isPreview; } @@ -363,7 +385,7 @@ CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes) int NbNodes = IDsOfNodes.length(); if (NbNodes < 3) { - return false; + return 0; } std::vector nodes (NbNodes); @@ -548,6 +570,184 @@ CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces return 0; } +//============================================================================= +/*! + * \brief Bind a node to a vertex + * \param NodeID - node ID + * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0] + * \retval boolean - false if NodeID or VertexID is invalid + */ +//============================================================================= + +void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID) + throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + + SMESHDS_Mesh * mesh = GetMeshDS(); + SMDS_MeshNode* node = const_cast( mesh->FindNode(NodeID) ); + if ( !node ) + THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM); + + if ( mesh->MaxShapeIndex() < VertexID ) + THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM); + + TopoDS_Shape shape = mesh->IndexToShape( VertexID ); + if ( shape.ShapeType() != TopAbs_VERTEX ) + THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM); + + mesh->SetNodeOnVertex( node, VertexID ); +} + +//============================================================================= +/*! + * \brief Store node position on an edge + * \param NodeID - node ID + * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0] + * \param paramOnEdge - parameter on edge where the node is located + * \retval boolean - false if any parameter is invalid + */ +//============================================================================= + +void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID, + CORBA::Double paramOnEdge) + throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + + SMESHDS_Mesh * mesh = GetMeshDS(); + SMDS_MeshNode* node = const_cast( mesh->FindNode(NodeID) ); + if ( !node ) + THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM); + + if ( mesh->MaxShapeIndex() < EdgeID ) + THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM); + + TopoDS_Shape shape = mesh->IndexToShape( EdgeID ); + if ( shape.ShapeType() != TopAbs_EDGE ) + THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM); + + Standard_Real f,l; + BRep_Tool::Range( TopoDS::Edge( shape ), f,l); + if ( paramOnEdge < f || paramOnEdge > l ) + THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM); + + mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge ); +} + +//============================================================================= +/*! + * \brief Store node position on a face + * \param NodeID - node ID + * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0] + * \param u - U parameter on face where the node is located + * \param v - V parameter on face where the node is located + * \retval boolean - false if any parameter is invalid + */ +//============================================================================= + +void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID, + CORBA::Double u, CORBA::Double v) + throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + + SMESHDS_Mesh * mesh = GetMeshDS(); + SMDS_MeshNode* node = const_cast( mesh->FindNode(NodeID) ); + if ( !node ) + THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM); + + if ( mesh->MaxShapeIndex() < FaceID ) + THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM); + + TopoDS_Shape shape = mesh->IndexToShape( FaceID ); + if ( shape.ShapeType() != TopAbs_FACE ) + THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM); + + BRepAdaptor_Surface surf( TopoDS::Face( shape )); + bool isOut = ( u < surf.FirstUParameter() || + u > surf.LastUParameter() || + v < surf.FirstVParameter() || + v > surf.LastVParameter() ); + + if ( isOut ) { +#ifdef _DEBUG_ + MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of " + << " u( " << surf.FirstUParameter() + << "," << surf.LastUParameter() + << ") v( " << surf.FirstVParameter() + << "," << surf.LastVParameter() << ")" ); +#endif + THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM); + } + + mesh->SetNodeOnFace( node, FaceID, u, v ); +} + +//============================================================================= +/*! + * \brief Bind a node to a solid + * \param NodeID - node ID + * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0] + * \retval boolean - false if NodeID or SolidID is invalid + */ +//============================================================================= + +void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID) + throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + + SMESHDS_Mesh * mesh = GetMeshDS(); + SMDS_MeshNode* node = const_cast( mesh->FindNode(NodeID) ); + if ( !node ) + THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM); + + if ( mesh->MaxShapeIndex() < SolidID ) + THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM); + + TopoDS_Shape shape = mesh->IndexToShape( SolidID ); + if ( shape.ShapeType() != TopAbs_SOLID && + shape.ShapeType() != TopAbs_SHELL) + THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM); + + mesh->SetNodeInVolume( node, SolidID ); +} + +//============================================================================= +/*! + * \brief Bind an element to a shape + * \param ElementID - element ID + * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0] + * \retval boolean - false if ElementID or ShapeID is invalid + */ +//============================================================================= + +void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID, + CORBA::Long ShapeID) + throw (SALOME::SALOME_Exception) +{ + Unexpect aCatch(SALOME_SalomeException); + + SMESHDS_Mesh * mesh = GetMeshDS(); + SMDS_MeshElement* elem = const_cast(mesh->FindElement(ElementID)); + if ( !elem ) + THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM); + + if ( mesh->MaxShapeIndex() < ShapeID ) + THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM); + + TopoDS_Shape shape = mesh->IndexToShape( ShapeID ); + if ( shape.ShapeType() != TopAbs_EDGE && + shape.ShapeType() != TopAbs_FACE && + shape.ShapeType() != TopAbs_SOLID && + shape.ShapeType() != TopAbs_SHELL ) + THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM); + + mesh->SetMeshElementOnShape( elem, ShapeID ); +} + + //============================================================================= /*! * @@ -622,7 +822,7 @@ CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1, bool stat = aMeshEditor.DeleteDiag ( n1, n2 ); - StoreResult(aMeshEditor); + storeResult(aMeshEditor); return stat; } @@ -687,10 +887,10 @@ namespace */ //================================================================================ - void ToMap(const SMESH::long_array & IDs, - const SMESHDS_Mesh* aMesh, - TIDSortedElemSet& aMap, - const SMDSAbs_ElementType aType = SMDSAbs_All ) + void arrayToSet(const SMESH::long_array & IDs, + const SMESHDS_Mesh* aMesh, + TIDSortedElemSet& aMap, + const SMDSAbs_ElementType aType = SMDSAbs_All ) { for (int i=0; i( SMESH_Gen_i::GetServant( Criterion ).in() ); @@ -735,7 +935,7 @@ CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfE bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle ); - StoreResult(anEditor); + storeResult(anEditor); return stat; } @@ -788,7 +988,7 @@ CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfE SMESHDS_Mesh* aMesh = GetMeshDS(); TIDSortedElemSet faces; - ToMap(IDsOfElements, aMesh, faces, SMDSAbs_Face); + arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face); SMESH::NumericalFunctor_i* aNumericalFunctor = dynamic_cast( SMESH_Gen_i::GetServant( Criterion ).in() ); @@ -808,7 +1008,7 @@ CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfE ::SMESH_MeshEditor anEditor( myMesh ); CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit ); - StoreResult(anEditor); + storeResult(anEditor); return stat; } @@ -859,7 +1059,7 @@ CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfEle SMESHDS_Mesh* aMesh = GetMeshDS(); TIDSortedElemSet faces; - ToMap(IDsOfElements, aMesh, faces, SMDSAbs_Face); + arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face); // Update Python script TPythonDump() << "isDone = " << this << ".SplitQuad( " @@ -871,7 +1071,7 @@ CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfEle ::SMESH_MeshEditor anEditor( myMesh ); CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 ); - StoreResult(anEditor); + storeResult(anEditor); return stat; } @@ -1021,7 +1221,7 @@ CORBA::Boolean SMESHDS_Mesh* aMesh = GetMeshDS(); TIDSortedElemSet elements; - ToMap(IDsOfElements, aMesh, elements, SMDSAbs_Face); + arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face); set fixedNodes; for (int i = 0; i < IDsOfFixedNodes.length(); i++) { @@ -1038,7 +1238,7 @@ CORBA::Boolean anEditor.Smooth(elements, fixedNodes, method, MaxNbOfIterations, MaxAspectRatio, IsParametric ); - StoreResult(anEditor); + storeResult(anEditor); // Update Python script TPythonDump() << "isDone = " << this << "." @@ -1128,22 +1328,38 @@ void SMESH_MeshEditor_i::RenumberElements() GetMeshDS()->Renumber( false ); } +//======================================================================= + /*! + * \brief Return groups by their IDs + */ +//======================================================================= + +SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list* groupIDs) +{ + if ( !groupIDs ) + return 0; + myMesh_i->CreateGroupServants(); + return myMesh_i->GetGroups( *groupIDs ); +} //======================================================================= -//function : RotationSweep -//purpose : +//function : rotationSweep +//purpose : //======================================================================= -void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements, - const SMESH::AxisStruct & theAxis, - CORBA::Double theAngleInRadians, - CORBA::Long theNbOfSteps, - CORBA::Double theTolerance) +SMESH::ListOfGroups* +SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements, + const SMESH::AxisStruct & theAxis, + CORBA::Double theAngleInRadians, + CORBA::Long theNbOfSteps, + CORBA::Double theTolerance, + const bool theMakeGroups, + const SMDSAbs_ElementType theElementType) { initData(); TIDSortedElemSet inElements, copyElements; - ToMap(theIDsOfElements, GetMeshDS(), inElements); + arrayToSet(theIDsOfElements, GetMeshDS(), inElements, theElementType); TIDSortedElemSet* workElements = & inElements; TPreviewMesh tmpMesh( SMDSAbs_Face ); @@ -1166,21 +1382,70 @@ void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElement gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz )); ::SMESH_MeshEditor anEditor( mesh ); - anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians, - theNbOfSteps, theTolerance, makeWalls); + ::SMESH_MeshEditor::PGroupIDs groupIds = + anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians, + theNbOfSteps, theTolerance, theMakeGroups, makeWalls); + storeResult(anEditor); + + return theMakeGroups ? getGroups(groupIds.get()) : 0; +} - StoreResult(anEditor); +//======================================================================= +//function : RotationSweep +//purpose : +//======================================================================= +void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements, + const SMESH::AxisStruct & theAxis, + CORBA::Double theAngleInRadians, + CORBA::Long theNbOfSteps, + CORBA::Double theTolerance) +{ if ( !myPreviewMode ) { - // Update Python script - TPythonDump() << "axis = " << theAxis; TPythonDump() << this << ".RotationSweep( " - << theIDsOfElements - << ", axis, " + << theIDsOfElements << ", " + << theAxis << ", " << theAngleInRadians << ", " << theNbOfSteps << ", " << theTolerance << " )"; } + rotationSweep(theIDsOfElements, + theAxis, + theAngleInRadians, + theNbOfSteps, + theTolerance, + false); +} + +//======================================================================= +//function : RotationSweepMakeGroups +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements, + const SMESH::AxisStruct& theAxis, + CORBA::Double theAngleInRadians, + CORBA::Long theNbOfSteps, + CORBA::Double theTolerance) +{ + SMESH::ListOfGroups *aGroups = rotationSweep(theIDsOfElements, + theAxis, + theAngleInRadians, + theNbOfSteps, + theTolerance, + true); + if ( !myPreviewMode ) { + TPythonDump aPythonDump; + DumpGroupsList(aPythonDump,aGroups); + aPythonDump<< this << ".RotationSweepMakeGroups( " + << theIDsOfElements << ", " + << theAxis << ", " + << theAngleInRadians << ", " + << theNbOfSteps << ", " + << theTolerance << " )"; + } + return aGroups; } //======================================================================= @@ -1194,68 +1459,234 @@ void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject CORBA::Long theNbOfSteps, CORBA::Double theTolerance) { - initData(); - + if ( !myPreviewMode ) { + TPythonDump() << this << ".RotationSweepObject( " + << theObject << ", " + << theAxis << ", " + << theAngleInRadians << ", " + << theNbOfSteps << ", " + << theTolerance << " )"; + } SMESH::long_array_var anElementsId = theObject->GetIDs(); - RotationSweep(anElementsId, theAxis, theAngleInRadians, theNbOfSteps, theTolerance); + rotationSweep(anElementsId, + theAxis, + theAngleInRadians, + theNbOfSteps, + theTolerance, + false); +} - // Clear python line, created by RotationSweep() - SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); - aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID()); +//======================================================================= +//function : RotationSweepObject1D +//purpose : +//======================================================================= - // Update Python script - TPythonDump() << this << ".RotationSweepObject( " - << theObject - << ", axis, " - << theAngleInRadians << ", " - << theNbOfSteps << ", " - << theTolerance << " )"; +void SMESH_MeshEditor_i::RotationSweepObject1D(SMESH::SMESH_IDSource_ptr theObject, + const SMESH::AxisStruct & theAxis, + CORBA::Double theAngleInRadians, + CORBA::Long theNbOfSteps, + CORBA::Double theTolerance) +{ + if ( !myPreviewMode ) { + TPythonDump() << this << ".RotationSweepObject1D( " + << theObject << ", " + << theAxis << ", " + << theAngleInRadians << ", " + << theNbOfSteps << ", " + << theTolerance << " )"; + } + SMESH::long_array_var anElementsId = theObject->GetIDs(); + rotationSweep(anElementsId, + theAxis, + theAngleInRadians, + theNbOfSteps, + theTolerance, + false, + SMDSAbs_Edge); } //======================================================================= -//function : ExtrusionSweep +//function : RotationSweepObject2D //purpose : //======================================================================= -void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements, - const SMESH::DirStruct & theStepVector, - CORBA::Long theNbOfSteps) +void SMESH_MeshEditor_i::RotationSweepObject2D(SMESH::SMESH_IDSource_ptr theObject, + const SMESH::AxisStruct & theAxis, + CORBA::Double theAngleInRadians, + CORBA::Long theNbOfSteps, + CORBA::Double theTolerance) +{ + if ( !myPreviewMode ) { + TPythonDump() << this << ".RotationSweepObject2D( " + << theObject << ", " + << theAxis << ", " + << theAngleInRadians << ", " + << theNbOfSteps << ", " + << theTolerance << " )"; + } + SMESH::long_array_var anElementsId = theObject->GetIDs(); + rotationSweep(anElementsId, + theAxis, + theAngleInRadians, + theNbOfSteps, + theTolerance, + false, + SMDSAbs_Face); +} + +//======================================================================= +//function : RotationSweepObjectMakeGroups +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject, + const SMESH::AxisStruct& theAxis, + CORBA::Double theAngleInRadians, + CORBA::Long theNbOfSteps, + CORBA::Double theTolerance) +{ + SMESH::long_array_var anElementsId = theObject->GetIDs(); + SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId, + theAxis, + theAngleInRadians, + theNbOfSteps, + theTolerance, + true); + if ( !myPreviewMode ) { + TPythonDump aPythonDump; + DumpGroupsList(aPythonDump,aGroups); + aPythonDump<< this << ".RotationSweepObjectMakeGroups( " + << theObject << ", " + << theAxis << ", " + << theAngleInRadians << ", " + << theNbOfSteps << ", " + << theTolerance << " )"; + } + return aGroups; +} + +//======================================================================= +//function : RotationSweepObject1DMakeGroups +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::RotationSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject, + const SMESH::AxisStruct& theAxis, + CORBA::Double theAngleInRadians, + CORBA::Long theNbOfSteps, + CORBA::Double theTolerance) +{ + SMESH::long_array_var anElementsId = theObject->GetIDs(); + SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId, + theAxis, + theAngleInRadians, + theNbOfSteps, + theTolerance, + true, + SMDSAbs_Edge); + if ( !myPreviewMode ) { + TPythonDump aPythonDump; + DumpGroupsList(aPythonDump,aGroups); + aPythonDump<< this << ".RotationSweepObject1DMakeGroups( " + << theObject << ", " + << theAxis << ", " + << theAngleInRadians << ", " + << theNbOfSteps << ", " + << theTolerance << " )"; + } + return aGroups; +} + +//======================================================================= +//function : RotationSweepObject2DMakeGroups +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::RotationSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject, + const SMESH::AxisStruct& theAxis, + CORBA::Double theAngleInRadians, + CORBA::Long theNbOfSteps, + CORBA::Double theTolerance) +{ + SMESH::long_array_var anElementsId = theObject->GetIDs(); + SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId, + theAxis, + theAngleInRadians, + theNbOfSteps, + theTolerance, + true, + SMDSAbs_Face); + if ( !myPreviewMode ) { + TPythonDump aPythonDump; + DumpGroupsList(aPythonDump,aGroups); + aPythonDump<< this << ".RotationSweepObject2DMakeGroups( " + << theObject << ", " + << theAxis << ", " + << theAngleInRadians << ", " + << theNbOfSteps << ", " + << theTolerance << " )"; + } + return aGroups; +} + + +//======================================================================= +//function : extrusionSweep +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements, + const SMESH::DirStruct & theStepVector, + CORBA::Long theNbOfSteps, + const bool theMakeGroups, + const SMDSAbs_ElementType theElementType) { initData(); -#ifdef NO_CAS_CATCH try { +#ifdef NO_CAS_CATCH OCC_CATCH_SIGNALS; -#else - CASCatch_TRY { #endif - SMESHDS_Mesh* aMesh = GetMeshDS(); - TIDSortedElemSet elements; - ToMap(theIDsOfElements, aMesh, elements); + arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType); const SMESH::PointStruct * P = &theStepVector.PS; gp_Vec stepVec( P->x, P->y, P->z ); TElemOfElemListMap aHystory; ::SMESH_MeshEditor anEditor( myMesh ); - anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory); + ::SMESH_MeshEditor::PGroupIDs groupIds = + anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups); - StoreResult(anEditor); + storeResult(anEditor); - // Update Python script - TPythonDump() << "stepVector = " << theStepVector; - TPythonDump() << this << ".ExtrusionSweep( " - << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )"; + return theMakeGroups ? getGroups(groupIds.get()) : 0; -#ifdef NO_CAS_CATCH } catch(Standard_Failure) { -#else - } CASCatch_CATCH(Standard_Failure) { -#endif Handle(Standard_Failure) aFail = Standard_Failure::Caught(); INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() ); } + return 0; +} + +//======================================================================= +//function : ExtrusionSweep +//purpose : +//======================================================================= + +void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements, + const SMESH::DirStruct & theStepVector, + CORBA::Long theNbOfSteps) +{ + extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false ); + if ( !myPreviewMode ) { + TPythonDump() << this << ".ExtrusionSweep( " + << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )"; + } } @@ -1268,18 +1699,12 @@ void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObjec const SMESH::DirStruct & theStepVector, CORBA::Long theNbOfSteps) { - initData(); - SMESH::long_array_var anElementsId = theObject->GetIDs(); - ExtrusionSweep(anElementsId, theStepVector, theNbOfSteps); - - // Clear python line, created by ExtrusionSweep() - SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); - aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID()); - - // Update Python script - TPythonDump() << this << ".ExtrusionSweepObject( " - << theObject << ", stepVector, " << theNbOfSteps << " )"; + extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false ); + if ( !myPreviewMode ) { + TPythonDump() << this << ".ExtrusionSweepObject( " + << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )"; + } } //======================================================================= @@ -1291,29 +1716,12 @@ void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObj const SMESH::DirStruct & theStepVector, CORBA::Long theNbOfSteps) { - initData(); - - SMESHDS_Mesh* aMesh = GetMeshDS(); - - SMESH::long_array_var allElementsId = theObject->GetIDs(); - - TIDSortedElemSet elements; - ToMap(allElementsId, aMesh, elements); - - const SMESH::PointStruct * P = &theStepVector.PS; - gp_Vec stepVec( P->x, P->y, P->z ); - - ::SMESH_MeshEditor anEditor( myMesh ); - //anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps); - TElemOfElemListMap aHystory; - anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory); - - StoreResult(anEditor); - - // Update Python script - TPythonDump() << "stepVector = " << theStepVector; - TPythonDump() << this << ".ExtrusionSweepObject1D( " - << theObject << ", stepVector, " << theNbOfSteps << " )"; + SMESH::long_array_var anElementsId = theObject->GetIDs(); + extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge ); + if ( !myPreviewMode ) { + TPythonDump() << this << ".ExtrusionSweepObject1D( " + << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )"; + } } //======================================================================= @@ -1325,71 +1733,198 @@ void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObj const SMESH::DirStruct & theStepVector, CORBA::Long theNbOfSteps) { - initData(); - - SMESHDS_Mesh* aMesh = GetMeshDS(); - - SMESH::long_array_var allElementsId = theObject->GetIDs(); - - TIDSortedElemSet elements; - ToMap(allElementsId, aMesh, elements); - - const SMESH::PointStruct * P = &theStepVector.PS; - gp_Vec stepVec( P->x, P->y, P->z ); - - ::SMESH_MeshEditor anEditor( myMesh ); - //anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps); - TElemOfElemListMap aHystory; - anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory); - - StoreResult(anEditor); - - // Update Python script - TPythonDump() << "stepVector = " << theStepVector; - TPythonDump() << this << ".ExtrusionSweepObject2D( " - << theObject << ", stepVector, " << theNbOfSteps << " )"; + SMESH::long_array_var anElementsId = theObject->GetIDs(); + extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face ); + if ( !myPreviewMode ) { + TPythonDump() << this << ".ExtrusionSweepObject2D( " + << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )"; + } } - //======================================================================= -//function : AdvancedExtrusion -//purpose : +//function : ExtrusionSweepMakeGroups +//purpose : //======================================================================= -void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements, - const SMESH::DirStruct & theStepVector, - CORBA::Long theNbOfSteps, - CORBA::Long theExtrFlags, - CORBA::Double theSewTolerance) +SMESH::ListOfGroups* +SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements, + const SMESH::DirStruct& theStepVector, + CORBA::Long theNbOfSteps) { - initData(); - - SMESHDS_Mesh* aMesh = GetMeshDS(); + SMESH::ListOfGroups* aGroups = extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true ); + + if ( !myPreviewMode ) { + TPythonDump aPythonDump; + DumpGroupsList(aPythonDump,aGroups); + aPythonDump << this << ".ExtrusionSweepMakeGroups( " + << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )"; + } + return aGroups; +} +//======================================================================= +//function : ExtrusionSweepObjectMakeGroups +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject, + const SMESH::DirStruct& theStepVector, + CORBA::Long theNbOfSteps) +{ + SMESH::long_array_var anElementsId = theObject->GetIDs(); + SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true ); + + if ( !myPreviewMode ) { + TPythonDump aPythonDump; + DumpGroupsList(aPythonDump,aGroups); + aPythonDump<< this << ".ExtrusionSweepObjectMakeGroups( " + << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )"; + } + return aGroups; +} + +//======================================================================= +//function : ExtrusionSweepObject1DMakeGroups +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject, + const SMESH::DirStruct& theStepVector, + CORBA::Long theNbOfSteps) +{ + SMESH::long_array_var anElementsId = theObject->GetIDs(); + SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge ); + if ( !myPreviewMode ) { + TPythonDump aPythonDump; + DumpGroupsList(aPythonDump,aGroups); + aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( " + << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )"; + } + return aGroups; +} + +//======================================================================= +//function : ExtrusionSweepObject2DMakeGroups +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject, + const SMESH::DirStruct& theStepVector, + CORBA::Long theNbOfSteps) +{ + SMESH::long_array_var anElementsId = theObject->GetIDs(); + SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face ); + if ( !myPreviewMode ) { + TPythonDump aPythonDump; + DumpGroupsList(aPythonDump,aGroups); + aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( " + << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )"; + } + return aGroups; +} + + +//======================================================================= +//function : advancedExtrusion +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements, + const SMESH::DirStruct & theStepVector, + CORBA::Long theNbOfSteps, + CORBA::Long theExtrFlags, + CORBA::Double theSewTolerance, + const bool theMakeGroups) +{ + initData(); TIDSortedElemSet elements; - ToMap(theIDsOfElements, aMesh, elements); + arrayToSet(theIDsOfElements, GetMeshDS(), elements); const SMESH::PointStruct * P = &theStepVector.PS; gp_Vec stepVec( P->x, P->y, P->z ); ::SMESH_MeshEditor anEditor( myMesh ); TElemOfElemListMap aHystory; - anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, - theExtrFlags, theSewTolerance); + ::SMESH_MeshEditor::PGroupIDs groupIds = + anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, + theMakeGroups, theExtrFlags, theSewTolerance); + storeResult(anEditor); - StoreResult(anEditor); + return theMakeGroups ? getGroups(groupIds.get()) : 0; +} - // Update Python script - TPythonDump() << "stepVector = " << theStepVector; - TPythonDump() << this << ".AdvancedExtrusion(" +//======================================================================= +//function : AdvancedExtrusion +//purpose : +//======================================================================= + +void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements, + const SMESH::DirStruct & theStepVector, + CORBA::Long theNbOfSteps, + CORBA::Long theExtrFlags, + CORBA::Double theSewTolerance) +{ + if ( !myPreviewMode ) { + TPythonDump() << "stepVector = " << theStepVector; + TPythonDump() << this << ".AdvancedExtrusion(" + << theIDsOfElements + << ", stepVector, " + << theNbOfSteps << "," + << theExtrFlags << ", " + << theSewTolerance << " )"; + } + advancedExtrusion( theIDsOfElements, + theStepVector, + theNbOfSteps, + theExtrFlags, + theSewTolerance, + false); +} + +//======================================================================= +//function : AdvancedExtrusionMakeGroups +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements, + const SMESH::DirStruct& theStepVector, + CORBA::Long theNbOfSteps, + CORBA::Long theExtrFlags, + CORBA::Double theSewTolerance) +{ + SMESH::ListOfGroups * aGroups = advancedExtrusion( theIDsOfElements, + theStepVector, + theNbOfSteps, + theExtrFlags, + theSewTolerance, + true); + + if ( !myPreviewMode ) { + TPythonDump() << "stepVector = " << theStepVector; + TPythonDump aPythonDump; + DumpGroupsList(aPythonDump,aGroups); + aPythonDump << this << ".AdvancedExtrusionMakeGroups(" << theIDsOfElements << ", stepVector, " << theNbOfSteps << "," << theExtrFlags << ", " << theSewTolerance << " )"; + } + return aGroups; } +//================================================================================ +/*! + * \brief Convert extrusion error to IDL enum + */ +//================================================================================ + #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm; static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e ) @@ -1406,41 +1941,49 @@ static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_Mesh return SMESH::SMESH_MeshEditor::EXTR_OK; } + //======================================================================= -//function : ExtrusionAlongPath -//purpose : +//function : extrusionAlongPath +//purpose : //======================================================================= -SMESH::SMESH_MeshEditor::Extrusion_Error - SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements, - SMESH::SMESH_Mesh_ptr thePathMesh, - GEOM::GEOM_Object_ptr thePathShape, - CORBA::Long theNodeStart, - CORBA::Boolean theHasAngles, - const SMESH::double_array & theAngles, - CORBA::Boolean theHasRefPoint, - const SMESH::PointStruct & theRefPoint) +SMESH::ListOfGroups* +SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements, + SMESH::SMESH_Mesh_ptr thePathMesh, + GEOM::GEOM_Object_ptr thePathShape, + CORBA::Long theNodeStart, + CORBA::Boolean theHasAngles, + const SMESH::double_array & theAngles, + CORBA::Boolean theHasRefPoint, + const SMESH::PointStruct & theRefPoint, + const bool theMakeGroups, + SMESH::SMESH_MeshEditor::Extrusion_Error & theError, + const SMDSAbs_ElementType theElementType) { initData(); - SMESHDS_Mesh* aMesh = GetMeshDS(); - - if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) - return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE; + if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) { + theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE; + return 0; + } + SMESH_Mesh_i* aMeshImp = SMESH::DownCast( thePathMesh ); - SMESH_Mesh_i* aMeshImp = dynamic_cast( SMESH_Gen_i::GetServant( thePathMesh ).in() ); TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape ); SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape ); - if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) - return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE; + if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) { + theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE; + return 0; + } SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart); - if ( !nodeStart ) - return SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE; + if ( !nodeStart ) { + theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE; + return 0; + } TIDSortedElemSet elements; - ToMap(theIDsOfElements, aMesh, elements); + arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType); list angles; for (int i = 0; i < theAngles.length(); i++) { @@ -1449,35 +1992,67 @@ SMESH::SMESH_MeshEditor::Extrusion_Error gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z ); - // Update Python script - TPythonDump() << "rotAngles = " << theAngles; - - if ( theHasRefPoint ) - TPythonDump() << "refPoint = SMESH.PointStruct( " - << refPnt.X() << ", " - << refPnt.Y() << ", " - << refPnt.Z() << " )"; - else - TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )"; - - TPythonDump() << "error = " << this << ".ExtrusionAlongPath( " - << theIDsOfElements << ", " - << thePathMesh << ", " - << thePathShape << ", " - << theNodeStart << ", " - << theHasAngles << ", " - << "rotAngles" << ", " - << theHasRefPoint << ", refPoint )"; + int nbOldGroups = myMesh->NbGroup(); ::SMESH_MeshEditor anEditor( myMesh ); - SMESH::SMESH_MeshEditor::Extrusion_Error error = - convExtrError( anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart, - theHasAngles, angles, - theHasRefPoint, refPnt ) ); + ::SMESH_MeshEditor::Extrusion_Error error = + anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart, + theHasAngles, angles, + theHasRefPoint, refPnt, theMakeGroups ); + storeResult(anEditor); + theError = convExtrError( error ); + + if ( theMakeGroups ) { + list groupIDs = myMesh->GetGroupIds(); + list::iterator newBegin = groupIDs.begin(); + std::advance( newBegin, nbOldGroups ); // skip old groups + groupIDs.erase( groupIDs.begin(), newBegin ); + return getGroups( & groupIDs ); + } + return 0; +} - StoreResult(anEditor); +//======================================================================= +//function : ExtrusionAlongPath +//purpose : +//======================================================================= - return error; +SMESH::SMESH_MeshEditor::Extrusion_Error + SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements, + SMESH::SMESH_Mesh_ptr thePathMesh, + GEOM::GEOM_Object_ptr thePathShape, + CORBA::Long theNodeStart, + CORBA::Boolean theHasAngles, + const SMESH::double_array & theAngles, + CORBA::Boolean theHasRefPoint, + const SMESH::PointStruct & theRefPoint) +{ + if ( !myPreviewMode ) { + TPythonDump() << "error = " << this << ".ExtrusionAlongPath( " + << theIDsOfElements << ", " + << thePathMesh << ", " + << thePathShape << ", " + << theNodeStart << ", " + << theHasAngles << ", " + << theAngles << ", " + << theHasRefPoint << ", " + << "SMESH.PointStruct( " + << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", " + << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", " + << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )"; + } + SMESH::SMESH_MeshEditor::Extrusion_Error anError; + extrusionAlongPath( theIDsOfElements, + thePathMesh, + thePathShape, + theNodeStart, + theHasAngles, + theAngles, + theHasRefPoint, + theRefPoint, + false, + anError); + return anError; } //======================================================================= @@ -1495,29 +2070,344 @@ SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObje CORBA::Boolean theHasRefPoint, const SMESH::PointStruct & theRefPoint) { - initData(); + if ( !myPreviewMode ) { + TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( " + << theObject << ", " + << thePathMesh << ", " + << thePathShape << ", " + << theNodeStart << ", " + << theHasAngles << ", " + << theAngles << ", " + << theHasRefPoint << ", " + << "SMESH.PointStruct( " + << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", " + << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", " + << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )"; + } + SMESH::SMESH_MeshEditor::Extrusion_Error anError; + SMESH::long_array_var anElementsId = theObject->GetIDs(); + extrusionAlongPath( anElementsId, + thePathMesh, + thePathShape, + theNodeStart, + theHasAngles, + theAngles, + theHasRefPoint, + theRefPoint, + false, + anError); + return anError; +} + +//======================================================================= +//function : ExtrusionAlongPathObject1D +//purpose : +//======================================================================= +SMESH::SMESH_MeshEditor::Extrusion_Error +SMESH_MeshEditor_i::ExtrusionAlongPathObject1D(SMESH::SMESH_IDSource_ptr theObject, + SMESH::SMESH_Mesh_ptr thePathMesh, + GEOM::GEOM_Object_ptr thePathShape, + CORBA::Long theNodeStart, + CORBA::Boolean theHasAngles, + const SMESH::double_array & theAngles, + CORBA::Boolean theHasRefPoint, + const SMESH::PointStruct & theRefPoint) +{ + if ( !myPreviewMode ) { + TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject1D( " + << theObject << ", " + << thePathMesh << ", " + << thePathShape << ", " + << theNodeStart << ", " + << theHasAngles << ", " + << theAngles << ", " + << theHasRefPoint << ", " + << "SMESH.PointStruct( " + << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", " + << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", " + << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )"; + } + SMESH::SMESH_MeshEditor::Extrusion_Error anError; SMESH::long_array_var anElementsId = theObject->GetIDs(); - SMESH::SMESH_MeshEditor::Extrusion_Error error = ExtrusionAlongPath - (anElementsId, thePathMesh, thePathShape, theNodeStart, - theHasAngles, theAngles, theHasRefPoint, theRefPoint); + extrusionAlongPath( anElementsId, + thePathMesh, + thePathShape, + theNodeStart, + theHasAngles, + theAngles, + theHasRefPoint, + theRefPoint, + false, + anError, + SMDSAbs_Edge); + return anError; +} + +//======================================================================= +//function : ExtrusionAlongPathObject2D +//purpose : +//======================================================================= - // Clear python line, created by ExtrusionAlongPath() - SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); - aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID()); +SMESH::SMESH_MeshEditor::Extrusion_Error +SMESH_MeshEditor_i::ExtrusionAlongPathObject2D(SMESH::SMESH_IDSource_ptr theObject, + SMESH::SMESH_Mesh_ptr thePathMesh, + GEOM::GEOM_Object_ptr thePathShape, + CORBA::Long theNodeStart, + CORBA::Boolean theHasAngles, + const SMESH::double_array & theAngles, + CORBA::Boolean theHasRefPoint, + const SMESH::PointStruct & theRefPoint) +{ + if ( !myPreviewMode ) { + TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject2D( " + << theObject << ", " + << thePathMesh << ", " + << thePathShape << ", " + << theNodeStart << ", " + << theHasAngles << ", " + << theAngles << ", " + << theHasRefPoint << ", " + << "SMESH.PointStruct( " + << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", " + << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", " + << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )"; + } + SMESH::SMESH_MeshEditor::Extrusion_Error anError; + SMESH::long_array_var anElementsId = theObject->GetIDs(); + extrusionAlongPath( anElementsId, + thePathMesh, + thePathShape, + theNodeStart, + theHasAngles, + theAngles, + theHasRefPoint, + theRefPoint, + false, + anError, + SMDSAbs_Face); + return anError; +} + + +//======================================================================= +//function : ExtrusionAlongPathMakeGroups +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements, + SMESH::SMESH_Mesh_ptr thePathMesh, + GEOM::GEOM_Object_ptr thePathShape, + CORBA::Long theNodeStart, + CORBA::Boolean theHasAngles, + const SMESH::double_array& theAngles, + CORBA::Boolean theHasRefPoint, + const SMESH::PointStruct& theRefPoint, + SMESH::SMESH_MeshEditor::Extrusion_Error& Error) +{ + SMESH::ListOfGroups * aGroups = extrusionAlongPath( theIDsOfElements, + thePathMesh, + thePathShape, + theNodeStart, + theHasAngles, + theAngles, + theHasRefPoint, + theRefPoint, + true, + Error); + if ( !myPreviewMode ) { + bool isDumpGroups = aGroups && aGroups->length() > 0; + TPythonDump aPythonDump; + if(isDumpGroups) { + aPythonDump << "("<GetIDs(); + SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId, + thePathMesh, + thePathShape, + theNodeStart, + theHasAngles, + theAngles, + theHasRefPoint, + theRefPoint, + true, + Error); + + if ( !myPreviewMode ) { + bool isDumpGroups = aGroups && aGroups->length() > 0; + TPythonDump aPythonDump; + if(isDumpGroups) { + aPythonDump << "("<GetIDs(); + SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId, + thePathMesh, + thePathShape, + theNodeStart, + theHasAngles, + theAngles, + theHasRefPoint, + theRefPoint, + true, + Error, + SMDSAbs_Edge); + + if ( !myPreviewMode ) { + bool isDumpGroups = aGroups && aGroups->length() > 0; + TPythonDump aPythonDump; + if(isDumpGroups) { + aPythonDump << "("<GetIDs(); + SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId, + thePathMesh, + thePathShape, + theNodeStart, + theHasAngles, + theAngles, + theHasRefPoint, + theRefPoint, + true, + Error, + SMDSAbs_Face); + + if ( !myPreviewMode ) { + bool isDumpGroups = aGroups && aGroups->length() > 0; + TPythonDump aPythonDump; + if(isDumpGroups) { + aPythonDump << "("< 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() ) + { + SMESH_Mesh_i* aMeshImp = SMESH::DownCast( thePathMesh ); + TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape ); + SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape ); + if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) + return aResult._retn(); + int nbSteps = aSubMesh->GetSubMeshDS()->NbElements(); + if ( nbSteps == nbAngles ) + { + aResult.inout() = theAngles; + } + else + { + aResult->length( nbSteps ); + double rAn2St = double( nbAngles ) / double( nbSteps ); + double angPrev = 0, angle; + for ( int iSt = 0; iSt < nbSteps; ++iSt ) + { + double angCur = rAn2St * ( iSt+1 ); + double angCurFloor = floor( angCur ); + double angPrevFloor = floor( angPrev ); + if ( angPrevFloor == angCurFloor ) + angle = rAn2St * theAngles[ int( angCurFloor ) ]; + else + { + int iP = int( angPrevFloor ); + double angPrevCeil = ceil(angPrev); + angle = ( angPrevCeil - angPrev ) * theAngles[ iP ]; + + int iC = int( angCurFloor ); + if ( iC < nbAngles ) + angle += ( angCur - angCurFloor ) * theAngles[ iC ]; + + iP = int( angPrevCeil ); + while ( iC-- > iP ) + angle += theAngles[ iC ]; + } + aResult[ iSt ] = angle; + angPrev = angCur; + } + } + } + // Update Python script + TPythonDump() << "rotAngles = " << theAngles; + TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( " + << thePathMesh << ", " + << thePathShape << ", " + << "rotAngles )"; + return aResult._retn(); } + //======================================================================= -//function : Mirror -//purpose : +//function : mirror +//purpose : //======================================================================= -void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements, - const SMESH::AxisStruct & theAxis, - SMESH::SMESH_MeshEditor::MirrorType theMirrorType, - CORBA::Boolean theCopy) +SMESH::ListOfGroups* +SMESH_MeshEditor_i::mirror(const SMESH::long_array & theIDsOfElements, + const SMESH::AxisStruct & theAxis, + SMESH::SMESH_MeshEditor::MirrorType theMirrorType, + CORBA::Boolean theCopy, + const bool theMakeGroups, + ::SMESH_Mesh* theTargetMesh) { initData(); - SMESHDS_Mesh* aMesh = GetMeshDS(); - TIDSortedElemSet elements; - ToMap(theIDsOfElements, aMesh, elements); + arrayToSet(theIDsOfElements, GetMeshDS(), elements); gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z ); gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz ); gp_Trsf aTrsf; - TCollection_AsciiString typeStr; switch ( theMirrorType ) { case SMESH::SMESH_MeshEditor::POINT: aTrsf.SetMirror( P ); - typeStr = "SMESH.SMESH_MeshEditor.POINT"; break; case SMESH::SMESH_MeshEditor::AXIS: aTrsf.SetMirror( gp_Ax1( P, V )); - typeStr = "SMESH.SMESH_MeshEditor.AXIS"; break; default: aTrsf.SetMirror( gp_Ax2( P, V )); - typeStr = "SMESH.SMESH_MeshEditor.PLANE"; } - // Update Python script - TPythonDump() << this << ".Mirror( " - << theIDsOfElements << ", " - << theAxis << ", " - << typeStr << ", " - << theCopy << " )"; - ::SMESH_MeshEditor anEditor( myMesh ); - anEditor.Transform (elements, aTrsf, theCopy); + ::SMESH_MeshEditor::PGroupIDs groupIds = + anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh); if(theCopy) { - StoreResult(anEditor); + storeResult(anEditor); } + return theMakeGroups ? getGroups(groupIds.get()) : 0; +} + +//======================================================================= +//function : Mirror +//purpose : +//======================================================================= + +void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements, + const SMESH::AxisStruct & theAxis, + SMESH::SMESH_MeshEditor::MirrorType theMirrorType, + CORBA::Boolean theCopy) +{ + if ( !myPreviewMode ) { + TPythonDump() << this << ".Mirror( " + << theIDsOfElements << ", " + << theAxis << ", " + << mirrorTypeName(theMirrorType) << ", " + << theCopy << " )"; + } + mirror(theIDsOfElements, theAxis, theMirrorType, theCopy, false); } @@ -1602,68 +2556,201 @@ void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObj SMESH::SMESH_MeshEditor::MirrorType theMirrorType, CORBA::Boolean theCopy) { - initData(); - + if ( !myPreviewMode ) { + TPythonDump() << this << ".MirrorObject( " + << theObject << ", " + << theAxis << ", " + << mirrorTypeName(theMirrorType) << ", " + << theCopy << " )"; + } SMESH::long_array_var anElementsId = theObject->GetIDs(); - Mirror(anElementsId, theAxis, theMirrorType, theCopy); + mirror(anElementsId, theAxis, theMirrorType, theCopy, false); +} - // Clear python line, created by Mirror() - SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); - aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID()); +//======================================================================= +//function : MirrorMakeGroups +//purpose : +//======================================================================= - // Update Python script - TCollection_AsciiString typeStr; - switch ( theMirrorType ) { - case SMESH::SMESH_MeshEditor::POINT: - typeStr = "SMESH.SMESH_MeshEditor.POINT"; - break; - case SMESH::SMESH_MeshEditor::AXIS: - typeStr = "SMESH.SMESH_MeshEditor.AXIS"; - break; - default: - typeStr = "SMESH.SMESH_MeshEditor.PLANE"; +SMESH::ListOfGroups* +SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements, + const SMESH::AxisStruct& theMirror, + SMESH::SMESH_MeshEditor::MirrorType theMirrorType) +{ + SMESH::ListOfGroups * aGroups = mirror(theIDsOfElements, theMirror, theMirrorType, true, true); + if ( !myPreviewMode ) { + TPythonDump aPythonDump; + DumpGroupsList(aPythonDump,aGroups); + aPythonDump << this << ".MirrorMakeGroups( " + << theIDsOfElements << ", " + << theMirror << ", " + << mirrorTypeName(theMirrorType) << " )"; } - TPythonDump() << "axis = " << theAxis; - TPythonDump() << this << ".MirrorObject( " + return aGroups; +} + +//======================================================================= +//function : MirrorObjectMakeGroups +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject, + const SMESH::AxisStruct& theMirror, + SMESH::SMESH_MeshEditor::MirrorType theMirrorType) +{ + SMESH::long_array_var anElementsId = theObject->GetIDs(); + SMESH::ListOfGroups * aGroups = mirror(anElementsId, theMirror, theMirrorType, true, true); + if ( !myPreviewMode ) { + TPythonDump aPythonDump; + DumpGroupsList(aPythonDump,aGroups); + aPythonDump << this << ".MirrorObjectMakeGroups( " << theObject << ", " - << "axis, " - << typeStr << ", " - << theCopy << " )"; + << theMirror << ", " + << mirrorTypeName(theMirrorType) << " )"; + } + return aGroups; } //======================================================================= -//function : Translate -//purpose : +//function : MirrorMakeMesh +//purpose : //======================================================================= -void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements, - const SMESH::DirStruct & theVector, - CORBA::Boolean theCopy) +SMESH::SMESH_Mesh_ptr +SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements, + const SMESH::AxisStruct& theMirror, + SMESH::SMESH_MeshEditor::MirrorType theMirrorType, + CORBA::Boolean theCopyGroups, + const char* theMeshName) { - initData(); + SMESH_Mesh_i* mesh_i; + SMESH::SMESH_Mesh_var mesh; + { // open new scope to dump "MakeMesh" command + // and then "GetGroups" using SMESH_Mesh::GetGroups() + + TPythonDump pydump; // to prevent dump at mesh creation + + mesh = makeMesh( theMeshName ); + mesh_i = SMESH::DownCast( mesh ); + if (mesh_i) { + mirror(theIDsOfElements, theMirror, theMirrorType, + false, theCopyGroups, & mesh_i->GetImpl()); + mesh_i->CreateGroupServants(); + } + + if ( !myPreviewMode ) { + pydump << mesh << " = " << this << ".MirrorMakeMesh( " + << theIDsOfElements << ", " + << theMirror << ", " + << mirrorTypeName(theMirrorType) << ", " + << theCopyGroups << ", '" + << theMeshName << "' )"; + } + } - SMESHDS_Mesh* aMesh = GetMeshDS(); + //dump "GetGroups" + if(!myPreviewMode && mesh_i) + mesh_i->GetGroups(); + + return mesh._retn(); +} + +//======================================================================= +//function : MirrorObjectMakeMesh +//purpose : +//======================================================================= + +SMESH::SMESH_Mesh_ptr +SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject, + const SMESH::AxisStruct& theMirror, + SMESH::SMESH_MeshEditor::MirrorType theMirrorType, + CORBA::Boolean theCopyGroups, + const char* theMeshName) +{ + SMESH_Mesh_i* mesh_i; + SMESH::SMESH_Mesh_var mesh; + { // open new scope to dump "MakeMesh" command + // and then "GetGroups" using SMESH_Mesh::GetGroups() + + TPythonDump pydump; // to prevent dump at mesh creation + + mesh = makeMesh( theMeshName ); + mesh_i = SMESH::DownCast( mesh ); + if ( mesh_i ) { + SMESH::long_array_var anElementsId = theObject->GetIDs(); + mirror(anElementsId, theMirror, theMirrorType, + false, theCopyGroups, & mesh_i->GetImpl()); + mesh_i->CreateGroupServants(); + } + + if ( !myPreviewMode ) { + pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( " + << theObject << ", " + << theMirror << ", " + << mirrorTypeName(theMirrorType) << ", " + << theCopyGroups << ", '" + << theMeshName << "' )"; + } + } + + //dump "GetGroups" + if(!myPreviewMode && mesh_i) + mesh_i->GetGroups(); + + return mesh._retn(); +} + +//======================================================================= +//function : translate +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements, + const SMESH::DirStruct & theVector, + CORBA::Boolean theCopy, + const bool theMakeGroups, + ::SMESH_Mesh* theTargetMesh) +{ + initData(); TIDSortedElemSet elements; - ToMap(theIDsOfElements, aMesh, elements); + arrayToSet(theIDsOfElements, GetMeshDS(), elements); gp_Trsf aTrsf; const SMESH::PointStruct * P = &theVector.PS; aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z )); ::SMESH_MeshEditor anEditor( myMesh ); - anEditor.Transform (elements, aTrsf, theCopy); + ::SMESH_MeshEditor::PGroupIDs groupIds = + anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh); - if(theCopy) { - StoreResult(anEditor); - } + if(theCopy) + storeResult(anEditor); - // Update Python script - TPythonDump() << "vector = " << theVector; - TPythonDump() << this << ".Translate( " - << theIDsOfElements - << ", vector, " - << theCopy << " )"; + return theMakeGroups ? getGroups(groupIds.get()) : 0; +} + +//======================================================================= +//function : Translate +//purpose : +//======================================================================= + +void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements, + const SMESH::DirStruct & theVector, + CORBA::Boolean theCopy) +{ + if ( !myPreviewMode ) { + TPythonDump() << this << ".Translate( " + << theIDsOfElements << ", " + << theVector << ", " + << theCopy << " )"; + } + translate(theIDsOfElements, + theVector, + theCopy, + false); } //======================================================================= @@ -1675,38 +2762,165 @@ void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject, const SMESH::DirStruct & theVector, CORBA::Boolean theCopy) { - initData(); + if ( !myPreviewMode ) { + TPythonDump() << this << ".TranslateObject( " + << theObject << ", " + << theVector << ", " + << theCopy << " )"; + } + SMESH::long_array_var anElementsId = theObject->GetIDs(); + translate(anElementsId, + theVector, + theCopy, + false); +} +//======================================================================= +//function : TranslateMakeGroups +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements, + const SMESH::DirStruct& theVector) +{ + SMESH::ListOfGroups * aGroups = translate(theIDsOfElements,theVector,true,true); + if ( !myPreviewMode ) { + TPythonDump aPythonDump; + DumpGroupsList(aPythonDump,aGroups); + aPythonDump << this << ".TranslateMakeGroups( " + << theIDsOfElements << ", " + << theVector << " )"; + } + return aGroups; +} + +//======================================================================= +//function : TranslateObjectMakeGroups +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject, + const SMESH::DirStruct& theVector) +{ SMESH::long_array_var anElementsId = theObject->GetIDs(); - Translate(anElementsId, theVector, theCopy); + SMESH::ListOfGroups * aGroups = translate(anElementsId, theVector, true, true); + + if ( !myPreviewMode ) { - // Clear python line, created by Translate() - SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); - aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID()); + TPythonDump aPythonDump; + DumpGroupsList(aPythonDump,aGroups); + aPythonDump << this << ".TranslateObjectMakeGroups( " + << theObject << ", " + << theVector << " )"; + } + return aGroups; +} - // Update Python script - TPythonDump() << this << ".TranslateObject( " - << theObject - << ", vector, " - << theCopy << " )"; +//======================================================================= +//function : TranslateMakeMesh +//purpose : +//======================================================================= + +SMESH::SMESH_Mesh_ptr +SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements, + const SMESH::DirStruct& theVector, + CORBA::Boolean theCopyGroups, + const char* theMeshName) +{ + SMESH_Mesh_i* mesh_i; + SMESH::SMESH_Mesh_var mesh; + + { // open new scope to dump "MakeMesh" command + // and then "GetGroups" using SMESH_Mesh::GetGroups() + + TPythonDump pydump; // to prevent dump at mesh creation + + mesh = makeMesh( theMeshName ); + mesh_i = SMESH::DownCast( mesh ); + + if ( mesh_i ) { + translate(theIDsOfElements, theVector, + false, theCopyGroups, & mesh_i->GetImpl()); + mesh_i->CreateGroupServants(); + } + + if ( !myPreviewMode ) { + pydump << mesh << " = " << this << ".TranslateMakeMesh( " + << theIDsOfElements << ", " + << theVector << ", " + << theCopyGroups << ", '" + << theMeshName << "' )"; + } + } + + //dump "GetGroups" + if(!myPreviewMode && mesh_i) + mesh_i->GetGroups(); + + return mesh._retn(); } //======================================================================= -//function : Rotate -//purpose : +//function : TranslateObjectMakeMesh +//purpose : //======================================================================= -void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements, - const SMESH::AxisStruct & theAxis, - CORBA::Double theAngle, - CORBA::Boolean theCopy) +SMESH::SMESH_Mesh_ptr +SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject, + const SMESH::DirStruct& theVector, + CORBA::Boolean theCopyGroups, + const char* theMeshName) { - initData(); + SMESH_Mesh_i* mesh_i; + SMESH::SMESH_Mesh_var mesh; + { // open new scope to dump "MakeMesh" command + // and then "GetGroups" using SMESH_Mesh::GetGroups() + + TPythonDump pydump; // to prevent dump at mesh creation + mesh = makeMesh( theMeshName ); + mesh_i = SMESH::DownCast( mesh ); + + if ( mesh_i ) { + SMESH::long_array_var anElementsId = theObject->GetIDs(); + translate(anElementsId, theVector, + false, theCopyGroups, & mesh_i->GetImpl()); + mesh_i->CreateGroupServants(); + } + if ( !myPreviewMode ) { + pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( " + << theObject << ", " + << theVector << ", " + << theCopyGroups << ", '" + << theMeshName << "' )"; + } + } + + //dump "GetGroups" + if(!myPreviewMode && mesh_i) + mesh_i->GetGroups(); + + return mesh._retn(); +} - SMESHDS_Mesh* aMesh = GetMeshDS(); +//======================================================================= +//function : rotate +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements, + const SMESH::AxisStruct & theAxis, + CORBA::Double theAngle, + CORBA::Boolean theCopy, + const bool theMakeGroups, + ::SMESH_Mesh* theTargetMesh) +{ + initData(); TIDSortedElemSet elements; - ToMap(theIDsOfElements, aMesh, elements); + arrayToSet(theIDsOfElements, GetMeshDS(), elements); gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z ); gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz ); @@ -1715,19 +2929,37 @@ void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements, aTrsf.SetRotation( gp_Ax1( P, V ), theAngle); ::SMESH_MeshEditor anEditor( myMesh ); - anEditor.Transform (elements, aTrsf, theCopy); + ::SMESH_MeshEditor::PGroupIDs groupIds = + anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh); if(theCopy) { - StoreResult(anEditor); + storeResult(anEditor); } + return theMakeGroups ? getGroups(groupIds.get()) : 0; +} - // Update Python script - TPythonDump() << "axis = " << theAxis; - TPythonDump() << this << ".Rotate( " - << theIDsOfElements - << ", axis, " - << theAngle << ", " - << theCopy << " )"; +//======================================================================= +//function : Rotate +//purpose : +//======================================================================= + +void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements, + const SMESH::AxisStruct & theAxis, + CORBA::Double theAngle, + CORBA::Boolean theCopy) +{ + if ( !myPreviewMode ) { + TPythonDump() << this << ".Rotate( " + << theIDsOfElements << ", " + << theAxis << ", " + << theAngle << ", " + << theCopy << " )"; + } + rotate(theIDsOfElements, + theAxis, + theAngle, + theCopy, + false); } //======================================================================= @@ -1740,21 +2972,155 @@ void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject, CORBA::Double theAngle, CORBA::Boolean theCopy) { - initData(); + if ( !myPreviewMode ) { + TPythonDump() << this << ".RotateObject( " + << theObject << ", " + << theAxis << ", " + << theAngle << ", " + << theCopy << " )"; + } + SMESH::long_array_var anElementsId = theObject->GetIDs(); + rotate(anElementsId, + theAxis, + theAngle, + theCopy, + false); +} +//======================================================================= +//function : RotateMakeGroups +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements, + const SMESH::AxisStruct& theAxis, + CORBA::Double theAngle) +{ + SMESH::ListOfGroups * aGroups = rotate(theIDsOfElements,theAxis,theAngle,true,true); + if ( !myPreviewMode ) { + TPythonDump aPythonDump; + DumpGroupsList(aPythonDump,aGroups); + aPythonDump << this << ".RotateMakeGroups( " + << theIDsOfElements << ", " + << theAxis << ", " + << theAngle << " )"; + } + return aGroups; +} + +//======================================================================= +//function : RotateObjectMakeGroups +//purpose : +//======================================================================= + +SMESH::ListOfGroups* +SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject, + const SMESH::AxisStruct& theAxis, + CORBA::Double theAngle) +{ SMESH::long_array_var anElementsId = theObject->GetIDs(); - Rotate(anElementsId, theAxis, theAngle, theCopy); + SMESH::ListOfGroups * aGroups = rotate(anElementsId,theAxis,theAngle,true,true); + + if ( !myPreviewMode ) { + TPythonDump aPythonDump; + DumpGroupsList(aPythonDump,aGroups); + aPythonDump << this << ".RotateObjectMakeGroups( " + << theObject << ", " + << theAxis << ", " + << theAngle << " )"; + } + return aGroups; +} - // Clear python line, created by Rotate() - SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); - aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID()); +//======================================================================= +//function : RotateMakeMesh +//purpose : +//======================================================================= - // Update Python script - TPythonDump() << this << ".RotateObject( " - << theObject - << ", axis, " - << theAngle << ", " - << theCopy << " )"; +SMESH::SMESH_Mesh_ptr +SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements, + const SMESH::AxisStruct& theAxis, + CORBA::Double theAngleInRadians, + CORBA::Boolean theCopyGroups, + const char* theMeshName) +{ + SMESH::SMESH_Mesh_var mesh; + SMESH_Mesh_i* mesh_i; + + { // open new scope to dump "MakeMesh" command + // and then "GetGroups" using SMESH_Mesh::GetGroups() + + TPythonDump pydump; // to prevent dump at mesh creation + + mesh = makeMesh( theMeshName ); + mesh_i = SMESH::DownCast( mesh ); + + if ( mesh_i ) { + rotate(theIDsOfElements, theAxis, theAngleInRadians, + false, theCopyGroups, & mesh_i->GetImpl()); + mesh_i->CreateGroupServants(); + } + if ( !myPreviewMode ) { + pydump << mesh << " = " << this << ".RotateMakeMesh( " + << theIDsOfElements << ", " + << theAxis << ", " + << theAngleInRadians << ", " + << theCopyGroups << ", '" + << theMeshName << "' )"; + } + } + + //dump "GetGroups" + if(!myPreviewMode && mesh_i) + mesh_i->GetGroups(); + + return mesh._retn(); +} + +//======================================================================= +//function : RotateObjectMakeMesh +//purpose : +//======================================================================= + +SMESH::SMESH_Mesh_ptr +SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject, + const SMESH::AxisStruct& theAxis, + CORBA::Double theAngleInRadians, + CORBA::Boolean theCopyGroups, + const char* theMeshName) +{ + SMESH::SMESH_Mesh_var mesh; + SMESH_Mesh_i* mesh_i; + + {// open new scope to dump "MakeMesh" command + // and then "GetGroups" using SMESH_Mesh::GetGroups() + + TPythonDump pydump; // to prevent dump at mesh creation + mesh = makeMesh( theMeshName ); + mesh_i = SMESH::DownCast( mesh ); + + if (mesh_i ) { + SMESH::long_array_var anElementsId = theObject->GetIDs(); + rotate(anElementsId, theAxis, theAngleInRadians, + false, theCopyGroups, & mesh_i->GetImpl()); + mesh_i->CreateGroupServants(); + } + if ( !myPreviewMode ) { + pydump << mesh << " = " << this << ".RotateObjectMakeMesh( " + << theObject << ", " + << theAxis << ", " + << theAngleInRadians << ", " + << theCopyGroups << ", '" + << theMeshName << "' )"; + } + } + + //dump "GetGroups" + if(!myPreviewMode && mesh_i) + mesh_i->GetGroups(); + + return mesh._retn(); } //======================================================================= @@ -1778,12 +3144,11 @@ void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tol for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) { list< const SMDS_MeshNode* >& aListOfNodes = *llIt; list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();; - SMESH::long_array& aGroup = (*GroupsOfNodes)[i]; + SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ]; aGroup.length( aListOfNodes.size() ); for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ ) aGroup[ j ] = (*lIt)->GetID(); } - // Update Python script TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( " << Tolerance << " )"; } @@ -1835,12 +3200,11 @@ void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) { list< const SMDS_MeshNode* >& aListOfNodes = *llIt; list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();; - SMESH::long_array& aGroup = GroupsOfNodes[ i ]; + SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ]; aGroup.length( aListOfNodes.size() ); for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ ) aGroup[ j ] = (*lIt)->GetID(); } - // Update Python script TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( " <MoveNode(node, x, y, z); // fill preview data ::SMESH_MeshEditor anEditor( & tmpMesh ); - StoreResult( anEditor ); + storeResult( anEditor ); } else { @@ -2043,9 +3403,9 @@ CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x, } if ( !myPreviewMode ) { - // Update Python script TPythonDump() << "nodeID = " << this - << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z << " )"; + << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z + << ", " << nodeID << " )"; } return nodeID; @@ -2110,7 +3470,6 @@ SMESH::SMESH_MeshEditor::Sew_Error !aSide2ThirdNode) return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND; - // Update Python script TPythonDump() << "error = " << this << ".SewFreeBorders( " << FirstNodeID1 << ", " << SecondNodeID1 << ", " @@ -2133,7 +3492,7 @@ SMESH::SMESH_MeshEditor::Sew_Error CreatePolygons, CreatePolyedrs) ); - StoreResult(anEditor); + storeResult(anEditor); return error; } @@ -2170,7 +3529,6 @@ SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1, !aSide2SecondNode) return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND; - // Update Python script TPythonDump() << "error = " << this << ".SewConformFreeBorders( " << FirstNodeID1 << ", " << SecondNodeID1 << ", " @@ -2189,7 +3547,7 @@ SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1, true, false, false) ); - StoreResult(anEditor); + storeResult(anEditor); return error; } @@ -2228,7 +3586,6 @@ SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder, !aSide2SecondNode) return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES; - // Update Python script TPythonDump() << "error = " << this << ".SewBorderToSide( " << FirstNodeIDOnFreeBorder << ", " << SecondNodeIDOnFreeBorder << ", " @@ -2250,7 +3607,7 @@ SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder, CreatePolygons, CreatePolyedrs) ); - StoreResult(anEditor); + storeResult(anEditor); return error; } @@ -2286,10 +3643,9 @@ SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements, return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES; TIDSortedElemSet aSide1Elems, aSide2Elems; - ToMap(IDsOfSide1Elements, aMesh, aSide1Elems); - ToMap(IDsOfSide2Elements, aMesh, aSide2Elems); + arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems); + arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems); - // Update Python script TPythonDump() << "error = " << this << ".SewSideElements( " << IDsOfSide1Elements << ", " << IDsOfSide2Elements << ", " @@ -2306,7 +3662,7 @@ SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements, aSecondNode1ToMerge, aSecondNode2ToMerge)); - StoreResult(anEditor); + storeResult(anEditor); return error; } @@ -2330,7 +3686,7 @@ CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide, int nbn = newIDs.length(); int i=0; - vector aNodes (nbn); + vector aNodes(nbn); int nbn1=-1; for(; iFindNode(newIDs[i]); @@ -2339,14 +3695,13 @@ CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide, aNodes[nbn1] = aNode; } } - // Update Python script TPythonDump() << "isDone = " << this << ".ChangeElemNodes( " << ide << ", " << newIDs << " )"; #ifdef _DEBUG_ TPythonDump() << "print 'ChangeElemNodes: ', isDone"; #endif - return GetMeshDS()->ChangeElementNodes( elem, &aNodes[0], nbn1+1 ); + return GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 ); } //================================================================================ @@ -2356,7 +3711,7 @@ CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide, */ //================================================================================ -void SMESH_MeshEditor_i::StoreResult(::SMESH_MeshEditor& anEditor) +void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor) { if ( myPreviewMode ) { // --- MeshPreviewStruct filling --- @@ -2493,20 +3848,52 @@ void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d) { ::SMESH_MeshEditor anEditor( myMesh ); anEditor.ConvertToQuadratic(theForce3d); - // Update Python script TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )"; } //======================================================================= //function : ConvertFromQuadratic -//purpose : +//purpose : //======================================================================= CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic() { ::SMESH_MeshEditor anEditor( myMesh ); CORBA::Boolean isDone = anEditor.ConvertFromQuadratic(); - // Update Python script TPythonDump() << this << ".ConvertFromQuadratic()"; return isDone; } + +//======================================================================= +//function : makeMesh +//purpose : create a named imported mesh +//======================================================================= + +SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName) +{ + SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen(); + SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh(); + SALOMEDS::Study_var study = gen->GetCurrentStudy(); + SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh ); + gen->SetName( meshSO, theMeshName, "Mesh" ); + + SALOMEDS::StudyBuilder_var builder = study->NewBuilder(); + SALOMEDS::GenericAttribute_var anAttr + = builder->FindOrCreateAttribute( meshSO, "AttributePixMap" ); + SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" ); + + return mesh._retn(); +} + +//======================================================================= +//function : DumpGroupsList +//purpose : +//======================================================================= +void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython, + const SMESH::ListOfGroups * theGroupList) +{ + bool isDumpGroupList = theGroupList && theGroupList->length() > 0; + if(isDumpGroupList) { + theDumpPython << theGroupList << " = "; + } +}