Back to index

salome-geom  6.5.0
BasicGUI_CurveDlg.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   : BasicGUI_CurveDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 
00027 #include "BasicGUI_CurveDlg.h"
00028 #include "BasicGUI_ParamCurveWidget.h"
00029 
00030 #include <DlgRef.h>
00031 #include <GeometryGUI.h>
00032 #include <GEOMBase.h>
00033 
00034 #include <SUIT_ResourceMgr.h>
00035 #include <SUIT_Session.h>
00036 #include <SalomeApp_Application.h>
00037 #include <SalomeApp_Study.h>
00038 #include <LightApp_SelectionMgr.h>
00039 
00040 #include <SALOME_ListIteratorOfListIO.hxx>
00041 #include <SALOME_ListIO.hxx>
00042 
00043 #include <TopoDS_Shape.hxx>
00044 #include <TopoDS.hxx>
00045 #include <TopExp.hxx>
00046 #include <TColStd_IndexedMapOfInteger.hxx>
00047 #include <TopTools_IndexedMapOfShape.hxx>
00048 
00049 #include <GEOMImpl_Types.hxx>
00050 
00051 //=================================================================================
00052 // class    : BasicGUI_CurveDlg()
00053 // purpose  : Constructs a BasicGUI_CurveDlg which is a child of 'parent', with the
00054 //            name 'name' and widget flags set to 'f'.
00055 //            The dialog will by default be modeless, unless you set 'modal' to
00056 //            TRUE to construct a modal dialog.
00057 //=================================================================================
00058 BasicGUI_CurveDlg::BasicGUI_CurveDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
00059                                       bool modal, Qt::WindowFlags fl )
00060   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
00061 {
00062   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_POLYLINE" ) ) );
00063   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SPLINE" ) ) );
00064   QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BEZIER" ) ) );
00065   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00066 
00067   setWindowTitle( tr( "GEOM_CURVE_TITLE" ) );
00068 
00069   /***************************************************************/
00070   mainFrame()->RadioButton1->setIcon( image0 );
00071   mainFrame()->RadioButton2->setIcon( image3 );
00072   mainFrame()->RadioButton3->setIcon( image2 );
00073 
00074   QGroupBox* creationModeCroup = new QGroupBox(this);
00075   QButtonGroup* bg = new QButtonGroup(this);
00076 
00077   creationModeCroup->setTitle( tr( "GEOM_CURVE_CRMODE" ) );  
00078   QHBoxLayout * creationModeLayout = new QHBoxLayout(creationModeCroup);
00079   myBySelectionBtn = new QRadioButton(  tr( "GEOM_CURVE_SELECTION" ) ,creationModeCroup );
00080   myAnaliticalBtn = new QRadioButton(  tr( "GEOM_CURVE_ANALITICAL" ) ,creationModeCroup );
00081 
00082   bg->addButton(myBySelectionBtn);
00083   bg->addButton(myAnaliticalBtn);
00084   
00085   creationModeLayout->addWidget(myBySelectionBtn);
00086   creationModeLayout->addWidget(myAnaliticalBtn);
00087 
00088   GroupPoints = new DlgRef_1Sel3Check( centralWidget() );
00089 
00090   GroupPoints->GroupBox1->setTitle( tr( "GEOM_NODES" ) );
00091   GroupPoints->TextLabel1->setText( tr( "GEOM_POINTS" ) );
00092   GroupPoints->PushButton1->setIcon( image1 );
00093   GroupPoints->PushButton1->setDown( true );
00094 
00095   GroupPoints->LineEdit1->setReadOnly( true );
00096 
00097   GroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
00098   GroupPoints->CheckButton1->setChecked(false);
00099   //GroupPoints->CheckButton1->hide();
00100 
00101   GroupPoints->CheckButton2->setText( tr( "GEOM_IS_REORDER" ) );
00102   GroupPoints->CheckButton2->setChecked(false);
00103   GroupPoints->CheckButton2->hide();
00104 
00105   GroupPoints->CheckButton3->hide();
00106 
00107   myParams = new BasicGUI_ParamCurveWidget( centralWidget() );
00108 
00109   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00110   layout->setMargin( 0 ); layout->setSpacing( 6 );
00111   layout->addWidget( creationModeCroup );
00112   layout->addWidget( GroupPoints );
00113   layout->addWidget( myParams );
00114   /***************************************************************/
00115 
00116   setHelpFileName( "create_curve_page.html" );
00117 
00118   Init();
00119 }
00120 
00121 
00122 //=================================================================================
00123 // function : ~BasicGUI_CurveDlg()
00124 // purpose  : Destroys the object and frees any allocated resources
00125 //=================================================================================
00126 BasicGUI_CurveDlg::~BasicGUI_CurveDlg()
00127 {
00128 }
00129 
00130 
00131 //=================================================================================
00132 // function : Init()
00133 // purpose  :
00134 //=================================================================================
00135 void BasicGUI_CurveDlg::Init()
00136 {
00137   /* init variables */
00138   myEditCurrentArgument = GroupPoints->LineEdit1;
00139 
00140   myPoints.clear();
00141 
00142   globalSelection(); // close local contexts, if any
00143   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
00144 
00145   showOnlyPreviewControl();
00146   myBySelectionBtn->setChecked(true);
00147 
00148   /* Get setting of step value from file configuration */
00149   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
00150   double step = resMgr ? resMgr->doubleValue( "Geometry", "SettingsGeomStep", 10. ) : 10.;
00151 
00152   double aMax( 100. ), aMin( 0.0 );
00153 
00154   /* min, max, step and decimals for spin boxes & initial values */
00155   initSpinBox( myParams->myPMin, COORD_MIN, COORD_MAX, step, "length_precision" );
00156   initSpinBox( myParams->myPMax, COORD_MIN, COORD_MAX, step, "length_precision" );
00157   myParams->myPStep->setValue( 10 );
00158   myParams->myPStep->setMaximum( 999 );
00159   myParams->myPStep->setSingleStep( 10 );
00160   myParams->myPMin->setValue( aMin );
00161   myParams->myPMax->setValue( aMax );
00162   myParams->myPStep->setValue( step );
00163   myParams->myXExpr->setText("t");
00164   myParams->myYExpr->setText("t");
00165   myParams->myZExpr->setText("t");
00166   
00167   myParams->hide();
00168 
00169   /* signals and slots connections */
00170   connect( myGeomGUI,        SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog( ) ) );
00171   connect( myGeomGUI,        SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
00172 
00173   connect( buttonOk(),       SIGNAL( clicked() ),                      this, SLOT( ClickOnOk() ) );
00174   connect( buttonApply(),    SIGNAL( clicked() ),                      this, SLOT( ClickOnApply() ) );
00175 
00176   connect( this,             SIGNAL( constructorsClicked( int ) ),     this, SLOT( ConstructorsClicked( int ) ) );
00177 
00178   connect( GroupPoints->PushButton1,  SIGNAL( clicked() ),             this, SLOT( SetEditCurrentArgument() ) );
00179 
00180   connect( GroupPoints->CheckButton1, SIGNAL( toggled(bool) ),         this, SLOT( CheckButtonToggled() ) );
00181   connect( GroupPoints->CheckButton2, SIGNAL( toggled(bool) ),         this, SLOT( CheckButtonToggled() ) );
00182 
00183   connect( myGeomGUI->getApp()->selectionMgr(),
00184            SIGNAL( currentSelectionChanged() ),                        this, SLOT( SelectionIntoArgument() ) );
00185 
00186   connect( myBySelectionBtn, SIGNAL( clicked() ),                      this, SLOT( CreationModeChanged() ) );
00187   connect( myAnaliticalBtn,  SIGNAL( clicked() ),                      this, SLOT( CreationModeChanged() ) );
00188 
00189   connect(myParams->myPMin,  SIGNAL(valueChanged(double)),             this, SLOT(ValueChangedInSpinBox(double)));
00190   connect(myParams->myPMax,  SIGNAL(valueChanged(double)),             this, SLOT(ValueChangedInSpinBox(double)));
00191   connect(myParams->myPStep, SIGNAL(valueChanged(int)),                this, SLOT(ValueChangedInSpinBox(int)));
00192 
00193   connect(myParams->myXExpr, SIGNAL(editingFinished()),                this, SLOT(OnEditingFinished()));
00194   connect(myParams->myYExpr, SIGNAL(editingFinished()),                this, SLOT(OnEditingFinished()));
00195   connect(myParams->myZExpr, SIGNAL(editingFinished()),                this, SLOT(OnEditingFinished()));
00196 
00197   initName( tr( "GEOM_CURVE" ) );
00198   resize(100,100);
00199   ConstructorsClicked( 0 );  
00200 }
00201 
00202 //=================================================================================
00203 // function : ConstructorsClicked()
00204 // purpose  :
00205 //=================================================================================
00206 void BasicGUI_CurveDlg::ConstructorsClicked( int id )
00207 {
00208   QString aTitle = tr( id == 0 ? "GEOM_POLYLINE" : id == 1 ? "GEOM_BEZIER" : "GEOM_INTERPOL" );
00209   mainFrame()->GroupConstructors->setTitle( aTitle );
00210 
00211   if (id == 0) { // polyline (wire)
00212     //GroupPoints->CheckButton1->hide();
00213     GroupPoints->CheckButton1->setText( tr( "GEOM_BUILD_CLOSED_WIRE" ) );
00214     GroupPoints->CheckButton2->hide();
00215   }
00216   else if (id == 1) { // bezier
00217     //GroupPoints->CheckButton1->hide();
00218     GroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
00219     GroupPoints->CheckButton2->hide();
00220   }
00221   else { // b-spline
00222     //GroupPoints->CheckButton1->show();
00223     GroupPoints->CheckButton1->setText( tr( "GEOM_IS_CLOSED" ) );
00224     GroupPoints->CheckButton2->show();
00225   }
00226 
00227   myPoints.clear();
00228 
00229   myEditCurrentArgument->setText( "" );
00230   qApp->processEvents();
00231   updateGeometry();
00232   resize( minimumSizeHint() );
00233   SelectionIntoArgument();
00234 }
00235 
00236 
00237 //=================================================================================
00238 // function : SetEditCurrentArgument()
00239 // purpose  :
00240 //=================================================================================
00241 void BasicGUI_CurveDlg::SetEditCurrentArgument()
00242 {
00243   if ( sender() == GroupPoints->PushButton1 )
00244     myEditCurrentArgument = GroupPoints->LineEdit1;
00245   myEditCurrentArgument->setFocus();
00246   SelectionIntoArgument();
00247 }
00248 
00249 //=================================================================================
00250 // function : CheckButtonToggled()
00251 // purpose  :
00252 //=================================================================================
00253 void BasicGUI_CurveDlg::CheckButtonToggled()
00254 {
00255   processPreview();
00256 }
00257 
00258 //=================================================================================
00259 // function : ClickOnOk()
00260 // purpose  :
00261 //=================================================================================
00262 void BasicGUI_CurveDlg::ClickOnOk()
00263 {
00264   setIsApplyAndClose( true );
00265   if ( ClickOnApply() )
00266     ClickOnCancel();
00267 }
00268 
00269 //=================================================================================
00270 // function : ClickOnApply()
00271 // purpose  :
00272 //=================================================================================
00273 bool BasicGUI_CurveDlg::ClickOnApply()
00274 {
00275   if ( !onAccept() )
00276     return false;
00277 
00278   initName();
00279   globalSelection(); // close local contexts, if any
00280   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
00281   return true;
00282 }
00283 
00284 static void synchronize( QList<GEOM::GeomObjPtr>& left, QList<GEOM::GeomObjPtr>& right )
00285 {
00286   // 1. remove items from the "left" list that are not in the "right" list
00287   QMutableListIterator<GEOM::GeomObjPtr> it1( left );
00288   while ( it1.hasNext() ) {
00289     GEOM::GeomObjPtr o1 = it1.next();
00290     bool found = false;
00291     QMutableListIterator<GEOM::GeomObjPtr> it2( right );
00292     while ( it2.hasNext() && !found )
00293       found = o1 == it2.next();
00294     if ( !found )
00295       it1.remove();
00296   }
00297   // 2. add items from the "right" list that are not in the "left" list (to keep selection order)
00298   it1 = right;
00299   while ( it1.hasNext() ) {
00300     GEOM::GeomObjPtr o1 = it1.next();
00301     bool found = false;
00302     QMutableListIterator<GEOM::GeomObjPtr> it2( left );
00303     while ( it2.hasNext() && !found )
00304       found = o1 == it2.next();
00305     if ( !found )
00306       left << o1;
00307   }
00308 }
00309 
00310 //=================================================================================
00311 // function : SelectionIntoArgument()
00312 // purpose  : Called when selection as changed or other case
00313 //=================================================================================
00314 void BasicGUI_CurveDlg::SelectionIntoArgument()
00315 {
00316   QList<GEOM::GeomObjPtr> points = getSelected( TopAbs_VERTEX, -1 );
00317   synchronize( myPoints, points );
00318   if ( !myPoints.isEmpty()  )
00319     GroupPoints->LineEdit1->setText( QString::number( myPoints.count() ) + "_" + tr( "GEOM_POINT" ) + tr( "_S_" ) );
00320   else
00321     GroupPoints->LineEdit1->setText( "" );
00322   processPreview();
00323 }
00324 
00325 
00326 //=================================================================================
00327 // function : ActivateThisDialog()
00328 // purpose  :
00329 //=================================================================================
00330 void BasicGUI_CurveDlg::ActivateThisDialog()
00331 {
00332   GEOMBase_Skeleton::ActivateThisDialog();
00333   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00334            this, SLOT( SelectionIntoArgument() ) );
00335 
00336   globalSelection(); // close local contexts, if any
00337   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
00338 
00339   ConstructorsClicked( getConstructorId() );
00340 }
00341 
00342 //=================================================================================
00343 // function : DeactivateActiveDialog()
00344 // purpose  : public slot to deactivate if active
00345 //=================================================================================
00346 void BasicGUI_CurveDlg::DeactivateActiveDialog()
00347 {
00348   // myGeomGUI->SetState( -1 );
00349   GEOMBase_Skeleton::DeactivateActiveDialog();
00350 }
00351 
00352 //=================================================================================
00353 // function : enterEvent()
00354 // purpose  :
00355 //=================================================================================
00356 void BasicGUI_CurveDlg::enterEvent( QEvent* )
00357 {
00358   if ( !mainFrame()->GroupConstructors->isEnabled() )
00359     ActivateThisDialog();
00360 }
00361 
00362 //=================================================================================
00363 // function : createOperation
00364 // purpose  :
00365 //=================================================================================
00366 GEOM::GEOM_IOperations_ptr BasicGUI_CurveDlg::createOperation()
00367 {
00368   return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
00369 }
00370 
00371 //=================================================================================
00372 // function : isValid
00373 // purpose  :
00374 //=================================================================================
00375 bool BasicGUI_CurveDlg::isValid( QString& msg )
00376 {
00377   if( myBySelectionBtn->isChecked() )
00378     return myPoints.count() > 1;
00379   else {
00380     bool ok = myParams->myPMin->isValid( msg, !IsPreview() ) &&
00381               myParams->myPMax->isValid( msg, !IsPreview() ) &&
00382               myParams->myPStep->isValid( msg, !IsPreview() );
00383     ok &= !myParams->myXExpr->text().isEmpty();
00384     ok &= !myParams->myYExpr->text().isEmpty();
00385     ok &= !myParams->myZExpr->text().isEmpty();
00386     return ok;
00387   }
00388 }
00389 
00390 //=================================================================================
00391 // function : execute
00392 // purpose  :
00393 //=================================================================================
00394 bool BasicGUI_CurveDlg::execute( ObjectList& objects )
00395 {
00396   bool res = false;
00397 
00398   GEOM::GEOM_Object_var anObj;
00399 
00400   GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() );
00401 
00402   GEOM::ListOfGO_var points = new GEOM::ListOfGO();
00403   points->length( myPoints.count() );
00404   for ( int i = 0; i < myPoints.count(); i++ )
00405     points[i] = myPoints[i].copy();
00406 
00407   switch ( getConstructorId() ) {
00408   case 0 :
00409     if( myBySelectionBtn->isChecked() )
00410       anObj = anOper->MakePolyline( points.in(), GroupPoints->CheckButton1->isChecked() );
00411     else
00412       anObj = anOper->MakeCurveParametricNew(qPrintable(myParams->myXExpr->text()),
00413                                      qPrintable(myParams->myYExpr->text()),
00414                                      qPrintable(myParams->myZExpr->text()),
00415                                      myParams->myPMin->value(),
00416                                      myParams->myPMax->value(),
00417                                      myParams->myPStep->value(),
00418                                      GEOM::Polyline);
00419     res = true;
00420     break;
00421   case 1 :
00422     if( myBySelectionBtn->isChecked() )
00423       anObj = anOper->MakeSplineBezier( points.in(), GroupPoints->CheckButton1->isChecked() );
00424     else
00425       anObj = anOper->MakeCurveParametricNew(qPrintable(myParams->myXExpr->text()),
00426                                      qPrintable(myParams->myYExpr->text()),
00427                                      qPrintable(myParams->myZExpr->text()),
00428                                      myParams->myPMin->value(),
00429                                      myParams->myPMax->value(),
00430                                      myParams->myPStep->value(),
00431                                      GEOM::Bezier);
00432 
00433     res = true;
00434     break;
00435   case 2 :
00436     if( myBySelectionBtn->isChecked() )
00437       anObj = anOper->MakeSplineInterpolation( points.in(), GroupPoints->CheckButton1->isChecked(),
00438                                           GroupPoints->CheckButton2->isChecked() );
00439     else
00440       anObj = anOper->MakeCurveParametricNew(qPrintable(myParams->myXExpr->text()),
00441                                      qPrintable(myParams->myYExpr->text()),
00442                                      qPrintable(myParams->myZExpr->text()),
00443                                      myParams->myPMin->value(),
00444                                      myParams->myPMax->value(),
00445                                      myParams->myPStep->value(),
00446                                      GEOM::Interpolation);
00447     res = true;
00448     break;
00449   }
00450 
00451   if ( !anObj->_is_nil() ) {
00452     if(myAnaliticalBtn->isChecked() && !IsPreview()) {
00453       QStringList aParameters;
00454       aParameters<<myParams->myPMin->text();
00455       aParameters<<myParams->myPMax->text();
00456       aParameters<<myParams->myPStep->text();
00457       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00458     }
00459     objects.push_back( anObj._retn() );
00460   }
00461   
00462   return res;
00463 }
00464 
00465 //=================================================================================
00466 // function : addSubshapeToStudy
00467 // purpose  : virtual method to add new SubObjects if local selection
00468 //=================================================================================
00469 void BasicGUI_CurveDlg::addSubshapesToStudy()
00470 {
00471   for ( int i = 0; i < myPoints.count(); i++ )
00472     GEOMBase::PublishSubObject( myPoints[i].get() );
00473 }
00474 
00475 //=================================================================================
00476 // function : CreationModeChanged
00477 // purpose  :
00478 //=================================================================================
00479 void BasicGUI_CurveDlg::CreationModeChanged() {
00480   const QObject* s = sender();
00481   GroupPoints->setVisible(myBySelectionBtn == s);
00482   myParams->setVisible(myBySelectionBtn != s);
00483   
00484   ConstructorsClicked( getConstructorId() );
00485 }
00486 
00487 //=================================================================================
00488 // function : ValueChangedInSpinBox()
00489 // purpose  :
00490 //=================================================================================
00491 void BasicGUI_CurveDlg::ValueChangedInSpinBox(double/*theValue*/)
00492 {
00493   processPreview();
00494 }
00495 
00496 //=================================================================================
00497 // function : ValueChangedInSpinBox()
00498 // purpose  :
00499 //=================================================================================
00500 void BasicGUI_CurveDlg::ValueChangedInSpinBox(int/*theValue*/)
00501 {
00502   processPreview();
00503 }
00504 
00505 //=================================================================================
00506 // function : ValueChangedInSpinBox()
00507 // purpose  :
00508 //=================================================================================
00509 void BasicGUI_CurveDlg::OnEditingFinished() {
00510   processPreview();
00511 }