Salome HOME
0022845: EDF GEOM: [HYDRO] Hiding the coordinates system part of the dialog box in...
[modules/geom.git] / src / EntityGUI / EntityGUI_PolylineDlg.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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
23 #include "EntityGUI_PolylineDlg.h"
24 #include <CurveCreator_Curve.hxx>
25 #include <CurveCreator_Displayer.hxx>
26 #include <CurveCreator_Utils.hxx>
27 #include <CurveCreator_Widget.h>
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include "utilities.h"
33
34 #include <OCCViewer_ViewManager.h>
35 #include <LightApp_SelectionMgr.h>
36 #include <SalomeApp_Application.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <SUIT_Session.h>
39 #include "utilities.h"
40
41 #include <BRep_Tool.hxx>
42 #include <Geom_Surface.hxx>
43 #include <GeomLib_IsPlanarSurface.hxx>
44 #include <Prs3d_LineAspect.hxx>
45 #include <TopoDS.hxx>
46
47 #include <QGroupBox>
48 #include <QVBoxLayout>
49
50 //#define SET_PLANE
51
52 //=================================================================================
53 // function : Constructor
54 // purpose  :
55 //=================================================================================
56 EntityGUI_PolylineDlg::EntityGUI_PolylineDlg
57         (GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl)
58   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ),
59     myCurve               (0),
60     myEditorWidget        (0),
61     myAddElementBox       (0),
62     myPlnComboBox         (0),
63     myPlnButton           (0),
64     myPlnSelButton        (0),
65     myWPlaneLineEdit      (0),
66     myPolylineSelButton   (0),
67     myPolylineEdit        (0),
68     myEditCurrentArgument (0),
69     myPreviewManager(0),
70     myPreviewZLayer(-1)
71 {
72   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
73   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
74
75   setWindowTitle(tr("POLYLINE_DLG_TITLE"));
76
77   /***************************************************************/
78   mainFrame()->GroupConstructors->setTitle(tr("POLYLINE_TITLE"));
79   mainFrame()->RadioButton1->setIcon(image0);
80   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
81   mainFrame()->RadioButton2->close();
82   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
83   mainFrame()->RadioButton3->close();
84
85   QGroupBox   *aGroupBox1 = new QGroupBox(this);
86   QGridLayout *aPlaneLayout = new QGridLayout(aGroupBox1);
87
88   aPlaneLayout->setSpacing(6);
89   aPlaneLayout->setMargin(11);
90
91   myPlnComboBox = new QComboBox(aGroupBox1);
92   aPlaneLayout->addWidget(myPlnComboBox, 0, 0, 1, 3);
93
94   myPlnButton = new QPushButton (aGroupBox1);
95   myPlnButton->setText( tr( "GEOM_SKETCHER_RESTORE" ) );
96   aPlaneLayout->addWidget(myPlnButton, 0, 3);
97
98   bool isCS = false;
99 #ifdef SET_PLANE
100   isCS = true;
101 #endif
102   myPlnComboBox->setVisible( isCS );
103   myPlnButton->setVisible( isCS );
104
105 #ifdef SET_PLANE
106   QLabel *aPlaneLbl = new QLabel(tr("GEOM_PLANE"), aGroupBox1);
107
108   myPlnSelButton = new QPushButton (aGroupBox1);
109   myPlnSelButton->setIcon(image1);
110   myWPlaneLineEdit = new QLineEdit (aGroupBox1);
111   myWPlaneLineEdit->setReadOnly(true);
112 #endif
113
114   QLabel *aPolylineLbl = new QLabel(tr("POLYLINE_IMPORT"), aGroupBox1);
115
116   myPolylineSelButton = new QPushButton (aGroupBox1);
117   myPolylineSelButton->setIcon(image1);
118   myPolylineSelButton->setCheckable(true);
119   myPolylineEdit = new QLineEdit (aGroupBox1);
120   myPolylineEdit->setReadOnly(true);
121
122 #ifdef SET_PLANE
123   aPlaneLayout->addWidget(aPlaneLbl, 1, 0);
124   aPlaneLayout->addWidget(myPlnSelButton, 1, 1);
125   aPlaneLayout->addWidget(myWPlaneLineEdit, 1, 2, 1, 2);
126 #endif
127   aPlaneLayout->addWidget(aPolylineLbl, 2, 0);
128   aPlaneLayout->addWidget(myPolylineSelButton, 2, 1);
129   aPlaneLayout->addWidget(myPolylineEdit, 2, 2, 1, 2);
130   
131   aPlaneLayout->setColumnStretch(2, 1);
132
133   myCurve = new CurveCreator_Curve( CurveCreator::Dim2d );
134   myEditorWidget = new CurveCreator_Widget (centralWidget(), myCurve);
135   myAddElementBox = new QGroupBox (tr("POLYLINE_ADD_SECTION"), centralWidget());
136
137   QBoxLayout* anAddElementLayout = new QVBoxLayout( myAddElementBox );
138
139   anAddElementLayout->setMargin( 0 );
140   anAddElementLayout->setSpacing( 6 );
141
142   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
143
144   layout->setMargin( 0 );
145   layout->setSpacing( 6 );
146   layout->addWidget( aGroupBox1 );
147   layout->addWidget( myEditorWidget );
148   layout->addWidget( myAddElementBox );
149
150   /***************************************************************/
151
152   setHelpFileName( "create_polyline_page.html" );
153
154   /* Initializations */
155   Init();
156 }
157
158 //=================================================================================
159 // function : Destructor
160 // purpose  :
161 //=================================================================================
162 EntityGUI_PolylineDlg::~EntityGUI_PolylineDlg()
163 {
164   erasePreview();
165 }
166
167 //=================================================================================
168 // function : Init()
169 // purpose  :
170 //=================================================================================
171 void EntityGUI_PolylineDlg::Init()
172 {
173   initName(tr("POLYLINE_NAME"));
174
175   SalomeApp_Application *anApp        = myGeomGUI->getApp();
176   OCCViewer_ViewManager *aViewManager = dynamic_cast<OCCViewer_ViewManager*>
177     (anApp->getViewManager(OCCViewer_Viewer::Type(), true));
178   LightApp_SelectionMgr *aSelMgr = myGeomGUI->getApp()->selectionMgr();
179
180   myEditorWidget->setOCCViewer(aViewManager ? aViewManager->getOCCViewer() : 0);
181   setPreviewManager( aViewManager );
182
183   // Init the list of local coordinate system
184   gp_Pnt aPnt(0., 0., 0.);
185   gp_Dir aDirN(0., 0., 1.);
186   gp_Dir aDirX(1., 0., 0.);
187   gp_Ax3 aLCS(aPnt, aDirN, aDirX);
188
189   //add Global CS
190   myPlnComboBox->addItem(tr("GEOM_GCS"), false);
191   myWPlaneList.push_back(GEOM::GeomObjPtr());
192   myLCSList.push_back(aLCS);
193
194 #ifdef SET_PLANE
195   connect( myPlnSelButton, SIGNAL(toggled(bool)),
196            this,           SLOT(SetEditCurrentArgument(bool)) );
197 #endif
198   connect( myPolylineSelButton, SIGNAL(toggled(bool)),
199            this,                SLOT(SetEditCurrentArgument(bool)) );
200   connect( aSelMgr, SIGNAL(currentSelectionChanged()),
201            this,    SLOT(SelectionIntoArgument()) );
202   connect( myEditorWidget, SIGNAL(subOperationStarted(QWidget*, bool)),
203            this,           SLOT(processStartedSubOperation(QWidget*, bool)) );
204   connect( myEditorWidget, SIGNAL(subOperationFinished(QWidget*)),
205            this,           SLOT(processFinishedSubOperation(QWidget*)) );
206 #ifdef SET_PLANE
207   connect( myPlnComboBox,  SIGNAL(activated(int)),
208            this,           SLOT(ActivateLocalCS()) );
209   connect( myPlnButton,    SIGNAL(clicked()),
210            this,           SLOT(ActivateLocalCS()) );
211 #endif
212   connect( buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()) );
213   connect( buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()) );
214
215   myAddElementBox->hide();
216
217   // Processing of the selected object
218   myPolylineSelButton->setChecked( true );
219   SelectionIntoArgument( true );
220 }
221
222 //=================================================================================
223 // function : Clear
224 // purpose  :
225 //=================================================================================
226 void EntityGUI_PolylineDlg::Clear()
227 {
228   delete myCurve;
229
230   myCurve = new CurveCreator_Curve( CurveCreator::Dim2d );
231   myEditorWidget->setCurve(myCurve);
232 }
233
234 //=================================================================================
235 // function : GetCurveParams
236 // purpose  :
237 //=================================================================================
238 void EntityGUI_PolylineDlg::GetCurveParams(GEOM::ListOfListOfDouble &theCoords,
239                                            GEOM::string_array       &theNames,
240                                            GEOM::short_array        &theTypes,
241                                            GEOM::ListOfBool         &theCloseds)
242 {
243   const int aNbSec = myCurve->getNbSections();
244   int       i;
245   int       j;
246
247   theCoords.length(aNbSec);
248   theNames.length(aNbSec);
249   theTypes.length(aNbSec);
250   theCloseds.length(aNbSec);
251
252   for (i = 0; i < aNbSec; ++i) {
253     // Set coordinates
254     CurveCreator::Coordinates aCoords   = myCurve->getPoints(i);
255     const int                 aNbPoints = aCoords.size();
256
257     theCoords[i].length(aNbPoints);
258
259     for (j = 0; j < aNbPoints; ++j) {
260       theCoords[i][j] = aCoords[j];
261     }
262
263     // Set section type
264     const CurveCreator::SectionType aType = myCurve->getSectionType(i);
265
266     switch (aType) {
267       case CurveCreator::Spline:
268         theTypes[i] = GEOM::Interpolation;
269         break;
270       case CurveCreator::Polyline:
271       default:
272         theTypes[i] = GEOM::Polyline;
273         break;
274     }
275
276     // Set section names and closed flags.
277     theNames[i]   = CORBA::string_dup(myCurve->getSectionName(i).c_str());
278     theCloseds[i] = myCurve->isClosed(i);
279   }
280 }
281
282 //=================================================================================
283 // function : createOperation
284 // purpose  :
285 //=================================================================================
286 GEOM::GEOM_IOperations_ptr EntityGUI_PolylineDlg::createOperation()
287 {
288   return getGeomEngine()->GetICurvesOperations( getStudyId() );
289 }
290
291 //=================================================================================
292 // function : isValid
293 // purpose  :
294 //=================================================================================
295 bool EntityGUI_PolylineDlg::isValid( QString& msg )
296 {
297   return true;
298 }
299
300 //=================================================================================
301 // function : execute
302 // purpose  :
303 //=================================================================================
304 bool EntityGUI_PolylineDlg::execute( ObjectList& objects )
305 {
306   GEOM::GEOM_ICurvesOperations_var anOper =
307     GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
308
309   // Get the polyline creation parameters.
310   GEOM::ListOfListOfDouble aCoords;
311   GEOM::string_array       aNames;
312   GEOM::short_array        aTypes;
313   GEOM::ListOfBool         aCloseds;
314
315   GetCurveParams(aCoords, aNames, aTypes, aCloseds);
316
317   // Get Working Plane.
318   int ind = myPlnComboBox->currentIndex();
319
320   if (ind != -1) {
321     bool                  isPlane = myPlnComboBox->itemData(ind).toBool();
322     GEOM::GEOM_Object_var anObj;
323
324     // Perform operation
325     if (isPlane) {
326       anObj = anOper->MakePolyline2DOnPlane
327         (aCoords, aNames, aTypes, aCloseds, myWPlaneList.at(ind).get());
328     } else {
329       gp_Ax3             anAxis = myLCSList.at(ind);
330       GEOM::ListOfDouble aPlane;
331
332       aPlane.length(9);
333       aPlane[0] = anAxis.Location().X();
334       aPlane[1] = anAxis.Location().Y();
335       aPlane[2] = anAxis.Location().Z();
336       aPlane[3] = anAxis.Direction().X();
337       aPlane[4] = anAxis.Direction().Y();
338       aPlane[5] = anAxis.Direction().Z();
339       aPlane[6] = anAxis.XDirection().X();
340       aPlane[7] = anAxis.XDirection().Y();
341       aPlane[8] = anAxis.XDirection().Z();
342
343       anObj = anOper->MakePolyline2D
344         (aCoords, aNames, aTypes, aCloseds, aPlane);
345     }
346
347     if (!anObj->_is_nil()) {
348       objects.push_back(anObj._retn());
349     }
350   }
351
352   return true;
353 }
354
355 //=================================================================================
356 // function : ClickOnOk()
357 // purpose  :
358 //=================================================================================
359 void EntityGUI_PolylineDlg::ClickOnOk()
360 {
361   setIsApplyAndClose( true );
362
363   if (ClickOnApply())
364     ClickOnCancel();
365 }
366
367 //=================================================================================
368 // function : ClickOnApply()
369 // purpose  :
370 //=================================================================================
371 bool EntityGUI_PolylineDlg::ClickOnApply()
372 {
373   if (!onAccept())
374     return false;
375
376   initName();
377
378   // Reset actions
379   myEditorWidget->reset();
380
381   return true;
382 }
383
384 //=================================================================================
385 // function : ClickOnCancel()
386 // purpose  :
387 //=================================================================================
388 void EntityGUI_PolylineDlg::ClickOnCancel()
389 {
390   myEditorWidget->SetViewer2DMode(false);
391   GEOMBase_Skeleton::ClickOnCancel();
392 }
393
394 //=================================================================================
395 // function : processStartedSubOperation
396 // purpose  :
397 //=================================================================================
398 void EntityGUI_PolylineDlg::processStartedSubOperation( QWidget* theWidget, bool theIsEdit )
399 {
400   myEditorWidget->setEnabled( false );
401
402   myAddElementBox->setTitle( theIsEdit ? tr( "POLYLINE_EDIT_SECTION" ) : tr( "POLYLINE_ADD_SECTION" ) );
403   QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
404   anAddElementLayout->addWidget( theWidget );
405
406   theWidget->show();
407   myAddElementBox->show();
408 }
409
410
411 //=================================================================================
412 // function : processFinishedSubOperation
413 // purpose  :
414 //=================================================================================
415 void EntityGUI_PolylineDlg::processFinishedSubOperation( QWidget* theWidget )
416 {
417   myEditorWidget->setEnabled( true );
418
419   QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
420   anAddElementLayout->removeWidget( theWidget );
421
422   theWidget->hide();
423   myAddElementBox->hide();
424 }
425
426 //=================================================================================
427 // function : deleteSelected
428 // purpose  : Redirect the delete action to editor widget
429 //=================================================================================
430 void EntityGUI_PolylineDlg::deleteSelected()
431 {
432   myEditorWidget->removeSelected();
433 }
434
435 //=================================================================================
436 // function : deleteEnabled
437 // purpose  : Checks whether there are some to delete
438 //=================================================================================
439 bool EntityGUI_PolylineDlg::deleteEnabled()
440 {
441   return myEditorWidget->removeEnabled();
442 }
443
444 //=================================================================================
445 // function : SelectionIntoArgument
446 // purpose  : Called when selection is changed
447 //=================================================================================
448 void EntityGUI_PolylineDlg::SelectionIntoArgument( bool isForced )
449 {
450   bool             isModified      = isForced;
451   GEOM::GeomObjPtr aSelectedObject = getSelected(TopAbs_SHAPE);
452   TopoDS_Shape     aShape;
453
454   if (aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) &&
455       !aShape.IsNull())
456   {
457     QString aName = GEOMBase::GetName(aSelectedObject.get()); 
458
459     if ( myEditCurrentArgument == myPolylineEdit && isCheckToSelect() )
460     {
461       // Import a curve
462       CurveCreator_Curve *aNewCurve = 
463         new CurveCreator_Curve(CurveCreator::Dim2d);
464       gp_Ax3              aLocalCS;
465
466       if (CurveCreator_Utils::constructCurve(aShape, aNewCurve, aLocalCS)) {
467         // Change the current curve be the new one.
468         myEditorWidget->setCurve(aNewCurve);
469         delete myCurve;
470         myCurve = aNewCurve;
471         isModified = true;
472         myPolylineEdit->setText(aName);
473 #ifdef SET_PLANE
474         AddLocalCS(aSelectedObject.get(), false, aLocalCS);
475         myWPlaneLineEdit->clear();
476         myPlnSelButton->setChecked(false);
477 #endif
478         myPolylineSelButton->setChecked(false);
479
480         disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
481         myGeomGUI->getApp()->selectionMgr()->clearSelected();
482         connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
483                 this, SLOT(SelectionIntoArgument()));
484       } else {
485         // Does nothing, just clears selection.
486         delete aNewCurve;
487       }
488     }
489 #ifdef SET_PLANE
490     else if ( myEditCurrentArgument == myWPlaneLineEdit && isCheckToSelect() )
491     {
492       // Import planar face.
493       if (aShape.ShapeType() == TopAbs_FACE) {
494         // Check if the face is planar
495         Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
496         GeomLib_IsPlanarSurface aPlanarCheck(aSurf, Precision::Confusion());
497
498         if (aPlanarCheck.IsPlanar()) {
499           myWPlaneLineEdit->setText(aName);
500           myPolylineEdit->clear();
501           AddLocalCS(aSelectedObject.get(), true, 
502                      WPlaneToLCS(aSelectedObject.get()));
503           isModified = true;
504           myPlnSelButton->setChecked(false);
505           myPolylineSelButton->setChecked(false);
506         }
507       }
508       
509       if (!isModified) {
510         myEditCurrentArgument->setText(tr("GEOM_SKETCHER_WPLANE"));
511       }
512     }
513 #endif
514   }
515   else
516   {
517     if (isForced)
518     {
519 #ifdef SET_PLANE
520       myPlnSelButton->setChecked(false);
521 #endif
522       myPolylineSelButton->setChecked(false);
523     }
524   }
525
526   if (!isModified)
527   {
528     // Does nothing, just clears selection.
529     disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
530     myGeomGUI->getApp()->selectionMgr()->clearSelected();
531     connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
532             this, SLOT(SelectionIntoArgument()));
533   }
534   else
535     displayPreview();
536 }
537
538 //=================================================================================
539 // function : SetEditCurrentArgument()
540 // purpose  :
541 //=================================================================================
542 void EntityGUI_PolylineDlg::SetEditCurrentArgument( bool isChecked )
543 {
544   if (sender() == myPlnSelButton)
545   {
546 #ifdef SET_PLANE
547     myEditCurrentArgument = myWPlaneLineEdit;
548     myEditCurrentArgument->setFocus();
549     myPolylineSelButton->blockSignals(true);
550     myPolylineSelButton->setChecked(false);
551     myPolylineSelButton->blockSignals(false);
552 #endif
553   }
554   else if (sender() == myPolylineSelButton)
555   {
556     myEditCurrentArgument = myPolylineEdit;
557     myEditCurrentArgument->setFocus();
558 #ifdef SET_PLANE
559     myPlnSelButton->blockSignals(true);
560     myPlnSelButton->setChecked(false);
561     myPlnSelButton->blockSignals(false);
562 #endif
563   }
564 }
565
566 //=================================================================================
567 // function : ActivateThisDialog
568 // purpose  :
569 //=================================================================================
570 void EntityGUI_PolylineDlg::ActivateThisDialog()
571 {
572   GEOMBase_Skeleton::ActivateThisDialog();
573
574   connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
575            this, SLOT(SelectionIntoArgument()));
576 }
577
578 //=================================================================================
579 // function : enterEvent()
580 // purpose  :
581 //=================================================================================
582 void EntityGUI_PolylineDlg::enterEvent (QEvent*)
583 {
584   if (!mainFrame()->GroupConstructors->isEnabled())
585     ActivateThisDialog();
586 }
587
588 //=================================================================================
589 // function : ActivateLocalCS
590 // purpose  : Activate & Fit Working plane
591 //=================================================================================
592 void EntityGUI_PolylineDlg::ActivateLocalCS()
593 {
594   const int ind = myPlnComboBox->currentIndex();
595
596   if (ind == 0) {
597     // Default plane
598 #ifdef SET_PLANE
599     myWPlaneLineEdit->clear();
600 #endif
601     myPolylineEdit->clear();
602   } else if (ind > 0) { // Skip 0 as it is default
603     // Update text on line edits.
604     QString aName   = GEOMBase::GetName(GetActiveWPlane().get());
605     bool    isPlane = myPlnComboBox->itemData(ind).toBool();
606
607     if (isPlane) {
608 #ifdef SET_PLANE
609       myWPlaneLineEdit->setText(aName);
610 #endif
611       myPolylineEdit->clear();
612     } else {
613       myPolylineEdit->setText(aName);
614 #ifdef SET_PLANE
615       myWPlaneLineEdit->clear();
616 #endif
617     }
618   }
619
620   gp_Ax3 anAxis = GetActiveLocalCS();
621
622   myGeomGUI->SetWorkingPlane(anAxis);
623   myGeomGUI->ActiveWorkingPlane();
624 }
625
626 //=================================================================================
627 // function : GetActiveLocalCS
628 // purpose  : Get Working plane
629 //=================================================================================
630 gp_Ax3 EntityGUI_PolylineDlg::GetActiveLocalCS()
631 {
632   const int ind = myPlnComboBox->currentIndex();
633
634   return ind >= 0 ? myLCSList.at(ind) : myGeomGUI->GetWorkingPlane();
635 }
636
637 //=================================================================================
638 // function : GetActiveWPlane
639 // purpose  : Get Working plane
640 //=================================================================================
641 GEOM::GeomObjPtr EntityGUI_PolylineDlg::GetActiveWPlane()
642 {
643   const int ind = myPlnComboBox->currentIndex();
644
645   return ind >= 0 ? myWPlaneList.at(ind) : GEOM::GeomObjPtr();
646 }
647
648 //=================================================================================
649 // function : AddLocalCS()
650 // purpose  : Add All Coordinates systems in study
651 //=================================================================================
652 void EntityGUI_PolylineDlg::AddLocalCS(GEOM::GeomObjPtr  theSelectedObject,
653                                        const bool        IsPlane,
654                                        const gp_Ax3      &theLCS)
655 {
656   QString aName = GEOMBase::GetName(theSelectedObject.get());
657
658   int index = myPlnComboBox->findText(aName, Qt::MatchExactly);
659
660   if (index == -1) { // If the working plane hasn't been added yet
661     myWPlaneList.push_back(theSelectedObject);
662     myLCSList.push_back(theLCS);
663     myPlnComboBox->addItem(aName, QVariant(IsPlane));
664     index = myPlnComboBox->count();
665     myPlnComboBox->setCurrentIndex(index - 1);
666   } else {
667     myPlnComboBox->setCurrentIndex(index);
668   }
669   ActivateLocalCS();
670 }
671
672 //=================================================================================
673 // function : WPlaneToLCS ( aWPlane )
674 // purpose  : 
675 //=================================================================================
676 gp_Ax3 EntityGUI_PolylineDlg::WPlaneToLCS(GEOM::GeomObjPtr theGeomObj)
677 {
678   TopoDS_Shape aShape =
679     GEOM_Client::get_client().GetShape(GeometryGUI::GetGeomGen(), theGeomObj.get());
680   gp_Ax3 aLCS;
681
682   if (theGeomObj || aShape.IsNull()) {
683     MESSAGE("CORBA::is_nil(theGeomObj) || aShape.IsNull()")
684   }
685
686   aLCS.Transform(aShape.Location().Transformation());
687
688   if (aShape.ShapeType() == TopAbs_FACE) {
689     GEOM::GEOM_IMeasureOperations_ptr aMeasureOp =
690       myGeomGUI->GetGeomGen()->GetIMeasureOperations(getStudyId());
691     double Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz;
692
693     aMeasureOp->GetPosition(theGeomObj.get(), Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz);
694
695     if (aMeasureOp->IsDone()) {
696       gp_Pnt aPnt (Ox, Oy, Oz);
697       gp_Dir aDirN (Zx, Zy, Zz);
698       gp_Dir aDirX (Xx, Xy, Xz);
699       aLCS = gp_Ax3(aPnt, aDirN, aDirX);
700     }
701   }
702
703   return aLCS;
704 }
705
706 //=================================================================================
707 // function : getSourceObjects
708 // purpose  : virtual method to get source objects
709 //=================================================================================
710 QList<GEOM::GeomObjPtr> EntityGUI_PolylineDlg::getSourceObjects()
711 {
712   return myWPlaneList;
713 }
714
715 //=================================================================================
716 // function : setPreviewManager ( OCCViewer_ViewManager )
717 // purpose  : Sets view manager to control the displayed objects.
718 //=================================================================================
719 void EntityGUI_PolylineDlg::setPreviewManager( OCCViewer_ViewManager* theManager )
720 {
721   myPreviewManager = theManager;
722
723   if ( getPreviewManager() )
724   {
725     if( OCCViewer_Viewer* aViewer = getPreviewManager()->getOCCViewer() )
726     {
727       Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
728       if( !aCtx.IsNull() )
729       {
730         // Add Z layer to show temporary objects
731         int aZLayer = -1;
732         aViewer->getViewer3d()->AddZLayer( aZLayer );
733         setPreviewZLayer( aZLayer );
734       }
735     }
736   }
737 }
738
739 //=================================================================================
740 // function : getPreviewManager()
741 // purpose  : 
742 //=================================================================================
743 OCCViewer_ViewManager* EntityGUI_PolylineDlg::getPreviewManager()
744 {
745   return myPreviewManager;
746 }
747
748 //=================================================================================
749 // function : setPreviewZLayer( theZLayer )
750 // purpose  : Sets Z layer to show temporary objects.
751 //=================================================================================
752 void EntityGUI_PolylineDlg::setPreviewZLayer( int theZLayer )
753 {
754   if ( theZLayer != myPreviewZLayer )
755     myPreviewZLayer = theZLayer;
756 }
757
758 //=================================================================================
759 // function : getPreviewZLayer()
760 // purpose  : 
761 //=================================================================================
762 int EntityGUI_PolylineDlg::getPreviewZLayer() const
763 {
764   return myPreviewZLayer;
765 }
766
767 //=================================================================================
768 // function : displayPreview()
769 // purpose  : 
770 //=================================================================================
771 void EntityGUI_PolylineDlg::displayPreview()
772 {
773   if ( getPreviewManager() )
774   {
775     if ( OCCViewer_Viewer* aViewer = getPreviewManager()->getOCCViewer() )
776     {
777       // Disable changing of OCCViewer's selection to use vertex of curve selection
778       disconnect(getPreviewManager(), SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
779                  aViewer,             SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
780
781       Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
782       if ( !aCtx.IsNull() )
783       {
784         CurveCreator_Displayer* aDisplayer = new CurveCreator_Displayer( aCtx, getPreviewZLayer() );
785         myCurve->setDisplayer( aDisplayer );
786
787         Handle(AIS_InteractiveObject) anAISObj = myCurve->getAISObject( true );
788         aDisplayer->display( anAISObj, true );
789
790         // Set color for temporary AIS_InteractiveObject
791         anAISObj->Attributes()->WireAspect()->SetColor( Quantity_NOC_VIOLET );
792         aCtx->Redisplay( anAISObj );
793       }
794     }
795   }
796 }
797
798 //=================================================================================
799 // function : erasePreview()
800 // purpose  : 
801 //=================================================================================
802 void EntityGUI_PolylineDlg::erasePreview()
803 {
804   CurveCreator_Displayer* aDisplayer = myCurve ? myCurve->getDisplayer() : 0;
805   if( getPreviewManager() )
806   {
807     if( OCCViewer_Viewer* aViewer = getPreviewManager()->getOCCViewer() )
808     {
809       Handle(AIS_InteractiveContext) aCtx = aViewer->getAISContext();
810       if( !aCtx.IsNull() && aDisplayer )
811         aDisplayer->eraseAll( true );
812
813       // Enable changing of OCCViewer's selection
814       connect(getPreviewManager(), SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
815               aViewer,             SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
816     }
817   }
818
819   setPreviewManager( NULL );
820   if ( myCurve )
821   {
822     delete myCurve;
823     myCurve = NULL;
824   }
825 }
826
827 //=================================================================================
828 // function : isCheckToSelect()
829 // purpose  : 
830 //=================================================================================
831 bool EntityGUI_PolylineDlg::isCheckToSelect()
832 {
833 #ifdef SET_PLANE
834   return myPlnSelButton->isChecked();
835 #endif
836   return myPolylineSelButton->isChecked();
837 }