Salome HOME
0020082: EDF 869 GEOM : Edges Orientation indicator/reverse
authordmv <dmv@opencascade.com>
Tue, 15 Sep 2009 13:00:06 +0000 (13:00 +0000)
committerdmv <dmv@opencascade.com>
Tue, 15 Sep 2009 13:00:06 +0000 (13:00 +0000)
src/SMESHGUI/SMESHGUI_Hypotheses.h
src/SMESHGUI/SMESHGUI_MeshOp.cxx
src/StdMeshersGUI/StdMeshersGUI_NbSegmentsCreator.cxx
src/StdMeshersGUI/StdMeshersGUI_StdHypothesisCreator.cxx
src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx
src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.h

index cccf69f..0372b09 100644 (file)
@@ -68,6 +68,9 @@ public:
   QString                      getShapeEntry() const { return myShapeEntry; }
   void                         setShapeEntry( const QString& theEntry );
 
+  QString                      getMainShapeEntry() const { return myMainShapeEntry; }
+  void                         setMainShapeEntry( const QString& theEntry ) { myMainShapeEntry = theEntry; }
+
 signals:
   void                         finished( int );
 
@@ -126,6 +129,7 @@ private:
   bool                         myIsCreate;
   QtxDialog*                   myDlg;
   QString                      myShapeEntry;
+  QString                      myMainShapeEntry;
 };
 
 class SMESHGUI_HypothesisDlg : public QtxDialog
index 32b21f7..310f34d 100644 (file)
@@ -1069,18 +1069,45 @@ void SMESHGUI_MeshOp::createHypothesis(const int theDim,
       removeCustomFilters(); // Issue 0020170
 
       // Get Entry of the Geom object
+      QString aGeomEntry = "";
+      QString aMeshEntry = "";
       QString anObjEntry = "";
-      anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
-      if ( anObjEntry == "" ) {
-        anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
-       if ( anObjEntry != "" ) {
-         _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
-         GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
-         anObjEntry = ( aGeomVar->_is_nil() ) ? "" : anObjEntry = aGeomVar->GetStudyEntry();
-       }
+      aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
+      aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
+      anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
+      
+      if ( aMeshEntry != "" ) { // Get Geom object from Mesh
+        _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
+        GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
+        aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
+      }
+      
+      if ( aMeshEntry == "" && aGeomEntry == "" ) {
+        _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
+        GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
+        aGeomEntry = aGeomVar->GetStudyEntry();
       }
 
-      aCreator->setShapeEntry( anObjEntry );
+      if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) { // take geometry from submesh
+        _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
+        if ( pObj ) {
+          // if current object is sub-mesh
+          SMESH::SMESH_subMesh_var aSubMeshVar =
+            SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
+          if ( !aSubMeshVar->_is_nil() ) {
+            SMESH::SMESH_Mesh_var aMeshVar =  aSubMeshVar->GetFather();
+            if ( !aMeshVar->_is_nil() ) {
+              _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
+              GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
+              aMeshEntry = aGeomVar->GetStudyEntry();
+            }
+          }
+        }
+      }
+      
+      aCreator->setShapeEntry( aGeomEntry );
+      if ( aMeshEntry != "" )
+        aCreator->setMainShapeEntry( aMeshEntry );
       myDlg->setEnabled( false );
       aCreator->create(initParamHyp, aHypName, myDlg, this, SLOT( onHypoCreated( int ) ) );
       dialog = true;
@@ -1163,18 +1190,45 @@ void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
     aCreator->setInitParamsHypothesis( initParamHyp );
 
     // Get Entry of the Geom object
+    QString aGeomEntry = "";
+    QString aMeshEntry = "";
     QString anObjEntry = "";
-    anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
-    if ( anObjEntry == "" ) {
-      anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
-      if ( anObjEntry != "" ) {
-       _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
-       GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
-       anObjEntry = aGeomVar->GetStudyEntry();
+    aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
+    aMeshEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Mesh );
+    anObjEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Obj );
+
+    if ( aMeshEntry != "" ) { // Get Geom object from Mesh
+      _PTR(SObject) pObj = studyDS()->FindObjectID( aMeshEntry.toLatin1().data() );
+      GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
+      aMeshEntry = ( aGeomVar->_is_nil() ) ? "" : aMeshEntry = aGeomVar->GetStudyEntry();
+    }
+
+    if ( aMeshEntry == "" && aGeomEntry == "" ) {
+      _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
+      GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
+      aGeomEntry = aGeomVar->GetStudyEntry();
+    }
+
+    if ( anObjEntry != "" && aGeomEntry != "" && aMeshEntry == "" ) { // take geometry from submesh
+      _PTR(SObject) pObj = studyDS()->FindObjectID( anObjEntry.toLatin1().data() );
+      if ( pObj ) {
+        // if current object is sub-mesh
+        SMESH::SMESH_subMesh_var aSubMeshVar =
+          SMESH::SMESH_subMesh::_narrow( _CAST( SObject,pObj )->GetObject() );
+        if ( !aSubMeshVar->_is_nil() ) {
+          SMESH::SMESH_Mesh_var aMeshVar =  aSubMeshVar->GetFather();
+          if ( !aMeshVar->_is_nil() ) {
+            _PTR(SObject) aMeshSO = SMESH::FindSObject( aMeshVar );
+            GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( aMeshSO );
+            aMeshEntry = aGeomVar->GetStudyEntry();
+          }
+        }
       }
     }
 
-    aCreator->setShapeEntry( anObjEntry );
+    aCreator->setShapeEntry( aGeomEntry );
+    if ( aMeshEntry != "" )
+      aCreator->setMainShapeEntry( aMeshEntry );
     removeCustomFilters(); // Issue 0020170
     myDlg->setEnabled( false );
     aCreator->edit( aHyp.in(), aHypItem.second, dlg(), this, SLOT( onHypoEdited( int ) ) );
index 93b3ca6..50906a0 100644 (file)
@@ -197,14 +197,16 @@ QFrame* StdMeshersGUI_NbSegmentsCreator::buildFrame()
   row++;
 
   // 8) reverce edge parameters
-  myReversedEdgesBox = new QGroupBox(tr( "SMESH_REVERCE_EDGES" ), fr);
+  myReversedEdgesBox = new QGroupBox(tr( "SMESH_REVERSED_EDGES" ), fr);
   QHBoxLayout* edgeLay = new QHBoxLayout( myReversedEdgesBox );
 
   myDirectionWidget = new StdMeshersGUI_SubShapeSelectorWdg();
-  QString anEntry = getShapeEntry();
-  if ( anEntry == "" )
-    anEntry = h->GetObjectEntry();
-  myDirectionWidget->SetMainShapeEntry( anEntry );
+  QString aGeomEntry = getShapeEntry();
+  QString aMainEntry = getMainShapeEntry();
+  if ( aGeomEntry == "" )
+    aGeomEntry = h->GetObjectEntry();
+  myDirectionWidget->SetGeomShapeEntry( aGeomEntry );
+  myDirectionWidget->SetMainShapeEntry( aMainEntry );
   myDirectionWidget->SetListOfIDs( h->GetReversedEdges() );
   edgeLay->addWidget( myDirectionWidget );
 
index 3523158..a377b80 100644 (file)
@@ -455,8 +455,7 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
       h->SetParameters(SMESHGUI::JoinObjectParameters(aVariablesList));
       if (w) {
         h->SetReversedEdges( w->GetListOfIDs() );
-        const char * entry = w->GetMainShapeEntry();
-        h->SetObjectEntry( entry );
+        h->SetObjectEntry( w->GetMainShapeEntry() );
       }
     }
     else if( hypType()=="FixedPoints1D" )
