Back to index

salome-geom  6.5.0
RepairGUI_DivideEdgeDlg.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   : RepairGUI_DivideEdgeDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 //
00027 #include "RepairGUI_DivideEdgeDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOMBase.h>
00032 #include <SalomeApp_DoubleSpinBox.h>
00033 
00034 #include <SalomeApp_Application.h>
00035 #include <LightApp_SelectionMgr.h>
00036 #include <SUIT_Session.h>
00037 #include <SUIT_ResourceMgr.h>
00038 
00039 #include <GEOMImpl_Types.hxx>
00040 
00041 #include <TopAbs.hxx>
00042 #include <Geom_Curve.hxx>
00043 #include <gp_Pnt.hxx>
00044 #include <TopoDS.hxx>
00045 #include <TopExp.hxx>
00046 #include <TopoDS_Edge.hxx>
00047 #include <BRep_Tool.hxx>
00048 #include <TopTools_IndexedMapOfShape.hxx>
00049 #include <BRepBuilderAPI_MakeVertex.hxx>
00050 #include <TColStd_IndexedMapOfInteger.hxx>
00051 
00052 //=================================================================================
00053 // class    : RepairGUI_DivideEdgeDlg()
00054 // purpose  : Constructs a RepairGUI_DivideEdgeDlg  which is a child of 'parent', with the
00055 //            name 'name' and widget flags set to 'f'.
00056 //            The dialog will by default be modeless, unless you set 'modal' to
00057 //            TRUE to construct a modal dialog.
00058 //=================================================================================
00059 RepairGUI_DivideEdgeDlg::RepairGUI_DivideEdgeDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
00060                                                   bool modal )
00061   : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
00062 {
00063   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_DIVIDE_EDGE" ) ) );
00064   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00065 
00066   setWindowTitle( tr( "GEOM_DIVIDE_EDGE_TITLE" ) );
00067 
00068   /***************************************************************/
00069   mainFrame()->GroupConstructors->setTitle(tr("GEOM_DIVIDE_EDGE_TITLE"));
00070   mainFrame()->RadioButton1->setIcon( image0 );
00071   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
00072   mainFrame()->RadioButton2->close();
00073   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
00074   mainFrame()->RadioButton3->close();
00075 
00076   GroupPoints = new DlgRef_1SelExt( centralWidget() );
00077   GroupPoints->GroupBox1->setTitle( tr( "GEOM_ADD_POINT" ) );
00078   GroupPoints->TextLabel1->setText( tr( "GEOM_EDGE" ) );
00079   GroupPoints->PushButton1->setIcon( image1 );
00080   GroupPoints->LineEdit1->setReadOnly( true );
00081 
00082   QRadioButton* rb1 = new QRadioButton( tr( "GEOM_BY_PARAMETER" ), GroupPoints->Box );
00083   QRadioButton* rb2 = new QRadioButton( tr( "GEOM_BY_LENGTH" ),    GroupPoints->Box );
00084 
00085   myIsParameterGr = new QButtonGroup( GroupPoints->Box );
00086   myIsParameterGr->addButton( rb1, 0 );
00087   myIsParameterGr->addButton( rb2, 1 );
00088   rb1->setChecked( true );
00089 
00090   myValEdt = new SalomeApp_DoubleSpinBox( GroupPoints->Box );
00091   initSpinBox( myValEdt, 0., 1., 0.1, "parametric_precision" );
00092   myValEdt->setValue( 0.5 );
00093   QLabel* aLbl1 = new QLabel( tr( "GEOM_VALUE" ), GroupPoints->Box );
00094 
00095   QGridLayout* l = new QGridLayout( GroupPoints->Box );
00096   l->setMargin( 0 ); l->setSpacing( 6 );
00097   l->addWidget( rb1, 0, 0, 1, 2 );
00098   l->addWidget( rb2, 1, 0, 1, 2 );
00099   l->addWidget( aLbl1, 2, 0 );
00100   l->addWidget( myValEdt, 2, 1 );
00101 
00102   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00103   layout->setMargin( 0 ); layout->setSpacing( 6 );
00104   layout->addWidget( GroupPoints );
00105 
00106   /***************************************************************/
00107 
00108   setHelpFileName( "add_point_on_edge_operation_page.html" );
00109 
00110   Init();
00111 }
00112 
00113 //=================================================================================
00114 // function : ~RepairGUI_DivideEdgeDlg()
00115 // purpose  : Destroys the object and frees any allocated resources
00116 //=================================================================================
00117 RepairGUI_DivideEdgeDlg::~RepairGUI_DivideEdgeDlg()
00118 {
00119 }
00120 
00121 //=================================================================================
00122 // function : Init()
00123 // purpose  :
00124 //=================================================================================
00125 void RepairGUI_DivideEdgeDlg::Init()
00126 {
00127   /* init variables */
00128   myEditCurrentArgument = GroupPoints->LineEdit1;
00129 
00130   myObject = GEOM::GEOM_Object::_nil();
00131   myIndex = -1;
00132 
00133   //myGeomGUI->SetState( 0 );
00134   initSelection();
00135 
00136   /* signals and slots connections */
00137   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00138   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00139 
00140   connect( myValEdt,   SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
00141 
00142   connect( GroupPoints->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
00143   connect( GroupPoints->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
00144 
00145   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
00146            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00147 
00148   initName( tr( "DEVIDE_EDGE_NEW_OBJECT_NAME" ) );
00149   resize(100,100);
00150   SelectionIntoArgument();
00151 }
00152 
00153 //=================================================================================
00154 // function : ValueChangedInSpinBox()
00155 // purpose  : On change value in spin box
00156 //=================================================================================
00157 void RepairGUI_DivideEdgeDlg::ValueChangedInSpinBox()
00158 {
00159   displayPreview();
00160 }
00161 
00162 //=================================================================================
00163 // function : displayPreview()
00164 // purpose  : On display Preview
00165 //=================================================================================
00166 void RepairGUI_DivideEdgeDlg::displayPreview()
00167 {
00168   erasePreview();
00169   if ( myObject->_is_nil() )
00170     return;
00171 
00172   TopoDS_Shape aShape;
00173   gp_Pnt aPnt;
00174   GEOMBase::GetShape( myObject, aShape, TopAbs_SHAPE );
00175 
00176   if ( myIndex != -1) {
00177     TopTools_IndexedMapOfShape aShapes;
00178     TopExp::MapShapes(aShape, aShapes);
00179     aShape = aShapes.FindKey(myIndex);
00180   }
00181 
00182   if (aShape.ShapeType() == TopAbs_EDGE) {
00183     Standard_Real aFP, aLP, aP;
00184     Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
00185     aP = aFP + (aLP - aFP) * myValEdt->value();
00186     aPnt = aCurve->Value(aP);
00187     BRepBuilderAPI_MakeVertex mkVertex (aPnt);
00188     aShape = mkVertex.Shape();
00189     // Build prs
00190     SALOME_Prs* aPrs = getDisplayer()->BuildPrs( aShape );
00191     if ( aPrs != 0 && !aPrs->IsNull() )
00192       GEOMBase_Helper::displayPreview( aPrs, false, true );
00193   } 
00194 }
00195 
00196 //=================================================================================
00197 // function : ClickOnOk()
00198 // purpose  : Same than click on apply but close this dialog.
00199 //=================================================================================
00200 void RepairGUI_DivideEdgeDlg::ClickOnOk()
00201 {
00202   setIsApplyAndClose( true );
00203   if ( ClickOnApply() )
00204     ClickOnCancel();
00205 }
00206 
00207 
00208 //=================================================================================
00209 // function : ClickOnApply()
00210 // purpose  :
00211 //=================================================================================
00212 bool RepairGUI_DivideEdgeDlg::ClickOnApply()
00213 {
00214   if ( !onAccept() )
00215     return false;
00216 
00217   initName();
00218 
00219   myEditCurrentArgument->setText( "" );
00220   myObject = GEOM::GEOM_Object::_nil();
00221   myIndex = -1;
00222 
00223   initSelection();
00224 
00225   return true;
00226 }
00227 
00228 
00229 //=================================================================================
00230 // function : SelectionIntoArgument()
00231 // purpose  : Called when selection as changed or other case
00232 //          : used only by SelectButtonC1A1 (LineEditC1A1)
00233 //=================================================================================
00234 void RepairGUI_DivideEdgeDlg::SelectionIntoArgument()
00235 {
00236   myEditCurrentArgument->setText( "" );
00237 
00238   myObject = GEOM::GEOM_Object::_nil();
00239   myIndex = -1;
00240 
00241   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00242   SALOME_ListIO aSelList;
00243   aSelMgr->selectedObjects(aSelList);
00244 
00245   if ( aSelList.Extent() == 1 ) {
00246     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
00247     GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO );
00248     if ( !CORBA::is_nil( aSelectedObj ) )
00249     {
00250       TopoDS_Shape aShape;
00251       QString aName = GEOMBase::GetName( aSelectedObj );
00252       if ( GEOMBase::GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) )
00253       {
00254         const int aType = aShape.ShapeType();
00255         if ( aType <= TopAbs_EDGE ) // edge, wire, face, shell, solid, compound
00256         {
00257           GEOM::short_array anIndexes;
00258 
00259           TColStd_IndexedMapOfInteger aMap;
00260           SalomeApp_Application* anApp =
00261             (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
00262           anApp->selectionMgr()->GetIndexes( anIO, aMap );
00263 
00264           if ( !aMap.IsEmpty() ) // sub-shape selection
00265           {
00266             myIndex = aMap( 1 );
00267             myObject = aSelectedObj;
00268             myEditCurrentArgument->setText( aName += QString( ":edge_%1" ).arg( myIndex ) );
00269           }
00270           else if ( aType == TopAbs_EDGE ) // single shape selection
00271           {
00272             myIndex = -1;
00273             myObject = aSelectedObj;
00274             myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
00275           }
00276           else // face, shell, solid or compound was selected, and NOT its sub-shape.
00277           {
00278             myIndex = -1;
00279             myObject = GEOM::GEOM_Object::_nil();
00280           }
00281         }
00282       }
00283     }
00284   }
00285 
00286   displayPreview();
00287 }
00288 
00289 //=================================================================================
00290 // function : SetEditCurrentArgument()
00291 // purpose  :
00292 //=================================================================================
00293 void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument()
00294 {
00295   if ( sender() == GroupPoints->PushButton1 ) {
00296     GroupPoints->LineEdit1->setFocus();
00297     myEditCurrentArgument = GroupPoints->LineEdit1;
00298   }
00299   SelectionIntoArgument();
00300 }
00301 
00302 
00303 //=================================================================================
00304 // function : LineEditReturnPressed()
00305 // purpose  :
00306 //=================================================================================
00307 void RepairGUI_DivideEdgeDlg::LineEditReturnPressed()
00308 {
00309   if ( sender() == GroupPoints->LineEdit1 ) {
00310     myEditCurrentArgument = GroupPoints->LineEdit1;
00311     GEOMBase_Skeleton::LineEditReturnPressed();
00312   }
00313 }
00314 
00315 
00316 //=================================================================================
00317 // function : ActivateThisDialog()
00318 // purpose  :
00319 //=================================================================================
00320 void RepairGUI_DivideEdgeDlg::ActivateThisDialog()
00321 {
00322   GEOMBase_Skeleton::ActivateThisDialog();
00323   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
00324            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00325 
00326 //  myObject = GEOM::GEOM_Object::_nil();
00327   myIndex = -1;
00328 
00329   //myGeomGUI->SetState( 0 );
00330   initSelection();
00331 }
00332 
00333 //=================================================================================
00334 // function : enterEvent()
00335 // purpose  : Mouse enter onto the dialog to activate it
00336 //=================================================================================
00337 void RepairGUI_DivideEdgeDlg::enterEvent( QEvent* )
00338 {
00339   if ( !mainFrame()->GroupConstructors->isEnabled() )
00340     ActivateThisDialog();
00341 }
00342 
00343 
00344 //=================================================================================
00345 // function : createOperation
00346 // purpose  :
00347 //=================================================================================
00348 GEOM::GEOM_IOperations_ptr RepairGUI_DivideEdgeDlg::createOperation()
00349 {
00350   return getGeomEngine()->GetIHealingOperations( getStudyId() );
00351 }
00352 
00353 //=================================================================================
00354 // function : isValid
00355 // purpose  :
00356 //=================================================================================
00357 bool RepairGUI_DivideEdgeDlg::isValid( QString& msg )
00358 {
00359   bool ok = myValEdt->isValid( msg, !IsPreview() );
00360   return !myObject->_is_nil() && ok;
00361 }
00362 
00363 //=================================================================================
00364 // function : execute
00365 // purpose  :
00366 //=================================================================================
00367 bool RepairGUI_DivideEdgeDlg::execute( ObjectList& objects )
00368 {
00369   GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
00370   GEOM::GEOM_Object_var anObj = anOper->DivideEdge( myObject, myIndex, myValEdt->value(), getIsByParameter() );
00371   bool aResult = !anObj->_is_nil();
00372   if ( aResult )
00373   {
00374     if ( !IsPreview() )
00375     {
00376       QStringList aParameters;
00377       aParameters << "";
00378       aParameters << myValEdt->text();
00379       aParameters << "";
00380       anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00381     }
00382     objects.push_back( anObj._retn() );
00383   }
00384 
00385   return aResult;
00386 }
00387 
00388 //=================================================================================
00389 // function : getIsByParameter
00390 // purpose  :
00391 //=================================================================================
00392 bool RepairGUI_DivideEdgeDlg::getIsByParameter() const
00393 {
00394   return myIsParameterGr->button( 0 )->isChecked();
00395 }
00396 
00397 //=================================================================================
00398 // function : initSelection
00399 // purpose  :
00400 //=================================================================================
00401 void RepairGUI_DivideEdgeDlg::initSelection()
00402 {
00403   GEOM::GEOM_Object_var aNullGeomObject;
00404   localSelection( aNullGeomObject, TopAbs_EDGE ); // load local selection on ALL objects
00405 }