Back to index

salome-geom  6.5.0
GenerationGUI_RevolDlg.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_RevolDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 
00027 #include "GenerationGUI_RevolDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOMBase.h>
00032 
00033 #include <SUIT_Session.h>
00034 #include <SUIT_ResourceMgr.h>
00035 #include <SalomeApp_Application.h>
00036 #include <LightApp_SelectionMgr.h>
00037 
00038 #include <TopoDS_Shape.hxx>
00039 #include <TopoDS_Edge.hxx>
00040 #include <TopoDS.hxx>
00041 #include <TopExp.hxx>
00042 #include <TColStd_IndexedMapOfInteger.hxx>
00043 #include <TopTools_IndexedMapOfShape.hxx>
00044 #include <TopExp_Explorer.hxx>
00045 
00046 #include <GEOMImpl_Types.hxx>
00047 
00048 //=================================================================================
00049 // class    : GenerationGUI_RevolDlg()
00050 // purpose  : Constructs a GenerationGUI_RevolDlg which is a child of 'parent', with the
00051 //            name 'name' and widget flags set to 'f'.
00052 //            The dialog will by default be modeless, unless you set 'modal' to
00053 //            TRUE to construct a modal dialog.
00054 //=================================================================================
00055 GenerationGUI_RevolDlg::GenerationGUI_RevolDlg (GeometryGUI* theGeometryGUI, QWidget* parent,
00056                                                 bool modal, Qt::WindowFlags fl)
00057   : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
00058 {
00059   QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_REVOL")));
00060   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
00061 
00062   setWindowTitle(tr("GEOM_REVOLUTION_TITLE"));
00063 
00064   /***************************************************************/
00065   mainFrame()->GroupConstructors->setTitle(tr("GEOM_REVOLUTION"));
00066   mainFrame()->RadioButton1->setIcon(image0);
00067   mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
00068   mainFrame()->RadioButton2->close();
00069   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
00070   mainFrame()->RadioButton3->close();
00071 
00072   GroupPoints = new DlgRef_2Sel1Spin2Check(centralWidget());
00073   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
00074   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
00075   GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
00076   GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
00077   GroupPoints->PushButton1->setIcon(image1);
00078   GroupPoints->PushButton2->setIcon(image1);
00079   GroupPoints->LineEdit1->setReadOnly(true);
00080   GroupPoints->LineEdit2->setReadOnly(true);
00081   GroupPoints->CheckButton1->setText(tr("GEOM_BOTHWAY"));
00082   GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
00083 
00084   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00085   layout->setMargin(0); layout->setSpacing(6);
00086   layout->addWidget(GroupPoints);
00087   /***************************************************************/
00088 
00089   setHelpFileName("create_revolution_page.html");
00090 
00091   // Initialisation
00092   Init();
00093 }
00094 
00095 //=================================================================================
00096 // function : ~GenerationGUI_RevolDlg()
00097 // purpose  : Destroys the object and frees any allocated resources
00098 //=================================================================================
00099 GenerationGUI_RevolDlg::~GenerationGUI_RevolDlg()
00100 {
00101   // no need to delete child widgets, Qt does it all for us
00102 }
00103 
00104 //=================================================================================
00105 // function : Init()
00106 // purpose  :
00107 //=================================================================================
00108 void GenerationGUI_RevolDlg::Init()
00109 {
00110   // min, max, step and decimals for spin boxes & initial values
00111   double SpecificStep = 5;
00112   initSpinBox(GroupPoints->SpinBox_DX, -360.0, 360.0, SpecificStep, "angle_precision" );
00113   GroupPoints->SpinBox_DX->setValue(45.0);
00114 
00115   // init variables
00116   GroupPoints->LineEdit1->setReadOnly(true);
00117   GroupPoints->LineEdit2->setReadOnly(true);
00118 
00119   GroupPoints->LineEdit1->setText("");
00120   GroupPoints->LineEdit2->setText("");
00121 
00122   myBaseObjects.clear();
00123   myAxis.nullify();
00124 
00125   showOnlyPreviewControl();
00126 
00127   // signals and slots connections
00128   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00129   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00130 
00131   connect(GroupPoints->PushButton1,  SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00132   connect(GroupPoints->PushButton2,  SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00133 
00134   connect(GroupPoints->SpinBox_DX,   SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
00135   connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)),        this, SLOT(onBothway()));
00136   connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)),        this, SLOT(onReverse()));
00137 
00138   // san: We don't need this, as the default step value is not used in this dialog box
00139   //connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
00140 
00141   initName(tr("GEOM_REVOLUTION"));
00142   resize(100,100);
00143 
00144   GroupPoints->PushButton1->click();
00145   SelectionIntoArgument();
00146 }
00147 
00148 //=================================================================================
00149 // function : SetDoubleSpinBoxStep()
00150 // purpose  : Double spin box management
00151 //=================================================================================
00152 void GenerationGUI_RevolDlg::SetDoubleSpinBoxStep (double step)
00153 {
00154   GroupPoints->SpinBox_DX->setSingleStep(step);
00155 }
00156 
00157 //=================================================================================
00158 // function : ClickOnOk()
00159 // purpose  :
00160 //=================================================================================
00161 void GenerationGUI_RevolDlg::ClickOnOk()
00162 {
00163   setIsApplyAndClose( true );
00164   if (ClickOnApply())
00165     ClickOnCancel();
00166 }
00167 
00168 //=================================================================================
00169 // function : ClickOnApply()
00170 // purpose  :
00171 //=================================================================================
00172 bool GenerationGUI_RevolDlg::ClickOnApply()
00173 {
00174   if (!onAccept())
00175     return false;
00176 
00177   initName();
00178   // activate selection and connect selection manager
00179   GroupPoints->PushButton1->click();
00180   return true;
00181 }
00182 
00183 //=================================================================================
00184 // function : SelectionIntoArgument()
00185 // purpose  : Called when selection is changed or on dialog initialization or activation
00186 //=================================================================================
00187 void GenerationGUI_RevolDlg::SelectionIntoArgument()
00188 {
00189   erasePreview();
00190   myEditCurrentArgument->setText("");
00191 
00192   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
00193     myBaseObjects.clear();
00194     QList<GEOM::GeomObjPtr> objects = getSelected( TopAbs_SHAPE, -1 );
00195     for ( int i = 0; i < objects.count(); i++ ) {
00196       GEOM::shape_type stype = objects[i]->GetMaxShapeType();
00197       if ( stype < GEOM::SHELL || stype > GEOM::VERTEX )
00198        continue;
00199       myBaseObjects << objects[i];
00200     }
00201     if ( !myBaseObjects.isEmpty() ) {
00202       QString aName = myBaseObjects.count() > 1 ? QString( "%1_objects").arg( myBaseObjects.count() ) : GEOMBase::GetName( myBaseObjects[0].get() );
00203       myEditCurrentArgument->setText( aName );
00204     }
00205   }
00206   else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
00207     myAxis = getSelected( TopAbs_EDGE );
00208     if ( myAxis ) {
00209       QString aName = GEOMBase::GetName( myAxis.get() );
00210       myEditCurrentArgument->setText( aName );
00211       if ( myBaseObjects.isEmpty() )
00212        GroupPoints->PushButton1->click();
00213     }
00214   }
00215   processPreview();
00216 }
00217 
00218 //=================================================================================
00219 // function : SetEditCurrentArgument()
00220 // purpose  :
00221 //=================================================================================
00222 void GenerationGUI_RevolDlg::SetEditCurrentArgument()
00223 {
00224   QPushButton* send = (QPushButton*)sender();
00225 
00226   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00227   globalSelection(GEOM_ALLSHAPES);
00228   if (send == GroupPoints->PushButton1) {
00229     myEditCurrentArgument = GroupPoints->LineEdit1;
00230     GroupPoints->PushButton2->setDown(false);
00231     GroupPoints->LineEdit2->setEnabled(false);
00232   }
00233   else if (send == GroupPoints->PushButton2) {
00234     myEditCurrentArgument = GroupPoints->LineEdit2;
00235     GroupPoints->PushButton1->setDown(false);
00236     GroupPoints->LineEdit1->setEnabled(false);
00237     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
00238   }
00239   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00240           this, SLOT(SelectionIntoArgument()));
00241 
00242   // enable line edit
00243   myEditCurrentArgument->setEnabled(true);
00244   myEditCurrentArgument->setFocus();
00245   // after setFocus(), because it will be setDown(false) when loses focus
00246   send->setDown(true);
00247 
00248   // seems we need it only to avoid preview disappearing, caused by selection mode change
00249   processPreview();
00250 }
00251 
00252 //=================================================================================
00253 // function : ActivateThisDialog()
00254 // purpose  :
00255 //=================================================================================
00256 void GenerationGUI_RevolDlg::ActivateThisDialog()
00257 {
00258   GEOMBase_Skeleton::ActivateThisDialog();
00259   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00260            this, SLOT( SelectionIntoArgument() ) );
00261 
00262   processPreview();
00263 }
00264 
00265 //=================================================================================
00266 // function : enterEvent()
00267 // purpose  :
00268 //=================================================================================
00269 void GenerationGUI_RevolDlg::enterEvent (QEvent*)
00270 {
00271   if (!mainFrame()->GroupConstructors->isEnabled())
00272     ActivateThisDialog();
00273 }
00274 
00275 //=================================================================================
00276 // function : ValueChangedInSpinBox()
00277 // purpose  :
00278 //=================================================================================
00279 void GenerationGUI_RevolDlg::ValueChangedInSpinBox()
00280 {
00281   processPreview();
00282 }
00283 
00284 //=================================================================================
00285 // function : getAngle()
00286 // purpose  :
00287 //=================================================================================
00288 double GenerationGUI_RevolDlg::getAngle() const
00289 {
00290   return GroupPoints->SpinBox_DX->value();
00291 }
00292 
00293 //=================================================================================
00294 // function : createOperation
00295 // purpose  :
00296 //=================================================================================
00297 GEOM::GEOM_IOperations_ptr GenerationGUI_RevolDlg::createOperation()
00298 {
00299   return getGeomEngine()->GetI3DPrimOperations(getStudyId());
00300 }
00301 
00302 //=================================================================================
00303 // function : isValid
00304 // purpose  :
00305 //=================================================================================
00306 bool GenerationGUI_RevolDlg::isValid (QString& msg)
00307 {
00308   return GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && !myBaseObjects.isEmpty() && myAxis;
00309 }
00310 
00311 //=================================================================================
00312 // function : execute
00313 // purpose  :
00314 //=================================================================================
00315 bool GenerationGUI_RevolDlg::execute (ObjectList& objects)
00316 {
00317   GEOM::GEOM_Object_var anObj;
00318   GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
00319 
00320   for (int i = 0; i < myBaseObjects.count(); i++) {
00321     if (!GroupPoints->CheckButton1->isChecked())
00322       anObj = anOper->MakeRevolutionAxisAngle(myBaseObjects[i].get(), myAxis.get(),
00323                                               getAngle() * M_PI / 180.);
00324     else
00325       anObj = anOper->MakeRevolutionAxisAngle2Ways(myBaseObjects[i].get(), myAxis.get(),
00326                                                    getAngle() * M_PI / 180.);
00327     
00328     if (!anObj->_is_nil()) {
00329       if (!IsPreview()) {
00330         QStringList aParameters;
00331         aParameters << GroupPoints->SpinBox_DX->text();
00332         anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00333       }
00334       objects.push_back(anObj._retn());
00335     }
00336   }
00337 
00338   return true;
00339 }
00340 
00341 //=================================================================================
00342 // function :  onReverse()
00343 // purpose  :
00344 //=================================================================================
00345 void GenerationGUI_RevolDlg::onReverse()
00346 {
00347   double anOldValue = GroupPoints->SpinBox_DX->value();
00348   GroupPoints->SpinBox_DX->setValue(-anOldValue);
00349 }
00350 
00351 //=================================================================================
00352 // function :  onBothway()
00353 // purpose  :
00354 //=================================================================================
00355 void GenerationGUI_RevolDlg::onBothway()
00356 {
00357   GroupPoints->CheckButton2->setEnabled(!GroupPoints->CheckButton1->isChecked());
00358   processPreview();
00359 }
00360 
00361 //=================================================================================
00362 // function : addSubshapeToStudy
00363 // purpose  : virtual method to add new SubObjects if local selection
00364 //=================================================================================
00365 void GenerationGUI_RevolDlg::addSubshapesToStudy()
00366 {
00367   GEOMBase::PublishSubObject( myAxis.get() );
00368 }
00369 
00370 //=================================================================================
00371 // function : extractPrefix
00372 // purpose  : redefined from GEOMBase_Helper class
00373 //=================================================================================
00374 bool GenerationGUI_RevolDlg::extractPrefix() const
00375 {
00376   return myBaseObjects.count() > 1;
00377 }