Back to index

salome-geom  6.5.0
BuildGUI_SolidDlg.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_SolidDlg.cxx
00025 // Author : Damien COQUERET, Open CASCADE S.A.S.
00026 
00027 #include "BuildGUI_SolidDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOMBase.h>
00032 
00033 #include <GEOMImpl_Types.hxx>
00034 
00035 #include <SUIT_ResourceMgr.h>
00036 #include <SUIT_MessageBox.h>
00037 #include <SUIT_Session.h>
00038 #include <SalomeApp_Application.h>
00039 #include <LightApp_SelectionMgr.h>
00040 
00041 #include <TColStd_MapOfInteger.hxx>
00042 
00043 //=================================================================================
00044 // class    : BuildGUI_SolidDlg()
00045 // purpose  : Constructs a BuildGUI_SolidDlg which is a child of 'parent', with the
00046 //            name 'name' and widget flags set to 'f'.
00047 //            The dialog will by default be modeless, unless you set 'modal' to
00048 //            TRUE to construct a modal dialog.
00049 //=================================================================================
00050 BuildGUI_SolidDlg::BuildGUI_SolidDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
00051   : GEOMBase_Skeleton( theGeometryGUI, parent )
00052 {
00053   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_SOLID" ) ) );
00054   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00055 
00056   setWindowTitle( tr( "GEOM_SOLID_TITLE" ) );
00057 
00058   /***************************************************************/
00059   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SOLID" ) );
00060   mainFrame()->RadioButton1->setIcon( image0 );
00061   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
00062   mainFrame()->RadioButton2->close();
00063   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
00064   mainFrame()->RadioButton3->close();
00065 
00066   GroupSolid = new DlgRef_1Sel1Check( centralWidget() );
00067 
00068   GroupSolid->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
00069   GroupSolid->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
00070   GroupSolid->CheckButton1->setText( tr( "GEOM_CREATE_SINGLE_SOLID" ) );
00071   GroupSolid->PushButton1->setIcon( image1 );
00072   GroupSolid->LineEdit1->setReadOnly( true );
00073 
00074   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00075   layout->setMargin( 0 ); layout->setSpacing( 6 );
00076   layout->addWidget( GroupSolid );
00077   /***************************************************************/
00078 
00079   setHelpFileName("create_solid_page.html");
00080 
00081   /* Initialisations */
00082   Init();
00083 }
00084 
00085 
00086 //=================================================================================
00087 // function : ~BuildGUI_SolidDlg()
00088 // purpose  : Destroys the object and frees any allocated resources
00089 //=================================================================================
00090 BuildGUI_SolidDlg::~BuildGUI_SolidDlg()
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_SolidDlg::Init()
00101 {
00102   /* init variables */
00103   myEditCurrentArgument = GroupSolid->LineEdit1;
00104   GroupSolid->LineEdit1->setReadOnly( true );
00105   GroupSolid->CheckButton1->setChecked( true );
00106 
00107   myShells.clear();
00108 
00109   //globalSelection( GEOM_SHELL );
00110   TColStd_MapOfInteger aMap;
00111   aMap.Add( GEOM_SHELL );
00112   aMap.Add( GEOM_COMPOUNDFILTER );
00113   QList<int> aSubShapes;
00114   aSubShapes.append( GEOM_SHELL );
00115   globalSelection( aMap, aSubShapes );
00116 
00117   /* signals and slots connections */
00118   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00119   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00120 
00121   connect( GroupSolid->PushButton1,  SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
00122   connect( GroupSolid->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( EnableNameField( bool ) ) );
00123 
00124   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
00125            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00126 
00127   initName( tr( "GEOM_SOLID" ) );
00128   SelectionIntoArgument();
00129 }
00130 
00131 
00132 //=================================================================================
00133 // function : ClickOnOk()
00134 // purpose  :
00135 //=================================================================================
00136 void BuildGUI_SolidDlg::ClickOnOk()
00137 {
00138   setIsApplyAndClose( true );
00139   if ( ClickOnApply() )
00140     ClickOnCancel();
00141 }
00142 
00143 //=================================================================================
00144 // function : ClickOnApply()
00145 // purpose  :
00146 //=================================================================================
00147 bool BuildGUI_SolidDlg::ClickOnApply()
00148 {
00149   if ( !onAccept() )
00150     return false;
00151 
00152   initName();
00153   return true;
00154 }
00155 
00156 
00157 //=================================================================================
00158 // function : SelectionIntoArgument()
00159 // purpose  : Called when selection as changed or other case
00160 //=================================================================================
00161 void BuildGUI_SolidDlg::SelectionIntoArgument()
00162 {
00163   myEditCurrentArgument->setText( "" );
00164 
00165   //myShells = getSelected( TopAbs_SHELL, -1 );
00166   QList<TopAbs_ShapeEnum> types;
00167   types << TopAbs_SHELL << TopAbs_COMPOUND;
00168   myShells = getSelected( types, -1 );
00169 
00170   if ( !myShells.isEmpty() ) {
00171     QString aName = myShells.count() > 1 ? QString( "%1_objects").arg( myShells.count() ) : GEOMBase::GetName( myShells[0].get() );
00172     myEditCurrentArgument->setText( aName );
00173   }
00174 }
00175 
00176 //=================================================================================
00177 // function : SetEditCurrentArgument()
00178 // purpose  :
00179 //=================================================================================
00180 void BuildGUI_SolidDlg::SetEditCurrentArgument()
00181 {
00182   QPushButton* send = (QPushButton*)sender();
00183   if ( send != GroupSolid->PushButton1 )
00184     return;
00185 
00186   //globalSelection( GEOM_SHELL );
00187   TColStd_MapOfInteger aMap;
00188   aMap.Add( GEOM_SHELL );
00189   aMap.Add( GEOM_COMPOUNDFILTER );
00190   QList<int> aSubShapes;
00191   aSubShapes.append( GEOM_SHELL );
00192   globalSelection( aMap, aSubShapes );
00193 
00194   myEditCurrentArgument = GroupSolid->LineEdit1;
00195 
00196   myEditCurrentArgument->setFocus();
00197   SelectionIntoArgument();
00198 }
00199 
00200 
00201 //=================================================================================
00202 // function : ActivateThisDialog()
00203 // purpose  :
00204 //=================================================================================
00205 void BuildGUI_SolidDlg::ActivateThisDialog()
00206 {
00207   GEOMBase_Skeleton::ActivateThisDialog();
00208   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
00209            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00210 
00211   //globalSelection( GEOM_SHELL );
00212   TColStd_MapOfInteger aMap;
00213   aMap.Add( GEOM_SHELL );
00214   aMap.Add( GEOM_COMPOUNDFILTER );
00215   QList<int> aSubShapes;
00216   aSubShapes.append( GEOM_SHELL );
00217   globalSelection( aMap, aSubShapes );
00218 }
00219 
00220 
00221 //=================================================================================
00222 // function : enterEvent()
00223 // purpose  :
00224 //=================================================================================
00225 void BuildGUI_SolidDlg::enterEvent( QEvent* )
00226 {
00227   if ( !mainFrame()->GroupConstructors->isEnabled() )
00228     ActivateThisDialog();
00229 }
00230 
00231 
00232 //=================================================================================
00233 // function :  EnableNameField()
00234 // purpose  :
00235 //=================================================================================
00236 void  BuildGUI_SolidDlg::EnableNameField( bool toEnable )
00237 {
00238   mainFrame()->GroupBoxName->setEnabled( toEnable );
00239 }
00240 
00241 //=================================================================================
00242 // function : createOperation
00243 // purpose  :
00244 //=================================================================================
00245 GEOM::GEOM_IOperations_ptr BuildGUI_SolidDlg::createOperation()
00246 {
00247   return getGeomEngine()->GetIShapesOperations( getStudyId() );
00248 }
00249 
00250 //=================================================================================
00251 // function : isValid
00252 // purpose  :
00253 //=================================================================================
00254 bool BuildGUI_SolidDlg::isValid (QString& msg)
00255 {
00256   bool ok = !myShells.isEmpty();
00257 
00258   GEOM::MeasureOpPtr anOp;
00259   anOp.take(myGeomGUI->GetGeomGen()->GetIMeasureOperations(getStudyId()));
00260 
00261   for ( int i = 0, n = myShells.count(); i < n && ok; i++ ) {
00262     CORBA::String_var aRes = anOp->IsGoodForSolid(myShells[i].get());
00263     if (strlen(aRes.in())) {
00264       msg = QObject::tr(aRes.in()).arg(GEOMBase::GetName(myShells[i].get()));
00265       ok = false;
00266     }
00267   }
00268   return ok;
00269 }
00270 
00271 /*
00272 //=================================================================================
00273 // function : isClosed
00274 // purpose  : Check the object 'i' in myShells list is closed or unclosed
00275 //=================================================================================
00276 bool BuildGUI_SolidDlg::isClosed( GEOM::GEOM_Object_ptr shell )
00277 {
00278   bool ok = false;
00279 
00280   GEOM::GEOM_IKindOfShape::shape_kind aKind;
00281   GEOM::ListOfLong_var anInts;
00282   GEOM::ListOfDouble_var aDbls;
00283 
00284   if ( !CORBA::is_nil( shell ) ) {
00285     GEOM::MeasureOpPtr anOp;
00286     anOp.take( myGeomGUI->GetGeomGen()->GetIMeasureOperations( getStudyId() ) );
00287 
00288     // Detect kind of shape and parameters
00289     aKind = anOp->KindOfShape(shell, anInts, aDbls);
00290 
00291     if ( anOp->IsDone() ) {
00292       if ( anInts[0] == 1 )
00293         ok = true;
00294       else if ( anInts[0] == 2 )
00295         ok = false;
00296     }
00297     else {
00298       MESSAGE ("KindOfShape Operation is NOT DONE!!!");
00299     }
00300   }
00301   else {
00302     MESSAGE ("Shape is NULL!!!");
00303   }
00304 
00305   return ok;
00306 }
00307 */
00308 
00309 //=================================================================================
00310 // function : execute
00311 // purpose  :
00312 //=================================================================================
00313 bool BuildGUI_SolidDlg::execute( ObjectList& objects )
00314 {
00315   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
00316 
00317   if ( GroupSolid->CheckButton1->isChecked() ) {
00318     GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
00319     objlist->length( myShells.count() );
00320     for ( int i = 0; i < myShells.count(); i++ )
00321       objlist[i] = myShells[i].copy();
00322 
00323     GEOM::GEOM_Object_var anObj = anOper->MakeSolidShells( objlist.in() );
00324 
00325     if ( !anObj->_is_nil() )
00326       objects.push_back( anObj._retn() );
00327   }
00328   else {
00329     for ( int i = 0, n = myShells.count(); i< n; i++ ) {
00330       GEOM::GEOM_Object_var anObj = anOper->MakeSolidShell( myShells[ i ].get() );
00331 
00332      if ( !anObj->_is_nil() )
00333        objects.push_back( anObj._retn() );
00334     }
00335   }
00336 
00337   return true;
00338 }