Salome HOME
a3171f10a4ff0ce6c467943195038d1285e5a104
[modules/geom.git] / src / EntityGUI / EntityGUI_3DSketcherDlg.cxx
1 // GEOM GEOMGUI : GUI for Geometry component
2 //
3 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : EntityGUI_3DSketcherDlg.cxx
23 // Author : DMV, OCN
24 //
25
26 #include "EntityGUI_3DSketcherDlg.h"
27 #include "EntityGUI_Widgets.h"
28 #include <QtxDoubleSpinBox.h>
29
30 #include <GEOMBase.h>
31 #include <GeometryGUI.h>
32 #include <GEOMImpl_Types.hxx>
33 #include <Precision.hxx>  
34
35 #include <DlgRef.h>
36 #include <SUIT_Desktop.h>
37 #include <SUIT_Session.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SalomeApp_Application.h>
41 #include <LightApp_Application.h>
42 #include <LightApp_SelectionMgr.h>
43
44 #include <BRep_Tool.hxx>
45 #include <TopExp.hxx>
46 #include <TopExp_Explorer.hxx>
47 #include <TopoDS_Vertex.hxx>
48 #include <TopoDS.hxx>
49 #include <TColStd_IndexedMapOfInteger.hxx>
50 #include <BRepBuilderAPI_Transform.hxx>
51 #include <BRepBuilderAPI_MakeWire.hxx>
52
53 class Locker
54 {
55 public:
56   Locker( bool& l ) : myLock( l ) { myLock = true;  }
57   ~Locker()                       { myLock = false; }
58 private:
59   bool& myLock;
60 };
61
62 //=================================================================================
63 // class    : EntityGUI_3DSketcherDlg()
64 // purpose  : Constructs a EntityGUI_3DSketcherDlg which is a child of 'parent', with the
65 //            name 'name' and widget flags set to 'f'.
66 //            The dialog will by default be modeless, unless you set 'modal' to
67 //            TRUE to construct a modal dialog.
68 //=================================================================================
69 EntityGUI_3DSketcherDlg::EntityGUI_3DSketcherDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
70                                                   bool modal, Qt::WindowFlags fl,
71                                                   const double lineWidth )
72   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ),
73     myMode( -1 ),
74     myOK( false ),
75     myLineWidth( lineWidth ),
76     myGeometryGUI( theGeometryGUI )
77 {
78   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
79   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO" ) ) );
80   QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_REDO" ) ) );
81   QPixmap image3( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICO_3DSKETCH" ) ) );
82
83   setWindowTitle( tr( "GEOM_3DSKETCHER_TITLE" ) );
84
85   /***************************************************************/
86
87   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_3DSKETCHER" ) );
88   mainFrame()->RadioButton1->setIcon( image3 );;
89   mainFrame()->RadioButton2->close();
90   mainFrame()->RadioButton3->close();
91
92   GroupType = new DlgRef_3Radio(centralWidget());
93   GroupType->GroupBox1->setTitle(tr("GEOM_COORDINATES_TYPE"));
94   GroupType->RadioButton1->setText(tr("GEOM_SKETCHER_ABS"));
95   GroupType->RadioButton2->setText(tr("GEOM_SKETCHER_REL"));
96   GroupType->RadioButton3->close();
97   myTypeGroup = new QButtonGroup( this );
98   myTypeGroup->addButton( GroupType->RadioButton1, 0 );
99   myTypeGroup->addButton( GroupType->RadioButton2, 1 );
100
101   Group3Spin = new EntityGUI_3Spin( centralWidget() );
102   Group3Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
103   Group3Spin->buttonApply->setText( tr( "GEOM_SKETCHER_APPLY" ) );
104   Group3Spin->buttonUndo->setIcon( image1 );
105   Group3Spin->buttonRedo->setIcon( image2 );
106   Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
107   Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
108   Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Z2" ) );
109
110   buttonOk()->setText( tr( "GEOM_BUT_END_SKETCH" ) );
111   buttonApply()->setText( tr( "GEOM_BUT_CLOSE_SKETCH" ) );
112   
113   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
114   layout->setMargin( 0 ); layout->setSpacing( 6 );
115   layout->addWidget( GroupType );
116   layout->addWidget( Group3Spin );
117
118   setHelpFileName( "create_3dsketcher_page.html" );
119
120   resize(100,100);
121   Init();
122 }  
123
124
125
126 //=================================================================================
127 // function : ~EntityGUI_3DSketcherDlg()
128 // purpose  : Destroys the object and frees any allocated resources
129 //=================================================================================
130 EntityGUI_3DSketcherDlg::~EntityGUI_3DSketcherDlg()
131 {
132   myGeomGUI->SetActiveDialogBox( 0 );
133 }
134
135 //=================================================================================
136 // function : Init()
137 // purpose  :
138 //=================================================================================
139 void EntityGUI_3DSketcherDlg::Init()
140 {
141   myOK = false;
142
143   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
144
145   /* Get setting of step value from file configuration */
146   double step = SUIT_Session::session()->resourceMgr()->doubleValue( "Geometry", "SettingsGeomStep", 100.0 );
147
148   /* min, max, step and decimals for spin boxes */
149   initSpinBox( Group3Spin->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
150   initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
151   initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
152
153   Group3Spin->SpinBox_DX->setValue(0.0);
154   Group3Spin->SpinBox_DY->setValue(0.0);
155   Group3Spin->SpinBox_DZ->setValue(0.0);
156
157   /* signals and slots connections */
158   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
159   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
160
161   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
162
163   connect( Group3Spin->buttonApply,  SIGNAL( clicked() ), this, SLOT( ClickOnAddPoint() ) );
164   connect( Group3Spin->buttonUndo,   SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
165   connect( Group3Spin->buttonRedo,   SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) ) ;
166
167   connect( myTypeGroup, SIGNAL( buttonClicked( int ) ),  this, SLOT( TypeClicked( int ) ) );
168
169   connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
170   connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
171   connect( Group3Spin->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
172
173   connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
174
175   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
176   connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
177
178   initName( tr( "GEOM_3DSKETCHER" ) );
179
180   UpdateButtonsState();
181   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
182 }
183
184 //=================================================================================
185 // function : TypeClicked()
186 // purpose  : Radio button management
187 //=================================================================================
188 void EntityGUI_3DSketcherDlg::TypeClicked( int mode )
189 {
190   if ( mode == myMode ) return;
191
192   bool blocked = Group3Spin->SpinBox_DX->signalsBlocked();
193   Group3Spin->SpinBox_DX->blockSignals(true);
194   Group3Spin->SpinBox_DY->blockSignals(true);
195   Group3Spin->SpinBox_DZ->blockSignals(true);
196   // Get setting of step value from file configuration
197   XYZ xyz = getLastPoint();
198   bool okx, oky, okz;
199   Group3Spin->SpinBox_DX->text().toDouble( &okx );
200   Group3Spin->SpinBox_DY->text().toDouble( &oky );
201   Group3Spin->SpinBox_DZ->text().toDouble( &okz );
202   if ( mode == 0 ) {  // XY
203     Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
204     Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
205     Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Z2" ) );
206     if ( okx ) Group3Spin->SpinBox_DX->setValue( xyz.x + Group3Spin->SpinBox_DX->value() );
207     if ( oky ) Group3Spin->SpinBox_DY->setValue( xyz.y + Group3Spin->SpinBox_DY->value() );
208     if ( okz ) Group3Spin->SpinBox_DZ->setValue( xyz.z + Group3Spin->SpinBox_DZ->value() );
209     Group3Spin->buttonApply->setFocus();
210   }
211   else { // DXDY
212     Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
213     Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
214     Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_DZ2" ) );
215     if ( okx ) Group3Spin->SpinBox_DX->setValue( Group3Spin->SpinBox_DX->value() - xyz.x );
216     if ( oky ) Group3Spin->SpinBox_DY->setValue( Group3Spin->SpinBox_DY->value() - xyz.y );
217     if ( okz ) Group3Spin->SpinBox_DZ->setValue( Group3Spin->SpinBox_DZ->value() - xyz.z );
218     Group3Spin->buttonApply->setFocus();
219   }
220   Group3Spin->SpinBox_DX->blockSignals(blocked);
221   Group3Spin->SpinBox_DY->blockSignals(blocked);
222   Group3Spin->SpinBox_DZ->blockSignals(blocked);
223
224   myMode = mode;
225 }
226
227 //=================================================================================
228 // function : ClickOnAddPoint()
229 // purpose  : called when the point coordinates is Applyed
230 //=================================================================================
231 void EntityGUI_3DSketcherDlg::ClickOnAddPoint()
232 {
233   QString msg;
234   if ( !isValid( msg ) ) {
235     showError( msg );
236     return;
237   }
238
239   myPointsList.append( getCurrentPoint() );
240   myRedoList.clear();
241
242   if ( myMode == 1 ) {
243     Group3Spin->SpinBox_DX->setValue( 0.0 );
244     Group3Spin->SpinBox_DY->setValue( 0.0 );
245     Group3Spin->SpinBox_DZ->setValue( 0.0 );
246   }
247   UpdateButtonsState();
248   GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
249 }
250
251 //=================================================================================
252 // function : UpdateButtonsState()
253 // purpose  : 
254 //=================================================================================
255 void EntityGUI_3DSketcherDlg::UpdateButtonsState()
256 {
257   if ( myPointsList.count() == 0 ) GroupType->RadioButton1->click();
258   GroupType->RadioButton2->setEnabled( myPointsList.count() > 0 );
259   Group3Spin->buttonUndo->setEnabled( myPointsList.count() > 0 );
260   Group3Spin->buttonRedo->setEnabled( myRedoList.count() > 0 );
261 }
262
263 //=================================================================================
264 // function : ClickOnUndo()
265 // purpose  :
266 //=================================================================================
267 void EntityGUI_3DSketcherDlg::ClickOnUndo()
268 {
269   if (myPointsList.count() > 0) {
270     myRedoList.append( myPointsList.takeLast() );
271     UpdateButtonsState();
272     GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
273   }
274 }
275
276 //=================================================================================
277 // function : ClickOnRedo()
278 // purpose  :
279 //=================================================================================
280 void EntityGUI_3DSketcherDlg::ClickOnRedo()
281 {
282   if ( myRedoList.count() > 0) {
283     myPointsList.append( myRedoList.takeLast() );
284     UpdateButtonsState();
285     GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
286   }
287 }
288
289 //=================================================================================
290 // function : SelectionIntoArgument()
291 // purpose  : Called when selection as changed
292 //=================================================================================
293 void EntityGUI_3DSketcherDlg::SelectionIntoArgument()
294 {
295   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
296   SALOME_ListIO aSelList;
297   aSelMgr->selectedObjects(aSelList);
298
299   int nbSel = aSelList.Extent();
300   if ( nbSel == 1 ) {
301     Standard_Boolean aRes = Standard_False;
302     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aRes);
303     if (!CORBA::is_nil(aSelectedObject) && aRes) {
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( 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( 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( 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   TopoDS_Shape aShape;
606   if ( !GEOMBase::GetShape( theObject, aShape ) ||
607        aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
608     return false;
609
610   theApplyedWire = aShape;
611   if ( myOK  )
612      return true;
613
614   BRepBuilderAPI_MakeWire aBuilder;
615   TopExp_Explorer edgeExp( aShape, TopAbs_EDGE );
616   while ( 1 ) {
617     TopoDS_Shape anEdge = edgeExp.Current();
618     edgeExp.Next();
619     if ( edgeExp.More() ) // i.e. non-last edge
620       aBuilder.Add( TopoDS::Edge( anEdge ) );
621     else {
622       theLastSegment = anEdge;
623       break;
624     }
625   }
626
627   if ( aBuilder.IsDone() ) {
628     theApplyedWire = aBuilder.Shape();
629   }
630   else if ( !theLastSegment.IsNull() ) {
631     TopExp_Explorer vertexExp( theLastSegment, TopAbs_VERTEX );
632     theApplyedWire = vertexExp.Current();
633   }
634
635   return true;
636 }