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