]> SALOME platform Git repositories - modules/geom.git/blob - src/BuildGUI/BuildGUI_FaceDlg.cxx
Salome HOME
0022758: [EDF] Creation of a face from a surface and limiting edges
[modules/geom.git] / src / BuildGUI / BuildGUI_FaceDlg.cxx
1 // Copyright (C) 2007-2014  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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : BuildGUI_FaceDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26
27 #include "BuildGUI_FaceDlg.h"
28
29 #include <GEOMImpl_Types.hxx>
30 #include <TColStd_MapOfInteger.hxx>
31
32 #include <DlgRef.h>
33 #include <GeometryGUI.h>
34 #include <GEOMBase.h>
35
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
38
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_Session.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_OverrideCursor.h>
43
44 //=================================================================================
45 // class    : BuildGUI_FaceDlg()
46 // purpose  : Constructs a BuildGUI_FaceDlg which is a child of 'parent', with the 
47 //            name 'name' and widget flags set to 'f'.
48 //            The dialog will by default be modeless, unless you set 'modal' to
49 //            TRUE to construct a modal dialog.
50 //=================================================================================
51 BuildGUI_FaceDlg::BuildGUI_FaceDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
52   : GEOMBase_Skeleton( theGeometryGUI, parent ),
53     GroupWire        (0),
54     myGroupSurf      (0)
55 {
56   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
57   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_FACE" ) ) );
58   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_FACE_SURFACE" ) ) );
59
60   setWindowTitle( tr( "GEOM_FACE_TITLE" ) );
61
62   /***************************************************************/
63   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_FACE" ) );
64   mainFrame()->RadioButton1->setIcon( image1 );
65   mainFrame()->RadioButton2->setIcon( image2 );
66   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
67   mainFrame()->RadioButton3->close();
68
69   GroupWire = new DlgRef_1Sel1Check( centralWidget() );
70
71   GroupWire->GroupBox1->setTitle( tr( "GEOM_FACE_FFW" ) );
72   GroupWire->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
73   GroupWire->CheckButton1->setText( tr( "GEOM_FACE_OPT" ) );
74   GroupWire->PushButton1->setIcon( image0 );
75
76   myGroupSurf = new DlgRef_2Sel(centralWidget());
77
78   myGroupSurf->GroupBox1->setTitle(tr("GEOM_FACE_FROM_SURFACE" ) );
79   myGroupSurf->TextLabel1->setText(tr("GEOM_FACE"));
80   myGroupSurf->TextLabel2->setText(tr("GEOM_WIRE"));
81   myGroupSurf->PushButton1->setIcon(image0);
82   myGroupSurf->PushButton2->setIcon(image0);
83
84   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
85   layout->setMargin( 0 ); layout->setSpacing( 6 );
86   layout->addWidget( GroupWire );
87   layout->addWidget(myGroupSurf);
88   /***************************************************************/
89
90   setHelpFileName("create_face_page.html");
91
92   /* Initialisations */
93   Init();
94 }
95
96
97 //=================================================================================
98 // function : ~BuildGUI_FaceDlg()
99 // purpose  : Destroys the object and frees any allocated resources
100 //=================================================================================
101 BuildGUI_FaceDlg::~BuildGUI_FaceDlg()
102 {
103   // no need to delete child widgets, Qt does it all for us
104 }
105
106
107 //=================================================================================
108 // function : Init()
109 // purpose  :
110 //=================================================================================
111 void BuildGUI_FaceDlg::Init()
112 {
113   /* init variables */
114   myEditCurrentArgument = GroupWire->LineEdit1;
115   GroupWire->LineEdit1->setReadOnly( true );
116   myGroupSurf->LineEdit1->setReadOnly( true );
117   myGroupSurf->LineEdit2->setReadOnly( true );
118
119   GroupWire->CheckButton1->setChecked( true );
120   myWires.clear();
121   myFace.nullify();
122   myWire.nullify();
123
124   /* signals and slots connections */
125   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
126   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()),        this, SLOT(ClickOnCancel()));
127
128   connect(this,      SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
129
130   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
131   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
132   connect( GroupWire->LineEdit1,   SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
133   connect( GroupWire->PushButton1, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
134   connect( myGroupSurf->LineEdit1,   SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
135   connect( myGroupSurf->PushButton1, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
136   connect( myGroupSurf->LineEdit2,   SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
137   connect( myGroupSurf->PushButton2, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
138   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
139            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
140
141   initName( tr( "GEOM_FACE" ) );
142
143   ConstructorsClicked(0);
144 }
145
146 //=================================================================================
147 // function : ConstructorsClicked()
148 // purpose  : Radio button management
149 //=================================================================================
150 void BuildGUI_FaceDlg::ConstructorsClicked(int constructorId)
151 {
152   switch (constructorId) {
153   case 0:
154     {
155       TColStd_MapOfInteger aMap;
156
157       aMap.Add(GEOM_EDGE);
158       aMap.Add(GEOM_WIRE);
159       aMap.Add(GEOM_FACE);
160       aMap.Add(GEOM_SHELL);
161       aMap.Add(GEOM_SOLID);
162       aMap.Add(GEOM_COMPOUND);
163       globalSelection(aMap);
164
165       myEditCurrentArgument = GroupWire->LineEdit1;
166       GroupWire->LineEdit1->setText("");
167       GroupWire->show();
168       myGroupSurf->hide();
169       break;
170     }
171   case 1:
172     {
173       globalSelection(GEOM_FACE); // For the first element.
174
175       myEditCurrentArgument = myGroupSurf->LineEdit1;
176       myGroupSurf->LineEdit1->setText("");
177       myGroupSurf->PushButton1->setDown(true);
178       myGroupSurf->PushButton2->setDown(false);
179       GroupWire->hide();
180       myGroupSurf->show();
181       break;
182     }
183   }
184
185   myWires.clear();
186   myFace.nullify();
187   myWire.nullify();
188   qApp->processEvents();
189   updateGeometry();
190   resize(minimumSizeHint());
191   SelectionIntoArgument();
192 }
193
194 //=================================================================================
195 // function : ClickOnOk()
196 // purpose  :
197 //=================================================================================
198 void BuildGUI_FaceDlg::ClickOnOk()
199 {
200   setIsApplyAndClose( true );
201   if ( ClickOnApply() )
202     ClickOnCancel();
203 }
204
205
206 //=================================================================================
207 // function : ClickOnApply()
208 // purpose  :
209 //=================================================================================
210 bool BuildGUI_FaceDlg::ClickOnApply()
211 {
212   if ( !onAccept() )
213     return false;
214
215   initName();
216   return true;
217 }
218
219
220 //=================================================================================
221 // function : SelectionIntoArgument()
222 // purpose  : Called when selection as changed or other case
223 //=================================================================================
224 void BuildGUI_FaceDlg::SelectionIntoArgument()
225 {
226   if (myEditCurrentArgument == GroupWire->LineEdit1) {
227     myEditCurrentArgument->setText( "" );
228
229     QList<TopAbs_ShapeEnum> types;
230     types << TopAbs_EDGE  << TopAbs_WIRE  << TopAbs_FACE
231           << TopAbs_SHELL << TopAbs_SOLID << TopAbs_COMPOUND;
232     myWires = getSelected( types, -1 );
233
234     if ( !myWires.isEmpty() ) {
235       QString aName = myWires.count() > 1 ? QString( "%1_objects").arg( myWires.count() ) : GEOMBase::GetName( myWires[0].get() );
236       myEditCurrentArgument->setText( aName );
237     }
238   } else if (myEditCurrentArgument == myGroupSurf->LineEdit1 ||
239              myEditCurrentArgument == myGroupSurf->LineEdit2) {
240     const bool isEditFace = myEditCurrentArgument == myGroupSurf->LineEdit1;
241     const TopAbs_ShapeEnum aType = isEditFace ? TopAbs_FACE : TopAbs_WIRE;
242     GEOM::GeomObjPtr aSelectedObject = getSelected(aType);
243     GEOM::GeomObjPtr &anObj = isEditFace ? myFace : myWire;
244
245     if (aSelectedObject) {
246       myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject.get()));
247       anObj = aSelectedObject;
248     } else {
249       myEditCurrentArgument->setText("");
250       anObj.nullify();
251     }
252
253     if (isEditFace) {
254       if (myFace && !myWire) {
255         myGroupSurf->PushButton2->click();
256       }
257     } else {
258       if (!myFace && myWire) {
259         myGroupSurf->PushButton1->click();
260       }
261     }
262   }
263
264   displayPreview(true);
265 }
266
267
268 //=================================================================================
269 // function : SetEditCurrentArgument()
270 // purpose  :
271 //=================================================================================
272 void BuildGUI_FaceDlg::SetEditCurrentArgument()
273 {
274   QPushButton* send = (QPushButton*)sender();
275   if (send == GroupWire->PushButton1) {
276     TColStd_MapOfInteger aMap;
277   
278     aMap.Add(GEOM_EDGE);
279     aMap.Add(GEOM_WIRE);
280     aMap.Add(GEOM_FACE);
281     aMap.Add(GEOM_SHELL);
282     aMap.Add(GEOM_SOLID);
283     aMap.Add(GEOM_COMPOUND);
284     globalSelection(aMap);
285     myEditCurrentArgument = GroupWire->LineEdit1;
286   }
287   else if (send == myGroupSurf->PushButton1) {
288     globalSelection(GEOM_FACE);
289     myEditCurrentArgument = myGroupSurf->LineEdit1;
290     myGroupSurf->PushButton2->setDown(false);
291     myGroupSurf->LineEdit2->setEnabled(false);
292   }
293   else if (send == myGroupSurf->PushButton2) {
294     globalSelection(GEOM_WIRE);
295     myEditCurrentArgument = myGroupSurf->LineEdit2;
296     myGroupSurf->PushButton1->setDown(false);
297     myGroupSurf->LineEdit1->setEnabled(false);
298   }
299
300   // enable line edit
301   myEditCurrentArgument->setEnabled(true);
302   myEditCurrentArgument->setFocus();
303   send->setDown(true);
304   displayPreview(true);
305 }
306
307
308 //=================================================================================
309 // function : ActivateThisDialog()
310 // purpose  :
311 //=================================================================================
312 void BuildGUI_FaceDlg::ActivateThisDialog()
313 {
314   GEOMBase_Skeleton::ActivateThisDialog();
315   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
316            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
317   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
318            this, SLOT(SelectionIntoArgument()));
319
320   ConstructorsClicked(getConstructorId());
321 }
322
323
324 //=================================================================================
325 // function : enterEvent()
326 // purpose  :
327 //=================================================================================
328 void BuildGUI_FaceDlg::enterEvent( QEvent* )
329 {
330   if ( !mainFrame()->GroupConstructors->isEnabled() )
331     ActivateThisDialog(); 
332 }
333
334 //=================================================================================
335 // function : createOperation
336 // purpose  :
337 //=================================================================================
338 GEOM::GEOM_IOperations_ptr BuildGUI_FaceDlg::createOperation()
339 {
340   return getGeomEngine()->GetIShapesOperations( getStudyId() );
341 }
342
343 //=================================================================================
344 // function : isValid
345 // purpose  :
346 //=================================================================================
347 bool BuildGUI_FaceDlg::isValid( QString& )
348 {
349   bool ok = false;
350
351   switch (getConstructorId()) {
352   case 0:
353     ok = !myWires.isEmpty();
354     break;
355   case 1:
356     ok = myFace && myWire;
357     break;
358   default:
359     break;
360   }
361
362   return ok;
363 }
364
365 //=================================================================================
366 // function : execute
367 // purpose  :
368 //=================================================================================
369 bool BuildGUI_FaceDlg::execute( ObjectList& objects )
370 {
371   bool res = false;
372   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
373   GEOM::GEOM_Object_var anObj;
374
375   switch (getConstructorId()) {
376   case 0:
377     {
378       GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
379       
380       objlist->length( myWires.count() );
381
382       for ( int i = 0; i < myWires.count(); i++ ) {
383         objlist[i] = myWires[i].copy();
384       }
385
386       anObj = anOper->MakeFaceWires( objlist.in(), GroupWire->CheckButton1->isChecked() );
387       res   = true;
388     }
389     break;
390   case 1:
391     anObj = anOper->MakeFaceFromSurface(myFace.get(), myWire.get());
392     res   = true;
393     break;
394   default:
395     break;
396   }
397
398   if (!anObj->_is_nil()) {
399     objects.push_back(anObj._retn());
400
401     if (!anOper->IsDone() && QString(anOper->GetErrorCode()) == "MAKE_FACE_TOLERANCE_TOO_BIG") {
402       SUIT_OverrideCursor wc;
403       wc.suspend();
404       QString msgw = QObject::tr(anOper->GetErrorCode());
405       SUIT_MessageBox::warning(this, tr("WRN_WARNING"), msgw, tr("BUT_OK"));
406       anOper->SetErrorCode("PAL_NO_ERROR");
407     }
408   }
409
410   return res;
411 }