1 // Copyright (C) 2007-2021 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, or (at your option) any later version.
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_SELECT" ) ) );
54 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_SOLID" ) ) );
55 QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SOLID_FROM_FACES" ) ) );
57 setWindowTitle( tr( "GEOM_SOLID_TITLE" ) );
59 /***************************************************************/
60 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SOLID" ) );
61 mainFrame()->RadioButton1->setIcon( image1 );
62 mainFrame()->RadioButton2->setIcon( image2 );
63 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
64 mainFrame()->RadioButton3->close();
66 GroupSolid = new DlgRef_1Sel1Check( centralWidget() );
67 GroupSolid->GroupBox1->setTitle( tr( "GEOM_SOLID_SHELLS" ) );
68 GroupSolid->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
69 GroupSolid->CheckButton1->setText( tr( "GEOM_CREATE_SINGLE_SOLID" ) );
70 GroupSolid->PushButton1->setIcon( image0 );
71 GroupSolid->LineEdit1->setReadOnly( true );
73 GroupFaces = new DlgRef_1Sel1Check( centralWidget() );
74 GroupFaces->GroupBox1->setTitle( tr( "GEOM_SOLID_FACES" ) );
75 GroupFaces->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
76 GroupFaces->CheckButton1->setText( tr( "GEOM_SOLID_FROM_FACE_OPT" ) );
77 GroupFaces->PushButton1->setIcon( image0 );
78 GroupFaces->LineEdit1->setReadOnly( true );
80 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
81 layout->setMargin( 0 ); layout->setSpacing( 6 );
82 layout->addWidget( GroupSolid );
83 layout->addWidget( GroupFaces );
84 /***************************************************************/
86 setHelpFileName("create_solid_page.html");
93 //=================================================================================
94 // function : ~BuildGUI_SolidDlg()
95 // purpose : Destroys the object and frees any allocated resources
96 //=================================================================================
97 BuildGUI_SolidDlg::~BuildGUI_SolidDlg()
99 // no need to delete child widgets, Qt does it all for us
103 //=================================================================================
106 //=================================================================================
107 void BuildGUI_SolidDlg::Init()
110 myEditCurrentArgument = GroupSolid->LineEdit1;
111 GroupSolid->LineEdit1->setReadOnly( true );
112 GroupSolid->CheckButton1->setChecked( true );
116 //globalSelection( GEOM_SHELL );
117 TColStd_MapOfInteger aMap;
118 aMap.Add( GEOM_SHELL );
119 aMap.Add( GEOM_COMPOUNDFILTER );
120 QList<int> aSubShapes;
121 aSubShapes.append( GEOM_SHELL );
122 globalSelection( aMap, aSubShapes );
124 /* signals and slots connections */
125 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
126 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
128 connect(this, SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
130 connect( GroupSolid->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
131 connect( GroupFaces->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
132 connect( GroupSolid->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( EnableNameField( bool ) ) );
134 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
135 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
137 initName( tr( "GEOM_SOLID" ) );
138 SelectionIntoArgument();
140 ConstructorsClicked(0);
144 //=================================================================================
145 // function : ClickOnOk()
147 //=================================================================================
148 void BuildGUI_SolidDlg::ClickOnOk()
150 setIsApplyAndClose( true );
151 if ( ClickOnApply() )
155 //=================================================================================
156 // function : ClickOnApply()
158 //=================================================================================
159 bool BuildGUI_SolidDlg::ClickOnApply()
166 myEditCurrentArgument->setText("");
167 ConstructorsClicked(getConstructorId());
172 //=================================================================================
173 // function : ConstructorsClicked()
174 // purpose : Radio button management
175 //=================================================================================
176 void BuildGUI_SolidDlg::ConstructorsClicked(int constructorId)
178 switch (constructorId) {
184 myEditCurrentArgument = GroupSolid->LineEdit1;
185 GroupSolid->LineEdit1->setText("");
193 myEditCurrentArgument = GroupFaces->LineEdit1;
194 GroupFaces->LineEdit1->setText("");
199 qApp->processEvents();
201 resize(minimumSizeHint());
202 SelectionIntoArgument();
205 //=================================================================================
206 // function : SelectionIntoArgument()
207 // purpose : Called when selection as changed or other case
208 //=================================================================================
209 void BuildGUI_SolidDlg::SelectionIntoArgument()
211 myEditCurrentArgument->setText( "" );
213 //myShells = getSelected( TopAbs_SHELL, -1 );
214 QList<TopAbs_ShapeEnum> types;
215 if (myEditCurrentArgument == GroupSolid->LineEdit1)
216 types << TopAbs_SHELL << TopAbs_COMPOUND;
217 else if (myEditCurrentArgument == GroupFaces->LineEdit1)
218 types << TopAbs_FACE << TopAbs_SHELL << TopAbs_COMPOUND;
219 myShells = getSelected( types, -1 );
221 if ( !myShells.isEmpty() ) {
222 QString aName = myShells.count() > 1 ? QString( "%1_objects").arg( myShells.count() ) : GEOMBase::GetName( myShells[0].get() );
223 myEditCurrentArgument->setText( aName );
227 //=================================================================================
228 // function : SetEditCurrentArgument()
230 //=================================================================================
231 void BuildGUI_SolidDlg::SetEditCurrentArgument()
233 QPushButton* send = (QPushButton*)sender();
235 TColStd_MapOfInteger aMap;
236 QList<int> aSubShapes;
237 aMap.Add( GEOM_COMPOUNDFILTER );
239 if (send == GroupSolid->PushButton1) {
240 aMap.Add( GEOM_SHELL );
241 aSubShapes.append( GEOM_SHELL );
242 globalSelection( aMap, aSubShapes );
243 myEditCurrentArgument = GroupSolid->LineEdit1;
245 else if (send == GroupFaces->PushButton1) {
246 aMap.Add( GEOM_SHELL );
247 aMap.Add( GEOM_FACE );
248 aSubShapes.append( GEOM_SHELL );
249 aSubShapes.append( GEOM_FACE );
250 globalSelection( aMap, aSubShapes );
251 myEditCurrentArgument = GroupFaces->LineEdit1;
254 myEditCurrentArgument->setFocus();
255 SelectionIntoArgument();
259 //=================================================================================
260 // function : ActivateThisDialog()
262 //=================================================================================
263 void BuildGUI_SolidDlg::ActivateThisDialog()
265 GEOMBase_Skeleton::ActivateThisDialog();
266 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
267 this, SLOT(SelectionIntoArgument()));
269 ConstructorsClicked(getConstructorId());
273 //=================================================================================
274 // function : enterEvent()
276 //=================================================================================
277 void BuildGUI_SolidDlg::enterEvent( QEvent* )
279 if ( !mainFrame()->GroupConstructors->isEnabled() )
280 ActivateThisDialog();
284 //=================================================================================
285 // function : EnableNameField()
287 //=================================================================================
288 void BuildGUI_SolidDlg::EnableNameField( bool toEnable )
290 mainFrame()->GroupBoxName->setEnabled( toEnable );
293 //=================================================================================
294 // function : createOperation
296 //=================================================================================
297 GEOM::GEOM_IOperations_ptr BuildGUI_SolidDlg::createOperation()
299 return getGeomEngine()->GetIShapesOperations();
302 //=================================================================================
303 // function : isValid
305 //=================================================================================
306 bool BuildGUI_SolidDlg::isValid (QString& msg)
308 bool ok = !myShells.isEmpty();
310 GEOM::MeasureOpPtr anOp;
311 anOp.take(myGeomGUI->GetGeomGen()->GetIMeasureOperations());
312 if (getConstructorId() == 0 && (!GroupSolid->CheckButton1->isChecked() || myShells.count() == 1)) {
313 for (int i = 0, n = myShells.count(); i < n && ok; i++) {
314 CORBA::String_var aRes = anOp->IsGoodForSolid(myShells[i].get());
315 if (strlen(aRes.in())) {
316 msg = QObject::tr(aRes.in()).arg(GEOMBase::GetName(myShells[i].get()));
325 //=================================================================================
326 // function : isClosed
327 // purpose : Check the object 'i' in myShells list is closed or unclosed
328 //=================================================================================
329 bool BuildGUI_SolidDlg::isClosed( GEOM::GEOM_Object_ptr shell )
333 GEOM::GEOM_IKindOfShape::shape_kind aKind;
334 GEOM::ListOfLong_var anInts;
335 GEOM::ListOfDouble_var aDbls;
337 if ( !CORBA::is_nil( shell ) ) {
338 GEOM::MeasureOpPtr anOp;
339 anOp.take( myGeomGUI->GetGeomGen()->GetIMeasureOperations() );
341 // Detect kind of shape and parameters
342 aKind = anOp->KindOfShape(shell, anInts, aDbls);
344 if ( anOp->IsDone() ) {
345 if ( anInts[0] == 1 )
347 else if ( anInts[0] == 2 )
351 MESSAGE ("KindOfShape Operation is NOT DONE!!!");
355 MESSAGE ("Shape is NULL!!!");
362 //=================================================================================
363 // function : execute
365 //=================================================================================
366 bool BuildGUI_SolidDlg::execute( ObjectList& objects )
368 GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
369 GEOM::GEOM_Object_var anObj;
371 switch (getConstructorId()) {
374 if ( GroupSolid->CheckButton1->isChecked() ) {
375 GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
376 objlist->length( myShells.count() );
377 for ( int i = 0; i < myShells.count(); i++ )
378 objlist[i] = myShells[i].copy();
380 anObj = anOper->MakeSolidShells( objlist.in() );
381 if ( !anObj->_is_nil() ) objects.push_back( anObj._retn() );
384 for ( int i = 0, n = myShells.count(); i< n; i++ ) {
385 anObj = anOper->MakeSolidShell( myShells[ i ].get() );
386 if ( !anObj->_is_nil() ) objects.push_back( anObj._retn() );
393 GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
394 objlist->length( myShells.count() );
395 for ( int i = 0; i < myShells.count(); i++ )
396 objlist[i] = myShells[i].copy();
398 anObj = anOper->MakeSolidFromConnectedFaces( objlist.in(), GroupFaces->CheckButton1->isChecked() );
399 if ( !anObj->_is_nil() ) objects.push_back( anObj._retn() );
408 //=================================================================================
409 // function : getSourceObjects
410 // purpose : virtual method to get source objects
411 //=================================================================================
412 QList<GEOM::GeomObjPtr> BuildGUI_SolidDlg::getSourceObjects()