Salome HOME
Updated copyright comment
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI_DocumentPanel.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 0c4db33..03f5357
@@ -1,9 +1,9 @@
-// Copyright (C) 2009-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2009-2024  CEA, EDF
 //
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #include "Hex.hxx"
 #include <iostream>
-#include <QtGui>
 #include <QFlags>
+#include <QKeyEvent>
+#include <QStyledItemDelegate>
 
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
+#ifndef DISABLE_PYCONSOLE
 #include <PyConsole_Console.h>
+#endif
 #include <SalomeApp_Tools.h>
 
 #include <Standard_GUID.hxx>
@@ -59,6 +62,8 @@
 
 #include <GEOMBase.h>
 
+#include <utilities.h>
+
 #define BUTTON_BOX_MIN_WIDTH 5
 #define VERTEX_COORD_MIN -1000000
 #define VERTEX_COORD_MAX  1000000
@@ -792,10 +797,13 @@ void HexaBaseDialog::onSelectionChanged( const QItemSelection& sel, const QItemS
 // ============================================================== showEvent
 void HexaBaseDialog::showEvent( QShowEvent * event )
 {
-    if ( _editMode == INFO_MODE )
-        getDocumentModel()->allowEdition();
-    else
-        getDocumentModel()->disallowEdition();
+    // Do not disallow edition, otherwise we can't expand group items
+    // (e.g. vertices) when creating an item (e.g. a vertex or an edge).
+    // Hence, no need to allow edition in info mode.
+    //if ( _editMode == INFO_MODE )
+    //    getDocumentModel()->allowEdition();
+    //else
+    //    getDocumentModel()->disallowEdition();
 
     //Connect to salome selection signals
     if (HEXABLOCKGUI::selectionMgr() != NULL)
@@ -1789,9 +1797,9 @@ bool HexaDialog::apply(QModelIndex& result)
     }
 
     nbItems = iElts.count();
-    if ( quads_rb->isChecked() and (nbItems>=2 and nbItems<=6) ){ // build from quads iElts.count() should be between [2,6]
+    if ( quads_rb->isChecked() && (nbItems>=2 && nbItems<=6) ){ // build from quads iElts.count() should be between [2,6]
         iHexa = getDocumentModel()->addHexaQuads( iElts );
-    } else if ( vertices_rb->isChecked() and nbItems== 8 ){ // build from vertices
+    } else if ( vertices_rb->isChecked() && nbItems== 8 ){ // build from vertices
         iHexa = getDocumentModel()->addHexaVertices( iElts[0], iElts[1], iElts[2], iElts[3],
                 iElts[4], iElts[5], iElts[6], iElts[7] );
     }
@@ -3433,10 +3441,10 @@ bool JoinQuadDialog::apply(QModelIndex& result)
             iquads << iquad;
     }
     QModelIndex iquaddest = patternDataModel->mapToSource( _index[quad_dest_le] );
-    QModelIndex ivex0 = patternDataModel->mapToSource( _index[vex0_le] );
-    QModelIndex ivex1 = patternDataModel->mapToSource( _index[vex1_le] );
-    QModelIndex ivex2 = patternDataModel->mapToSource( _index[vex2_le] );
-    QModelIndex ivex3 = patternDataModel->mapToSource( _index[vex3_le] );
+    QModelIndex ivex0 = patternDataModel->mapToSource( _index[vex0_le] ); // from point a
+    QModelIndex ivex1 = patternDataModel->mapToSource( _index[vex1_le] ); // from point b
+    QModelIndex ivex2 = patternDataModel->mapToSource( _index[vex2_le] ); // to point a
+    QModelIndex ivex3 = patternDataModel->mapToSource( _index[vex3_le] ); // to point b
     double nb = nb_spb->value();
 
     vector<double> heights;
@@ -5874,6 +5882,7 @@ bool ComputeMeshDialog::apply(QModelIndex& result)
     _currentObj = NULL;
 
     if (getDocumentModel() == NULL) return false;
+#ifndef DISABLE_PYCONSOLE
     QString command = QString("import hexablock ; %1 = hexablock.mesh(\"%2\", \"%1\", %3, \"%4\")")
                                                                                                          .arg( _name->text() )
                                                                                                          .arg( getDocumentModel()->getName() )
@@ -5887,6 +5896,9 @@ bool ComputeMeshDialog::apply(QModelIndex& result)
         pyConsole->exec( command );
     else
         return false;
+#else
+    return false;
+#endif
 
     return true;
 }
@@ -5899,8 +5911,6 @@ HexaBaseDialog(parent, editmode, f)
     _helpFileName = "gui_replace_hexa.html";
     setupUi( this );
     _initWidget(editmode);
-
-    radioButton->click();
 }
 
 // ============================================================== Destructeur
@@ -5928,16 +5938,13 @@ QModelIndexList ReplaceHexaDialog::getAssocsVTK()
             assocs << iQuad;
     }
 
