Salome HOME
Merging with WPdev
[modules/geom.git] / src / GEOMGUI / GeometryGUI.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 //
23 //
24 //  File   : GeometryGUI.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "GeometryGUI.h"
30 #include "GEOMGUI_OCCSelector.h"
31 #include "GEOMGUI_Selection.h"
32 #include "GEOM_Displayer.h"
33
34 #include <SUIT_MessageBox.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_ViewManager.h>
38
39 #include <OCCViewer_ViewWindow.h>
40 #include <OCCViewer_ViewPort3d.h>
41 #include <OCCViewer_ViewModel.h>
42 #include <OCCViewer_ViewManager.h>
43
44 #include <SVTK_ViewWindow.h>
45 #include <SVTK_RenderWindowInteractor.h>
46 #include <SVTK_InteractorStyle.h>
47 #include <SVTK_ViewModel.h>
48 #include <SVTK_ViewManager.h>
49
50 #include <SalomeApp_Application.h>
51 #include <LightApp_SelectionMgr.h>
52 #include <LightApp_VTKSelector.h>
53 #include <SalomeApp_Study.h>
54 #include <LightApp_Preferences.h>
55 #include <SALOME_LifeCycleCORBA.hxx>
56 #include <SALOME_ListIO.hxx>
57
58 // External includes
59 #include <qfileinfo.h>
60 #include <qpainter.h>
61
62 #include <Prs3d_Drawer.hxx>
63 #include <Prs3d_IsoAspect.hxx>
64 #include <OSD_SharedLibrary.hxx>
65
66 #include <utilities.h>
67
68 #include <vtkCamera.h>
69 #include <vtkRenderer.h>
70
71
72 extern "C" {
73   Standard_EXPORT CAM_Module* createModule() {
74     return new GeometryGUI();
75   }
76 }
77
78
79
80 GEOM::GEOM_Gen_var GeometryGUI::myComponentGeom = GEOM::GEOM_Gen::_nil();
81
82 GEOM::GEOM_Gen_var GeometryGUI::GetGeomGen()
83 {
84   // Bug 12290: exception in Mesh GUI on GEOMBase::GetShape() if Geometry GUI hasn't been loaded
85   if (CORBA::is_nil(myComponentGeom))
86     InitGeomGen();
87   return GeometryGUI::myComponentGeom;
88 }
89
90 bool GeometryGUI::InitGeomGen()
91 {
92   GeometryGUI aGG;
93   if( CORBA::is_nil( myComponentGeom ) ) return false;
94   return true;
95 }
96
97 //=======================================================================
98 // function : ClientSObjectToObject
99 // purpose  :
100 //=======================================================================
101 CORBA::Object_var GeometryGUI::ClientSObjectToObject (_PTR(SObject) theSObject)
102 {
103   _PTR(GenericAttribute) anAttr;
104   CORBA::Object_var anObj;
105   try {
106     std::string aValue = theSObject->GetIOR();
107     if (strcmp(aValue.c_str(), "") != 0) {
108       CORBA::ORB_ptr anORB = SalomeApp_Application::orb();
109       anObj = anORB->string_to_object(aValue.c_str());
110     }
111   } catch(...) {
112     INFOS("ClientSObjectToObject - Unknown exception was occured!!!");
113   }
114   return anObj._retn();
115 }
116
117 //=======================================================================
118 // function : ClientStudyToStudy
119 // purpose  :
120 //=======================================================================
121 SALOMEDS::Study_var GeometryGUI::ClientStudyToStudy (_PTR(Study) theStudy)
122 {
123   SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
124   CORBA::Object_var aSMObject = aNamingService->Resolve("/myStudyManager");
125   SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(aSMObject);
126   int aStudyID = theStudy->StudyId();
127   SALOMEDS::Study_var aDSStudy = aStudyManager->GetStudyByID(aStudyID);
128   return aDSStudy._retn();
129 }
130
131 //=================================================================================
132 // class   : CustomItem
133 // purpose : Set Font to a text.
134 //=================================================================================
135 class CustomItem : public QCustomMenuItem
136 {
137 public:
138   CustomItem(const QString& s, const QFont& f) : myString(s), myFont(f) {}
139   ~CustomItem() {}
140
141   void paint(QPainter* p, const QColorGroup& cg, bool act, bool /*enabled*/, int x, int y, int w, int h)
142   {
143     p->save();
144     p->fillRect( x, y, w, h, act ? cg.highlight() : cg.mid() );
145     p->setPen( act ? cg.highlightedText() : cg.buttonText() );
146     p->setFont( myFont );
147     p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
148     p->restore();
149   }
150
151   QSize sizeHint()
152   {
153     return QFontMetrics( myFont ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
154   }
155
156   bool fullSpan() const
157   {
158     return true;
159   }
160
161 private:
162   QString myString;
163   QFont   myFont;
164 };
165
166 //=======================================================================
167 // function : GeometryGUI::GeometryGUI()
168 // purpose  : Constructor
169 //=======================================================================
170 GeometryGUI::GeometryGUI() :
171   SalomeApp_Module( "GEOM" )
172 {
173   if ( CORBA::is_nil( myComponentGeom ) )
174   {
175     SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( getApp()->namingService() );
176     Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "GEOM" );
177     myComponentGeom  = GEOM::GEOM_Gen::_narrow( comp );
178   }
179
180   myState           = -1;
181   myActiveDialogBox = 0;
182   myFatherior       = "";
183
184   gp_Pnt origin = gp_Pnt(0., 0., 0.);
185   gp_Dir direction = gp_Dir(0., 0., 1.);
186   myWorkingPlane = gp_Ax3(origin, direction);
187
188   myOCCSelectors.setAutoDelete( true );
189   myVTKSelectors.setAutoDelete( true );
190
191   myDisplayer = 0;
192 }
193
194 //=======================================================================
195 // function : GeometryGUI::~GeometryGUI()
196 // purpose  : Destructor
197 //=======================================================================
198 GeometryGUI::~GeometryGUI()
199 {
200 }
201
202 //=======================================================================
203 // function : GeometryGUI::getLibrary()
204 // purpose  : get or load GUI library by name [ internal ]
205 //=======================================================================
206 typedef GEOMGUI* (*LibraryGUI)( GeometryGUI* );
207 GEOMGUI* GeometryGUI::getLibrary( const QString& libraryName )
208 {
209   if ( !myGUIMap.contains( libraryName ) ) {
210     // try to load library if it is not loaded yet
211     QCString libs;
212 #ifndef WNT
213     if( ( libs = getenv( "LD_LIBRARY_PATH" ) ) ) {
214           QStringList dirList = QStringList::split( ":", libs, false ); // skip empty entries
215 #else
216         if( ( libs = getenv( "PATH" ) ) ) {
217           QStringList dirList = QStringList::split( ";", libs, false ); // skip empty entries
218 #endif
219       for( int i = dirList.count()-1; i >= 0; i-- ) {
220         QString dir = dirList[ i ];
221         QFileInfo fi( Qtx::addSlash( dirList[ i ] ) + libraryName );
222         if( fi.exists() ) {
223           OSD_SharedLibrary aSharedLibrary( (char*)fi.fileName().latin1() );
224           bool res = aSharedLibrary.DlOpen( OSD_RTLD_LAZY );
225           if( !res ) {
226             MESSAGE( "Can't open library : " << aSharedLibrary.DlError() );
227             continue; // continue search further
228           }
229           OSD_Function osdF = aSharedLibrary.DlSymb( "GetLibGUI" );
230           if ( osdF != NULL ) {
231             LibraryGUI func = (GEOMGUI* (*) (GeometryGUI*))osdF;
232             GEOMGUI* libGUI = (*func)(this);
233             if ( libGUI ) {
234               myGUIMap[ libraryName ] = libGUI;
235               break; // found and loaded!
236             }
237           }
238         }
239       }
240     }
241   }
242   if ( myGUIMap.contains( libraryName ) )
243     // library is successfully loaded
244     return myGUIMap[ libraryName ];
245   return 0;
246 }
247
248 //=======================================================================
249 // function : GeometryGUI::ActiveWorkingPlane()
250 // purpose  : Activate Working Plane View
251 //=======================================================================
252 void GeometryGUI::ActiveWorkingPlane()
253 {
254   gp_Dir DZ = myWorkingPlane.Direction();
255   gp_Dir DY = myWorkingPlane.YDirection();
256
257   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
258   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
259   bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
260
261   if( ViewOCC ) {
262     OCCViewer_ViewWindow* vw = dynamic_cast<OCCViewer_ViewWindow*>( window );
263     if ( vw ) {
264       Handle(V3d_View) view3d =  vw->getViewPort()->getView();
265
266       view3d->SetProj(DZ.X(), DZ.Y(), DZ.Z());
267       view3d->SetUp(DY.X(), DY.Y(), DY.Z());
268
269       vw->onViewFitAll();
270     }
271   }
272   else if( ViewVTK ) {
273     SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
274     if ( vw ) {
275       vtkCamera* camera = vw->getRenderer()->GetActiveCamera();
276
277       camera->SetPosition(DZ.X(), DZ.Y(), DZ.Z());
278       camera->SetViewUp(DY.X(), DY.Y(), DY.Z());
279       camera->SetFocalPoint(0,0,0);
280
281       vw->onFitAll();
282     }
283   }
284 }
285
286 //=======================================================================
287 // function : GeometryGUI::SetActiveDialogBox()
288 // purpose  : Set active dialog box
289 //=======================================================================
290 void GeometryGUI::SetActiveDialogBox( QDialog* aDlg )
291 {
292   myActiveDialogBox = (QDialog*)aDlg;
293 }
294
295 //=======================================================================
296 // function : GeometryGUI::EmitSignalDeactivateDialog()
297 // purpose  : Emit a signal to deactivate the active dialog Box
298 //=======================================================================
299 void GeometryGUI::EmitSignalDeactivateDialog()
300 {
301   emit SignalDeactivateActiveDialog();
302 }
303
304 //=======================================================================
305 // function : GeometryGUI::EmitSignalCloseAllDialogs()
306 // purpose  : Emit a signal to close all non modal dialogs box
307 //=======================================================================
308 void GeometryGUI::EmitSignalCloseAllDialogs()
309 {
310   emit SignalCloseAllDialogs();
311 }
312
313 //=======================================================================
314 // function : GeometryGUI::EmitSignalDefaultStepValueChanged()
315 // purpose  : Emit a signal to inform that default real spin box step has
316 //            been changed
317 //=======================================================================
318 void GeometryGUI::EmitSignalDefaultStepValueChanged(double newVal)
319 {
320   emit SignalDefaultStepValueChanged(newVal);
321 }
322
323 //=======================================================================
324 // function : GeometryGUI::OnGUIEvent()
325 // purpose  : common slot for all menu/toolbar actions
326 //=======================================================================
327 void GeometryGUI::OnGUIEvent()
328 {
329   const QObject* obj = sender();
330   if ( !obj || !obj->inherits( "QAction" ) )
331     return;
332   int id = actionId((QAction*)obj);
333   if ( id != -1 )
334     OnGUIEvent( id );
335 }
336
337 //=======================================================================
338 // function : GeometryGUI::OnGUIEvent()
339 // purpose  : manage all events on GUI [static]
340 //=======================================================================
341 void GeometryGUI::OnGUIEvent( int id )
342 {
343   SUIT_Application* anApp = application();
344   if (!anApp) return;
345   SUIT_Desktop* desk = anApp->desktop();
346
347   // check type of the active viewframe
348   SUIT_ViewWindow* window = desk->activeWindow();
349   bool ViewOCC = ( window && window->getViewManager()->getType() == OCCViewer_Viewer::Type() );
350   bool ViewVTK = ( window && window->getViewManager()->getType() == SVTK_Viewer::Type() );
351   // if current viewframe is not of OCC and not of VTK type - return immediately
352   // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
353   bool NotViewerDependentCommand = ( id == 901 || id == 216 || id == 213 );
354   if ( !ViewOCC && !ViewVTK && !NotViewerDependentCommand )
355       return;
356
357   // fix for IPAL9103, point 2
358   if ( CORBA::is_nil( GetGeomGen() ) ) {
359     SUIT_MessageBox::error1( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_GET_ENGINE" ), tr( "GEOM_BUT_OK" ) );
360     return;
361   }
362
363   GEOMGUI* library = 0;
364   // try to get-or-load corresponding GUI library
365   if( id == 111  ||  // MENU FILE - IMPORT BREP
366       id == 112  ||  // MENU FILE - IMPORT IGES
367       id == 113  ||  // MENU FILE - IMPORT STEP
368       id == 121  ||  // MENU FILE - EXPORT BREP
369       id == 122  ||  // MENU FILE - EXPORT IGES
370       id == 123  ||  // MENU FILE - EXPORT STEP
371       id == 31   ||  // MENU EDIT - COPY
372       id == 33   ||  // MENU EDIT - DELETE
373       id == 411  ||  // MENU SETTINGS - ADD IN STUDY
374       id == 412  ||  // MENU SETTINGS - SHADING COLOR
375       id == 413  ||  // MENU SETTINGS - ISOS
376       id == 414  ||  // MENU SETTINGS - STEP VALUE FOR SPIN BOXES
377       id == 5103 ||  // MENU TOOLS - CHECK GEOMETRY
378       id == 8032 ||  // POPUP VIEWER - COLOR
379       id == 8033 ||  // POPUP VIEWER - TRANSPARENCY
380       id == 8034 ||  // POPUP VIEWER - ISOS
381       id == 804  ||  // POPUP VIEWER - ADD IN STUDY
382       id == 901  ||  // OBJECT BROWSER - RENAME
383       id == 9024 ) { // OBJECT BROWSER - OPEN
384     //cout << "id " << id << " received" << endl;
385 #ifndef WNT
386         library = getLibrary( "libGEOMToolsGUI.so" );
387 #else
388         library = getLibrary( "GEOMToolsGUI.dll" );
389 #endif
390   }
391   else if( id == 211  ||  // MENU VIEW - WIREFRAME/SHADING
392            id == 212  ||  // MENU VIEW - DISPLAY ALL
393            id == 213  ||  // MENU VIEW - DISPLAY ONLY
394            id == 214  ||  // MENU VIEW - ERASE ALL
395            id == 215  ||  // MENU VIEW - ERASE
396            id == 216  ||  // MENU VIEW - DISPLAY
397            id == 80311 ||  // POPUP VIEWER - WIREFRAME
398            id == 80312 ) { // POPUP VIEWER - SHADING
399 #ifndef WNT
400         library = getLibrary( "libDisplayGUI.so" );
401 #else
402         library = getLibrary( "DisplayGUI.dll" );
403 #endif
404   }
405   else if( id == 4011 ||  // MENU BASIC - POINT
406            id == 4012 ||  // MENU BASIC - LINE
407            id == 4013 ||  // MENU BASIC - CIRCLE
408            id == 4014 ||  // MENU BASIC - ELLIPSE
409            id == 4015 ||  // MENU BASIC - ARC
410            id == 4016 ||  // MENU BASIC - VECTOR
411            id == 4017 ||  // MENU BASIC - PLANE
412            id == 4018 ||  // MENU BASIC - WPLANE
413            id == 4019 ||  // MENU BASIC - CURVE
414            id == 4020 ) { // MENU BASIC - REPAIR
415 #ifndef WNT
416         library = getLibrary( "libBasicGUI.so" );
417 #else
418         library = getLibrary( "BasicGUI.dll" );
419 #endif
420   }
421   else if( id == 4021 ||  // MENU PRIMITIVE - BOX
422            id == 4022 ||  // MENU PRIMITIVE - CYLINDER
423            id == 4023 ||  // MENU PRIMITIVE - SPHERE
424            id == 4024 ||  // MENU PRIMITIVE - TORUS
425            id == 4025 ) { // MENU PRIMITIVE - CONE
426 #ifndef WNT
427         library = getLibrary( "libPrimitiveGUI.so" );
428 #else
429         library = getLibrary( "PrimitiveGUI.dll" );
430 #endif
431   }
432   else if( id == 4031 ||  // MENU GENERATION - PRISM
433            id == 4032 ||  // MENU GENERATION - REVOLUTION
434            id == 4033 ||  // MENU GENERATION - FILLING
435            id == 4034 ) { // MENU GENERATION - PIPE
436 #ifndef WNT
437         library = getLibrary( "libGenerationGUI.so" );
438 #else
439         library = getLibrary( "GenerationGUI.dll" );
440 #endif
441   }
442   else if( id == 404 ||   // MENU ENTITY - SKETCHER
443            id == 407 ) {  // MENU ENTITY - EXPLODE
444 #ifndef WNT
445         library = getLibrary( "libEntityGUI.so" );
446 #else
447         library = getLibrary( "EntityGUI.dll" );
448 #endif
449   }
450   else if( id == 4081 ||  // MENU BUILD - EDGE
451            id == 4082 ||  // MENU BUILD - WIRE
452            id == 4083 ||  // MENU BUILD - FACE
453            id == 4084 ||  // MENU BUILD - SHELL
454            id == 4085 ||  // MENU BUILD - SOLID
455            id == 4086 ) { // MENU BUILD - COMPUND
456 #ifndef WNT
457         library = getLibrary( "libBuildGUI.so" );
458 #else
459         library = getLibrary( "BuildGUI.dll" );
460 #endif
461   }
462   else if( id == 5011 ||  // MENU BOOLEAN - FUSE
463            id == 5012 ||  // MENU BOOLEAN - COMMON
464            id == 5013 ||  // MENU BOOLEAN - CUT
465            id == 5014 ) { // MENU BOOLEAN - SECTION
466 #ifndef WNT
467         library = getLibrary( "libBooleanGUI.so" );
468 #else
469         library = getLibrary( "BooleanGUI.dll" );
470 #endif
471   }
472   else if( id == 5021 ||  // MENU TRANSFORMATION - TRANSLATION
473            id == 5022 ||  // MENU TRANSFORMATION - ROTATION
474            id == 5023 ||  // MENU TRANSFORMATION - LOCATION
475            id == 5024 ||  // MENU TRANSFORMATION - MIRROR
476            id == 5025 ||  // MENU TRANSFORMATION - SCALE
477            id == 5026 ||  // MENU TRANSFORMATION - OFFSET
478            id == 5027 ||  // MENU TRANSFORMATION - MULTI-TRANSLATION
479            id == 5028 ) { // MENU TRANSFORMATION - MULTI-ROTATION
480 #ifndef WNT
481         library = getLibrary( "libTransformationGUI.so" );
482 #else
483         library = getLibrary( "TransformationGUI.dll" );
484 #endif
485   }
486   else if( id == 503 ||   // MENU OPERATION - PARTITION
487            id == 504 ||   // MENU OPERATION - ARCHIMEDE
488            id == 505 ||   // MENU OPERATION - FILLET
489            id == 506 ||   // MENU OPERATION - CHAMFER
490            id == 507 ) {  // MENU OPERATION - CLIPPING RANGE
491 #ifndef WNT
492         library = getLibrary( "libOperationGUI.so" );
493 #else
494         library = getLibrary( "OperationGUI.dll" );
495 #endif
496   }
497   else if( id == 601 ||   // MENU REPAIR - SEWING
498            id == 603 ||   // MENU REPAIR - SUPPRESS FACES
499            id == 604 ||   // MENU REPAIR - SUPPRESS HOLE
500            id == 605 ||   // MENU REPAIR - SHAPE PROCESSING
501            id == 606 ||   // MENU REPAIR - CLOSE CONTOUR
502            id == 607 ||   // MENU REPAIR - REMOVE INTERNAL WIRES
503            id == 608 ||   // MENU REPAIR - ADD POINT ON EDGE
504            id == 609 ||   // MENU REPAIR - FREE BOUNDARIES
505            id == 610 ||   // MENU REPAIR - FREE FACES
506            id == 611 ||   // MENU REPAIR - CHANGE ORIENTATION
507            id == 602 ) {  // MENU REPAIR - GLUE FACES
508 #ifndef WNT
509         library = getLibrary( "libRepairGUI.so" );
510 #else
511         library = getLibrary( "RepairGUI.dll" );
512 #endif
513   }
514   else if( id == 701   ||  // MENU MEASURE - PROPERTIES
515            id == 702   ||  // MENU MEASURE - CDG
516            id == 703   ||  // MENU MEASURE - INERTIA
517            id == 7041  ||  // MENU MEASURE - BOUNDING BOX
518            id == 7042  ||  // MENU MEASURE - MIN DISTANCE
519            id == 705   ||  // MENU MEASURE - TOLERANCE
520            id == 706   ||  // MENU MEASURE - WHATIS
521            id == 707   ||  // MENU MEASURE - CHECK
522            id == 7072  ||  // MENU MEASURE - CHECK COMPOUND OF BLOCKS
523            id == 708 ) {  // MENU MEASURE - POINT COORDINATES
524 #ifndef WNT
525         library = getLibrary( "libMeasureGUI.so" );
526 #else
527         library = getLibrary( "MeasureGUI.dll" );
528 #endif
529   }
530   else if( id == 800  ||  // MENU GROUP - CREATE
531            id == 8001 ||  // POPUP MENU - CREATE GROUP
532            id == 801 ) {  // MENU GROUP - EDIT
533 #ifndef WNT
534         library = getLibrary( "libGroupGUI.so" );
535 #else
536         library = getLibrary( "GroupGUI.dll" );
537 #endif
538   }
539   else if( id == 9999  ||  // MENU BLOCKS - HEXAHEDRAL SOLID
540            id == 9998  ||  // MENU BLOCKS - MULTI-TRANSFORMATION
541            id == 9997  ||  // MENU BLOCKS - QUADRANGLE FACE
542            id == 99991 ||  // MENU BLOCKS - PROPAGATE
543            id == 9995 ) { // MENU BLOCKS - EXPLODE ON BLOCKS
544 #ifndef WNT
545         library = getLibrary( "libBlocksGUI.so" );
546 #else
547         library = getLibrary( "BlocksGUI.dll" );
548 #endif
549   }
550
551   // call method of corresponding GUI library
552   if ( library )
553     library->OnGUIEvent( id, desk );
554   else
555     SUIT_MessageBox::error1( desk, tr( "GEOM_ERROR" ), tr( "GEOM_ERR_LIB_NOT_FOUND" ), tr( "GEOM_BUT_OK" ) );
556 }
557
558
559 //=================================================================================
560 // function : GeometryGUI::OnKeyPress()
561 // purpose  : Called when any key is pressed by user [static]
562 //=================================================================================
563 void GeometryGUI::OnKeyPress( SUIT_ViewWindow* win, QKeyEvent* pe )
564 {
565   GUIMap::Iterator it;
566   bool bOk = true;
567   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
568     SUIT_Application* anApp = application();
569     if (!anApp) return;
570     bOk = bOk && it.data()->OnKeyPress( pe, anApp->desktop(), win );
571   }
572 //  return bOk;
573 }
574
575
576 //=================================================================================
577 // function : GeometryGUI::OnMouseMove()
578 // purpose  : Manages mouse move events [static]
579 //=================================================================================
580 void GeometryGUI::OnMouseMove( SUIT_ViewWindow* win, QMouseEvent* pe )
581 {
582   GUIMap::Iterator it;
583   bool bOk = true;
584   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
585     SUIT_Application* anApp = application();
586     if (!anApp) return;
587     bOk = bOk && it.data()->OnMouseMove( pe, anApp->desktop(), win );
588   }
589 //  return bOk;
590 }
591
592
593 //=================================================================================
594 // function : GeometryGUI::0nMousePress()
595 // purpose  : Manage mouse press events [static]
596 //=================================================================================
597 void GeometryGUI::OnMousePress( SUIT_ViewWindow* win, QMouseEvent* pe )
598 {
599   GUIMap::Iterator it;
600   // OnMousePress() should return false if this event should be processed further
601   // (see OCCViewer_Viewer3d::onMousePress() for explanation)
602   bool processed = false;
603   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it ) {
604     SUIT_Application* anApp = application();
605     if (!anApp) return;
606     processed = processed || it.data()->OnMousePress( pe, anApp->desktop(), win );
607   }
608 //  return processed;
609 }
610
611 /*
612 static void UpdateVtkSelection()
613 {
614   QPtrList<SUIT_ViewWindow> winList = application()->desktop()->windows();
615   SUIT_ViewWindow* win = 0;
616   for ( win = winList.first(); win; win = winList.next() ) {
617     if ( win->getViewManager()->getTypeView() == VIEW_VTK ) {
618       SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
619       if ( vw ) {
620         SVTK_RenderWindowInteractor* anInteractor = vw->getRWInteractor();
621         anInteractor->SetSelectionProp();
622         anInteractor->SetSelectionTolerance();
623         SVTK_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
624         if (aStyle) {
625           aStyle->setPreselectionProp();
626         }
627       }
628     }
629   }
630 }
631
632 //=================================================================================
633 // function : GeometryGUI::SetSettings()
634 // purpose  : Called when GEOM module is activated [static]
635 //=================================================================================
636 bool GeometryGUI::SetSettings()
637 {
638   QMenuBar*     Mb = parent->getMainMenuBar();
639   SUIT_Study*   ActiveStudy = application()->activeStudy();
640
641 // Wireframe or Shading
642   int DisplayMode = 0;
643   SUIT_ViewWindow* window = application()->desktop()->activeWindow();
644   bool ViewOCC = ( window && window->getViewManager()->getType() == VIEW_OCC );
645   bool ViewVTK = ( window && window->getViewManager()->getType() == VIEW_VTK );
646   if ( ViewOCC ) {
647     OCCViewer_ViewManager* vm = dynamic_cast<OCCViewer_ViewManager*>( window->getViewManager() );
648     if ( vm ) {
649       Handle(AIS_InteractiveContext) ic = vm->getOCCViewer()->getAISContext();
650       DisplayMode = ic->DisplayMode();
651     }
652   }
653   else if ( ViewVTK ) {
654     SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>( window );
655     if ( vw ) {
656       SVTK_RenderWindowInteractor* myRenderInter = vw->getRWInteractor();
657       DisplayMode = myRenderInter->GetDisplayMode();
658     }
659   }
660
661   if( DisplayMode == 1 )
662     getApp()->
663     Mb->changeItem( 211, tr( "GEOM_MEN_WIREFRAME" ) );
664   else
665     Mb->changeItem( 211, tr( "GEOM_MEN_SHADING" ) );
666
667
668   // Add in Study  - !!!ALWAYS TRUE!!! /////// VSR : TO BE REMOVED
669   QString AddInStudy = QAD_CONFIG->getSetting("Geometry:SettingsAddInStudy");
670   int Settings_AddInStudy;
671   //  if(!AddInStudy.isEmpty())
672   //    Settings_AddInStudy = AddInStudy.toInt();
673   //  else
674
675   Settings_AddInStudy = 1;
676   Mb->setItemChecked(411, Settings_AddInStudy);
677
678   // step value
679   QString S = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
680   if(S.isEmpty())
681     QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", "100");
682
683   // isos
684   int count = ActiveStudy->getStudyFramesCount();
685   for(int i = 0; i < count; i++) {
686     if(ActiveStudy->getStudyFrame(i)->getTypeView() == VIEW_OCC) {
687       OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)ActiveStudy->getStudyFrame(i)->getRightFrame()->getViewFrame())->getViewer();
688       Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
689
690       QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
691       QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
692       if(!IsoU.isEmpty())
693         ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
694       if(!IsoV.isEmpty())
695         ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
696     }
697   }
698
699   setActionsEnabled();
700
701   // PAL5356: update VTK selection
702   ::UpdateVtkSelection();
703   bool bOk = true;
704   GUIMap::Iterator it;
705   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
706     bOk = bOk && it.data()->SetSettings( parent );
707
708   // MZN: Enable/disable "Clipping range" menu item(from GEOM_CLIPPING variable)
709   if (getenv( "GEOM_CLIPPING" ) == NULL)
710     {
711       QMenuItem* mi = Mb->findItem(50);
712       if (mi && mi->popup())
713       mi->popup()->removeItem(507);
714     }
715
716   return bOk;
717 }
718 */
719
720 //=======================================================================
721 // function : createGeomAction
722 // purpose  :
723 //=======================================================================
724 void GeometryGUI::createGeomAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
725 {
726   QIconSet icon;
727   QWidget* parent = application()->desktop();
728   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
729   QPixmap pix;
730   if ( icon_id.length() )
731     pix = resMgr->loadPixmap( "GEOM", tr( icon_id ) );
732   else
733     pix = resMgr->loadPixmap( "GEOM", tr( QString( "ICO_" )+po_id ), false );
734   if ( !pix.isNull() )
735     icon = QIconSet( pix );
736
737   QString tooltip    = tr( QString( "TOP_" )+po_id ),
738           menu       = tr( QString( "MEN_" )+po_id ),
739           status_bar = tr( QString( "STB_" )+po_id );
740
741   createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
742 }
743
744
745
746 //=======================================================================
747 // function : GeometryGUI::initialize()
748 // purpose  : Called when GEOM module is created
749 //=======================================================================
750 void GeometryGUI::initialize( CAM_Application* app )
751 {
752   SalomeApp_Module::initialize( app );
753
754   // ----- create actions --------------
755
756   createGeomAction( 111, "IMPORT", "", (CTRL + Key_I) );
757   createGeomAction( 121, "EXPORT", "", (CTRL + Key_E) );
758
759   createGeomAction( 33, "DELETE" );
760
761   createGeomAction( 4011, "POINT" );
762   createGeomAction( 4012, "LINE" );
763   createGeomAction( 4013, "CIRCLE" );
764   createGeomAction( 4014, "ELLIPSE" );
765   createGeomAction( 4015, "ARC" );
766   createGeomAction( 4019, "CURVE" );
767   createGeomAction( 4016, "VECTOR" );
768   createGeomAction( 4017, "PLANE" );
769   createGeomAction( 4018, "WORK_PLANE" );
770   createGeomAction( 4020, "LOCAL_CS" );
771
772   createGeomAction( 4021, "BOX" );
773   createGeomAction( 4022, "CYLINDER" );
774   createGeomAction( 4023, "SPHERE" );
775   createGeomAction( 4024, "TORUS" );
776   createGeomAction( 4025, "CONE" );
777
778   createGeomAction( 4031, "EXTRUSION" );
779   createGeomAction( 4032, "REVOLUTION" );
780   createGeomAction( 4033, "FILLING" );
781   createGeomAction( 4034, "PIPE" );
782
783   createGeomAction( 800, "GROUP_CREATE" );
784   createGeomAction( 801, "GROUP_EDIT" );
785
786   createGeomAction( 9997, "Q_FACE" );
787   createGeomAction( 9999, "HEX_SOLID" );
788
789   createGeomAction( 404, "SKETCH" );
790   createGeomAction( 407, "EXPLODE" );
791
792   createGeomAction( 4081, "EDGE" );
793   createGeomAction( 4082, "WIRE" );
794   createGeomAction( 4083, "FACE" );
795   createGeomAction( 4084, "SHELL" );
796   createGeomAction( 4085, "SOLID" );
797   createGeomAction( 4086, "COMPOUND" );
798
799   createGeomAction( 5011, "FUSE" );
800   createGeomAction( 5012, "COMMON" );
801   createGeomAction( 5013, "CUT" );
802   createGeomAction( 5014, "SECTION" );
803
804   createGeomAction( 5021, "TRANSLATION" );
805   createGeomAction( 5022, "ROTATION" );
806   createGeomAction( 5023, "MODIFY_LOCATION" );
807   createGeomAction( 5024, "MIRROR" );
808   createGeomAction( 5025, "SCALE" );
809   createGeomAction( 5026, "OFFSET" );
810   createGeomAction( 5027, "MUL_TRANSLATION" );
811   createGeomAction( 5028, "MUL_ROTATION" );
812
813   createGeomAction( 503, "PARTITION" );
814   createGeomAction( 504, "ARCHIMEDE" );
815   createGeomAction( 505, "FILLET" );
816   createGeomAction( 506, "CHAMFER" );
817   //createGeomAction( 507, "CLIPPING" );
818
819   createGeomAction( 9998, "MUL_TRANSFORM" );
820   createGeomAction( 9995, "EXPLODE_BLOCKS" );
821   createGeomAction( 99991, "PROPAGATE" );
822
823   createGeomAction( 601, "SEWING" );
824   createGeomAction( 602, "GLUE_FACES" );
825   createGeomAction( 603, "SUPPRESS_FACES" );
826   createGeomAction( 604, "SUPPERSS_HOLES" );
827   createGeomAction( 605, "SHAPE_PROCESS" );
828   createGeomAction( 606, "CLOSE_CONTOUR" );
829   createGeomAction( 607, "SUPPRESS_INT_WIRES" );
830   createGeomAction( 608, "POINT_ON_EDGE" );
831   createGeomAction( 609, "CHECK_FREE_BNDS" );
832   createGeomAction( 610, "CHECK_FREE_FACES" );
833   createGeomAction( 611, "CHANGE_ORIENTATION" );
834
835   createGeomAction( 708, "POINT_COORDS" );
836   createGeomAction( 701, "BASIC_PROPS" );
837   createGeomAction( 702, "MASS_CENTER" );
838   createGeomAction( 703, "INERTIA" );
839   createGeomAction( 7041, "BND_BOX" );
840   createGeomAction( 7042, "MIN_DIST" );
841
842   createGeomAction( 705, "TOLERANCE" );
843   createGeomAction( 706, "WHAT_IS" );
844   createGeomAction( 707, "CHECK" );
845   createGeomAction( 7072, "CHECK_COMPOUND" );
846
847   createGeomAction( 5103, "CHECK_GEOMETRY" );
848
849   createGeomAction( 412, "SHADING_COLOR" );
850   createGeomAction( 413, "ISOS" );
851   createGeomAction( 414, "STEP_VALUE" );
852
853   createGeomAction( 211, "SHADING" );
854   createGeomAction( 212, "DISPLAY_ALL" );
855   createGeomAction( 214, "ERASE_ALL" );
856   createGeomAction( 216, "DISPLAY" );
857   createGeomAction( 213, "DISPLAY_ONLY" );
858   createGeomAction( 215, "ERASE" );
859
860   createGeomAction( 901, "POP_RENAME" );
861   createGeomAction( 80311, "POP_WIREFRAME", "", 0, true );
862   createGeomAction( 80312, "POP_SHADING", "", 0, true );
863   createGeomAction( 8032, "POP_COLOR" );
864   createGeomAction( 8033, "POP_TRANSPARENCY" );
865   createGeomAction( 8034, "POP_ISOS" );
866   createGeomAction( 8001, "POP_CREATE_GROUP" );
867
868   // make wireframe-shading items to be exclusive (only one at a time is selected)
869   //QActionGroup* dispModeGr = new QActionGroup( this, "", true );
870   //dispModeGr->add( action( 80311 ) );
871   //dispModeGr->add( action( 80312 ) );
872   // ---- create menu --------------------------
873
874   int fileId = createMenu( tr( "MEN_FILE" ), -1, -1 );
875   createMenu( separator(), fileId, 10 );
876   createMenu( 111, fileId, 10 );
877   createMenu( 121, fileId, 10 );
878   createMenu( separator(), fileId, -1 );
879
880   int editId = createMenu( tr( "MEN_EDIT" ), -1, -1 );
881   createMenu( 33, editId, -1 );
882
883   int newEntId = createMenu( tr( "MEN_NEW_ENTITY" ), -1, -1, 10 );
884
885   int basicId = createMenu( tr( "MEN_BASIC" ), newEntId, -1 );
886   createMenu( 4011, basicId, -1 );
887   createMenu( 4012, basicId, -1 );
888   createMenu( 4013, basicId, -1 );
889   createMenu( 4014, basicId, -1 );
890   createMenu( 4015, basicId, -1 );
891   createMenu( 4019, basicId, -1 );
892   createMenu( separator(), basicId, -1 );
893   createMenu( 4016, basicId, -1 );
894   createMenu( 4017, basicId, -1 );
895   createMenu( 4018, basicId, -1 );
896   createMenu( 4020, basicId, -1 );
897
898   int primId = createMenu( tr( "MEN_PRIMITIVES" ), newEntId, -1 );
899   createMenu( 4021, primId, -1 );
900   createMenu( 4022, primId, -1 );
901   createMenu( 4023, primId, -1 );
902   createMenu( 4024, primId, -1 );
903   createMenu( 4025, primId, -1 );
904
905   int genId = createMenu( tr( "MEN_GENERATION" ), newEntId, -1 );
906   createMenu( 4031, genId, -1 );
907   createMenu( 4032, genId, -1 );
908   createMenu( 4033, genId, -1 );
909   createMenu( 4034, genId, -1 );
910   createMenu( separator(), newEntId, -1 );
911
912   int groupId = createMenu( tr( "MEN_GROUP" ), newEntId, -1 );
913   createMenu( 800, groupId, -1 );
914   createMenu( 801, groupId, -1 );
915   createMenu( separator(), newEntId, -1 );
916
917   int blocksId = createMenu( tr( "MEN_BLOCKS" ), newEntId, -1 );
918   createMenu( 9997, blocksId, -1 );
919   createMenu( 9999, blocksId, -1 );
920
921   createMenu( separator(), newEntId, -1 );
922   createMenu( 404, newEntId, -1 );
923   createMenu( separator(), newEntId, -1 );
924   createMenu( 407, newEntId, -1 );
925
926   int buildId = createMenu( tr( "MEN_BUILD" ), newEntId, -1 );
927   createMenu( 4081, buildId, -1 );
928   createMenu( 4082, buildId, -1 );
929   createMenu( 4083, buildId, -1 );
930   createMenu( 4084, buildId, -1 );
931   createMenu( 4085, buildId, -1 );
932   createMenu( 4086, buildId, -1 );
933
934   int operId = createMenu( tr( "MEN_OPERATIONS" ), -1, -1, 10 );
935
936   int boolId = createMenu( tr( "MEN_BOOLEAN" ), operId, -1 );
937   createMenu( 5011, boolId, -1 );
938   createMenu( 5012, boolId, -1 );
939   createMenu( 5013, boolId, -1 );
940   createMenu( 5014, boolId, -1 );
941
942   int transId = createMenu( tr( "MEN_TRANSFORMATION" ), operId, -1 );
943   createMenu( 5021, transId, -1 );
944   createMenu( 5022, transId, -1 );
945   createMenu( 5023, transId, -1 );
946   createMenu( 5024, transId, -1 );
947   createMenu( 5025, transId, -1 );
948   createMenu( 5026, transId, -1 );
949   createMenu( separator(), transId, -1 );
950   createMenu( 5027, transId, -1 );
951   createMenu( 5028, transId, -1 );
952
953   createMenu( 503, operId, -1 );
954   createMenu( 504, operId, -1 );
955   createMenu( separator(), operId, -1 );
956   createMenu( 505, transId, -1 );
957   createMenu( 506, transId, -1 );
958   //createMenu( 507, transId, -1 );
959
960   int blockId = createMenu( tr( "MEN_BLOCKS" ), operId, -1 );
961   createMenu( 9998, blockId, -1 );
962   createMenu( 9995, blockId, -1 );
963   createMenu( 99991, blockId, -1 );
964
965   int repairId = createMenu( tr( "MEN_REPAIR" ), -1, -1, 10 );
966   createMenu( 605, repairId, -1 );
967   createMenu( 603, repairId, -1 );
968   createMenu( 606, repairId, -1 );
969   createMenu( 607, repairId, -1 );
970   createMenu( 604, repairId, -1 );
971   createMenu( 601, repairId, -1 );
972   createMenu( 602, repairId, -1 );
973   createMenu( 608, repairId, -1 );
974   createMenu( 609, repairId, -1 );
975   createMenu( 610, repairId, -1 );
976   createMenu( 611, repairId, -1 );
977
978   int measurId = createMenu( tr( "MEN_MEASURES" ), -1, -1, 10 );
979   createMenu( 708, measurId, -1 );
980   createMenu( 701, measurId, -1 );
981   createMenu( separator(), measurId, -1 );
982   createMenu( 702, measurId, -1 );
983   createMenu( 703, measurId, -1 );
984   createMenu( separator(), measurId, -1 );
985
986   int dimId = createMenu( tr( "MEN_DIMENSIONS" ), measurId, -1 );
987   createMenu( 7041, dimId, -1 );
988   createMenu( 7042, dimId, -1 );
989   createMenu( separator(), measurId, -1 );
990
991   createMenu( 705, measurId, -1 );
992   createMenu( separator(), measurId, -1 );
993   createMenu( 706, measurId, -1 );
994   createMenu( 707, measurId, -1 );
995   createMenu( 7072, measurId, -1 );
996
997   int toolsId = createMenu( tr( "MEN_TOOLS" ), -1, -1, 50 );
998   createMenu( separator(), toolsId, -1 );
999   createMenu( 5103, toolsId, -1 );
1000
1001   //int prefId = createMenu( tr( "MEN_PREFERENCES" ), -1, -1, 50 );
1002   //createMenu( separator(), prefId, -1 );
1003   //int geomId = createMenu( tr( "MEN_PREFERENCES_GEOM" ), prefId, -1 );
1004   //createMenu( 412, geomId, -1 );
1005   //createMenu( 413, geomId, -1 );
1006   //createMenu( 414, geomId, -1 );
1007   //createMenu( separator(), prefId, -1 );
1008
1009   int viewId = createMenu( tr( "MEN_VIEW" ), -1, -1 );
1010   createMenu( separator(), viewId, -1 );
1011
1012   int dispmodeId = createMenu( tr( "MEN_DISPLAY_MODE" ), viewId, -1 );
1013   createMenu( 211, dispmodeId, -1 );
1014
1015   createMenu( separator(), viewId, -1 );
1016   createMenu( 212, viewId, -1 );
1017   createMenu( 214, viewId, -1 );
1018   createMenu( separator(), viewId, -1 );
1019
1020 /*
1021   PAL9111:
1022   because of these items are accessible through object browser and viewers
1023   we have removed they from main menu
1024
1025   createMenu( 216, viewId, -1 );
1026   createMenu( 213, viewId, -1 );
1027   createMenu( 215, viewId, -1 );
1028 */
1029
1030   // ---- create toolbars --------------------------
1031
1032   int basicTbId = createTool( tr( "TOOL_BASIC" ) );
1033   createTool( 4011, basicTbId );
1034   createTool( 4012, basicTbId );
1035   createTool( 4013, basicTbId );
1036   createTool( 4014, basicTbId );
1037   createTool( 4015, basicTbId );
1038   createTool( 4019, basicTbId );
1039   createTool( 4016, basicTbId );
1040   createTool( 4017, basicTbId );
1041   createTool( 4018, basicTbId );
1042   createTool( 4020, basicTbId );
1043
1044   int primTbId = createTool( tr( "TOOL_PRIMITIVES" ) );
1045   createTool( 4021, primTbId );
1046   createTool( 4022, primTbId );
1047   createTool( 4023, primTbId );
1048   createTool( 4024, primTbId );
1049   createTool( 4025, primTbId );
1050
1051   int boolTbId = createTool( tr( "TOOL_BOOLEAN" ) );
1052   createTool( 5011, boolTbId );
1053   createTool( 5012, boolTbId );
1054   createTool( 5013, boolTbId );
1055   createTool( 5014, boolTbId );
1056
1057   int genTbId = createTool( tr( "TOOL_GENERATION" ) );
1058   createTool( 4031, genTbId );
1059   createTool( 4032, genTbId );
1060   createTool( 4033, genTbId );
1061   createTool( 4034, genTbId );
1062
1063   int transTbId = createTool( tr( "TOOL_TRANSFORMATION" ) );
1064   createTool( 5021, transTbId );
1065   createTool( 5022, transTbId );
1066   createTool( 5023, transTbId );
1067   createTool( 5024, transTbId );
1068   createTool( 5025, transTbId );
1069   createTool( 5026, transTbId );
1070   createTool( separator(), transTbId );
1071   createTool( 5027, transTbId );
1072   createTool( 5028, transTbId );
1073
1074   // ---- create popup menus --------------------------
1075
1076   QString clientOCCorVTK = "(client='OCCViewer' or client='VTKViewer')";
1077   QString clientOCCorVTK_AndSomeVisible = clientOCCorVTK + " and selcount>0 and isVisible";
1078
1079   QtxPopupMgr* mgr = popupMgr();
1080   mgr->insert( action(  901 ), -1, -1 );  // rename
1081   mgr->setRule( action( 901 ), "$type in {'Shape' 'Group'} and selcount=1", true );
1082   mgr->insert( action(  8001 ), -1, -1 ); // create group
1083   mgr->setRule( action( 8001 ), "client='ObjectBrowser' and type='Shape' and selcount=1 and isOCC=true", true );
1084   mgr->insert( action(  801 ), -1, -1 );  // edit group
1085   mgr->setRule( action( 801 ),  "client='ObjectBrowser' and type='Group' and selcount=1 and isOCC=true", true );
1086   mgr->insert( separator(), -1, -1 );     // -----------
1087   dispmodeId = mgr->insert(  tr( "MEN_DISPLAY_MODE" ), -1, -1 ); // display mode menu
1088   mgr->insert( action(  80311 ), dispmodeId, -1 ); // wireframe
1089   mgr->setRule( action( 80311 ), clientOCCorVTK_AndSomeVisible, true );
1090   mgr->setRule( action( 80311 ), clientOCCorVTK + " and displaymode='Wireframe'", false );
1091   mgr->insert( action(  80312 ), dispmodeId, -1 ); // shading
1092   mgr->setRule( action( 80312 ), clientOCCorVTK_AndSomeVisible, true );
1093   mgr->setRule( action( 80312 ), clientOCCorVTK + " and displaymode='Shading'", false );
1094   mgr->insert( separator(), -1, -1 );     // -----------
1095   mgr->insert( action(  8032 ), -1, -1 ); // color
1096   mgr->setRule( action( 8032 ), clientOCCorVTK_AndSomeVisible + " and ($component={'GEOM'})", true );
1097   mgr->insert( action(  8033 ), -1, -1 ); // transparency
1098   mgr->setRule( action( 8033 ), clientOCCorVTK_AndSomeVisible, true );
1099   mgr->insert( action(  8034 ), -1, -1 ); // isos
1100   mgr->setRule( action( 8034 ), "client='OCCViewer' and selcount>0 and isVisible", true );
1101   mgr->insert( separator(), -1, -1 );     // -----------
1102
1103
1104   QString canDisplay = "($component={'GEOM'}) and (selcount>0) and ({true} in $canBeDisplayed) ",
1105           onlyComponent = "((type='Component') and selcount=1)",
1106           rule = canDisplay + "and ((($type in {%1}) and( %2 )) or " + onlyComponent + ")",
1107           types = "'Shape' 'Group'";
1108
1109   mgr->insert( action(  216 ), -1, -1 ); // display
1110   mgr->setRule( action( 216 ), rule.arg( types ).arg( "not isVisible" ), true );
1111
1112   mgr->insert( action(  215 ), -1, -1 ); // erase
1113   mgr->setRule( action( 215 ), rule.arg( types ).arg( "isVisible" ), true );
1114
1115   mgr->insert( action(  214 ), -1, -1 ); // erase All
1116   mgr->setRule( action( 214 ), clientOCCorVTK, true );
1117
1118   mgr->insert( action(  213 ), -1, -1 ); // display only
1119   mgr->setRule( action( 213 ), rule.arg( types ).arg( "true" ), true );
1120   mgr->insert( separator(), -1, -1 );
1121
1122   mgr->hide( mgr->actionId( action( myEraseAll ) ) );
1123 }
1124
1125 //=======================================================================
1126 // function : GeometryGUI::activateModule()
1127 // purpose  : Called when GEOM module is activated
1128 //=======================================================================
1129 bool GeometryGUI::activateModule( SUIT_Study* study )
1130 {
1131   if ( CORBA::is_nil( myComponentGeom ) )
1132     return false;
1133
1134   bool res = SalomeApp_Module::activateModule( study );
1135
1136   if ( !res )
1137     return false;
1138
1139   setMenuShown( true );
1140   setToolShown( true );
1141
1142   connect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1143           this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1144
1145   // Reset actions accelerator keys
1146   //action(111)->setAccel(QKeySequence(CTRL + Key_I)); // Import
1147   //action(121)->setAccel(QKeySequence(CTRL + Key_E)); // Export
1148   action(111)->setEnabled(true); // Import
1149   action(121)->setEnabled(true); // Export
1150
1151   GUIMap::Iterator it;
1152   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1153     it.data()->activate( application()->desktop() );
1154
1155   LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1156   SUIT_ViewManager* vm;
1157   ViewManagerList OCCViewManagers, VTKViewManagers;
1158   application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
1159   for ( vm = OCCViewManagers.first(); vm; vm = OCCViewManagers.next() )
1160     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1161   application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
1162   for ( vm = VTKViewManagers.first(); vm; vm = VTKViewManagers.next() )
1163     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1164
1165   // disable OCC selectors
1166   getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1167   for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1168     sr->setEnabled(true);
1169
1170   // disable VTK selectors
1171   getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1172   for ( LightApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1173     sr->setEnabled(true);
1174
1175   return true;
1176 }
1177
1178
1179 //=======================================================================
1180 // function : GeometryGUI::deactivateModule()
1181 // purpose  : Called when GEOM module is deactivated
1182 //=======================================================================
1183 bool GeometryGUI::deactivateModule( SUIT_Study* study )
1184 {
1185   setMenuShown( false );
1186   setToolShown( false );
1187
1188   disconnect( application()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
1189              this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ) );
1190
1191   EmitSignalCloseAllDialogs();
1192
1193   GUIMap::Iterator it;
1194   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
1195     it.data()->deactivate();
1196
1197   // Unset actions accelerator keys
1198   //action(111)->setAccel(QKeySequence()); // Import
1199   //action(121)->setAccel(QKeySequence()); // Export
1200   action(111)->setEnabled(false); // Import
1201   action(121)->setEnabled(false); // Export
1202
1203   myOCCSelectors.clear();
1204   getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
1205
1206   myVTKSelectors.clear();
1207   getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() );
1208
1209   return SalomeApp_Module::deactivateModule( study );
1210 }
1211
1212 //=================================================================================
1213 // function : GeometryGUI::DefinePopup()
1214 // purpose  : Called from desktop to define popup menu [static]
1215 //=================================================================================
1216 /*
1217 void GeometryGUI::DefinePopup(QString& theContext, QString& theParent, QString& theObject)
1218 {
1219   QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
1220   SALOME_Selection* Sel  = SALOME_Selection::Selection(ActiveStudy->getSelection());
1221
1222   theObject  = "";
1223   theContext = "";
1224
1225   if ( theParent == "Viewer" ) {
1226     if ( Sel->IObjectCount() == 0 )
1227       theContext = "NothingSelected";
1228   }
1229
1230   if ( Sel->IObjectCount() == 1 ) {
1231     Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
1232     if( IO->hasEntry() ) {
1233       SALOMEDS::SObject_var sobj = ActiveStudy->getStudyDocument()->FindObjectID( IO->getEntry() );
1234       if ( !sobj->_is_nil() ) {
1235         SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1236         if ( !strcmp(scomp->GetID(), IO->getEntry() ) ) {
1237           // component is selected
1238           theObject = "Component";
1239         }
1240         else {
1241           GEOM::GEOM_Object_var aGObj = GEOM::GEOM_Object::_narrow( sobj->GetObject() );
1242           if ( !CORBA::is_nil( aGObj ) ) {
1243             switch( aGObj->GetType() ) {
1244             case GEOM_GROUP:
1245               theObject = "Group";
1246               break;
1247             default:
1248               theObject = "Shape";
1249               break;
1250             }
1251           }
1252         }
1253       }
1254     }
1255   }
1256 }
1257
1258 //=================================================================================
1259 // function : GeometryGUI::CustomPopup()
1260 // purpose  : Called from desktop to create popup menu [static]
1261 //=================================================================================
1262 bool GeometryGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
1263                               const QString& theParent, const QString& theObject)
1264 {
1265   GeometryGUI* geomGUI = GetGeomGUI();
1266
1267   // Deactivate any non modal dialog box to get the neutral point
1268   geomGUI->EmitSignalDeactivateDialog();
1269   QAD_Study* anActiveStudy    = parent->getActiveStudy();
1270   QAD_StudyFrame* aStudyFrame = anActiveStudy->getActiveStudyFrame();
1271   QAD_ViewFrame* aViewFrame   = aStudyFrame->getRightFrame()->getViewFrame();
1272   SALOME_Selection* Sel       = SALOME_Selection::Selection(anActiveStudy->getSelection());
1273   QString parentComponent     = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
1274   bool isOCCViewer            = aViewFrame->getTypeView() == VIEW_OCC;
1275   bool isVTKViewer            = aViewFrame->getTypeView() == VIEW_VTK;
1276   int aDisplayMode            = 0;
1277   QString objectName;
1278
1279   if ( aViewFrame->getTypeView() == VIEW_OCC )
1280     aDisplayMode = ((OCCViewer_ViewFrame*)aViewFrame)->getViewer()->getAISContext()->DisplayMode();
1281   else if ( aViewFrame->getTypeView() == VIEW_VTK )
1282     aDisplayMode = (dynamic_cast<SVTK_ViewFrame*>( aViewFrame )->getRWInteractor()->GetDisplayMode();
1283
1284   int nbSel = Sel->IObjectCount();
1285
1286   if( nbSel == 0 ) {
1287     ////// NOTHING SELECTED
1288     popup->clear();
1289   }
1290   else if ( nbSel == 1 ) {
1291     ////// SINGLE OBJECT SELECTION
1292     if ( parentComponent != parent->getActiveComponent() )  {
1293       ////// selected object does not belong to GEOM module:
1294       // remove all commands except Display/Erase...
1295       while ( 1 ) {
1296         int id = popup->idAt( 0 );
1297         if ( id <= QAD_TopLabel_Popup_ID )
1298           popup->removeItemAt( 0 );
1299         else
1300           break;
1301       }
1302     }
1303     else {
1304       ////// selected object belong to the GEOM module
1305       // get interactive object
1306       Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1307       objectName = IObject->getName();
1308       // if object has entry get SObject
1309       SALOMEDS::SObject_var SO;
1310       if ( IObject->hasEntry() )
1311         SO = anActiveStudy->getStudyDocument()->FindObjectID( IObject->getEntry() );
1312
1313       if ( theObject == "Component" ) {
1314         ////// menu for component
1315         if ( !isOCCViewer && !isVTKViewer ) {
1316           popup->removeItem( QAD_DisplayOnly_Popup_ID );
1317           popup->removeItem( QAD_Display_Popup_ID );
1318           popup->removeItem( QAD_Erase_Popup_ID );
1319         }
1320       }
1321       else {
1322         ////// not component (should be shape)
1323         if ( IObject->hasEntry() )  /////// VSR : TO BE REMOVED
1324           popup->removeItem( 804 ); // "Add in Study"
1325
1326         // Here could be analysis of the geom shape's type
1327         // ... //
1328
1329         SALOMEDS::GenericAttribute_var aTmpAttr;
1330         if( SO->_is_nil() || SO->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR") )
1331           popup->removeItem( 9024 ); // "Open" /////// VSR : TO BE REMOVED
1332
1333         if ( !isOCCViewer && theParent == "ObjectBrowser" ) {
1334           if ( theObject == "Shape" )
1335             popup->removeItem( 800 ); // Create Group
1336           else if ( theObject == "Group" )
1337             popup->removeItem( 801 ); // Edit Group
1338         }
1339
1340         if ( isOCCViewer || isVTKViewer ) {
1341           ////// current viewer is OCC or VTK
1342           SALOME_Prs* prs = aViewFrame->CreatePrs( IObject->getEntry() );
1343           if ( aViewFrame->isVisible( IObject ) ) {
1344             ////// object is already displayed in the viewer
1345             popup->removeItem( QAD_Display_Popup_ID );
1346             if ( isOCCViewer ) {
1347               ////// OCC viewer only
1348               OCCViewer_Prs* occPrs = dynamic_cast<OCCViewer_Prs*>( prs );
1349               if ( occPrs && !occPrs->IsNull() ) {
1350                 AIS_ListOfInteractive ioList;
1351                 occPrs->GetObjects( ioList );
1352                 QMenuItem* mi = popup->findItem( 803 );
1353                 if ( mi && mi->popup() ) {
1354                   if ( ioList.First()->DisplayMode() == 0 )
1355                     mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1356                   else if ( ioList.First()->DisplayMode() == 1 )
1357                     mi->popup()->setItemChecked( 80312, true ); // "Shading"
1358                   else if ( ioList.First()->DisplayMode() < 0 )
1359                     mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1360                 }
1361               }
1362             }
1363             else {
1364               ////// VTK viewer only
1365               popup->removeItem( 8034 ); // "Isos"
1366               SVTK_Prs* vtkPrs = dynamic_cast<SVTK_Prs*>( prs );
1367               if ( vtkPrs && !vtkPrs->IsNull() ) {
1368                 vtkActorCollection* actorList = vtkPrs->GetObjects();
1369                 actorList->InitTraversal();
1370                 SALOME_Actor* ac = SALOME_Actor::SafeDownCast( actorList->GetNextActor() );
1371                 QMenuItem* mi = popup->findItem( 803 );
1372                 if ( ac && mi && mi->popup() ) {
1373                   if ( ac->getDisplayMode() == 0 )
1374                     mi->popup()->setItemChecked( 80311, true ); // "Wireframe"
1375                   else if ( ac->getDisplayMode() == 1 )
1376                     mi->popup()->setItemChecked( 80312, true ); // "Shading"
1377                   else
1378                     mi->popup()->setItemChecked( aDisplayMode == 0 ? 80311 : 80312 , true ); // "Wireframe" or "Shading"
1379                 }
1380               }
1381             }
1382           }
1383           else {
1384             ////// object is not yet displayed in the viewer
1385             popup->removeItem( 803 );  // "Display Mode"
1386             popup->removeItem( 8032 ); // "Color"
1387             popup->removeItem( 8033 ); // "Transparency"
1388             popup->removeItem( 8034 ); // "Isos"
1389             popup->removeItem( QAD_Erase_Popup_ID );
1390           }
1391           delete prs;
1392         }
1393         else {
1394           ////// other viewer type (neither OCC nor VTK)
1395           popup->removeItem( 803 );  // "Display Mode"
1396           popup->removeItem( 8032 ); // "Color"
1397           popup->removeItem( 8033 ); // "Transparency"
1398           popup->removeItem( 8034 ); // "Isos"
1399           popup->removeItem( QAD_Display_Popup_ID );
1400           popup->removeItem( QAD_DisplayOnly_Popup_ID );
1401           popup->removeItem( QAD_Erase_Popup_ID );
1402         }
1403       }
1404     }
1405   }
1406   else {
1407     ////// MULTIPLE SELECTION
1408     if ( parentComponent != parent->getActiveComponent() )  {
1409       ////// not GEOM module objects or objects belong to different modules
1410       // remove all commands except Display/Erase...
1411       while ( 1 ) {
1412         int id = popup->idAt( 0 );
1413         if ( id <= QAD_TopLabel_Popup_ID )
1414           popup->removeItemAt( 0 );
1415         else
1416           break;
1417       }
1418       if ( parentComponent.isNull() )  {
1419         ////// objects belong to different modules
1420         popup->removeItem(QAD_Display_Popup_ID);
1421         popup->removeItem(QAD_DisplayOnly_Popup_ID);
1422         popup->removeItem(QAD_Erase_Popup_ID);
1423       }
1424       else {
1425         objectName = tr( "GEOM_MEN_POPUP_NAME" ).arg( nbSel );
1426       }
1427     }
1428     else {
1429       ////// all selected objects belong to GEOM module
1430       popup->removeItem( 901 ); // "Rename"
1431
1432       SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1433       bool isComponent  = false;
1434       bool needOpen     = false;
1435       bool needDisplay  = false;
1436       bool needErase    = false;
1437       int needToPublish = 0;
1438
1439       for( ;It.More();It.Next() ) {
1440         Handle(SALOME_InteractiveObject) anIObject = It.Value();
1441
1442         if ( aViewFrame->isVisible( anIObject ) )
1443           needErase   = true;
1444         else
1445           needDisplay = true;
1446
1447         if( anIObject->hasEntry() ) {
1448           needToPublish = -1; /////// VSR : TO BE REMOVED
1449           SALOMEDS::SObject_var obj = anActiveStudy->getStudyDocument()->FindObjectID( anIObject->getEntry() );
1450           SALOMEDS::GenericAttribute_var aTmpAttr;
1451           if ( !obj->_is_nil() && !obj->GetFatherComponent()->FindAttribute( aTmpAttr, "AttributeIOR" ) )
1452             needOpen = true;  /////// VSR : TO BE REMOVED
1453           if ( !obj->_is_nil() && QString( obj->GetID() ) == QString( obj->GetFatherComponent()->GetID() ) )
1454             isComponent = true;
1455         }
1456         else {
1457           if ( needToPublish != -1 ) needToPublish = 1;
1458         }
1459       }
1460       if( needOpen || ( !isOCCViewer && !isVTKViewer ) ) {
1461         ////// Data is not loaded yet or current viewer is neither OCC nor VTK
1462         popup->removeItem( 803 );  // "Display Mode"
1463         popup->removeItem( 8032 ); // "Color"
1464         popup->removeItem( 8033 ); // "Transparency"
1465         popup->removeItem( 8034 ); // "Isos"
1466         popup->removeItem( 804 );  // "Add in Study"
1467         popup->removeItem( QAD_DisplayOnly_Popup_ID );
1468         popup->removeItem( QAD_Display_Popup_ID );
1469         popup->removeItem( QAD_Erase_Popup_ID );
1470       }
1471       else {
1472         popup->removeItem( 9024 );   // "Open"
1473         if ( needToPublish <= 0 )
1474           popup->removeItem( 804 );  // "Add in Study"
1475
1476         if( isComponent ) {
1477           popup->removeItem( 803 );  // "Display Mode"
1478           popup->removeItem( 8032 ); // "Color"
1479           popup->removeItem( 8033 ); // "Transparency"
1480           popup->removeItem( 8034 ); // "Isos"
1481           popup->removeItem( QAD_DisplayOnly_Popup_ID );
1482         }
1483
1484         if ( !needDisplay )
1485           popup->removeItem( QAD_Display_Popup_ID );
1486         if ( !needErase )
1487           popup->removeItem( QAD_Erase_Popup_ID );
1488         if ( !isOCCViewer )
1489           popup->removeItem( 8034 ); // "Isos"
1490       }
1491     }
1492   }
1493
1494   // check popup for unnecessary separators
1495   QAD_Tools::checkPopup( popup );
1496   // find popup menu's TopLabel item (with title)
1497   int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
1498   if ( topItem >= 0 ) {
1499     // remove popup menu's title item
1500     popup->removeItem( QAD_TopLabel_Popup_ID );
1501     if ( theParent == "Viewer" && !objectName.isEmpty() && popup->count() > 0 ) {
1502       // set bold font for popup menu's title
1503       QFont f = popup->font(); f.setBold( TRUE );
1504       popup->removeItem( QAD_TopLabel_Popup_ID );
1505       popup->insertItem( new CustomItem( objectName, f ), QAD_TopLabel_Popup_ID, topItem );
1506     }
1507   }
1508
1509   return false;
1510 }
1511
1512 */
1513
1514 //=======================================================================
1515 // function : GeometryGUI::BuildPresentation()
1516 // purpose  :
1517 //=======================================================================
1518 void GeometryGUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& io, SUIT_ViewWindow* win )
1519 {
1520   //GEOM_Displayer().Display( io, false, win );
1521 }
1522
1523 //=======================================================================
1524 // function : onWindowActivated()
1525 // purpose  : update menu items' status - disable non-OCC-viewer-compatible actions
1526 //=======================================================================
1527 void GeometryGUI::onWindowActivated( SUIT_ViewWindow* win )
1528 {
1529   if ( !win )
1530     return;
1531
1532   const bool ViewOCC = ( win->getViewManager()->getType() == OCCViewer_Viewer::Type() );
1533 //  const bool ViewVTK = ( win->getViewManager()->getType() == SVTK_Viewer::Type() );
1534
1535   // disable non-OCC viewframe menu commands
1536 //  action( 404 )->setEnabled( ViewOCC ); // SKETCHER
1537   action( 603 )->setEnabled( ViewOCC ); // SuppressFace
1538   action( 604 )->setEnabled( ViewOCC ); // SuppressHole
1539   action( 606 )->setEnabled( ViewOCC ); // CloseContour
1540   action( 607 )->setEnabled( ViewOCC ); // RemoveInternalWires
1541   action( 608 )->setEnabled( ViewOCC ); // AddPointOnEdge
1542 //  action( 609 )->setEnabled( ViewOCC ); // Free boundaries
1543   action( 413 )->setEnabled( ViewOCC ); // Isos Settings
1544
1545   action( 800 )->setEnabled( ViewOCC ); // Create Group
1546   action( 801 )->setEnabled( ViewOCC ); // Edit Group
1547
1548   action( 9998 )->setEnabled( ViewOCC ); // MENU BLOCKS - MULTI-TRANSFORMATION
1549 }
1550
1551 void GeometryGUI::windows( QMap<int, int>& mappa ) const
1552 {
1553   mappa.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::DockLeft );
1554   mappa.insert( SalomeApp_Application::WT_PyConsole, Qt::DockBottom );
1555 }
1556
1557 void GeometryGUI::viewManagers( QStringList& lst ) const
1558 {
1559   lst.append( OCCViewer_Viewer::Type() );
1560 }
1561
1562 void GeometryGUI::onViewManagerAdded( SUIT_ViewManager* vm )
1563 {
1564   if ( vm->getType() == OCCViewer_Viewer::Type() )
1565   {
1566     qDebug( "connect" );
1567     connect( vm, SIGNAL( keyPress  ( SUIT_ViewWindow*, QKeyEvent* ) ),
1568              this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
1569     connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
1570              this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
1571     connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
1572              this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
1573
1574
1575     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1576     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
1577
1578     // disable OCC selectors
1579     getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
1580     for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1581       sr->setEnabled(true);
1582   }
1583   else if ( vm->getType() == SVTK_Viewer::Type() )
1584   {
1585     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
1586     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
1587
1588     // disable VTK selectors
1589     getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
1590     for ( LightApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1591       sr->setEnabled(true);
1592   }
1593 }
1594
1595 void GeometryGUI::onViewManagerRemoved( SUIT_ViewManager* vm )
1596 {
1597   SUIT_ViewModel* viewer = vm->getViewModel();
1598   if ( vm->getType() == OCCViewer_Viewer::Type() )
1599   {
1600     for ( GEOMGUI_OCCSelector* sr = myOCCSelectors.first(); sr; sr = myOCCSelectors.next() )
1601       if ( sr->viewer() == viewer )
1602       {
1603         myOCCSelectors.remove( sr );
1604         break;
1605       }
1606   }
1607   if ( vm->getType() == SVTK_Viewer::Type() )
1608   {
1609     for ( LightApp_VTKSelector* sr = myVTKSelectors.first(); sr; sr = myVTKSelectors.next() )
1610       if ( sr->viewer() == viewer )
1611       {
1612         myVTKSelectors.remove( sr );
1613         break;
1614       }
1615   }
1616 }
1617
1618 QString GeometryGUI::engineIOR() const
1619 {
1620   QString anIOR = QString::null;
1621   if ( !CORBA::is_nil( GetGeomGen() ) )
1622   {
1623     CORBA::String_var objStr = getApp()->orb()->object_to_string( GetGeomGen() );
1624     anIOR = QString( objStr.in() );
1625 //    free( objStr ); ASV : 26.07.06 : commented out because it raises exception and blocks application
1626   }
1627   return anIOR;
1628 }
1629
1630 LightApp_Selection* GeometryGUI::createSelection() const
1631 {
1632   return new GEOMGUI_Selection();
1633 }
1634
1635 void GeometryGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& title )
1636 {
1637   SalomeApp_Module::contextMenuPopup( client, menu, title );
1638   SALOME_ListIO lst;
1639   getApp()->selectionMgr()->selectedObjects( lst );
1640   if ( ( client == "OCCViewer" || client == "VTKViewer" ) && lst.Extent() == 1 ) {
1641     Handle(SALOME_InteractiveObject) io = lst.First();
1642     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
1643     _PTR(Study) study = appStudy->studyDS();
1644     _PTR(SObject) obj = study->FindObjectID( io->getEntry() );
1645     if ( obj )
1646       title = QString( obj->GetName().c_str() );
1647   }
1648 }
1649
1650 void GeometryGUI::createPreferences()
1651 {
1652   int tabId = addPreference( tr( "PREF_TAB_SETTINGS" ) );
1653
1654   int genGroup = addPreference( tr( "PREF_GROUP_GENERAL" ), tabId );
1655   setPreferenceProperty( genGroup, "columns", 1 );
1656
1657   int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup,
1658                             LightApp_Preferences::Selector, "Geometry", "display_mode" );
1659
1660   addPreference( tr( "PREF_SHADING_COLOR" ), genGroup,
1661                  LightApp_Preferences::Color, "Geometry", "shading_color" );
1662
1663   addPreference( tr( "PREF_WIREFRAME_COLOR" ), genGroup,
1664                  LightApp_Preferences::Color, "Geometry", "wireframe_color" );
1665
1666   addPreference( tr( "PREF_FREE_BOUND_COLOR" ), genGroup,
1667                  LightApp_Preferences::Color, "Geometry", "free_bound_color" );
1668
1669   addPreference( tr( "PREF_LINE_COLOR"), genGroup,
1670                  LightApp_Preferences::Color, "Geometry", "line_color" );
1671
1672   addPreference( tr( "PREF_POINT_COLOR"), genGroup,
1673                  LightApp_Preferences::Color, "Geometry", "point_color" );
1674
1675   addPreference( tr( "PREF_ISOS_COLOR" ), genGroup,
1676                  LightApp_Preferences::Color, "Geometry", "isos_color" );
1677
1678   int step = addPreference( tr( "PREF_STEP_VALUE" ), genGroup,
1679                             LightApp_Preferences::IntSpin, "Geometry", "SettingsGeomStep" );
1680
1681   // Set property for default display mode
1682   QStringList aModesList;
1683   aModesList.append( tr("MEN_WIREFRAME") );
1684   aModesList.append( tr("MEN_SHADING") );
1685
1686   QValueList<QVariant> anIndexesList;
1687   anIndexesList.append(0);
1688   anIndexesList.append(1);
1689
1690   setPreferenceProperty( dispmode, "strings", aModesList );
1691   setPreferenceProperty( dispmode, "indexes", anIndexesList );
1692
1693   // Set property for step value for spinboxes
1694   setPreferenceProperty( step, "min", 0.001 );
1695   setPreferenceProperty( step, "max", 10000 );
1696   setPreferenceProperty( step, "precision", 3 );
1697
1698 }
1699
1700 void GeometryGUI::preferencesChanged( const QString& section, const QString& param )
1701 {
1702   if (section == "Geometry") {
1703     SUIT_ResourceMgr* aResourceMgr = SUIT_Session::session()->resourceMgr();
1704     if (param == QString("SettingsGeomStep")) {
1705       double spin_step = aResourceMgr->doubleValue(section, param, 100.);
1706       EmitSignalDefaultStepValueChanged(spin_step);
1707     }
1708   }
1709 }
1710
1711 LightApp_Displayer* GeometryGUI::displayer()
1712 {
1713   if( !myDisplayer )
1714     myDisplayer = new GEOM_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
1715   return myDisplayer;
1716 }