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