Salome HOME
Merge from BR_Dev_For_4_0 branch (from tag mergeto_BR_QT4_Dev_17Jan08)
[modules/geom.git] / src / RepairGUI / RepairGUI_RemoveExtraEdgesDlg.cxx
1 // GEOM GEOMGUI : GUI for Geometry component
2 // 
3 // This library is distributed in the hope that it will be useful, 
4 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
5 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
6 // Lesser General Public License for more details. 
7 // 
8 // You should have received a copy of the GNU Lesser General Public 
9 // License along with this library; if not, write to the Free Software 
10 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
11 // 
12 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
13 //
14 //  File   : RepairGUI_RemoveExtraEdgesDlg.cxx
15 //  Author : Michael Zorin, Open CASCADE S.A.S.
16 //
17
18 #include "RepairGUI_RemoveExtraEdgesDlg.h"
19
20 #include <DlgRef.h>
21 #include <GeometryGUI.h>
22 #include <GEOMBase.h>
23
24 #include <SalomeApp_Application.h>
25 #include <LightApp_SelectionMgr.h>
26 #include <SUIT_Session.h>
27 #include <SUIT_ResourceMgr.h>
28
29 #include <GEOMImpl_Types.hxx>
30
31 #include <TColStd_MapOfInteger.hxx>
32
33 //=================================================================================
34 // class    : RepairGUI_RemoveExtraEdgesDlg()
35 // purpose  : Constructs a RepairGUI_RemoveExtraEdgesDlg which is a child of 'parent', with the
36 //            name 'name' and widget flags set to 'f'.
37 //            The dialog will by default be modeless, unless you set 'modal' to
38 //            TRUE to construct a modal dialog.
39 //=================================================================================
40 RepairGUI_RemoveExtraEdgesDlg::RepairGUI_RemoveExtraEdgesDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
41                                                               bool modal )
42   : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
43 {
44   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_REMOVE_EXTRA_EDGES" ) ) );
45   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
46     
47   setWindowTitle( tr( "GEOM_REMOVE_EXTRA_EDGES_TITLE" ) );
48
49   /***************************************************************/
50   mainFrame()->GroupConstructors->setTitle(tr("GEOM_REMOVE_EXTRA_EDGES_TITLE"));
51   mainFrame()->RadioButton1->setIcon( image0 );
52   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
53   mainFrame()->RadioButton2->close();
54   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
55   mainFrame()->RadioButton3->close();
56
57   GroupPoints = new DlgRef_1Sel( centralWidget() );
58   GroupPoints->GroupBox1->setTitle( tr( "GEOM_REMOVE_EXTRA_EDGES" ) );
59   GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
60   GroupPoints->PushButton1->setIcon( image1 );
61   GroupPoints->LineEdit1->setReadOnly( true );
62
63   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
64   layout->setMargin( 0 ); layout->setSpacing( 6 );
65   layout->addWidget( GroupPoints );
66
67   /***************************************************************/
68   
69   setHelpFileName( "remove_extra_edges_operation_page.html" );
70
71   Init();
72 }
73
74
75 //=================================================================================
76 // function : ~RepairGUI_RemoveExtraEdgesDlg()
77 // purpose  : Destroys the object and frees any allocated resources
78 //=================================================================================
79 RepairGUI_RemoveExtraEdgesDlg::~RepairGUI_RemoveExtraEdgesDlg()
80 {
81 }
82
83
84 //=================================================================================
85 // function : Init()
86 // purpose  :
87 //=================================================================================
88 void RepairGUI_RemoveExtraEdgesDlg::Init()
89 {
90   /* init variables */
91   myEditCurrentArgument = GroupPoints->LineEdit1;
92   
93   myOkObject = false;
94
95   activateSelection();
96   
97   /* signals and slots connections */
98   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
99   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
100
101   connect( GroupPoints->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
102   connect( GroupPoints->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
103
104   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
105            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
106
107   initName( tr( "REMOVE_EXTRA_EDGES_NEW_OBJ_NAME" ) );
108 }
109
110
111 //=================================================================================
112 // function : ClickOnOk()
113 // purpose  : Same than click on apply but close this dialog.
114 //=================================================================================
115 void RepairGUI_RemoveExtraEdgesDlg::ClickOnOk()
116 {
117   if ( ClickOnApply() )
118     ClickOnCancel();
119 }
120
121 //=================================================================================
122 // function : ClickOnApply()
123 // purpose  :
124 //=================================================================================
125 bool RepairGUI_RemoveExtraEdgesDlg::ClickOnApply()
126 {
127   if ( !onAccept() )
128     return false;
129
130   initName();
131
132   myEditCurrentArgument->setText( "" );
133   myObject = GEOM::GEOM_Object::_nil();
134   
135   activateSelection();
136
137   return true;
138 }
139
140
141 //=================================================================================
142 // function : SelectionIntoArgument()
143 // purpose  : Called when selection as changed or other case
144 //          : used only by SelectButtonC1A1 (LineEditC1A1)
145 //=================================================================================
146 void RepairGUI_RemoveExtraEdgesDlg::SelectionIntoArgument()
147 {
148   myEditCurrentArgument->setText( "" );
149   QString aName;
150   
151   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
152     if ( IObjectCount() != 1 ) {
153       if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
154         myOkObject = false;
155       return;
156     }
157   }
158   
159   // nbSel == 1
160   Standard_Boolean testResult = Standard_False;
161   GEOM::GEOM_Object_ptr aSelectedObject =
162     GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
163
164   if ( !testResult )
165     return;
166   
167   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
168     myObject = aSelectedObject;
169     myOkObject = true;
170   }
171
172   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
173 }
174
175 //=================================================================================
176 // function : SetEditCurrentArgument()
177 // purpose  :
178 //=================================================================================
179 void RepairGUI_RemoveExtraEdgesDlg::SetEditCurrentArgument()
180 {
181   if( sender() == GroupPoints->PushButton1 ) {
182     GroupPoints->LineEdit1->setFocus();
183     myEditCurrentArgument = GroupPoints->LineEdit1;
184   }
185   SelectionIntoArgument();
186 }
187
188
189 //=================================================================================
190 // function : LineEditReturnPressed()
191 // purpose  :
192 //=================================================================================
193 void RepairGUI_RemoveExtraEdgesDlg::LineEditReturnPressed()
194 {
195   if ( sender() == GroupPoints->LineEdit1 ) {
196     myEditCurrentArgument = GroupPoints->LineEdit1;
197     GEOMBase_Skeleton::LineEditReturnPressed();
198   }
199 }
200
201
202 //=================================================================================
203 // function : ActivateThisDialog()
204 // purpose  :
205 //=================================================================================
206 void RepairGUI_RemoveExtraEdgesDlg::ActivateThisDialog()
207 {
208   GEOMBase_Skeleton::ActivateThisDialog();
209   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
210            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
211
212   activateSelection();
213 }
214
215
216 //=================================================================================
217 // function : enterEvent()
218 // purpose  : Mouse enter onto the dialog to activate it
219 //=================================================================================
220 void RepairGUI_RemoveExtraEdgesDlg::enterEvent(QEvent* e)
221 {
222   if ( !mainFrame()->GroupConstructors->isEnabled() )
223     ActivateThisDialog();
224 }
225
226
227 //=================================================================================
228 // function : activateSelection
229 // purpose  : activate selection of solids and compounds
230 //=================================================================================
231 void RepairGUI_RemoveExtraEdgesDlg::activateSelection()
232 {
233   TColStd_MapOfInteger aTypes;
234   aTypes.Add( GEOM_SOLID );
235   aTypes.Add( GEOM_COMPOUND );
236   globalSelection( aTypes );
237 }
238
239 //=================================================================================
240 // function : createOperation
241 // purpose  :
242 //=================================================================================
243 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveExtraEdgesDlg::createOperation()
244 {
245   return getGeomEngine()->GetIBlocksOperations( getStudyId() );
246 }
247
248 //=================================================================================
249 // function : isValid
250 // purpose  :
251 //=================================================================================
252 bool RepairGUI_RemoveExtraEdgesDlg::isValid( QString& msg )
253 {
254   return myOkObject;
255 }
256
257 //=================================================================================
258 // function : execute
259 // purpose  :
260 //=================================================================================
261 bool RepairGUI_RemoveExtraEdgesDlg::execute( ObjectList& objects )
262 {
263   GEOM::GEOM_Object_var anObj;
264   
265   anObj = GEOM::GEOM_IBlocksOperations::_narrow( getOperation() )->RemoveExtraEdges( myObject );
266   
267   if ( !anObj->_is_nil() )
268     objects.push_back( anObj._retn() );
269
270   return true;
271 }