From a88e2af2a6e9b88fa72e6563a77374fd5f499cd6 Mon Sep 17 00:00:00 2001 From: enk Date: Wed, 29 Dec 2004 14:32:59 +0000 Subject: [PATCH] Bug PAL7334 - DEVELOPMENT : Control Improvement Bug PAL7613: Needless submenu in the 3D Viewer popup for meshes groups --- idl/SMESH_Filter.idl | 16 +++- resources/SMESH_en.xml | 5 + src/Controls/SMESHControls.cxx | 2 + src/Controls/SMESH_Controls.cxx | 142 ++++++++++++++++++++++++++++ src/Controls/SMESH_ControlsDef.hxx | 20 ++++ src/OBJECT/SMESH_Actor.cxx | 9 ++ src/OBJECT/SMESH_Actor.h | 2 +- src/OBJECT/SMESH_DeviceActor.cxx | 65 ++++++++++++- src/SMESHGUI/SMESHGUI.cxx | 34 +++++-- src/SMESHGUI/SMESHGUI_FilterDlg.cxx | 1 + src/SMESHGUI/SMESH_msg_en.po | 15 ++- src/SMESH_I/SMESH_Filter_i.cxx | 52 ++++++++++ src/SMESH_I/SMESH_Filter_i.hxx | 17 ++++ 13 files changed, 365 insertions(+), 15 deletions(-) diff --git a/idl/SMESH_Filter.idl b/idl/SMESH_Filter.idl index d6cfc5ed8..367e53da2 100644 --- a/idl/SMESH_Filter.idl +++ b/idl/SMESH_Filter.idl @@ -54,6 +54,7 @@ module SMESH FT_FreeBorders, FT_FreeEdges, FT_MultiConnection, + FT_MultiConnection2D, FT_Length, FT_Length2D, FT_BelongToGeom, @@ -108,13 +109,23 @@ module SMESH struct Value { double myLength; - long myElemId; long myPnt1, myPnt2; }; typedef sequence Values; Values GetValues(); }; - interface MultiConnection : NumericalFunctor{}; + interface MultiConnection : NumericalFunctor{}; + interface MultiConnection2D : NumericalFunctor + { + struct Value + { + long myNbConnects; + long myPnt1, myPnt2; + }; + + typedef sequence Values; + Values GetValues(); + }; /*! * Predicates are intended for verification of criteria, @@ -342,6 +353,7 @@ module SMESH Length CreateLength(); Length2D CreateLength2D(); MultiConnection CreateMultiConnection(); + MultiConnection2D CreateMultiConnection2D(); /*! * Create logical functors ( predicates ) diff --git a/resources/SMESH_en.xml b/resources/SMESH_en.xml index 0ebb0d48a..91fc25362 100644 --- a/resources/SMESH_en.xml +++ b/resources/SMESH_en.xml @@ -79,6 +79,7 @@ + @@ -259,6 +260,7 @@ + @@ -313,6 +315,7 @@ + @@ -369,6 +372,7 @@ + @@ -419,6 +423,7 @@ + diff --git a/src/Controls/SMESHControls.cxx b/src/Controls/SMESHControls.cxx index 0490f9ff1..0c8d145a3 100644 --- a/src/Controls/SMESHControls.cxx +++ b/src/Controls/SMESHControls.cxx @@ -29,7 +29,9 @@ int main(int argc, char** argv) new Skew(); new Area(); new Length(); + // new Length2D(); new MultiConnection(); + // new MultiConnection2D(); new FreeBorders(); new LessThan(); new MoreThan(); diff --git a/src/Controls/SMESH_Controls.cxx b/src/Controls/SMESH_Controls.cxx index 5d38ccc00..d0ee98ef4 100644 --- a/src/Controls/SMESH_Controls.cxx +++ b/src/Controls/SMESH_Controls.cxx @@ -1020,6 +1020,148 @@ SMDSAbs_ElementType MultiConnection::GetType() const return SMDSAbs_Edge; } +/* + Class : MultiConnection2D + Description : Functor for calculating number of faces conneted to the edge +*/ +double MultiConnection2D::GetValue( const TSequenceOfXYZ& P ) +{ + return 0; +} + +double MultiConnection2D::GetValue( long theElementId ) +{ + TSequenceOfXYZ P; + int aResult = 0; + + if (GetPoints(theElementId,P)){ + double aVal; + const SMDS_MeshElement* anFaceElem = myMesh->FindElement( theElementId ); + SMDSAbs_ElementType aType = anFaceElem->GetType(); + + int len = P.size(); + + TColStd_MapOfInteger aMap; + int aResult = 0; + + switch (aType){ + case SMDSAbs_All: + case SMDSAbs_Node: + case SMDSAbs_Edge: + case SMDSAbs_Face: + if (len == 3){ // triangles + int Nb[3] = {0,0,0}; + + int i=0; + SMDS_ElemIteratorPtr anIter = anFaceElem->nodesIterator(); + if ( anIter != 0 ) { + while( anIter->more() ) { + const SMDS_MeshNode* aNode = (SMDS_MeshNode*)anIter->next(); + if ( aNode == 0 ){ + break; + } + SMDS_ElemIteratorPtr anElemIter = aNode->GetInverseElementIterator(); + while( anElemIter->more() ) { + const SMDS_MeshElement* anElem = anElemIter->next(); + if ( anElem != 0 && anElem->GetType() != SMDSAbs_Edge ) { + int anId = anElem->GetID(); + + if ( anIter->more() ) // i.e. first node + aMap.Add( anId ); + else if ( aMap.Contains( anId ) ){ + Nb[i]++; + } + } + else if ( anElem != 0 && anElem->GetType() == SMDSAbs_Edge ) i++; + } + } + } + + aResult = Max(Max(Nb[0],Nb[1]),Nb[2]); + } + break; + case SMDSAbs_Volume: + default: aResult=0; + } + + } + return aResult;//getNbMultiConnection( myMesh, theId ); +} + +double MultiConnection2D::GetBadRate( double Value, int /*nbNodes*/ ) const +{ + return Value; +} + +SMDSAbs_ElementType MultiConnection2D::GetType() const +{ + return SMDSAbs_Face; +} + +MultiConnection2D::Value::Value(long thePntId1, long thePntId2) +{ + myPntId[0] = thePntId1; myPntId[1] = thePntId2; + if(thePntId1 > thePntId2){ + myPntId[1] = thePntId1; myPntId[0] = thePntId2; + } +} + +bool MultiConnection2D::Value::operator<(const MultiConnection2D::Value& x) const{ + if(myPntId[0] < x.myPntId[0]) return true; + if(myPntId[0] == x.myPntId[0]) + if(myPntId[1] < x.myPntId[1]) return true; + return false; +} + +void MultiConnection2D::GetValues(MValues& theValues){ + SMDS_FaceIteratorPtr anIter = myMesh->facesIterator(); + for(; anIter->more(); ){ + const SMDS_MeshFace* anElem = anIter->next(); + long anElemId = anElem->GetID(); + SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator(); + long aNodeId[3]; + + //int aNbConnects=0; + const SMDS_MeshNode* aNode0; + const SMDS_MeshNode* aNode1; + const SMDS_MeshNode* aNode2; + if(aNodesIter->more()){ + aNode0 = (SMDS_MeshNode*) aNodesIter->next(); + aNode1 = aNode0; + const SMDS_MeshNode* aNodes = (SMDS_MeshNode*) aNode1; + aNodeId[0] = aNodeId[1] = aNodes->GetID(); + } + for(; aNodesIter->more(); ){ + aNode2 = (SMDS_MeshNode*) aNodesIter->next(); + long anId = aNode2->GetID(); + aNodeId[2] = anId; + + Value aValue(aNodeId[1],aNodeId[2]); + MValues::iterator aItr = theValues.find(aValue); + if (aItr != theValues.end()){ + aItr->second += 1; + //aNbConnects = nb; + } else { + theValues[aValue] = 1; + //aNbConnects = 1; + } + //cout << "NodeIds: "<SetRange(aScalars->GetRange()); theLookupTable->Build(); + myMergeFilter->SetScalars(aDataSet); + aDataSet->Delete(); + } + else if (MultiConnection2D* aMultiConnection2D = dynamic_cast(theFunctor.get())){ + SMESH::Controls::MultiConnection2D::MValues aValues; + + myVisualObj->UpdateFunctor(theFunctor); + + aMultiConnection2D->GetValues(aValues); + vtkUnstructuredGrid* aDataSet = vtkUnstructuredGrid::New(); + vtkUnstructuredGrid* aGrid = myVisualObj->GetUnstructuredGrid(); + aDataSet->SetPoints(aGrid->GetPoints()); + + vtkIdType aNbCells = aValues.size(); + vtkDoubleArray *aScalars = vtkDoubleArray::New(); + aScalars->SetNumberOfComponents(1); + aScalars->SetNumberOfTuples(aNbCells); + + vtkIdType aCellsSize = 3*aNbCells; + vtkCellArray* aConnectivity = vtkCellArray::New(); + aConnectivity->Allocate( aCellsSize, 0 ); + + vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New(); + aCellTypesArray->SetNumberOfComponents( 1 ); + aCellTypesArray->Allocate( aNbCells * aCellTypesArray->GetNumberOfComponents() ); + + vtkIdList *anIdList = vtkIdList::New(); + anIdList->SetNumberOfIds(2); + + MultiConnection2D::MValues::const_iterator anIter = aValues.begin(); + int i = 0; + for(vtkIdType aVtkId; anIter != aValues.end(); anIter++,i++){ + const MultiConnection2D::Value& aValue = (*anIter).first; + int aNode[2] = { + myVisualObj->GetNodeVTKId(aValue.myPntId[0]), + myVisualObj->GetNodeVTKId(aValue.myPntId[1]) + }; + if(aNode[0] >= 0 && aNode[1] >= 0){ + anIdList->SetId( 0, aNode[0] ); + anIdList->SetId( 1, aNode[1] ); + aConnectivity->InsertNextCell( anIdList ); + aCellTypesArray->InsertNextValue( VTK_LINE ); + aScalars->SetValue(i,(*anIter).second); + } + } + + vtkIntArray* aCellLocationsArray = vtkIntArray::New(); + aCellLocationsArray->SetNumberOfComponents( 1 ); + aCellLocationsArray->SetNumberOfTuples( aNbCells ); + + aConnectivity->InitTraversal(); + for( vtkIdType idType = 0, *pts, npts; aConnectivity->GetNextCell( npts, pts ); idType++ ) + aCellLocationsArray->SetValue( idType, aConnectivity->GetTraversalLocation( npts ) ); + + aDataSet->SetCells( aCellTypesArray, aCellLocationsArray,aConnectivity ); + SetUnstructuredGrid(aDataSet); + + aDataSet->GetCellData()->SetScalars(aScalars); + aScalars->Delete(); + + theLookupTable->SetRange(aScalars->GetRange()); + theLookupTable->Build(); + myMergeFilter->SetScalars(aDataSet); aDataSet->Delete(); } diff --git a/src/SMESHGUI/SMESHGUI.cxx b/src/SMESHGUI/SMESHGUI.cxx index 0c6049cab..339b56a39 100644 --- a/src/SMESHGUI/SMESHGUI.cxx +++ b/src/SMESHGUI/SMESHGUI.cxx @@ -563,6 +563,10 @@ namespace{ aTitle = QObject::tr( "MULTI_BORDERS" ); aControl = SMESH_Actor::eMultiConnection; break; + case 6019: + aTitle = QObject::tr( "MULTI2D_BORDERS" ); + aControl = SMESH_Actor::eMultiConnection2D; + break; case 6011: aTitle = QObject::tr( "AREA_ELEMENTS" ); aControl = SMESH_Actor::eArea; @@ -2081,6 +2085,7 @@ bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent) case 6011: case 6001: case 6018: + case 6019: case 6002: case 6003: case 6004: @@ -2428,30 +2433,40 @@ bool SMESHGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString // Display Entity mi = popup->findItem( 1135 ); - if ( mi && mi->popup() ) { + int aIsSomething=0; + if (aNbVolumes>0) aIsSomething++; + if (aNbFaces>0) aIsSomething++; + if (aNbEdges>0) aIsSomething++; + if ( mi && (aIsSomething <= 1)){ + popup->removeItem(1135); + }else if ( mi && mi->popup() ) { QPopupMenu* aPopup = mi->popup(); unsigned int aMode = anActor->GetEntityMode(); - + + bool aIsVolumesMode = aMode & SMESH_Actor::eVolumes; + bool aIsFacesMode = aMode & SMESH_Actor::eFaces; + bool aIsEdgesMode = aMode & SMESH_Actor::eEdges; + if(aNbVolumes == 0) aPopup->removeItem( 219 ); else - aPopup->setItemChecked( 219, aMode & SMESH_Actor::eVolumes ); + aPopup->setItemChecked( 219, aIsVolumesMode ); if(aNbFaces == 0) aPopup->removeItem( 218 ); else - aPopup->setItemChecked( 218, aMode & SMESH_Actor::eFaces ); + aPopup->setItemChecked( 218, aIsFacesMode ); if(aNbEdges == 0) aPopup->removeItem( 217 ); else - aPopup->setItemChecked( 217, aMode & SMESH_Actor::eEdges ); + aPopup->setItemChecked( 217, aIsEdgesMode ); - bool aIsRemove = (aNbVolumes == 0 || aMode & SMESH_Actor::eVolumes); - aIsRemove &= (aNbFaces == 0 || aMode & SMESH_Actor::eFaces); - aIsRemove &= (aNbEdges == 0 || aMode & SMESH_Actor::eEdges); + bool aIsRemove = (aNbVolumes == 0 || aIsVolumesMode); + aIsRemove &= (aNbFaces == 0 || aIsFacesMode); + aIsRemove &= (aNbEdges == 0 || aIsEdgesMode); if(aIsRemove) aPopup->removeItem( 220 ); @@ -2476,6 +2491,8 @@ bool SMESHGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString break; case SMESH_Actor::eMultiConnection: mi->popup()->setItemChecked( 6004, true ); break; + case SMESH_Actor::eMultiConnection2D: + mi->popup()->setItemChecked( 6019, true ); break; case SMESH_Actor::eArea: mi->popup()->setItemChecked( 6011, true ); break; case SMESH_Actor::eTaper: @@ -2511,6 +2528,7 @@ bool SMESHGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString mi->popup()->removeItem( 6014 ); mi->popup()->removeItem( 6015 ); mi->popup()->removeItem( 6016 ); + mi->popup()->removeItem( 6019 ); } if(aNbVolumes == 0){ mi->popup()->removeItem( 6017 ); diff --git a/src/SMESHGUI/SMESHGUI_FilterDlg.cxx b/src/SMESHGUI/SMESHGUI_FilterDlg.cxx index fff798a30..66bc89083 100755 --- a/src/SMESHGUI/SMESHGUI_FilterDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_FilterDlg.cxx @@ -1278,6 +1278,7 @@ const QMap& SMESHGUI_FilterTable::getCriteria( const int theType ) aCriteria[ SMESH::FT_BelongToPlane ] = tr( "BELONG_TO_PLANE" ); aCriteria[ SMESH::FT_BelongToCylinder ] = tr( "BELONG_TO_CYLINDER" ); aCriteria[ SMESH::FT_Length2D ] = tr( "LENGTH2D" ); + aCriteria[ SMESH::FT_MultiConnection2D] = tr( "MULTI2D_BORDERS" ); } return aCriteria; } diff --git a/src/SMESHGUI/SMESH_msg_en.po b/src/SMESHGUI/SMESH_msg_en.po index a84e68a07..78bcd46fd 100644 --- a/src/SMESHGUI/SMESH_msg_en.po +++ b/src/SMESHGUI/SMESH_msg_en.po @@ -961,9 +961,15 @@ msgstr "Free borders" msgid "SMESHGUI_FilterTable::MULTI_BORDERS" msgstr "Borders at multi-connections" +#msgid "SMESHGUI_FilterTable::MULTI2D_BORDERS" +#msgstr "Borders at multi-connections 2D" + msgid "SMESHGUI_FilterTable::LENGTH" msgstr "Length" +#msgid "SMESHGUI_FilterTable::LENGTH2D" +#msgstr "Length2D" + msgid "SMESHGUI_FilterTable::ASPECT_RATIO" msgstr "Aspect ratio" @@ -1096,13 +1102,16 @@ msgid "LENGTH_EDGES" msgstr "Length" msgid "LENGTH2D_EDGES" -msgstr "Length2D" +msgstr "Length 2D" msgid "FREE_BORDERS" -msgstr "Free borders" +msgstr "Free Borders" msgid "MULTI_BORDERS" -msgstr "Borders at multi-connections" +msgstr "Borders at Multi-Connections" + +msgid "MULTI2D_BORDERS" +msgstr "Borders at Multi-Connections 2D" msgid "AREA_ELEMENTS" msgstr "Area" diff --git a/src/SMESH_I/SMESH_Filter_i.cxx b/src/SMESH_I/SMESH_Filter_i.cxx index 6b12b6ad1..4d98d80c3 100644 --- a/src/SMESH_I/SMESH_Filter_i.cxx +++ b/src/SMESH_I/SMESH_Filter_i.cxx @@ -483,6 +483,46 @@ FunctorType MultiConnection_i::GetFunctorType() return SMESH::FT_MultiConnection; } +/* + Class : MultiConnection2D_i + Description : Functor for calculating number of faces conneted to the edge +*/ +MultiConnection2D_i::MultiConnection2D_i() +{ + myNumericalFunctorPtr.reset( new Controls::MultiConnection2D() ); + myFunctorPtr = myNumericalFunctorPtr; +} + +FunctorType MultiConnection2D_i::GetFunctorType() +{ + return SMESH::FT_MultiConnection2D; +} + +SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues() +{ + INFOS("MultiConnection2D_i::GetValues"); + SMESH::Controls::MultiConnection2D::MValues aValues; + myMulticonnection2DPtr->GetValues( aValues ); + + long i = 0, iEnd = aValues.size(); + + SMESH::MultiConnection2D::Values_var aResult = new SMESH::MultiConnection2D::Values(iEnd); + + SMESH::Controls::MultiConnection2D::MValues::const_iterator anIter; + for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ ) + { + const SMESH::Controls::MultiConnection2D::Value& aVal = (*anIter).first; + SMESH::MultiConnection2D::Value &aValue = aResult[ i ]; + + aValue.myPnt1 = aVal.myPntId[ 0 ]; + aValue.myPnt2 = aVal.myPntId[ 1 ]; + aValue.myNbConnects = (*anIter).second; + + } + + INFOS("Multiconnection2D_i::GetValuess~"); + return aResult._retn(); +} /* PREDICATES @@ -1092,6 +1132,12 @@ MultiConnection_ptr FilterManager_i::CreateMultiConnection() return anObj._retn(); } +MultiConnection2D_ptr FilterManager_i::CreateMultiConnection2D() +{ + SMESH::MultiConnection2D_i* aServant = new SMESH::MultiConnection2D_i(); + SMESH::MultiConnection2D_var anObj = aServant->_this(); + return anObj._retn(); +} BelongToGeom_ptr FilterManager_i::CreateBelongToGeom() { @@ -1470,6 +1516,9 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria case SMESH::FT_MultiConnection: aFunctor = aFilterMgr->CreateMultiConnection(); break; + case SMESH::FT_MultiConnection2D: + aFunctor = aFilterMgr->CreateMultiConnection2D(); + break; case SMESH::FT_Length: aFunctor = aFilterMgr->CreateLength(); break; @@ -1741,6 +1790,7 @@ static inline LDOMString toString( const long theType ) case FT_FreeBorders : return "Free borders"; case FT_FreeEdges : return "Free edges"; case FT_MultiConnection : return "Borders at multi-connections"; + case FT_MultiConnection2D: return "Borders at multi-connections 2D"; case FT_Length : return "Length"; case FT_Length2D : return "Length2D"; case FT_LessThan : return "Less than"; @@ -1772,7 +1822,9 @@ static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr ) else if ( theStr.equals( "Free borders" ) ) return FT_FreeBorders; else if ( theStr.equals( "Free edges" ) ) return FT_FreeEdges; else if ( theStr.equals( "Borders at multi-connections" ) ) return FT_MultiConnection; + // else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D; else if ( theStr.equals( "Length" ) ) return FT_Length; + // else if ( theStr.equals( "Length2D" ) ) return FT_Length2D; else if ( theStr.equals( "Range of IDs" ) ) return FT_RangeOfIds; else if ( theStr.equals( "Less than" ) ) return FT_LessThan; else if ( theStr.equals( "More than" ) ) return FT_MoreThan; diff --git a/src/SMESH_I/SMESH_Filter_i.hxx b/src/SMESH_I/SMESH_Filter_i.hxx index 95e7b58e9..4e884a416 100644 --- a/src/SMESH_I/SMESH_Filter_i.hxx +++ b/src/SMESH_I/SMESH_Filter_i.hxx @@ -247,6 +247,22 @@ public: FunctorType GetFunctorType(); }; +/* + Class : MultiConnection2D_i + Description : Functor for calculating number of faces conneted to the edge +*/ +class MultiConnection2D_i: public virtual POA_SMESH::MultiConnection2D, + public virtual NumericalFunctor_i +{ +public: + MultiConnection2D_i(); + SMESH::MultiConnection2D::Values* GetValues(); + FunctorType GetFunctorType(); + +protected: + Controls::MultiConnection2DPtr myMulticonnection2DPtr; +}; + /* PREDICATES @@ -620,6 +636,7 @@ public: Length_ptr CreateLength(); Length2D_ptr CreateLength2D(); MultiConnection_ptr CreateMultiConnection(); + MultiConnection2D_ptr CreateMultiConnection2D(); BelongToGeom_ptr CreateBelongToGeom(); BelongToPlane_ptr CreateBelongToPlane(); -- 2.39.2