Salome HOME
bc76f7931c45a5ce0c5a66077f69801e11618093
[modules/geom.git] / src / RepairGUI / RepairGUI.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : RepairGUI.cxx
23 //  Author : Damien COQUERET, Open CASCADE S.A.S.
24
25 #include "RepairGUI.h"
26
27 #include <GeometryGUI.h>
28 #include "GeometryGUI_Operations.h"
29
30 #include <SUIT_Desktop.h>
31 #include <SUIT_Session.h>
32 #include <SUIT_OverrideCursor.h>
33 #include <SalomeApp_Application.h>
34
35 #include "RepairGUI_SewingDlg.h"        // Method SEWING
36 #include "RepairGUI_SuppressFacesDlg.h" // Method SUPPRESS FACES
37 #include "RepairGUI_RemoveHolesDlg.h"   // Method SUPPRESS HOLE
38 #include "RepairGUI_ShapeProcessDlg.h"  // Method PROCESS SHAPE
39 #include "RepairGUI_CloseContourDlg.h"  // Method CLOSE CONTOUR
40 #include "RepairGUI_RemoveIntWiresDlg.h"// Method REMOVE INTERNAL WIRES
41 #include "RepairGUI_DivideEdgeDlg.h"    // Method DIVIDE EDGE
42 #include "RepairGUI_FreeBoundDlg.h"     // Method FREE BOUNDARIES
43 #include "RepairGUI_FreeFacesDlg.h"     // Method FREE FACES
44 #include "RepairGUI_GlueDlg.h"          // Method GLUE FACES
45 #include "RepairGUI_LimitToleranceDlg.h"    // Method LIMIT TOLERANCE
46 #include "RepairGUI_ChangeOrientationDlg.h" // Method CHANGE ORIENTATION
47 #include "RepairGUI_RemoveWebsDlg.h"        // Method REMOVE INTERNAL FACES
48 #include "RepairGUI_RemoveExtraEdgesDlg.h"  // Method REMOVE EXTRA EDGES
49 #include "RepairGUI_FuseEdgesDlg.h"         // Method FUSE COLLINEAR EDGES
50 #include "RepairGUI_UnionFacesDlg.h"        // Method UNION FACES
51 #include "RepairGUI_InspectObjectDlg.h"     // Method INSPECT OBJECT
52
53 //=======================================================================
54 // function : RepairGUI()
55 // purpose  : Constructor
56 //=======================================================================
57 RepairGUI::RepairGUI( GeometryGUI* parent )
58   : GEOMGUI( parent )
59 {
60 }
61
62 //=======================================================================
63 // function : ~RepairGUI()
64 // purpose  : Destructor
65 //=======================================================================
66 RepairGUI::~RepairGUI()
67 {
68 }
69
70
71 //=======================================================================
72 // function : OnGUIEvent()
73 // purpose  :
74 //=======================================================================
75 bool RepairGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
76 {
77   SalomeApp_Application* app = getGeometryGUI()->getApp();
78   if ( !app ) return false;
79
80   getGeometryGUI()->EmitSignalDeactivateDialog();
81
82   QDialog* aDlg = NULL;
83   switch (theCommandID) {
84   case GEOMOp::OpSewing:           aDlg = new RepairGUI_SewingDlg            (getGeometryGUI(), parent); break;
85   case GEOMOp::OpGlueFaces: aDlg = new RepairGUI_GlueDlg (getGeometryGUI(), parent, false, TopAbs_FACE); break;
86   case GEOMOp::OpGlueEdges: aDlg = new RepairGUI_GlueDlg (getGeometryGUI(), parent, false, TopAbs_EDGE); break;
87   case GEOMOp::OpLimitTolerance:   aDlg = new RepairGUI_LimitToleranceDlg    (getGeometryGUI(), parent); break;
88   case GEOMOp::OpSuppressFaces:    aDlg = new RepairGUI_SuppressFacesDlg     (getGeometryGUI(), parent); break;
89   case GEOMOp::OpSuppressHoles:    aDlg = new RepairGUI_RemoveHolesDlg       (getGeometryGUI(), parent); break;
90   case GEOMOp::OpShapeProcess:     aDlg = new RepairGUI_ShapeProcessDlg      (getGeometryGUI(), parent); break;
91   case GEOMOp::OpCloseContour:     aDlg = new RepairGUI_CloseContourDlg      (getGeometryGUI(), parent); break;
92   case GEOMOp::OpRemoveIntWires:   aDlg = new RepairGUI_RemoveIntWiresDlg    (getGeometryGUI(), parent); break;
93   case GEOMOp::OpAddPointOnEdge:   aDlg = new RepairGUI_DivideEdgeDlg        (getGeometryGUI(), parent); break;
94   case GEOMOp::OpFreeBoundaries:   aDlg = new RepairGUI_FreeBoundDlg         (getGeometryGUI(), parent); break;
95   case GEOMOp::OpFreeFaces:        aDlg = new RepairGUI_FreeFacesDlg         (getGeometryGUI(), parent); break;
96   case GEOMOp::OpOrientation:      aDlg = new RepairGUI_ChangeOrientationDlg (getGeometryGUI(), parent); break;
97   case GEOMOp::OpRemoveWebs:       aDlg = new RepairGUI_RemoveWebsDlg        (getGeometryGUI(), parent); break;
98   case GEOMOp::OpRemoveExtraEdges: aDlg = new RepairGUI_RemoveExtraEdgesDlg  (getGeometryGUI(), parent); break;
99   case GEOMOp::OpFuseEdges:        aDlg = new RepairGUI_FuseEdgesDlg         (getGeometryGUI(), parent); break;
100   case GEOMOp::OpUnionFaces:       aDlg = new RepairGUI_UnionFacesDlg        (getGeometryGUI(), parent); break;
101   case GEOMOp::OpInspectObj:       aDlg = new RepairGUI_InspectObjectDlg     (getGeometryGUI(), parent); break;
102   default:
103     app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
104     break;
105   }
106
107   if (aDlg)
108     aDlg->show();
109
110   return true;
111 }
112
113
114 //=====================================================================================
115 // EXPORTED METHODS
116 //=====================================================================================
117 extern "C"
118 {
119 #ifdef WIN32
120   __declspec( dllexport )
121 #endif
122   GEOMGUI* GetLibGUI( GeometryGUI* parent )
123   {
124     return new RepairGUI( parent );
125   }
126 }
127
128 //=====================================================================================
129 // Statistics dialog
130 //=====================================================================================
131
132 #include <QDialog>
133 #include <QHBoxLayout>
134 #include <QHeaderView>
135 #include <QPushButton>
136 #include <QString>
137 #include <QStringList>
138 #include <QTableWidget>
139 #include <QTableWidget>
140 #include <QTableWidgetItem>
141 #include <QVBoxLayout>
142
143 namespace
144 {
145   class StatsDlg : public QDialog
146   {
147   public:
148     StatsDlg( GEOM::ModifStatistics_var stats, QWidget* parent );
149   };
150
151   StatsDlg::StatsDlg( GEOM::ModifStatistics_var stats, QWidget* parent ): QDialog( parent )
152   {
153     setModal( true );
154     setWindowTitle( tr( "GEOM_HEALING_STATS_TITLE" ) );
155     setMinimumWidth( 500 );
156
157     const int nbRows = stats->length();
158     const int nbCols = 2;
159     QTableWidget* table = new QTableWidget( nbRows, nbCols, this );
160     table->setEditTriggers( QAbstractItemView::NoEditTriggers );
161     table->horizontalHeader()->setSectionResizeMode( 1, QHeaderView::Interactive );
162
163     table->horizontalHeader()->setStretchLastSection( true );
164
165     QStringList headers;
166     headers << tr( "GEOM_HEALING_STATS_COL_1" );
167     headers << tr( "GEOM_HEALING_STATS_COL_2" );
168     table->setHorizontalHeaderLabels( headers );
169
170     // buttons
171
172     QPushButton* okBtn = new QPushButton( tr( "GEOM_BUT_OK" ), this );
173     okBtn->setAutoDefault( true );
174     okBtn->setDefault( true );
175     okBtn->setFocus();
176     // QPushButton* helpBtn = new QPushButton( tr( "GEOM_BUT_HELP" ), this );
177     // helpBtn->setAutoDefault( true );
178
179     QHBoxLayout* btnLayout = new QHBoxLayout;
180     btnLayout->setMargin( 0 );
181     btnLayout->setSpacing( 6 );
182
183     btnLayout->addStretch();
184     btnLayout->addWidget( okBtn );
185     btnLayout->addStretch();
186     // btnLayout->addWidget( helpBtn );
187
188     QVBoxLayout* aLay = new QVBoxLayout( this );
189     aLay->setMargin( 9 );
190     aLay->setSpacing( 6 );
191     aLay->addWidget( table );
192     aLay->addLayout( btnLayout );
193
194     // fill the table
195     for ( int row = 0; row < nbRows; ++row )
196     {
197       table->setItem( row, 0, new QTableWidgetItem( QString::number( stats[ row ].count )));
198       table->setItem( row, 1, new QTableWidgetItem( tr( stats[ row ].name.in() )));
199     }
200
201     connect( okBtn,       SIGNAL( clicked() ), this, SLOT( reject() ));
202     //connect( helpBtn,     SIGNAL( clicked() ), this, SLOT( help() ));
203   }
204 }
205
206 //================================================================================
207 /*!
208  * \brief Show a dialog providing info on what is done by healing
209  */
210 //================================================================================
211
212 void RepairGUI::ShowStatistics( GEOM::GEOM_IHealingOperations_var anOper, QWidget* parent )
213 {
214   GEOM::ModifStatistics_var stats = anOper->GetStatistics();
215
216   if ( ! &stats.in() || stats->length() == 0 )
217     return;
218
219   SUIT_OverrideCursor wc;
220   wc.suspend();
221
222   StatsDlg dlg( stats, parent );
223   dlg.exec();
224 }