Salome HOME
Using files from package LightApp instead of SalomeApp
[modules/geom.git] / src / BooleanGUI / BooleanGUI_Dialog.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  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. 
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : BooleanGUI_Dialog.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "BooleanGUI_Dialog.h"
30 #include "BooleanGUI.h"
31 #include "DlgRef_2Sel_QTD.h"
32
33 #include "SUIT_Session.h"
34 #include "SalomeApp_Application.h"
35 #include "LightApp_SelectionMgr.h"
36
37 #include <qlabel.h>
38
39 using namespace std;
40
41 //=================================================================================
42 // class    : BooleanGUI_Dialog()
43 // purpose  : Constructs a BooleanGUI_Dialog which is a child of 'parent', with the
44 //            name 'name' and widget flags set to 'f'.
45 //            The dialog will by default be modeless, unless you set 'modal' to
46 //            TRUE to construct a modal dialog.
47 //=================================================================================
48 BooleanGUI_Dialog::BooleanGUI_Dialog( const int theOperation, QWidget* parent, const char* name, bool modal, WFlags fl)
49   :GEOMBase_Skeleton(parent, name, modal, fl),
50    myOperation( theOperation )
51 {
52   QPixmap image0;
53   QString aTitle, aCaption;
54   switch ( myOperation )
55   {
56         case BooleanGUI::COMMON:
57           image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_COMMON")));
58                         aTitle = tr("GEOM_COMMON");
59                         aCaption = tr("GEOM_COMMON_TITLE");
60                         break;
61                 case BooleanGUI::CUT:
62           image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CUT")));
63                         aTitle = tr("GEOM_CUT");
64                         aCaption = tr("GEOM_CUT_TITLE");
65                         break;
66                 case BooleanGUI::FUSE:
67           image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_FUSE")));
68                         aTitle = tr("GEOM_FUSE");
69                         aCaption = tr("GEOM_FUSE_TITLE");
70                         break;
71                 case BooleanGUI::SECTION:
72           image0 = QPixmap( SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SECTION")));
73                         aTitle = tr("GEOM_SECTION");
74                         aCaption = tr("GEOM_SECTION_TITLE");
75                         break;
76         }
77   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
78
79   setCaption( aCaption );
80
81   /***************************************************************/
82   GroupConstructors->setTitle( aTitle );
83   RadioButton1->setPixmap( image0 );
84   RadioButton2->close(TRUE);
85   RadioButton3->close(TRUE);
86
87   myGroup = new DlgRef_2Sel_QTD(this, "GroupCommon");
88   myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
89   if ( myOperation != BooleanGUI::CUT )
90   {
91         myGroup->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
92         myGroup->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
93   }
94   else
95   {
96         myGroup->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
97         myGroup->TextLabel2->setText(tr("GEOM_TOOL_OBJECT"));
98   }
99   
100   myGroup->PushButton1->setPixmap(image1);
101   myGroup->PushButton2->setPixmap(image1);
102   myGroup->LineEdit1->setReadOnly( true );
103   myGroup->LineEdit2->setReadOnly( true );
104
105   Layout1->addWidget(myGroup, 2, 0);
106   /***************************************************************/
107
108   /* Initialisation */
109   Init();
110 }
111
112
113 //=================================================================================
114 // function : ~BooleanGUI_Dialog()
115 // purpose  : Destroys the object and frees any allocated resources
116 //=================================================================================
117 BooleanGUI_Dialog::~BooleanGUI_Dialog()
118 {
119 }
120
121
122
123 //=================================================================================
124 // function : Init()
125 // purpose  :
126 //=================================================================================
127 void BooleanGUI_Dialog::Init()
128 {
129   /* init variables */
130   myEditCurrentArgument = myGroup->LineEdit1;
131
132    /* signals and slots connections */
133   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
134   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
135
136   connect(myGroup->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
137   connect(myGroup->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
138
139   connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140   connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141
142   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
143           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
144
145   initName( GroupConstructors->title() );
146
147   globalSelection( GEOM_ALLSHAPES );
148 }
149
150
151 //=================================================================================
152 // function : ClickOnOk()
153 // purpose  :
154 //=================================================================================
155 void BooleanGUI_Dialog::ClickOnOk()
156 {
157   if ( ClickOnApply() )
158     ClickOnCancel();
159 }
160
161
162 //=================================================================================
163 // function : ClickOnApply()
164 // purpose  :
165 //=================================================================================
166 bool BooleanGUI_Dialog::ClickOnApply()
167 {
168   if ( !onAccept() )
169     return false;  
170
171   initName();
172   return true;
173 }
174
175
176 //=================================================================================
177 // function : SelectionIntoArgument()
178 // purpose  : Called when selection has changed
179 //=================================================================================
180 void BooleanGUI_Dialog::SelectionIntoArgument()
181 {
182   myEditCurrentArgument->setText( "" );
183
184   if ( IObjectCount() != 1 )
185   {
186     if      ( myEditCurrentArgument == myGroup->LineEdit1 )   myObject1 = GEOM::GEOM_Object::_nil();
187     else if ( myEditCurrentArgument == myGroup->LineEdit2 )   myObject2 = GEOM::GEOM_Object::_nil();
188     return;
189   }
190
191   // nbSel == 1
192   Standard_Boolean aRes = Standard_False;
193   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
194   if ( !CORBA::is_nil( aSelectedObject ) && aRes && GEOMBase::IsShape( aSelectedObject ) )
195   {
196     myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
197     if      ( myEditCurrentArgument == myGroup->LineEdit1 )   myObject1 = aSelectedObject;
198     else if ( myEditCurrentArgument == myGroup->LineEdit2 )   myObject2 = aSelectedObject;
199   }
200 }
201
202
203 //=================================================================================
204 // function : SetEditCurrentArgument()
205 // purpose  :
206 //=================================================================================
207 void BooleanGUI_Dialog::SetEditCurrentArgument()
208 {
209   QPushButton* send = (QPushButton*)sender();
210
211   if      ( send == myGroup->PushButton1 ) myEditCurrentArgument = myGroup->LineEdit1;
212   else if ( send == myGroup->PushButton2 ) myEditCurrentArgument = myGroup->LineEdit2;
213
214   myEditCurrentArgument->setFocus();
215   SelectionIntoArgument();
216 }
217
218
219
220 //=================================================================================
221 // function : LineEditReturnPressed()
222 // purpose  :
223 //=================================================================================
224 void BooleanGUI_Dialog::LineEditReturnPressed()
225 {
226   QLineEdit* send = (QLineEdit*)sender();
227   if ( send == myGroup->LineEdit1 || send == myGroup->LineEdit2 )
228   {
229     myEditCurrentArgument = send;
230     GEOMBase_Skeleton::LineEditReturnPressed();
231   }
232 }
233
234
235 //=================================================================================
236 // function : ActivateThisDialog()
237 // purpose  :
238 //=================================================================================
239 void BooleanGUI_Dialog::ActivateThisDialog()
240 {
241   GEOMBase_Skeleton::ActivateThisDialog();
242   globalSelection( GEOM_ALLSHAPES );
243   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
244           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
245 }
246
247
248 //=================================================================================
249 // function : enterEvent()
250 // purpose  : when mouse enter onto the QWidget
251 //=================================================================================
252 void BooleanGUI_Dialog::enterEvent(QEvent * e)
253 {
254   if ( !GroupConstructors->isEnabled() )
255     ActivateThisDialog();
256 }
257
258 //=================================================================================
259 // function : createOperation
260 // purpose  :
261 //=================================================================================
262 GEOM::GEOM_IOperations_ptr BooleanGUI_Dialog::createOperation()
263 {
264   return getGeomEngine()->GetIBooleanOperations( getStudyId() );
265 }
266
267 //=================================================================================
268 // function : isValid
269 // purpose  :
270 //=================================================================================
271 bool BooleanGUI_Dialog::isValid( QString& msg )
272 {
273   return !CORBA::is_nil( myObject1 ) && !CORBA::is_nil( myObject2 );
274 }
275
276 //=================================================================================
277 // function : execute
278 // purpose  :
279 //=================================================================================
280 bool BooleanGUI_Dialog::execute( ObjectList& objects )
281 {
282   GEOM::GEOM_Object_var anObj;
283  
284   anObj = GEOM::GEOM_IBooleanOperations::_narrow( getOperation() )->MakeBoolean( myObject1, myObject2, myOperation );
285   if ( !anObj->_is_nil() )
286     objects.push_back( anObj._retn() );
287
288   return true;
289 }