Back to index

salome-geom  6.5.0
EntityGUI_3DSketcherDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // GEOM GEOMGUI : GUI for Geometry component
00021 // File   : EntityGUI_3DSketcherDlg.cxx
00022 // Author : DMV, OCN
00023 //
00024 #include "EntityGUI_3DSketcherDlg.h"
00025 #include "EntityGUI_Widgets.h"
00026 #include <SalomeApp_DoubleSpinBox.h>
00027 
00028 #include <GEOMBase.h>
00029 #include <GeometryGUI.h>
00030 #include <GEOMImpl_Types.hxx>
00031 #include <Precision.hxx>  
00032 
00033 #include <DlgRef.h>
00034 #include <SUIT_Desktop.h>
00035 #include <SUIT_Session.h>
00036 #include <SUIT_MessageBox.h>
00037 #include <SUIT_ResourceMgr.h>
00038 #include <SalomeApp_Application.h>
00039 #include <LightApp_Application.h>
00040 #include <LightApp_SelectionMgr.h>
00041 
00042 //#include <BRep_Tool.hxx>
00043 //#include <TopExp.hxx>
00044 //#include <TopExp_Explorer.hxx>
00045 //#include <TopoDS_Vertex.hxx>
00046 //#include <TopoDS.hxx>
00047 #include <TColStd_IndexedMapOfInteger.hxx>
00048 //#include <BRepBuilderAPI_Transform.hxx>
00049 //#include <BRepBuilderAPI_MakeWire.hxx>
00050 #include <BRepBuilderAPI_MakeVertex.hxx>
00051 #include <BRepBuilderAPI_MakePolygon.hxx>
00052 #include <BRepBuilderAPI_MakeEdge.hxx>
00053 
00054 class Locker
00055 {
00056 public:
00057   Locker( bool& l ) : myLock( l ) { myLock = true;  }
00058   ~Locker()                       { myLock = false; }
00059 private:
00060   bool& myLock;
00061 };
00062 
00063 //=================================================================================
00064 // class    : EntityGUI_3DSketcherDlg()
00065 // purpose  : Constructs a EntityGUI_3DSketcherDlg which is a child of 'parent', with the
00066 //            name 'name' and widget flags set to 'f'.
00067 //            The dialog will by default be modeless, unless you set 'modal' to
00068 //            TRUE to construct a modal dialog.
00069 //=================================================================================
00070 EntityGUI_3DSketcherDlg::EntityGUI_3DSketcherDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
00071                                                   bool modal, Qt::WindowFlags fl,
00072                                                   const double lineWidth )
00073   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ),
00074     myMode( -1 ),
00075     myOK( false ),
00076     myLineWidth( lineWidth ),
00077     myGeometryGUI( theGeometryGUI )
00078 {
00079   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00080   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO" ) ) );
00081   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_REDO" ) ) );
00082   QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICO_3DSKETCH" ) ) );
00083 
00084   setWindowTitle( tr( "GEOM_3DSKETCHER_TITLE" ) );
00085 
00086   /***************************************************************/
00087 
00088   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_3DSKETCHER" ) );
00089   mainFrame()->RadioButton1->setIcon( image3 );;
00090   mainFrame()->RadioButton2->close();
00091   mainFrame()->RadioButton3->close();
00092 
00093   GroupType = new DlgRef_3Radio(centralWidget());
00094   GroupType->GroupBox1->setTitle(tr("GEOM_COORDINATES_TYPE"));
00095   GroupType->RadioButton1->setText(tr("GEOM_SKETCHER_ABS"));
00096   GroupType->RadioButton2->setText(tr("GEOM_SKETCHER_REL"));
00097   GroupType->RadioButton3->close();
00098   myTypeGroup = new QButtonGroup( this );
00099   myTypeGroup->addButton( GroupType->RadioButton1, 0 );
00100   myTypeGroup->addButton( GroupType->RadioButton2, 1 );
00101 
00102   Group3Spin = new EntityGUI_3Spin( centralWidget() );
00103   Group3Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
00104   Group3Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
00105   Group3Spin->buttonUndo->setIcon( image1 );
00106   Group3Spin->buttonRedo->setIcon( image2 );
00107   Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
00108   Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
00109   Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Z2" ) );
00110 
00111   buttonOk()->setText( tr( "GEOM_BUT_END_SKETCH" ) );
00112   buttonApply()->setText( tr( "GEOM_BUT_CLOSE_SKETCH" ) );
00113   
00114   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00115   layout->setMargin( 0 ); layout->setSpacing( 6 );
00116   layout->addWidget( GroupType );
00117   layout->addWidget( Group3Spin );
00118 
00119   setHelpFileName( "create_3dsketcher_page.html" );
00120 
00121   resize(100,100);
00122   Init();
00123 }  
00124 
00125 
00126 
00127 //=================================================================================
00128 // function : ~EntityGUI_3DSketcherDlg()
00129 // purpose  : Destroys the object and frees any allocated resources
00130 //=================================================================================
00131 EntityGUI_3DSketcherDlg::~EntityGUI_3DSketcherDlg()
00132 {
00133   myGeomGUI->SetActiveDialogBox( 0 );
00134 }
00135 
00136 //=================================================================================
00137 // function : Init()
00138 // purpose  :
00139 //=================================================================================
00140 void EntityGUI_3DSketcherDlg::Init()
00141 {
00142   myOK = false;
00143 
00144   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
00145 
00146   /* Get setting of step value from file configuration */
00147   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
00148 
00149   /* min, max, step and decimals for spin boxes */
00150   initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
00151   initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
00152   initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
00153 
00154   Group3Spin->SpinBox_DX->setValue(0.0);
00155   Group3Spin->SpinBox_DY->setValue(0.0);
00156   Group3Spin->SpinBox_DZ->setValue(0.0);
00157 
00158   /* signals and slots connections */
00159   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00160   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00161 
00162   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00163 
00164   connect( Group3Spin->buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnAddPoint() ) );
00165   connect( Group3Spin->buttonUndo,   SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
00166   connect( Group3Spin->buttonRedo,   SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) ) ;
00167 
00168   connect( myTypeGroup, SIGNAL( buttonClicked( int ) ),  this, SLOT( TypeClicked( int ) ) );
00169 
00170   connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00171   connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00172   connect( Group3Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
00173 
00174   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
00175 
00176   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
00177   connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
00178 
00179   initName( tr( "GEOM_3DSKETCHER" ) );
00180 
00181   UpdateButtonsState();
00182   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
00183 }
00184 
00185 //=================================================================================
00186 // function : TypeClicked()
00187 // purpose  : Radio button management
00188 //=================================================================================
00189 void EntityGUI_3DSketcherDlg::TypeClicked( int mode )
00190 {
00191   if ( mode == myMode ) return;
00192 
00193   bool blocked = Group3Spin->SpinBox_DX->signalsBlocked();
00194   Group3Spin->SpinBox_DX->blockSignals(true);
00195   Group3Spin->SpinBox_DY->blockSignals(true);
00196   Group3Spin->SpinBox_DZ->blockSignals(true);
00197   // Get setting of step value from file configuration
00198   XYZ xyz = getLastPoint();
00199   bool okx, oky, okz;
00200   Group3Spin->SpinBox_DX->text().toDouble( &okx );
00201   Group3Spin->SpinBox_DY->text().toDouble( &oky );
00202   Group3Spin->SpinBox_DZ->text().toDouble( &okz );
00203   if ( mode == 0 ) {  // XY
00204     Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
00205     Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
00206     Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Z2" ) );
00207     if ( okx ) Group3Spin->SpinBox_DX->setValue( xyz.x + Group3Spin->SpinBox_DX->value() );
00208     if ( oky ) Group3Spin->SpinBox_DY->setValue( xyz.y + Group3Spin->SpinBox_DY->value() );
00209     if ( okz ) Group3Spin->SpinBox_DZ->setValue( xyz.z + Group3Spin->SpinBox_DZ->value() );
00210     Group3Spin->buttonApply->setFocus();
00211   }
00212   else { // DXDY
00213     Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
00214     Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
00215     Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_DZ2" ) );
00216     if ( okx ) Group3Spin->SpinBox_DX->setValue( Group3Spin->SpinBox_DX->value() - xyz.x );
00217     if ( oky ) Group3Spin->SpinBox_DY->setValue( Group3Spin->SpinBox_DY->value() - xyz.y );
00218     if ( okz ) Group3Spin->SpinBox_DZ->setValue( Group3Spin->SpinBox_DZ->value() - xyz.z );
00219     Group3Spin->buttonApply->setFocus();
00220   }
00221   Group3Spin->SpinBox_DX->blockSignals(blocked);
00222   Group3Spin->SpinBox_DY->blockSignals(blocked);
00223   Group3Spin->SpinBox_DZ->blockSignals(blocked);
00224 
00225   myMode = mode;
00226 }
00227 
00228 //=================================================================================
00229 // function : ClickOnAddPoint()
00230 // purpose  : called when the point coordinates is Applyed
00231 //=================================================================================
00232 void EntityGUI_3DSketcherDlg::ClickOnAddPoint()
00233 {
00234   QString msg;
00235   if ( !isValid( msg ) ) {
00236     showError( msg );
00237     return;
00238   }
00239 
00240   myPointsList.append( getCurrentPoint() );
00241   myRedoList.clear();
00242 
00243   if ( myMode == 1 ) {
00244     Group3Spin->SpinBox_DX->setValue( 0.0 );
00245     Group3Spin->SpinBox_DY->setValue( 0.0 );
00246     Group3Spin->SpinBox_DZ->setValue( 0.0 );
00247   }
00248   UpdateButtonsState();
00249   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
00250 }
00251 
00252 //=================================================================================
00253 // function : UpdateButtonsState()
00254 // purpose  : 
00255 //=================================================================================
00256 void EntityGUI_3DSketcherDlg::UpdateButtonsState()
00257 {
00258   if ( myPointsList.count() == 0 ) GroupType->RadioButton1->click();
00259   GroupType->RadioButton2->setEnabled( myPointsList.count() > 0 );
00260   Group3Spin->buttonUndo->setEnabled( myPointsList.count() > 0 );
00261   Group3Spin->buttonRedo->setEnabled( myRedoList.count() > 0 );
00262 }
00263 
00264 //=================================================================================
00265 // function : ClickOnUndo()
00266 // purpose  :
00267 //=================================================================================
00268 void EntityGUI_3DSketcherDlg::ClickOnUndo()
00269 {
00270   if (myPointsList.count() > 0) {
00271     myRedoList.append( myPointsList.takeLast() );
00272     UpdateButtonsState();
00273     GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
00274   }
00275 }
00276 
00277 //=================================================================================
00278 // function : ClickOnRedo()
00279 // purpose  :
00280 //=================================================================================
00281 void EntityGUI_3DSketcherDlg::ClickOnRedo()
00282 {
00283   if ( myRedoList.count() > 0) {
00284     myPointsList.append( myRedoList.takeLast() );
00285     UpdateButtonsState();
00286     GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
00287   }
00288 }
00289 
00290 //=================================================================================
00291 // function : SelectionIntoArgument()
00292 // purpose  : Called when selection as changed
00293 //=================================================================================
00294 void EntityGUI_3DSketcherDlg::SelectionIntoArgument()
00295 {
00296   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00297   SALOME_ListIO aSelList;
00298   aSelMgr->selectedObjects(aSelList);
00299 
00300   int nbSel = aSelList.Extent();
00301   if ( nbSel == 1 ) {
00302     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
00303     if ( !CORBA::is_nil(aSelectedObject) ) {
00304       TopoDS_Shape aShape;
00305       if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE)) { // Explore the shape if its a local selection
00306         TColStd_IndexedMapOfInteger aMap;
00307         aSelMgr->GetIndexes(aSelList.First(), aMap);
00308         if (aMap.Extent() == 1)
00309           {
00310             int anIndex = aMap(1);
00311             GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
00312             aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
00313           }
00314       }
00315       bool isOk = true;
00316       if ( aShape.ShapeType() != TopAbs_VERTEX )
00317         isOk = GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX);
00318       if (isOk) {
00319         gp_Pnt aPnt;
00320         if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
00321           // set coordinates to the Spin Boxes
00322           double aX, aY, aZ;
00323           aX = aPnt.X();
00324           aY = aPnt.Y();
00325           aZ = aPnt.Z();
00326           bool blocked = Group3Spin->SpinBox_DX->signalsBlocked();
00327           Group3Spin->SpinBox_DX->blockSignals(true);
00328           Group3Spin->SpinBox_DY->blockSignals(true);
00329           Group3Spin->SpinBox_DZ->blockSignals(true);
00330           if ( GroupType->RadioButton1->isChecked() ) {
00331             Group3Spin->SpinBox_DX->setValue( aX );
00332             Group3Spin->SpinBox_DY->setValue( aY );
00333             Group3Spin->SpinBox_DZ->setValue( aZ );
00334           } else if ( GroupType->RadioButton2->isChecked() ) {
00335             XYZ xyz = getLastPoint();
00336             Group3Spin->SpinBox_DX->setValue( aX - xyz.x );
00337             Group3Spin->SpinBox_DY->setValue( aY - xyz.y );
00338             Group3Spin->SpinBox_DZ->setValue( aZ - xyz.z );
00339           }
00340           Group3Spin->SpinBox_DX->blockSignals(blocked);
00341           Group3Spin->SpinBox_DY->blockSignals(blocked);
00342           Group3Spin->SpinBox_DZ->blockSignals(blocked);
00343         }
00344       }
00345     }
00346   }
00347   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
00348 }
00349 
00350 //=================================================================================
00351 // function : DeactivateActiveDialog()
00352 // purpose  :
00353 //=================================================================================
00354 void EntityGUI_3DSketcherDlg::DeactivateActiveDialog()
00355 {
00356   setEnabled( false );
00357   globalSelection();
00358   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
00359   myGeomGUI->SetActiveDialogBox( 0 );
00360 }
00361 
00362 
00363 //=================================================================================
00364 // function : ActivateThisDialog()
00365 // purpose  :
00366 //=================================================================================
00367 void EntityGUI_3DSketcherDlg::ActivateThisDialog()
00368 {
00369   myGeomGUI->EmitSignalDeactivateDialog();
00370   setEnabled( true );
00371   myGeomGUI->SetActiveDialogBox( this );
00372 
00373   connect( myGeomGUI->getApp()->selectionMgr(),
00374           SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00375 
00376   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
00377   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
00378 }
00379 
00380 
00381 //=================================================================================
00382 // function : ValueChangedInSpinBox()
00383 // purpose  :
00384 //=================================================================================
00385 void EntityGUI_3DSketcherDlg::ValueChangedInSpinBox( double newValue )
00386 {
00387   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
00388 }
00389 
00390 //=================================================================================
00391 // function : enterEvent()
00392 // purpose  :
00393 //=================================================================================
00394 void EntityGUI_3DSketcherDlg::enterEvent( QEvent* )
00395 {
00396   if ( !mainFrame()->GroupConstructors->isEnabled() )
00397     ActivateThisDialog();
00398 }
00399 
00400 //=================================================================================
00401 // function : createOperation
00402 // purpose  :
00403 //=================================================================================
00404 GEOM::GEOM_IOperations_ptr EntityGUI_3DSketcherDlg::createOperation()
00405 {
00406   return getGeomEngine()->GetICurvesOperations( getStudyId() );
00407 }
00408 
00409 //=================================================================================
00410 // function : isValid
00411 // purpose  :
00412 //=================================================================================
00413 bool EntityGUI_3DSketcherDlg::isValid( QString& msg )
00414 {
00415   bool ok = true;
00416   ok = Group3Spin->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
00417   ok = Group3Spin->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
00418   ok = Group3Spin->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
00419   return ok;
00420 }
00421 
00422 //=================================================================================
00423 // function : execute
00424 // purpose  :
00425 //=================================================================================
00426 bool EntityGUI_3DSketcherDlg::execute( ObjectList& objects )
00427 {
00428   GEOM::ListOfDouble_var aCoordsArray = new GEOM::ListOfDouble;
00429   if (!myOK || myPointsList.size() == 0)
00430     aCoordsArray->length((myPointsList.size()+1)*3);
00431   else
00432     aCoordsArray->length(myPointsList.size()*3);
00433 
00434   QStringList aParameters;
00435 
00436   int i = 0;
00437   QList<XYZ>::const_iterator it;
00438   for(it = myPointsList.begin(); it != myPointsList.end(); ++it ) {
00439     aCoordsArray[i++] = (*it).x;
00440     aCoordsArray[i++] = (*it).y;
00441     aCoordsArray[i++] = (*it).z;
00442     aParameters << (*it).xt;
00443     aParameters << (*it).yt;
00444     aParameters << (*it).zt;
00445   }
00446 
00447   if (!myOK || myPointsList.size() == 0) {
00448     XYZ xyz = getCurrentPoint();
00449     aCoordsArray[i++] = xyz.x;
00450     aCoordsArray[i++] = xyz.y;
00451     aCoordsArray[i++] = xyz.z;
00452     aParameters << xyz.xt;
00453     aParameters << xyz.yt;
00454     aParameters << xyz.zt;
00455   } 
00456 
00457   GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
00458   GEOM::GEOM_Object_var anObj = anOper->Make3DSketcher( aCoordsArray );
00459 
00460   if ( !anObj->_is_nil() ) {
00461     if ( !IsPreview() ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00462     objects.push_back( anObj._retn() );
00463   }
00464 
00465   return true;
00466 }
00467 
00468 //=================================================================================
00469 // function : SetDoubleSpinBoxStep()
00470 // purpose  : Double spin box management
00471 //=================================================================================
00472 void EntityGUI_3DSketcherDlg::SetDoubleSpinBoxStep( double step )
00473 {
00474   Group3Spin->SpinBox_DX->setSingleStep(step);
00475   Group3Spin->SpinBox_DY->setSingleStep(step);
00476   Group3Spin->SpinBox_DZ->setSingleStep(step);
00477 }
00478 
00479 //=================================================================================
00480 // function : ClickOnOk()
00481 // purpose  :
00482 //=================================================================================
00483 void EntityGUI_3DSketcherDlg::ClickOnOk()
00484 {
00485   Locker lock( myOK );
00486 
00487   if ( !onAccept() )
00488     return;
00489 
00490   ClickOnCancel();
00491 }
00492 
00493 //=================================================================================
00494 // function : ClickOnApply()
00495 // purpose  :
00496 //=================================================================================
00497 bool EntityGUI_3DSketcherDlg::ClickOnApply()
00498 {
00499   QString msg;
00500   if ( !isValid( msg ) ) {
00501     showError( msg );
00502     return false;
00503   }
00504 
00505   if (myPointsList.count() > 0)
00506     myPointsList.append(myPointsList[0]);
00507 
00508   Locker lock( myOK );
00509 
00510   if ( !onAccept() )
00511     return false;
00512 
00513   ClickOnCancel();
00514   return true;
00515 }
00516 
00517 //=================================================================================
00518 // function : getLastPoint()
00519 // purpose  : return last points from list
00520 //=================================================================================
00521 EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getLastPoint() const
00522 {
00523   return myPointsList.count() > 0 ? myPointsList.last() : XYZ();
00524 }
00525 
00526 //=================================================================================
00527 // function : getCurrentPoint()
00528 // purpose  : returns current points
00529 //=================================================================================
00530 EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getCurrentPoint() const
00531 {
00532   XYZ xyz;
00533   if ( myMode == 0 ) {
00534     xyz.x = Group3Spin->SpinBox_DX->value();
00535     xyz.y = Group3Spin->SpinBox_DY->value();
00536     xyz.z = Group3Spin->SpinBox_DZ->value();
00537   } 
00538   else {
00539     xyz = getLastPoint();
00540     xyz.x += Group3Spin->SpinBox_DX->value();
00541     xyz.y += Group3Spin->SpinBox_DY->value();
00542     xyz.z += Group3Spin->SpinBox_DZ->value();
00543   }
00544   xyz.xt = Group3Spin->SpinBox_DX->text();
00545   xyz.yt = Group3Spin->SpinBox_DY->text();
00546   xyz.zt = Group3Spin->SpinBox_DZ->text();
00547   return xyz;
00548 }
00549 
00550 //================================================================
00551 // Function : displayPreview
00552 // Purpose  : Method for displaying preview of resulting shape
00553 //            Redefined from GEOMBase_Helper.
00554 //================================================================
00555 void EntityGUI_3DSketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
00556                                               const bool            append,
00557                                               const bool            activate,
00558                                               const bool            update,
00559                                               const double          lineWidth,
00560                                               const int             displayMode,
00561                                               const int             color )
00562 {
00563   // Set color for preview shape
00564   getDisplayer()->SetColor( Quantity_NOC_RED );
00565 
00566   // set width of displayed shape
00567   getDisplayer()->SetWidth( (lineWidth == -1)?myLineWidth:lineWidth ); 
00568 
00569   // Disable activation of selection
00570   getDisplayer()->SetToActivate( activate );
00571 
00572   // Make a reference to GEOM_Object
00573   CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
00574   getDisplayer()->SetName( objStr.in() );
00575 
00576   // Create wire from applied object
00577   TopoDS_Shape anApplyedWire, aLastSegment;
00578   if ( !createShapes( object, anApplyedWire, aLastSegment ) )
00579     return;
00580 
00581   // Build prs
00582   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
00583   if ( aPrs != 0 && !aPrs->IsNull() )
00584     GEOMBase_Helper::displayPreview( aPrs, append, update );
00585 
00586   getDisplayer()->SetColor( Quantity_NOC_VIOLET );
00587   aPrs = getDisplayer()->BuildPrs( aLastSegment );
00588   if ( aPrs != 0 && !aPrs->IsNull() )
00589     GEOMBase_Helper::displayPreview( aPrs, append, update );
00590 
00591   getDisplayer()->UnsetName();
00592 
00593   // Enable activation of displayed objects
00594   getDisplayer()->SetToActivate( true );
00595 }
00596 
00597 //================================================================
00598 // Function : createShapes
00599 // Purpose  : Create applyed wire, and last segment from entry object
00600 //================================================================
00601 bool EntityGUI_3DSketcherDlg::createShapes( GEOM::GEOM_Object_ptr /*theObject*/,
00602                                             TopoDS_Shape&         theApplyedWire,
00603                                             TopoDS_Shape&         theLastSegment )
00604 {
00605   QList<gp_Pnt> points;
00606   foreach( XYZ xyz, myPointsList) {
00607     gp_Pnt p(xyz.x, xyz.y, xyz.z);
00608     if ( points.isEmpty() || points.last().Distance(p) > gp::Resolution())
00609       points << p;
00610   } 
00611   
00612   if ( points.count() == 1 ) {
00613     // only one point is created
00614     BRepBuilderAPI_MakeVertex mkVertex (points.last());
00615     theApplyedWire = mkVertex.Shape();
00616   }
00617   else if ( points.count() > 1 ) {
00618     // wire is created
00619     BRepBuilderAPI_MakePolygon mkWire;
00620     foreach( gp_Pnt p, points )
00621       mkWire.Add(p);
00622     theApplyedWire = mkWire.Shape();
00623   }
00624 
00625   XYZ curxyz = getCurrentPoint();
00626   gp_Pnt curpnt(curxyz.x, curxyz.y, curxyz.z);
00627   
00628   if ( points.isEmpty() || points.last().Distance(curpnt) <= gp::Resolution() ) {
00629     BRepBuilderAPI_MakeVertex mkVertex (curpnt);
00630     theLastSegment = mkVertex.Shape();
00631   }
00632   else {
00633     BRepBuilderAPI_MakeEdge mkEdge(points.last(), curpnt);
00634     theLastSegment = mkEdge.Shape();
00635   }
00636 
00637   /* VSR: old algorithm does not work properly, see bug 0020899
00638   TopoDS_Shape aShape;
00639   if ( !GEOMBase::GetShape( theObject, aShape ) )
00640     return false;
00641 
00642   if( aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
00643     return false;
00644 
00645   theApplyedWire = aShape;
00646   if ( myOK  )
00647      return true;
00648 
00649   BRepBuilderAPI_MakeWire aBuilder;
00650   TopExp_Explorer edgeExp( aShape, TopAbs_EDGE );
00651   while ( 1 ) {
00652     TopoDS_Shape anEdge = edgeExp.Current();
00653     edgeExp.Next();
00654     if ( edgeExp.More() ) // i.e. non-last edge
00655       aBuilder.Add( TopoDS::Edge( anEdge ) );
00656     else {
00657       theLastSegment = anEdge;
00658       break;
00659     }
00660   }
00661 
00662   if ( aBuilder.IsDone() ) {
00663     theApplyedWire = aBuilder.Shape();
00664   }
00665   else if ( !theLastSegment.IsNull() ) {
00666     TopExp_Explorer vertexExp( theLastSegment, TopAbs_VERTEX );
00667     theApplyedWire = vertexExp.Current();
00668     }
00669   */
00670 
00671   return true;
00672 }