Salome HOME
0021179: EDF 1654 SMESH GEOM: better look'n'feel
[modules/geom.git] / src / EntityGUI / EntityGUI_3DSketcherDlg.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // GEOM GEOMGUI : GUI for Geometry component
21 // File   : EntityGUI_3DSketcherDlg.cxx
22 // Author : DMV, OCN
23 //
24 #include "EntityGUI_3DSketcherDlg.h"
25 #include "EntityGUI_Widgets.h"
26 #include <SalomeApp_DoubleSpinBox.h>
27
28 #include <GEOMBase.h>
29 #include <GeometryGUI.h>
30 #include <GEOMImpl_Types.hxx>
31 #include <Precision.hxx>  
32
33 #include <DlgRef.h>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_Application.h>
40 #include <LightApp_SelectionMgr.h>
41
42 //#include <BRep_Tool.hxx>
43 //#include <TopExp.hxx>
44 //#include <TopExp_Explorer.hxx>
45 //#include <TopoDS_Vertex.hxx>
46 //#include <TopoDS.hxx>
47 #include <TColStd_IndexedMapOfInteger.hxx>
48 //#include <BRepBuilderAPI_Transform.hxx>
49 //#include <BRepBuilderAPI_MakeWire.hxx>
50 #include <BRepBuilderAPI_MakeVertex.hxx>
51 #include <BRepBuilderAPI_MakePolygon.hxx>
52 #include <BRepBuilderAPI_MakeEdge.hxx>
53
54 class Locker
55 {
56 public:
57   Locker( bool& l ) : myLock( l ) { myLock = true;  }
58   ~Locker()                       { myLock = false; }
59 private:
60   bool& myLock;
61 };
62
63 //=================================================================================
64 // class    : EntityGUI_3DSketcherDlg()
65 // purpose  : Constructs a EntityGUI_3DSketcherDlg which is a child of 'parent', with the
66 //            name 'name' and widget flags set to 'f'.
67 //            The dialog will by default be modeless, unless you set 'modal' to
68 //            TRUE to construct a modal dialog.
69 //=================================================================================
70 EntityGUI_3DSketcherDlg::EntityGUI_3DSketcherDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
71                                                   bool modal, Qt::WindowFlags fl,
72                                                   const double lineWidth )
73   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ),
74     myMode( -1 ),
75     myOK( false ),
76     myLineWidth( lineWidth ),
77     myGeometryGUI( theGeometryGUI )
78 {
79   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
80   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO" ) ) );
81   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_REDO" ) ) );
82   QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICO_3DSKETCH" ) ) );
83
84   setWindowTitle( tr( "GEOM_3DSKETCHER_TITLE" ) );
85
86   /***************************************************************/
87
88   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_3DSKETCHER" ) );
89   mainFrame()->RadioButton1->setIcon( image3 );;
90   mainFrame()->RadioButton2->close();
91   mainFrame()->RadioButton3->close();
92
93   GroupType = new DlgRef_3Radio(centralWidget());
94   GroupType->GroupBox1->setTitle(tr("GEOM_COORDINATES_TYPE"));
95   GroupType->RadioButton1->setText(tr("GEOM_SKETCHER_ABS"));
96   GroupType->RadioButton2->setText(tr("GEOM_SKETCHER_REL"));
97   GroupType->RadioButton3->close();
98   myTypeGroup = new QButtonGroup( this );
99   myTypeGroup->addButton( GroupType->RadioButton1, 0 );
100   myTypeGroup->addButton( GroupType->RadioButton2, 1 );
101
102   Group3Spin = new EntityGUI_3Spin( centralWidget() );
103   Group3Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
104   Group3Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
105   Group3Spin->buttonUndo->setIcon( image1 );
106   Group3Spin->buttonRedo->setIcon( image2 );
107   Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
108   Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
109   Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Z2" ) );
110
111   buttonOk()->setText( tr( "GEOM_BUT_END_SKETCH" ) );
112   buttonApply()->setText( tr( "GEOM_BUT_CLOSE_SKETCH" ) );
113   
114   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
115   layout->setMargin( 0 ); layout->setSpacing( 6 );
116   layout->addWidget( GroupType );
117   layout->addWidget( Group3Spin );
118
119   setHelpFileName( "create_3dsketcher_page.html" );
120
121   resize(100,100);
122   Init();
123 }  
124
125
126
127 //=================================================================================
128 // function : ~EntityGUI_3DSketcherDlg()
129 // purpose  : Destroys the object and frees any allocated resources
130 //=================================================================================
131 EntityGUI_3DSketcherDlg::~EntityGUI_3DSketcherDlg()
132 {
133   myGeomGUI->SetActiveDialogBox( 0 );
134 }
135
136 //=================================================================================
137 // function : Init()
138 // purpose  :
139 //=================================================================================
140 void EntityGUI_3DSketcherDlg::Init()
141 {
142   myOK = false;
143
144   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
145
146   /* Get setting of step value from file configuration */
147   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
148
149   /* min, max, step and decimals for spin boxes */
150   initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
151   initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
152   initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
153
154   Group3Spin->SpinBox_DX->setValue(0.0);
155   Group3Spin->SpinBox_DY->setValue(0.0);
156   Group3Spin->SpinBox_DZ->setValue(0.0);
157
158   /* signals and slots connections */
159   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
160   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
161
162   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
163
164   connect( Group3Spin->buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnAddPoint() ) );
165   connect( Group3Spin->buttonUndo,   SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
166   connect( Group3Spin->buttonRedo,   SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) ) ;
167
168   connect( myTypeGroup, SIGNAL( buttonClicked( int ) ),  this, SLOT( TypeClicked( int ) ) );
169
170   connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
171   connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
172   connect( Group3Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
173
174   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
175
176   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
177   connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
178
179   initName( tr( "GEOM_3DSKETCHER" ) );
180
181   UpdateButtonsState();
182   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
183 }
184
185 //=================================================================================
186 // function : TypeClicked()
187 // purpose  : Radio button management
188 //=================================================================================
189 void EntityGUI_3DSketcherDlg::TypeClicked( int mode )
190 {
191   if ( mode == myMode ) return;
192
193   bool blocked = Group3Spin->SpinBox_DX->signalsBlocked();
194   Group3Spin->SpinBox_DX->blockSignals(true);
195   Group3Spin->SpinBox_DY->blockSignals(true);
196   Group3Spin->SpinBox_DZ->blockSignals(true);
197   // Get setting of step value from file configuration
198   XYZ xyz = getLastPoint();
199   bool okx, oky, okz;
200   Group3Spin->SpinBox_DX->text().toDouble( &okx );
201   Group3Spin->SpinBox_DY->text().toDouble( &oky );
202   Group3Spin->SpinBox_DZ->text().toDouble( &okz );
203   if ( mode == 0 ) {  // XY
204     Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
205     Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
206     Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Z2" ) );
207     if ( okx ) Group3Spin->SpinBox_DX->setValue( xyz.x + Group3Spin->SpinBox_DX->value() );
208     if ( oky ) Group3Spin->SpinBox_DY->setValue( xyz.y + Group3Spin->SpinBox_DY->value() );
209     if ( okz ) Group3Spin->SpinBox_DZ->setValue( xyz.z + Group3Spin->SpinBox_DZ->value() );
210     Group3Spin->buttonApply->setFocus();
211   }
212   else { // DXDY
213     Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
214     Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
215     Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_DZ2" ) );
216     if ( okx ) Group3Spin->SpinBox_DX->setValue( Group3Spin->SpinBox_DX->value() - xyz.x );
217     if ( oky ) Group3Spin->SpinBox_DY->setValue( Group3Spin->SpinBox_DY->value() - xyz.y );
218     if ( okz ) Group3Spin->SpinBox_DZ->setValue( Group3Spin->SpinBox_DZ->value() - xyz.z );
219     Group3Spin->buttonApply->setFocus();
220   }
221   Group3Spin->SpinBox_DX->blockSignals(blocked);
222   Group3Spin->SpinBox_DY->blockSignals(blocked);
223   Group3Spin->SpinBox_DZ->blockSignals(blocked);
224
225   myMode = mode;
226 }
227
228 //=================================================================================
229 // function : ClickOnAddPoint()
230 // purpose  : called when the point coordinates is Applyed
231 //=================================================================================
232 void EntityGUI_3DSketcherDlg::ClickOnAddPoint()
233 {
234   QString msg;
235   if ( !isValid( msg ) ) {
236     showError( msg );
237     return;
238   }
239
240   myPointsList.append( getCurrentPoint() );
241   myRedoList.clear();
242
243   if ( myMode == 1 ) {
244     Group3Spin->SpinBox_DX->setValue( 0.0 );
245     Group3Spin->SpinBox_DY->setValue( 0.0 );
246     Group3Spin->SpinBox_DZ->setValue( 0.0 );
247   }
248   UpdateButtonsState();
249   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
250 }
251
252 //=================================================================================
253 // function : UpdateButtonsState()
254 // purpose  : 
255 //=================================================================================
256 void EntityGUI_3DSketcherDlg::UpdateButtonsState()
257 {
258   if ( myPointsList.count() == 0 ) GroupType->RadioButton1->click();
259   GroupType->RadioButton2->setEnabled( myPointsList.count() > 0 );
260   Group3Spin->buttonUndo->setEnabled( myPointsList.count() > 0 );
261   Group3Spin->buttonRedo->setEnabled( myRedoList.count() > 0 );
262 }
263
264 //=================================================================================
265 // function : ClickOnUndo()
266 // purpose  :
267 //=================================================================================
268 void EntityGUI_3DSketcherDlg::ClickOnUndo()
269 {
270   if (myPointsList.count() > 0) {
271     myRedoList.append( myPointsList.takeLast() );
272     UpdateButtonsState();
273     GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
274   }
275 }
276
277 //=================================================================================
278 // function : ClickOnRedo()
279 // purpose  :
280 //=================================================================================
281 void EntityGUI_3DSketcherDlg::ClickOnRedo()
282 {
283   if ( myRedoList.count() > 0) {
284     myPointsList.append( myRedoList.takeLast() );
285     UpdateButtonsState();
286     GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
287   }
288 }
289
290 //=================================================================================
291 // function : SelectionIntoArgument()
292 // purpose  : Called when selection as changed
293 //=================================================================================
294 void EntityGUI_3DSketcherDlg::SelectionIntoArgument()
295 {
296   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
297   SALOME_ListIO aSelList;
298   aSelMgr->selectedObjects(aSelList);
299
300   int nbSel = aSelList.Extent();
301   if ( nbSel == 1 ) {
302     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
303     if ( !CORBA::is_nil(aSelectedObject) ) {
304       TopoDS_Shape aShape;
305       if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE)) { // Explore the shape if its a local selection
306         TColStd_IndexedMapOfInteger aMap;
307         aSelMgr->GetIndexes(aSelList.First(), aMap);
308         if (aMap.Extent() == 1)
309           {
310             int anIndex = aMap(1);
311             GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
312             aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
313           }
314       }
315       bool isOk = true;
316       if ( aShape.ShapeType() != TopAbs_VERTEX )
317         isOk = GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_VERTEX);
318       if (isOk) {
319         gp_Pnt aPnt;
320         if ( GEOMBase::VertexToPoint( aShape, aPnt ) ) {
321           // set coordinates to the Spin Boxes
322           double aX, aY, aZ;
323           aX = aPnt.X();
324           aY = aPnt.Y();
325           aZ = aPnt.Z();
326           bool blocked = Group3Spin->SpinBox_DX->signalsBlocked();
327           Group3Spin->SpinBox_DX->blockSignals(true);
328           Group3Spin->SpinBox_DY->blockSignals(true);
329           Group3Spin->SpinBox_DZ->blockSignals(true);
330           if ( GroupType->RadioButton1->isChecked() ) {
331             Group3Spin->SpinBox_DX->setValue( aX );
332             Group3Spin->SpinBox_DY->setValue( aY );
333             Group3Spin->SpinBox_DZ->setValue( aZ );
334           } else if ( GroupType->RadioButton2->isChecked() ) {
335             XYZ xyz = getLastPoint();
336             Group3Spin->SpinBox_DX->setValue( aX - xyz.x );
337             Group3Spin->SpinBox_DY->setValue( aY - xyz.y );
338             Group3Spin->SpinBox_DZ->setValue( aZ - xyz.z );
339           }
340           Group3Spin->SpinBox_DX->blockSignals(blocked);
341           Group3Spin->SpinBox_DY->blockSignals(blocked);
342           Group3Spin->SpinBox_DZ->blockSignals(blocked);
343         }
344       }
345     }
346   }
347   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
348 }
349
350 //=================================================================================
351 // function : DeactivateActiveDialog()
352 // purpose  :
353 //=================================================================================
354 void EntityGUI_3DSketcherDlg::DeactivateActiveDialog()
355 {
356   setEnabled( false );
357   globalSelection();
358   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
359   myGeomGUI->SetActiveDialogBox( 0 );
360 }
361
362
363 //=================================================================================
364 // function : ActivateThisDialog()
365 // purpose  :
366 //=================================================================================
367 void EntityGUI_3DSketcherDlg::ActivateThisDialog()
368 {
369   myGeomGUI->EmitSignalDeactivateDialog();
370   setEnabled( true );
371   myGeomGUI->SetActiveDialogBox( this );
372
373   connect( myGeomGUI->getApp()->selectionMgr(),
374           SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
375
376   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
377   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
378 }
379
380
381 //=================================================================================
382 // function : ValueChangedInSpinBox()
383 // purpose  :
384 //=================================================================================
385 void EntityGUI_3DSketcherDlg::ValueChangedInSpinBox( double newValue )
386 {
387   GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
388 }
389
390 //=================================================================================
391 // function : enterEvent()
392 // purpose  :
393 //=================================================================================
394 void EntityGUI_3DSketcherDlg::enterEvent( QEvent* )
395 {
396   if ( !mainFrame()->GroupConstructors->isEnabled() )
397     ActivateThisDialog();
398 }
399
400 //=================================================================================
401 // function : createOperation
402 // purpose  :
403 //=================================================================================
404 GEOM::GEOM_IOperations_ptr EntityGUI_3DSketcherDlg::createOperation()
405 {
406   return getGeomEngine()->GetICurvesOperations( getStudyId() );
407 }
408
409 //=================================================================================
410 // function : isValid
411 // purpose  :
412 //=================================================================================
413 bool EntityGUI_3DSketcherDlg::isValid( QString& msg )
414 {
415   bool ok = true;
416   ok = Group3Spin->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
417   ok = Group3Spin->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
418   ok = Group3Spin->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
419   return ok;
420 }
421
422 //=================================================================================
423 // function : execute
424 // purpose  :
425 //=================================================================================
426 bool EntityGUI_3DSketcherDlg::execute( ObjectList& objects )
427 {
428   GEOM::ListOfDouble_var aCoordsArray = new GEOM::ListOfDouble;
429   if (!myOK || myPointsList.size() == 0)
430     aCoordsArray->length((myPointsList.size()+1)*3);
431   else
432     aCoordsArray->length(myPointsList.size()*3);
433
434   QStringList aParameters;
435
436   int i = 0;
437   QList<XYZ>::const_iterator it;
438   for(it = myPointsList.begin(); it != myPointsList.end(); ++it ) {
439     aCoordsArray[i++] = (*it).x;
440     aCoordsArray[i++] = (*it).y;
441     aCoordsArray[i++] = (*it).z;
442     aParameters << (*it).xt;
443     aParameters << (*it).yt;
444     aParameters << (*it).zt;
445   }
446
447   if (!myOK || myPointsList.size() == 0) {
448     XYZ xyz = getCurrentPoint();
449     aCoordsArray[i++] = xyz.x;
450     aCoordsArray[i++] = xyz.y;
451     aCoordsArray[i++] = xyz.z;
452     aParameters << xyz.xt;
453     aParameters << xyz.yt;
454     aParameters << xyz.zt;
455   } 
456
457   GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
458   GEOM::GEOM_Object_var anObj = anOper->Make3DSketcher( aCoordsArray );
459
460   if ( !anObj->_is_nil() ) {
461     if ( !IsPreview() ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
462     objects.push_back( anObj._retn() );
463   }
464
465   return true;
466 }
467
468 //=================================================================================
469 // function : SetDoubleSpinBoxStep()
470 // purpose  : Double spin box management
471 //=================================================================================
472 void EntityGUI_3DSketcherDlg::SetDoubleSpinBoxStep( double step )
473 {
474   Group3Spin->SpinBox_DX->setSingleStep(step);
475   Group3Spin->SpinBox_DY->setSingleStep(step);
476   Group3Spin->SpinBox_DZ->setSingleStep(step);
477 }
478
479 //=================================================================================
480 // function : ClickOnOk()
481 // purpose  :
482 //=================================================================================
483 void EntityGUI_3DSketcherDlg::ClickOnOk()
484 {
485   Locker lock( myOK );
486
487   if ( !onAccept() )
488     return;
489
490   ClickOnCancel();
491 }
492
493 //=================================================================================
494 // function : ClickOnApply()
495 // purpose  :
496 //=================================================================================
497 bool EntityGUI_3DSketcherDlg::ClickOnApply()
498 {
499   QString msg;
500   if ( !isValid( msg ) ) {
501     showError( msg );
502     return false;
503   }
504
505   if (myPointsList.count() > 0)
506     myPointsList.append(myPointsList[0]);
507
508   Locker lock( myOK );
509
510   if ( !onAccept() )
511     return false;
512
513   ClickOnCancel();
514   return true;
515 }
516
517 //=================================================================================
518 // function : getLastPoint()
519 // purpose  : return last points from list
520 //=================================================================================
521 EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getLastPoint() const
522 {
523   return myPointsList.count() > 0 ? myPointsList.last() : XYZ();
524 }
525
526 //=================================================================================
527 // function : getCurrentPoint()
528 // purpose  : returns current points
529 //=================================================================================
530 EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getCurrentPoint() const
531 {
532   XYZ xyz;
533   if ( myMode == 0 ) {
534     xyz.x = Group3Spin->SpinBox_DX->value();
535     xyz.y = Group3Spin->SpinBox_DY->value();
536     xyz.z = Group3Spin->SpinBox_DZ->value();
537   } 
538   else {
539     xyz = getLastPoint();
540     xyz.x += Group3Spin->SpinBox_DX->value();
541     xyz.y += Group3Spin->SpinBox_DY->value();
542     xyz.z += Group3Spin->SpinBox_DZ->value();
543   }
544   xyz.xt = Group3Spin->SpinBox_DX->text();
545   xyz.yt = Group3Spin->SpinBox_DY->text();
546   xyz.zt = Group3Spin->SpinBox_DZ->text();
547   return xyz;
548 }
549
550 //================================================================
551 // Function : displayPreview
552 // Purpose  : Method for displaying preview of resulting shape
553 //            Redefined from GEOMBase_Helper.
554 //================================================================
555 void EntityGUI_3DSketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
556                                               const bool            append,
557                                               const bool            activate,
558                                               const bool            update,
559                                               const double          lineWidth,
560                                               const int             displayMode,
561                                               const int             color )
562 {
563   // Set color for preview shape
564   getDisplayer()->SetColor( Quantity_NOC_RED );
565
566   // set width of displayed shape
567   getDisplayer()->SetWidth( (lineWidth == -1)?myLineWidth:lineWidth ); 
568
569   // Disable activation of selection
570   getDisplayer()->SetToActivate( activate );
571
572   // Make a reference to GEOM_Object
573   CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
574   getDisplayer()->SetName( objStr.in() );
575
576   // Create wire from applied object
577   TopoDS_Shape anApplyedWire, aLastSegment;
578   if ( !createShapes( object, anApplyedWire, aLastSegment ) )
579     return;
580
581   // Build prs
582   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( anApplyedWire );
583   if ( aPrs != 0 && !aPrs->IsNull() )
584     GEOMBase_Helper::displayPreview( aPrs, append, update );
585
586   getDisplayer()->SetColor( Quantity_NOC_VIOLET );
587   aPrs = getDisplayer()->BuildPrs( aLastSegment );
588   if ( aPrs != 0 && !aPrs->IsNull() )
589     GEOMBase_Helper::displayPreview( aPrs, append, update );
590
591   getDisplayer()->UnsetName();
592
593   // Enable activation of displayed objects
594   getDisplayer()->SetToActivate( true );
595 }
596
597 //================================================================
598 // Function : createShapes
599 // Purpose  : Create applyed wire, and last segment from entry object
600 //================================================================
601 bool EntityGUI_3DSketcherDlg::createShapes( GEOM::GEOM_Object_ptr /*theObject*/,
602                                             TopoDS_Shape&         theApplyedWire,
603                                             TopoDS_Shape&         theLastSegment )
604 {
605   QList<gp_Pnt> points;
606   foreach( XYZ xyz, myPointsList) {
607     gp_Pnt p(xyz.x, xyz.y, xyz.z);
608     if ( points.isEmpty() || points.last().Distance(p) > gp::Resolution())
609       points << p;
610   } 
611   
612   if ( points.count() == 1 ) {
613     // only one point is created
614     BRepBuilderAPI_MakeVertex mkVertex (points.last());
615     theApplyedWire = mkVertex.Shape();
616   }
617   else if ( points.count() > 1 ) {
618     // wire is created
619     BRepBuilderAPI_MakePolygon mkWire;
620     foreach( gp_Pnt p, points )
621       mkWire.Add(p);
622     theApplyedWire = mkWire.Shape();
623   }
624
625   XYZ curxyz = getCurrentPoint();
626   gp_Pnt curpnt(curxyz.x, curxyz.y, curxyz.z);
627   
628   if ( points.isEmpty() || points.last().Distance(curpnt) <= gp::Resolution() ) {
629     BRepBuilderAPI_MakeVertex mkVertex (curpnt);
630     theLastSegment = mkVertex.Shape();
631   }
632   else {
633     BRepBuilderAPI_MakeEdge mkEdge(points.last(), curpnt);
634     theLastSegment = mkEdge.Shape();
635   }
636
637   /* VSR: old algorithm does not work properly, see bug 0020899
638   TopoDS_Shape aShape;
639   if ( !GEOMBase::GetShape( theObject, aShape ) )
640     return false;
641
642   if( aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
643     return false;
644
645   theApplyedWire = aShape;
646   if ( myOK  )
647      return true;
648
649   BRepBuilderAPI_MakeWire aBuilder;
650   TopExp_Explorer edgeExp( aShape, TopAbs_EDGE );
651   while ( 1 ) {
652     TopoDS_Shape anEdge = edgeExp.Current();
653     edgeExp.Next();
654     if ( edgeExp.More() ) // i.e. non-last edge
655       aBuilder.Add( TopoDS::Edge( anEdge ) );
656     else {
657       theLastSegment = anEdge;
658       break;
659     }
660   }
661
662   if ( aBuilder.IsDone() ) {
663     theApplyedWire = aBuilder.Shape();
664   }
665   else if ( !theLastSegment.IsNull() ) {
666     TopExp_Explorer vertexExp( theLastSegment, TopAbs_VERTEX );
667     theApplyedWire = vertexExp.Current();
668     }
669   */
670
671   return true;
672 }