Back to index

salome-geom  6.5.0
GenerationGUI_FillingDlg.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   : GenerationGUI_FillingDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 //
00027 #include "GenerationGUI_FillingDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOMBase.h>
00032 
00033 #include <SUIT_ResourceMgr.h>
00034 #include <SUIT_Session.h>
00035 #include <SalomeApp_Application.h>
00036 #include <LightApp_SelectionMgr.h>
00037 
00038 #include <TopoDS_Iterator.hxx>
00039 #include <GEOMImpl_Types.hxx>
00040 
00041 //=================================================================================
00042 // class    : GenerationGUI_FillingDlg()
00043 // purpose  : Constructs a GenerationGUI_FillingDlg which is a child of 'parent', with the
00044 //            name 'name' and widget flags set to 'f'.
00045 //            The dialog will by default be modeless, unless you set 'modal' to
00046 //            TRUE to construct a modal dialog.
00047 //=================================================================================
00048 GenerationGUI_FillingDlg::GenerationGUI_FillingDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
00049                                                     bool modal, Qt::WindowFlags fl )
00050   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
00051 {
00052   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_FILLING" ) ) );
00053   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00054 
00055   setWindowTitle( tr( "GEOM_FILLING_TITLE" ) );
00056 
00057   /***************************************************************/
00058   mainFrame()->GroupConstructors->setTitle( tr ( "GEOM_FILLING" ) );
00059   mainFrame()->RadioButton1->setIcon( image0 );
00060   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
00061   mainFrame()->RadioButton2->close();
00062   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
00063   mainFrame()->RadioButton3->close();
00064 
00065   GroupPoints = new DlgRef_1Sel5Spin1Check( centralWidget() );
00066   GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
00067   GroupPoints->TextLabel1->setText( tr( "GEOM_FILLING_COMPOUND" ) );
00068   GroupPoints->TextLabel2->setText( tr( "GEOM_FILLING_MIN_DEG" ) );
00069   GroupPoints->TextLabel3->setText( tr( "GEOM_FILLING_TOL_2D" ) );
00070   GroupPoints->TextLabel4->setText( tr( "GEOM_FILLING_NB_ITER" ) );
00071   GroupPoints->TextLabel5->setText( tr( "GEOM_FILLING_MAX_DEG" ) );
00072   GroupPoints->TextLabel6->setText( tr( "GEOM_FILLING_TOL_3D" ) );
00073   GroupPoints->CheckBox1->setText( tr( "GEOM_FILLING_APPROX" ) );
00074   GroupPoints->TextLabel7->setText( tr( "GEOM_FILLING_METHOD" ) );
00075   GroupPoints->PushButton1->setIcon( image1 );
00076   GroupPoints->LineEdit1->setReadOnly( true );
00077 
00078   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00079   layout->setMargin( 0 ); layout->setSpacing( 6 );
00080   layout->addWidget( GroupPoints  );
00081   /***************************************************************/
00082 
00083   setHelpFileName( "create_filling_page.html" );
00084 
00085   /* Initialisations */
00086   Init();
00087 }
00088 
00089 //=================================================================================
00090 // function : ~GenerationGUI_FillingDlg()
00091 // purpose  : Destroys the object and frees any allocated resources
00092 //=================================================================================
00093 GenerationGUI_FillingDlg::~GenerationGUI_FillingDlg()
00094 {
00095   // no need to delete child widgets, Qt does it all for us
00096 }
00097 
00098 //=================================================================================
00099 // function : Init()
00100 // purpose  :
00101 //=================================================================================
00102 void GenerationGUI_FillingDlg::Init()
00103 {
00104   /* init variables */
00105   myEditCurrentArgument = GroupPoints->LineEdit1;
00106   GroupPoints->LineEdit1->setReadOnly( true );
00107 
00108   globalSelection( GEOM_COMPOUND );
00109 
00110   int SpecificStep1 = 1;
00111   double SpecificStep2 = 0.0001;
00112   /* min, max, step and decimals for spin boxes & initial values */
00113   initSpinBox( GroupPoints->SpinBox1, 2, MAX_NUMBER,  SpecificStep1 );
00114   initSpinBox( GroupPoints->SpinBox2, 0.00001, 10000.0, SpecificStep2, "len_tol_precision" );
00115   initSpinBox( GroupPoints->SpinBox3, 0, MAX_NUMBER,  SpecificStep1 );
00116   initSpinBox( GroupPoints->SpinBox4, 1, MAX_NUMBER,  SpecificStep1 );
00117   initSpinBox( GroupPoints->SpinBox5, 0.00001, 10000.0, SpecificStep2, "len_tol_precision" );
00118 
00119   GroupPoints->SpinBox1->setValue( 2 );
00120   GroupPoints->SpinBox2->setValue( 0.0001 );
00121   GroupPoints->SpinBox3->setValue( 0 );
00122   GroupPoints->SpinBox4->setValue( 5 );
00123   GroupPoints->SpinBox5->setValue( 0.0001 );
00124 
00125   GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_DEFAULT"));
00126   GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_USEORI"));
00127   GroupPoints->ComboBox1->addItem(tr("GEOM_FILLING_AUTO"));
00128 
00129   showOnlyPreviewControl();
00130 
00131   /* signals and slots connections */
00132   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00133   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00134 
00135   connect( GroupPoints->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
00136 
00137   connect( GroupPoints->ComboBox1, SIGNAL(activated(int)), this, SLOT(MethodChanged()));
00138 
00139   connect( GroupPoints->SpinBox1, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00140   connect( GroupPoints->SpinBox2, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00141   connect( GroupPoints->SpinBox3, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00142   connect( GroupPoints->SpinBox4, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00143   connect( GroupPoints->SpinBox5, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00144 
00145   connect( GroupPoints->CheckBox1, SIGNAL( stateChanged( int ) ),
00146            this, SLOT( ApproxChanged() ) );
00147 
00148   // san: Commented, as all spin boxes here either are integer or use specific non-default step value
00149   //connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
00150 
00151   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
00152            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00153 
00154   initName( tr( "GEOM_FILLING" ) );
00155   resize(100,100);
00156 }
00157 
00158 //=================================================================================
00159 // function : SetDoubleSpinBoxStep()
00160 // purpose  : Double spin box management
00161 //=================================================================================
00162 void GenerationGUI_FillingDlg::SetDoubleSpinBoxStep( double step )
00163 {
00164   GroupPoints->SpinBox2->setSingleStep(step);
00165   GroupPoints->SpinBox5->setSingleStep(step);
00166 }
00167 
00168 
00169 //=================================================================================
00170 // function : ClickOnOk()
00171 // purpose  :
00172 //=================================================================================
00173 void GenerationGUI_FillingDlg::ClickOnOk()
00174 {
00175   setIsApplyAndClose( true );
00176   if ( ClickOnApply() )
00177     ClickOnCancel();
00178 }
00179 
00180 
00181 //=================================================================================
00182 // function : ClickOnApply()
00183 // purpose  :
00184 //=================================================================================
00185 bool GenerationGUI_FillingDlg::ClickOnApply()
00186 {
00187   if ( !onAccept() )
00188     return false;
00189 
00190   initName();
00191   return true;
00192 }
00193 
00194 
00195 //=================================================================================
00196 // function : SelectionIntoArgument()
00197 // purpose  : Called when selection as changed or other case
00198 //=================================================================================
00199 void GenerationGUI_FillingDlg::SelectionIntoArgument()
00200 {
00201   erasePreview();
00202   myEditCurrentArgument->setText("");
00203 
00204   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
00205     myCompound = getSelected( TopAbs_COMPOUND );
00206     if ( myCompound ) {
00207       if ( myCompound->GetMaxShapeType() < GEOM::WIRE || myCompound->GetMinShapeType() > GEOM::EDGE ) {
00208        myCompound.nullify();
00209       }
00210       else {
00211        QString aName = GEOMBase::GetName( myCompound.get() );
00212        myEditCurrentArgument->setText( aName );
00213       }
00214     }
00215   }
00216 
00217   processPreview();
00218 }
00219 
00220 //=================================================================================
00221 // function : SetEditCurrentArgument()
00222 // purpose  :
00223 //=================================================================================
00224 void GenerationGUI_FillingDlg::SetEditCurrentArgument()
00225 {
00226   QPushButton* send = (QPushButton*)sender();
00227   globalSelection( GEOM_ALLSHAPES );
00228 
00229   if ( send == GroupPoints->PushButton1 ) {
00230     GroupPoints->LineEdit1->setFocus();
00231     myEditCurrentArgument = GroupPoints->LineEdit1;
00232     globalSelection( GEOM_COMPOUND );
00233     this->SelectionIntoArgument();
00234   }
00235 }
00236 
00237 
00238 //=================================================================================
00239 // function : ActivateThisDialog()
00240 // purpose  :
00241 //=================================================================================
00242 void GenerationGUI_FillingDlg::ActivateThisDialog()
00243 {
00244   GEOMBase_Skeleton::ActivateThisDialog();
00245   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
00246            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00247   globalSelection( GEOM_COMPOUND );
00248   processPreview();
00249 }
00250 
00251 
00252 //=================================================================================
00253 // function : enterEvent()
00254 // purpose  :
00255 //=================================================================================
00256 void GenerationGUI_FillingDlg::enterEvent( QEvent* )
00257 {
00258   if ( !mainFrame()->GroupConstructors->isEnabled() )
00259     ActivateThisDialog();
00260 }
00261 
00262 
00263 //=================================================================================
00264 // function : ValueChangedInSpinBox()
00265 // purpose  :
00266 //=================================================================================
00267 void GenerationGUI_FillingDlg::ValueChangedInSpinBox( double newValue )
00268 {
00269   processPreview();
00270 }
00271 
00272 //=================================================================================
00273 // function : MethodChanged
00274 // purpose  :
00275 //=================================================================================
00276 void GenerationGUI_FillingDlg::MethodChanged()
00277 {
00278   processPreview();
00279 }
00280 
00281 //=================================================================================
00282 // function : ApproxChanged()
00283 // purpose  :
00284 //=================================================================================
00285 void GenerationGUI_FillingDlg::ApproxChanged()
00286 {
00287   processPreview();
00288 }
00289 
00290 
00291 //=================================================================================
00292 // function : createOperation
00293 // purpose  :
00294 //=================================================================================
00295 GEOM::GEOM_IOperations_ptr GenerationGUI_FillingDlg::createOperation()
00296 {
00297   return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
00298 }
00299 
00300 //=================================================================================
00301 // function : isValid
00302 // purpose  :
00303 //=================================================================================
00304 bool GenerationGUI_FillingDlg::isValid( QString& msg )
00305 {
00306   bool ok = GroupPoints->SpinBox1->isValid( msg, !IsPreview() ) &&
00307             GroupPoints->SpinBox2->isValid( msg, !IsPreview() ) &&
00308             GroupPoints->SpinBox3->isValid( msg, !IsPreview() ) &&
00309             GroupPoints->SpinBox4->isValid( msg, !IsPreview() ) &&
00310             GroupPoints->SpinBox5->isValid( msg, !IsPreview() ) &&
00311             myCompound;
00312   return ok;
00313 }
00314 
00315 //=================================================================================
00316 // function : execute
00317 // purpose  :
00318 //=================================================================================
00319 bool GenerationGUI_FillingDlg::execute( ObjectList& objects )
00320 {
00321   GEOM::GEOM_I3DPrimOperations_var anOper =
00322     GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
00323 
00324   GEOM::filling_oper_method aMethod;
00325   switch (GroupPoints->ComboBox1->currentIndex())
00326   {
00327     case 0:  aMethod = GEOM::FOM_Default; break;
00328     case 1:  aMethod = GEOM::FOM_UseOri; break;
00329     case 2:  aMethod = GEOM::FOM_AutoCorrect; break;
00330     default: break;
00331   }
00332 
00333   GEOM::GEOM_Object_var anObj =
00334     anOper->MakeFilling( myCompound.get(), 
00335                       GroupPoints->SpinBox1->value(), 
00336                       GroupPoints->SpinBox4->value(), 
00337                       GroupPoints->SpinBox2->value(),
00338                       GroupPoints->SpinBox5->value(),
00339                          GroupPoints->SpinBox3->value(), 
00340                       aMethod,
00341                       GroupPoints->CheckBox1->isChecked() );
00342   if ( !anObj->_is_nil() )
00343   {
00344     if ( !IsPreview() )
00345     {
00346       QStringList aParameters;
00347       aParameters << GroupPoints->SpinBox1->text();
00348       aParameters << GroupPoints->SpinBox2->text();
00349       aParameters << GroupPoints->SpinBox3->text();
00350       aParameters << GroupPoints->SpinBox4->text();
00351       aParameters << GroupPoints->SpinBox5->text();
00352       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00353     }
00354     objects.push_back( anObj._retn() );
00355   }
00356 
00357   return true;
00358 }