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