Salome HOME
2b76cc7cf8b772e5530b885a94f0e4d0a447d0fb
[modules/geom.git] / src / BuildGUI / BuildGUI_FaceDlg.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   : BuildGUI_FaceDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "BuildGUI_FaceDlg.h"
31 #include "QAD_Desktop.h"
32 #include "GEOMImpl_Types.hxx"
33
34 //Qt includes
35 #include <qcheckbox.h>
36
37 //=================================================================================
38 // class    : BuildGUI_FaceDlg()
39 // purpose  : Constructs a BuildGUI_FaceDlg which is a child of 'parent', with the 
40 //            name 'name' and widget flags set to 'f'.
41 //            The dialog will by default be modeless, unless you set 'modal' to
42 //            TRUE to construct a modal dialog.
43 //=================================================================================
44 BuildGUI_FaceDlg::BuildGUI_FaceDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
45   :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
46 {
47   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_BUILD_FACE")));
48   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
49
50   setCaption(tr("GEOM_FACE_TITLE"));
51
52   /***************************************************************/
53   GroupConstructors->setTitle(tr("GEOM_FACE"));
54   RadioButton1->setPixmap(image0);
55   RadioButton2->close(TRUE);
56   RadioButton3->close(TRUE);
57
58   GroupWire = new DlgRef_1Sel1Check_QTD(this, "GroupWire");
59   GroupWire->GroupBox1->setTitle(tr("GEOM_FACE_FFW"));
60   GroupWire->TextLabel1->setText(tr("GEOM_WIRES"));
61   GroupWire->CheckButton1->setText(tr("GEOM_FACE_OPT"));
62   GroupWire->PushButton1->setPixmap(image1);
63
64   Layout1->addWidget(GroupWire, 2, 0);
65   /***************************************************************/
66
67   /* Initialisations */
68   Init();
69 }
70
71
72 //=================================================================================
73 // function : ~BuildGUI_FaceDlg()
74 // purpose  : Destroys the object and frees any allocated resources
75 //=================================================================================
76 BuildGUI_FaceDlg::~BuildGUI_FaceDlg()
77 {
78   // no need to delete child widgets, Qt does it all for us
79 }
80
81
82 //=================================================================================
83 // function : Init()
84 // purpose  :
85 //=================================================================================
86 void BuildGUI_FaceDlg::Init()
87 {
88   /* init variables */
89   myEditCurrentArgument = GroupWire->LineEdit1;
90   GroupWire->LineEdit1->setReadOnly( true );
91
92   GroupWire->CheckButton1->setChecked(TRUE);
93
94   globalSelection( GEOM_WIRE );
95
96   /* signals and slots connections */
97   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
98   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
99   connect(GroupWire->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
100   connect(GroupWire->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));  
101   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
102
103   initName(tr("GEOM_FACE"));
104 }
105
106
107 //=================================================================================
108 // function : ClickOnOk()
109 // purpose  :
110 //=================================================================================
111 void BuildGUI_FaceDlg::ClickOnOk()
112 {
113   if ( ClickOnApply() )
114     ClickOnCancel();
115 }
116
117
118 //=================================================================================
119 // function : ClickOnApply()
120 // purpose  :
121 //=================================================================================
122 bool BuildGUI_FaceDlg::ClickOnApply()
123 {
124   if ( !onAccept() )
125     return false;
126
127   initName();
128   return true;
129 }
130
131
132 //=================================================================================
133 // function : SelectionIntoArgument()
134 // purpose  : Called when selection as changed or other case
135 //=================================================================================
136 void BuildGUI_FaceDlg::SelectionIntoArgument()
137 {
138   myEditCurrentArgument->setText("");
139   QString aName;
140   
141   int aNbSel = GEOMBase::GetNameOfSelectedIObjects(mySelection, aName);
142   
143   if(aNbSel < 1)
144     {
145       myWires.length(0);
146       return;
147     }
148   
149   GEOMBase::ConvertListOfIOInListOfGO(mySelection->StoredIObjects(), myWires);
150   if (!myWires.length())
151     return;
152   if(aNbSel != 1)
153     aName = tr("%1_wires").arg(aNbSel);
154   
155   myEditCurrentArgument->setText( aName );
156   
157   myEditCurrentArgument->setText( aName );
158 }
159
160
161 //=================================================================================
162 // function : SetEditCurrentArgument()
163 // purpose  :
164 //=================================================================================
165 void BuildGUI_FaceDlg::SetEditCurrentArgument()
166 {
167   QPushButton* send = (QPushButton*)sender();
168   if (send != GroupWire->PushButton1)
169     return;
170   
171   globalSelection( GEOM_WIRE );
172   myEditCurrentArgument = GroupWire->LineEdit1;
173
174   myEditCurrentArgument->setFocus();
175   SelectionIntoArgument();
176 }
177
178
179 //=================================================================================
180 // function : ActivateThisDialog()
181 // purpose  :
182 //=================================================================================
183 void BuildGUI_FaceDlg::ActivateThisDialog()
184 {
185   GEOMBase_Skeleton::ActivateThisDialog();
186   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
187   globalSelection( GEOM_WIRE );
188 }
189
190
191 //=================================================================================
192 // function : enterEvent()
193 // purpose  :
194 //=================================================================================
195 void BuildGUI_FaceDlg::enterEvent(QEvent* e)
196 {
197   if ( !GroupConstructors->isEnabled() )
198     ActivateThisDialog(); 
199 }
200
201 //=================================================================================
202 // function : createOperation
203 // purpose  :
204 //=================================================================================
205 GEOM::GEOM_IOperations_ptr BuildGUI_FaceDlg::createOperation()
206 {
207   return getGeomEngine()->GetIShapesOperations( getStudyId() );
208 }
209
210 //=================================================================================
211 // function : isValid
212 // purpose  :
213 //=================================================================================
214 bool BuildGUI_FaceDlg::isValid( QString& )
215 {
216   return (myWires.length() != 0);
217 }
218
219 //=================================================================================
220 // function : execute
221 // purpose  :
222 //=================================================================================
223 bool BuildGUI_FaceDlg::execute( ObjectList& objects )
224 {
225   GEOM::GEOM_Object_var anObj;
226
227   bool isPlanarWanted = GroupWire->CheckButton1->isChecked();
228   anObj = GEOM::GEOM_IShapesOperations::_narrow(
229     getOperation() )->MakeFaceWires( myWires, isPlanarWanted );
230
231   if ( !anObj->_is_nil() )
232     objects.push_back( anObj._retn() );
233
234   return true;
235 }
236