-    if (radioButton_2->isChecked())
+    nbQuads = quads_lw_2->count();
+    for( int i = 0; i < nbQuads; ++i)
     {
-        nbQuads = quads_lw_2->count();
-        for( int i = 0; i < nbQuads; ++i)
-        {
-            item = quads_lw_2->item(i);
-            iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
-            if (iQuad.isValid())
-                assocs << iQuad;
-        }
+        item = quads_lw_2->item(i);
+        iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
+        if (iQuad.isValid())
+            assocs << iQuad;
     }
 
     return assocs;
@@ -5952,19 +5959,15 @@ void ReplaceHexaDialog::_initInputWidget( Mode editmode )
 
     c1_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
     c2_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
-    c3_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
 
     p1_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
     p2_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
-    p3_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
 
     c1_le->installEventFilter(this);
     c2_le->installEventFilter(this);
-    c3_le->installEventFilter(this);
 
     p1_le->installEventFilter(this);
     p2_le->installEventFilter(this);
-    p3_le->installEventFilter(this);
 
     quads_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
     quads_lw->installEventFilter(this);
@@ -5985,11 +5988,9 @@ void ReplaceHexaDialog::_initInputWidget( Mode editmode )
 
     c1_le->setReadOnly(true);
     c2_le->setReadOnly(true);
-    c3_le->setReadOnly(true);
 
     p1_le->setReadOnly(true);
     p2_le->setReadOnly(true);
-    p3_le->setReadOnly(true);
 
     connect(quads_lw,    SIGNAL(itemSelectionChanged()),
             this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
@@ -6004,24 +6005,21 @@ void ReplaceHexaDialog::clear()
     quads_lw->clear();
     modelUnregister(quads_lw);
 
+    quads_lw_2->clear();
+    modelUnregister(quads_lw_2);
+
     p1_le->clear();
     modelUnregister(p1_le);
 
     p2_le->clear();
     modelUnregister(p2_le);
 
-    p3_le->clear();
-    modelUnregister(p3_le);
-
     c1_le->clear();
     modelUnregister(c1_le);
 
     c2_le->clear();
     modelUnregister(c2_le);
 
-    c3_le->clear();
-    modelUnregister(c3_le);
-
     modelUnregister(this);
 }
 
@@ -6075,43 +6073,30 @@ bool ReplaceHexaDialog::apply(QModelIndex& result)
             iquads_source << iquad;
     }
 
+    QModelIndexList iquads_dest;
+    nbQuads = quads_lw_2->count();
+    for (int i = 0; i < nbQuads; ++i)
+    {
+        item = quads_lw_2->item(i);
+        iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
+        if (iquad.isValid())
+            iquads_dest << iquad;
+    }
+
     QModelIndex ip1_source = patternDataModel->mapToSource( _index[p1_le] );
     QModelIndex ip2_source = patternDataModel->mapToSource( _index[p2_le] );
-    QModelIndex ip3_source = patternDataModel->mapToSource( _index[p3_le] );
 
     QModelIndex ic1_dest = patternDataModel->mapToSource( _index[c1_le] );
     QModelIndex ic2_dest = patternDataModel->mapToSource( _index[c2_le] );
-    QModelIndex ic3_dest = patternDataModel->mapToSource( _index[c3_le] );
 
-    bool ipts_ok = ip1_source.isValid() && ip2_source.isValid() && ip3_source.isValid() &&
-                      ic1_dest.isValid() && ic2_dest.isValid() && ic3_dest.isValid();
+    bool ipts_ok = ip1_source.isValid() && ip2_source.isValid() &&
+                      ic1_dest.isValid() && ic2_dest.isValid();
 
     if (ipts_ok)
     {
-        if (radioButton->isChecked())
-        {
-            ielts = getDocumentModel()->replace( iquads_source,
-                                                 ip1_source, ic1_dest,
-                                                 ip2_source, ic2_dest,
-                                                 ip3_source, ic3_dest );
-        }
-        else if (radioButton_2->isChecked())
-        {
-            QModelIndexList iquads_dest;
-            nbQuads = quads_lw_2->count();
-            for (int i = 0; i < nbQuads; ++i)
-            {
-                item = quads_lw_2->item(i);
-                iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
-                if (iquad.isValid())
-                    iquads_dest << iquad;
-            }
-
             ielts = getDocumentModel()->replace( iquads_source, iquads_dest,
                                                  ip1_source, ic1_dest,
-                                                 ip2_source, ic2_dest,
-                                                 ip3_source, ic3_dest);
-        }
+                                                 ip2_source, ic2_dest );
     }
 
     if ( !ielts.isValid() ){
@@ -6783,7 +6768,7 @@ void ModelInfoDialog::hideEvent ( QHideEvent * event )
 AddShapeDialog::AddShapeDialog(QWidget* parent, Mode editmode, Qt::WindowFlags wf):
                  HexaBaseDialog(parent, editmode, wf)
 {
-    _helpFileName = "";
+    _helpFileName = "gui_add_geometry.html#guiaddgeometry";
     setupUi( this );
     _initWidget(editmode);
     setWindowTitle(HEXABLOCKGUI::tr("ADD_SHAPE"));