Salome HOME
Merge from V5_1_3_BR branch (07/12/09)
[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(100,100);
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_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
450   GEOM::GEOM_Object_var anObj = anOper->Make3DSketcher( aCoordsArray );
451
452   if ( !anObj->_is_nil() )
453     objects.push_back( anObj._retn() );
454
455   return true;
456 }
457
458 //=================================================================================
459 // function : initSpinBox()
460 // purpose  :
461 //=================================================================================
462
463 void EntityGUI_3DSketcherDlg::initSpinBox( QDoubleSpinBox* spinBox,
464                                          double min,  double max,
465                                          double step, int decimals )
466 {
467   spinBox->setDecimals( decimals );
468   spinBox->setRange( min, max );
469   spinBox->setSingleStep( step );
470 }
471
472 //=================================================================================
473 // function : SetDoubleSpinBoxStep()
474 // purpose  : Double spin box management
475 //=================================================================================
476 void EntityGUI_3DSketcherDlg::SetDoubleSpinBoxStep( double step )
477 {
478   Group3Spin->SpinBox_DX->setSingleStep(step);
479   Group3Spin->SpinBox_DY->setSingleStep(step);
480   Group3Spin->SpinBox_DZ->setSingleStep(step);
481 }
482
483 //=================================================================================
484 // function : ClickOnOk()
485 // purpose  :
486 //=================================================================================
487 void EntityGUI_3DSketcherDlg::ClickOnOk()
488 {
489   Locker lock( myOK );
490
491   if ( !onAccept() )
492     return;
493
494   ClickOnCancel();
495 }
496
497 //=================================================================================
498 // function : ClickOnApply()
499 // purpose  :
500 //=================================================================================
501 bool EntityGUI_3DSketcherDlg::ClickOnApply()
502 {
503   if (myPointsList.count() > 3) {
504     myPointsList.append(myPointsList[0]);
505     myPointsList.append(myPointsList[1]);
506     myPointsList.append(myPointsList[2]);
507   }
508
509   Locker lock( myOK );
510
511   if ( !onAccept() )
512     return false;
513
514   ClickOnCancel();
515   return true;
516 }
517
518 //=================================================================================
519 // function : GetLastPoints()
520 // purpose  : return last points from list
521 //=================================================================================
522 void EntityGUI_3DSketcherDlg::GetLastPoints(double& x, double& y, double& z)
523 {
524   int count = myPointsList.count();
525   x = count > 2 ? myPointsList[count-3] : 0.0;
526   y = count > 2 ? myPointsList[count-2] : 0.0;
527   z = count > 2 ? myPointsList[count-1] : 0.0;
528 }
529
530 //=================================================================================
531 // function : GetCurrentPoints()
532 // purpose  : returns current points
533 //=================================================================================
534 void EntityGUI_3DSketcherDlg::GetCurrentPoints(double& x, double& y, double& z)
535 {
536   if ( GroupType->RadioButton1->isChecked() ) {
537     x = Group3Spin->SpinBox_DX->value();
538     y = Group3Spin->SpinBox_DY->value();
539     z = Group3Spin->SpinBox_DZ->value();
540   } else { // if (GroupType->RadioButton2->isChecked())
541     GetLastPoints(x, y, z);
542     x += Group3Spin->SpinBox_DX->value();
543     y += Group3Spin->SpinBox_DY->value();
544     z += Group3Spin->SpinBox_DZ->value();
545   }
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 applayed 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   if ( myOK  ) {
609      theApplyedWire = aShape;
610      return true;
611   }
612
613   BRepBuilderAPI_MakeWire aBuilder;
614   TopExp_Explorer anExp( aShape, TopAbs_EDGE );
615   while ( 1 ) {
616     TopoDS_Shape anEdge = anExp.Current();
617     anExp.Next();
618     if ( anExp.More() ) // i.e. non-last edge
619       aBuilder.Add( TopoDS::Edge( anEdge ) );
620     else {
621       theLastSegment = anEdge;
622       break;
623     }
624   }
625
626   if ( aBuilder.IsDone() )
627     theApplyedWire = aBuilder.Shape();
628
629   return true;
630 }