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
30 #include "RepairGUI_GlueDlg.h"
32 #include "DlgRef_1Sel_Ext.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_SpinBoxDbl.h"
36 #include "QAD_MessageBox.h"
37 #include "QAD_WaitCursor.h"
39 #include "OCCViewer_Viewer3d.h"
40 #include "SALOME_ListIteratorOfListIO.hxx"
41 #include "SALOMEGUI_QtCatchCorbaException.hxx"
43 #include "GEOMImpl_Types.hxx"
45 #define DEFAULT_TOLERANCE_VALUE 1e-07
48 //=================================================================================
49 // class : RepairGUI_GlueDlg()
50 // purpose : Constructs a RepairGUI_GlueDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // TRUE to construct a modal dialog.
54 //=================================================================================
55 RepairGUI_GlueDlg::RepairGUI_GlueDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
56 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
58 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_GLUE_FACES")));
59 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
61 setCaption(tr("GEOM_GLUE_TITLE"));
63 /***************************************************************/
64 GroupConstructors->setTitle(tr("GEOM_GLUE_TITLE"));
65 RadioButton1->setPixmap(image0);
66 RadioButton2->close(TRUE);
67 RadioButton3->close(TRUE);
69 GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
70 GroupPoints->GroupBox1->setTitle(tr("GEOM_GLUE"));
71 GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
72 GroupPoints->PushButton1->setPixmap(image1);
73 GroupPoints->LineEdit1->setReadOnly( true );
75 Layout1->addWidget(GroupPoints, 2, 0);
77 QGridLayout* aLay = new QGridLayout( 0, 2, 2, 0, 6, "aLay" );
78 QLabel* aLbl1 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints->GroupBox1 );
79 myTolEdt = new QAD_SpinBoxDbl( GroupPoints->GroupBox1, 0, 100, 1e-7, 10, 1e-10 );
80 myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
82 aLay->addWidget( aLbl1, 0, 0 );
83 aLay->addWidget( myTolEdt, 0, 1 );
85 GroupPoints->getGroupBoxLayout()->addLayout( aLay, 3, 0 );
86 /***************************************************************/
92 //=================================================================================
93 // function : ~RepairGUI_GlueDlg()
94 // purpose : Destroys the object and frees any allocated resources
95 //=================================================================================
96 RepairGUI_GlueDlg::~RepairGUI_GlueDlg()
101 //=================================================================================
104 //=================================================================================
105 void RepairGUI_GlueDlg::Init()
108 myEditCurrentArgument = GroupPoints->LineEdit1;
110 myObject = GEOM::GEOM_Object::_nil();
112 myGeomGUI->SetState( 0 );
113 globalSelection( GEOM_COMPOUND );
115 /* signals and slots connections */
116 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
117 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
118 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
120 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
121 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
123 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
124 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
126 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
128 initName( tr( "GLUE_NEW_OBJ_NAME" ) );
132 //=================================================================================
133 // function : ClickOnOk()
134 // purpose : Same than click on apply but close this dialog.
135 //=================================================================================
136 void RepairGUI_GlueDlg::ClickOnOk()
138 if ( ClickOnApply() )
144 //=================================================================================
145 // function : ClickOnApply()
147 //=================================================================================
148 bool RepairGUI_GlueDlg::ClickOnApply()
150 if ( !onAcceptLocal() )
155 GroupPoints->LineEdit1->setText("");
156 myObject = GEOM::GEOM_Object::_nil();
158 globalSelection( GEOM_COMPOUND );
164 //=================================================================================
165 // function : ClickOnCancel()
167 //=================================================================================
168 void RepairGUI_GlueDlg::ClickOnCancel()
170 GEOMBase_Skeleton::ClickOnCancel();
174 //=================================================================================
175 // function : SelectionIntoArgument()
176 // purpose : Called when selection
177 //=================================================================================
178 void RepairGUI_GlueDlg::SelectionIntoArgument()
181 myEditCurrentArgument->setText("");
182 myObject = GEOM::GEOM_Object::_nil();
184 if ( mySelection->IObjectCount() == 1 ) {
185 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
186 Standard_Boolean aRes;
187 myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
189 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
193 //=================================================================================
194 // function : SetEditCurrentArgument()
196 //=================================================================================
197 void RepairGUI_GlueDlg::SetEditCurrentArgument()
199 const QObject* send = sender();
200 if ( send == GroupPoints->PushButton1 ) {
201 myEditCurrentArgument->setFocus();
202 SelectionIntoArgument();
207 //=================================================================================
208 // function : LineEditReturnPressed()
210 //=================================================================================
211 void RepairGUI_GlueDlg::LineEditReturnPressed()
213 const QObject* send = sender();
214 if( send == GroupPoints->LineEdit1 ) {
215 myEditCurrentArgument = GroupPoints->LineEdit1;
216 GEOMBase_Skeleton::LineEditReturnPressed();
221 //=================================================================================
222 // function : DeactivateActiveDialog()
224 //=================================================================================
225 void RepairGUI_GlueDlg::DeactivateActiveDialog()
227 myGeomGUI->SetState( -1 );
228 GEOMBase_Skeleton::DeactivateActiveDialog();
232 //=================================================================================
233 // function : ActivateThisDialog()
235 //=================================================================================
236 void RepairGUI_GlueDlg::ActivateThisDialog()
238 GEOMBase_Skeleton::ActivateThisDialog();
239 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
241 GroupPoints->LineEdit1->setText("");
242 myObject = GEOM::GEOM_Object::_nil();
244 myGeomGUI->SetState( 0 );
245 globalSelection( GEOM_COMPOUND );
249 //=================================================================================
250 // function : enterEvent()
251 // purpose : Mouse enter onto the dialog to activate it
252 //=================================================================================
253 void RepairGUI_GlueDlg::enterEvent(QEvent* e)
255 if ( !GroupConstructors->isEnabled() )
256 ActivateThisDialog();
260 //=================================================================================
261 // function : closeEvent()
263 //=================================================================================
264 void RepairGUI_GlueDlg::closeEvent(QCloseEvent* e)
266 myGeomGUI->SetState( -1 );
267 GEOMBase_Skeleton::closeEvent( e );
270 //=================================================================================
271 // function : createOperation
273 //=================================================================================
274 GEOM::GEOM_IOperations_ptr RepairGUI_GlueDlg::createOperation()
276 return getGeomEngine()->GetIShapesOperations( getStudyId() );
279 //=================================================================================
280 // function : isValid
282 //=================================================================================
283 bool RepairGUI_GlueDlg::isValid( QString& msg )
285 return !myObject->_is_nil() && ( IsPreview() || myTolEdt->value() > 0. );
288 //=================================================================================
289 // function : execute
291 //=================================================================================
292 bool RepairGUI_GlueDlg::execute( ObjectList& objects )
294 bool aResult = false;
295 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow
296 ( getOperation() )->MakeGlueFaces( myObject, myTolEdt->value() );
297 aResult = !anObj->_is_nil();
299 objects.push_back( anObj._retn() );
304 //================================================================
305 // Function : clearShapeBufferLocal
307 //================================================================
308 void RepairGUI_GlueDlg::clearShapeBufferLocal( GEOM::GEOM_Object_ptr theObj )
310 if ( CORBA::is_nil( theObj ) )
313 string IOR = GeometryGUI::GetORB()->object_to_string( theObj );
314 TCollection_AsciiString asciiIOR( strdup( IOR.c_str() ) );
315 GeometryGUI::GetGeomGUI()->GetShapeReader().RemoveShapeFromBuffer( asciiIOR );
317 if ( !getStudy() || CORBA::is_nil( getStudy()->getStudyDocument() ) )
320 SALOMEDS::Study_var aStudy = getStudy()->getStudyDocument();
321 SALOMEDS::SObject_var aSObj = aStudy->FindObjectIOR( IOR.c_str() );
322 if ( CORBA::is_nil( aSObj ) )
325 SALOMEDS::ChildIterator_var anIt = aStudy->NewChildIterator( aSObj );
326 for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
327 SALOMEDS::GenericAttribute_var anAttr;
328 if ( anIt->Value()->FindAttribute(anAttr, "AttributeIOR") ) {
329 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
330 TCollection_AsciiString asciiIOR( anIOR->Value() );
331 GeometryGUI::GetGeomGUI()->GetShapeReader().RemoveShapeFromBuffer( asciiIOR );
336 //================================================================
337 // Function : onAccept
338 // Purpose : This method should be called from dialog's slots onOk() and onApply()
339 // It perfroms user input validation, then it
340 // performs a proper operation and manages transactions, etc.
341 //================================================================
342 bool RepairGUI_GlueDlg::onAcceptLocal( const bool publish, const bool useTransaction )
344 QAD_Study* aDoc = QAD_Application::getDesktop()->getActiveStudy();
345 SALOMEDS::Study_var aStudy = aDoc->getStudyDocument();
347 bool aLocked = aStudy->GetProperties()->IsLocked();
349 MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
350 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
351 QObject::tr("WRN_WARNING"),
352 QObject::tr("WRN_STUDY_LOCKED"),
353 QObject::tr("BUT_OK") );
358 if ( !isValid( msg ) ) {
363 erasePreview( false );
366 if ( ( !publish && !useTransaction ) || openCommand() ) {
368 QAD_Application::getDesktop()->putInfo( "" );
370 // JFA 28.12.2004 if ( !execute( objects ) || !getOperation()->IsDone() ) {
371 if ( !execute( objects ) ) { // JFA 28.12.2004 // To enable warnings
377 const int nbObjs = objects.size();
378 bool withChildren = false;
379 for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
383 aName = strlen( getNewObjectName() ) ? GEOMBase::GetDefaultName( getNewObjectName() ) : GEOMBase::GetDefaultName( getPrefix( *it ) );
385 aName = getNewObjectName();
386 // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
387 if ( aName.isEmpty() )
388 aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
390 addInStudy( *it, aName.latin1() );
391 withChildren = false;
392 display( *it, false );
394 else { // asv : fix of PAL6454. If publish==false, then the original shape was modified, and need to be re-cached in GEOM_Client
396 clearShapeBufferLocal( *it );
398 redisplay( *it, withChildren, false );
405 QAD_Application::getDesktop()->putInfo( QObject::tr("GEOM_PRP_DONE") );
411 // JFA 28.12.2004 BEGIN // To enable warnings
412 if ( !getOperation()->_is_nil() ) {
413 if ( !getOperation()->IsDone() ) {
415 QString msgw = QObject::tr( getOperation()->GetErrorCode() );
416 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
417 QObject::tr( "WRN_WARNING" ),
419 QObject::tr( "BUT_OK" ));
422 // JFA 28.12.2004 END
426 catch( const SALOME::SALOME_Exception& e ) {
427 QtCatchCorbaException( e );