Back to index

salome-geom  6.5.0
GenerationGUI_PipeDlg.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_PipeDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 //
00027 #include "GenerationGUI_PipeDlg.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.hxx>
00040 #include <TopExp.hxx>
00041 #include <TColStd_IndexedMapOfInteger.hxx>
00042 #include <TopTools_IndexedMapOfShape.hxx>
00043 #include <TColStd_IndexedMapOfInteger.hxx>
00044 #include <TColStd_MapOfInteger.hxx>
00045 
00046 #include <GEOMImpl_Types.hxx>
00047 
00048 //=================================================================================
00049 // class    : GenerationGUI_PipeDlg()
00050 // purpose  : Constructs a GenerationGUI_PipeDlg 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_PipeDlg::GenerationGUI_PipeDlg (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_PIPE")));
00060   QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
00061   QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PIPE_BINORMAL")));
00062 
00063   setWindowTitle(tr("GEOM_PIPE_TITLE"));
00064 
00065   /***************************************************************/
00066   mainFrame()->GroupConstructors->setTitle(tr("GEOM_PIPE"));
00067   mainFrame()->RadioButton1->setIcon(image0);
00068   mainFrame()->RadioButton2->setIcon(image2);
00069   mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
00070   mainFrame()->RadioButton3->close();
00071 
00072   GroupPoints = new DlgRef_3Sel1Check(centralWidget());
00073 
00074   GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
00075   GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
00076   GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
00077   GroupPoints->TextLabel3->setText(tr("GEOM_BINORMAL"));
00078   GroupPoints->PushButton1->setIcon(image1);
00079   GroupPoints->PushButton2->setIcon(image1);
00080   GroupPoints->PushButton3->setIcon(image1);
00081   GroupPoints->CheckButton1->setText(tr("GEOM_SELECT_UNPUBLISHED_EDGES"));
00082 
00083   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
00084   layout->setMargin(0); layout->setSpacing(6);
00085   layout->addWidget(GroupPoints);
00086   /***************************************************************/
00087 
00088   setHelpFileName("create_extrusion_alongpath_page.html");
00089 
00090   // Initialisation
00091   Init();
00092 }
00093 
00094 //=================================================================================
00095 // function : ~GenerationGUI_PipeDlg()
00096 // purpose  : Destroys the object and frees any allocated resources
00097 //=================================================================================
00098 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
00099 {
00100   // no need to delete child widgets, Qt does it all for us
00101 }
00102 
00103 //=================================================================================
00104 // function : Init()
00105 // purpose  :
00106 //=================================================================================
00107 void GenerationGUI_PipeDlg::Init()
00108 {
00109   // init variables
00110   GroupPoints->LineEdit1->setReadOnly(true);
00111   GroupPoints->LineEdit2->setReadOnly(true);
00112   GroupPoints->LineEdit3->setReadOnly(true);
00113 
00114   GroupPoints->LineEdit1->setText("");
00115   GroupPoints->LineEdit2->setText("");
00116   GroupPoints->LineEdit3->setText("");
00117   myPath.nullify();
00118   myVec.nullify();
00119 
00120   GroupPoints->CheckButton1->setEnabled(false);
00121 
00122   showOnlyPreviewControl();
00123 
00124   // signals and slots connections
00125   connect(buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00126   connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00127 
00128   connect(this,          SIGNAL(constructorsClicked(int)), this, SLOT(ConstructorsClicked(int)));
00129 
00130   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00131   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00132   connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
00133 
00134   connect(GroupPoints->CheckButton1,   SIGNAL(toggled(bool)), this, SLOT(SelectionTypeButtonClicked()));
00135 
00136   initName(tr("GEOM_PIPE"));
00137   resize(100,100);
00138 
00139   GroupPoints->TextLabel3->hide();
00140   GroupPoints->PushButton3->hide();
00141   GroupPoints->LineEdit3->hide();
00142   ConstructorsClicked(0);
00143 
00144   GroupPoints->PushButton1->click();
00145   SelectionIntoArgument();
00146 }
00147 
00148 //=================================================================================
00149 // function : ConstructorsClicked()
00150 // purpose  : Radio button management
00151 //=================================================================================
00152 void GenerationGUI_PipeDlg::ConstructorsClicked( int constructorId )
00153 {
00154   erasePreview();
00155 
00156   switch (constructorId) {
00157   case 0:
00158     GroupPoints->TextLabel3->hide();
00159     GroupPoints->PushButton3->hide();
00160     GroupPoints->LineEdit3->hide();
00161     GroupPoints->PushButton1->click();
00162     break;
00163   case 1:
00164     GroupPoints->TextLabel3->show();
00165     GroupPoints->PushButton3->show();
00166     GroupPoints->LineEdit3->show();
00167     break;
00168   default:
00169     break;
00170   }
00171 
00172   qApp->processEvents();
00173   updateGeometry();
00174   resize(100,100);
00175 
00176   SelectionIntoArgument();
00177   processPreview();
00178 }
00179 
00180 //=================================================================================
00181 // function : SelectionBittonClicked()
00182 // purpose  : Selection type Radio button management
00183 //=================================================================================
00184 void GenerationGUI_PipeDlg::SelectionTypeButtonClicked()
00185 {
00186   globalSelection();
00187   if ( GroupPoints->CheckButton1->isChecked() ) {
00188     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
00189   } else {
00190     TColStd_MapOfInteger aMap;
00191     aMap.Add(GEOM_COMPOUND);
00192     aMap.Add(GEOM_WIRE);
00193     aMap.Add(GEOM_LINE);
00194     globalSelection(aMap);
00195   }
00196   if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
00197     myEditCurrentArgument->setText("");
00198     myPath.nullify();
00199   }
00200   processPreview();
00201 }
00202 
00203 //=================================================================================
00204 // function : ClickOnOk()
00205 // purpose  :
00206 //=================================================================================
00207 void GenerationGUI_PipeDlg::ClickOnOk()
00208 {
00209   setIsApplyAndClose( true );
00210   if (ClickOnApply())
00211     ClickOnCancel();
00212 }
00213 
00214 //=================================================================================
00215 // function : ClickOnApply()
00216 // purpose  :
00217 //=================================================================================
00218 bool GenerationGUI_PipeDlg::ClickOnApply()
00219 {
00220   if (!onAccept())
00221     return false;
00222 
00223   initName();
00224   if ( getConstructorId() != 1 )
00225     ConstructorsClicked( getConstructorId() );
00226   // activate selection and connect selection manager
00227   GroupPoints->PushButton1->click();
00228   return true;
00229 }
00230 
00231 //=================================================================================
00232 // function : SelectionIntoArgument()
00233 // purpose  : Called when selection is changed or on dialog initialization or activation
00234 //=================================================================================
00235 void GenerationGUI_PipeDlg::SelectionIntoArgument()
00236 {
00237   erasePreview();
00238   myEditCurrentArgument->setText("");
00239 
00240   if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
00241     myBaseObjects.clear();
00242     QList<GEOM::GeomObjPtr> objects = getSelected( TopAbs_SHAPE, -1 );
00243     for ( int i = 0; i < objects.count(); i++ ) {
00244       GEOM::shape_type stype = objects[i]->GetMaxShapeType();
00245       GEOM::shape_type maxallowed = getConstructorId() == 1 ? GEOM::FACE : GEOM::SHELL;
00246       GEOM::shape_type minallowed = getConstructorId() == 1 ? GEOM::EDGE : GEOM::VERTEX;
00247       if ( stype < maxallowed || stype > minallowed )
00248        continue;
00249       myBaseObjects << objects[i];
00250     }
00251     if ( !myBaseObjects.isEmpty() ) {
00252       QString aName = myBaseObjects.count() > 1 ? QString( "%1_objects").arg( myBaseObjects.count() ) : GEOMBase::GetName( myBaseObjects[0].get() );
00253       myEditCurrentArgument->setText( aName );
00254     }
00255   }
00256   else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
00257     QList<TopAbs_ShapeEnum> types;
00258     types << TopAbs_EDGE << TopAbs_WIRE;
00259     myPath = getSelected( types );
00260     if ( myPath ) {
00261       QString aName = GEOMBase::GetName( myPath.get() );
00262       myEditCurrentArgument->setText( aName );
00263       if ( getConstructorId() == 1 && !myVec )
00264        GroupPoints->PushButton3->click();
00265       else if ( myBaseObjects.isEmpty() )
00266        GroupPoints->PushButton1->click();
00267     }
00268   }
00269   else if (myEditCurrentArgument == GroupPoints->LineEdit3) {
00270     myVec = getSelected( TopAbs_EDGE );
00271     if ( myVec ) {
00272       QString aName = GEOMBase::GetName( myVec.get() );
00273       myEditCurrentArgument->setText( aName );
00274       if ( myBaseObjects.isEmpty() )
00275        GroupPoints->PushButton1->click();
00276       else if ( !myPath )
00277        GroupPoints->PushButton2->click();
00278     }
00279   }
00280 
00281   processPreview();
00282 }
00283 
00284 //=================================================================================
00285 // function : SetEditCurrentArgument()
00286 // purpose  :
00287 //=================================================================================
00288 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
00289 {
00290   QPushButton* send = (QPushButton*)sender();
00291 
00292   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
00293   globalSelection(GEOM_ALLSHAPES);
00294   GroupPoints->PushButton1->setDown(false);
00295   GroupPoints->PushButton2->setDown(false);
00296   GroupPoints->PushButton3->setDown(false);
00297   GroupPoints->LineEdit1->setEnabled(false);
00298   GroupPoints->LineEdit2->setEnabled(false);
00299   GroupPoints->LineEdit3->setEnabled(false);
00300   if (send == GroupPoints->PushButton1) {
00301     myEditCurrentArgument = GroupPoints->LineEdit1;
00302     GroupPoints->CheckButton1->setEnabled(false);
00303   }
00304   else if (send == GroupPoints->PushButton2) {
00305     myEditCurrentArgument = GroupPoints->LineEdit2;
00306 
00307     if ( GroupPoints->CheckButton1->isChecked() ) {
00308       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
00309     } else {
00310       TColStd_MapOfInteger aMap;
00311       aMap.Add(GEOM_COMPOUND);
00312       aMap.Add(GEOM_WIRE);
00313       aMap.Add(GEOM_LINE);
00314       globalSelection(aMap);
00315     }
00316     GroupPoints->CheckButton1->setEnabled(true);
00317   }
00318   else if(send == GroupPoints->PushButton3) {
00319     myEditCurrentArgument = GroupPoints->LineEdit3;
00320     GroupPoints->CheckButton1->setEnabled(false);
00321     localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
00322   }
00323   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
00324           this, SLOT(SelectionIntoArgument()));
00325 
00326   // enable line edit
00327   myEditCurrentArgument->setEnabled(true);
00328   myEditCurrentArgument->setFocus();
00329   // after setFocus(), because it will be setDown(false) when loses focus
00330   send->setDown(true);
00331 
00332   // seems we need it only to avoid preview disappearing, caused by selection mode change
00333   processPreview();
00334 }
00335 
00336 //=================================================================================
00337 // function : ActivateThisDialog()
00338 // purpose  :
00339 //=================================================================================
00340 void GenerationGUI_PipeDlg::ActivateThisDialog()
00341 {
00342   GEOMBase_Skeleton::ActivateThisDialog();
00343   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
00344            this, SLOT( SelectionIntoArgument() ) );
00345 
00346   ConstructorsClicked(getConstructorId());
00347 }
00348 
00349 //=================================================================================
00350 // function : enterEvent()
00351 // purpose  : when mouse enter onto the QWidget
00352 //=================================================================================
00353 void GenerationGUI_PipeDlg::enterEvent (QEvent*)
00354 {
00355   if (!mainFrame()->GroupConstructors->isEnabled())
00356     ActivateThisDialog();
00357 }
00358 
00359 //=================================================================================
00360 // function : createOperation
00361 // purpose  :
00362 //=================================================================================
00363 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
00364 {
00365   return getGeomEngine()->GetI3DPrimOperations(getStudyId());
00366 }
00367 
00368 //=================================================================================
00369 // function : isValid
00370 // purpose  :
00371 //=================================================================================
00372 bool GenerationGUI_PipeDlg::isValid (QString&)
00373 {
00374   bool ok = false;
00375   switch ( getConstructorId() ) {
00376   case 0 :
00377     ok = !myBaseObjects.isEmpty() && myPath;
00378     break;
00379   case 1 :
00380     ok = !myBaseObjects.isEmpty() && myPath && myVec;
00381     break;
00382   default:
00383     break;
00384   }
00385   return ok;
00386 }
00387 
00388 //=================================================================================
00389 // function : execute
00390 // purpose  :
00391 //=================================================================================
00392 bool GenerationGUI_PipeDlg::execute (ObjectList& objects)
00393 {
00394   GEOM::GEOM_Object_var anObj;
00395 
00396   GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation());
00397 
00398   for (int i = 0; i < myBaseObjects.count(); i++) {
00399     switch ( getConstructorId() ) {
00400     case 0 :
00401       anObj = anOper->MakePipe(myBaseObjects[i].get(), myPath.get());
00402       break;
00403     case 1 :
00404       anObj = anOper->MakePipeBiNormalAlongVector(myBaseObjects[i].get(), myPath.get(), myVec.get());
00405       break;
00406     }
00407     
00408     if (!anObj->_is_nil())
00409       objects.push_back(anObj._retn());
00410   }
00411   return true;
00412 }
00413 
00414 //=================================================================================
00415 // function : addSubshapeToStudy
00416 // purpose  : virtual method to add new SubObjects if local selection
00417 //=================================================================================
00418 void GenerationGUI_PipeDlg::addSubshapesToStudy()
00419 {
00420   GEOMBase::PublishSubObject( myPath.get() );
00421   GEOMBase::PublishSubObject( myVec.get() );
00422 }
00423 
00424 //=================================================================================
00425 // function : extractPrefix
00426 // purpose  : redefined from GEOMBase_Helper class
00427 //=================================================================================
00428 bool GenerationGUI_PipeDlg::extractPrefix() const
00429 {
00430   return myBaseObjects.count() > 1;
00431 }