Back to index

salome-geom  6.5.0
BuildGUI_CompoundDlg.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_CompoundDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 //
00027 #include "BuildGUI_CompoundDlg.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_Session.h>
00037 #include <SalomeApp_Application.h>
00038 #include <LightApp_SelectionMgr.h>
00039 
00040 //=================================================================================
00041 // class    : BuildGUI_CompoundDlg()
00042 // purpose  : Constructs a BuildGUI_CompoundDlg which is a child of 'parent', with the 
00043 //            name 'name' and widget flags set to 'f'.
00044 //            The dialog will by default be modeless, unless you set 'modal' to
00045 //            TRUE to construct a modal dialog.
00046 //=================================================================================
00047 BuildGUI_CompoundDlg::BuildGUI_CompoundDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
00048   : GEOMBase_Skeleton( theGeometryGUI, parent )
00049 {
00050   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_COMPOUND" ) ) );
00051   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00052 
00053   setWindowTitle( tr( "GEOM_COMPOUND_TITLE" ) );
00054 
00055   /***************************************************************/
00056   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_COMPOUND" ) );
00057   mainFrame()->RadioButton1->setIcon( image0 );
00058   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
00059   mainFrame()->RadioButton2->close();
00060   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
00061   mainFrame()->RadioButton3->close();
00062 
00063   GroupShapes = new DlgRef_1Sel( centralWidget() );
00064 
00065   GroupShapes->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
00066   GroupShapes->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
00067   GroupShapes->PushButton1->setIcon( image1 );
00068   GroupShapes->LineEdit1->setReadOnly( true );
00069 
00070   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00071   layout->setMargin( 0 ); layout->setSpacing( 6 );
00072   layout->addWidget( GroupShapes );
00073   /***************************************************************/
00074 
00075   setHelpFileName("create_compound_page.html");
00076 
00077   /* Initialisations */
00078   Init();
00079 }
00080 
00081 
00082 //=================================================================================
00083 // function : ~BuildGUI_CompoundDlg()
00084 // purpose  : Destroys the object and frees any allocated resources
00085 //=================================================================================
00086 BuildGUI_CompoundDlg::~BuildGUI_CompoundDlg()
00087 {
00088   // no need to delete child widgets, Qt does it all for us
00089 }
00090 
00091 
00092 //=================================================================================
00093 // function : Init()
00094 // purpose  :
00095 //=================================================================================
00096 void BuildGUI_CompoundDlg::Init()
00097 {
00098   /* init variables */
00099   myEditCurrentArgument = GroupShapes->LineEdit1;
00100   GroupShapes->LineEdit1->setReadOnly( true );
00101   
00102   myShapes.clear();
00103 
00104   mainFrame()->GroupBoxPublish->show();
00105   mainFrame()->CheckBoxPreview->hide();
00106 
00107   /* signals and slots connections */
00108   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00109   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00110   connect( GroupShapes->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
00111   connect( ( (SalomeApp_Application*)(SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
00112            SIGNAL(currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00113 
00114   globalSelection( GEOM_ALLSHAPES );
00115 
00116   initName( tr( "GEOM_COMPOUND" ) );
00117   SelectionIntoArgument();
00118 }
00119 
00120 
00121 //=================================================================================
00122 // function : ClickOnOk()
00123 // purpose  :
00124 //=================================================================================
00125 void BuildGUI_CompoundDlg::ClickOnOk()
00126 {
00127   setIsApplyAndClose( true );
00128   if ( ClickOnApply() )
00129     ClickOnCancel();
00130 }
00131 
00132 
00133 //=================================================================================
00134 // function : ClickOnApply()
00135 // purpose  :
00136 //=================================================================================
00137 bool BuildGUI_CompoundDlg::ClickOnApply()
00138 {
00139   if ( !onAccept() )
00140     return false;
00141 
00142   initName();
00143   return true;
00144 }
00145 
00146 
00147 //=================================================================================
00148 // function : SelectionIntoArgument()
00149 // purpose  : Called when selection as changed or other case
00150 //=================================================================================
00151 void BuildGUI_CompoundDlg::SelectionIntoArgument()
00152 {
00153   myEditCurrentArgument->setText( "" );
00154 
00155   myShapes = getSelected( TopAbs_SHAPE, -1 );
00156 
00157   if ( !myShapes.isEmpty() ) {
00158     QString aName = myShapes.count() > 1 ? QString( "%1_objects").arg( myShapes.count() ) : GEOMBase::GetName( myShapes[0].get() );
00159     myEditCurrentArgument->setText( aName );
00160   }
00161 }
00162 
00163 
00164 //=================================================================================
00165 // function : SetEditCurrentArgument()
00166 // purpose  :
00167 //=================================================================================
00168 void BuildGUI_CompoundDlg::SetEditCurrentArgument()
00169 {
00170   QPushButton* send = (QPushButton*)sender();
00171   if ( send != GroupShapes->PushButton1 )
00172     return;
00173   
00174   myEditCurrentArgument = GroupShapes->LineEdit1;
00175   
00176   myEditCurrentArgument->setFocus();
00177   SelectionIntoArgument();
00178 }
00179 
00180 
00181 //=================================================================================
00182 // function : ActivateThisDialog()
00183 // purpose  :
00184 //=================================================================================
00185 void BuildGUI_CompoundDlg::ActivateThisDialog()
00186 {
00187   GEOMBase_Skeleton::ActivateThisDialog();
00188   globalSelection( GEOM_ALLSHAPES );
00189   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
00190            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00191 }
00192 
00193 
00194 //=================================================================================
00195 // function : enterEvent()
00196 // purpose  :
00197 //=================================================================================
00198 void BuildGUI_CompoundDlg::enterEvent(QEvent* e)
00199 {
00200   if ( !mainFrame()->GroupConstructors->isEnabled() )
00201     ActivateThisDialog(); 
00202 }
00203 
00204 //=================================================================================
00205 // function : createOperation
00206 // purpose  :
00207 //=================================================================================
00208 GEOM::GEOM_IOperations_ptr BuildGUI_CompoundDlg::createOperation()
00209 {
00210   return getGeomEngine()->GetIShapesOperations( getStudyId() );
00211 }
00212 
00213 //=================================================================================
00214 // function : isValid
00215 // purpose  :
00216 //=================================================================================
00217 bool BuildGUI_CompoundDlg::isValid( QString& )
00218 {
00219   return !myShapes.isEmpty();
00220 }
00221 
00222 //=================================================================================
00223 // function : execute
00224 // purpose  :
00225 //=================================================================================
00226 bool BuildGUI_CompoundDlg::execute( ObjectList& objects )
00227 {
00228   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
00229 
00230   GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
00231   objlist->length( myShapes.count() );
00232   for ( int i = 0; i < myShapes.count(); i++ )
00233     objlist[i] = myShapes[i].copy();
00234 
00235   GEOM::GEOM_Object_var anObj = anOper->MakeCompound( objlist );
00236 
00237   if ( !anObj->_is_nil() )
00238     objects.push_back( anObj._retn() );
00239 
00240   return true;
00241 }
00242 
00243 //=================================================================================
00244 // function : restoreSubShapes
00245 // purpose  :
00246 //=================================================================================
00247 void BuildGUI_CompoundDlg::restoreSubShapes( SALOMEDS::Study_ptr   theStudy,
00248                                              SALOMEDS::SObject_ptr theSObject )
00249 {
00250   if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
00251     // empty list of arguments means that all arguments should be restored
00252     getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
00253                                          /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GEOM::FSM_GetSame
00254                                          /*theInheritFirstArg=*/false,
00255                                          mainFrame()->CheckBoxAddPrefix->isChecked() );
00256   }
00257 }