1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : BuildGUI_SolidDlg.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
27 #include "BuildGUI_SolidDlg.h"
30 #include <GeometryGUI.h>
33 #include <GEOMImpl_Types.hxx>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_Session.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
41 #include <TColStd_MapOfInteger.hxx>
43 //=================================================================================
44 // class : BuildGUI_SolidDlg()
45 // purpose : Constructs a BuildGUI_SolidDlg which is a child of 'parent', with the
46 // name 'name' and widget flags set to 'f'.
47 // The dialog will by default be modeless, unless you set 'modal' to
48 // TRUE to construct a modal dialog.
49 //=================================================================================
50 BuildGUI_SolidDlg::BuildGUI_SolidDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
51 : GEOMBase_Skeleton( theGeometryGUI, parent )
53 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_SOLID" ) ) );
54 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
56 setWindowTitle( tr( "GEOM_SOLID_TITLE" ) );
58 /***************************************************************/
59 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SOLID" ) );
60 mainFrame()->RadioButton1->setIcon( image0 );
61 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
62 mainFrame()->RadioButton2->close();
63 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
64 mainFrame()->RadioButton3->close();
66 GroupSolid = new DlgRef_1Sel1Check( centralWidget() );
68 GroupSolid->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
69 GroupSolid->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
70 GroupSolid->CheckButton1->setText( tr( "GEOM_CREATE_SINGLE_SOLID" ) );
71 GroupSolid->PushButton1->setIcon( image1 );
72 GroupSolid->LineEdit1->setReadOnly( true );
74 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
75 layout->setMargin( 0 ); layout->setSpacing( 6 );
76 layout->addWidget( GroupSolid );
77 /***************************************************************/
79 setHelpFileName("create_solid_page.html");
86 //=================================================================================
87 // function : ~BuildGUI_SolidDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 BuildGUI_SolidDlg::~BuildGUI_SolidDlg()
92 // no need to delete child widgets, Qt does it all for us
96 //=================================================================================
99 //=================================================================================
100 void BuildGUI_SolidDlg::Init()
103 myEditCurrentArgument = GroupSolid->LineEdit1;
104 GroupSolid->LineEdit1->setReadOnly( true );
105 GroupSolid->CheckButton1->setChecked( true );
109 //globalSelection( GEOM_SHELL );
110 TColStd_MapOfInteger aMap;
111 aMap.Add( GEOM_SHELL );
112 aMap.Add( GEOM_COMPOUNDFILTER );
113 QList<int> aSubShapes;
114 aSubShapes.append( GEOM_SHELL );
115 globalSelection( aMap, aSubShapes );
117 /* signals and slots connections */
118 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
119 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
121 connect( GroupSolid->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
122 connect( GroupSolid->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( EnableNameField( bool ) ) );
124 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
125 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
127 initName( tr( "GEOM_SOLID" ) );
128 SelectionIntoArgument();
132 //=================================================================================
133 // function : ClickOnOk()
135 //=================================================================================
136 void BuildGUI_SolidDlg::ClickOnOk()
138 setIsApplyAndClose( true );
139 if ( ClickOnApply() )
143 //=================================================================================
144 // function : ClickOnApply()
146 //=================================================================================
147 bool BuildGUI_SolidDlg::ClickOnApply()
157 //=================================================================================
158 // function : SelectionIntoArgument()
159 // purpose : Called when selection as changed or other case
160 //=================================================================================
161 void BuildGUI_SolidDlg::SelectionIntoArgument()
163 myEditCurrentArgument->setText( "" );
165 //myShells = getSelected( TopAbs_SHELL, -1 );
166 QList<TopAbs_ShapeEnum> types;
167 types << TopAbs_SHELL << TopAbs_COMPOUND;
168 myShells = getSelected( types, -1 );
170 if ( !myShells.isEmpty() ) {
171 QString aName = myShells.count() > 1 ? QString( "%1_objects").arg( myShells.count() ) : GEOMBase::GetName( myShells[0].get() );
172 myEditCurrentArgument->setText( aName );
176 //=================================================================================
177 // function : SetEditCurrentArgument()
179 //=================================================================================
180 void BuildGUI_SolidDlg::SetEditCurrentArgument()
182 QPushButton* send = (QPushButton*)sender();
183 if ( send != GroupSolid->PushButton1 )
186 //globalSelection( GEOM_SHELL );
187 TColStd_MapOfInteger aMap;
188 aMap.Add( GEOM_SHELL );
189 aMap.Add( GEOM_COMPOUNDFILTER );
190 QList<int> aSubShapes;
191 aSubShapes.append( GEOM_SHELL );
192 globalSelection( aMap, aSubShapes );
194 myEditCurrentArgument = GroupSolid->LineEdit1;
196 myEditCurrentArgument->setFocus();
197 SelectionIntoArgument();
201 //=================================================================================
202 // function : ActivateThisDialog()
204 //=================================================================================
205 void BuildGUI_SolidDlg::ActivateThisDialog()
207 GEOMBase_Skeleton::ActivateThisDialog();
208 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
209 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
211 //globalSelection( GEOM_SHELL );
212 TColStd_MapOfInteger aMap;
213 aMap.Add( GEOM_SHELL );
214 aMap.Add( GEOM_COMPOUNDFILTER );
215 QList<int> aSubShapes;
216 aSubShapes.append( GEOM_SHELL );
217 globalSelection( aMap, aSubShapes );
221 //=================================================================================
222 // function : enterEvent()
224 //=================================================================================
225 void BuildGUI_SolidDlg::enterEvent( QEvent* )
227 if ( !mainFrame()->GroupConstructors->isEnabled() )
228 ActivateThisDialog();
232 //=================================================================================
233 // function : EnableNameField()
235 //=================================================================================
236 void BuildGUI_SolidDlg::EnableNameField( bool toEnable )
238 mainFrame()->GroupBoxName->setEnabled( toEnable );
241 //=================================================================================
242 // function : createOperation
244 //=================================================================================
245 GEOM::GEOM_IOperations_ptr BuildGUI_SolidDlg::createOperation()
247 return getGeomEngine()->GetIShapesOperations( getStudyId() );
250 //=================================================================================
251 // function : isValid
253 //=================================================================================
254 bool BuildGUI_SolidDlg::isValid (QString& msg)
256 bool ok = !myShells.isEmpty();
258 GEOM::MeasureOpPtr anOp;
259 anOp.take(myGeomGUI->GetGeomGen()->GetIMeasureOperations(getStudyId()));
261 if (!GroupSolid->CheckButton1->isChecked() || myShells.count() == 1) {
262 for (int i = 0, n = myShells.count(); i < n && ok; i++) {
263 CORBA::String_var aRes = anOp->IsGoodForSolid(myShells[i].get());
264 if (strlen(aRes.in())) {
265 msg = QObject::tr(aRes.in()).arg(GEOMBase::GetName(myShells[i].get()));
274 //=================================================================================
275 // function : isClosed
276 // purpose : Check the object 'i' in myShells list is closed or unclosed
277 //=================================================================================
278 bool BuildGUI_SolidDlg::isClosed( GEOM::GEOM_Object_ptr shell )
282 GEOM::GEOM_IKindOfShape::shape_kind aKind;
283 GEOM::ListOfLong_var anInts;
284 GEOM::ListOfDouble_var aDbls;
286 if ( !CORBA::is_nil( shell ) ) {
287 GEOM::MeasureOpPtr anOp;
288 anOp.take( myGeomGUI->GetGeomGen()->GetIMeasureOperations( getStudyId() ) );
290 // Detect kind of shape and parameters
291 aKind = anOp->KindOfShape(shell, anInts, aDbls);
293 if ( anOp->IsDone() ) {
294 if ( anInts[0] == 1 )
296 else if ( anInts[0] == 2 )
300 MESSAGE ("KindOfShape Operation is NOT DONE!!!");
304 MESSAGE ("Shape is NULL!!!");
311 //=================================================================================
312 // function : execute
314 //=================================================================================
315 bool BuildGUI_SolidDlg::execute( ObjectList& objects )
317 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
319 if ( GroupSolid->CheckButton1->isChecked() ) {
320 GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
321 objlist->length( myShells.count() );
322 for ( int i = 0; i < myShells.count(); i++ )
323 objlist[i] = myShells[i].copy();
325 GEOM::GEOM_Object_var anObj = anOper->MakeSolidShells( objlist.in() );
327 if ( !anObj->_is_nil() )
328 objects.push_back( anObj._retn() );
331 for ( int i = 0, n = myShells.count(); i< n; i++ ) {
332 GEOM::GEOM_Object_var anObj = anOper->MakeSolidShell( myShells[ i ].get() );
334 if ( !anObj->_is_nil() )
335 objects.push_back( anObj._retn() );