@@ -477,8 +476,7 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
       }
       if (w2) {
         h->SetReversedEdges( w2->GetListOfIDs() );
-        const char * entry = w2->GetMainShapeEntry();
-        h->SetObjectEntry( entry );
+        h->SetObjectEntry( w2->GetMainShapeEntry() );
       }
     }
     else if( hypType()=="MaxElementArea" )
@@ -606,8 +604,8 @@ QString StdMeshersGUI_StdHypothesisCreator::storeParams() const
       StdMeshersGUI_SubShapeSelectorWdg* w = 
         widget< StdMeshersGUI_SubShapeSelectorWdg >( 0 );
       if (w) {
-        if( w->GetListOfIDs()->length()>0 ) {
-          h->SetTriaVertex( w->GetListOfIDs()[0] );
+        if( int id = w->GetListOfIDs()[0] ) {
+          h->SetTriaVertex( id );
         }
         const char * entry = w->GetMainShapeEntry();
         h->SetObjectEntry( entry );
@@ -736,10 +734,13 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
 
     StdMeshersGUI_SubShapeSelectorWdg* aDirectionWidget =
       new StdMeshersGUI_SubShapeSelectorWdg();
-    QString anEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
-    if ( anEntry == "" )
-      anEntry = h->GetObjectEntry();
-    aDirectionWidget->SetMainShapeEntry( anEntry );
+    QString aGeomEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
+    QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
+    if ( aGeomEntry == "" )
+      aGeomEntry = h->GetObjectEntry();
+
+    aDirectionWidget->SetGeomShapeEntry( aGeomEntry );
+    aDirectionWidget->SetMainShapeEntry( aMainEntry );
     aDirectionWidget->SetListOfIDs( h->GetReversedEdges() );
     aDirectionWidget->showPreview( true );
     customWidgets()->append ( aDirectionWidget );
@@ -769,9 +770,11 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
     StdMeshersGUI_SubShapeSelectorWdg* aDirectionWidget =
       new StdMeshersGUI_SubShapeSelectorWdg();
     QString anEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
+    QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
     if ( anEntry == "" )
       anEntry = h->GetObjectEntry();
-    aDirectionWidget->SetMainShapeEntry( anEntry );
+    aDirectionWidget->SetGeomShapeEntry( anEntry );
+    aDirectionWidget->SetMainShapeEntry( aMainEntry );
     aDirectionWidget->SetListOfIDs( h->GetReversedEdges() );
     aDirectionWidget->showPreview( true );
     customWidgets()->append ( aDirectionWidget );
@@ -823,11 +826,12 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
     StdMeshersGUI_SubShapeSelectorWdg* aDirectionWidget =
       new StdMeshersGUI_SubShapeSelectorWdg();
     QString anEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
+    QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
     if ( anEntry == "" )
       anEntry = h->GetObjectEntry();
-    aDirectionWidget->SetMainShapeEntry( anEntry );
+    aDirectionWidget->SetGeomShapeEntry( anEntry );
+    aDirectionWidget->SetMainShapeEntry( aMainEntry );
     aDirectionWidget->SetListOfIDs( h->GetReversedEdges() );
-    aDirectionWidget->SetMainShapeEntry( h->GetObjectEntry() );
     aDirectionWidget->showPreview( true );
     customWidgets()->append ( aDirectionWidget );
   }
@@ -984,9 +988,11 @@ bool StdMeshersGUI_StdHypothesisCreator::stdParams( ListOfStdParams& p ) const
     aDirectionWidget->SetMaxSize(1);
     aDirectionWidget->SetSubShType(TopAbs_VERTEX);
     QString anEntry = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
+    QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
     if ( anEntry == "" )
       anEntry = h->GetObjectEntry();
-    aDirectionWidget->SetMainShapeEntry( anEntry );
+    aDirectionWidget->SetGeomShapeEntry( anEntry );
+    aDirectionWidget->SetMainShapeEntry( aMainEntry );
     SMESH::long_array_var aVec = new SMESH::long_array;
     int vertID = h->GetTriaVertex();
     if(vertID>0) {
index 0d0a79c..0705f57 100644 (file)
@@ -23,6 +23,7 @@
 // Author : Open CASCADE S.A.S. (dmv)
 // SMESH includes
 //
+
 #include "StdMeshersGUI_SubShapeSelectorWdg.h"
 
 // SMESH Includes
@@ -141,6 +142,7 @@ StdMeshersGUI_SubShapeSelectorWdg::~StdMeshersGUI_SubShapeSelectorWdg()
 void StdMeshersGUI_SubShapeSelectorWdg::init()
 {
   myParamValue = "";
+  myIsNotCorrected = true; // to dont call the GetCorrectedValue method twice
   myListOfIDs.clear();
   mySelectedIDs.clear();
 
@@ -334,13 +336,14 @@ void StdMeshersGUI_SubShapeSelectorWdg::onListSelectionChanged()
 // function : setGeomShape
 // purpose  : Called to set geometry
 //================================================================================
-void StdMeshersGUI_SubShapeSelectorWdg::SetMainShapeEntry( const QString& theEntry )
+void StdMeshersGUI_SubShapeSelectorWdg::SetGeomShapeEntry( const QString& theEntry )
 {
   if ( theEntry != "") {
     myParamValue = theEntry;
     myEntry = theEntry;
-    myMainShape = GetTopoDSByEntry( theEntry );
+    myGeomShape = GetTopoDSByEntry( theEntry );
     updateState();
+    myIsNotCorrected = true;
   }
 }
 
@@ -351,7 +354,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::SetMainShapeEntry( const QString& theEnt
 void StdMeshersGUI_SubShapeSelectorWdg::updateState()
 {
   bool state = false;
-  if ( !myMainShape.IsNull() )
+  if ( !myGeomShape.IsNull() )
     state = true;
   
   myListWidget->setEnabled( state );
@@ -361,8 +364,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::updateState()
   if (state) {
     myPreviewActor = new SMESH_PreviewActorsCollection();
     myPreviewActor->SetSelector( mySelector );
-    //myPreviewActor->Init( myMainShape, TopAbs_EDGE, myEntry );
-    myPreviewActor->Init( myMainShape, mySubShType, myEntry );
+    myPreviewActor->Init( myGeomShape, mySubShType, myEntry );
     myPreviewActor->SetShown( false );
     myIsShown = false;
     if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) {
@@ -414,6 +416,10 @@ TopoDS_Shape StdMeshersGUI_SubShapeSelectorWdg::GetTopoDSByEntry( const QString&
 SMESH::long_array_var StdMeshersGUI_SubShapeSelectorWdg::GetListOfIDs()
 {
   SMESH::long_array_var anArray = new SMESH::long_array;
+
+  if ( myMainEntry != "" && myIsNotCorrected )
+    myListOfIDs = GetCorrectedListOfIDs( true );
+
   int size = myListOfIDs.size();
   anArray->length( size );
   if ( size ) {
@@ -435,6 +441,65 @@ void StdMeshersGUI_SubShapeSelectorWdg::SetListOfIDs( SMESH::long_array_var theI
   int size = theIds->length();
   for ( int i = 0; i < size; i++ )
     mySelectedIDs.append( theIds[ i ] );
+
+  mySelectedIDs = GetCorrectedListOfIDs( false );
   onAdd();
 }
 
+//=================================================================================
+// function : SetMainShapeEntry
+// purpose  : Called to set the Main Object Entry
+//=================================================================================
+void StdMeshersGUI_SubShapeSelectorWdg::SetMainShapeEntry( const QString& theEntry )
+{
+  myMainEntry = theEntry;
+  myMainShape = GetTopoDSByEntry( theEntry );
+  myIsNotCorrected = true;
+}
+
+//=================================================================================
+// function : GetMainShapeEntry
+// purpose  : Called to get the Main Object Entry
+//=================================================================================
+const char* StdMeshersGUI_SubShapeSelectorWdg::GetMainShapeEntry()
+{
+  if ( myMainEntry == "")
+    return myEntry.toLatin1().data();
+
+  return myMainEntry.toLatin1().data();
+}
+
+//=================================================================================
+// function : GetCorrectedListOfIds
+// purpose  : Called to convert the list of IDs from subshape IDs to main shape IDs
+//=================================================================================
+QList<int> StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs( bool fromSubshapeToMainshape )
+{
+  if ( myMainShape.IsNull() || myGeomShape.IsNull() )
+    return myListOfIDs;
+
+  QList<int> aList;
+  TopTools_IndexedMapOfShape   aGeomMap;
+  TopTools_IndexedMapOfShape   aMainMap;
+  TopExp::MapShapes(myGeomShape, aGeomMap);
+  TopExp::MapShapes(myMainShape, aMainMap);
+
+  if ( fromSubshapeToMainshape ) { // convert indexes from subshape to mainshape
+    int size = myListOfIDs.size();
+    for (int i = 0; i < size; i++) {
+      TopoDS_Shape aSubShape = aGeomMap.FindKey( myListOfIDs.at(i) );
+      int index = aMainMap.FindIndex( aSubShape );
+      aList.append( index );
+    }
+    myIsNotCorrected = false;
+  } else { // convert indexes from main shape to subshape
+    int size = mySelectedIDs.size();
+    for (int i = 0; i < size; i++) {
+      TopoDS_Shape aSubShape = aMainMap.FindKey( mySelectedIDs.at(i) );
+      int index = aGeomMap.FindIndex( aSubShape );
+      aList.append( index );
+    }
+  }
+
+  return aList;
+}
index 6447516..48f4bc8 100644 (file)
@@ -59,11 +59,17 @@ public:
   SMESH::long_array_var          GetListOfIDs();
   void                           SetListOfIDs( SMESH::long_array_var );
 
+  void                           SetGeomShapeEntry( const QString& theEntry );
+  const char*                    GetGeomShapeEntry() { return myEntry.toLatin1().data();}
+
   void                           SetMainShapeEntry( const QString& theEntry );
-  const char*                    GetMainShapeEntry() { return myEntry.toLatin1().data();}
+  const char*                    GetMainShapeEntry();
 
+  TopoDS_Shape                   GetGeomShape() { return myGeomShape; }
   TopoDS_Shape                   GetMainShape() { return myMainShape; }
 
+  QList<int>                     GetCorrectedListOfIDs( bool fromSubshapeToMainshape = true );
+
   static GEOM::GEOM_Object_var   GetGeomObjectByEntry( const QString& );
   static TopoDS_Shape            GetTopoDSByEntry( const QString& );
 
@@ -91,8 +97,10 @@ private:
   LightApp_SelectionMgr*         mySelectionMgr;          /* User shape selection */
   SVTK_Selector*                 mySelector;
   SMESH::SMESH_Mesh_var          myMesh;
+  TopoDS_Shape                   myGeomShape;
   TopoDS_Shape                   myMainShape;
   QString                        myEntry;
+  QString                        myMainEntry;
   vtkRenderer*                   myRenderer;
   
   QListWidget*                   myListWidget;
@@ -103,6 +111,7 @@ private:
   
   QString                        myParamValue;
   bool                           myIsShown;
+  bool                           myIsNotCorrected;
 
   // for manage possible size of myListOfIDs
   int                            myMaxSize;