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