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