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