Back to index

salome-geom  6.5.0
BuildGUI_FaceDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // GEOM GEOMGUI : GUI for Geometry component
00024 // File   : BuildGUI_FaceDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 
00027 #include "BuildGUI_FaceDlg.h"
00028 
00029 #include <GEOMImpl_Types.hxx>
00030 #include <TColStd_MapOfInteger.hxx>
00031 
00032 #include <DlgRef.h>
00033 #include <GeometryGUI.h>
00034 #include <GEOMBase.h>
00035 
00036 #include <SalomeApp_Application.h>
00037 #include <LightApp_SelectionMgr.h>
00038 
00039 #include <SUIT_ResourceMgr.h>
00040 #include <SUIT_Session.h>
00041 #include <SUIT_MessageBox.h>
00042 #include <SUIT_OverrideCursor.h>
00043 
00044 //=================================================================================
00045 // class    : BuildGUI_FaceDlg()
00046 // purpose  : Constructs a BuildGUI_FaceDlg which is a child of 'parent', with the 
00047 //            name 'name' and widget flags set to 'f'.
00048 //            The dialog will by default be modeless, unless you set 'modal' to
00049 //            TRUE to construct a modal dialog.
00050 //=================================================================================
00051 BuildGUI_FaceDlg::BuildGUI_FaceDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
00052   : GEOMBase_Skeleton( theGeometryGUI, parent )
00053 {
00054   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_FACE" ) ) );
00055   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00056 
00057   setWindowTitle( tr( "GEOM_FACE_TITLE" ) );
00058 
00059   /***************************************************************/
00060   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_FACE" ) );
00061   mainFrame()->RadioButton1->setIcon( image0 );
00062   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
00063   mainFrame()->RadioButton2->close();
00064   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
00065   mainFrame()->RadioButton3->close();
00066 
00067   GroupWire = new DlgRef_1Sel1Check( centralWidget() );
00068 
00069   GroupWire->GroupBox1->setTitle( tr( "GEOM_FACE_FFW" ) );
00070   GroupWire->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
00071   GroupWire->CheckButton1->setText( tr( "GEOM_FACE_OPT" ) );
00072   GroupWire->PushButton1->setIcon( image1 );
00073 
00074   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00075   layout->setMargin( 0 ); layout->setSpacing( 6 );
00076   layout->addWidget( GroupWire );
00077   /***************************************************************/
00078 
00079   setHelpFileName("create_face_page.html");
00080 
00081   /* Initialisations */
00082   Init();
00083 }
00084 
00085 
00086 //=================================================================================
00087 // function : ~BuildGUI_FaceDlg()
00088 // purpose  : Destroys the object and frees any allocated resources
00089 //=================================================================================
00090 BuildGUI_FaceDlg::~BuildGUI_FaceDlg()
00091 {
00092   // no need to delete child widgets, Qt does it all for us
00093 }
00094 
00095 
00096 //=================================================================================
00097 // function : Init()
00098 // purpose  :
00099 //=================================================================================
00100 void BuildGUI_FaceDlg::Init()
00101 {
00102   /* init variables */
00103   myEditCurrentArgument = GroupWire->LineEdit1;
00104   GroupWire->LineEdit1->setReadOnly( true );
00105 
00106   GroupWire->CheckButton1->setChecked( true );
00107   myWires.clear();
00108 
00109   TColStd_MapOfInteger aMap;
00110   aMap.Add( GEOM_EDGE );
00111   aMap.Add( GEOM_WIRE );
00112   globalSelection( aMap );
00113 
00114   /* signals and slots connections */
00115   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00116   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00117   connect( GroupWire->LineEdit1,   SIGNAL( returnPressed()), this, SLOT( LineEditReturnPressed() ) );
00118   connect( GroupWire->PushButton1, SIGNAL( clicked() ),      this, SLOT( SetEditCurrentArgument() ) );
00119   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
00120            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00121 
00122   initName( tr( "GEOM_FACE" ) );
00123   SelectionIntoArgument();
00124 }
00125 
00126 
00127 //=================================================================================
00128 // function : ClickOnOk()
00129 // purpose  :
00130 //=================================================================================
00131 void BuildGUI_FaceDlg::ClickOnOk()
00132 {
00133   setIsApplyAndClose( true );
00134   if ( ClickOnApply() )
00135     ClickOnCancel();
00136 }
00137 
00138 
00139 //=================================================================================
00140 // function : ClickOnApply()
00141 // purpose  :
00142 //=================================================================================
00143 bool BuildGUI_FaceDlg::ClickOnApply()
00144 {
00145   if ( !onAccept() )
00146     return false;
00147 
00148   initName();
00149   return true;
00150 }
00151 
00152 
00153 //=================================================================================
00154 // function : SelectionIntoArgument()
00155 // purpose  : Called when selection as changed or other case
00156 //=================================================================================
00157 void BuildGUI_FaceDlg::SelectionIntoArgument()
00158 {
00159   myEditCurrentArgument->setText( "" );
00160 
00161   QList<TopAbs_ShapeEnum> types;
00162   types << TopAbs_EDGE << TopAbs_WIRE;
00163   myWires = getSelected( types, -1 );
00164 
00165   if ( !myWires.isEmpty() ) {
00166     QString aName = myWires.count() > 1 ? QString( "%1_objects").arg( myWires.count() ) : GEOMBase::GetName( myWires[0].get() );
00167     myEditCurrentArgument->setText( aName );
00168   }
00169 }
00170 
00171 
00172 //=================================================================================
00173 // function : SetEditCurrentArgument()
00174 // purpose  :
00175 //=================================================================================
00176 void BuildGUI_FaceDlg::SetEditCurrentArgument()
00177 {
00178   QPushButton* send = (QPushButton*)sender();
00179   if ( send != GroupWire->PushButton1 )
00180     return;
00181   
00182   TColStd_MapOfInteger aMap;
00183   aMap.Add( GEOM_EDGE );
00184   aMap.Add( GEOM_WIRE );
00185   globalSelection( aMap );
00186 
00187   myEditCurrentArgument = GroupWire->LineEdit1;
00188 
00189   myEditCurrentArgument->setFocus();
00190   SelectionIntoArgument();
00191 }
00192 
00193 
00194 //=================================================================================
00195 // function : ActivateThisDialog()
00196 // purpose  :
00197 //=================================================================================
00198 void BuildGUI_FaceDlg::ActivateThisDialog()
00199 {
00200   GEOMBase_Skeleton::ActivateThisDialog();
00201   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
00202            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00203   TColStd_MapOfInteger aMap;
00204   aMap.Add( GEOM_EDGE );
00205   aMap.Add( GEOM_WIRE );
00206   globalSelection( aMap );
00207 }
00208 
00209 
00210 //=================================================================================
00211 // function : enterEvent()
00212 // purpose  :
00213 //=================================================================================
00214 void BuildGUI_FaceDlg::enterEvent( QEvent* )
00215 {
00216   if ( !mainFrame()->GroupConstructors->isEnabled() )
00217     ActivateThisDialog(); 
00218 }
00219 
00220 //=================================================================================
00221 // function : createOperation
00222 // purpose  :
00223 //=================================================================================
00224 GEOM::GEOM_IOperations_ptr BuildGUI_FaceDlg::createOperation()
00225 {
00226   return getGeomEngine()->GetIShapesOperations( getStudyId() );
00227 }
00228 
00229 //=================================================================================
00230 // function : isValid
00231 // purpose  :
00232 //=================================================================================
00233 bool BuildGUI_FaceDlg::isValid( QString& )
00234 {
00235   return !myWires.isEmpty();
00236 }
00237 
00238 //=================================================================================
00239 // function : execute
00240 // purpose  :
00241 //=================================================================================
00242 bool BuildGUI_FaceDlg::execute( ObjectList& objects )
00243 {
00244   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
00245 
00246   GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
00247   objlist->length( myWires.count() );
00248   for ( int i = 0; i < myWires.count(); i++ )
00249     objlist[i] = myWires[i].copy();
00250 
00251   GEOM::GEOM_Object_var anObj = anOper->MakeFaceWires( objlist.in(), GroupWire->CheckButton1->isChecked() );
00252 
00253   if (!anObj->_is_nil()) {
00254     objects.push_back(anObj._retn());
00255 
00256     if (!anOper->IsDone() && QString(anOper->GetErrorCode()) == "MAKE_FACE_TOLERANCE_TOO_BIG") {
00257       SUIT_OverrideCursor wc;
00258       wc.suspend();
00259       QString msgw = QObject::tr(anOper->GetErrorCode());
00260       SUIT_MessageBox::warning(this, tr("WRN_WARNING"), msgw, tr("BUT_OK"));
00261       anOper->SetErrorCode("PAL_NO_ERROR");
00262     }
00263   }
00264 
00265   return true;
00266 }