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