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 : RepairGUI_GlueDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "RepairGUI_GlueDlg.h"
30 #include "DlgRef_1Sel_Ext.h"
31 #include "GEOMImpl_Types.hxx"
33 #include "QtxDblSpinBox.h"
34 #include "SalomeApp_Application.h"
35 #include "SalomeApp_SelectionMgr.h"
36 #include "SalomeApp_Study.h"
37 #include "SalomeApp_Tools.h"
39 #include "SUIT_Session.h"
40 #include "SUIT_MessageBox.h"
41 #include "SUIT_OverrideCursor.h"
43 #include "SALOME_ListIteratorOfListIO.hxx"
45 #include <TCollection_AsciiString.hxx>
47 #include <qapplication.h>
52 #define DEFAULT_TOLERANCE_VALUE 1e-07
54 //=================================================================================
55 // class : RepairGUI_GlueDlg()
56 // purpose : Constructs a RepairGUI_GlueDlg which is a child of 'parent', with the
57 // name 'name' and widget flags set to 'f'.
58 // The dialog will by default be modeless, unless you set 'modal' to
59 // TRUE to construct a modal dialog.
60 //=================================================================================
61 RepairGUI_GlueDlg::RepairGUI_GlueDlg(QWidget* parent, const char* name, bool modal, WFlags fl)
62 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
64 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_GLUE_FACES")));
65 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
67 setCaption(tr("GEOM_GLUE_TITLE"));
69 /***************************************************************/
70 GroupConstructors->setTitle(tr("GEOM_GLUE_TITLE"));
71 RadioButton1->setPixmap(image0);
72 RadioButton2->close(TRUE);
73 RadioButton3->close(TRUE);
75 GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
76 GroupPoints->GroupBox1->setTitle(tr("GEOM_GLUE"));
77 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
78 GroupPoints->PushButton1->setPixmap(image1);
79 GroupPoints->LineEdit1->setReadOnly( true );
81 Layout1->addWidget(GroupPoints, 2, 0);
83 QGridLayout* aLay = new QGridLayout( 0, 2, 2, 0, 6, "aLay" );
84 QLabel* aLbl1 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints->GroupBox1 );
85 myTolEdt = new QtxDblSpinBox( 0, 100, 1e-7, GroupPoints->GroupBox1 );//QAD_SpinBoxDbl( GroupPoints->GroupBox1, 0, 100, 1e-7, 10, 1e-10 );
86 myTolEdt->setPrecision( 10 );
87 myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
89 aLay->addWidget( aLbl1, 0, 0 );
90 aLay->addWidget( myTolEdt, 0, 1 );
92 GroupPoints->getGroupBoxLayout()->addLayout( aLay, 3, 0 );
93 /***************************************************************/
99 //=================================================================================
100 // function : ~RepairGUI_GlueDlg()
101 // purpose : Destroys the object and frees any allocated resources
102 //=================================================================================
103 RepairGUI_GlueDlg::~RepairGUI_GlueDlg()
108 //=================================================================================
111 //=================================================================================
112 void RepairGUI_GlueDlg::Init()
115 myEditCurrentArgument = GroupPoints->LineEdit1;
117 myObject = GEOM::GEOM_Object::_nil();
119 //myGeomGUI->SetState( 0 );
120 globalSelection( GEOM_COMPOUND );
122 /* signals and slots connections */
123 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
124 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
125 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
127 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
128 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
130 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
131 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
133 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
134 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
136 initName( tr( "GLUE_NEW_OBJ_NAME" ) );
140 //=================================================================================
141 // function : ClickOnOk()
142 // purpose : Same than click on apply but close this dialog.
143 //=================================================================================
144 void RepairGUI_GlueDlg::ClickOnOk()
146 if ( ClickOnApply() )
152 //=================================================================================
153 // function : ClickOnApply()
155 //=================================================================================
156 bool RepairGUI_GlueDlg::ClickOnApply()
158 if ( !onAcceptLocal() )
163 GroupPoints->LineEdit1->setText("");
164 myObject = GEOM::GEOM_Object::_nil();
166 globalSelection( GEOM_COMPOUND );
172 //=================================================================================
173 // function : ClickOnCancel()
175 //=================================================================================
176 void RepairGUI_GlueDlg::ClickOnCancel()
178 GEOMBase_Skeleton::ClickOnCancel();
182 //=================================================================================
183 // function : SelectionIntoArgument()
184 // purpose : Called when selection
185 //=================================================================================
186 void RepairGUI_GlueDlg::SelectionIntoArgument()
189 myEditCurrentArgument->setText("");
190 myObject = GEOM::GEOM_Object::_nil();
192 if ( IObjectCount() == 1 ) {
193 Handle(SALOME_InteractiveObject) anIO = firstIObject();
194 Standard_Boolean aRes;
195 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
197 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
201 //=================================================================================
202 // function : SetEditCurrentArgument()
204 //=================================================================================
205 void RepairGUI_GlueDlg::SetEditCurrentArgument()
207 const QObject* send = sender();
208 if ( send == GroupPoints->PushButton1 ) {
209 myEditCurrentArgument->setFocus();
210 SelectionIntoArgument();
215 //=================================================================================
216 // function : LineEditReturnPressed()
218 //=================================================================================
219 void RepairGUI_GlueDlg::LineEditReturnPressed()
221 const QObject* send = sender();
222 if( send == GroupPoints->LineEdit1 ) {
223 myEditCurrentArgument = GroupPoints->LineEdit1;
224 GEOMBase_Skeleton::LineEditReturnPressed();
229 //=================================================================================
230 // function : DeactivateActiveDialog()
232 //=================================================================================
233 void RepairGUI_GlueDlg::DeactivateActiveDialog()
235 //myGeomGUI->SetState( -1 );
236 GEOMBase_Skeleton::DeactivateActiveDialog();
240 //=================================================================================
241 // function : ActivateThisDialog()
243 //=================================================================================
244 void RepairGUI_GlueDlg::ActivateThisDialog()
246 GEOMBase_Skeleton::ActivateThisDialog();
247 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
248 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
250 GroupPoints->LineEdit1->setText("");
251 myObject = GEOM::GEOM_Object::_nil();
253 //myGeomGUI->SetState( 0 );
254 globalSelection( GEOM_COMPOUND );
258 //=================================================================================
259 // function : enterEvent()
260 // purpose : Mouse enter onto the dialog to activate it
261 //=================================================================================
262 void RepairGUI_GlueDlg::enterEvent(QEvent* e)
264 if ( !GroupConstructors->isEnabled() )
265 ActivateThisDialog();
269 //=================================================================================
270 // function : closeEvent()
272 //=================================================================================
273 void RepairGUI_GlueDlg::closeEvent(QCloseEvent* e)
275 //myGeomGUI->SetState( -1 );
276 GEOMBase_Skeleton::closeEvent( e );
279 //=================================================================================
280 // function : createOperation
282 //=================================================================================
283 GEOM::GEOM_IOperations_ptr RepairGUI_GlueDlg::createOperation()
285 return getGeomEngine()->GetIShapesOperations( getStudyId() );
288 //=================================================================================
289 // function : isValid
291 //=================================================================================
292 bool RepairGUI_GlueDlg::isValid( QString& msg )
294 return !myObject->_is_nil() && ( IsPreview() || myTolEdt->value() > 0. );
297 //=================================================================================
298 // function : execute
300 //=================================================================================
301 bool RepairGUI_GlueDlg::execute( ObjectList& objects )
303 bool aResult = false;
304 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow
305 ( getOperation() )->MakeGlueFaces( myObject, myTolEdt->value() );
306 aResult = !anObj->_is_nil();
308 objects.push_back( anObj._retn() );
313 //================================================================
314 // Function : clearShapeBufferLocal
316 //================================================================
317 void RepairGUI_GlueDlg::clearShapeBufferLocal( GEOM::GEOM_Object_ptr theObj )
319 if ( CORBA::is_nil( theObj ) )
322 string IOR = myGeomGUI->getApp()->orb()->object_to_string( theObj );
323 TCollection_AsciiString asciiIOR( strdup( IOR.c_str() ) );
324 myGeomGUI->GetShapeReader().RemoveShapeFromBuffer( asciiIOR );
326 if ( !getStudy() || !( getStudy()->studyDS() ) )
329 _PTR(Study) aStudy = getStudy()->studyDS();
330 _PTR(SObject) aSObj ( aStudy->FindObjectIOR( IOR ) );
334 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
335 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
336 _PTR(GenericAttribute) anAttr;
337 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
338 _PTR(AttributeIOR) anIOR ( anAttr );
339 TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
340 myGeomGUI->GetShapeReader().RemoveShapeFromBuffer( asciiIOR );
345 //================================================================
346 // Function : onAccept
347 // Purpose : This method should be called from dialog's slots onOk() and onApply()
348 // It perfroms user input validation, then it
349 // performs a proper operation and manages transactions, etc.
350 //================================================================
351 bool RepairGUI_GlueDlg::onAcceptLocal( const bool publish, const bool useTransaction )
353 if ( !getStudy() || !( getStudy()->studyDS() ) )
356 _PTR(Study) aStudy = getStudy()->studyDS();
358 bool aLocked = aStudy->GetProperties()->IsLocked();
360 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
361 SUIT_MessageBox::warn1 ( (QWidget*)(SUIT_Session::session()->activeApplication()->desktop()),
362 QObject::tr("WRN_WARNING"),
363 QObject::tr("WRN_STUDY_LOCKED"),
364 QObject::tr("BUT_OK") );
369 if ( !isValid( msg ) ) {
374 erasePreview( false );
377 if ( ( !publish && !useTransaction ) || openCommand() ) {
379 SUIT_OverrideCursor wc;
381 SUIT_Session::session()->activeApplication()->putInfo( "" );
383 // JFA 28.12.2004 if ( !execute( objects ) || !getOperation()->IsDone() ) {
384 if ( !execute( objects ) ) { // JFA 28.12.2004 // To enable warnings
390 const int nbObjs = objects.size();
391 bool withChildren = false;
392 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
396 aName = strlen( getNewObjectName() ) ? GEOMBase::GetDefaultName( getNewObjectName() ) : GEOMBase::GetDefaultName( getPrefix( *it ) );
398 aName = getNewObjectName();
399 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
400 if ( aName.isEmpty() )
401 aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
403 addInStudy( *it, aName.latin1() );
404 withChildren = false;
405 display( *it, false );
407 else { // asv : fix of PAL6454. If publish==false, then the original shape was modified, and need to be re-cached in GEOM_Client
409 clearShapeBufferLocal( *it );
411 redisplay( *it, withChildren, false );
418 SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
424 // JFA 28.12.2004 BEGIN // To enable warnings
425 if ( !getOperation()->_is_nil() ) {
426 if ( !getOperation()->IsDone() ) {
428 QString msgw = QObject::tr( getOperation()->GetErrorCode() );
429 SUIT_MessageBox::warn1((QWidget*)(SUIT_Session::session()->activeApplication()->desktop()),
430 QObject::tr( "WRN_WARNING" ),
432 QObject::tr( "BUT_OK" ));
435 // JFA 28.12.2004 END
439 catch( const SALOME::SALOME_Exception& e ) {
440 SalomeApp_Tools::QtCatchCorbaException( e );