From d0f366c4a3a66a71b0be94f7a6e2d146f80a94c4 Mon Sep 17 00:00:00 2001 From: smh Date: Tue, 7 Feb 2006 15:01:11 +0000 Subject: [PATCH] Merge from OCC_development_generic_2006 Preparation of 3.2.0a1 --- idl/SMESH_Gen.idl | 38 +- resources/SMESHCatalog.xml | 1 + src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx | 750 +++++++----------- src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx | 30 +- src/DriverMED/Makefile.in | 2 +- src/OBJECT/SMESH_Actor.cxx | 5 +- src/SMESH/SMESH_Algo.cxx | 103 ++- src/SMESH/SMESH_Algo.hxx | 24 + src/SMESH/SMESH_Hypothesis.hxx | 10 + src/SMESH/SMESH_Mesh.cxx | 2 +- src/SMESHFiltersSelection/Makefile.in | 2 +- src/SMESHGUI/Makefile.in | 6 +- src/SMESHGUI/SMESHGUI.cxx | 77 +- src/SMESHGUI/SMESHGUI.h | 1 + src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx | 1 + src/SMESHGUI/SMESHGUI_ClippingDlg.cxx | 1 + .../SMESHGUI_CreatePolyhedralVolumeDlg.cxx | 31 +- src/SMESHGUI/SMESHGUI_FilterDlg.cxx | 6 +- src/SMESHGUI/SMESHGUI_GEOMGenUtils.cxx | 7 +- src/SMESHGUI/SMESHGUI_GroupDlg.cxx | 34 +- src/SMESHGUI/SMESHGUI_Hypotheses.cxx | 134 +++- src/SMESHGUI/SMESHGUI_Hypotheses.h | 9 +- src/SMESHGUI/SMESHGUI_MeshDlg.cxx | 38 + src/SMESHGUI/SMESHGUI_MeshDlg.h | 5 + src/SMESHGUI/SMESHGUI_MeshOp.cxx | 454 +++++++++-- src/SMESHGUI/SMESHGUI_MeshOp.h | 13 +- src/SMESHGUI/SMESHGUI_MeshPatternDlg.cxx | 1 + src/SMESHGUI/SMESHGUI_MoveNodesDlg.cxx | 1 + src/SMESHGUI/SMESHGUI_MultiEditDlg.cxx | 10 +- src/SMESHGUI/SMESHGUI_NodesDlg.cxx | 1 + src/SMESHGUI/SMESHGUI_RemoveElementsDlg.cxx | 8 +- src/SMESHGUI/SMESHGUI_RemoveNodesDlg.cxx | 1 + src/SMESHGUI/SMESHGUI_Selection.cxx | 4 +- src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.cxx | 490 ++++++++++++ src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.h | 115 +++ src/SMESHGUI/SMESHGUI_VTKUtils.cxx | 87 +- src/SMESHGUI/SMESHGUI_VTKUtils.h | 17 +- src/SMESHGUI/SMESH_msg_en.po | 49 +- src/SMESH_I/Makefile.in | 2 +- src/SMESH_I/SMESH_Gen_i.cxx | 157 +++- src/SMESH_I/SMESH_Gen_i.hxx | 12 + src/SMESH_I/SMESH_Mesh_i.cxx | 33 +- src/StdMeshers/StdMeshers_Arithmetic1D.cxx | 68 +- src/StdMeshers/StdMeshers_Arithmetic1D.hxx | 16 +- src/StdMeshers/StdMeshers_AutomaticLength.cxx | 81 +- src/StdMeshers/StdMeshers_AutomaticLength.hxx | 8 + src/StdMeshers/StdMeshers_Deflection1D.cxx | 88 ++ src/StdMeshers/StdMeshers_Deflection1D.hxx | 16 +- src/StdMeshers/StdMeshers_LengthFromEdges.cxx | 22 +- src/StdMeshers/StdMeshers_LengthFromEdges.hxx | 18 +- src/StdMeshers/StdMeshers_LocalLength.cxx | 73 +- src/StdMeshers/StdMeshers_LocalLength.hxx | 30 +- src/StdMeshers/StdMeshers_MEFISTO_2D.cxx | 145 ++-- src/StdMeshers/StdMeshers_MaxElementArea.cxx | 55 +- src/StdMeshers/StdMeshers_MaxElementArea.hxx | 30 +- .../StdMeshers_MaxElementVolume.cxx | 65 +- .../StdMeshers_MaxElementVolume.hxx | 16 +- .../StdMeshers_NotConformAllowed.cxx | 16 + .../StdMeshers_NotConformAllowed.hxx | 19 +- .../StdMeshers_NumberOfSegments.cxx | 58 +- .../StdMeshers_NumberOfSegments.hxx | 17 +- src/StdMeshers/StdMeshers_Propagation.cxx | 20 +- src/StdMeshers/StdMeshers_Propagation.hxx | 18 +- .../StdMeshers_QuadranglePreference.cxx | 16 + .../StdMeshers_QuadranglePreference.hxx | 11 + src/StdMeshers/StdMeshers_Quadrangle_2D.cxx | 724 ++++++++++++++++- src/StdMeshers/StdMeshers_Quadrangle_2D.hxx | 16 + src/StdMeshers/StdMeshers_Regular_1D.cxx | 9 +- src/StdMeshers/StdMeshers_StartEndLength.cxx | 65 +- src/StdMeshers/StdMeshers_StartEndLength.hxx | 19 +- .../StdMeshersGUI_CreateStdHypothesisDlg.cxx | 111 --- .../StdMeshersGUI_DistrPreview.cxx | 47 +- .../StdMeshersGUI_DistrPreview.h | 2 +- .../StdMeshersGUI_DistrTable.cxx | 34 +- src/StdMeshersGUI/StdMeshersGUI_DistrTable.h | 9 +- .../StdMeshersGUI_NbSegmentsCreator.cxx | 62 +- .../StdMeshersGUI_NbSegmentsCreator.h | 4 +- .../StdMeshersGUI_Parameters.cxx | 622 --------------- src/StdMeshersGUI/StdMeshersGUI_Parameters.h | 87 -- .../StdMeshersGUI_StdHypothesisCreator.cxx | 117 ++- .../StdMeshersGUI_StdHypothesisCreator.h | 4 +- src/StdMeshersGUI/StdMeshers_icons.po | 113 --- src/StdMeshersGUI/StdMeshers_msg_en.po | 9 + 83 files changed, 3847 insertions(+), 1885 deletions(-) create mode 100644 src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.cxx create mode 100644 src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.h delete mode 100644 src/StdMeshersGUI/StdMeshersGUI_CreateStdHypothesisDlg.cxx delete mode 100644 src/StdMeshersGUI/StdMeshersGUI_Parameters.cxx delete mode 100644 src/StdMeshersGUI/StdMeshersGUI_Parameters.h delete mode 100644 src/StdMeshersGUI/StdMeshers_icons.po diff --git a/idl/SMESH_Gen.idl b/idl/SMESH_Gen.idl index 5757e1075..bc6edfb72 100644 --- a/idl/SMESH_Gen.idl +++ b/idl/SMESH_Gen.idl @@ -80,6 +80,19 @@ module SMESH in string theLibName ) raises ( SALOME::SALOME_Exception ); + /*! + * Return a hypothesis holding parameter values corresponding to the mesh + * existing on the given geometry. + * The returned hypothesis may be the one existing in a study and used + * to compute the mesh, or a temporary one created just to pass parameter + * values + */ + SMESH_Hypothesis GetHypothesisParameterValues( in string theHypName, + in string theLibName, + in SMESH_Mesh theMesh, + in GEOM::GEOM_Object theGeom) + raises ( SALOME::SALOME_Exception ); + /*! * Create a Mesh object, given a geometry shape. * Mesh is created empty (no points, no elements). @@ -120,15 +133,14 @@ module SMESH * First, verify list of hypothesis associated with the subShape, * return NOK if hypothesis are not sufficient */ - boolean Compute( in SMESH_Mesh theMesh, + boolean Compute( in SMESH_Mesh theMesh, in GEOM::GEOM_Object theSubObject ) raises ( SALOME::SALOME_Exception ); /*! - * + * Return true if hypotheses are defined well */ - - boolean IsReadyToCompute( in SMESH_Mesh theMesh, + boolean IsReadyToCompute( in SMESH_Mesh theMesh, in GEOM::GEOM_Object theSubObject ) raises ( SALOME::SALOME_Exception ); @@ -136,7 +148,7 @@ module SMESH * Return errors of hypotheses definintion * algo_error_array is empty if everything is OK */ - algo_error_array GetAlgoState( in SMESH_Mesh theMesh, + algo_error_array GetAlgoState( in SMESH_Mesh theMesh, in GEOM::GEOM_Object theSubObject ) raises ( SALOME::SALOME_Exception ); @@ -144,15 +156,19 @@ module SMESH * */ long_array GetSubShapesId( in GEOM::GEOM_Object theMainObject, - in object_array theListOfSubObjects ) + in object_array theListOfSubObjects ) raises ( SALOME::SALOME_Exception ); - + /*! - * + * Return geometrical object the given element is built on. + * The returned geometrical object, if not nil, is either found in the + * study or is published by this method with the given name */ - // long_array GetSubMeshesState( in object_array theListOfSubShape ) - // raises ( SALOME::SALOME_Exception ); - + GEOM::GEOM_Object GetGeometryByMeshElement( in SMESH_Mesh theMesh, + in long theElementID, + in string theGeomName) + raises ( SALOME::SALOME_Exception ); + }; }; diff --git a/resources/SMESHCatalog.xml b/resources/SMESHCatalog.xml index e77ee98df..f9bb6595a 100644 --- a/resources/SMESHCatalog.xml +++ b/resources/SMESHCatalog.xml @@ -20,6 +20,7 @@ Mesh component 1 ModuleMesh.png + 1 SMESH diff --git a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx index b9d84175f..44e05bf77 100644 --- a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx @@ -34,6 +34,7 @@ #include "SMESHDS_Group.hxx" #include "MED_Factory.hxx" +#include "MED_CoordUtils.hxx" #include "MED_Utilities.hxx" #include @@ -48,7 +49,9 @@ static int MYDEBUG = 0; using namespace MED; -void DriverMED_R_SMESHDS_Mesh::SetMeshName(string theMeshName) +void +DriverMED_R_SMESHDS_Mesh +::SetMeshName(string theMeshName) { myMeshName = theMeshName; } @@ -61,83 +64,9 @@ FindNode(const SMDS_Mesh* theMesh, TInt theId){ } -enum ECoordName{eX, eY, eZ, eNone}; -typedef TFloat (*TGetCoord)(MED::PNodeInfo&, TInt); - -template -TFloat GetCoord(MED::PNodeInfo& thePNodeInfo, TInt theElemId){ - return thePNodeInfo->GetNodeCoord(theElemId,TheCoordId); -} - -template<> -TFloat GetCoord(MED::PNodeInfo& thePNodeInfo, TInt theElemId){ - return 0.0; -} - - -static TGetCoord aXYZGetCoord[3] = { - &GetCoord, - &GetCoord, - &GetCoord -}; - - -static TGetCoord aXYGetCoord[3] = { - &GetCoord, - &GetCoord, - &GetCoord -}; - -static TGetCoord aYZGetCoord[3] = { - &GetCoord, - &GetCoord, - &GetCoord -}; - -static TGetCoord aXZGetCoord[3] = { - &GetCoord, - &GetCoord, - &GetCoord -}; - - -static TGetCoord aXGetCoord[3] = { - &GetCoord, - &GetCoord, - &GetCoord -}; - -static TGetCoord aYGetCoord[3] = { - &GetCoord, - &GetCoord, - &GetCoord -}; - -static TGetCoord aZGetCoord[3] = { - &GetCoord, - &GetCoord, - &GetCoord -}; - - -class TCoordHelper{ - MED::PNodeInfo myPNodeInfo; - TGetCoord* myGetCoord; -public: - TCoordHelper(const MED::PNodeInfo& thePNodeInfo, - TGetCoord* theGetCoord): - myPNodeInfo(thePNodeInfo), - myGetCoord(theGetCoord) - {} - virtual ~TCoordHelper(){} - TFloat GetCoord(TInt theElemId, TInt theCoodId){ - return (*myGetCoord[theCoodId])(myPNodeInfo,theElemId); - } -}; -typedef boost::shared_ptr TCoordHelperPtr; - - -Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform() +Driver_Mesh::Status +DriverMED_R_SMESHDS_Mesh +::Perform() { Status aResult = DRS_FAIL; try{ @@ -193,50 +122,17 @@ Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform() //------------------------------------------------------ PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo); - TCoordHelperPtr aCoordHelperPtr; - { - TInt aMeshDimension = aMeshInfo->GetDim(); - bool anIsDimPresent[3] = {false, false, false}; - for(TInt iDim = 0; iDim < aMeshDimension; iDim++){ - string aDimName = aNodeInfo->GetCoordName(iDim); - if(aDimName == "x" || aDimName == "X") - anIsDimPresent[eX] = true; - else if(aDimName == "y" || aDimName == "Y") - anIsDimPresent[eY] = true; - else if(aDimName == "z" || aDimName == "Z") - anIsDimPresent[eZ] = true; - } - switch(aMeshDimension){ - case 3: - aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXYZGetCoord)); - break; - case 2: - if(anIsDimPresent[eY] && anIsDimPresent[eZ]) - aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aYZGetCoord)); - else if(anIsDimPresent[eX] && anIsDimPresent[eZ]) - aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXZGetCoord)); - else - aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXYGetCoord)); - break; - case 1: - if(anIsDimPresent[eY]) - aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aYGetCoord)); - else if(anIsDimPresent[eZ]) - aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aZGetCoord)); - else - aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXGetCoord)); - break; - } - } + PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo); EBooleen anIsNodeNum = aNodeInfo->IsElemNum(); TInt aNbElems = aNodeInfo->GetNbElem(); if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<GetPCellInfo(aMeshInfo,anEntity,aGeom); + EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX; + TInt aNbElems = aCellInfo->GetNbElem(); + if(MYDEBUG) MESSAGE("Perform - anEntity = "<GetFamNum(iElem); + try{ + //MESSAGE("Try to create element # " << iElem << " with id = " + // << aCellInfo->GetElemNum(iElem)); + switch(aGeom){ + case eSEG2: + case eSEG3: + if(anIsElemNum) + anElement = myMesh->AddEdgeWithID(aNodeIds[0], + aNodeIds[1], + aCellInfo->GetElemNum(iElem)); + if (!anElement) { + anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1])); + isRenum = anIsElemNum; + } + break; + case eTRIA3: + case eTRIA6: + aNbNodes = 3; + if(anIsElemNum) + anElement = myMesh->AddFaceWithID(aNodeIds[0], + aNodeIds[1], + aNodeIds[2], + aCellInfo->GetElemNum(iElem)); + if (!anElement) { + anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1]), + FindNode(myMesh,aNodeIds[2])); + isRenum = anIsElemNum; + } + break; + case eQUAD4: + case eQUAD8: + aNbNodes = 4; + // There is some differnce between SMDS and MED + if(anIsElemNum) + anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1], aNodeIds[2], aNodeIds[3], - aNodeIds[4], - aNodeIds[5], - aNodeIds[6], - aNodeIds[7], aCellInfo->GetElemNum(iElem)); - if (!anElement) { - anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]), + if (!anElement) { + anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]), FindNode(myMesh,aNodeIds[1]), FindNode(myMesh,aNodeIds[2]), - FindNode(myMesh,aNodeIds[3]), - FindNode(myMesh,aNodeIds[4]), - FindNode(myMesh,aNodeIds[5]), - FindNode(myMesh,aNodeIds[6]), - FindNode(myMesh,aNodeIds[7])); - isRenum = anIsElemNum; + FindNode(myMesh,aNodeIds[3])); + isRenum = anIsElemNum; + } + break; + case eTETRA4: + case eTETRA10: + aNbNodes = 4; + if(anIsElemNum) + anElement = myMesh->AddVolumeWithID(aNodeIds[0], + aNodeIds[1], + aNodeIds[2], + aNodeIds[3], + aCellInfo->GetElemNum(iElem)); + if (!anElement) { + anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1]), + FindNode(myMesh,aNodeIds[2]), + FindNode(myMesh,aNodeIds[3])); + isRenum = anIsElemNum; + } + break; + case ePYRA5: + case ePYRA13: + aNbNodes = 5; + // There is some differnce between SMDS and MED + if(anIsElemNum) + anElement = myMesh->AddVolumeWithID(aNodeIds[0], + aNodeIds[1], + aNodeIds[2], + aNodeIds[3], + aNodeIds[4], + aCellInfo->GetElemNum(iElem)); + if (!anElement) { + anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1]), + FindNode(myMesh,aNodeIds[2]), + FindNode(myMesh,aNodeIds[3]), + FindNode(myMesh,aNodeIds[4])); + isRenum = anIsElemNum; + } + break; + case ePENTA6: + case ePENTA15: + aNbNodes = 6; + if(anIsElemNum) + anElement = myMesh->AddVolumeWithID(aNodeIds[0], + aNodeIds[1], + aNodeIds[2], + aNodeIds[3], + aNodeIds[4], + aNodeIds[5], + aCellInfo->GetElemNum(iElem)); + if (!anElement) { + anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1]), + FindNode(myMesh,aNodeIds[2]), + FindNode(myMesh,aNodeIds[3]), + FindNode(myMesh,aNodeIds[4]), + FindNode(myMesh,aNodeIds[5])); + isRenum = anIsElemNum; + } + break; + case eHEXA8: + case eHEXA20: + aNbNodes = 8; + if(anIsElemNum) + anElement = myMesh->AddVolumeWithID(aNodeIds[0], + aNodeIds[1], + aNodeIds[2], + aNodeIds[3], + aNodeIds[4], + aNodeIds[5], + aNodeIds[6], + aNodeIds[7], + aCellInfo->GetElemNum(iElem)); + if (!anElement) { + anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1]), + FindNode(myMesh,aNodeIds[2]), + FindNode(myMesh,aNodeIds[3]), + FindNode(myMesh,aNodeIds[4]), + FindNode(myMesh,aNodeIds[5]), + FindNode(myMesh,aNodeIds[6]), + FindNode(myMesh,aNodeIds[7])); + isRenum = anIsElemNum; + } + break; } - break; + }catch(const std::exception& exc){ + //INFOS("Follow exception was cought:\n\t"<AddElement(anElement); - aFamily->SetType(anElement->GetType()); - } - } - } + if (!anElement) { + aResult = DRS_WARN_SKIP_ELEM; + } + else { + if (isRenum) { + anIsElemNum = eFAUX; + takeNumbers = false; + if (aResult < DRS_WARN_RENUMBER) + aResult = DRS_WARN_RENUMBER; + } + if ( checkFamilyID ( aFamily, aFamNum )) { + // Save reference to this element from its family + myFamilies[aFamNum]->AddElement(anElement); + myFamilies[aFamNum]->SetType(anElement->GetType()); + } + } + } + }} } } - break; } } }catch(const std::exception& exc){ diff --git a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx index 980a648d0..22b33cf63 100644 --- a/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_W_SMESHDS_Mesh.cxx @@ -329,12 +329,11 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() int aFamId = (*aFamsIter)->GetId(); const set& anElems = (*aFamsIter)->GetElements(); - set::const_iterator anElemsIter = anElems.begin(); + set::const_iterator anElemsIter = anElems.begin(); for (; anElemsIter != anElems.end(); anElemsIter++) { anElemFamMap[*anElemsIter] = aFamId; } -// delete (*aFamsIter); } // Storing SMDS nodes to the MED file for the MED mesh @@ -373,8 +372,9 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() const ERepere SMDS_COORDINATE_SYSTEM = eCART; PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo, - SMDS_COORDINATE_SYSTEM, aCoordinates, + eFULL_INTERLACE, + SMDS_COORDINATE_SYSTEM, aCoordNames, aCoordUnits, aFamilyNums, @@ -421,8 +421,8 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo, SMDS_MED_ENTITY, eSEG2, - SMDS_MED_CONNECTIVITY, aConnectivity, + SMDS_MED_CONNECTIVITY, aFamilyNums, anElemNums); myMed->SetCellInfo(aCellInfo); @@ -532,8 +532,8 @@ Driver_Mesh::Status DriverMED_W_SMESHDS_Mesh::Perform() PCellInfo aCellInfo = myMed->CrCellInfo(aMeshInfo, SMDS_MED_ENTITY, eTRIA3, - SMDS_MED_CONNECTIVITY, aTriaConn, + SMDS_MED_CONNECTIVITY, aTriaFamilyNums, anTriaElemNums); MESSAGE("Perform - anEntity = "< +#include "VTKViewer_ExtractUnstructuredGrid.h" #include "SUIT_Session.h" #include "SUIT_ResourceMgr.h" #include +#include #include #include #include @@ -786,6 +787,8 @@ vtkDataSet* SMESH_ActorDef::GetInput(){ void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){ + Superclass::SetTransform(theTransform); + myNodeActor->SetTransform(theTransform); myBaseActor->SetTransform(theTransform); diff --git a/src/SMESH/SMESH_Algo.cxx b/src/SMESH/SMESH_Algo.cxx index 9d439f763..3cddc41e7 100644 --- a/src/SMESH/SMESH_Algo.cxx +++ b/src/SMESH/SMESH_Algo.cxx @@ -32,6 +32,7 @@ using namespace std; #include "SMESH_Mesh.hxx" #include "SMESH_HypoFilter.hxx" #include "SMDS_FacePosition.hxx" +#include "SMDS_EdgePosition.hxx" #include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" #include "SMESHDS_Mesh.hxx" @@ -149,24 +150,24 @@ const list & SMESH_Algo::GetAppliedHypothesis( double SMESH_Algo::EdgeLength(const TopoDS_Edge & E) { - double UMin = 0, UMax = 0; - TopLoc_Location L; - if (BRep_Tool::Degenerated(E)) - return 0; - Handle(Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax); - GeomAdaptor_Curve AdaptCurve(C); - GCPnts_AbscissaPoint gabs; - double length = gabs.Length(AdaptCurve, UMin, UMax); - return length; + double UMin = 0, UMax = 0; + if (BRep_Tool::Degenerated(E)) + return 0; + TopLoc_Location L; + Handle(Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax); + GeomAdaptor_Curve AdaptCurve(C); + GCPnts_AbscissaPoint gabs; + double length = gabs.Length(AdaptCurve, UMin, UMax); + return length; } //================================================================================ /*! * \brief Find out elements orientation on a geometrical face - * \param theFace - The face correctly oriented in the shape being meshed - * \param theMeshDS - The mesh data structure - * \retval bool - true if the face normal and the normal of first element - * in the correspoding submesh point in different directions + * \param theFace - The face correctly oriented in the shape being meshed + * \param theMeshDS - The mesh data structure + * \retval bool - true if the face normal and the normal of first element + * in the correspoding submesh point in different directions */ //================================================================================ @@ -267,3 +268,79 @@ bool SMESH_Algo::IsReversedSubMesh (const TopoDS_Face& theFace, return Ne * Nf < 0.; } + +//================================================================================ +/*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as the algorithm does not hold parameters values + */ +//================================================================================ + +bool SMESH_Algo::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/, + const TopoDS_Shape& /*theShape*/) +{ + return false; +} + +//================================================================================ +/*! + * \brief Fill vector of node parameters on geometrical edge, including vertex nodes + * \param theMesh - The mesh containing nodes + * \param theEdge - The geometrical edge of interest + * \param theParams - The resulting vector of sorted node parameters + * \retval bool - false if not all parameters are OK + */ +//================================================================================ + +bool SMESH_Algo::GetNodeParamOnEdge(const SMESHDS_Mesh* theMesh, + const TopoDS_Edge& theEdge, + vector< double > & theParams) +{ + theParams.clear(); + + if ( !theMesh || theEdge.IsNull() ) + return false; + + SMESHDS_SubMesh * eSubMesh = theMesh->MeshElements( theEdge ); + if ( !eSubMesh || !eSubMesh->GetElements()->more() ) + return false; // edge is not meshed + + int nbEdgeNodes = 0; + set < double > paramSet; + if ( eSubMesh ) + { + // loop on nodes of an edge: sort them by param on edge + SMDS_NodeIteratorPtr nIt = eSubMesh->GetNodes(); + while ( nIt->more() ) + { + const SMDS_MeshNode* node = nIt->next(); + const SMDS_PositionPtr& pos = node->GetPosition(); + if ( pos->GetTypeOfPosition() != SMDS_TOP_EDGE ) + return false; + const SMDS_EdgePosition* epos = + static_cast(node->GetPosition().get()); + paramSet.insert( epos->GetUParameter() ); + ++nbEdgeNodes; + } + } + // add vertex nodes params + Standard_Real f, l; + BRep_Tool::Range(theEdge, f, l); + paramSet.insert( f ); + paramSet.insert( l ); + if ( paramSet.size() != nbEdgeNodes + 2 ) + return false; // there are equal parameters + + // fill the vector + theParams.resize( paramSet.size() ); + set < double >::iterator par = paramSet.begin(); + vector< double >::iterator vecPar = theParams.begin(); + for ( ; par != paramSet.end(); ++par, ++vecPar ) + *vecPar = *par; + + return theParams.size() > 1; +} diff --git a/src/SMESH/SMESH_Algo.hxx b/src/SMESH/SMESH_Algo.hxx index 12c72d828..c92b5893f 100644 --- a/src/SMESH/SMESH_Algo.hxx +++ b/src/SMESH/SMESH_Algo.hxx @@ -41,6 +41,7 @@ class SMESH_Gen; class SMESH_Mesh; class TopoDS_Face; +class TopoDS_Shape; class SMESHDS_Mesh; class SMESH_Algo:public SMESH_Hypothesis @@ -64,6 +65,19 @@ class SMESH_Algo:public SMESH_Hypothesis static double EdgeLength(const TopoDS_Edge & E); + /*! + * \brief Fill vector of node parameters on geometrical edge, including vertex nodes + * \param theMesh - The mesh containing nodes + * \param theEdge - The geometrical edge of interest + * \param theParams - The resulting vector of sorted node parameters + * \retval bool - false if not all parameters are OK + */ + static bool GetNodeParamOnEdge(const SMESHDS_Mesh* theMesh, + const TopoDS_Edge& theEdge, + std::vector< double > & theParams); + + //static bool GetSegmentLengths(); + /*! * \brief Find out elements orientation on a geometrical face * \param theFace - The face correctly oriented in the shape being meshed @@ -74,6 +88,16 @@ class SMESH_Algo:public SMESH_Hypothesis static bool IsReversedSubMesh (const TopoDS_Face& theFace, SMESHDS_Mesh* theMeshDS); + /*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as the algorithm does not hold parameters values + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + public: // algo features diff --git a/src/SMESH/SMESH_Hypothesis.hxx b/src/SMESH/SMESH_Hypothesis.hxx index 1d881a680..2edcd141a 100644 --- a/src/SMESH/SMESH_Hypothesis.hxx +++ b/src/SMESH/SMESH_Hypothesis.hxx @@ -32,6 +32,8 @@ #include "SMESHDS_Hypothesis.hxx" class SMESH_Gen; +class TopoDS_Shape; +class SMESH_Mesh; class SMESH_Hypothesis: public SMESHDS_Hypothesis { @@ -61,6 +63,14 @@ public: const char* GetLibName() const; void SetLibName(const char* theLibName); + /*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape)=0; + protected: SMESH_Gen* _gen; int _studyId; diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx index ffd77cd55..a4b5f80af 100644 --- a/src/SMESH/SMESH_Mesh.cxx +++ b/src/SMESH/SMESH_Mesh.cxx @@ -1069,8 +1069,8 @@ void SMESH_Mesh::RemoveGroup (const int theGroupID) if (_mapGroup.find(theGroupID) == _mapGroup.end()) return; GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() ); - _mapGroup.erase (theGroupID); delete _mapGroup[theGroupID]; + _mapGroup.erase (theGroupID); } //============================================================================= diff --git a/src/SMESHFiltersSelection/Makefile.in b/src/SMESHFiltersSelection/Makefile.in index e9c388166..c438321b7 100644 --- a/src/SMESHFiltersSelection/Makefile.in +++ b/src/SMESHFiltersSelection/Makefile.in @@ -64,7 +64,7 @@ EXPORT_HEADERS= SMESH_Type.h \ # additionnal information to compil and link file CPPFLAGS += $(OCC_INCLUDES) $(QT_INCLUDES) $(PYTHON_INCLUDES) $(VTK_INCLUDES) \ -I${KERNEL_ROOT_DIR}/include/salome -I${GUI_ROOT_DIR}/include/salome \ - -I${GEOM_ROOT_DIR}/include/salome -I${BOOSTDIR} + -I${GEOM_ROOT_DIR}/include/salome ${BOOST_CPPFLAGS} CXXFLAGS += $(OCC_CXXFLAGS) -I${KERNEL_ROOT_DIR}/include/salome -I${GUI_ROOT_DIR}/include/salome \ -I${GEOM_ROOT_DIR}/include/salome -I${BOOSTDIR} LDFLAGS += $(OCC_KERNEL_LIBS) -L${GUI_ROOT_DIR}/lib/salome -L${GEOM_ROOT_DIR}/lib/salome -lSalomeApp -lsuit diff --git a/src/SMESHGUI/Makefile.in b/src/SMESHGUI/Makefile.in index a1d7e8ac6..55987d6c2 100644 --- a/src/SMESHGUI/Makefile.in +++ b/src/SMESHGUI/Makefile.in @@ -108,7 +108,8 @@ LIB_SRC = SMESHGUI.cxx \ SMESHGUI_MeshDlg.cxx \ SMESHGUI_MeshOp.cxx \ SMESHGUI_Displayer.cxx \ - SMESHGUI_Hypotheses.cxx + SMESHGUI_Hypotheses.cxx \ + SMESHGUI_ShapeByMeshDlg.cxx LIB_MOC = \ SMESHGUI.h \ @@ -155,7 +156,8 @@ LIB_MOC = \ SMESHGUI_Dialog.h \ SMESHGUI_MeshDlg.h \ SMESHGUI_MeshOp.h \ - SMESHGUI_Hypotheses.h + SMESHGUI_Hypotheses.h \ + SMESHGUI_ShapeByMeshDlg.h LIB_CLIENT_IDL = SALOME_Exception.idl \ diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index fae703982..ecc471d99 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -104,7 +104,6 @@ #include "SUIT_ResourceMgr.h" #include "SUIT_FileDlg.h" #include "SUIT_Desktop.h" -#include "SUIT_ResourceMgr.h" #include "SUIT_OverrideCursor.h" #include "SUIT_Study.h" #include "SUIT_Session.h" @@ -1071,6 +1070,10 @@ bool SMESHGUI::OnGUIEvent( int theCommandID ) if( !mgr ) return false; + if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) { + GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy()); + } + SUIT_ViewWindow* view = application()->desktop()->activeWindow(); SVTK_ViewWindow* vtkwnd = dynamic_cast( view ); @@ -2995,11 +2998,67 @@ void SMESHGUI::createPreferences() void SMESHGUI::preferencesChanged( const QString& sect, const QString& name ) { - if( sect=="SMESH" ) + if( sect=="SMESH" ){ + float sbX1,sbY1,sbW,sbH; + std::string aWarning; + SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this); if( name=="selection_object_color" || name=="selection_element_color" || name=="selection_width" || name=="highlight_color" || name=="highlight_width" || name=="selection_precision_node" || name=="selection_precision_element" ) SMESH::UpdateSelectionProp( this ); + else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){ + sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1); + sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW); + if(sbX1+sbW > 1.0){ + aWarning = "Origin and Size Vertical: X+Width > 1\n"; + sbX1=0.01; + sbW=0.05; + aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1); + aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW); + } + } + else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){ + sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1); + sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH); + if(sbY1+sbH > 1.0){ + aWarning = "Origin and Size Vertical: Y+Height > 1\n"; + sbY1=0.01; + sbH=0.5; + aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1); + aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH); + } + } + else if(name == QString("scalar_bar_horizontal_x") || name == QString("scalar_bar_horizontal_width")){ + sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1); + sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW); + if(sbX1+sbW > 1.0){ + aWarning = "Origin and Size Horizontal: X+Width > 1\n"; + sbX1=0.2; + sbW=0.6; + aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1); + aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW); + } + } + else if(name == QString("scalar_bar_horizontal_y") || name == QString("scalar_bar_horizontal_height")){ + sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1); + sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH); + if(sbY1+sbH > 1.0){ + aWarning = "Origin and Size Horizontal: Y+Height > 1\n"; + sbY1=0.01; + sbH=0.12; + aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1); + aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH); + } + } + + if(aWarning.size() != 0){ + aWarning += "The default values are applied instead."; + SUIT_MessageBox::warn1(SMESHGUI::desktop(), + QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"), + QObject::tr(aWarning.c_str()), + QObject::tr("SMESH_BUT_OK")); + } + } } //================================================================================ @@ -3083,6 +3142,20 @@ LightApp_Operation* SMESHGUI::createOperation( const int id ) const return op; } +//================================================================================ +/*! + * \brief Stops current operations and starts a given one + * \param id - The id of the operation to start + */ +//================================================================================ + +void SMESHGUI::switchToOperation(int id) +{ + if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) + activeStudy()->abortAllOperations(); + startOperation( id ); +} + LightApp_Displayer* SMESHGUI::displayer() { if( !myDisplayer ) diff --git a/src/SMESHGUI/SMESHGUI.h b/src/SMESHGUI/SMESHGUI.h index 595d831e7..9626e4358 100644 --- a/src/SMESHGUI/SMESHGUI.h +++ b/src/SMESHGUI/SMESHGUI.h @@ -83,6 +83,7 @@ public : void ResetState() ; void SetState(int aState) ; bool DefineDlgPosition(QWidget* aDlg, int& x, int& y) ; + void switchToOperation(int id) ; virtual bool OnGUIEvent ( int id ); virtual bool OnMousePress ( QMouseEvent*, SUIT_ViewWindow* ); diff --git a/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx b/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx index 0b5e32022..7a396fd41 100644 --- a/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_AddMeshElementDlg.cxx @@ -65,6 +65,7 @@ #include #include #include +#include // QT Includes #include diff --git a/src/SMESHGUI/SMESHGUI_ClippingDlg.cxx b/src/SMESHGUI/SMESHGUI_ClippingDlg.cxx index 4fe87b62a..5bac21893 100644 --- a/src/SMESHGUI/SMESHGUI_ClippingDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_ClippingDlg.cxx @@ -69,6 +69,7 @@ #include #include #include +#include // STL includes #include diff --git a/src/SMESHGUI/SMESHGUI_CreatePolyhedralVolumeDlg.cxx b/src/SMESHGUI/SMESHGUI_CreatePolyhedralVolumeDlg.cxx index 157a05b0f..abced02c6 100644 --- a/src/SMESHGUI/SMESHGUI_CreatePolyhedralVolumeDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_CreatePolyhedralVolumeDlg.cxx @@ -62,6 +62,7 @@ #include #include #include +#include // QT Includes #include @@ -109,6 +110,7 @@ class TPolySimulation{ myPreviewActor->PickableOff(); myPreviewActor->VisibilityOff(); myPreviewActor->SetMapper( myMapper ); + myPreviewActor->SetRepresentation( 3 ); float anRGB[3]; vtkProperty* aProp = vtkProperty::New(); @@ -398,8 +400,6 @@ void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId) { if ( myActor ){ myActor->SetPointRepresentation(true); - myActor->SetEntityMode(SMESH_Actor::eVolumes); - myActor->SetRepresentation(SMESH_Actor::eSurface); } else SMESH::SetPointRepresentation(true); @@ -421,9 +421,6 @@ void SMESHGUI_CreatePolyhedralVolumeDlg::ConstructorsClicked(int constructorId) { if( myActor ){ myActor->SetPointRepresentation(false); - myActor->SetEntityMode(SMESH_Actor::eFaces); - myActor->SetEntityMode(SMESH_Actor::eVolumes); - myActor->SetRepresentation(SMESH_Actor::eSurface); } else { SMESH::SetPointRepresentation(false); } @@ -528,8 +525,11 @@ void SMESHGUI_CreatePolyhedralVolumeDlg::ClickOnApply() //SALOME_ListIO aList; //mySelectionMgr->setSelectedObjects( aList ); - mySimulation->SetVisibility(false); SMESH::UpdateView(); + if( myActor ){ + unsigned int anEntityMode = myActor->GetEntityMode(); + myActor->SetEntityMode(SMESH_Actor::eVolumes | anEntityMode); + } ConstructorsClicked( GetConstructorId() ); busy = false; } @@ -640,7 +640,8 @@ void SMESHGUI_CreatePolyhedralVolumeDlg::onTextChange(const QString& theNewText) buttonOk->setEnabled( false ); buttonApply->setEnabled( false ); } - displaySimulation(); + if(aListId.count()>1) + displaySimulation(); } } } @@ -694,9 +695,10 @@ void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument() // get selected nodes/faces QString aString = ""; + int anbNodes=0,aNbFaces=0; switch(GetConstructorId()){ case 0:{ - int anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString); + anbNodes = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString); if (anbNodes >= 3) AddButton->setEnabled(true); else if (anbNodes < 3){ @@ -709,7 +711,7 @@ void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument() } case 1:{ // get selected faces - int aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString); + aNbFaces = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString); if (aNbFaces<=1){ buttonOk->setEnabled( false ); buttonApply->setEnabled( false ); @@ -727,8 +729,8 @@ void SMESHGUI_CreatePolyhedralVolumeDlg::SelectionIntoArgument() } default: return; } - - displaySimulation(); + if(anbNodes>2 || aNbFaces>1) + displaySimulation(); } //======================================================================= @@ -742,8 +744,6 @@ void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation() SMESH::TPolySimulation::TVTKIds aVTKIds; vtkIdType aType = VTK_CONVEX_POINT_SET ; if (GetConstructorId() == 0){ - if(!Preview->isChecked()) myActor->SetEntityMode(SMESH_Actor::eFaces); - else myActor->SetEntityMode(SMESH_Actor::eVolumes); if (!AddButton->isEnabled()){ QListBoxItem* anItem; mySimulation->ResetGrid(true); @@ -771,7 +771,6 @@ void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation() } else { // add ids from edit line QStringList anEditIds = QStringList::split( " ", myEditCurrentArgument->text(), false); - myActor->SetEntityMode(SMESH_Actor::eFaces); for ( int i = 0; i < anEditIds.count(); i++ ) aVTKIds.push_back( myActor->GetObject()->GetNodeVTKId( anEditIds[ i ].toInt() )); aType = VTK_POLYGON; @@ -781,10 +780,6 @@ void SMESHGUI_CreatePolyhedralVolumeDlg::displaySimulation() SMDS_Mesh* aMesh = 0; if ( myActor ){ aMesh = myActor->GetObject()->GetMesh(); - if (Preview->isChecked()) - myActor->SetEntityMode(SMESH_Actor::eVolumes); - else - myActor->SetEntityMode(SMESH_Actor::eFaces); } if ( aMesh ) { QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false); diff --git a/src/SMESHGUI/SMESHGUI_FilterDlg.cxx b/src/SMESHGUI/SMESHGUI_FilterDlg.cxx index 6e4ab9f01..cd3d8eb65 100755 --- a/src/SMESHGUI/SMESHGUI_FilterDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_FilterDlg.cxx @@ -2260,17 +2260,17 @@ bool SMESHGUI_FilterDlg::createFilter (const int theType) //======================================================================= void SMESHGUI_FilterDlg::insertFilterInViewer() { - if (SVTK_InteractorStyle* aStyle = SMESH::GetInteractorStyle()) { + if (SVTK_Selector* aSelector = SMESH::GetSelector()) { SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType(); if (myFilter[ myTable->GetType() ]->_is_nil() || myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() || !mySetInViewer->isChecked()) { - SMESH::RemoveFilter(getFilterId(anEntType), aStyle); + SMESH::RemoveFilter(getFilterId(anEntType), aSelector); } else { Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter(); aFilter->SetPredicate(myFilter[ myTable->GetType() ]->GetPredicate()); - SMESH::SetFilter(aFilter, aStyle); + SMESH::SetFilter(aFilter, aSelector); } } } diff --git a/src/SMESHGUI/SMESHGUI_GEOMGenUtils.cxx b/src/SMESHGUI/SMESHGUI_GEOMGenUtils.cxx index c9ffc82e6..4ea7e9180 100644 --- a/src/SMESHGUI/SMESHGUI_GEOMGenUtils.cxx +++ b/src/SMESHGUI/SMESHGUI_GEOMGenUtils.cxx @@ -37,8 +37,11 @@ namespace SMESH { { static GEOM::GEOM_Gen_var aGEOMGen; - if(CORBA::is_nil(aGEOMGen)) - aGEOMGen = GeometryGUI::GetGeomGen(); + if(CORBA::is_nil(aGEOMGen)) { + if ( GeometryGUI::GetGeomGen()->_is_nil() ) + GeometryGUI::InitGeomGen(); + aGEOMGen = GeometryGUI::GetGeomGen(); + } return aGEOMGen; } diff --git a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx index 82da54af8..b9396313b 100644 --- a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx @@ -89,6 +89,7 @@ SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name, WStyle_Title | WStyle_SysMenu | WDestructiveClose), mySMESHGUI( theModule ), mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), + mySelector(SMESH::GetViewWindow( theModule )->GetSelector()), myIsBusy( false ), myActor( 0 ) { @@ -103,7 +104,6 @@ SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name, myGeomGroupLine->setEnabled(false); } - mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector(); /* Move widget on the botton right corner of main widget */ int x, y ; @@ -121,12 +121,11 @@ SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule, const char* name, WStyle_Title | WStyle_SysMenu | WDestructiveClose), mySMESHGUI( theModule ), mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ), + mySelector(SMESH::GetViewWindow( theModule )->GetSelector()), myIsBusy( false ) { if (!name) setName("SMESHGUI_GroupDlg"); - mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector(); - initDialog(false); if (!theGroup->_is_nil()) init(theGroup); @@ -563,14 +562,14 @@ void SMESHGUI_GroupDlg::setSelectionMode (int theMode) aViewWindow->SetSelectionMode(VolumeSelection); } } else { - if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) - aViewWindow->SetSelectionMode(ActorSelection); if (theMode == 4) mySelectionMgr->installFilter(mySubMeshFilter); else if (theMode == 5) mySelectionMgr->installFilter(myGroupFilter); else if (theMode == 6) mySelectionMgr->installFilter(myMeshFilter); + if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) + aViewWindow->SetSelectionMode(ActorSelection); } mySelectionMode = theMode; } @@ -716,8 +715,6 @@ void SMESHGUI_GroupDlg::onListSelectionChanged() SALOME_ListIO aList; aList.Append(myActor->getIO()); mySelectionMgr->setSelectedObjects(aList,false); - if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) - aViewWindow->highlight( myActor->getIO(), true, true ); } myIsBusy = false; } @@ -1096,12 +1093,27 @@ void SMESHGUI_GroupDlg::onAdd() SMESH::ElementType aType = SMESH::ALL; switch(myTypeId) { - case 0: aType = SMESH::NODE; break; - case 1: aType = SMESH::EDGE; break; - case 2: aType = SMESH::FACE; break; - case 3: aType = SMESH::VOLUME; break; + case 0: + aType = SMESH::NODE; + mySelector->SetSelectionMode(NodeSelection); + break; + case 1: + aType = SMESH::EDGE; + mySelector->SetSelectionMode(EdgeSelection); + break; + case 2: + aType = SMESH::FACE; + mySelector->SetSelectionMode(FaceSelection); + break; + case 3: + aType = SMESH::VOLUME; + mySelector->SetSelectionMode(VolumeSelection); + break; + default: + mySelector->SetSelectionMode(ActorSelection); } + if (myCurrentLineEdit == 0) { //if (aNbSel != 1) { myIsBusy = false; return; } QString aListStr = ""; diff --git a/src/SMESHGUI/SMESHGUI_Hypotheses.cxx b/src/SMESHGUI/SMESHGUI_Hypotheses.cxx index 676c37cc4..6926df448 100644 --- a/src/SMESHGUI/SMESHGUI_Hypotheses.cxx +++ b/src/SMESHGUI/SMESHGUI_Hypotheses.cxx @@ -27,6 +27,16 @@ SMESHGUI_GenericHypothesisCreator::~SMESHGUI_GenericHypothesisCreator() { } +void SMESHGUI_GenericHypothesisCreator::create( SMESH::SMESH_Hypothesis_ptr initParamsHyp, + QWidget* parent) +{ + MESSAGE( "Creation of hypothesis with initial params" ); + + if ( !CORBA::is_nil( initParamsHyp ) && hypType() == initParamsHyp->GetName() ) + myInitParamsHypo = SMESH::SMESH_Hypothesis::_duplicate( initParamsHyp ); + create( false, parent ); +} + void SMESHGUI_GenericHypothesisCreator::create( const bool isAlgo, QWidget* parent ) { MESSAGE( "Creation of hypothesis" ); @@ -94,6 +104,7 @@ bool SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ bool res = true; myHypo = SMESH::SMESH_Hypothesis::_duplicate( h ); + QFrame* fr = buildFrame(); if( fr ) { @@ -105,12 +116,18 @@ bool SMESHGUI_GenericHypothesisCreator::editHypothesis( SMESH::SMESH_Hypothesis_ dlg->setType( type() ); retrieveParams(); res = dlg->exec()==QDialog::Accepted; - if( res ) - storeParams(); + if( res ) { + QString paramValues = storeParams(); + if ( !paramValues.isEmpty() ) { + if ( _PTR(SObject) SHyp = SMESH::FindSObject( myHypo )) + SMESH::SetValue( SHyp, paramValues ); + } + } delete dlg; } changeWidgets().clear(); myHypo = SMESH::SMESH_Hypothesis::_nil(); + myInitParamsHypo = SMESH::SMESH_Hypothesis::_nil(); return res; } @@ -144,37 +161,38 @@ QFrame* SMESHGUI_GenericHypothesisCreator::buildStdFrame() QLabel* lab = new QLabel( (*anIt).myName, GroupC1 ); GroupC1Layout->addWidget( lab, i, 0 ); - QWidget* w = 0; - switch( (*anIt).myValue.type() ) - { - case QVariant::Int: - { - QtxIntSpinBox* sb = new QtxIntSpinBox( GroupC1, (*anIt).myName.latin1() ); - attuneStdWidget( sb, i ); - sb->setValue( (*anIt).myValue.toInt() ); - connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) ); - w = sb; - } - break; - case QVariant::Double: - { - QtxDblSpinBox* sb = new SMESHGUI_SpinBox( GroupC1, (*anIt).myName.latin1() ); - attuneStdWidget( sb, i ); - sb->setValue( (*anIt).myValue.toDouble() ); - connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) ); - w = sb; - } - break; - case QVariant::String: + QWidget* w = getCustomWidget( *anIt, GroupC1 ); + if ( !w ) + switch( (*anIt).myValue.type() ) { - QLineEdit* le = new QLineEdit( GroupC1, (*anIt).myName.latin1() ); - attuneStdWidget( le, i ); - le->setText( (*anIt).myValue.toString() ); - connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) ); - w = le; + case QVariant::Int: + { + QtxIntSpinBox* sb = new QtxIntSpinBox( GroupC1, (*anIt).myName.latin1() ); + attuneStdWidget( sb, i ); + sb->setValue( (*anIt).myValue.toInt() ); + connect( sb, SIGNAL( valueChanged( int ) ), this, SLOT( onValueChanged() ) ); + w = sb; + } + break; + case QVariant::Double: + { + QtxDblSpinBox* sb = new SMESHGUI_SpinBox( GroupC1, (*anIt).myName.latin1() ); + attuneStdWidget( sb, i ); + sb->setValue( (*anIt).myValue.toDouble() ); + connect( sb, SIGNAL( valueChanged( double ) ), this, SLOT( onValueChanged() ) ); + w = sb; + } + break; + case QVariant::String: + { + QLineEdit* le = new QLineEdit( GroupC1, (*anIt).myName.latin1() ); + attuneStdWidget( le, i ); + le->setText( (*anIt).myValue.toString() ); + connect( le, SIGNAL( textChanged( const QString& ) ), this, SLOT( onValueChanged() ) ); + w = le; + } + break; } - break; - } if( w ) { @@ -224,17 +242,56 @@ bool SMESHGUI_GenericHypothesisCreator::getStdParamFromDlg( ListOfStdParams& par params.append( item ); } - else + else if ( getParamFromCustomWidget( item, *anIt )) + { + params.append( item ); + } + + else res = false; } return res; } +QString SMESHGUI_GenericHypothesisCreator::stdParamValues( const ListOfStdParams& params) +{ + QString valueStr = ""; + ListOfStdParams::const_iterator param = params.begin(), aLast = params.end(); + for( int i=0; param!=aLast; param++, i++ ) + { + if ( i > 0 ) + valueStr += "; "; + switch( (*param).myValue.type() ) + { + case QVariant::Int: + valueStr += valueStr.number( (*param).myValue.toInt() ); + break; + case QVariant::Double: + valueStr += valueStr.number( (*param).myValue.toDouble() ); + break; + case QVariant::String: + valueStr += (*param).myValue.toString(); + break; + default: + QVariant valCopy = (*param).myValue; + valueStr += valCopy.asString(); + } + } + return valueStr; +} + SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::hypothesis() const { return myHypo; } +SMESH::SMESH_Hypothesis_var SMESHGUI_GenericHypothesisCreator::initParamsHypothesis() const +{ + if ( CORBA::is_nil( myInitParamsHypo )) + return myHypo; + return myInitParamsHypo; +} + QString SMESHGUI_GenericHypothesisCreator::hypType() const { return myHypType; @@ -273,10 +330,15 @@ QString SMESHGUI_GenericHypothesisCreator::type() const { return QString(); } - - - - +QWidget* SMESHGUI_GenericHypothesisCreator::getCustomWidget( const StdParam & /*param*/, + QWidget* /*parent*/) const +{ + return 0; +} +bool SMESHGUI_GenericHypothesisCreator::getParamFromCustomWidget( StdParam& , QWidget* ) const +{ + return false; +} diff --git a/src/SMESHGUI/SMESHGUI_Hypotheses.h b/src/SMESHGUI/SMESHGUI_Hypotheses.h index a4558df89..d47422a4a 100644 --- a/src/SMESHGUI/SMESHGUI_Hypotheses.h +++ b/src/SMESHGUI/SMESHGUI_Hypotheses.h @@ -50,6 +50,7 @@ public: void create( const bool isAlgo, QWidget* ); void edit( SMESH::SMESH_Hypothesis_ptr, QWidget* ); + void create( SMESH::SMESH_Hypothesis_ptr, QWidget* ); virtual bool checkParams() const = 0; QString hypType() const; @@ -67,16 +68,20 @@ protected: typedef QPtrList ListOfWidgets; SMESH::SMESH_Hypothesis_var hypothesis() const; + SMESH::SMESH_Hypothesis_var initParamsHypothesis() const; const ListOfWidgets& widgets() const; ListOfWidgets& changeWidgets(); virtual QFrame* buildFrame () = 0; QFrame* buildStdFrame (); virtual void retrieveParams() const = 0; - virtual void storeParams () const = 0; + virtual QString storeParams () const = 0; virtual bool stdParams ( ListOfStdParams& ) const; bool getStdParamFromDlg( ListOfStdParams& ) const; + static QString stdParamValues( const ListOfStdParams& ); virtual void attuneStdWidget( QWidget*, const int ) const; + virtual QWidget* getCustomWidget( const StdParam &, QWidget* ) const; + virtual bool getParamFromCustomWidget( StdParam& , QWidget* ) const; virtual QString caption() const; virtual QPixmap icon() const; virtual QString type() const; @@ -88,7 +93,7 @@ private: bool editHypothesis( SMESH::SMESH_Hypothesis_ptr, QWidget* ); private: - SMESH::SMESH_Hypothesis_var myHypo; + SMESH::SMESH_Hypothesis_var myHypo, myInitParamsHypo; QString myHypType; ListOfWidgets myParamWidgets; bool myIsCreate; diff --git a/src/SMESHGUI/SMESHGUI_MeshDlg.cxx b/src/SMESHGUI/SMESHGUI_MeshDlg.cxx index 6d9e88e58..a9dbbcaa1 100644 --- a/src/SMESHGUI/SMESHGUI_MeshDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_MeshDlg.cxx @@ -371,6 +371,7 @@ SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh createObject( tr( "MESH" ), aGrp, Mesh ); // geometry createObject( tr( "GEOMETRY" ), aGrp, Geom ); + myGeomPopup = 0; // Create tab widget @@ -520,3 +521,40 @@ void SMESHGUI_MeshDlg::onHypoSetButton() { myHypoSetPopup->exec( QCursor::pos() ); } + +//================================================================================ +/*! + * \brief Enable showing of the popup when Geometry selection btn is clicked + * \param enable - true to enable + */ +//================================================================================ + +enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX }; + +void SMESHGUI_MeshDlg::setGeomPopupEnabled( const bool enable ) +{ + if ( QButton* selBtn = dynamic_cast( objectWg( Geom, Btn ))) + { + disconnect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) )); + if ( enable ) { + if ( ! myGeomPopup ) { + myGeomPopup = new QPopupMenu(); + myGeomPopup->insertItem( tr("DIRECT_GEOM_SELECTION"), DIRECT_GEOM_INDEX ); + myGeomPopup->insertItem( tr("GEOM_BY_MESH_ELEM_SELECTION"), GEOM_BY_MESH_INDEX ); + connect( myGeomPopup, SIGNAL( activated( int ) ), SLOT( onGeomPopup( int ) ) ); + } + connect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) )); + } + } +} + +void SMESHGUI_MeshDlg::onGeomSelectionButton(bool isBtnOn) +{ + if ( myGeomPopup && isBtnOn ) + myGeomPopup->exec( QCursor::pos() ); +} + +void SMESHGUI_MeshDlg::onGeomPopup( int index ) +{ + emit geomSelectionByMesh( index == GEOM_BY_MESH_INDEX ); +} diff --git a/src/SMESHGUI/SMESHGUI_MeshDlg.h b/src/SMESHGUI/SMESHGUI_MeshDlg.h index f83b77c48..f12773bd1 100644 --- a/src/SMESHGUI/SMESHGUI_MeshDlg.h +++ b/src/SMESHGUI/SMESHGUI_MeshDlg.h @@ -71,21 +71,26 @@ public: void setCurrentTab( const int ); void setMaxHypoDim( const int ); void setHypoSets( const QStringList& ); + void setGeomPopupEnabled( const bool ); signals: void hypoSet( const QString& ); + void geomSelectionByMesh( bool ); private slots: void onHypoSetPopup( int ); void onHypoSetButton(); + void onGeomPopup( int ); + void onGeomSelectionButton( bool ); private: QMap< int, SMESHGUI_MeshTab* > myTabs; QTabWidget* myTabWg; QPopupMenu* myHypoSetPopup; + QPopupMenu* myGeomPopup; }; /*! diff --git a/src/SMESHGUI/SMESHGUI_MeshOp.cxx b/src/SMESHGUI/SMESHGUI_MeshOp.cxx index 7904ea372..1bf664dfd 100644 --- a/src/SMESHGUI/SMESHGUI_MeshOp.cxx +++ b/src/SMESHGUI/SMESHGUI_MeshOp.cxx @@ -31,6 +31,7 @@ #include "SMESHGUI_MeshOp.h" #include "SMESHGUI_MeshDlg.h" +#include "SMESHGUI_ShapeByMeshDlg.h" #include "SMESH_TypeFilter.hxx" #include "SMESHGUI.h" @@ -38,11 +39,14 @@ #include "SMESHGUI_Hypotheses.h" #include "SMESHGUI_Utils.h" #include "SMESHGUI_GEOMGenUtils.h" +#include "SMESHGUI_VTKUtils.h" #include "SMESH_TypeFilter.hxx" #include "SMESH_NumberFilter.hxx" #include "GEOM_SelectionFilter.h" +#include "GEOMBase.h" +#include "GeometryGUI.h" #include "SalomeApp_Tools.h" #include "SALOMEDSClient_Study.hxx" @@ -51,14 +55,13 @@ #include "SALOMEDS_SComponent.hxx" #include "SALOMEDS_SObject.hxx" - #include "LightApp_SelectionMgr.h" #include "LightApp_UpdateFlags.h" #include "SUIT_MessageBox.h" #include "SUIT_Desktop.h" #include "SUIT_OverrideCursor.h" - -#include "GEOMBase.h" +#include "SALOME_InteractiveObject.hxx" +#include "SALOME_ListIO.hxx" #include "utilities.h" @@ -68,6 +71,17 @@ #include #include +enum { GLOBAL_ALGO_TAG =3, + GLOBAL_HYPO_TAG =2, + LOCAL_ALGO_TAG =2, + LOCAL_HYPO_TAG =1, + SUBMESH_ON_EDGE_TAG =5, + SUBMESH_ON_WIRE_TAG =6, + SUBMESH_ON_FACE_TAG =7, + SUBMESH_ON_SHELL_TAG =8, + SUBMESH_ON_SOLID_TAG =9, + SUBMESH_ON_COMPOUND_TAG=10 }; + //================================================================================ /*! * \brief Constructor @@ -81,8 +95,11 @@ SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh ) : SMESHGUI_SelectionOp(), myToCreate( theToCreate ), myIsMesh( theIsMesh ), - myDlg( 0 ) + myDlg( 0 ), + myShapeByMeshDlg( 0 ) { + if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists + GeometryGUI::InitGeomGen(); } //================================================================================ @@ -92,7 +109,7 @@ SMESHGUI_MeshOp::SMESHGUI_MeshOp( const bool theToCreate, const bool theIsMesh ) //================================================================================ SMESHGUI_MeshOp::~SMESHGUI_MeshOp() { - if( myDlg ) + if ( myDlg ) delete myDlg; } @@ -190,6 +207,7 @@ void SMESHGUI_MeshOp::startOperation() this, SLOT( onEditHyp( const int, const int) ) ); } connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& ))); + connect( myDlg, SIGNAL( geomSelectionByMesh( bool )), SLOT( onGeomSelectionByMesh( bool ))); } SMESHGUI_SelectionOp::startOperation(); @@ -253,6 +271,105 @@ SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const return 0; } +//================================================================================ +/*! + * \brief check if selected shape is a subshape of the shape to mesh + * \retval bool - check result + */ +//================================================================================ + +bool SMESHGUI_MeshOp::isSubshapeOk() const +{ + if ( !myToCreate || myIsMesh ) // not submesh creation + return false; + + QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh ); + QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom ); + _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() ); + _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() ); + if ( pMesh && pGeom ) { + SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface( pMesh ); + if ( !mesh->_is_nil() ) { + GEOM::GEOM_Object_var mainGeom, subGeom; + mainGeom = mesh->GetShapeToMesh(); + subGeom = SMESH::SObjectToInterface( pGeom ); + if ( !mainGeom->_is_nil() && !subGeom->_is_nil() ) { + TopoDS_Shape mainShape, subShape; + if ( GEOMBase::GetShape( mainGeom, mainShape ) && + GEOMBase::GetShape( subGeom, subShape ) ) + { + int index = GEOMBase::GetIndex( subShape, mainShape, 0 ); + if ( index > 0 ) { + // 1 is index of mainShape itself + return index > 1; // it is a subshape + } + // is it a group? + GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen(); + _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); + if ( !geomGen->_is_nil() && aStudy ) { + GEOM::GEOM_IGroupOperations_var op = + geomGen->GetIGroupOperations( aStudy->StudyId() ); + if ( ! op->_is_nil() ) { + GEOM::GEOM_Object_var mainObj = op->GetMainShape( subGeom ); + if ( !mainObj->_is_nil() ) + return ( string( mainObj->GetEntry() ) == string( mainGeom->GetEntry() )); + } + } + } + } + } + } + return false; +} + +//================================================================================ +/*! + * \brief find an existing submesh by the selected shape + * \retval _PTR(SObject) - the found submesh SObject + */ +//================================================================================ + +_PTR(SObject) SMESHGUI_MeshOp::getSubmeshByGeom() const +{ + QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh ); + QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom ); + _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() ); + _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() ); + if ( pMesh && pGeom ) { + GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface( pGeom ); + if ( !geom->_is_nil() ) { + int tag = -1; + switch ( geom->GetShapeType() ) { + case GEOM::EDGE: tag = SUBMESH_ON_EDGE_TAG ; break; + case GEOM::WIRE: tag = SUBMESH_ON_WIRE_TAG ; break; + case GEOM::FACE: tag = SUBMESH_ON_FACE_TAG ; break; + case GEOM::SHELL: tag = SUBMESH_ON_SHELL_TAG ; break; + case GEOM::SOLID: tag = SUBMESH_ON_SOLID_TAG ; break; + case GEOM::COMPOUND: tag = SUBMESH_ON_COMPOUND_TAG; break; + default:; + } + _PTR(SObject) aSubmeshRoot; + _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); + if ( pMesh->FindSubObject( tag, aSubmeshRoot ) ) + { + _PTR(ChildIterator) smIter = aStudy->NewChildIterator( aSubmeshRoot ); + for (; smIter->More(); smIter->Next() ) + { + _PTR(SObject) aSmObj = smIter->Value(); + _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSmObj); + for (; anIter1->More(); anIter1->Next()) { + _PTR(SObject) pGeom2 = anIter1->Value(); + if ( pGeom2->ReferencedObject( pGeom2 ) && + pGeom2->GetID() == pGeom->GetID() ) + return aSmObj; + } + } + } + } + } + return _PTR(SObject)(); +} + //================================================================================ /*! * \brief Updates dialog's look and feel @@ -262,41 +379,17 @@ SUIT_SelectionFilter* SMESHGUI_MeshOp::createFilter( const int theId ) const //================================================================================ void SMESHGUI_MeshOp::selectionDone() { + if ( myShapeByMeshDlg && myShapeByMeshDlg->isShown() ) + return; + SMESHGUI_SelectionOp::selectionDone(); - if ( !myToCreate ) + try { - try - { - QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ); - _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() ); - if ( pObj != 0 ) - { - SMESH::SMESH_subMesh_var aVar = - SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() ); - myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() ); - myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide(); - myDlg->updateGeometry(); - myDlg->adjustSize(); - readMesh(); - } - else - myDlg->reset(); - } - catch ( const SALOME::SALOME_Exception& S_ex ) - { - SalomeApp_Tools::QtCatchCorbaException( S_ex ); - } - catch ( ... ) - { - } - } + // Enable tabs according to shape dimension - // Enable tabs according to shape dimension + int shapeDim = 3; - int shapeDim = 3; - try - { GEOM::GEOM_Object_var aGeomVar; QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom ); _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() ); @@ -332,6 +425,61 @@ void SMESHGUI_MeshOp::selectionDone() } } } + myDlg->setMaxHypoDim( shapeDim ); + + if ( !myToCreate ) // edition: read hypotheses + { + QString anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ); + _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.latin1() ); + if ( pObj != 0 ) + { + SMESH::SMESH_subMesh_var aVar = + SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() ); + myDlg->setObjectShown( SMESHGUI_MeshDlg::Mesh, !aVar->_is_nil() ); + myDlg->objectWg( SMESHGUI_MeshDlg::Mesh, SMESHGUI_MeshDlg::Btn )->hide(); + myDlg->updateGeometry(); + myDlg->adjustSize(); + readMesh(); + } + else + myDlg->reset(); + + } + else if ( !myIsMesh ) // submesh creation + { + // if a submesh on the selected shape already exist, pass to submesh edition mode + if ( _PTR(SObject) pSubmesh = getSubmeshByGeom() ) { + SMESH::SMESH_subMesh_var sm = + SMESH::SObjectToInterface( pSubmesh ); + bool editSubmesh = ( !sm->_is_nil() && + SUIT_MessageBox::question2( myDlg, tr( "SMESH_WARNING" ), + tr( "EDIT_SUBMESH_QUESTION"), + tr( "SMESH_BUT_YES" ), + tr( "SMESH_BUT_NO" ), 1, 0, 0 )); + if ( editSubmesh ) + { + selectionMgr()->clearFilters(); + selectObject( pSubmesh ); + SMESHGUI::GetSMESHGUI()->switchToOperation(704); + return; + } + else + { + selectObject( _PTR(SObject)() ); + myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" ); + } + } + + // enable/disable popup for choice of geom selection way + bool enable = false; + QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh ); + if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) { + SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface( pMesh ); + if ( !mesh->_is_nil() ) + enable = ( shapeDim > 1 ) && ( mesh->NbEdges() > 0 ); + } + myDlg->setGeomPopupEnabled( enable ); + } } catch ( const SALOME::SALOME_Exception& S_ex ) { @@ -340,7 +488,6 @@ void SMESHGUI_MeshOp::selectionDone() catch ( ... ) { } - myDlg->setMaxHypoDim( shapeDim ); } //================================================================================ @@ -371,6 +518,20 @@ bool SMESHGUI_MeshOp::isValid( QString& theMess ) const return false; } + // Imported mesh, if create sub-mesh or edit mesh + if ( !myToCreate || ( myToCreate && !myIsMesh )) + { + QString aMeshEntry = myDlg->selectedObject + ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj ); + if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) { + SMESH::SMESH_Mesh_var mesh = SMESH::SObjectToInterface( pMesh ); + if ( !mesh->_is_nil() && CORBA::is_nil( mesh->GetShapeToMesh() )) { + theMess = tr( "IMPORTED_MESH" ); + return false; + } + } + } + // Geom if ( myToCreate ) { @@ -402,8 +563,14 @@ bool SMESHGUI_MeshOp::isValid( QString& theMess ) const theMess = tr( "MESH_IS_NULL" ); return false; } + if ( !isSubshapeOk() ) + { + theMess = tr( "INVALID_SUBSHAPE" ); + return false; + } } } + return true; } @@ -468,9 +635,9 @@ void SMESHGUI_MeshOp::existingHyps( const int theDim, bool isMesh = !_CAST( SComponent, theFather ); int aPart = -1; if ( isMesh ) - aPart = theHypType == Algo ? 3 : 2; + aPart = theHypType == Algo ? GLOBAL_ALGO_TAG : GLOBAL_HYPO_TAG; else - aPart = theHypType == Algo ? 2 : 1; + aPart = theHypType == Algo ? LOCAL_ALGO_TAG : LOCAL_HYPO_TAG; if ( theFather->FindSubObject( aPart, aHypRoot ) ) { @@ -511,6 +678,66 @@ void SMESHGUI_MeshOp::existingHyps( const int theDim, } } +//================================================================================ +/*! + * \brief If create or edit a submesh, return a hypothesis holding parameters used + * to mesh a subshape + * \param aHypType - The hypothesis type name + * \param aServerLib - Server library name + * \param hypData - The structure holding the hypothesis type etc. + * \retval SMESH::SMESH_Hypothesis_var - the hypothesis holding parameter values + */ +//================================================================================ + +SMESH::SMESH_Hypothesis_var +SMESHGUI_MeshOp::getInitParamsHypothesis( const QString& aHypType, + const QString& aServerLib ) const +{ + if ( aHypType.isEmpty() || aServerLib.isEmpty() ) + return SMESH::SMESH_Hypothesis::_nil(); + + const int nbColonsInMeshEntry = 3; + bool isSubMesh = myToCreate ? + !myIsMesh : + myDlg->selectedObject( SMESHGUI_MeshDlg::Obj ).contains(':') > nbColonsInMeshEntry; + + if ( isSubMesh ) + { + // get mesh and geom object + SMESH::SMESH_Mesh_var aMeshVar = SMESH::SMESH_Mesh::_nil(); + GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil(); + + QString anEntry = myDlg->selectedObject + ( myToCreate ? SMESHGUI_MeshDlg::Mesh : SMESHGUI_MeshDlg::Obj ); + if ( _PTR(SObject) pObj = studyDS()->FindObjectID( anEntry.latin1() )) + { + CORBA::Object_ptr Obj = _CAST( SObject,pObj )->GetObject(); + if ( myToCreate ) // mesh and geom may be selected + { + aMeshVar = SMESH::SMESH_Mesh::_narrow( Obj ); + anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom ); + if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.latin1() )) + aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() ); + } + else // edition: sub-mesh may be selected + { + SMESH::SMESH_subMesh_var sm = SMESH::SMESH_subMesh::_narrow( Obj ); + if ( !sm->_is_nil() ) { + aMeshVar = sm->GetFather(); + aGeomVar = sm->GetSubShape(); + } + } + } + + if ( !aMeshVar->_is_nil() && !aGeomVar->_is_nil() ) + return SMESHGUI::GetSMESHGen()->GetHypothesisParameterValues( aHypType, + aServerLib, + aMeshVar, + aGeomVar ); + } + return SMESH::SMESH_Hypothesis::_nil(); +} + //================================================================================ /*! * \brief Calls plugin methods for hypothesis creation @@ -560,8 +787,22 @@ void SMESHGUI_MeshOp::onCreateHyp( const int theHypType, const int theIndex ) SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHypTypeName ); // Create hypothesis - if( aCreator ) - aCreator->create( false, myDlg ); + if ( aCreator ) + { + // When create or edit a submesh, try to initialize a new hypothesis + // with values used to mesh a subshape + SMESH::SMESH_Hypothesis_var initParamHyp = + getInitParamsHypothesis( aHypTypeName, aData->ServerLibName ); + + if ( initParamHyp->_is_nil() ) + aCreator->create( false, myDlg ); + else + aCreator->create( initParamHyp, myDlg ); + } + else + { + SMESH::CreateHypothesis( aHypTypeName, aData->Label, false ); + } } QStringList aNewHyps; @@ -650,18 +891,18 @@ void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName ) { // try to find an existing hypo QValueList & aList = myExistingHyps[ aDim ][ aHypType ]; - int iHyp = 0, nbHyp = aList.count(); - for ( ; iHyp < nbHyp; ++iHyp ) - { - SMESH::SMESH_Hypothesis_var aHyp = aList[ iHyp ]; - if ( !aHyp->_is_nil() && aHypoTypeName == aHyp->GetName() ) { - index = iHyp; - break; - } - } + int /*iHyp = 0,*/ nbHyp = aList.count(); +// for ( ; iHyp < nbHyp; ++iHyp ) +// { +// SMESH::SMESH_Hypothesis_var aHyp = aList[ iHyp ]; +// if ( !aHyp->_is_nil() && aHypoTypeName == aHyp->GetName() ) { +// index = iHyp; +// break; +// } +// } if ( index >= 0 ) // found { - // select an algorithm + // select the found hypothesis setCurrentHyp ( aDim, aHypType, index ); } else @@ -676,7 +917,18 @@ void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName ) // Get hypotheses creator client (GUI) SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator( aHypoTypeName ); - aCreator->create( false, myDlg ); + if ( aCreator ) + { + // When create or edit a submesh, try to initialize a new hypothesis + // with values used to mesh a subshape + SMESH::SMESH_Hypothesis_var initParamHyp = + getInitParamsHypothesis( aHypoTypeName, aHypData->ServerLibName ); + aCreator->create( initParamHyp, myDlg ); + } + else + { + SMESH::CreateHypothesis( aHypoTypeName, aHypData->Label, isAlgo ); + } } QStringList aNewHyps; _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" ); @@ -1203,3 +1455,103 @@ bool SMESHGUI_MeshOp::isValid( SUIT_Operation* theOp ) const { return SMESHGUI_Operation::isValid( theOp ) && !theOp->inherits( "SMESHGUI_MeshOp" ); } + +//================================================================================ +/*! + * \brief SLOT. Is called when the user selects a way of geometry selection + * \param theByMesh - true if the user wants to find geometry by mesh element + */ +//================================================================================ + +void SMESHGUI_MeshOp::onGeomSelectionByMesh( bool theByMesh ) +{ + if ( theByMesh ) { + if ( !myShapeByMeshDlg ) { + myShapeByMeshDlg = new SMESHGUI_ShapeByMeshDlg( SMESHGUI::GetSMESHGUI(), "ShapeByMeshDlg"); + connect(myShapeByMeshDlg, SIGNAL(PublishShape()), SLOT(onPublishShapeByMeshDlg())); + connect(myShapeByMeshDlg, SIGNAL(Close()), SLOT(onCloseShapeByMeshDlg())); + } + // set mesh object to dlg + QString aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh ); + if ( _PTR(SObject) pMesh = studyDS()->FindObjectID( aMeshEntry.latin1() )) { + SMESH::SMESH_Mesh_var aMeshVar = + SMESH::SMESH_Mesh::_narrow( _CAST( SObject,pMesh )->GetObject() ); + if ( !aMeshVar->_is_nil() ) { + myDlg->hide(); + myDlg->activateObject( SMESHGUI_MeshDlg::Mesh ); + myShapeByMeshDlg->Init(); + myShapeByMeshDlg->SetMesh( aMeshVar ); + myShapeByMeshDlg->show(); + } + } + } +} + +//================================================================================ +/*! + * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg + */ +//================================================================================ + +void SMESHGUI_MeshOp::onPublishShapeByMeshDlg() +{ + if ( myShapeByMeshDlg ) { + // Select a found geometry object + GEOM::GEOM_Object_var aGeomVar = myShapeByMeshDlg->GetShape(); + if ( !aGeomVar->_is_nil() ) + { + QString ID = aGeomVar->GetStudyEntry(); + if ( _PTR(SObject) aGeomSO = studyDS()->FindObjectID( ID )) { + SMESH::SMESH_Mesh_ptr aMeshPtr = myShapeByMeshDlg->GetMesh(); + if ( !CORBA::is_nil( aMeshPtr )) { + if (_PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshPtr )) { + myDlg->activateObject( SMESHGUI_MeshDlg::Mesh ); + myDlg->selectObject( aMeshSO->GetName(), SMESHGUI_MeshDlg::Mesh, aMeshSO->GetID() ); + } + } + myDlg->activateObject( SMESHGUI_MeshDlg::Geom ); + selectObject( aGeomSO ); + //selectionDone(); + } + } + else { + onCloseShapeByMeshDlg(); + } + } + myDlg->show(); +} + +//================================================================================ +/*! + * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg + */ +//================================================================================ + +void SMESHGUI_MeshOp::onCloseShapeByMeshDlg() +{ + if ( myDlg ) { + myDlg->show(); + myDlg->activateObject( SMESHGUI_MeshDlg::Geom ); + myDlg->selectObject( "", SMESHGUI_MeshDlg::Geom, "" ); + } +} + +//================================================================================ +/*! + * \brief Selects a SObject + * \param theSObj - the SObject to select + */ +//================================================================================ + +void SMESHGUI_MeshOp::selectObject( _PTR(SObject) theSObj ) const +{ + if ( LightApp_SelectionMgr* sm = selectionMgr() ) { + SALOME_ListIO anIOList; + if ( theSObj ) { + Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject + ( theSObj->GetID().c_str(), "SMESH", theSObj->GetName().c_str() ); + anIOList.Append( anIO ); + } + sm->setSelectedObjects( anIOList, false ); + } +} diff --git a/src/SMESHGUI/SMESHGUI_MeshOp.h b/src/SMESHGUI/SMESHGUI_MeshOp.h index 5041fcecb..677731a3b 100644 --- a/src/SMESHGUI/SMESHGUI_MeshOp.h +++ b/src/SMESHGUI/SMESHGUI_MeshOp.h @@ -40,9 +40,7 @@ #include CORBA_SERVER_HEADER(SMESH_Mesh) class SMESHGUI_MeshDlg; -class SMESH_TypeFilter; -class SMESH_NumberFilter; - +class SMESHGUI_ShapeByMeshDlg; /*! * \brief Operation for mech creation or editing @@ -72,6 +70,9 @@ protected slots: void onCreateHyp( const int theHypType, const int theIndex ); void onEditHyp( const int theHypType, const int theIndex ); void onHypoSet( const QString& theSetName ); + void onGeomSelectionByMesh( bool ); + void onPublishShapeByMeshDlg(); + void onCloseShapeByMeshDlg(); private: bool isValid( QString& ) const; @@ -97,12 +98,18 @@ private: QString name( _PTR(SObject) ) const; int find( const SMESH::SMESH_Hypothesis_var&, const QValueList& ) const; + SMESH::SMESH_Hypothesis_var getInitParamsHypothesis( const QString& aHypType, + const QString& aServerLib ) const; + bool isSubshapeOk() const; + _PTR(SObject) getSubmeshByGeom() const; + void selectObject( _PTR(SObject) ) const; private: typedef QMap< int, QValueList > IdToHypListMap; typedef QMap< int, IdToHypListMap > DimToHypMap; SMESHGUI_MeshDlg* myDlg; + SMESHGUI_ShapeByMeshDlg* myShapeByMeshDlg; bool myToCreate; bool myIsMesh; diff --git a/src/SMESHGUI/SMESHGUI_MeshPatternDlg.cxx b/src/SMESHGUI/SMESHGUI_MeshPatternDlg.cxx index 205b5b346..c7ceb4bb9 100755 --- a/src/SMESHGUI/SMESHGUI_MeshPatternDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_MeshPatternDlg.cxx @@ -91,6 +91,7 @@ #include #include #include +#include #define SPACING 5 #define MARGIN 10 diff --git a/src/SMESHGUI/SMESHGUI_MoveNodesDlg.cxx b/src/SMESHGUI/SMESHGUI_MoveNodesDlg.cxx index 1cb0413fb..1f8dbe539 100644 --- a/src/SMESHGUI/SMESHGUI_MoveNodesDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_MoveNodesDlg.cxx @@ -63,6 +63,7 @@ #include #include #include +#include // QT includes #include diff --git a/src/SMESHGUI/SMESHGUI_MultiEditDlg.cxx b/src/SMESHGUI/SMESHGUI_MultiEditDlg.cxx index 6a70e8d5e..74ad155bd 100755 --- a/src/SMESHGUI/SMESHGUI_MultiEditDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_MultiEditDlg.cxx @@ -51,7 +51,6 @@ #include "SVTK_Selector.h" #include "SVTK_ViewModel.h" #include "SVTK_ViewWindow.h" -#include "SVTK_InteractorStyle.h" // OCCT Includes #include @@ -71,6 +70,7 @@ #include #include #include +#include // QT Includes #include @@ -504,8 +504,8 @@ void SMESHGUI_MultiEditDlg::onSelectionDone() myActor = SMESH::FindActorByEntry(aList.First()->getEntry()); if (!myActor) myActor = SMESH::FindActorByObject(myMesh); - SVTK_InteractorStyle* aStyle = SMESH::GetInteractorStyle(); - Handle(VTKViewer_Filter) aFilter = aStyle->GetFilter(myFilterType); + SVTK_Selector* aSelector = SMESH::GetSelector(); + Handle(VTKViewer_Filter) aFilter = aSelector->GetFilter(myFilterType); if (!aFilter.IsNull()) aFilter->SetActor(myActor); } @@ -605,9 +605,9 @@ void SMESHGUI_MultiEditDlg::onFilterAccepted() //======================================================================= bool SMESHGUI_MultiEditDlg::isIdValid (const int theId) const { - SVTK_InteractorStyle* aStyle = SMESH::GetInteractorStyle(); + SVTK_Selector* aSelector = SMESH::GetSelector(); Handle(SMESHGUI_Filter) aFilter = - Handle(SMESHGUI_Filter)::DownCast(aStyle->GetFilter(myFilterType)); + Handle(SMESHGUI_Filter)::DownCast(aSelector->GetFilter(myFilterType)); return (!aFilter.IsNull() && aFilter->IsObjValid(theId)); } diff --git a/src/SMESHGUI/SMESHGUI_NodesDlg.cxx b/src/SMESHGUI/SMESHGUI_NodesDlg.cxx index 55b31e524..0e29413e7 100644 --- a/src/SMESHGUI/SMESHGUI_NodesDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_NodesDlg.cxx @@ -69,6 +69,7 @@ #include #include #include +#include // QT Includes #include diff --git a/src/SMESHGUI/SMESHGUI_RemoveElementsDlg.cxx b/src/SMESHGUI/SMESHGUI_RemoveElementsDlg.cxx index 8bd1824a2..ef6dfa0d2 100644 --- a/src/SMESHGUI/SMESHGUI_RemoveElementsDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_RemoveElementsDlg.cxx @@ -45,6 +45,7 @@ #include "SVTK_ViewWindow.h" #include "SALOME_ListIO.hxx" +#include "SalomeApp_Tools.h" #include "utilities.h" // OCCT Includes @@ -257,11 +258,16 @@ void SMESHGUI_RemoveElementsDlg::ClickOnApply() try { SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor(); aResult = aMeshEditor->RemoveElements(anArrayOfIdeces.inout()); - } catch (...) { + } catch (const SALOME::SALOME_Exception& S_ex) { + SalomeApp_Tools::QtCatchCorbaException(S_ex); + myEditCurrentArgument->clear(); + } catch (...){ + myEditCurrentArgument->clear(); } if (aResult) { myEditCurrentArgument->clear(); + mySelector->ClearIndex(); SMESH::UpdateView(); } } diff --git a/src/SMESHGUI/SMESHGUI_RemoveNodesDlg.cxx b/src/SMESHGUI/SMESHGUI_RemoveNodesDlg.cxx index be9e9e38a..775bff01a 100644 --- a/src/SMESHGUI/SMESHGUI_RemoveNodesDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_RemoveNodesDlg.cxx @@ -265,6 +265,7 @@ void SMESHGUI_RemoveNodesDlg::ClickOnApply() if (aResult) { myEditCurrentArgument->clear(); + mySelector->ClearIndex(); SMESH::UpdateView(); } diff --git a/src/SMESHGUI/SMESHGUI_Selection.cxx b/src/SMESHGUI/SMESHGUI_Selection.cxx index 927ac7f16..88d44c541 100644 --- a/src/SMESHGUI/SMESHGUI_Selection.cxx +++ b/src/SMESHGUI/SMESHGUI_Selection.cxx @@ -327,8 +327,8 @@ QVariant SMESHGUI_Selection::isVisible( int ind ) const QString ent = entry( ind ); SMESH_Actor* actor = SMESH::FindActorByEntry( ent.latin1() ); if ( actor && actor->hasIO() ) { - SVTK_RenderWindowInteractor* renderInter = SMESH::GetCurrentVtkView()->getRWInteractor(); - return QVariant( renderInter->isVisible( actor->getIO() ), 0 ); + if(SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView()) + return QVariant( aViewWindow->isVisible( actor->getIO() ), 0 ); } } return QVariant( false, 0 ); diff --git a/src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.cxx b/src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.cxx new file mode 100644 index 000000000..d437ee1ef --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.cxx @@ -0,0 +1,490 @@ +// SMESH SMESHGUI : GUI for SMESH component +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SMESHGUI_ShapeByMeshDlg.cxx +// Author : Edward AGAPOV +// Module : SMESH + +#include "SMESHGUI_ShapeByMeshDlg.h" + +#include "SMESHGUI.h" +#include "SMESHGUI_GEOMGenUtils.h" +#include "SMESHGUI_IdValidator.h" +#include "SMESHGUI_MeshUtils.h" +#include "SMESHGUI_Utils.h" +#include "SMESHGUI_VTKUtils.h" + +#include "SMDS_Mesh.hxx" +#include "SMDS_MeshNode.hxx" +#include "SMESH_Actor.h" + +#include "GEOMBase.h" +#include "GeometryGUI.h" + +#include "LightApp_DataOwner.h" +#include "LightApp_SelectionMgr.h" +#include "SALOMEDSClient_SObject.hxx" +#include "SALOME_ListIO.hxx" +#include "SUIT_Desktop.h" +#include "SVTK_Selector.h" +#include "SVTK_ViewWindow.h" +#include "SVTK_ViewModel.h" +#include "SalomeApp_Tools.h" + +// OCCT Includes +#include +#include +#include + +// QT Includes +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SPACING 5 +#define MARGIN 10 + +enum { EDGE = 0, FACE, VOLUME }; + +/*! + * \brief Dialog to publish a sub-shape of the mesh main shape + * by selecting mesh elements + */ +SMESHGUI_ShapeByMeshDlg::SMESHGUI_ShapeByMeshDlg( SMESHGUI* theModule, + const char* theName) + : QDialog( SMESH::GetDesktop( theModule ), theName, false, + WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu), + mySMESHGUI( theModule ), + mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ) +{ + setCaption(tr("CAPTION")); + + QVBoxLayout* aDlgLay = new QVBoxLayout (this, MARGIN, SPACING); + + QFrame* aMainFrame = createMainFrame (this); + QFrame* aBtnFrame = createButtonFrame(this); + + aDlgLay->addWidget(aMainFrame); + aDlgLay->addWidget(aBtnFrame); + + aDlgLay->setStretchFactor(aMainFrame, 1); + + myViewWindow = SMESH::GetViewWindow( mySMESHGUI ); + + Init(); +} + +//======================================================================= +// function : createMainFrame() +// purpose : Create frame containing dialog's input fields +//======================================================================= +QFrame* SMESHGUI_ShapeByMeshDlg::createMainFrame (QWidget* theParent) +{ + QFrame* aMainGrp = new QFrame(theParent, "main frame"); + QGridLayout* aLayout = new QGridLayout(aMainGrp, 3, 2); + aLayout->setSpacing(6); + aLayout->setAutoAdd(false); + + // elem type + myElemTypeGroup = new QButtonGroup(1, Qt::Vertical, aMainGrp, "Group types"); + myElemTypeGroup->setTitle(tr("SMESH_ELEMENT_TYPE")); + myElemTypeGroup->setExclusive(true); + + (new QRadioButton( tr("SMESH_EDGE") , myElemTypeGroup))->setChecked(true); + new QRadioButton( tr("SMESH_FACE") , myElemTypeGroup); + new QRadioButton( tr("SMESH_VOLUME"), myElemTypeGroup); + + // element id + QLabel* anIdLabel = new QLabel( aMainGrp, "element id label"); + anIdLabel->setText( tr("ELEMENT_ID") ); + myElementId = new QLineEdit( aMainGrp, "element id"); + myElementId->setValidator( new SMESHGUI_IdValidator( theParent, "id validator", 1 )); + + // shape name + QLabel* aNameLabel = new QLabel( aMainGrp, "geom name label"); + aNameLabel->setText( tr("GEOMETRY_NAME") ); + myGeomName = new QLineEdit( aMainGrp, "geom name"); + + aLayout->addMultiCellWidget(myElemTypeGroup, 0, 0, 0, 1); + aLayout->addWidget(anIdLabel, 1, 0); + aLayout->addWidget(myElementId, 1, 1); + aLayout->addWidget(aNameLabel, 2, 0); + aLayout->addWidget(myGeomName, 2, 1); + + connect(myElemTypeGroup, SIGNAL(clicked(int)), SLOT(onTypeChanged(int))); + connect(myElementId, SIGNAL(textChanged(const QString&)), SLOT(onElemIdChanged(const QString&))); + + return aMainGrp; +} + +//======================================================================= +// function : createButtonFrame() +// purpose : Create frame containing buttons +//======================================================================= +QFrame* SMESHGUI_ShapeByMeshDlg::createButtonFrame (QWidget* theParent) +{ + QFrame* aFrame = new QFrame(theParent); + aFrame->setFrameStyle(QFrame::Box | QFrame::Sunken); + + myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), aFrame); + myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame); + + QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); + + QHBoxLayout* aLay = new QHBoxLayout(aFrame, MARGIN, SPACING); + + aLay->addWidget(myOkBtn); + aLay->addItem(aSpacer); + aLay->addWidget(myCloseBtn); + + connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk())); + connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose())); + + return aFrame; +} + +//======================================================================= +// function : ~SMESHGUI_ShapeByMeshDlg() +// purpose : Destructor +//======================================================================= +SMESHGUI_ShapeByMeshDlg::~SMESHGUI_ShapeByMeshDlg() +{ + // no need to delete child widgets, Qt does it all for us +} + +//======================================================================= +// function : Init() +// purpose : Init dialog fields, connect signals and slots, show dialog +//======================================================================= +void SMESHGUI_ShapeByMeshDlg::Init() +{ + SetMesh( SMESH::SMESH_Mesh::_nil() ); + myIsManualIdEnter = false; + + //erasePreview(); + + mySMESHGUI->SetActiveDialogBox((QDialog*)this); + + // selection and SMESHGUI + connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate())); + connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose())); + + setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); + qApp->processEvents(); + updateGeometry(); + adjustSize(); + resize(minimumSize()); + + activateSelection(); + onSelectionDone(); + + int x, y; + mySMESHGUI->DefineDlgPosition(this, x, y); + this->move(x, y); + this->show(); +} + +//======================================================================= +// function : SetMesh() +// purpose : Set mesh to dialog +//======================================================================= + +void SMESHGUI_ShapeByMeshDlg::SetMesh (SMESH::SMESH_Mesh_ptr thePtr) +{ + myMesh = SMESH::SMESH_Mesh::_duplicate(thePtr); + myGeomObj = GEOM::GEOM_Object::_nil(); + myHasSolids = false; + + vector< bool > hasElement (myElemTypeGroup->count(), false); + if (!myMesh->_is_nil() && myViewWindow ) + { + _PTR(SObject) aSobj = SMESH::FindSObject(myMesh.in()); + SUIT_DataOwnerPtr anIObj (new LightApp_DataOwner(aSobj->GetID().c_str())); + + vector< int > nbShapes( TopAbs_SHAPE, 0 ); + int shapeDim = 0; // max dim with several shapes + if ( mySelectionMgr->isOk(anIObj) ) // check that the mesh has a valid shape + { + _PTR(SObject) aSO = SMESH::FindSObject(myMesh.in()); + GEOM::GEOM_Object_var mainShape = SMESH::GetGeom(aSO); + if ( !mainShape->_is_nil() ) + { + if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists + GeometryGUI::InitGeomGen(); + TopoDS_Shape aShape; + if ( GEOMBase::GetShape(mainShape, aShape)) + { + TopAbs_ShapeEnum types[4] = { TopAbs_EDGE, TopAbs_FACE, TopAbs_SHELL, TopAbs_SOLID }; + for ( int dim = 4; dim > 0; --dim ) { + TopAbs_ShapeEnum type = types[ dim - 1 ]; + TopAbs_ShapeEnum avoid = ( type == TopAbs_SHELL ) ? TopAbs_SOLID : TopAbs_SHAPE; + TopExp_Explorer exp( aShape, type, avoid ); + for ( ; nbShapes[ type ] < 2 && exp.More(); exp.Next() ) + ++nbShapes[ type ]; + if ( nbShapes[ type ] > 1 ) { + shapeDim = dim; + break; + } + } + } + } + } + if (shapeDim > 0) + { + if ( nbShapes[ TopAbs_SHELL ] + nbShapes[ TopAbs_SOLID ] > 1 ) + shapeDim = 3; + hasElement[ EDGE ] = shapeDim > 0 && myMesh->NbEdges() ; + hasElement[ FACE ] = shapeDim > 1 && myMesh->NbFaces() ; + hasElement[ VOLUME ] = shapeDim > 2 && myMesh->NbVolumes(); + + if ( hasElement[ EDGE ] && myViewWindow->GetSelector() ) + { + connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone())); + } + } + myHasSolids = nbShapes[ TopAbs_SOLID ]; + } + + // disable inexistant elem types + for ( int i = 0; i < myElemTypeGroup->count(); ++i ) { + if ( QButton* button = myElemTypeGroup->find( i ) ) + button->setEnabled( hasElement[ i ] ); + } + myElementId->setEnabled( hasElement[ EDGE ] ); + myGeomName-> setEnabled( hasElement[ EDGE ] ); + + setElementID(""); +} + +//======================================================================= +// function : GetShape() +// purpose : Get published sub-shape +//======================================================================= +GEOM::GEOM_Object_ptr SMESHGUI_ShapeByMeshDlg::GetShape() +{ + return myGeomObj.in(); +} + +//======================================================================= +// function : onOk() +// purpose : SLOT called when "Ok" button pressed. +//======================================================================= +void SMESHGUI_ShapeByMeshDlg::onOk() +{ + try { + int elemID = myElementId->text().toInt(); + myGeomObj = SMESHGUI::GetSMESHGen()->GetGeometryByMeshElement + ( myMesh.in(), elemID, myGeomName->text().latin1()); + + accept(); + emit PublishShape(); + } + catch (const SALOME::SALOME_Exception& S_ex) { + SalomeApp_Tools::QtCatchCorbaException(S_ex); + } + catch (...) { + } + myViewWindow->SetSelectionMode( ActorSelection ); + disconnect(mySelectionMgr, 0, this, 0); + disconnect(mySMESHGUI, 0, this, 0); + mySMESHGUI->ResetState(); +} + +//======================================================================= +// function : onClose() +// purpose : SLOT called when "Close" button pressed. Close dialog +//======================================================================= +void SMESHGUI_ShapeByMeshDlg::onClose() +{ + myViewWindow->SetSelectionMode( ActorSelection ); + disconnect(mySelectionMgr, 0, this, 0); + disconnect(mySMESHGUI, 0, this, 0); + mySMESHGUI->ResetState(); + reject(); + emit Close(); +} + +//======================================================================= +// function : onSelectionDone() +// purpose : SLOT called when selection changed +//======================================================================= +void SMESHGUI_ShapeByMeshDlg::onSelectionDone() +{ + myOkBtn->setEnabled( false ); + setElementID(""); + + try { + SALOME_ListIO aList; + mySelectionMgr->selectedObjects(aList, SVTK_Viewer::Type()); + if (aList.Extent() != 1) + return; + + SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(aList.First()); + if (aMesh->_is_nil() || myMesh->_is_nil() || aMesh->GetId() != myMesh->GetId() ) + return; + + QString aString; + int nbElems = SMESH::GetNameOfSelectedElements(myViewWindow->GetSelector(), + aList.First(), aString); + if ( nbElems == 1 ) { + setElementID( aString ); + myOkBtn->setEnabled( true ); + } + } catch (...) { + } +} + +//======================================================================= +// function : onDeactivate() +// purpose : SLOT called when dialog must be deativated +//======================================================================= +void SMESHGUI_ShapeByMeshDlg::onDeactivate() +{ + if ( isEnabled() ) { + //disconnect(mySelectionMgr, 0, this, 0); + myViewWindow->SetSelectionMode( ActorSelection ); + setEnabled(false); + } +} + +//======================================================================= +// function : enterEvent() +// purpose : Event filter +//======================================================================= +void SMESHGUI_ShapeByMeshDlg::enterEvent (QEvent*) +{ + // there is a stange problem that enterEvent() comes after onSave() + if ( isVisible () && !isEnabled() ) { + mySMESHGUI->EmitSignalDeactivateDialog(); + setEnabled(true); + activateSelection(); + //connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone())); + } +} + +//================================================================================= +// function : closeEvent() +// purpose : Close dialog box +//================================================================================= +void SMESHGUI_ShapeByMeshDlg::closeEvent (QCloseEvent*) +{ + onClose(); +} + +//======================================================================= +// function : activateSelection() +// purpose : Activate selection in accordance with current pattern type +//======================================================================= +void SMESHGUI_ShapeByMeshDlg::activateSelection() +{ + mySelectionMgr->clearFilters(); + SMESH::SetPointRepresentation(false); + + myGeomName->setText(""); + + if ( myViewWindow ) + { + QString geomName; + Selection_Mode mode = EdgeSelection; + switch ( myElemTypeGroup->id( myElemTypeGroup->selected() )) { + case EDGE : + mode = EdgeSelection; geomName = tr("GEOM_EDGE"); break; + case FACE : + mode = FaceSelection; geomName = tr("GEOM_FACE"); break; + case VOLUME: + mode = VolumeSelection; geomName = tr(myHasSolids ? "GEOM_SOLID" : "GEOM_SHELL"); break; + default: return; + } + if ( myViewWindow->SelectionMode() != mode ) + myViewWindow->SetSelectionMode( mode ); + + myGeomName->setText( GEOMBase::GetDefaultName( geomName )); + } +} + +//======================================================================= +//function : onTypeChanged +//purpose : SLOT. Called when element type changed. +//======================================================================= + +void SMESHGUI_ShapeByMeshDlg::onTypeChanged (int theType) +{ + setElementID(""); + activateSelection(); +} + +//======================================================================= +//function : onTypeChanged +//purpose : SLOT. Called when element id is entered +// Highlight the element whose Ids the user entered manually +//======================================================================= + +void SMESHGUI_ShapeByMeshDlg::onElemIdChanged(const QString& theNewText) +{ + myOkBtn->setEnabled( false ); + + if ( myIsManualIdEnter && !myMesh->_is_nil() && myViewWindow ) + if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) + if ( SMDS_Mesh* aMesh = actor->GetObject()->GetMesh() ) + { + SMDSAbs_ElementType type = SMDSAbs_Edge; + switch ( myElemTypeGroup->id( myElemTypeGroup->selected() )) { + case EDGE : type = SMDSAbs_Edge; break; + case FACE : type = SMDSAbs_Face; break; + case VOLUME: type = SMDSAbs_Volume; break; + default: return; + } + TColStd_MapOfInteger newIndices; + QStringList aListId = QStringList::split( " ", theNewText, false); + for ( int i = 0; i < aListId.count(); i++ ) { + if ( const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() )) + if ( e->GetType() == type ) + newIndices.Add( e->GetID() ); + } + + if ( !newIndices.IsEmpty() && newIndices.Extent() == 1 ) + if ( SVTK_Selector* s = myViewWindow->GetSelector() ) { + s->AddOrRemoveIndex( actor->getIO(), newIndices, false ); + myViewWindow->highlight( actor->getIO(), true, true ); + myOkBtn->setEnabled( true ); + } + } +} + +//======================================================================= +//function : setElementID +//purpose : programmatically set element id +//======================================================================= + +void SMESHGUI_ShapeByMeshDlg::setElementID(const QString& theText) +{ + myIsManualIdEnter = false; + myElementId->setText(theText); + myIsManualIdEnter = true; +} diff --git a/src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.h b/src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.h new file mode 100644 index 000000000..1f1a50c6e --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_ShapeByMeshDlg.h @@ -0,0 +1,115 @@ +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SMESHGUI_ShapeByMeshDlg.h +// Author : Edward AGAPOV +// Module : SMESH + + +#ifndef SMESHGUI_ShapeByMeshDlg_H +#define SMESHGUI_ShapeByMeshDlg_H + +#include + +// IDL Headers +#include +#include CORBA_SERVER_HEADER(GEOM_Gen) +#include CORBA_SERVER_HEADER(SMESH_Mesh) + +class QCloseEvent; +class QFrame; +class QLineEdit; +class QPushButton; +class LightApp_SelectionMgr; +class SVTK_ViewWindow; +class QButtonGroup; +class SMESHGUI; + +/*! + * \brief Dialog to publish a sub-shape of the mesh main shape + * by selecting mesh elements + */ + +class SMESHGUI_ShapeByMeshDlg : public QDialog +{ + Q_OBJECT + +public: + SMESHGUI_ShapeByMeshDlg( SMESHGUI* theModule, + const char* theName = 0); + virtual ~SMESHGUI_ShapeByMeshDlg(); + + void Init(); + void SetMesh (SMESH::SMESH_Mesh_ptr); + SMESH::SMESH_Mesh_ptr GetMesh () { return myMesh; } + GEOM::GEOM_Object_ptr GetShape(); + +signals: + + void PublishShape(); + void Close(); + +private: + + void closeEvent (QCloseEvent* e); + void enterEvent (QEvent*); + +private slots: + + void onOk(); + void onClose(); + + void onDeactivate(); + + void onSelectionDone(); + void onTypeChanged (int); + void onElemIdChanged (const QString&); + +private: + + QFrame* createButtonFrame (QWidget*); + QFrame* createMainFrame (QWidget*); + //void displayPreview(); + //void erasePreview(); + void activateSelection(); + void setElementID(const QString&); + +private: + + QButtonGroup* myElemTypeGroup; + QLineEdit* myElementId; + QLineEdit* myGeomName; + + QPushButton* myOkBtn; + QPushButton* myCloseBtn; + + SMESHGUI* mySMESHGUI; + LightApp_SelectionMgr* mySelectionMgr; + SVTK_ViewWindow* myViewWindow; + + SMESH::SMESH_Mesh_var myMesh; + GEOM::GEOM_Object_var myGeomObj; + + bool myIsManualIdEnter; + bool myHasSolids; +}; + +#endif diff --git a/src/SMESHGUI/SMESHGUI_VTKUtils.cxx b/src/SMESHGUI/SMESHGUI_VTKUtils.cxx index 01cf071d8..76a8cb1a6 100644 --- a/src/SMESHGUI/SMESHGUI_VTKUtils.cxx +++ b/src/SMESHGUI/SMESHGUI_VTKUtils.cxx @@ -36,9 +36,6 @@ #include "SVTK_Selector.h" #include "SVTK_ViewModel.h" #include "SVTK_ViewWindow.h" -#include "SVTK_RenderWindow.h" -#include "SVTK_InteractorStyle.h" -#include "SVTK_RenderWindowInteractor.h" #include "utilities.h" @@ -448,85 +445,83 @@ namespace SMESH{ double SP1 = mgr->doubleValue( "SMESH", "selection_precision_node", 0.025 ), SP2 = mgr->doubleValue( "SMESH", "selection_precision_element", 0.001 ); - for ( int i=0, n=views.count(); igetRWInteractor(); - if (anInteractor) { - // mesh element selection - anInteractor->SetSelectionProp(aSelColor.red()/255., aSelColor.green()/255., - aSelColor.blue()/255., SW ); - - // tolerances - anInteractor->SetSelectionTolerance(SP1, SP2); - - // pre-selection - SVTK_InteractorStyle* aStyle = - dynamic_cast( anInteractor->GetInteractorStyle() ); - if (aStyle) { - aStyle->setPreselectionProp(aPreColor.red()/255., aPreColor.green()/255., - aPreColor.blue()/255., PW); - } - } + for ( int i=0, n=views.count(); iSetSelectionProp(aSelColor.red()/255., + aSelColor.green()/255., + aSelColor.blue()/255., + SW ); + // tolerances + aVtkView->SetSelectionTolerance(SP1, SP2); + + // pre-selection + aVtkView->SetPreselectionProp(aPreColor.red()/255., + aPreColor.green()/255., + aPreColor.blue()/255., + PW); // update actors vtkRenderer* aRenderer = aVtkView->getRenderer(); vtkActorCollection *aCollection = aRenderer->GetActors(); aCollection->InitTraversal(); while(vtkActor *anAct = aCollection->GetNextActor()){ if(SMESH_Actor *anActor = dynamic_cast(anAct)){ - anActor->SetHighlightColor(aHiColor.red()/255., aHiColor.green()/255., + anActor->SetHighlightColor(aHiColor.red()/255., + aHiColor.green()/255., aHiColor.blue()/255.); - anActor->SetPreHighlightColor(aPreColor.red()/255., aPreColor.green()/255., + anActor->SetPreHighlightColor(aPreColor.red()/255., + aPreColor.green()/255., aPreColor.blue()/255.); } } + } } } //---------------------------------------------------------------------------- - SVTK_InteractorStyle* GetInteractorStyle(SUIT_ViewWindow *theWindow){ - if(SVTK_ViewWindow* aWnd = GetVtkViewWindow(theWindow)){ - if(SVTK_RenderWindowInteractor* anInteractor = aWnd->getRWInteractor()){ - return dynamic_cast( anInteractor->GetInteractorStyle() ); - } - } + SVTK_Selector* + GetSelector(SUIT_ViewWindow *theWindow) + { + if(SVTK_ViewWindow* aWnd = GetVtkViewWindow(theWindow)) + return aWnd->GetSelector(); + return NULL; } void SetFilter(const Handle(VTKViewer_Filter)& theFilter, - SVTK_InteractorStyle* theStyle) + SVTK_Selector* theSelector) { - if (theStyle) - theStyle->SetFilter(theFilter); + if (theSelector) + theSelector->SetFilter(theFilter); } - Handle(VTKViewer_Filter) GetFilter(int theId, SVTK_InteractorStyle* theStyle) + Handle(VTKViewer_Filter) GetFilter(int theId, SVTK_Selector* theSelector) { - return theStyle->GetFilter(theId); + return theSelector->GetFilter(theId); } - bool IsFilterPresent(int theId, SVTK_InteractorStyle* theStyle) + bool IsFilterPresent(int theId, SVTK_Selector* theSelector) { - return theStyle->IsFilterPresent(theId); + return theSelector->IsFilterPresent(theId); } - void RemoveFilter(int theId, SVTK_InteractorStyle* theStyle) + void RemoveFilter(int theId, SVTK_Selector* theSelector) { - theStyle->RemoveFilter(theId); + theSelector->RemoveFilter(theId); } - void RemoveFilters(SVTK_InteractorStyle* theStyle) + void RemoveFilters(SVTK_Selector* theSelector) { - for ( int id = SMESHGUI_NodeFilter; theStyle && id < SMESHGUI_LastFilter; id++ ) - theStyle->RemoveFilter( id ); + for ( int id = SMESHGUI_NodeFilter; theSelector && id < SMESHGUI_LastFilter; id++ ) + theSelector->RemoveFilter( id ); } bool IsValid(SALOME_Actor* theActor, int theCellId, - SVTK_InteractorStyle* theStyle) + SVTK_Selector* theSelector) { - return theStyle->IsValid(theActor,theCellId); + return theSelector->IsValid(theActor,theCellId); } diff --git a/src/SMESHGUI/SMESHGUI_VTKUtils.h b/src/SMESHGUI/SMESHGUI_VTKUtils.h index 53754a313..6b64521f0 100644 --- a/src/SMESHGUI/SMESHGUI_VTKUtils.h +++ b/src/SMESHGUI/SMESHGUI_VTKUtils.h @@ -34,7 +34,6 @@ class SUIT_Study; class SUIT_ViewWindow; class SUIT_ViewManager; -class SVTK_InteractorStyle; class SVTK_ViewWindow; class SVTK_Selector; @@ -119,25 +118,25 @@ namespace SMESH{ //---------------------------------------------------------------------------- - SVTK_InteractorStyle* - GetInteractorStyle (SUIT_ViewWindow* = GetActiveWindow()); + SVTK_Selector* + GetSelector(SUIT_ViewWindow* = GetActiveWindow()); void SetFilter (const Handle(VTKViewer_Filter)& theFilter, - SVTK_InteractorStyle* theStyle = GetInteractorStyle()); + SVTK_Selector* theSelector = GetSelector()); Handle(VTKViewer_Filter) - GetFilter (int theId, SVTK_InteractorStyle* theStyle = GetInteractorStyle()); + GetFilter (int theId, SVTK_Selector* theSelector = GetSelector()); bool IsFilterPresent (int theId, - SVTK_InteractorStyle* theStyle = GetInteractorStyle()); + SVTK_Selector* theSelector = GetSelector()); void RemoveFilter (int theId, - SVTK_InteractorStyle* theStyle = GetInteractorStyle()); + SVTK_Selector* theSelector = GetSelector()); - void RemoveFilters (SVTK_InteractorStyle* theStyle = GetInteractorStyle()); + void RemoveFilters (SVTK_Selector* theSelector = GetSelector()); bool IsValid (SALOME_Actor* theActor, int theCellId, - SVTK_InteractorStyle* theStyle = GetInteractorStyle()); + SVTK_Selector* theSelector = GetSelector()); //---------------------------------------------------------------------------- int GetNameOfSelectedNodes(SVTK_Selector* theSelector, diff --git a/src/SMESHGUI/SMESH_msg_en.po b/src/SMESHGUI/SMESH_msg_en.po index 073353aca..b0c73c29e 100644 --- a/src/SMESHGUI/SMESH_msg_en.po +++ b/src/SMESHGUI/SMESH_msg_en.po @@ -1,3 +1,18 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR Free Software Foundation, Inc. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"PO-Revision-Date: 2006-01-13 13:50+0300\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + # This is a Qt message file in .po format. Each msgid starts with # a scope. This scope should *NOT* be translated - eg. "Foo::Bar" # would be translated to "Pub", not "Foo::Pub". @@ -615,6 +630,10 @@ msgid "SMESH_UPDATEVIEW" msgstr "Update View" +#Warning incorrect values +msgid "SMESH_ERR_SCALARBAR_PARAMS" +msgstr "Warning! The parameters is incorrect" + # -------------- Connectivity -------------- #Boundary Edges @@ -2893,6 +2912,26 @@ msgstr "Assign a set of hypotheses" #----------------------------------------------------------- +msgid "SMESHGUI_ShapeByMeshDlg::CAPTION" +msgstr "Find geometry by mesh element" + +msgid "SMESH_ELEMENT_TYPE" +msgstr "Element Type" + +msgid "ELEMENT_ID" +msgstr "Element ID" + +msgid "GEOMETRY_NAME" +msgstr "Geometry name" + +msgid "DIRECT_GEOM_SELECTION" +msgstr "Direct geometry selection" + +msgid "GEOM_BY_MESH_ELEM_SELECTION" +msgstr "Find geometry by mesh element selection" + +#----------------------------------------------------------- + msgid "SMESHGUI_MeshTab::ALGORITHM" msgstr "Algorithm" @@ -2931,9 +2970,17 @@ msgstr "Geometry object is not defined\nPlease specify it and try again" msgid "SMESHGUI_MeshOp::THERE_IS_NO_OBJECT_FOR_EDITING" msgstr "There is no object for editing. Please\nselect mesh or sub-mesh and try again" +msgid "SMESHGUI_MeshOp::EDIT_SUBMESH_QUESTION" +msgstr "A submesh on the selected geometry already exists.\n Do you want to edit this submesh?" + msgid "SMESHGUI_MeshOp::MESH_IS_NULL" msgstr "Mesh is null" +msgid "SMESHGUI_MeshOp::IMPORTED_MESH" +msgstr "Mesh is not built on geometry" + +msgid "SMESHGUI_MeshOp::INVALID_SUBSHAPE" +msgstr "Geometry object is not a subshape of the shape to mesh" + msgid "SMESHGUI_MeshOp::MESH_IS_NOT_DEFINED" msgstr "Mesh is not defined\nPlease specify it and try again" - diff --git a/src/SMESH_I/Makefile.in b/src/SMESH_I/Makefile.in index 5ea16f7fc..179743728 100644 --- a/src/SMESH_I/Makefile.in +++ b/src/SMESH_I/Makefile.in @@ -96,7 +96,7 @@ LDFLAGS+= -L${KERNEL_ROOT_DIR}/lib/salome -lSalomeContainer -lSalomeNS -lRegistr LDFLAGSFORBIN += -lSMDS -lSMESHDS \ - -L${MED_ROOT_DIR}/lib/salome -lMEDWrapper -lMEDWrapperBase -lMEDWrapper_V2_1 -lMEDWrapper_V2_2 \ + -L${MED_ROOT_DIR}/lib/salome -lMEDWrapper -lMEDWrapperBase -lMEDWrapper_V2_1 -lMEDWrapper_V2_2 -lmed_V2_1 \ -lMeshDriver -lMeshDriverMED -lMeshDriverUNV -lMeshDriverDAT -lMeshDriverSTL \ -L${KERNEL_ROOT_DIR}/lib/salome -lSalomeContainer -lSalomeNS -lRegistry -lSalomeResourcesManager \ -lOpUtil -lSALOMELocalTrace -lSALOMEBasics -lSalomeNotification -lCASCatch \ diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index f4999c97f..79f87e116 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -41,6 +41,8 @@ #include #include #include +#include +#include #include #include #include @@ -64,7 +66,10 @@ #include "SMESHDS_Document.hxx" #include "SMESHDS_Group.hxx" #include "SMESHDS_GroupOnGeom.hxx" +#include "SMESH_Mesh.hxx" +#include "SMESH_Hypothesis.hxx" #include "SMESH_Group.hxx" +#include "SMESH_MeshEditor.hxx" #include "SMDS_EdgePosition.hxx" #include "SMDS_FacePosition.hxx" @@ -490,6 +495,84 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypNam return hyp._retn(); } +//================================================================================ +/*! + * \brief Return hypothesis of given type holding parameter values of the existing mesh + * \param theHypType - hypothesis type name + * \param theLibName - plugin library name + * \param theMesh - The mesh of interest + * \param theGeom - The shape to get parameter values from + * \retval SMESH::SMESH_Hypothesis_ptr - The returned hypothesis may be the one existing + * in a study and used to compute the mesh, or a temporary one created just to pass + * parameter values + */ +//================================================================================ + +SMESH::SMESH_Hypothesis_ptr +SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType, + const char* theLibName, + SMESH::SMESH_Mesh_ptr theMesh, + GEOM::GEOM_Object_ptr theGeom) + throw ( SALOME::SALOME_Exception ) +{ + Unexpect aCatch(SALOME_SalomeException); + if ( CORBA::is_nil( theMesh ) ) + THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM ); + if ( CORBA::is_nil( theGeom ) ) + THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM ); + + // ----------------------------------------------- + // find hypothesis used to mesh theGeom + // ----------------------------------------------- + + // get mesh and shape + SMESH_Mesh_i* meshServant = SMESH::DownCast( theMesh ); + TopoDS_Shape shape = GeomObjectToShape( theGeom ); + if ( !meshServant || shape.IsNull() ) + return SMESH::SMESH_Hypothesis::_nil(); + ::SMESH_Mesh& mesh = meshServant->GetImpl(); + + if ( mesh.NbNodes() == 0 ) // empty mesh + return SMESH::SMESH_Hypothesis::_nil(); + + // create a temporary hypothesis to know its dimention + SMESH::SMESH_Hypothesis_var tmpHyp = this->createHypothesis( theHypType, theLibName ); + SMESH_Hypothesis_i* hypServant = SMESH::DownCast( tmpHyp ); + if ( !hypServant ) + return SMESH::SMESH_Hypothesis::_nil(); + ::SMESH_Hypothesis* hyp = hypServant->GetImpl(); + + // look for a hypothesis of theHypType used to mesh the shape + if ( myGen.GetShapeDim( shape ) == hyp->GetDim() ) + { + // check local shape + SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( theGeom ); + int nbLocalHyps = aHypList->length(); + for ( int i = 0; i < nbLocalHyps; i++ ) + if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND local! + return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] ); + // check super shapes + TopTools_ListIteratorOfListOfShape itShape( mesh.GetAncestors( shape )); + while ( nbLocalHyps == 0 && itShape.More() ) { + GEOM::GEOM_Object_ptr geomObj = ShapeToGeomObject( itShape.Value() ); + if ( ! CORBA::is_nil( geomObj )) { + SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( geomObj ); + nbLocalHyps = aHypList->length(); + for ( int i = 0; i < nbLocalHyps; i++ ) + if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND global! + return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] ); + } + itShape.Next(); + } + } + + // let the temporary hypothesis find out some how parameter values + if ( hyp->SetParametersByMesh( &mesh, shape )) + return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp ); + + return SMESH::SMESH_Hypothesis::_nil(); +} + //============================================================================= /*! * SMESH_Gen_i::CreateMesh @@ -506,7 +589,7 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObj // create mesh SMESH::SMESH_Mesh_var mesh = this->createMesh(); // set shape - SMESH_Mesh_i* meshServant = dynamic_cast( GetServant( mesh ).in() ); + SMESH_Mesh_i* meshServant = SMESH::DownCast( mesh ); ASSERT( meshServant ); meshServant->SetShape( theShapeObject ); @@ -930,6 +1013,63 @@ CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh, return false; } +//================================================================================ +/*! + * \brief Return geometrical object the given element is built on + * \param theMesh - the mesh the element is in + * \param theElementID - the element ID + * \param theGeomName - the name of the result geom object if it is not yet published + * \retval GEOM::GEOM_Object_ptr - the found or just published geom object + */ +//================================================================================ + +GEOM::GEOM_Object_ptr +SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh, + CORBA::Long theElementID, + const char* theGeomName) + throw ( SALOME::SALOME_Exception ) +{ + Unexpect aCatch(SALOME_SalomeException); + if ( CORBA::is_nil( theMesh ) ) + THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM ); + + GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh(); + GEOM::GEOM_Gen_var geomGen = GetGeomEngine(); + + // get a core mesh DS + SMESH_Mesh_i* meshServant = SMESH::DownCast( theMesh ); + if ( meshServant && !geomGen->_is_nil() && !mainShape->_is_nil() ) + { + ::SMESH_Mesh & mesh = meshServant->GetImpl(); + SMESHDS_Mesh* meshDS = mesh.GetMeshDS(); + // find the element in mesh + if ( const SMDS_MeshElement * elem = meshDS->FindElement( theElementID ) ) + // find a shape id by the element + if ( int shapeID = ::SMESH_MeshEditor( &mesh ).FindShape( elem )) { + // get a geom object by the shape id + GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID )); + if ( geom->_is_nil() ) { + GEOM::GEOM_IShapesOperations_var op = + geomGen->GetIShapesOperations( GetCurrentStudyID() ); + if ( !op->_is_nil() ) + geom = op->GetSubShape( mainShape, shapeID ); + } + if ( !geom->_is_nil() ) { + // try to find the corresponding SObject + GeomObjectToShape( geom ); // geom client remembers the found shape + SALOMEDS::SObject_var SObj = ObjectToSObject( myCurrentStudy, geom.in() ); + if ( SObj->_is_nil() ) + // publish a new subshape + SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape ); + // return only published geometry + if ( !SObj->_is_nil() ) + return geom._retn(); + } + } + } + return GEOM::GEOM_Object::_nil(); +} + //============================================================================= /*! * SMESH_Gen_i::Save @@ -938,8 +1078,8 @@ CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh, */ //============================================================================= SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, - const char* theURL, - bool isMultiFile ) + const char* theURL, + bool isMultiFile ) { INFOS( "SMESH_Gen_i::Save" ); @@ -988,6 +1128,15 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, HDFgroup* aSubSubGroup; hdf_size aSize[ 1 ]; + + //Remove the files if they exist: BugID: 11225 + TCollection_AsciiString cmd("rm -f \""); + cmd+=filename; + cmd+="\" \""; + cmd+=meshfile; + cmd+="\""; + system(cmd.ToCString()); + // MED writer to be used by storage process DriverMED_W_SMESHDS_Mesh myWriter; myWriter.SetFile( meshfile.ToCString() ); @@ -996,7 +1145,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, // ---> create HDF file aFile = new HDFfile( filename.ToCString() ); aFile->CreateOnDisk(); - + // --> iterator for top-level objects SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent ); for ( ; itBig->More(); itBig->Next() ) { diff --git a/src/SMESH_I/SMESH_Gen_i.hxx b/src/SMESH_I/SMESH_Gen_i.hxx index b2d6d882a..f1cce1453 100644 --- a/src/SMESH_I/SMESH_Gen_i.hxx +++ b/src/SMESH_I/SMESH_Gen_i.hxx @@ -176,6 +176,13 @@ public: const char* theLibName) throw ( SALOME::SALOME_Exception ); + // Return hypothesis of given type holding parameter values of the existing mesh + SMESH::SMESH_Hypothesis_ptr GetHypothesisParameterValues (const char* theHypType, + const char* theLibName, + SMESH::SMESH_Mesh_ptr theMesh, + GEOM::GEOM_Object_ptr theGeom) + throw ( SALOME::SALOME_Exception ); + // Create empty mesh on a shape SMESH::SMESH_Mesh_ptr CreateMesh( GEOM::GEOM_Object_ptr theShapeObject ) throw ( SALOME::SALOME_Exception ); @@ -213,6 +220,11 @@ public: const SMESH::object_array& theListOfSubShape ) throw ( SALOME::SALOME_Exception ); + // Return geometrical object the given element is built on + GEOM::GEOM_Object_ptr GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh, + CORBA::Long theElementID, + const char* theGeomName) + throw ( SALOME::SALOME_Exception ); // **************************************************** // Interface inherited methods (from SALOMEDS::Driver) diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index d8445554f..c56c56918 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -380,7 +380,7 @@ SMESH_Hypothesis::Hypothesis_Status int hypId = myHyp->GetId(); status = _impl->AddHypothesis(myLocSubShape, hypId); if ( !SMESH_Hypothesis::IsStatusFatal(status) ) { - _mapHypo[hypId] = myHyp; + _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp ); // assure there is a corresponding submesh if ( !_impl->IsMainShape( myLocSubShape )) { int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape ); @@ -1194,29 +1194,16 @@ static void PrepareForWriting (const char* file) THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM); } } else { - // nonexisting file - TCollection_AsciiString aDirName = aPath.TrekValue(aPath.TrekLength()); - aPath.UpTrek(); - aPath.SetName(aDirName); - aPath.SetExtension(""); - OSD_Directory aDir (aPath); - TCollection_AsciiString aFullDirName; - aPath.SystemName(aFullDirName); - if (aDir.Exists()) { - aFile.Reset(); - aFile.Build(OSD_WriteOnly, OSD_Protection()); - if (aFile.Failed()) { - TCollection_AsciiString msg ("You cannot write to directory "); - msg += aFullDirName + "."; - THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM); - } else { - aFile.Close(); - aFile.Remove(); - } - } else { - TCollection_AsciiString msg ("Directory "); - msg += aFullDirName + " does not exist."; + // nonexisting file; check if it can be created + aFile.Reset(); + aFile.Build(OSD_WriteOnly, OSD_Protection()); + if (aFile.Failed()) { + TCollection_AsciiString msg ("You cannot create the file "); + msg += aFullName + ". Check the directory existance and access rights."; THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM); + } else { + aFile.Close(); + aFile.Remove(); } } } diff --git a/src/StdMeshers/StdMeshers_Arithmetic1D.cxx b/src/StdMeshers/StdMeshers_Arithmetic1D.cxx index c2241c07f..b4953a35a 100644 --- a/src/StdMeshers/StdMeshers_Arithmetic1D.cxx +++ b/src/StdMeshers/StdMeshers_Arithmetic1D.cxx @@ -26,20 +26,34 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_Arithmetic1D.hxx" +#include "SMESH_Algo.hxx" +#include "SMESH_Mesh.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + //============================================================================= /*! * */ //============================================================================= -StdMeshers_Arithmetic1D::StdMeshers_Arithmetic1D(int hypId, int studyId, - SMESH_Gen * gen):SMESH_Hypothesis(hypId, studyId, gen) +StdMeshers_Arithmetic1D::StdMeshers_Arithmetic1D(int hypId, int studyId, SMESH_Gen * gen) + :SMESH_Hypothesis(hypId, studyId, gen) { _begLength = 1.; - _endLength = 1.; + _endLength = 10.; _name = "Arithmetic1D"; _param_algo_dim = 1; } @@ -137,3 +151,49 @@ istream & operator >>(istream & load, StdMeshers_Arithmetic1D & hyp) { return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize start and end length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_Arithmetic1D::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _begLength = _endLength = 0.; + + Standard_Real UMin, UMax; + TopLoc_Location L; + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + for ( int i = 1; i <= edgeMap.Extent(); ++i ) + { + const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( i )); + Handle(Geom_Curve) C = BRep_Tool::Curve(edge, L, UMin, UMax); + GeomAdaptor_Curve AdaptCurve(C); + + vector< double > params; + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params )) + { + nbEdges++; + _begLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[0], params[1]); + int nb = params.size(); + _endLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[nb-2], params[nb-1]); + } + } + if ( nbEdges ) { + _begLength /= nbEdges; + _endLength /= nbEdges; + } + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_Arithmetic1D.hxx b/src/StdMeshers/StdMeshers_Arithmetic1D.hxx index ca49df175..0f5e2e045 100644 --- a/src/StdMeshers/StdMeshers_Arithmetic1D.hxx +++ b/src/StdMeshers/StdMeshers_Arithmetic1D.hxx @@ -43,10 +43,18 @@ public: double GetLength(bool isStartLength) const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream& operator << (ostream & save, StdMeshers_Arithmetic1D & hyp); - friend istream& operator >> (istream & load, StdMeshers_Arithmetic1D & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream& operator << (std::ostream & save, StdMeshers_Arithmetic1D & hyp); + friend std::istream& operator >> (std::istream & load, StdMeshers_Arithmetic1D & hyp); + + /*! + * \brief Initialize start and end length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); protected: double _begLength, _endLength; diff --git a/src/StdMeshers/StdMeshers_AutomaticLength.cxx b/src/StdMeshers/StdMeshers_AutomaticLength.cxx index 1176ebe18..fa74a7dc5 100644 --- a/src/StdMeshers/StdMeshers_AutomaticLength.cxx +++ b/src/StdMeshers/StdMeshers_AutomaticLength.cxx @@ -31,6 +31,7 @@ #include "SMESH_Mesh.hxx" #include "SMESHDS_Mesh.hxx" #include "SMESH_Algo.hxx" +#include "SMESHDS_SubMesh.hxx" #include "utilities.h" @@ -47,8 +48,8 @@ using namespace std; */ //============================================================================= -StdMeshers_AutomaticLength::StdMeshers_AutomaticLength(int hypId, int studyId, - SMESH_Gen * gen):SMESH_Hypothesis(hypId, studyId, gen) +StdMeshers_AutomaticLength::StdMeshers_AutomaticLength(int hypId, int studyId, SMESH_Gen * gen) + :SMESH_Hypothesis(hypId, studyId, gen) { _name = "AutomaticLength"; _param_algo_dim = 1; // is used by SMESH_Regular_1D @@ -80,6 +81,9 @@ StdMeshers_AutomaticLength::~StdMeshers_AutomaticLength() */ //================================================================================ +const double theCoarseConst = 0.5; +const double theFineConst = 4.5; + void StdMeshers_AutomaticLength::SetFineness(double theFineness) throw(SALOME_Exception) { @@ -113,12 +117,11 @@ inline const TopoDS_TShape* getTShape(const TopoDS_Shape& theShape) */ //================================================================================ -static void computeLengths( const SMESH_Mesh* theMesh, +static void computeLengths( SMESHDS_Mesh* aMesh, map & theTShapeToLengthMap) { theTShapeToLengthMap.clear(); - SMESHDS_Mesh* aMesh = const_cast< SMESH_Mesh* > ( theMesh )->GetMeshDS(); TopoDS_Shape aMainShape = aMesh->ShapeToMesh(); // Find length of longest and shortest edge @@ -197,8 +200,10 @@ double StdMeshers_AutomaticLength::GetLength(const SMESH_Mesh* theMesh, if ( anEdge.IsNull() || anEdge.ShapeType() != TopAbs_EDGE ) throw SALOME_Exception(LOCALIZED("Bad edge shape")); - if ( theMesh != _mesh ) { - computeLengths( theMesh, _TShapeToLength ); + if ( theMesh != _mesh ) + { + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* > ( theMesh )->GetMeshDS(); + computeLengths( aMeshDS, _TShapeToLength ); _mesh = theMesh; } @@ -208,7 +213,7 @@ double StdMeshers_AutomaticLength::GetLength(const SMESH_Mesh* theMesh, if ( tshape_length == _TShapeToLength.end() ) return 1; // it is a dgenerated edge - return tshape_length->second / (0.5 + 4.5 * _fineness); + return tshape_length->second / (theCoarseConst + theFineConst * _fineness); } //============================================================================= @@ -257,3 +262,65 @@ istream & operator >>(istream & load, StdMeshers_AutomaticLength & hyp) { return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize Fineness by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_AutomaticLength::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _fineness = 0; + + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + for ( int i = 1; i <= edgeMap.Extent(); ++i ) + { + const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( i )); + + // assure the base automatic length is stored in _TShapeToLength + if ( i == 1 ) + GetLength( theMesh, edge ); + + // get current segment length + double L = SMESH_Algo::EdgeLength( edge ); + if ( L <= DBL_MIN ) + continue; + SMESHDS_SubMesh * eSubMesh = aMeshDS->MeshElements( edge ); + if ( !eSubMesh ) + return false; + double segLen = L / eSubMesh->NbElements(); + + // get segment length from _TShapeToLength + map::iterator tshape_length = + _TShapeToLength.find( getTShape( edge )); + if ( tshape_length == _TShapeToLength.end() ) + continue; + double autoLen = tshape_length->second; + + // segLen = autoLen / (theCoarseConst + theFineConst * _fineness) --> + _fineness += ( autoLen / segLen - theCoarseConst ) / theFineConst; + + ++nbEdges; + } + if ( nbEdges ) + _fineness /= nbEdges; + + if (_fineness > 1.0) + _fineness = 1.0; + else if (_fineness < 0.0) + _fineness = 0.0; + + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_AutomaticLength.hxx b/src/StdMeshers/StdMeshers_AutomaticLength.hxx index b8234b6db..fcdd63940 100644 --- a/src/StdMeshers/StdMeshers_AutomaticLength.hxx +++ b/src/StdMeshers/StdMeshers_AutomaticLength.hxx @@ -78,6 +78,14 @@ public: friend std::ostream & operator <<(std::ostream & save, StdMeshers_AutomaticLength & hyp); friend std::istream & operator >>(std::istream & load, StdMeshers_AutomaticLength & hyp); + /*! + * \brief Initialize Fineness by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + protected: std::map _TShapeToLength; const SMESH_Mesh* _mesh; diff --git a/src/StdMeshers/StdMeshers_Deflection1D.cxx b/src/StdMeshers/StdMeshers_Deflection1D.cxx index f6e54691c..bc97ab03f 100644 --- a/src/StdMeshers/StdMeshers_Deflection1D.cxx +++ b/src/StdMeshers/StdMeshers_Deflection1D.cxx @@ -30,6 +30,19 @@ using namespace std; #include "StdMeshers_Deflection1D.hxx" #include "utilities.h" +#include "SMESH_Mesh.hxx" +#include "SMESH_Algo.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include //============================================================================= /*! @@ -134,3 +147,78 @@ istream & operator >>(istream & load, StdMeshers_Deflection1D & hyp) { return hyp.LoadFrom( load ); } +//================================================================================ +/*! + * \brief Evaluate curve deflection between two points + * \param theCurve - the curve + * \param theU1 - the parameter of the first point + * \param theU2 - the parameter of the second point + * \retval double - deflection value + */ +//================================================================================ + +static double deflection(const GeomAdaptor_Curve & theCurve, + double theU1, + double theU2) +{ + if ( theCurve.GetType() == GeomAbs_Line ) + return 0; + // line between theU1 and theU2 + gp_Pnt p1 = theCurve.Value( theU1 ), p2 = theCurve.Value( theU2 ); + gp_Lin segment( p1, gp_Vec( p1, p2 )); + + // evaluate square distance of theCurve from the segment + Standard_Real dist2 = 0; + const int nbPnt = 7; + const double step = ( theU2 - theU1 ) / nbPnt; + while (( theU1 += step ) < theU2 ) + dist2 = Max( dist2, segment.SquareDistance( theCurve.Value( theU1 ))); + + return sqrt( dist2 ); +} + +//================================================================================ +/*! + * \brief Initialize deflection value by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_Deflection1D::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _value = 0.; + + Standard_Real UMin, UMax; + TopLoc_Location L; + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + + for ( int iE = 1; iE <= edgeMap.Extent(); ++iE ) + { + const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( iE )); + Handle(Geom_Curve) C = BRep_Tool::Curve( edge, L, UMin, UMax ); + GeomAdaptor_Curve AdaptCurve(C); + if ( AdaptCurve.GetType() != GeomAbs_Line ) + { + vector< double > params; + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params )) + { + nbEdges++; + for ( int i = 1; i < params.size(); ++i ) + _value = Max( _value, deflection( AdaptCurve, params[ i-1 ], params[ i ])); + } + } + else + nbEdges++; + } + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_Deflection1D.hxx b/src/StdMeshers/StdMeshers_Deflection1D.hxx index 1ed43cb7d..8aa7112fe 100644 --- a/src/StdMeshers/StdMeshers_Deflection1D.hxx +++ b/src/StdMeshers/StdMeshers_Deflection1D.hxx @@ -41,10 +41,18 @@ class StdMeshers_Deflection1D:public SMESH_Hypothesis double GetDeflection() const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator <<(ostream & save, StdMeshers_Deflection1D & hyp); - friend istream & operator >>(istream & load, StdMeshers_Deflection1D & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator <<(std::ostream & save, StdMeshers_Deflection1D & hyp); + friend std::istream & operator >>(std::istream & load, StdMeshers_Deflection1D & hyp); + + /*! + * \brief Initialize deflection value by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); protected: double _value; diff --git a/src/StdMeshers/StdMeshers_LengthFromEdges.cxx b/src/StdMeshers/StdMeshers_LengthFromEdges.cxx index f21f199f5..55adccca7 100644 --- a/src/StdMeshers/StdMeshers_LengthFromEdges.cxx +++ b/src/StdMeshers/StdMeshers_LengthFromEdges.cxx @@ -27,10 +27,12 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_LengthFromEdges.hxx" + #include "utilities.h" +using namespace std; + //============================================================================= /*! * @@ -42,8 +44,6 @@ StdMeshers_LengthFromEdges::StdMeshers_LengthFromEdges(int hypId, int studyId, S { _mode =1; _name = "LengthFromEdges"; -// SCRUTE(_name); -// SCRUTE(&_name); _param_algo_dim = 2; // is used by SMESH_MEFISTO_2D } @@ -137,3 +137,19 @@ istream & operator >> (istream & load, StdMeshers_LengthFromEdges & hyp) return hyp.LoadFrom( load ); } +//================================================================================ +/*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ +//================================================================================ + +bool StdMeshers_LengthFromEdges::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/, + const TopoDS_Shape& /*theShape*/) +{ + return false; +} diff --git a/src/StdMeshers/StdMeshers_LengthFromEdges.hxx b/src/StdMeshers/StdMeshers_LengthFromEdges.hxx index d514e7c94..c7b20a3b3 100644 --- a/src/StdMeshers/StdMeshers_LengthFromEdges.hxx +++ b/src/StdMeshers/StdMeshers_LengthFromEdges.hxx @@ -45,10 +45,20 @@ public: int GetMode(); - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator << (ostream & save, StdMeshers_LengthFromEdges & hyp); - friend istream & operator >> (istream & load, StdMeshers_LengthFromEdges & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator << (std::ostream & save, StdMeshers_LengthFromEdges & hyp); + friend std::istream & operator >> (std::istream & load, StdMeshers_LengthFromEdges & hyp); + + /*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); protected: int _mode; diff --git a/src/StdMeshers/StdMeshers_LocalLength.cxx b/src/StdMeshers/StdMeshers_LocalLength.cxx index 457d8d80c..90010a213 100644 --- a/src/StdMeshers/StdMeshers_LocalLength.cxx +++ b/src/StdMeshers/StdMeshers_LocalLength.cxx @@ -27,24 +27,37 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_LocalLength.hxx" + +#include "SMESH_Mesh.hxx" +#include "SMESH_Algo.hxx" + #include "utilities.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + //============================================================================= /*! * */ //============================================================================= -StdMeshers_LocalLength::StdMeshers_LocalLength(int hypId, int studyId, - SMESH_Gen * gen):SMESH_Hypothesis(hypId, studyId, gen) +StdMeshers_LocalLength::StdMeshers_LocalLength(int hypId, int studyId, SMESH_Gen * gen) + :SMESH_Hypothesis(hypId, studyId, gen) { - _length = 1.; - _name = "LocalLength"; -// SCRUTE(_name); -// SCRUTE(&_name); - _param_algo_dim = 1; // is used by SMESH_Regular_1D + _length = 1.; + _name = "LocalLength"; + _param_algo_dim = 1; // is used by SMESH_Regular_1D } //============================================================================= @@ -135,3 +148,47 @@ istream & operator >>(istream & load, StdMeshers_LocalLength & hyp) { return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize segment length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_LocalLength::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _length = 0.; + + Standard_Real UMin, UMax; + TopLoc_Location L; + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + for ( int iE = 1; iE <= edgeMap.Extent(); ++iE ) + { + const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( iE )); + Handle(Geom_Curve) C = BRep_Tool::Curve( edge, L, UMin, UMax ); + GeomAdaptor_Curve AdaptCurve(C); + + vector< double > params; + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params )) + { + for ( int i = 1; i < params.size(); ++i ) + _length += GCPnts_AbscissaPoint::Length( AdaptCurve, params[ i-1 ], params[ i ]); + nbEdges += params.size() - 1; + } + } + if ( nbEdges ) + _length /= nbEdges; + + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_LocalLength.hxx b/src/StdMeshers/StdMeshers_LocalLength.hxx index aba58e51a..a48d2859b 100644 --- a/src/StdMeshers/StdMeshers_LocalLength.hxx +++ b/src/StdMeshers/StdMeshers_LocalLength.hxx @@ -35,21 +35,29 @@ class StdMeshers_LocalLength:public SMESH_Hypothesis { - public: - StdMeshers_LocalLength(int hypId, int studyId, SMESH_Gen * gen); - virtual ~ StdMeshers_LocalLength(); + public: + StdMeshers_LocalLength(int hypId, int studyId, SMESH_Gen * gen); + virtual ~ StdMeshers_LocalLength(); - void SetLength(double length) throw(SALOME_Exception); + void SetLength(double length) throw(SALOME_Exception); - double GetLength() const; + double GetLength() const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator <<(ostream & save, StdMeshers_LocalLength & hyp); - friend istream & operator >>(istream & load, StdMeshers_LocalLength & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator <<(std::ostream & save, StdMeshers_LocalLength & hyp); + friend std::istream & operator >>(std::istream & load, StdMeshers_LocalLength & hyp); - protected: - double _length; + /*! + * \brief Initialize segment length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + + protected: + double _length; }; #endif diff --git a/src/StdMeshers/StdMeshers_MEFISTO_2D.cxx b/src/StdMeshers/StdMeshers_MEFISTO_2D.cxx index ed166fc03..4852ce4fe 100644 --- a/src/StdMeshers/StdMeshers_MEFISTO_2D.cxx +++ b/src/StdMeshers/StdMeshers_MEFISTO_2D.cxx @@ -324,7 +324,8 @@ static bool fixOverlappedLinkUV( R2& uv0, const R2& uv1, const R2& uv2 ) uv0.y -= delta; else uv0.y += delta; -// MESSAGE(" -> " << uv0.x << " " << uv0.y << " "); +// #ifdef _DEBUG_ +// MESSAGE(" -> " << uv0.x << " " << uv0.y << " "); // MESSAGE("v1( " << v1.X() << " " << v1.Y() << " ) " << // "v2( " << v2.X() << " " << v2.Y() << " ) "); // MESSAGE("SIN: " << sqrt(1 - dot * dot / (sqMod1 * sqMod2))); @@ -336,6 +337,7 @@ static bool fixOverlappedLinkUV( R2& uv0, const R2& uv1, const R2& uv2 ) // dot = v1*v2; // double sin = sqrt(1 - dot * dot / (sqMod1 * sqMod2)); // MESSAGE("NEW SIN: " << sin); +// #endif return true; } return false; @@ -475,134 +477,109 @@ bool StdMeshers_MEFISTO_2D::LoadPoints(SMESH_Mesh & aMesh, double scaley, const TopTools_IndexedDataMapOfShapeListOfShape& VWMap) { -// MESSAGE("StdMeshers_MEFISTO_2D::LoadPoints"); - - //SMDS_Mesh * meshDS = aMesh.GetMeshDS(); + // MESSAGE("StdMeshers_MEFISTO_2D::LoadPoints"); TopoDS_Face F = TopoDS::Face(FF.Oriented(TopAbs_FORWARD)); - int mInit = m, mFirst, iEdge; + list< int > mOnVertex; + gp_XY scale( scalex, scaley ); TopoDS_Wire W = TopoDS::Wire(WW.Oriented(TopAbs_FORWARD)); BRepTools_WireExplorer wexp(W, F); - for (wexp.Init(W, F), iEdge = 0; wexp.More(); wexp.Next(), iEdge++) + for ( wexp.Init(W, F); wexp.More(); wexp.Next() ) { const TopoDS_Edge & E = wexp.Current(); + bool isForward = (E.Orientation() == TopAbs_FORWARD); // --- IDNodes of first and last Vertex - TopoDS_Vertex VFirst, VLast; + TopoDS_Vertex VFirst, VLast, V; TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l + V = isForward ? VFirst : VLast; - ASSERT(!VFirst.IsNull()); - SMDS_NodeIteratorPtr lid= - aMesh.GetSubMesh(VFirst)->GetSubMeshDS()->GetNodes(); + ASSERT(!V.IsNull()); + SMDS_NodeIteratorPtr lid= aMesh.GetSubMesh(V)->GetSubMeshDS()->GetNodes(); if ( !lid->more() ) { MESSAGE (" NO NODE BUILT ON VERTEX "); return false; } const SMDS_MeshNode* idFirst = lid->next(); - ASSERT(!VLast.IsNull()); - lid=aMesh.GetSubMesh(VLast)->GetSubMeshDS()->GetNodes(); - if ( !lid->more() ) { - MESSAGE (" NO NODE BUILT ON VERTEX "); - return false; - } - const SMDS_MeshNode* idLast = lid->next(); - // --- edge internal IDNodes (relies on good order storage, not checked) - int nbPoints = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes(); - - double f, l; - Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l); - - SMDS_NodeIteratorPtr ite= aMesh.GetSubMesh(E)->GetSubMeshDS()->GetNodes(); - - //bool isForward = (E.Orientation() == TopAbs_FORWARD); map params; + const SMDS_MeshNode * node; - while(ite->more()) + SMDS_NodeIteratorPtr nodeIt= aMesh.GetSubMesh(E)->GetSubMeshDS()->GetNodes(); + while ( nodeIt->more() ) { - const SMDS_MeshNode * node = ite->next(); + node = nodeIt->next(); const SMDS_EdgePosition* epos = static_cast(node->GetPosition().get()); - double param = epos->GetUParameter(); - params[param] = node; + params[ epos->GetUParameter() ] = node; } + int nbPoints = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes(); if ( nbPoints != params.size()) { MESSAGE( "BAD NODE ON EDGE POSITIONS" ); return false; } - mFirst = m; - // --- load 2D values into MEFISTO structure, // add IDNodes in mefistoToDS map - if (E.Orientation() == TopAbs_FORWARD) + + double f, l, uFirst, u; + Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l); + uFirst = isForward ? f : l; + + // vertex node + gp_Pnt2d p = C2d->Value( uFirst ).XY().Multiplied( scale ); + if ( fixCommonVertexUV( p, V, W, myOuterWire, F, VWMap, aMesh )) + myNodesOnCommonV.push_back( idFirst ); + mOnVertex.push_back( m ); + uvslf[m].x = p.X(); + uvslf[m].y = p.Y(); + mefistoToDS[m + 1] = idFirst; + //MESSAGE(" "<::iterator u_n = params.begin(); + map::reverse_iterator u_n_rev = params.rbegin(); + for ( int i = 0; i < nbPoints; ++i ) { - gp_Pnt2d p = C2d->Value(f).XY().Multiplied( scale ); // first point = Vertex Forward - if ( fixCommonVertexUV( p, VFirst, W, myOuterWire, F, VWMap, aMesh )) - myNodesOnCommonV.push_back( idFirst ); - uvslf[m].x = p.X(); - uvslf[m].y = p.Y(); - mefistoToDS[m + 1] = idFirst; - //MESSAGE(" "<::iterator itp = params.begin(); - for (int i = 1; i <= nbPoints; i++) // nbPoints internal - { - double param = (*itp).first; - gp_Pnt2d p = C2d->Value(param).XY().Multiplied( scale ); - uvslf[m].x = p.X(); - uvslf[m].y = p.Y(); - mefistoToDS[m + 1] = (*itp).second; - //MESSAGE(" "<first; + node = u_n->second; + ++u_n; + } else { + u = u_n_rev->first; + node = u_n_rev->second; + ++u_n_rev; } - } - else - { - gp_Pnt2d p = C2d->Value(l).XY().Multiplied( scale ); // last point = Vertex Reversed - if ( fixCommonVertexUV( p, VLast, W, myOuterWire, F, VWMap, aMesh )) - myNodesOnCommonV.push_back( idLast ); + gp_Pnt2d p = C2d->Value( u ).XY().Multiplied( scale ); uvslf[m].x = p.X(); uvslf[m].y = p.Y(); - mefistoToDS[m + 1] = idLast; + mefistoToDS[m + 1] = node; //MESSAGE(" "<::reverse_iterator itp = params.rbegin(); - for (int i = nbPoints; i >= 1; i--) - { - double param = (*itp).first; - gp_Pnt2d p = C2d->Value(param).XY().Multiplied( scale ); - uvslf[m].x = p.X(); - uvslf[m].y = p.Y(); - mefistoToDS[m + 1] = (*itp).second; - //MESSAGE(" "< 0 ) - fixOverlappedLinkUV (uvslf[ mFirst - 1], - uvslf[ mFirst ], - uvslf[ mFirst + 1 ]); - } // for wexp - fixOverlappedLinkUV (uvslf[ m - 1], - uvslf[ mInit ], - uvslf[ mInit + 1 ]); + // prevent failure on overlapped adjacent links, + // check only links ending in vertex nodes + int mFirst = mOnVertex.front(), mLast = m - 1; + list< int >::iterator mIt = mOnVertex.begin(); + for ( ; mIt != mOnVertex.end(); ++mIt ) { + int i = *mIt; + int iB = i - 1, iA = i + 1; // indices Before and After + if ( iB < mFirst ) iB = mLast; + if ( iA > mLast ) iA = mFirst; + fixOverlappedLinkUV (uvslf[ iB ], uvslf[ i ], uvslf[ iA ]); + } return true; } diff --git a/src/StdMeshers/StdMeshers_MaxElementArea.cxx b/src/StdMeshers/StdMeshers_MaxElementArea.cxx index c4a2d5e17..08c69e68b 100644 --- a/src/StdMeshers/StdMeshers_MaxElementArea.cxx +++ b/src/StdMeshers/StdMeshers_MaxElementArea.cxx @@ -27,10 +27,20 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_MaxElementArea.hxx" + +#include "SMESH_ControlsDef.hxx" +#include "SMDS_MeshElement.hxx" +#include "SMESHDS_SubMesh.hxx" +#include "SMESH_Mesh.hxx" + +#include +#include + #include "utilities.h" +using namespace std; + //============================================================================= /*! * @@ -42,8 +52,6 @@ StdMeshers_MaxElementArea::StdMeshers_MaxElementArea(int hypId, int studyId, SME { _maxArea =1.; _name = "MaxElementArea"; -// SCRUTE(_name); -// SCRUTE(&_name); _param_algo_dim = 2; } @@ -137,3 +145,44 @@ istream & operator >> (istream & load, StdMeshers_MaxElementArea & hyp) return hyp.LoadFrom( load ); } +//================================================================================ +/*! + * \brief Initialize maximal area by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_MaxElementArea::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _maxArea = 0; + + SMESH::Controls::Area areaControl; + SMESH::Controls::TSequenceOfXYZ nodesCoords; + + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + + TopTools_IndexedMapOfShape faceMap; + TopExp::MapShapes( theShape, TopAbs_FACE, faceMap ); + for ( int iF = 1; iF <= faceMap.Extent(); ++iF ) + { + SMESHDS_SubMesh * subMesh = aMeshDS->MeshElements( faceMap( iF )); + if ( !subMesh ) + return false; + SMDS_ElemIteratorPtr fIt = subMesh->GetElements(); + while ( fIt->more() ) + { + const SMDS_MeshElement* elem = fIt->next(); + if ( elem->GetType() == SMDSAbs_Face ) { + areaControl.GetPoints( elem, nodesCoords ); + _maxArea = max( _maxArea, areaControl.GetValue( nodesCoords )); + } + } + } + return _maxArea > 0; +} diff --git a/src/StdMeshers/StdMeshers_MaxElementArea.hxx b/src/StdMeshers/StdMeshers_MaxElementArea.hxx index 52af887c8..44e8d0921 100644 --- a/src/StdMeshers/StdMeshers_MaxElementArea.hxx +++ b/src/StdMeshers/StdMeshers_MaxElementArea.hxx @@ -35,21 +35,29 @@ class StdMeshers_MaxElementArea:public SMESH_Hypothesis { - public: - StdMeshers_MaxElementArea(int hypId, int studyId, SMESH_Gen * gen); - virtual ~ StdMeshers_MaxElementArea(); +public: + StdMeshers_MaxElementArea(int hypId, int studyId, SMESH_Gen * gen); + virtual ~ StdMeshers_MaxElementArea(); - void SetMaxArea(double maxArea) throw(SALOME_Exception); + void SetMaxArea(double maxArea) throw(SALOME_Exception); - double GetMaxArea() const; + double GetMaxArea() const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator <<(ostream & save, StdMeshers_MaxElementArea & hyp); - friend istream & operator >>(istream & load, StdMeshers_MaxElementArea & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator <<(std::ostream & save, StdMeshers_MaxElementArea & hyp); + friend std::istream & operator >>(std::istream & load, StdMeshers_MaxElementArea & hyp); - protected: - double _maxArea; + /*! + * \brief Initialize maximal area by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + +protected: + double _maxArea; }; #endif diff --git a/src/StdMeshers/StdMeshers_MaxElementVolume.cxx b/src/StdMeshers/StdMeshers_MaxElementVolume.cxx index f9f6b6322..c4e58949f 100644 --- a/src/StdMeshers/StdMeshers_MaxElementVolume.cxx +++ b/src/StdMeshers/StdMeshers_MaxElementVolume.cxx @@ -30,8 +30,18 @@ using namespace std; #include "StdMeshers_MaxElementVolume.hxx" + +#include "SMDS_MeshElement.hxx" +#include "SMESHDS_SubMesh.hxx" +#include "SMESH_ControlsDef.hxx" +#include "SMESH_Mesh.hxx" + #include "utilities.h" +#include +#include +#include + //============================================================================= /*! * @@ -41,10 +51,8 @@ using namespace std; StdMeshers_MaxElementVolume::StdMeshers_MaxElementVolume(int hypId, int studyId, SMESH_Gen* gen) : SMESH_Hypothesis(hypId, studyId, gen) { - _maxVolume =1.; + _maxVolume = 1.; _name = "MaxElementVolume"; -// SCRUTE(_name); - SCRUTE(&_name); _param_algo_dim = 3; } @@ -139,3 +147,54 @@ istream & operator >> (istream & load, StdMeshers_MaxElementVolume & hyp) return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize maximal area by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_MaxElementVolume::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _maxVolume = 0; + + SMESH::Controls::Volume volumeControl; + + TopTools_IndexedMapOfShape volMap; + TopExp::MapShapes( theShape, TopAbs_SOLID, volMap ); + if ( volMap.IsEmpty() ) + TopExp::MapShapes( theShape, TopAbs_SHELL, volMap ); + if ( volMap.IsEmpty() ) + return false; + + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + + for ( int iV = 1; iV <= volMap.Extent(); ++iV ) + { + const TopoDS_Shape& S = volMap( iV ); + SMESHDS_SubMesh * subMesh = aMeshDS->MeshElements( S ); + if ( !subMesh && S.ShapeType() == TopAbs_SOLID ) { + TopExp_Explorer shellExp( S, TopAbs_SHELL ); + if ( shellExp.More() ) + subMesh = aMeshDS->MeshElements( shellExp.Current() ); + } + if ( !subMesh) + return false; + SMDS_ElemIteratorPtr vIt = subMesh->GetElements(); + while ( vIt->more() ) + { + const SMDS_MeshElement* elem = vIt->next(); + if ( elem->GetType() == SMDSAbs_Volume ) { + _maxVolume = max( _maxVolume, volumeControl.GetValue( elem->GetID() )); + } + } + } + return _maxVolume > 0; +} diff --git a/src/StdMeshers/StdMeshers_MaxElementVolume.hxx b/src/StdMeshers/StdMeshers_MaxElementVolume.hxx index ee9986f1f..870aac92a 100644 --- a/src/StdMeshers/StdMeshers_MaxElementVolume.hxx +++ b/src/StdMeshers/StdMeshers_MaxElementVolume.hxx @@ -45,10 +45,18 @@ public: double GetMaxVolume() const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator << (ostream & save, StdMeshers_MaxElementVolume & hyp); - friend istream & operator >> (istream & load, StdMeshers_MaxElementVolume & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator << (std::ostream & save, StdMeshers_MaxElementVolume & hyp); + friend std::istream & operator >> (std::istream & load, StdMeshers_MaxElementVolume & hyp); + + /*! + * \brief Initialize maximal volume by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); protected: double _maxVolume; diff --git a/src/StdMeshers/StdMeshers_NotConformAllowed.cxx b/src/StdMeshers/StdMeshers_NotConformAllowed.cxx index 5c471b2a0..5799cbce6 100644 --- a/src/StdMeshers/StdMeshers_NotConformAllowed.cxx +++ b/src/StdMeshers/StdMeshers_NotConformAllowed.cxx @@ -96,3 +96,19 @@ istream & operator >> (istream & load, StdMeshers_NotConformAllowed & hyp) { return load; } +//================================================================================ +/*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ +//================================================================================ + +bool StdMeshers_NotConformAllowed::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/, + const TopoDS_Shape& /*theShape*/) +{ + return false; +} diff --git a/src/StdMeshers/StdMeshers_NotConformAllowed.hxx b/src/StdMeshers/StdMeshers_NotConformAllowed.hxx index 079742458..3ffb7b71c 100644 --- a/src/StdMeshers/StdMeshers_NotConformAllowed.hxx +++ b/src/StdMeshers/StdMeshers_NotConformAllowed.hxx @@ -39,10 +39,21 @@ public: StdMeshers_NotConformAllowed(int hypId, int studyId, SMESH_Gen* gen); virtual ~StdMeshers_NotConformAllowed(); - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator << (ostream & save, StdMeshers_NotConformAllowed & hyp); - friend istream & operator >> (istream & load, StdMeshers_NotConformAllowed & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator << (std::ostream & save, StdMeshers_NotConformAllowed & hyp); + friend std::istream & operator >> (std::istream & load, StdMeshers_NotConformAllowed & hyp); + + /*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + }; #endif diff --git a/src/StdMeshers/StdMeshers_NumberOfSegments.cxx b/src/StdMeshers/StdMeshers_NumberOfSegments.cxx index 0b9d33355..139ea22e6 100644 --- a/src/StdMeshers/StdMeshers_NumberOfSegments.cxx +++ b/src/StdMeshers/StdMeshers_NumberOfSegments.cxx @@ -27,20 +27,27 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_NumberOfSegments.hxx" + #include "StdMeshers_Distribution.hxx" -#include -#include -#include -#include +#include "SMESHDS_SubMesh.hxx" +#include "SMESH_Mesh.hxx" + #include -#include #include -#include +#include +#include #include +#include +#include #include +#include +#include +#include +#include + +using namespace std; const double PRECISION = 1e-7; @@ -640,3 +647,40 @@ istream & operator >>(istream & load, StdMeshers_NumberOfSegments & hyp) { return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize number of segments by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_NumberOfSegments::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _numberOfSegments = 0; + _distrType = DT_Regular; + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + for ( int i = 1; i <= edgeMap.Extent(); ++i ) + { + // get current segment length + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + SMESHDS_SubMesh * eSubMesh = aMeshDS->MeshElements( edgeMap( i )); + if ( eSubMesh && eSubMesh->NbElements()) + _numberOfSegments += eSubMesh->NbElements(); + + ++nbEdges; + } + if ( nbEdges ) + _numberOfSegments /= nbEdges; + + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_NumberOfSegments.hxx b/src/StdMeshers/StdMeshers_NumberOfSegments.hxx index 28d829b75..3878330c8 100644 --- a/src/StdMeshers/StdMeshers_NumberOfSegments.hxx +++ b/src/StdMeshers/StdMeshers_NumberOfSegments.hxx @@ -161,10 +161,19 @@ public: int ConversionMode() const throw (SALOME_Exception); - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream& operator << (ostream & save, StdMeshers_NumberOfSegments & hyp); - friend istream& operator >> (istream & load, StdMeshers_NumberOfSegments & hyp); + + /*! + * \brief Initialize number of segments by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream& operator << (std::ostream & save, StdMeshers_NumberOfSegments & hyp); + friend std::istream& operator >> (std::istream & load, StdMeshers_NumberOfSegments & hyp); protected: int _numberOfSegments; //!< an edge will be split on to this number of segments diff --git a/src/StdMeshers/StdMeshers_Propagation.cxx b/src/StdMeshers/StdMeshers_Propagation.cxx index f314b4c28..6672e2565 100644 --- a/src/StdMeshers/StdMeshers_Propagation.cxx +++ b/src/StdMeshers/StdMeshers_Propagation.cxx @@ -24,10 +24,12 @@ // Module : SMESH // $Header$ -using namespace std; #include "StdMeshers_Propagation.hxx" + #include "utilities.h" +using namespace std; + //============================================================================= /*! * @@ -100,3 +102,19 @@ std::string StdMeshers_Propagation::GetName () { return "Propagation"; } +//================================================================================ +/*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ +//================================================================================ + +bool StdMeshers_Propagation::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/, + const TopoDS_Shape& /*theShape*/) +{ + return false; +} diff --git a/src/StdMeshers/StdMeshers_Propagation.hxx b/src/StdMeshers/StdMeshers_Propagation.hxx index 4ee7c5628..ef750b9ed 100644 --- a/src/StdMeshers/StdMeshers_Propagation.hxx +++ b/src/StdMeshers/StdMeshers_Propagation.hxx @@ -36,12 +36,22 @@ class StdMeshers_Propagation:public SMESH_Hypothesis StdMeshers_Propagation(int hypId, int studyId, SMESH_Gen * gen); virtual ~ StdMeshers_Propagation(); - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator <<(ostream & save, StdMeshers_Propagation & hyp); - friend istream & operator >>(istream & load, StdMeshers_Propagation & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator <<(std::ostream & save, StdMeshers_Propagation & hyp); + friend std::istream & operator >>(std::istream & load, StdMeshers_Propagation & hyp); static std::string GetName (); + + /*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); }; #endif diff --git a/src/StdMeshers/StdMeshers_QuadranglePreference.cxx b/src/StdMeshers/StdMeshers_QuadranglePreference.cxx index 4ba3dd8ed..60dc49499 100644 --- a/src/StdMeshers/StdMeshers_QuadranglePreference.cxx +++ b/src/StdMeshers/StdMeshers_QuadranglePreference.cxx @@ -98,3 +98,19 @@ istream & operator >>(istream & load, StdMeshers_QuadranglePreference & hyp) { return hyp.LoadFrom( load ); } +//================================================================================ +/*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ +//================================================================================ + +bool StdMeshers_QuadranglePreference::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/, + const TopoDS_Shape& /*theShape*/) +{ + return false; +} diff --git a/src/StdMeshers/StdMeshers_QuadranglePreference.hxx b/src/StdMeshers/StdMeshers_QuadranglePreference.hxx index eb2fdca04..ba6eaef5e 100644 --- a/src/StdMeshers/StdMeshers_QuadranglePreference.hxx +++ b/src/StdMeshers/StdMeshers_QuadranglePreference.hxx @@ -47,6 +47,17 @@ class StdMeshers_QuadranglePreference:public SMESH_Hypothesis virtual std::istream & LoadFrom(std::istream & load); friend std::ostream & operator <<(std::ostream & save, StdMeshers_QuadranglePreference & hyp); friend std::istream & operator >>(std::istream & load, StdMeshers_QuadranglePreference & hyp); + + /*! + * \brief Initialize my parameter values by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + * + * Just return false as this hypothesis does not have parameters values + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + }; #endif diff --git a/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx b/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx index e40390c6e..9ffa37d1f 100644 --- a/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx +++ b/src/StdMeshers/StdMeshers_Quadrangle_2D.cxx @@ -51,10 +51,21 @@ using namespace std; #include #include #include +#include +#include #include "utilities.h" #include "Utils_ExceptHandlers.hxx" +#ifndef StdMeshers_Array2OfNode_HeaderFile +#define StdMeshers_Array2OfNode_HeaderFile +typedef const SMDS_MeshNode* SMDS_MeshNodePtr; +#include +DEFINE_BASECOLLECTION (StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr) +DEFINE_ARRAY2(StdMeshers_Array2OfNode, + StdMeshers_BaseCollectionNodePtr, SMDS_MeshNodePtr) +#endif + //============================================================================= /*! @@ -117,7 +128,28 @@ bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh, SMESHDS_Mesh * meshDS = aMesh.GetMeshDS(); aMesh.GetSubMesh(aShape); - FaceQuadStruct *quad = CheckAnd2Dcompute(aMesh, aShape); + //FaceQuadStruct *quad = CheckAnd2Dcompute(aMesh, aShape); + FaceQuadStruct* quad = CheckNbEdges(aMesh, aShape); + + if (!quad) + return false; + + if(myQuadranglePreference) { + int n1 = quad->nbPts[0]; + int n2 = quad->nbPts[1]; + int n3 = quad->nbPts[2]; + int n4 = quad->nbPts[3]; + int nfull = n1+n2+n3+n4; + int ntmp = nfull/2; + ntmp = ntmp*2; + if( nfull==ntmp && ( (n1!=n3) || (n2!=n4) ) ) { + // special path for using only quandrangle faces + return ComputeQuadPref(aMesh, aShape, quad); + } + } + + // set normalized grid on unit square in parametric domain + SetNormalizedGrid(aMesh, aShape, quad); if (!quad) return false; @@ -490,14 +522,16 @@ bool StdMeshers_Quadrangle_2D::Compute (SMESH_Mesh& aMesh, return isOk; } + //============================================================================= /*! * */ //============================================================================= -FaceQuadStruct *StdMeshers_Quadrangle_2D::CheckAnd2Dcompute - (SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) throw(SALOME_Exception) +FaceQuadStruct* StdMeshers_Quadrangle_2D::CheckNbEdges(SMESH_Mesh & aMesh, + const TopoDS_Shape & aShape) + throw(SALOME_Exception) { Unexpect aCatch(SalomeException); @@ -505,42 +539,56 @@ FaceQuadStruct *StdMeshers_Quadrangle_2D::CheckAnd2Dcompute // verify 1 wire only, with 4 edges - if (NumberOfWires(F) != 1) - { + if (NumberOfWires(F) != 1) { INFOS("only 1 wire by face (quadrangles)"); return 0; } const TopoDS_Wire& W = BRepTools::OuterWire(F); BRepTools_WireExplorer wexp (W, F); - FaceQuadStruct *quad = new FaceQuadStruct; + FaceQuadStruct* quad = new FaceQuadStruct; for (int i = 0; i < 4; i++) quad->uv_edges[i] = 0; quad->uv_grid = 0; int nbEdges = 0; - for (wexp.Init(W, F); wexp.More(); wexp.Next()) - { + for (wexp.Init(W, F); wexp.More(); wexp.Next()) { const TopoDS_Edge& E = wexp.Current(); int nb = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes(); - if (nbEdges < 4) - { + if (nbEdges < 4) { quad->edge[nbEdges] = E; quad->nbPts[nbEdges] = nb + 2; // internal points + 2 extrema } nbEdges++; } - if (nbEdges != 4) - { + if (nbEdges != 4) { INFOS("face must have 4 edges /quadrangles"); QuadDelete(quad); return 0; } - // set normalized grid on unit square in parametric domain + return quad; +} + + +//============================================================================= +/*! + * + */ +//============================================================================= + +FaceQuadStruct *StdMeshers_Quadrangle_2D::CheckAnd2Dcompute + (SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + + FaceQuadStruct *quad = CheckNbEdges(aMesh, aShape); + + if(!quad) return 0; - SetNormalizedGrid(aMesh, F, quad); + // set normalized grid on unit square in parametric domain + SetNormalizedGrid(aMesh, aShape, quad); return quad; } @@ -789,6 +837,654 @@ void StdMeshers_Quadrangle_2D::SetNormalizedGrid (SMESH_Mesh & aMesh, } } + +//======================================================================= +//function : ShiftQuad +//purpose : auxilary function for ComputeQuadPref +//======================================================================= +static void ShiftQuad(FaceQuadStruct* quad, const int num, bool WisF) +{ + if(num>3) return; + int i; + for(i=1; i<=num; i++) { + int nbPts3 = quad->nbPts[0]; + quad->nbPts[0] = quad->nbPts[1]; + quad->nbPts[1] = quad->nbPts[2]; + quad->nbPts[2] = quad->nbPts[3]; + quad->nbPts[3] = nbPts3; + TopoDS_Edge edge3 = quad->edge[0]; + quad->edge[0] = quad->edge[1]; + quad->edge[1] = quad->edge[2]; + quad->edge[2] = quad->edge[3]; + quad->edge[3] = edge3; + double first3 = quad->first[0]; + quad->first[0] = quad->first[1]; + quad->first[1] = quad->first[2]; + quad->first[2] = quad->first[3]; + quad->first[3] = first3; + double last3 = quad->last[0]; + quad->last[0] = quad->last[1]; + quad->last[1] = quad->last[2]; + quad->last[2] = quad->last[3]; + quad->last[3] = last3; + bool isEdgeForward3 = quad->isEdgeForward[0]; + quad->isEdgeForward[0] = quad->isEdgeForward[1]; + quad->isEdgeForward[1] = quad->isEdgeForward[2]; + quad->isEdgeForward[2] = quad->isEdgeForward[3]; + quad->isEdgeForward[3] = isEdgeForward3; + bool isEdgeOut3 = quad->isEdgeOut[0]; + quad->isEdgeOut[0] = quad->isEdgeOut[1]; + quad->isEdgeOut[1] = quad->isEdgeOut[2]; + quad->isEdgeOut[2] = quad->isEdgeOut[3]; + quad->isEdgeOut[3] = isEdgeOut3; + UVPtStruct* uv_edges3 = quad->uv_edges[0]; + quad->uv_edges[0] = quad->uv_edges[1]; + quad->uv_edges[1] = quad->uv_edges[2]; + quad->uv_edges[2] = quad->uv_edges[3]; + quad->uv_edges[3] = uv_edges3; + } + if(!WisF) { + // replacement left and right edges + int nbPts3 = quad->nbPts[1]; + quad->nbPts[1] = quad->nbPts[3]; + quad->nbPts[3] = nbPts3; + TopoDS_Edge edge3 = quad->edge[1]; + quad->edge[1] = quad->edge[3]; + quad->edge[3] = edge3; + double first3 = quad->first[1]; + quad->first[1] = quad->first[3]; + quad->first[3] = first3; + double last3 = quad->last[1]; + quad->last[1] = quad->last[2]; + quad->last[3] = last3; + bool isEdgeForward3 = quad->isEdgeForward[1]; + quad->isEdgeForward[1] = quad->isEdgeForward[3]; + quad->isEdgeForward[3] = isEdgeForward3; + bool isEdgeOut3 = quad->isEdgeOut[1]; + quad->isEdgeOut[1] = quad->isEdgeOut[3]; + quad->isEdgeOut[3] = isEdgeOut3; + UVPtStruct* uv_edges3 = quad->uv_edges[1]; + quad->uv_edges[1] = quad->uv_edges[3]; + quad->uv_edges[3] = uv_edges3; + } +} + + +//======================================================================= +//function : CalcUV +//purpose : auxilary function for ComputeQuadPref +//======================================================================= +static gp_XY CalcUV(double x0, double x1, double y0, double y1, + FaceQuadStruct* quad, + const gp_Pnt2d& a0, const gp_Pnt2d& a1, + const gp_Pnt2d& a2, const gp_Pnt2d& a3, + const Handle(Geom2d_Curve)& c2db, + const Handle(Geom2d_Curve)& c2dr, + const Handle(Geom2d_Curve)& c2dt, + const Handle(Geom2d_Curve)& c2dl) +{ + int nb = quad->nbPts[0]; + int nr = quad->nbPts[1]; + int nt = quad->nbPts[2]; + int nl = quad->nbPts[3]; + + UVPtStruct* uv_eb = quad->uv_edges[0]; + UVPtStruct* uv_er = quad->uv_edges[1]; + UVPtStruct* uv_et = quad->uv_edges[2]; + UVPtStruct* uv_el = quad->uv_edges[3]; + + double x = (x0 + y0 * (x1 - x0)) / (1 - (y1 - y0) * (x1 - x0)); + double y = y0 + x * (y1 - y0); + + double param_b = uv_eb[0].param + x * (uv_eb[nb-1].param - uv_eb[0].param); + double param_t = uv_et[0].param + x * (uv_et[nt-1].param - uv_et[0].param); + double param_r = uv_er[0].param + y * (uv_er[nr-1].param - uv_er[0].param); + double param_l = uv_el[0].param + y * (uv_el[nl-1].param - uv_el[0].param); + + gp_Pnt2d p0 = c2db->Value(param_b); + gp_Pnt2d p1 = c2dr->Value(param_r); + gp_Pnt2d p2 = c2dt->Value(param_t); + gp_Pnt2d p3 = c2dl->Value(param_l); + + double u = (1 - y) * p0.X() + x * p1.X() + y * p2.X() + (1 - x) * p3.X(); + double v = (1 - y) * p0.Y() + x * p1.Y() + y * p2.Y() + (1 - x) * p3.Y(); + + u -= (1 - x) * (1 - y) * a0.X() + x * (1 - y) * a1.X() + + x * y * a2.X() + (1 - x) * y * a3.X(); + v -= (1 - x) * (1 - y) * a0.Y() + x * (1 - y) * a1.Y() + + x * y * a2.Y() + (1 - x) * y * a3.Y(); + + //cout<<"x0="<ShapeToIndex( F ); + + int nb = quad->nbPts[0]; + int nr = quad->nbPts[1]; + int nt = quad->nbPts[2]; + int nl = quad->nbPts[3]; + int dh = abs(nb-nt); + int dv = abs(nr-nl); + + if( dh>=dv ) { + if( nt>nb ) { + // it is a base case => not shift quad but me be replacement is need + ShiftQuad(quad,0,WisF); + } + else { + // we have to shift quad on 2 + ShiftQuad(quad,2,WisF); + } + } + else { + if( nr>nl ) { + // we have to shift quad on 3 + ShiftQuad(quad,3,WisF); + } + else { + // we have to shift quad on 1 + ShiftQuad(quad,1,WisF); + } + } + + nb = quad->nbPts[0]; + nr = quad->nbPts[1]; + nt = quad->nbPts[2]; + nl = quad->nbPts[3]; + dh = abs(nb-nt); + dv = abs(nr-nl); + int nbh = Max(nb,nt); + int nbv = Max(nr,nl); + int addh = 0; + int addv = 0; + + // orientation of face and 3 main domain for future faces + // 0 top 1 + // 1------------1 + // | | | | + // | | | | + // | L | | R | + // left | | | | rigth + // | / \ | + // | / C \ | + // |/ \| + // 0------------0 + // 0 bottom 1 + + if(dh>dv) { + addv = (dh-dv)/2; + nbv = nbv + addv; + } + else { // dv>=dh + addh = (dv-dh)/2; + nbh = nbh + addh; + } + + Handle(Geom2d_Curve) c2d[4]; + for(i=0; i<4; i++) { + c2d[i] = BRep_Tool::CurveOnSurface(quad->edge[i], F, + quad->first[i], quad->last[i]); + } + + bool loadOk = true; + for(i=0; i<2; i++) { + quad->uv_edges[i] = LoadEdgePoints2(aMesh, F, quad->edge[i], false); + if(!quad->uv_edges[i]) loadOk = false; + } + for(i=2; i<4; i++) { + quad->uv_edges[i] = LoadEdgePoints2(aMesh, F, quad->edge[i], true); + if (!quad->uv_edges[i]) loadOk = false; + } + if (!loadOk) { + INFOS("StdMeshers_Quadrangle_2D::ComputeQuadPref - LoadEdgePoints failed"); + QuadDelete( quad ); + quad = 0; + return false; + } + + UVPtStruct* uv_eb = quad->uv_edges[0]; + UVPtStruct* uv_er = quad->uv_edges[1]; + UVPtStruct* uv_et = quad->uv_edges[2]; + UVPtStruct* uv_el = quad->uv_edges[3]; + + // arrays for normalized params + //cout<<"Dump B:"<X()<<","<Y()<<","<Z()<<")"<D0(uv_eb[0].param,a[0]); + c2d[0]->D0(uv_eb[nb-1].param,a[1]); + c2d[2]->D0(uv_et[nt-1].param,a[2]); + c2d[2]->D0(uv_et[0].param,a[3]); + //cout<<" a[0]("<0) { + // add top nodes + for(i=1; i<=dl; i++) + NodesL.SetValue(i+1,nl,uv_et[i].node); + // create and add needed nodes + TColgp_SequenceOfXY UVtmp; + for(i=1; i<=dl; i++) { + double x0 = npt.Value(i+1); + double x1 = x0; + // diagonal node + double y0 = npl.Value(i+1); + double y1 = npr.Value(i+1); + gp_XY UV = CalcUV(x0, x1, y0, y1, quad, a[0], a[1], a[2], a[3], + c2d[0], c2d[1], c2d[2], c2d[3]); + gp_Pnt P = S->Value(UV.X(),UV.Y()); + SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z()); + meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y()); + NodesL.SetValue(i+1,1,N); + if(UVL.Length()Value(UV.X(),UV.Y()); + SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z()); + meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y()); + NodesL.SetValue(i+1,j,N); + if( i==dl ) UVtmp.Append(UV); + } + } + for(i=1; i<=UVtmp.Length() && UVL.Length()X()<<","<Y()<<","<Z()<<")"; + // } + // cout<AddFace(NodesL.Value(i,j), NodesL.Value(i+1,j), + NodesL.Value(i+1,j+1), NodesL.Value(i,j+1)); + meshDS->SetMeshElementOnShape(F, geomFaceID); + } + else { + SMDS_MeshFace* F = + meshDS->AddFace(NodesL.Value(i,j), NodesL.Value(i,j+1), + NodesL.Value(i+1,j+1), NodesL.Value(i+1,j)); + meshDS->SetMeshElementOnShape(F, geomFaceID); + } + } + } + } + else { + // fill UVL using c2d + for(i=1; iD0(uv_el[i].param,p2d); + UVL.Append(p2d.XY()); + } + } + + // step2: create faces for right domain + StdMeshers_Array2OfNode NodesR(1,dr+1,1,nr); + // add right nodes + for(j=1; j<=nr; j++) + NodesR.SetValue(1,j,uv_er[nr-j].node); + if(dr>0) { + // add top nodes + for(i=1; i<=dr; i++) + NodesR.SetValue(i+1,1,uv_et[nt-1-i].node); + // create and add needed nodes + TColgp_SequenceOfXY UVtmp; + for(i=1; i<=dr; i++) { + double x0 = npt.Value(nt-i); + double x1 = x0; + // diagonal node + double y0 = npl.Value(i+1); + double y1 = npr.Value(i+1); + gp_XY UV = CalcUV(x0, x1, y0, y1, quad, a[0], a[1], a[2], a[3], + c2d[0], c2d[1], c2d[2], c2d[3]); + gp_Pnt P = S->Value(UV.X(),UV.Y()); + SMDS_MeshNode * N = meshDS->AddNode(P.X(), P.Y(), P.Z()); + meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y()); + NodesR.SetValue(i+1,nr,N); + if(UVR.Length()Value(UV.X(),UV.Y()); + SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z()); + meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y()); + NodesR.SetValue(i+1,j,N); + if( i==dr ) UVtmp.Prepend(UV); + } + } + for(i=1; i<=UVtmp.Length() && UVR.Length()AddFace(NodesR.Value(i,j), NodesR.Value(i+1,j), + NodesR.Value(i+1,j+1), NodesR.Value(i,j+1)); + meshDS->SetMeshElementOnShape(F, geomFaceID); + } + else { + SMDS_MeshFace* F = + meshDS->AddFace(NodesR.Value(i,j), NodesR.Value(i,j+1), + NodesR.Value(i+1,j+1), NodesR.Value(i+1,j)); + meshDS->SetMeshElementOnShape(F, geomFaceID); + } + } + } + } + else { + // fill UVR using c2d + for(i=1; iD0(uv_er[i].param,p2d); + UVR.Append(p2d.XY()); + } + } + + // step3: create faces for central domain + StdMeshers_Array2OfNode NodesC(1,nb,1,nbv); + // add first string using NodesL + for(i=1; i<=dl+1; i++) + NodesC.SetValue(1,i,NodesL(i,1)); + for(i=2; i<=nl; i++) + NodesC.SetValue(1,dl+i,NodesL(dl+1,i)); + // add last string using NodesR + for(i=1; i<=dr+1; i++) + NodesC.SetValue(nb,i,NodesR(i,nr)); + for(i=1; iD0(uv_eb[i-1].param,p2d); + } + // create and add needed nodes + // add linear layers + for(i=2; iValue(UV.X(),UV.Y()); + SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z()); + meshDS->SetNodeOnFace(N, geomFaceID, UV.X(), UV.Y()); + NodesC.SetValue(i,nbv-nnn+j,N); + } + } + // add diagonal layers + //cout<<"UVL.Length()="<Value(u,v); + SMDS_MeshNode* N = meshDS->AddNode(P.X(), P.Y(), P.Z()); + meshDS->SetNodeOnFace(N, geomFaceID, u, v); + NodesC.SetValue(j,i+1,N); + } + } + // create faces + for(i=1; iAddFace(NodesC.Value(i,j), NodesC.Value(i+1,j), + NodesC.Value(i+1,j+1), NodesC.Value(i,j+1)); + meshDS->SetMeshElementOnShape(F, geomFaceID); + } + else { + SMDS_MeshFace* F = + meshDS->AddFace(NodesC.Value(i,j), NodesC.Value(i,j+1), + NodesC.Value(i+1,j+1), NodesC.Value(i+1,j)); + meshDS->SetMeshElementOnShape(F, geomFaceID); + } + } + } + + QuadDelete(quad); + bool isOk = true; + return isOk; +} + + +//============================================================================= +/*! + * LoadEdgePoints2 + */ +//============================================================================= +UVPtStruct* StdMeshers_Quadrangle_2D::LoadEdgePoints2 (SMESH_Mesh & aMesh, + const TopoDS_Face& F, + const TopoDS_Edge& E, + bool IsReverse) +{ + //MESSAGE("StdMeshers_Quadrangle_2D::LoadEdgePoints"); + // --- IDNodes of first and last Vertex + TopoDS_Vertex VFirst, VLast; + TopExp::Vertices(E, VFirst, VLast); // corresponds to f and l + + ASSERT(!VFirst.IsNull()); + SMDS_NodeIteratorPtr lid = aMesh.GetSubMesh(VFirst)->GetSubMeshDS()->GetNodes(); + if (!lid->more()) { + MESSAGE ( "NO NODE BUILT ON VERTEX" ); + return 0; + } + const SMDS_MeshNode* idFirst = lid->next(); + + ASSERT(!VLast.IsNull()); + lid = aMesh.GetSubMesh(VLast)->GetSubMeshDS()->GetNodes(); + if (!lid->more()) { + MESSAGE ( "NO NODE BUILT ON VERTEX" ); + return 0; + } + const SMDS_MeshNode* idLast = lid->next(); + + // --- edge internal IDNodes (relies on good order storage, not checked) + + map params; + SMDS_NodeIteratorPtr ite = aMesh.GetSubMesh(E)->GetSubMeshDS()->GetNodes(); + + while(ite->more()) { + const SMDS_MeshNode* node = ite->next(); + const SMDS_EdgePosition* epos = + static_cast(node->GetPosition().get()); + double param = epos->GetUParameter(); + params[param] = node; + } + + int nbPoints = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes(); + if (nbPoints != params.size()) { + MESSAGE( "BAD NODE ON EDGE POSITIONS" ); + return 0; + } + UVPtStruct* uvslf = new UVPtStruct[nbPoints + 2]; + + double f, l; + Handle(Geom2d_Curve) C2d = BRep_Tool::CurveOnSurface(E, F, f, l); + + const TopoDS_Wire& W = BRepTools::OuterWire(F); + bool FisF = (F.Orientation()==TopAbs_FORWARD); + bool WisF = (W.Orientation()==TopAbs_FORWARD); + bool isForward = (E.Orientation()==TopAbs_FORWARD); + //if(isForward) cout<<"E is FORWARD"<Value(f); // first point = Vertex Forward + uvslf[0].x = p.X(); + uvslf[0].y = p.Y(); + uvslf[0].param = f; + uvslf[0].node = idFirst; + //MESSAGE("__ f "<::iterator itp = params.begin(); + for (int i = 1; i <= nbPoints; i++) { // nbPoints internal + double param = (*itp).first; + gp_Pnt2d p = C2d->Value(param); + uvslf[i].x = p.X(); + uvslf[i].y = p.Y(); + uvslf[i].param = param; + uvslf[i].node = (*itp).second; + //MESSAGE("__ "<Value(l); // last point = Vertex Reversed + uvslf[nbPoints + 1].x = p.X(); + uvslf[nbPoints + 1].y = p.Y(); + uvslf[nbPoints + 1].param = l; + uvslf[nbPoints + 1].node = idLast; + //MESSAGE("__ l "<Value(l); // first point = Vertex Reversed + uvslf[0].x = p.X(); + uvslf[0].y = p.Y(); + uvslf[0].param = l; + uvslf[0].node = idLast; + //MESSAGE("__ l "<::reverse_iterator itp = params.rbegin(); + for (int j = nbPoints; j >= 1; j--) { // nbPoints internal + double param = (*itp).first; + int i = nbPoints + 1 - j; + gp_Pnt2d p = C2d->Value(param); + uvslf[i].x = p.X(); + uvslf[i].y = p.Y(); + uvslf[i].param = param; + uvslf[i].node = (*itp).second; + //MESSAGE("__ "<Value(f); // last point = Vertex Forward + uvslf[nbPoints + 1].x = p.X(); + uvslf[nbPoints + 1].y = p.Y(); + uvslf[nbPoints + 1].param = f; + uvslf[nbPoints + 1].node = idFirst; + //MESSAGE("__ f "< - #include "StdMeshers_LocalLength.hxx" #include "StdMeshers_NumberOfSegments.hxx" #include "StdMeshers_Arithmetic1D.hxx" #include "StdMeshers_StartEndLength.hxx" #include "StdMeshers_Deflection1D.hxx" -#include +#include "StdMeshers_AutomaticLength.hxx" #include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" @@ -66,10 +62,13 @@ using namespace std; #include #include #include +#include #include #include +using namespace std; + //============================================================================= /*! * diff --git a/src/StdMeshers/StdMeshers_StartEndLength.cxx b/src/StdMeshers/StdMeshers_StartEndLength.cxx index 1d7016206..46320768f 100644 --- a/src/StdMeshers/StdMeshers_StartEndLength.cxx +++ b/src/StdMeshers/StdMeshers_StartEndLength.cxx @@ -25,11 +25,22 @@ // Module : SMESH // $Header$ -using namespace std; - #include "StdMeshers_StartEndLength.hxx" -#include "utilities.h" +#include "SMESH_Algo.hxx" +#include "SMESH_Mesh.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; //============================================================================= /*! @@ -43,7 +54,7 @@ StdMeshers_StartEndLength::StdMeshers_StartEndLength(int hypId, :SMESH_Hypothesis(hypId, studyId, gen) { _begLength = 1.; - _endLength = 1.; + _endLength = 10.; _name = "StartEndLength"; _param_algo_dim = 1; // is used by SMESH_Regular_1D } @@ -141,3 +152,49 @@ istream & operator >>(istream & load, StdMeshers_StartEndLength & hyp) { return hyp.LoadFrom( load ); } + +//================================================================================ +/*! + * \brief Initialize start and end length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ +//================================================================================ + +bool StdMeshers_StartEndLength::SetParametersByMesh(const SMESH_Mesh* theMesh, + const TopoDS_Shape& theShape) +{ + if ( !theMesh || theShape.IsNull() ) + return false; + + _begLength = _endLength = 0.; + + Standard_Real UMin, UMax; + TopLoc_Location L; + + int nbEdges = 0; + TopTools_IndexedMapOfShape edgeMap; + TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap ); + for ( int i = 1; i <= edgeMap.Extent(); ++i ) + { + const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( i )); + Handle(Geom_Curve) C = BRep_Tool::Curve(edge, L, UMin, UMax); + GeomAdaptor_Curve AdaptCurve(C); + + vector< double > params; + SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS(); + if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params )) + { + nbEdges++; + _begLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[0], params[1]); + int nb = params.size(); + _endLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[nb-2], params[nb-1]); + } + } + if ( nbEdges ) { + _begLength /= nbEdges; + _endLength /= nbEdges; + } + return nbEdges; +} diff --git a/src/StdMeshers/StdMeshers_StartEndLength.hxx b/src/StdMeshers/StdMeshers_StartEndLength.hxx index 05bd2e0bb..52a8a58b2 100644 --- a/src/StdMeshers/StdMeshers_StartEndLength.hxx +++ b/src/StdMeshers/StdMeshers_StartEndLength.hxx @@ -41,12 +41,21 @@ class StdMeshers_StartEndLength:public SMESH_Hypothesis double GetLength(bool isStartLength) const; - virtual ostream & SaveTo(ostream & save); - virtual istream & LoadFrom(istream & load); - friend ostream & operator <<(ostream & save, StdMeshers_StartEndLength & hyp); - friend istream & operator >>(istream & load, StdMeshers_StartEndLength & hyp); + virtual std::ostream & SaveTo(std::ostream & save); + virtual std::istream & LoadFrom(std::istream & load); + friend std::ostream & operator <<(std::ostream & save, StdMeshers_StartEndLength & hyp); + friend std::istream & operator >>(std::istream & load, StdMeshers_StartEndLength & hyp); - protected: + + /*! + * \brief Initialize start and end length by the mesh built on the geometry + * \param theMesh - the built mesh + * \param theShape - the geometry of interest + * \retval bool - true if parameter values have been successfully defined + */ + virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape); + +protected: double _begLength, _endLength; }; diff --git a/src/StdMeshersGUI/StdMeshersGUI_CreateStdHypothesisDlg.cxx b/src/StdMeshersGUI/StdMeshersGUI_CreateStdHypothesisDlg.cxx deleted file mode 100644 index 29205f4d1..000000000 --- a/src/StdMeshersGUI/StdMeshersGUI_CreateStdHypothesisDlg.cxx +++ /dev/null @@ -1,111 +0,0 @@ -// SMESH StdMeshersGUI : GUI for StdMeshers plugin -// -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org -// -// -// -// File : StdMeshersGUI_CreateStdHypothesisDlg.cxx -// Moved here from SMESHGUI_CreateStdHypothesisDlg.cxx -// Author : Nicolas REJNERI -// Module : SMESH -// $Header$ - -using namespace std; -#include "StdMeshersGUI_CreateStdHypothesisDlg.h" -#include "StdMeshersGUI_Parameters.h" -#include "SMESHGUI.h" -#include "SMESHGUI_Hypotheses.h" - -#include "utilities.h" - -#include "SUIT_MessageBox.h" -#include "SUIT_ResourceMgr.h" -#include "SUIT_OverrideCursor.h" -#include "SUIT_Desktop.h" - -//================================================================================= -// class : StdMeshersGUI_CreateStdHypothesisDlg() -// purpose : -//================================================================================= -StdMeshersGUI_CreateStdHypothesisDlg::StdMeshersGUI_CreateStdHypothesisDlg (const QString& hypType, - QWidget* parent, - const char* name, - bool /*modal*/, - WFlags fl) - : StdMeshersGUI_CreateHypothesisDlg (hypType, parent, name, true, fl) -{ - QString hypTypeStr; - if (hypType.compare("LocalLength") == 0) - hypTypeStr = "LOCAL_LENGTH"; - else if (hypType.compare("NumberOfSegments") == 0) - hypTypeStr = "NB_SEGMENTS"; - else if (hypType.compare("MaxElementArea") == 0) - hypTypeStr = "MAX_ELEMENT_AREA"; - else if (hypType.compare("MaxElementVolume") == 0) - hypTypeStr = "MAX_ELEMENT_VOLUME"; - else if (hypType.compare("StartEndLength") == 0) - hypTypeStr = "START_END_LENGTH"; - else if (hypType.compare("Deflection1D") == 0) - hypTypeStr = "DEFLECTION1D"; - else if (hypType.compare("Arithmetic1D") == 0) - hypTypeStr = "ARITHMETIC_1D"; - else if (hypType.compare("AutomaticLength") == 0) - hypTypeStr = "AUTOMATIC_LENGTH"; - else - return; - - QString caption( tr ( QString( "SMESH_%1_TITLE" ).arg( hypTypeStr ))); - QString hypTypeName( tr ( QString( "SMESH_%1_HYPOTHESIS" ).arg( hypTypeStr ))); - QString hypIconName( tr ( QString( "ICON_DLG_%1" ).arg( hypTypeStr ))); - - CreateDlgLayout(caption, - SMESHGUI::resourceMgr()->loadPixmap( "SMESH", hypIconName ), - hypTypeName); -} - -//================================================================================= -// function : ~StdMeshersGUI_CreateStdHypothesisDlg() -// purpose : Destroys the object and frees any allocated resources -//================================================================================= -StdMeshersGUI_CreateStdHypothesisDlg::~StdMeshersGUI_CreateStdHypothesisDlg() -{ - // no need to delete child widgets, Qt does it all for us -} -//================================================================================= -// function : FillParameters() -// purpose : -//================================================================================= -void StdMeshersGUI_CreateStdHypothesisDlg::GetParameters - (const QString & hypType, - std::list & params) -{ - StdMeshersGUI_Parameters::GetParameters( hypType, params ); -} - -//================================================================================= -// function : SetParameters() -// purpose : -//================================================================================= -bool StdMeshersGUI_CreateStdHypothesisDlg::SetParameters - (SMESH::SMESH_Hypothesis_ptr theHyp, const list & params) -{ - StdMeshersGUI_Parameters::SetParameters( theHyp, params ); - return true; -} diff --git a/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx index f763fbd9c..0d66dc53a 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.cxx @@ -19,8 +19,8 @@ StdMeshersGUI_DistrPreview::StdMeshersGUI_DistrPreview( QWidget* p, StdMeshers:: { myHypo = StdMeshers::StdMeshers_NumberOfSegments::_duplicate( h ); myVars.ChangeValue( 1 ) = new Expr_NamedUnknown( "t" ); - myCurve1 = insertCurve( QString() ); - myCurve2 = insertCurve( QString() ); + myDensity = insertCurve( QString() ); + myDistr = insertCurve( QString() ); myMsg = insertMarker( new QwtPlotMarker( this ) ); setMarkerPos( myMsg, 0.5, 0.5 ); setMarkerLabelPen( myMsg, QPen( Qt::red, 1 ) ); @@ -28,11 +28,16 @@ StdMeshersGUI_DistrPreview::StdMeshersGUI_DistrPreview( QWidget* p, StdMeshers:: f.setPointSize( 14 ); f.setBold( true ); setMarkerFont( myMsg, f ); - setCurvePen( myCurve1, QPen( Qt::red, 1 ) ); + setCurvePen( myDensity, QPen( Qt::red, 1 ) ); QColor dc = Qt::blue; - setCurvePen( myCurve2, QPen( dc, 1 ) ); - setCurveSymbol( myCurve2, QwtSymbol( QwtSymbol::XCross, QBrush( dc ), QPen( dc ), QSize( 5, 5 ) ) ); + setCurvePen( myDistr, QPen( dc, 1 ) ); + setCurveSymbol( myDistr, QwtSymbol( QwtSymbol::XCross, QBrush( dc ), QPen( dc ), QSize( 5, 5 ) ) ); + setAutoLegend( true ); + enableLegend( true ); + setLegendPos( Qwt::Bottom ); + setCurveTitle( myDensity, tr( "SMESH_DENSITY_FUNC" ) ); + setCurveTitle( myDistr, tr( "SMESH_DISTR" ) ); } StdMeshersGUI_DistrPreview::~StdMeshersGUI_DistrPreview() @@ -196,9 +201,9 @@ void StdMeshersGUI_DistrPreview::update() max_x = x[i]; } - setAxisScale( curveXAxis( myCurve1 ), min_x, max_x ); - setAxisScale( curveYAxis( myCurve1 ), min( 0.0, min_y ), max( 0.0, max_y ) ); - setCurveData( myCurve1, x, y, size ); + setAxisScale( curveXAxis( myDensity ), min_x, max_x ); + setAxisScale( curveYAxis( myDensity ), min( 0.0, min_y ), max( 0.0, max_y ) ); + setCurveData( myDensity, x, y, size ); if( x ) delete[] x; if( y ) @@ -213,19 +218,33 @@ void StdMeshersGUI_DistrPreview::update() x[i] = distr[i]; y[i] = 0; } - setCurveData( myCurve2, x, y, size ); + setCurveData( myDistr, x, y, size ); delete[] x; delete[] y; x = y = 0; - replot(); + + OSD::SetSignal( true ); + CASCatch_CatchSignals aCatchSignals; + aCatchSignals.Activate(); + + CASCatch_TRY + { + replot(); + } + CASCatch_CATCH(CASCatch_Failure) + { + aCatchSignals.Deactivate(); + Handle(CASCatch_Failure) aFail = CASCatch_Failure::Caught(); + } + aCatchSignals.Deactivate(); } void StdMeshersGUI_DistrPreview::showError() { - setAxisScale( curveXAxis( myCurve1 ), 0.0, 1.0 ); - setAxisScale( curveYAxis( myCurve1 ), 0.0, 1.0 ); - setCurveData( myCurve1, 0, 0, 0 ); - setCurveData( myCurve2, 0, 0, 0 ); + setAxisScale( curveXAxis( myDensity ), 0.0, 1.0 ); + setAxisScale( curveYAxis( myDensity ), 0.0, 1.0 ); + setCurveData( myDensity, 0, 0, 0 ); + setCurveData( myDistr, 0, 0, 0 ); setMarkerLabel( myMsg, tr( "SMESH_INVALID_FUNCTION" ) ); replot(); } diff --git a/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.h b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.h index 5a3551dae..224658823 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.h +++ b/src/StdMeshersGUI/StdMeshersGUI_DistrPreview.h @@ -48,7 +48,7 @@ private: bool myIsTable; Conversion myConv; SMESH::double_array myTableFunc; - long myCurve1, myCurve2, myMsg; + long myDensity, myDistr, myMsg; Handle(ExprIntrp_GenExp) myExpr; Expr_Array1OfNamedUnknown myVars; TColStd_Array1OfReal myValues; diff --git a/src/StdMeshersGUI/StdMeshersGUI_DistrTable.cxx b/src/StdMeshersGUI/StdMeshersGUI_DistrTable.cxx index db0b7f3ff..31eeae6fe 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_DistrTable.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_DistrTable.cxx @@ -26,9 +26,10 @@ // $Header$ #include "StdMeshersGUI_DistrTable.h" +#include + #include #include -#include #include //================================================================================= @@ -40,8 +41,8 @@ StdMeshersGUI_DistrTable::StdMeshersGUI_DistrTable( const int rows, QWidget* par { horizontalHeader()->setLabel( 0, "t" ); horizontalHeader()->setLabel( 1, "f(t)" ); - myArgV = new QDoubleValidator( 0.0, 1.0, 3, this ); - myFuncV = new QDoubleValidator( 0.0, 1E10, 3, this ); + myArgV = new QtxDblValidator( 0.0, 1.0, 3, this ); + myFuncV = new QtxDblValidator( 0.0, 1E20, 3, this ); } StdMeshersGUI_DistrTable::~StdMeshersGUI_DistrTable() @@ -70,6 +71,14 @@ void StdMeshersGUI_DistrTable::stopEditing( const bool accept ) endEdit( currEditRow(), currEditCol(), accept, false ); } +QWidget* StdMeshersGUI_DistrTable::beginEdit( int row, int col, bool replace ) +{ + QWidget* w = QTable::beginEdit( row, col, replace ); + if( w && w->inherits( "QLineEdit" ) ) + ( ( QLineEdit* )w )->selectAll(); + return w; +} + void StdMeshersGUI_DistrTable::edit( const int r, const int c ) { if( isEditing() ) @@ -265,8 +274,24 @@ void StdMeshersGUI_DistrTable::setData( const SMESH::double_array& d ) { stopEditing( false ); setNumRows( d.length()/2 ); + QString val; for( int i=0; ifixup( val ); + setText( i/2, i%2, val ); + } +} + +QtxDblValidator* StdMeshersGUI_DistrTable::argValidator() const +{ + return myArgV; +} + +QtxDblValidator* StdMeshersGUI_DistrTable::funcValidator() const +{ + return myFuncV; } //================================================================================= @@ -346,3 +371,4 @@ void StdMeshersGUI_DistrTableFrame::onButtonClicked() else if( sender()==button( REMOVE_ROW ) ) emit toEdit( REMOVE_ROW, table()->currentRow() ); } + diff --git a/src/StdMeshersGUI/StdMeshersGUI_DistrTable.h b/src/StdMeshersGUI/StdMeshersGUI_DistrTable.h index 6f6ca829a..a6f7f6106 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_DistrTable.h +++ b/src/StdMeshersGUI/StdMeshersGUI_DistrTable.h @@ -34,7 +34,7 @@ #include CORBA_SERVER_HEADER(SMESH_Mesh) class QButton; -class QDoubleValidator; +class QtxDblValidator; /*! * \brief Values corresponding to buttons for table resize @@ -65,17 +65,21 @@ public: void data( SMESH::double_array& ); void setData( const SMESH::double_array& ); + QtxDblValidator* argValidator() const; + QtxDblValidator* funcValidator() const; + protected: virtual QWidget* createEditor( int, int, bool ) const; virtual bool eventFilter( QObject*, QEvent* ); virtual void keyPressEvent( QKeyEvent* ); + virtual QWidget* beginEdit( int row, int col, bool replace ); virtual void edit( const int, const int ); private slots: void onEdit( TableButton, int ); private: - QDoubleValidator *myArgV, *myFuncV; + QtxDblValidator *myArgV, *myFuncV; }; @@ -122,6 +126,5 @@ private: StdMeshersGUI_DistrTable *myTable; }; - #endif diff --git a/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx index a071169ae..f190fb2ca 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -142,7 +143,7 @@ QFrame* StdMeshersGUI_NbSegmentsCreator::buildFrame() myConv->setColumnLayout( 0, Qt::Vertical ); QGridLayout* convLay = new QGridLayout( myConv->layout() ); convLay->addWidget( new QRadioButton( tr( "SMESH_EXP_MODE" ), myConv ), 0, 0 ); - convLay->addWidget( new QRadioButton( tr( "SMESH_CUT_NEG_MODE" ), myConv ), 1, 0 ); + convLay->addWidget( myCutNeg = new QRadioButton( tr( "SMESH_CUT_NEG_MODE" ), myConv ), 1, 0 ); myGroupLayout->addWidget( myConv, row, 1 ); row++; @@ -176,17 +177,59 @@ void StdMeshersGUI_NbSegmentsCreator::retrieveParams() const myExpr->setText( data.myExpr ); } -void StdMeshersGUI_NbSegmentsCreator::storeParams() const +QString StdMeshersGUI_NbSegmentsCreator::storeParams() const { NbSegmentsHypothesisData data; readParamsFromWidgets( data ); storeParamsToHypo( data ); + + QString valStr = QString::number( data.myNbSeg ) += "; "; + + enum DistrType + { + Regular, //!< equidistant distribution + Scale, //!< scale distribution + TabFunc, //!< distribution with density function presented by table + ExprFunc //!< distribution with density function presented by expression + }; + bool hasConv = false; + switch ( data.myDistrType ) { + case Regular : + valStr += tr("SMESH_DISTR_REGULAR"); + break; + case Scale : + valStr += tr("SMESH_NB_SEGMENTS_SCALE_PARAM") + " = " + QString::number( data.myScale ); + break; + case TabFunc : { + //valStr += tr("SMESH_TAB_FUNC"); + bool param = true; + for( int i=0; i < data.myTable.length(); i++, param = !param ) { + if ( param ) + valStr += "["; + valStr += QString::number( data.myTable[ i ]); + valStr += ( param ? "," : "]" ); + } + hasConv = true; + break; + } + case ExprFunc: + valStr += data.myExpr; + hasConv = true; + break; + } + if ( hasConv ) + if ( data.myConv ) + valStr += "; " + tr("SMESH_CUT_NEG_MODE"); + else + valStr += "; " + tr("SMESH_EXP_MODE"); + + return valStr; } bool StdMeshersGUI_NbSegmentsCreator::readParamsFromHypo( NbSegmentsHypothesisData& h_data ) const { StdMeshers::StdMeshers_NumberOfSegments_var h = - StdMeshers::StdMeshers_NumberOfSegments::_narrow( hypothesis() ); + StdMeshers::StdMeshers_NumberOfSegments::_narrow( initParamsHypothesis() ); HypothesisData* data = SMESH::GetHypothesisData( hypType() ); h_data.myName = isCreation() && data ? data->Label : ""; @@ -270,6 +313,19 @@ void StdMeshersGUI_NbSegmentsCreator::onValueChanged() { int distr = myDistr->currentItem(); +/* if( distr==2 ) //table func + myCutNeg->setText( tr( "SMESH_NO_CONV" ) ); + else if( distr==3 ) + myCutNeg->setText( tr( "SMESH_CUT_NEG_MODE" ) );*/ + + if( distr==2 && sender()==myConv ) //table func + { + myTable->table()->funcValidator()->setBottom( myConv->id( myConv->selected() )==0 ? -1E20 : 0 ); + SMESH::double_array arr; + myTable->table()->data( arr ); + myTable->table()->setData( arr ); //update data in table + } + myScale->setShown( distr==1 ); myLScale->setShown( distr==1 ); diff --git a/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h index 26ca09918..6d902fe80 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h +++ b/src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.h @@ -15,6 +15,7 @@ class StdMeshersGUI_DistrPreview; class QLineEdit; class QButtonGroup; class QGridLayout; +class QRadioButton; typedef struct { @@ -38,7 +39,7 @@ public: protected: virtual QFrame* buildFrame(); virtual void retrieveParams() const; - virtual void storeParams() const; + virtual QString storeParams() const; protected slots: virtual void onValueChanged(); @@ -59,6 +60,7 @@ private: QLabel *myLScale, *myLTable, *myLExpr, *myLConv, *myInfo; QGridLayout* myGroupLayout; int myTableRow, myPreviewRow; + QRadioButton* myCutNeg; }; #endif diff --git a/src/StdMeshersGUI/StdMeshersGUI_Parameters.cxx b/src/StdMeshersGUI/StdMeshersGUI_Parameters.cxx deleted file mode 100644 index 06c6540c8..000000000 --- a/src/StdMeshersGUI/StdMeshersGUI_Parameters.cxx +++ /dev/null @@ -1,622 +0,0 @@ -// SMESH StdMeshersGUI : GUI for standard meshers -// -// Copyright (C) 2003 CEA -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org or email : webmaster.salome@opencascade.org -// -// -// -// File : StdMeshersGUI_Parameters.cxx -// Module : SMESH -// $Header$ - -#include "StdMeshersGUI_Parameters.h" - -#include -#include -#include -#include - -#include -//#include - -using namespace std; - -#define VALUE_MAX 1.0e+15 // COORD_MAX -#define VALUE_MAX_2 (VALUE_MAX*VALUE_MAX) -#define VALUE_MAX_3 (VALUE_MAX*VALUE_MAX*VALUE_MAX) - -#define VALUE_SMALL 1.0e-15 -#define VALUE_SMALL_2 (VALUE_SMALL*VALUE_SMALL) -#define VALUE_SMALL_3 (VALUE_SMALL*VALUE_SMALL*VALUE_SMALL) - -//======================================================================= -//function : HasParameters -//purpose : -//======================================================================= - -bool StdMeshersGUI_Parameters::HasParameters (const QString& hypType) -{ - return ((hypType.compare("LocalLength") == 0) || - (hypType.compare("NumberOfSegments") == 0) || - (hypType.compare("MaxElementArea") == 0) || - (hypType.compare("MaxElementVolume") == 0) || - (hypType.compare("StartEndLength") == 0) || - (hypType.compare("Deflection1D") == 0) || - (hypType.compare("AutomaticLength") == 0) || - (hypType.compare("Arithmetic1D") == 0)); -} - -//======================================================================= -//function : SetInitValue -//purpose : -//======================================================================= - -void StdMeshersGUI_Parameters::SetInitValue(SMESHGUI_aParameterPtr param, - int initValue) -{ - SMESHGUI_intParameter* p = dynamic_cast(param.get()); - if ( p ) - { - p->InitValue() = initValue; - return; - } - - SMESHGUI_enumParameter* q = dynamic_cast(param.get()); - if( q ) - { - q->InitValue() = initValue; - return; - } - - SMESHGUI_boolParameter* b = dynamic_cast(param.get()); - if( b ) - { - b->InitValue() = (bool)initValue; - return; - } -} - -//======================================================================= -//function : SetInitValue -//purpose : -//======================================================================= - -void StdMeshersGUI_Parameters::SetInitValue(SMESHGUI_aParameterPtr param, - double initValue) -{ - SMESHGUI_doubleParameter* p = dynamic_cast(param.get()); - if ( p ) p->InitValue() = initValue; -} - -//======================================================================= -//function : SetInitValue -//purpose : -//======================================================================= - -void StdMeshersGUI_Parameters::SetInitValue(SMESHGUI_aParameterPtr param, - const char* initValue) -{ - SMESHGUI_strParameter* p = dynamic_cast(param.get()); - if ( p ) p->InitValue() = initValue; -} - -//======================================================================= -//function : SetInitValue -//purpose : -//======================================================================= -void StdMeshersGUI_Parameters::SetInitValue( SMESHGUI_aParameterPtr param, - SMESH::double_array& initValue) -{ - SMESHGUI_tableParameter* p = dynamic_cast(param.get()); - if( p ) - { - p->setRowCount( initValue.length()/2 ); - p->setData( initValue ); - } -} - -//================================================================================ -/*! - * \brief Macros to comfortably create SMESHGUI_aParameterPtr of different types - */ -//================================================================================ - -// SMESHGUI_doubleParameter( initValue, label, bottom, top, step, decimals ) -#define DOUBLE_PARAM(v,l,b,t,s,d) SMESHGUI_aParameterPtr(new SMESHGUI_doubleParameter(v,l,b,t,s,d)) -#define INT_PARAM(v,l,b,t) SMESHGUI_aParameterPtr(new SMESHGUI_intParameter(v,l,b,t)) -#define ENUM_PARAM(v,i,l) SMESHGUI_aParameterPtr(new SMESHGUI_enumParameter(v,i,l)) -#define STR_PARAM(i,l,preview) SMESHGUI_aParameterPtr(new SMESHGUI_strParameter(i,l,preview)) -#define BOOL_PARAM(i,l,preview) SMESHGUI_aParameterPtr(new SMESHGUI_boolParameter(i,l,preview)) - -//================================================================================ -/*! - * \brief Fill parameter list with default values - * \param hypType - The name of hypothesis type - * \param paramList - The list to fill - */ -//================================================================================ - -void StdMeshersGUI_Parameters::GetParameters (const QString& hypType, - list & paramList ) -{ - paramList.clear(); - - if (hypType.compare("LocalLength") == 0) - { - paramList.push_back( DOUBLE_PARAM (1.0, - QObject::tr("SMESH_LOCAL_LENGTH_PARAM"), - VALUE_SMALL, VALUE_MAX, 1.0, 6)); - } - else if (hypType.compare("NumberOfSegments") == 0) - { - //0-th parameter in list - paramList.push_back ( INT_PARAM (3, - QObject::tr("SMESH_NB_SEGMENTS_PARAM"), - 1, 9999 )); - QStringList types; - types.append( QObject::tr( "SMESH_DISTR_REGULAR" ) ); - types.append( QObject::tr( "SMESH_DISTR_SCALE" ) ); - types.append( QObject::tr( "SMESH_DISTR_TAB" ) ); - types.append( QObject::tr( "SMESH_DISTR_EXPR" ) ); - //string description of distribution types - - SMESHGUI_enumParameter* type = new SMESHGUI_enumParameter( types, 0, QObject::tr( "SMESH_DISTR_TYPE" ) ); - SMESHGUI_dependParameter::ShownMap& aMap = type->shownMap(); - aMap[0].append( 0 ); // if DistrType=0 (regular), then number of segments and types are shown (0-th and 1-th) - aMap[0].append( 1 ); - aMap[1].append( 0 ); // if DistrType=1 (scale), then number of segments, types and scale are shown - aMap[1].append( 1 ); - aMap[1].append( 2 ); - aMap[2].append( 0 ); // if DistrType=2 (table), then number of segments, types, table and exponent are shown - aMap[2].append( 1 ); - aMap[2].append( 3 ); - aMap[2].append( 5 ); - aMap[3].append( 0 ); // if DistrType=3 (expression), then number of segments, types, expression and exponent are shown - aMap[3].append( 1 ); - aMap[3].append( 4 ); - aMap[3].append( 5 ); - //1-th parameter in list - paramList.push_back ( SMESHGUI_aParameterPtr( type ) ); - - //2-th parameter in list - paramList.push_back ( DOUBLE_PARAM (1.0, - QObject::tr("SMESH_NB_SEGMENTS_SCALE_PARAM"), - VALUE_SMALL, VALUE_MAX, 0.1, 6 )); - SMESHGUI_tableParameter* tab = new SMESHGUI_tableParameter( 0.0, QObject::tr( "SMESH_TAB_FUNC" ), true ); - tab->setRowCount( 5 ); - tab->setColCount( 2 ); - //default size of table: 5x2 - - tab->setColName( 0, "t" ); - tab->setColName( 1, "f(t)" ); - tab->setValidator( 0, 0.0, 1.0, 3 ); - tab->setValidator( 1, 1E-7, 1E+300, 3 ); - tab->setEditRows( true ); - - //3-th parameter in list - paramList.push_back ( SMESHGUI_aParameterPtr( tab ) ); - - //4-th parameter in list - paramList.push_back ( STR_PARAM ( "", QObject::tr( "SMESH_EXPR_FUNC" ), true ) ); - - //5-th parameter in list - paramList.push_back ( BOOL_PARAM ( false, QObject::tr( "SMESH_EXP_MODE" ), true ) ); - } - else if (hypType.compare("Arithmetic1D") == 0) - { - paramList.push_back( DOUBLE_PARAM ( 1.0, - QObject::tr("SMESH_START_LENGTH_PARAM"), - VALUE_SMALL, VALUE_MAX, 1, 6)); - paramList.push_back( DOUBLE_PARAM ( 10.0, - QObject::tr("SMESH_END_LENGTH_PARAM"), - VALUE_SMALL, VALUE_MAX, 1, 6)); - } - else if (hypType.compare("MaxElementArea") == 0) - { - paramList.push_back( DOUBLE_PARAM (1.0, - QObject::tr("SMESH_MAX_ELEMENT_AREA_PARAM"), - VALUE_SMALL_2, VALUE_MAX_2, 1.0, 6)); - } - else if (hypType.compare("MaxElementVolume") == 0) - { - paramList.push_back( DOUBLE_PARAM ( 1.0, - QObject::tr("SMESH_MAX_ELEMENT_VOLUME_PARAM"), - VALUE_SMALL_3, VALUE_MAX_3, 1.0, 6)); - } - else if (hypType.compare("StartEndLength") == 0) - { - paramList.push_back( DOUBLE_PARAM ( 1.0, - QObject::tr("SMESH_START_LENGTH_PARAM"), - VALUE_SMALL, VALUE_MAX, 1, 6)); - paramList.push_back( DOUBLE_PARAM ( 10.0, - QObject::tr("SMESH_END_LENGTH_PARAM"), - VALUE_SMALL, VALUE_MAX, 1, 6)); - } - else if (hypType.compare("Deflection1D") == 0) - { - paramList.push_back( DOUBLE_PARAM ( 1.0, - QObject::tr("SMESH_DEFLECTION1D_PARAM"), - VALUE_SMALL, VALUE_MAX, 1, 6)); - } - else if (hypType.compare("AutomaticLength") == 0) - { - SMESHGUI_aParameter * param = - new StdMeshersGUI_doubleSliderParameter ( QObject::tr("SMESH_FINENESS_PARAM"), - "0 ", " 1", - 0.0, 0.0, 1.0, 0.05); - paramList.push_back( SMESHGUI_aParameterPtr( param )); - } -} - -//================================================================================ -/*! - * \brief Fill parameter list with real values the hypothesis has - * \param theHyp - The hypothesis to retrieve parameter values from - * \param paramList - The list to fill - */ -//================================================================================ - -void StdMeshersGUI_Parameters::GetParameters (SMESH::SMESH_Hypothesis_ptr theHyp, - list & paramList ) -{ - paramList.clear(); - - if (theHyp->_is_nil()) return; - - QString hypType = theHyp->GetName(); - GetParameters( hypType, paramList ); // get default parameters - if ( paramList.empty() ) - return; - - // set current values - if (hypType.compare("LocalLength") == 0) - { - StdMeshers::StdMeshers_LocalLength_var LL = - StdMeshers::StdMeshers_LocalLength::_narrow(theHyp); - SetInitValue( paramList.front(), LL->GetLength() ); - } - else if (hypType.compare("NumberOfSegments") == 0) - { - StdMeshers::StdMeshers_NumberOfSegments_var NOS = - StdMeshers::StdMeshers_NumberOfSegments::_narrow(theHyp); - - list::iterator anIt = paramList.begin(); - SetInitValue( *anIt, (int) NOS->GetNumberOfSegments()); anIt++; - int DType = (int) NOS->GetDistrType(); - SetInitValue( *anIt, DType ); anIt++; - - if( DType==1 ) - SetInitValue( *anIt, NOS->GetScaleFactor()); - anIt++; - - if( DType==2 ) - { - SMESH::double_array* tab_func = NOS->GetTableFunction(); - SetInitValue( *anIt, *tab_func ); - delete tab_func; - } - anIt++; - - if( DType==3 ) - { - char* expr_func = NOS->GetExpressionFunction(); - SetInitValue( *anIt, expr_func ); - //delete expr_func; - } - anIt++; - - if( DType==2 || DType==3 ) - SetInitValue( *anIt, (bool)NOS->IsExponentMode()); - } - else if (hypType.compare("Arithmetic1D") == 0) - { - StdMeshers::StdMeshers_Arithmetic1D_var hyp = - StdMeshers::StdMeshers_Arithmetic1D::_narrow(theHyp); - SetInitValue( paramList.front(), hyp->GetLength( true )) ; - SetInitValue( paramList.back(), hyp->GetLength( false )) ; - } - else if (hypType.compare("MaxElementArea") == 0) - { - StdMeshers::StdMeshers_MaxElementArea_var MEA = - StdMeshers::StdMeshers_MaxElementArea::_narrow(theHyp); - SetInitValue( paramList.front(), MEA->GetMaxElementArea() ); - } - else if (hypType.compare("MaxElementVolume") == 0) - { - StdMeshers::StdMeshers_MaxElementVolume_var MEV = - StdMeshers::StdMeshers_MaxElementVolume::_narrow(theHyp); - SetInitValue( paramList.front(), MEV->GetMaxElementVolume() ); - } - else if (hypType.compare("StartEndLength") == 0) - { - StdMeshers::StdMeshers_StartEndLength_var hyp = - StdMeshers::StdMeshers_StartEndLength::_narrow(theHyp); - SetInitValue( paramList.front(), hyp->GetLength( true )); - SetInitValue( paramList.back(), hyp->GetLength( false )); - } - else if (hypType.compare("Deflection1D") == 0) - { - StdMeshers::StdMeshers_Deflection1D_var hyp = - StdMeshers::StdMeshers_Deflection1D::_narrow(theHyp); - SetInitValue( paramList.back(), hyp->GetDeflection()) ; - } - else if (hypType.compare("AutomaticLength") == 0) - { - StdMeshers::StdMeshers_AutomaticLength_var hyp = - StdMeshers::StdMeshers_AutomaticLength::_narrow(theHyp); - SetInitValue( paramList.back(), hyp->GetFineness()); - } -} - -//================================================================================ -/*! - * \brief Return parameter values as a string - * \param hyp - not used - * \param paramList - list of parameter values - * \param params - output string - */ -//================================================================================ - -void StdMeshersGUI_Parameters::GetParameters (SMESH::SMESH_Hypothesis_ptr , - const list& paramList, - QString& params) -{ - params = ""; - list::const_iterator paramIt = paramList.begin(); - for ( ; paramIt != paramList.end(); paramIt++) { - if (params.compare("")) params += " ; "; - - SMESHGUI_aParameter::Type t = (*paramIt)->GetType(); - if( t==SMESHGUI_aParameter::DOUBLE ) - { - double aDoubleValue = 0.; - (*paramIt)->GetNewDouble(aDoubleValue); - params += QString::number(aDoubleValue); - } - else if( t==SMESHGUI_aParameter::STRING || t==SMESHGUI_aParameter::ENUM ) - { - QString aStrValue( "" ); - (*paramIt)->GetNewText(aStrValue); - params += aStrValue.simplifyWhiteSpace(); - } - else if( t==SMESHGUI_aParameter::TABLE ) - { - params += "TABLE"; - } - else - { - int aIntValue = 0; - (*paramIt)->GetNewInt(aIntValue); - params += QString::number(aIntValue); - } - } -} - -//======================================================================= -//function : SetParameters -//purpose : -//======================================================================= - -//================================================================================ -/*! - * \brief Set parameter values from the list into a hypothesis - * \param theHyp - The hypothesis to modify - * \param paramList - list of parameter values - * \retval bool - true if any parameter value changed - */ -//================================================================================ - -bool StdMeshersGUI_Parameters::SetParameters(SMESH::SMESH_Hypothesis_ptr theHyp, - const list & paramList ) -{ - if (theHyp->_is_nil() || paramList.empty()) return false; - - bool modified = false; - - QString hypType = theHyp->GetName(); - - if (hypType.compare("LocalLength") == 0) - { - StdMeshers::StdMeshers_LocalLength_var LL = - StdMeshers::StdMeshers_LocalLength::_narrow(theHyp); - double length = LL->GetLength(); - modified = paramList.front()->GetNewDouble( length ); - LL->SetLength(length); - } - else if (hypType.compare("NumberOfSegments") == 0) - { - StdMeshers::StdMeshers_NumberOfSegments_var NOS = - StdMeshers::StdMeshers_NumberOfSegments::_narrow(theHyp); - - list::const_iterator anIt = paramList.begin(); - int NbSeg, DType; - double Scale; - SMESH::double_array TabF; - QString exprF; - int expType; - - modified = (*anIt)->GetNewInt( NbSeg ); anIt++; - modified = (*anIt)->GetNewInt( DType ) || modified; anIt++; - modified = (*anIt)->GetNewDouble( Scale ) || modified; anIt++; - SMESHGUI_aParameterPtr p = *anIt; - ((SMESHGUI_tableParameter*)p.get())->data( TabF ); anIt++; modified = true; - modified = (*anIt)->GetNewText( exprF ) || modified; anIt++; - modified = (*anIt)->GetNewInt( expType ) || modified; - - NOS->SetNumberOfSegments( NbSeg ); - NOS->SetDistrType( DType ); - if( DType==1 ) - NOS->SetScaleFactor( Scale ); - if( DType==2 ) - NOS->SetTableFunction( TabF ); - if( DType==3 ) - NOS->SetExpressionFunction( CORBA::string_dup( exprF.latin1() ) ); - if( DType==2 || DType==3 ) - NOS->SetExponentMode( (bool)expType ); - } - else if (hypType.compare("Arithmetic1D") == 0) - { - if ( paramList.size() != 2 ) - return false; - StdMeshers::StdMeshers_Arithmetic1D_var hyp = - StdMeshers::StdMeshers_Arithmetic1D::_narrow(theHyp); - double begLength = hyp->GetLength( true ) ; - double endLength = hyp->GetLength( false ) ; - modified = paramList.front()->GetNewDouble( begLength ); - modified = paramList.back()->GetNewDouble( endLength ) || modified; - hyp->SetLength( begLength, true ); - hyp->SetLength( endLength, false ); - } - else if (hypType.compare("MaxElementArea") == 0) - { - StdMeshers::StdMeshers_MaxElementArea_var MEA = - StdMeshers::StdMeshers_MaxElementArea::_narrow(theHyp); - double MaxArea = MEA->GetMaxElementArea(); - modified = paramList.front()->GetNewDouble( MaxArea ); - MEA->SetMaxElementArea(MaxArea); - } - else if (hypType.compare("MaxElementVolume") == 0) - { - StdMeshers::StdMeshers_MaxElementVolume_var MEV = - StdMeshers::StdMeshers_MaxElementVolume::_narrow(theHyp); - double MaxVolume = MEV->GetMaxElementVolume() ; - modified = paramList.front()->GetNewDouble( MaxVolume ); - MEV->SetMaxElementVolume(MaxVolume); - } - else if (hypType.compare("StartEndLength") == 0) - { - if ( paramList.size() != 2 ) - return false; - StdMeshers::StdMeshers_StartEndLength_var hyp = - StdMeshers::StdMeshers_StartEndLength::_narrow(theHyp); - double begLength = hyp->GetLength( true ) ; - double endLength = hyp->GetLength( false ) ; - modified = paramList.front()->GetNewDouble( begLength ); - modified = paramList.back()->GetNewDouble( endLength ) || modified; - hyp->SetLength( begLength, true ); - hyp->SetLength( endLength, false ); - } - else if (hypType.compare("Deflection1D") == 0) - { - StdMeshers::StdMeshers_Deflection1D_var hyp = - StdMeshers::StdMeshers_Deflection1D::_narrow(theHyp); - double value = hyp->GetDeflection() ; - modified = paramList.front()->GetNewDouble( value ); - hyp->SetDeflection( value ); - } - else if (hypType.compare("AutomaticLength") == 0) - { - StdMeshers::StdMeshers_AutomaticLength_var hyp = - StdMeshers::StdMeshers_AutomaticLength::_narrow(theHyp); - double value = hyp->GetFineness() ; - modified = paramList.front()->GetNewDouble( value ); - hyp->SetFineness( value ); - } - return modified ; -} - -//================================================================================ -/*! - * \brief Widget: slider with left and right labels - */ -//================================================================================ - -class StdMeshersGUI_SliderWith2Lables: public QHBox -{ -public: - StdMeshersGUI_SliderWith2Lables( const QString& leftLabel, - const QString& rightLabel, - QWidget * parent =0, - const char * name=0 ); - QSlider * getSlider() const { return _slider; } -private: - QSlider * _slider; -}; - -StdMeshersGUI_SliderWith2Lables::StdMeshersGUI_SliderWith2Lables( const QString& leftLabel, - const QString& rightLabel, - QWidget * parent, - const char * name ) - :QHBox(parent,name) -{ - if ( !leftLabel.isEmpty() ) - (new QLabel( this ))->setText( leftLabel ); - - _slider = new QSlider( Horizontal, this ); - - if ( !rightLabel.isEmpty() ) - (new QLabel( this ))->setText( rightLabel ); -} - -//================================================================================ -/*! - * \brief Constructor - * \param label - main label - * \param leftLabel - label to the left of slider - * \param rightLabel - label to the right of slider - * \param initValue - initial slider value - * \param bottom - least slider value - * \param top - maximal slider value - * \param precision - slider value precision - */ -//================================================================================ - -StdMeshersGUI_doubleSliderParameter:: -StdMeshersGUI_doubleSliderParameter (const QString& label, - const QString& leftLabel, - const QString& rightLabel, - const double initValue, - const double bottom, - const double top , - const double precision) - :SMESHGUI_doubleParameter(initValue,label,bottom,top,precision), - _leftLabel(leftLabel), _rightLabel(rightLabel) -{ -} - -QWidget* StdMeshersGUI_doubleSliderParameter::CreateWidget( QWidget* parent ) const -{ - return new StdMeshersGUI_SliderWith2Lables( _leftLabel, _rightLabel, parent ); -} - -void StdMeshersGUI_doubleSliderParameter::InitializeWidget( QWidget* aWidget) const -{ - StdMeshersGUI_SliderWith2Lables * paramWidget = - dynamic_cast (aWidget); - if ( paramWidget && paramWidget->getSlider() ) - { - QSlider * slider = paramWidget->getSlider(); - slider->setRange( 0, toInt( _top )); - slider->setValue( toInt( _initValue )); - } -} - -void StdMeshersGUI_doubleSliderParameter::TakeValue( QWidget* aWidget) -{ - StdMeshersGUI_SliderWith2Lables * paramWidget = - dynamic_cast (aWidget); - if ( paramWidget && paramWidget->getSlider() ) - { - int val = paramWidget->getSlider()->value(); - _newValue = Bottom() + val * Step(); - } -} -int StdMeshersGUI_doubleSliderParameter::toInt( double val ) const -{ - return (int) ceil(( val - _bottom ) / _step ); -} diff --git a/src/StdMeshersGUI/StdMeshersGUI_Parameters.h b/src/StdMeshersGUI/StdMeshersGUI_Parameters.h deleted file mode 100644 index 87dc7a45b..000000000 --- a/src/StdMeshersGUI/StdMeshersGUI_Parameters.h +++ /dev/null @@ -1,87 +0,0 @@ -// SMESH StdMeshersGUI : GUI for standard meshers -// -// Copyright (C) 2003 CEA -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org or email : webmaster.salome@opencascade.org -// -// -// -// File : StdMeshersGUI_Parameters.h -// Module : SMESH -// $Header$ - -#ifndef STDMESHERSGUI_PARAMETERS_H -#define STDMESHERSGUI_PARAMETERS_H - -#include -#include CORBA_SERVER_HEADER(SMESH_BasicHypothesis) -#include CORBA_SERVER_HEADER(SMESH_Mesh) - -#include "SMESHGUI_aParameter.h" - -#include -#include - -class StdMeshersGUI_Parameters -{ - public: - static bool HasParameters (const QString& hypType); - - static void GetParameters (const QString& hypType, - std::list & params ); - - static void GetParameters (SMESH::SMESH_Hypothesis_ptr hyp, - std::list & params ); - static void GetParameters (SMESH::SMESH_Hypothesis_ptr hyp, - const std::list & paramList, - QString& params); - - static bool SetParameters(SMESH::SMESH_Hypothesis_ptr hyp, - const std::list & params ); - - static void SetInitValue(SMESHGUI_aParameterPtr param, - int initValue); - static void SetInitValue(SMESHGUI_aParameterPtr param, - double initValue); - static void SetInitValue(SMESHGUI_aParameterPtr param, - const char* initValue); - static void SetInitValue(SMESHGUI_aParameterPtr param, - SMESH::double_array& initValue); -}; - -/*! - * \brief This class provides double parameter with slider control - */ -class StdMeshersGUI_doubleSliderParameter: public SMESHGUI_doubleParameter -{ -public: - StdMeshersGUI_doubleSliderParameter(const QString& label = QString::null, - const QString& leftLabel = QString::null, - const QString& rightLabel = QString::null, - const double initValue = 0.0, - const double bottom = 0, - const double top = 1, - const double precision = 0.1); - virtual QWidget* CreateWidget( QWidget* ) const; - virtual void InitializeWidget( QWidget* ) const; - virtual void TakeValue( QWidget* ); - int toInt( double val ) const; -private: - QString _leftLabel, _rightLabel; -}; - -#endif diff --git a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx index d39c223c1..33abb0698 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx @@ -39,6 +39,9 @@ #include CORBA_SERVER_HEADER(SMESH_Mesh) #include +#include +#include +#include const double VALUE_MAX = 1.0e+15, // COORD_MAX @@ -72,7 +75,7 @@ void StdMeshersGUI_StdHypothesisCreator::retrieveParams() const //here this method must be empty because buildStdParam sets values itself } -void StdMeshersGUI_StdHypothesisCreator::storeParams() const +QString StdMeshersGUI_StdHypothesisCreator::storeParams() const { ListOfStdParams params; bool res = getStdParamFromDlg( params ); @@ -82,6 +85,8 @@ void StdMeshersGUI_StdHypothesisCreator::storeParams() const params.remove( params.begin() ); } + QString valueStr = stdParamValues( params ); + if( res && !params.isEmpty() ) { if( hypType()=="LocalLength" ) @@ -128,7 +133,15 @@ void StdMeshersGUI_StdHypothesisCreator::storeParams() const h->SetDeflection( params[0].myValue.toDouble() ); } + else if( hypType()=="AutomaticLength" ) + { + StdMeshers::StdMeshers_AutomaticLength_var h = + StdMeshers::StdMeshers_AutomaticLength::_narrow( hypothesis() ); + + h->SetFineness( params[0].myValue.toDouble() ); + } } + return valueStr; } bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const @@ -145,64 +158,75 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const p.append( item ); } + SMESH::SMESH_Hypothesis_var hyp = initParamsHypothesis(); + if( hypType()=="LocalLength" ) { StdMeshers::StdMeshers_LocalLength_var h = - StdMeshers::StdMeshers_LocalLength::_narrow( hypothesis() ); + StdMeshers::StdMeshers_LocalLength::_narrow( hyp ); item.myName = tr("SMESH_LOCAL_LENGTH_PARAM"); - item.myValue = isCreation() ? 1.0 : h->GetLength(); + item.myValue = h->GetLength(); p.append( item ); } else if( hypType()=="Arithmetic1D" ) { StdMeshers::StdMeshers_Arithmetic1D_var h = - StdMeshers::StdMeshers_Arithmetic1D::_narrow( hypothesis() ); + StdMeshers::StdMeshers_Arithmetic1D::_narrow( hyp ); item.myName = tr( "SMESH_START_LENGTH_PARAM" ); - item.myValue = isCreation() ? 1.0 : h->GetLength( true ); + item.myValue = h->GetLength( true ); p.append( item ); item.myName = tr( "SMESH_END_LENGTH_PARAM" ); - item.myValue = isCreation() ? 10.0 : h->GetLength( false ); + item.myValue = h->GetLength( false ); p.append( item ); } else if( hypType()=="MaxElementArea" ) { StdMeshers::StdMeshers_MaxElementArea_var h = - StdMeshers::StdMeshers_MaxElementArea::_narrow( hypothesis() ); + StdMeshers::StdMeshers_MaxElementArea::_narrow( hyp ); item.myName = tr( "SMESH_MAX_ELEMENT_AREA_PARAM" ); - item.myValue = isCreation() ? 1.0 : h->GetMaxElementArea(); + item.myValue = h->GetMaxElementArea(); p.append( item ); } else if( hypType()=="MaxElementVolume" ) { StdMeshers::StdMeshers_MaxElementVolume_var h = - StdMeshers::StdMeshers_MaxElementVolume::_narrow( hypothesis() ); + StdMeshers::StdMeshers_MaxElementVolume::_narrow( hyp ); item.myName = tr( "SMESH_MAX_ELEMENT_VOLUME_PARAM" ); - item.myValue = isCreation() ? 1.0 : h->GetMaxElementVolume(); + item.myValue = h->GetMaxElementVolume(); p.append( item ); } else if( hypType()=="StartEndLength" ) { StdMeshers::StdMeshers_StartEndLength_var h = - StdMeshers::StdMeshers_StartEndLength::_narrow( hypothesis() ); + StdMeshers::StdMeshers_StartEndLength::_narrow( hyp ); item.myName = tr( "SMESH_START_LENGTH_PARAM" ); - item.myValue = isCreation() ? 1.0 : h->GetLength( true ); + item.myValue = h->GetLength( true ); p.append( item ); item.myName = tr( "SMESH_END_LENGTH_PARAM" ); - item.myValue = isCreation() ? 10.0 : h->GetLength( false ); + item.myValue = h->GetLength( false ); p.append( item ); } else if( hypType()=="Deflection1D" ) { StdMeshers::StdMeshers_Deflection1D_var h = - StdMeshers::StdMeshers_Deflection1D::_narrow( hypothesis() ); + StdMeshers::StdMeshers_Deflection1D::_narrow( hyp ); item.myName = tr( "SMESH_DEFLECTION1D_PARAM" ); - item.myValue = isCreation() ? 1.0 : h->GetDeflection(); + item.myValue = h->GetDeflection(); + p.append( item ); + } + else if( hypType()=="AutomaticLength" ) + { + StdMeshers::StdMeshers_AutomaticLength_var h = + StdMeshers::StdMeshers_AutomaticLength::_narrow( hyp ); + + item.myName = tr( "SMESH_FINENESS_PARAM" ); + item.myValue = h->GetFineness(); p.append( item ); } else @@ -267,6 +291,7 @@ QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) cons types.insert( "StartEndLength", "START_END_LENGTH" ); types.insert( "Deflection1D", "DEFLECTION1D" ); types.insert( "Arithmetic1D", "ARITHMETIC_1D" ); + types.insert( "AutomaticLength", "AUTOMATIC_LENGTH" ); } QString res; @@ -275,3 +300,65 @@ QString StdMeshersGUI_StdHypothesisCreator::hypTypeName( const QString& t ) cons return res; } + +//================================================================================ +/*! + * \brief Widget: slider with left and right labels + */ +//================================================================================ + +class TDoubleSliderWith2Lables: public QHBox +{ +public: + TDoubleSliderWith2Lables( const QString& leftLabel, const QString& rightLabel, + const double initValue, const double bottom, + const double top , const double precision, + QWidget * parent=0 , const char * name=0 ) + :QHBox(parent,name), _bottom(bottom), _precision(precision) + { + if ( !leftLabel.isEmpty() ) (new QLabel( this ))->setText( leftLabel ); + _slider = new QSlider( Horizontal, this ); + _slider->setRange( 0, toInt( top )); + _slider->setValue( toInt( initValue )); + if ( !rightLabel.isEmpty() ) (new QLabel( this ))->setText( rightLabel ); + } + double value() const { return _bottom + _slider->value() * _precision; } + QSlider * getSlider() const { return _slider; } + int toInt( double val ) const { return (int) ceil(( val - _bottom ) / _precision ); } +private: + double _bottom, _precision; + QSlider * _slider; +}; + +//======================================================================= +//function : getCustomWidget +//purpose : +//======================================================================= + +QWidget* StdMeshersGUI_StdHypothesisCreator::getCustomWidget( const StdParam & param, + QWidget* parent) const +{ + if ( hypType()=="AutomaticLength" && param.myValue.type() == QVariant::Double ) + return new TDoubleSliderWith2Lables( "0 ", " 1", param.myValue.toDouble(), + 0, 1, 0.01, parent ); + + return 0; +} + +//======================================================================= +//function : getParamFromCustomWidget +//purpose : +//======================================================================= + +bool StdMeshersGUI_StdHypothesisCreator::getParamFromCustomWidget( StdParam & param, + QWidget* widget) const +{ + if ( hypType()=="AutomaticLength" ) { + TDoubleSliderWith2Lables* w = dynamic_cast( widget ); + if ( w ) { + param.myValue = w->value(); + return true; + } + } + return false; +} diff --git a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h index d818ec5fe..216324cab 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h +++ b/src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.h @@ -46,12 +46,14 @@ public: protected: virtual QFrame* buildFrame (); virtual void retrieveParams() const; - virtual void storeParams () const; + virtual QString storeParams () const; virtual bool stdParams ( ListOfStdParams& ) const; virtual void attuneStdWidget( QWidget*, const int ) const; virtual QString caption() const; virtual QPixmap icon() const; virtual QString type() const; + virtual QWidget* getCustomWidget( const StdParam&, QWidget* ) const; + virtual bool getParamFromCustomWidget( StdParam& , QWidget* ) const; private: QString hypTypeName( const QString& ) const; diff --git a/src/StdMeshersGUI/StdMeshers_icons.po b/src/StdMeshersGUI/StdMeshers_icons.po deleted file mode 100644 index 64fe98459..000000000 --- a/src/StdMeshersGUI/StdMeshers_icons.po +++ /dev/null @@ -1,113 +0,0 @@ -# This is a Qt message file in .po format. Each msgid starts with -# a scope. This scope should *NOT* be translated - eg. "Foo::Bar" -# would be translated to "Pub", not "Foo::Pub". -msgid "" -msgstr "" -"Project-Id-Version: PROJECT VERSION\n" -"POT-Creation-Date: 2002-05-28 10:57:43 AM CEST\n" -"PO-Revision-Date: YYYY-MM-DD\n" -"Last-Translator: FULLNAME \n" -"Content-Type: text/plain; charset=iso-8859-1\n" - - -#Select Icon -msgid "ICON_SELECT" -msgstr "select1.png" - - -#----------------------------------------------------------- -# Hypothesis -#----------------------------------------------------------- - -#Hypo Local Length -msgid "ICON_DLG_LOCAL_LENGTH" -msgstr "mesh_hypo_length.png" - -#Hypo Nb Segments -msgid "ICON_DLG_NB_SEGMENTS" -msgstr "mesh_hypo_segment.png" - -#Hypo Max Area -msgid "ICON_DLG_MAX_ELEMENT_AREA" -msgstr "mesh_hypo_area.png" - -#Hypo Max Volume -msgid "ICON_DLG_MAX_ELEMENT_VOLUME" -msgstr "mesh_hypo_volume.png" - -#Hypo Start End Length -msgid "ICON_DLG_START_END_LENGTH" -msgstr "mesh_hypo_length.png" - -#Hypo deflection 1D -msgid "ICON_DLG_DEFLECTION1D" -msgstr "mesh_hypo_length.png" - -#Hypo Geometric 1D -msgid "ICON_DLG_GEOMETRIC_1D" -msgstr "mesh_hypo_length.png" - -#Hypo Arithmetic 1D -msgid "ICON_DLG_ARITHMETIC_1D" -msgstr "mesh_hypo_length.png" - - -#----------------------------------------------------------- -# ObjectBrowser -#----------------------------------------------------------- - -#mesh_tree_algo_regular -msgid "ICON_SMESH_TREE_ALGO_Regular_1D" -msgstr "mesh_tree_algo_regular.png" - -#mesh_tree_algo_hexa -msgid "ICON_SMESH_TREE_ALGO_Hexa_3D" -msgstr "mesh_tree_algo_hexa.png" - -#mesh_tree_algo_mefisto -msgid "ICON_SMESH_TREE_ALGO_MEFISTO_2D" -msgstr "mesh_tree_algo_mefisto.png" - -#mesh_tree_algo_quad -msgid "ICON_SMESH_TREE_ALGO_Quadrangle_2D" -msgstr "mesh_tree_algo_quad.png" - -#mesh_tree_hypo_area -msgid "ICON_SMESH_TREE_HYPO_MaxElementArea" -msgstr "mesh_tree_hypo_area.png" - -#mesh_tree_hypo_length -msgid "ICON_SMESH_TREE_HYPO_LocalLength" -msgstr "mesh_tree_hypo_length.png" - -#mesh_tree_hypo_segment -msgid "ICON_SMESH_TREE_HYPO_NumberOfSegments" -msgstr "mesh_tree_hypo_segment.png" - -#mesh_tree_hypo_volume -msgid "ICON_SMESH_TREE_HYPO_MaxElementVolume" -msgstr "mesh_tree_hypo_volume.png" - -#mesh_tree_hypo_length -msgid "ICON_SMESH_TREE_HYPO_LengthFromEdges" -msgstr "mesh_tree_hypo_length.png" - -#mesh_tree_hypo_nonconform -msgid "ICON_SMESH_TREE_HYPO_NotConformAllowed" -msgstr "mesh_tree_hypo_length.png" - -#mesh_tree_hypo_start_end_length -msgid "ICON_SMESH_TREE_HYPO_StartEndLength" -msgstr "mesh_tree_hypo_length.png" - -#mesh_tree_hypo_deflection1d -msgid "ICON_SMESH_TREE_HYPO_Deflection1D" -msgstr "mesh_tree_hypo_length.png" - -#mesh_tree_hypo_Arithmetic1d -msgid "ICON_SMESH_TREE_HYPO_Arithmetic1D" -msgstr "mesh_tree_hypo_length.png" - -#mesh_tree_hypo_propagation -msgid "ICON_SMESH_TREE_HYPO_Propagation" -msgstr "mesh_tree_hypo_length.png" diff --git a/src/StdMeshersGUI/StdMeshers_msg_en.po b/src/StdMeshersGUI/StdMeshers_msg_en.po index 19cd9295e..dc86b0046 100644 --- a/src/StdMeshersGUI/StdMeshers_msg_en.po +++ b/src/StdMeshersGUI/StdMeshers_msg_en.po @@ -47,6 +47,12 @@ msgstr "Distribution with analitic density" msgid "SMESH_NB_SEGMENTS_SCALE_PARAM" msgstr "Scale Factor" +msgid "SMESH_DENSITY_FUNC" +msgstr "Density function" + +msgid "SMESH_DISTR" +msgstr "Distribution" + msgid "SMESH_TAB_FUNC" msgstr "Table function" @@ -65,6 +71,9 @@ msgstr "Exponent" msgid "SMESH_CUT_NEG_MODE" msgstr "Cut negative" +msgid "SMESH_NO_CONV" +msgstr "No conversion" + msgid "SMESH_INSERT_ROW" msgstr "Insert row" -- 2.39.2