From: gdd Date: Fri, 2 Sep 2011 12:00:56 +0000 (+0000) Subject: Update GHS3DPLUGIN: X-Git-Tag: V6_4_0a1~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1d6ee490388589f6a0cbfeb503c14581c620ed90;p=plugins%2Fhybridplugin.git Update GHS3DPLUGIN: - Fixes for enforced vertices and meshes - Update GUI --- diff --git a/idl/GHS3DPlugin_Algorithm.idl b/idl/GHS3DPlugin_Algorithm.idl index 8d04925..79ec320 100644 --- a/idl/GHS3DPlugin_Algorithm.idl +++ b/idl/GHS3DPlugin_Algorithm.idl @@ -37,12 +37,24 @@ module GHS3DPlugin struct GHS3DEnforcedVertex { string name; string geomEntry; + boolean isCompound; TCoords coords; string groupName; double size; }; typedef sequence GHS3DEnforcedVertexList; + + struct GHS3DEnforcedMesh { + string name; + string entry; + SMESH::ElementType elementType; + string groupName; + double size; + }; + + typedef sequence GHS3DEnforcedMeshList; + /*! * GHS3DPlugin_GHS3D: interface of "Tetrahedron (GHS3D)" algorithm */ @@ -134,7 +146,9 @@ module GHS3DPlugin * To set an enforced vertex */ boolean SetEnforcedVertex(in double x, in double y, in double z, in double size) raises (SALOME::SALOME_Exception); + boolean SetEnforcedVertexNamed(in double x, in double y, in double z, in double size, in string vertexName) raises (SALOME::SALOME_Exception); boolean SetEnforcedVertexWithGroup(in double x, in double y, in double z, in double size, in string groupName) raises (SALOME::SALOME_Exception); + boolean SetEnforcedVertexNamedWithGroup(in double x, in double y, in double z, in double size, in string vertexName, in string groupName) raises (SALOME::SALOME_Exception); boolean SetEnforcedVertexGeom(in GEOM::GEOM_Object theVertex, in double size) raises (SALOME::SALOME_Exception); boolean SetEnforcedVertexGeomWithGroup(in GEOM::GEOM_Object theVertex, in double size, in string groupName) raises (SALOME::SALOME_Exception); double GetEnforcedVertex(in double x, in double y, in double z) raises (SALOME::SALOME_Exception); @@ -143,12 +157,24 @@ module GHS3DPlugin boolean RemoveEnforcedVertexGeom(in GEOM::GEOM_Object theVertex) raises (SALOME::SALOME_Exception); GHS3DEnforcedVertexList GetEnforcedVertices(); void ClearEnforcedVertices(); + /*! + * Set/get/unset an enforced vertex (private method for GUI) + */ + boolean p_SetEnforcedVertex(in double size, in double x, in double y, in double z, + in string theVertexName, in string theVertexEntry, in string groupName, + in boolean isCompound) raises (SALOME::SALOME_Exception); boolean SetEnforcedMesh(in SMESH::SMESH_IDSource theSource, in SMESH::ElementType elementType) raises (SALOME::SALOME_Exception); boolean SetEnforcedMeshWithGroup(in SMESH::SMESH_IDSource theSource, in SMESH::ElementType elementType, in string groupName) raises (SALOME::SALOME_Exception); boolean SetEnforcedMeshSize(in SMESH::SMESH_IDSource theSource, in SMESH::ElementType elementType, in double size) raises (SALOME::SALOME_Exception); boolean SetEnforcedMeshSizeWithGroup(in SMESH::SMESH_IDSource theSource, in SMESH::ElementType elementType, in double size, in string groupName) raises (SALOME::SALOME_Exception); + GHS3DEnforcedMeshList GetEnforcedMeshes(); void ClearEnforcedMeshes(); + /*! + * Set/get/unset an enforced vertex (private method for GUI) + */ + boolean p_SetEnforcedMesh(in SMESH::SMESH_IDSource theSource, in SMESH::ElementType elementType, + in double size, in string groupName) raises (SALOME::SALOME_Exception); }; }; diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx index 7d04f53..4ae9afa 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx @@ -996,13 +996,14 @@ static int findShapeID(SMESH_Mesh& mesh, //======================================================================= -//function : updateMeshGroups +//function : addElemInMeshGroup //purpose : Update or create groups in mesh //======================================================================= -static void updateMeshGroups(SMESH_Mesh* theMesh, +static void addElemInMeshGroup(SMESH_Mesh* theMesh, const SMDS_MeshElement* anElem, - std::string groupName) + std::string groupName, + std::set groupsToRemove) { bool groupDone = false; SMESH_Mesh::GroupIteratorPtr grIt = theMesh->GetGroups(); @@ -1011,7 +1012,7 @@ static void updateMeshGroups(SMESH_Mesh* theMesh, if ( !group ) continue; SMESHDS_GroupBase* groupDS = group->GetGroupDS(); if ( !groupDS ) continue; - if ( groupDS->GetType()==anElem->GetType() && groupName.compare(group->GetName())==0) { + if ( groupDS->GetType()==anElem->GetType() &&groupName.compare(group->GetName())==0) { SMESHDS_Group* aGroupDS = static_cast( groupDS ); aGroupDS->SMDSGroup().Add(anElem); groupDone = true; @@ -1019,6 +1020,7 @@ static void updateMeshGroups(SMESH_Mesh* theMesh, break; } } + if (!groupDone) { int groupId; @@ -1033,6 +1035,29 @@ static void updateMeshGroups(SMESH_Mesh* theMesh, throw SALOME_Exception(LOCALIZED("A enforced vertex node was not added to a group")); } + +//======================================================================= +//function : updateMeshGroups +//purpose : Update or create groups in mesh +//======================================================================= + +static void updateMeshGroups(SMESH_Mesh* theMesh, std::set groupsToRemove) +{ + SMESH_Mesh::GroupIteratorPtr grIt = theMesh->GetGroups(); + while (grIt->more()) { + SMESH_Group * group = grIt->next(); + if ( !group ) continue; + SMESHDS_GroupBase* groupDS = group->GetGroupDS(); + if ( !groupDS ) continue; + std::string currentGroupName = (string)group->GetName(); + if (groupDS->IsEmpty() && groupsToRemove.find(currentGroupName) != groupsToRemove.end()) { + // Previous group created by enforced elements + MESSAGE("Delete previous group created by removed enforced elements: " << group->GetName()) + theMesh->RemoveGroup(groupDS->GetID()); + } + } +} + //======================================================================= //function : readGMFFile //purpose : read GMF file w/o geometry associated to mesh @@ -1048,7 +1073,9 @@ static bool readGMFFile(const char* theFile, map & theNodeToGhs3dIdMap, std::vector & aNodeGroupByGhs3dId, std::vector & anEdgeGroupByGhs3dId, - std::vector & aFaceGroupByGhs3dId) + std::vector & aFaceGroupByGhs3dId, + std::set & groupsToRemove + ) { SMESHDS_Mesh* theMeshDS = theHelper->GetMeshDS(); @@ -1074,6 +1101,9 @@ static bool readGMFFile(const char* theFile, int aGMFNodeID = 0, shapeID; int *nodeAssigne; const SMDS_MeshNode** GMFNode; +#ifdef _DEBUG_ + std::map > subdomainId2tetraId; +#endif std::map tabRef; tabRef[GmfVertices] = 3; // for new nodes and enforced nodes @@ -1181,7 +1211,7 @@ static bool readGMFFile(const char* theFile, GMFNode[ aGMFID ] = aGMFNode; nodeAssigne[ aGMFID ] = 0; if (aGMFID-1 < aNodeGroupByGhs3dId.size() && !aNodeGroupByGhs3dId.at(aGMFID-1).empty()) - updateMeshGroups(theHelper->GetMesh(), aGMFNode, aNodeGroupByGhs3dId.at(aGMFID-1)); + addElemInMeshGroup(theHelper->GetMesh(), aGMFNode, aNodeGroupByGhs3dId.at(aGMFID-1), groupsToRemove); } } } @@ -1212,8 +1242,13 @@ static bool readGMFFile(const char* theFile, } else if (token == GmfTetrahedra && nbElem > 0) { std::cout << " Tetrahedra" << std::endl; - for ( int iElem = 0; iElem < nbElem; iElem++ ) + for ( int iElem = 0; iElem < nbElem; iElem++ ) { GmfGetLin(InpMsh, token, &id[iElem*tabRef[token]], &id[iElem*tabRef[token]+1], &id[iElem*tabRef[token]+2], &id[iElem*tabRef[token]+3], &dummy); +#ifdef _DEBUG_ + subdomainId2tetraId[dummy].insert(iElem+1); +// MESSAGE("subdomainId2tetraId["< 0) { std::cout << " Hexahedra" << std::endl; @@ -1272,7 +1307,7 @@ static bool readGMFFile(const char* theFile, if (fullyCreatedElement) { aCreatedElem = theHelper->AddEdge( node[0], node[1], /*id =*/0, /*force3d =*/false ); if (anEdgeGroupByGhs3dId.size() && !anEdgeGroupByGhs3dId[iElem].empty()) - updateMeshGroups(theHelper->GetMesh(), aCreatedElem, anEdgeGroupByGhs3dId[iElem]); + addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, anEdgeGroupByGhs3dId[iElem], groupsToRemove); } break; case GmfTriangles: @@ -1281,7 +1316,7 @@ static bool readGMFFile(const char* theFile, for ( int iRef = 0; iRef < nbRef; iRef++ ) nodeAssigne[ nodeID[ iRef ]] = 1; if (aFaceGroupByGhs3dId.size() && !aFaceGroupByGhs3dId[iElem].empty()) - updateMeshGroups(theHelper->GetMesh(), aCreatedElem, aFaceGroupByGhs3dId[iElem]); + addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, aFaceGroupByGhs3dId[iElem], groupsToRemove); } break; case GmfQuadrilaterals: @@ -1343,6 +1378,28 @@ static bool readGMFFile(const char* theFile, GmfCloseMesh(InpMsh); delete [] GMFNode; delete [] nodeAssigne; +#ifdef _DEBUG_ + MESSAGE("Nb subdomains " << subdomainId2tetraId.size()); + std::map >::const_iterator subdomainIt = subdomainId2tetraId.begin(); + TCollection_AsciiString aSubdomainFileName = theFile; + aSubdomainFileName = aSubdomainFileName + ".subdomain"; + ofstream aSubdomainFile ( aSubdomainFileName.ToCString() , ios::out); + + aSubdomainFile << "Nb subdomains " << subdomainId2tetraId.size() << std::endl; + for(;subdomainIt != subdomainId2tetraId.end() ; ++subdomainIt) { + int subdomainId = subdomainIt->first; + std::set tetraIds = subdomainIt->second; + MESSAGE("Subdomain #"<::const_iterator tetraIdsIt = tetraIds.begin(); + aSubdomainFile << subdomainId << std::endl; + for(;tetraIdsIt != tetraIds.end() ; ++tetraIdsIt) { + aSubdomainFile << (*tetraIdsIt) << " "; + } + aSubdomainFile << std::endl; + } + aSubdomainFile.close(); +#endif + return true; } @@ -1572,7 +1629,7 @@ static bool writeGMFFile(const char* theMesh std::vector > ReqVerTab; if (nbEnforcedVertices) { // ReqVerTab.clear(); - std::cout << theEnforcedVertices.size() << " nodes from enforced vertices ..." << std::endl; + std::cout << nbEnforcedVertices << " nodes from enforced vertices ..." << std::endl; // Iterate over the enforced vertices for(vertexIt = theEnforcedVertices.begin() ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) { double x = vertexIt->first[0]; @@ -1620,10 +1677,13 @@ static bool writeGMFFile(const char* theMesh GmfSetKwd(idxRequired, GmfVertices, requiredNodes + solSize); GmfSetKwd(idxSol, GmfSolAtVertices, requiredNodes + solSize, 1, TypTab); int usedEnforcedNodes = 0; + std::string gn = ""; for (ghs3dNodeIt = theRequiredNodes.begin();ghs3dNodeIt != theRequiredNodes.end();++ghs3dNodeIt) { GmfSetLin(idxRequired, GmfVertices, (*ghs3dNodeIt)->X(), (*ghs3dNodeIt)->Y(), (*ghs3dNodeIt)->Z(), dummyint); GmfSetLin(idxSol, GmfSolAtVertices, 0.0); - aNodeGroupByGhs3dId[usedEnforcedNodes] = theEnforcedNodes.find((*ghs3dNodeIt))->second; + if (theEnforcedNodes.find((*ghs3dNodeIt)) != theEnforcedNodes.end()) + gn = theEnforcedNodes.find((*ghs3dNodeIt))->second; + aNodeGroupByGhs3dId[usedEnforcedNodes] = gn; usedEnforcedNodes++; } @@ -1634,7 +1694,7 @@ static bool writeGMFFile(const char* theMesh GmfSetLin(idxRequired, GmfVertices, ReqVerTab[i][0], ReqVerTab[i][1], ReqVerTab[i][2], dummyint); GmfSetLin(idxSol, GmfSolAtVertices, solTab); aNodeGroupByGhs3dId[usedEnforcedNodes] = enfVerticesWithGroup.find(ReqVerTab[i])->second; - std::cout << "aNodeGroupByGhs3dId["<second<<"\""<, std::string> enfVerticesWithGroup; GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues coordsSizeMap; TopoDS_Shape GeomShape; - TopAbs_ShapeEnum GeomType; +// TopAbs_ShapeEnum GeomType; std::vector coords; gp_Pnt aPnt; GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* enfVertex; GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList enfVertices = GHS3DPlugin_Hypothesis::GetEnforcedVertices(_hyp); GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList::const_iterator enfVerIt = enfVertices.begin(); + MESSAGE("Populating enfVerticesWithGroup"); for ( ; enfVerIt != enfVertices.end() ; ++enfVerIt) { enfVertex = (*enfVerIt); - if (enfVertex->geomEntry.empty() && enfVertex->coords.size()) { +// if (enfVertex->geomEntry.empty() && enfVertex->coords.size()) { + if (enfVertex->coords.size()) { coordsSizeMap.insert(make_pair(enfVertex->coords,enfVertex->size)); - enfVerticesWithGroup.insert(make_pair(coords,enfVertex->groupName)); + enfVerticesWithGroup.insert(make_pair(enfVertex->coords,enfVertex->groupName)); + MESSAGE("enfVerticesWithGroup.insert(make_pair(("<coords[0]<<","<coords[1]<<","<coords[2]<<"),\""<groupName<<"\"))"); } - if (!enfVertex->geomEntry.empty()) { + else { +// if (!enfVertex->geomEntry.empty()) { GeomShape = entryToShape(enfVertex->geomEntry); - GeomType = GeomShape.ShapeType(); - - if (GeomType == TopAbs_VERTEX) { - coords.clear(); - aPnt = BRep_Tool::Pnt(TopoDS::Vertex(GeomShape)); - coords.push_back(aPnt.X()); - coords.push_back(aPnt.Y()); - coords.push_back(aPnt.Z()); - if (coordsSizeMap.find(coords) == coordsSizeMap.end()) { - coordsSizeMap.insert(make_pair(coords,enfVertex->size)); - enfVerticesWithGroup.insert(make_pair(coords,enfVertex->groupName)); - } - } +// GeomType = GeomShape.ShapeType(); - // Group Management - if (GeomType == TopAbs_COMPOUND){ +// if (!enfVertex->isCompound) { +// // if (GeomType == TopAbs_VERTEX) { +// coords.clear(); +// aPnt = BRep_Tool::Pnt(TopoDS::Vertex(GeomShape)); +// coords.push_back(aPnt.X()); +// coords.push_back(aPnt.Y()); +// coords.push_back(aPnt.Z()); +// if (coordsSizeMap.find(coords) == coordsSizeMap.end()) { +// coordsSizeMap.insert(make_pair(coords,enfVertex->size)); +// enfVerticesWithGroup.insert(make_pair(coords,enfVertex->groupName)); +// } +// } +// +// // Group Management +// else { +// if (GeomType == TopAbs_COMPOUND){ for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()){ coords.clear(); if (it.Value().ShapeType() == TopAbs_VERTEX){ @@ -3301,10 +3367,11 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, if (coordsSizeMap.find(coords) == coordsSizeMap.end()) { coordsSizeMap.insert(make_pair(coords,enfVertex->size)); enfVerticesWithGroup.insert(make_pair(coords,enfVertex->groupName)); + MESSAGE("enfVerticesWithGroup.insert(make_pair(("<groupName<<"\"))"); } } } - } +// } } } @@ -3381,14 +3448,22 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, // -------------- // read a result // -------------- - + std::set groupsToRemove = _hyp->GetGroupsToRemove(); + Ok = readGMFFile(aResultFileName.ToCString(), #ifdef WITH_SMESH_CANCEL_COMPUTE this, #endif theHelper, theShape, aNodeByGhs3dId, aNodeToGhs3dIdMap, - aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId); + aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId, + groupsToRemove); + updateMeshGroups(theHelper->GetMesh(), groupsToRemove); + + if ( Ok ) { + GHS3DPlugin_Hypothesis* that = (GHS3DPlugin_Hypothesis*)this->_hyp; + that->ClearGroupsToRemove(); + } // --------------------- // remove working files // --------------------- @@ -4026,12 +4101,13 @@ bool GHS3DPlugin_GHS3D::importGMFMesh(const char* theGMFFileName, SMESH_Mesh& th std::map dummyNodeMap; std::map, std::string> dummyEnfVertGroup; std::vector dummyElemGroup; + std::set dummyGroupsToRemove; bool ok = readGMFFile(theGMFFileName, #ifdef WITH_SMESH_CANCEL_COMPUTE this, #endif - helper, theMesh.GetShapeToMesh(), dummyNodeVector, dummyNodeMap, dummyElemGroup, dummyElemGroup, dummyElemGroup); + helper, theMesh.GetShapeToMesh(), dummyNodeVector, dummyNodeMap, dummyElemGroup, dummyElemGroup, dummyElemGroup, dummyGroupsToRemove); theMesh.GetMeshDS()->Modified(); return ok; } diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx index c18cc42..c654daf 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx @@ -57,6 +57,9 @@ GHS3DPlugin_Hypothesis::GHS3DPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen _enfVertexEntrySizeList(DefaultGHS3DEnforcedVertexEntryValues()), _coordsEnfVertexMap(DefaultCoordsGHS3DEnforcedVertexMap()), _geomEntryEnfVertexMap(DefaultGeomEntryGHS3DEnforcedVertexMap()), + + _enfMeshList(DefaultGHS3DEnforcedMeshList()), + _entryEnfMeshMap(DefaultEntryGHS3DEnforcedMeshListMap()), _enfNodes(TIDSortedNodeGroupMap()), _enfEdges(TIDSortedElemGroupMap()), _enfTriangles(TIDSortedElemGroupMap()), @@ -65,6 +68,7 @@ GHS3DPlugin_Hypothesis::GHS3DPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen { _name = "GHS3D_Parameters"; _param_algo_dim = 3; + _groupsToRemove.clear(); } //======================================================================= @@ -331,10 +335,10 @@ std::string GHS3DPlugin_Hypothesis::GetTextOption() const //======================================================================= bool GHS3DPlugin_Hypothesis::SetEnforcedVertex(std::string theName, std::string theEntry, std::string theGroupName, - double size, double x, double y, double z) + double size, double x, double y, double z, bool isCompound) { - MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedVertex("<< theName << ", "<< theEntry << ", " << theGroupName << ", " - << size << ", " << x << ", " << y << ", " << z << ")"); + MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedVertex(\""<< theName << "\", \""<< theEntry << "\", \"" << theGroupName << "\", " + << size << ", " << x << ", " << y << ", " << z << ", "<< isCompound << ")"); bool toNotify = false; bool toCreate = true; @@ -344,13 +348,14 @@ bool GHS3DPlugin_Hypothesis::SetEnforcedVertex(std::string theName, std::string newEnfVertex->name = theName; newEnfVertex->geomEntry = theEntry; newEnfVertex->coords.clear(); - if (theEntry == "") { + if (!isCompound) { newEnfVertex->coords.push_back(x); newEnfVertex->coords.push_back(y); newEnfVertex->coords.push_back(z); } newEnfVertex->groupName = theGroupName; newEnfVertex->size = size; + newEnfVertex->isCompound = isCompound; // update _enfVertexList @@ -415,20 +420,35 @@ bool GHS3DPlugin_Hypothesis::SetEnforcedVertex(std::string theName, std::string //======================================================================= //function : SetEnforcedMesh //======================================================================= -bool GHS3DPlugin_Hypothesis::SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, double size, std::string groupName) +bool GHS3DPlugin_Hypothesis::SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, double size, std::string groupName) { TIDSortedElemSet theElemSet; SMDS_ElemIteratorPtr eIt = theMesh.GetMeshDS()->elementsIterator(SMDSAbs_ElementType(elementType)); while ( eIt->more() ) theElemSet.insert( eIt->next() ); MESSAGE("Add "<name = name; + newEnfMesh->entry = entry; + newEnfMesh->elementType = elementType; + newEnfMesh->size = size; + newEnfMesh->groupName = groupName; + + TGHS3DEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh); + if (it == _enfMeshList.end()) { + _entryEnfMeshMap[entry].insert(newEnfMesh); + _enfMeshList.insert(newEnfMesh); + } + } + return added; } //======================================================================= //function : SetEnforcedGroup //======================================================================= -bool GHS3DPlugin_Hypothesis::SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SMESH::long_array_var theIDs, SMESH::ElementType elementType, double size, std::string groupName) +bool GHS3DPlugin_Hypothesis::SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SMESH::long_array_var theIDs, SMESH::ElementType elementType, std::string name, std::string entry, double size, std::string groupName) { MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedGroup"); TIDSortedElemSet theElemSet; @@ -454,7 +474,22 @@ bool GHS3DPlugin_Hypothesis::SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SME // theElemSet.insert( it->next() ); MESSAGE("Add "<name = name; + newEnfMesh->entry = entry; + newEnfMesh->elementType = elementType; + newEnfMesh->size = size; + newEnfMesh->groupName = groupName; + + TGHS3DEnforcedMeshList::iterator it = _enfMeshList.find(newEnfMesh); + if (it == _enfMeshList.end()) { + _entryEnfMeshMap[entry].insert(newEnfMesh); + _enfMeshList.insert(newEnfMesh); + } + } + return added; } //======================================================================= @@ -609,6 +644,8 @@ bool GHS3DPlugin_Hypothesis::RemoveEnforcedVertex(double x, double y, double z, // update _enfVertexList TGHS3DEnforcedVertexList::iterator it = _enfVertexList.find(oldEnfVertex); if (it != _enfVertexList.end()) { + if ((*it)->groupName != "") + _groupsToRemove.insert((*it)->groupName); _enfVertexList.erase(it); toNotify = true; MESSAGE("Done"); @@ -625,12 +662,17 @@ bool GHS3DPlugin_Hypothesis::RemoveEnforcedVertex(double x, double y, double z, //======================================================================= void GHS3DPlugin_Hypothesis::ClearEnforcedVertices() { - _enfVertexList.clear(); - _coordsEnfVertexMap.clear(); - _geomEntryEnfVertexMap.clear(); - _enfVertexCoordsSizeList.clear(); - _enfVertexEntrySizeList.clear(); - NotifySubMeshesHypothesisModification(); + TGHS3DEnforcedVertexList::const_iterator it = _enfVertexList.begin(); + for(;it != _enfVertexList.end();++it) { + if ((*it)->groupName != "") + _groupsToRemove.insert((*it)->groupName); + } + _enfVertexList.clear(); + _coordsEnfVertexMap.clear(); + _geomEntryEnfVertexMap.clear(); + _enfVertexCoordsSizeList.clear(); + _enfVertexEntrySizeList.clear(); + NotifySubMeshesHypothesisModification(); } //======================================================================= @@ -638,15 +680,32 @@ void GHS3DPlugin_Hypothesis::ClearEnforcedVertices() //======================================================================= void GHS3DPlugin_Hypothesis::ClearEnforcedMeshes() { + TGHS3DEnforcedMeshList::const_iterator it = _enfMeshList.begin(); + for(;it != _enfMeshList.end();++it) { + if ((*it)->groupName != "") + _groupsToRemove.insert((*it)->groupName); + } _enfNodes.clear(); _enfEdges.clear(); _enfTriangles.clear(); _nodeIDToSizeMap.clear(); _elementIDToSizeMap.clear(); + _enfMeshList.clear(); + _entryEnfMeshMap.clear(); NotifySubMeshesHypothesisModification(); } +//======================================================================= +//function : SetGroupsToRemove +//======================================================================= + +void GHS3DPlugin_Hypothesis::ClearGroupsToRemove() +{ + _groupsToRemove.clear(); +} + + //======================================================================= //function : DefaultMeshHoles //======================================================================= @@ -785,14 +844,14 @@ bool GHS3DPlugin_Hypothesis::DefaultToRemoveCentralPoint() return false; } -//======================================================================= -//function : DefaultID2SizeMap -//======================================================================= - -GHS3DPlugin_Hypothesis::TID2SizeMap GHS3DPlugin_Hypothesis::DefaultID2SizeMap() -{ - return GHS3DPlugin_Hypothesis::TID2SizeMap(); -} +// //======================================================================= +// //function : DefaultID2SizeMap +// //======================================================================= +// +// GHS3DPlugin_Hypothesis::TID2SizeMap GHS3DPlugin_Hypothesis::DefaultID2SizeMap() +// { +// return GHS3DPlugin_Hypothesis::TID2SizeMap(); +// } //======================================================================= @@ -833,6 +892,7 @@ std::ostream & GHS3DPlugin_Hypothesis::SaveTo(std::ostream & save) if (!enfVertex->geomEntry.empty()) { save << " " << "__BEGIN_ENTRY__"; save << " " << enfVertex->geomEntry; + save << " " << enfVertex->isCompound; save << " " << "__END_ENTRY__"; } if (!enfVertex->groupName.empty()) { @@ -982,6 +1042,7 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load) if (hasEnforcedVertices) { std::string txt, name, entry, groupName; double size, coords[3]; + bool isCompound; bool hasCoords = false; while (isOK) { isOK = (load >> txt); // __BEGIN_VERTEX__ @@ -995,6 +1056,7 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load) if (txt == "__END_VERTEX__") { enfVertex->name = name; enfVertex->geomEntry = entry; + enfVertex->isCompound = isCompound; enfVertex->groupName = groupName; enfVertex->coords.clear(); if (hasCoords) @@ -1028,6 +1090,7 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load) if (txt == "__BEGIN_ENTRY__") { // __BEGIN_ENTRY__ isOK = (load >> entry); + isOK = (load >> isCompound); isOK = (load >> txt); // __END_ENTRY__ if (txt != "__END_ENTRY__") throw std::exception(); diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx index 481619f..622a169 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx @@ -52,6 +52,7 @@ public: struct TGHS3DEnforcedVertex { std::string name; std::string geomEntry; + bool isCompound; std::vector coords; std::string groupName; double size; @@ -71,10 +72,40 @@ public: typedef std::set< TGHS3DEnforcedVertex*, CompareGHS3DEnforcedVertex > TGHS3DEnforcedVertexList; // Map Coords / Enforced node typedef std::map< std::vector, TGHS3DEnforcedVertex* > TCoordsGHS3DEnforcedVertexMap; - // Map geom entry / Enforced ndoe + // Map geom entry / Enforced node typedef std::map< std::string, TGHS3DEnforcedVertex* > TGeomEntryGHS3DEnforcedVertexMap; - // Map groupName / Enforced ndoe - typedef std::map< std::string, TGHS3DEnforcedVertex* > TGroupNameGHS3DEnforcedVertexMap; + // Map groupName / Enforced node + typedef std::map< std::string, TGHS3DEnforcedVertexList > TGroupNameGHS3DEnforcedVertexMap; + + //////////////////// + // Enforced meshes + //////////////////// + + struct TGHS3DEnforcedMesh { + std::string name; + std::string entry; + SMESH::ElementType elementType; + std::string groupName; + double size; + }; + + struct CompareGHS3DEnforcedMesh { + bool operator () (const TGHS3DEnforcedMesh* e1, const TGHS3DEnforcedMesh* e2) const { + if (e1 && e2) { + if (e1->entry == e2->entry) + return (e1->elementType < e2->elementType); + else + return (e1->entry < e2->entry); + } + else + return false; + } + }; + typedef std::set< TGHS3DEnforcedMesh*, CompareGHS3DEnforcedMesh > TGHS3DEnforcedMeshList; + // Map mesh entry / Enforced mesh list + // ex: 0:1:2:1 -> [ ("Mesh_1", "0:1:2:1", TopAbs_NODE, "", -1), + // ("Mesh_1", "0:1:2:1", TopAbs_EDGE, "edge group", 5)] + typedef std::map< std::string, TGHS3DEnforcedMeshList > TEntryGHS3DEnforcedMeshListMap; typedef std::map TID2SizeMap; @@ -178,7 +209,7 @@ public: * To set an enforced vertex */ bool SetEnforcedVertex(std::string aName, std::string anEntry, std::string aGroupName, - double size, double x=0.0, double y=0.0, double z=0.0); + double size, double x=0.0, double y=0.0, double z=0.0, bool isCompound = false); TGHS3DEnforcedVertex* GetEnforcedVertex(double x, double y, double z) throw (std::invalid_argument); TGHS3DEnforcedVertex* GetEnforcedVertex(const std::string anEntry) throw (std::invalid_argument); bool RemoveEnforcedVertex(double x=0.0, double y=0.0, double z=0.0, const std::string anEntry="" ) throw (std::invalid_argument); @@ -192,9 +223,11 @@ public: /*! * To set enforced elements */ - bool SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, double size, std::string groupName = ""); - bool SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SMESH::long_array_var theIDs, SMESH::ElementType elementType, double size, std::string groupName = ""); + bool SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, std::string name, std::string entry, double size, std::string groupName = ""); + bool SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SMESH::long_array_var theIDs, SMESH::ElementType elementType, std::string name, std::string entry, double size, std::string groupName = ""); bool SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, double size, std::string groupName = ""); + const TGHS3DEnforcedMeshList _GetEnforcedMeshes() const { return _enfMeshList; } + const TEntryGHS3DEnforcedMeshListMap _GetEnforcedMeshesByEntry() const { return _entryEnfMeshMap; } void ClearEnforcedMeshes(); const TIDSortedNodeGroupMap _GetEnforcedNodes() const { return _enfNodes; } const TIDSortedElemGroupMap _GetEnforcedEdges() const { return _enfEdges; } @@ -209,12 +242,18 @@ public: static TGHS3DEnforcedVertexEntryValues GetEnforcedVerticesEntrySize(const GHS3DPlugin_Hypothesis* hyp); static TCoordsGHS3DEnforcedVertexMap GetEnforcedVerticesByCoords(const GHS3DPlugin_Hypothesis* hyp); static TGeomEntryGHS3DEnforcedVertexMap GetEnforcedVerticesByEntry(const GHS3DPlugin_Hypothesis* hyp); + + static TGHS3DEnforcedMeshList GetEnforcedMeshes(const GHS3DPlugin_Hypothesis* hyp); + static TEntryGHS3DEnforcedMeshListMap GetEnforcedMeshesByEntry(const GHS3DPlugin_Hypothesis* hyp); static TIDSortedNodeGroupMap GetEnforcedNodes(const GHS3DPlugin_Hypothesis* hyp); static TIDSortedElemGroupMap GetEnforcedEdges(const GHS3DPlugin_Hypothesis* hyp); static TIDSortedElemGroupMap GetEnforcedTriangles(const GHS3DPlugin_Hypothesis* hyp); static TID2SizeMap GetNodeIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp); static TID2SizeMap GetElementIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp); + std::set GetGroupsToRemove() const {return _groupsToRemove;} + void ClearGroupsToRemove(); + static bool DefaultMeshHoles(); static short DefaultMaximumMemory(); static short DefaultInitialMemory(); @@ -226,6 +265,7 @@ public: static bool DefaultToUseBoundaryRecoveryVersion(); static bool DefaultToUseFEMCorrection(); static bool DefaultToRemoveCentralPoint(); + static TGHS3DEnforcedVertex DefaultGHS3DEnforcedVertex() {return TGHS3DEnforcedVertex();} static TGHS3DEnforcedVertexList DefaultGHS3DEnforcedVertexList() {return TGHS3DEnforcedVertexList();} static TGHS3DEnforcedVertexCoordsValues DefaultGHS3DEnforcedVertexCoordsValues() {return TGHS3DEnforcedVertexCoordsValues();} @@ -233,9 +273,13 @@ public: static TCoordsGHS3DEnforcedVertexMap DefaultCoordsGHS3DEnforcedVertexMap() {return TCoordsGHS3DEnforcedVertexMap();} static TGeomEntryGHS3DEnforcedVertexMap DefaultGeomEntryGHS3DEnforcedVertexMap() {return TGeomEntryGHS3DEnforcedVertexMap();} static TGroupNameGHS3DEnforcedVertexMap DefaultGroupNameGHS3DEnforcedVertexMap() {return TGroupNameGHS3DEnforcedVertexMap();} - static TIDSortedNodeGroupMap DefaultIDSortedNodeGroupMap() {return TIDSortedNodeGroupMap();} - static TIDSortedElemGroupMap DefaultIDSortedElemGroupMap() {return TIDSortedElemGroupMap();} - static TID2SizeMap DefaultID2SizeMap(); + + static TGHS3DEnforcedMesh DefaultGHS3DEnforcedMesh() {return TGHS3DEnforcedMesh();} + static TGHS3DEnforcedMeshList DefaultGHS3DEnforcedMeshList() {return TGHS3DEnforcedMeshList();} + static TEntryGHS3DEnforcedMeshListMap DefaultEntryGHS3DEnforcedMeshListMap() {return TEntryGHS3DEnforcedMeshListMap();} + static TIDSortedNodeGroupMap DefaultIDSortedNodeGroupMap() {return TIDSortedNodeGroupMap();} + static TIDSortedElemGroupMap DefaultIDSortedElemGroupMap() {return TIDSortedElemGroupMap();} + static TID2SizeMap DefaultID2SizeMap() {return TID2SizeMap();} // Persistence virtual std::ostream & SaveTo(std::ostream & save); @@ -267,6 +311,7 @@ private: bool myToUseFemCorrection; bool myToRemoveCentralPoint; std::string myTextOption; + TGHS3DEnforcedVertexList _enfVertexList; TGHS3DEnforcedVertexCoordsValues _enfVertexCoordsSizeList; TGHS3DEnforcedVertexEntryValues _enfVertexEntrySizeList; @@ -274,12 +319,19 @@ private: TCoordsGHS3DEnforcedVertexMap _coordsEnfVertexMap; // map to get "geom" enf vertex (through the geom entries) TGeomEntryGHS3DEnforcedVertexMap _geomEntryEnfVertexMap; + + + TGHS3DEnforcedMeshList _enfMeshList; + // map to get enf meshes through the entries + TEntryGHS3DEnforcedMeshListMap _entryEnfMeshMap; TIDSortedNodeGroupMap _enfNodes; TIDSortedElemGroupMap _enfEdges; TIDSortedElemGroupMap _enfTriangles; TID2SizeMap _nodeIDToSizeMap; TID2SizeMap _elementIDToSizeMap; std::map _entryToElemsMap; + + std::set _groupsToRemove; }; diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx index 7feffde..987cd83 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx @@ -37,6 +37,13 @@ #include "SMESH_TypeDefs.hxx" #include "SMESHDS_GroupBase.hxx" +// SALOME KERNEL includes +#include "SALOMEDSClient.hxx" +#include +// // IDL headers +// #include +// #include CORBA_SERVER_HEADER(SALOMEDS) + #ifndef GHS3D_VERSION #define GHS3D_VERSION 41 #endif @@ -355,14 +362,28 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertex(CORBA::Double x, CORBA::Double throw (SALOME::SALOME_Exception) { ASSERT(myBaseImpl); MESSAGE("IDL : SetEnforcedVertex( "<< x << ", " << y << ", " << z << ", " << size << ")"); - return _SetEnforcedVertex(size, x, y, z); + return p_SetEnforcedVertex(size, x, y, z); +} + +bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexNamed(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size, const char* theVertexName) + throw (SALOME::SALOME_Exception) { + ASSERT(myBaseImpl); + MESSAGE("IDL : SetEnforcedVertexNamed( "<< x << ", " << y << ", " << z << ", " << size << ", " << theVertexName << ")"); + return p_SetEnforcedVertex(size, x, y, z, theVertexName, "", ""); } bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexWithGroup(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size, const char* theGroupName) throw (SALOME::SALOME_Exception) { ASSERT(myBaseImpl); MESSAGE("IDL : SetEnforcedVertexWithGroup( "<< x << ", " << y << ", " << z << ", " << size << ", " << theGroupName << ")"); - return _SetEnforcedVertex(size, x, y, z, "", "", theGroupName); + return p_SetEnforcedVertex(size, x, y, z, "", "", theGroupName); +} + +bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexNamedWithGroup(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size, const char* theVertexName, const char* theGroupName) + throw (SALOME::SALOME_Exception) { + ASSERT(myBaseImpl); + MESSAGE("IDL : SetEnforcedVertexNamedWithGroup( "<< x << ", " << y << ", " << z << ", " << size << ", " << theVertexName << ", " << theGroupName << ")"); + return p_SetEnforcedVertex(size, x, y, z, theVertexName, "", theGroupName); } bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex, CORBA::Double size) @@ -375,14 +396,19 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVe } string theVertexEntry = theVertex->GetStudyEntry(); + CORBA::Double x = 0, y = 0, z = 0; + CORBA::Boolean isCompound = false; + GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine(); + SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen(); if (theVertexEntry.empty()) { - GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine(); - SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen(); string aName; - if (theVertex->GetShapeType() == GEOM::VERTEX) + if (theVertex->GetShapeType() == GEOM::VERTEX) { aName = "Vertex_"; - if (theVertex->GetShapeType() == GEOM::COMPOUND) + } + if (theVertex->GetShapeType() == GEOM::COMPOUND) { aName = "Compound_"; + isCompound = true; + } aName += theVertex->GetEntry(); SALOMEDS::SObject_ptr theSVertex = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theVertex, aName.c_str()); if (!theSVertex->_is_nil()) @@ -391,10 +417,19 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVe if (theVertexEntry.empty()) THROW_SALOME_CORBA_EXCEPTION( "Geom object is not published in study" ,SALOME::BAD_PARAM ); + if (theVertex->GetShapeType() == GEOM::VERTEX) { + GEOM::GEOM_IMeasureOperations_var measureOp = geomGen->GetIMeasureOperations( smeshGen->GetCurrentStudy()->StudyId() ); + if (CORBA::is_nil(measureOp)) + return false; + + measureOp->PointCoordinates (theVertex, x, y, z); + MESSAGE("Point coordinates from measureOp: " << x << ", " << y << ", " << z); + } + string theVertexName = theVertex->GetName(); MESSAGE("IDL : SetEnforcedVertexGeom( "<< theVertexEntry << ", " << size<< ")"); - return _SetEnforcedVertex(size, 0, 0, 0, theVertexName.c_str(), theVertexEntry.c_str()); + return p_SetEnforcedVertex(size, x, y, z, theVertexName.c_str(), theVertexEntry.c_str(), "", isCompound); } bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexGeomWithGroup(GEOM::GEOM_Object_ptr theVertex, CORBA::Double size, const char* theGroupName) @@ -407,14 +442,19 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexGeomWithGroup(GEOM::GEOM_Object_ } string theVertexEntry = theVertex->GetStudyEntry(); + CORBA::Double x = 0, y = 0, z = 0; + CORBA::Boolean isCompound = false; + GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine(); + SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen(); if (theVertexEntry.empty()) { - GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine(); - SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen(); string aName; - if (theVertex->GetShapeType() == GEOM::VERTEX) + if (theVertex->GetShapeType() == GEOM::VERTEX) { aName = "Vertex_"; - if (theVertex->GetShapeType() == GEOM::COMPOUND) + } + if (theVertex->GetShapeType() == GEOM::COMPOUND) { aName = "Compound_"; + isCompound = true; + } aName += theVertex->GetEntry(); SALOMEDS::SObject_ptr theSVertex = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theVertex, aName.c_str()); if (!theSVertex->_is_nil()) @@ -423,21 +463,33 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexGeomWithGroup(GEOM::GEOM_Object_ if (theVertexEntry.empty()) THROW_SALOME_CORBA_EXCEPTION( "Geom object is not published in study" ,SALOME::BAD_PARAM ); + if (theVertex->GetShapeType() == GEOM::VERTEX) { + GEOM::GEOM_IMeasureOperations_var measureOp = geomGen->GetIMeasureOperations( smeshGen->GetCurrentStudy()->StudyId() ); + if (CORBA::is_nil(measureOp)) + return false; + + measureOp->PointCoordinates (theVertex, x, y, z); + MESSAGE("Point coordinates from measureOp: " << x << ", " << y << ", " << z); + } + string theVertexName = theVertex->GetName(); MESSAGE("IDL : SetEnforcedVertexGeomWithGroup( "<< theVertexEntry << ", " << size<< ", " << theGroupName << ")"); - return _SetEnforcedVertex(size, 0, 0, 0, theVertexName.c_str(), theVertexEntry.c_str(), theGroupName); + return p_SetEnforcedVertex(size, x, y, z, theVertexName.c_str(), theVertexEntry.c_str(), theGroupName, isCompound); } -bool GHS3DPlugin_Hypothesis_i:: _SetEnforcedVertex(CORBA::Double size, CORBA::Double x, CORBA::Double y, CORBA::Double z, - const char* theVertexName, const char* theVertexEntry, const char* theGroupName) +bool GHS3DPlugin_Hypothesis_i:: p_SetEnforcedVertex(CORBA::Double size, CORBA::Double x, CORBA::Double y, CORBA::Double z, + const char* theVertexName, const char* theVertexEntry, const char* theGroupName, + CORBA::Boolean isCompound) throw (SALOME::SALOME_Exception) { ASSERT(myBaseImpl); - MESSAGE("IDL : _SetEnforcedVertex(" << size << ", " << x << ", " << y << ", " << z << ", \"" << theVertexName << "\", \"" << theVertexEntry << "\", \"" << theGroupName << "\")"); + MESSAGE("IDL : p_SetEnforcedVertex(" << size << ", " << x << ", " << y << ", " << z << ", \"" << theVertexName << "\", \"" << theVertexEntry << "\", \"" << theGroupName << "\", " << isCompound<< ")"); bool newValue = false; + ::GHS3DPlugin_Hypothesis::TCoordsGHS3DEnforcedVertexMap coordsList; + ::GHS3DPlugin_Hypothesis::TGeomEntryGHS3DEnforcedVertexMap enfVertexEntryList; if (string(theVertexEntry).empty()) { - ::GHS3DPlugin_Hypothesis::TCoordsGHS3DEnforcedVertexMap coordsList = this->GetImpl()->_GetEnforcedVerticesByCoords(); + coordsList = this->GetImpl()->_GetEnforcedVerticesByCoords(); std::vector coords; coords.push_back(x); coords.push_back(y); @@ -445,7 +497,8 @@ bool GHS3DPlugin_Hypothesis_i:: _SetEnforcedVertex(CORBA::Double size, CORBA::Do if (coordsList.find(coords) == coordsList.end()) { MESSAGE("Coords not found: add it in coordsList"); newValue = true; - } else { + } + else { MESSAGE("Coords already found, compare names"); ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex *enfVertex = this->GetImpl()->GetEnforcedVertex(x, y, z); if ((enfVertex->name != theVertexName) || (enfVertex->groupName != theGroupName) || (enfVertex->size != size)) { @@ -464,16 +517,18 @@ bool GHS3DPlugin_Hypothesis_i:: _SetEnforcedVertex(CORBA::Double size, CORBA::Do SMESH::TPythonDump() << "isDone = " << _this() << ".SetEnforcedVertex(" << x << ", " << y << ", " << z << ", " << size << ")"; else SMESH::TPythonDump() << "isDone = " << _this() << ".SetEnforcedVertexWithGroup(" << x << ", " << y << ", " << z << ", " << size << ", \"" << theGroupName << "\")"; -// else -// if (string(theGroupName).empty()) -// SMESH::TPythonDump() << _this() << ".SetEnforcedVertexNamed(" << theFaceEntry << ", " << x << ", " << y << ", " << z << ", \"" << theVertexName << "\")"; -// else -// SMESH::TPythonDump() << _this() << ".SetEnforcedVertexNamedWithGroup(" << theFaceEntry << ", " << x << ", " << y << ", " << z << ", \"" -// << theVertexName << "\", \"" << theGroupName << "\")"; + } + else { + if (string(theGroupName).empty()) + SMESH::TPythonDump() << "isDone = " << _this() << ".SetEnforcedVertexNamed(" << x << ", " << y << ", " << z << ", " << size << ", \"" << theVertexName << "\")"; + else + SMESH::TPythonDump() << "isDone = " << _this() << ".SetEnforcedVertexNamedWithGroup(" << x << ", " << y << ", " << z << ", " << size << ", \"" << theVertexName << "\", \"" << theGroupName << "\")"; } } - } else { - ::GHS3DPlugin_Hypothesis::TGeomEntryGHS3DEnforcedVertexMap enfVertexEntryList = this->GetImpl()->_GetEnforcedVerticesByEntry(); + } + else { +// if (isCompound || (!isCompound && !string(theVertexEntry).empty())) { + enfVertexEntryList = this->GetImpl()->_GetEnforcedVerticesByEntry(); // ::BLSURFPlugin_Hypothesis::TGeomEntryGHS3DEnforcedVertexMap::const_iterator it = enfVertexEntryList.find(theVertexEntry); if ( enfVertexEntryList.find(theVertexEntry) == enfVertexEntryList.end()) { MESSAGE("Geom entry not found: add it in enfVertexEntryList"); @@ -501,7 +556,7 @@ bool GHS3DPlugin_Hypothesis_i:: _SetEnforcedVertex(CORBA::Double size, CORBA::Do } if (newValue) - this->GetImpl()->SetEnforcedVertex(theVertexName, theVertexEntry, theGroupName, size, x, y, z); + this->GetImpl()->SetEnforcedVertex(theVertexName, theVertexEntry, theGroupName, size, x, y, z, isCompound); MESSAGE("IDL : SetEnforcedVertexEntry END"); return newValue; @@ -615,11 +670,13 @@ GHS3DPlugin::GHS3DEnforcedVertexList* GHS3DPlugin_Hypothesis_i::GetEnforcedVerti enfVertex->groupName = CORBA::string_dup(currentVertex->groupName.c_str()); // Size enfVertex->size = currentVertex->size; + // isCompound + enfVertex->isCompound = currentVertex->isCompound; result[i]=enfVertex; } - SMESH::TPythonDump() << "allEnforcedVertices = " << _this() << ".GetEnforcedVertices()"; +// SMESH::TPythonDump() << "allEnforcedVertices = " << _this() << ".GetEnforcedVertices()"; return result._retn(); } @@ -717,6 +774,42 @@ void GHS3DPlugin_Hypothesis_i::ClearEnforcedMeshes() SMESH::TPythonDump () << _this() << ".ClearEnforcedMeshes() "; } +//======================================================================= +//function : GetEnforcedMeshes +//======================================================================= + +GHS3DPlugin::GHS3DEnforcedMeshList* GHS3DPlugin_Hypothesis_i::GetEnforcedMeshes() +{ + ASSERT(myBaseImpl); + GHS3DPlugin::GHS3DEnforcedMeshList_var result = new GHS3DPlugin::GHS3DEnforcedMeshList(); + + const ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedMeshList enfMeshList = this->GetImpl()->_GetEnforcedMeshes(); + result->length( enfMeshList.size() ); + + ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedMeshList::const_iterator it = enfMeshList.begin(); + + for (int i = 0 ; it != enfMeshList.end(); ++it, ++i ) { + ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedMesh* currentMesh = (*it); + GHS3DPlugin::GHS3DEnforcedMesh_var enfMesh = new GHS3DPlugin::GHS3DEnforcedMesh(); + // Name + enfMesh->name = CORBA::string_dup(currentMesh->name.c_str()); + // Mesh Entry + enfMesh->entry = CORBA::string_dup(currentMesh->entry.c_str()); + // isCompound + enfMesh->elementType = currentMesh->elementType; + // Group Name + enfMesh->groupName = CORBA::string_dup(currentMesh->groupName.c_str()); + // Size + enfMesh->size = currentMesh->size; + + result[i]=enfMesh; + } + +// SMESH::TPythonDump() << "allEnforcedVertices = " << _this() << ".GetEnforcedVertices()"; + + return result._retn(); +} + /*! * \brief Adds enforced elements of type elementType using another mesh/sub-mesh/mesh group theSource. The elements will be grouped in theGroupName. */ @@ -724,21 +817,22 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshWithGroup(SMESH::SMESH_IDSource_pt throw (SALOME::SALOME_Exception) { #if GHS3D_VERSION >= 42 - bool res = _SetEnforcedMesh(theSource, theType, -1.0, theGroupName); - SMESH_Mesh_i* theMesh_i = SMESH::DownCast( theSource); - SMESH_Group_i* theGroup_i = SMESH::DownCast( theSource); - SMESH_GroupOnGeom_i* theGroupOnGeom_i = SMESH::DownCast( theSource); - if (theGroup_i || theGroupOnGeom_i) - { - SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshWithGroup( " - << theSource << ", " << theType << ", \"" << theGroupName << "\" )"; - } - else if (theMesh_i) - { - SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshWithGroup( " - << theSource << ".GetMesh(), " << theType << ", \"" << theGroupName << "\" )"; - } - return res; + return p_SetEnforcedMesh(theSource, theType, -1.0, theGroupName); +// bool res = p_SetEnforcedMesh(theSource, theType, -1.0, theGroupName); +// SMESH_Mesh_i* theMesh_i = SMESH::DownCast( theSource); +// SMESH_Group_i* theGroup_i = SMESH::DownCast( theSource); +// SMESH_GroupOnGeom_i* theGroupOnGeom_i = SMESH::DownCast( theSource); +// if (theGroup_i || theGroupOnGeom_i) +// { +// SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshWithGroup( " +// << theSource << ", " << theType << ", \"" << theGroupName << "\" )"; +// } +// else if (theMesh_i) +// { +// SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshWithGroup( " +// << theSource << ".GetMesh(), " << theType << ", \"" << theGroupName << "\" )"; +// } +// return res; #else SALOME::ExceptionStruct ExDescription; ExDescription.text = "Bad version of GHS3D. It must >= 4.2."; @@ -755,23 +849,24 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshWithGroup(SMESH::SMESH_IDSource_pt bool GHS3DPlugin_Hypothesis_i::SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType) throw (SALOME::SALOME_Exception) { - MESSAGE("GHS3DPlugin_Hypothesis_i::SetEnforcedMesh"); +// MESSAGE("GHS3DPlugin_Hypothesis_i::SetEnforcedMesh"); #if GHS3D_VERSION >= 42 - bool res = _SetEnforcedMesh(theSource, theType, -1.0); - SMESH_Mesh_i* theMesh_i = SMESH::DownCast( theSource); - SMESH_Group_i* theGroup_i = SMESH::DownCast( theSource); - SMESH_GroupOnGeom_i* theGroupOnGeom_i = SMESH::DownCast( theSource); - if (theGroup_i || theGroupOnGeom_i) - { - SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMesh( " - << theSource << ", " << theType << " )"; - } - else if (theMesh_i) - { - SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMesh( " - << theSource << ".GetMesh(), " << theType << " )"; - } - return res; + return p_SetEnforcedMesh(theSource, theType); +// bool res = p_SetEnforcedMesh(theSource, theType); +// SMESH_Mesh_i* theMesh_i = SMESH::DownCast( theSource); +// SMESH_Group_i* theGroup_i = SMESH::DownCast( theSource); +// SMESH_GroupOnGeom_i* theGroupOnGeom_i = SMESH::DownCast( theSource); +// if (theGroup_i || theGroupOnGeom_i) +// { +// SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMesh( " +// << theSource << ", " << theType << " )"; +// } +// else if (theMesh_i) +// { +// SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMesh( " +// << theSource << ".GetMesh(), " << theType << " )"; +// } +// return res; #else SALOME::ExceptionStruct ExDescription; ExDescription.text = "Bad version of GHS3D. It must >= 4.2."; @@ -788,7 +883,8 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSour bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshSizeWithGroup(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType, double theSize, const char* theGroupName) throw (SALOME::SALOME_Exception) { - if (theSize <= 0) { +#if GHS3D_VERSION >= 42 + if (theSize < 0) { SALOME::ExceptionStruct ExDescription; ExDescription.text = "Size cannot be negative"; ExDescription.type = SALOME::BAD_PARAM; @@ -797,21 +893,30 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshSizeWithGroup(SMESH::SMESH_IDSourc throw SALOME::SALOME_Exception(ExDescription); } - bool res = _SetEnforcedMesh(theSource, theType, theSize,theGroupName); - SMESH_Mesh_i* theMesh_i = SMESH::DownCast( theSource); - SMESH_Group_i* theGroup_i = SMESH::DownCast( theSource); - SMESH_GroupOnGeom_i* theGroupOnGeom_i = SMESH::DownCast( theSource); - if (theGroup_i || theGroupOnGeom_i) - { - SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshSizeWithGroup( " - << theSource << ", " << theType << ", " << theSize << ", \"" << theGroupName << "\" )"; - } - else if (theMesh_i) - { - SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshSizeWithGroup( " - << theSource << ".GetMesh(), " << theType << ", " << theSize << ", \"" << theGroupName << "\" )"; - } - return res; + return p_SetEnforcedMesh(theSource, theType, theSize, theGroupName); +// bool res = p_SetEnforcedMesh(theSource, theType, theSize, theGroupName); +// SMESH_Mesh_i* theMesh_i = SMESH::DownCast( theSource); +// SMESH_Group_i* theGroup_i = SMESH::DownCast( theSource); +// SMESH_GroupOnGeom_i* theGroupOnGeom_i = SMESH::DownCast( theSource); +// if (theGroup_i || theGroupOnGeom_i) +// { +// SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshSizeWithGroup( " +// << theSource << ", " << theType << ", " << theSize << ", \"" << theGroupName << "\" )"; +// } +// else if (theMesh_i) +// { +// SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshSizeWithGroup( " +// << theSource << ".GetMesh(), " << theType << ", " << theSize << ", \"" << theGroupName << "\" )"; +// } +// return res; +#else + SALOME::ExceptionStruct ExDescription; + ExDescription.text = "Bad version of GHS3D. It must >= 4.2."; + ExDescription.type = SALOME::BAD_PARAM; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx"; + ExDescription.lineNumber = 750; + throw SALOME::SALOME_Exception(ExDescription); +#endif } /*! @@ -820,36 +925,45 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshSizeWithGroup(SMESH::SMESH_IDSourc bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshSize(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType, double theSize) throw (SALOME::SALOME_Exception) { - if (theSize <= 0) { +#if GHS3D_VERSION >= 42 + if (theSize < 0) { SALOME::ExceptionStruct ExDescription; ExDescription.text = "Size cannot be negative"; ExDescription.type = SALOME::BAD_PARAM; ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx"; - ExDescription.lineNumber = 812; + ExDescription.lineNumber = 781; throw SALOME::SALOME_Exception(ExDescription); } - - bool res = _SetEnforcedMesh(theSource, theType, theSize); - SMESH_Mesh_i* theMesh_i = SMESH::DownCast( theSource); - SMESH_Group_i* theGroup_i = SMESH::DownCast( theSource); - SMESH_GroupOnGeom_i* theGroupOnGeom_i = SMESH::DownCast( theSource); - if (theGroup_i || theGroupOnGeom_i) - { - SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshSize( " - << theSource << ", " << theType << ", " << theSize << " )"; - } - else if (theMesh_i) - { - SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshSize( " - << theSource << ".GetMesh(), " << theType << ", " << theSize << " )"; - } - return res; + return p_SetEnforcedMesh(theSource, theType, theSize); +// bool res = p_SetEnforcedMesh(theSource, theType, theSize); +// SMESH_Mesh_i* theMesh_i = SMESH::DownCast( theSource); +// SMESH_Group_i* theGroup_i = SMESH::DownCast( theSource); +// SMESH_GroupOnGeom_i* theGroupOnGeom_i = SMESH::DownCast( theSource); +// if (theGroup_i || theGroupOnGeom_i) +// { +// SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshSize( " +// << theSource << ", " << theType << ", " << theSize << " )"; +// } +// else if (theMesh_i) +// { +// SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshSize( " +// << theSource << ".GetMesh(), " << theType << ", " << theSize << " )"; +// } +// return res; +#else + SALOME::ExceptionStruct ExDescription; + ExDescription.text = "Bad version of GHS3D. It must >= 4.2."; + ExDescription.type = SALOME::BAD_PARAM; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx"; + ExDescription.lineNumber = 750; + throw SALOME::SALOME_Exception(ExDescription); +#endif } -bool GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType, double theSize, const char* theGroupName) +bool GHS3DPlugin_Hypothesis_i::p_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType, double theSize, const char* theGroupName) throw (SALOME::SALOME_Exception) { - MESSAGE("GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh"); + MESSAGE("GHS3DPlugin_Hypothesis_i::p_SetEnforcedMesh"); ASSERT(myBaseImpl); if (CORBA::is_nil( theSource )) @@ -892,11 +1006,33 @@ bool GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSou SMESH_Group_i* theGroup_i = SMESH::DownCast( theSource); SMESH_GroupOnGeom_i* theGroupOnGeom_i = SMESH::DownCast( theSource); TIDSortedElemSet theElemSet; - + SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen(); + SALOMEDS::SObject_ptr SObj = smeshGen->ObjectToSObject(smeshGen->GetCurrentStudy(),theSource); if (theMesh_i) { try { - return this->GetImpl()->SetEnforcedMesh(theMesh_i->GetImpl(), theType, theSize, theGroupName); + bool res = this->GetImpl()->SetEnforcedMesh(theMesh_i->GetImpl(), theType, SObj->GetName() , SObj->GetID(), theSize, theGroupName); + if (theSize > 0) { + if (theGroupName != "") { + SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshSizeWithGroup( " + << theSource << ".GetMesh(), " << theType << ", " << theSize << ", \"" << theGroupName << "\" )"; + } + else { + SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshSize( " + << theSource << ".GetMesh(), " << theType << ", " << theSize << ", \"" << theGroupName << "\" )"; + } + } + else { + if (theGroupName != "") { + SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshWithGroup( " + << theSource << ".GetMesh(), " << theType << ", \"" << theGroupName << "\" )"; + } + else { + SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMesh( " + << theSource << ".GetMesh(), " << theType << " )"; + } + } + return res; } catch (const std::invalid_argument& ex) { SALOME::ExceptionStruct ExDescription; @@ -914,7 +1050,28 @@ bool GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSou { MESSAGE("The source is a group") try { - return this->GetImpl()->SetEnforcedGroup(theGroup_i->GetGroupDS()->GetMesh(),theGroup_i->GetListOfID(), theType, theSize, theGroupName); + bool res = this->GetImpl()->SetEnforcedGroup(theGroup_i->GetGroupDS()->GetMesh(), theGroup_i->GetListOfID(), theType, SObj->GetName() , SObj->GetID(), theSize, theGroupName); + if (theSize > 0) { + if (theGroupName != "") { + SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshSizeWithGroup( " + << theSource << ", " << theType << ", " << theSize << ", \"" << theGroupName << "\" )"; + } + else { + SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshSize( " + << theSource << ", " << theType << ", " << theSize << ", \"" << theGroupName << "\" )"; + } + } + else { + if (theGroupName != "") { + SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshWithGroup( " + << theSource << ", " << theType << ", \"" << theGroupName << "\" )"; + } + else { + SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMesh( " + << theSource << ", " << theType << " )"; + } + } + return res; } catch (const std::invalid_argument& ex) { SALOME::ExceptionStruct ExDescription; @@ -932,7 +1089,28 @@ bool GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSou { MESSAGE("The source is a group on geom") try { - return this->GetImpl()->SetEnforcedGroup(theGroupOnGeom_i->GetGroupDS()->GetMesh(),theGroupOnGeom_i->GetListOfID(), theType, theSize, theGroupName); + bool res = this->GetImpl()->SetEnforcedGroup(theGroupOnGeom_i->GetGroupDS()->GetMesh(),theGroupOnGeom_i->GetListOfID(), theType, SObj->GetName() , SObj->GetID(), theSize, theGroupName); + if (theSize > 0) { + if (theGroupName != "") { + SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshSizeWithGroup( " + << theSource << ", " << theType << ", " << theSize << ", \"" << theGroupName << "\" )"; + } + else { + SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshSize( " + << theSource << ", " << theType << ", " << theSize << ", \"" << theGroupName << "\" )"; + } + } + else { + if (theGroupName != "") { + SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMeshWithGroup( " + << theSource << ", " << theType << ", \"" << theGroupName << "\" )"; + } + else { + SMESH::TPythonDump () << "isDone = " << _this() << ".SetEnforcedMesh( " + << theSource << ", " << theType << " )"; + } + } + return res; } catch (const std::invalid_argument& ex) { SALOME::ExceptionStruct ExDescription; diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx index 3e5597a..8bfe974 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx @@ -125,26 +125,31 @@ class GHS3DPLUGIN_EXPORT GHS3DPlugin_Hypothesis_i: /*! * To set an enforced vertex */ - bool _SetEnforcedVertex(CORBA::Double size, CORBA::Double x = 0, CORBA::Double y = 0, CORBA::Double z = 0, - const char* theVertexName = "", const char* theVertexEntry = "", const char* theGroupName = "") - throw (SALOME::SALOME_Exception); + bool p_SetEnforcedVertex(CORBA::Double size, CORBA::Double x = 0, CORBA::Double y = 0, CORBA::Double z = 0, + const char* theVertexName = "", const char* theVertexEntry = "", const char* theGroupName = "", + CORBA::Boolean isCompound = false) + throw (SALOME::SALOME_Exception); bool SetEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size) throw (SALOME::SALOME_Exception); + bool SetEnforcedVertexNamed(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size, const char* theVertexName) throw (SALOME::SALOME_Exception); bool SetEnforcedVertexWithGroup(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size, const char* theGroupName) throw (SALOME::SALOME_Exception); - bool SetEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex, CORBA::Double size) throw (SALOME::SALOME_Exception); // TODO - bool SetEnforcedVertexGeomWithGroup(GEOM::GEOM_Object_ptr theVertex, CORBA::Double size, const char* theGroupName) throw (SALOME::SALOME_Exception); // TODO + bool SetEnforcedVertexNamedWithGroup(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size, const char* theVertexName, const char* theGroupName) throw (SALOME::SALOME_Exception); + bool SetEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex, CORBA::Double size) throw (SALOME::SALOME_Exception); + bool SetEnforcedVertexGeomWithGroup(GEOM::GEOM_Object_ptr theVertex, CORBA::Double size, const char* theGroupName) throw (SALOME::SALOME_Exception); CORBA::Double GetEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z) throw (SALOME::SALOME_Exception); - CORBA::Double GetEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex) throw (SALOME::SALOME_Exception); // TODO + CORBA::Double GetEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex) throw (SALOME::SALOME_Exception); bool RemoveEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z) throw (SALOME::SALOME_Exception); - bool RemoveEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex) throw (SALOME::SALOME_Exception); // TODO + bool RemoveEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex) throw (SALOME::SALOME_Exception); GHS3DPlugin::GHS3DEnforcedVertexList* GetEnforcedVertices(); void ClearEnforcedVertices(); /*! * To set an enforced mesh - */ + */ + bool p_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType elementType, double size = -1, const char* theGroupName="") throw (SALOME::SALOME_Exception); bool SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType elementType) throw (SALOME::SALOME_Exception); bool SetEnforcedMeshWithGroup(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType elementType, const char* theGroupName) throw (SALOME::SALOME_Exception); bool SetEnforcedMeshSize(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType elementType, double size) throw (SALOME::SALOME_Exception); bool SetEnforcedMeshSizeWithGroup(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType elementType, double size, const char* theGroupName) throw (SALOME::SALOME_Exception); + GHS3DPlugin::GHS3DEnforcedMeshList* GetEnforcedMeshes(); void ClearEnforcedMeshes(); // Get implementation @@ -153,9 +158,6 @@ class GHS3DPLUGIN_EXPORT GHS3DPlugin_Hypothesis_i: // Verify whether hypothesis supports given entity type CORBA::Boolean IsDimSupported( SMESH::Dimension type ); - private: - - bool _SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType elementType, double size, const char* theGroupName="") throw (SALOME::SALOME_Exception); }; #endif diff --git a/src/GUI/GHS3DPluginGUI.cxx b/src/GUI/GHS3DPluginGUI.cxx new file mode 100644 index 0000000..9007c1a --- /dev/null +++ b/src/GUI/GHS3DPluginGUI.cxx @@ -0,0 +1,50 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D +// +// 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.com +// + +// --- +// File : GHS3DPluginGUI.cxx +// Authors : Gilles DAVID (Euriware) +// --- +// +#ifdef WNT +// E.A. : On windows with python 2.6, there is a conflict +// E.A. : between pymath.h and Standard_math.h which define +// E.A. : some same symbols : acosh, asinh, ... +#include +#include +#endif + +#include "GHS3DPluginGUI_HypothesisCreator.h" + +//============================================================================= +/*! GetHypothesisCreator + * + */ +//============================================================================= +extern "C" +{ + GHS3DPLUGINGUI_EXPORT + SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator( const QString& aHypType ) + { + SMESHGUI_GenericHypothesisCreator* aCreator = NULL; + if ( aHypType == "GHS3D_Parameters" ) + aCreator = new GHS3DPluginGUI_HypothesisCreator( aHypType ); + return aCreator; + } +} \ No newline at end of file diff --git a/src/GUI/GHS3DPluginGUI_Enums.h b/src/GUI/GHS3DPluginGUI_Enums.h new file mode 100644 index 0000000..0ba8945 --- /dev/null +++ b/src/GUI/GHS3DPluginGUI_Enums.h @@ -0,0 +1,84 @@ +// Copyright (C) 2004-2011 CEA/DEN, EDF R&D +// +// 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.com +// + +// GHS3DPlugin GUI: GUI for plugged-in mesher GHS3DPlugin +// File : GHS3DPluginGUI_Enums.h +// Author : Gilles DAVID (Euriware) +// Module : GHS3DPlugin +// +#ifndef GHS3DPLUGINGUI_Enums_HeaderFile +#define GHS3DPLUGINGUI_Enums_HeaderFile + +// tabs +enum { + STD_TAB = 0, + ADV_TAB, + ENF_VER_TAB, + ENF_MESH_TAB +}; + +// Enforced vertices array columns +enum { + ENF_VER_NAME_COLUMN = 0, + ENF_VER_X_COLUMN, + ENF_VER_Y_COLUMN, + ENF_VER_Z_COLUMN, + ENF_VER_SIZE_COLUMN, + ENF_VER_ENTRY_COLUMN, + ENF_VER_COMPOUND_COLUMN, + ENF_VER_GROUP_COLUMN, + ENF_VER_NB_COLUMNS +}; + +// Enforced meshes array columns +enum { + ENF_MESH_NAME_COLUMN = 0, + ENF_MESH_ENTRY_COLUMN, + ENF_MESH_CONSTRAINT_COLUMN, + ENF_MESH_SIZE_COLUMN, + ENF_MESH_GROUP_COLUMN, + ENF_MESH_NB_COLUMNS +}; + +// Enforced vertices widget inputs +enum { + ENF_VER_WARNING = 0, + ENF_VER_VERTEX /*= 0*/, + ENF_VER_X_COORD, + ENF_VER_Y_COORD, + ENF_VER_Z_COORD, + ENF_VER_SIZE, + ENF_VER_GROUP, + ENF_VER_BTN, + ENF_VER_NB_LINES +}; + +// Enforced meshes widget inputs +enum { + ENF_MESH_WARNING = 0, + ENF_MESH_MESH /*= 0*/, + ENF_MESH_CONSTRAINT, + ENF_MESH_SIZE, + ENF_MESH_GROUP, + ENF_MESH_BTN, + ENF_MESH_NB_LINES +}; + + +#endif \ No newline at end of file diff --git a/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx index 4d4a278..2b8e500 100644 --- a/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx +++ b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx @@ -24,10 +24,19 @@ // $Header: // #include "GHS3DPluginGUI_HypothesisCreator.h" +// #include "GHS3DPluginGUI_EnforcedDelegates.h" +#include "GHS3DPluginGUI_Enums.h" + +#include "GeometryGUI.h" #include +#include #include +#include +#include +#include +#include #include #include #include @@ -35,7 +44,10 @@ #include #include +#include + #include +#include #include #include #include @@ -46,43 +58,16 @@ #include #include #include +#include #include -#include -#include +#include #include -#include #include #include -// tabs -enum { - STD_TAB = 0, - ADV_TAB, - ENF_VER_TAB -}; - -// Enforced vertices array columns -enum { - ENF_VER_X_COLUMN = 0, - ENF_VER_Y_COLUMN, - ENF_VER_Z_COLUMN, - ENF_VER_SIZE_COLUMN, - ENF_VER_NB_COLUMNS -}; - -// Enforced vertices inputs -enum { - ENF_VER_BTNS = 0, - ENF_VER_X_COORD, - ENF_VER_Y_COORD, - ENF_VER_Z_COORD, - ENF_VER_SIZE, - ENF_VER_VERTEX_BTN, - ENF_VER_SEPARATOR, - ENF_VER_REMOVE_BTN, -}; +#include namespace { @@ -120,66 +105,280 @@ namespace { } } -class QDoubleValidator; - // -// BEGIN DoubleLineEditDelegate +// BEGIN EnforcedVertexTableWidgetDelegate // -DoubleLineEditDelegate::DoubleLineEditDelegate(QObject *parent) +EnforcedVertexTableWidgetDelegate::EnforcedVertexTableWidgetDelegate(QObject *parent) : QItemDelegate(parent) { } -QWidget *DoubleLineEditDelegate::createEditor(QWidget *parent, - const QStyleOptionViewItem &/* option */, - const QModelIndex &/* index */) const +QWidget *EnforcedVertexTableWidgetDelegate::createEditor(QWidget *parent, + const QStyleOptionViewItem & option , + const QModelIndex & index ) const { + QModelIndex father = index.parent(); + QString entry = father.child(index.row(), ENF_VER_ENTRY_COLUMN).data().toString(); + + if (index.column() == ENF_VER_X_COLUMN || + index.column() == ENF_VER_Y_COLUMN || + index.column() == ENF_VER_Z_COLUMN || + index.column() == ENF_VER_SIZE_COLUMN) { + SMESHGUI_SpinBox *editor = new SMESHGUI_SpinBox(parent); + if (index.column() == ENF_VER_SIZE_COLUMN) + editor->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision"); + else + editor->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision"); + editor->setReadOnly(!entry.isEmpty()); + editor->setDisabled(!entry.isEmpty()); + return editor; + } +// else if (index.column() == ENF_VER_COMPOUND_COLUMN) { +// QCheckBox *editor = new QCheckBox(parent); +// editor->setDisabled(!entry.isEmpty()); +// return editor; +// } + else if (index.column() == ENF_VER_GROUP_COLUMN || + index.column() == ENF_VER_NAME_COLUMN) { +// else { QLineEdit *editor = new QLineEdit(parent); - editor->setValidator(new QDoubleValidator(parent)); - + if (index.column() != ENF_VER_GROUP_COLUMN) { + editor->setReadOnly(!entry.isEmpty()); + editor->setDisabled(!entry.isEmpty()); + } return editor; + } + return QItemDelegate::createEditor(parent, option, index); } -void DoubleLineEditDelegate::setEditorData(QWidget *editor, - const QModelIndex &index) const +void EnforcedVertexTableWidgetDelegate::setEditorData(QWidget *editor, + const QModelIndex &index) const { - QString value = index.model()->data(index, Qt::EditRole).toString(); + if (index.column() == ENF_VER_X_COLUMN || + index.column() == ENF_VER_Y_COLUMN || + index.column() == ENF_VER_Z_COLUMN || + index.column() == ENF_VER_SIZE_COLUMN) + { + SMESHGUI_SpinBox *lineEdit = qobject_cast(editor); + lineEdit->SetValue(index.data().toDouble()); + } + else if (index.column() == ENF_VER_COMPOUND_COLUMN) { + QCheckBox *checkBox = qobject_cast(editor); + checkBox->setChecked(index.data().toBool()); + } + else { + QItemDelegate::setEditorData(editor, index); + } +} - QLineEdit *lineEdit = static_cast(editor); - lineEdit->setText(value); +void EnforcedVertexTableWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const +{ + QModelIndex parent = index.parent(); + + QString entry = parent.child(index.row(), ENF_VER_ENTRY_COLUMN).data().toString(); + bool isCompound = parent.child(index.row(), ENF_VER_COMPOUND_COLUMN).data(Qt::CheckStateRole).toBool(); + + if (index.column() == ENF_VER_X_COLUMN || + index.column() == ENF_VER_Y_COLUMN || + index.column() == ENF_VER_Z_COLUMN) { + SMESHGUI_SpinBox *lineEdit = qobject_cast(editor); + if (!isCompound && !vertexExists(model, index, lineEdit->GetString())) + model->setData(index, lineEdit->GetValue(), Qt::EditRole); + } + else if (index.column() == ENF_VER_SIZE_COLUMN) + { + SMESHGUI_SpinBox *lineEdit = qobject_cast(editor); + const double newsize = lineEdit->GetValue(); + if (newsize > 0) + model->setData(index, newsize, Qt::EditRole); + } + else if (index.column() == ENF_VER_NAME_COLUMN) { + QLineEdit *lineEdit = qobject_cast(editor); + QString value = lineEdit->text(); + if (entry.isEmpty() && !vertexExists(model, index, value)) + model->setData(index, value, Qt::EditRole); + } + else if (index.column() == ENF_VER_ENTRY_COLUMN) { + QLineEdit *lineEdit = qobject_cast(editor); + QString value = lineEdit->text(); + if (! vertexExists(model, index, value)) + model->setData(index, value, Qt::EditRole); + } + else if (index.column() == ENF_VER_COMPOUND_COLUMN) { + QCheckBox *checkBox = qobject_cast(editor); + model->setData(index, checkBox->isChecked(), Qt::CheckStateRole); + } + else { + QItemDelegate::setModelData(editor, model, index); + } } -void DoubleLineEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const +void EnforcedVertexTableWidgetDelegate::updateEditorGeometry(QWidget *editor, + const QStyleOptionViewItem &option, const QModelIndex &/* index */) const { - QLineEdit *lineEdit = static_cast(editor); - bool ok; - double value = lineEdit->text().toDouble(&ok); + editor->setGeometry(option.rect); +} - if (ok) { - model->setData(index, value, Qt::EditRole); - MESSAGE("Value " << value << " was set at index(" << index.row() << "," << index.column() << ")"); +bool EnforcedVertexTableWidgetDelegate::vertexExists(QAbstractItemModel *model, + const QModelIndex &index, + QString value) const +{ + bool exists = false; + QModelIndex parent = index.parent(); + int row = index.row(); + int col = index.column(); + + if (parent.isValid() && !value.isEmpty()) { + if (col == ENF_VER_X_COLUMN || col == ENF_VER_Y_COLUMN || col == ENF_VER_Z_COLUMN) { + double x, y, z; + if (col == ENF_VER_X_COLUMN) { + x = value.toDouble(); + y = parent.child(row, ENF_VER_Y_COLUMN).data().toDouble(); + z = parent.child(row, ENF_VER_Z_COLUMN).data().toDouble(); + } + if (col == ENF_VER_Y_COLUMN) { + y = value.toDouble(); + x = parent.child(row, ENF_VER_X_COLUMN).data().toDouble(); + z = parent.child(row, ENF_VER_Z_COLUMN).data().toDouble(); + } + if (col == ENF_VER_Z_COLUMN) { + z = value.toDouble(); + x = parent.child(row, ENF_VER_X_COLUMN).data().toDouble(); + y = parent.child(row, ENF_VER_Y_COLUMN).data().toDouble(); + } + int nbChildren = model->rowCount(parent); + for (int i = 0 ; i < nbChildren ; i++) { + if (i != row) { + double childX = parent.child(i, ENF_VER_X_COLUMN).data().toDouble(); + double childY = parent.child(i, ENF_VER_Y_COLUMN).data().toDouble(); + double childZ = parent.child(i, ENF_VER_Z_COLUMN).data().toDouble(); + if ((childX == x) && (childY == y) && (childZ == z)) { + exists = true; + break; + } + } + } + } + else if (col == ENF_VER_NAME_COLUMN) { + QString name = parent.child(row, ENF_VER_NAME_COLUMN).data().toString(); + if (name == value) + exists = true; } + } + + return exists; } -void DoubleLineEditDelegate::updateEditorGeometry(QWidget *editor, +// +// END EnforcedVertexTableWidgetDelegate +// + +// +// BEGIN EnforcedMeshTableWidgetDelegate +// + +EnforcedMeshTableWidgetDelegate::EnforcedMeshTableWidgetDelegate(QObject *parent) + : QItemDelegate(parent) +{ +} + +QWidget *EnforcedMeshTableWidgetDelegate::createEditor(QWidget *parent, + const QStyleOptionViewItem & option , + const QModelIndex & index ) const +{ + if (index.column() == ENF_MESH_SIZE_COLUMN) { + SMESHGUI_SpinBox *editor = new SMESHGUI_SpinBox(parent); + editor->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision"); + return editor; + } + return QItemDelegate::createEditor(parent, option, index); +} + +void EnforcedMeshTableWidgetDelegate::setEditorData(QWidget *editor, + const QModelIndex &index) const +{ + if (index.column() == ENF_MESH_SIZE_COLUMN) { + SMESHGUI_SpinBox *spinBox = qobject_cast(editor); + spinBox->SetValue(index.data().toDouble()); + } + else + QItemDelegate::setEditorData(editor, index); +} + +void EnforcedMeshTableWidgetDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const +{ + if (index.column() == ENF_MESH_SIZE_COLUMN) + { + SMESHGUI_SpinBox *spinBox = qobject_cast(editor); + const double newsize = spinBox->GetValue(); + if (newsize > 0) + model->setData(index, newsize, Qt::EditRole); + } + else + QItemDelegate::setModelData(editor, model, index); + +} + +void EnforcedMeshTableWidgetDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const { editor->setGeometry(option.rect); } +// bool EnforcedMeshTableWidgetDelegate::enfMeshExists(QAbstractItemModel *model, +// const QModelIndex &index, +// QString value) const +// { +// bool exists = false; +// QModelIndex parent = index.parent(); +// int row = index.row(); +// int col = index.column(); +// return exists; +// } + // -// END DoubleLineEditDelegate +// END EnforcedMeshTableWidgetDelegate // + GHS3DPluginGUI_HypothesisCreator::GHS3DPluginGUI_HypothesisCreator( const QString& theHypType ) : SMESHGUI_GenericHypothesisCreator( theHypType ) { + GeomToolSelected = NULL; + GeomToolSelected = getGeomSelectionTool(); + + iconVertex = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_OBJBROWSER_VERTEX"))); + iconCompound = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_OBJBROWSER_COMPOUND"))); +// mySelectionMgr = SMESH::GetSelectionMgr(SMESHGUI::GetSMESHGUI()); + myEnfMeshConstraintLabels << tr( "GHS3D_ENF_MESH_CONSTRAINT_NODE" ) << tr( "GHS3D_ENF_MESH_CONSTRAINT_EDGE" ) << tr("GHS3D_ENF_MESH_CONSTRAINT_FACE"); } GHS3DPluginGUI_HypothesisCreator::~GHS3DPluginGUI_HypothesisCreator() { + GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this; + that->getGeomSelectionTool()->selectionMgr()->clearFilters(); + myEnfMeshWdg->deactivateSelection(); +} + +/** + * \brief {Get or create the geom selection tool for active study} + * */ +GeomSelectionTools* GHS3DPluginGUI_HypothesisCreator::getGeomSelectionTool() +{ + GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this; + _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); + if (that->GeomToolSelected == NULL || that->GeomToolSelected->getMyStudy() != aStudy) { + that->GeomToolSelected = new GeomSelectionTools(aStudy); + } + return that->GeomToolSelected; +} + +GEOM::GEOM_Gen_var GHS3DPluginGUI_HypothesisCreator::getGeomEngine() +{ + return GeometryGUI::GetGeomGen(); } QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame() @@ -213,7 +412,7 @@ QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame() myToMeshHolesCheck = new QCheckBox( tr( "GHS3D_TO_MESH_HOLES" ), myStdGroup ); aStdLayout->addWidget( myToMeshHolesCheck, row++, 0, 1, 2 ); - aStdLayout->addWidget( new QLabel( tr( "GHS3D_OPTIMIZATIOL_LEVEL" ), myStdGroup ), row, 0 ); + aStdLayout->addWidget( new QLabel( tr( "GHS3D_OPTIMIZATIOL_LEVEL" ), myStdGroup ), row, 0, 1, 1 ); myOptimizationLevelCombo = new QComboBox( myStdGroup ); aStdLayout->addWidget( myOptimizationLevelCombo, row++, 1, 1, 1 ); @@ -221,7 +420,7 @@ QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame() types << tr( "LEVEL_NONE" ) << tr( "LEVEL_LIGHT" ) << tr( "LEVEL_MEDIUM" ) << tr( "LEVEL_STANDARDPLUS" ) << tr( "LEVEL_STRONG" ); myOptimizationLevelCombo->addItems( types ); - aStdLayout->setRowStretch( row, 5 ); + aStdLayout->setRowStretch( row, 10 ); // advanced parameters myAdvGroup = new QWidget(); @@ -287,60 +486,180 @@ QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame() anAdvLayout->addWidget( aTextOptionLabel, 9, 0, 1, 1 ); anAdvLayout->addWidget( myTextOption, 9, 1, 1, 2 ); - // Size Maps parameters + // Enforced vertices parameters myEnfGroup = new QWidget(); - QGridLayout* anSmpLayout = new QGridLayout(myEnfGroup); - - mySmpModel = new QStandardItemModel(0, ENF_VER_NB_COLUMNS); - myEnforcedTableView = new QTableView(myEnfGroup); - myEnforcedTableView->setModel(mySmpModel); - myEnforcedTableView->setSortingEnabled(true); - myEnforcedTableView->setItemDelegateForColumn(ENF_VER_SIZE_COLUMN,new DoubleLineEditDelegate(this)); - anSmpLayout->addWidget(myEnforcedTableView, 1, 0, 9, 1); + QGridLayout* anEnfLayout = new QGridLayout(myEnfGroup); + + myEnforcedTableWidget = new QTableWidget(myEnfGroup); + myEnforcedTableWidget ->setMinimumWidth(300); + myEnforcedTableWidget->setRowCount( 0 ); + myEnforcedTableWidget->setColumnCount( ENF_VER_NB_COLUMNS ); + myEnforcedTableWidget->setSortingEnabled(true); QStringList enforcedHeaders; - enforcedHeaders << tr( "GHS3D_ENF_VER_X_COLUMN" )<< tr( "GHS3D_ENF_VER_Y_COLUMN" ) << tr( "GHS3D_ENF_VER_Z_COLUMN" ) << tr( "GHS3D_ENF_VER_SIZE_COLUMN" ); - mySmpModel->setHorizontalHeaderLabels(enforcedHeaders); - myEnforcedTableView->setAlternatingRowColors(true); - myEnforcedTableView->verticalHeader()->hide(); - myEnforcedTableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch); + enforcedHeaders << tr( "GHS3D_ENF_NAME_COLUMN" ) + << tr( "GHS3D_ENF_VER_X_COLUMN" )<< tr( "GHS3D_ENF_VER_Y_COLUMN" ) << tr( "GHS3D_ENF_VER_Z_COLUMN" ) + << tr( "GHS3D_ENF_SIZE_COLUMN" ) << tr("GHS3D_ENF_ENTRY_COLUMN") << tr("GHS3D_ENF_VER_COMPOUND_COLUMN") << tr( "GHS3D_ENF_GROUP_COLUMN" ); + + myEnforcedTableWidget->setHorizontalHeaderLabels(enforcedHeaders); + myEnforcedTableWidget->verticalHeader()->hide(); + myEnforcedTableWidget->horizontalHeader()->setStretchLastSection(true); + myEnforcedTableWidget->setAlternatingRowColors(true); + myEnforcedTableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); + myEnforcedTableWidget->setSelectionBehavior(QAbstractItemView::SelectItems); + myEnforcedTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Interactive); + myEnforcedTableWidget->resizeColumnsToContents(); + myEnforcedTableWidget->hideColumn(ENF_VER_ENTRY_COLUMN); + myEnforcedTableWidget->hideColumn(ENF_VER_COMPOUND_COLUMN); + + myEnforcedTableWidget->setItemDelegate(new EnforcedVertexTableWidgetDelegate()); + +// VERTEX SELECTION + TColStd_MapOfInteger shapeTypes; + shapeTypes.Add( TopAbs_VERTEX ); + shapeTypes.Add( TopAbs_COMPOUND ); + + SMESH_NumberFilter* vertexFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, shapeTypes); + myEnfVertexWdg = new StdMeshersGUI_ObjectReferenceParamWdg( vertexFilter, 0, /*multiSel=*/true, /*stretch=*/false); + myEnfVertexWdg->SetDefaultText(tr("GHS3D_ENF_SELECT_VERTEX"), "QLineEdit { color: grey }"); QLabel* myXCoordLabel = new QLabel( tr( "GHS3D_ENF_VER_X_LABEL" ), myEnfGroup ); - anSmpLayout->addWidget(myXCoordLabel, ENF_VER_X_COORD, 1, 1, 1); - myXCoord = new QLineEdit(myEnfGroup); - myXCoord->setValidator(new QDoubleValidator(myEnfGroup)); - anSmpLayout->addWidget(myXCoord, ENF_VER_X_COORD, 2, 1, 1); + myXCoord = new SMESHGUI_SpinBox(myEnfGroup); + myXCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision"); QLabel* myYCoordLabel = new QLabel( tr( "GHS3D_ENF_VER_Y_LABEL" ), myEnfGroup ); - anSmpLayout->addWidget(myYCoordLabel, ENF_VER_Y_COORD, 1, 1, 1); - myYCoord = new QLineEdit(myEnfGroup); - myYCoord->setValidator(new QDoubleValidator(myEnfGroup)); - anSmpLayout->addWidget(myYCoord, ENF_VER_Y_COORD, 2, 1, 1); + myYCoord = new SMESHGUI_SpinBox(myEnfGroup); + myYCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision"); QLabel* myZCoordLabel = new QLabel( tr( "GHS3D_ENF_VER_Z_LABEL" ), myEnfGroup ); - anSmpLayout->addWidget(myZCoordLabel, ENF_VER_Z_COORD, 1, 1, 1); - myZCoord = new QLineEdit(myEnfGroup); - myZCoord->setValidator(new QDoubleValidator(myEnfGroup)); - anSmpLayout->addWidget(myZCoord, ENF_VER_Z_COORD, 2, 1, 1); - QLabel* mySizeLabel = new QLabel( tr( "GHS3D_ENF_VER_SIZE_LABEL" ), myEnfGroup ); - anSmpLayout->addWidget(mySizeLabel, ENF_VER_SIZE, 1, 1, 1); - mySizeValue = new QLineEdit(myEnfGroup); - mySizeValue->setValidator(new QDoubleValidator(myEnfGroup)); - anSmpLayout->addWidget(mySizeValue, ENF_VER_SIZE, 2, 1, 1); - - addVertexButton = new QPushButton(tr("GHS3D_ENF_VER_VERTEX"),myEnfGroup); - anSmpLayout->addWidget(addVertexButton, ENF_VER_VERTEX_BTN, 1, 1, 2); + myZCoord = new SMESHGUI_SpinBox(myEnfGroup); + myZCoord->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision"); + QLabel* mySizeLabel = new QLabel( tr( "GHS3D_ENF_SIZE_LABEL" ), myEnfGroup ); + mySizeValue = new SMESHGUI_SpinBox(myEnfGroup); + mySizeValue->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision"); + + QLabel* myGroupNameLabel = new QLabel( tr( "GHS3D_ENF_GROUP_LABEL" ), myEnfGroup ); + myGroupName = new QLineEdit(myEnfGroup); + + addVertexButton = new QPushButton(tr("GHS3D_ENF_ADD"),myEnfGroup); addVertexButton->setEnabled(false); + removeVertexButton = new QPushButton(tr("GHS3D_ENF_REMOVE"),myEnfGroup); +// myGlobalGroupName = new QCheckBox(tr("GHS3D_ENF_VER_GROUPS"), myEnfGroup); +// myGlobalGroupName->setChecked(false); + + QGroupBox* GroupBox = new QGroupBox( myEnfGroup ); + QLabel* info = new QLabel( GroupBox ); + info->setText( tr( "GHS3D_ENF_VER_INFO" ) ); + info->setWordWrap( true ); + QVBoxLayout* GroupBoxVLayout = new QVBoxLayout( GroupBox ); + GroupBoxVLayout->setSpacing( 6 ); + GroupBoxVLayout->setMargin( 11 ); + GroupBoxVLayout->addWidget( info ); + + + anEnfLayout->addWidget(GroupBox, ENF_VER_WARNING, 0, 1, 2 ); + anEnfLayout->addWidget(myEnforcedTableWidget, ENF_VER_VERTEX, 0, ENF_VER_NB_LINES, 1); + + QGridLayout* anEnfLayout2 = new QGridLayout(myEnfGroup); + anEnfLayout2->addWidget(myEnfVertexWdg, ENF_VER_VERTEX, 0, 1, 2); + anEnfLayout2->addWidget(myXCoordLabel, ENF_VER_X_COORD, 0, 1, 1); + anEnfLayout2->addWidget(myXCoord, ENF_VER_X_COORD, 1, 1, 1); + anEnfLayout2->addWidget(myYCoordLabel, ENF_VER_Y_COORD, 0, 1, 1); + anEnfLayout2->addWidget(myYCoord, ENF_VER_Y_COORD, 1, 1, 1); + anEnfLayout2->addWidget(myZCoordLabel, ENF_VER_Z_COORD, 0, 1, 1); + anEnfLayout2->addWidget(myZCoord, ENF_VER_Z_COORD, 1, 1, 1); + anEnfLayout2->addWidget(mySizeLabel, ENF_VER_SIZE, 0, 1, 1); + anEnfLayout2->addWidget(mySizeValue, ENF_VER_SIZE, 1, 1, 1); + anEnfLayout2->addWidget(myGroupNameLabel, ENF_VER_GROUP, 0, 1, 1); + anEnfLayout2->addWidget(myGroupName, ENF_VER_GROUP, 1, 1, 1); + anEnfLayout2->addWidget(addVertexButton, ENF_VER_BTN, 0, 1, 1); + anEnfLayout2->addWidget(removeVertexButton, ENF_VER_BTN, 1, 1, 1); + anEnfLayout2->setRowStretch(ENF_VER_NB_LINES, 1); + + anEnfLayout->addLayout(anEnfLayout2, ENF_VER_VERTEX, 1,ENF_VER_NB_LINES, 1); + anEnfLayout->setRowStretch(ENF_VER_VERTEX, 10); + + + // Enforced meshes parameters + myEnfMeshGroup = new QWidget(); + QGridLayout* anEnfMeshLayout = new QGridLayout(myEnfMeshGroup); + + myEnforcedMeshTableWidget = new QTableWidget(myEnfGroup); + myEnforcedMeshTableWidget->setRowCount( 0 ); + myEnforcedMeshTableWidget->setColumnCount( ENF_MESH_NB_COLUMNS ); + myEnforcedMeshTableWidget->setSortingEnabled(true); + myEnforcedMeshTableWidget->verticalHeader()->hide(); + QStringList enforcedMeshHeaders; + enforcedMeshHeaders << tr( "GHS3D_ENF_NAME_COLUMN" ) + << tr( "GHS3D_ENF_ENTRY_COLUMN" ) + << tr( "GHS3D_ENF_MESH_CONSTRAINT_COLUMN" ) + << tr( "GHS3D_ENF_SIZE_COLUMN" ) + << tr( "GHS3D_ENF_GROUP_COLUMN" ); + myEnforcedMeshTableWidget->setHorizontalHeaderLabels(enforcedMeshHeaders); + myEnforcedMeshTableWidget->horizontalHeader()->setStretchLastSection(true); + myEnforcedMeshTableWidget->horizontalHeader()->setResizeMode(QHeaderView::Interactive); + myEnforcedMeshTableWidget->setAlternatingRowColors(true); + myEnforcedMeshTableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); + myEnforcedMeshTableWidget->setSelectionBehavior(QAbstractItemView::SelectItems); + myEnforcedMeshTableWidget->resizeColumnsToContents(); + myEnforcedMeshTableWidget->hideColumn(ENF_MESH_ENTRY_COLUMN); + + myEnforcedMeshTableWidget->setItemDelegate(new EnforcedMeshTableWidgetDelegate()); + +// myEnfMesh = SMESH::SMESH_Mesh::_nil(); +// myEnfMeshArray = new SMESH::mesh_array(); - QFrame *line = new QFrame(myEnfGroup); - line->setFrameShape(QFrame::HLine); - line->setFrameShadow(QFrame::Sunken); - anSmpLayout->addWidget(line, ENF_VER_SEPARATOR, 1, 1, 2); + myEnfMeshWdg = new StdMeshersGUI_ObjectReferenceParamWdg( IDSOURCE, myEnfMeshGroup, /*multiSel=*/true); + myEnfMeshWdg->SetDefaultText(tr("GHS3D_ENF_SELECT_MESH"), "QLineEdit { color: grey }"); + + myEnfMeshWdg->AvoidSimultaneousSelection(myEnfVertexWdg); + + QLabel* myMeshConstraintLabel = new QLabel( tr( "GHS3D_ENF_MESH_CONSTRAINT_LABEL" ), myEnfMeshGroup ); + myEnfMeshConstraint = new QComboBox(myEnfMeshGroup); + myEnfMeshConstraint->insertItems(0,myEnfMeshConstraintLabels); + myEnfMeshConstraint->setEditable(false); + myEnfMeshConstraint->setCurrentIndex(0); + + QLabel* myMeshSizeLabel = new QLabel( tr( "GHS3D_ENF_SIZE_LABEL" ), myEnfMeshGroup ); + myMeshSizeValue = new SMESHGUI_SpinBox(myEnfMeshGroup); + myMeshSizeValue->RangeStepAndValidator(0, COORD_MAX, 10.0, "length_precision"); - removeVertexButton = new QPushButton(tr("GHS3D_ENF_VER_REMOVE"),myEnfGroup); - anSmpLayout->addWidget(removeVertexButton, ENF_VER_REMOVE_BTN, 1, 1, 2); - + QLabel* myMeshGroupNameLabel = new QLabel( tr( "GHS3D_ENF_GROUP_LABEL" ), myEnfMeshGroup ); + myMeshGroupName = new QLineEdit(myEnfMeshGroup); + + addEnfMeshButton = new QPushButton(tr("GHS3D_ENF_ADD"),myEnfMeshGroup); +// addEnfMeshButton->setEnabled(false); + removeEnfMeshButton = new QPushButton(tr("GHS3D_ENF_REMOVE"),myEnfMeshGroup); + + QGroupBox* GroupBox2 = new QGroupBox( myEnfMeshGroup ); + QLabel* info2 = new QLabel( GroupBox2 ); + info2->setText( tr( "GHS3D_ENF_MESH_INFO" ) ); + info2->setWordWrap( true ); + QVBoxLayout* GroupBox2VLayout = new QVBoxLayout( GroupBox2 ); + GroupBox2VLayout->setSpacing( 6 ); + GroupBox2VLayout->setMargin( 11 ); + GroupBox2VLayout->addWidget( info2 ); + + anEnfMeshLayout->addWidget( GroupBox2, ENF_MESH_WARNING, 0, 1, 2 ); + anEnfMeshLayout->addWidget(myEnforcedMeshTableWidget, ENF_MESH_MESH, 0, ENF_MESH_NB_LINES , 1); + + QGridLayout* anEnfMeshLayout2 = new QGridLayout(myEnfMeshGroup); + anEnfMeshLayout2->addWidget(myEnfMeshWdg, ENF_MESH_MESH, 0, 1, 2); + anEnfMeshLayout2->addWidget(myMeshConstraintLabel, ENF_MESH_CONSTRAINT, 0, 1, 1); + anEnfMeshLayout2->addWidget(myEnfMeshConstraint, ENF_MESH_CONSTRAINT, 1, 1, 1); + anEnfMeshLayout2->addWidget(myMeshSizeLabel, ENF_MESH_SIZE, 0, 1, 1); + anEnfMeshLayout2->addWidget(myMeshSizeValue, ENF_MESH_SIZE, 1, 1, 1); + anEnfMeshLayout2->addWidget(myMeshGroupNameLabel, ENF_MESH_GROUP, 0, 1, 1); + anEnfMeshLayout2->addWidget(myMeshGroupName, ENF_MESH_GROUP, 1, 1, 1); + anEnfMeshLayout2->addWidget(addEnfMeshButton, ENF_MESH_BTN, 0, 1, 1); + anEnfMeshLayout2->addWidget(removeEnfMeshButton, ENF_MESH_BTN, 1, 1, 1); + anEnfMeshLayout2->setRowStretch(ENF_MESH_NB_LINES, 1); + + anEnfMeshLayout->addLayout(anEnfMeshLayout2, ENF_MESH_MESH, 1, ENF_MESH_NB_LINES, 1); + anEnfMeshLayout->setRowStretch(ENF_MESH_MESH, 10); + // add tabs tab->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) ); tab->insertTab( ADV_TAB, myAdvGroup, tr( "GHS3D_ADV_ARGS" ) ); tab->insertTab( ENF_VER_TAB, myEnfGroup, tr( "GHS3D_ENFORCED_VERTICES" ) ); + tab->insertTab( ENF_MESH_TAB, myEnfMeshGroup, tr( "GHS3D_ENFORCED_MESHES" ) ); tab->setCurrentIndex( STD_TAB ); // connections @@ -348,108 +667,758 @@ QFrame* GHS3DPluginGUI_HypothesisCreator::buildFrame() connect( myInitialMemoryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) ); connect( myBoundaryRecoveryCheck, SIGNAL( toggled( bool ) ), this, SLOT( updateWidgets() ) ); connect( dirBtn, SIGNAL( clicked() ), this, SLOT( onDirBtnClicked() ) ); - connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) ); - connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) ); - connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) ); - connect( mySizeValue, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) ); + connect( myEnforcedTableWidget, SIGNAL( itemClicked(QTableWidgetItem *)), this, SLOT( synchronizeCoords() ) ); + connect( myEnforcedTableWidget, SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) ); + connect( myEnforcedTableWidget, SIGNAL( itemSelectionChanged() ), this, SLOT( synchronizeCoords() ) ); + connect( addVertexButton, SIGNAL( clicked()), this, SLOT( onAddEnforcedVertex() ) ); + connect( removeVertexButton, SIGNAL( clicked()), this, SLOT( onRemoveEnforcedVertex() ) ); + connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) ); + connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( checkVertexIsDefined() ) ); + connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + connect( mySizeValue, SIGNAL( textChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) ); + connect( myXCoord, SIGNAL( valueChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + connect( myYCoord, SIGNAL( valueChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + connect( myZCoord, SIGNAL( valueChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + connect( mySizeValue, SIGNAL( valueChanged(const QString&) ), this, SLOT( checkVertexIsDefined() ) ); connect( this, SIGNAL( vertexDefined(bool) ), addVertexButton, SLOT( setEnabled(bool) ) ); - connect( addVertexButton, SIGNAL( clicked() ), this, SLOT( onVertexBtnClicked() ) ); - connect( removeVertexButton, SIGNAL( clicked() ), this, SLOT( onRemoveVertexBtnClicked() ) ); - + connect( addEnfMeshButton, SIGNAL( clicked()), this, SLOT( onAddEnforcedMesh() ) ); + connect( removeEnfMeshButton, SIGNAL( clicked()), this, SLOT( onRemoveEnforcedMesh() ) ); +// connect( myEnfMeshWdg, SIGNAL( contentModified()), this, SLOT( checkEnfMeshIsDefined() ) ); +// connect( myEnfMeshConstraint, SIGNAL( currentIndexChanged(int) ), this, SLOT( checkEnfMeshIsDefined() ) ); +// connect( myMeshSizeValue, SIGNAL( textChanged(const QString&) ), this, SLOT( checkEnfMeshIsDefined() ) ); +// connect( this, SIGNAL( enfMeshDefined(bool) ), addEnfMeshButton, SLOT( setEnabled(bool) ) ); return fr; } -bool GHS3DPluginGUI_HypothesisCreator::smpVertexExists(double x, double y, double z) const -{ - const int rowCount = mySmpModel->rowCount(); - for (int i=0 ; i < rowCount ; i++) { - double myX = mySmpModel->data(mySmpModel->index(i, ENF_VER_X_COLUMN)).toDouble(); - if (myX == x) { -// MESSAGE("Found x value " << x << " at row " << i); - double myY = mySmpModel->data(mySmpModel->index(i, ENF_VER_Y_COLUMN)).toDouble(); - if (myY == y) { -// MESSAGE("Found y value " << y << " at row " << i); - double myZ = mySmpModel->data(mySmpModel->index(i, ENF_VER_Z_COLUMN)).toDouble(); - if (myZ == z) { - MESSAGE("Found x value " << x << " at row " << i); - MESSAGE("Found y value " << y << " at row " << i); - MESSAGE("Found z value " << z << " at row " << i); - return true; - } - } +/** + * This method checks if an enforced vertex is defined; +**/ +void GHS3DPluginGUI_HypothesisCreator::clearEnfVertexSelection() +{ + if (myEnfVertexWdg->NbObjects() != 0) { + disconnect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) ); + disconnect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( checkVertexIsDefined() ) ); + myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil()); + connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) ); + connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( checkVertexIsDefined() ) ); + } + GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this; + that->checkVertexIsDefined(); +} + +/** + * This method checks if an enforced vertex is defined; +**/ +void GHS3DPluginGUI_HypothesisCreator::checkVertexIsDefined() +{ + bool enfVertexIsDefined = false; + enfVertexIsDefined = (!mySizeValue->GetString().isEmpty() && + (!myEnfVertexWdg->NbObjects() == 0 || + (myEnfVertexWdg->NbObjects() == 0 && !myXCoord->GetString().isEmpty() + && !myYCoord->GetString().isEmpty() + && !myZCoord->GetString().isEmpty()))); + emit vertexDefined(enfVertexIsDefined); +} + +/** + * This method checks if an enforced mesh is defined; +**/ +void GHS3DPluginGUI_HypothesisCreator::checkEnfMeshIsDefined() +{ + emit enfMeshDefined((!myMeshSizeValue->GetString().isEmpty() && !myEnfVertexWdg->NbObjects() == 0)); +} + +/** + * This method resets the content of the X, Y, Z, size and GroupName widgets; +**/ +void GHS3DPluginGUI_HypothesisCreator::clearEnforcedVertexWidgets() +{ + myXCoord->setCleared(true); + myYCoord->setCleared(true); + myZCoord->setCleared(true); +// mySizeValue->setCleared(true); + myXCoord->setText(""); + myYCoord->setText(""); + myZCoord->setText(""); +// mySizeValue->setText(""); +// myGroupName->setText(""); + addVertexButton->setEnabled(false); +} + +/** GHS3DPluginGUI_HypothesisCreator::updateEnforcedVertexValues(item) +This method updates the tooltip of a modified item. The QLineEdit widgets content +is synchronized with the coordinates of the enforced vertex clicked in the tree widget. +*/ +void GHS3DPluginGUI_HypothesisCreator::updateEnforcedVertexValues(QTableWidgetItem* item) { +// MESSAGE("GHS3DPluginGUI_HypothesisCreator::updateEnforcedVertexValues"); + int row = myEnforcedTableWidget->row(item); + + QVariant vertexName = myEnforcedTableWidget->item(row,ENF_VER_NAME_COLUMN)->data(Qt::EditRole); + QVariant x = myEnforcedTableWidget->item(row,ENF_VER_X_COLUMN)->data( Qt::EditRole); + QVariant y = myEnforcedTableWidget->item(row,ENF_VER_Y_COLUMN)->data( Qt::EditRole); + QVariant z = myEnforcedTableWidget->item(row,ENF_VER_Z_COLUMN)->data( Qt::EditRole); + QVariant size = myEnforcedTableWidget->item(row,ENF_VER_SIZE_COLUMN)->data( Qt::EditRole); + QVariant entry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data( Qt::EditRole); + QString groupName = myEnforcedTableWidget->item(row,ENF_VER_GROUP_COLUMN)->data( Qt::EditRole).toString(); + + clearEnforcedVertexWidgets(); + + if ( !x.isNull() || !entry.isNull()) { + QString toolTip = vertexName.toString(); + toolTip += QString("("); + if (entry.isNull() || (!entry.isNull() && entry.toString() == "")) { + toolTip += x.toString(); + toolTip += QString(", ") + y.toString(); + toolTip += QString(", ") + z.toString(); + } + else + toolTip += entry.toString(); + toolTip += QString(")"); + + if (!size.isNull()) + toolTip += QString("=") + size.toString(); + + if (!groupName.isEmpty()) + toolTip += QString(" [") + groupName + QString("]"); + +// MESSAGE("Tooltip: " << toolTip.toStdString()); + for (int col=0;colitem(row,col)->setToolTip(toolTip); + + if (!x.isNull()) { + disconnect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + disconnect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + disconnect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + myXCoord->SetValue(x.toDouble()); + myYCoord->SetValue(y.toDouble()); + myZCoord->SetValue(z.toDouble()); + connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + } + if (!size.isNull()) + mySizeValue->SetValue(size.toDouble()); + + if (!groupName.isEmpty()) + myGroupName->setText(groupName); + } +} + +void GHS3DPluginGUI_HypothesisCreator::onSelectEnforcedVertex() { + int nbSelEnfVertex = myEnfVertexWdg->NbObjects(); + clearEnforcedVertexWidgets(); + if (nbSelEnfVertex == 1) + { + if ( CORBA::is_nil( getGeomEngine() ) && !GeometryGUI::InitGeomGen() ) + return ; + + myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(nbSelEnfVertex-1); + if (myEnfVertex == GEOM::GEOM_Object::_nil()) + return; + if (myEnfVertex->GetShapeType() == GEOM::VERTEX) { + GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this; + GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() ); + if (CORBA::is_nil(measureOp)) + return; + + CORBA::Double x,y,z; + measureOp->PointCoordinates (myEnfVertex, x, y, z); + if ( measureOp->IsDone() ) + { + disconnect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + disconnect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + disconnect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + myXCoord->SetValue(x); + myYCoord->SetValue(y); + myZCoord->SetValue(z); + connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); } } -// MESSAGE("Not found x,y,z values: " << x << " " << y << " " << z); - return false; + } +} + +/** GHS3DPluginGUI_HypothesisCreator::synchronizeCoords() +This method synchronizes the QLineEdit/SMESHGUI_SpinBox widgets content with the coordinates +of the enforced vertex clicked in the tree widget. +*/ +void GHS3DPluginGUI_HypothesisCreator::synchronizeCoords() { + clearEnforcedVertexWidgets(); + QList items = myEnforcedTableWidget->selectedItems(); +// myEnfVertexWdg->disconnect(SIGNAL(contentModified())); + disconnect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) ); + if (! items.isEmpty()) { + QTableWidgetItem *item; + int row; + QVariant entry; + if (items.size() == 1) { + item = items[0]; + row = myEnforcedTableWidget->row(item); + QVariant x = myEnforcedTableWidget->item(row,ENF_VER_X_COLUMN)->data( Qt::EditRole); + QVariant y = myEnforcedTableWidget->item(row,ENF_VER_Y_COLUMN)->data( Qt::EditRole); + QVariant z = myEnforcedTableWidget->item(row,ENF_VER_Z_COLUMN)->data( Qt::EditRole); + QVariant size = myEnforcedTableWidget->item(row,ENF_VER_SIZE_COLUMN)->data( Qt::EditRole); + entry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data( Qt::EditRole); + if (!entry.isNull()) { + SMESH::string_array_var objIds = new SMESH::string_array; + objIds->length(1); + objIds[0] = entry.toString().toStdString().c_str(); + myEnfVertexWdg->SetObjects(objIds); + } + else { + myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil()); + } + QVariant group = myEnforcedTableWidget->item(row,ENF_VER_GROUP_COLUMN)->data( Qt::EditRole); + if (!x.isNull()/* && entry.isNull()*/) { +// disconnect( myXCoord, SIGNAL( textChanged(const QString &)), this, SLOT( onSelectEnforcedVertex() ) ); + disconnect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + disconnect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + disconnect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + myXCoord->SetValue(x.toDouble()); + myYCoord->SetValue(y.toDouble()); + myZCoord->SetValue(z.toDouble()); + connect( myXCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + connect( myYCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + connect( myZCoord, SIGNAL( textChanged(const QString&) ), this, SLOT( clearEnfVertexSelection() ) ); + } + if (!size.isNull()) + mySizeValue->SetValue(size.toDouble()); + + if (!group.isNull() && (!x.isNull() || !entry.isNull())) + myGroupName->setText(group.toString()); + } + else { + QList entryList; + for (int i = 0; i < items.size(); ++i) { + item = items[i]; + row = myEnforcedTableWidget->row(item); + entry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data( Qt::EditRole); + if (!entry.isNull()) + entryList << entry.toString(); + } + if (entryList.size() > 0) { + SMESH::string_array_var objIds = new SMESH::string_array; + objIds->length(entryList.size()); + for (int i = 0; i < entryList.size() ; i++) + objIds[i] = entryList.at(i).toStdString().c_str(); + myEnfVertexWdg->SetObjects(objIds); + } + else { + myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil()); + } + } + } + else { + myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil()); + } + connect( myEnfVertexWdg, SIGNAL( contentModified()), this, SLOT( onSelectEnforcedVertex() ) ); + GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this; + that->checkVertexIsDefined(); } -bool GHS3DPluginGUI_HypothesisCreator::checkVertexIsDefined() +/** GHS3DPluginGUI_HypothesisCreator::addEnforcedMesh( x, y, z, vertexName, geomEntry, groupName) +This method adds in the tree widget an enforced mesh from mesh, submesh or group with optionally size and and groupName. +*/ +void GHS3DPluginGUI_HypothesisCreator::addEnforcedMesh(std::string name, std::string entry, int elementType, double size, std::string groupName) { - bool val = (!myXCoord->text().isEmpty())&&(!myYCoord->text().isEmpty())&&(!myZCoord->text().isEmpty())&&(!mySizeValue->text().isEmpty()); - bool isDefined = val; - if (val) - isDefined = ! smpVertexExists(myXCoord->text().toDouble(),myYCoord->text().toDouble(),myZCoord->text().toDouble()); + MESSAGE("addEnforcedMesh(\"" << name << ", \"" << entry << "\", " << elementType << ", " << size << ", \"" << groupName << "\")"); + bool okToCreate = true; + QString itemEntry = ""; + int itemElementType = 0; + int rowCount = myEnforcedMeshTableWidget->rowCount(); + bool allColumns = true; + for (int row = 0;row(myEnforcedMeshTableWidget->cellWidget(row, col)) == 0) { + allColumns = false; + MESSAGE("allColumns = false"); + break; + } + } + else if (myEnforcedMeshTableWidget->item(row, col) == 0) { + allColumns = false; + MESSAGE("allColumns = false"); + break; + } + if (col == ENF_MESH_CONSTRAINT_COLUMN) { + QComboBox* itemComboBox = qobject_cast(myEnforcedMeshTableWidget->cellWidget(row, col)); + itemElementType = itemComboBox->currentIndex(); + MESSAGE("itemElementType: " << itemElementType); + } + else if (col == ENF_MESH_ENTRY_COLUMN) + itemEntry = myEnforcedMeshTableWidget->item(row, col)->data(Qt::EditRole).toString(); + } + + if (!allColumns) + break; + + if (itemEntry == QString(entry.c_str()) && itemElementType == elementType) { +// // update size +// if (itemSize != size) { +// MESSAGE("Size is updated from \"" << itemSize << "\" to \"" << size << "\""); +// myEnforcedMeshTableWidget->item(row, ENF_MESH_SIZE_COLUMN)->setData( Qt::EditRole, QVariant(size)); +// } +// // update group name +// if (itemGroupName.toStdString() != groupName) { +// MESSAGE("Group is updated from \"" << itemGroupName.toStdString() << "\" to \"" << groupName << "\""); +// myEnforcedMeshTableWidget->item(row, ENF_MESH_GROUP_COLUMN)->setData( Qt::EditRole, QVariant(groupName.c_str())); +// } + okToCreate = false; + break; + } // if + } // for - emit vertexDefined(isDefined); - return isDefined; + + if (!okToCreate) + return; + + MESSAGE("Creation of enforced mesh"); + + myEnforcedMeshTableWidget->setRowCount(rowCount+1); + myEnforcedMeshTableWidget->setSortingEnabled(false); + + for (int col=0;colpalette(); + pal.setColor(QPalette::Button, Qt::white); + comboBox->setPalette(pal); + comboBox->insertItems(0,myEnfMeshConstraintLabels); + comboBox->setEditable(false); + comboBox->setCurrentIndex(elementType); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << comboBox->currentText().toStdString()); + myEnforcedMeshTableWidget->setCellWidget(rowCount,col,comboBox); + } + else { + QTableWidgetItem* item = new QTableWidgetItem(); + item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled); + switch (col) { + case ENF_MESH_NAME_COLUMN: + item->setData( 0, name.c_str() ); + item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString()); + myEnforcedMeshTableWidget->setItem(rowCount,col,item); + break; + case ENF_MESH_ENTRY_COLUMN: + item->setData( 0, entry.c_str() ); + item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString()); + myEnforcedMeshTableWidget->setItem(rowCount,col,item); + break; + case ENF_MESH_SIZE_COLUMN: + item->setData( 0, size ); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString()); + myEnforcedMeshTableWidget->setItem(rowCount,col,item); + break; + case ENF_MESH_GROUP_COLUMN: + item->setData( 0, groupName.c_str() ); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString()); + myEnforcedMeshTableWidget->setItem(rowCount,col,item); + break; + default: + break; + } + } + MESSAGE("Done"); + } + +// connect( myEnforcedMeshTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) ); + + myEnforcedMeshTableWidget->setSortingEnabled(true); +// myEnforcedTableWidget->setCurrentItem(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN)); +// updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN)); + } -void GHS3DPluginGUI_HypothesisCreator::onVertexBtnClicked() +/** GHS3DPluginGUI_HypothesisCreator::addEnforcedVertex( x, y, z, size, vertexName, geomEntry, groupName) +This method adds in the tree widget an enforced vertex with given size and coords (x,y,z) or GEOM vertex or compound and with optionally groupName. +*/ +void GHS3DPluginGUI_HypothesisCreator::addEnforcedVertex(double x, double y, double z, double size, std::string vertexName, std::string geomEntry, std::string groupName, bool isCompound) { - MESSAGE("GHS3DPluginGUI_HypothesisCreator::onVertexBtnClicked()"); - const int row = mySmpModel->rowCount() ; - double x = myXCoord->text().toDouble(); - double y = myYCoord->text().toDouble(); - double z = myZCoord->text().toDouble(); - double size = mySizeValue->text().toDouble(); + MESSAGE("addEnforcedVertex(" << x << ", " << y << ", " << z << ", " << size << ", \"" << vertexName << ", \"" << geomEntry << "\", \"" << groupName << "\", " << isCompound << ")"); + myEnforcedTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *))); + bool okToCreate = true; + double itemX,itemY,itemZ,itemSize = 0; + QString itemEntry, itemGroupName = QString(""); +// bool itemIsCompound; + int rowCount = myEnforcedTableWidget->rowCount(); + QVariant data; + bool allColumns; + for (int row = 0;rowitem(row, col) == 0) { + allColumns = false; + break; + } + + data = myEnforcedTableWidget->item(row, col)->data(Qt::EditRole); + if (!data.isNull()) { + switch (col) { + case ENF_VER_GROUP_COLUMN: + itemGroupName = data.toString(); + break; + case ENF_VER_ENTRY_COLUMN: + itemEntry = data.toString(); + break; +// case ENF_VER_COMPOUND_COLUMN: +// itemIsCompound = data.toBool(); +// break; + case ENF_VER_X_COLUMN: + itemX = data.toDouble(); + break; + case ENF_VER_Y_COLUMN: + itemY = data.toDouble(); + break; + case ENF_VER_Z_COLUMN: + itemZ = data.toDouble(); + break; + case ENF_VER_SIZE_COLUMN: + itemSize = data.toDouble(); + break; + default: + break; + } + } + } + + if (!allColumns) + break; + + + if (( !isCompound && ((itemX == x) && (itemY == y) && (itemZ == z))) || /*( (itemEntry.toStdString() != "") && */ (itemEntry.toStdString() == geomEntry)/*)*/) { + // update size + if (itemSize != size) { + MESSAGE("Size is updated from \"" << itemSize << "\" to \"" << size << "\""); + myEnforcedTableWidget->item(row, ENF_VER_SIZE_COLUMN)->setData( Qt::EditRole, QVariant(size)); + } + // update group name + if (itemGroupName.toStdString() != groupName) { + MESSAGE("Group is updated from \"" << itemGroupName.toStdString() << "\" to \"" << groupName << "\""); + myEnforcedTableWidget->item(row, ENF_VER_GROUP_COLUMN)->setData( Qt::EditRole, QVariant(groupName.c_str())); + } + okToCreate = false; + break; + } // if + } // for + if (!okToCreate) { + if (geomEntry.empty()) { + MESSAGE("Vertex with coords " << x << ", " << y << ", " << z << " already exist: dont create again"); + } + else { + MESSAGE("Vertex with entry " << geomEntry << " already exist: dont create again"); + } + return; + } - if (smpVertexExists(x,y,z)) return; + if (geomEntry.empty()) { + MESSAGE("Vertex with coords " << x << ", " << y << ", " << z<< " is created"); + } + else { + MESSAGE("Vertex with geom entry " << geomEntry << " is created"); + } + + int vertexIndex=0; + int indexRef = -1; + QString myVertexName; + while(indexRef != vertexIndex) { + indexRef = vertexIndex; + if (vertexName.empty()) + myVertexName = QString("Vertex #%1").arg(vertexIndex); + else + myVertexName = QString(vertexName.c_str()); + + for (int row = 0;rowitem(row,ENF_VER_NAME_COLUMN)->data(Qt::EditRole).toString(); + if (myVertexName == name) { + vertexIndex++; + break; + } + } + } + + MESSAGE("myVertexName is \"" << myVertexName.toStdString() << "\""); + myEnforcedTableWidget->setRowCount(rowCount+1); + myEnforcedTableWidget->setSortingEnabled(false); + for (int col=0;colsetFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled); + switch (col) { + case ENF_VER_NAME_COLUMN: + item->setData( Qt::EditRole, myVertexName ); + if (!geomEntry.empty()) { + if (isCompound) + item->setIcon(QIcon(iconCompound.scaled(iconCompound.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation))); + else + item->setIcon(QIcon(iconVertex.scaled(iconVertex.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation))); + } + break; + case ENF_VER_X_COLUMN: + if (!isCompound) + item->setData( 0, QVariant(x) ); + break; + case ENF_VER_Y_COLUMN: + if (!isCompound) + item->setData( 0, QVariant(y) ); + break; + case ENF_VER_Z_COLUMN: + if (!isCompound) + item->setData( 0, QVariant(z) ); + break; + case ENF_VER_SIZE_COLUMN: + item->setData( 0, QVariant(size) ); + break; + case ENF_VER_ENTRY_COLUMN: + if (!geomEntry.empty()) + item->setData( 0, QString(geomEntry.c_str()) ); + break; + case ENF_VER_COMPOUND_COLUMN: + item->setData( Qt::CheckStateRole, isCompound ); + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable); + break; + case ENF_VER_GROUP_COLUMN: + if (!groupName.empty()) + item->setData( 0, QString(groupName.c_str()) ); + break; + default: + break; + } -// double size = 10.0; - // ENF_VER_X_COLUMN - mySmpModel->setData(mySmpModel->index(row, ENF_VER_X_COLUMN),x); - mySmpModel->setItem( row, ENF_VER_X_COLUMN, new QStandardItem(QString::number(x)) ); - mySmpModel->item( row, ENF_VER_X_COLUMN )->setFlags( Qt::ItemIsSelectable ); - // ENF_VER_Y_COLUMN - mySmpModel->setData(mySmpModel->index(row, ENF_VER_Y_COLUMN),y); - mySmpModel->setItem( row, ENF_VER_Y_COLUMN, new QStandardItem(QString::number(y)) ); - mySmpModel->item( row, ENF_VER_Y_COLUMN )->setFlags( Qt::ItemIsSelectable ); - // ENF_VER_Z_COLUMN - mySmpModel->setData(mySmpModel->index(row, ENF_VER_Z_COLUMN),z); - mySmpModel->setItem( row, ENF_VER_Z_COLUMN, new QStandardItem(QString::number(z)) ); - mySmpModel->item( row, ENF_VER_Z_COLUMN )->setFlags( Qt::ItemIsSelectable ); - // ENF_VER_SIZE_COLUMN - mySmpModel->setData(mySmpModel->index(row, ENF_VER_SIZE_COLUMN),size); - mySmpModel->setItem( row, ENF_VER_SIZE_COLUMN, new QStandardItem(QString::number(size,'f')) ); - - myEnforcedTableView->clearSelection(); - myEnforcedTableView->scrollTo( mySmpModel->item( row, ENF_VER_SIZE_COLUMN )->index() ); - checkVertexIsDefined(); -} - -void GHS3DPluginGUI_HypothesisCreator::onRemoveVertexBtnClicked() -{ - QList selectedRows; - QList selectedIndex = myEnforcedTableView->selectionModel()->selectedIndexes(); - int row; - QModelIndex index; - foreach( index, selectedIndex ) { - row = index.row(); - if ( !selectedRows.contains( row ) ) - selectedRows.append( row ); - } - qSort( selectedRows ); - QListIterator it( selectedRows ); - it.toBack(); - while ( it.hasPrevious() ) { - row = it.previous(); - MESSAGE("delete row #"<< row); - mySmpModel->removeRow(row ); - } - myEnforcedTableView->clearSelection(); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString()); + myEnforcedTableWidget->setItem(rowCount,col,item); + MESSAGE("Done"); + } + + connect( myEnforcedTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) ); + + myEnforcedTableWidget->setSortingEnabled(true); +// myEnforcedTableWidget->setCurrentItem(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN)); + updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN)); +} + +/** GHS3DPluginGUI_HypothesisCreator::onAddEnforcedMesh() +This method is called when a item is added into the enforced meshes tree widget +*/ +void GHS3DPluginGUI_HypothesisCreator::onAddEnforcedMesh() +{ + MESSAGE("GHS3DPluginGUI_HypothesisCreator::onAddEnforcedMesh()"); + + GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this; + + that->getGeomSelectionTool()->selectionMgr()->clearFilters(); + myEnfMeshWdg->deactivateSelection(); + + for (int column = 0; column < myEnforcedMeshTableWidget->columnCount(); ++column) + myEnforcedMeshTableWidget->resizeColumnToContents(column); + + // Vertex selection + int selEnfMeshes = myEnfMeshWdg->NbObjects(); + if (selEnfMeshes == 0) + return; + + std::string groupName = myMeshGroupName->text().toStdString(); +// if (myGlobalGroupName->isChecked()) +// groupName = myGlobalGroupName->text().toStdString(); + + if (boost::trim_copy(groupName).empty()) + groupName = ""; + + + double size = -1; + if (!myMeshSizeValue->GetString().isEmpty()) + size = myMeshSizeValue->GetValue(); +// if (size < 0) +// return; + + int elementType = myEnfMeshConstraint->currentIndex(); + + + _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); + _PTR(SObject) aSObj; //SMESH::SMESH_IDSource::_nil; + QString meshEntry = myEnfMeshWdg->GetValue(); + MESSAGE("myEnfMeshWdg->GetValue()" << meshEntry.toStdString()); + + if (selEnfMeshes == 1) + { + MESSAGE("1 SMESH object selected"); +// myEnfMesh = myEnfMeshWdg->GetObject< SMESH::SMESH_IDSource >(); +// std::string entry = myEnfMeshWdg->GetValue(); + aSObj = aStudy->FindObjectID(meshEntry.toStdString().c_str()); + CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj,aStudy); + if (!CORBA::is_nil(anObj)) { +// SMESH::SMESH_IDSource_var theSource = SMESH::SObjectToInterface( aSObj ); + addEnforcedMesh( aSObj->GetName(), aSObj->GetID(), elementType, size, groupName); + } + } + else + { + MESSAGE(selEnfMeshes << " SMESH objects selected"); + QStringList meshEntries = meshEntry.split(" ", QString::SkipEmptyParts); + QStringListIterator meshEntriesIt (meshEntries); + while (meshEntriesIt.hasNext()) { + aSObj = aStudy->FindObjectID(meshEntriesIt.next().toStdString().c_str()); + CORBA::Object_var anObj = SMESH::SObjectToObject(aSObj,aStudy); + if (!CORBA::is_nil(anObj)) { +// SMESH::SMESH_IDSource_var theSource = SMESH::SObjectToInterface( aSObj ); + addEnforcedMesh( aSObj->GetName(), aSObj->GetID(), elementType, size, groupName); + } + } + } + + myEnfVertexWdg->SetObject(SMESH::SMESH_IDSource::_nil()); + + for (int column = 0; column < myEnforcedMeshTableWidget->columnCount(); ++column) + myEnforcedMeshTableWidget->resizeColumnToContents(column); +} + + +/** GHS3DPluginGUI_HypothesisCreator::onAddEnforcedVertex() +This method is called when a item is added into the enforced vertices tree widget +*/ +void GHS3DPluginGUI_HypothesisCreator::onAddEnforcedVertex() +{ + MESSAGE("GHS3DPluginGUI_HypothesisCreator::onAddEnforcedVertex()"); + + GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this; + + that->getGeomSelectionTool()->selectionMgr()->clearFilters(); + myEnfVertexWdg->deactivateSelection(); + + for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column) + myEnforcedTableWidget->resizeColumnToContents(column); + + // Vertex selection + int selEnfVertex = myEnfVertexWdg->NbObjects(); + bool coordsEmpty = (myXCoord->text().isEmpty()) || (myYCoord->text().isEmpty()) || (myZCoord->text().isEmpty()); + if ((selEnfVertex == 0) && coordsEmpty) + return; + + std::string groupName = myGroupName->text().toStdString(); +// if (myGlobalGroupName->isChecked()) +// groupName = myGlobalGroupName->text().toStdString(); + + if (boost::trim_copy(groupName).empty()) + groupName = ""; + + double size = mySizeValue->GetValue(); + + if (selEnfVertex <= 1) + { + MESSAGE("0 or 1 GEOM object selected"); + double x = 0, y = 0, z=0; + if (myXCoord->GetString() != "") { + x = myXCoord->GetValue(); + y = myYCoord->GetValue(); + z = myZCoord->GetValue(); + } + if (selEnfVertex == 1) { + MESSAGE("1 GEOM object selected"); + myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(); + std::string entry = ""; + if (myEnfVertex != GEOM::GEOM_Object::_nil()) + entry = myEnfVertex->GetStudyEntry(); + addEnforcedVertex(x, y, z, size, myEnfVertex->GetName(),entry, groupName, myEnfVertex->GetShapeType() == GEOM::COMPOUND); + } + else { + MESSAGE("0 GEOM object selected"); + MESSAGE("Coords: ("<GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() ); + if (CORBA::is_nil(measureOp)) + return; + + CORBA::Double x = 0, y = 0,z = 0; + for (int j = 0 ; j < selEnfVertex ; j++) + { + myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(j); + if (myEnfVertex == GEOM::GEOM_Object::_nil()) + continue; + if (myEnfVertex->GetShapeType() == GEOM::VERTEX) { + measureOp->PointCoordinates (myEnfVertex, x, y, z); + if ( measureOp->IsDone() ) + addEnforcedVertex(x, y, z, size, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName); + } else if (myEnfVertex->GetShapeType() == GEOM::COMPOUND) { + addEnforcedVertex(0., 0., 0., size, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName, true); + } + } + } + + myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil()); + + for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column) + myEnforcedTableWidget->resizeColumnToContents(column); +} + +/** GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedMesh() +This method is called when a item is removed from the enforced meshes tree widget +*/ +void GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedMesh() +{ + QList selectedRows; + QList selectedItems = myEnforcedMeshTableWidget->selectedItems(); + QTableWidgetItem* item; + int row; + foreach( item, selectedItems ) { + row = item->row(); + if (!selectedRows.contains( row ) ) + selectedRows.append(row); + } + + qSort( selectedRows ); + QListIterator it( selectedRows ); + it.toBack(); + while ( it.hasPrevious() ) { + row = it.previous(); + MESSAGE("delete row #"<< row); + myEnforcedMeshTableWidget->removeRow(row ); + } + + myEnforcedMeshTableWidget->selectionModel()->clearSelection(); } + +/** GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedVertex() +This method is called when a item is removed from the enforced vertices tree widget +*/ +void GHS3DPluginGUI_HypothesisCreator::onRemoveEnforcedVertex() +{ + QList selectedRows; + QList selectedItems = myEnforcedTableWidget->selectedItems(); + QTableWidgetItem* item; + int row; + foreach( item, selectedItems ) { + row = item->row(); + if (!selectedRows.contains( row ) ) + selectedRows.append(row); + } + + qSort( selectedRows ); + QListIterator it( selectedRows ); + it.toBack(); + while ( it.hasPrevious() ) { + row = it.previous(); + MESSAGE("delete row #"<< row); + myEnforcedTableWidget->removeRow(row ); + } + + myEnforcedTableWidget->selectionModel()->clearSelection(); +} + void GHS3DPluginGUI_HypothesisCreator::onDirBtnClicked() { QString dir = SUIT_FileDlg::getExistingDirectory( dlg(), myWorkingDir->text(), QString() ); @@ -482,6 +1451,7 @@ bool GHS3DPluginGUI_HypothesisCreator::checkParams(QString& msg) const void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const { MESSAGE("GHS3DPluginGUI_HypothesisCreator::retrieveParams"); + GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this; GHS3DHypothesisData data; readParamsFromHypo( data ); @@ -506,38 +1476,152 @@ void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const myTextOption ->setText ( data.myTextOption ); TEnfVertexList::const_iterator it; - int row = 0; + int rowCount = 0; + myEnforcedTableWidget->setSortingEnabled(false); + myEnforcedTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *))); for(it = data.myEnforcedVertices.begin() ; it != data.myEnforcedVertices.end(); it++ ) { TEnfVertex* enfVertex = (*it); - if (enfVertex->coords.size()) { - double x = enfVertex->coords.at(0); - double y = enfVertex->coords.at(1); - double z = enfVertex->coords.at(2); - double size = enfVertex->size; - // ENF_VER_X_COLUMN - mySmpModel->setData(mySmpModel->index(row, ENF_VER_X_COLUMN),x); - mySmpModel->setItem( row, ENF_VER_X_COLUMN, new QStandardItem(QString::number(x)) ); - mySmpModel->item( row, ENF_VER_X_COLUMN )->setFlags( Qt::ItemIsSelectable ); - // ENF_VER_Y_COLUMN - mySmpModel->setData(mySmpModel->index(row, ENF_VER_Y_COLUMN),y); - mySmpModel->setItem( row, ENF_VER_Y_COLUMN, new QStandardItem(QString::number(y)) ); - mySmpModel->item( row, ENF_VER_Y_COLUMN )->setFlags( Qt::ItemIsSelectable ); - // ENF_VER_Z_COLUMN - mySmpModel->setData(mySmpModel->index(row, ENF_VER_Z_COLUMN),z); - mySmpModel->setItem( row, ENF_VER_Z_COLUMN, new QStandardItem(QString::number(z)) ); - mySmpModel->item( row, ENF_VER_Z_COLUMN )->setFlags( Qt::ItemIsSelectable ); - // ENF_VER_SIZE_COLUMN - mySmpModel->setData(mySmpModel->index(row, ENF_VER_SIZE_COLUMN),size); - mySmpModel->setItem( row, ENF_VER_SIZE_COLUMN, new QStandardItem(QString::number(size)) ); - - MESSAGE("Row " << row << ": (" << x << ","<< y << ","<< z << ") ="<< size); - row++; + myEnforcedTableWidget->setRowCount(rowCount+1); + + for (int col=0;colisCompound: " << enfVertex->isCompound); + QTableWidgetItem* item = new QTableWidgetItem(); + item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled); + switch (col) { + case ENF_VER_NAME_COLUMN: + item->setData( 0, enfVertex->name.c_str() ); + if (!enfVertex->geomEntry.empty()) { + if (enfVertex->isCompound) + item->setIcon(QIcon(iconCompound.scaled(iconCompound.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation))); + else + item->setIcon(QIcon(iconVertex.scaled(iconVertex.size()*0.7,Qt::KeepAspectRatio,Qt::SmoothTransformation))); + + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString()); + } + break; + case ENF_VER_X_COLUMN: + if (!enfVertex->isCompound) { + item->setData( 0, enfVertex->coords.at(0) ); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString()); + } + break; + case ENF_VER_Y_COLUMN: + if (!enfVertex->isCompound) { + item->setData( 0, enfVertex->coords.at(1) ); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString()); + } + break; + case ENF_VER_Z_COLUMN: + if (!enfVertex->isCompound) { + item->setData( 0, enfVertex->coords.at(2) ); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString()); + } + break; + case ENF_VER_SIZE_COLUMN: + item->setData( 0, enfVertex->size ); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString()); + break; + case ENF_VER_ENTRY_COLUMN: + item->setData( 0, enfVertex->geomEntry.c_str() ); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString()); + break; + case ENF_VER_COMPOUND_COLUMN: + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable); + item->setData( Qt::CheckStateRole, enfVertex->isCompound ); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << enfVertex->isCompound); + break; + case ENF_VER_GROUP_COLUMN: + item->setData( 0, enfVertex->groupName.c_str() ); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString()); + break; + default: + break; + } + + myEnforcedTableWidget->setItem(rowCount,col,item); + MESSAGE("Done"); } + that->updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN)); + rowCount++; } + + connect( myEnforcedTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) ); + myEnforcedTableWidget->setSortingEnabled(true); + + for (int column = 0; column < myEnforcedTableWidget->columnCount(); ++column) + myEnforcedTableWidget->resizeColumnToContents(column); + + // Update Enforced meshes QTableWidget + TEnfMeshList::const_iterator itMesh; + rowCount = 0; + myEnforcedMeshTableWidget->setSortingEnabled(false); +// myEnforcedMeshTableWidget->disconnect(SIGNAL( itemChanged(QTableWidgetItem *))); + for(itMesh = data.myEnforcedMeshes.begin() ; itMesh != data.myEnforcedMeshes.end(); itMesh++ ) + { + TEnfMesh* enfMesh = (*itMesh); + myEnforcedMeshTableWidget->setRowCount(rowCount+1); + + for (int col=0;colpalette(); + pal.setColor(QPalette::Button, Qt::white); + comboBox->setPalette(pal); + comboBox->insertItems(0,myEnfMeshConstraintLabels); + comboBox->setEditable(false); + comboBox->setCurrentIndex(enfMesh->elementType); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << comboBox->currentText().toStdString()); + myEnforcedMeshTableWidget->setCellWidget(rowCount,col,comboBox); + } + else { + QTableWidgetItem* item = new QTableWidgetItem(); + item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled); + switch (col) { + case ENF_MESH_NAME_COLUMN: + item->setData( 0, enfMesh->name.c_str() ); + item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString()); + myEnforcedMeshTableWidget->setItem(rowCount,col,item); + break; + case ENF_MESH_ENTRY_COLUMN: + item->setData( 0, enfMesh->entry.c_str() ); + item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString()); + myEnforcedMeshTableWidget->setItem(rowCount,col,item); + break; + case ENF_MESH_SIZE_COLUMN: + item->setData( 0, enfMesh->size ); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString()); + myEnforcedMeshTableWidget->setItem(rowCount,col,item); + break; + case ENF_MESH_GROUP_COLUMN: + item->setData( 0, enfMesh->groupName.c_str() ); + MESSAGE("Add item in table at (" << rowCount << "," << col << "): " << item->text().toStdString()); + myEnforcedMeshTableWidget->setItem(rowCount,col,item); + break; + default: + break; + } + } + +// myEnforcedMeshTableWidget->setItem(rowCount,col,item); + MESSAGE("Done"); + } +// that->updateEnforcedVertexValues(myEnforcedTableWidget->item(rowCount,ENF_VER_NAME_COLUMN)); + rowCount++; + } + +// connect( myEnforcedMeshTableWidget,SIGNAL( itemChanged(QTableWidgetItem *)), this, SLOT( updateEnforcedVertexValues(QTableWidgetItem *) ) ); + myEnforcedMeshTableWidget->setSortingEnabled(true); + + for (int col=0;colresizeColumnToContents(col); - GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this; that->updateWidgets(); + that->checkVertexIsDefined(); } QString GHS3DPluginGUI_HypothesisCreator::storeParams() const @@ -583,26 +1667,26 @@ QString GHS3DPluginGUI_HypothesisCreator::storeParams() const valStr += " "; valStr += data.myTextOption; - valStr += " #BEGIN ENFORCED VERTICES#"; - // Add size map parameters storage - for (int i=0 ; irowCount() ; i++) { - valStr += " ("; - double x = mySmpModel->data(mySmpModel->index(i,ENF_VER_X_COLUMN)).toDouble(); - double y = mySmpModel->data(mySmpModel->index(i,ENF_VER_Y_COLUMN)).toDouble(); - double z = mySmpModel->data(mySmpModel->index(i,ENF_VER_Z_COLUMN)).toDouble(); - double size = mySmpModel->data(mySmpModel->index(i,ENF_VER_SIZE_COLUMN)).toDouble(); - valStr += QString::number( x ); - valStr += ","; - valStr += QString::number( y ); - valStr += ","; - valStr += QString::number( z ); - valStr += ")="; - valStr += QString::number( size ); - if (i!=mySmpModel->rowCount()-1) - valStr += ";"; - } - valStr += " #END ENFORCED VERTICES#"; - MESSAGE(valStr.toStdString()); +// valStr += " #BEGIN ENFORCED VERTICES#"; +// // Add size map parameters storage +// for (int i=0 ; irowCount() ; i++) { +// valStr += " ("; +// double x = mySmpModel->data(mySmpModel->index(i,ENF_VER_X_COLUMN)).toDouble(); +// double y = mySmpModel->data(mySmpModel->index(i,ENF_VER_Y_COLUMN)).toDouble(); +// double z = mySmpModel->data(mySmpModel->index(i,ENF_VER_Z_COLUMN)).toDouble(); +// double size = mySmpModel->data(mySmpModel->index(i,ENF_VER_SIZE_COLUMN)).toDouble(); +// valStr += QString::number( x ); +// valStr += ","; +// valStr += QString::number( y ); +// valStr += ","; +// valStr += QString::number( z ); +// valStr += ")="; +// valStr += QString::number( size ); +// if (i!=mySmpModel->rowCount()-1) +// valStr += ";"; +// } +// valStr += " #END ENFORCED VERTICES#"; +// MESSAGE(valStr.toStdString()); return valStr; } @@ -638,6 +1722,7 @@ bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& myVertex->geomEntry = CORBA::string_dup(vertices[i].geomEntry.in()); myVertex->groupName = CORBA::string_dup(vertices[i].groupName.in()); myVertex->size = vertices[i].size; + myVertex->isCompound = vertices[i].isCompound; if (vertices[i].coords.length()) { for (int c = 0; c < vertices[i].coords.length() ; c++) myVertex->coords.push_back(vertices[i].coords[c]); @@ -645,6 +1730,30 @@ bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& } h_data.myEnforcedVertices.insert(myVertex); } + + GHS3DPlugin::GHS3DEnforcedMeshList_var enfMeshes = h->GetEnforcedMeshes(); + MESSAGE("enfMeshes->length(): " << enfMeshes->length()); + h_data.myEnforcedMeshes.clear(); + for (int i=0 ; ilength() ; i++) { + TEnfMesh* myEnfMesh = new TEnfMesh(); + myEnfMesh->name = CORBA::string_dup(enfMeshes[i].name.in()); + myEnfMesh->entry = CORBA::string_dup(enfMeshes[i].entry.in()); + myEnfMesh->groupName = CORBA::string_dup(enfMeshes[i].groupName.in()); + myEnfMesh->size = enfMeshes[i].size; + switch (enfMeshes[i].elementType) { + case SMESH::NODE: + myEnfMesh->elementType = 0; + break; + case SMESH::EDGE: + myEnfMesh->elementType = 1; + break; + case SMESH::FACE: + myEnfMesh->elementType = 2; + break; + } +// myEnfMesh->elementType = enfMeshes[i].elementType; + h_data.myEnforcedMeshes.insert(myEnfMesh); + } return true; } @@ -687,6 +1796,7 @@ bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisD if ( h->GetTextOption() != h_data.myTextOption ) h->SetTextOption ( h_data.myTextOption.toLatin1().constData() ); + // Enforced vertices int nbVertex = (int) h_data.myEnforcedVertices.size(); GHS3DPlugin::GHS3DEnforcedVertexList_var vertexHyp = h->GetEnforcedVertices(); int nbVertexHyp = vertexHyp->length(); @@ -694,53 +1804,61 @@ bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisD MESSAGE("Store params for size maps: " << nbVertex << " enforced vertices"); MESSAGE("h->GetEnforcedVertices()->length(): " << nbVertexHyp); - // Some vertices were removed - if (nbVertex < nbVertexHyp) { -// if (nbVertex == 0) -// h->ClearEnforcedVertices(); -// else { - // iterate over vertices of hypo - for(int i = 0 ; i RemoveEnforcedVertex(x,y,z); - } - } -// } - } + // 1. Clear all enforced vertices in hypothesis + // 2. Add new enforced vertex according to h_data + if ( nbVertexHyp > 0) + h->ClearEnforcedVertices(); TEnfVertexList::const_iterator it; + double x = 0, y = 0, z = 0; for(it = h_data.myEnforcedVertices.begin() ; it != h_data.myEnforcedVertices.end(); it++ ) { TEnfVertex* enfVertex = (*it); + x =y =z = 0; if (enfVertex->coords.size()) { - double x = enfVertex->coords.at(0); - double y = enfVertex->coords.at(1); - double z = enfVertex->coords.at(2); - double size = enfVertex->size; - MESSAGE("(" << x << ", " - << y << ", " - << z << ") = " - << size ); - double mySize; - try { - mySize = h->GetEnforcedVertex(x,y,z); - MESSAGE("Old size: " << mySize); - if (mySize != size) { - MESSAGE("Setting new size: " << size); - h->SetEnforcedVertex(x,y,z,size); - } - } - catch (...) { - MESSAGE("Setting new size: " << size); - h->SetEnforcedVertex( x, y, z, size); - } + x = enfVertex->coords.at(0); + y = enfVertex->coords.at(1); + z = enfVertex->coords.at(2); } - } - } + ok = h->p_SetEnforcedVertex( enfVertex->size, x, y, z, enfVertex->name.c_str(), enfVertex->geomEntry.c_str(), enfVertex->groupName.c_str(), enfVertex->isCompound); + } // for + + // Enforced Meshes + int nbEnfMeshes = (int) h_data.myEnforcedMeshes.size(); + GHS3DPlugin::GHS3DEnforcedMeshList_var enfMeshListHyp = h->GetEnforcedMeshes(); + int nbEnfMeshListHyp = enfMeshListHyp->length(); + + MESSAGE("Store params for size maps: " << nbEnfMeshes << " enforced meshes"); + MESSAGE("h->GetEnforcedMeshes()->length(): " << nbEnfMeshListHyp); + + // 1. Clear all enforced vertices in hypothesis + // 2. Add new enforced vertex according to h_data + if ( nbEnfMeshListHyp > 0) + h->ClearEnforcedMeshes(); + + TEnfMeshList::const_iterator itEnfMesh; + _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); + for(itEnfMesh = h_data.myEnforcedMeshes.begin() ; itEnfMesh != h_data.myEnforcedMeshes.end(); itEnfMesh++ ) { + TEnfMesh* enfMesh = (*itEnfMesh); + + _PTR(SObject) aSObj = aStudy->FindObjectID(enfMesh->entry.c_str()); + SMESH::SMESH_IDSource_var theSource = SMESH::SObjectToInterface( aSObj ); + SMESH::ElementType elementType; + switch(enfMesh->elementType) { + case 0: + elementType = SMESH::NODE; + case 1: + elementType = SMESH::EDGE; + case 2: + elementType = SMESH::FACE; + } + + ok = h->p_SetEnforcedMesh(theSource, elementType, enfMesh->size, enfMesh->groupName.c_str()); + } // for + } // try +// catch(const std::exception& ex) { +// std::cout << "Exception: " << ex.what() << std::endl; +// throw ex; +// } catch ( const SALOME::SALOME_Exception& ex ) { SalomeApp_Tools::QtCatchCorbaException( ex ); @@ -765,23 +1883,57 @@ bool GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DHypothesisDat h_data.myBoundaryRecovery = myBoundaryRecoveryCheck->isChecked(); h_data.myFEMCorrection = myFEMCorrectionCheck->isChecked(); h_data.myTextOption = myTextOption->text(); + + // Enforced vertices h_data.myEnforcedVertices.clear(); - - for (int i=0 ; irowCount() ; i++) { + QVariant valueX, valueY, valueZ; + for (int row=0 ; rowrowCount() ; row++) { + TEnfVertex *myVertex = new TEnfVertex(); - myVertex->name = ""; - myVertex->geomEntry = ""; - myVertex->groupName = ""; - myVertex->coords.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_X_COLUMN)).toDouble()); - myVertex->coords.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_Y_COLUMN)).toDouble()); - myVertex->coords.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_Z_COLUMN)).toDouble()); - myVertex->size = mySmpModel->data(mySmpModel->index(i,ENF_VER_SIZE_COLUMN)).toDouble(); - MESSAGE("Add new enforced vertex (" << myVertex->coords.at(0) << ", " - << myVertex->coords.at(1) << ", " - << myVertex->coords.at(2) << ") = " - << myVertex->size); + myVertex->name = myEnforcedTableWidget->item(row,ENF_VER_NAME_COLUMN)->data(Qt::EditRole).toString().toStdString(); + MESSAGE("Add new enforced vertex \"" << myVertex->name << "\"" ); + myVertex->geomEntry = myEnforcedTableWidget->item(row,ENF_VER_ENTRY_COLUMN)->data(Qt::EditRole).toString().toStdString(); + if (myVertex->geomEntry.size()) + MESSAGE("Geom entry is \"" << myVertex->geomEntry << "\"" ); + myVertex->groupName = myEnforcedTableWidget->item(row,ENF_VER_GROUP_COLUMN)->data(Qt::EditRole).toString().toStdString(); + if (myVertex->groupName.size()) + MESSAGE("Group name is \"" << myVertex->groupName << "\"" ); + valueX = myEnforcedTableWidget->item(row,ENF_VER_X_COLUMN)->data(Qt::EditRole); + valueY = myEnforcedTableWidget->item(row,ENF_VER_Y_COLUMN)->data(Qt::EditRole); + valueZ = myEnforcedTableWidget->item(row,ENF_VER_Z_COLUMN)->data(Qt::EditRole); + if (!valueX.isNull() && !valueY.isNull() && !valueZ.isNull()) { + myVertex->coords.push_back(valueX.toDouble()); + myVertex->coords.push_back(valueY.toDouble()); + myVertex->coords.push_back(valueZ.toDouble()); + MESSAGE("Coords are (" << myVertex->coords.at(0) << ", " + << myVertex->coords.at(1) << ", " + << myVertex->coords.at(2) << ")"); + } + myVertex->size = myEnforcedTableWidget->item(row,ENF_VER_SIZE_COLUMN)->data(Qt::EditRole).toDouble(); + MESSAGE("Size is " << myVertex->size); + myVertex->isCompound = myEnforcedTableWidget->item(row,ENF_VER_COMPOUND_COLUMN)->data(Qt::CheckStateRole).toBool(); + MESSAGE("Is compound ? " << myVertex->isCompound); h_data.myEnforcedVertices.insert(myVertex); } + + // Enforced meshes + h_data.myEnforcedMeshes.clear(); + for (int row=0 ; rowrowCount() ; row++) { + + TEnfMesh *myEnfMesh = new TEnfMesh(); + myEnfMesh->name = myEnforcedMeshTableWidget->item(row,ENF_MESH_NAME_COLUMN)->data(Qt::EditRole).toString().toStdString(); + MESSAGE("Add new enforced mesh \"" << myEnfMesh->name << "\"" ); + myEnfMesh->entry = myEnforcedMeshTableWidget->item(row,ENF_MESH_ENTRY_COLUMN)->data(Qt::EditRole).toString().toStdString(); + MESSAGE("Entry is \"" << myEnfMesh->entry << "\"" ); + myEnfMesh->groupName = myEnforcedMeshTableWidget->item(row,ENF_MESH_GROUP_COLUMN)->data(Qt::EditRole).toString().toStdString(); + MESSAGE("Group name is \"" << myEnfMesh->groupName << "\"" ); + myEnfMesh->size = myEnforcedMeshTableWidget->item(row,ENF_MESH_SIZE_COLUMN)->data(Qt::EditRole).toDouble(); + MESSAGE("Size is " << myEnfMesh->size); + QComboBox* combo = qobject_cast(myEnforcedMeshTableWidget->cellWidget(row,ENF_MESH_CONSTRAINT_COLUMN)); + myEnfMesh->elementType = combo->currentIndex(); + MESSAGE("Element type: " << myEnfMesh->elementType); + h_data.myEnforcedMeshes.insert(myEnfMesh); + } return true; } @@ -805,19 +1957,3 @@ QString GHS3DPluginGUI_HypothesisCreator::helpPage() const { return "ghs3d_hypo_page.html"; } - -//============================================================================= -/*! GetHypothesisCreator - * - */ -//============================================================================= -extern "C" -{ - GHS3DPLUGINGUI_EXPORT - SMESHGUI_GenericHypothesisCreator* GetHypothesisCreator( const QString& aHypType ) - { - if ( aHypType == "GHS3D_Parameters" ) - return new GHS3DPluginGUI_HypothesisCreator( aHypType ); - return 0; - } -} diff --git a/src/GUI/GHS3DPluginGUI_HypothesisCreator.h b/src/GUI/GHS3DPluginGUI_HypothesisCreator.h index 3e883b2..a71f6c2 100644 --- a/src/GUI/GHS3DPluginGUI_HypothesisCreator.h +++ b/src/GUI/GHS3DPluginGUI_HypothesisCreator.h @@ -36,30 +36,63 @@ #endif #include -// #include +#include +#include #include #include #include #include +#include #include CORBA_SERVER_HEADER(GHS3DPlugin_Algorithm) +#include CORBA_SERVER_HEADER(SMESH_Gen) +#include CORBA_SERVER_HEADER(SMESH_Mesh) class QWidget; class QComboBox; class QCheckBox; class QLineEdit; class QSpinBox; -class QStandardItemModel; -class QTableView; +class QTableWidget; +class QTableWidgetItem; class QHeaderView; -class QDoubleSpinBox; +class SMESHGUI_SpinBox; +class StdMeshersGUI_ObjectReferenceParamWdg; class LightApp_SelectionMgr; +class SUIT_SelectionFilter; + +class QTEnfVertex +{ + +public: + QTEnfVertex(double size, double x=0., double y=0., double z=0., QString name="", QString geomEntry="", QString groupName="", bool isCompound = false); + +private: + bool operator == (const QTEnfVertex* other) const { + if (other) { + if (this->coords.size() && other->coords.size()) + return (this->coords == other->coords); + else + return (this->geomEntry == other->geomEntry); + } + } + + QString name; + QString geomEntry; + bool isCompound; + QString groupName; + double size; + std::vector coords; +}; + +typedef QList< QTEnfVertex* > QEnfVertexList; // Enforced vertex struct TEnfVertex{ std::string name; std::string geomEntry; + bool isCompound; std::vector coords; std::string groupName; double size; @@ -81,7 +114,30 @@ struct CompareEnfVertices // List of enforced vertices typedef std::set< TEnfVertex*, CompareEnfVertices > TEnfVertexList; -// typedef std::vector TEnforcedVertexCoordsValues; +// Enforced mesh +struct TEnfMesh{ + std::string name; + std::string entry; + int elementType; + std::string groupName; + double size; +}; + +struct CompareEnfMeshes +{ + bool operator () (const TEnfMesh* e1, const TEnfMesh* e2) const { + if (e1 && e2) { + if (e1->entry == e2->entry) + return (e1->elementType < e2->elementType); + else + return (e1->entry < e2->entry); + } + else + return false; + } +}; +// List of enforced meshes +typedef std::set< TEnfMesh*, CompareEnfMeshes > TEnfMeshList; typedef struct { @@ -90,6 +146,7 @@ typedef struct QString myName,myWorkingDir,myTextOption; short myVerboseLevel; TEnfVertexList myEnforcedVertices; + TEnfMeshList myEnforcedMeshes; } GHS3DHypothesisData; /*! @@ -118,18 +175,35 @@ protected: protected slots: void onDirBtnClicked(); void updateWidgets(); - void onVertexBtnClicked(); - void onRemoveVertexBtnClicked(); - bool checkVertexIsDefined(); - + + void addEnforcedVertex(double x=0, double y=0, double z=0, double size = 0, + std::string vertexName = "", std::string geomEntry = "", std::string groupName = "", + bool isCompound = false); + void onAddEnforcedVertex(); + void onRemoveEnforcedVertex(); + void synchronizeCoords(); + void updateEnforcedVertexValues(QTableWidgetItem* ); + void onSelectEnforcedVertex(); + void clearEnforcedVertexWidgets(); + void checkVertexIsDefined(); + void clearEnfVertexSelection(); + + void addEnforcedMesh(std::string name, std::string entry, int elementType, double size = 0, std::string groupName = ""); + void onAddEnforcedMesh(); + void onRemoveEnforcedMesh(); + void synchronizeEnforcedMesh(); + void checkEnfMeshIsDefined(); + signals: void vertexDefined(bool); - + void enfMeshDefined(bool); + private: bool readParamsFromHypo( GHS3DHypothesisData& ) const; bool readParamsFromWidgets( GHS3DHypothesisData& ) const; bool storeParamsToHypo( const GHS3DHypothesisData& ) const; - bool smpVertexExists(double, double, double) const; + GeomSelectionTools* getGeomSelectionTool(); + GEOM::GEOM_Gen_var getGeomEngine(); private: QWidget* myStdGroup; @@ -149,38 +223,76 @@ private: QCheckBox* myRemoveInitialCentralPointCheck; QCheckBox* myBoundaryRecoveryCheck; QCheckBox* myFEMCorrectionCheck; -QLineEdit* myTextOption; + QLineEdit* myTextOption; QWidget* myEnfGroup; - QStandardItemModel* mySmpModel; - QTableView* myEnforcedTableView; - QLineEdit* myXCoord; - QLineEdit* myYCoord; - QLineEdit* myZCoord; - QLineEdit* mySizeValue; + QPixmap iconVertex, iconCompound; + StdMeshersGUI_ObjectReferenceParamWdg *myEnfVertexWdg; + GEOM::GEOM_Object_var myEnfVertex; + QTableWidget* myEnforcedTableWidget; + SMESHGUI_SpinBox* myXCoord; + SMESHGUI_SpinBox* myYCoord; + SMESHGUI_SpinBox* myZCoord; + SMESHGUI_SpinBox* mySizeValue; + QLineEdit* myGroupName; +// QGroupBox* makeGroupsCheck; +// QCheckBox* myGlobalGroupName; QPushButton* addVertexButton; QPushButton* removeVertexButton; - LightApp_SelectionMgr* mySelectionMgr; /* User shape selection */ + QWidget* myEnfMeshGroup; + StdMeshersGUI_ObjectReferenceParamWdg *myEnfMeshWdg; +// SMESH::SMESH_IDSource_var myEnfMesh; + QComboBox* myEnfMeshConstraint; + QStringList myEnfMeshConstraintLabels; +// SMESH::mesh_array_var myEnfMeshArray; + QTableWidget* myEnforcedMeshTableWidget; + SMESHGUI_SpinBox* myMeshSizeValue; + QLineEdit* myMeshGroupName; + QPushButton* addEnfMeshButton; + QPushButton* removeEnfMeshButton; + + GeomSelectionTools* GeomToolSelected; // SVTK_Selector* mySelector; +// LightApp_SelectionMgr* mySelectionMgr; /* User shape selection */ +}; + +class EnforcedVertexTableWidgetDelegate : public QItemDelegate +{ + Q_OBJECT + +public: + EnforcedVertexTableWidgetDelegate(QObject *parent = 0); + + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index) const; + + void setEditorData(QWidget *editor, const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const; + + void updateEditorGeometry(QWidget *editor, + const QStyleOptionViewItem &option, const QModelIndex &index) const; + + bool vertexExists(QAbstractItemModel *model, const QModelIndex &index, QString value) const; }; -class DoubleLineEditDelegate : public QItemDelegate +class EnforcedMeshTableWidgetDelegate : public QItemDelegate { Q_OBJECT public: - DoubleLineEditDelegate(QObject *parent = 0); + EnforcedMeshTableWidgetDelegate(QObject *parent = 0); - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, - const QModelIndex &index) const; + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, + const QModelIndex &index) const; - void setEditorData(QWidget *editor, const QModelIndex &index) const; - void setModelData(QWidget *editor, QAbstractItemModel *model, - const QModelIndex &index) const; + void setEditorData(QWidget *editor, const QModelIndex &index) const; + void setModelData(QWidget *editor, QAbstractItemModel *model, + const QModelIndex &index) const; - void updateEditorGeometry(QWidget *editor, - const QStyleOptionViewItem &option, const QModelIndex &index) const; + void updateEditorGeometry(QWidget *editor, + const QStyleOptionViewItem &option, const QModelIndex &index) const; }; #endif diff --git a/src/GUI/GHS3DPlugin_msg_en.ts b/src/GUI/GHS3DPlugin_msg_en.ts index 3be9da8..65569d8 100644 --- a/src/GUI/GHS3DPlugin_msg_en.ts +++ b/src/GUI/GHS3DPlugin_msg_en.ts @@ -103,6 +103,14 @@ GHS3D_ENFORCED_VERTICES Enforced vertices + + GHS3D_ENFORCED_MESHES + Enforced meshes + + + GHS3D_ENF_NAME_COLUMN + Name + GHS3D_ENF_VER_X_COLUMN X @@ -116,9 +124,33 @@ Z - GHS3D_ENF_VER_SIZE_COLUMN + GHS3D_ENF_SIZE_COLUMN Size + + GHS3D_ENF_ENTRY_COLUMN + Vertex Entry + + + GHS3D_ENF_MESH_CONSTRAINT_COLUMN + Constraint + + + GHS3D_ENF_VER_COMPOUND_COLUMN + Compound + + + GHS3D_ENF_GROUP_COLUMN + Group + + + GHS3D_ENF_SELECT_VERTEX + Select a vertex + + + GHS3D_ENF_SELECT_MESH + Select a mesh + GHS3D_ENF_VER_X_LABEL X: @@ -132,16 +164,44 @@ Z: - GHS3D_ENF_VER_SIZE_LABEL + GHS3D_ENF_MESH_CONSTRAINT_LABEL + Constraint: + + + GHS3D_ENF_MESH_CONSTRAINT_NODE + Nodes + + + GHS3D_ENF_MESH_CONSTRAINT_EDGE + Edges + + + GHS3D_ENF_MESH_CONSTRAINT_FACE + Faces + + + GHS3D_ENF_SIZE_LABEL Size: - GHS3D_ENF_VER_VERTEX - Add enforced vertex + GHS3D_ENF_GROUP_LABEL + Group: + + + GHS3D_ENF_ADD + Add + + + GHS3D_ENF_REMOVE + Remove + + + GHS3D_ENF_VER_INFO + <b>Warning</b>: Enforced vertices are currently only taken into account for meshes w/o associated geometry. - GHS3D_ENF_VER_REMOVE - Remove vertex + GHS3D_ENF_MESH_INFO + <b>Warning</b>: Enforced meshes are currently only taken into account for meshes w/o associated geometry. diff --git a/src/GUI/GHS3DPlugin_msg_fr.ts b/src/GUI/GHS3DPlugin_msg_fr.ts index 853049d..86452f3 100755 --- a/src/GUI/GHS3DPlugin_msg_fr.ts +++ b/src/GUI/GHS3DPlugin_msg_fr.ts @@ -103,6 +103,14 @@ GHS3D_ENFORCED_VERTICES Points de passage + + GHS3D_ENFORCED_MESHES + Maillages de contrainte + + + GHS3D_ENF_NAME_COLUMN + Nom + GHS3D_ENF_VER_X_COLUMN X @@ -116,9 +124,33 @@ Z - GHS3D_ENF_VER_SIZE_COLUMN + GHS3D_ENF_SIZE_COLUMN Taille + + GHS3D_ENF_ENTRY_COLUMN + ID de point + + + GHS3D_ENF_MESH_CONSTRAINT_COLUMN + Contrainte + + + GHS3D_ENF_VER_COMPOUND_COLUMN + Compound + + + GHS3D_ENF_GROUP_COLUMN + Groupe + + + GHS3D_ENF_SELECT_VERTEX + Sélectionnez une/des point(s) + + + GHS3D_ENF_SELECT_MESH + Sélectionnez une/des maillage(s) + GHS3D_ENF_VER_X_LABEL X: @@ -132,16 +164,44 @@ Z: - GHS3D_ENF_VER_SIZE_LABEL + GHS3D_ENF_MESH_CONSTRAINT_LABEL + Contrainte: + + + GHS3D_ENF_MESH_CONSTRAINT_NODE + Noeuds + + + GHS3D_ENF_MESH_CONSTRAINT_EDGE + Segments + + + GHS3D_ENF_MESH_CONSTRAINT_FACE + Faces + + + GHS3D_ENF_SIZE_LABEL Taille: - GHS3D_ENF_VER_VERTEX - Ajouter un point de passage + GHS3D_ENF_GROUP_LABEL + Groupe: + + + GHS3D_ENF_ADD + Ajouter + + + GHS3D_ENF_REMOVE + Supprimer + + + GHS3D_ENF_VER_INFO + <b>Attention</b>: Les points de passage ne sont pris en compte que pour des maillage sans géométrie associée. - GHS3D_ENF_VER_REMOVE - Supprimer un point + GHS3D_ENF_MESH_INFO + <b>Attention</b>: Les éléments de contraintes ne sont pris en compte que pour des maillage sans géométrie associée. diff --git a/src/GUI/Makefile.am b/src/GUI/Makefile.am index e5b3c4c..3c3f4a0 100644 --- a/src/GUI/Makefile.am +++ b/src/GUI/Makefile.am @@ -26,18 +26,26 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am # header files -salomeinclude_HEADERS = +salomeinclude_HEADERS = \ + GHS3DPluginGUI_HypothesisCreator.h \ + GHS3DPluginGUI_Enums.h # Libraries targets lib_LTLIBRARIES = libGHS3DPluginGUI.la -dist_libGHS3DPluginGUI_la_SOURCES = GHS3DPluginGUI_HypothesisCreator.cxx +dist_libGHS3DPluginGUI_la_SOURCES = \ + GHS3DPluginGUI.cxx \ + GHS3DPluginGUI_HypothesisCreator.cxx -MOC_FILES = GHS3DPluginGUI_HypothesisCreator_moc.cxx -nodist_libGHS3DPluginGUI_la_SOURCES= $(MOC_FILES) +MOC_FILES = \ + GHS3DPluginGUI_HypothesisCreator_moc.cxx + +nodist_libGHS3DPluginGUI_la_SOURCES= \ + $(MOC_FILES) libGHS3DPluginGUI_la_CPPFLAGS = \ $(QT_INCLUDES) \ + $(CAS_CPPFLAGS) \ $(KERNEL_CXXFLAGS) \ $(GUI_CXXFLAGS) \ $(GEOM_CXXFLAGS) \ @@ -46,8 +54,7 @@ libGHS3DPluginGUI_la_CPPFLAGS = \ $(BOOST_CPPFLAGS) \ $(CORBA_CXXFLAGS) \ $(CORBA_INCLUDES) \ - $(CAS_CPPFLAGS) \ - -I$(srcdir)/.. \ + -I$(srcdir)/../GHS3DPlugin \ -I$(top_builddir)/idl libGHS3DPluginGUI_la_LDFLAGS = \ @@ -55,7 +62,7 @@ libGHS3DPluginGUI_la_LDFLAGS = \ $(QT_LIBS) \ $(KERNEL_LDFLAGS) -lSALOMELocalTrace \ $(MED_LDFLAGS) -lSalomeIDLMED \ - $(SMESH_LDFLAGS) -lSMESH \ + $(SMESH_LDFLAGS) -lSMESH -lGeomSelectionTools -lStdMeshersGUI\ $(GUI_LDFLAGS) -lsuit -lqtx -lSalomeApp \ $(CAS_KERNEL)