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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 "LightApp_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(GeometryGUI* theGeometryGUI, QWidget* parent,
62 const char* name, bool modal, WFlags fl)
63 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
64 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
66 QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_GLUE_FACES")));
67 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
69 setCaption(tr("GEOM_GLUE_TITLE"));
71 /***************************************************************/
72 GroupConstructors->setTitle(tr("GEOM_GLUE_TITLE"));
73 RadioButton1->setPixmap(image0);
74 RadioButton2->close(TRUE);
75 RadioButton3->close(TRUE);
77 GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
78 GroupPoints->GroupBox1->setTitle(tr("GEOM_GLUE"));
79 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
80 GroupPoints->PushButton1->setPixmap(image1);
81 GroupPoints->LineEdit1->setReadOnly( true );
83 Layout1->addWidget(GroupPoints, 2, 0);
85 QGridLayout* aLay = new QGridLayout( 0, 2, 2, 0, 6, "aLay" );
86 QLabel* aLbl1 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints->GroupBox1 );
87 myTolEdt = new QtxDblSpinBox( 0, 100, 1e-7, GroupPoints->GroupBox1 );
88 myTolEdt->setPrecision( 10 );
89 myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
91 aLay->addWidget( aLbl1, 0, 0 );
92 aLay->addWidget( myTolEdt, 0, 1 );
94 GroupPoints->getGroupBoxLayout()->addLayout( aLay, 3, 0 );
95 /***************************************************************/
97 setHelpFileName("glue_faces.htm");
103 //=================================================================================
104 // function : ~RepairGUI_GlueDlg()
105 // purpose : Destroys the object and frees any allocated resources
106 //=================================================================================
107 RepairGUI_GlueDlg::~RepairGUI_GlueDlg()
112 //=================================================================================
115 //=================================================================================
116 void RepairGUI_GlueDlg::Init()
119 myEditCurrentArgument = GroupPoints->LineEdit1;
121 myObject = GEOM::GEOM_Object::_nil();
123 //myGeomGUI->SetState( 0 );
124 globalSelection( GEOM_COMPOUND );
126 /* signals and slots connections */
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() )
151 //=================================================================================
152 // function : ClickOnApply()
154 //=================================================================================
155 bool RepairGUI_GlueDlg::ClickOnApply()
157 if ( !onAcceptLocal() )
162 GroupPoints->LineEdit1->setText("");
163 myObject = GEOM::GEOM_Object::_nil();
165 globalSelection( GEOM_COMPOUND );
171 //=================================================================================
172 // function : SelectionIntoArgument()
173 // purpose : Called when selection
174 //=================================================================================
175 void RepairGUI_GlueDlg::SelectionIntoArgument()
178 myEditCurrentArgument->setText("");
179 myObject = GEOM::GEOM_Object::_nil();
181 if ( IObjectCount() == 1 ) {
182 Handle(SALOME_InteractiveObject) anIO = firstIObject();
183 Standard_Boolean aRes;
184 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
186 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
190 //=================================================================================
191 // function : SetEditCurrentArgument()
193 //=================================================================================
194 void RepairGUI_GlueDlg::SetEditCurrentArgument()
196 const QObject* send = sender();
197 if ( send == GroupPoints->PushButton1 ) {
198 myEditCurrentArgument->setFocus();
199 SelectionIntoArgument();
204 //=================================================================================
205 // function : LineEditReturnPressed()
207 //=================================================================================
208 void RepairGUI_GlueDlg::LineEditReturnPressed()
210 const QObject* send = sender();
211 if( send == GroupPoints->LineEdit1 ) {
212 myEditCurrentArgument = GroupPoints->LineEdit1;
213 GEOMBase_Skeleton::LineEditReturnPressed();
218 //=================================================================================
219 // function : ActivateThisDialog()
221 //=================================================================================
222 void RepairGUI_GlueDlg::ActivateThisDialog()
224 GEOMBase_Skeleton::ActivateThisDialog();
225 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
226 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
228 GroupPoints->LineEdit1->setText("");
229 myObject = GEOM::GEOM_Object::_nil();
231 //myGeomGUI->SetState( 0 );
232 globalSelection( GEOM_COMPOUND );
236 //=================================================================================
237 // function : enterEvent()
238 // purpose : Mouse enter onto the dialog to activate it
239 //=================================================================================
240 void RepairGUI_GlueDlg::enterEvent(QEvent* e)
242 if ( !GroupConstructors->isEnabled() )
243 ActivateThisDialog();
247 //=================================================================================
248 // function : closeEvent()
250 //=================================================================================
251 void RepairGUI_GlueDlg::closeEvent(QCloseEvent* e)
253 //myGeomGUI->SetState( -1 );
254 GEOMBase_Skeleton::closeEvent( e );
257 //=================================================================================
258 // function : createOperation
260 //=================================================================================
261 GEOM::GEOM_IOperations_ptr RepairGUI_GlueDlg::createOperation()
263 return getGeomEngine()->GetIShapesOperations( getStudyId() );
266 //=================================================================================
267 // function : isValid
269 //=================================================================================
270 bool RepairGUI_GlueDlg::isValid( QString& msg )
272 return !myObject->_is_nil() && ( IsPreview() || myTolEdt->value() > 0. );
275 //=================================================================================
276 // function : execute
278 //=================================================================================
279 bool RepairGUI_GlueDlg::execute( ObjectList& objects )
281 bool aResult = false;
282 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow
283 ( getOperation() )->MakeGlueFaces( myObject, myTolEdt->value() );
284 aResult = !anObj->_is_nil();
286 objects.push_back( anObj._retn() );
291 //================================================================
292 // Function : clearShapeBufferLocal
294 //================================================================
295 void RepairGUI_GlueDlg::clearShapeBufferLocal( GEOM::GEOM_Object_ptr theObj )
297 if ( CORBA::is_nil( theObj ) )
300 string IOR = myGeomGUI->getApp()->orb()->object_to_string( theObj );
301 TCollection_AsciiString asciiIOR( strdup( IOR.c_str() ) );
302 myGeomGUI->GetShapeReader().RemoveShapeFromBuffer( asciiIOR );
304 if ( !getStudy() || !( getStudy()->studyDS() ) )
307 _PTR(Study) aStudy = getStudy()->studyDS();
308 _PTR(SObject) aSObj ( aStudy->FindObjectIOR( IOR ) );
312 _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
313 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
314 _PTR(GenericAttribute) anAttr;
315 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
316 _PTR(AttributeIOR) anIOR ( anAttr );
317 TCollection_AsciiString asciiIOR( (char*)anIOR->Value().c_str() );
318 myGeomGUI->GetShapeReader().RemoveShapeFromBuffer( asciiIOR );
323 //================================================================
324 // Function : onAccept
325 // Purpose : This method should be called from dialog's slots onOk() and onApply()
326 // It perfroms user input validation, then it
327 // performs a proper operation and manages transactions, etc.
328 //================================================================
329 bool RepairGUI_GlueDlg::onAcceptLocal( const bool publish, const bool useTransaction )
331 if ( !getStudy() || !( getStudy()->studyDS() ) )
334 _PTR(Study) aStudy = getStudy()->studyDS();
336 bool aLocked = aStudy->GetProperties()->IsLocked();
338 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
339 SUIT_MessageBox::warn1 ( (QWidget*)(SUIT_Session::session()->activeApplication()->desktop()),
340 QObject::tr("WRN_WARNING"),
341 QObject::tr("WRN_STUDY_LOCKED"),
342 QObject::tr("BUT_OK") );
347 if ( !isValid( msg ) ) {
352 erasePreview( false );
355 if ( ( !publish && !useTransaction ) || openCommand() ) {
357 SUIT_OverrideCursor wc;
359 SUIT_Session::session()->activeApplication()->putInfo( "" );
361 // JFA 28.12.2004 if ( !execute( objects ) || !getOperation()->IsDone() ) {
362 if ( !execute( objects ) ) { // JFA 28.12.2004 // To enable warnings
368 const int nbObjs = objects.size();
369 bool withChildren = false;
370 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
374 aName = strlen( getNewObjectName() ) ? GEOMBase::GetDefaultName( getNewObjectName() ) : GEOMBase::GetDefaultName( getPrefix( *it ) );
376 aName = getNewObjectName();
377 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
378 if ( aName.isEmpty() )
379 aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
381 addInStudy( *it, aName.latin1() );
382 withChildren = false;
383 display( *it, false );
385 else { // asv : fix of PAL6454. If publish==false, then the original shape was modified, and need to be re-cached in GEOM_Client
387 clearShapeBufferLocal( *it );
389 redisplay( *it, withChildren, false );
396 SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
402 // JFA 28.12.2004 BEGIN // To enable warnings
403 if ( !getOperation()->_is_nil() ) {
404 if ( !getOperation()->IsDone() ) {
406 QString msgw = QObject::tr( getOperation()->GetErrorCode() );
407 SUIT_MessageBox::warn1((QWidget*)(SUIT_Session::session()->activeApplication()->desktop()),
408 QObject::tr( "WRN_WARNING" ),
410 QObject::tr( "BUT_OK" ));
413 // JFA 28.12.2004 END
417 catch( const SALOME::SALOME_Exception& e ) {
418 SalomeApp_Tools::QtCatchCorbaException( e );