1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : BuildGUI_SolidDlg.cxx
25 // Author : Damien COQUERET
29 #include "BuildGUI_SolidDlg.h"
30 #include "GEOMImpl_Types.hxx"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
37 #include <qcheckbox.h>
40 //=================================================================================
41 // class : BuildGUI_SolidDlg()
42 // purpose : Constructs a BuildGUI_SolidDlg which is a child of 'parent', with the
43 // name 'name' and widget flags set to 'f'.
44 // The dialog will by default be modeless, unless you set 'modal' to
45 // TRUE to construct a modal dialog.
46 //=================================================================================
47 BuildGUI_SolidDlg::BuildGUI_SolidDlg(QWidget* parent, const char* name, bool modal, WFlags fl)
48 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
50 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BUILD_SOLID")));
51 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
53 setCaption(tr("GEOM_SOLID_TITLE"));
55 /***************************************************************/
56 GroupConstructors->setTitle(tr("GEOM_SOLID"));
57 RadioButton1->setPixmap(image0);
58 RadioButton2->close(TRUE);
59 RadioButton3->close(TRUE);
61 GroupSolid = new DlgRef_1Sel1Check_QTD(this, "GroupSolid");
62 GroupSolid->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
63 GroupSolid->TextLabel1->setText(tr("GEOM_OBJECTS"));
64 GroupSolid->CheckButton1->setText(tr("GEOM_CREATE_SINGLE_SOLID"));
65 GroupSolid->PushButton1->setPixmap(image1);
66 GroupSolid->LineEdit1->setReadOnly( true );
68 Layout1->addWidget(GroupSolid, 2, 0);
69 /***************************************************************/
76 //=================================================================================
77 // function : ~BuildGUI_SolidDlg()
78 // purpose : Destroys the object and frees any allocated resources
79 //=================================================================================
80 BuildGUI_SolidDlg::~BuildGUI_SolidDlg()
82 // no need to delete child widgets, Qt does it all for us
86 //=================================================================================
89 //=================================================================================
90 void BuildGUI_SolidDlg::Init()
93 myEditCurrentArgument = GroupSolid->LineEdit1;
94 GroupSolid->LineEdit1->setReadOnly( true );
95 GroupSolid->CheckButton1->setChecked( true );
99 globalSelection( GEOM_SHELL );
101 /* signals and slots connections */
102 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
103 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
105 connect(GroupSolid->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
106 connect(GroupSolid->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(EnableNameField(bool)));
108 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
109 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
111 initName(tr("GEOM_SOLID"));
115 //=================================================================================
116 // function : ClickOnOk()
118 //=================================================================================
119 void BuildGUI_SolidDlg::ClickOnOk()
121 if ( ClickOnApply() )
125 //=================================================================================
126 // function : ClickOnApply()
128 //=================================================================================
129 bool BuildGUI_SolidDlg::ClickOnApply()
139 //=================================================================================
140 // function : SelectionIntoArgument()
141 // purpose : Called when selection as changed or other case
142 //=================================================================================
143 void BuildGUI_SolidDlg::SelectionIntoArgument()
145 myEditCurrentArgument->setText("");
146 QString aString = "";
149 int nbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aString);
153 aString = tr("%1_objects").arg(nbSel);
155 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myShells);
156 if (!myShells.length())
159 myEditCurrentArgument->setText(aString);
163 //=================================================================================
164 // function : SetEditCurrentArgument()
166 //=================================================================================
167 void BuildGUI_SolidDlg::SetEditCurrentArgument()
169 QPushButton* send = (QPushButton*)sender();
170 if(send != GroupSolid->PushButton1)
173 globalSelection( GEOM_SHELL );
174 myEditCurrentArgument = GroupSolid->LineEdit1;
176 myEditCurrentArgument->setFocus();
177 SelectionIntoArgument();
181 //=================================================================================
182 // function : ActivateThisDialog()
184 //=================================================================================
185 void BuildGUI_SolidDlg::ActivateThisDialog()
187 GEOMBase_Skeleton::ActivateThisDialog();
188 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
189 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
190 globalSelection( GEOM_SHELL );
194 //=================================================================================
195 // function : enterEvent()
197 //=================================================================================
198 void BuildGUI_SolidDlg::enterEvent(QEvent* e)
200 if ( !GroupConstructors->isEnabled() )
201 ActivateThisDialog();
205 //=================================================================================
206 // function : EnableNameField()
208 //=================================================================================
209 void BuildGUI_SolidDlg::EnableNameField(bool toEnable)
211 this->GroupBoxName->setEnabled(toEnable);
214 //=================================================================================
215 // function : createOperation
217 //=================================================================================
218 GEOM::GEOM_IOperations_ptr BuildGUI_SolidDlg::createOperation()
220 return getGeomEngine()->GetIShapesOperations( getStudyId() );
223 //=================================================================================
224 // function : isValid
226 //=================================================================================
227 bool BuildGUI_SolidDlg::isValid( QString& )
232 //=================================================================================
233 // function : execute
235 //=================================================================================
236 bool BuildGUI_SolidDlg::execute( ObjectList& objects )
238 bool toCreateSingleSolid = GroupSolid->CheckButton1->isChecked();
240 if ( toCreateSingleSolid )
242 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow(
243 getOperation() )->MakeSolidShells( myShells );
245 if ( !anObj->_is_nil() )
246 objects.push_back( anObj._retn() );
250 for ( int i = 0, n = myShells.length(); i< n; i++ )
252 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow(
253 getOperation() )->MakeSolidShell( myShells[ i ] );
255 if ( !anObj->_is_nil() )
256 objects.push_back( anObj._retn() );