Back to index

salome-geom  6.5.0
BuildGUI_WireDlg.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_WireDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 //
00027 #include "BuildGUI_WireDlg.h"
00028 
00029 #include <GEOMImpl_Types.hxx>
00030 
00031 #include <DlgRef.h>
00032 #include <GeometryGUI.h>
00033 #include <GEOMBase.h>
00034 
00035 #include <SUIT_ResourceMgr.h>
00036 #include <SUIT_Session.h>
00037 #include <SalomeApp_Application.h>
00038 #include <LightApp_SelectionMgr.h>
00039 #include <SALOME_ListIteratorOfListIO.hxx>
00040 
00041 #include <TColStd_MapOfInteger.hxx>
00042 #include <TColStd_IndexedMapOfInteger.hxx>
00043 #include <TopTools_IndexedMapOfShape.hxx>
00044 #include <Precision.hxx>
00045 
00046 //=================================================================================
00047 // class    : BuildGUI_WireDlg()
00048 // purpose  : Constructs a BuildGUI_WireDlg which is a child of 'parent', with the 
00049 //            name 'name' and widget flags set to 'f'.
00050 //            The dialog will by default be modeless, unless you set 'modal' to
00051 //            TRUE to construct a modal dialog.
00052 //=================================================================================
00053 BuildGUI_WireDlg::BuildGUI_WireDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
00054   : GEOMBase_Skeleton( theGeometryGUI, parent )
00055 {
00056   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_WIRE" ) ) );
00057   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00058 
00059   setWindowTitle( tr( "GEOM_WIRE_TITLE" ) );
00060 
00061   /***************************************************************/
00062   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_WIRE" ) );
00063   mainFrame()->RadioButton1->setIcon( image0 );
00064   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
00065   mainFrame()->RadioButton2->close();
00066   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
00067   mainFrame()->RadioButton3->close();
00068 
00069   GroupType = new DlgRef_3Radio( centralWidget() );
00070   GroupType->GroupBox1->setTitle( tr( "GEOM_OBJECT_TYPE" ) );
00071   GroupType->RadioButton1->setText( tr( "GEOM_EDGE" ) );
00072   GroupType->RadioButton2->setText( tr( "GEOM_WIRE" ) );
00073   GroupType->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
00074   GroupType->RadioButton3->close();
00075 
00076   GroupArgs = new DlgRef_1Sel1Spin( centralWidget() );
00077   GroupArgs->GroupBox1->setTitle( tr( "GEOM_WIRE_CONNECT" ) );
00078   GroupArgs->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
00079   GroupArgs->PushButton1->setIcon( image1 );
00080   GroupArgs->LineEdit1->setReadOnly( true );
00081 
00082   GroupArgs->TextLabel2->setText( tr( "GEOM_TOLERANCE" ) );
00083   double SpecificStep = 0.0001;
00084   double prec = Precision::Confusion();
00085   initSpinBox(GroupArgs->SpinBox_DX, prec, MAX_NUMBER, SpecificStep, "len_tol_precision" );
00086   GroupArgs->SpinBox_DX->setValue(prec);
00087 
00088   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00089   layout->setMargin( 0 ); layout->setSpacing( 6 );
00090   layout->addWidget( GroupType );
00091   layout->addWidget( GroupArgs );
00092   /***************************************************************/
00093 
00094   setHelpFileName( "create_wire_page.html" );
00095 
00096   /* Initialisations */
00097   Init();
00098 }
00099 
00100 
00101 //=================================================================================
00102 // function : ~BuildGUI_WireDlg()
00103 // purpose  : Destroys the object and frees any allocated resources
00104 //=================================================================================
00105 BuildGUI_WireDlg::~BuildGUI_WireDlg()
00106 {
00107   // no need to delete child widgets, Qt does it all for us
00108 }
00109 
00110 
00111 //=================================================================================
00112 // function : Init()
00113 // purpose  :
00114 //=================================================================================
00115 void BuildGUI_WireDlg::Init()
00116 {
00117   /* init variables */
00118   myEditCurrentArgument = GroupArgs->LineEdit1;
00119   GroupArgs->LineEdit1->setReadOnly( true );
00120   GroupType->RadioButton1->setChecked(true);
00121   
00122   myEdgesAndWires.clear();
00123 
00124   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
00125 
00126   /* signals and slots connections */
00127   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00128   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00129   connect( GroupArgs->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
00130   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
00131            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00132 
00133   connect( GroupType->RadioButton1, SIGNAL( clicked() ), this, SLOT( TypeButtonClicked() ) );
00134   connect( GroupType->RadioButton2, SIGNAL( clicked() ), this, SLOT( TypeButtonClicked() ) );
00135 
00136   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
00137   connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
00138   
00139   initName( tr( "GEOM_WIRE" ) );
00140   SelectionIntoArgument();
00141 }
00142 
00143 
00144 //=================================================================================
00145 // function : ClickOnOk()
00146 // purpose  :
00147 //=================================================================================
00148 void BuildGUI_WireDlg::ClickOnOk()
00149 {
00150   setIsApplyAndClose( true );
00151   if ( ClickOnApply() )
00152     ClickOnCancel();
00153 }
00154 
00155 
00156 //=================================================================================
00157 // function : ClickOnApply()
00158 // purpose  :
00159 //=================================================================================
00160 bool BuildGUI_WireDlg::ClickOnApply()
00161 {
00162   if ( !onAccept() )
00163     return false;
00164 
00165   initName();
00166   TypeButtonClicked();
00167   myEdgesAndWires.clear();
00168   myEditCurrentArgument->setText( "" );
00169   return true;
00170 }
00171 
00172 //=================================================================================
00173 // function : TypeBittonClicked()
00174 // purpose  : Radio button management
00175 //=================================================================================
00176 void BuildGUI_WireDlg::TypeButtonClicked()
00177 {
00178   if ( GroupType->RadioButton1->isChecked() ) {
00179     globalSelection(); // close local contexts, if any
00180     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
00181     GroupArgs->TextLabel1->setText( tr( "GEOM_EDGE" ) );
00182   }
00183   else if ( GroupType->RadioButton2->isChecked() ) {
00184     globalSelection(); // close local contexts, if any
00185     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_WIRE );
00186     GroupArgs->TextLabel1->setText( tr( "GEOM_WIRE" ) );
00187   }
00188   SelectionIntoArgument();
00189 }
00190 
00191 //=================================================================================
00192 // function : SelectionIntoArgument()
00193 // purpose  : Called when selection as changed or other case
00194 //=================================================================================
00195 void BuildGUI_WireDlg::SelectionIntoArgument()
00196 {
00197   myEditCurrentArgument->setText( "" );
00198 
00199   QList<TopAbs_ShapeEnum> types;
00200   types << TopAbs_EDGE << TopAbs_WIRE;
00201   myEdgesAndWires = getSelected( types, -1 );
00202 
00203   if ( !myEdgesAndWires.isEmpty() ) {
00204     QString aName = myEdgesAndWires.count() > 1 ? QString( "%1_objects").arg( myEdgesAndWires.count() ) : GEOMBase::GetName( myEdgesAndWires[0].get() );
00205     myEditCurrentArgument->setText( aName );
00206   }
00207 }
00208 
00209 
00210 //=================================================================================
00211 // function : SetEditCurrentArgument()
00212 // purpose  :
00213 //=================================================================================
00214 void BuildGUI_WireDlg::SetEditCurrentArgument()
00215 {
00216   QPushButton* send = (QPushButton*)sender();
00217   if ( send != GroupArgs->PushButton1 )
00218     return;
00219 
00220   TypeButtonClicked();
00221   myEditCurrentArgument = GroupArgs->LineEdit1;
00222 
00223   myEditCurrentArgument->setFocus();
00224   SelectionIntoArgument();
00225 }
00226 
00227 
00228 //=================================================================================
00229 // function : ActivateThisDialog()
00230 // purpose  :
00231 //=================================================================================
00232 void BuildGUI_WireDlg::ActivateThisDialog()
00233 {
00234   GEOMBase_Skeleton::ActivateThisDialog();
00235   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
00236            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00237 
00238   TypeButtonClicked();
00239 }
00240 
00241 //=================================================================================
00242 // function : DeactivateActiveDialog()
00243 // purpose  : public slot to deactivate if active
00244 //=================================================================================
00245 void BuildGUI_WireDlg::DeactivateActiveDialog()
00246 {
00247   GEOMBase_Skeleton::DeactivateActiveDialog();
00248 }
00249 
00250 //=================================================================================
00251 // function : enterEvent()
00252 // purpose  :
00253 //=================================================================================
00254 void BuildGUI_WireDlg::enterEvent( QEvent* )
00255 {
00256   if ( !mainFrame()->GroupConstructors->isEnabled() )
00257     ActivateThisDialog();
00258 }
00259 
00260 //=================================================================================
00261 // function : createOperation
00262 // purpose  :
00263 //=================================================================================
00264 GEOM::GEOM_IOperations_ptr BuildGUI_WireDlg::createOperation()
00265 {
00266   return getGeomEngine()->GetIShapesOperations( getStudyId() );
00267 }
00268 
00269 //=================================================================================
00270 // function : isValid
00271 // purpose  :
00272 //=================================================================================
00273 bool BuildGUI_WireDlg::isValid (QString& msg)
00274 {
00275   return GroupArgs->SpinBox_DX->isValid(msg, !IsPreview()) && !myEdgesAndWires.isEmpty();
00276 }
00277 
00278 //=================================================================================
00279 // function : execute
00280 // purpose  :
00281 //=================================================================================
00282 bool BuildGUI_WireDlg::execute (ObjectList& objects)
00283 {
00284   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
00285 
00286   GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
00287   objlist->length( myEdgesAndWires.count() );
00288   for ( int i = 0; i < myEdgesAndWires.count(); i++ )
00289     objlist[i] = myEdgesAndWires[i].copy();
00290 
00291   GEOM::GEOM_Object_var anObj = anOper->MakeWire(objlist.in(), GroupArgs->SpinBox_DX->value());
00292 
00293   if (!anObj->_is_nil())
00294     objects.push_back(anObj._retn());
00295 
00296   return true;
00297 }
00298 
00299 //=================================================================================
00300 // function : addSubshapeToStudy
00301 // purpose  : virtual method to add new SubObjects if local selection
00302 //=================================================================================
00303 void BuildGUI_WireDlg::addSubshapesToStudy()
00304 {
00305   for ( int i = 0; i < myEdgesAndWires.count(); i++ )
00306     GEOMBase::PublishSubObject( myEdgesAndWires[i].get() );
00307 }