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